@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,69 @@
1
+ import type { GenContext } from '../foundation/axes.js';
2
+ import type { Rng } from '../foundation/prng.js';
3
+ import type { Schema, Infer } from '../foundation/types.js';
4
+ import type { TraceCollector } from './trace.js';
5
+ /**
6
+ * Per-leaf stable-seed hook.
7
+ *
8
+ * Called for every leaf-value sampling (string/number/decimal/boolean/enum/domain).
9
+ * Return a non-empty string to deterministically reseed *just this leaf*
10
+ * (path-scoped) — useful for snapshot/CI runs where a subset of rows must
11
+ * stay identical regardless of the outer `seed`.
12
+ * Return `null`/`undefined`/`''` to fall back to the shared rng (normal random).
13
+ *
14
+ * Composite kinds (object/array/tuple/union) are unaffected; their children
15
+ * re-enter this hook with their own path.
16
+ */
17
+ export type StableByFn = (ctx: GenContext) => string | null | undefined;
18
+ /**
19
+ * Per-modifier probabilities for random injection during generation.
20
+ *
21
+ * These are opt-in. With the default `{ default: 0, optional: 0, nullable: 0 }`
22
+ * `mock()` always samples a real value for the underlying type and never
23
+ * silently substitutes the modifier short-circuit. Set a non-zero probability
24
+ * to exercise the `undefined` / `null` / default-value paths.
25
+ */
26
+ export type ModifierProbs = {
27
+ /** Probability that `.default(v)` returns `v` instead of sampling. */
28
+ readonly default?: number;
29
+ /** Probability that `.optional()` returns `undefined`. */
30
+ readonly optional?: number;
31
+ /** Probability that `.nullable()` returns `null`. */
32
+ readonly nullable?: number;
33
+ };
34
+ export type MockOptions = {
35
+ /** Override the deterministic seed. Either a string or unsigned 32-bit int. */
36
+ readonly seed?: string | number;
37
+ /** Caller-supplied context channel exposed to derived/invariants as `ctx.input`. */
38
+ readonly input?: Readonly<Record<string, unknown>>;
39
+ /** Top-level row index (used by `mockDataset` so per-row derived can read `ctx.index`). */
40
+ readonly index?: number;
41
+ /** Optional trace collector — receives one entry per resolved field. */
42
+ readonly trace?: TraceCollector;
43
+ /** Reseed leaf sampling deterministically from a caller-chosen key. */
44
+ readonly stableBy?: StableByFn;
45
+ /**
46
+ * Probabilities used for modifier short-circuits during sampling.
47
+ *
48
+ * Defaults are **all zero** — modifiers do not inject randomness unless you
49
+ * explicitly opt in. This makes `mock()` exercise the underlying type by
50
+ * default (e.g. `mock(str().optional())` always returns a string).
51
+ */
52
+ readonly modifierProbs?: ModifierProbs;
53
+ /**
54
+ * Override the PRNG factory used when `seed` is a number.
55
+ *
56
+ * Defaults to `mulberry32`. When `seed` is a string the seed is
57
+ * first hashed (`seedFromString`) and then handed to this factory.
58
+ *
59
+ * Useful for tests that need to inject a constant or recorded RNG to
60
+ * exercise probability-driven branches deterministically. Production
61
+ * callers should leave this unset — `mulberry32` is the seeded default
62
+ * the determinism contract is calibrated against, and swapping it
63
+ * perturbs the output sequence.
64
+ */
65
+ readonly prng?: (seed: number) => Rng;
66
+ };
67
+ /** Generate using the explicit standard preset. Custom schemas use their composed runtime. */
68
+ export declare const mock: <S extends Schema>(schema: S, options?: MockOptions) => Infer<S>;
69
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/generator/engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAGhD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,UAAU,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;AAEvE;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,sEAAsE;IACtE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,0DAA0D;IAC1D,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC1B,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAC3B,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,+EAA+E;IAC/E,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC/B,oFAAoF;IACpF,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IAClD,2FAA2F;IAC3F,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,wEAAwE;IACxE,QAAQ,CAAC,KAAK,CAAC,EAAE,cAAc,CAAA;IAC/B,uEAAuE;IACvE,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAA;IAC9B;;;;;;OAMG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAA;IACtC;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,CAAA;CACtC,CAAA;AAED,8FAA8F;AAC9F,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,EAAE,QAAQ,CAAC,EAAE,UAAS,WAAgB,KAAG,KAAK,CAAC,CAAC,CAA0C,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { standardRuntime } from '../standard/runtime.js';
2
+ /** Generate using the explicit standard preset. Custom schemas use their composed runtime. */
3
+ export const mock = (schema, options = {}) => standardRuntime.mock(schema, options);
4
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/generator/engine.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAmExD,8FAA8F;AAC9F,MAAM,CAAC,MAAM,IAAI,GAAG,CAAmB,MAAS,EAAE,UAAuB,EAAE,EAAY,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Replay / snapshot helpers — thin layer over `mock()` for tests.
3
+ *
4
+ * `replay(schema, opts)` returns a function bound to a fixed (seed, input)
5
+ * pair. Calling it twice always returns deep-equal values; the function is
6
+ * the canonical way to assert determinism in test suites.
7
+ *
8
+ * `expectStable(schema, opts)` runs the generator twice and throws if the
9
+ * outputs differ — surfaces non-determinism introduced by misuse of
10
+ * `derivedFrom` (e.g. reading `Date.now()`).
11
+ */
12
+ import type { RuntimeReplay } from '../runtime/runtime.js';
13
+ import { type MockOptions } from './engine.js';
14
+ import type { Infer, Schema } from '../foundation/types.js';
15
+ /** A reusable standard-runtime generator with frozen options and contract identities. */
16
+ export type Replay<S extends Schema> = RuntimeReplay<S>;
17
+ /** Bind the standard composition; custom schemas use runtime.replay. */
18
+ export declare const replay: <S extends Schema>(schema: S, options?: MockOptions) => Replay<S>;
19
+ /**
20
+ * Run the generator twice with identical inputs and assert deep equality.
21
+ * Returns the produced value on success; throws on divergence.
22
+ *
23
+ * **This is a diagnostic, not a determinism guarantee.** It runs the
24
+ * schema *twice* with the same seed and compares the outputs
25
+ * structurally — useful for catching obvious non-determinism (a
26
+ * `derivedFrom` reading `Date.now()`, a stray `Math.random()`,
27
+ * iteration over a `Set`), but two iterations cannot prove the entire
28
+ * RNG sequence is fixed. The strong contract is {@link replay}, which
29
+ * binds a (seed, input) pair and lets the caller pin the value at the
30
+ * snapshot site.
31
+ *
32
+ * Treat `expectStable` as the equivalent of a smoke test: cheap to
33
+ * keep in a regression suite, fast to fail loudly when a callback
34
+ * goes off-piste, but not a substitute for `replay`-backed snapshots
35
+ * for surfaces that must round-trip across releases.
36
+ */
37
+ export declare const expectStable: <S extends Schema>(schema: S, options?: MockOptions) => Infer<S>;
38
+ //# sourceMappingURL=replay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../../src/generator/replay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,EAAQ,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAE3D,yFAAyF;AACzF,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,MAAM,IAAI,aAAa,CAAC,CAAC,CAAC,CAAA;AAEvD,wEAAwE;AACxE,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,MAAM,EAAE,QAAQ,CAAC,EAAE,UAAS,WAAgB,KAAG,MAAM,CAAC,CAAC,CAA4C,CAAA;AAEpI;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,EAAE,QAAQ,CAAC,EAAE,UAAS,WAAgB,KAAG,KAAK,CAAC,CAAC,CAU5F,CAAA"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Replay / snapshot helpers — thin layer over `mock()` for tests.
3
+ *
4
+ * `replay(schema, opts)` returns a function bound to a fixed (seed, input)
5
+ * pair. Calling it twice always returns deep-equal values; the function is
6
+ * the canonical way to assert determinism in test suites.
7
+ *
8
+ * `expectStable(schema, opts)` runs the generator twice and throws if the
9
+ * outputs differ — surfaces non-determinism introduced by misuse of
10
+ * `derivedFrom` (e.g. reading `Date.now()`).
11
+ */
12
+ import { isDeepStrictEqual } from 'node:util';
13
+ import { standardRuntime } from '../standard/runtime.js';
14
+ import { mock } from './engine.js';
15
+ /** Bind the standard composition; custom schemas use runtime.replay. */
16
+ export const replay = (schema, options = {}) => standardRuntime.replay(schema, options);
17
+ /**
18
+ * Run the generator twice with identical inputs and assert deep equality.
19
+ * Returns the produced value on success; throws on divergence.
20
+ *
21
+ * **This is a diagnostic, not a determinism guarantee.** It runs the
22
+ * schema *twice* with the same seed and compares the outputs
23
+ * structurally — useful for catching obvious non-determinism (a
24
+ * `derivedFrom` reading `Date.now()`, a stray `Math.random()`,
25
+ * iteration over a `Set`), but two iterations cannot prove the entire
26
+ * RNG sequence is fixed. The strong contract is {@link replay}, which
27
+ * binds a (seed, input) pair and lets the caller pin the value at the
28
+ * snapshot site.
29
+ *
30
+ * Treat `expectStable` as the equivalent of a smoke test: cheap to
31
+ * keep in a regression suite, fast to fail loudly when a callback
32
+ * goes off-piste, but not a substitute for `replay`-backed snapshots
33
+ * for surfaces that must round-trip across releases.
34
+ */
35
+ export const expectStable = (schema, options = {}) => {
36
+ const a = mock(schema, options);
37
+ const b = mock(schema, options);
38
+ if (!isDeepStrictEqual(a, b)) {
39
+ throw new Error('expectStable: generator produced different values for identical seed/input — ' +
40
+ 'likely a non-deterministic derivedFrom callback (e.g. Date.now, Math.random, network).');
41
+ }
42
+ return a;
43
+ };
44
+ //# sourceMappingURL=replay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replay.js","sourceRoot":"","sources":["../../src/generator/replay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAExD,OAAO,EAAE,IAAI,EAAoB,MAAM,aAAa,CAAA;AAMpD,wEAAwE;AACxE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAmB,MAAS,EAAE,UAAuB,EAAE,EAAa,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEpI;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAmB,MAAS,EAAE,UAAuB,EAAE,EAAY,EAAE;IAC/F,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,IAAI,CAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CACb,+EAA+E;YAC7E,wFAAwF,CAC3F,CAAA;IACH,CAAC;IACD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Trace collector — records which axis fired at each path during a
3
+ * single `mock()` call.
4
+ *
5
+ * The trace is a read-only audit of the generator's decisions: every
6
+ * produced value is annotated with the axis that won.
7
+ *
8
+ * Usage:
9
+ *
10
+ * const trace = createTrace()
11
+ * const value = mock(schema, { seed: 's', trace })
12
+ * console.log(trace.entries) // → TraceEntry[]
13
+ */
14
+ /**
15
+ * Which axis decided a value at a given path.
16
+ *
17
+ * - `default` : pure value (`undefined` slot in optional/default)
18
+ * - `optional-skip` : optional field rolled `undefined`
19
+ * - `nullable-null` : nullable field rolled `null`
20
+ * - `derived` : produced by `derivedFrom(...)`
21
+ * - `occasionally` : forced by an `occasionally(...)` override
22
+ * - `eventually` : forced by an `eventually(...)` override (modulo `index`)
23
+ * - `invariant-pass` : sampled then accepted by all `invariant(...)`
24
+ * - `invariant-fail` : retry exhausted before invariants held
25
+ * - `domain` : sampled from `in([...])` candidate set
26
+ * - `distribution` : sampled via `weighted|normal|typically`
27
+ * - `type` : fell through to type-default sampling
28
+ */
29
+ export type TraceAxis = 'default' | 'optional-skip' | 'nullable-null' | 'derived' | 'occasionally' | 'eventually' | 'invariant-pass' | 'invariant-fail' | 'domain' | 'distribution' | 'type';
30
+ export type TraceEntry = {
31
+ readonly path: readonly (string | number)[];
32
+ readonly axis: TraceAxis;
33
+ /** Attempts taken before invariants accepted (only meaningful when invariants run). */
34
+ readonly attempts?: number;
35
+ /** Free-form annotation (e.g. distribution kind, picked literal). */
36
+ readonly note?: string;
37
+ /** Contracts involved in this node, captured by the selected runtime. */
38
+ readonly contracts?: {
39
+ readonly kind: import('../runtime/runtime.js').SchemaContract;
40
+ readonly behaviors: readonly import('../runtime/runtime.js').SchemaContract[];
41
+ };
42
+ };
43
+ export type TraceCollector = {
44
+ /** Append a single entry. Called by the engine — do not call from user code. */
45
+ readonly emit: (entry: TraceEntry) => void;
46
+ /** Read-only view of entries collected so far. */
47
+ readonly entries: readonly TraceEntry[];
48
+ /** All paths where a specific axis fired. */
49
+ readonly axisFiredAt: (axis: TraceAxis) => readonly (readonly (string | number)[])[];
50
+ /** Pretty multi-line dump (one entry per line, JSON-pointer-style paths). */
51
+ readonly format: () => string;
52
+ };
53
+ export declare const createTrace: () => TraceCollector;
54
+ //# sourceMappingURL=trace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../src/generator/trace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,SAAS,GACjB,SAAS,GACT,eAAe,GACf,eAAe,GACf,SAAS,GACT,cAAc,GACd,YAAY,GACZ,gBAAgB,GAChB,gBAAgB,GAChB,QAAQ,GACR,cAAc,GACd,MAAM,CAAA;AAEV,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IAC3C,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;IACxB,uFAAuF;IACvF,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC1B,qEAAqE;IACrE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,yEAAyE;IACzE,QAAQ,CAAC,SAAS,CAAC,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,uBAAuB,EAAE,cAAc,CAAC;QAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,OAAO,uBAAuB,EAAE,cAAc,EAAE,CAAA;KAAE,CAAA;CACtK,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,gFAAgF;IAChF,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;IAC1C,kDAAkD;IAClD,QAAQ,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,CAAA;IACvC,6CAA6C;IAC7C,QAAQ,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,EAAE,CAAA;IACpF,6EAA6E;IAC7E,QAAQ,CAAC,MAAM,EAAE,MAAM,MAAM,CAAA;CAC9B,CAAA;AAED,eAAO,MAAM,WAAW,QAAO,cAuB9B,CAAA"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Trace collector — records which axis fired at each path during a
3
+ * single `mock()` call.
4
+ *
5
+ * The trace is a read-only audit of the generator's decisions: every
6
+ * produced value is annotated with the axis that won.
7
+ *
8
+ * Usage:
9
+ *
10
+ * const trace = createTrace()
11
+ * const value = mock(schema, { seed: 's', trace })
12
+ * console.log(trace.entries) // → TraceEntry[]
13
+ */
14
+ export const createTrace = () => {
15
+ const entries = [];
16
+ return {
17
+ emit(entry) {
18
+ entries.push(entry);
19
+ },
20
+ get entries() {
21
+ return entries;
22
+ },
23
+ axisFiredAt(axis) {
24
+ return entries.filter((e) => e.axis === axis).map((e) => e.path);
25
+ },
26
+ format() {
27
+ return entries
28
+ .map((e) => {
29
+ const ptr = '/' + e.path.map((p) => String(p)).join('/');
30
+ const attempts = e.attempts !== undefined ? ` attempts=${e.attempts}` : '';
31
+ const note = e.note !== undefined ? ` (${e.note})` : '';
32
+ return `${ptr.padEnd(40)} ${e.axis}${attempts}${note}`;
33
+ })
34
+ .join('\n');
35
+ },
36
+ };
37
+ };
38
+ //# sourceMappingURL=trace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace.js","sourceRoot":"","sources":["../../src/generator/trace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAoDH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAmB,EAAE;IAC9C,MAAM,OAAO,GAAiB,EAAE,CAAA;IAChC,OAAO;QACL,IAAI,CAAC,KAAK;YACR,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACrB,CAAC;QACD,IAAI,OAAO;YACT,OAAO,OAAO,CAAA;QAChB,CAAC;QACD,WAAW,CAAC,IAAI;YACd,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QAClE,CAAC;QACD,MAAM;YACJ,OAAO,OAAO;iBACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;gBACT,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;gBACxD,MAAM,QAAQ,GAAG,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;gBAC1E,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;gBACvD,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,QAAQ,GAAG,IAAI,EAAE,CAAA;YACxD,CAAC,CAAC;iBACD,IAAI,CAAC,IAAI,CAAC,CAAA;QACf,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * databehave — Zero-dependency data schema DSL.
3
+ *
4
+ * Public surface:
5
+ * - schema DSL (primitives, composites, decimal, conditional)
6
+ * - data-schema axes (distribution, derived, invariants, domain,
7
+ * discriminated unions, dataset with identity, eventually, correlate)
8
+ * - generator (`mock`) + validator (`parse`/`safeParse`)
9
+ * - debug / determinism (`createTrace`, `replay`, `expectStable`)
10
+ * - cross-dataset FK (`relate`)
11
+ * - extensibility (`walkSchema`, `fromIR`, low-level PRNG, IR types) for
12
+ * third-party packages (CLI, OpenAPI ingestion, zod adapters, …)
13
+ *
14
+ * databehave intentionally ships NO HTTP/server/framework integration. Wire it
15
+ * into your transport of choice (Fastify/Express/msw/node:http) in ~80 LOC.
16
+ */
17
+ export { str, num, int, bool, null_, StringSchema, NumberSchema, IntSchema, BooleanSchema, NullSchema, } from './schema/primitives.js';
18
+ export { decimal, DecimalSchema } from './schema/decimal.js';
19
+ export { obj, arr, tuple, union, literal, enum_, ObjectSchema, ArraySchema, TupleSchema, UnionSchema, LiteralSchema, EnumSchema, } from './schema/composites.js';
20
+ export { discriminated } from './schema/conditional.js';
21
+ export { mock, type MockOptions, type ModifierProbs, type StableByFn } from './generator/engine.js';
22
+ export type { Rng } from './foundation/prng.js';
23
+ export { parse, safeParse, type SafeParseResult } from './validator/parse.js';
24
+ export { createTrace, type TraceAxis, type TraceCollector, type TraceEntry, } from './generator/trace.js';
25
+ export { replay, expectStable, type Replay } from './generator/replay.js';
26
+ export { mockDataset, identityFor, type DatasetOptions } from './dataset/dataset.js';
27
+ export { relate, type RelateOptions } from './dataset/relate.js';
28
+ export { Schema, type Infer, type Modifiers, type SchemaNode } from './foundation/types.js';
29
+ export type { Axes, DerivedFn, Distribution, DomainConstraint, EventuallyOverride, GenContext, InvariantFn, NormalDistribution, OccasionalOverride, TypicalDistribution, WeightedDistribution, } from './foundation/axes.js';
30
+ export { DataBehaveError, ConformError, SchemaConflictError, type Issue, type IssueCode, } from './foundation/errors.js';
31
+ export { createSchemaRuntime, IR_VERSION, type SchemaRuntime, type SchemaRuntimeOptions, type SchemaContract, type SchemaEnvelope, type SchemaVisitor, type WalkPath, type RuntimeReplay } from './runtime/runtime.js';
32
+ export { defineKind, defineBehavior, type KindDescriptor, type KindDefinition, type TypedKind, type BehaviorDescriptor, type BehaviorDefinition, type TypedBehavior, type BehaviorPhase, type SchemaChild, type GenerationContext, type GenerationNext, type SamplingContext, type ValidationContext } from './runtime/contracts.js';
33
+ export { standardKinds } from './standard/kinds.js';
34
+ export { standardBehaviors } from './standard/behaviors.js';
35
+ export { standardRuntime } from './standard/runtime.js';
36
+ export type { StandardSchemaNode } from './foundation/ir.js';
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EACL,GAAG,EACH,GAAG,EACH,GAAG,EACH,IAAI,EACJ,KAAK,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,aAAa,EACb,UAAU,GACX,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC5D,OAAO,EACL,GAAG,EACH,GAAG,EACH,KAAK,EACL,KAAK,EACL,OAAO,EACP,KAAK,EACL,YAAY,EACZ,WAAW,EACX,WAAW,EACX,WAAW,EACX,aAAa,EACb,UAAU,GACX,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAGvD,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACnG,YAAY,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EACL,WAAW,EACX,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,UAAU,GAChB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAA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oB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * databehave — Zero-dependency data schema DSL.
3
+ *
4
+ * Public surface:
5
+ * - schema DSL (primitives, composites, decimal, conditional)
6
+ * - data-schema axes (distribution, derived, invariants, domain,
7
+ * discriminated unions, dataset with identity, eventually, correlate)
8
+ * - generator (`mock`) + validator (`parse`/`safeParse`)
9
+ * - debug / determinism (`createTrace`, `replay`, `expectStable`)
10
+ * - cross-dataset FK (`relate`)
11
+ * - extensibility (`walkSchema`, `fromIR`, low-level PRNG, IR types) for
12
+ * third-party packages (CLI, OpenAPI ingestion, zod adapters, …)
13
+ *
14
+ * databehave intentionally ships NO HTTP/server/framework integration. Wire it
15
+ * into your transport of choice (Fastify/Express/msw/node:http) in ~80 LOC.
16
+ */
17
+ // ── schema DSL ────────────────────────────────────────────────────────────
18
+ export { str, num, int, bool, null_, StringSchema, NumberSchema, IntSchema, BooleanSchema, NullSchema, } from './schema/primitives.js';
19
+ export { decimal, DecimalSchema } from './schema/decimal.js';
20
+ export { obj, arr, tuple, union, literal, enum_, ObjectSchema, ArraySchema, TupleSchema, UnionSchema, LiteralSchema, EnumSchema, } from './schema/composites.js';
21
+ export { discriminated } from './schema/conditional.js';
22
+ // ── generator + validator ─────────────────────────────────────────────────
23
+ export { mock } from './generator/engine.js';
24
+ export { parse, safeParse } from './validator/parse.js';
25
+ export { createTrace, } from './generator/trace.js';
26
+ export { replay, expectStable } from './generator/replay.js';
27
+ // ── dataset ───────────────────────────────────────────────────────────────
28
+ export { mockDataset, identityFor } from './dataset/dataset.js';
29
+ export { relate } from './dataset/relate.js';
30
+ // ── foundation types & axes ───────────────────────────────────────────────
31
+ export { Schema } from './foundation/types.js';
32
+ // ── errors ────────────────────────────────────────────────────────────────
33
+ export { DataBehaveError, ConformError, SchemaConflictError, } from './foundation/errors.js';
34
+ // Instance-local schema composition and extension contracts.
35
+ export { createSchemaRuntime, IR_VERSION } from './runtime/runtime.js';
36
+ export { defineKind, defineBehavior } from './runtime/contracts.js';
37
+ export { standardKinds } from './standard/kinds.js';
38
+ export { standardBehaviors } from './standard/behaviors.js';
39
+ export { standardRuntime } from './standard/runtime.js';
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,6EAA6E;AAC7E,OAAO,EACL,GAAG,EACH,GAAG,EACH,GAAG,EACH,IAAI,EACJ,KAAK,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,aAAa,EACb,UAAU,GACX,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC5D,OAAO,EACL,GAAG,EACH,GAAG,EACH,KAAK,EACL,KAAK,EACL,OAAO,EACP,KAAK,EACL,YAAY,EACZ,WAAW,EACX,WAAW,EACX,WAAW,EACX,aAAa,EACb,UAAU,GACX,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAEvD,6EAA6E;AAC7E,OAAO,EAAE,IAAI,EAAyD,MAAM,uBAAuB,CAAA;AAEnG,OAAO,EAAE,KAAK,EAAE,SAAS,EAAwB,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EACL,WAAW,GAIZ,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,MAAM,EAAE,YAAY,EAAe,MAAM,uBAAuB,CAAA;AAEzE,6EAA6E;AAC7E,OAAO,EAAE,WAAW,EAAE,WAAW,EAAuB,MAAM,sBAAsB,CAAA;AACpF,OAAO,EAAE,MAAM,EAAsB,MAAM,qBAAqB,CAAA;AAEhE,6EAA6E;AAC7E,OAAO,EAAE,MAAM,EAA+C,MAAM,uBAAuB,CAAA;AAe3F,6EAA6E;AAC7E,OAAO,EACL,eAAe,EACf,YAAY,EACZ,mBAAmB,GAGpB,MAAM,wBAAwB,CAAA;AAE/B,6DAA6D;AAC7D,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAkJ,MAAM,sBAAsB,CAAA;AACtN,OAAO,EAAE,UAAU,EAAE,cAAc,EAAmQ,MAAM,wBAAwB,CAAA;AACpU,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @databehave/schema/internal — low-level extensibility surface.
3
+ *
4
+ * Re-exports the IR walker, the IR discriminants, the axis types, and
5
+ * seeded PRNG primitives that exist for third-party packages (CLI tools,
6
+ * OpenAPI ingestion, zod adapters, …) to build on. These are versioned
7
+ * more loosely than the main DSL:
8
+ *
9
+ * • SchemaNode / IR shape changes are MAJOR (see docs/stability.md).
10
+ * • PRNG output is deterministic across PATCH/MINOR for a given seed.
11
+ *
12
+ * **Do not import from `@databehave/schema/internal` in application code.**
13
+ * Prefer the high-level `mock()` / `parse()` / `safeParse()` from the package
14
+ * root. Importing internals couples you to the IR and bypasses fail-loud guards.
15
+ */
16
+ export { walkSchema, fromIR, serializeSchema, deserializeSchema, IR_VERSION, type SchemaEnvelope, type SchemaVisitor, type WalkPath, } from './foundation/walk.js';
17
+ export { mulberry32, rngFromString, seedFromString, type Rng, } from './foundation/prng.js';
18
+ export { Schema } from './foundation/types.js';
19
+ export type { Infer } from './foundation/types.js';
20
+ export type { ArrayKind, BooleanKind, DecimalKind, DiscriminatedKind, EnumKind, LiteralKind, Modifiers, NullKind, NumberKind, ObjectKind, SchemaCore, SchemaNode, StandardSchemaNode, StringFormat, StringKind, TupleKind, UnionKind, } from './foundation/ir.js';
21
+ export type { Axes, DerivedFn, Distribution, DomainConstraint, EventuallyOverride, GenContext, InvariantFn, NormalDistribution, OccasionalOverride, TypicalDistribution, WeightedDistribution, } from './foundation/axes.js';
22
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,UAAU,EACV,MAAM,EACN,eAAe,EACf,iBAAiB,EACjB,UAAU,EACV,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,QAAQ,GACd,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,EACd,KAAK,GAAG,GACT,MAAM,sBAAsB,CAAA;AAS7B,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,YAAY,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAElD,YAAY,EAEV,SAAS,EACT,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,SAAS,EACT,QAAQ,EACR,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,SAAS,EACT,SAAS,GACV,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EAEV,IAAI,EACJ,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,sBAAsB,CAAA"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @databehave/schema/internal — low-level extensibility surface.
3
+ *
4
+ * Re-exports the IR walker, the IR discriminants, the axis types, and
5
+ * seeded PRNG primitives that exist for third-party packages (CLI tools,
6
+ * OpenAPI ingestion, zod adapters, …) to build on. These are versioned
7
+ * more loosely than the main DSL:
8
+ *
9
+ * • SchemaNode / IR shape changes are MAJOR (see docs/stability.md).
10
+ * • PRNG output is deterministic across PATCH/MINOR for a given seed.
11
+ *
12
+ * **Do not import from `@databehave/schema/internal` in application code.**
13
+ * Prefer the high-level `mock()` / `parse()` / `safeParse()` from the package
14
+ * root. Importing internals couples you to the IR and bypasses fail-loud guards.
15
+ */
16
+ export { walkSchema, fromIR, serializeSchema, deserializeSchema, IR_VERSION, } from './foundation/walk.js';
17
+ export { mulberry32, rngFromString, seedFromString, } from './foundation/prng.js';
18
+ // ── extension-author types ─────────────────────────────────────────
19
+ //
20
+ // Surfaced so extension code (codegen, IR transforms, OpenAPI adapters)
21
+ // can name the IR discriminants and the `_applyAxes` argument shape
22
+ // without reaching into deep paths. Type-only re-exports — they emit
23
+ // no runtime JS.
24
+ export { Schema } from './foundation/types.js';
25
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,UAAU,EACV,MAAM,EACN,eAAe,EACf,iBAAiB,EACjB,UAAU,GAIX,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,GAEf,MAAM,sBAAsB,CAAA;AAE7B,sEAAsE;AACtE,EAAE;AACF,wEAAwE;AACxE,oEAAoE;AACpE,qEAAqE;AACrE,iBAAiB;AAEjB,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA"}
@@ -0,0 +1,7 @@
1
+ import { type Capability, type Plugin } from '@databehave/core';
2
+ import { type SchemaRuntime, type SchemaRuntimeOptions } from './runtime/runtime.js';
3
+ /** Optional application capability; standalone schema imports never load the host. */
4
+ export declare const schemaCapability: Capability<SchemaRuntime>;
5
+ /** Compose a new synchronous schema registry during each host's setup phase. */
6
+ export declare const schemaPlugin: (options: SchemaRuntimeOptions) => Plugin;
7
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,UAAU,EAAE,KAAK,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAC3E,OAAO,EAAuB,KAAK,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAEzG,sFAAsF;AACtF,eAAO,MAAM,gBAAgB,EAAE,UAAU,CAAC,aAAa,CAGtD,CAAA;AAED,gFAAgF;AAChF,eAAO,MAAM,YAAY,GAAI,SAAS,oBAAoB,KAAG,MAO3D,CAAA"}
package/dist/plugin.js ADDED
@@ -0,0 +1,14 @@
1
+ import { capability } from '@databehave/core';
2
+ import { createSchemaRuntime } from './runtime/runtime.js';
3
+ /** Optional application capability; standalone schema imports never load the host. */
4
+ export const schemaCapability = capability('databehave.schema.runtime', 1);
5
+ /** Compose a new synchronous schema registry during each host's setup phase. */
6
+ export const schemaPlugin = (options) => ({
7
+ id: 'databehave.schema',
8
+ apiVersion: 1,
9
+ provides: [schemaCapability],
10
+ setup(context) {
11
+ context.provide(schemaCapability, createSchemaRuntime(options));
12
+ },
13
+ });
14
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgC,MAAM,kBAAkB,CAAA;AAC3E,OAAO,EAAE,mBAAmB,EAAiD,MAAM,sBAAsB,CAAA;AAEzG,sFAAsF;AACtF,MAAM,CAAC,MAAM,gBAAgB,GAA8B,UAAU,CACnE,2BAA2B,EAC3B,CAAC,CACF,CAAA;AAED,gFAAgF;AAChF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAA6B,EAAU,EAAE,CAAC,CAAC;IACtE,EAAE,EAAE,mBAAmB;IACvB,UAAU,EAAE,CAAC;IACb,QAAQ,EAAE,CAAC,gBAAgB,CAAC;IAC5B,KAAK,CAAC,OAAO;QACX,OAAO,CAAC,OAAO,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAA;IACjE,CAAC;CACF,CAAC,CAAA"}
@@ -0,0 +1,101 @@
1
+ import type { GenContext } from '../foundation/axes.js';
2
+ import type { Issue } from '../foundation/errors.js';
3
+ import type { SchemaNode } from '../foundation/ir.js';
4
+ import type { Rng } from '../foundation/prng.js';
5
+ import { Schema } from '../foundation/types.js';
6
+ import type { ModifierProbs } from '../generator/engine.js';
7
+ import type { TraceEntry } from '../generator/trace.js';
8
+ /** A structural child and its traversal path segment. */
9
+ export interface SchemaChild {
10
+ readonly key: string | number;
11
+ readonly node: SchemaNode;
12
+ }
13
+ /** Candidate sampling scoped to one downstream generation continuation. */
14
+ export interface SamplingContext {
15
+ readonly candidates: readonly unknown[];
16
+ readonly fallback: () => unknown;
17
+ }
18
+ /** Continue with the current sampling scope, or override it for this call only. */
19
+ export type GenerationNext = (sampling?: SamplingContext) => unknown;
20
+ /** Services scoped to one generation call; recursion retains its runtime. */
21
+ export interface GenerationContext extends GenContext {
22
+ readonly sampling?: SamplingContext;
23
+ readonly path: readonly (string | number)[];
24
+ readonly rng: Rng;
25
+ readonly leafRng: () => Rng;
26
+ readonly modifierProbs: Required<ModifierProbs>;
27
+ readonly isDeferred: (node: SchemaNode) => boolean;
28
+ readonly generate: (node: SchemaNode, path: readonly (string | number)[], parent: Readonly<Record<string, unknown>>) => unknown;
29
+ readonly emit: (entry: TraceEntry) => void;
30
+ }
31
+ /** Validation services scoped to a node; plugins report issues or recurse. */
32
+ export interface ValidationContext extends GenContext {
33
+ readonly path: readonly (string | number)[];
34
+ readonly issues: Issue[];
35
+ readonly describe: (node: SchemaNode) => string;
36
+ readonly isDeferred: (node: SchemaNode) => boolean;
37
+ readonly check: (node: SchemaNode, value: unknown, path: readonly (string | number)[], issues: Issue[], root: unknown, parent: Readonly<Record<string, unknown>> | undefined) => unknown;
38
+ }
39
+ /** A kind owns its complete structural and value contract. */
40
+ export interface KindDescriptor {
41
+ readonly id: string;
42
+ readonly version: number;
43
+ readonly describe?: (node: SchemaNode, describeChild: (node: SchemaNode) => string) => string;
44
+ readonly checkMetadata: (node: unknown) => SchemaNode;
45
+ readonly generate: (node: SchemaNode, context: GenerationContext) => unknown;
46
+ readonly validate: (node: SchemaNode, value: unknown, context: ValidationContext) => unknown;
47
+ readonly children: (node: SchemaNode) => readonly SchemaChild[];
48
+ readonly rebuild: (node: SchemaNode, children: readonly SchemaChild[]) => SchemaNode;
49
+ }
50
+ /** Fixed phase barriers; composition order determines order within each phase. */
51
+ export type BehaviorPhase = 'modifier' | 'derived' | 'cadence' | 'invariant' | 'sample';
52
+ /** Behavior policy uses middleware so short circuits and bounded retries are explicit. */
53
+ export interface BehaviorDescriptor {
54
+ readonly id: string;
55
+ readonly version: number;
56
+ readonly phase: BehaviorPhase;
57
+ readonly read: (node: SchemaNode) => unknown;
58
+ readonly write: (node: SchemaNode, metadata: unknown) => SchemaNode;
59
+ readonly checkMetadata: (metadata: unknown) => unknown;
60
+ readonly appliesTo: (node: SchemaNode, metadata: unknown) => boolean;
61
+ readonly merge: (previous: unknown, next: unknown) => unknown;
62
+ readonly generate: (metadata: unknown, node: SchemaNode, context: GenerationContext, next: GenerationNext) => unknown;
63
+ readonly validate: (metadata: unknown, node: SchemaNode, value: unknown, context: ValidationContext, next: () => unknown) => unknown;
64
+ readonly serialize: (metadata: unknown) => unknown;
65
+ }
66
+ /** Typed public kind authoring; the parser validates every untrusted node. */
67
+ export interface KindDefinition<T, N extends SchemaNode> {
68
+ readonly id: N['kind'];
69
+ readonly version: number;
70
+ readonly describe?: (node: N, describeChild: (node: SchemaNode) => string) => string;
71
+ readonly checkMetadata: (node: unknown) => N;
72
+ readonly generate: (node: N, context: GenerationContext) => T;
73
+ readonly validate: (node: N, value: unknown, context: ValidationContext) => unknown;
74
+ readonly children: (node: N) => readonly SchemaChild[];
75
+ readonly rebuild: (node: N, children: readonly SchemaChild[]) => N;
76
+ }
77
+ /** Kind descriptor with a type-safe builder; no builder subclass is required. */
78
+ export interface TypedKind<T, N extends SchemaNode> extends KindDescriptor {
79
+ readonly schema: (metadata: Omit<N, 'kind'>) => Schema<T>;
80
+ }
81
+ /** Erase only the validated metadata type at the registry boundary. */
82
+ export declare const defineKind: <T, N extends SchemaNode>(definition: KindDefinition<T, N>) => TypedKind<T, N>;
83
+ /** Typed behavior authoring with the common instance-independent metadata carrier. */
84
+ export interface BehaviorDefinition<M> {
85
+ readonly id: string;
86
+ readonly version: number;
87
+ readonly phase: BehaviorPhase;
88
+ readonly checkMetadata: (metadata: unknown) => M;
89
+ readonly appliesTo: (node: SchemaNode, metadata: M) => boolean;
90
+ readonly merge: (previous: M, next: M) => M;
91
+ readonly generate: (metadata: M, node: SchemaNode, context: GenerationContext, next: GenerationNext) => unknown;
92
+ readonly validate: (metadata: M, node: SchemaNode, value: unknown, context: ValidationContext, next: () => unknown) => unknown;
93
+ readonly serialize: (metadata: M) => unknown;
94
+ }
95
+ /** Behavior descriptor with a typed metadata attachment helper. */
96
+ export interface TypedBehavior<M> extends BehaviorDescriptor {
97
+ readonly apply: <T>(schema: Schema<T>, metadata: M) => Schema<T>;
98
+ }
99
+ /** Adapt typed metadata to the public behavior contract. */
100
+ export declare const defineBehavior: <M>(definition: BehaviorDefinition<M>) => TypedBehavior<M>;
101
+ //# sourceMappingURL=contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/runtime/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,KAAK,EAAE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