arktype 2.1.19 → 2.1.21
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 +6 -35
- package/out/attributes.d.ts +10 -3
- package/out/keywords/string.d.ts +5 -3
- package/out/keywords/string.js +75 -43
- package/out/methods/base.d.ts +4 -4
- package/out/nary.d.ts +318 -325
- package/out/parser/tupleLiteral.js +9 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -79,7 +79,7 @@ Otherwise, consider sending me an email (david@arktype.io) or [message me on Dis
|
|
|
79
79
|
<th>tmm</th>
|
|
80
80
|
<th>mishushakov</th>
|
|
81
81
|
<th>mewhhaha</th>
|
|
82
|
-
<th>
|
|
82
|
+
<th>jahands</th>
|
|
83
83
|
</tr>
|
|
84
84
|
<tr>
|
|
85
85
|
<td>
|
|
@@ -108,20 +108,20 @@ Otherwise, consider sending me an email (david@arktype.io) or [message me on Dis
|
|
|
108
108
|
src="https://avatars.githubusercontent.com/mewhhaha"
|
|
109
109
|
/></a>
|
|
110
110
|
</td>
|
|
111
|
-
|
|
112
|
-
<a href="https://github.com/
|
|
111
|
+
<td>
|
|
112
|
+
<a href="https://github.com/jahands"
|
|
113
113
|
><img
|
|
114
114
|
height="64px"
|
|
115
|
-
src="https://avatars.githubusercontent.com/
|
|
115
|
+
src="https://avatars.githubusercontent.com/jahands"
|
|
116
116
|
/></a>
|
|
117
117
|
</td>
|
|
118
118
|
</tr>
|
|
119
119
|
<tr>
|
|
120
120
|
<th>drwpwrs</th>
|
|
121
|
-
<th>Timeraa</th>
|
|
122
121
|
<th>Phalangers</th>
|
|
123
122
|
<th>WilliamConnatser</th>
|
|
124
123
|
<th>JameEnder</th>
|
|
124
|
+
<th>tylim88</th>
|
|
125
125
|
</tr>
|
|
126
126
|
<tr>
|
|
127
127
|
<td>
|
|
@@ -131,13 +131,6 @@ Otherwise, consider sending me an email (david@arktype.io) or [message me on Dis
|
|
|
131
131
|
src="https://avatars.githubusercontent.com/drwpwrs"
|
|
132
132
|
/></a>
|
|
133
133
|
</td>
|
|
134
|
-
<td>
|
|
135
|
-
<a href="https://github.com/Timeraa"
|
|
136
|
-
><img
|
|
137
|
-
height="64px"
|
|
138
|
-
src="https://avatars.githubusercontent.com/Timeraa"
|
|
139
|
-
/></a>
|
|
140
|
-
</td>
|
|
141
134
|
<td>
|
|
142
135
|
<a href="https://github.com/Phalangers"
|
|
143
136
|
><img
|
|
@@ -159,34 +152,12 @@ Otherwise, consider sending me an email (david@arktype.io) or [message me on Dis
|
|
|
159
152
|
src="https://avatars.githubusercontent.com/JameEnder"
|
|
160
153
|
/></a>
|
|
161
154
|
</td>
|
|
162
|
-
|
|
163
|
-
<tr>
|
|
164
|
-
<th>tylim88</th>
|
|
165
|
-
<th>jahands</th>
|
|
166
|
-
<th></th>
|
|
167
|
-
<th></th>
|
|
168
|
-
<th></th>
|
|
169
|
-
</tr>
|
|
170
|
-
<tr>
|
|
171
|
-
<td>
|
|
155
|
+
<td>
|
|
172
156
|
<a href="https://github.com/tylim88"
|
|
173
157
|
><img
|
|
174
158
|
height="64px"
|
|
175
159
|
src="https://avatars.githubusercontent.com/tylim88"
|
|
176
160
|
/></a>
|
|
177
161
|
</td>
|
|
178
|
-
<td>
|
|
179
|
-
<a href="https://github.com/jahands"
|
|
180
|
-
><img
|
|
181
|
-
height="64px"
|
|
182
|
-
src="https://avatars.githubusercontent.com/jahands"
|
|
183
|
-
/></a>
|
|
184
|
-
</td>
|
|
185
|
-
<td>
|
|
186
|
-
</td>
|
|
187
|
-
<td>
|
|
188
|
-
</td>
|
|
189
|
-
<td>
|
|
190
|
-
</td>
|
|
191
162
|
</tr>
|
|
192
163
|
</table>
|
package/out/attributes.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArkError, ArkErrors, Morph } from "@ark/schema";
|
|
2
|
-
import { type anyOrNever, type array, type Brand, type equals, type Hkt, type intersectArrays, type isSafelyMappable, type merge, type Primitive, type show } from "@ark/util";
|
|
2
|
+
import { type anyOrNever, type array, type Brand, type equals, type Hkt, type intersectArrays, type isSafelyMappable, type merge, type optionalKeyOf, type Primitive, type show, type unionKeyOf, type unionToTuple } from "@ark/util";
|
|
3
3
|
import type { arkPrototypes } from "./keywords/constructors.ts";
|
|
4
4
|
import type { type } from "./keywords/keywords.ts";
|
|
5
5
|
import type { Type } from "./type.ts";
|
|
@@ -53,9 +53,16 @@ type TerminallyInferredObject = arkPrototypes.instanceOf<BuiltinTerminalObjectKi
|
|
|
53
53
|
export type inferPredicate<t, predicate> = predicate extends (data: any, ...args: any[]) => data is infer narrowed ? narrowed : t;
|
|
54
54
|
export type inferNaryPipe<morphs extends readonly Morph[]> = _inferNaryPipe<morphs, unknown>;
|
|
55
55
|
type _inferNaryPipe<remaining extends readonly unknown[], result> = remaining extends (readonly [infer head extends Morph, ...infer tail extends Morph[]]) ? _inferNaryPipe<tail, inferMorph<result, head>> : result;
|
|
56
|
-
export type inferNaryIntersection<types extends readonly unknown[]> = _inferNaryIntersection<types, unknown>;
|
|
56
|
+
export type inferNaryIntersection<types extends readonly unknown[]> = number extends types["length"] ? _inferNaryIntersection<unionToTuple<types[number]>, unknown> : _inferNaryIntersection<types, unknown>;
|
|
57
57
|
type _inferNaryIntersection<remaining extends readonly unknown[], result> = remaining extends readonly [infer head, ...infer tail] ? _inferNaryIntersection<tail, inferIntersection<result, head>> : result;
|
|
58
|
-
export type inferNaryMerge<types extends readonly unknown[]> = _inferNaryMerge<types, {}>;
|
|
58
|
+
export type inferNaryMerge<types extends readonly unknown[]> = number extends types["length"] ? _inferUnorderedMerge<types> : _inferNaryMerge<types, {}>;
|
|
59
|
+
type _inferUnorderedMerge<types extends readonly unknown[], optionalKey extends PropertyKey = optionalAtLeastOnceUnionKeyOf<types[number]>, requiredKey extends PropertyKey = Exclude<unionKeyOf<types[number]>, optionalKey>> = show<{
|
|
60
|
+
[k in requiredKey]: types[number] extends infer v ? v extends unknown ? k extends keyof v ? v[k] : never : never : never;
|
|
61
|
+
} & {
|
|
62
|
+
[k in optionalKey]?: types[number] extends infer v ? v extends unknown ? k extends keyof v ? v[k] : never : never : never;
|
|
63
|
+
}>;
|
|
64
|
+
/** Coalesce keys that exist and are optional on one or more branches of a union */
|
|
65
|
+
type optionalAtLeastOnceUnionKeyOf<t> = t extends unknown ? optionalKeyOf<t> : never;
|
|
59
66
|
type _inferNaryMerge<remaining extends readonly unknown[], result> = remaining extends (readonly [infer head, ...infer tail extends readonly unknown[]]) ? _inferNaryMerge<tail, merge<result, head>> : result;
|
|
60
67
|
export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
|
|
61
68
|
declare const isMorphOutKey: " isMorphOut";
|
package/out/keywords/string.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Intersection, type JsonSchema } from "@ark/schema";
|
|
2
2
|
import { type Json } from "@ark/util";
|
|
3
3
|
import type { To } from "../attributes.ts";
|
|
4
4
|
import type { Module, Submodule } from "../module.ts";
|
|
5
|
-
export declare const regexStringNode: (regex: RegExp, description: string) =>
|
|
5
|
+
export declare const regexStringNode: (regex: RegExp, description: string, jsonSchemaFormat?: JsonSchema.Format) => Intersection.Node;
|
|
6
6
|
export declare const stringInteger: stringInteger.module;
|
|
7
7
|
export declare namespace stringInteger {
|
|
8
8
|
type module = Module<submodule>;
|
|
@@ -184,7 +184,7 @@ export declare namespace normalize {
|
|
|
184
184
|
};
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
-
export declare const
|
|
187
|
+
export declare const stringNumeric: stringNumeric.module;
|
|
188
188
|
export declare namespace stringNumeric {
|
|
189
189
|
type module = Module<submodule>;
|
|
190
190
|
type submodule = Submodule<$>;
|
|
@@ -286,6 +286,7 @@ export declare const string: Module<{
|
|
|
286
286
|
}>;
|
|
287
287
|
}>;
|
|
288
288
|
numeric: Submodule<stringNumeric.submodule>;
|
|
289
|
+
regex: unknown;
|
|
289
290
|
semver: unknown;
|
|
290
291
|
trim: Submodule<trim.submodule>;
|
|
291
292
|
upper: Submodule<upper.submodule>;
|
|
@@ -322,6 +323,7 @@ export declare namespace string {
|
|
|
322
323
|
lower: lower.submodule;
|
|
323
324
|
normalize: normalize.submodule;
|
|
324
325
|
numeric: stringNumeric.submodule;
|
|
326
|
+
regex: string;
|
|
325
327
|
semver: string;
|
|
326
328
|
trim: trim.submodule;
|
|
327
329
|
upper: upper.submodule;
|
package/out/keywords/string.js
CHANGED
|
@@ -2,15 +2,20 @@ import { ArkErrors, intrinsic, node, rootSchema } from "@ark/schema";
|
|
|
2
2
|
import { flatMorph, numericStringMatcher, wellFormedIntegerMatcher } from "@ark/util";
|
|
3
3
|
import { Scope } from "../scope.js";
|
|
4
4
|
import { number } from "./number.js";
|
|
5
|
-
//
|
|
6
|
-
export const regexStringNode = (regex, description) =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
5
|
+
// non-trivial expressions should have an explanation or attribution
|
|
6
|
+
export const regexStringNode = (regex, description, jsonSchemaFormat) => {
|
|
7
|
+
const schema = {
|
|
8
|
+
domain: "string",
|
|
9
|
+
pattern: {
|
|
10
|
+
rule: regex.source,
|
|
11
|
+
flags: regex.flags,
|
|
12
|
+
meta: description
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
if (jsonSchemaFormat)
|
|
16
|
+
schema.meta = { format: jsonSchemaFormat };
|
|
17
|
+
return node("intersection", schema);
|
|
18
|
+
};
|
|
14
19
|
const stringIntegerRoot = regexStringNode(wellFormedIntegerMatcher, "a well-formed integer string");
|
|
15
20
|
export const stringInteger = Scope.module({
|
|
16
21
|
root: stringIntegerRoot,
|
|
@@ -25,10 +30,10 @@ export const stringInteger = Scope.module({
|
|
|
25
30
|
}, {
|
|
26
31
|
name: "string.integer"
|
|
27
32
|
});
|
|
28
|
-
const hex = regexStringNode(/^[
|
|
33
|
+
const hex = regexStringNode(/^[\dA-Fa-f]+$/, "hex characters only");
|
|
29
34
|
const base64 = Scope.module({
|
|
30
|
-
root: regexStringNode(/^(?:[A-Za-
|
|
31
|
-
url: regexStringNode(/^(?:[
|
|
35
|
+
root: regexStringNode(/^(?:[\d+/A-Za-z]{4})*(?:[\d+/A-Za-z]{2}==|[\d+/A-Za-z]{3}=)?$/, "base64-encoded"),
|
|
36
|
+
url: regexStringNode(/^(?:[\w-]{4})*(?:[\w-]{2}(?:==|%3D%3D)?|[\w-]{3}(?:=|%3D)?)?$/, "base64url-encoded")
|
|
32
37
|
}, {
|
|
33
38
|
name: "string.base64"
|
|
34
39
|
});
|
|
@@ -45,7 +50,7 @@ export const capitalize = Scope.module({
|
|
|
45
50
|
});
|
|
46
51
|
// https://github.com/validatorjs/validator.js/blob/master/src/lib/isLuhnNumber.js
|
|
47
52
|
export const isLuhnValid = (creditCardInput) => {
|
|
48
|
-
const sanitized = creditCardInput.
|
|
53
|
+
const sanitized = creditCardInput.replaceAll(/[ -]+/g, "");
|
|
49
54
|
let sum = 0;
|
|
50
55
|
let digit;
|
|
51
56
|
let tmpNum;
|
|
@@ -55,10 +60,7 @@ export const isLuhnValid = (creditCardInput) => {
|
|
|
55
60
|
tmpNum = Number.parseInt(digit, 10);
|
|
56
61
|
if (shouldDouble) {
|
|
57
62
|
tmpNum *= 2;
|
|
58
|
-
|
|
59
|
-
sum += (tmpNum % 10) + 1;
|
|
60
|
-
else
|
|
61
|
-
sum += tmpNum;
|
|
63
|
+
sum += tmpNum >= 10 ? (tmpNum % 10) + 1 : tmpNum;
|
|
62
64
|
}
|
|
63
65
|
else
|
|
64
66
|
sum += tmpNum;
|
|
@@ -67,7 +69,7 @@ export const isLuhnValid = (creditCardInput) => {
|
|
|
67
69
|
return !!(sum % 10 === 0 ? sanitized : false);
|
|
68
70
|
};
|
|
69
71
|
// https://github.com/validatorjs/validator.js/blob/master/src/lib/isCreditCard.js
|
|
70
|
-
const creditCardMatcher = /^(?:4
|
|
72
|
+
const creditCardMatcher = /^(?:4\d{12}(?:\d{3,6})?|5[1-5]\d{14}|(222[1-9]|22[3-9]\d|2[3-6]\d{2}|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}|6[27]\d{14}|^(81\d{14,17}))$/;
|
|
71
73
|
export const creditCard = rootSchema({
|
|
72
74
|
domain: "string",
|
|
73
75
|
pattern: {
|
|
@@ -83,7 +85,7 @@ const dayDelimiterMatcher = /^[./-]$/;
|
|
|
83
85
|
// ISO 8601 date/time modernized from https://github.com/validatorjs/validator.js/blob/master/src/lib/isISO8601.js
|
|
84
86
|
// Based on https://tc39.es/ecma262/#sec-date-time-string-format, the T
|
|
85
87
|
// delimiter for date/time is mandatory. Regex from validator.js strict matcher:
|
|
86
|
-
export const iso8601Matcher = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))(
|
|
88
|
+
export const iso8601Matcher = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))(T((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([,.]\d+(?!:))?)?(\17[0-5]\d([,.]\d+)?)?([Zz]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
|
|
87
89
|
const isValidDateInstance = (date) => !Number.isNaN(+date);
|
|
88
90
|
const writeFormattedExpected = (format) => `a ${format}-formatted date`;
|
|
89
91
|
export const tryParseDatePattern = (data, opts) => {
|
|
@@ -125,7 +127,7 @@ const parsableDate = rootSchema({
|
|
|
125
127
|
}).assertHasKind("intersection");
|
|
126
128
|
const epochRoot = stringInteger.root.internal
|
|
127
129
|
.narrow((s, ctx) => {
|
|
128
|
-
//
|
|
130
|
+
// this is safe since it has already
|
|
129
131
|
// been validated as an integer string
|
|
130
132
|
const n = Number.parseInt(s);
|
|
131
133
|
const out = number.epoch(n);
|
|
@@ -179,10 +181,12 @@ export const stringDate = Scope.module({
|
|
|
179
181
|
name: "string.date"
|
|
180
182
|
});
|
|
181
183
|
const email = regexStringNode(
|
|
184
|
+
// considered https://colinhacks.com/essays/reasonable-email-regex but it includes a lookahead
|
|
185
|
+
// which breaks some integrations e.g. fast-check
|
|
186
|
+
// regex based on:
|
|
182
187
|
// https://www.regular-expressions.info/email.html
|
|
183
|
-
/^[
|
|
184
|
-
//
|
|
185
|
-
// Adjusted to incorporate unmerged fix in https://github.com/validatorjs/validator.js/pull/2083
|
|
188
|
+
/^[\w%+.-]+@[\d.A-Za-z-]+\.[A-Za-z]{2,}$/, "an email address", "email");
|
|
189
|
+
// based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isIP.js
|
|
186
190
|
const ipv4Segment = "(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
|
|
187
191
|
const ipv4Address = `(${ipv4Segment}[.]){3}${ipv4Segment}`;
|
|
188
192
|
const ipv4Matcher = new RegExp(`^${ipv4Address}$`);
|
|
@@ -199,8 +203,8 @@ const ipv6Matcher = new RegExp("^(" +
|
|
|
199
203
|
")(%[0-9a-zA-Z.]{1,})?$");
|
|
200
204
|
export const ip = Scope.module({
|
|
201
205
|
root: ["v4 | v6", "@", "an IP address"],
|
|
202
|
-
v4: regexStringNode(ipv4Matcher, "an IPv4 address"),
|
|
203
|
-
v6: regexStringNode(ipv6Matcher, "an IPv6 address")
|
|
206
|
+
v4: regexStringNode(ipv4Matcher, "an IPv4 address", "ipv4"),
|
|
207
|
+
v6: regexStringNode(ipv6Matcher, "an IPv6 address", "ipv6")
|
|
204
208
|
}, {
|
|
205
209
|
name: "string.ip"
|
|
206
210
|
});
|
|
@@ -322,7 +326,7 @@ export const normalize = Scope.module({
|
|
|
322
326
|
name: "string.normalize"
|
|
323
327
|
});
|
|
324
328
|
const numericRoot = regexStringNode(numericStringMatcher, "a well-formed numeric string");
|
|
325
|
-
export const
|
|
329
|
+
export const stringNumeric = Scope.module({
|
|
326
330
|
root: numericRoot,
|
|
327
331
|
parse: rootSchema({
|
|
328
332
|
in: numericRoot,
|
|
@@ -332,8 +336,28 @@ export const numeric = Scope.module({
|
|
|
332
336
|
}, {
|
|
333
337
|
name: "string.numeric"
|
|
334
338
|
});
|
|
335
|
-
|
|
336
|
-
const
|
|
339
|
+
const regexPatternDescription = "a regex pattern";
|
|
340
|
+
const regex = rootSchema({
|
|
341
|
+
domain: "string",
|
|
342
|
+
predicate: {
|
|
343
|
+
meta: regexPatternDescription,
|
|
344
|
+
predicate: (s, ctx) => {
|
|
345
|
+
try {
|
|
346
|
+
new RegExp(s);
|
|
347
|
+
return true;
|
|
348
|
+
}
|
|
349
|
+
catch (e) {
|
|
350
|
+
return ctx.reject({
|
|
351
|
+
code: "predicate",
|
|
352
|
+
expected: regexPatternDescription,
|
|
353
|
+
problem: String(e)
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
meta: { format: "regex" }
|
|
359
|
+
});
|
|
360
|
+
const 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-]+)*))?$/;
|
|
337
361
|
const semver = regexStringNode(semverMatcher, "a semantic version (see https://semver.org/)");
|
|
338
362
|
const preformattedTrim = regexStringNode(
|
|
339
363
|
// no leading or trailing whitespace
|
|
@@ -362,7 +386,7 @@ const upper = Scope.module({
|
|
|
362
386
|
const isParsableUrl = (s) => {
|
|
363
387
|
if (URL.canParse)
|
|
364
388
|
return URL.canParse(s);
|
|
365
|
-
//
|
|
389
|
+
// TODO[2025-04-30] remove once Node 18 is EOL and we can rely on URL.canParse
|
|
366
390
|
try {
|
|
367
391
|
new URL(s);
|
|
368
392
|
return true;
|
|
@@ -376,7 +400,10 @@ const urlRoot = rootSchema({
|
|
|
376
400
|
predicate: {
|
|
377
401
|
meta: "a URL string",
|
|
378
402
|
predicate: isParsableUrl
|
|
379
|
-
}
|
|
403
|
+
},
|
|
404
|
+
// URL.canParse allows a subset of the RFC-3986 URI spec
|
|
405
|
+
// since there is no other serializable validation, best include a format
|
|
406
|
+
meta: { format: "uri" }
|
|
380
407
|
});
|
|
381
408
|
export const url = Scope.module({
|
|
382
409
|
root: urlRoot,
|
|
@@ -396,29 +423,33 @@ export const url = Scope.module({
|
|
|
396
423
|
}, {
|
|
397
424
|
name: "string.url"
|
|
398
425
|
});
|
|
399
|
-
//
|
|
426
|
+
// based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
|
|
400
427
|
export const uuid = Scope.module({
|
|
401
428
|
// the meta tuple expression ensures the error message does not delegate
|
|
402
429
|
// to the individual branches, which are too detailed
|
|
403
|
-
root: [
|
|
430
|
+
root: [
|
|
431
|
+
"versioned | nil | max",
|
|
432
|
+
"@",
|
|
433
|
+
{ description: "a UUID", format: "uuid" }
|
|
434
|
+
],
|
|
404
435
|
"#nil": "'00000000-0000-0000-0000-000000000000'",
|
|
405
436
|
"#max": "'ffffffff-ffff-ffff-ffff-ffffffffffff'",
|
|
406
|
-
"#versioned": /[
|
|
407
|
-
v1: regexStringNode(/^[
|
|
408
|
-
v2: regexStringNode(/^[
|
|
409
|
-
v3: regexStringNode(/^[
|
|
410
|
-
v4: regexStringNode(/^[
|
|
411
|
-
v5: regexStringNode(/^[
|
|
412
|
-
v6: regexStringNode(/^[
|
|
413
|
-
v7: regexStringNode(/^[
|
|
414
|
-
v8: regexStringNode(/^[
|
|
437
|
+
"#versioned": /[\da-f]{8}-[\da-f]{4}-[1-8][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}/i,
|
|
438
|
+
v1: regexStringNode(/^[\da-f]{8}-[\da-f]{4}-1[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i, "a UUIDv1"),
|
|
439
|
+
v2: regexStringNode(/^[\da-f]{8}-[\da-f]{4}-2[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i, "a UUIDv2"),
|
|
440
|
+
v3: regexStringNode(/^[\da-f]{8}-[\da-f]{4}-3[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i, "a UUIDv3"),
|
|
441
|
+
v4: regexStringNode(/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i, "a UUIDv4"),
|
|
442
|
+
v5: regexStringNode(/^[\da-f]{8}-[\da-f]{4}-5[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i, "a UUIDv5"),
|
|
443
|
+
v6: regexStringNode(/^[\da-f]{8}-[\da-f]{4}-6[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i, "a UUIDv6"),
|
|
444
|
+
v7: regexStringNode(/^[\da-f]{8}-[\da-f]{4}-7[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i, "a UUIDv7"),
|
|
445
|
+
v8: regexStringNode(/^[\da-f]{8}-[\da-f]{4}-8[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i, "a UUIDv8")
|
|
415
446
|
}, {
|
|
416
447
|
name: "string.uuid"
|
|
417
448
|
});
|
|
418
449
|
export const string = Scope.module({
|
|
419
450
|
root: intrinsic.string,
|
|
420
451
|
alpha: regexStringNode(/^[A-Za-z]*$/, "only letters"),
|
|
421
|
-
alphanumeric: regexStringNode(/^[
|
|
452
|
+
alphanumeric: regexStringNode(/^[\dA-Za-z]*$/, "only letters and digits 0-9"),
|
|
422
453
|
hex,
|
|
423
454
|
base64,
|
|
424
455
|
capitalize,
|
|
@@ -431,7 +462,8 @@ export const string = Scope.module({
|
|
|
431
462
|
json,
|
|
432
463
|
lower,
|
|
433
464
|
normalize,
|
|
434
|
-
numeric,
|
|
465
|
+
numeric: stringNumeric,
|
|
466
|
+
regex,
|
|
435
467
|
semver,
|
|
436
468
|
trim,
|
|
437
469
|
upper,
|
package/out/methods/base.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BaseNode, BaseRoot, Disjoint, JsonSchema, NodeSelector, Predicate, StandardSchemaV1, TypeMeta, UndeclaredKeyBehavior } from "@ark/schema";
|
|
1
|
+
import type { BaseNode, BaseRoot, Disjoint, JsonSchema, NodeSelector, Predicate, StandardSchemaV1, ToJsonSchema, TypeMeta, UndeclaredKeyBehavior } from "@ark/schema";
|
|
2
2
|
import type { anyOrNever, array, Callable, ErrorMessage, inferred, JsonStructure, unset } from "@ark/util";
|
|
3
3
|
import type { defaultFor, distill, inferIntersection, inferPipe, InferredMorph, Out, To } from "../attributes.ts";
|
|
4
4
|
import type { ArkAmbient } from "../config.ts";
|
|
@@ -98,9 +98,9 @@ export interface Inferred<out t = unknown, $ = {}> {
|
|
|
98
98
|
/**
|
|
99
99
|
* #### generate a JSON Schema
|
|
100
100
|
*
|
|
101
|
-
* @throws {
|
|
101
|
+
* @throws {ToJsonSchema.Error} if this cannot be converted to JSON Schema
|
|
102
102
|
*/
|
|
103
|
-
toJsonSchema(): JsonSchema;
|
|
103
|
+
toJsonSchema(options?: ToJsonSchema.Options): JsonSchema;
|
|
104
104
|
/**
|
|
105
105
|
* #### metadata like custom descriptions and error messages
|
|
106
106
|
*
|
|
@@ -322,7 +322,7 @@ export interface Inferred<out t = unknown, $ = {}> {
|
|
|
322
322
|
/**
|
|
323
323
|
* #### apply a predicate function to output
|
|
324
324
|
*
|
|
325
|
-
* ✅ go-to fallback for validation not composable via
|
|
325
|
+
* ✅ go-to fallback for validation not composable via built-in types and operators
|
|
326
326
|
* ✅ runs after all other validators and morphs, if present
|
|
327
327
|
* 🥸 {@link https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates | Type predicates} can be used as casts
|
|
328
328
|
*
|