arktype 3.0.0-beta.2 → 3.0.0-rc.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/README.md +55 -20
- package/out/_internal/regex/quantify.d.ts +17 -1
- package/out/_internal/schema/refinements/range.d.ts +2 -1
- package/out/_internal/schema/roots/domain.d.ts +1 -0
- package/out/_internal/schema/roots/root.d.ts +3 -1
- package/out/_internal/schema/roots/union.d.ts +8 -3
- package/out/_internal/schema/shared/compile.d.ts +2 -0
- package/out/_internal/schema/shared/declare.d.ts +9 -6
- package/out/_internal/schema/shared/errors.d.ts +3 -0
- package/out/_internal/schema/shared/issues.d.ts +5 -1
- package/out/_internal/schema/shared/issuesLean.d.ts +4 -0
- package/out/_internal/schema/shared/issuesNone.d.ts +1 -0
- package/out/_internal/schema/shared/issuesNoneLean.d.ts +1 -0
- package/out/_internal/schema/shared/standardFailure.d.ts +1 -0
- package/out/_internal/schema/shared/toJsonSchema.d.ts +16 -3
- package/out/_internal/schema/shared/transform.d.ts +1 -0
- package/out/_internal/sets/constraint.d.ts +2 -0
- package/out/_internal/sets/fromJsonSchema.d.ts +3 -1
- package/out/_internal/util/registry.d.ts +1 -1
- package/out/attributes.d.ts +12 -8
- package/out/{chunk-QBX4MEQR.js → chunk-3HZC67MT.js} +15 -15
- package/out/{chunk-5TN5JRP7.js → chunk-3KBOPH3J.js} +63 -41
- package/out/{chunk-NIZDOWFU.js → chunk-46PLKNON.js} +2 -2
- package/out/{chunk-7JXN4WJX.js → chunk-4FTHWK63.js} +1 -1
- package/out/{chunk-EA2DNEDI.js → chunk-4HREHNIV.js} +12 -12
- package/out/{chunk-J7CKAEDX.js → chunk-4NZCLVBD.js} +1 -1
- package/out/{chunk-7N3JEHA4.js → chunk-6FMBO47M.js} +1 -1
- package/out/{chunk-W77ROLOT.js → chunk-7TALAWYX.js} +1 -1
- package/out/{chunk-YMYPW3L5.js → chunk-BCYKO54Z.js} +3 -3
- package/out/{chunk-7SVIUP6X.js → chunk-C2JOL5M2.js} +2 -2
- package/out/{chunk-GPNWBJL3.js → chunk-C2V6QPE3.js} +17 -11
- package/out/{chunk-XMEK4I7J.js → chunk-C3B4IFQL.js} +887 -266
- package/out/{chunk-FY4M7GE7.js → chunk-FWRSDUJ2.js} +4 -4
- package/out/chunk-GID3FSQA.js +161 -0
- package/out/{chunk-CGWRW4JZ.js → chunk-K7SLP5D2.js} +4 -4
- package/out/{chunk-KDMHK4KP.js → chunk-KQPSKGUI.js} +2 -2
- package/out/{chunk-KVQCLBJR.js → chunk-KXOC3JEX.js} +241 -66
- package/out/{chunk-CQU7WIIR.js → chunk-KXOSUYRA.js} +6 -6
- package/out/{chunk-5WRZ25AB.js → chunk-MTWKGAGO.js} +4 -4
- package/out/{chunk-OA5Q2JLI.js → chunk-NU73GNCX.js} +8 -4
- package/out/{chunk-ZFB6DQWY.js → chunk-P5W67FQH.js} +6 -11
- package/out/{chunk-A7A6FDBS.js → chunk-PDLTEX6Z.js} +50 -44
- package/out/{chunk-RAM6G3F6.js → chunk-QUS4IAXJ.js} +26 -25
- package/out/{chunk-HA3POWOU.js → chunk-R7WXIH5P.js} +6 -5
- package/out/{chunk-YN3XRJ7H.js → chunk-UJJGG4VQ.js} +1 -1
- package/out/{chunk-NIYAI7AF.js → chunk-US6BWOGJ.js} +3 -3
- package/out/{chunk-JZ4KBCMM.js → chunk-VMMMOO4R.js} +21 -13
- package/out/{chunk-PIFOURNM.js → chunk-VYMXHSFR.js} +11 -4
- package/out/{chunk-57LF5Y5P.js → chunk-W2XOI5DY.js} +1 -1
- package/out/{chunk-SGFGLENC.js → chunk-WC5L5YRP.js} +3 -3
- package/out/{chunk-V4TZHFNK.js → chunk-WKOSL2G6.js} +1 -1
- package/out/{chunk-UH6XKS3C.js → chunk-XNUAQSJ4.js} +30 -9
- package/out/{chunk-C5JGK6GT.js → chunk-ZRYEHGSG.js} +20 -3
- package/out/cli.d.ts +5 -1
- package/out/cli.js +301 -49
- package/out/codecs.d.ts +4 -3
- package/out/codecs.js +18 -18
- package/out/config.js +8 -8
- package/out/declare.d.ts +2 -4
- package/out/errors.js +8 -8
- package/out/fn.d.ts +2 -2
- package/out/fromJsonSchema.d.ts +1 -1
- package/out/generic.d.ts +7 -4
- package/out/i18n.js +5 -5
- package/out/index.js +19 -19
- package/out/internal.js +32 -32
- package/out/island.js +18 -18
- package/out/islandDependency.js +33 -33
- package/out/jsonSchema/infer.d.ts +16 -6
- package/out/jsonSchema/validate.d.ts +16 -4
- package/out/keywords/functions.d.ts +4 -169
- package/out/keywords/keywords.d.ts +1 -1
- package/out/keywords/phrases.d.ts +3 -168
- package/out/keywords/ts.js +14 -14
- package/out/locales/de.js +6 -6
- package/out/locales/en.js +15 -15
- package/out/match.d.ts +12 -9
- package/out/mutatesInput.js +14 -14
- package/out/nary.d.ts +219 -193
- package/out/parser/definition.d.ts +2 -2
- package/out/parser/shift/operator/default.d.ts +2 -2
- package/out/parser/tupleExpressions.d.ts +2 -0
- package/out/precompiled.js +11 -11
- package/out/runtime.d.ts +1 -1
- package/out/runtime.js +5 -5
- package/out/schema.js +11 -11
- package/out/schemaInternal.js +29 -17
- package/out/schemaRuntime.js +4 -4
- package/out/schemaRuntimeLean.js +60 -36
- package/out/schemaRuntimeNone.js +52 -31
- package/out/schemaRuntimeNoneLean.js +52 -31
- package/out/type.d.ts +3 -3
- package/out/util.js +14 -11
- package/out/variants/base.d.ts +9 -8
- package/out/variants/object.d.ts +14 -6
- package/package.json +4 -4
- package/skills/arktype/SKILL.md +17 -17
- package/skills/arktype/references/migrating.md +13 -13
- package/skills/arktype/references/precompile.md +4 -4
- package/out/chunk-CSVAPWDE.js +0 -83
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
encode,
|
|
3
3
|
inverses
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-GID3FSQA.js";
|
|
5
5
|
import {
|
|
6
6
|
type
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-C2V6QPE3.js";
|
|
8
8
|
import {
|
|
9
9
|
capitalizeString,
|
|
10
10
|
keepFormatted,
|
|
@@ -23,10 +23,10 @@ import {
|
|
|
23
23
|
writeEpoch,
|
|
24
24
|
writeIsoDate,
|
|
25
25
|
writeUrl
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-4HREHNIV.js";
|
|
27
27
|
import {
|
|
28
28
|
$ark
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-PDLTEX6Z.js";
|
|
30
30
|
|
|
31
31
|
// ../schema/out/codecs.js
|
|
32
32
|
$ark.encode = encode;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import {
|
|
2
|
+
referencesWithoutCases,
|
|
3
|
+
withoutUndefined
|
|
4
|
+
} from "./chunk-KXOC3JEX.js";
|
|
5
|
+
import {
|
|
6
|
+
$ark
|
|
7
|
+
} from "./chunk-PDLTEX6Z.js";
|
|
8
|
+
import {
|
|
9
|
+
assertUnchecked,
|
|
10
|
+
defining,
|
|
11
|
+
hasArkKind,
|
|
12
|
+
isResolutionFinal
|
|
13
|
+
} from "./chunk-3KBOPH3J.js";
|
|
14
|
+
import {
|
|
15
|
+
omit,
|
|
16
|
+
throwParseError
|
|
17
|
+
} from "./chunk-3HZC67MT.js";
|
|
18
|
+
|
|
19
|
+
// ../schema/out/shared/codecs.js
|
|
20
|
+
var inverses = /* @__PURE__ */ new WeakMap();
|
|
21
|
+
var encoders = /* @__PURE__ */ new WeakMap();
|
|
22
|
+
var writeMissingInverseMessage = (expression) => `A morph must have an inverse to be encoded: ${expression}`;
|
|
23
|
+
var encode = function (node) {
|
|
24
|
+
let encoder = encoders.get(node);
|
|
25
|
+
if (!encoder) {
|
|
26
|
+
const isFinal = isResolutionFinal();
|
|
27
|
+
if (isFinal)
|
|
28
|
+
defining(() => {
|
|
29
|
+
});
|
|
30
|
+
let raw;
|
|
31
|
+
try {
|
|
32
|
+
raw = encoderOf(node);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
if (isFinal)
|
|
35
|
+
defining(() => {
|
|
36
|
+
});
|
|
37
|
+
throw e;
|
|
38
|
+
}
|
|
39
|
+
assertUnchecked();
|
|
40
|
+
encoders.set(node, encoder = node.$.fin(raw));
|
|
41
|
+
}
|
|
42
|
+
return encoder;
|
|
43
|
+
};
|
|
44
|
+
var encoderOf = function (node) {
|
|
45
|
+
const branchTfs = [];
|
|
46
|
+
const mapper = (kind, inner, ctx) => kind === "morph" ? invert(inner, node.$, mapper, ctx) : kind === "optional" && "default" in inner ? node.$.node("required", {
|
|
47
|
+
...omit(inner, { default: 1 }),
|
|
48
|
+
value: decodedValueOf(inner.value, node.$)
|
|
49
|
+
}) : kind === "structure" ? requireDefaulted(inner) : kind === "sequence" ? requireDefaultables(inner, node.$) : kind === "union" ? encodeUnion(inner, branchTfs.pop(), node.$) : inner;
|
|
50
|
+
return node.transform(mapper, {
|
|
51
|
+
shouldTf: (n) => {
|
|
52
|
+
const tfs = n.tfs || n.is("optional") && n.hasDef();
|
|
53
|
+
if (tfs && n.is("union"))
|
|
54
|
+
branchTfs.push(n.branches.map(transformsOnEncode));
|
|
55
|
+
return tfs;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
var transformsOnEncode = function (root) {
|
|
60
|
+
if (!root.tfs)
|
|
61
|
+
return false;
|
|
62
|
+
const visited = /* @__PURE__ */ new Set();
|
|
63
|
+
const queue = [root];
|
|
64
|
+
for (let i = 0; i < queue.length; i++) {
|
|
65
|
+
for (const ref of referencesWithoutCases(queue[i])) {
|
|
66
|
+
if (visited.has(ref))
|
|
67
|
+
continue;
|
|
68
|
+
visited.add(ref);
|
|
69
|
+
if (ref.is("morph"))
|
|
70
|
+
return true;
|
|
71
|
+
if (ref.is("structure") && ref.undeclared === "delete")
|
|
72
|
+
return true;
|
|
73
|
+
if (ref.is("alias") && !ref.isIo)
|
|
74
|
+
queue.push(ref.resolution);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
};
|
|
79
|
+
var encodeUnion = function (inner, tfs, $) {
|
|
80
|
+
if (inner.ordered) {
|
|
81
|
+
return {
|
|
82
|
+
...inner,
|
|
83
|
+
branches: sortByTfs(inner.branches, tfs),
|
|
84
|
+
ordered: true
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const plain = [];
|
|
88
|
+
const morphed = [];
|
|
89
|
+
for (let i = 0; i < inner.branches.length; i++) {
|
|
90
|
+
const branch = inner.branches[i];
|
|
91
|
+
if (branch.hasAlias ? tfs[i] : branch.tfs)
|
|
92
|
+
morphed.push(branch);
|
|
93
|
+
else
|
|
94
|
+
plain.push(branch);
|
|
95
|
+
}
|
|
96
|
+
if (!plain.length)
|
|
97
|
+
return { ...inner, branches: morphed };
|
|
98
|
+
if (!morphed.length)
|
|
99
|
+
return inner;
|
|
100
|
+
const morphedBranches = morphed.length > 1 ? $.node("union", { branches: morphed }).branches : morphed;
|
|
101
|
+
const overlapsPlain = plain.some((p) => morphedBranches.some((m) => p._in.overlaps(m._in)));
|
|
102
|
+
if (!overlapsPlain)
|
|
103
|
+
return { ...inner, branches: [...plain, ...morphedBranches] };
|
|
104
|
+
const plainBranches = plain.length > 1 ? $.node("union", { branches: plain }).branches : plain;
|
|
105
|
+
return {
|
|
106
|
+
...inner,
|
|
107
|
+
// a branch without morphs encodes a value unchanged, so try it before
|
|
108
|
+
// an overlapping codec branch
|
|
109
|
+
branches: [...plainBranches, ...morphedBranches],
|
|
110
|
+
ordered: true
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
var sortByTfs = (branches, tfs) => branches.map((branch, i) => [branch, tfs[i]]).sort((l, r) => Number(l[1]) - Number(r[1])).map(([branch]) => branch);
|
|
114
|
+
var invert = function (inner, $, mapper, ctx) {
|
|
115
|
+
let encoder = inner.declaredOut ?? $ark.kw.unknown.internal;
|
|
116
|
+
let inverse = inner.inverse;
|
|
117
|
+
const head = hasArkKind(inner.morphs[0], "root") ? inner.morphs[0] : void 0;
|
|
118
|
+
for (let i = inner.morphs.length - 1; i >= (head ? 1 : 0); i--) {
|
|
119
|
+
const morph = inner.morphs[i];
|
|
120
|
+
if (hasArkKind(morph, "root")) {
|
|
121
|
+
encoder = pipeEncoder(encoder, morph.transformWithin(mapper, ctx) ?? $ark.kw.unknown.internal);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
encoder = $.node("morph", {
|
|
125
|
+
morphs: [
|
|
126
|
+
encoder,
|
|
127
|
+
inverse ?? inverses.get(morph) ?? throwParseError(writeMissingInverseMessage($.node("morph", inner).expression))
|
|
128
|
+
],
|
|
129
|
+
inverse: morph
|
|
130
|
+
});
|
|
131
|
+
inverse = void 0;
|
|
132
|
+
}
|
|
133
|
+
const decodedIn = inner.declaredIn ?? head;
|
|
134
|
+
return decodedIn ? pipeEncoder(encoder, decodedIn) : encoder;
|
|
135
|
+
};
|
|
136
|
+
var pipeEncoder = (encoder, next) => encoder.isUnknown() ? next : next.isUnknown() ? encoder : encoder.rawPipeOnce(next);
|
|
137
|
+
var requireDefaulted = function (inner) {
|
|
138
|
+
if (!inner.optional)
|
|
139
|
+
return inner;
|
|
140
|
+
const props = [...inner.required ?? [], ...inner.optional];
|
|
141
|
+
return {
|
|
142
|
+
...inner,
|
|
143
|
+
required: props.filter((prop) => prop.is("required")),
|
|
144
|
+
optional: props.filter((prop) => prop.is("optional")),
|
|
145
|
+
order: inner.order ?? props.map((prop) => prop.key)
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
var requireDefaultables = function ({ defaultables = [], ...inner }, $) { return ({
|
|
149
|
+
...inner,
|
|
150
|
+
prefix: [
|
|
151
|
+
...inner.prefix ?? [],
|
|
152
|
+
...defaultables.map(([node]) => decodedValueOf(node, $))
|
|
153
|
+
]
|
|
154
|
+
}) };
|
|
155
|
+
var decodedValueOf = (value, $) => $.cfg.exactOptionalPropertyTypes === false ? withoutUndefined(value) : value;
|
|
156
|
+
|
|
157
|
+
export {
|
|
158
|
+
inverses,
|
|
159
|
+
writeMissingInverseMessage,
|
|
160
|
+
encode
|
|
161
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CompiledFunction
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-VYMXHSFR.js";
|
|
4
4
|
import {
|
|
5
5
|
ArkTraversal,
|
|
6
6
|
applyUnread
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-PDLTEX6Z.js";
|
|
8
8
|
import {
|
|
9
9
|
TransformErrors,
|
|
10
10
|
addMorphErrs,
|
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
allowsInContext,
|
|
13
13
|
applyCyclic,
|
|
14
14
|
transformResolution
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-3KBOPH3J.js";
|
|
16
16
|
import {
|
|
17
17
|
unset
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-3HZC67MT.js";
|
|
19
19
|
|
|
20
20
|
// ../schema/out/shared/rootApply.js
|
|
21
21
|
var rootApplyRuntime = {
|