@databehave/schema 0.1.4 → 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/CHANGELOG.md +31 -0
- package/README.md +12 -1
- package/dist/dataset/dataset.d.ts +4 -45
- package/dist/dataset/dataset.d.ts.map +1 -1
- package/dist/dataset/dataset.js +4 -94
- package/dist/dataset/dataset.js.map +1 -1
- package/dist/dataset/generate.d.ts +49 -0
- package/dist/dataset/generate.d.ts.map +1 -0
- package/dist/dataset/generate.js +96 -0
- package/dist/dataset/generate.js.map +1 -0
- package/dist/foundation/axes.d.ts +4 -9
- package/dist/foundation/axes.d.ts.map +1 -1
- package/dist/foundation/axes.js +11 -37
- package/dist/foundation/axes.js.map +1 -1
- package/dist/foundation/errors.d.ts +7 -5
- package/dist/foundation/errors.d.ts.map +1 -1
- package/dist/foundation/errors.js +1 -1
- package/dist/foundation/errors.js.map +1 -1
- package/dist/foundation/ir.d.ts +9 -1
- package/dist/foundation/ir.d.ts.map +1 -1
- package/dist/foundation/ir.js.map +1 -1
- package/dist/foundation/types.d.ts.map +1 -1
- package/dist/foundation/types.js +9 -42
- package/dist/foundation/types.js.map +1 -1
- package/dist/foundation/walk.d.ts +7 -71
- package/dist/foundation/walk.d.ts.map +1 -1
- package/dist/foundation/walk.js +8 -264
- package/dist/foundation/walk.js.map +1 -1
- package/dist/generator/engine.d.ts +4 -35
- package/dist/generator/engine.d.ts.map +1 -1
- package/dist/generator/engine.js +3 -574
- package/dist/generator/engine.js.map +1 -1
- package/dist/generator/replay.d.ts +4 -8
- package/dist/generator/replay.d.ts.map +1 -1
- package/dist/generator/replay.js +3 -20
- package/dist/generator/replay.js.map +1 -1
- package/dist/generator/trace.d.ts +5 -0
- package/dist/generator/trace.d.ts.map +1 -1
- package/dist/generator/trace.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/plugin.d.ts +7 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +14 -0
- package/dist/plugin.js.map +1 -0
- package/dist/runtime/contracts.d.ts +101 -0
- package/dist/runtime/contracts.d.ts.map +1 -0
- package/dist/runtime/contracts.js +67 -0
- package/dist/runtime/contracts.js.map +1 -0
- package/dist/runtime/runtime.d.ts +56 -0
- package/dist/runtime/runtime.d.ts.map +1 -0
- package/dist/runtime/runtime.js +392 -0
- package/dist/runtime/runtime.js.map +1 -0
- package/dist/runtime.d.ts +7 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +5 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schema/decimal.d.ts +2 -2
- package/dist/schema/decimal.js +2 -2
- package/dist/standard/behaviors.d.ts +6 -0
- package/dist/standard/behaviors.d.ts.map +1 -0
- package/dist/standard/behaviors.js +358 -0
- package/dist/standard/behaviors.js.map +1 -0
- package/dist/standard/generation.d.ts +53 -0
- package/dist/standard/generation.d.ts.map +1 -0
- package/dist/standard/generation.js +359 -0
- package/dist/standard/generation.js.map +1 -0
- package/dist/standard/kinds.d.ts +6 -0
- package/dist/standard/kinds.d.ts.map +1 -0
- package/dist/standard/kinds.js +178 -0
- package/dist/standard/kinds.js.map +1 -0
- package/dist/standard/runtime.d.ts +3 -0
- package/dist/standard/runtime.d.ts.map +1 -0
- package/dist/standard/runtime.js +9 -0
- package/dist/standard/runtime.js.map +1 -0
- package/dist/standard/validation.d.ts +44 -0
- package/dist/standard/validation.d.ts.map +1 -0
- package/dist/standard/validation.js +353 -0
- package/dist/standard/validation.js.map +1 -0
- package/dist/standard.d.ts +5 -0
- package/dist/standard.d.ts.map +1 -0
- package/dist/standard.js +5 -0
- package/dist/standard.js.map +1 -0
- package/dist/validator/parse.d.ts +2 -11
- package/dist/validator/parse.d.ts.map +1 -1
- package/dist/validator/parse.js +3 -426
- package/dist/validator/parse.js.map +1 -1
- package/package.json +24 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ir.js","sourceRoot":"","sources":["../../src/foundation/ir.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAwFH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"ir.js","sourceRoot":"","sources":["../../src/foundation/ir.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAwFH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAsCrC,kFAAkF;AAClF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAgB,EAAE,KAAyB,EAAc,EAAE;IAClF,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,EAAE,CAAA;IAC5B,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAA;IAC1F,MAAM,IAAI,GAAc,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,EAAE,CAAA;IAClH,OAAO,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;AAChC,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/foundation/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/foundation/types.ts"],"names":[],"mappings":"AACA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,gBAAgB,EAAsB,WAAW,EAAsB,MAAM,WA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
2
|
-
* Phantom-typed schema builder + Infer<>.
|
|
3
|
-
*
|
|
4
|
-
* Every builder carries:
|
|
5
|
-
* - `_node`: serializable IR (runtime)
|
|
6
|
-
* - `_type`: phantom TS type parameter for inference (compile-time only)
|
|
7
|
-
*
|
|
8
|
-
* Modifiers (.nullable / .optional / .default / .describe) return a *new*
|
|
9
|
-
* builder with updated phantom type and updated IR.
|
|
10
|
-
*/
|
|
1
|
+
import { standardBehaviors } from '../standard/behaviors.js';
|
|
11
2
|
import { SchemaConflictError } from './errors.js';
|
|
12
3
|
import { withMods } from './ir.js';
|
|
13
4
|
/**
|
|
@@ -39,39 +30,15 @@ import { withMods } from './ir.js';
|
|
|
39
30
|
export const Discrete = Symbol('databehave.cap.discrete');
|
|
40
31
|
export const Numeric = Symbol('databehave.cap.numeric');
|
|
41
32
|
export const Continuous = Symbol('databehave.cap.continuous');
|
|
42
|
-
/**
|
|
43
|
-
* Allow-list for which IR kinds may legally carry each axis distribution.
|
|
44
|
-
*
|
|
45
|
-
* Mirrors the type-system `this:` gating on `.weighted` / `.normal` /
|
|
46
|
-
* `.typically`. Used by the runtime guard in those methods to fail-loud
|
|
47
|
-
* when a caller bypasses TypeScript (`as any`, plain JS, `// @ts-ignore`).
|
|
48
|
-
*
|
|
49
|
-
* Stays in sync with `docs/stability.md` "capability matrix".
|
|
50
|
-
*/
|
|
51
|
-
const CAP_BY_OP = {
|
|
52
|
-
// .weighted: discrete-valued kinds. For `kind:'number'` it is allowed only
|
|
53
|
-
// when `int === true` (further check below).
|
|
54
|
-
weighted: new Set(['number', 'string', 'literal', 'enum', 'boolean']),
|
|
55
|
-
// .normal: continuous-numeric kinds. For `kind:'number'` it is allowed
|
|
56
|
-
// only when `int === false` (further check below).
|
|
57
|
-
normal: new Set(['number', 'decimal']),
|
|
58
|
-
// .typically: any numeric kind (int or float or decimal — for ints the
|
|
59
|
-
// generator clamps and rounds).
|
|
60
|
-
typically: new Set(['number', 'decimal']),
|
|
61
|
-
};
|
|
33
|
+
/** Standard fluent builders delegate applicability to the standard behavior owner. */
|
|
62
34
|
const checkAxisAllowed = (op, node) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
throw new SchemaConflictError(`.weighted() is not applicable to num() (continuous); use int().weighted([...]) for discrete numeric weighting`, [], `see docs/stability.md (capability matrix)`);
|
|
71
|
-
}
|
|
72
|
-
if (op === 'normal' && isInt) {
|
|
73
|
-
throw new SchemaConflictError(`.normal() is not applicable to int() (discrete); use num().normal(...) for a continuous Gaussian`, [], `see docs/stability.md (capability matrix)`);
|
|
74
|
-
}
|
|
35
|
+
const metadata = op === 'weighted' ? { kind: 'weighted', weights: [] }
|
|
36
|
+
: op === 'normal' ? { kind: 'normal', mean: 0, stddev: 1 }
|
|
37
|
+
: { kind: 'typical', from: 0, to: 1 };
|
|
38
|
+
const distribution = standardBehaviors.find((behavior) => behavior.id === 'distribution');
|
|
39
|
+
if (distribution === undefined || !distribution.appliesTo(node, metadata)) {
|
|
40
|
+
const label = node.kind === 'number' ? (node.int === true ? 'int() (discrete)' : 'num() (continuous)') : `schema kind '${node.kind}'`;
|
|
41
|
+
throw new SchemaConflictError(`.${op}() is not applicable to ${label}`, [], 'see docs/stability.md (capability matrix)');
|
|
75
42
|
}
|
|
76
43
|
};
|
|
77
44
|
/** Base builder. Subclasses (StringSchema, NumberSchema, …) extend this. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/foundation/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/foundation/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAa5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,C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with paths
|
|
9
|
-
* - `fromIR(node)` : reconstruct a `Schema` builder from IR
|
|
10
|
-
*
|
|
11
|
-
* Combined with the already-public `SchemaNode`, `Modifiers`, `Axes`,
|
|
12
|
-
* `mock`, `parse`, `mockDataset`, `createTrace`, and `seedFromString` /
|
|
13
|
-
* `rngFromString`, this is the full extension contract.
|
|
14
|
-
*
|
|
15
|
-
* Extension authors do NOT subclass `Schema`. They build IR (or compose
|
|
16
|
-
* existing builders) and call `fromIR` to obtain a typed builder back.
|
|
17
|
-
*/
|
|
18
|
-
import { Schema } from './types.js';
|
|
19
|
-
import type { SchemaNode } from './ir.js';
|
|
20
|
-
export type WalkPath = readonly (string | number)[];
|
|
21
|
-
export type SchemaVisitor = {
|
|
22
|
-
/** Called before descending into a node's children. Return false to skip subtree. */
|
|
23
|
-
readonly enter?: (node: SchemaNode, path: WalkPath) => void | boolean;
|
|
24
|
-
/** Called after all children have been visited. */
|
|
25
|
-
readonly leave?: (node: SchemaNode, path: WalkPath) => void;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Depth-first pre/post-order traversal of a schema IR tree.
|
|
29
|
-
*
|
|
30
|
-
* The visitor receives every node (including composites) with its
|
|
31
|
-
* JSON-pointer-style path. Use this to power codegen (OpenAPI, zod, SQL DDL,
|
|
32
|
-
* documentation) without coupling to the builder classes.
|
|
33
|
-
*/
|
|
34
|
-
export declare const walkSchema: (schemaOrNode: Schema | SchemaNode, visitor: SchemaVisitor) => void;
|
|
35
|
-
/**
|
|
36
|
-
* Reconstruct a `Schema` builder from an IR node.
|
|
37
|
-
*
|
|
38
|
-
* Modifiers (`nullable`, `optional`, `default`, `describe`, axes) are
|
|
39
|
-
* preserved. Returns `Schema<unknown>` — extension authors that know the shape
|
|
40
|
-
* statically can cast to a more precise type.
|
|
41
|
-
*/
|
|
42
|
-
export declare const fromIR: (node: SchemaNode) => Schema<unknown>;
|
|
43
|
-
/** Current IR contract version. Bumped on every MAJOR release. */
|
|
44
|
-
export declare const IR_VERSION: 1;
|
|
45
|
-
/** Envelope produced by {@link serializeSchema}. */
|
|
46
|
-
export interface SchemaEnvelope {
|
|
47
|
-
/** Reserved for forward compatibility; do not vary. */
|
|
48
|
-
readonly $databehaveVersion: typeof IR_VERSION;
|
|
49
|
-
readonly node: SchemaNode;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Wrap a schema's IR in a versioned envelope safe for serialisation
|
|
53
|
-
* (JSON, disk, IPC). Pair with {@link deserializeSchema} on the
|
|
54
|
-
* receiving end.
|
|
55
|
-
*
|
|
56
|
-
* Throws {@link SchemaConflictError} (`code: 'serialize.closure-axis'`)
|
|
57
|
-
* when any node in the tree carries a closure-bearing axis — `derived`,
|
|
58
|
-
* `invariants`, or an `occasionally` override whose `value` is a
|
|
59
|
-
* function. Closures cannot survive a JSON round-trip, so encoding such
|
|
60
|
-
* a schema would silently drop the axis on the receiving end and
|
|
61
|
-
* produce subtly wrong values. The check is loud at the encode site so
|
|
62
|
-
* callers reach for {@link replay} or hand-coded carriers instead.
|
|
63
|
-
*/
|
|
64
|
-
export declare const serializeSchema: (schema: Schema<unknown>) => SchemaEnvelope;
|
|
65
|
-
/**
|
|
66
|
-
* Inverse of {@link serializeSchema}. Throws when the envelope was
|
|
67
|
-
* produced by an incompatible MAJOR version — the failure is loud
|
|
68
|
-
* because silently loading a node with a renamed or removed field
|
|
69
|
-
* would manifest as a subtle generation/parse bug far from the cause.
|
|
70
|
-
*/
|
|
71
|
-
export declare const deserializeSchema: (envelope: unknown) => Schema<unknown>;
|
|
1
|
+
export { IR_VERSION, type SchemaEnvelope, type SchemaVisitor, type WalkPath } from '../runtime/runtime.js';
|
|
2
|
+
/** Standard preset traversal. Custom schemas use runtime.walkSchema. */
|
|
3
|
+
export declare const walkSchema: (schema: import("./types.js").Schema | import("./ir.js").SchemaNode, visitor: import("./walk.js").SchemaVisitor) => void;
|
|
4
|
+
/** Validate and rebuild through the standard kind descriptors. */
|
|
5
|
+
export declare const fromIR: (node: unknown) => import("./types.js").Schema<unknown>;
|
|
6
|
+
export declare const serializeSchema: (schema: import("./types.js").Schema) => import("./walk.js").SchemaEnvelope;
|
|
7
|
+
export declare const deserializeSchema: (envelope: unknown) => import("./types.js").Schema<unknown>;
|
|
72
8
|
//# sourceMappingURL=walk.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../../src/foundation/walk.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../../src/foundation/walk.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAC1G,wEAAwE;AACxE,eAAO,MAAM,UAAU,0HAA6B,CAAA;AACpD,kEAAkE;AAClE,eAAO,MAAM,MAAM,yDAAyB,CAAA;AAC5C,eAAO,MAAM,eAAe,6EAAkC,CAAA;AAC9D,eAAO,MAAM,iBAAiB,6DAAoC,CAAA"}
|
package/dist/foundation/walk.js
CHANGED
|
@@ -1,265 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* - `fromIR(node)` : reconstruct a `Schema` builder from IR
|
|
10
|
-
*
|
|
11
|
-
* Combined with the already-public `SchemaNode`, `Modifiers`, `Axes`,
|
|
12
|
-
* `mock`, `parse`, `mockDataset`, `createTrace`, and `seedFromString` /
|
|
13
|
-
* `rngFromString`, this is the full extension contract.
|
|
14
|
-
*
|
|
15
|
-
* Extension authors do NOT subclass `Schema`. They build IR (or compose
|
|
16
|
-
* existing builders) and call `fromIR` to obtain a typed builder back.
|
|
17
|
-
*/
|
|
18
|
-
import { arr, enum_, literal, obj, tuple, union, } from '../schema/composites.js';
|
|
19
|
-
import { discriminated } from '../schema/conditional.js';
|
|
20
|
-
import { decimal } from '../schema/decimal.js';
|
|
21
|
-
import { bool, int, null_, num, str } from '../schema/primitives.js';
|
|
22
|
-
import { SchemaConflictError } from './errors.js';
|
|
23
|
-
import { Schema } from './types.js';
|
|
24
|
-
/**
|
|
25
|
-
* Depth-first pre/post-order traversal of a schema IR tree.
|
|
26
|
-
*
|
|
27
|
-
* The visitor receives every node (including composites) with its
|
|
28
|
-
* JSON-pointer-style path. Use this to power codegen (OpenAPI, zod, SQL DDL,
|
|
29
|
-
* documentation) without coupling to the builder classes.
|
|
30
|
-
*/
|
|
31
|
-
export const walkSchema = (schemaOrNode, visitor) => {
|
|
32
|
-
const root = schemaOrNode instanceof Schema ? schemaOrNode._node : schemaOrNode;
|
|
33
|
-
walk(root, [], visitor);
|
|
34
|
-
};
|
|
35
|
-
const walk = (node, path, v) => {
|
|
36
|
-
const shouldDescend = v.enter ? v.enter(node, path) !== false : true;
|
|
37
|
-
if (shouldDescend) {
|
|
38
|
-
switch (node.kind) {
|
|
39
|
-
case 'object':
|
|
40
|
-
for (const k of Object.keys(node.fields)) {
|
|
41
|
-
walk(node.fields[k], [...path, k], v);
|
|
42
|
-
}
|
|
43
|
-
break;
|
|
44
|
-
case 'array':
|
|
45
|
-
walk(node.item, [...path, '[]'], v);
|
|
46
|
-
break;
|
|
47
|
-
case 'tuple':
|
|
48
|
-
node.items.forEach((it, i) => walk(it, [...path, i], v));
|
|
49
|
-
break;
|
|
50
|
-
case 'union':
|
|
51
|
-
node.options.forEach((o, i) => walk(o, [...path, `|${i}`], v));
|
|
52
|
-
break;
|
|
53
|
-
case 'discriminated': {
|
|
54
|
-
// Positional `|i` tags mirror `union` so codegen tools can treat
|
|
55
|
-
// both as ordered alternatives.
|
|
56
|
-
const tags = Object.keys(node.branches);
|
|
57
|
-
tags.forEach((tag, i) => walk(node.branches[tag], [...path, `|${i}`], v));
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
default:
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
v.leave?.(node, path);
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Reconstruct a `Schema` builder from an IR node.
|
|
68
|
-
*
|
|
69
|
-
* Modifiers (`nullable`, `optional`, `default`, `describe`, axes) are
|
|
70
|
-
* preserved. Returns `Schema<unknown>` — extension authors that know the shape
|
|
71
|
-
* statically can cast to a more precise type.
|
|
72
|
-
*/
|
|
73
|
-
export const fromIR = (node) => {
|
|
74
|
-
const base = buildBase(node);
|
|
75
|
-
return applyMods(base, node);
|
|
76
|
-
};
|
|
77
|
-
const buildBase = (node) => {
|
|
78
|
-
switch (node.kind) {
|
|
79
|
-
case 'string': {
|
|
80
|
-
let s = str();
|
|
81
|
-
if (node.min !== undefined)
|
|
82
|
-
s = s.min(node.min);
|
|
83
|
-
if (node.max !== undefined)
|
|
84
|
-
s = s.max(node.max);
|
|
85
|
-
if (node.pattern !== undefined)
|
|
86
|
-
s = s.pattern(node.pattern);
|
|
87
|
-
return s;
|
|
88
|
-
}
|
|
89
|
-
case 'number': {
|
|
90
|
-
let n = node.int ? int() : num();
|
|
91
|
-
if (node.min !== undefined)
|
|
92
|
-
n = n.min(node.min);
|
|
93
|
-
if (node.max !== undefined)
|
|
94
|
-
n = n.max(node.max);
|
|
95
|
-
return n;
|
|
96
|
-
}
|
|
97
|
-
case 'decimal': {
|
|
98
|
-
let d = decimal(node.precision, node.scale);
|
|
99
|
-
if (node.min !== undefined)
|
|
100
|
-
d = d.min(node.min);
|
|
101
|
-
if (node.max !== undefined)
|
|
102
|
-
d = d.max(node.max);
|
|
103
|
-
return d;
|
|
104
|
-
}
|
|
105
|
-
case 'boolean':
|
|
106
|
-
return bool();
|
|
107
|
-
case 'null':
|
|
108
|
-
return null_();
|
|
109
|
-
case 'literal':
|
|
110
|
-
return literal(node.value);
|
|
111
|
-
case 'enum':
|
|
112
|
-
return enum_(node.values);
|
|
113
|
-
case 'object': {
|
|
114
|
-
const fields = {};
|
|
115
|
-
for (const k of Object.keys(node.fields)) {
|
|
116
|
-
fields[k] = fromIR(node.fields[k]);
|
|
117
|
-
}
|
|
118
|
-
return obj(fields);
|
|
119
|
-
}
|
|
120
|
-
case 'array': {
|
|
121
|
-
let a = arr(fromIR(node.item));
|
|
122
|
-
if (node.length !== undefined)
|
|
123
|
-
a = a.length(node.length);
|
|
124
|
-
else {
|
|
125
|
-
if (node.minLength !== undefined)
|
|
126
|
-
a = a.min(node.minLength);
|
|
127
|
-
if (node.maxLength !== undefined)
|
|
128
|
-
a = a.max(node.maxLength);
|
|
129
|
-
}
|
|
130
|
-
return a;
|
|
131
|
-
}
|
|
132
|
-
case 'tuple': {
|
|
133
|
-
const items = node.items.map((it) => fromIR(it));
|
|
134
|
-
return tuple(...items);
|
|
135
|
-
}
|
|
136
|
-
case 'union': {
|
|
137
|
-
const opts = node.options.map((o) => fromIR(o));
|
|
138
|
-
return union(...opts);
|
|
139
|
-
}
|
|
140
|
-
case 'discriminated': {
|
|
141
|
-
// Reconstruct the branches as object schemas and feed them back to the
|
|
142
|
-
// builder. Round-tripping preserves the discriminator key.
|
|
143
|
-
const branchSchemas = {};
|
|
144
|
-
for (const tag of Object.keys(node.branches)) {
|
|
145
|
-
branchSchemas[tag] = fromIR(node.branches[tag]);
|
|
146
|
-
}
|
|
147
|
-
return discriminated(node.key, branchSchemas);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
const applyMods = (schema, node) => {
|
|
152
|
-
const mods = node.mods;
|
|
153
|
-
if (mods === undefined)
|
|
154
|
-
return schema;
|
|
155
|
-
let out = schema;
|
|
156
|
-
if (mods.nullable === true)
|
|
157
|
-
out = out.nullable();
|
|
158
|
-
if (mods.optional === true)
|
|
159
|
-
out = out.optional();
|
|
160
|
-
if (mods.hasDefault === true)
|
|
161
|
-
out = out.default(mods.defaultValue);
|
|
162
|
-
if (mods.description !== undefined)
|
|
163
|
-
out = out.describe(mods.description);
|
|
164
|
-
if (mods.axes !== undefined) {
|
|
165
|
-
// Use the public axes-replay helper instead of reaching through a
|
|
166
|
-
// protected method via a cast.
|
|
167
|
-
out = out._applyAxes(mods.axes);
|
|
168
|
-
}
|
|
169
|
-
return out;
|
|
170
|
-
};
|
|
171
|
-
// ── IR versioning ──────────────────────────────────────────────────────
|
|
172
|
-
//
|
|
173
|
-
// The wire envelope ships a `$databehaveVersion` so a node serialised
|
|
174
|
-
// by one MAJOR cannot silently load into an incompatible one. Bare
|
|
175
|
-
// `SchemaNode`s remain accepted by `fromIR` for backward compatibility
|
|
176
|
-
// with in-process extension authors; cross-process / on-disk callers
|
|
177
|
-
// should round-trip through `serializeSchema` / `deserializeSchema`.
|
|
178
|
-
/** Current IR contract version. Bumped on every MAJOR release. */
|
|
179
|
-
export const IR_VERSION = 1;
|
|
180
|
-
/**
|
|
181
|
-
* Wrap a schema's IR in a versioned envelope safe for serialisation
|
|
182
|
-
* (JSON, disk, IPC). Pair with {@link deserializeSchema} on the
|
|
183
|
-
* receiving end.
|
|
184
|
-
*
|
|
185
|
-
* Throws {@link SchemaConflictError} (`code: 'serialize.closure-axis'`)
|
|
186
|
-
* when any node in the tree carries a closure-bearing axis — `derived`,
|
|
187
|
-
* `invariants`, or an `occasionally` override whose `value` is a
|
|
188
|
-
* function. Closures cannot survive a JSON round-trip, so encoding such
|
|
189
|
-
* a schema would silently drop the axis on the receiving end and
|
|
190
|
-
* produce subtly wrong values. The check is loud at the encode site so
|
|
191
|
-
* callers reach for {@link replay} or hand-coded carriers instead.
|
|
192
|
-
*/
|
|
193
|
-
export const serializeSchema = (schema) => {
|
|
194
|
-
assertNoClosureAxes(schema._node, []);
|
|
195
|
-
return {
|
|
196
|
-
$databehaveVersion: IR_VERSION,
|
|
197
|
-
node: schema._node,
|
|
198
|
-
};
|
|
199
|
-
};
|
|
200
|
-
const assertNoClosureAxes = (node, path) => {
|
|
201
|
-
const axes = node.mods?.axes;
|
|
202
|
-
if (axes !== undefined) {
|
|
203
|
-
if (typeof axes.derived === 'function') {
|
|
204
|
-
throw new SchemaConflictError(`serializeSchema: axis 'derived' carries a closure that cannot be JSON-serialised`, [...path, 'axes', 'derived'], 'closures cannot survive JSON round-trip — keep derivedFrom() at the call site', 'serialize.closure-axis');
|
|
205
|
-
}
|
|
206
|
-
if (axes.invariants !== undefined && axes.invariants.length > 0) {
|
|
207
|
-
const idx = axes.invariants.findIndex((fn) => typeof fn === 'function');
|
|
208
|
-
if (idx >= 0) {
|
|
209
|
-
throw new SchemaConflictError(`serializeSchema: axis 'invariants[${idx}]' carries a closure that cannot be JSON-serialised`, [...path, 'axes', 'invariants', idx], 'closures cannot survive JSON round-trip — keep invariant() at the call site', 'serialize.closure-axis');
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
if (axes.occasionally !== undefined) {
|
|
213
|
-
const idx = axes.occasionally.findIndex((o) => typeof o.value === 'function');
|
|
214
|
-
if (idx >= 0) {
|
|
215
|
-
throw new SchemaConflictError(`serializeSchema: axis 'occasionally[${idx}].value' carries a closure that cannot be JSON-serialised`, [...path, 'axes', 'occasionally', idx, 'value'], 'closures cannot survive JSON round-trip — keep occasionally() at the call site', 'serialize.closure-axis');
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
switch (node.kind) {
|
|
220
|
-
case 'object':
|
|
221
|
-
for (const k of Object.keys(node.fields)) {
|
|
222
|
-
assertNoClosureAxes(node.fields[k], [...path, k]);
|
|
223
|
-
}
|
|
224
|
-
return;
|
|
225
|
-
case 'array':
|
|
226
|
-
assertNoClosureAxes(node.item, [...path, '[]']);
|
|
227
|
-
return;
|
|
228
|
-
case 'tuple':
|
|
229
|
-
node.items.forEach((it, i) => assertNoClosureAxes(it, [...path, i]));
|
|
230
|
-
return;
|
|
231
|
-
case 'union':
|
|
232
|
-
node.options.forEach((o, i) => assertNoClosureAxes(o, [...path, `|${i}`]));
|
|
233
|
-
return;
|
|
234
|
-
case 'discriminated': {
|
|
235
|
-
const tags = Object.keys(node.branches);
|
|
236
|
-
tags.forEach((tag, i) => assertNoClosureAxes(node.branches[tag], [...path, `|${i}`]));
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
default:
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
/**
|
|
244
|
-
* Inverse of {@link serializeSchema}. Throws when the envelope was
|
|
245
|
-
* produced by an incompatible MAJOR version — the failure is loud
|
|
246
|
-
* because silently loading a node with a renamed or removed field
|
|
247
|
-
* would manifest as a subtle generation/parse bug far from the cause.
|
|
248
|
-
*/
|
|
249
|
-
export const deserializeSchema = (envelope) => {
|
|
250
|
-
if (typeof envelope !== 'object' || envelope === null) {
|
|
251
|
-
throw new TypeError(`databehave/deserializeSchema: expected an envelope object, got ${typeof envelope}`);
|
|
252
|
-
}
|
|
253
|
-
const v = envelope.$databehaveVersion;
|
|
254
|
-
if (v !== IR_VERSION) {
|
|
255
|
-
throw new Error(`databehave/deserializeSchema: incompatible IR version ` +
|
|
256
|
-
`(envelope=${JSON.stringify(v)}, this build=${IR_VERSION}). ` +
|
|
257
|
-
`Re-serialise with the matching databehave MAJOR.`);
|
|
258
|
-
}
|
|
259
|
-
const node = envelope.node;
|
|
260
|
-
if (typeof node !== 'object' || node === null) {
|
|
261
|
-
throw new TypeError('databehave/deserializeSchema: envelope.node must be an IR object');
|
|
262
|
-
}
|
|
263
|
-
return fromIR(node);
|
|
264
|
-
};
|
|
1
|
+
import { standardRuntime } from '../standard/runtime.js';
|
|
2
|
+
export { IR_VERSION } from '../runtime/runtime.js';
|
|
3
|
+
/** Standard preset traversal. Custom schemas use runtime.walkSchema. */
|
|
4
|
+
export const walkSchema = standardRuntime.walkSchema;
|
|
5
|
+
/** Validate and rebuild through the standard kind descriptors. */
|
|
6
|
+
export const fromIR = standardRuntime.fromIR;
|
|
7
|
+
export const serializeSchema = standardRuntime.serializeSchema;
|
|
8
|
+
export const deserializeSchema = standardRuntime.deserializeSchema;
|
|
265
9
|
//# sourceMappingURL=walk.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walk.js","sourceRoot":"","sources":["../../src/foundation/walk.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"walk.js","sourceRoot":"","sources":["../../src/foundation/walk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,UAAU,EAA0D,MAAM,uBAAuB,CAAA;AAC1G,wEAAwE;AACxE,MAAM,CAAC,MAAM,UAAU,GAAG,eAAe,CAAC,UAAU,CAAA;AACpD,kEAAkE;AAClE,MAAM,CAAC,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,CAAA;AAC5C,MAAM,CAAC,MAAM,eAAe,GAAG,eAAe,CAAC,eAAe,CAAA;AAC9D,MAAM,CAAC,MAAM,iBAAiB,GAAG,eAAe,CAAC,iBAAiB,CAAA"}
|
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generator engine — turns a SchemaNode + context into a deterministic value.
|
|
3
|
-
*
|
|
4
|
-
* Wires the data-schema axes into the sampling pipeline.
|
|
5
|
-
* Resolution priority during sampling:
|
|
6
|
-
*
|
|
7
|
-
* 1. invariants (rejection-sample until they hold; bounded by MAX_ATTEMPTS)
|
|
8
|
-
* 2. identity (handled at dataset layer; not seen here)
|
|
9
|
-
* 3. derived (computed from sibling/root context — skip sampling entirely)
|
|
10
|
-
* 4. conditional (union / discriminated branch selection)
|
|
11
|
-
* 5. domain (closed candidate set)
|
|
12
|
-
* 6. distribution (weighted / normal / typical)
|
|
13
|
-
* 7. type (fall-back bounds from the IR)
|
|
14
|
-
*/
|
|
15
1
|
import type { GenContext } from '../foundation/axes.js';
|
|
16
|
-
import type {
|
|
17
|
-
import {
|
|
18
|
-
import type { Infer, Schema } from '../foundation/types.js';
|
|
2
|
+
import type { Rng } from '../foundation/prng.js';
|
|
3
|
+
import type { Schema, Infer } from '../foundation/types.js';
|
|
19
4
|
import type { TraceCollector } from './trace.js';
|
|
20
5
|
/**
|
|
21
6
|
* Per-leaf stable-seed hook.
|
|
@@ -68,7 +53,7 @@ export type MockOptions = {
|
|
|
68
53
|
/**
|
|
69
54
|
* Override the PRNG factory used when `seed` is a number.
|
|
70
55
|
*
|
|
71
|
-
* Defaults to
|
|
56
|
+
* Defaults to `mulberry32`. When `seed` is a string the seed is
|
|
72
57
|
* first hashed (`seedFromString`) and then handed to this factory.
|
|
73
58
|
*
|
|
74
59
|
* Useful for tests that need to inject a constant or recorded RNG to
|
|
@@ -79,22 +64,6 @@ export type MockOptions = {
|
|
|
79
64
|
*/
|
|
80
65
|
readonly prng?: (seed: number) => Rng;
|
|
81
66
|
};
|
|
82
|
-
/**
|
|
83
|
-
* Generate a value that conforms to the given schema.
|
|
84
|
-
*
|
|
85
|
-
* Deterministic: identical `schema` + `options.seed` always yields the same
|
|
86
|
-
* value, on every machine, every run.
|
|
87
|
-
*/
|
|
67
|
+
/** Generate using the explicit standard preset. Custom schemas use their composed runtime. */
|
|
88
68
|
export declare const mock: <S extends Schema>(schema: S, options?: MockOptions) => Infer<S>;
|
|
89
|
-
export type GenState = {
|
|
90
|
-
rng: Rng;
|
|
91
|
-
rootSeed: string;
|
|
92
|
-
root: unknown;
|
|
93
|
-
modifierProbs: Required<ModifierProbs>;
|
|
94
|
-
input?: Readonly<Record<string, unknown>>;
|
|
95
|
-
rootIndex?: number;
|
|
96
|
-
trace?: TraceCollector;
|
|
97
|
-
stableBy?: StableByFn;
|
|
98
|
-
};
|
|
99
|
-
export declare const generateNode: (node: SchemaNode, path: readonly (string | number)[], parent: Readonly<Record<string, unknown>>, state: GenState) => unknown;
|
|
100
69
|
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/generator/engine.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sour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