arktype 3.0.0-beta.1 → 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 +48 -144
- package/out/_internal/regex/charset.d.ts +24 -0
- package/out/_internal/regex/escape.d.ts +29 -0
- package/out/_internal/regex/execArray.d.ts +24 -0
- package/out/_internal/regex/group.d.ts +34 -0
- package/out/_internal/regex/index.d.ts +2 -0
- package/out/_internal/regex/internal.d.ts +9 -0
- package/out/_internal/regex/parse.d.ts +10 -0
- package/out/_internal/regex/quantify.d.ts +59 -0
- package/out/_internal/regex/regex.d.ts +38 -0
- package/out/_internal/regex/state.d.ts +383 -0
- package/out/_internal/schema/codecs.d.ts +2 -0
- package/out/_internal/schema/config.d.ts +103 -0
- package/out/_internal/schema/constraint.d.ts +78 -0
- package/out/_internal/schema/errors.d.ts +1 -0
- package/out/_internal/schema/generic.d.ts +85 -0
- package/out/_internal/schema/i18n.d.ts +3 -0
- package/out/_internal/schema/index.d.ts +54 -0
- package/out/_internal/schema/internal.d.ts +15 -0
- package/out/_internal/schema/intrinsic.d.ts +28 -0
- package/out/_internal/schema/kinds.d.ts +76 -0
- package/out/_internal/schema/module.d.ts +23 -0
- package/out/_internal/schema/mutatesInput.d.ts +2 -0
- package/out/_internal/schema/node.d.ts +349 -0
- package/out/_internal/schema/parse.d.ts +77 -0
- package/out/_internal/schema/parseSchema.d.ts +116 -0
- package/out/_internal/schema/predicate.d.ts +46 -0
- package/out/_internal/schema/refinements/after.d.ts +32 -0
- package/out/_internal/schema/refinements/before.d.ts +32 -0
- package/out/_internal/schema/refinements/divisor.d.ts +41 -0
- package/out/_internal/schema/refinements/exactLength.d.ts +43 -0
- package/out/_internal/schema/refinements/kinds.d.ts +40 -0
- package/out/_internal/schema/refinements/max.d.ts +33 -0
- package/out/_internal/schema/refinements/maxLength.d.ts +32 -0
- package/out/_internal/schema/refinements/min.d.ts +33 -0
- package/out/_internal/schema/refinements/minLength.d.ts +32 -0
- package/out/_internal/schema/refinements/notEqual.d.ts +38 -0
- package/out/_internal/schema/refinements/notEqualLength.d.ts +38 -0
- package/out/_internal/schema/refinements/pattern.d.ts +43 -0
- package/out/_internal/schema/refinements/range.d.ts +101 -0
- package/out/_internal/schema/roots/alias.d.ts +49 -0
- package/out/_internal/schema/roots/basis.d.ts +12 -0
- package/out/_internal/schema/roots/domain.d.ts +45 -0
- package/out/_internal/schema/roots/intersection.d.ts +72 -0
- package/out/_internal/schema/roots/morph.d.ts +59 -0
- package/out/_internal/schema/roots/proto.d.ts +42 -0
- package/out/_internal/schema/roots/root.d.ts +163 -0
- package/out/_internal/schema/roots/union.d.ts +146 -0
- package/out/_internal/schema/roots/unit.d.ts +36 -0
- package/out/_internal/schema/runtime.d.ts +29 -0
- package/out/_internal/schema/runtimeLean.d.ts +2 -0
- package/out/_internal/schema/runtimeNone.d.ts +2 -0
- package/out/_internal/schema/runtimeNoneLean.d.ts +2 -0
- package/out/_internal/schema/scope.d.ts +203 -0
- package/out/_internal/schema/shared/codecs.d.ts +5 -0
- package/out/_internal/schema/shared/compile.d.ts +144 -0
- package/out/_internal/schema/shared/configured.d.ts +14 -0
- package/out/_internal/schema/shared/declare.d.ts +100 -0
- package/out/_internal/schema/shared/disjoint.d.ts +45 -0
- package/out/_internal/schema/shared/enWriters.d.ts +30 -0
- package/out/_internal/schema/shared/errorModes.d.ts +25 -0
- package/out/_internal/schema/shared/errorWriters.d.ts +34 -0
- package/out/_internal/schema/shared/errors.d.ts +264 -0
- package/out/_internal/schema/shared/implement.d.ts +154 -0
- package/out/_internal/schema/shared/inPlace.d.ts +8 -0
- package/out/_internal/schema/shared/issueFeatures.d.ts +38 -0
- package/out/_internal/schema/shared/issues.d.ts +261 -0
- package/out/_internal/schema/shared/issuesLean.d.ts +80 -0
- package/out/_internal/schema/shared/issuesNone.d.ts +22 -0
- package/out/_internal/schema/shared/issuesNoneLean.d.ts +20 -0
- package/out/_internal/schema/shared/issuesUndetailed.d.ts +25 -0
- package/out/_internal/schema/shared/jsonSchema.d.ts +153 -0
- package/out/_internal/schema/shared/listed.d.ts +15 -0
- package/out/_internal/schema/shared/locale.d.ts +149 -0
- package/out/_internal/schema/shared/registry.d.ts +16 -0
- package/out/_internal/schema/shared/render.d.ts +3 -0
- package/out/_internal/schema/shared/rootApply.d.ts +19 -0
- package/out/_internal/schema/shared/sets.d.ts +26 -0
- package/out/_internal/schema/shared/standardFailure.d.ts +22 -0
- package/out/_internal/schema/shared/standardSchema.d.ts +124 -0
- package/out/_internal/schema/shared/toJsonSchema.d.ts +229 -0
- package/out/_internal/schema/shared/transform.d.ts +35 -0
- package/out/_internal/schema/shared/traversal.d.ts +288 -0
- package/out/_internal/schema/shared/utils.d.ts +59 -0
- package/out/_internal/schema/structure/index.d.ts +43 -0
- package/out/_internal/schema/structure/optional.d.ts +61 -0
- package/out/_internal/schema/structure/prop.d.ts +45 -0
- package/out/_internal/schema/structure/required.d.ts +49 -0
- package/out/_internal/schema/structure/sequence.d.ts +127 -0
- package/out/_internal/schema/structure/shared.d.ts +3 -0
- package/out/_internal/schema/structure/structure.d.ts +178 -0
- package/out/_internal/schema/units.d.ts +123 -0
- package/out/_internal/sets/algebra.d.ts +26 -0
- package/out/_internal/sets/constraint.d.ts +19 -0
- package/out/_internal/sets/engine.d.ts +2 -0
- package/out/_internal/sets/formats.d.ts +23 -0
- package/out/_internal/sets/fromJsonSchema.d.ts +15 -0
- package/out/_internal/sets/implement.d.ts +16 -0
- package/out/_internal/sets/index.d.ts +2 -0
- package/out/_internal/sets/internal.d.ts +20 -0
- package/out/_internal/sets/intersections.d.ts +5 -0
- package/out/_internal/sets/kinds.d.ts +3 -0
- package/out/_internal/sets/refinements.d.ts +14 -0
- package/out/_internal/sets/roots/alias.d.ts +3 -0
- package/out/_internal/sets/roots/domain.d.ts +3 -0
- package/out/_internal/sets/roots/intersection.d.ts +4 -0
- package/out/_internal/sets/roots/morph.d.ts +4 -0
- package/out/_internal/sets/roots/proto.d.ts +3 -0
- package/out/_internal/sets/roots/union.d.ts +16 -0
- package/out/_internal/sets/roots/unit.d.ts +3 -0
- package/out/_internal/sets/structure/index.d.ts +3 -0
- package/out/_internal/sets/structure/prop.d.ts +8 -0
- package/out/_internal/sets/structure/sequence.d.ts +3 -0
- package/out/_internal/sets/structure/structure.d.ts +3 -0
- package/out/_internal/sets/toJsonSchema.d.ts +25 -0
- package/out/_internal/util/arrays.d.ts +130 -0
- package/out/_internal/util/clone.d.ts +4 -0
- package/out/_internal/util/describe.d.ts +25 -0
- package/out/_internal/util/domain.d.ts +49 -0
- package/out/_internal/util/errors.d.ts +29 -0
- package/out/_internal/util/facts.d.ts +22 -0
- package/out/_internal/util/flatMorph.d.ts +41 -0
- package/out/_internal/util/formats.d.ts +8 -0
- package/out/_internal/util/functions.d.ts +33 -0
- package/out/_internal/util/generics.d.ts +65 -0
- package/out/_internal/util/get.d.ts +9 -0
- package/out/_internal/util/hkt.d.ts +27 -0
- package/out/_internal/util/i18n.d.ts +12 -0
- package/out/_internal/util/index.d.ts +28 -0
- package/out/_internal/util/internal.d.ts +2 -0
- package/out/_internal/util/intersections.d.ts +50 -0
- package/out/_internal/util/isomorphic.d.ts +8 -0
- package/out/_internal/util/keys.d.ts +18 -0
- package/out/_internal/util/lazily.d.ts +7 -0
- package/out/_internal/util/numbers.d.ts +82 -0
- package/out/_internal/util/objectKinds.d.ts +157 -0
- package/out/_internal/util/path.d.ts +16 -0
- package/out/_internal/util/primitive.d.ts +16 -0
- package/out/_internal/util/records.d.ts +173 -0
- package/out/_internal/util/registry.d.ts +13 -0
- package/out/_internal/util/scanner.d.ts +110 -0
- package/out/_internal/util/serialize.d.ts +40 -0
- package/out/_internal/util/strings.d.ts +35 -0
- package/out/_internal/util/traits.d.ts +89 -0
- package/out/_internal/util/unionToTuple.d.ts +14 -0
- package/out/_internal/util/weak.d.ts +8 -0
- package/out/attributes.d.ts +15 -11
- package/out/checkers.d.ts +1 -1
- package/out/chunk-22RQSVV3.js +0 -0
- package/out/chunk-3HZC67MT.js +965 -0
- package/out/chunk-3KBOPH3J.js +1564 -0
- package/out/chunk-3SH2BQ4T.js +15 -0
- package/out/chunk-46PLKNON.js +126 -0
- package/out/{chunk-G45P2CLE.js → chunk-4FTHWK63.js} +6 -1
- package/out/{chunk-UK5UGFOX.js → chunk-4HREHNIV.js} +23 -11
- package/out/chunk-4NZCLVBD.js +14 -0
- package/out/chunk-6FMBO47M.js +7 -0
- package/out/chunk-7TALAWYX.js +10 -0
- package/out/{chunk-DLWCO4RV.js → chunk-BCYKO54Z.js} +11 -2
- package/out/chunk-BDJVONP7.js +168 -0
- package/out/{chunk-E3DZXEZK.js → chunk-C2JOL5M2.js} +4 -2
- package/out/{chunk-2U2AWCI3.js → chunk-C2V6QPE3.js} +126 -97
- package/out/chunk-C3B4IFQL.js +6408 -0
- package/out/chunk-CWSF57VM.js +10 -0
- package/out/chunk-F5BACUJS.js +7 -0
- package/out/{chunk-EVCML554.js → chunk-FWRSDUJ2.js} +14 -5
- package/out/chunk-GID3FSQA.js +161 -0
- package/out/chunk-I2KLQ2HA.js +22 -0
- package/out/chunk-K7SLP5D2.js +84 -0
- package/out/chunk-KQPSKGUI.js +9 -0
- package/out/chunk-KXOC3JEX.js +8234 -0
- package/out/chunk-KXOSUYRA.js +405 -0
- package/out/chunk-LHNEY6QW.js +0 -0
- package/out/chunk-MTWKGAGO.js +323 -0
- package/out/chunk-NU73GNCX.js +170 -0
- package/out/{chunk-RAZ3TXOE.js → chunk-P5W67FQH.js} +34 -19
- package/out/chunk-PDLTEX6Z.js +1118 -0
- package/out/{chunk-VV6YDN2D.js → chunk-QUS4IAXJ.js} +304 -263
- package/out/chunk-R7WXIH5P.js +94 -0
- package/out/chunk-TACLEIDM.js +95 -0
- package/out/chunk-UJJGG4VQ.js +71 -0
- package/out/chunk-US6BWOGJ.js +109 -0
- package/out/chunk-VMMMOO4R.js +945 -0
- package/out/chunk-VYMXHSFR.js +439 -0
- package/out/chunk-W2XOI5DY.js +141 -0
- package/out/chunk-WC5L5YRP.js +25 -0
- package/out/{chunk-NRIGTMPM.js → chunk-WKOSL2G6.js} +4 -1
- package/out/chunk-XLG66ZDF.js +0 -0
- package/out/{chunk-5U2ZMDNI.js → chunk-XNUAQSJ4.js} +52 -30
- package/out/chunk-ZRYEHGSG.js +79 -0
- package/out/cli.d.ts +28 -0
- package/out/cli.js +636 -0
- package/out/codecs.d.ts +6 -5
- package/out/codecs.js +23 -7
- package/out/config.d.ts +5 -17
- package/out/config.js +11 -2
- package/out/declare.d.ts +40 -12
- package/out/deferred.d.ts +2 -2
- package/out/errors.d.ts +1 -1
- package/out/errors.js +10 -2
- package/out/fn.d.ts +20 -13
- package/out/fromJsonSchema.d.ts +18 -0
- package/out/generic.d.ts +9 -6
- package/out/i18n.d.ts +2 -2
- package/out/i18n.js +9 -2
- package/out/index.d.ts +16 -7
- package/out/index.js +25 -8
- package/out/internal.d.ts +4 -0
- package/out/internal.js +41 -17
- package/out/island.js +22 -6
- package/out/islandDependency.js +42 -18
- package/out/jsonSchema/infer.d.ts +805 -0
- package/out/jsonSchema/validate.d.ts +416 -0
- package/out/keywords/Array.d.ts +2 -2
- package/out/keywords/builtins.d.ts +3 -3
- package/out/keywords/constructors.d.ts +1 -1
- package/out/keywords/functions.d.ts +5 -192
- package/out/keywords/keywords.d.ts +3 -3
- package/out/keywords/number.d.ts +2 -2
- package/out/keywords/phrases.d.ts +4 -191
- package/out/keywords/string.d.ts +3 -3
- package/out/keywords/ts.d.ts +18 -18
- package/out/keywords/ts.js +19 -4
- package/out/locale.d.ts +6 -2
- package/out/locales/de.js +9 -2
- package/out/locales/en.js +21 -5
- package/out/match.d.ts +13 -10
- package/out/module.d.ts +2 -2
- package/out/mutatesInput.js +18 -3
- package/out/nary.d.ts +220 -194
- package/out/parser/ast/bounds.d.ts +2 -2
- package/out/parser/ast/default.d.ts +2 -2
- package/out/parser/ast/divisor.d.ts +2 -2
- package/out/parser/ast/generic.d.ts +2 -2
- package/out/parser/ast/infer.d.ts +1 -1
- package/out/parser/ast/keyof.d.ts +2 -2
- package/out/parser/ast/utils.d.ts +1 -1
- package/out/parser/ast/validate.d.ts +2 -2
- package/out/parser/definition.d.ts +4 -4
- package/out/parser/objectLiteral.d.ts +2 -2
- package/out/parser/property.d.ts +2 -2
- package/out/parser/reduce/dynamic.d.ts +2 -2
- package/out/parser/reduce/shared.d.ts +1 -1
- package/out/parser/reduce/static.d.ts +1 -1
- package/out/parser/shift/operand/enclosed.d.ts +2 -2
- package/out/parser/shift/operand/genericArgs.d.ts +2 -2
- package/out/parser/shift/operand/operand.d.ts +1 -1
- package/out/parser/shift/operand/unenclosed.d.ts +2 -2
- package/out/parser/shift/operand/unresolvable.d.ts +2 -2
- package/out/parser/shift/operator/bounds.d.ts +2 -2
- package/out/parser/shift/operator/brand.d.ts +2 -2
- package/out/parser/shift/operator/default.d.ts +4 -4
- package/out/parser/shift/operator/divisor.d.ts +1 -1
- package/out/parser/shift/operator/operator.d.ts +1 -1
- package/out/parser/shift/tokens.d.ts +1 -1
- package/out/parser/string.d.ts +2 -2
- package/out/parser/tupleExpressions.d.ts +6 -8
- package/out/parser/tupleLiteral.d.ts +2 -2
- package/out/precompiled.d.ts +1 -1
- package/out/precompiled.js +16 -2
- package/out/regex.d.ts +1 -0
- package/out/regex.js +2 -0
- package/out/runtime.d.ts +10 -8
- package/out/runtime.js +6 -4
- package/out/runtimeDevelopment.js +70 -52
- package/out/schema.d.ts +1 -0
- package/out/schema.js +15 -0
- package/out/schemaInternal.d.ts +1 -0
- package/out/schemaInternal.js +1401 -0
- package/out/schemaIssueFeatures.d.ts +1 -0
- package/out/schemaRuntime.d.ts +1 -0
- package/out/schemaRuntime.js +7 -0
- package/out/schemaRuntimeLean.d.ts +1 -0
- package/out/schemaRuntimeLean.js +1870 -0
- package/out/schemaRuntimeNone.d.ts +1 -0
- package/out/schemaRuntimeNone.js +1774 -0
- package/out/schemaRuntimeNoneLean.d.ts +1 -0
- package/out/schemaRuntimeNoneLean.js +1767 -0
- package/out/scope.d.ts +3 -4
- package/out/shared/issueFeatures.d.ts +38 -0
- package/out/shared/issueFeatures.js +40 -0
- package/out/standalone/artifact.d.ts +6 -6
- package/out/standalone/baking.d.ts +2 -2
- package/out/standalone/combinators.d.ts +1 -1
- package/out/standalone/compilers.d.ts +1 -1
- package/out/standalone/fallbacks.d.ts +1 -1
- package/out/standalone/keys.d.ts +1 -1
- package/out/standalone/sites.d.ts +3 -3
- package/out/standalone/units.d.ts +1 -1
- package/out/standalone/values.d.ts +1 -1
- package/out/type.d.ts +6 -6
- package/out/util.d.ts +1 -0
- package/out/util.js +137 -0
- package/out/variants/array.d.ts +6 -6
- package/out/variants/base.d.ts +61 -10
- package/out/variants/date.d.ts +5 -5
- package/out/variants/instantiate.d.ts +1 -1
- package/out/variants/number.d.ts +6 -6
- package/out/variants/object.d.ts +25 -12
- package/out/variants/string.d.ts +8 -8
- package/package.json +183 -8
- package/skills/arktype/SKILL.md +93 -93
- package/skills/arktype/references/migrating.md +144 -158
- package/skills/arktype/references/precompile.md +7 -7
- package/out/chunk-4CUA5XIP.js +0 -7
- package/out/chunk-GPNK5353.js +0 -2529
- package/out/chunk-MLKGABMK.js +0 -9
- package/out/chunk-PRTMQCHS.js +0 -3
- package/out/chunk-R5G57XC7.js +0 -7
- package/out/chunk-SWOOCAHN.js +0 -4
- package/out/chunk-TAHPKDNM.js +0 -3
- package/out/chunk-UETB6YE2.js +0 -14
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import {
|
|
2
|
+
registerBuilderCompiler,
|
|
3
|
+
registeredReference
|
|
4
|
+
} from "./chunk-PDLTEX6Z.js";
|
|
5
|
+
import {
|
|
6
|
+
TransformErrors,
|
|
7
|
+
addMorphErrs,
|
|
8
|
+
allowsInBranchBy,
|
|
9
|
+
disallowed,
|
|
10
|
+
enterApplied,
|
|
11
|
+
exitApplied,
|
|
12
|
+
mergeTransformed,
|
|
13
|
+
rejected,
|
|
14
|
+
rejects,
|
|
15
|
+
transformIfAllowed,
|
|
16
|
+
transformResolution,
|
|
17
|
+
transformedInApply,
|
|
18
|
+
transformsValid
|
|
19
|
+
} from "./chunk-3KBOPH3J.js";
|
|
20
|
+
import {
|
|
21
|
+
CastableBase,
|
|
22
|
+
DynamicFunction,
|
|
23
|
+
hasDomain,
|
|
24
|
+
isDotAccessible,
|
|
25
|
+
serializePrimitive,
|
|
26
|
+
throwInternalError
|
|
27
|
+
} from "./chunk-3HZC67MT.js";
|
|
28
|
+
|
|
29
|
+
// ../schema/out/shared/compile.js
|
|
30
|
+
var writeErrorBuilder = function (context) {
|
|
31
|
+
let body = "error.data = data\nerror.path = path\n";
|
|
32
|
+
for (const k in context) {
|
|
33
|
+
const key = JSON.stringify(k);
|
|
34
|
+
body += `error[${key}] = context[${key}]
|
|
35
|
+
`;
|
|
36
|
+
}
|
|
37
|
+
for (const k of writtenSlots)
|
|
38
|
+
if (!(k in context))
|
|
39
|
+
body += `error.${k} = undefined
|
|
40
|
+
`;
|
|
41
|
+
return `${body}return error
|
|
42
|
+
`;
|
|
43
|
+
};
|
|
44
|
+
var writtenSlots = ["propString", "expected", "actual", "message"];
|
|
45
|
+
registerBuilderCompiler((context) => tryJit(() => new DynamicFunction("context", "path", "data", "error", writeErrorBuilder(context))));
|
|
46
|
+
var refusesJit = false;
|
|
47
|
+
var canJit = (config) => !config.jitless && !refusesJit;
|
|
48
|
+
var tryJit = function (jit) {
|
|
49
|
+
if (refusesJit)
|
|
50
|
+
return;
|
|
51
|
+
try {
|
|
52
|
+
return jit();
|
|
53
|
+
} catch (e) {
|
|
54
|
+
if (!(e instanceof EvalError))
|
|
55
|
+
throw e;
|
|
56
|
+
refusesJit = true;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var CompiledFunction = class extends CastableBase {
|
|
60
|
+
argNames;
|
|
61
|
+
lines = [];
|
|
62
|
+
get body() {
|
|
63
|
+
return this.lines.join("");
|
|
64
|
+
}
|
|
65
|
+
constructor(...args) {
|
|
66
|
+
super();
|
|
67
|
+
this.argNames = args;
|
|
68
|
+
for (const arg of args) {
|
|
69
|
+
if (arg in this) {
|
|
70
|
+
throw new Error(`Arg name '${arg}' would overwrite an existing property on FunctionBody`);
|
|
71
|
+
}
|
|
72
|
+
;
|
|
73
|
+
this[arg] = arg;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
indentation = 0;
|
|
77
|
+
indent() {
|
|
78
|
+
this.indentation += 4;
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
dedent() {
|
|
82
|
+
this.indentation -= 4;
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
prop(key, optional = false) {
|
|
86
|
+
return compileLiteralPropAccess(key, optional);
|
|
87
|
+
}
|
|
88
|
+
index(key, optional = false) {
|
|
89
|
+
return indexPropAccess(`${key}`, optional);
|
|
90
|
+
}
|
|
91
|
+
line(statement) {
|
|
92
|
+
this.lines.push(`${" ".repeat(this.indentation)}${statement}
|
|
93
|
+
`);
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
const(identifier, expression) {
|
|
97
|
+
this.line(`const ${identifier} = ${expression}`);
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
let(identifier, expression) {
|
|
101
|
+
return this.line(`let ${identifier} = ${expression}`);
|
|
102
|
+
}
|
|
103
|
+
set(identifier, expression) {
|
|
104
|
+
return this.line(`${identifier} = ${expression}`);
|
|
105
|
+
}
|
|
106
|
+
if(condition, then) {
|
|
107
|
+
return this.block(`if (${condition})`, then);
|
|
108
|
+
}
|
|
109
|
+
elseIf(condition, then) {
|
|
110
|
+
return this.block(`else if (${condition})`, then);
|
|
111
|
+
}
|
|
112
|
+
else(then) {
|
|
113
|
+
return this.block("else", then);
|
|
114
|
+
}
|
|
115
|
+
/** Current index is "i" */
|
|
116
|
+
for(until, body, initialValue = 0) {
|
|
117
|
+
return this.loop(`for (let i = ${initialValue}; ${until}; i++)`, body);
|
|
118
|
+
}
|
|
119
|
+
/** Current key is "k" */
|
|
120
|
+
forIn(object, body) {
|
|
121
|
+
return this.loop(`for (const k in ${object})`, body);
|
|
122
|
+
}
|
|
123
|
+
loopDepth = 0;
|
|
124
|
+
loop(prefix, body) {
|
|
125
|
+
this.loopDepth++;
|
|
126
|
+
this.block(prefix, body);
|
|
127
|
+
this.loopDepth--;
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
block(prefix, contents, suffix = "") {
|
|
131
|
+
this.line(`${prefix} {`);
|
|
132
|
+
this.indent();
|
|
133
|
+
contents(this);
|
|
134
|
+
this.dedent();
|
|
135
|
+
return this.line(`}${suffix}`);
|
|
136
|
+
}
|
|
137
|
+
return(expression = "") {
|
|
138
|
+
return this.line(`return ${expression}`);
|
|
139
|
+
}
|
|
140
|
+
write(name = "anonymous", indent = 0) {
|
|
141
|
+
return `${name}(${this.argNames.join(", ")}) { ${indent ? this.body.split("\n").map((l) => " ".repeat(indent) + `${l}`).join("\n") : this.body} }`;
|
|
142
|
+
}
|
|
143
|
+
compile() {
|
|
144
|
+
return new DynamicFunction(...this.argNames, this.body);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var compileSerializedValue = (value) => hasDomain(value, "object") || typeof value === "symbol" ? registeredReference(value) : serializePrimitive(value);
|
|
148
|
+
var compileLiteralPropAccess = function (key, optional = false) {
|
|
149
|
+
if (typeof key === "string" && isDotAccessible(key))
|
|
150
|
+
return `${optional ? "?" : ""}.${key}`;
|
|
151
|
+
return indexPropAccess(serializeLiteralKey(key), optional);
|
|
152
|
+
};
|
|
153
|
+
var serializeLiteralKey = (key) => typeof key === "symbol" ? registeredReference(key) : JSON.stringify(key);
|
|
154
|
+
var indexPropAccess = (key, optional = false) => `${optional ? "?." : ""}[${key}]`;
|
|
155
|
+
var expectedOf = (meta, description) => typeof meta.expected === "string" ? meta.expected : description;
|
|
156
|
+
var NodeCompiler = class extends CompiledFunction {
|
|
157
|
+
trav;
|
|
158
|
+
/** whether the traversal it compiles takes `ctx` */
|
|
159
|
+
needsCtx;
|
|
160
|
+
refs;
|
|
161
|
+
/** whether the transform it compiles checks for errors a transformed child added */
|
|
162
|
+
checksErrs = false;
|
|
163
|
+
constructor(ctx) {
|
|
164
|
+
super("data", "ctx");
|
|
165
|
+
this.trav = ctx.kind;
|
|
166
|
+
this.needsCtx = ctx.needsCtx ?? true;
|
|
167
|
+
this.refs = ctx.refs;
|
|
168
|
+
}
|
|
169
|
+
/** an expression calling node's traversal, or a referenced one's by id */
|
|
170
|
+
inv(node, opts) {
|
|
171
|
+
const arg = opts?.arg ?? this.data;
|
|
172
|
+
if (typeof node === "string")
|
|
173
|
+
return `${this.refToId(node, opts)}(${arg}, ${this.ctx})`;
|
|
174
|
+
const kind = opts?.kind ?? this.trav;
|
|
175
|
+
if (this.trav === "Transform" && kind === "Allows" && node.allowsCtx)
|
|
176
|
+
return this.allows(node, arg);
|
|
177
|
+
const reference = this.refToId(node.id, opts);
|
|
178
|
+
if (kind === "Transform" && node.tfsById)
|
|
179
|
+
return `${this.ref(transformResolution)}(${this.ctx}, "${this.nameOf(node.id)}", ${arg}, ${reference})`;
|
|
180
|
+
return this.needsCtxFor(node, kind) ? `${reference}(${arg}, ${this.ctx})` : `${reference}(${arg})`;
|
|
181
|
+
}
|
|
182
|
+
// Allows adds no errors to ctx, so a predicate reading it runs in a branch
|
|
183
|
+
allows(node, arg = this.data) {
|
|
184
|
+
if (!node.allowsCtx)
|
|
185
|
+
return this.inv(node, { arg, kind: "Allows" });
|
|
186
|
+
return node.checksCtx ? `${this.ref(allowsInBranchBy)}(${this.ctx}, ${this.refToId(node.id, { kind: "Allows" })}, ${arg})` : `${this.ref(node)}.allows(${arg})`;
|
|
187
|
+
}
|
|
188
|
+
applyMember(node, member = node) {
|
|
189
|
+
return member.hasAlias ? this.resolution(node, member.id) : this.inv(node);
|
|
190
|
+
}
|
|
191
|
+
// a cycle member is entered as a resolution, so it is applied once
|
|
192
|
+
resolution(node, id, arg = this.data) {
|
|
193
|
+
const apply = this.traversal(node, "Apply");
|
|
194
|
+
return `${this.ref(enterApplied)}(ctx, "${this.nameOf(id)}", ${arg}) ?? ${this.ref(exitApplied)}(ctx, ${apply}(${arg}, ctx))`;
|
|
195
|
+
}
|
|
196
|
+
refToId(id, opts) {
|
|
197
|
+
const invokedKind = opts?.kind ?? this.trav;
|
|
198
|
+
const base = `${this.nameOf(id)}${invokedKind}`;
|
|
199
|
+
return opts?.bind ? `${base}.bind(${opts?.bind})` : base;
|
|
200
|
+
}
|
|
201
|
+
// overridden to rename nodes in emitted code
|
|
202
|
+
nameOf(id) {
|
|
203
|
+
return id;
|
|
204
|
+
}
|
|
205
|
+
prop(key, optional = false) {
|
|
206
|
+
return typeof key === "symbol" ? indexPropAccess(this.ref(key), optional) : super.prop(key, optional);
|
|
207
|
+
}
|
|
208
|
+
serialize(value) {
|
|
209
|
+
return hasDomain(value, "object") || typeof value === "symbol" ? this.ref(value) : serializePrimitive(value);
|
|
210
|
+
}
|
|
211
|
+
/** validates that a numeric literal interpolated into generated JS is a number */
|
|
212
|
+
num(n) {
|
|
213
|
+
if (typeof n !== "number")
|
|
214
|
+
throwInternalError(`Expected a numeric literal (was ${typeof n})`);
|
|
215
|
+
return `${n}`;
|
|
216
|
+
}
|
|
217
|
+
ref(value) {
|
|
218
|
+
if (!this.refs)
|
|
219
|
+
return registeredReference(value);
|
|
220
|
+
let name = this.refs.get(value);
|
|
221
|
+
if (name === void 0)
|
|
222
|
+
this.refs.set(value, name = `r${this.refs.size}`);
|
|
223
|
+
return name;
|
|
224
|
+
}
|
|
225
|
+
site(node) {
|
|
226
|
+
return this.ref(node.failSite);
|
|
227
|
+
}
|
|
228
|
+
error(node, key, data = "data") {
|
|
229
|
+
return this.failsSite(this.site(node), data, key);
|
|
230
|
+
}
|
|
231
|
+
// a call failing a site, at a key of data where it's passed one, which
|
|
232
|
+
// arktype's traversal enters in its _at. A validator's errors take neither
|
|
233
|
+
// a site nor a key, so its compilers write the call another way
|
|
234
|
+
failsSite(site, data, key) {
|
|
235
|
+
return `ctx._at(${site}, ${data}${key === void 0 ? "" : `, ${key}`})`;
|
|
236
|
+
}
|
|
237
|
+
// a call failing one of two sites at a key of data: the first where a
|
|
238
|
+
// condition holds
|
|
239
|
+
failsEither(condition, site, otherwise, data, key) {
|
|
240
|
+
return this.failsSite(`${condition} ? ${site} : ${otherwise}`, data, key);
|
|
241
|
+
}
|
|
242
|
+
// a call applying data's value at a key, by SiteFailureContext's short name
|
|
243
|
+
failsIn(args) {
|
|
244
|
+
return `ctx._in(${args})`;
|
|
245
|
+
}
|
|
246
|
+
// what _in takes after data: the key, the site it's missing at and its
|
|
247
|
+
// value. Read where it's compiled, a value's key is a constant, where ctx
|
|
248
|
+
// reads data by whatever key any site passes, which V8 can only look up
|
|
249
|
+
applied(key, value, missing) {
|
|
250
|
+
return this.shortest || this.readsApplied ? missing === void 0 ? key : `${key}, ${missing}` : `${key}, ${missing ?? "void 0"}, ${value}`;
|
|
251
|
+
}
|
|
252
|
+
// a case returning what the next one does falls through to it
|
|
253
|
+
switch(on, cases, otherwise) {
|
|
254
|
+
return this.block(`switch(${on})`, () => {
|
|
255
|
+
for (const [i, [label, returned]] of cases.entries()) {
|
|
256
|
+
const next = cases[i + 1];
|
|
257
|
+
const fallsThrough = label !== "default" && next?.[0] !== "default" && next?.[1] === returned;
|
|
258
|
+
this.line(fallsThrough ? `${label}:` : `${label}: return ${returned}`);
|
|
259
|
+
}
|
|
260
|
+
return this;
|
|
261
|
+
}).return(otherwise);
|
|
262
|
+
}
|
|
263
|
+
needsCtxFor(node, kind = this.trav) {
|
|
264
|
+
return this.trav === "Apply" || (kind === "Transform" ? node.tfCtx : node.allowsCtx);
|
|
265
|
+
}
|
|
266
|
+
// rejects data Allows can't read an object's first key from
|
|
267
|
+
rejectNullish(node) {
|
|
268
|
+
return this.block("switch (data)", () => this.line(`case null: case undefined: return ${this.rejection(node)}`));
|
|
269
|
+
}
|
|
270
|
+
// a transforming object's Allows rejects through disallowed; a build for size returns false
|
|
271
|
+
rejection(node) {
|
|
272
|
+
return this.trav === "Allows" && !this.shortest && node.tfs ? `${this.ref(disallowed)}()` : "false";
|
|
273
|
+
}
|
|
274
|
+
initErrCount() {
|
|
275
|
+
return this.const("errN", "ctx.errN");
|
|
276
|
+
}
|
|
277
|
+
travKey(keyExpr, accessExpression, node) {
|
|
278
|
+
const fails = this.keyFails(keyExpr, accessExpression, node);
|
|
279
|
+
if (fails !== void 0)
|
|
280
|
+
return this.if(fails, () => this.return(false));
|
|
281
|
+
if (this.trav === "Apply")
|
|
282
|
+
return this.applyKey(keyExpr, accessExpression, node);
|
|
283
|
+
if (this.loopDepth > 0 && isRefinedPattern(node)) {
|
|
284
|
+
const allows = this.traversal(node, "Allows");
|
|
285
|
+
return this.const("value", accessExpression).if(`!${allows}(value)`, () => this.return(`${this.ref(rejected)}(${allows}, value)`));
|
|
286
|
+
}
|
|
287
|
+
this.line(`${this.ctx}.path.push(${keyExpr})`);
|
|
288
|
+
this.check(node, { arg: accessExpression });
|
|
289
|
+
return this.line(`${this.ctx}.path.pop()`);
|
|
290
|
+
}
|
|
291
|
+
keyFails(key, value, node) {
|
|
292
|
+
if (this.trav !== "Apply") {
|
|
293
|
+
const condition2 = node.jsCond?.(this, value);
|
|
294
|
+
if (condition2 !== void 0)
|
|
295
|
+
return `!(${condition2})`;
|
|
296
|
+
if (this.loopDepth > 0 && isRefinedPattern(node) || node.allowsCtx && node.checksCtx)
|
|
297
|
+
return;
|
|
298
|
+
return `!${this.inv(node, { arg: value })}`;
|
|
299
|
+
}
|
|
300
|
+
if (node.hasMorph || node.hasAlias)
|
|
301
|
+
return;
|
|
302
|
+
if (node.tfs && node.allowsCtx && node.checksCtx)
|
|
303
|
+
return;
|
|
304
|
+
const checksAllowsFirst = node.tfs || (this.loopDepth > 0 || node.is("union") && !node.discriminant) && isDecidedByAllows(node);
|
|
305
|
+
const condition = node.is("union") && !checksAllowsFirst ? void 0 : node.jsCond?.(this, value);
|
|
306
|
+
if (condition !== void 0 && !node.is("union"))
|
|
307
|
+
return `!(${condition}) && ${this.error(node, key)}`;
|
|
308
|
+
const allows = !checksAllowsFirst ? "" : isRefinedPattern(node) ? `${this.ref(rejects)}(${this.traversal(node, "Allows")}, ${value}) && ` : condition === void 0 ? `!${this.allows(node, value)} && ` : `!(${condition}) && `;
|
|
309
|
+
if (checksAllowsFirst && isRefinedBasis(node))
|
|
310
|
+
return `${allows}${this.failsEither(node.basis.jsCond(this, value), this.site(node.preStruct[0]), this.site(node.basis), "data", key)}`;
|
|
311
|
+
return `${allows}${this.failsIn(`${this.traversal(node, "Apply")}, ${this.data}, ${this.applied(key, value)}`)}`;
|
|
312
|
+
}
|
|
313
|
+
// a cyclic value is applied inline
|
|
314
|
+
applyKey(key, value, node) {
|
|
315
|
+
const apply = node.entersAlias && node.hasAlias ? `(${this.resolution(node, node.id, value)})` : this.inv(node, { arg: value });
|
|
316
|
+
const fails = () => this.line("ctx.path.pop()").return(false);
|
|
317
|
+
this.line(`ctx.path.push(${key})`);
|
|
318
|
+
if (!node.hasAlias) {
|
|
319
|
+
this.if(`${this.ref(transformsValid)}(ctx) && ${this.allows(node, value)}`, () => this.line(`${this.ref(transformedInApply)}(ctx, ${this.inv(node, { arg: value, kind: "Transform" })})`)).elseIf(`!${apply}`, fails);
|
|
320
|
+
} else {
|
|
321
|
+
this.if(node.tfs ? `!(${this.ref(transformIfAllowed)}(ctx, ${this.ref(node)}, ${value}) || ${apply})` : `!${apply}`, fails);
|
|
322
|
+
}
|
|
323
|
+
return this.line("ctx.path.pop()");
|
|
324
|
+
}
|
|
325
|
+
initTf(transformedChildren) {
|
|
326
|
+
this.checksErrs = transformedChildren.some((child) => child.hasMorph || child.tfCtx);
|
|
327
|
+
if (!this.checksErrs)
|
|
328
|
+
return this;
|
|
329
|
+
return this.needsCtx ? this.initErrCount() : this.line("let failed");
|
|
330
|
+
}
|
|
331
|
+
tfKey(name, input, steps, opts) {
|
|
332
|
+
const nodes = steps.map((step) => step.node);
|
|
333
|
+
const keyExpr = opts?.keyExpr;
|
|
334
|
+
const assign = (assignee, node, arg) => {
|
|
335
|
+
const pushesKey = keyExpr !== void 0 && node.tfCtx;
|
|
336
|
+
if (pushesKey)
|
|
337
|
+
this.line(`${this.ctx}.path.push(${keyExpr})`);
|
|
338
|
+
const transformed = arg === input ? this.inv(node, { arg }) : `${arg} === ${input} || ${this.ref(node)}.allows(${arg}) ? ${this.inv(node, { arg })} : ${this.ref(mergeTransformed)}(${input}, ${arg}, ${this.inv(node, { arg: input })})`;
|
|
339
|
+
this.line(`${assignee} = ${transformed}`);
|
|
340
|
+
return pushesKey ? this.line(`${this.ctx}.path.pop()`) : this;
|
|
341
|
+
};
|
|
342
|
+
const isTransformErrors = () => `typeof ${name} === "function" && ${name} instanceof ${this.ref(TransformErrors)}`;
|
|
343
|
+
const assignSteps = () => {
|
|
344
|
+
const errN = `${name}ErrorCount`;
|
|
345
|
+
if (nodes.slice(0, -1).some((node) => node.tfCtx))
|
|
346
|
+
this.const(errN, `${this.ctx}.errN`);
|
|
347
|
+
for (let i = 0; i < steps.length; i++) {
|
|
348
|
+
const { node, signature } = steps[i];
|
|
349
|
+
const previous = nodes.slice(0, i);
|
|
350
|
+
const conditions = signature ? [this.inv(signature, { arg: keyExpr, kind: "Allows" })] : [];
|
|
351
|
+
if (previous.some(returnsTransformErrors))
|
|
352
|
+
conditions.push(`!(${isTransformErrors()})`);
|
|
353
|
+
if (previous.some((node2) => node2.tfCtx))
|
|
354
|
+
conditions.push(`${this.ctx}.errN === ${errN}`);
|
|
355
|
+
const assignStep = () => assign(name, node, i === 0 ? input : name);
|
|
356
|
+
if (conditions.length)
|
|
357
|
+
this.if(conditions.join(" && "), assignStep);
|
|
358
|
+
else
|
|
359
|
+
assignStep();
|
|
360
|
+
}
|
|
361
|
+
return this;
|
|
362
|
+
};
|
|
363
|
+
if (steps.length === 1 && !steps[0].signature && !opts?.condition)
|
|
364
|
+
assign(`const ${name}`, steps[0].node, input);
|
|
365
|
+
else {
|
|
366
|
+
this.let(name, input);
|
|
367
|
+
if (opts?.condition)
|
|
368
|
+
this.if(opts.condition, assignSteps);
|
|
369
|
+
else
|
|
370
|
+
assignSteps();
|
|
371
|
+
}
|
|
372
|
+
const onChange = () => {
|
|
373
|
+
opts?.onChange?.();
|
|
374
|
+
return this;
|
|
375
|
+
};
|
|
376
|
+
const checksErrors = nodes.some(returnsTransformErrors);
|
|
377
|
+
if (!checksErrors && !opts?.onChange)
|
|
378
|
+
return this;
|
|
379
|
+
return this.if(this.cmpTfd(steps, name, "!==", input), () => {
|
|
380
|
+
if (!checksErrors)
|
|
381
|
+
return onChange();
|
|
382
|
+
this.if(isTransformErrors(), () => this.addMorphErrs(name, keyExpr));
|
|
383
|
+
return opts?.onChange ? this.else(onChange) : this;
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
addMorphErrs(errors, keyExpr) {
|
|
387
|
+
const key = keyExpr === void 0 ? "" : `, ${keyExpr}`;
|
|
388
|
+
return this.line(this.needsCtx ? `${this.ref(addMorphErrs)}(${this.ctx}, ${errors}${key})` : `failed = ${errors}.addTo(failed${key})`);
|
|
389
|
+
}
|
|
390
|
+
cmpTfd(steps, transformed, operator, input) {
|
|
391
|
+
const canChangeSignOfZero = steps.some(({ node }) => node.isRoot() && node.branches.some((n) => !n.is("intersection")));
|
|
392
|
+
return canChangeSignOfZero ? `${operator === "===" ? "" : "!"}Object.is(${transformed}, ${input})` : `${transformed} ${operator} ${input}`;
|
|
393
|
+
}
|
|
394
|
+
retIfFailed() {
|
|
395
|
+
if (!this.checksErrs)
|
|
396
|
+
return this;
|
|
397
|
+
return this.needsCtx ? this.if("ctx.errN > errN", () => this.return("data")) : this.if("failed", () => this.return("failed"));
|
|
398
|
+
}
|
|
399
|
+
condition(node) {
|
|
400
|
+
return node.jsCond?.(this, this.data) ?? this.inv(node);
|
|
401
|
+
}
|
|
402
|
+
check(node, opts) {
|
|
403
|
+
const arg = opts?.arg ?? this.data;
|
|
404
|
+
const condition = opts?.kind || this.trav === "Apply" && node.is("union") ? void 0 : node.jsCond?.(this, arg);
|
|
405
|
+
const fail = () => opts?.breaks ? this.line("break") : this.return(false);
|
|
406
|
+
if (condition === void 0)
|
|
407
|
+
return this.if(`!${this.inv(node, opts)}`, fail);
|
|
408
|
+
return this.if(this.trav === "Allows" ? `!(${condition})` : `!(${condition}) && ${this.error(node, void 0, arg)}`, fail);
|
|
409
|
+
}
|
|
410
|
+
checkLeaf(node) {
|
|
411
|
+
const condition = node.jsCond(this, this.data);
|
|
412
|
+
return this.return(this.trav === "Allows" ? condition : `${condition} || !${this.error(node)}`);
|
|
413
|
+
}
|
|
414
|
+
// a traversal passed as a value rather than called
|
|
415
|
+
traversal(node, kind) {
|
|
416
|
+
return this.refToId(node.id, { kind });
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
var returnsTransformErrors = (node) => node.hasMorph && !node.tfCtx;
|
|
420
|
+
var isPredicate = (node) => node.is("predicate");
|
|
421
|
+
var isDecidedByAllows = (node) => !node.hasMorph && !node.allowsCtx && !node.selectReferences(isPredicate).length;
|
|
422
|
+
var isRefinedBasis = (node) => node.is("intersection") && node.basis !== null && node.children.length === 2 && node.preStruct.length === 1;
|
|
423
|
+
var isRefinedPattern = (node) => isRefinedBasis(node) && node.preStruct[0].is("pattern");
|
|
424
|
+
|
|
425
|
+
export {
|
|
426
|
+
canJit,
|
|
427
|
+
tryJit,
|
|
428
|
+
CompiledFunction,
|
|
429
|
+
compileSerializedValue,
|
|
430
|
+
compileLiteralPropAccess,
|
|
431
|
+
serializeLiteralKey,
|
|
432
|
+
indexPropAccess,
|
|
433
|
+
expectedOf,
|
|
434
|
+
NodeCompiler,
|
|
435
|
+
returnsTransformErrors,
|
|
436
|
+
isDecidedByAllows,
|
|
437
|
+
isRefinedBasis,
|
|
438
|
+
isRefinedPattern
|
|
439
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineValue,
|
|
3
|
+
hasKey,
|
|
4
|
+
includes,
|
|
5
|
+
isEmptyObject,
|
|
6
|
+
printable,
|
|
7
|
+
throwParseError
|
|
8
|
+
} from "./chunk-3HZC67MT.js";
|
|
9
|
+
|
|
10
|
+
// ../schema/out/shared/jsonSchema.js
|
|
11
|
+
var ToJsonSchemaError = class extends Error {
|
|
12
|
+
name = "ToJsonSchemaError";
|
|
13
|
+
code;
|
|
14
|
+
context;
|
|
15
|
+
constructor(code, context, path = "", message = `Can't convert "${code}"${path && ` at ${path}`} to JSON Schema. Configure fallback.${code} to write it:
|
|
16
|
+
${printable(context, { quoteKeys: false, indent: 4 })}`) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.context = context;
|
|
20
|
+
}
|
|
21
|
+
hasCode(code) {
|
|
22
|
+
return this.code === code;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var supportedJsonSchemaTargets = [
|
|
26
|
+
"draft-2020-12",
|
|
27
|
+
"draft-07",
|
|
28
|
+
"openapi-3.0"
|
|
29
|
+
];
|
|
30
|
+
var toJsonSchemaTargets = [
|
|
31
|
+
"draft-2020-12",
|
|
32
|
+
"draft-07",
|
|
33
|
+
"openapi-3.0",
|
|
34
|
+
"openapi-3.1"
|
|
35
|
+
];
|
|
36
|
+
var writeInvalidJsonSchemaTargetMessage = (target, targets = supportedJsonSchemaTargets) => {
|
|
37
|
+
const quoted = targets.map((t) => `"${t}"`);
|
|
38
|
+
return `JSONSchema target '${target}' is not supported (must be ${quoted.slice(0, -1).join(", ")} or ${quoted[quoted.length - 1]})`;
|
|
39
|
+
};
|
|
40
|
+
var validateStandardJsonSchemaTarget = (target) => {
|
|
41
|
+
if (!includes(supportedJsonSchemaTargets, target))
|
|
42
|
+
throwParseError(writeInvalidJsonSchemaTargetMessage(target));
|
|
43
|
+
return target;
|
|
44
|
+
};
|
|
45
|
+
var validateToJsonSchemaTarget = (target) => {
|
|
46
|
+
if (!includes(toJsonSchemaTargets, target)) {
|
|
47
|
+
throwParseError(writeInvalidJsonSchemaTargetMessage(target, toJsonSchemaTargets));
|
|
48
|
+
}
|
|
49
|
+
return target;
|
|
50
|
+
};
|
|
51
|
+
var openApiNull = () => ({
|
|
52
|
+
type: "string",
|
|
53
|
+
nullable: true,
|
|
54
|
+
enum: [null]
|
|
55
|
+
});
|
|
56
|
+
var writeUnionJsonSchema = (branches, target, meta, metaJson, discriminant) => {
|
|
57
|
+
if (!branches.length)
|
|
58
|
+
return { not: {} };
|
|
59
|
+
if (branches.length === 1)
|
|
60
|
+
return branches[0];
|
|
61
|
+
const unitKey = target === "openapi-3.0" ? "enum" : "const";
|
|
62
|
+
if (branches.every((branch) => (
|
|
63
|
+
// units with no meta but the union's own are an enum
|
|
64
|
+
Object.entries(branch).every(([k, v]) => k === unitKey || k === "type" || v === meta[k] || v === metaJson[k]) && hasKey(branch, unitKey)
|
|
65
|
+
))) {
|
|
66
|
+
const values = branches.flatMap((branch) => unitKey === "enum" ? branch.enum : [branch.const]);
|
|
67
|
+
const { type } = branches[0];
|
|
68
|
+
return type && branches.every((branch) => branch.type === type) ? { type, enum: values } : { enum: values };
|
|
69
|
+
}
|
|
70
|
+
return discriminant && branches.every(requiresKeyOf(discriminant.key)) ? writeOneOf(branches, discriminant) : { anyOf: branches };
|
|
71
|
+
};
|
|
72
|
+
var requiresKeyOf = (key) => (branch) => "$ref" in branch || !!branch.required?.includes(key);
|
|
73
|
+
var writeOneOf = (branches, { key, values, writesKeyword }) => {
|
|
74
|
+
if (!writesKeyword)
|
|
75
|
+
return { oneOf: branches };
|
|
76
|
+
const mapping = {};
|
|
77
|
+
for (let i = 0; i < branches.length; i++) {
|
|
78
|
+
const ref = branches[i].$ref;
|
|
79
|
+
if (ref)
|
|
80
|
+
for (const value of values[i])
|
|
81
|
+
defineValue(mapping, value, ref);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
oneOf: branches,
|
|
85
|
+
discriminator: isEmptyObject(mapping) ? { propertyName: key } : { propertyName: key, mapping }
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
var writeNullableJsonSchema = (schema, isUnion, target) => {
|
|
89
|
+
if (target === "openapi-3.0" && typeof schema.type === "string") {
|
|
90
|
+
return Object.assign(schema, { nullable: true }, "enum" in schema && {
|
|
91
|
+
enum: [...schema.enum, null]
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
anyOf: [
|
|
96
|
+
...isUnion && "anyOf" in schema ? schema.anyOf : [schema],
|
|
97
|
+
target === "openapi-3.0" ? openApiNull() : { type: "null" }
|
|
98
|
+
]
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// ../schema/out/shared/configured.js
|
|
103
|
+
var isPlain = (value) => {
|
|
104
|
+
const proto = Object.getPrototypeOf(value);
|
|
105
|
+
return proto === Object.prototype || proto === null;
|
|
106
|
+
};
|
|
107
|
+
var copyPlain = (value) => typeof value !== "object" || value === null ? value : Array.isArray(value) ? value.map(copyPlain) : isPlain(value) ? Object.fromEntries(Object.entries(value).map(([k, v]) => [k, copyPlain(v)])) : value;
|
|
108
|
+
var copyConfig = (config) => {
|
|
109
|
+
const copy = {};
|
|
110
|
+
for (const k in config) {
|
|
111
|
+
const v = config[k];
|
|
112
|
+
copy[k] = k === "locale" ? v : copyPlain(v);
|
|
113
|
+
}
|
|
114
|
+
return copy;
|
|
115
|
+
};
|
|
116
|
+
var isSameConfig = (l, r) => {
|
|
117
|
+
if (l === r)
|
|
118
|
+
return true;
|
|
119
|
+
if (typeof l === "function" && typeof r === "function") {
|
|
120
|
+
const source = Function.prototype.toString.call(l);
|
|
121
|
+
return source === Function.prototype.toString.call(r) && !/\[native code]\s*}$/.test(source);
|
|
122
|
+
}
|
|
123
|
+
if (typeof l !== "object" || typeof r !== "object" || !l || !r)
|
|
124
|
+
return false;
|
|
125
|
+
const entries = Object.entries(l);
|
|
126
|
+
return entries.length === Object.keys(r).length && entries.every(([k, v]) => Object.prototype.hasOwnProperty.call(r, k) && isSameConfig(v, r[k]));
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export {
|
|
130
|
+
copyConfig,
|
|
131
|
+
isSameConfig,
|
|
132
|
+
ToJsonSchemaError,
|
|
133
|
+
supportedJsonSchemaTargets,
|
|
134
|
+
toJsonSchemaTargets,
|
|
135
|
+
writeInvalidJsonSchemaTargetMessage,
|
|
136
|
+
validateStandardJsonSchemaTarget,
|
|
137
|
+
validateToJsonSchemaTarget,
|
|
138
|
+
openApiNull,
|
|
139
|
+
writeUnionJsonSchema,
|
|
140
|
+
writeNullableJsonSchema
|
|
141
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type
|
|
3
|
+
} from "./chunk-C2V6QPE3.js";
|
|
4
|
+
import {
|
|
5
|
+
parse
|
|
6
|
+
} from "./chunk-C3B4IFQL.js";
|
|
7
|
+
import {
|
|
8
|
+
RootModule
|
|
9
|
+
} from "./chunk-KXOC3JEX.js";
|
|
10
|
+
|
|
11
|
+
// out/fromJsonSchema.js
|
|
12
|
+
var fromJsonSchema = (schema) => (
|
|
13
|
+
// the node is read in an isolated scope, so type() rebinds it to arktype's
|
|
14
|
+
type(parse(schema))
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
// out/module.js
|
|
18
|
+
var Module = RootModule;
|
|
19
|
+
var BoundModule = RootModule;
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
fromJsonSchema,
|
|
23
|
+
Module,
|
|
24
|
+
BoundModule
|
|
25
|
+
};
|
|
File without changes
|