Skip to main content

SerializationSchemaMeta

type

A structural, introspectable description of a SerializationSchema. It carries exactly the information needed to coerce a value (which the schema closes over) so that tooling can also walk it — for example to derive a `fast-check` arbitrary that generates example values, or to emit a JSON Schema document. The data here is the same domain information the parser already needs, so making it available costs (almost) nothing in the production bundle.

type SerializationSchemaMeta = { readonly kind: 'string'; } | { readonly kind: 'number'; /** The inclusive lower bound of the domain, when constrained. */ readonly min?: number; /** The inclusive upper bound of the domain, when constrained. */ readonly max?: number; /** Whether the domain is restricted to integers. */ readonly integer?: boolean; /** Whether a finite value outside the bounds clamps to the nearest. */ readonly clamp?: boolean; } | { readonly kind: 'boolean'; } | { readonly kind: 'enum'; readonly values: readonly unknown[]; } | { readonly kind: 'array'; readonly item: InnerSerializationSchema; } | { readonly kind: 'nullable'; readonly inner: InnerSerializationSchema; /** Whether a value equal to `inner`'s default is treated as `null`. */ readonly defaultAsNull?: boolean; } | { readonly kind: 'optional'; readonly inner: InnerSerializationSchema; /** Whether a value equal to `inner`'s default is treated as absent. */ readonly omitDefault?: boolean; } | { readonly kind: 'union'; readonly members: readonly InnerSerializationSchema[]; } | { readonly kind: 'raw'; } | { readonly kind: 'object'; readonly fields: SerializationSchemaFields; } | { readonly kind: 'aliased'; readonly inner: InnerSerializationSchema; /** Legacy input spellings, mapped to the value each denotes. */ readonly aliases: { readonly [alias: string]: unknown; }; } | { /** * A {@link transformValue}: `inner`'s domain on the way in, and an * opaque function on the way out. * * The kind exists to say that last part. The transform is an arbitrary * closure, so it is the one part of a schema that cannot be described * structurally, and a consumer that walked into `inner` and stopped — * which is what inheriting `inner`'s meta made every consumer do — would * be describing the schema's *input* while believing it had described * its output. For a generator of example inputs that is the right * answer; for a code generator it is a parse that silently drops the * transform. */ readonly kind: 'transform'; readonly inner: InnerSerializationSchema; }

Import

import { SerializationSchemaMeta } from '@modular/sdk/editor';