@databehave/schema 0.1.3 → 0.2.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.
Files changed (123) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +12 -1
  3. package/dist/dataset/dataset.d.ts +6 -0
  4. package/dist/dataset/dataset.d.ts.map +1 -0
  5. package/dist/dataset/dataset.js +6 -0
  6. package/dist/dataset/dataset.js.map +1 -0
  7. package/dist/dataset/generate.d.ts +49 -0
  8. package/dist/dataset/generate.d.ts.map +1 -0
  9. package/dist/dataset/generate.js +96 -0
  10. package/dist/dataset/generate.js.map +1 -0
  11. package/dist/dataset/relate.d.ts +32 -0
  12. package/dist/dataset/relate.d.ts.map +1 -0
  13. package/dist/dataset/relate.js +46 -0
  14. package/dist/dataset/relate.js.map +1 -0
  15. package/dist/foundation/axes.d.ts +96 -0
  16. package/dist/foundation/axes.d.ts.map +1 -0
  17. package/dist/foundation/axes.js +16 -0
  18. package/dist/foundation/axes.js.map +1 -0
  19. package/dist/foundation/errors.d.ts +101 -0
  20. package/dist/foundation/errors.d.ts.map +1 -0
  21. package/dist/foundation/errors.js +91 -0
  22. package/dist/foundation/errors.js.map +1 -0
  23. package/dist/foundation/hash.d.ts +12 -0
  24. package/dist/foundation/hash.d.ts.map +1 -0
  25. package/dist/foundation/hash.js +21 -0
  26. package/dist/foundation/hash.js.map +1 -0
  27. package/dist/foundation/ir.d.ts +99 -0
  28. package/dist/foundation/ir.d.ts.map +1 -0
  29. package/dist/foundation/ir.js +16 -0
  30. package/dist/foundation/ir.js.map +1 -0
  31. package/dist/foundation/prng.d.ts +27 -0
  32. package/dist/foundation/prng.d.ts.map +1 -0
  33. package/dist/foundation/prng.js +56 -0
  34. package/dist/foundation/prng.js.map +1 -0
  35. package/dist/foundation/types.d.ts +116 -0
  36. package/dist/foundation/types.d.ts.map +1 -0
  37. package/dist/foundation/types.js +155 -0
  38. package/dist/foundation/types.js.map +1 -0
  39. package/dist/foundation/walk.d.ts +8 -0
  40. package/dist/foundation/walk.d.ts.map +1 -0
  41. package/dist/foundation/walk.js +9 -0
  42. package/dist/foundation/walk.js.map +1 -0
  43. package/dist/generator/engine.d.ts +69 -0
  44. package/dist/generator/engine.d.ts.map +1 -0
  45. package/dist/generator/engine.js +4 -0
  46. package/dist/generator/engine.js.map +1 -0
  47. package/dist/generator/replay.d.ts +38 -0
  48. package/dist/generator/replay.d.ts.map +1 -0
  49. package/dist/generator/replay.js +44 -0
  50. package/dist/generator/replay.js.map +1 -0
  51. package/dist/generator/trace.d.ts +54 -0
  52. package/dist/generator/trace.d.ts.map +1 -0
  53. package/dist/generator/trace.js +38 -0
  54. package/dist/generator/trace.js.map +1 -0
  55. package/dist/index.d.ts +37 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +40 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/internal.d.ts +22 -0
  60. package/dist/internal.d.ts.map +1 -0
  61. package/dist/internal.js +25 -0
  62. package/dist/internal.js.map +1 -0
  63. package/dist/plugin.d.ts +7 -0
  64. package/dist/plugin.d.ts.map +1 -0
  65. package/dist/plugin.js +14 -0
  66. package/dist/plugin.js.map +1 -0
  67. package/dist/runtime/contracts.d.ts +101 -0
  68. package/dist/runtime/contracts.d.ts.map +1 -0
  69. package/dist/runtime/contracts.js +67 -0
  70. package/dist/runtime/contracts.js.map +1 -0
  71. package/dist/runtime/runtime.d.ts +56 -0
  72. package/dist/runtime/runtime.d.ts.map +1 -0
  73. package/dist/runtime/runtime.js +392 -0
  74. package/dist/runtime/runtime.js.map +1 -0
  75. package/dist/runtime.d.ts +7 -0
  76. package/dist/runtime.d.ts.map +1 -0
  77. package/dist/runtime.js +5 -0
  78. package/dist/runtime.js.map +1 -0
  79. package/dist/schema/composites.d.ts +104 -0
  80. package/dist/schema/composites.d.ts.map +1 -0
  81. package/dist/schema/composites.js +134 -0
  82. package/dist/schema/composites.js.map +1 -0
  83. package/dist/schema/conditional.d.ts +28 -0
  84. package/dist/schema/conditional.d.ts.map +1 -0
  85. package/dist/schema/conditional.js +52 -0
  86. package/dist/schema/conditional.js.map +1 -0
  87. package/dist/schema/decimal.d.ts +33 -0
  88. package/dist/schema/decimal.d.ts.map +1 -0
  89. package/dist/schema/decimal.js +39 -0
  90. package/dist/schema/decimal.js.map +1 -0
  91. package/dist/schema/primitives.d.ts +47 -0
  92. package/dist/schema/primitives.d.ts.map +1 -0
  93. package/dist/schema/primitives.js +78 -0
  94. package/dist/schema/primitives.js.map +1 -0
  95. package/dist/standard/behaviors.d.ts +6 -0
  96. package/dist/standard/behaviors.d.ts.map +1 -0
  97. package/dist/standard/behaviors.js +358 -0
  98. package/dist/standard/behaviors.js.map +1 -0
  99. package/dist/standard/generation.d.ts +53 -0
  100. package/dist/standard/generation.d.ts.map +1 -0
  101. package/dist/standard/generation.js +359 -0
  102. package/dist/standard/generation.js.map +1 -0
  103. package/dist/standard/kinds.d.ts +6 -0
  104. package/dist/standard/kinds.d.ts.map +1 -0
  105. package/dist/standard/kinds.js +178 -0
  106. package/dist/standard/kinds.js.map +1 -0
  107. package/dist/standard/runtime.d.ts +3 -0
  108. package/dist/standard/runtime.d.ts.map +1 -0
  109. package/dist/standard/runtime.js +9 -0
  110. package/dist/standard/runtime.js.map +1 -0
  111. package/dist/standard/validation.d.ts +44 -0
  112. package/dist/standard/validation.d.ts.map +1 -0
  113. package/dist/standard/validation.js +353 -0
  114. package/dist/standard/validation.js.map +1 -0
  115. package/dist/standard.d.ts +5 -0
  116. package/dist/standard.d.ts.map +1 -0
  117. package/dist/standard.js +5 -0
  118. package/dist/standard.js.map +1 -0
  119. package/dist/validator/parse.d.ts +13 -0
  120. package/dist/validator/parse.d.ts.map +1 -0
  121. package/dist/validator/parse.js +4 -0
  122. package/dist/validator/parse.js.map +1 -0
  123. package/package.json +26 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/foundation/errors.ts"],"names":[],"mappings":"AA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ED,MAAM,WAAW,GAAG,CAAC,CAAQ,EAAU,EAAE;IACvC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACjF,MAAM,QAAQ,GAAG,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAC1E,MAAM,QAAQ,GACZ,UAAU,IAAI,CAAC;QACb,CAAC,CAAC,aAAa,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE;QAC1C,CAAC,CAAC,EAAE,CAAA;IACR,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,GAAG,QAAQ,GAAG,QAAQ,EAAE,CAAA;AACnD,CAAC,CAAA;AAED,MAAM,aAAa,GAAG,CAAC,CAAU,EAAU,EAAE;IAC3C,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,CAAC,CAAC,CAAA;IAClB,CAAC;AACH,CAAC,CAAA"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Stable identity hash for seed derivation.
