schema_json.ts

Serializes a schema to the interchange form the Rust crate loads.

A node is {kind, def} as SchemaDefs has it, with def left out where it is undefined. A lazy holds a function there, so its def becomes a name, and the document is an envelope, {schema, defs}, whose defs are what the names stand for.

The crate refuses what it can't carry across, and so does this: it throws, naming the kind and the path, on anything Schema::from_json would reject, and on what the crate's parser would not read of the document itself: a string that is not well-formed Unicode, and nesting deeper than SCHEMA_JSON_MAX_DEPTH. A schema that serializes is one the crate loads. The reverse does not hold: schemas are counted through every lazy, so that a function making a new lazy each call ends, and a schema more than SCHEMA_JSON_MAX_DEPTH schemas deep that way is refused though its document would load.

It is a module of its own, so a bundle that serializes no schema carries none of it. It needs String.prototype.isWellFormed.

view source

Declarations
#

7 declarations

SCHEMA_JSON_MAX_DEPTH
#

schema_json.ts view source

127

The deepest that arrays and objects can be nested in a text the crate reads, a document in the interchange form included. The crate's MAX_DEPTH.

import {SCHEMA_JSON_MAX_DEPTH} from '@fuzdev/fuz_schema/schema_json.ts';

SCHEMA_JSON_MAX_NESTING
#

schema_json.ts view source

16

The most wrappers, lazy, union options, and starts of a pipe around one value. The crate's MAX_NESTING.

import {SCHEMA_JSON_MAX_NESTING} from '@fuzdev/fuz_schema/schema_json.ts';

SCHEMA_JSON_REFUSED_KEYS
#

schema_json.ts view source

readonly string[]

The names of the members of Object.prototype. The library reads an object's entries through the prototype, so an entry with one of these names sees the member when the input lacks the key, and is refused. So is a variant whose key is one.

import {SCHEMA_JSON_REFUSED_KEYS} from '@fuzdev/fuz_schema/schema_json.ts';

SCHEMA_JSON_UNSUPPORTED_KINDS
#

schema_json.ts view source

readonly string[]

The kinds that hold a JavaScript value, which the form has no way to write, and which the crate refuses by name. with_default_fn holds one too and is refused the same way here, and the crate refuses it as a kind it doesn't know. The crate refuses object_with_rest, keyed_record, and to_integer as kinds it doesn't know too, as ones it doesn't carry yet, and to_schema_json refuses them as not portable.

import {SCHEMA_JSON_UNSUPPORTED_KINDS} from '@fuzdev/fuz_schema/schema_json.ts';

SchemaJson
#

SchemaJsonNode
#

schema_json.ts view source

A node of the interchange form.

import type {SchemaJsonNode} from '@fuzdev/fuz_schema/schema_json.ts';

members

kind
: string
#
def
?: unknown
#

to_schema_json
#

schema_json.ts view source

to_schema_json(schema: AnySchema): SchemaJson

Serializes schema to the interchange form.

A lazy is named by what it defers to, $0, $1, and so on in the order they are met, so two lazy that return the same schema share a name. Each function a lazy holds is called once, however many schemas hold it.

import {to_schema_json} from '@fuzdev/fuz_schema/schema_json.ts';

throws

  • Error - naming the kind and the path of anything the Rust crate refuses

Depends on
#

Imported by
#