API reference
Every public name exported from @omnist-dev/omnist (see src/index.ts), grouped by area, with signatures. This mirrors the Python package's __all__ -- see layout.md for which src/*.ts module owns each group.
Errors
class OmnistError extends Error-- the base of every error this library throws.class SchemaError extends OmnistErrorclass ParseError extends OmnistErrorclass WriteError extends OmnistErrorclass DocumentError extends OmnistErrorclass DetachedNode extends OmnistErrorclass UnsafeXMLWarning extends OmnistErrortype OmnistIssue-- the shape of a single validation/lint finding.
Documents
class Doc-- a guarded wrapper around aNode.static of(value: unknown): Docconstructor(node: Node, path?: string)get isLeaf(): booleanget value(): Scalaredges(): Array<[string, Doc]>labels(): string[]get(label: string): Doc[]getOne(label: string): Doccount(label: string): numberchild(label: string): Docadd(label: string, value: unknown): Docremove(label: string): Docset(label: string, value: unknown): DoctoData(): NodetoGrouped(): unknownequals(other: unknown): boolean
function doc(value: unknown): Doc-- builds aDocfrom a plain JS value, or passes an existingDocthrough.type Node = Scalar | Edge[]type Edge = { label: string; target: Node }type Scalar = string | number | boolean | Date | null
Schema model
class Schema-- a rootRefTypeplus an environment of namedRecords.constructor(root: RefType, env?)readonly root: RefTypereadonly env: ReadonlyMap<string, Record>resolve(type: FieldType): Record | ScalarType | AnyFieldTypevalidate(d: Doc): ValidationResultvalidates(d: Doc): booleancompatibleWith(other: Schema): booleanequivalent(other: Schema): booleannormalize(): Schemaprune(): SchemaisEmpty(): boolean
function schema(root: RefType | string, env?): Schemafunction record(...fields: Field[]): Recordfunction field(label: string, type: FieldType, min?: number, max?: number | null): Fieldfunction ref(name: string): RefTypefunction nullable(scalarType: ScalarType | AnyFieldType): ScalarTypeconst t: { string, integer, number, boolean, date, time, datetime }-- the seven pre-builtScalarTypes.const ANY: AnyFieldTypeconst SCALAR_KINDS: readonly ScalarKind[]function cardinalityStr(f: Field): stringfunction recordField(rec: Record, label: string): Field | undefinedfunction fieldTypeEquals(a, b): booleanfunction recordEquals(a, b): booleanfunction schemaEquals(a, b): booleanfunction matchesKind(value: unknown, name: ScalarKind): booleanfunction valueKind(v: unknown): ScalarKindfunction validationResultToString(res: ValidationResult): string- Types:
ScalarKind,FieldType,ScalarType,RefType,AnyFieldType,Field,Record,ValidationResult.
OSD
function parseSchema(text: string): Schemafunction toOsd(schema: Schema, opts?: ToOsdOptions): stringtype ToOsdOptions
Operations
function infer(samples: readonly unknown[], options?: InferOptions): Schemafunction inferWithReport(samples, options?): { schema: Schema; report: AnyFallback[] }type InferOptions = { rootName?: string; allowAny?: boolean }type AnyFallbackfunction materialize(node: Node, schema: Schema): Node-- schema-directed deserialization (upgrades value-exact leaves to match the schema).function lint(s: Schema): LintFinding[]type LintFindingSchema.prototype.compatibleWith(other)/.equivalent(other)/.normalize()/.prune()/.isEmpty()-- the schema-comparison and -reduction operations. Packageexportsonly publish the top-level@omnist-dev/omnistmodule (seepackage.json), soextract,isomorphic, and the standaloneops/*functions these methods delegate to are internal implementation detail, not public API, in this release.
Formats
Every format module exports the same three-function shape:
readJson(text, opts?: ReadJsonOptions): Node/writeJson(node, opts?: WriteJsonOptions): string/checkJson(node): WriteReportreadOml(text, opts?): Node/writeOml(node, opts?: WriteOmlOptions): string/checkOml(node): WriteReportreadXml(text, opts?: ReadXmlOptions): Node/writeXml(node, opts?: WriteXmlOptions): string/checkXml(node): WriteReportreadToml(text, opts?: ReadTomlOptions): Node/writeToml(node, opts?: WriteTomlOptions): string/checkToml(node): WriteReportreadYaml(text, opts?: ReadYamlOptions): Node/writeYaml(node, opts?: WriteYamlOptions): string/checkYaml(node): WriteReport
See Formats for the per-format mapping and caveats.
Adjustment reports
class WriteReport--.adjustments: Adjustment[],.ok: boolean.type Adjustment = { code: string; path: string; message: string; severity: Severity }type Severityfunction finishWrite(opts: FinishWriteOptions): WriteReporttype FinishWriteOptions
Format registry
function registerFormat(f: Format): voidfunction getFormat(name: string): Formatfunction formats(): string[]type Format = { name: string; read; write; check }
Version
const VERSION = "0.0.1-alpha"