@databehave/schema 0.1.2 → 0.1.4

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 (77) hide show
  1. package/dist/dataset/dataset.d.ts +47 -0
  2. package/dist/dataset/dataset.d.ts.map +1 -0
  3. package/dist/dataset/dataset.js +96 -0
  4. package/dist/dataset/dataset.js.map +1 -0
  5. package/dist/dataset/relate.d.ts +32 -0
  6. package/dist/dataset/relate.d.ts.map +1 -0
  7. package/dist/dataset/relate.js +46 -0
  8. package/dist/dataset/relate.js.map +1 -0
  9. package/dist/foundation/axes.d.ts +101 -0
  10. package/dist/foundation/axes.d.ts.map +1 -0
  11. package/dist/foundation/axes.js +42 -0
  12. package/dist/foundation/axes.js.map +1 -0
  13. package/dist/foundation/errors.d.ts +99 -0
  14. package/dist/foundation/errors.d.ts.map +1 -0
  15. package/dist/foundation/errors.js +91 -0
  16. package/dist/foundation/errors.js.map +1 -0
  17. package/dist/foundation/hash.d.ts +12 -0
  18. package/dist/foundation/hash.d.ts.map +1 -0
  19. package/dist/foundation/hash.js +21 -0
  20. package/dist/foundation/hash.js.map +1 -0
  21. package/dist/foundation/ir.d.ts +91 -0
  22. package/dist/foundation/ir.d.ts.map +1 -0
  23. package/dist/foundation/ir.js +16 -0
  24. package/dist/foundation/ir.js.map +1 -0
  25. package/dist/foundation/prng.d.ts +27 -0
  26. package/dist/foundation/prng.d.ts.map +1 -0
  27. package/dist/foundation/prng.js +56 -0
  28. package/dist/foundation/prng.js.map +1 -0
  29. package/dist/foundation/types.d.ts +116 -0
  30. package/dist/foundation/types.d.ts.map +1 -0
  31. package/dist/foundation/types.js +188 -0
  32. package/dist/foundation/types.js.map +1 -0
  33. package/dist/foundation/walk.d.ts +72 -0
  34. package/dist/foundation/walk.d.ts.map +1 -0
  35. package/dist/foundation/walk.js +265 -0
  36. package/dist/foundation/walk.js.map +1 -0
  37. package/dist/generator/engine.d.ts +100 -0
  38. package/dist/generator/engine.d.ts.map +1 -0
  39. package/dist/generator/engine.js +575 -0
  40. package/dist/generator/engine.js.map +1 -0
  41. package/dist/generator/replay.d.ts +42 -0
  42. package/dist/generator/replay.d.ts.map +1 -0
  43. package/dist/generator/replay.js +61 -0
  44. package/dist/generator/replay.js.map +1 -0
  45. package/dist/generator/trace.d.ts +49 -0
  46. package/dist/generator/trace.d.ts.map +1 -0
  47. package/dist/generator/trace.js +38 -0
  48. package/dist/generator/trace.js.map +1 -0
  49. package/dist/index.d.ts +31 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.js +34 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/internal.d.ts +22 -0
  54. package/dist/internal.d.ts.map +1 -0
  55. package/dist/internal.js +25 -0
  56. package/dist/internal.js.map +1 -0
  57. package/dist/schema/composites.d.ts +104 -0
  58. package/dist/schema/composites.d.ts.map +1 -0
  59. package/dist/schema/composites.js +134 -0
  60. package/dist/schema/composites.js.map +1 -0
  61. package/dist/schema/conditional.d.ts +28 -0
  62. package/dist/schema/conditional.d.ts.map +1 -0
  63. package/dist/schema/conditional.js +52 -0
  64. package/dist/schema/conditional.js.map +1 -0
  65. package/dist/schema/decimal.d.ts +33 -0
  66. package/dist/schema/decimal.d.ts.map +1 -0
  67. package/dist/schema/decimal.js +39 -0
  68. package/dist/schema/decimal.js.map +1 -0
  69. package/dist/schema/primitives.d.ts +47 -0
  70. package/dist/schema/primitives.d.ts.map +1 -0
  71. package/dist/schema/primitives.js +78 -0
  72. package/dist/schema/primitives.js.map +1 -0
  73. package/dist/validator/parse.d.ts +22 -0
  74. package/dist/validator/parse.d.ts.map +1 -0
  75. package/dist/validator/parse.js +427 -0
  76. package/dist/validator/parse.js.map +1 -0
  77. package/package.json +3 -1
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Discriminated union.
3
+ *
4
+ * `discriminated(key, map)` builds a schema whose branches are selected by
5
+ * the value of the named discriminator field, both during generation and
6
+ * during validation.
7
+ *
8
+ * Each entry in `map` must be an object-kind schema whose `key` field is a
9
+ * `literal(...)` matching the map key. This is enforced at build time so
10
+ * the discriminator is genuinely useful: generation picks one branch and
11
+ * sets the key; validation reads the key and dispatches to the matching
12
+ * branch (O(1), with errors keyed on the discriminator).
13
+ *
14
+ * ```ts
15
+ * const Variant = discriminated('kind', {
16
+ * alpha: obj({ kind: literal('alpha'), score: decimal(10, 4) }),
17
+ * beta: obj({ kind: literal('beta'), weight: decimal(10, 4) }),
18
+ * })
19
+ * ```
20
+ */
21
+ import { Schema } from '../foundation/types.js';
22
+ const isObjectNode = (n) => n.kind === 'object';
23
+ /**
24
+ * Build a discriminated union keyed on `key`. Each value in `map` must be a
25
+ * schema (typically `obj({...})`) whose `key` field is a `literal(...)`
26
+ * matching the map key.
27
+ */
28
+ export const discriminated = (key, map) => {
29
+ const tags = Object.keys(map);
30
+ if (tags.length === 0) {
31
+ throw new RangeError(`discriminated("${key}"): map must contain at least one branch`);
32
+ }
33
+ const branches = {};
34
+ for (const tag of tags) {
35
+ const branch = map[tag]._node;
36
+ if (!isObjectNode(branch)) {
37
+ throw new RangeError(`discriminated("${key}"): branch ${JSON.stringify(tag)} must be an obj({...}) schema`);
38
+ }
39
+ const keyField = branch.fields[key];
40
+ if (keyField === undefined) {
41
+ throw new RangeError(`discriminated("${key}"): branch ${JSON.stringify(tag)} is missing the discriminator field "${key}"`);
42
+ }
43
+ if (keyField.kind !== 'literal' || keyField.value !== tag) {
44
+ throw new RangeError(`discriminated("${key}"): branch ${JSON.stringify(tag)} must declare ` +
45
+ `${key}: literal(${JSON.stringify(tag)})`);
46
+ }
47
+ branches[tag] = branch;
48
+ }
49
+ const node = { kind: 'discriminated', key, branches };
50
+ return new Schema(node);
51
+ };
52
+ //# sourceMappingURL=conditional.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conditional.js","sourceRoot":"","sources":["../../src/schema/conditional.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,MAAM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C5C,CAAA;QACH,CAAC;QACD,QAAQ,CAAC,GAAG,CAAC,GAAG,MAAM,CAAA;IACxB,CAAC;IAED,MAAM,IAAI,GAAsB,EAAE,IAAI,EAAE,eAAe,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAA;IACxE,OAAO,IAAI,MAAM,CAAC,IAAI,CAAgE,CAAA;AACxF,CAAC,CAAA"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Decimal — fixed-point numeric represented as a string for precision safety.
3
+ *
4
+ * Targets Snowflake / Postgres NUMERIC(precision, scale). Generated values are
5
+ * always strings (e.g. `"123.4500000000000000000"` for scale=19) so callers
6
+ * never lose precision through JavaScript number coercion.
7
+ *
8
+ * The inferred type is `string` for ergonomic interop with the rest of the
9
+ * ecosystem. Callers needing a nominal brand can intersect via `Infer<typeof S>
10
+ * & Brand` themselves; databehave intentionally avoids forcing a brand to keep
11
+ * `decimal().default('0.0')` and JSON round-trips friction-free.
12
+ */
13
+ import type { DecimalKind, Modifiers } from '../foundation/ir.js';
14
+ import { Continuous, Numeric, Schema } from '../foundation/types.js';
15
+ export declare class DecimalSchema extends Schema<string> {
16
+ readonly _node: DecimalKind & {
17
+ mods?: Modifiers;
18
+ };
19
+ readonly [Numeric]: true;
20
+ readonly [Continuous]: true;
21
+ /** Inclusive lower bound. Pass as a numeric string. */
22
+ min(value: string | number): DecimalSchema;
23
+ /** Inclusive upper bound. Pass as a numeric string. */
24
+ max(value: string | number): DecimalSchema;
25
+ }
26
+ /**
27
+ * Declare a fixed-point decimal column.
28
+ *
29
+ * @param precision total significant digits (1..38 for Snowflake)
30
+ * @param scale digits after the decimal point (0..precision)
31
+ */
32
+ export declare const decimal: (precision: number, scale: number) => DecimalSchema;
33
+ //# sourceMappingURL=decimal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../src/schema/decimal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACjE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAEpE,qBAAa,aAAc,SAAQ,MAAM,CAAC,MAAM,CAAC;IAC/C,SAAiB,KAAK,EAAE,WAAW,GAAG;QAAE,IAAI,CAAC,EAAE,SAAS,CAAA;KAAE,CAAA;IAC1D,SAAiB,CAAC,OAAO,CAAC,EAAE,IAAI,CAAA;IAChC,SAAiB,CAAC,UAAU,CAAC,EAAE,IAAI,CAAA;IAEnC,uDAAuD;IACvD,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,aAAa;IAG1C,uDAAuD;IACvD,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,aAAa;CAG3C;AAED;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAAI,WAAW,MAAM,EAAE,OAAO,MAAM,KAAG,aAQ1D,CAAA"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Decimal — fixed-point numeric represented as a string for precision safety.
3
+ *
4
+ * Targets Snowflake / Postgres NUMERIC(precision, scale). Generated values are
5
+ * always strings (e.g. `"123.4500000000000000000"` for scale=19) so callers
6
+ * never lose precision through JavaScript number coercion.
7
+ *
8
+ * The inferred type is `string` for ergonomic interop with the rest of the
9
+ * ecosystem. Callers needing a nominal brand can intersect via `Infer<typeof S>
10
+ * & Brand` themselves; databehave intentionally avoids forcing a brand to keep
11
+ * `decimal().default('0.0')` and JSON round-trips friction-free.
12
+ */
13
+ import { Continuous, Numeric, Schema } from '../foundation/types.js';
14
+ export class DecimalSchema extends Schema {
15
+ /** Inclusive lower bound. Pass as a numeric string. */
16
+ min(value) {
17
+ return new DecimalSchema({ ...this._node, min: String(value) });
18
+ }
19
+ /** Inclusive upper bound. Pass as a numeric string. */
20
+ max(value) {
21
+ return new DecimalSchema({ ...this._node, max: String(value) });
22
+ }
23
+ }
24
+ /**
25
+ * Declare a fixed-point decimal column.
26
+ *
27
+ * @param precision total significant digits (1..38 for Snowflake)
28
+ * @param scale digits after the decimal point (0..precision)
29
+ */
30
+ export const decimal = (precision, scale) => {
31
+ if (!Number.isInteger(precision) || precision < 1 || precision > 38) {
32
+ throw new RangeError(`decimal: precision must be integer in [1, 38], got ${precision}`);
33
+ }
34
+ if (!Number.isInteger(scale) || scale < 0 || scale > precision) {
35
+ throw new RangeError(`decimal: scale must be integer in [0, precision], got ${scale}`);
36
+ }
37
+ return new DecimalSchema({ kind: 'decimal', precision, scale });
38
+ };
39
+ //# sourceMappingURL=decimal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decimal.js","sourceRoot":"","sources":["../../src/schema/decimal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAEpE,MAAM,OAAO,aAAc,SAAQ,MAAc;IAK/C,uDAAuD;IACvD,GAAG,CAAC,KAAsB;QACxB,OAAO,IAAI,aAAa,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IACjE,CAAC;IACD,uDAAuD;IACvD,GAAG,CAAC,KAAsB;QACxB,OAAO,IAAI,aAAa,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IACjE,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,SAAiB,EAAE,KAAa,EAAiB,EAAE;IACzE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,SAAS,GAAG,CAAC,IAAI,SAAS,GAAG,EAAE,EAAE,CAAC;QACpE,MAAM,IAAI,UAAU,CAAC,sDAAsD,SAAS,EAAE,CAAC,CAAA;IACzF,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,SAAS,EAAE,CAAC;QAC/D,MAAM,IAAI,UAAU,CAAC,yDAAyD,KAAK,EAAE,CAAC,CAAA;IACxF,CAAC;IACD,OAAO,IAAI,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAA;AACjE,CAAC,CAAA"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Primitive schema builders: str, num, int, bool, null_.
3
+ *
4
+ * Each returns a {@link Schema} instance whose phantom `_type` reflects the
5
+ * generated TypeScript type, and whose `_node` is the serializable IR.
6
+ */
7
+ import type { Modifiers, NumberKind, StringKind } from '../foundation/ir.js';
8
+ import { Continuous, Discrete, Numeric, Schema } from '../foundation/types.js';
9
+ export declare class StringSchema extends Schema<string> {
10
+ readonly _node: StringKind & {
11
+ mods?: Modifiers;
12
+ };
13
+ readonly [Discrete]: true;
14
+ min(n: number): StringSchema;
15
+ max(n: number): StringSchema;
16
+ pattern(re: RegExp | string): StringSchema;
17
+ }
18
+ export declare const str: () => StringSchema;
19
+ export declare class NumberSchema extends Schema<number> {
20
+ readonly _node: NumberKind & {
21
+ mods?: Modifiers;
22
+ };
23
+ min(n: number): this;
24
+ max(n: number): this;
25
+ protected cloneWithNode(node: NumberKind & {
26
+ mods?: Modifiers;
27
+ }): this;
28
+ }
29
+ /** `int()`-flavoured number — discrete, no Gaussian. Extends `NumberSchema`. */
30
+ export declare class IntSchema extends NumberSchema {
31
+ readonly [Discrete]: true;
32
+ }
33
+ export declare const num: () => NumberSchema & {
34
+ readonly [Numeric]: true;
35
+ readonly [Continuous]: true;
36
+ };
37
+ export declare const int: () => IntSchema & {
38
+ readonly [Numeric]: true;
39
+ };
40
+ export declare class BooleanSchema extends Schema<boolean> {
41
+ readonly [Discrete]: true;
42
+ }
43
+ export declare class NullSchema extends Schema<null> {
44
+ }
45
+ export declare const bool: () => BooleanSchema;
46
+ export declare const null_: () => NullSchema;
47
+ //# sourceMappingURL=primitives.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/schema/primitives.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAC5E,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAM9E,qBAAa,YAAa,SAAQ,MAAM,CAAC,MAAM,CAAC;IAC9C,SAAiB,KAAK,EAAE,UAAU,GAAG;QAAE,IAAI,CAAC,EAAE,SAAS,CAAA;KAAE,CAAA;IACzD,SAAiB,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAA;IAEjC,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,YAAY;IAG5B,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,YAAY;IAG5B,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY;CAM3C;AAED,eAAO,MAAM,GAAG,QAAO,YACgC,CAAA;AA4BvD,qBAAa,YAAa,SAAQ,MAAM,CAAC,MAAM,CAAC;IAC9C,SAAiB,KAAK,EAAE,UAAU,GAAG;QAAE,IAAI,CAAC,EAAE,SAAS,CAAA;KAAE,CAAA;IAEzD,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAGpB,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAIpB,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG;QAAE,IAAI,CAAC,EAAE,SAAS,CAAA;KAAE,GAAG,IAAI;CAKvE;AAED,gFAAgF;AAChF,qBAAa,SAAU,SAAQ,YAAY;IACzC,SAAiB,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAA;CAClC;AAED,eAAO,MAAM,GAAG,QAAO,YAAY,GAAG;IACpC,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,CAAA;IACxB,QAAQ,CAAC,CAAC,UAAU,CAAC,EAAE,IAAI,CAAA;CAK1B,CAAA;AAEH,eAAO,MAAM,GAAG,QAAO,SAAS,GAAG;IAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,CAAA;CAG1D,CAAA;AAMH,qBAAa,aAAc,SAAQ,MAAM,CAAC,OAAO,CAAC;IAChD,SAAiB,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAA;CAClC;AAED,qBAAa,UAAW,SAAQ,MAAM,CAAC,IAAI,CAAC;CAAG;AAE/C,eAAO,MAAM,IAAI,QAAO,aAAuD,CAAA;AAE/E,eAAO,MAAM,KAAK,QAAO,UAA8C,CAAA"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Primitive schema builders: str, num, int, bool, null_.
3
+ *
4
+ * Each returns a {@link Schema} instance whose phantom `_type` reflects the
5
+ * generated TypeScript type, and whose `_node` is the serializable IR.
6
+ */
7
+ import { Continuous, Discrete, Numeric, Schema } from '../foundation/types.js';
8
+ // ──────────────────────────────────────────────────────────────────────────
9
+ // string
10
+ // ──────────────────────────────────────────────────────────────────────────
11
+ export class StringSchema extends Schema {
12
+ min(n) {
13
+ return new StringSchema({ ...this._node, min: n });
14
+ }
15
+ max(n) {
16
+ return new StringSchema({ ...this._node, max: n });
17
+ }
18
+ pattern(re) {
19
+ return new StringSchema({
20
+ ...this._node,
21
+ pattern: typeof re === 'string' ? re : re.source,
22
+ });
23
+ }
24
+ }
25
+ export const str = () => new StringSchema({ kind: 'string', format: 'plain' });
26
+ // ──────────────────────────────────────────────────────────────────────────
27
+ // number / int
28
+ //
29
+ // `NumberSchema` is the base class for both float-shaped (`num()`) and
30
+ // integer-shaped (`int()`) numeric schemas — the IR-level distinction is
31
+ // `_node.int`, this hierarchy is just a type-system reflection of it.
32
+ //
33
+ // Capability markers are NOT declared on the `NumberSchema` class because
34
+ // they need to differ between the two factories without violating subclass
35
+ // override constraints:
36
+ // - `num()` returns `NumberSchema & { [Numeric]: true; [Continuous]: true }`
37
+ // — gets `.normal` / `.typically`, but NOT `.weighted` (continuous
38
+ // values can't be enumerated).
39
+ // - `int()` returns `IntSchema & { [Numeric]: true }` (with `[Discrete]`
40
+ // declared on the class) — gets `.weighted` and `.typically` (the
41
+ // latter clamps and rounds), but NOT `.normal` (Gaussian on integers
42
+ // would silently lose σ to rounding).
43
+ // - `decimal()` (in `./decimal.ts`) carries `[Numeric]` AND `[Continuous]`
44
+ // by class declaration, mirroring `num()`.
45
+ //
46
+ // `min` / `max` use `this`-typed returns (rather than the explicit class
47
+ // type) so the marker intersection is preserved through chains:
48
+ // `num().min(0).normal(0, 1)` ✓
49
+ // `int().min(1).max(5).weighted([...])` ✓
50
+ // ──────────────────────────────────────────────────────────────────────────
51
+ export class NumberSchema extends Schema {
52
+ min(n) {
53
+ return this.cloneWithNode({ ...this._node, min: n });
54
+ }
55
+ max(n) {
56
+ return this.cloneWithNode({ ...this._node, max: n });
57
+ }
58
+ cloneWithNode(node) {
59
+ const next = Object.create(Object.getPrototypeOf(this));
60
+ Object.assign(next, this, { _node: node });
61
+ return next;
62
+ }
63
+ }
64
+ /** `int()`-flavoured number — discrete, no Gaussian. Extends `NumberSchema`. */
65
+ export class IntSchema extends NumberSchema {
66
+ }
67
+ export const num = () => new NumberSchema({ kind: 'number', int: false });
68
+ export const int = () => new IntSchema({ kind: 'number', int: true });
69
+ // ──────────────────────────────────────────────────────────────────────────
70
+ // boolean / null
71
+ // ──────────────────────────────────────────────────────────────────────────
72
+ export class BooleanSchema extends Schema {
73
+ }
74
+ export class NullSchema extends Schema {
75
+ }
76
+ export const bool = () => new BooleanSchema({ kind: 'boolean' });
77
+ export const null_ = () => new NullSchema({ kind: 'null' });
78
+ //# sourceMappingURL=primitives.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitives.js","sourceRoot":"","s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E,IAAI,EAAE,MAAM,EAAE,CAAC,CAAA"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Validator — verify that a value conforms to a schema.
3
+ *
4
+ * `parse` throws ConformError. `safeParse` returns a discriminated result.
5
+ *
6
+ * Behavioral axes are enforced in addition to shape:
7
+ * - `domain` (`values` and `lookup`)
8
+ * - `invariants` (single-record) and `correlate` (multi-field, same axis)
9
+ * - `derived` (value must equal what `derivedFrom(...)` would compute)
10
+ */
11
+ import { ConformError } from '../foundation/errors.js';
12
+ import type { Infer, Schema } from '../foundation/types.js';
13
+ export type SafeParseResult<T> = {
14
+ readonly ok: true;
15
+ readonly value: T;
16
+ } | {
17
+ readonly ok: false;
18
+ readonly error: ConformError;
19
+ };
20
+ export declare const parse: <S extends Schema>(schema: S, value: unknown) => Infer<S>;
21
+ export declare const safeParse: <S extends Schema>(schema: S, value: unknown) => SafeParseResult<Infer<S>>;
22
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/validator/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,YAAY,EAAc,MAAM,yBAAyB,CAAA;AAElE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAE3D,MAAM,MAAM,eAAe,CAAC,CAAC,IACzB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GACxC;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;CAAE,CAAA;AAExD,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,OAAO,KAAG,KAAK,CAAC,CAAC,CAK1E,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,OAAO,KAAG,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAK/F,CAAA"}