3
+ */
4
+ /**
5
+ * Build a deterministic identity string from sorted query/path/identity values.
6
+ *
7
+ * Example:
8
+ * identityKey('GET', '/items', { group_code: 'A', date: '2026-05-22' })
9
+ * → 'GET|/items|date=2026-05-22&group_code=A'
10
+ */
11
+ export declare const identityKey: (method: string, path: string, parts: Record<string, string | number | boolean | null | undefined>) => string;
12
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/foundation/hash.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,MAAM,EACd,MAAM,MAAM,EACZ,OAAO,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,KAClE,MASF,CAAA"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Stable identity hash for seed derivation.
3
+ */
4
+ /**
5
+ * Build a deterministic identity string from sorted query/path/identity values.
6
+ *
7
+ * Example:
8
+ * identityKey('GET', '/items', { group_code: 'A', date: '2026-05-22' })
9
+ * → 'GET|/items|date=2026-05-22&group_code=A'
10
+ */
11
+ export const identityKey = (method, path, parts) => {
12
+ const flat = Object.keys(parts)
13
+ .sort()
14
+ .map((k) => {
15
+ const v = parts[k];
16
+ return `${k}=${v === undefined || v === null ? '' : String(v)}`;
17
+ })
18
+ .join('&');
19
+ return `${method}|${path}|${flat}`;
20
+ };
21
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/foundation/hash.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,MAAc,EACd,IAAY,EACZ,KAAmE,EAC3D,EAAE;IACV,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;SAC5B,IAAI,EAAE;SACN,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QAClB,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAA;IACjE,CAAC,CAAC;SACD,IAAI,CAAC,GAAG,CAAC,CAAA;IACZ,OAAO,GAAG,MAAM,IAAI,IAAI,IAAI,IAAI,EAAE,CAAA;AACpC,CAAC,CAAA"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Internal Representation (IR) of a databehave schema.
3
+ *
4
+ * Every schema builder compiles to one of these serializable nodes.
5
+ * The generator and validator operate on IR — never on builder classes —
6
+ * so IR can be inspected, logged, transformed, or transported.
7
+ */
8
+ export type StringFormat = 'plain' | 'uuid' | 'email' | 'url' | 'ipv4' | 'ipv6' | 'date' | 'datetime' | 'time';
9
+ export type NumberKind = {
10
+ readonly kind: 'number';
11
+ readonly int: boolean;
12
+ readonly bits?: 8 | 16 | 32 | 64;
13
+ readonly unsigned?: boolean;
14
+ readonly min?: number;
15
+ readonly max?: number;
16
+ };
17
+ export type StringKind = {
18
+ readonly kind: 'string';
19
+ readonly format: StringFormat;
20
+ readonly min?: number;
21
+ readonly max?: number;
22
+ readonly pattern?: string;
23
+ };
24
+ export type DecimalKind = {
25
+ readonly kind: 'decimal';
26
+ readonly precision: number;
27
+ readonly scale: number;
28
+ readonly min?: string;
29
+ readonly max?: string;
30
+ };
31
+ export type BooleanKind = {
32
+ readonly kind: 'boolean';
33
+ };
34
+ export type NullKind = {
35
+ readonly kind: 'null';
36
+ };
37
+ export type LiteralKind = {
38
+ readonly kind: 'literal';
39
+ readonly value: string | number | boolean | null;
40
+ };
41
+ export type EnumKind = {
42
+ readonly kind: 'enum';
43
+ readonly values: readonly (string | number)[];
44
+ };
45
+ export type ArrayKind = {
46
+ readonly kind: 'array';
47
+ readonly item: SchemaNode;
48
+ readonly length?: number;
49
+ readonly minLength?: number;
50
+ readonly maxLength?: number;
51
+ };
52
+ export type ObjectKind = {
53
+ readonly kind: 'object';
54
+ readonly fields: Readonly<Record<string, SchemaNode>>;
55
+ };
56
+ export type TupleKind = {
57
+ readonly kind: 'tuple';
58
+ readonly items: readonly SchemaNode[];
59
+ };
60
+ export type UnionKind = {
61
+ readonly kind: 'union';
62
+ readonly options: readonly SchemaNode[];
63
+ };
64
+ /**
65
+ * A discriminated union — selects exactly one branch by the value of `key`.
66
+ *
67
+ * Each entry in `branches` must be an object-kind schema whose `key` field is
68
+ * a `literal(...)` matching the map key. Generator and validator both use
69
+ * the discriminator for O(1) branch selection.
70
+ */
71
+ export type DiscriminatedKind = {
72
+ readonly kind: 'discriminated';
73
+ readonly key: string;
74
+ readonly branches: Readonly<Record<string, SchemaNode>>;
75
+ };
76
+ import type { Axes } from './axes.js';
77
+ export type Modifiers = {
78
+ readonly nullable?: boolean;
79
+ readonly optional?: boolean;
80
+ readonly hasDefault?: boolean;
81
+ readonly defaultValue?: unknown;
82
+ readonly description?: string;
83
+ readonly axes?: Axes;
84
+ readonly behaviors?: Readonly<Record<string, unknown>>;
85
+ };
86
+ export type SchemaCore = NumberKind | StringKind | DecimalKind | BooleanKind | NullKind | LiteralKind | EnumKind | ArrayKind | ObjectKind | TupleKind | UnionKind | DiscriminatedKind;
87
+ /** Standard node union used within the standard descriptors. */
88
+ export type StandardSchemaNode = SchemaCore & {
89
+ readonly mods?: Modifiers;
90
+ };
91
+ /** Open node carrier; each registered kind validates its own metadata. */
92
+ export interface SchemaNode {
93
+ readonly kind: string;
94
+ readonly mods?: Modifiers;
95
+ readonly [metadata: string]: unknown;
96
+ }
97
+ /** Helper: produce a fresh node with merged modifiers. `axes` are deep-merged. */
98
+ export declare const withMods: (node: SchemaNode, patch: Partial<Modifiers>) => SchemaNode;
99
+ //# sourceMappingURL=ir.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ir.d.ts","sourceRoot":"","sources":["../../src/foundation/ir.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,YAAY,GACpB,OAAO,GACP,MAAM,GACN,OAAO,GACP,KAAK,GACL,MAAM,GACN,MAAM,GACN,MAAM,GACN,UAAU,GACV,MAAM,CAAA;AAEV,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,EAAE,Q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AAA;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;IAC7B,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAA;IAC/B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAA;IACpB,QAAQ,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;CACvD,CAAA;AAED,MAAM,MAAM,UAAU,GAClB,UAAU,GACV,UAAU,GACV,WAAW,GACX,WAAW,GACX,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,SAAS,GACT,UAAU,GACV,SAAS,GACT,SAAS,GACT,iBAAiB,CAAA;AAErB,gEAAgE;AAChE,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG;IAC5C,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAA;CAC1B,CAAA;AAED,0EAA0E;AAC1E,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAA;IACzB,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;CACrC;AAED,kFAAkF;AAClF,eAAO,MAAM,QAAQ,GAAI,MAAM,UAAU,EAAE,OAAO,OAAO,CAAC,SAAS,CAAC,KAAG,UAKtE,CAAA"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Internal Representation (IR) of a databehave schema.
3
+ *
4
+ * Every schema builder compiles to one of these serializable nodes.
5
+ * The generator and validator operate on IR — never on builder classes —
6
+ * so IR can be inspected, logged, transformed, or transported.
7
+ */
8
+ import { mergeAxes } from './axes.js';
9
+ /** Helper: produce a fresh node with merged modifiers. `axes` are deep-merged. */
10
+ export const withMods = (node, patch) => {
11
+ const prev = node.mods ?? {};
12
+ const mergedAxes = patch.axes !== undefined ? mergeAxes(prev.axes, patch.axes) : prev.axes;
13
+ const next = mergedAxes !== undefined ? { ...prev, ...patch, axes: mergedAxes } : { ...prev, ...patch };
14
+ return { ...node, mods: next };
15
+ };
16
+ //# sourceMappingURL=ir.js.map
@@ -0,0 +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;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"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * mulberry32 — tiny, fast, deterministic 32-bit PRNG.
3
+ *
4
+ * Zero-dependency. Identical seed → identical sequence on every machine.
5
+ * Period ≈ 2^32, ample for mock generation.
6
+ *
7
+ * Reference: https://gist.github.com/tommyettinger/46a3a48c0d7fe27ea3aaa5fa8f1ba0e8
8
+ */
9
+ export type Rng = {
10
+ /** Next uniformly-distributed float in `[0, 1)`. */
11
+ next(): number;
12
+ /** Next integer in `[min, max]` (inclusive). */
13
+ int(min: number, max: number): number;
14
+ /** Pick one element of `items` uniformly. */
15
+ pick<T>(items: readonly T[]): T;
16
+ };
17
+ /**
18
+ * Create a deterministic PRNG seeded by a 32-bit unsigned integer.
19
+ *
20
+ * For string seeds, use {@link rngFromString}.
21
+ */
22
+ export declare const mulberry32: (seed: number) => Rng;
23
+ /** Derive a 32-bit unsigned seed from an arbitrary string (FNV-1a 32-bit). */
24
+ export declare const seedFromString: (s: string) => number;
25
+ /** Convenience: build an Rng from a string seed. */
26
+ export declare const rngFromString: (s: string) => Rng;
27
+ //# sourceMappingURL=prng.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prng.d.ts","sourceRoot":"","sources":["../../src/foundation/prng.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,GAAG,GAAG;IAChB,oDAAoD;IACpD,IAAI,IAAI,MAAM,CAAA;IACd,gDAAgD;IAChD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;IACrC,6CAA6C;IAC7C,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,CAAA;CAChC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,KAAG,GA8BzC,CAAA;AAED,8EAA8E;AAC9E,eAAO,MAAM,cAAc,GAAI,GAAG,MAAM,KAAG,MAO1C,CAAA;AAED,oDAAoD;AACpD,eAAO,MAAM,aAAa,GAAI,GAAG,MAAM,KAAG,GAAoC,CAAA"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * mulberry32 — tiny, fast, deterministic 32-bit PRNG.
3
+ *
4
+ * Zero-dependency. Identical seed → identical sequence on every machine.
5
+ * Period ≈ 2^32, ample for mock generation.
6
+ *
7
+ * Reference: https://gist.github.com/tommyettinger/46a3a48c0d7fe27ea3aaa5fa8f1ba0e8
8
+ */
9
+ /**
10
+ * Create a deterministic PRNG seeded by a 32-bit unsigned integer.
11
+ *
12
+ * For string seeds, use {@link rngFromString}.
13
+ */
14
+ export const mulberry32 = (seed) => {
15
+ // Force u32.
16
+ let state = seed >>> 0;
17
+ const next = () => {
18
+ state = (state + 0x6d2b79f5) >>> 0;
19
+ let t = state;
20
+ t = Math.imul(t ^ (t >>> 15), t | 1);
21
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
22
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
23
+ };
24
+ return {
25
+ next,
26
+ int(min, max) {
27
+ if (!Number.isFinite(min) || !Number.isFinite(max)) {
28
+ throw new RangeError(`rng.int requires finite bounds, got [${min}, ${max}]`);
29
+ }
30
+ if (min > max)
31
+ throw new RangeError(`rng.int: min (${min}) > max (${max})`);
32
+ const lo = Math.ceil(min);
33
+ const hi = Math.floor(max);
34
+ return lo + Math.floor(next() * (hi - lo + 1));
35
+ },
36
+ pick(items) {
37
+ if (items.length === 0)
38
+ throw new RangeError('rng.pick: empty array');
39
+ const idx = Math.floor(next() * items.length);
40
+ // Safe: idx ∈ [0, items.length-1]
41
+ return items[idx];
42
+ },
43
+ };
44
+ };
45
+ /** Derive a 32-bit unsigned seed from an arbitrary string (FNV-1a 32-bit). */
46
+ export const seedFromString = (s) => {
47
+ let h = 0x811c9dc5;
48
+ for (let i = 0; i < s.length; i += 1) {
49
+ h ^= s.charCodeAt(i);
50
+ h = Math.imul(h, 0x01000193);
51
+ }
52
+ return h >>> 0;
53
+ };
54
+ /** Convenience: build an Rng from a string seed. */
55
+ export const rngFromString = (s) => mulberry32(seedFromString(s));
56
+ //# sourceMappingURL=prng.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prng.js","sourceRoot":"","sources":["../../src/foundation/prng.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAWH;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAO,EAAE;I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mB;YACzB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,MAAM,IAAI,UAAU,CAAC,uBAAuB,CAAC,CAAA;YACrE,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;YAC7C,kCAAkC;YAClC,OAAO,KAAK,CAAC,GAAG,CAAM,CAAA;QACxB,CAAC;KACF,CAAA;AACH,CAAC,CAAA;AAED,8EAA8E;AAC9E,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAS,EAAU,EAAE;IAClD,IAAI,CAAC,GAAG,UAAU,CAAA;IAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QACpB,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,CAAA;IAC9B,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,CAAA;AAChB,CAAC,CAAA;AAED,oDAAoD;AACpD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAS,EAAO,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA"}
@@ -0,0 +1,116 @@
1
+ /**
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
+ */
11
+ import type { Axes, DerivedFn, Distribution, DomainConstraint, InvariantFn } from './axes.js';
12
+ import type { Modifiers, SchemaNode } from './ir.js';
13
+ /**
14
+ * Module-private capability marker symbol keys.
15
+ *
16
+ * Schemas opt into a capability by `declare`ing the corresponding bracketed
17
+ * property as the literal `true`. Methods like `.weighted` / `.normal` /
18
+ * `.typically` then gate themselves with a `this:` constraint that requires
19
+ * the marker. Symbols (rather than string keys like `_capDiscrete`) keep the
20
+ * markers out of consumer IntelliSense and out of any `Object.keys` loop.
21
+ *
22
+ * Three caps are required to mirror the runtime allow-list cleanly:
23
+ *
24
+ * - `Discrete` — values are enumerable; `.weighted` is meaningful.
25
+ * Carried by `str / int / bool / literal / enum`.
26
+ * - `Numeric` — values are bounded numerics; `.typically(from, to)` is
27
+ * meaningful (the generator clamps and, for integers,
28
+ * rounds). Carried by `num / int / decimal`.
29
+ * - `Continuous` — values are real-valued; `.normal(mean, σ)` is
30
+ * meaningful (Gaussian on integers would silently lose
31
+ * σ to rounding, so int is excluded). Carried by
32
+ * `num / decimal`.
33
+ *
34
+ * The symbols are real runtime values so subclass files can `import` them
35
+ * to redeclare the marker. They are NOT re-exported from the package root
36
+ * or from `@databehave/schema/internal`; the package's `exports` field
37
+ * limits deep-path imports to those two entries.
38
+ */
39
+ export declare const Discrete: unique symbol;
40
+ export declare const Numeric: unique symbol;
41
+ export declare const Continuous: unique symbol;
42
+ /** Base builder. Subclasses (StringSchema, NumberSchema, …) extend this. */
43
+ export declare class Schema<T = unknown> {
44
+ readonly _type: T;
45
+ readonly _node: SchemaNode;
46
+ readonly [Discrete]: boolean;
47
+ readonly [Numeric]: boolean;
48
+ readonly [Continuous]: boolean;
49
+ constructor(node: SchemaNode);
50
+ nullable(): Schema<T | null>;
51
+ optional(): Schema<T | undefined>;
52
+ default(value: T): Schema<T>;
53
+ describe(text: string): this;
54
+ /** Weighted distribution over discrete values. Weights are relative. */
55
+ weighted(this: this & {
56
+ readonly [Discrete]: true;
57
+ }, weights: ReadonlyArray<readonly [T & (string | number | boolean), number]>): this;
58
+ /** Normal (Gaussian) distribution for numeric schemas. */
59
+ normal(this: this & {
60
+ readonly [Continuous]: true;
61
+ }, mean: number, stddev: number): this;
62
+ /** Typical range — values concentrate uniformly inside [from, to]. */
63
+ typically(this: this & {
64
+ readonly [Numeric]: true;
65
+ }, from: number, to: number): this;
66
+ /** Force `value` with probability `p` (stacks before base distribution). */
67
+ occasionally(value: T, p: number): this;
68
+ /**
69
+ * Force `value` every `every` rows (deterministic, driven by `ctx.index`).
70
+ *
71
+ * Useful for periodic rare events that must hit at a guaranteed cadence
72
+ * (e.g. a recurring reset every N rows). Skipped when `ctx.index` is undefined.
73
+ */
74
+ eventually(every: number, value: T, opts?: {
75
+ readonly offset?: number;
76
+ }): this;
77
+ /**
78
+ * Field is computed from sibling/root context — generator skips sampling.
79
+ *
80
+ * The generic `U extends T` ensures the function's return type is
81
+ * assignable to the schema's value type. Combined with `relate(rows, field)`
82
+ * (which propagates `R[K]` through `DerivedFn<R[K]>`), this catches
83
+ * FK-type mismatches at compile time
84
+ * (e.g. `int().derivedFrom(relate(rowsWithStringSku, 'sku'))`).
85
+ */
86
+ derivedFrom<U extends T>(fn: DerivedFn<U>): this;
87
+ /** Single-record predicate. Generator retries up to MAX_ATTEMPTS to satisfy. */
88
+ invariant(fn: InvariantFn): this;
89
+ /** Restrict to a closed candidate set or a lookup-by-sibling-field map. */
90
+ in(constraint: DomainConstraint | readonly unknown[]): this;
91
+ /**
92
+ * Re-apply a complete `Axes` record to this schema. Public so that
93
+ * IR-reconstruction helpers (e.g. `fromIR`) can replay axes without
94
+ * reaching through a protected method via casts. Prefer the fluent axis
95
+ * builders (`.weighted`, `.in`, `.derivedFrom`, ...) in user code.
96
+ *
97
+ * Note: this is a low-level escape hatch — it does NOT run the
98
+ * capability allow-list that `.weighted` / `.normal` / `.typically`
99
+ * apply. Callers that round-trip IR are trusted to keep the IR coherent.
100
+ */
101
+ _applyAxes(axes: Axes): this;
102
+ protected withAxes(axes: Axes): this;
103
+ protected withModsPreserveType(patch: Partial<Modifiers>): this;
104
+ }
105
+ /**
106
+ * Infer the TypeScript type a schema generates / accepts.
107
+ *
108
+ * ```ts
109
+ * const User = obj({ id: int(), name: str() })
110
+ * type User = Infer<typeof User> // { id: number; name: string }
111
+ * ```
112
+ */
113
+ export type Infer<S> = S extends Schema<infer T> ? T : never;
114
+ /** Re-export modifier shape for advanced consumers. */
115
+ export type { Distribution, DomainConstraint, Modifiers, SchemaNode };
116
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
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,WAAW,CAAA;AAErI,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAGpD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,QAAQ,EAAE,OAAO,MAA0C,CAAA;AACxE,eAAO,MAAM,OAAO,EAAE,OAAO,MAAyC,CAAA;AACtE,eAAO,MAAM,UAAU,EAAE,OAAO,MAA4C,CAAA;AAc5E,4EAA4E;AAC5E,qBAAa,MAAM,CAAC,CAAC,GAAG,OAAO;IAC7B,SAAiB,KAAK,EAAE,CAAC,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;IAmB1B,SAAiB,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IACpC,SAAiB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;IACnC,SAAiB,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;gBAE1B,IAAI,EAAE,UAAU;IAI5B,QAAQ,IAAI,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC;IAI5B,QAAQ,IAAI,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;IAIjC,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;IAI5B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAM5B,wEAAwE;IACxE,QAAQ,CACN,IAAI,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pC,SAAS,CAAC,oBAAoB,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI;CAOhE;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAE5D,uDAAuD;AACvD,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,UAAU,EAAE,CAAA"}
@@ -0,0 +1,155 @@
1
+ import { standardBehaviors } from '../standard/behaviors.js';
2
+ import { SchemaConflictError } from './errors.js';
3
+ import { withMods } from './ir.js';
4
+ /**
5
+ * Module-private capability marker symbol keys.
6
+ *
7
+ * Schemas opt into a capability by `declare`ing the corresponding bracketed
8
+ * property as the literal `true`. Methods like `.weighted` / `.normal` /
9
+ * `.typically` then gate themselves with a `this:` constraint that requires
10
+ * the marker. Symbols (rather than string keys like `_capDiscrete`) keep the
11
+ * markers out of consumer IntelliSense and out of any `Object.keys` loop.
12
+ *
13
+ * Three caps are required to mirror the runtime allow-list cleanly:
14
+ *
15
+ * - `Discrete` — values are enumerable; `.weighted` is meaningful.
16
+ * Carried by `str / int / bool / literal / enum`.
17
+ * - `Numeric` — values are bounded numerics; `.typically(from, to)` is
18
+ * meaningful (the generator clamps and, for integers,
19
+ * rounds). Carried by `num / int / decimal`.
20
+ * - `Continuous` — values are real-valued; `.normal(mean, σ)` is
21
+ * meaningful (Gaussian on integers would silently lose
22
+ * σ to rounding, so int is excluded). Carried by
23
+ * `num / decimal`.
24
+ *
25
+ * The symbols are real runtime values so subclass files can `import` them
26
+ * to redeclare the marker. They are NOT re-exported from the package root
27
+ * or from `@databehave/schema/internal`; the package's `exports` field
28
+ * limits deep-path imports to those two entries.
29
+ */
30
+ export const Discrete = Symbol('databehave.cap.discrete');
31
+ export const Numeric = Symbol('databehave.cap.numeric');
32
+ export const Continuous = Symbol('databehave.cap.continuous');
33
+ /** Standard fluent builders delegate applicability to the standard behavior owner. */
34
+ const checkAxisAllowed = (op, node) => {
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)');
42
+ }
43
+ };
44
+ /** Base builder. Subclasses (StringSchema, NumberSchema, …) extend this. */
45
+ export class Schema {
46
+ _node;
47
+ constructor(node) {
48
+ this._node = node;
49
+ }
50
+ nullable() {
51
+ return new Schema(withMods(this._node, { nullable: true }));
52
+ }
53
+ optional() {
54
+ return new Schema(withMods(this._node, { optional: true }));
55
+ }
56
+ default(value) {
57
+ return new Schema(withMods(this._node, { hasDefault: true, defaultValue: value }));
58
+ }
59
+ describe(text) {
60
+ return this.withModsPreserveType({ description: text });
61
+ }
62
+ // ── data-schema axes ──────────────────────────────────────────────────────
63
+ /** Weighted distribution over discrete values. Weights are relative. */
64
+ weighted(weights) {
65
+ checkAxisAllowed('weighted', this._node);
66
+ return this.withAxes({
67
+ distribution: {
68
+ kind: 'weighted',
69
+ weights: weights,
70
+ },
71
+ });
72
+ }
73
+ /** Normal (Gaussian) distribution for numeric schemas. */
74
+ normal(mean, stddev) {
75
+ checkAxisAllowed('normal', this._node);
76
+ return this.withAxes({ distribution: { kind: 'normal', mean, stddev } });
77
+ }
78
+ /** Typical range — values concentrate uniformly inside [from, to]. */
79
+ typically(from, to) {
80
+ checkAxisAllowed('typically', this._node);
81
+ return this.withAxes({ distribution: { kind: 'typical', from, to } });
82
+ }
83
+ /** Force `value` with probability `p` (stacks before base distribution). */
84
+ occasionally(value, p) {
85
+ if (!(p >= 0 && p <= 1))
86
+ throw new RangeError(`occasionally: p must be in [0,1], got ${p}`);
87
+ const override = { value, p };
88
+ return this.withAxes({ occasionally: [override] });
89
+ }
90
+ /**
91
+ * Force `value` every `every` rows (deterministic, driven by `ctx.index`).
92
+ *
93
+ * Useful for periodic rare events that must hit at a guaranteed cadence
94
+ * (e.g. a recurring reset every N rows). Skipped when `ctx.index` is undefined.
95
+ */
96
+ eventually(every, value, opts) {
97
+ if (!Number.isInteger(every) || every < 1) {
98
+ throw new RangeError(`eventually: every must be a positive integer, got ${every}`);
99
+ }
100
+ const override = {
101
+ value,
102
+ every,
103
+ ...(opts?.offset !== undefined ? { offset: opts.offset } : {}),
104
+ };
105
+ return this.withAxes({ eventually: [override] });
106
+ }
107
+ /**
108
+ * Field is computed from sibling/root context — generator skips sampling.
109
+ *
110
+ * The generic `U extends T` ensures the function's return type is
111
+ * assignable to the schema's value type. Combined with `relate(rows, field)`
112
+ * (which propagates `R[K]` through `DerivedFn<R[K]>`), this catches
113
+ * FK-type mismatches at compile time
114
+ * (e.g. `int().derivedFrom(relate(rowsWithStringSku, 'sku'))`).
115
+ */
116
+ derivedFrom(fn) {
117
+ return this.withAxes({ derived: fn });
118
+ }
119
+ /** Single-record predicate. Generator retries up to MAX_ATTEMPTS to satisfy. */
120
+ invariant(fn) {
121
+ return this.withAxes({ invariants: [fn] });
122
+ }
123
+ /** Restrict to a closed candidate set or a lookup-by-sibling-field map. */
124
+ in(constraint) {
125
+ const dom = Array.isArray(constraint)
126
+ ? { kind: 'values', values: constraint }
127
+ : constraint;
128
+ return this.withAxes({ domain: dom });
129
+ }
130
+ // ── internal helpers ──────────────────────────────────────────────────────
131
+ /**
132
+ * Re-apply a complete `Axes` record to this schema. Public so that
133
+ * IR-reconstruction helpers (e.g. `fromIR`) can replay axes without
134
+ * reaching through a protected method via casts. Prefer the fluent axis
135
+ * builders (`.weighted`, `.in`, `.derivedFrom`, ...) in user code.
136
+ *
137
+ * Note: this is a low-level escape hatch — it does NOT run the
138
+ * capability allow-list that `.weighted` / `.normal` / `.typically`
139
+ * apply. Callers that round-trip IR are trusted to keep the IR coherent.
140
+ */
141
+ _applyAxes(axes) {
142
+ return this.withModsPreserveType({ axes });
143
+ }
144
+ withAxes(axes) {
145
+ return this.withModsPreserveType({ axes });
146
+ }
147
+ withModsPreserveType(patch) {
148
+ const next = Object.create(Object.getPrototypeOf(this));
149
+ Object.assign(next, this, {
150
+ _node: withMods(this._node, patch),
151
+ });
152
+ return next;
153
+ }
154
+ }
155
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
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,CAAA;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAkB,MAAM,CAAC,yBAAyB,CAAC,CAAA;AACxE,MAAM,CAAC,MAAM,OAAO,GAAkB,MAAM,CAAC,wBAAwB,CAAC,CAAA;AACtE,MAAM,CAAC,MAAM,UAAU,GAAkB,MAAM,CAAC,2BAA2B,CAAC,CAAA;AAE5E,sFAAsF;AACtF,MAAM,gBAAgB,GAAG,CAAC,EAAuC,EAAE,IAAgB,EAAQ,EAAE;IAC3F,MAAM,QAAQ,GAAiB,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,EAAE;QAClF,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;YAC1D,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI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AC,CAAA;IAC5C,CAAC;IACS,QAAQ,CAAC,IAAU;QAC3B,OAAO,IAAI,CAAC,oBAAoB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;IAC5C,CAAC;IAES,oBAAoB,CAAC,KAAyB;QACtD,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAW,CAAS,CAAA;QACzE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE;YACxB,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC;SACH,CAAC,CAAA;QAClC,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
@@ -0,0 +1,8 @@
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>;
8
+ //# sourceMappingURL=walk.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,9 @@
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;
9
+ //# sourceMappingURL=walk.js.map
@@ -0,0 +1 @@
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"}