@es-joy/jsoe 0.16.0 → 0.17.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/.ncurc.cjs +4 -5
- package/CHANGES.md +4 -0
- package/README.md +27 -3
- package/badges/licenses-badge.svg +1 -0
- package/dist/formatAndTypeChoices.d.ts +39 -19
- package/dist/formatAndTypeChoices.d.ts.map +1 -1
- package/dist/formats/indexedDBKey.d.ts +1 -1
- package/dist/formats/indexedDBKey.d.ts.map +1 -1
- package/dist/formats/json.d.ts +1 -1
- package/dist/formats/json.d.ts.map +1 -1
- package/dist/formats/schema.d.ts +11 -0
- package/dist/formats/schema.d.ts.map +1 -0
- package/dist/formats/structuredCloning.d.ts +11 -13
- package/dist/formats/structuredCloning.d.ts.map +1 -1
- package/dist/formats.d.ts +86 -25
- package/dist/formats.d.ts.map +1 -1
- package/dist/fundamentalTypes/BooleanObjectType.d.ts +1 -1
- package/dist/fundamentalTypes/BooleanObjectType.d.ts.map +1 -1
- package/dist/fundamentalTypes/NumberObjectType.d.ts +1 -1
- package/dist/fundamentalTypes/NumberObjectType.d.ts.map +1 -1
- package/dist/fundamentalTypes/StringObjectType.d.ts +1 -1
- package/dist/fundamentalTypes/StringObjectType.d.ts.map +1 -1
- package/dist/fundamentalTypes/arrayReferenceType.d.ts +1 -1
- package/dist/fundamentalTypes/arrayType.d.ts +3 -3
- package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
- package/dist/fundamentalTypes/bigintObjectType.d.ts +6 -0
- package/dist/fundamentalTypes/bigintObjectType.d.ts.map +1 -0
- package/dist/fundamentalTypes/bigintType.d.ts +1 -1
- package/dist/fundamentalTypes/bigintType.d.ts.map +1 -1
- package/dist/fundamentalTypes/blobType.d.ts +1 -1
- package/dist/fundamentalTypes/blobType.d.ts.map +1 -1
- package/dist/fundamentalTypes/booleanType.d.ts +8 -0
- package/dist/fundamentalTypes/booleanType.d.ts.map +1 -0
- package/dist/fundamentalTypes/catchType.d.ts +6 -0
- package/dist/fundamentalTypes/catchType.d.ts.map +1 -0
- package/dist/fundamentalTypes/dateType.d.ts +4 -4
- package/dist/fundamentalTypes/dateType.d.ts.map +1 -1
- package/dist/fundamentalTypes/domexceptionType.d.ts +1 -1
- package/dist/fundamentalTypes/domexceptionType.d.ts.map +1 -1
- package/dist/fundamentalTypes/enumType.d.ts +6 -0
- package/dist/fundamentalTypes/enumType.d.ts.map +1 -0
- package/dist/fundamentalTypes/errorType.d.ts +1 -1
- package/dist/fundamentalTypes/errorType.d.ts.map +1 -1
- package/dist/fundamentalTypes/fileType.d.ts +1 -1
- package/dist/fundamentalTypes/fileType.d.ts.map +1 -1
- package/dist/fundamentalTypes/filelistType.d.ts +1 -1
- package/dist/fundamentalTypes/filelistType.d.ts.map +1 -1
- package/dist/fundamentalTypes/functionType.d.ts +6 -0
- package/dist/fundamentalTypes/functionType.d.ts.map +1 -0
- package/dist/fundamentalTypes/literalType.d.ts +6 -0
- package/dist/fundamentalTypes/literalType.d.ts.map +1 -0
- package/dist/fundamentalTypes/mapType.d.ts +1 -1
- package/dist/fundamentalTypes/mapType.d.ts.map +1 -1
- package/dist/fundamentalTypes/nanType.d.ts +6 -0
- package/dist/fundamentalTypes/nanType.d.ts.map +1 -0
- package/dist/fundamentalTypes/nativeEnumType.d.ts +6 -0
- package/dist/fundamentalTypes/nativeEnumType.d.ts.map +1 -0
- package/dist/fundamentalTypes/neverType.d.ts +6 -0
- package/dist/fundamentalTypes/neverType.d.ts.map +1 -0
- package/dist/fundamentalTypes/noneditableType.d.ts +1 -1
- package/dist/fundamentalTypes/noneditableType.d.ts.map +1 -1
- package/dist/fundamentalTypes/nullType.d.ts +1 -1
- package/dist/fundamentalTypes/nullType.d.ts.map +1 -1
- package/dist/fundamentalTypes/numberType.d.ts +1 -1
- package/dist/fundamentalTypes/numberType.d.ts.map +1 -1
- package/dist/fundamentalTypes/objectReferenceType.d.ts +1 -1
- package/dist/fundamentalTypes/objectType.d.ts +1 -1
- package/dist/fundamentalTypes/objectType.d.ts.map +1 -1
- package/dist/fundamentalTypes/promiseType.d.ts +6 -0
- package/dist/fundamentalTypes/promiseType.d.ts.map +1 -0
- package/dist/fundamentalTypes/recordType.d.ts +6 -0
- package/dist/fundamentalTypes/recordType.d.ts.map +1 -0
- package/dist/fundamentalTypes/regexpType.d.ts +1 -1
- package/dist/fundamentalTypes/regexpType.d.ts.map +1 -1
- package/dist/fundamentalTypes/setType.d.ts +1 -1
- package/dist/fundamentalTypes/setType.d.ts.map +1 -1
- package/dist/fundamentalTypes/sparseUndefinedType.d.ts +1 -1
- package/dist/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -1
- package/dist/fundamentalTypes/stringType.d.ts +1 -1
- package/dist/fundamentalTypes/stringType.d.ts.map +1 -1
- package/dist/fundamentalTypes/symbolType.d.ts +8 -0
- package/dist/fundamentalTypes/symbolType.d.ts.map +1 -0
- package/dist/fundamentalTypes/tupleType.d.ts +6 -0
- package/dist/fundamentalTypes/tupleType.d.ts.map +1 -0
- package/dist/fundamentalTypes/undefinedType.d.ts +1 -1
- package/dist/fundamentalTypes/undefinedType.d.ts.map +1 -1
- package/dist/fundamentalTypes/voidType.d.ts +6 -0
- package/dist/fundamentalTypes/voidType.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9660 -1586
- package/dist/subTypes/blobHTMLType.d.ts.map +1 -1
- package/dist/subTypes/falseType.d.ts +1 -1
- package/dist/subTypes/trueType.d.ts +1 -1
- package/dist/superTypes/SpecialNumberType.d.ts +1 -1
- package/dist/superTypes/SpecialRealNumberType.d.ts +1 -1
- package/dist/superTypes/SpecialRealNumberType.d.ts.map +1 -1
- package/dist/superTypes/buffersourceType.d.ts +1 -1
- package/dist/superTypes/buffersourceType.d.ts.map +1 -1
- package/dist/superTypes/dommatrixType.d.ts +1 -1
- package/dist/superTypes/dommatrixType.d.ts.map +1 -1
- package/dist/superTypes/dompointType.d.ts +1 -1
- package/dist/superTypes/dompointType.d.ts.map +1 -1
- package/dist/superTypes/domrectType.d.ts +1 -1
- package/dist/superTypes/domrectType.d.ts.map +1 -1
- package/dist/superTypes/errorsSpecialType.d.ts +1 -1
- package/dist/superTypes/errorsSpecialType.d.ts.map +1 -1
- package/dist/typeChoices.d.ts +33 -16
- package/dist/typeChoices.d.ts.map +1 -1
- package/dist/types.d.ts +161 -157
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/dialogs.d.ts +3 -3
- package/dist/utils/dialogs.d.ts.map +1 -1
- package/dist/utils/jsonPointer.d.ts.map +1 -1
- package/dist/utils/media.d.ts.map +1 -1
- package/dist/utils/objects.d.ts +16 -0
- package/dist/utils/objects.d.ts.map +1 -0
- package/dist/utils/types.d.ts +1 -1
- package/dist/utils/types.d.ts.map +1 -1
- package/dist/vendor-imports.d.ts +1 -1
- package/eslint.config.js +74 -0
- package/licenseInfo.json +4 -0
- package/package.json +33 -42
- package/rollup.config.js +15 -0
- package/src/formatAndTypeChoices.js +68 -54
- package/src/formats/indexedDBKey.js +9 -4
- package/src/formats/json.js +7 -4
- package/src/formats/schema.js +772 -0
- package/src/formats/structuredCloning.js +187 -86
- package/src/formats.js +61 -26
- package/src/fundamentalTypes/BooleanObjectType.js +18 -6
- package/src/fundamentalTypes/NumberObjectType.js +18 -5
- package/src/fundamentalTypes/StringObjectType.js +20 -8
- package/src/fundamentalTypes/arrayType.js +1241 -533
- package/src/fundamentalTypes/bigintObjectType.js +64 -0
- package/src/fundamentalTypes/bigintType.js +31 -5
- package/src/fundamentalTypes/blobType.js +201 -190
- package/src/fundamentalTypes/booleanType.js +63 -0
- package/src/fundamentalTypes/catchType.js +140 -0
- package/src/fundamentalTypes/dateType.js +57 -19
- package/src/fundamentalTypes/domexceptionType.js +61 -63
- package/src/fundamentalTypes/enumType.js +52 -0
- package/src/fundamentalTypes/errorType.js +20 -7
- package/src/fundamentalTypes/fileType.js +195 -189
- package/src/fundamentalTypes/filelistType.js +4 -0
- package/src/fundamentalTypes/functionType.js +150 -0
- package/src/fundamentalTypes/literalType.js +81 -0
- package/src/fundamentalTypes/mapType.js +4 -0
- package/src/fundamentalTypes/nanType.js +41 -0
- package/src/fundamentalTypes/nativeEnumType.js +155 -0
- package/src/fundamentalTypes/neverType.js +44 -0
- package/src/fundamentalTypes/noneditableType.js +19 -5
- package/src/fundamentalTypes/nullType.js +16 -6
- package/src/fundamentalTypes/numberType.js +49 -6
- package/src/fundamentalTypes/objectType.js +10 -2
- package/src/fundamentalTypes/promiseType.js +60 -0
- package/src/fundamentalTypes/recordType.js +42 -0
- package/src/fundamentalTypes/regexpType.js +51 -33
- package/src/fundamentalTypes/setType.js +4 -0
- package/src/fundamentalTypes/sparseUndefinedType.js +3 -0
- package/src/fundamentalTypes/stringType.js +254 -6
- package/src/fundamentalTypes/symbolType.js +81 -0
- package/src/fundamentalTypes/tupleType.js +39 -0
- package/src/fundamentalTypes/undefinedType.js +14 -4
- package/src/fundamentalTypes/voidType.js +48 -0
- package/src/jsoe.css +37 -3
- package/src/subTypes/blobHTMLType.js +33 -24
- package/src/superTypes/SpecialRealNumberType.js +22 -6
- package/src/superTypes/buffersourceType.js +86 -30
- package/src/superTypes/dommatrixType.js +24 -7
- package/src/superTypes/dompointType.js +27 -7
- package/src/superTypes/domrectType.js +33 -7
- package/src/superTypes/errorsSpecialType.js +30 -14
- package/src/typeChoices.js +115 -44
- package/src/types.js +129 -45
- package/src/utils/FileList.js +3 -3
- package/src/utils/dialogs.js +6 -8
- package/src/utils/objects.js +22 -0
- package/src/vendor-imports.js +1 -1
- package/tsconfig.json +2 -2
- package/vendor/jamilih/dist/jml-es.js +23 -6
- package/vendor/typeson-registry/dist/index.js +77 -47
- package/vendor/zod/lib/index.mjs +4236 -0
- package/vendor/zodex/dist/esm/dezerialize.d.ts +26 -0
- package/vendor/zodex/dist/esm/dezerialize.js +393 -0
- package/vendor/zodex/dist/esm/index.d.ts +9 -0
- package/vendor/zodex/dist/esm/index.js +4 -0
- package/vendor/zodex/dist/esm/infer.d.ts +29 -0
- package/vendor/zodex/dist/esm/infer.js +1 -0
- package/vendor/zodex/dist/esm/package.json +1 -0
- package/vendor/zodex/dist/esm/types.d.ts +201 -0
- package/vendor/zodex/dist/esm/types.js +13 -0
- package/vendor/zodex/dist/esm/ui.d.ts +23 -0
- package/vendor/zodex/dist/esm/ui.js +10 -0
- package/vendor/zodex/dist/esm/zerialize.d.ts +50 -0
- package/vendor/zodex/dist/esm/zerialize.js +417 -0
- package/vendor/zodex/dist/esm/zod-types.d.ts +11 -0
- package/vendor/zodex/dist/esm/zod-types.js +1 -0
- package/.eslintignore +0 -13
- package/.eslintrc.cjs +0 -145
- package/.nyc_output/out.json +0 -117370
- package/cypress.config.ts +0 -15
- package/demo/index-instrumented.html +0 -29
- package/demo/index-instrumented.js +0 -644
- package/demo/index.html +0 -29
- package/demo/index.js +0 -215
- package/src/formats/schemaAndArbitrary.js +0 -20
- package/src/formats/schemaOnly.js +0 -539
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { SzOptional, SzNullable, SzReadonly, SzDefault, SzLiteral, SzArray, SzObject, SzUnion, SzDiscriminatedUnion, SzIntersection, SzTuple, SzRecord, SzMap, SzSet, SzFunction, SzEnum, SzNativeEnum, SzPromise, SzEffect, SzCatch, SzType, SzString, SzNumber, SzBoolean, SzBigInt, SzNaN, SzDate, SzAny, SzNever, SzNull, SzUndefined, SzSymbol, SzUnknown, SzVoid, SzRef } from "./types.js";
|
|
3
|
+
import { ZodTypes } from "./zod-types.js";
|
|
4
|
+
type DezerializerOptions = {
|
|
5
|
+
superRefinements?: {
|
|
6
|
+
[key: string]: (value: unknown, ctx: z.RefinementCtx) => Promise<void> | void;
|
|
7
|
+
};
|
|
8
|
+
transforms?: {
|
|
9
|
+
[key: string]: (value: unknown, ctx: z.RefinementCtx) => Promise<unknown> | unknown;
|
|
10
|
+
};
|
|
11
|
+
preprocesses?: {
|
|
12
|
+
[key: string]: (value: unknown, ctx: z.RefinementCtx) => unknown;
|
|
13
|
+
};
|
|
14
|
+
path: string;
|
|
15
|
+
pathToSchema: Map<string, ZodTypes>;
|
|
16
|
+
$refs: [z.ZodLazy<any>, string][];
|
|
17
|
+
originalShape: SzType;
|
|
18
|
+
};
|
|
19
|
+
type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
|
20
|
+
type OmitKey<T, K> = DistributiveOmit<T, keyof K>;
|
|
21
|
+
export type Dezerialize<T extends SzType | SzRef> = T extends SzRef ? any : T extends SzOptional ? Dezerialize<OmitKey<T, SzOptional>> extends infer I ? I extends ZodTypes ? z.ZodOptional<I> : never : never : T extends SzNullable ? Dezerialize<OmitKey<T, SzNullable>> extends infer I ? I extends ZodTypes ? z.ZodNullable<I> : never : never : T extends SzReadonly ? Dezerialize<OmitKey<T, SzReadonly>> extends infer I ? I extends ZodTypes ? z.ZodReadonly<I> : never : never : T extends SzDefault<any> ? Dezerialize<OmitKey<T, SzDefault<any>>> extends infer I ? I extends ZodTypes ? z.ZodDefault<I> : never : never : T extends SzString ? z.ZodString : T extends SzNumber ? z.ZodNumber : T extends SzBoolean ? z.ZodBoolean : T extends SzBigInt ? z.ZodBigInt : T extends SzNaN ? z.ZodNaN : T extends SzDate ? z.ZodDate : T extends SzUndefined ? z.ZodUndefined : T extends SzNull ? z.ZodNull : T extends SzSymbol ? z.ZodSymbol : T extends SzAny ? z.ZodAny : T extends SzUnknown ? z.ZodUnknown : T extends SzNever ? z.ZodNever : T extends SzVoid ? z.ZodVoid : T extends SzLiteral<infer Value> ? z.ZodLiteral<Value> : T extends SzTuple<infer _Items> ? z.ZodTuple<any> : T extends SzSet<infer Value> ? z.ZodSet<Dezerialize<Value>> : T extends SzArray<infer Element> ? z.ZodArray<Dezerialize<Element>> : T extends SzObject<infer Properties> ? z.ZodObject<{
|
|
22
|
+
[Property in keyof Properties]: Dezerialize<Properties[Property]>;
|
|
23
|
+
}> : T extends SzRecord<infer Key, infer Value> ? z.ZodRecord<Dezerialize<Key>, Dezerialize<Value>> : T extends SzMap<infer Key, infer Value> ? z.ZodMap<Dezerialize<Key>, Dezerialize<Value>> : T extends SzEnum<infer Values> ? z.ZodEnum<Values> : T extends SzUnion<infer _Options> ? z.ZodUnion<any> : T extends SzDiscriminatedUnion<infer Discriminator, infer _Options> ? z.ZodDiscriminatedUnion<Discriminator, any> : T extends SzIntersection<infer L, infer R> ? z.ZodIntersection<Dezerialize<L>, Dezerialize<R>> : T extends SzFunction<infer Args, infer Return> ? z.ZodFunction<Dezerialize<Args>, Dezerialize<Return>> : T extends SzPromise<infer Value> ? z.ZodPromise<Dezerialize<Value>> : T extends SzEffect<infer Value> ? z.ZodEffects<Dezerialize<Value>> : T extends SzCatch<infer Value> ? z.ZodCatch<Dezerialize<Value>> : T extends SzNativeEnum<infer Value> ? z.ZodNativeEnum<Value> : unknown;
|
|
24
|
+
export declare function dezerializeRefs(shape: SzType, opts: DezerializerOptions): ZodTypes;
|
|
25
|
+
export declare function dezerialize(shape: SzType, opts?: Partial<DezerializerOptions>): ZodTypes;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
function checkRef(item, opts) {
|
|
3
|
+
if ("$ref" in item) {
|
|
4
|
+
const lazy = z.lazy(() => z.null());
|
|
5
|
+
opts.$refs.push([lazy, item.$ref]);
|
|
6
|
+
return lazy;
|
|
7
|
+
}
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
const d = dezerializeRefs;
|
|
11
|
+
const dezerializers = {
|
|
12
|
+
number: (shape) => {
|
|
13
|
+
let n = shape.coerce ? z.coerce.number() : z.number();
|
|
14
|
+
if (shape.min !== undefined) {
|
|
15
|
+
n = shape.minInclusive ? n.min(shape.min) : n.gt(shape.min);
|
|
16
|
+
}
|
|
17
|
+
if (shape.max !== undefined) {
|
|
18
|
+
n = shape.maxInclusive ? n.max(shape.max) : n.lt(shape.max);
|
|
19
|
+
}
|
|
20
|
+
if (shape.multipleOf !== undefined) {
|
|
21
|
+
n = n.multipleOf(shape.multipleOf);
|
|
22
|
+
}
|
|
23
|
+
if (shape.int) {
|
|
24
|
+
n = n.int();
|
|
25
|
+
}
|
|
26
|
+
if (shape.finite) {
|
|
27
|
+
n = n.finite();
|
|
28
|
+
}
|
|
29
|
+
return n;
|
|
30
|
+
},
|
|
31
|
+
string: (shape) => {
|
|
32
|
+
let s = shape.coerce ? z.coerce.string() : z.string();
|
|
33
|
+
if (shape.min !== undefined) {
|
|
34
|
+
s = s.min(shape.min);
|
|
35
|
+
}
|
|
36
|
+
if (shape.max !== undefined) {
|
|
37
|
+
s = s.max(shape.max);
|
|
38
|
+
}
|
|
39
|
+
if (shape.length !== undefined) {
|
|
40
|
+
s = s.length(shape.length);
|
|
41
|
+
}
|
|
42
|
+
if (shape.startsWith !== undefined) {
|
|
43
|
+
s = s.startsWith(shape.startsWith);
|
|
44
|
+
}
|
|
45
|
+
if (shape.endsWith !== undefined) {
|
|
46
|
+
s = s.endsWith(shape.endsWith);
|
|
47
|
+
}
|
|
48
|
+
if (shape.toLowerCase !== undefined) {
|
|
49
|
+
s = s.toLowerCase();
|
|
50
|
+
}
|
|
51
|
+
if (shape.toUpperCase !== undefined) {
|
|
52
|
+
s = s.toUpperCase();
|
|
53
|
+
}
|
|
54
|
+
if (shape.trim !== undefined) {
|
|
55
|
+
s = s.trim();
|
|
56
|
+
}
|
|
57
|
+
if ("includes" in shape) {
|
|
58
|
+
s = s.includes(shape.includes, { position: shape.position });
|
|
59
|
+
}
|
|
60
|
+
if ("regex" in shape) {
|
|
61
|
+
s = s.regex(new RegExp(shape.regex, shape.flags));
|
|
62
|
+
}
|
|
63
|
+
if ("kind" in shape) {
|
|
64
|
+
if (shape.kind == "ip") {
|
|
65
|
+
s = s.ip({ version: shape.version });
|
|
66
|
+
}
|
|
67
|
+
else if (shape.kind == "datetime") {
|
|
68
|
+
s = s.datetime({
|
|
69
|
+
offset: shape.offset,
|
|
70
|
+
precision: shape.precision,
|
|
71
|
+
local: shape.local,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else if (shape.kind == "time") {
|
|
75
|
+
s = s.time({
|
|
76
|
+
precision: shape.precision,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
s = s[shape.kind]();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return s;
|
|
84
|
+
},
|
|
85
|
+
boolean: (shape) => (shape.coerce ? z.coerce.boolean() : z.boolean()),
|
|
86
|
+
nan: () => z.nan(),
|
|
87
|
+
bigInt: (shape) => {
|
|
88
|
+
let i = shape.coerce ? z.coerce.bigint() : z.bigint();
|
|
89
|
+
if (shape.min !== undefined) {
|
|
90
|
+
const min = BigInt(shape.min);
|
|
91
|
+
i = shape.minInclusive ? i.min(min) : i.gt(min);
|
|
92
|
+
}
|
|
93
|
+
if (shape.max !== undefined) {
|
|
94
|
+
const max = BigInt(shape.max);
|
|
95
|
+
i = shape.maxInclusive ? i.max(max) : i.lt(max);
|
|
96
|
+
}
|
|
97
|
+
if (shape.multipleOf !== undefined) {
|
|
98
|
+
const multipleOf = BigInt(shape.multipleOf);
|
|
99
|
+
i = i.multipleOf(multipleOf);
|
|
100
|
+
}
|
|
101
|
+
return i;
|
|
102
|
+
},
|
|
103
|
+
date: (shape) => {
|
|
104
|
+
let i = shape.coerce ? z.coerce.date() : z.date();
|
|
105
|
+
if (shape.min !== undefined) {
|
|
106
|
+
i = i.min(new Date(shape.min));
|
|
107
|
+
}
|
|
108
|
+
if (shape.max !== undefined) {
|
|
109
|
+
i = i.max(new Date(shape.max));
|
|
110
|
+
}
|
|
111
|
+
return i;
|
|
112
|
+
},
|
|
113
|
+
undefined: () => z.undefined(),
|
|
114
|
+
null: () => z.null(),
|
|
115
|
+
any: () => z.any(),
|
|
116
|
+
unknown: () => z.unknown(),
|
|
117
|
+
never: () => z.never(),
|
|
118
|
+
void: () => z.void(),
|
|
119
|
+
literal: (shape) => z.literal(shape.value),
|
|
120
|
+
symbol: () => z.symbol(),
|
|
121
|
+
tuple: ((shape, opts) => {
|
|
122
|
+
let i = z.tuple(shape.items.map((item, idx) => {
|
|
123
|
+
return (checkRef(item, opts) ||
|
|
124
|
+
d(item, {
|
|
125
|
+
...opts,
|
|
126
|
+
path: opts.path + "/items/" + idx,
|
|
127
|
+
}));
|
|
128
|
+
}));
|
|
129
|
+
if (shape.rest) {
|
|
130
|
+
const rest = checkRef(shape.rest, opts) ||
|
|
131
|
+
d(shape.rest, {
|
|
132
|
+
...opts,
|
|
133
|
+
path: opts.path + "/rest",
|
|
134
|
+
});
|
|
135
|
+
i = i.rest(rest);
|
|
136
|
+
}
|
|
137
|
+
opts.pathToSchema.set(opts.path, i);
|
|
138
|
+
return i;
|
|
139
|
+
}),
|
|
140
|
+
set: ((shape, opts) => {
|
|
141
|
+
let i = z.set(checkRef(shape.value, opts) ||
|
|
142
|
+
d(shape.value, {
|
|
143
|
+
...opts,
|
|
144
|
+
path: opts.path + "/value",
|
|
145
|
+
}));
|
|
146
|
+
if (shape.minSize !== undefined) {
|
|
147
|
+
i = i.min(shape.minSize);
|
|
148
|
+
}
|
|
149
|
+
if (shape.maxSize !== undefined) {
|
|
150
|
+
i = i.max(shape.maxSize);
|
|
151
|
+
}
|
|
152
|
+
opts.pathToSchema.set(opts.path, i);
|
|
153
|
+
return i;
|
|
154
|
+
}),
|
|
155
|
+
array: ((shape, opts) => {
|
|
156
|
+
let i = z.array(checkRef(shape.element, opts) ||
|
|
157
|
+
d(shape.element, {
|
|
158
|
+
...opts,
|
|
159
|
+
path: opts.path + "/element",
|
|
160
|
+
}));
|
|
161
|
+
if (shape.minLength !== undefined) {
|
|
162
|
+
i = i.min(shape.minLength);
|
|
163
|
+
}
|
|
164
|
+
if (shape.maxLength !== undefined) {
|
|
165
|
+
i = i.max(shape.maxLength);
|
|
166
|
+
}
|
|
167
|
+
opts.pathToSchema.set(opts.path, i);
|
|
168
|
+
return i;
|
|
169
|
+
}),
|
|
170
|
+
object: ((shape, opts) => {
|
|
171
|
+
let i = z.object(Object.fromEntries(Object.entries(shape.properties).map(([key, value]) => {
|
|
172
|
+
return [
|
|
173
|
+
key,
|
|
174
|
+
checkRef(value, opts) ||
|
|
175
|
+
d(value, {
|
|
176
|
+
...opts,
|
|
177
|
+
path: opts.path + "/properties/" + key,
|
|
178
|
+
}),
|
|
179
|
+
];
|
|
180
|
+
})));
|
|
181
|
+
if (shape.catchall) {
|
|
182
|
+
i = i.catchall(d(shape.catchall, opts));
|
|
183
|
+
}
|
|
184
|
+
else if (shape.unknownKeys === "strict") {
|
|
185
|
+
i = i.strict();
|
|
186
|
+
}
|
|
187
|
+
else if (shape.unknownKeys === "passthrough") {
|
|
188
|
+
i = i.passthrough();
|
|
189
|
+
}
|
|
190
|
+
opts.pathToSchema.set(opts.path, i);
|
|
191
|
+
return i;
|
|
192
|
+
}),
|
|
193
|
+
record: ((shape, opts) => {
|
|
194
|
+
const i = z.record(checkRef(shape.key, opts) ||
|
|
195
|
+
d(shape.key, {
|
|
196
|
+
...opts,
|
|
197
|
+
path: opts.path + "/key",
|
|
198
|
+
}), checkRef(shape.value, opts) ||
|
|
199
|
+
d(shape.value, {
|
|
200
|
+
...opts,
|
|
201
|
+
path: opts.path + "/value",
|
|
202
|
+
}));
|
|
203
|
+
opts.pathToSchema.set(opts.path, i);
|
|
204
|
+
return i;
|
|
205
|
+
}),
|
|
206
|
+
map: ((shape, opts) => {
|
|
207
|
+
const i = z.map(checkRef(shape.key, opts) ||
|
|
208
|
+
d(shape.key, {
|
|
209
|
+
...opts,
|
|
210
|
+
path: opts.path + "/key",
|
|
211
|
+
}), checkRef(shape.value, opts) ||
|
|
212
|
+
d(shape.value, {
|
|
213
|
+
...opts,
|
|
214
|
+
path: opts.path + "/value",
|
|
215
|
+
}));
|
|
216
|
+
opts.pathToSchema.set(opts.path, i);
|
|
217
|
+
return i;
|
|
218
|
+
}),
|
|
219
|
+
nativeEnum: ((shape) => z.nativeEnum(shape.values)),
|
|
220
|
+
enum: ((shape) => z.enum(shape.values)),
|
|
221
|
+
union: ((shape, opts) => {
|
|
222
|
+
const i = z.union(shape.options.map((opt, idx) => checkRef(opt, opts) ||
|
|
223
|
+
d(opt, {
|
|
224
|
+
...opts,
|
|
225
|
+
path: opts.path + "/options/" + idx,
|
|
226
|
+
})));
|
|
227
|
+
opts.pathToSchema.set(opts.path, i);
|
|
228
|
+
return i;
|
|
229
|
+
}),
|
|
230
|
+
discriminatedUnion: ((shape, opts) => {
|
|
231
|
+
const i = z.discriminatedUnion(shape.discriminator, shape.options.map((opt, idx) => checkRef(opt, opts) ||
|
|
232
|
+
d(opt, {
|
|
233
|
+
...opts,
|
|
234
|
+
path: opts.path + "/options/" + idx,
|
|
235
|
+
})));
|
|
236
|
+
opts.pathToSchema.set(opts.path, i);
|
|
237
|
+
return i;
|
|
238
|
+
}),
|
|
239
|
+
intersection: ((shape, opts) => {
|
|
240
|
+
const i = z.intersection(checkRef(shape.left, opts) ||
|
|
241
|
+
d(shape.left, {
|
|
242
|
+
...opts,
|
|
243
|
+
path: opts.path + "/left",
|
|
244
|
+
}), checkRef(shape.right, opts) ||
|
|
245
|
+
d(shape.right, {
|
|
246
|
+
...opts,
|
|
247
|
+
path: opts.path + "/right",
|
|
248
|
+
}));
|
|
249
|
+
opts.pathToSchema.set(opts.path, i);
|
|
250
|
+
return i;
|
|
251
|
+
}),
|
|
252
|
+
function: ((shape, opts) => {
|
|
253
|
+
const i = z.function(checkRef(shape.args, opts) ||
|
|
254
|
+
d(shape.args, {
|
|
255
|
+
...opts,
|
|
256
|
+
path: opts.path + "/args",
|
|
257
|
+
}), checkRef(shape.returns, opts) ||
|
|
258
|
+
d(shape.returns, {
|
|
259
|
+
...opts,
|
|
260
|
+
path: opts.path + "/returns",
|
|
261
|
+
}));
|
|
262
|
+
opts.pathToSchema.set(opts.path, i);
|
|
263
|
+
return i;
|
|
264
|
+
}),
|
|
265
|
+
promise: ((shape, opts) => {
|
|
266
|
+
const i = z.promise(checkRef(shape.value, opts) ||
|
|
267
|
+
d(shape.value, {
|
|
268
|
+
...opts,
|
|
269
|
+
path: opts.path + "/value",
|
|
270
|
+
}));
|
|
271
|
+
opts.pathToSchema.set(opts.path, i);
|
|
272
|
+
return i;
|
|
273
|
+
}),
|
|
274
|
+
catch: ((shape, opts) => {
|
|
275
|
+
let base = checkRef(shape.innerType, opts) ||
|
|
276
|
+
d(shape.innerType, {
|
|
277
|
+
...opts,
|
|
278
|
+
path: opts.path + "/innerType",
|
|
279
|
+
});
|
|
280
|
+
base = base.catch(shape.value);
|
|
281
|
+
opts.pathToSchema.set(opts.path, base);
|
|
282
|
+
return base;
|
|
283
|
+
}),
|
|
284
|
+
effect: ((shape, opts) => {
|
|
285
|
+
let base = checkRef(shape.inner, opts) ||
|
|
286
|
+
d(shape.inner, {
|
|
287
|
+
...opts,
|
|
288
|
+
path: opts.path + "/inner",
|
|
289
|
+
});
|
|
290
|
+
if (!("superRefinements" in opts ||
|
|
291
|
+
"transforms" in opts ||
|
|
292
|
+
"preprocesses" in opts)) {
|
|
293
|
+
opts.pathToSchema.set(opts.path, base);
|
|
294
|
+
return base;
|
|
295
|
+
}
|
|
296
|
+
for (const { name, type } of shape.effects) {
|
|
297
|
+
if (type === "refinement" && opts.superRefinements?.[name]) {
|
|
298
|
+
base = base.superRefine(opts.superRefinements[name]);
|
|
299
|
+
}
|
|
300
|
+
else if (type === "transform" && opts.transforms?.[name]) {
|
|
301
|
+
base = base.transform(opts.transforms[name]);
|
|
302
|
+
}
|
|
303
|
+
else if (type === "preprocess" && opts.preprocesses?.[name]) {
|
|
304
|
+
base = z.preprocess(opts.preprocesses[name], base);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
opts.pathToSchema.set(opts.path, base);
|
|
308
|
+
return base;
|
|
309
|
+
}),
|
|
310
|
+
};
|
|
311
|
+
// Must match the exported Dezerialize types
|
|
312
|
+
// export function dezerialize<T extends SzType>(shape: T, opts?: DezerializerOptions): Dezerialize<T> {
|
|
313
|
+
export function dezerializeRefs(shape, opts) {
|
|
314
|
+
if ("isOptional" in shape) {
|
|
315
|
+
const { isOptional, ...rest } = shape;
|
|
316
|
+
const inner = d(rest, opts);
|
|
317
|
+
const result = isOptional ? inner.optional() : inner;
|
|
318
|
+
opts.pathToSchema.set(opts.path, result);
|
|
319
|
+
return result;
|
|
320
|
+
}
|
|
321
|
+
if ("isNullable" in shape) {
|
|
322
|
+
const { isNullable, ...rest } = shape;
|
|
323
|
+
const inner = d(rest, opts);
|
|
324
|
+
const result = isNullable ? inner.nullable() : inner;
|
|
325
|
+
opts.pathToSchema.set(opts.path, result);
|
|
326
|
+
return result;
|
|
327
|
+
}
|
|
328
|
+
if ("defaultValue" in shape) {
|
|
329
|
+
const { defaultValue, ...rest } = shape;
|
|
330
|
+
const inner = d(rest, opts);
|
|
331
|
+
const result = inner.default(shape.type === "bigInt"
|
|
332
|
+
? BigInt(defaultValue)
|
|
333
|
+
: shape.type === "date"
|
|
334
|
+
? new Date(defaultValue)
|
|
335
|
+
: defaultValue);
|
|
336
|
+
opts.pathToSchema.set(opts.path, result);
|
|
337
|
+
return result;
|
|
338
|
+
}
|
|
339
|
+
if ("readonly" in shape) {
|
|
340
|
+
const { readonly, ...rest } = shape;
|
|
341
|
+
const inner = d(rest, opts);
|
|
342
|
+
const result = readonly ? inner.readonly() : inner;
|
|
343
|
+
opts.pathToSchema.set(opts.path, result);
|
|
344
|
+
return result;
|
|
345
|
+
}
|
|
346
|
+
if ("description" in shape && typeof shape.description === "string") {
|
|
347
|
+
const { description, ...rest } = shape;
|
|
348
|
+
const inner = d(rest, opts);
|
|
349
|
+
const result = inner.describe(description);
|
|
350
|
+
opts.pathToSchema.set(opts.path, result);
|
|
351
|
+
return result;
|
|
352
|
+
}
|
|
353
|
+
return dezerializers[shape.type](shape, opts);
|
|
354
|
+
}
|
|
355
|
+
function resolvePointer(obj, pointer) {
|
|
356
|
+
const tokens = pointer.split("/").slice(1);
|
|
357
|
+
return tokens.reduce((acc, token) => {
|
|
358
|
+
/* c8 ignore next -- Guard */
|
|
359
|
+
if (acc === undefined)
|
|
360
|
+
return acc;
|
|
361
|
+
return acc[token.replace(/~1/g, "/").replace(/~0/g, "~")];
|
|
362
|
+
}, obj);
|
|
363
|
+
}
|
|
364
|
+
export function dezerialize(shape, opts = {}) {
|
|
365
|
+
if (!("path" in opts)) {
|
|
366
|
+
opts.path = "#";
|
|
367
|
+
}
|
|
368
|
+
if (!("pathToSchema" in opts)) {
|
|
369
|
+
opts.pathToSchema = new Map();
|
|
370
|
+
}
|
|
371
|
+
if (!("$refs" in opts)) {
|
|
372
|
+
opts.$refs = [];
|
|
373
|
+
}
|
|
374
|
+
if (!("originalShape" in opts)) {
|
|
375
|
+
opts.originalShape = shape;
|
|
376
|
+
}
|
|
377
|
+
const options = opts;
|
|
378
|
+
const dez = dezerializeRefs(shape, options);
|
|
379
|
+
for (const [lazy, $ref] of options.$refs) {
|
|
380
|
+
lazy._def.getter = () => {
|
|
381
|
+
const schema = options.pathToSchema.get($ref);
|
|
382
|
+
if (schema) {
|
|
383
|
+
return schema;
|
|
384
|
+
}
|
|
385
|
+
const obj = resolvePointer(options.originalShape, $ref);
|
|
386
|
+
// Ensure we act on the same options as the main document JSON
|
|
387
|
+
const dez = dezerialize(obj, options);
|
|
388
|
+
options.pathToSchema.set($ref, dez);
|
|
389
|
+
return dez;
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
return dez;
|
|
393
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SzType } from "./types.js";
|
|
2
|
+
export * from "./dezerialize.js";
|
|
3
|
+
export * from "./zerialize.js";
|
|
4
|
+
export * from "./types.js";
|
|
5
|
+
export { mapTypesToViews } from "./ui.js";
|
|
6
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
7
|
+
export type SzPropertyKeysOf<T extends SzType> = KeysOfUnion<Extract<T, {
|
|
8
|
+
type: "object";
|
|
9
|
+
}>["properties"]>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { SzType, SzOptional, SzNullable, SzArray, SzObject, SzUnion, SzDiscriminatedUnion, SzIntersection, SzTuple, SzRecord, SzMap, SzSet, SzFunction, SzEnum, SzPromise } from "./types.js";
|
|
2
|
+
type PrimitiveTypes = {
|
|
3
|
+
string: string;
|
|
4
|
+
number: number;
|
|
5
|
+
boolean: boolean;
|
|
6
|
+
nan: number;
|
|
7
|
+
date: Date;
|
|
8
|
+
symbol: symbol;
|
|
9
|
+
undefined: undefined;
|
|
10
|
+
null: null;
|
|
11
|
+
any: any;
|
|
12
|
+
unknown: unknown;
|
|
13
|
+
never: never;
|
|
14
|
+
void: void;
|
|
15
|
+
};
|
|
16
|
+
type RequiredKeys<T extends Record<string, any>> = {
|
|
17
|
+
[K in keyof T]: T[K] extends SzOptional ? never : K;
|
|
18
|
+
}[keyof T];
|
|
19
|
+
type OptionalKeys<T extends Record<string, any>> = {
|
|
20
|
+
[K in keyof T]: T[K] extends SzOptional ? K : never;
|
|
21
|
+
}[keyof T];
|
|
22
|
+
export type SzInfer<T extends SzType> = (T extends SzOptional ? undefined : never) | (T extends SzNullable ? null : never) | (T["type"] extends keyof PrimitiveTypes ? PrimitiveTypes[T["type"]] : T extends {
|
|
23
|
+
type: "literal";
|
|
24
|
+
} ? T["value"] : T extends SzArray<infer T> ? SzInfer<T>[] : T extends SzObject<infer Properties> ? {
|
|
25
|
+
[Key in RequiredKeys<Properties>]: SzInfer<Properties[Key]>;
|
|
26
|
+
} & {
|
|
27
|
+
[Key in OptionalKeys<Properties>]?: SzInfer<Properties[Key]>;
|
|
28
|
+
} : T extends SzUnion<infer Options> ? SzInfer<Options[number]> : T extends SzDiscriminatedUnion<infer _D, infer Options> ? SzInfer<Options[number]> : T extends SzIntersection<infer L, infer R> ? SzInfer<L> & SzInfer<R> : T extends SzTuple<infer Items> ? SzInfer<Items[number]>[] : T extends SzRecord<infer _Key, infer Value> ? Record<string, SzInfer<Value>> : T extends SzMap<infer _Key, infer Value> ? Record<string, SzInfer<Value>> : T extends SzSet<infer T> ? T[] : T extends SzFunction<infer Args, infer Return> ? (...args: SzInfer<Args>[]) => SzInfer<Return> : T extends SzEnum<infer Values> ? Values[number] : T extends SzPromise<infer Value> ? Promise<SzInfer<Value>> : unknown);
|
|
29
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "module"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { ValueOf } from "type-fest";
|
|
2
|
+
export type SzNumber = {
|
|
3
|
+
type: "number";
|
|
4
|
+
coerce?: boolean;
|
|
5
|
+
min?: number;
|
|
6
|
+
max?: number;
|
|
7
|
+
minInclusive?: boolean;
|
|
8
|
+
maxInclusive?: boolean;
|
|
9
|
+
multipleOf?: number;
|
|
10
|
+
int?: boolean;
|
|
11
|
+
finite?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type SzBigInt = {
|
|
14
|
+
type: "bigInt";
|
|
15
|
+
coerce?: boolean;
|
|
16
|
+
min?: string;
|
|
17
|
+
max?: string;
|
|
18
|
+
minInclusive?: boolean;
|
|
19
|
+
maxInclusive?: boolean;
|
|
20
|
+
multipleOf?: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const STRING_KINDS: Set<"email" | "url" | "emoji" | "uuid" | "nanoid" | "cuid" | "cuid2" | "ulid" | "date" | "duration" | "base64">;
|
|
23
|
+
export type SzString = {
|
|
24
|
+
type: "string";
|
|
25
|
+
coerce?: boolean;
|
|
26
|
+
min?: number;
|
|
27
|
+
max?: number;
|
|
28
|
+
length?: number;
|
|
29
|
+
startsWith?: string;
|
|
30
|
+
endsWith?: string;
|
|
31
|
+
toLowerCase?: boolean;
|
|
32
|
+
toUpperCase?: boolean;
|
|
33
|
+
trim?: boolean;
|
|
34
|
+
} & (object | {
|
|
35
|
+
includes: string;
|
|
36
|
+
position?: number;
|
|
37
|
+
}) & (object | {
|
|
38
|
+
kind: "ip";
|
|
39
|
+
version?: "v4" | "v6";
|
|
40
|
+
} | {
|
|
41
|
+
regex: string;
|
|
42
|
+
flags?: string;
|
|
43
|
+
} | {
|
|
44
|
+
kind: "time";
|
|
45
|
+
precision?: number;
|
|
46
|
+
} | {
|
|
47
|
+
kind: "datetime";
|
|
48
|
+
offset?: true;
|
|
49
|
+
local?: true;
|
|
50
|
+
precision?: number;
|
|
51
|
+
} | {
|
|
52
|
+
kind: typeof STRING_KINDS extends Set<infer T> ? T : never;
|
|
53
|
+
});
|
|
54
|
+
export type SzDate = {
|
|
55
|
+
type: "date";
|
|
56
|
+
coerce?: boolean;
|
|
57
|
+
min?: number;
|
|
58
|
+
max?: number;
|
|
59
|
+
};
|
|
60
|
+
export type SzBoolean = {
|
|
61
|
+
type: "boolean";
|
|
62
|
+
coerce?: boolean;
|
|
63
|
+
};
|
|
64
|
+
export type SzNaN = {
|
|
65
|
+
type: "nan";
|
|
66
|
+
};
|
|
67
|
+
export type SzUndefined = {
|
|
68
|
+
type: "undefined";
|
|
69
|
+
};
|
|
70
|
+
export type SzNull = {
|
|
71
|
+
type: "null";
|
|
72
|
+
};
|
|
73
|
+
export type SzAny = {
|
|
74
|
+
type: "any";
|
|
75
|
+
};
|
|
76
|
+
export type SzUnknown = {
|
|
77
|
+
type: "unknown";
|
|
78
|
+
};
|
|
79
|
+
export type SzNever = {
|
|
80
|
+
type: "never";
|
|
81
|
+
};
|
|
82
|
+
export type SzVoid = {
|
|
83
|
+
type: "void";
|
|
84
|
+
};
|
|
85
|
+
export type SzSymbol = {
|
|
86
|
+
type: "symbol";
|
|
87
|
+
};
|
|
88
|
+
export type SzPrimitive = SzBoolean | SzNumber | SzBigInt | SzString | SzNaN | SzDate | SzUndefined | SzNull | SzAny | SzUnknown | SzNever | SzVoid | SzSymbol;
|
|
89
|
+
export type SzLiteral<T> = {
|
|
90
|
+
type: "literal";
|
|
91
|
+
value: T;
|
|
92
|
+
};
|
|
93
|
+
export type SzArray<T extends SzType = SzType> = {
|
|
94
|
+
type: "array";
|
|
95
|
+
element: T;
|
|
96
|
+
minLength?: number;
|
|
97
|
+
maxLength?: number;
|
|
98
|
+
};
|
|
99
|
+
export type SzObject<T extends Record<string, SzType> = Record<string, SzType>, U extends SzType = SzType> = {
|
|
100
|
+
type: "object";
|
|
101
|
+
properties: T;
|
|
102
|
+
unknownKeys?: "strict" | "strip" | "passthrough";
|
|
103
|
+
catchall?: U;
|
|
104
|
+
};
|
|
105
|
+
export type SzUnion<Options extends [SzType, ...SzType[]] = [SzType]> = {
|
|
106
|
+
type: "union";
|
|
107
|
+
options: Options;
|
|
108
|
+
};
|
|
109
|
+
export type SzDiscriminatedUnionOption<Discriminator extends string> = {
|
|
110
|
+
[key in Discriminator]: SzType;
|
|
111
|
+
} & SzType;
|
|
112
|
+
export type SzDiscriminatedUnion<Discriminator extends string = string, Options extends SzDiscriminatedUnionOption<Discriminator>[] = []> = {
|
|
113
|
+
type: "discriminatedUnion";
|
|
114
|
+
discriminator: Discriminator;
|
|
115
|
+
options: Options;
|
|
116
|
+
};
|
|
117
|
+
export type SzIntersection<Left extends SzType = SzType, Right extends SzType = SzType> = {
|
|
118
|
+
type: "intersection";
|
|
119
|
+
left: Left;
|
|
120
|
+
right: Right;
|
|
121
|
+
};
|
|
122
|
+
export type SzTuple<Items extends [SzType, ...SzType[]] | [] = [SzType, ...SzType[]] | []> = {
|
|
123
|
+
type: "tuple";
|
|
124
|
+
items: Items;
|
|
125
|
+
rest?: SzType;
|
|
126
|
+
};
|
|
127
|
+
export type SzRecord<Key extends SzKey = SzKey, Value extends SzType = SzType> = {
|
|
128
|
+
type: "record";
|
|
129
|
+
key: Key;
|
|
130
|
+
value: Value;
|
|
131
|
+
};
|
|
132
|
+
export type SzMap<Key extends SzKey, Value extends SzType> = {
|
|
133
|
+
type: "map";
|
|
134
|
+
key: Key;
|
|
135
|
+
value: Value;
|
|
136
|
+
};
|
|
137
|
+
export type SzSet<T extends SzType = SzType> = {
|
|
138
|
+
type: "set";
|
|
139
|
+
value: T;
|
|
140
|
+
minSize?: number;
|
|
141
|
+
maxSize?: number;
|
|
142
|
+
};
|
|
143
|
+
export type SzFunction<Args extends SzTuple, Return extends SzType> = {
|
|
144
|
+
type: "function";
|
|
145
|
+
args: Args;
|
|
146
|
+
returns: Return;
|
|
147
|
+
};
|
|
148
|
+
export type SzEnum<Values extends [string, ...string[]] = [string, ...string[]]> = {
|
|
149
|
+
type: "enum";
|
|
150
|
+
values: Values;
|
|
151
|
+
};
|
|
152
|
+
export type SzNativeEnum<Values extends {
|
|
153
|
+
[key: string]: string | number;
|
|
154
|
+
[key: number]: string;
|
|
155
|
+
} = {
|
|
156
|
+
[key: string]: string | number;
|
|
157
|
+
[key: number]: string;
|
|
158
|
+
}> = {
|
|
159
|
+
type: "nativeEnum";
|
|
160
|
+
values: Values;
|
|
161
|
+
};
|
|
162
|
+
export type SzPromise<T extends SzType = SzType> = {
|
|
163
|
+
type: "promise";
|
|
164
|
+
value: T;
|
|
165
|
+
};
|
|
166
|
+
export type SzCatch<T extends SzType = SzType> = {
|
|
167
|
+
type: "catch";
|
|
168
|
+
value: any;
|
|
169
|
+
innerType: T;
|
|
170
|
+
};
|
|
171
|
+
export type SzEffect<T extends SzType = SzType> = {
|
|
172
|
+
type: "effect";
|
|
173
|
+
effects: {
|
|
174
|
+
name: string;
|
|
175
|
+
type: "refinement" | "transform" | "preprocess";
|
|
176
|
+
}[];
|
|
177
|
+
inner: T;
|
|
178
|
+
};
|
|
179
|
+
export type SzNullable = {
|
|
180
|
+
isNullable: boolean;
|
|
181
|
+
};
|
|
182
|
+
export type SzOptional = {
|
|
183
|
+
isOptional: boolean;
|
|
184
|
+
};
|
|
185
|
+
export type SzDefault<T> = {
|
|
186
|
+
defaultValue: T;
|
|
187
|
+
};
|
|
188
|
+
export type SzDescription = {
|
|
189
|
+
description: string;
|
|
190
|
+
};
|
|
191
|
+
export type SzReadonly = {
|
|
192
|
+
readonly: boolean;
|
|
193
|
+
};
|
|
194
|
+
export type SzRef = {
|
|
195
|
+
$ref: string;
|
|
196
|
+
};
|
|
197
|
+
export type SzExtras = Partial<SzNullable & SzOptional & SzDefault<any> & SzDescription & SzReadonly>;
|
|
198
|
+
export type SzKey = (SzString | SzNumber | SzSymbol) & SzExtras;
|
|
199
|
+
export type SzDefaultOrNullable = SzDefault<any> | SzNullable;
|
|
200
|
+
export type SzType = (SzPrimitive | SzLiteral<any> | SzArray<any> | SzObject<any, any> | SzUnion<any> | SzDiscriminatedUnion<any, any> | SzIntersection<any, any> | SzTuple<any> | SzRecord<any, any> | SzMap<any, any> | SzSet<any> | SzFunction<any, any> | SzEnum<any> | SzNativeEnum<any> | SzPromise<any> | SzEffect<any> | SzCatch<any>) & SzExtras;
|
|
201
|
+
export type SzUnionize<T extends SzType | SzRef> = T | (T extends SzArray<infer T> ? SzUnionize<T> : T extends SzObject<infer Properties> ? SzUnionize<ValueOf<Properties>> : T extends SzUnion<infer Options> ? SzUnionize<Options[number]> : T extends SzDiscriminatedUnion<infer _D, infer Options> ? SzUnionize<Options[number]> : T extends SzIntersection<infer L, infer R> ? SzUnionize<L | R> : T extends SzTuple<infer Items> ? SzUnionize<Items[number]> : T extends SzRecord<infer _Key, infer Value> ? SzUnionize<Value> : T extends SzMap<infer _Key, infer Value> ? SzUnionize<Value> : T extends SzSet<infer T> ? SzUnionize<T> : T extends SzFunction<infer Args, infer Return> ? SzUnionize<Args | Return> : T extends SzPromise<infer Value> ? SzUnionize<Value> : never);
|