API reference
Looking for the complete generated TypeDoc documentation? See the TypeDoc API Reference (opens in a new tab). (VitePress's client-side router intercepts same-page
<a>clicks regardless of a plaintarget="_self"attribute -- confirmed empirically: the top nav's "TypeDoc" link, the sidebar's, and this page's own prev/next pager link to the same URL all still get swallowed by the router when clicked from within rendered page content, even though the top-nav item itself (a different Vue component, not routed through content-click interception) does work withtarget="_self".target="_blank"reliably bypasses this everywhere, since opening a new tab is native browser behavior no SPA router can intercept.)
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 OmnistError--code?: stringandpath?: stringare populated forosd.ts's lexical/tokenization errors (theparse.*family, omnist-spec Sec8.3.1, extended by spec#46 to cover OSD's own lexing stage), with aline:colpath(Sec8.4). Every other throw site leaves bothundefined.class ParseError extends OmnistError--code?: stringandpath?: stringare populated foroml.ts's lexer/parser errors (theparse.*family, omnist-spec Sec8.3.1), with aline:colpath(Sec8.4). Ten of the elevenparse.*codes are reachable from OML's grammar;parse.separator-in-arrayis not (seesrc/oml.ts's file-top comment). Every other throw site leavescodeundefined-- some (invalid DATE/TIME/DATETIME literal values) still carry apath, since the position is always known there even without a code. The resource limits are coded:document.limit.depthanddocument.limit.nodesat$, anddocument.limit.int-digitsat the integer literal's Document path (spec E-4a); every reader takesmaxDepth,maxNodesandmaxIntDigitsto set them. A YAML!!omap,!!pairsor!!setis aParseErrorwithcodeformat.tag-forbiddenandpath$(C-13).class WriteError extends OmnistErrorclass DocumentError extends OmnistError--code?: stringandpath?: string; the YAML alias expansion limit (D-18/D-20) throws it withcodedocument.limit.alias-expansionandpath$, and the YAML expanded-size limit (D-22) withcodedocument.limit.expanded-sizeandpath$.class 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(ReadYamlOptions.maxAliasExpansion: the D-18 maximum expansion factor, defaultDEFAULT_MAX_ALIAS_EXPANSION= 50, at mostMAX_RECOMMENDED_ALIAS_EXPANSION= 10000) /writeYaml(node, opts?: WriteYamlOptions): string/checkYaml(node): WriteReport
Every read* function takes maxInputBytes in its options (spec D-23): the largest input, in UTF-8 bytes, it reads at all. The default is DEFAULT_MAX_INPUT_BYTES = 64 MiB; an integer of at least 1, otherwise a RangeError. A larger input is refused with a ParseError whose code is document.limit.input-size and path is $, before anything is decoded or parsed; an input of exactly the maximum is accepted, and a leading byte-order mark counts. readFormat(name, text, opts?) reads with any registered format under the same limit, checking the size before a plugin reader runs. See Limitations.
Every read* function also takes the three universal safety limits of spec D-9 as options (DocumentLimits): maxDepth (default DEFAULT_MAX_DEPTH = 200, levels of node nesting counted from the Document root, which is level 1), maxNodes (DEFAULT_MAX_NODES = 1,000,000, the root included, a scalar leaf not) and maxIntDigits (DEFAULT_MAX_INT_DIGITS = 4,300, the decimal digits of an integer's value, D-28). Each is an integer of at least 1, otherwise a RangeError. A refusal carries code DEPTH_CODE / NODES_CODE (document.limit.depth, document.limit.nodes) at path $, or INT_DIGITS_CODE (document.limit.int-digits) at the integer literal's Document path. See Limitations.
Every write* and check* function throws WriteError (write.unsupported-value, at the Document path of the node holding the string) for a string value or edge label with no UTF-8 encoding, a lone surrogate (spec C-9), whatever strict says; checkOml is no longer always empty for that reason.
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"