Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions all/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
export * from "@dpkit/arrow"
export * from "@dpkit/camtrap"
export * from "@dpkit/csv"
export * from "@dpkit/ckan"
export * from "@dpkit/core"
export * from "@dpkit/csv"
export * from "@dpkit/database"
export * from "@dpkit/datahub"
export * from "@dpkit/file"
export * from "@dpkit/folder"
export * from "@dpkit/github"
export * from "@dpkit/inline"
export * from "@dpkit/json"
export * from "@dpkit/jsonschema"
export * from "@dpkit/ods"
export * from "@dpkit/parquet"
export * from "@dpkit/table"
export * from "@dpkit/xlsx"
export * from "@dpkit/zenodo"

// TODO: Enable after migrated away from yauzl-promise (uses native crc32)
//export * from "@dpkit/zip"

Expand Down
1 change: 1 addition & 0 deletions all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@dpkit/github": "workspace:*",
"@dpkit/inline": "workspace:*",
"@dpkit/json": "workspace:*",
"@dpkit/jsonschema": "workspace:*",
"@dpkit/ods": "workspace:*",
"@dpkit/parquet": "workspace:*",
"@dpkit/table": "workspace:*",
Expand Down
8 changes: 4 additions & 4 deletions core/dialect/Dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import type { Metadata } from "../general/index.ts"
*/
export interface Dialect extends Metadata {
/**
* The name of this dialect
* JSON schema profile URL for validation
*/
name?: string
$schema?: string

/**
* JSON schema profile URL for validation
* The name of this dialect
*/
$schema?: string
name?: string

/**
* Whether the file includes a header row with field names
Expand Down
10 changes: 5 additions & 5 deletions core/package/Package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import type { Contributor } from "./Contributor.ts"
* @see https://datapackage.org/standard/data-package/
*/
export interface Package extends Metadata {
/**
* URL of profile (optional)
*/
$schema?: string

/**
* Data resources in this package (required)
*/
Expand All @@ -18,11 +23,6 @@ export interface Package extends Metadata {
*/
name?: string

/**
* Package schema URL for validation
*/
$schema?: string

/**
* Human-readable title
*/
Expand Down
5 changes: 5 additions & 0 deletions core/resource/Resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import type { Source } from "./Source.ts"
* @see https://datapackage.org/standard/data-resource/
*/
export interface Resource extends Metadata {
/**
* JSON schema profile URL for validation
*/
$schema?: string

/**
* Unique resource identifier
* Should use lowercase alphanumeric characters, periods, hyphens, and underscores
Expand Down
23 changes: 19 additions & 4 deletions core/schema/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@ import type { ForeignKey } from "./ForeignKey.ts"
*/
export interface Schema extends Metadata {
/**
* Fields in this schema (required)
* URL of profile (optional)
*/
fields: Field[]
$schema?: string

/**
* URL of schema (optional)
* Name of schema (optional)
*/
$schema?: string
name?: string

/**
* Title of schema (optional)
*/
title?: string

/**
* Description of schema (optional)
*/
description?: string

/**
* Fields in this schema (required)
*/
fields: Field[]

/**
* Field matching rule (optional)
Expand Down
1 change: 1 addition & 0 deletions docs/astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const PACKAGES = {
"@dpkit/github": "../github",
"@dpkit/inline": "../inline",
"@dpkit/json": "../json",
"@dpkit/jsonschema": "../jsonschema",
"@dpkit/ods": "../ods",
"@dpkit/parquet": "../parquet",
"@dpkit/table": "../table",
Expand Down
71 changes: 71 additions & 0 deletions dpkit/commands/schema/convert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { denormalizeJsonSchema, normalizeJsonSchema } from "@dpkit/all"
import { loadDescriptor, saveDescriptor } from "@dpkit/all"
import { Command, Option } from "commander"
import { helpConfiguration } from "../../helpers/help.ts"
import { Session } from "../../helpers/session.ts"
import * as params from "../../params/index.ts"

const format = new Option("--format <format>", "source schema format").choices([
"schema",
"jsonschema",
])

const toFormat = new Option(
"--to-format <format>",
"target schema format",
).choices(["schema", "jsonschema"])

export const convertSchemaCommand = new Command("convert")
.configureHelp(helpConfiguration)
.description("Convert schema between different formats")

.addArgument(params.positionalDescriptorPath)
.addOption(format)
.addOption(toFormat)
.addOption(params.toPath)
.addOption(params.json)
.addOption(params.debug)

.action(async (path, options) => {
const session = Session.create({
title: "Convert schema",
json: options.json || !options.toPath,
debug: options.debug,
})

if (!options.format && !options.toFormat) {
session.terminate("Either --format or --to-format must be specified")
process.exit(1)
}

if (options.format === options.toFormat) {
session.terminate("Source and target formats must be different")
process.exit(1)
}

const converter =
options.format === "schema" || options.toFormat === "jsonschema"
? denormalizeJsonSchema
: normalizeJsonSchema

const source = await session.task("Loading schema", loadDescriptor(path))
const target = await session.task(
"Converting schema",
// @ts-ignore
converter(source.descriptor),
)

if (!options.toPath) {
session.render(target)
return
}

await session.task(
"Saving schema",
saveDescriptor(target as any, {
path: options.toPath,
}),
)

session.success(`Converted schema from ${path} to ${options.toPath}`)
})
2 changes: 2 additions & 0 deletions dpkit/commands/schema/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Command } from "commander"
import { helpConfiguration } from "../../helpers/help.ts"
import { convertSchemaCommand } from "./convert.tsx"
import { exploreSchemaCommand } from "./explore.tsx"
import { inferSchemaCommand } from "./infer.tsx"
import { scriptSchemaCommand } from "./script.tsx"
Expand All @@ -10,6 +11,7 @@ export const schemaCommand = new Command("schema")
.description("Table Schema related commands")

.addCommand(inferSchemaCommand)
.addCommand(convertSchemaCommand)
.addCommand(exploreSchemaCommand)
.addCommand(scriptSchemaCommand)
.addCommand(validateSchemaCommand)
3 changes: 3 additions & 0 deletions jsonschema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @dpkit/jsonschema

dpkit is a fast data management framework built on top of the Data Package standard and Polars DataFrames. It supports various formats like CSV, JSON, and Parquet and integrates with data platforms such as CKAN, Zenodo, and GitHub. For more information, please visit the [documentation portal](https://dpkit.datist.io).
1 change: 1 addition & 0 deletions jsonschema/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./schema/index.ts"
33 changes: 33 additions & 0 deletions jsonschema/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@dpkit/jsonschema",
"type": "module",
"version": "0.0.0-development",
"exports": "./build/index.js",
"license": "MIT",
"author": "Evgeny Karev",
"repository": "https://github.com/datisthq/dpkit",
"description": "Fast TypeScript data management framework built on top of the Data Package standard and Polars DataFrames",
"keywords": [
"data",
"polars",
"dataframe",
"datapackage",
"tableschema",
"typescript",
"validation",
"quality",
"fair",
"jsonschema"
],
"scripts": {
"build": "tsc"
},
"dependencies": {
"@dpkit/core": "workspace:*",
"@types/json-schema": "^7.0.15",
"json-schema": "^0.4.0"
},
"devDependencies": {
"@dpkit/test": "workspace:*"
}
}
Loading