json-renderer 0.0.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/adapter.js ADDED
@@ -0,0 +1,4 @@
1
+ export function resolveNode(registry, type) {
2
+ const handler = registry[type];
3
+ return handler === undefined ? { status: 'unknown', type } : { status: 'resolved', type, handler };
4
+ }
@@ -0,0 +1,50 @@
1
+ const TEMPLATE = /\{\{\s*([^}\s]+)\s*\}\}/g;
2
+ /** Read a dotted path (`row.author.name`) out of a scope object. */
3
+ export function readPath(scope, path) {
4
+ let current = scope;
5
+ for (const segment of path.split('.')) {
6
+ if (current == null || typeof current !== 'object')
7
+ return undefined;
8
+ current = current[segment];
9
+ }
10
+ return current;
11
+ }
12
+ /**
13
+ * Resolve a binding expression. A template that is exactly one placeholder
14
+ * yields the raw value (so a boolean or an object survives); a template mixed
15
+ * with text is interpolated as a string.
16
+ */
17
+ export function resolveBinding(expression, scope) {
18
+ const single = expression.match(/^\{\{\s*([^}\s]+)\s*\}\}$/);
19
+ if (single) {
20
+ return readPath(scope, single[1]);
21
+ }
22
+ return expression.replace(TEMPLATE, (_match, path) => {
23
+ const value = readPath(scope, path);
24
+ return value == null ? '' : String(value);
25
+ });
26
+ }
27
+ /** Apply a node's `bindings` over its static props. */
28
+ export function resolveNodeProps(node, scope) {
29
+ if (!node.bindings)
30
+ return (node.props ?? {});
31
+ const resolved = { ...(node.props ?? {}) };
32
+ for (const [prop, expression] of Object.entries(node.bindings)) {
33
+ resolved[prop] = resolveBinding(expression, scope);
34
+ }
35
+ return resolved;
36
+ }
37
+ /**
38
+ * Layer scopes left-to-right, later layers winning. Scope layering is how a
39
+ * renderer adds row/item context inside a repeating node without rebuilding the
40
+ * document's scope.
41
+ */
42
+ export function composeScope(...layers) {
43
+ const composed = {};
44
+ for (const layer of layers) {
45
+ if (!layer)
46
+ continue;
47
+ Object.assign(composed, layer);
48
+ }
49
+ return composed;
50
+ }
package/esm/compose.js ADDED
@@ -0,0 +1,113 @@
1
+ export const DEFAULT_COMPOSE_VOCABULARY = {
2
+ fragmentNodeType: 'Fragment',
3
+ slotNodeType: 'Slot',
4
+ fragmentRefProp: 'ref',
5
+ slotNameProp: 'name',
6
+ };
7
+ function vocabularyOf(options) {
8
+ return { ...DEFAULT_COMPOSE_VOCABULARY, ...options.vocabulary };
9
+ }
10
+ function applyOverride(node, override) {
11
+ return {
12
+ ...node,
13
+ ...(override.type ? { type: override.type } : {}),
14
+ props: { ...node.props, ...override.props },
15
+ ...(override.bindings ? { bindings: { ...node.bindings, ...override.bindings } } : {}),
16
+ ...(override.actions ? { actions: { ...node.actions, ...override.actions } } : {}),
17
+ };
18
+ }
19
+ function expandChild(node, options, vocabulary) {
20
+ if (node.type === vocabulary.fragmentNodeType) {
21
+ const ref = node.props?.[vocabulary.fragmentRefProp];
22
+ const fragment = typeof ref === 'string' ? options.fragments?.[ref] : undefined;
23
+ // An unresolved reference stays in the tree so the renderer surfaces it
24
+ // rather than silently dropping content.
25
+ return fragment
26
+ ? [composeNode(fragment, options, vocabulary)]
27
+ : [composeNode({ ...node, children: [] }, options, vocabulary)];
28
+ }
29
+ if (node.type === vocabulary.slotNodeType) {
30
+ const name = node.props?.[vocabulary.slotNameProp];
31
+ const filler = typeof name === 'string' ? options.slots?.[name] : undefined;
32
+ if (filler === undefined) {
33
+ // No filler: fall back to the slot's own children (its default content).
34
+ return (node.children ?? []).flatMap((child) => expandChild(child, options, vocabulary));
35
+ }
36
+ const nodes = Array.isArray(filler) ? filler : [filler];
37
+ return nodes.map((filled) => composeNode(filled, options, vocabulary));
38
+ }
39
+ return [composeNode(node, options, vocabulary)];
40
+ }
41
+ function composeNode(node, options, vocabulary) {
42
+ const override = options.overrides?.[node.key];
43
+ const base = override ? applyOverride(node, override) : node;
44
+ const children = (base.children ?? [])
45
+ .filter((child) => !options.overrides?.[child.key]?.remove)
46
+ .flatMap((child) => expandChild(child, options, vocabulary));
47
+ return { ...base, children };
48
+ }
49
+ /**
50
+ * Compose a document: expand fragment references, fill slots, then apply
51
+ * per-node overrides. Pure — the input document is never mutated.
52
+ */
53
+ export function composeEnvelope(document, options = {}) {
54
+ return { ...document, page: composeNode(document.page, options, vocabularyOf(options)) };
55
+ }
56
+ export function composeNodeTree(node, options = {}) {
57
+ return composeNode(node, options, vocabularyOf(options));
58
+ }
59
+ /**
60
+ * Merge an overlay tree onto a base tree by node `key`: matching nodes have
61
+ * their props, bindings, and actions shallow-merged (overlay wins) and their
62
+ * children merged recursively; overlay children with no match are appended.
63
+ * This is the "hand-authored beats generated, at the node level" rule.
64
+ */
65
+ export function mergeNodeTrees(base, overlay) {
66
+ const merged = {
67
+ ...base,
68
+ ...(overlay.type ? { type: overlay.type } : {}),
69
+ props: { ...base.props, ...overlay.props },
70
+ ...(base.bindings || overlay.bindings ? { bindings: { ...base.bindings, ...overlay.bindings } } : {}),
71
+ ...(base.actions || overlay.actions ? { actions: { ...base.actions, ...overlay.actions } } : {}),
72
+ };
73
+ const overlayChildren = (overlay.children ?? []);
74
+ const byKey = new Map(overlayChildren.map((child) => [child.key, child]));
75
+ const consumed = new Set();
76
+ const children = (base.children ?? []).map((child) => {
77
+ const patch = byKey.get(child.key);
78
+ if (!patch)
79
+ return child;
80
+ consumed.add(child.key);
81
+ return mergeNodeTrees(child, patch);
82
+ });
83
+ for (const child of overlayChildren) {
84
+ if (!consumed.has(child.key))
85
+ children.push(child);
86
+ }
87
+ return { ...merged, children };
88
+ }
89
+ function mergeNamed(base, overlay) {
90
+ if (!base && !overlay)
91
+ return undefined;
92
+ const merged = new Map((base ?? []).map((entry) => [entry.name, entry]));
93
+ for (const entry of overlay ?? [])
94
+ merged.set(entry.name, entry);
95
+ return [...merged.values()];
96
+ }
97
+ /**
98
+ * Merge an overlay document onto a base document: envelope identity comes from
99
+ * the overlay when set, `meta` is shallow-merged, `registries` and `dataSources`
100
+ * are merged by name, and the page trees are merged by node key.
101
+ */
102
+ export function mergeEnvelopes(base, overlay) {
103
+ const registries = mergeNamed(base.registries, overlay.registries);
104
+ const dataSources = mergeNamed(base.dataSources, overlay.dataSources);
105
+ return {
106
+ ...base,
107
+ ...overlay,
108
+ ...(base.meta || overlay.meta ? { meta: { ...base.meta, ...overlay.meta } } : {}),
109
+ ...(registries ? { registries } : {}),
110
+ ...(dataSources ? { dataSources } : {}),
111
+ page: overlay.page ? mergeNodeTrees(base.page, overlay.page) : base.page,
112
+ };
113
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Value constraints a node can declare, and the pure check over them. Documents
3
+ * are authored elsewhere (a JSON Schema, a database constraint, an agent), so
4
+ * this layer never throws on malformed input.
5
+ */
6
+ /**
7
+ * Validate a single value against the constraints declared on its node.
8
+ * Returns a human-readable message, or `null` when the value is acceptable.
9
+ */
10
+ export function validateValue(value, constraints, required) {
11
+ const stringValue = value == null ? '' : String(value);
12
+ const isEmpty = stringValue.trim() === '';
13
+ if (required && isEmpty) {
14
+ return 'This field is required';
15
+ }
16
+ if (isEmpty)
17
+ return null;
18
+ if (constraints?.minLength != null && stringValue.length < constraints.minLength) {
19
+ return `Minimum ${constraints.minLength} characters required`;
20
+ }
21
+ if (constraints?.maxLength != null && stringValue.length > constraints.maxLength) {
22
+ return `Maximum ${constraints.maxLength} characters allowed`;
23
+ }
24
+ if (constraints?.minValue != null && typeof value === 'number' && value < constraints.minValue) {
25
+ return `Minimum value is ${constraints.minValue}`;
26
+ }
27
+ if (constraints?.maxValue != null && typeof value === 'number' && value > constraints.maxValue) {
28
+ return `Maximum value is ${constraints.maxValue}`;
29
+ }
30
+ if (constraints?.pattern) {
31
+ const regex = compilePattern(constraints.pattern);
32
+ if (regex && !regex.test(stringValue)) {
33
+ return 'Invalid format';
34
+ }
35
+ }
36
+ return null;
37
+ }
38
+ /**
39
+ * An uncompilable pattern must not take the document down — it is reported as
40
+ * unconstrained rather than as a failed value.
41
+ */
42
+ function compilePattern(pattern) {
43
+ try {
44
+ return new RegExp(pattern);
45
+ }
46
+ catch {
47
+ return null;
48
+ }
49
+ }
@@ -0,0 +1,23 @@
1
+ export const DOCUMENT_FORMAT_VERSION = '1.0';
2
+ /**
3
+ * Structural check against one envelope kind. Deliberately shallow: a full
4
+ * check is `parseDocument` (zod), this is the cheap discriminator a router or a
5
+ * content-kind switch needs.
6
+ */
7
+ export function isDocumentEnvelope(value, kind) {
8
+ if (!value || typeof value !== 'object')
9
+ return false;
10
+ const candidate = value;
11
+ return (candidate.type === kind.documentType && candidate.formatVersion === kind.formatVersion && !!candidate.page);
12
+ }
13
+ export function createEnvelope(kind, page, options = {}) {
14
+ return {
15
+ formatVersion: kind.formatVersion,
16
+ type: kind.documentType,
17
+ id: options.id ?? 'document',
18
+ ...(options.meta ? { meta: options.meta } : {}),
19
+ ...(options.registries ? { registries: options.registries } : {}),
20
+ ...(options.dataSources ? { dataSources: options.dataSources } : {}),
21
+ page,
22
+ };
23
+ }
package/esm/fields.js ADDED
@@ -0,0 +1,43 @@
1
+ import { walkNodes } from './node';
2
+ function fieldName(node) {
3
+ const name = node.props?.name;
4
+ return typeof name === 'string' ? name : undefined;
5
+ }
6
+ function* fieldNodes(node, isFieldNode) {
7
+ for (const current of walkNodes(node)) {
8
+ if (!isFieldNode(current))
9
+ continue;
10
+ const name = fieldName(current);
11
+ if (name === undefined)
12
+ continue;
13
+ yield [current, name];
14
+ }
15
+ }
16
+ /** Named fields in document order; field nodes without a `name` are skipped. */
17
+ export function collectFieldNames(node, isFieldNode) {
18
+ const names = [];
19
+ for (const [, name] of fieldNodes(node, isFieldNode))
20
+ names.push(name);
21
+ return names;
22
+ }
23
+ /** Default values declared by field nodes, keyed by field name. */
24
+ export function collectDefaultValues(node, isFieldNode) {
25
+ const values = {};
26
+ for (const [current, name] of fieldNodes(node, isFieldNode)) {
27
+ if (current.props.defaultValue !== undefined) {
28
+ values[name] = current.props.defaultValue;
29
+ }
30
+ }
31
+ return values;
32
+ }
33
+ /** Validation metadata declared by field nodes, keyed by field name. */
34
+ export function collectFieldConstraints(node, isFieldNode) {
35
+ const result = {};
36
+ for (const [current, name] of fieldNodes(node, isFieldNode)) {
37
+ result[name] = {
38
+ constraints: current.props.constraints,
39
+ required: current.props.required,
40
+ };
41
+ }
42
+ return result;
43
+ }
package/esm/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export * from './adapter';
2
+ export * from './bindings';
3
+ export * from './compose';
4
+ export * from './constraints';
5
+ export * from './envelope';
6
+ export * from './fields';
7
+ export * from './json-schema';
8
+ export * from './node';
9
+ export * from './registry';
10
+ export * from './zod';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * JSON Schema export of the format, for agents emitting documents as tool output
3
+ * and for editors/registries that validate without importing zod.
4
+ */
5
+ import { z } from 'zod';
6
+ import { documentEnvelopeSchema, documentNodeSchema } from './zod';
7
+ export function toJsonSchema(schema) {
8
+ return z.toJSONSchema(schema, { io: 'input' });
9
+ }
10
+ export function toEnvelopeJsonSchema() {
11
+ return toJsonSchema(documentEnvelopeSchema);
12
+ }
13
+ export function toNodeJsonSchema() {
14
+ return toJsonSchema(documentNodeSchema);
15
+ }
package/esm/node.js ADDED
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The node tree model: a document is a tree of typed nodes, and a node's `type`
3
+ * is a plain string resolved by an adapter's registry. The vocabulary is a
4
+ * parameter, never a fixed list — a host that renders `Input`/`DataTable` and a
5
+ * host that renders `chart.line` share this model.
6
+ */
7
+ /** Depth-first walk over a node and its descendants. */
8
+ export function* walkNodes(node) {
9
+ yield node;
10
+ for (const child of (node.children ?? [])) {
11
+ yield* walkNodes(child);
12
+ }
13
+ }
14
+ export function findNodeByKey(node, key) {
15
+ for (const current of walkNodes(node)) {
16
+ if (current.key === key)
17
+ return current;
18
+ }
19
+ return undefined;
20
+ }
21
+ export function collectNodes(node, predicate) {
22
+ const matches = [];
23
+ for (const current of walkNodes(node)) {
24
+ if (predicate(current))
25
+ matches.push(current);
26
+ }
27
+ return matches;
28
+ }
29
+ /**
30
+ * Rewrite a tree bottom-up. Pure: the input node is never mutated, so a
31
+ * transform is safe to run on a document that is also being rendered.
32
+ */
33
+ export function mapNodes(node, transform) {
34
+ const children = (node.children ?? []).map((child) => mapNodes(child, transform));
35
+ return transform({ ...node, children });
36
+ }
37
+ /** Node types used anywhere in a tree, sorted for stable output. */
38
+ export function collectNodeTypes(node) {
39
+ const types = new Set();
40
+ for (const current of walkNodes(node)) {
41
+ types.add(current.type);
42
+ }
43
+ return [...types].sort();
44
+ }
45
+ export function createNode(type, key, options = {}) {
46
+ return {
47
+ type,
48
+ key,
49
+ props: options.props ?? {},
50
+ children: options.children ?? [],
51
+ ...(options.bindings ? { bindings: options.bindings } : {}),
52
+ ...(options.actions ? { actions: options.actions } : {}),
53
+ };
54
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Registry resolution: node type → whatever an adapter renders with (a React
3
+ * component, a template function, an HTML serializer). The core owns the
4
+ * layering rules; the handler type is the adapter's business.
5
+ */
6
+ /**
7
+ * Layer registries left-to-right, later layers winning. This is how a host
8
+ * customizes rendering: base primitives, then an app registry, then per-document
9
+ * overrides — no forking of the renderer, and no single global map.
10
+ */
11
+ export function composeRegistry(...layers) {
12
+ const composed = {};
13
+ for (const layer of layers) {
14
+ if (!layer)
15
+ continue;
16
+ Object.assign(composed, layer);
17
+ }
18
+ return composed;
19
+ }
20
+ export function resolveHandler(registry, type) {
21
+ return registry[type];
22
+ }
23
+ /** Node types the registry can render, sorted for stable output. */
24
+ export function registeredTypes(registry) {
25
+ return Object.keys(registry).sort();
26
+ }
27
+ /** Node types a document uses that no registry layer satisfies. */
28
+ export function missingTypes(registry, usedTypes) {
29
+ const missing = new Set();
30
+ for (const type of usedTypes) {
31
+ if (!(type in registry))
32
+ missing.add(type);
33
+ }
34
+ return [...missing].sort();
35
+ }
package/esm/zod.js ADDED
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Runtime validation for the generic envelope. Concrete formats build their own
3
+ * schemas from these factories, so a vocabulary narrows props, actions, or node
4
+ * types without restating the tree rules.
5
+ */
6
+ import { z } from 'zod';
7
+ import { DOCUMENT_FORMAT_VERSION } from './envelope';
8
+ export const nodeConstraintsSchema = z.object({
9
+ minLength: z.number().int().nonnegative().optional(),
10
+ maxLength: z.number().int().nonnegative().optional(),
11
+ minValue: z.number().optional(),
12
+ maxValue: z.number().optional(),
13
+ pattern: z.string().optional(),
14
+ precision: z.number().int().nonnegative().optional(),
15
+ scale: z.number().int().nonnegative().optional(),
16
+ });
17
+ /** Props are open by default: a vocabulary extends this with what it knows. */
18
+ export const nodePropsSchema = z.looseObject({});
19
+ export const nodeBindingsSchema = z.record(z.string(), z.string());
20
+ export const nodeActionSchema = z.object({
21
+ type: z.string().min(1),
22
+ flowId: z.string().optional(),
23
+ handler: z.string().optional(),
24
+ inputMapping: z.record(z.string(), z.string()).optional(),
25
+ params: z.record(z.string(), z.unknown()).optional(),
26
+ });
27
+ export const nodeActionsSchema = z.record(z.string(), nodeActionSchema);
28
+ export const registrySourceSchema = z.object({
29
+ name: z.string().min(1),
30
+ url: z.string().min(1),
31
+ });
32
+ export const dataSourceSchema = z.looseObject({
33
+ name: z.string().min(1),
34
+ query: z.string().optional(),
35
+ variables: z.record(z.string(), z.unknown()).optional(),
36
+ });
37
+ export const documentMetadataSchema = z.looseObject({
38
+ title: z.string().optional(),
39
+ description: z.string().optional(),
40
+ });
41
+ /**
42
+ * Build the recursive node schema. Unknown node types pass by default: a
43
+ * registry may satisfy types this package has never heard of, and rejecting them
44
+ * here would make the format closed.
45
+ */
46
+ export function createNodeSchema(options = {}) {
47
+ const schema = z.lazy(() => z.object({
48
+ type: options.typeSchema ?? z.string().min(1),
49
+ key: z.string().min(1),
50
+ props: (options.propsSchema ?? nodePropsSchema).default({}),
51
+ children: z.array(schema).default([]),
52
+ bindings: nodeBindingsSchema.optional(),
53
+ actions: (options.actionsSchema ?? nodeActionsSchema).optional(),
54
+ }));
55
+ return schema;
56
+ }
57
+ export const documentNodeSchema = createNodeSchema();
58
+ /** Build the envelope schema around a node schema. */
59
+ export function createDocumentSchema(options = {}) {
60
+ const nodeSchema = options.nodeSchema ?? createNodeSchema(options);
61
+ return z.object({
62
+ formatVersion: options.kind?.formatVersion
63
+ ? z.literal(options.kind.formatVersion)
64
+ : z.string().min(1),
65
+ type: options.kind?.documentType ? z.literal(options.kind.documentType) : z.string().min(1),
66
+ id: z.string().min(1),
67
+ meta: documentMetadataSchema.optional(),
68
+ registries: z.array(registrySourceSchema).optional(),
69
+ dataSources: z.array(dataSourceSchema).optional(),
70
+ page: nodeSchema,
71
+ });
72
+ }
73
+ export const documentEnvelopeSchema = createDocumentSchema();
74
+ /** Throws a `ZodError` describing every problem in the document. */
75
+ export function parseEnvelope(value) {
76
+ return documentEnvelopeSchema.parse(value);
77
+ }
78
+ export function safeParseEnvelope(value) {
79
+ return documentEnvelopeSchema.safeParse(value);
80
+ }
81
+ export function parseNode(value) {
82
+ return documentNodeSchema.parse(value);
83
+ }
84
+ /** The version this package's generic envelope schema accepts by default. */
85
+ export const SCHEMA_FORMAT_VERSION = DOCUMENT_FORMAT_VERSION;
package/fields.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Field collection over a node tree. Which nodes are fields is a vocabulary
3
+ * decision, so every helper takes a predicate: the core knows the *shape* of a
4
+ * field (a `name`, an optional `defaultValue`, optional `constraints`) without
5
+ * knowing the node types that carry it.
6
+ */
7
+ import type { NodeConstraints } from './constraints';
8
+ import type { AnyDocumentNode } from './node';
9
+ /** Decides whether a node contributes a field. */
10
+ export type FieldNodePredicate<TNode extends AnyDocumentNode = AnyDocumentNode> = (node: TNode) => boolean;
11
+ export interface FieldConstraintEntry {
12
+ constraints?: NodeConstraints;
13
+ required?: boolean;
14
+ }
15
+ /** Named fields in document order; field nodes without a `name` are skipped. */
16
+ export declare function collectFieldNames<TNode extends AnyDocumentNode>(node: TNode, isFieldNode: FieldNodePredicate<TNode>): string[];
17
+ /** Default values declared by field nodes, keyed by field name. */
18
+ export declare function collectDefaultValues<TNode extends AnyDocumentNode>(node: TNode, isFieldNode: FieldNodePredicate<TNode>): Record<string, unknown>;
19
+ /** Validation metadata declared by field nodes, keyed by field name. */
20
+ export declare function collectFieldConstraints<TNode extends AnyDocumentNode>(node: TNode, isFieldNode: FieldNodePredicate<TNode>): Record<string, FieldConstraintEntry>;
package/fields.js ADDED
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectFieldNames = collectFieldNames;
4
+ exports.collectDefaultValues = collectDefaultValues;
5
+ exports.collectFieldConstraints = collectFieldConstraints;
6
+ const node_1 = require("./node");
7
+ function fieldName(node) {
8
+ const name = node.props?.name;
9
+ return typeof name === 'string' ? name : undefined;
10
+ }
11
+ function* fieldNodes(node, isFieldNode) {
12
+ for (const current of (0, node_1.walkNodes)(node)) {
13
+ if (!isFieldNode(current))
14
+ continue;
15
+ const name = fieldName(current);
16
+ if (name === undefined)
17
+ continue;
18
+ yield [current, name];
19
+ }
20
+ }
21
+ /** Named fields in document order; field nodes without a `name` are skipped. */
22
+ function collectFieldNames(node, isFieldNode) {
23
+ const names = [];
24
+ for (const [, name] of fieldNodes(node, isFieldNode))
25
+ names.push(name);
26
+ return names;
27
+ }
28
+ /** Default values declared by field nodes, keyed by field name. */
29
+ function collectDefaultValues(node, isFieldNode) {
30
+ const values = {};
31
+ for (const [current, name] of fieldNodes(node, isFieldNode)) {
32
+ if (current.props.defaultValue !== undefined) {
33
+ values[name] = current.props.defaultValue;
34
+ }
35
+ }
36
+ return values;
37
+ }
38
+ /** Validation metadata declared by field nodes, keyed by field name. */
39
+ function collectFieldConstraints(node, isFieldNode) {
40
+ const result = {};
41
+ for (const [current, name] of fieldNodes(node, isFieldNode)) {
42
+ result[name] = {
43
+ constraints: current.props.constraints,
44
+ required: current.props.required,
45
+ };
46
+ }
47
+ return result;
48
+ }
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export * from './adapter';
2
+ export * from './bindings';
3
+ export * from './compose';
4
+ export * from './constraints';
5
+ export * from './envelope';
6
+ export * from './fields';
7
+ export * from './json-schema';
8
+ export * from './node';
9
+ export * from './registry';
10
+ export * from './zod';
package/index.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./adapter"), exports);
18
+ __exportStar(require("./bindings"), exports);
19
+ __exportStar(require("./compose"), exports);
20
+ __exportStar(require("./constraints"), exports);
21
+ __exportStar(require("./envelope"), exports);
22
+ __exportStar(require("./fields"), exports);
23
+ __exportStar(require("./json-schema"), exports);
24
+ __exportStar(require("./node"), exports);
25
+ __exportStar(require("./registry"), exports);
26
+ __exportStar(require("./zod"), exports);
@@ -0,0 +1,8 @@
1
+ /**
2
+ * JSON Schema export of the format, for agents emitting documents as tool output
3
+ * and for editors/registries that validate without importing zod.
4
+ */
5
+ import { z } from 'zod';
6
+ export declare function toJsonSchema(schema: z.ZodType<unknown>): Record<string, unknown>;
7
+ export declare function toEnvelopeJsonSchema(): Record<string, unknown>;
8
+ export declare function toNodeJsonSchema(): Record<string, unknown>;
package/json-schema.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toJsonSchema = toJsonSchema;
4
+ exports.toEnvelopeJsonSchema = toEnvelopeJsonSchema;
5
+ exports.toNodeJsonSchema = toNodeJsonSchema;
6
+ /**
7
+ * JSON Schema export of the format, for agents emitting documents as tool output
8
+ * and for editors/registries that validate without importing zod.
9
+ */
10
+ const zod_1 = require("zod");
11
+ const zod_2 = require("./zod");
12
+ function toJsonSchema(schema) {
13
+ return zod_1.z.toJSONSchema(schema, { io: 'input' });
14
+ }
15
+ function toEnvelopeJsonSchema() {
16
+ return toJsonSchema(zod_2.documentEnvelopeSchema);
17
+ }
18
+ function toNodeJsonSchema() {
19
+ return toJsonSchema(zod_2.documentNodeSchema);
20
+ }