UNPKG

@dpkit/core

Version:

Fast TypeScript data management framework built on top of the Data Package standard and Polars DataFrames

30 lines (23 loc) 942 B
import { type Descriptor, validateDescriptor } from "../general/index.ts" import { loadProfile } from "../general/index.ts" import type { Schema } from "./Schema.ts" import { normalizeSchema } from "./process/normalize.ts" const DEFAULT_PROFILE = "https://datapackage.org/profiles/1.0/tableschema.json" /** * Validate a Schema descriptor (JSON Object) against its profile */ export async function validateSchema(source: Descriptor | Schema) { const descriptor = source as Descriptor const $schema = typeof descriptor.$schema === "string" ? descriptor.$schema : DEFAULT_PROFILE const profile = await loadProfile($schema) const { valid, errors } = await validateDescriptor(descriptor, { profile }) let schema: Schema | undefined = undefined if (valid) { // Validation + normalization = we can cast it schema = normalizeSchema(descriptor) as unknown as Schema } return { valid, errors, schema } }