smokin 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -0
- package/LICENSE +21 -0
- package/README.md +366 -0
- package/dist/dataset/dataset.d.ts +43 -0
- package/dist/dataset/dataset.d.ts.map +1 -0
- package/dist/dataset/dataset.js +63 -0
- package/dist/dataset/dataset.js.map +1 -0
- package/dist/dataset/relate.d.ts +32 -0
- package/dist/dataset/relate.d.ts.map +1 -0
- package/dist/dataset/relate.js +46 -0
- package/dist/dataset/relate.js.map +1 -0
- package/dist/foundation/axes.d.ts +92 -0
- package/dist/foundation/axes.d.ts.map +1 -0
- package/dist/foundation/axes.js +42 -0
- package/dist/foundation/axes.js.map +1 -0
- package/dist/foundation/errors.d.ts +30 -0
- package/dist/foundation/errors.d.ts.map +1 -0
- package/dist/foundation/errors.js +53 -0
- package/dist/foundation/errors.js.map +1 -0
- package/dist/foundation/hash.d.ts +16 -0
- package/dist/foundation/hash.d.ts.map +1 -0
- package/dist/foundation/hash.js +26 -0
- package/dist/foundation/hash.js.map +1 -0
- package/dist/foundation/ir.d.ts +79 -0
- package/dist/foundation/ir.d.ts.map +1 -0
- package/dist/foundation/ir.js +16 -0
- package/dist/foundation/ir.js.map +1 -0
- package/dist/foundation/prng.d.ts +27 -0
- package/dist/foundation/prng.d.ts.map +1 -0
- package/dist/foundation/prng.js +56 -0
- package/dist/foundation/prng.js.map +1 -0
- package/dist/foundation/types.d.ts +59 -0
- package/dist/foundation/types.d.ts.map +1 -0
- package/dist/foundation/types.js +99 -0
- package/dist/foundation/types.js.map +1 -0
- package/dist/foundation/walk.d.ts +43 -0
- package/dist/foundation/walk.d.ts.map +1 -0
- package/dist/foundation/walk.js +156 -0
- package/dist/foundation/walk.js.map +1 -0
- package/dist/generator/engine.d.ts +62 -0
- package/dist/generator/engine.d.ts.map +1 -0
- package/dist/generator/engine.js +369 -0
- package/dist/generator/engine.js.map +1 -0
- package/dist/generator/replay.d.ts +31 -0
- package/dist/generator/replay.d.ts.map +1 -0
- package/dist/generator/replay.js +66 -0
- package/dist/generator/replay.js.map +1 -0
- package/dist/generator/trace.d.ts +50 -0
- package/dist/generator/trace.d.ts.map +1 -0
- package/dist/generator/trace.js +39 -0
- package/dist/generator/trace.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/schema/composites.d.ts +91 -0
- package/dist/schema/composites.d.ts.map +1 -0
- package/dist/schema/composites.js +94 -0
- package/dist/schema/composites.js.map +1 -0
- package/dist/schema/conditional.d.ts +22 -0
- package/dist/schema/conditional.d.ts.map +1 -0
- package/dist/schema/conditional.js +29 -0
- package/dist/schema/conditional.js.map +1 -0
- package/dist/schema/decimal.d.ts +31 -0
- package/dist/schema/decimal.d.ts.map +1 -0
- package/dist/schema/decimal.js +39 -0
- package/dist/schema/decimal.js.map +1 -0
- package/dist/schema/primitives.d.ts +29 -0
- package/dist/schema/primitives.d.ts.map +1 -0
- package/dist/schema/primitives.js +44 -0
- package/dist/schema/primitives.js.map +1 -0
- package/dist/validator/parse.d.ts +17 -0
- package/dist/validator/parse.d.ts.map +1 -0
- package/dist/validator/parse.js +218 -0
- package/dist/validator/parse.js.map +1 -0
- package/package.json +59 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* smokin — 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
|
+
* smokin 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 } 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 { ConformError, SchemaConflictError } from './foundation/errors.js';
|
|
34
|
+
// ── extensibility (for third-party plugins) ───────────────────────────────
|
|
35
|
+
export { walkSchema, fromIR } from './foundation/walk.js';
|
|
36
|
+
export { mulberry32, rngFromString, seedFromString } from './foundation/prng.js';
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;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
+
* These produce TS types derived from their inputs via mapped / conditional
|
|
5
|
+
* types so that {@link Infer} yields the exact composite shape.
|
|
6
|
+
*/
|
|
7
|
+
import type { ArrayKind, EnumKind, LiteralKind, ObjectKind, TupleKind, UnionKind } from '../foundation/ir.js';
|
|
8
|
+
import { Schema, type Infer } from '../foundation/types.js';
|
|
9
|
+
type Fields = Record<string, Schema>;
|
|
10
|
+
/** Keys whose schema carries `optional: true` become optional in the output. */
|
|
11
|
+
type OptionalKeys<F extends Fields> = {
|
|
12
|
+
[K in keyof F]: F[K]['_node']['mods'] extends {
|
|
13
|
+
optional: true;
|
|
14
|
+
} ? K : never;
|
|
15
|
+
}[keyof F];
|
|
16
|
+
type RequiredKeys<F extends Fields> = Exclude<keyof F, OptionalKeys<F>>;
|
|
17
|
+
export type InferObject<F extends Fields> = {
|
|
18
|
+
[K in RequiredKeys<F>]: Infer<F[K]>;
|
|
19
|
+
} & {
|
|
20
|
+
[K in OptionalKeys<F>]?: Infer<F[K]>;
|
|
21
|
+
};
|
|
22
|
+
export declare class ObjectSchema<F extends Fields = Fields> extends Schema<{
|
|
23
|
+
[K in keyof InferObject<F>]: InferObject<F>[K];
|
|
24
|
+
}> {
|
|
25
|
+
readonly _node: ObjectKind & {
|
|
26
|
+
mods?: import('../foundation/ir.js').Modifiers;
|
|
27
|
+
};
|
|
28
|
+
readonly _fields: F;
|
|
29
|
+
constructor(fields: F);
|
|
30
|
+
/**
|
|
31
|
+
* Multi-field invariant (A5) — a predicate over the whole assembled object.
|
|
32
|
+
*
|
|
33
|
+
* Equivalent to `.invariant(...)` but typed against the object's inferred
|
|
34
|
+
* shape, so cross-field rules (e.g. `start <= end`) get full type-checking.
|
|
35
|
+
* The engine rejection-samples the object up to MAX_ATTEMPTS until the
|
|
36
|
+
* predicate holds.
|
|
37
|
+
*/
|
|
38
|
+
correlate(fn: (row: InferObject<F>) => boolean): this;
|
|
39
|
+
}
|
|
40
|
+
export declare const obj: <F extends Fields>(fields: F) => ObjectSchema<F>;
|
|
41
|
+
export declare class ArraySchema<S extends Schema> extends Schema<Infer<S>[]> {
|
|
42
|
+
readonly _node: ArrayKind & {
|
|
43
|
+
mods?: import('../foundation/ir.js').Modifiers;
|
|
44
|
+
};
|
|
45
|
+
readonly _item: S;
|
|
46
|
+
constructor(item: S, opts?: {
|
|
47
|
+
length?: number;
|
|
48
|
+
minLength?: number;
|
|
49
|
+
maxLength?: number;
|
|
50
|
+
});
|
|
51
|
+
length(n: number): ArraySchema<S>;
|
|
52
|
+
min(n: number): ArraySchema<S>;
|
|
53
|
+
max(n: number): ArraySchema<S>;
|
|
54
|
+
}
|
|
55
|
+
export declare const arr: <S extends Schema<unknown>>(item: S) => ArraySchema<S>;
|
|
56
|
+
type InferTuple<T extends readonly Schema[]> = {
|
|
57
|
+
[K in keyof T]: T[K] extends Schema ? Infer<T[K]> : never;
|
|
58
|
+
};
|
|
59
|
+
export declare class TupleSchema<T extends readonly Schema[]> extends Schema<InferTuple<T>> {
|
|
60
|
+
readonly _node: TupleKind & {
|
|
61
|
+
mods?: import('../foundation/ir.js').Modifiers;
|
|
62
|
+
};
|
|
63
|
+
readonly _items: T;
|
|
64
|
+
constructor(items: T);
|
|
65
|
+
}
|
|
66
|
+
export declare const tuple: <T extends readonly Schema<unknown>[]>(...items: T) => TupleSchema<T>;
|
|
67
|
+
type InferUnion<T extends readonly Schema[]> = T[number] extends Schema ? Infer<T[number]> : never;
|
|
68
|
+
export declare class UnionSchema<T extends readonly Schema[]> extends Schema<InferUnion<T>> {
|
|
69
|
+
readonly _node: UnionKind & {
|
|
70
|
+
mods?: import('../foundation/ir.js').Modifiers;
|
|
71
|
+
};
|
|
72
|
+
readonly _options: T;
|
|
73
|
+
constructor(options: T);
|
|
74
|
+
}
|
|
75
|
+
export declare const union: <T extends readonly Schema<unknown>[]>(...options: T) => UnionSchema<T>;
|
|
76
|
+
export declare class LiteralSchema<V extends string | number | boolean | null> extends Schema<V> {
|
|
77
|
+
readonly _node: LiteralKind & {
|
|
78
|
+
mods?: import('../foundation/ir.js').Modifiers;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export declare const literal: <V extends string | number | boolean | null>(value: V) => LiteralSchema<V>;
|
|
82
|
+
export declare class EnumSchema<V extends string | number> extends Schema<V> {
|
|
83
|
+
readonly _node: EnumKind & {
|
|
84
|
+
mods?: import('../foundation/ir.js').Modifiers;
|
|
85
|
+
};
|
|
86
|
+
readonly _values: readonly V[];
|
|
87
|
+
constructor(values: readonly V[]);
|
|
88
|
+
}
|
|
89
|
+
export declare const enum_: <V extends string | number>(values: readonly V[]) => EnumSchema<V>;
|
|
90
|
+
export {};
|
|
91
|
+
//# sourceMappingURL=composites.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composites.d.ts","sourceRoot":"","sources":["../../src/schema/composites.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,QAAQ,EACR,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACV,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAM3D,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAEpC,gFAAgF;AAChF,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI;KACnC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,SAAS;QAAE,QAAQ,EAAE,IAAI,CAAA;KAAE,GAAG,CAAC,GAAG,KAAK;CAC7E,CAAC,MAAM,CAAC,CAAC,CAAA;AAEV,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;AAEvE,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,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O,EAAE,CAAC;CAOvB;AAED,eAAO,MAAM,KAAK,qDAA6C,CAAC,KAAG,YAAY,CAAC,CACtD,CAAA;AAM1B,qBAAa,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAE,SAAQ,MAAM,CAAC,CAAC,CAAC;IACtF,SAAiB,KAAK,EAAE,WAAW,GAAG;QAAE,IAAI,CAAC,EAAE,OAAO,qBAAqB,EAAE,SAAS,CAAA;KAAE,CAAA;CACzF;AAED,eAAO,MAAM,OAAO,sDAAuD,CAAC,KAAG,cAAc,CAAC,CAC/C,CAAA;AAE/C,qBAAa,UAAU,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,MAAM,CAAC,CAAC,CAAC;IAClE,SAAiB,KAAK,EAAE,QAAQ,GAAG;QAAE,IAAI,CAAC,EAAE,OAAO,qBAAqB,EAAE,SAAS,CAAA;KAAE,CAAA;IACrF,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,CAAA;gBAElB,MAAM,EAAE,SAAS,CAAC,EAAE;CAOjC;AAED,eAAO,MAAM,KAAK,sCAAuC,SAAS,CAAC,EAAE,KAAG,WAAW,CAAC,CAC5D,CAAA"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composite schema builders: obj, arr, tuple, union, literal, enum_.
|
|
3
|
+
*
|
|
4
|
+
* These produce TS types derived from their inputs via mapped / conditional
|
|
5
|
+
* types so that {@link Infer} yields the exact composite shape.
|
|
6
|
+
*/
|
|
7
|
+
import { Schema } from '../foundation/types.js';
|
|
8
|
+
export class ObjectSchema extends Schema {
|
|
9
|
+
_fields;
|
|
10
|
+
constructor(fields) {
|
|
11
|
+
const irFields = {};
|
|
12
|
+
for (const k of Object.keys(fields)) {
|
|
13
|
+
irFields[k] = fields[k]._node;
|
|
14
|
+
}
|
|
15
|
+
super({ kind: 'object', fields: irFields });
|
|
16
|
+
this._fields = fields;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Multi-field invariant (A5) — a predicate over the whole assembled object.
|
|
20
|
+
*
|
|
21
|
+
* Equivalent to `.invariant(...)` but typed against the object's inferred
|
|
22
|
+
* shape, so cross-field rules (e.g. `start <= end`) get full type-checking.
|
|
23
|
+
* The engine rejection-samples the object up to MAX_ATTEMPTS until the
|
|
24
|
+
* predicate holds.
|
|
25
|
+
*/
|
|
26
|
+
correlate(fn) {
|
|
27
|
+
return this.invariant((v) => fn(v));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export const obj = (fields) => new ObjectSchema(fields);
|
|
31
|
+
// ──────────────────────────────────────────────────────────────────────────
|
|
32
|
+
// array
|
|
33
|
+
// ──────────────────────────────────────────────────────────────────────────
|
|
34
|
+
export class ArraySchema extends Schema {
|
|
35
|
+
_item;
|
|
36
|
+
constructor(item, opts = {}) {
|
|
37
|
+
const base = {
|
|
38
|
+
kind: 'array',
|
|
39
|
+
item: item._node,
|
|
40
|
+
...(opts.length !== undefined ? { length: opts.length } : {}),
|
|
41
|
+
...(opts.minLength !== undefined ? { minLength: opts.minLength } : {}),
|
|
42
|
+
...(opts.maxLength !== undefined ? { maxLength: opts.maxLength } : {}),
|
|
43
|
+
};
|
|
44
|
+
super(base);
|
|
45
|
+
this._item = item;
|
|
46
|
+
}
|
|
47
|
+
length(n) {
|
|
48
|
+
return new ArraySchema(this._item, { length: n });
|
|
49
|
+
}
|
|
50
|
+
min(n) {
|
|
51
|
+
return new ArraySchema(this._item, { minLength: n });
|
|
52
|
+
}
|
|
53
|
+
max(n) {
|
|
54
|
+
return new ArraySchema(this._item, { maxLength: n });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export const arr = (item) => new ArraySchema(item);
|
|
58
|
+
export class TupleSchema extends Schema {
|
|
59
|
+
_items;
|
|
60
|
+
constructor(items) {
|
|
61
|
+
super({ kind: 'tuple', items: items.map((s) => s._node) });
|
|
62
|
+
this._items = items;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export const tuple = (...items) => new TupleSchema(items);
|
|
66
|
+
export class UnionSchema extends Schema {
|
|
67
|
+
_options;
|
|
68
|
+
constructor(options) {
|
|
69
|
+
if (options.length === 0) {
|
|
70
|
+
throw new RangeError('union: requires at least one option');
|
|
71
|
+
}
|
|
72
|
+
super({ kind: 'union', options: options.map((s) => s._node) });
|
|
73
|
+
this._options = options;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export const union = (...options) => new UnionSchema(options);
|
|
77
|
+
// ──────────────────────────────────────────────────────────────────────────
|
|
78
|
+
// literal / enum
|
|
79
|
+
// ──────────────────────────────────────────────────────────────────────────
|
|
80
|
+
export class LiteralSchema extends Schema {
|
|
81
|
+
}
|
|
82
|
+
export const literal = (value) => new LiteralSchema({ kind: 'literal', value });
|
|
83
|
+
export class EnumSchema extends Schema {
|
|
84
|
+
_values;
|
|
85
|
+
constructor(values) {
|
|
86
|
+
if (values.length === 0) {
|
|
87
|
+
throw new RangeError('enum: requires at least one value');
|
|
88
|
+
}
|
|
89
|
+
super({ kind: 'enum', values });
|
|
90
|
+
this._values = values;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export const enum_ = (values) => new EnumSchema(values);
|
|
94
|
+
//# sourceMappingURL=composites.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composites.js","sourceRoot":"","sources":["../../src/schema/composites.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,OAAO,EAAE,MAAM,EAAc,MAAM,wBAAwB,CAAA;AAqB3D,MAAM,OAAO,YAAwC,SAAQ,MAG5D;IAEU,OAAO,CAAG;IAEnB,YAAY,MAAS;QACnB,MAAM,QAAQ,GAA6D,EAAE,CAAA;QAC7E,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YACpC,QAAQ,CAAC,CAAC,CAAC,GAAI,MAAM,CAAC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AAC,QAAQ,GAAG,OAAO,CAAA;IACzB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,CAA8B,GAAG,OAAU,EAAkB,EAAE,CAClF,IAAI,WAAW,CAAC,OAAO,CAAC,CAAA;AAE1B,6EAA6E;AAC7E,iBAAiB;AACjB,6EAA6E;AAE7E,MAAM,OAAO,aAA0D,SAAQ,MAAS;CAEvF;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAA6C,KAAQ,EAAoB,EAAE,CAChG,IAAI,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAA;AAE/C,MAAM,OAAO,UAAsC,SAAQ,MAAS;IAEzD,OAAO,CAAc;IAE9B,YAAY,MAAoB;QAC9B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,UAAU,CAAC,mCAAmC,CAAC,CAAA;QAC3D,CAAC;QACD,KAAK,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;IACvB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,CAA4B,MAAoB,EAAiB,EAAE,CACtF,IAAI,UAAU,CAAC,MAAM,CAAC,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discriminated union (Z_PLAN §4.5.6 — Conditional).
|
|
3
|
+
*
|
|
4
|
+
* `discriminated(key, map)` builds a union schema whose branches are selected
|
|
5
|
+
* by the value of the named discriminator field, both during generation and
|
|
6
|
+
* during validation.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const Fuel = discriminated('kind', {
|
|
10
|
+
* gas: obj({ kind: literal('gas'), heating_value: decimal(10, 4) }),
|
|
11
|
+
* liquid: obj({ kind: literal('liquid'), density: decimal(10, 4) }),
|
|
12
|
+
* })
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
import type { Infer, Schema } from '../foundation/types.js';
|
|
16
|
+
/**
|
|
17
|
+
* Build a discriminated union keyed on `key`. Each value in `map` must be a
|
|
18
|
+
* schema (typically `obj({...})`) whose `key` field is a `literal(...)`
|
|
19
|
+
* matching the map key.
|
|
20
|
+
*/
|
|
21
|
+
export declare const discriminated: <K extends string, M extends Readonly<Record<string, Schema<unknown>>>>(key: K, map: M) => Schema<{ [P in keyof M]: Infer<M[P]>; }[keyof M]>;
|
|
22
|
+
//# sourceMappingURL=conditional.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditional.d.ts","sourceRoot":"","sources":["../../src/schema/conditional.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAG3D;;;;GAIG;AACH,eAAO,MAAM,aAAa,+EAMnB,CAAC,OACD,CAAC,sDAQP,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discriminated union (Z_PLAN §4.5.6 — Conditional).
|
|
3
|
+
*
|
|
4
|
+
* `discriminated(key, map)` builds a union schema whose branches are selected
|
|
5
|
+
* by the value of the named discriminator field, both during generation and
|
|
6
|
+
* during validation.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const Fuel = discriminated('kind', {
|
|
10
|
+
* gas: obj({ kind: literal('gas'), heating_value: decimal(10, 4) }),
|
|
11
|
+
* liquid: obj({ kind: literal('liquid'), density: decimal(10, 4) }),
|
|
12
|
+
* })
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
import { UnionSchema } from './composites.js';
|
|
16
|
+
/**
|
|
17
|
+
* Build a discriminated union keyed on `key`. Each value in `map` must be a
|
|
18
|
+
* schema (typically `obj({...})`) whose `key` field is a `literal(...)`
|
|
19
|
+
* matching the map key.
|
|
20
|
+
*/
|
|
21
|
+
export const discriminated = (key, map) => {
|
|
22
|
+
const options = Object.values(map);
|
|
23
|
+
if (options.length === 0) {
|
|
24
|
+
throw new Error(`discriminated("${key}"): map must contain at least one branch`);
|
|
25
|
+
}
|
|
26
|
+
void key;
|
|
27
|
+
return new UnionSchema(options);
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=conditional.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditional.js","sourceRoot":"","sources":["../../src/schema/conditional.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAM3B,GAAM,EACN,GAAM,EAC4C,EAAE;IACpD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAA+B,CAAA;IAChE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,kBAAkB,GAAG,0CAA0C,CAAC,CAAA;IAClF,CAAC;IACD,KAAK,GAAG,CAAA;IACR,OAAO,IAAI,WAAW,CAAC,OAAO,CAAgE,CAAA;AAChG,CAAC,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
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; smokin 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 { Schema } from '../foundation/types.js';
|
|
15
|
+
export declare class DecimalSchema extends Schema<string> {
|
|
16
|
+
readonly _node: DecimalKind & {
|
|
17
|
+
mods?: Modifiers;
|
|
18
|
+
};
|
|
19
|
+
/** Inclusive lower bound. Pass as a numeric string. */
|
|
20
|
+
min(value: string | number): DecimalSchema;
|
|
21
|
+
/** Inclusive upper bound. Pass as a numeric string. */
|
|
22
|
+
max(value: string | number): DecimalSchema;
|
|
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 declare const decimal: (precision: number, scale: number) => DecimalSchema;
|
|
31
|
+
//# 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,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAE/C,qBAAa,aAAc,SAAQ,MAAM,CAAC,MAAM,CAAC;IAC/C,SAAiB,KAAK,EAAE,WAAW,GAAG;QAAE,IAAI,CAAC,EAAE,SAAS,CAAA;KAAE,CAAA;IAE1D,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,cAAe,MAAM,SAAS,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; smokin intentionally avoids forcing a brand to keep
|
|
11
|
+
* `decimal().default('0.0')` and JSON round-trips friction-free.
|
|
12
|
+
*/
|
|
13
|
+
import { 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, sc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
|
+
/**
|
|
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 { NumberKind, StringKind } from '../foundation/ir.js';
|
|
8
|
+
import { Schema } from '../foundation/types.js';
|
|
9
|
+
export declare class StringSchema extends Schema<string> {
|
|
10
|
+
readonly _node: StringKind & {
|
|
11
|
+
mods?: import('../foundation/ir.js').Modifiers;
|
|
12
|
+
};
|
|
13
|
+
min(n: number): StringSchema;
|
|
14
|
+
max(n: number): StringSchema;
|
|
15
|
+
pattern(re: RegExp | string): StringSchema;
|
|
16
|
+
}
|
|
17
|
+
export declare const str: () => StringSchema;
|
|
18
|
+
export declare class NumberSchema extends Schema<number> {
|
|
19
|
+
readonly _node: NumberKind & {
|
|
20
|
+
mods?: import('../foundation/ir.js').Modifiers;
|
|
21
|
+
};
|
|
22
|
+
min(n: number): NumberSchema;
|
|
23
|
+
max(n: number): NumberSchema;
|
|
24
|
+
}
|
|
25
|
+
export declare const num: () => NumberSchema;
|
|
26
|
+
export declare const int: () => NumberSchema;
|
|
27
|
+
export declare const bool: () => Schema<boolean>;
|
|
28
|
+
export declare const null_: () => Schema<null>;
|
|
29
|
+
//# 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,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAM/C,qBAAa,YAAa,SAAQ,MAAM,CAAC,MAAM,CAAC;IAC9C,SAAiB,KAAK,EAAE,UAAU,GAAG;QAAE,IAAI,CAAC,EAAE,OAAO,qBAAqB,EAAE,SAAS,CAAA;KAAE,CAAA;IAEvF,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;AAMvD,qBAAa,YAAa,SAAQ,MAAM,CAAC,MAAM,CAAC;IAC9C,SAAiB,KAAK,EAAE,UAAU,GAAG;QAAE,IAAI,CAAC,EAAE,OAAO,qBAAqB,EAAE,SAAS,CAAA;KAAE,CAAA;IAEvF,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,YAAY;IAG5B,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,YAAY;CAG7B;AAED,eAAO,MAAM,GAAG,QAAO,YAC2B,CAAA;AAElD,eAAO,MAAM,GAAG,QAAO,YAC0B,CAAA;AAMjD,eAAO,MAAM,IAAI,QAAO,OAAO,OAAO,CAA6C,CAAA;AAEnF,eAAO,MAAM,KAAK,QAAO,OAAO,IAAI,CAAuC,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
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 { 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
|
+
export class NumberSchema extends Schema {
|
|
30
|
+
min(n) {
|
|
31
|
+
return new NumberSchema({ ...this._node, min: n });
|
|
32
|
+
}
|
|
33
|
+
max(n) {
|
|
34
|
+
return new NumberSchema({ ...this._node, max: n });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export const num = () => new NumberSchema({ kind: 'number', int: false });
|
|
38
|
+
export const int = () => new NumberSchema({ kind: 'number', int: true });
|
|
39
|
+
// ──────────────────────────────────────────────────────────────────────────
|
|
40
|
+
// boolean / null
|
|
41
|
+
// ──────────────────────────────────────────────────────────────────────────
|
|
42
|
+
export const bool = () => new Schema({ kind: 'boolean' });
|
|
43
|
+
export const null_ = () => new Schema({ kind: 'null' });
|
|
44
|
+
//# sourceMappingURL=primitives.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../src/schema/primitives.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAE/C,6EAA6E;AAC7E,SAAS;AACT,6EAA6E;AAE7E,MAAM,OAAO,YAAa,SAAQ,MAAc;IAG9C,GAAG,CAAC,CAAS;QACX,OAAO,IAAI,YAAY,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;IACpD,CAAC;IACD,GAAG,CAAC,CAAS;QACX,OAAO,IAAI,YAAY,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE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GAAG,GAAiB,EAAE,CAAC,IAAI,MAAM,CAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validator — verify that a value conforms to a schema.
|
|
3
|
+
*
|
|
4
|
+
* `parse` throws ConformError. `safeParse` returns a discriminated result.
|
|
5
|
+
*/
|
|
6
|
+
import { ConformError } from '../foundation/errors.js';
|
|
7
|
+
import type { Infer, Schema } from '../foundation/types.js';
|
|
8
|
+
export type SafeParseResult<T> = {
|
|
9
|
+
readonly ok: true;
|
|
10
|
+
readonly value: T;
|
|
11
|
+
} | {
|
|
12
|
+
readonly ok: false;
|
|
13
|
+
readonly error: ConformError;
|
|
14
|
+
};
|
|
15
|
+
export declare const parse: <S extends Schema<unknown>>(schema: S, value: unknown) => Infer<S>;
|
|
16
|
+
export declare const safeParse: <S extends Schema<unknown>>(schema: S, value: unknown) => SafeParseResult<Infer<S>>;
|
|
17
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/validator/parse.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,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,sCAA8B,CAAC,SAAS,OAAO,KAAG,MAAM,CAAC,CAK1E,CAAA;AAED,eAAO,MAAM,SAAS,sCAA8B,CAAC,SAAS,OAAO,KAAG,gBAAgB,MAAM,CAAC,CAAC,CAK/F,CAAA"}
|