arktype 2.2.10 → 3.0.0-beta.1
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 +181 -15
- package/out/attributes.d.ts +50 -14
- package/out/checkers.d.ts +172 -0
- package/out/chunk-2U2AWCI3.js +626 -0
- package/out/chunk-4CUA5XIP.js +7 -0
- package/out/chunk-5U2ZMDNI.js +1566 -0
- package/out/chunk-DLWCO4RV.js +18 -0
- package/out/chunk-E3DZXEZK.js +72 -0
- package/out/chunk-EVCML554.js +47 -0
- package/out/chunk-G45P2CLE.js +63 -0
- package/out/chunk-GPNK5353.js +2529 -0
- package/out/chunk-MLKGABMK.js +9 -0
- package/out/chunk-NRIGTMPM.js +7 -0
- package/out/chunk-PRTMQCHS.js +3 -0
- package/out/chunk-R5G57XC7.js +7 -0
- package/out/chunk-RAZ3TXOE.js +313 -0
- package/out/chunk-SWOOCAHN.js +4 -0
- package/out/chunk-TAHPKDNM.js +3 -0
- package/out/chunk-UETB6YE2.js +14 -0
- package/out/chunk-UK5UGFOX.js +254 -0
- package/out/chunk-VV6YDN2D.js +6118 -0
- package/out/codecs.d.ts +21 -0
- package/out/codecs.js +7 -0
- package/out/config.d.ts +8 -3
- package/out/config.js +2 -3
- package/out/declare.d.ts +17 -3
- package/out/deferred.d.ts +10 -0
- package/out/errors.d.ts +1 -0
- package/out/errors.js +2 -0
- package/out/fn.d.ts +1 -1
- package/out/generic.d.ts +3 -3
- package/out/i18n.d.ts +2 -0
- package/out/i18n.js +2 -0
- package/out/index.d.ts +5 -4
- package/out/index.js +8 -9
- package/out/internal.d.ts +70 -0
- package/out/internal.js +17 -0
- package/out/island.d.ts +2 -0
- package/out/island.js +6 -0
- package/out/islandDependency.d.ts +2 -0
- package/out/islandDependency.js +18 -0
- package/out/keywords/Array.d.ts +2 -2
- package/out/keywords/builtins.d.ts +5 -3
- package/out/keywords/constructors.d.ts +9 -1
- package/out/keywords/functions.d.ts +254 -0
- package/out/keywords/keywords.d.ts +8 -9
- package/out/keywords/number.d.ts +2 -8
- package/out/keywords/phrases.d.ts +245 -0
- package/out/keywords/string.d.ts +14 -113
- package/out/keywords/ts.d.ts +35 -33
- package/out/keywords/ts.js +4 -82
- package/out/locale.d.ts +19 -0
- package/out/locales/de.d.ts +2 -0
- package/out/locales/de.js +2 -0
- package/out/locales/en.d.ts +4 -0
- package/out/locales/en.js +5 -0
- package/out/match.d.ts +6 -6
- package/out/module.d.ts +1 -1
- package/out/mutatesInput.js +3 -0
- package/out/parser/ast/generic.d.ts +6 -3
- package/out/parser/ast/infer.d.ts +1 -1
- package/out/parser/ast/validate.d.ts +11 -6
- package/out/parser/definition.d.ts +68 -7
- package/out/parser/objectLiteral.d.ts +40 -12
- package/out/parser/property.d.ts +3 -5
- package/out/parser/reduce/dynamic.d.ts +16 -7
- package/out/parser/reduce/shared.d.ts +4 -0
- package/out/parser/reduce/static.d.ts +13 -13
- package/out/parser/shift/operand/date.d.ts +0 -5
- package/out/parser/shift/operand/operand.d.ts +2 -1
- package/out/parser/shift/operand/unenclosed.d.ts +9 -6
- package/out/parser/shift/operand/unresolvable.d.ts +68 -0
- package/out/parser/shift/operator/bounds.d.ts +9 -4
- package/out/parser/shift/operator/brand.d.ts +2 -2
- package/out/parser/shift/operator/default.d.ts +2 -2
- package/out/parser/shift/operator/divisor.d.ts +2 -2
- package/out/parser/shift/operator/operator.d.ts +1 -1
- package/out/parser/shift/tokens.d.ts +9 -2
- package/out/parser/string.d.ts +61 -7
- package/out/parser/tupleExpressions.d.ts +7 -3
- package/out/precompiled.d.ts +1 -0
- package/out/precompiled.js +2 -0
- package/out/runtime.d.ts +181 -0
- package/out/runtime.js +4 -0
- package/out/runtimeDevelopment.d.ts +1 -0
- package/out/runtimeDevelopment.js +133 -0
- package/out/runtimeExports.d.ts +1 -0
- package/out/scope.d.ts +40 -11
- package/out/standalone/artifact.d.ts +265 -0
- package/out/standalone/baking.d.ts +201 -0
- package/out/standalone/combinators.d.ts +13 -0
- package/out/standalone/compilers.d.ts +23 -0
- package/out/standalone/creators.d.ts +41 -0
- package/out/standalone/fallbacks.d.ts +48 -0
- package/out/standalone/keys.d.ts +31 -0
- package/out/standalone/modules.d.ts +26 -0
- package/out/standalone/sites.d.ts +52 -0
- package/out/standalone/units.d.ts +31 -0
- package/out/standalone/values.d.ts +60 -0
- package/out/standalone.d.ts +16 -0
- package/out/type.d.ts +45 -6
- package/out/variants/array.d.ts +1 -1
- package/out/variants/base.d.ts +47 -27
- package/out/variants/date.d.ts +1 -1
- package/out/variants/instantiate.d.ts +4 -2
- package/out/variants/number.d.ts +1 -1
- package/out/variants/object.d.ts +17 -12
- package/out/variants/string.d.ts +1 -1
- package/package.json +169 -8
- package/skills/arktype/SKILL.md +278 -43
- package/skills/arktype/references/migrating.md +1296 -0
- package/skills/arktype/references/precompile.md +191 -0
- package/out/attributes.js +0 -3
- package/out/fn.js +0 -58
- package/out/generic.js +0 -37
- package/out/keywords/Array.js +0 -21
- package/out/keywords/FormData.js +0 -40
- package/out/keywords/TypedArray.js +0 -16
- package/out/keywords/builtins.js +0 -11
- package/out/keywords/constructors.js +0 -16
- package/out/keywords/keywords.js +0 -48
- package/out/keywords/number.js +0 -49
- package/out/keywords/string.js +0 -467
- package/out/match.js +0 -95
- package/out/module.js +0 -3
- package/out/nary.js +0 -1
- package/out/parser/ast/bounds.js +0 -1
- package/out/parser/ast/default.js +0 -1
- package/out/parser/ast/divisor.js +0 -1
- package/out/parser/ast/generic.js +0 -1
- package/out/parser/ast/infer.js +0 -1
- package/out/parser/ast/keyof.js +0 -1
- package/out/parser/ast/utils.js +0 -1
- package/out/parser/ast/validate.js +0 -3
- package/out/parser/definition.js +0 -78
- package/out/parser/objectLiteral.js +0 -113
- package/out/parser/property.js +0 -16
- package/out/parser/reduce/dynamic.js +0 -153
- package/out/parser/reduce/shared.js +0 -25
- package/out/parser/reduce/static.js +0 -1
- package/out/parser/shift/operand/date.js +0 -23
- package/out/parser/shift/operand/enclosed.js +0 -82
- package/out/parser/shift/operand/genericArgs.js +0 -16
- package/out/parser/shift/operand/operand.js +0 -16
- package/out/parser/shift/operand/unenclosed.js +0 -59
- package/out/parser/shift/operator/bounds.js +0 -91
- package/out/parser/shift/operator/brand.js +0 -6
- package/out/parser/shift/operator/default.js +0 -29
- package/out/parser/shift/operator/divisor.js +0 -13
- package/out/parser/shift/operator/operator.js +0 -28
- package/out/parser/shift/tokens.js +0 -37
- package/out/parser/string.js +0 -42
- package/out/parser/tupleExpressions.js +0 -75
- package/out/parser/tupleLiteral.js +0 -128
- package/out/scope.js +0 -106
- package/out/type.js +0 -55
- package/out/variants/array.js +0 -1
- package/out/variants/base.js +0 -1
- package/out/variants/date.js +0 -1
- package/out/variants/instantiate.js +0 -1
- package/out/variants/number.js +0 -1
- package/out/variants/object.js +0 -1
- package/out/variants/string.js +0 -1
- /package/out/{declare.js → mutatesInput.d.ts} +0 -0
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
import {
|
|
2
|
+
$arkTypeRegistry,
|
|
3
|
+
InternalScope,
|
|
4
|
+
deferDefinition,
|
|
5
|
+
deferredRecord,
|
|
6
|
+
keywordModule,
|
|
7
|
+
object,
|
|
8
|
+
tsGenericDefinitions,
|
|
9
|
+
tsKeywordDefinitions,
|
|
10
|
+
unknown
|
|
11
|
+
} from "./chunk-GPNK5353.js";
|
|
12
|
+
import {
|
|
13
|
+
keywordMeta
|
|
14
|
+
} from "./chunk-E3DZXEZK.js";
|
|
15
|
+
import {
|
|
16
|
+
capitalizeString,
|
|
17
|
+
epochDescriptions,
|
|
18
|
+
isEpochString,
|
|
19
|
+
isJsonString,
|
|
20
|
+
isLuhnValid,
|
|
21
|
+
isParsableDate,
|
|
22
|
+
isParsableUrl,
|
|
23
|
+
isRegexPattern,
|
|
24
|
+
lowercaseString,
|
|
25
|
+
maxEpoch,
|
|
26
|
+
normalizationsByForm,
|
|
27
|
+
parseDate,
|
|
28
|
+
parseEpoch,
|
|
29
|
+
parseFormData,
|
|
30
|
+
parseInteger,
|
|
31
|
+
parseIsoDate,
|
|
32
|
+
parseJson,
|
|
33
|
+
parseNumeric,
|
|
34
|
+
parseUrl,
|
|
35
|
+
parsesFinite,
|
|
36
|
+
trimString,
|
|
37
|
+
uppercaseString
|
|
38
|
+
} from "./chunk-UK5UGFOX.js";
|
|
39
|
+
|
|
40
|
+
// out/keywords/builtins.js
|
|
41
|
+
import { genericNode, intrinsic } from "@ark/schema";
|
|
42
|
+
import { cached, Hkt } from "@ark/util";
|
|
43
|
+
var MergeHkt = class extends Hkt {
|
|
44
|
+
description = 'merge an object\'s properties onto another like `Merge(User, { isAdmin: "true" })`';
|
|
45
|
+
};
|
|
46
|
+
var Merge = cached(() => genericNode(["base", intrinsic.object], ["props", intrinsic.object])((args) => args.base.merge(args.props), MergeHkt));
|
|
47
|
+
var builtinDefinitions = {
|
|
48
|
+
Key: () => intrinsic.key,
|
|
49
|
+
Merge
|
|
50
|
+
};
|
|
51
|
+
var arkBuiltins = /* @__PURE__ */ keywordModule(builtinDefinitions, { name: "builtins" });
|
|
52
|
+
|
|
53
|
+
// out/keywords/Array.js
|
|
54
|
+
import { genericNode as genericNode2, intrinsic as intrinsic2, rootSchema } from "@ark/schema";
|
|
55
|
+
import { Hkt as Hkt2, liftArray } from "@ark/util";
|
|
56
|
+
var liftFromHkt = class extends Hkt2 {
|
|
57
|
+
};
|
|
58
|
+
var liftFrom = function () { return genericNode2("element")((args) => {
|
|
59
|
+
const nonArrayElement = args.element.exclude(intrinsic2.Array);
|
|
60
|
+
const lifted = nonArrayElement.array();
|
|
61
|
+
return nonArrayElement.rawOr(lifted).pipe(liftArray).distribute((branch) => branch.assertIs("morph").declareOut(lifted), rootSchema);
|
|
62
|
+
}, liftFromHkt) };
|
|
63
|
+
var arkArray = keywordModule({
|
|
64
|
+
root: () => intrinsic2.Array,
|
|
65
|
+
readonly: "root",
|
|
66
|
+
index: () => intrinsic2.nonNegativeIntegerString,
|
|
67
|
+
liftFrom
|
|
68
|
+
}, {
|
|
69
|
+
name: "Array"
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// out/keywords/FormData.js
|
|
73
|
+
import { node } from "@ark/schema";
|
|
74
|
+
import { cached as cached2, registry } from "@ark/util";
|
|
75
|
+
var value = cached2(function () { return node("union", {
|
|
76
|
+
branches: [
|
|
77
|
+
node("domain", { domain: "string" }),
|
|
78
|
+
node("proto", { proto: registry.FileConstructor })
|
|
79
|
+
]
|
|
80
|
+
}) });
|
|
81
|
+
var parsedFormDataValue = () => value().rawOr(value().array());
|
|
82
|
+
var parsed = cached2(function () { return node("intersection", {
|
|
83
|
+
meta: keywordMeta("FormData.parsed"),
|
|
84
|
+
domain: node("domain", { domain: "object" }),
|
|
85
|
+
structure: node("structure", {
|
|
86
|
+
index: [
|
|
87
|
+
node("index", {
|
|
88
|
+
signature: node("domain", { domain: "string" }),
|
|
89
|
+
value: parsedFormDataValue()
|
|
90
|
+
})
|
|
91
|
+
]
|
|
92
|
+
})
|
|
93
|
+
}) });
|
|
94
|
+
var arkFormData = keywordModule({
|
|
95
|
+
root: () => ["instanceof", FormData],
|
|
96
|
+
value,
|
|
97
|
+
parsed,
|
|
98
|
+
parse: () => node("morph", {
|
|
99
|
+
morphs: [node("proto", { proto: FormData }), parseFormData],
|
|
100
|
+
declaredOut: parsed()
|
|
101
|
+
})
|
|
102
|
+
}, {
|
|
103
|
+
name: "FormData"
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// out/keywords/TypedArray.js
|
|
107
|
+
import { flatMorph, typedArrayConstructors } from "@ark/util";
|
|
108
|
+
var TypedArray = keywordModule(flatMorph(typedArrayConstructors, (k, constructor) => [
|
|
109
|
+
k.slice(0, -"Array".length),
|
|
110
|
+
["instanceof", constructor]
|
|
111
|
+
]), {
|
|
112
|
+
name: "TypedArray"
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// out/keywords/constructors.js
|
|
116
|
+
import { writeUnresolvableMessage } from "@ark/schema";
|
|
117
|
+
import { ecmascriptConstructors, platformConstructors, throwParseError, typedArrayConstructors as typedArrayConstructors2 } from "@ark/util";
|
|
118
|
+
var omittedPrototypes = {
|
|
119
|
+
Boolean: 1,
|
|
120
|
+
Number: 1,
|
|
121
|
+
String: 1
|
|
122
|
+
};
|
|
123
|
+
var instanceOfDefinitions = {};
|
|
124
|
+
for (const constructors of [
|
|
125
|
+
ecmascriptConstructors,
|
|
126
|
+
platformConstructors,
|
|
127
|
+
typedArrayConstructors2
|
|
128
|
+
]) {
|
|
129
|
+
for (const k in constructors) {
|
|
130
|
+
if (k in omittedPrototypes)
|
|
131
|
+
continue;
|
|
132
|
+
instanceOfDefinitions[k] = () => [
|
|
133
|
+
"instanceof",
|
|
134
|
+
constructors[k] ?? throwParseError(writeUnresolvableMessage(k))
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
var prototypeDefinitions = {
|
|
139
|
+
...instanceOfDefinitions,
|
|
140
|
+
Array: arkArray,
|
|
141
|
+
TypedArray,
|
|
142
|
+
FormData: arkFormData
|
|
143
|
+
};
|
|
144
|
+
var arkPrototypes = /* @__PURE__ */ keywordModule(prototypeDefinitions, {
|
|
145
|
+
name: "constructors"
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// out/keywords/number.js
|
|
149
|
+
import { intrinsic as intrinsic3, node as node2 } from "@ark/schema";
|
|
150
|
+
import { cached as cached3 } from "@ark/util";
|
|
151
|
+
var epoch = cached3(function () { return node2("intersection", {
|
|
152
|
+
domain: node2("domain", {
|
|
153
|
+
domain: "number",
|
|
154
|
+
meta: {
|
|
155
|
+
description: epochDescriptions.domain,
|
|
156
|
+
keyword: "number.epoch"
|
|
157
|
+
}
|
|
158
|
+
}),
|
|
159
|
+
divisor: node2("divisor", {
|
|
160
|
+
rule: 1,
|
|
161
|
+
meta: {
|
|
162
|
+
description: `an integer representing a Unix timestamp`,
|
|
163
|
+
keyword: "number.epoch"
|
|
164
|
+
}
|
|
165
|
+
}),
|
|
166
|
+
min: node2("min", {
|
|
167
|
+
rule: -maxEpoch,
|
|
168
|
+
meta: { description: epochDescriptions.min, keyword: "number.epoch" }
|
|
169
|
+
}),
|
|
170
|
+
max: node2("max", {
|
|
171
|
+
rule: maxEpoch,
|
|
172
|
+
meta: { description: epochDescriptions.max, keyword: "number.epoch" }
|
|
173
|
+
}),
|
|
174
|
+
meta: keywordMeta("number.epoch")
|
|
175
|
+
}) });
|
|
176
|
+
var integer = cached3(() => node2("intersection", {
|
|
177
|
+
domain: node2("domain", { domain: "number" }),
|
|
178
|
+
divisor: node2("divisor", { rule: 1 })
|
|
179
|
+
}));
|
|
180
|
+
var number = keywordModule({
|
|
181
|
+
root: () => intrinsic3.number,
|
|
182
|
+
integer,
|
|
183
|
+
epoch,
|
|
184
|
+
safe: function () { return node2("intersection", {
|
|
185
|
+
domain: node2("domain", {
|
|
186
|
+
domain: "number",
|
|
187
|
+
numberAllowsNaN: false
|
|
188
|
+
}),
|
|
189
|
+
min: node2("min", { rule: Number.MIN_SAFE_INTEGER }),
|
|
190
|
+
max: node2("max", { rule: Number.MAX_SAFE_INTEGER })
|
|
191
|
+
}) },
|
|
192
|
+
NaN: ["===", Number.NaN],
|
|
193
|
+
Infinity: ["===", Number.POSITIVE_INFINITY],
|
|
194
|
+
NegativeInfinity: ["===", Number.NEGATIVE_INFINITY]
|
|
195
|
+
}, {
|
|
196
|
+
name: "number"
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// out/keywords/string.js
|
|
200
|
+
import { $ark, constraintInputOf, intrinsic as intrinsic4, node as node3 } from "@ark/schema";
|
|
201
|
+
import { cached as cached4, flatMorph as flatMorph2, ipv4Matcher, ipv6Matcher, iso8601Matcher, numericStringMatcher, uuidMatcher, wellFormedIntegerMatcher } from "@ark/util";
|
|
202
|
+
var regexStringNode = function (regex2, alias, annotations) { return node3("intersection", {
|
|
203
|
+
domain: node3("domain", { domain: "string" }),
|
|
204
|
+
pattern: [
|
|
205
|
+
node3("pattern", {
|
|
206
|
+
...constraintInputOf("pattern", regex2),
|
|
207
|
+
meta: { ...keywordMeta(alias), ...annotations }
|
|
208
|
+
})
|
|
209
|
+
],
|
|
210
|
+
...annotations && { meta: annotations }
|
|
211
|
+
}) };
|
|
212
|
+
var predicateStringNode = function (predicate, alias, jsonSchema, meta) { return node3("intersection", {
|
|
213
|
+
domain: node3("domain", { domain: "string" }),
|
|
214
|
+
predicate: [
|
|
215
|
+
node3("predicate", {
|
|
216
|
+
meta: jsonSchema ? { ...keywordMeta(alias), jsonSchema } : keywordMeta(alias),
|
|
217
|
+
predicate
|
|
218
|
+
})
|
|
219
|
+
],
|
|
220
|
+
...meta && { meta }
|
|
221
|
+
}) };
|
|
222
|
+
var stringIntegerRoot = cached4(() => regexStringNode(wellFormedIntegerMatcher, "string.integer"));
|
|
223
|
+
var stringInteger = keywordModule({
|
|
224
|
+
root: stringIntegerRoot,
|
|
225
|
+
parse: () => node3("morph", {
|
|
226
|
+
morphs: [stringIntegerRoot(), parseInteger],
|
|
227
|
+
declaredOut: intrinsic4.integer
|
|
228
|
+
})
|
|
229
|
+
}, {
|
|
230
|
+
name: "string.integer"
|
|
231
|
+
});
|
|
232
|
+
var hex = () => regexStringNode(/^[\dA-Fa-f]+$/, "string.hex");
|
|
233
|
+
var base64 = keywordModule({
|
|
234
|
+
root: function () { return regexStringNode(/^(?:[\d+/A-Za-z]{4})*(?:[\d+/A-Za-z]{2}==|[\d+/A-Za-z]{3}=)?$/, "string.base64", { contentEncoding: "base64" }) },
|
|
235
|
+
url: function () { return regexStringNode(/^(?:[\w-]{4})*(?:[\w-]{2}(?:==|%3D%3D)?|[\w-]{3}(?:=|%3D)?)?$/, "string.base64.url", { contentEncoding: "base64url" }) }
|
|
236
|
+
}, {
|
|
237
|
+
name: "string.base64"
|
|
238
|
+
});
|
|
239
|
+
var preformattedCapitalize = cached4(() => regexStringNode(/^(?:[^a-z][\S\s]*)?$/, "string.capitalize.preformatted"));
|
|
240
|
+
var capitalize = keywordModule({
|
|
241
|
+
root: () => node3("morph", {
|
|
242
|
+
morphs: [intrinsic4.string, capitalizeString],
|
|
243
|
+
declaredOut: preformattedCapitalize()
|
|
244
|
+
}),
|
|
245
|
+
preformatted: preformattedCapitalize
|
|
246
|
+
}, {
|
|
247
|
+
name: "string.capitalize"
|
|
248
|
+
});
|
|
249
|
+
var creditCardMatcher = /^(?:4\d{12}(?:\d{3,6})?|(?:5[1-5]|6[27])\d{14}|(?:222[1-9]|22[3-9]\d|2[3-6]\d\d|27[01]\d|2720)\d{12}|6(?:011|5\d\d)\d{12,15}|3[47]\d{13}|3(?:0[0-5]|[68]\d)\d{11}|(?:2131|1800|35\d{3})\d{11}|81\d{14,17})$/;
|
|
250
|
+
var creditCard = cached4(function () { return node3("intersection", {
|
|
251
|
+
domain: node3("domain", { domain: "string" }),
|
|
252
|
+
pattern: [
|
|
253
|
+
node3("pattern", {
|
|
254
|
+
meta: keywordMeta("string.creditCard"),
|
|
255
|
+
rule: creditCardMatcher.source
|
|
256
|
+
})
|
|
257
|
+
],
|
|
258
|
+
predicate: [
|
|
259
|
+
node3("predicate", {
|
|
260
|
+
meta: keywordMeta("string.creditCard"),
|
|
261
|
+
predicate: isLuhnValid
|
|
262
|
+
})
|
|
263
|
+
]
|
|
264
|
+
}) });
|
|
265
|
+
var dayDelimiterMatcher = /^[./-]$/;
|
|
266
|
+
var isValidDateInstance = (date) => !Number.isNaN(+date);
|
|
267
|
+
var writeFormattedExpected = (format) => `a ${format}-formatted date`;
|
|
268
|
+
var tryParseDatePattern = function (data, opts) {
|
|
269
|
+
if (!opts?.format) {
|
|
270
|
+
const result = new Date(data);
|
|
271
|
+
return isValidDateInstance(result) ? result : "a valid date";
|
|
272
|
+
}
|
|
273
|
+
if (opts.format === "iso") {
|
|
274
|
+
return iso8601Matcher.test(data) ? new Date(data) : writeFormattedExpected("iso");
|
|
275
|
+
}
|
|
276
|
+
const dataParts = data.split(dayDelimiterMatcher);
|
|
277
|
+
const delimiter = data[dataParts[0].length];
|
|
278
|
+
const formatParts = delimiter ? opts.format.split(delimiter) : [opts.format];
|
|
279
|
+
if (dataParts.length !== formatParts.length)
|
|
280
|
+
return writeFormattedExpected(opts.format);
|
|
281
|
+
const parsedParts = {};
|
|
282
|
+
for (let i = 0; i < formatParts.length; i++) {
|
|
283
|
+
if (dataParts[i].length !== formatParts[i].length && // if format is "m" or "d", data is allowed to be 1 or 2 characters
|
|
284
|
+
!(formatParts[i].length === 1 && dataParts[i].length === 2))
|
|
285
|
+
return writeFormattedExpected(opts.format);
|
|
286
|
+
parsedParts[formatParts[i][0]] = dataParts[i];
|
|
287
|
+
}
|
|
288
|
+
const date = /* @__PURE__ */ new Date(`${parsedParts.m}/${parsedParts.d}/${parsedParts.y}`);
|
|
289
|
+
if (`${date.getDate()}` === parsedParts.d)
|
|
290
|
+
return date;
|
|
291
|
+
return writeFormattedExpected(opts.format);
|
|
292
|
+
};
|
|
293
|
+
var parsableDate = cached4(() => predicateStringNode(isParsableDate, "string.date", { format: "date-time" }));
|
|
294
|
+
var epochRoot = cached4(function () { return stringInteger.root.internal.rawConstrain("predicate", {
|
|
295
|
+
meta: keywordMeta("string.date.epoch"),
|
|
296
|
+
predicate: isEpochString
|
|
297
|
+
}).configure(keywordMeta("string.date.epoch"), "self").assertIs("intersection") });
|
|
298
|
+
var epoch2 = keywordModule({
|
|
299
|
+
root: epochRoot,
|
|
300
|
+
parse: () => node3("morph", {
|
|
301
|
+
morphs: [epochRoot(), parseEpoch],
|
|
302
|
+
declaredOut: intrinsic4.Date
|
|
303
|
+
})
|
|
304
|
+
}, {
|
|
305
|
+
name: "string.date.epoch"
|
|
306
|
+
});
|
|
307
|
+
var isoRoot = cached4(() => regexStringNode(iso8601Matcher, "string.date.iso", {
|
|
308
|
+
format: "date-time"
|
|
309
|
+
}).internal.assertIs("intersection"));
|
|
310
|
+
var iso = keywordModule({
|
|
311
|
+
root: isoRoot,
|
|
312
|
+
parse: () => node3("morph", {
|
|
313
|
+
morphs: [isoRoot(), parseIsoDate],
|
|
314
|
+
declaredOut: intrinsic4.Date
|
|
315
|
+
})
|
|
316
|
+
}, {
|
|
317
|
+
name: "string.date.iso"
|
|
318
|
+
});
|
|
319
|
+
var stringDate = keywordModule({
|
|
320
|
+
root: parsableDate,
|
|
321
|
+
parse: function () { return node3("morph", {
|
|
322
|
+
declaredIn: parsableDate(),
|
|
323
|
+
morphs: [intrinsic4.string, parseDate],
|
|
324
|
+
declaredOut: intrinsic4.Date
|
|
325
|
+
}) },
|
|
326
|
+
iso,
|
|
327
|
+
epoch: epoch2
|
|
328
|
+
}, {
|
|
329
|
+
name: "string.date"
|
|
330
|
+
});
|
|
331
|
+
var email = function () { return regexStringNode(
|
|
332
|
+
// considered https://colinhacks.com/essays/reasonable-email-regex but it includes a lookahead
|
|
333
|
+
// which breaks some integrations e.g. fast-check
|
|
334
|
+
// regex based on:
|
|
335
|
+
// https://www.regular-expressions.info/email.html
|
|
336
|
+
/^[\w%+.-]+@[\d.A-Za-z-]+\.[A-Za-z]{2,}$/,
|
|
337
|
+
"string.email",
|
|
338
|
+
{ format: "email" }
|
|
339
|
+
) };
|
|
340
|
+
var ip = keywordModule({
|
|
341
|
+
root: ["v4 | v6", "@", keywordMeta("string.ip")],
|
|
342
|
+
v4: () => regexStringNode(ipv4Matcher, "string.ip.v4", { format: "ipv4" }),
|
|
343
|
+
v6: () => regexStringNode(ipv6Matcher, "string.ip.v6", { format: "ipv6" })
|
|
344
|
+
}, {
|
|
345
|
+
name: "string.ip"
|
|
346
|
+
});
|
|
347
|
+
var jsonRoot = function () { return predicateStringNode(isJsonString, "string.json", { type: "string", contentMediaType: "application/json" }, keywordMeta("string.json")) };
|
|
348
|
+
var json = keywordModule({
|
|
349
|
+
root: jsonRoot,
|
|
350
|
+
parse: function () { return node3("morph", {
|
|
351
|
+
meta: "safe JSON string parser",
|
|
352
|
+
morphs: [intrinsic4.string, parseJson],
|
|
353
|
+
declaredOut: intrinsic4.jsonData
|
|
354
|
+
}) }
|
|
355
|
+
}, {
|
|
356
|
+
name: "string.json"
|
|
357
|
+
});
|
|
358
|
+
var preformattedLower = cached4(() => regexStringNode(/^[^A-Z]*$/, "string.lower.preformatted"));
|
|
359
|
+
var lower = keywordModule({
|
|
360
|
+
root: () => node3("morph", {
|
|
361
|
+
morphs: [intrinsic4.string, lowercaseString],
|
|
362
|
+
declaredOut: preformattedLower()
|
|
363
|
+
}),
|
|
364
|
+
preformatted: preformattedLower
|
|
365
|
+
}, {
|
|
366
|
+
name: "string.lower"
|
|
367
|
+
});
|
|
368
|
+
var normalizedForms = ["NFC", "NFD", "NFKC", "NFKD"];
|
|
369
|
+
var preformattedNodes = flatMorph2(normalizedForms, function (i, form) { return [
|
|
370
|
+
form,
|
|
371
|
+
cached4(() => node3("intersection", {
|
|
372
|
+
domain: node3("domain", { domain: "string" }),
|
|
373
|
+
predicate: [
|
|
374
|
+
node3("predicate", {
|
|
375
|
+
meta: keywordMeta(`string.normalize.${form}.preformatted`),
|
|
376
|
+
predicate: normalizationsByForm[form].predicate
|
|
377
|
+
})
|
|
378
|
+
],
|
|
379
|
+
meta: keywordMeta(`string.normalize.${form}.preformatted`)
|
|
380
|
+
}))
|
|
381
|
+
] });
|
|
382
|
+
var normalizeNodes = flatMorph2(normalizedForms, function (i, form) { return [
|
|
383
|
+
form,
|
|
384
|
+
() => node3("morph", {
|
|
385
|
+
morphs: [intrinsic4.string, normalizationsByForm[form].morphs],
|
|
386
|
+
declaredOut: preformattedNodes[form]()
|
|
387
|
+
})
|
|
388
|
+
] });
|
|
389
|
+
var NFC = keywordModule({
|
|
390
|
+
root: normalizeNodes.NFC,
|
|
391
|
+
preformatted: preformattedNodes.NFC
|
|
392
|
+
}, {
|
|
393
|
+
name: "string.normalize.NFC"
|
|
394
|
+
});
|
|
395
|
+
var NFD = keywordModule({
|
|
396
|
+
root: normalizeNodes.NFD,
|
|
397
|
+
preformatted: preformattedNodes.NFD
|
|
398
|
+
}, {
|
|
399
|
+
name: "string.normalize.NFD"
|
|
400
|
+
});
|
|
401
|
+
var NFKC = keywordModule({
|
|
402
|
+
root: normalizeNodes.NFKC,
|
|
403
|
+
preformatted: preformattedNodes.NFKC
|
|
404
|
+
}, {
|
|
405
|
+
name: "string.normalize.NFKC"
|
|
406
|
+
});
|
|
407
|
+
var NFKD = keywordModule({
|
|
408
|
+
root: normalizeNodes.NFKD,
|
|
409
|
+
preformatted: preformattedNodes.NFKD
|
|
410
|
+
}, {
|
|
411
|
+
name: "string.normalize.NFKD"
|
|
412
|
+
});
|
|
413
|
+
var normalize = keywordModule({
|
|
414
|
+
root: "NFC",
|
|
415
|
+
NFC,
|
|
416
|
+
NFD,
|
|
417
|
+
NFKC,
|
|
418
|
+
NFKD
|
|
419
|
+
}, {
|
|
420
|
+
name: "string.normalize"
|
|
421
|
+
});
|
|
422
|
+
var numericRoot = cached4(() => regexStringNode(numericStringMatcher, "string.numeric"));
|
|
423
|
+
var stringNumeric = keywordModule({
|
|
424
|
+
root: numericRoot,
|
|
425
|
+
parse: function () {
|
|
426
|
+
const root = numericRoot();
|
|
427
|
+
const input = $ark.cfg.numberAllowsInfinity ? root : node3("intersection", {
|
|
428
|
+
...root.inner,
|
|
429
|
+
predicate: [
|
|
430
|
+
node3("predicate", {
|
|
431
|
+
predicate: parsesFinite,
|
|
432
|
+
// JSON Schema can't say it, so the pattern stands for it
|
|
433
|
+
meta: {
|
|
434
|
+
...keywordMeta("string.numeric.parse"),
|
|
435
|
+
jsonSchema: {}
|
|
436
|
+
}
|
|
437
|
+
})
|
|
438
|
+
]
|
|
439
|
+
});
|
|
440
|
+
return node3("morph", {
|
|
441
|
+
morphs: [input, parseNumeric],
|
|
442
|
+
declaredOut: intrinsic4.number
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
}, {
|
|
446
|
+
name: "string.numeric"
|
|
447
|
+
});
|
|
448
|
+
var regex = () => predicateStringNode(isRegexPattern, "string.regex", { format: "regex" });
|
|
449
|
+
var semverMatcher = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][\dA-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][\dA-Za-z-]*))*))?(?:\+([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?$/;
|
|
450
|
+
var semver = () => regexStringNode(semverMatcher, "string.semver");
|
|
451
|
+
var preformattedTrim = cached4(() => regexStringNode(
|
|
452
|
+
// no leading or trailing whitespace
|
|
453
|
+
/^\S[\S\s]*\S$|^\S?$/,
|
|
454
|
+
"string.trim.preformatted"
|
|
455
|
+
));
|
|
456
|
+
var trim = keywordModule({
|
|
457
|
+
root: () => node3("morph", {
|
|
458
|
+
morphs: [intrinsic4.string, trimString],
|
|
459
|
+
declaredOut: preformattedTrim()
|
|
460
|
+
}),
|
|
461
|
+
preformatted: preformattedTrim
|
|
462
|
+
}, {
|
|
463
|
+
name: "string.trim"
|
|
464
|
+
});
|
|
465
|
+
var preformattedUpper = cached4(() => regexStringNode(/^[^a-z]*$/, "string.upper.preformatted"));
|
|
466
|
+
var upper = keywordModule({
|
|
467
|
+
root: () => node3("morph", {
|
|
468
|
+
morphs: [intrinsic4.string, uppercaseString],
|
|
469
|
+
declaredOut: preformattedUpper()
|
|
470
|
+
}),
|
|
471
|
+
preformatted: preformattedUpper
|
|
472
|
+
}, {
|
|
473
|
+
name: "string.upper"
|
|
474
|
+
});
|
|
475
|
+
var urlRoot = cached4(function () { return (
|
|
476
|
+
// URL.canParse and RFC 3986 differ only at the edges, e.g. a space in a path
|
|
477
|
+
predicateStringNode(isParsableUrl, "string.url", { format: "uri" })
|
|
478
|
+
) });
|
|
479
|
+
var url = keywordModule({
|
|
480
|
+
root: urlRoot,
|
|
481
|
+
parse: function () { return node3("morph", {
|
|
482
|
+
declaredIn: urlRoot(),
|
|
483
|
+
morphs: [intrinsic4.string, parseUrl],
|
|
484
|
+
declaredOut: node3("proto", { proto: URL })
|
|
485
|
+
}) }
|
|
486
|
+
}, {
|
|
487
|
+
name: "string.url"
|
|
488
|
+
});
|
|
489
|
+
var uuidVersions = [1, 2, 3, 4, 5, 6, 7, 8];
|
|
490
|
+
var uuid = keywordModule({
|
|
491
|
+
root: [
|
|
492
|
+
// one pattern: a union with the literals would make them required keys of an index signature
|
|
493
|
+
uuidMatcher,
|
|
494
|
+
"@",
|
|
495
|
+
{ ...keywordMeta("string.uuid"), format: "uuid" }
|
|
496
|
+
],
|
|
497
|
+
...flatMorph2(uuidVersions, function (i, version) { return [
|
|
498
|
+
`v${version}`,
|
|
499
|
+
() => regexStringNode(new RegExp(`^[\\dA-Fa-f]{8}-[\\dA-Fa-f]{4}-${version}[\\dA-Fa-f]{3}-[89ABab][\\dA-Fa-f]{3}-[\\dA-Fa-f]{12}$`), `string.uuid.v${version}`, { format: "uuid" })
|
|
500
|
+
] })
|
|
501
|
+
}, {
|
|
502
|
+
name: "string.uuid"
|
|
503
|
+
});
|
|
504
|
+
var string = keywordModule({
|
|
505
|
+
root: () => intrinsic4.string,
|
|
506
|
+
alpha: () => regexStringNode(/^[A-Za-z]*$/, "string.alpha"),
|
|
507
|
+
alphanumeric: () => regexStringNode(/^[\dA-Za-z]*$/, "string.alphanumeric"),
|
|
508
|
+
hex,
|
|
509
|
+
base58: () => regexStringNode(/^[1-9A-HJ-NP-Za-km-z]+$/, "string.base58"),
|
|
510
|
+
base64,
|
|
511
|
+
capitalize,
|
|
512
|
+
creditCard,
|
|
513
|
+
date: stringDate,
|
|
514
|
+
digits: () => regexStringNode(/^\d*$/, "string.digits"),
|
|
515
|
+
email,
|
|
516
|
+
integer: stringInteger,
|
|
517
|
+
ip,
|
|
518
|
+
json,
|
|
519
|
+
lower,
|
|
520
|
+
normalize,
|
|
521
|
+
numeric: stringNumeric,
|
|
522
|
+
regex,
|
|
523
|
+
semver,
|
|
524
|
+
trim,
|
|
525
|
+
upper,
|
|
526
|
+
url,
|
|
527
|
+
uuid
|
|
528
|
+
}, {
|
|
529
|
+
name: "string"
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
// out/keywords/keywords.js
|
|
533
|
+
import { RootModule } from "@ark/schema";
|
|
534
|
+
import { defineLazily, defineProperties } from "@ark/util";
|
|
535
|
+
var ark = new InternalScope({
|
|
536
|
+
...tsKeywordDefinitions,
|
|
537
|
+
...tsGenericDefinitions,
|
|
538
|
+
...prototypeDefinitions,
|
|
539
|
+
...builtinDefinitions,
|
|
540
|
+
string,
|
|
541
|
+
number,
|
|
542
|
+
object,
|
|
543
|
+
unknown
|
|
544
|
+
}, { prereducedAliases: true, name: "ark" }, true);
|
|
545
|
+
var arkExports = ark.internal.exportLazily();
|
|
546
|
+
var keywords = defineProperties(new RootModule({}), arkExports);
|
|
547
|
+
defineProperties($arkTypeRegistry.ambient, arkExports);
|
|
548
|
+
var typeAttachments = {};
|
|
549
|
+
for (const [k, resolve] of Object.entries({
|
|
550
|
+
string: () => deferDefinition("string", ark.internal) ?? arkExports.string.root,
|
|
551
|
+
number: () => deferDefinition("number", ark.internal) ?? arkExports.number.root,
|
|
552
|
+
bigint: () => deferDefinition("bigint", ark.internal) ?? arkExports.bigint,
|
|
553
|
+
boolean: () => deferDefinition("boolean", ark.internal) ?? arkExports.boolean,
|
|
554
|
+
symbol: () => deferDefinition("symbol", ark.internal) ?? arkExports.symbol,
|
|
555
|
+
undefined: () => deferDefinition("undefined", ark.internal) ?? arkExports.undefined,
|
|
556
|
+
null: () => deferDefinition("null", ark.internal) ?? arkExports.null,
|
|
557
|
+
object: () => deferDefinition("object", ark.internal) ?? arkExports.object.root,
|
|
558
|
+
unknown: () => arkExports.unknown.root,
|
|
559
|
+
false: () => deferDefinition("false", ark.internal) ?? arkExports.false,
|
|
560
|
+
true: () => deferDefinition("true", ark.internal) ?? arkExports.true,
|
|
561
|
+
never: () => arkExports.never,
|
|
562
|
+
arrayIndex: () => arkExports.Array.index,
|
|
563
|
+
Key: () => arkExports.Key,
|
|
564
|
+
Record: () => arkExports.Record,
|
|
565
|
+
Array: () => arkExports.Array.root,
|
|
566
|
+
Date: () => arkExports.Date
|
|
567
|
+
}))
|
|
568
|
+
defineLazily(typeAttachments, k, resolve);
|
|
569
|
+
$arkTypeRegistry.typeAttachments = typeAttachments;
|
|
570
|
+
var type = defineProperties(
|
|
571
|
+
ark.type,
|
|
572
|
+
// future scopes add these directly from the
|
|
573
|
+
// registry when their TypeParsers are instantiated
|
|
574
|
+
typeAttachments
|
|
575
|
+
);
|
|
576
|
+
Object.defineProperty(type, "Record", {
|
|
577
|
+
value: deferredRecord(ark.internal, () => arkExports.Record),
|
|
578
|
+
enumerable: true
|
|
579
|
+
});
|
|
580
|
+
var match = ark.match;
|
|
581
|
+
var fn = ark.fn;
|
|
582
|
+
var generic = ark.generic;
|
|
583
|
+
var schema = ark.schema;
|
|
584
|
+
var define = ark.define;
|
|
585
|
+
var declare = ark.declare;
|
|
586
|
+
|
|
587
|
+
export {
|
|
588
|
+
builtinDefinitions,
|
|
589
|
+
arkBuiltins,
|
|
590
|
+
arkArray,
|
|
591
|
+
arkFormData,
|
|
592
|
+
TypedArray,
|
|
593
|
+
prototypeDefinitions,
|
|
594
|
+
arkPrototypes,
|
|
595
|
+
epoch,
|
|
596
|
+
integer,
|
|
597
|
+
number,
|
|
598
|
+
iso8601Matcher,
|
|
599
|
+
regexStringNode,
|
|
600
|
+
stringInteger,
|
|
601
|
+
capitalize,
|
|
602
|
+
creditCard,
|
|
603
|
+
tryParseDatePattern,
|
|
604
|
+
stringDate,
|
|
605
|
+
ip,
|
|
606
|
+
json,
|
|
607
|
+
normalizedForms,
|
|
608
|
+
NFC,
|
|
609
|
+
NFD,
|
|
610
|
+
NFKC,
|
|
611
|
+
NFKD,
|
|
612
|
+
normalize,
|
|
613
|
+
stringNumeric,
|
|
614
|
+
url,
|
|
615
|
+
uuid,
|
|
616
|
+
string,
|
|
617
|
+
ark,
|
|
618
|
+
keywords,
|
|
619
|
+
type,
|
|
620
|
+
match,
|
|
621
|
+
fn,
|
|
622
|
+
generic,
|
|
623
|
+
schema,
|
|
624
|
+
define,
|
|
625
|
+
declare
|
|
626
|
+
};
|