typesea 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +85 -6
- package/README.md +143 -28
- package/dist/adapters/index.d.ts +50 -8
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +169 -48
- package/dist/aot/index.d.ts +19 -3
- package/dist/aot/index.d.ts.map +1 -1
- package/dist/aot/index.js +115 -17
- package/dist/async/index.d.ts +28 -56
- package/dist/async/index.d.ts.map +1 -1
- package/dist/async/index.js +94 -37
- package/dist/builders/composite.d.ts +43 -9
- package/dist/builders/composite.d.ts.map +1 -1
- package/dist/builders/composite.js +100 -17
- package/dist/builders/index.d.ts +8 -5
- package/dist/builders/index.d.ts.map +1 -1
- package/dist/builders/index.js +7 -4
- package/dist/builders/modifier.d.ts +36 -5
- package/dist/builders/modifier.d.ts.map +1 -1
- package/dist/builders/modifier.js +52 -5
- package/dist/builders/object/guard.d.ts +72 -24
- package/dist/builders/object/guard.d.ts.map +1 -1
- package/dist/builders/object/guard.js +139 -29
- package/dist/builders/object/index.d.ts +4 -2
- package/dist/builders/object/index.d.ts.map +1 -1
- package/dist/builders/object/index.js +3 -1
- package/dist/builders/object/schema.d.ts +88 -11
- package/dist/builders/object/schema.d.ts.map +1 -1
- package/dist/builders/object/schema.js +290 -23
- package/dist/builders/object/types.d.ts +20 -31
- package/dist/builders/object/types.d.ts.map +1 -1
- package/dist/builders/object/types.js +2 -0
- package/dist/builders/runtime.d.ts +40 -0
- package/dist/builders/runtime.d.ts.map +1 -0
- package/dist/builders/runtime.js +150 -0
- package/dist/builders/scalar.d.ts +49 -9
- package/dist/builders/scalar.d.ts.map +1 -1
- package/dist/builders/scalar.js +87 -9
- package/dist/builders/table.d.ts +35 -5
- package/dist/builders/table.d.ts.map +1 -1
- package/dist/builders/table.js +35 -5
- package/dist/builders/types.d.ts +20 -4
- package/dist/builders/types.d.ts.map +1 -1
- package/dist/builders/types.js +2 -0
- package/dist/compile/check-composite.d.ts +25 -2
- package/dist/compile/check-composite.d.ts.map +1 -1
- package/dist/compile/check-composite.js +699 -27
- package/dist/compile/check-scalar.d.ts +88 -0
- package/dist/compile/check-scalar.d.ts.map +1 -1
- package/dist/compile/check-scalar.js +570 -3
- package/dist/compile/check.d.ts +12 -0
- package/dist/compile/check.d.ts.map +1 -1
- package/dist/compile/check.js +62 -3
- package/dist/compile/context.d.ts +47 -9
- package/dist/compile/context.d.ts.map +1 -1
- package/dist/compile/context.js +53 -8
- package/dist/compile/first.d.ts +26 -0
- package/dist/compile/first.d.ts.map +1 -0
- package/dist/compile/first.js +850 -0
- package/dist/compile/graph-predicate.d.ts +4 -2
- package/dist/compile/graph-predicate.d.ts.map +1 -1
- package/dist/compile/graph-predicate.js +2272 -165
- package/dist/compile/guard.d.ts +16 -24
- package/dist/compile/guard.d.ts.map +1 -1
- package/dist/compile/guard.js +202 -72
- package/dist/compile/index.d.ts +3 -1
- package/dist/compile/index.d.ts.map +1 -1
- package/dist/compile/index.js +2 -0
- package/dist/compile/issue.d.ts +110 -0
- package/dist/compile/issue.d.ts.map +1 -1
- package/dist/compile/issue.js +184 -1
- package/dist/compile/names.d.ts +12 -2
- package/dist/compile/names.d.ts.map +1 -1
- package/dist/compile/names.js +19 -3
- package/dist/compile/predicate.d.ts +24 -0
- package/dist/compile/predicate.d.ts.map +1 -1
- package/dist/compile/predicate.js +287 -10
- package/dist/compile/runtime.d.ts +100 -13
- package/dist/compile/runtime.d.ts.map +1 -1
- package/dist/compile/runtime.js +56 -6
- package/dist/compile/source.d.ts +10 -2
- package/dist/compile/source.d.ts.map +1 -1
- package/dist/compile/source.js +385 -26
- package/dist/compile/types.d.ts +22 -0
- package/dist/compile/types.d.ts.map +1 -1
- package/dist/compile/types.js +2 -0
- package/dist/decoder/index.d.ts +92 -46
- package/dist/decoder/index.d.ts.map +1 -1
- package/dist/decoder/index.js +266 -39
- package/dist/evaluate/check-composite.d.ts +111 -2
- package/dist/evaluate/check-composite.d.ts.map +1 -1
- package/dist/evaluate/check-composite.js +343 -8
- package/dist/evaluate/check-scalar.d.ts +25 -0
- package/dist/evaluate/check-scalar.d.ts.map +1 -1
- package/dist/evaluate/check-scalar.js +124 -3
- package/dist/evaluate/check.d.ts +7 -0
- package/dist/evaluate/check.d.ts.map +1 -1
- package/dist/evaluate/check.js +62 -4
- package/dist/evaluate/index.d.ts +2 -0
- package/dist/evaluate/index.d.ts.map +1 -1
- package/dist/evaluate/index.js +2 -0
- package/dist/evaluate/issue.d.ts +11 -1
- package/dist/evaluate/issue.d.ts.map +1 -1
- package/dist/evaluate/issue.js +15 -1
- package/dist/evaluate/predicate.d.ts +16 -5
- package/dist/evaluate/predicate.d.ts.map +1 -1
- package/dist/evaluate/predicate.js +20 -5
- package/dist/evaluate/shared.d.ts +78 -13
- package/dist/evaluate/shared.d.ts.map +1 -1
- package/dist/evaluate/shared.js +101 -8
- package/dist/evaluate/state.d.ts +35 -13
- package/dist/evaluate/state.d.ts.map +1 -1
- package/dist/evaluate/state.js +35 -2
- package/dist/guard/array.d.ts +48 -0
- package/dist/guard/array.d.ts.map +1 -0
- package/dist/guard/array.js +84 -0
- package/dist/guard/base.d.ts +111 -31
- package/dist/guard/base.d.ts.map +1 -1
- package/dist/guard/base.js +165 -32
- package/dist/guard/date.d.ts +34 -0
- package/dist/guard/date.d.ts.map +1 -0
- package/dist/guard/date.js +60 -0
- package/dist/guard/error.d.ts +10 -5
- package/dist/guard/error.d.ts.map +1 -1
- package/dist/guard/error.js +10 -5
- package/dist/guard/index.d.ts +4 -0
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +4 -0
- package/dist/guard/number.d.ts +86 -11
- package/dist/guard/number.d.ts.map +1 -1
- package/dist/guard/number.js +159 -11
- package/dist/guard/props.d.ts +27 -3
- package/dist/guard/props.d.ts.map +1 -1
- package/dist/guard/props.js +27 -3
- package/dist/guard/read.d.ts +115 -10
- package/dist/guard/read.d.ts.map +1 -1
- package/dist/guard/read.js +185 -10
- package/dist/guard/registry.d.ts +12 -2
- package/dist/guard/registry.d.ts.map +1 -1
- package/dist/guard/registry.js +15 -3
- package/dist/guard/string.d.ts +115 -13
- package/dist/guard/string.d.ts.map +1 -1
- package/dist/guard/string.js +250 -13
- package/dist/guard/types.d.ts +110 -40
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/guard/types.js +2 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/internal/index.d.ts +42 -6
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +51 -8
- package/dist/ir/builder.d.ts +17 -127
- package/dist/ir/builder.d.ts.map +1 -1
- package/dist/ir/builder.js +80 -137
- package/dist/ir/freeze.d.ts +4 -0
- package/dist/ir/freeze.d.ts.map +1 -1
- package/dist/ir/freeze.js +66 -0
- package/dist/ir/index.d.ts +3 -1
- package/dist/ir/index.d.ts.map +1 -1
- package/dist/ir/index.js +2 -0
- package/dist/ir/regexp.d.ts +2 -0
- package/dist/ir/regexp.d.ts.map +1 -1
- package/dist/ir/regexp.js +2 -0
- package/dist/ir/types.d.ts +94 -56
- package/dist/ir/types.d.ts.map +1 -1
- package/dist/ir/types.js +2 -0
- package/dist/ir/validate.d.ts +8 -1
- package/dist/ir/validate.d.ts.map +1 -1
- package/dist/ir/validate.js +511 -61
- package/dist/issue/index.d.ts +42 -10
- package/dist/issue/index.d.ts.map +1 -1
- package/dist/issue/index.js +65 -11
- package/dist/json-schema/emit-combinator.d.ts +44 -4
- package/dist/json-schema/emit-combinator.d.ts.map +1 -1
- package/dist/json-schema/emit-combinator.js +44 -4
- package/dist/json-schema/emit-composite.d.ts +16 -2
- package/dist/json-schema/emit-composite.d.ts.map +1 -1
- package/dist/json-schema/emit-composite.js +81 -13
- package/dist/json-schema/emit-scalar.d.ts +26 -3
- package/dist/json-schema/emit-scalar.d.ts.map +1 -1
- package/dist/json-schema/emit-scalar.js +124 -10
- package/dist/json-schema/emit-types.d.ts +11 -1
- package/dist/json-schema/emit-types.d.ts.map +1 -1
- package/dist/json-schema/emit-types.js +2 -0
- package/dist/json-schema/emit.d.ts +12 -1
- package/dist/json-schema/emit.d.ts.map +1 -1
- package/dist/json-schema/emit.js +23 -3
- package/dist/json-schema/freeze.d.ts +13 -2
- package/dist/json-schema/freeze.d.ts.map +1 -1
- package/dist/json-schema/freeze.js +41 -8
- package/dist/json-schema/index.d.ts +16 -2
- package/dist/json-schema/index.d.ts.map +1 -1
- package/dist/json-schema/index.js +23 -3
- package/dist/json-schema/issue.d.ts +4 -1
- package/dist/json-schema/issue.d.ts.map +1 -1
- package/dist/json-schema/issue.js +4 -1
- package/dist/json-schema/read.d.ts +24 -3
- package/dist/json-schema/read.d.ts.map +1 -1
- package/dist/json-schema/read.js +59 -12
- package/dist/json-schema/types.d.ts +45 -16
- package/dist/json-schema/types.d.ts.map +1 -1
- package/dist/json-schema/types.js +2 -0
- package/dist/kind/index.d.ts +40 -28
- package/dist/kind/index.d.ts.map +1 -1
- package/dist/kind/index.js +41 -13
- package/dist/lower/index.d.ts +6 -1
- package/dist/lower/index.d.ts.map +1 -1
- package/dist/lower/index.js +462 -46
- package/dist/message/index.d.ts +64 -10
- package/dist/message/index.d.ts.map +1 -1
- package/dist/message/index.js +155 -17
- package/dist/optimize/algebraic.d.ts +54 -0
- package/dist/optimize/algebraic.d.ts.map +1 -0
- package/dist/optimize/algebraic.js +314 -0
- package/dist/optimize/compact.d.ts +8 -1
- package/dist/optimize/compact.d.ts.map +1 -1
- package/dist/optimize/compact.js +13 -2
- package/dist/optimize/domain.d.ts +16 -0
- package/dist/optimize/domain.d.ts.map +1 -0
- package/dist/optimize/domain.js +619 -0
- package/dist/optimize/fold-boolean.d.ts +17 -2
- package/dist/optimize/fold-boolean.d.ts.map +1 -1
- package/dist/optimize/fold-boolean.js +59 -14
- package/dist/optimize/fold-common.d.ts +43 -8
- package/dist/optimize/fold-common.d.ts.map +1 -1
- package/dist/optimize/fold-common.js +37 -6
- package/dist/optimize/fold-constraints.d.ts +33 -0
- package/dist/optimize/fold-constraints.d.ts.map +1 -0
- package/dist/optimize/fold-constraints.js +484 -0
- package/dist/optimize/fold-scalar.d.ts +98 -13
- package/dist/optimize/fold-scalar.d.ts.map +1 -1
- package/dist/optimize/fold-scalar.js +98 -13
- package/dist/optimize/fold.d.ts +8 -1
- package/dist/optimize/fold.d.ts.map +1 -1
- package/dist/optimize/fold.js +22 -2
- package/dist/optimize/index.d.ts +9 -1
- package/dist/optimize/index.d.ts.map +1 -1
- package/dist/optimize/index.js +18 -3
- package/dist/optimize/map-node.d.ts +3 -1
- package/dist/optimize/map-node.d.ts.map +1 -1
- package/dist/optimize/map-node.js +48 -3
- package/dist/optimize/peephole.d.ts +16 -0
- package/dist/optimize/peephole.d.ts.map +1 -0
- package/dist/optimize/peephole.js +254 -0
- package/dist/optimize/remap.d.ts +2 -0
- package/dist/optimize/remap.d.ts.map +1 -1
- package/dist/optimize/remap.js +2 -0
- package/dist/optimize/rewrite.d.ts +13 -8
- package/dist/optimize/rewrite.d.ts.map +1 -1
- package/dist/optimize/rewrite.js +13 -8
- package/dist/plan/cache.d.ts +9 -3
- package/dist/plan/cache.d.ts.map +1 -1
- package/dist/plan/cache.js +34 -6
- package/dist/plan/index.d.ts +2 -0
- package/dist/plan/index.d.ts.map +1 -1
- package/dist/plan/index.js +2 -0
- package/dist/plan/predicate.d.ts +2 -0
- package/dist/plan/predicate.d.ts.map +1 -1
- package/dist/plan/predicate.js +298 -29
- package/dist/plan/schema-predicate.d.ts +6 -0
- package/dist/plan/schema-predicate.d.ts.map +1 -1
- package/dist/plan/schema-predicate.js +382 -19
- package/dist/plan/types.d.ts +2 -0
- package/dist/plan/types.d.ts.map +1 -1
- package/dist/plan/types.js +2 -0
- package/dist/result/index.d.ts +19 -5
- package/dist/result/index.d.ts.map +1 -1
- package/dist/result/index.js +10 -2
- package/dist/schema/common.d.ts +69 -6
- package/dist/schema/common.d.ts.map +1 -1
- package/dist/schema/common.js +104 -10
- package/dist/schema/freeze.d.ts +4 -0
- package/dist/schema/freeze.d.ts.map +1 -1
- package/dist/schema/freeze.js +40 -0
- package/dist/schema/index.d.ts +5 -2
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +4 -1
- package/dist/schema/lazy.d.ts +4 -0
- package/dist/schema/lazy.d.ts.map +1 -1
- package/dist/schema/lazy.js +4 -0
- package/dist/schema/literal.d.ts +7 -1
- package/dist/schema/literal.d.ts.map +1 -1
- package/dist/schema/literal.js +7 -1
- package/dist/schema/types.d.ts +109 -100
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/types.js +13 -2
- package/dist/schema/undefined.d.ts +17 -0
- package/dist/schema/undefined.d.ts.map +1 -0
- package/dist/schema/undefined.js +77 -0
- package/dist/schema/validate.d.ts +8 -1
- package/dist/schema/validate.d.ts.map +1 -1
- package/dist/schema/validate.js +255 -57
- package/docs/api.md +128 -8
- package/docs/assets/benchmark-headline.svg +163 -0
- package/docs/engine-notes.md +62 -15
- package/docs/index.html +1340 -702
- package/docs/ko/api.md +375 -0
- package/docs/ko/engine-notes.md +156 -0
- package/docs/ko/readme.md +378 -0
- package/package.json +66 -65
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file runtime.ts
|
|
3
|
+
* @brief Runtime-object guard builders.
|
|
4
|
+
* @details These builders describe JavaScript object domains that JSON Schema
|
|
5
|
+
* and AOT source cannot faithfully serialize.
|
|
6
|
+
*/
|
|
7
|
+
import { BaseGuard, type Guard, type Infer, type Presence } from "../guard/index.js";
|
|
8
|
+
export type InstanceConstructor<TValue> = abstract new (...args: never[]) => TValue;
|
|
9
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
10
|
+
export interface JsonArray {
|
|
11
|
+
readonly length: number;
|
|
12
|
+
readonly [index: number]: JsonValue;
|
|
13
|
+
}
|
|
14
|
+
export interface JsonObject {
|
|
15
|
+
readonly [key: string]: JsonValue;
|
|
16
|
+
}
|
|
17
|
+
export type JsonValue = JsonPrimitive | JsonArray | JsonObject;
|
|
18
|
+
/**
|
|
19
|
+
* @brief Build a guard backed by ordinary instanceof semantics.
|
|
20
|
+
* @param constructor Constructor function used as the instance domain.
|
|
21
|
+
* @returns Fresh guard accepting values whose prototype chain matches constructor.
|
|
22
|
+
* @throws TypeError when constructor is not callable.
|
|
23
|
+
*/
|
|
24
|
+
export declare function instanceOf<TValue>(constructor: InstanceConstructor<TValue>): BaseGuard<TValue>;
|
|
25
|
+
/**
|
|
26
|
+
* @brief Require one own data property after a base guard succeeds.
|
|
27
|
+
* @param base Guard applied to the candidate value first.
|
|
28
|
+
* @param key Own string property key to inspect.
|
|
29
|
+
* @param value Guard applied to the property value.
|
|
30
|
+
* @returns Fresh guard preserving the base domain and recording the property type.
|
|
31
|
+
*/
|
|
32
|
+
export declare function property<TBase extends Guard<unknown, Presence>, const TKey extends string, TValue extends Guard<unknown, Presence>>(base: TBase, key: TKey, value: TValue): BaseGuard<Infer<TBase> & Readonly<Record<TKey, Infer<TValue>>>>;
|
|
33
|
+
/**
|
|
34
|
+
* @brief Build a recursive JSON-value guard.
|
|
35
|
+
* @returns Fresh guard accepting JSON-serializable values.
|
|
36
|
+
* @details The guard accepts finite numbers because TypeSea number semantics
|
|
37
|
+
* reject NaN and infinities. Object values are string-keyed records.
|
|
38
|
+
*/
|
|
39
|
+
export declare function json(): BaseGuard<JsonValue>;
|
|
40
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/builders/runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,SAAS,EAAE,KAAK,KAAK,EAAE,KAAK,KAAK,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAIrF,MAAM,MAAM,mBAAmB,CAAC,MAAM,IAClC,QAAQ,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,MAAM,CAAC;AAE9C,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAE7D,MAAM,WAAW,SAAS;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC;AAED,MAAM,WAAW,UAAU;IACvB,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED,MAAM,MAAM,SAAS,GACf,aAAa,GACb,SAAS,GACT,UAAU,CAAC;AAEjB;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAC7B,WAAW,EAAE,mBAAmB,CAAC,MAAM,CAAC,GACzC,SAAS,CAAC,MAAM,CAAC,CAcnB;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACpB,KAAK,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EACtC,KAAK,CAAC,IAAI,SAAS,MAAM,EACzB,MAAM,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EAEvC,IAAI,EAAE,KAAK,EACX,GAAG,EAAE,IAAI,EACT,KAAK,EAAE,MAAM,GACd,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAUjE;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,IAAI,SAAS,CAAC,SAAS,CAAC,CAU3C"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file runtime.ts
|
|
3
|
+
* @brief Runtime-object guard builders.
|
|
4
|
+
* @details These builders describe JavaScript object domains that JSON Schema
|
|
5
|
+
* and AOT source cannot faithfully serialize.
|
|
6
|
+
*/
|
|
7
|
+
import { SchemaTag } from "../kind/index.js";
|
|
8
|
+
import { BaseGuard } from "../guard/index.js";
|
|
9
|
+
import { readGuardSchema } from "../internal/index.js";
|
|
10
|
+
/**
|
|
11
|
+
* @brief Build a guard backed by ordinary instanceof semantics.
|
|
12
|
+
* @param constructor Constructor function used as the instance domain.
|
|
13
|
+
* @returns Fresh guard accepting values whose prototype chain matches constructor.
|
|
14
|
+
* @throws TypeError when constructor is not callable.
|
|
15
|
+
*/
|
|
16
|
+
export function instanceOf(constructor) {
|
|
17
|
+
const rawConstructor = constructor;
|
|
18
|
+
if (typeof rawConstructor !== "function") {
|
|
19
|
+
throw new TypeError("instanceOf constructor must be a function");
|
|
20
|
+
}
|
|
21
|
+
if (!hasObjectPrototype(rawConstructor)) {
|
|
22
|
+
throw new TypeError("instanceOf constructor must expose an object prototype");
|
|
23
|
+
}
|
|
24
|
+
const ctor = rawConstructor;
|
|
25
|
+
return new BaseGuard({
|
|
26
|
+
tag: SchemaTag.InstanceOf,
|
|
27
|
+
constructor: ctor,
|
|
28
|
+
name: readConstructorName(ctor)
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @brief Require one own data property after a base guard succeeds.
|
|
33
|
+
* @param base Guard applied to the candidate value first.
|
|
34
|
+
* @param key Own string property key to inspect.
|
|
35
|
+
* @param value Guard applied to the property value.
|
|
36
|
+
* @returns Fresh guard preserving the base domain and recording the property type.
|
|
37
|
+
*/
|
|
38
|
+
export function property(base, key, value) {
|
|
39
|
+
if (typeof key !== "string") {
|
|
40
|
+
throw new TypeError("property key must be a string");
|
|
41
|
+
}
|
|
42
|
+
return new BaseGuard({
|
|
43
|
+
tag: SchemaTag.Property,
|
|
44
|
+
base: readGuardSchema(base, "property base"),
|
|
45
|
+
key,
|
|
46
|
+
value: readGuardSchema(value, "property value")
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @brief Build a recursive JSON-value guard.
|
|
51
|
+
* @returns Fresh guard accepting JSON-serializable values.
|
|
52
|
+
* @details The guard accepts finite numbers because TypeSea number semantics
|
|
53
|
+
* reject NaN and infinities. Object values are string-keyed records.
|
|
54
|
+
*/
|
|
55
|
+
export function json() {
|
|
56
|
+
let cached;
|
|
57
|
+
const root = new BaseGuard({
|
|
58
|
+
tag: SchemaTag.Lazy,
|
|
59
|
+
get: () => {
|
|
60
|
+
cached ??= makeJsonSchema(root.schema);
|
|
61
|
+
return cached;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return root;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @brief Materialize the recursive JSON schema after the root guard exists.
|
|
68
|
+
* @param root Recursive root schema used by arrays and records.
|
|
69
|
+
* @returns Union schema for every JSON value variant.
|
|
70
|
+
*/
|
|
71
|
+
function makeJsonSchema(root) {
|
|
72
|
+
return {
|
|
73
|
+
tag: SchemaTag.Union,
|
|
74
|
+
options: [
|
|
75
|
+
{
|
|
76
|
+
tag: SchemaTag.String,
|
|
77
|
+
checks: []
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
tag: SchemaTag.Number,
|
|
81
|
+
checks: []
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
tag: SchemaTag.Boolean
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
tag: SchemaTag.Literal,
|
|
88
|
+
value: null
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
tag: SchemaTag.Array,
|
|
92
|
+
item: root,
|
|
93
|
+
checks: []
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
tag: SchemaTag.Refine,
|
|
97
|
+
inner: {
|
|
98
|
+
tag: SchemaTag.Record,
|
|
99
|
+
value: root
|
|
100
|
+
},
|
|
101
|
+
predicate: isJsonObject,
|
|
102
|
+
name: "json_object"
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @brief Accept only JSON object containers.
|
|
109
|
+
* @param value Candidate value already checked as a record.
|
|
110
|
+
* @returns True for ordinary or null-prototype objects.
|
|
111
|
+
*/
|
|
112
|
+
function isJsonObject(value) {
|
|
113
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
const prototype = Object.getPrototypeOf(value);
|
|
117
|
+
return prototype === Object.prototype || prototype === null;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* @brief Read a stable diagnostic name from a constructor function.
|
|
121
|
+
* @param constructor Function supplied to instanceOf.
|
|
122
|
+
* @returns Constructor name or a generic fallback.
|
|
123
|
+
*/
|
|
124
|
+
function readConstructorName(constructor) {
|
|
125
|
+
const descriptor = Object.getOwnPropertyDescriptor(constructor, "name");
|
|
126
|
+
const name = descriptor !== undefined && "value" in descriptor
|
|
127
|
+
? descriptor.value
|
|
128
|
+
: undefined;
|
|
129
|
+
return descriptor !== undefined &&
|
|
130
|
+
"value" in descriptor &&
|
|
131
|
+
typeof name === "string" &&
|
|
132
|
+
name.length !== 0
|
|
133
|
+
? name
|
|
134
|
+
: "constructor";
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* @brief Check that a function can participate in ordinary instance checks.
|
|
138
|
+
* @param constructor Function supplied to instanceOf.
|
|
139
|
+
* @returns True when the function exposes an object prototype slot.
|
|
140
|
+
*/
|
|
141
|
+
function hasObjectPrototype(constructor) {
|
|
142
|
+
const descriptor = Object.getOwnPropertyDescriptor(constructor, "prototype");
|
|
143
|
+
if (descriptor === undefined ||
|
|
144
|
+
!("value" in descriptor)) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
const prototype = descriptor.value;
|
|
148
|
+
return (typeof prototype === "object" && prototype !== null) ||
|
|
149
|
+
typeof prototype === "function";
|
|
150
|
+
}
|
|
@@ -1,39 +1,79 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file scalar.ts
|
|
3
3
|
* @brief Primitive and literal guard builders.
|
|
4
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
5
|
+
* with stable metadata.
|
|
4
6
|
*/
|
|
5
|
-
import { BaseGuard, NumberGuard, StringGuard } from "../guard/index.js";
|
|
7
|
+
import { BaseGuard, DateGuard, NumberGuard, StringGuard } from "../guard/index.js";
|
|
6
8
|
import type { LiteralValue } from "../schema/index.js";
|
|
9
|
+
export type EnumValues = readonly [string, ...string[]];
|
|
7
10
|
/**
|
|
8
|
-
* @brief string guard.
|
|
11
|
+
* @brief Shared string guard singleton.
|
|
12
|
+
* @details Primitive guards are immutable, so exporting one instance avoids
|
|
13
|
+
* allocation for the common `t.string` path.
|
|
9
14
|
*/
|
|
10
15
|
export declare const stringGuard: StringGuard<"required">;
|
|
11
16
|
/**
|
|
12
|
-
* @brief unknown guard.
|
|
17
|
+
* @brief Shared unknown guard singleton.
|
|
18
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
19
|
+
* with stable metadata.
|
|
13
20
|
*/
|
|
14
21
|
export declare const unknownGuard: BaseGuard<unknown, "required">;
|
|
15
22
|
/**
|
|
16
|
-
* @brief never guard.
|
|
23
|
+
* @brief Shared never guard singleton.
|
|
24
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
25
|
+
* with stable metadata.
|
|
17
26
|
*/
|
|
18
27
|
export declare const neverGuard: BaseGuard<never, "required">;
|
|
19
28
|
/**
|
|
20
|
-
* @brief number guard.
|
|
29
|
+
* @brief Shared finite number guard singleton.
|
|
30
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
31
|
+
* with stable metadata.
|
|
21
32
|
*/
|
|
22
33
|
export declare const numberGuard: NumberGuard<"required">;
|
|
23
34
|
/**
|
|
24
|
-
* @brief
|
|
35
|
+
* @brief Shared valid Date guard singleton.
|
|
36
|
+
* @details Date validation accepts Date objects whose time value is finite.
|
|
37
|
+
* Invalid Date instances are rejected.
|
|
38
|
+
*/
|
|
39
|
+
export declare const dateGuard: DateGuard<"required">;
|
|
40
|
+
/**
|
|
41
|
+
* @brief Shared bigint guard singleton.
|
|
42
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
43
|
+
* with stable metadata.
|
|
25
44
|
*/
|
|
26
45
|
export declare const bigintGuard: BaseGuard<bigint, "required">;
|
|
27
46
|
/**
|
|
28
|
-
* @brief symbol guard.
|
|
47
|
+
* @brief Shared symbol guard singleton.
|
|
48
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
49
|
+
* with stable metadata.
|
|
29
50
|
*/
|
|
30
51
|
export declare const symbolGuard: BaseGuard<symbol, "required">;
|
|
31
52
|
/**
|
|
32
|
-
* @brief boolean guard.
|
|
53
|
+
* @brief Shared boolean guard singleton.
|
|
54
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
55
|
+
* with stable metadata.
|
|
33
56
|
*/
|
|
34
57
|
export declare const booleanGuard: BaseGuard<boolean, "required">;
|
|
58
|
+
export declare const nullGuard: BaseGuard<null, "required">;
|
|
59
|
+
export declare const undefinedGuard: BaseGuard<undefined, "required">;
|
|
60
|
+
export declare const voidGuard: BaseGuard<undefined, "required">;
|
|
35
61
|
/**
|
|
36
|
-
* @brief literal.
|
|
62
|
+
* @brief Build a literal guard after rejecting non-literal runtime values.
|
|
63
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
64
|
+
* with stable metadata.
|
|
65
|
+
* @param value Literal value to match with Object.is.
|
|
66
|
+
* @returns Fresh guard for exactly the supplied literal.
|
|
67
|
+
* @throws TypeError when the value cannot be represented as a TypeSea literal.
|
|
37
68
|
*/
|
|
38
69
|
export declare function literal<const TValue extends LiteralValue>(value: TValue): BaseGuard<TValue>;
|
|
70
|
+
/**
|
|
71
|
+
* @brief Build a string literal enum guard.
|
|
72
|
+
* @param values Non-empty tuple of string literals.
|
|
73
|
+
* @returns Fresh guard accepting exactly one supplied enum member.
|
|
74
|
+
* @throws TypeError when values are empty, non-strings, or duplicated.
|
|
75
|
+
* @details The public export is aliased as `enum`; this internal name avoids
|
|
76
|
+
* spelling a reserved word as a local binding.
|
|
77
|
+
*/
|
|
78
|
+
export declare function enumValues<const TValues extends EnumValues>(values: TValues): BaseGuard<TValues[number]>;
|
|
39
79
|
//# sourceMappingURL=scalar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scalar.d.ts","sourceRoot":"","sources":["../../src/builders/scalar.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"scalar.d.ts","sourceRoot":"","sources":["../../src/builders/scalar.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACH,SAAS,EACT,SAAS,EACT,WAAW,EACX,WAAW,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAU,MAAM,oBAAoB,CAAC;AAG/D,MAAM,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,WAAW,yBAGtB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,YAAY,gCAEvB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,UAAU,8BAErB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,WAAW,yBAGtB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,SAAS,uBAGpB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,WAAW,+BAEtB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,WAAW,+BAEtB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,YAAY,gCAEvB,CAAC;AAEH,eAAO,MAAM,SAAS,6BAGpB,CAAC;AAEH,eAAO,MAAM,cAAc,kCAGzB,CAAC;AAEH,eAAO,MAAM,SAAS,kCAAiB,CAAC;AAExC;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,KAAK,CAAC,MAAM,SAAS,YAAY,EACrD,KAAK,EAAE,MAAM,GACd,SAAS,CAAC,MAAM,CAAC,CAYnB;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,CAAC,OAAO,SAAS,UAAU,EACvD,MAAM,EAAE,OAAO,GAChB,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CA0B5B"}
|
package/dist/builders/scalar.js
CHANGED
|
@@ -1,63 +1,141 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file scalar.ts
|
|
3
3
|
* @brief Primitive and literal guard builders.
|
|
4
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
5
|
+
* with stable metadata.
|
|
4
6
|
*/
|
|
5
7
|
import { SchemaTag } from "../kind/index.js";
|
|
6
|
-
import { BaseGuard, NumberGuard, StringGuard } from "../guard/index.js";
|
|
8
|
+
import { BaseGuard, DateGuard, NumberGuard, StringGuard } from "../guard/index.js";
|
|
7
9
|
import { isLiteralValue } from "../schema/index.js";
|
|
8
10
|
/**
|
|
9
|
-
* @brief string guard.
|
|
11
|
+
* @brief Shared string guard singleton.
|
|
12
|
+
* @details Primitive guards are immutable, so exporting one instance avoids
|
|
13
|
+
* allocation for the common `t.string` path.
|
|
10
14
|
*/
|
|
11
15
|
export const stringGuard = new StringGuard({
|
|
12
16
|
tag: SchemaTag.String,
|
|
13
17
|
checks: []
|
|
14
18
|
});
|
|
15
19
|
/**
|
|
16
|
-
* @brief unknown guard.
|
|
20
|
+
* @brief Shared unknown guard singleton.
|
|
21
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
22
|
+
* with stable metadata.
|
|
17
23
|
*/
|
|
18
24
|
export const unknownGuard = new BaseGuard({
|
|
19
25
|
tag: SchemaTag.Unknown
|
|
20
26
|
});
|
|
21
27
|
/**
|
|
22
|
-
* @brief never guard.
|
|
28
|
+
* @brief Shared never guard singleton.
|
|
29
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
30
|
+
* with stable metadata.
|
|
23
31
|
*/
|
|
24
32
|
export const neverGuard = new BaseGuard({
|
|
25
33
|
tag: SchemaTag.Never
|
|
26
34
|
});
|
|
27
35
|
/**
|
|
28
|
-
* @brief number guard.
|
|
36
|
+
* @brief Shared finite number guard singleton.
|
|
37
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
38
|
+
* with stable metadata.
|
|
29
39
|
*/
|
|
30
40
|
export const numberGuard = new NumberGuard({
|
|
31
41
|
tag: SchemaTag.Number,
|
|
32
42
|
checks: []
|
|
33
43
|
});
|
|
34
44
|
/**
|
|
35
|
-
* @brief
|
|
45
|
+
* @brief Shared valid Date guard singleton.
|
|
46
|
+
* @details Date validation accepts Date objects whose time value is finite.
|
|
47
|
+
* Invalid Date instances are rejected.
|
|
48
|
+
*/
|
|
49
|
+
export const dateGuard = new DateGuard({
|
|
50
|
+
tag: SchemaTag.Date,
|
|
51
|
+
checks: []
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* @brief Shared bigint guard singleton.
|
|
55
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
56
|
+
* with stable metadata.
|
|
36
57
|
*/
|
|
37
58
|
export const bigintGuard = new BaseGuard({
|
|
38
59
|
tag: SchemaTag.BigInt
|
|
39
60
|
});
|
|
40
61
|
/**
|
|
41
|
-
* @brief symbol guard.
|
|
62
|
+
* @brief Shared symbol guard singleton.
|
|
63
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
64
|
+
* with stable metadata.
|
|
42
65
|
*/
|
|
43
66
|
export const symbolGuard = new BaseGuard({
|
|
44
67
|
tag: SchemaTag.Symbol
|
|
45
68
|
});
|
|
46
69
|
/**
|
|
47
|
-
* @brief boolean guard.
|
|
70
|
+
* @brief Shared boolean guard singleton.
|
|
71
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
72
|
+
* with stable metadata.
|
|
48
73
|
*/
|
|
49
74
|
export const booleanGuard = new BaseGuard({
|
|
50
75
|
tag: SchemaTag.Boolean
|
|
51
76
|
});
|
|
77
|
+
export const nullGuard = new BaseGuard({
|
|
78
|
+
tag: SchemaTag.Literal,
|
|
79
|
+
value: null
|
|
80
|
+
});
|
|
81
|
+
export const undefinedGuard = new BaseGuard({
|
|
82
|
+
tag: SchemaTag.Literal,
|
|
83
|
+
value: undefined
|
|
84
|
+
});
|
|
85
|
+
export const voidGuard = undefinedGuard;
|
|
52
86
|
/**
|
|
53
|
-
* @brief literal.
|
|
87
|
+
* @brief Build a literal guard after rejecting non-literal runtime values.
|
|
88
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
89
|
+
* with stable metadata.
|
|
90
|
+
* @param value Literal value to match with Object.is.
|
|
91
|
+
* @returns Fresh guard for exactly the supplied literal.
|
|
92
|
+
* @throws TypeError when the value cannot be represented as a TypeSea literal.
|
|
54
93
|
*/
|
|
55
94
|
export function literal(value) {
|
|
56
95
|
if (!isLiteralValue(value)) {
|
|
57
96
|
throw new TypeError("literal value must be a primitive literal");
|
|
58
97
|
}
|
|
98
|
+
/*
|
|
99
|
+
* Literal schemas store the runtime value directly. Rejecting compound input
|
|
100
|
+
* here keeps later equality checks side-effect free and serializable.
|
|
101
|
+
*/
|
|
59
102
|
return new BaseGuard({
|
|
60
103
|
tag: SchemaTag.Literal,
|
|
61
104
|
value
|
|
62
105
|
});
|
|
63
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* @brief Build a string literal enum guard.
|
|
109
|
+
* @param values Non-empty tuple of string literals.
|
|
110
|
+
* @returns Fresh guard accepting exactly one supplied enum member.
|
|
111
|
+
* @throws TypeError when values are empty, non-strings, or duplicated.
|
|
112
|
+
* @details The public export is aliased as `enum`; this internal name avoids
|
|
113
|
+
* spelling a reserved word as a local binding.
|
|
114
|
+
*/
|
|
115
|
+
export function enumValues(values) {
|
|
116
|
+
const rawValues = values;
|
|
117
|
+
if (!Array.isArray(rawValues) || rawValues.length === 0) {
|
|
118
|
+
throw new TypeError("enum values must be a non-empty string array");
|
|
119
|
+
}
|
|
120
|
+
const checkedValues = rawValues;
|
|
121
|
+
const options = new Array(checkedValues.length);
|
|
122
|
+
for (let index = 0; index < checkedValues.length; index += 1) {
|
|
123
|
+
const value = checkedValues[index];
|
|
124
|
+
if (typeof value !== "string") {
|
|
125
|
+
throw new TypeError("enum values must be strings");
|
|
126
|
+
}
|
|
127
|
+
for (let seen = 0; seen < index; seen += 1) {
|
|
128
|
+
if (Object.is(checkedValues[seen], value)) {
|
|
129
|
+
throw new TypeError("enum values must be unique");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
options[index] = {
|
|
133
|
+
tag: SchemaTag.Literal,
|
|
134
|
+
value
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return new BaseGuard({
|
|
138
|
+
tag: SchemaTag.Union,
|
|
139
|
+
options
|
|
140
|
+
});
|
|
141
|
+
}
|
package/dist/builders/table.d.ts
CHANGED
|
@@ -1,41 +1,71 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file table.ts
|
|
3
3
|
* @brief Frozen public builder table.
|
|
4
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
5
|
+
* with stable metadata.
|
|
4
6
|
*/
|
|
5
7
|
import { asyncDecoder, asyncPipe, asyncRefine, asyncTransform } from "../async/index.js";
|
|
6
|
-
import { decoder, pipe, transform } from "../decoder/index.js";
|
|
7
|
-
import { array, discriminatedUnion, intersect, record, tuple, union } from "./composite.js";
|
|
8
|
-
import { lazy, nullable, optional, refine, undefinedable } from "./modifier.js";
|
|
9
|
-
import { extend, object, omit, partial, pick, strictObject } from "./object/index.js";
|
|
10
|
-
import { literal } from "./scalar.js";
|
|
8
|
+
import { catchValue, codec, decoder, defaultValue, pipe, prefault, transform } from "../decoder/index.js";
|
|
9
|
+
import { array, discriminatedUnion, intersect, map, record, set, tuple, union } from "./composite.js";
|
|
10
|
+
import { lazy, nullable, nullish, optional, refine, undefinedable } from "./modifier.js";
|
|
11
|
+
import { catchall, deepPartial, extend, merge, object, omit, partial, passthrough, pick, required, safeExtend, strict, strictObject, strip } from "./object/index.js";
|
|
12
|
+
import { enumValues, literal } from "./scalar.js";
|
|
13
|
+
import { instanceOf, json, property } from "./runtime.js";
|
|
11
14
|
/**
|
|
12
15
|
* @brief t.
|
|
16
|
+
* @details Frozen namespace of all public builders. Freezing prevents accidental
|
|
17
|
+
* mutation of shared singleton guards and helper functions after module load.
|
|
13
18
|
*/
|
|
14
19
|
export declare const t: Readonly<{
|
|
15
20
|
readonly unknown: import("../index.js").BaseGuard<unknown, "required">;
|
|
16
21
|
readonly never: import("../index.js").BaseGuard<never, "required">;
|
|
17
22
|
readonly string: import("../index.js").StringGuard<"required">;
|
|
18
23
|
readonly number: import("../index.js").NumberGuard<"required">;
|
|
24
|
+
readonly date: import("../index.js").DateGuard<"required">;
|
|
19
25
|
readonly bigint: import("../index.js").BaseGuard<bigint, "required">;
|
|
20
26
|
readonly symbol: import("../index.js").BaseGuard<symbol, "required">;
|
|
21
27
|
readonly boolean: import("../index.js").BaseGuard<boolean, "required">;
|
|
28
|
+
readonly null: import("../index.js").BaseGuard<null, "required">;
|
|
29
|
+
readonly undefined: import("../index.js").BaseGuard<undefined, "required">;
|
|
30
|
+
readonly void: import("../index.js").BaseGuard<undefined, "required">;
|
|
22
31
|
readonly literal: typeof literal;
|
|
32
|
+
readonly enum: typeof enumValues;
|
|
33
|
+
readonly enumValues: typeof enumValues;
|
|
23
34
|
readonly array: typeof array;
|
|
24
35
|
readonly tuple: typeof tuple;
|
|
25
36
|
readonly record: typeof record;
|
|
37
|
+
readonly map: typeof map;
|
|
38
|
+
readonly set: typeof set;
|
|
39
|
+
readonly instanceOf: typeof instanceOf;
|
|
40
|
+
readonly property: typeof property;
|
|
41
|
+
readonly json: typeof json;
|
|
26
42
|
readonly decoder: typeof decoder;
|
|
43
|
+
readonly default: typeof defaultValue;
|
|
44
|
+
readonly defaultValue: typeof defaultValue;
|
|
45
|
+
readonly prefault: typeof prefault;
|
|
46
|
+
readonly catch: typeof catchValue;
|
|
47
|
+
readonly codec: typeof codec;
|
|
27
48
|
readonly object: typeof object;
|
|
28
49
|
readonly strictObject: typeof strictObject;
|
|
29
50
|
readonly extend: typeof extend;
|
|
51
|
+
readonly merge: typeof merge;
|
|
30
52
|
readonly pick: typeof pick;
|
|
31
53
|
readonly omit: typeof omit;
|
|
32
54
|
readonly partial: typeof partial;
|
|
55
|
+
readonly deepPartial: typeof deepPartial;
|
|
56
|
+
readonly required: typeof required;
|
|
57
|
+
readonly safeExtend: typeof safeExtend;
|
|
58
|
+
readonly strict: typeof strict;
|
|
59
|
+
readonly passthrough: typeof passthrough;
|
|
60
|
+
readonly strip: typeof strip;
|
|
61
|
+
readonly catchall: typeof catchall;
|
|
33
62
|
readonly union: typeof union;
|
|
34
63
|
readonly intersect: typeof intersect;
|
|
35
64
|
readonly discriminatedUnion: typeof discriminatedUnion;
|
|
36
65
|
readonly optional: typeof optional;
|
|
37
66
|
readonly undefinedable: typeof undefinedable;
|
|
38
67
|
readonly nullable: typeof nullable;
|
|
68
|
+
readonly nullish: typeof nullish;
|
|
39
69
|
readonly lazy: typeof lazy;
|
|
40
70
|
readonly refine: typeof refine;
|
|
41
71
|
readonly transform: typeof transform;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../src/builders/table.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../src/builders/table.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,EACH,UAAU,EACV,KAAK,EAEL,OAAO,EACP,YAAY,EACZ,IAAI,EACJ,QAAQ,EACR,SAAS,EACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACH,KAAK,EACL,kBAAkB,EAClB,SAAS,EACT,GAAG,EACH,MAAM,EACN,GAAG,EACH,KAAK,EACL,KAAK,EACR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACH,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,MAAM,EACN,aAAa,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EACH,QAAQ,EACR,WAAW,EACX,MAAM,EACN,KAAK,EACL,MAAM,EACN,IAAI,EACJ,OAAO,EACP,WAAW,EACX,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,MAAM,EACN,YAAY,EACZ,KAAK,EACR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAIH,UAAU,EACV,OAAO,EASV,MAAM,aAAa,CAAC;AACrB,OAAO,EACH,UAAU,EACV,IAAI,EACJ,QAAQ,EACX,MAAM,cAAc,CAAC;AAEtB;;;;GAIG;AACH,eAAO,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2DH,CAAC"}
|
package/dist/builders/table.js
CHANGED
|
@@ -1,41 +1,71 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file table.ts
|
|
3
3
|
* @brief Frozen public builder table.
|
|
4
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
5
|
+
* with stable metadata.
|
|
4
6
|
*/
|
|
5
7
|
import { asyncDecoder, asyncPipe, asyncRefine, asyncTransform } from "../async/index.js";
|
|
6
|
-
import { coerce, decoder, pipe, transform } from "../decoder/index.js";
|
|
7
|
-
import { array, discriminatedUnion, intersect, record, tuple, union } from "./composite.js";
|
|
8
|
-
import { lazy, nullable, optional, refine, undefinedable } from "./modifier.js";
|
|
9
|
-
import { extend, object, omit, partial, pick, strictObject } from "./object/index.js";
|
|
10
|
-
import { bigintGuard, booleanGuard, literal, neverGuard, numberGuard, stringGuard, symbolGuard, unknownGuard } from "./scalar.js";
|
|
8
|
+
import { catchValue, codec, coerce, decoder, defaultValue, pipe, prefault, transform } from "../decoder/index.js";
|
|
9
|
+
import { array, discriminatedUnion, intersect, map, record, set, tuple, union } from "./composite.js";
|
|
10
|
+
import { lazy, nullable, nullish, optional, refine, undefinedable } from "./modifier.js";
|
|
11
|
+
import { catchall, deepPartial, extend, merge, object, omit, partial, passthrough, pick, required, safeExtend, strict, strictObject, strip } from "./object/index.js";
|
|
12
|
+
import { bigintGuard, booleanGuard, dateGuard, enumValues, literal, neverGuard, nullGuard, numberGuard, stringGuard, symbolGuard, unknownGuard, undefinedGuard, voidGuard } from "./scalar.js";
|
|
13
|
+
import { instanceOf, json, property } from "./runtime.js";
|
|
11
14
|
/**
|
|
12
15
|
* @brief t.
|
|
16
|
+
* @details Frozen namespace of all public builders. Freezing prevents accidental
|
|
17
|
+
* mutation of shared singleton guards and helper functions after module load.
|
|
13
18
|
*/
|
|
14
19
|
export const t = Object.freeze({
|
|
15
20
|
unknown: unknownGuard,
|
|
16
21
|
never: neverGuard,
|
|
17
22
|
string: stringGuard,
|
|
18
23
|
number: numberGuard,
|
|
24
|
+
date: dateGuard,
|
|
19
25
|
bigint: bigintGuard,
|
|
20
26
|
symbol: symbolGuard,
|
|
21
27
|
boolean: booleanGuard,
|
|
28
|
+
null: nullGuard,
|
|
29
|
+
undefined: undefinedGuard,
|
|
30
|
+
void: voidGuard,
|
|
22
31
|
literal,
|
|
32
|
+
enum: enumValues,
|
|
33
|
+
enumValues,
|
|
23
34
|
array,
|
|
24
35
|
tuple,
|
|
25
36
|
record,
|
|
37
|
+
map,
|
|
38
|
+
set,
|
|
39
|
+
instanceOf,
|
|
40
|
+
property,
|
|
41
|
+
json,
|
|
26
42
|
decoder,
|
|
43
|
+
default: defaultValue,
|
|
44
|
+
defaultValue,
|
|
45
|
+
prefault,
|
|
46
|
+
catch: catchValue,
|
|
47
|
+
codec,
|
|
27
48
|
object,
|
|
28
49
|
strictObject,
|
|
29
50
|
extend,
|
|
51
|
+
merge,
|
|
30
52
|
pick,
|
|
31
53
|
omit,
|
|
32
54
|
partial,
|
|
55
|
+
deepPartial,
|
|
56
|
+
required,
|
|
57
|
+
safeExtend,
|
|
58
|
+
strict,
|
|
59
|
+
passthrough,
|
|
60
|
+
strip,
|
|
61
|
+
catchall,
|
|
33
62
|
union,
|
|
34
63
|
intersect,
|
|
35
64
|
discriminatedUnion,
|
|
36
65
|
optional,
|
|
37
66
|
undefinedable,
|
|
38
67
|
nullable,
|
|
68
|
+
nullish,
|
|
39
69
|
lazy,
|
|
40
70
|
refine,
|
|
41
71
|
transform,
|
package/dist/builders/types.d.ts
CHANGED
|
@@ -1,24 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file types.ts
|
|
3
3
|
* @brief Shared builder type algebra.
|
|
4
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
5
|
+
* with stable metadata.
|
|
4
6
|
*/
|
|
5
7
|
import type { Guard, Infer, Presence } from "../guard/index.js";
|
|
6
8
|
/**
|
|
7
|
-
* @brief
|
|
9
|
+
* @brief Tuple builder input shape.
|
|
10
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
11
|
+
* with stable metadata.
|
|
8
12
|
*/
|
|
9
13
|
export type TupleShape = readonly Guard<unknown, Presence>[];
|
|
10
14
|
/**
|
|
11
|
-
* @brief
|
|
15
|
+
* @brief Infer tuple runtime value from a tuple guard shape.
|
|
16
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
17
|
+
* with stable metadata.
|
|
12
18
|
*/
|
|
13
19
|
export type InferTuple<TShape extends TupleShape> = {
|
|
14
20
|
readonly [TKey in keyof TShape]: Infer<TShape[TKey]>;
|
|
15
21
|
};
|
|
22
|
+
export type InferTupleWithRest<TShape extends TupleShape, TRest extends Guard<unknown, Presence>> = readonly [
|
|
23
|
+
...{
|
|
24
|
+
[TKey in keyof TShape]: Infer<TShape[TKey]>;
|
|
25
|
+
},
|
|
26
|
+
...Infer<TRest>[]
|
|
27
|
+
];
|
|
16
28
|
/**
|
|
17
|
-
* @brief union input.
|
|
29
|
+
* @brief Non-empty union builder input.
|
|
30
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
31
|
+
* with stable metadata.
|
|
18
32
|
*/
|
|
19
33
|
export type UnionInput = readonly [Guard<unknown, Presence>, ...Guard<unknown, Presence>[]];
|
|
20
34
|
/**
|
|
21
|
-
* @brief
|
|
35
|
+
* @brief Compile-time guard that each case owns the requested literal tag.
|
|
36
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
37
|
+
* with stable metadata.
|
|
22
38
|
*/
|
|
23
39
|
export type DiscriminatedUnionCases<TKey extends string, TCases extends Readonly<Record<string, Guard<unknown, Presence>>>> = string extends TKey ? TCases : {
|
|
24
40
|
readonly [TCase in keyof TCases]: TCase extends string ? Infer<TCases[TCase]> extends Readonly<Record<TKey, TCase>> ? TCases[TCase] : never : never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/builders/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/builders/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACR,KAAK,EACL,KAAK,EACL,QAAQ,EACX,MAAM,mBAAmB,CAAC;AAE3B;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC;AAE7D;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,MAAM,SAAS,UAAU,IAAI;IAChD,QAAQ,EAAE,IAAI,IAAI,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,kBAAkB,CAC1B,MAAM,SAAS,UAAU,EACzB,KAAK,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,IACtC,SAAS;IACT,GAAG;SACE,IAAI,IAAI,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;KAC9C;IACD,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE;CACpB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAClB,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;AAEvE;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,CAC/B,IAAI,SAAS,MAAM,EACnB,MAAM,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,IACjE,MAAM,SAAS,IAAI,GACjB,MAAM,GACN;IACM,QAAQ,EAAE,KAAK,IAAI,MAAM,MAAM,GAAG,KAAK,SAAS,MAAM,GAChD,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,GACtD,MAAM,CAAC,KAAK,CAAC,GACb,KAAK,GACb,KAAK;CACV,CAAC"}
|