arktype 1.0.28-alpha → 1.1.0-dev-2
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/dist/main.d.ts +11 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +8 -0
- package/dist/main.js.map +1 -0
- package/dist/match.d.ts +46 -0
- package/dist/match.d.ts.map +1 -0
- package/dist/match.js +23 -0
- package/dist/match.js.map +1 -0
- package/dist/parser/definition.d.ts +32 -0
- package/dist/parser/definition.d.ts.map +1 -0
- package/dist/parser/definition.js +29 -0
- package/dist/parser/definition.js.map +1 -0
- package/dist/parser/generic.d.ts +44 -0
- package/dist/parser/generic.d.ts.map +1 -0
- package/dist/parser/generic.js +46 -0
- package/dist/parser/generic.js.map +1 -0
- package/dist/parser/objectLiteral.d.ts +24 -0
- package/dist/parser/objectLiteral.d.ts.map +1 -0
- package/dist/parser/objectLiteral.js +38 -0
- package/dist/parser/objectLiteral.js.map +1 -0
- package/dist/parser/semantic/bounds.d.ts +13 -0
- package/dist/parser/semantic/bounds.d.ts.map +1 -0
- package/dist/parser/semantic/bounds.js +2 -0
- package/dist/parser/semantic/bounds.js.map +1 -0
- package/dist/parser/semantic/divisor.d.ts +9 -0
- package/dist/parser/semantic/divisor.d.ts.map +1 -0
- package/dist/parser/semantic/divisor.js +2 -0
- package/dist/parser/semantic/divisor.js.map +1 -0
- package/dist/parser/semantic/intersections.d.ts +15 -0
- package/dist/parser/semantic/intersections.d.ts.map +1 -0
- package/dist/parser/semantic/intersections.js +2 -0
- package/dist/parser/semantic/intersections.js.map +1 -0
- package/dist/parser/semantic/semantic.d.ts +22 -0
- package/dist/parser/semantic/semantic.d.ts.map +1 -0
- package/dist/parser/semantic/semantic.js +2 -0
- package/dist/parser/semantic/semantic.js.map +1 -0
- package/dist/parser/semantic/utils.d.ts +8 -0
- package/dist/parser/semantic/utils.d.ts.map +1 -0
- package/dist/parser/semantic/utils.js +2 -0
- package/dist/parser/semantic/utils.js.map +1 -0
- package/dist/parser/semantic/validate.d.ts +24 -0
- package/dist/parser/semantic/validate.d.ts.map +1 -0
- package/dist/parser/semantic/validate.js +2 -0
- package/dist/parser/semantic/validate.js.map +1 -0
- package/dist/parser/shared.d.ts +48 -0
- package/dist/parser/shared.d.ts.map +1 -0
- package/dist/parser/shared.js +41 -0
- package/dist/parser/shared.js.map +1 -0
- package/dist/parser/string/reduce/dynamic.d.ts +40 -0
- package/dist/parser/string/reduce/dynamic.d.ts.map +1 -0
- package/dist/parser/string/reduce/dynamic.js +122 -0
- package/dist/parser/string/reduce/dynamic.js.map +1 -0
- package/dist/parser/string/reduce/shared.d.ts +29 -0
- package/dist/parser/string/reduce/shared.d.ts.map +1 -0
- package/dist/parser/string/reduce/shared.js +7 -0
- package/dist/parser/string/reduce/shared.js.map +1 -0
- package/dist/parser/string/reduce/static.d.ts +177 -0
- package/dist/parser/string/reduce/static.d.ts.map +1 -0
- package/dist/parser/string/reduce/static.js +2 -0
- package/dist/parser/string/reduce/static.js.map +1 -0
- package/dist/parser/string/shift/operand/date.d.ts +11 -0
- package/dist/parser/string/shift/operand/date.d.ts.map +1 -0
- package/dist/parser/string/shift/operand/date.js +26 -0
- package/dist/parser/string/shift/operand/date.js.map +1 -0
- package/dist/parser/string/shift/operand/enclosed.d.ts +49 -0
- package/dist/parser/string/shift/operand/enclosed.d.ts.map +1 -0
- package/dist/parser/string/shift/operand/enclosed.js +50 -0
- package/dist/parser/string/shift/operand/enclosed.js.map +1 -0
- package/dist/parser/string/shift/operand/operand.d.ts +9 -0
- package/dist/parser/string/shift/operand/operand.d.ts.map +1 -0
- package/dist/parser/string/shift/operand/operand.js +17 -0
- package/dist/parser/string/shift/operand/operand.js.map +1 -0
- package/dist/parser/string/shift/operand/unenclosed.d.ts +36 -0
- package/dist/parser/string/shift/operand/unenclosed.d.ts.map +1 -0
- package/dist/parser/string/shift/operand/unenclosed.js +68 -0
- package/dist/parser/string/shift/operand/unenclosed.js.map +1 -0
- package/dist/parser/string/shift/operator/bounds.d.ts +55 -0
- package/dist/parser/string/shift/operator/bounds.d.ts.map +1 -0
- package/dist/parser/string/shift/operator/bounds.js +95 -0
- package/dist/parser/string/shift/operator/bounds.js.map +1 -0
- package/dist/parser/string/shift/operator/divisor.d.ts +9 -0
- package/dist/parser/string/shift/operator/divisor.d.ts.map +1 -0
- package/dist/parser/string/shift/operator/divisor.js +13 -0
- package/dist/parser/string/shift/operator/divisor.js.map +1 -0
- package/dist/parser/string/shift/operator/operator.d.ts +13 -0
- package/dist/parser/string/shift/operator/operator.d.ts.map +1 -0
- package/dist/parser/string/shift/operator/operator.js +29 -0
- package/dist/parser/string/shift/operator/operator.js.map +1 -0
- package/dist/parser/string/shift/scanner.d.ts +71 -0
- package/dist/parser/string/shift/scanner.d.ts.map +1 -0
- package/dist/parser/string/shift/scanner.js +99 -0
- package/dist/parser/string/shift/scanner.js.map +1 -0
- package/dist/parser/string/string.d.ts +26 -0
- package/dist/parser/string/string.d.ts.map +1 -0
- package/dist/parser/string/string.js +31 -0
- package/dist/parser/string/string.js.map +1 -0
- package/dist/parser/tuple.d.ts +73 -0
- package/dist/parser/tuple.d.ts.map +1 -0
- package/dist/parser/tuple.js +134 -0
- package/dist/parser/tuple.js.map +1 -0
- package/dist/scope.d.ts +159 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +248 -0
- package/dist/scope.js.map +1 -0
- package/dist/scopes/ark.d.ts +38 -0
- package/dist/scopes/ark.d.ts.map +1 -0
- package/dist/scopes/ark.js +24 -0
- package/dist/scopes/ark.js.map +1 -0
- package/dist/scopes/jsObjects.d.ts +19 -0
- package/dist/scopes/jsObjects.d.ts.map +1 -0
- package/dist/scopes/jsObjects.js +15 -0
- package/dist/scopes/jsObjects.js.map +1 -0
- package/dist/scopes/parsing.d.ts +18 -0
- package/dist/scopes/parsing.d.ts.map +1 -0
- package/dist/scopes/parsing.js +61 -0
- package/dist/scopes/parsing.js.map +1 -0
- package/dist/scopes/tsGenerics.d.ts +17 -0
- package/dist/scopes/tsGenerics.d.ts.map +1 -0
- package/dist/scopes/tsGenerics.js +13 -0
- package/dist/scopes/tsGenerics.js.map +1 -0
- package/dist/scopes/tsKeywords.d.ts +24 -0
- package/dist/scopes/tsKeywords.d.ts.map +1 -0
- package/dist/scopes/tsKeywords.js +20 -0
- package/dist/scopes/tsKeywords.js.map +1 -0
- package/dist/scopes/utils/creditCard.d.ts +3 -0
- package/dist/scopes/utils/creditCard.d.ts.map +1 -0
- package/dist/{mjs/scopes/validation → scopes/utils}/creditCard.js +14 -12
- package/dist/scopes/utils/creditCard.js.map +1 -0
- package/dist/{types/scopes/validation → scopes/utils}/date.d.ts +3 -2
- package/dist/scopes/utils/date.d.ts.map +1 -0
- package/dist/{mjs/scopes/validation → scopes/utils}/date.js +24 -19
- package/dist/scopes/utils/date.js.map +1 -0
- package/dist/scopes/validation.d.ts +20 -0
- package/dist/scopes/validation.d.ts.map +1 -0
- package/dist/scopes/validation.js +57 -0
- package/dist/scopes/validation.js.map +1 -0
- package/dist/type.d.ts +101 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js +138 -0
- package/dist/type.js.map +1 -0
- package/main.ts +20 -0
- package/match.ts +137 -0
- package/package.json +41 -108
- package/parser/definition.ts +156 -0
- package/parser/generic.ts +208 -0
- package/parser/objectLiteral.ts +120 -0
- package/parser/semantic/bounds.ts +63 -0
- package/parser/semantic/divisor.ts +13 -0
- package/parser/semantic/intersections.ts +47 -0
- package/parser/semantic/semantic.ts +107 -0
- package/parser/semantic/utils.ts +26 -0
- package/parser/semantic/validate.ts +105 -0
- package/parser/shared.ts +141 -0
- package/parser/string/reduce/dynamic.ts +181 -0
- package/parser/string/reduce/shared.ts +73 -0
- package/parser/string/reduce/static.ts +300 -0
- package/parser/string/shift/operand/date.ts +57 -0
- package/parser/string/shift/operand/enclosed.ts +119 -0
- package/parser/string/shift/operand/operand.ts +48 -0
- package/parser/string/shift/operand/unenclosed.ts +282 -0
- package/parser/string/shift/operator/bounds.ts +229 -0
- package/parser/string/shift/operator/divisor.ts +36 -0
- package/parser/string/shift/operator/operator.ts +82 -0
- package/parser/string/shift/scanner.ts +209 -0
- package/parser/string/string.ts +93 -0
- package/parser/tuple.ts +475 -0
- package/scope.ts +573 -0
- package/scopes/ark.ts +64 -0
- package/scopes/jsObjects.ts +29 -0
- package/scopes/parsing.ts +81 -0
- package/scopes/tsGenerics.ts +28 -0
- package/scopes/tsKeywords.ts +39 -0
- package/scopes/utils/creditCard.ts +37 -0
- package/scopes/utils/date.ts +108 -0
- package/scopes/validation.ts +81 -0
- package/type.ts +403 -0
- package/LICENSE +0 -7
- package/README.md +0 -351
- package/dist/cjs/main.js +0 -38
- package/dist/cjs/nodes/branch.js +0 -140
- package/dist/cjs/nodes/compose.js +0 -163
- package/dist/cjs/nodes/discriminate.js +0 -265
- package/dist/cjs/nodes/node.js +0 -139
- package/dist/cjs/nodes/predicate.js +0 -86
- package/dist/cjs/nodes/rules/class.js +0 -25
- package/dist/cjs/nodes/rules/collapsibleSet.js +0 -48
- package/dist/cjs/nodes/rules/divisor.js +0 -29
- package/dist/cjs/nodes/rules/props.js +0 -167
- package/dist/cjs/nodes/rules/range.js +0 -105
- package/dist/cjs/nodes/rules/regex.js +0 -26
- package/dist/cjs/nodes/rules/rules.js +0 -123
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/parse/ast/ast.js +0 -4
- package/dist/cjs/parse/ast/bound.js +0 -16
- package/dist/cjs/parse/ast/config.js +0 -13
- package/dist/cjs/parse/ast/distributableFunction.js +0 -48
- package/dist/cjs/parse/ast/divisor.js +0 -9
- package/dist/cjs/parse/ast/intersection.js +0 -30
- package/dist/cjs/parse/ast/keyof.js +0 -111
- package/dist/cjs/parse/ast/morph.js +0 -58
- package/dist/cjs/parse/ast/narrow.js +0 -22
- package/dist/cjs/parse/ast/node.js +0 -4
- package/dist/cjs/parse/ast/tuple.js +0 -94
- package/dist/cjs/parse/ast/union.js +0 -9
- package/dist/cjs/parse/ast/utils.js +0 -4
- package/dist/cjs/parse/definition.js +0 -61
- package/dist/cjs/parse/record.js +0 -37
- package/dist/cjs/parse/string/reduce/dynamic.js +0 -167
- package/dist/cjs/parse/string/reduce/shared.js +0 -23
- package/dist/cjs/parse/string/reduce/static.js +0 -4
- package/dist/cjs/parse/string/shift/operand/enclosed.js +0 -54
- package/dist/cjs/parse/string/shift/operand/operand.js +0 -11
- package/dist/cjs/parse/string/shift/operand/unenclosed.js +0 -53
- package/dist/cjs/parse/string/shift/operator/bounds.js +0 -87
- package/dist/cjs/parse/string/shift/operator/divisor.js +0 -35
- package/dist/cjs/parse/string/shift/operator/operator.js +0 -26
- package/dist/cjs/parse/string/shift/scanner.js +0 -114
- package/dist/cjs/parse/string/string.js +0 -43
- package/dist/cjs/scopes/ark.js +0 -45
- package/dist/cjs/scopes/cache.js +0 -52
- package/dist/cjs/scopes/expressions.js +0 -29
- package/dist/cjs/scopes/jsObjects.js +0 -93
- package/dist/cjs/scopes/scope.js +0 -323
- package/dist/cjs/scopes/tsKeywords.js +0 -113
- package/dist/cjs/scopes/type.js +0 -50
- package/dist/cjs/scopes/validation/creditCard.js +0 -47
- package/dist/cjs/scopes/validation/date.js +0 -62
- package/dist/cjs/scopes/validation/validation.js +0 -108
- package/dist/cjs/traverse/problems.js +0 -281
- package/dist/cjs/traverse/traverse.js +0 -390
- package/dist/cjs/utils/chainableNoOpProxy.js +0 -23
- package/dist/cjs/utils/data.js +0 -53
- package/dist/cjs/utils/domains.js +0 -30
- package/dist/cjs/utils/errors.js +0 -26
- package/dist/cjs/utils/freeze.js +0 -15
- package/dist/cjs/utils/generics.js +0 -63
- package/dist/cjs/utils/numericLiterals.js +0 -75
- package/dist/cjs/utils/objectKinds.js +0 -69
- package/dist/cjs/utils/paths.js +0 -32
- package/dist/cjs/utils/serialize.js +0 -74
- package/dist/cjs/utils/unionToTuple.js +0 -4
- package/dist/mjs/main.js +0 -8
- package/dist/mjs/nodes/branch.js +0 -123
- package/dist/mjs/nodes/compose.js +0 -141
- package/dist/mjs/nodes/discriminate.js +0 -250
- package/dist/mjs/nodes/node.js +0 -117
- package/dist/mjs/nodes/predicate.js +0 -69
- package/dist/mjs/nodes/rules/class.js +0 -11
- package/dist/mjs/nodes/rules/collapsibleSet.js +0 -34
- package/dist/mjs/nodes/rules/divisor.js +0 -15
- package/dist/mjs/nodes/rules/props.js +0 -149
- package/dist/mjs/nodes/rules/range.js +0 -86
- package/dist/mjs/nodes/rules/regex.js +0 -11
- package/dist/mjs/nodes/rules/rules.js +0 -106
- package/dist/mjs/package.json +0 -3
- package/dist/mjs/parse/ast/ast.js +0 -1
- package/dist/mjs/parse/ast/bound.js +0 -2
- package/dist/mjs/parse/ast/config.js +0 -9
- package/dist/mjs/parse/ast/distributableFunction.js +0 -34
- package/dist/mjs/parse/ast/divisor.js +0 -1
- package/dist/mjs/parse/ast/intersection.js +0 -16
- package/dist/mjs/parse/ast/keyof.js +0 -103
- package/dist/mjs/parse/ast/morph.js +0 -44
- package/dist/mjs/parse/ast/narrow.js +0 -14
- package/dist/mjs/parse/ast/node.js +0 -1
- package/dist/mjs/parse/ast/tuple.js +0 -80
- package/dist/mjs/parse/ast/union.js +0 -1
- package/dist/mjs/parse/ast/utils.js +0 -1
- package/dist/mjs/parse/definition.js +0 -46
- package/dist/mjs/parse/record.js +0 -29
- package/dist/mjs/parse/string/reduce/dynamic.js +0 -159
- package/dist/mjs/parse/string/reduce/shared.js +0 -6
- package/dist/mjs/parse/string/reduce/static.js +0 -1
- package/dist/mjs/parse/string/shift/operand/enclosed.js +0 -39
- package/dist/mjs/parse/string/shift/operand/operand.js +0 -3
- package/dist/mjs/parse/string/shift/operand/unenclosed.js +0 -36
- package/dist/mjs/parse/string/shift/operator/bounds.js +0 -70
- package/dist/mjs/parse/string/shift/operator/divisor.js +0 -21
- package/dist/mjs/parse/string/shift/operator/operator.js +0 -13
- package/dist/mjs/parse/string/shift/scanner.js +0 -106
- package/dist/mjs/parse/string/string.js +0 -28
- package/dist/mjs/scopes/ark.js +0 -28
- package/dist/mjs/scopes/cache.js +0 -38
- package/dist/mjs/scopes/expressions.js +0 -89
- package/dist/mjs/scopes/jsObjects.js +0 -82
- package/dist/mjs/scopes/scope.js +0 -303
- package/dist/mjs/scopes/tsKeywords.js +0 -116
- package/dist/mjs/scopes/type.js +0 -35
- package/dist/mjs/scopes/validation/validation.js +0 -112
- package/dist/mjs/traverse/problems.js +0 -260
- package/dist/mjs/traverse/traverse.js +0 -373
- package/dist/mjs/utils/chainableNoOpProxy.js +0 -15
- package/dist/mjs/utils/data.js +0 -38
- package/dist/mjs/utils/domains.js +0 -15
- package/dist/mjs/utils/errors.js +0 -10
- package/dist/mjs/utils/freeze.js +0 -7
- package/dist/mjs/utils/generics.js +0 -38
- package/dist/mjs/utils/numericLiterals.js +0 -72
- package/dist/mjs/utils/objectKinds.js +0 -55
- package/dist/mjs/utils/paths.js +0 -18
- package/dist/mjs/utils/serialize.js +0 -58
- package/dist/mjs/utils/unionToTuple.js +0 -1
- package/dist/tsconfig.temp.tsbuildinfo +0 -1
- package/dist/types/main.d.ts +0 -15
- package/dist/types/nodes/branch.d.ts +0 -29
- package/dist/types/nodes/compose.d.ts +0 -98
- package/dist/types/nodes/discriminate.d.ts +0 -26
- package/dist/types/nodes/node.d.ts +0 -69
- package/dist/types/nodes/predicate.d.ts +0 -18
- package/dist/types/nodes/rules/class.d.ts +0 -4
- package/dist/types/nodes/rules/collapsibleSet.d.ts +0 -4
- package/dist/types/nodes/rules/divisor.d.ts +0 -3
- package/dist/types/nodes/rules/props.d.ts +0 -43
- package/dist/types/nodes/rules/range.d.ts +0 -34
- package/dist/types/nodes/rules/regex.d.ts +0 -5
- package/dist/types/nodes/rules/rules.d.ts +0 -33
- package/dist/types/parse/ast/ast.d.ts +0 -24
- package/dist/types/parse/ast/bound.d.ts +0 -27
- package/dist/types/parse/ast/config.d.ts +0 -15
- package/dist/types/parse/ast/distributableFunction.d.ts +0 -18
- package/dist/types/parse/ast/divisor.d.ts +0 -13
- package/dist/types/parse/ast/intersection.d.ts +0 -31
- package/dist/types/parse/ast/keyof.d.ts +0 -10
- package/dist/types/parse/ast/morph.d.ts +0 -18
- package/dist/types/parse/ast/narrow.d.ts +0 -21
- package/dist/types/parse/ast/node.d.ts +0 -35
- package/dist/types/parse/ast/tuple.d.ts +0 -41
- package/dist/types/parse/ast/union.d.ts +0 -17
- package/dist/types/parse/ast/utils.d.ts +0 -7
- package/dist/types/parse/definition.d.ts +0 -30
- package/dist/types/parse/record.d.ts +0 -26
- package/dist/types/parse/string/reduce/dynamic.d.ts +0 -34
- package/dist/types/parse/string/reduce/shared.d.ts +0 -25
- package/dist/types/parse/string/reduce/static.d.ts +0 -130
- package/dist/types/parse/string/shift/operand/enclosed.d.ts +0 -28
- package/dist/types/parse/string/shift/operand/operand.d.ts +0 -9
- package/dist/types/parse/string/shift/operand/unenclosed.d.ts +0 -18
- package/dist/types/parse/string/shift/operator/bounds.d.ts +0 -21
- package/dist/types/parse/string/shift/operator/divisor.d.ts +0 -13
- package/dist/types/parse/string/shift/operator/operator.d.ts +0 -13
- package/dist/types/parse/string/shift/scanner.d.ts +0 -89
- package/dist/types/parse/string/string.d.ts +0 -25
- package/dist/types/scopes/ark.d.ts +0 -209
- package/dist/types/scopes/cache.d.ts +0 -14
- package/dist/types/scopes/expressions.d.ts +0 -136
- package/dist/types/scopes/jsObjects.d.ts +0 -26
- package/dist/types/scopes/scope.d.ts +0 -99
- package/dist/types/scopes/tsKeywords.d.ts +0 -50
- package/dist/types/scopes/type.d.ts +0 -67
- package/dist/types/scopes/validation/creditCard.d.ts +0 -2
- package/dist/types/scopes/validation/validation.d.ts +0 -49
- package/dist/types/traverse/problems.d.ts +0 -88
- package/dist/types/traverse/traverse.d.ts +0 -55
- package/dist/types/utils/chainableNoOpProxy.d.ts +0 -14
- package/dist/types/utils/data.d.ts +0 -13
- package/dist/types/utils/domains.d.ts +0 -32
- package/dist/types/utils/errors.d.ts +0 -6
- package/dist/types/utils/freeze.d.ts +0 -2
- package/dist/types/utils/generics.d.ts +0 -125
- package/dist/types/utils/numericLiterals.d.ts +0 -46
- package/dist/types/utils/objectKinds.d.ts +0 -84
- package/dist/types/utils/paths.d.ts +0 -9
- package/dist/types/utils/serialize.d.ts +0 -37
- package/dist/types/utils/unionToTuple.d.ts +0 -11
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { isWellFormedInteger, wellFormedNumberMatcher } from "../../utils/numericLiterals.js";
|
|
2
|
-
import { rootType, scope } from "../scope.js";
|
|
3
|
-
import { tsKeywords } from "../tsKeywords.js";
|
|
4
|
-
import { creditCard } from "./creditCard.js";
|
|
5
|
-
import { parsedDate } from "./date.js";
|
|
6
|
-
// Non-trivial expressions should have an explanation or attribution
|
|
7
|
-
const parsedNumber = rootType([
|
|
8
|
-
wellFormedNumberMatcher,
|
|
9
|
-
"|>",
|
|
10
|
-
(s)=>parseFloat(s)
|
|
11
|
-
], {
|
|
12
|
-
mustBe: "a well-formed numeric string"
|
|
13
|
-
});
|
|
14
|
-
const parsedInteger = rootType([
|
|
15
|
-
tsKeywords.string,
|
|
16
|
-
"|>",
|
|
17
|
-
(s, problems)=>{
|
|
18
|
-
if (!isWellFormedInteger(s)) {
|
|
19
|
-
return problems.mustBe("a well-formed integer string");
|
|
20
|
-
}
|
|
21
|
-
const parsed = parseInt(s);
|
|
22
|
-
return Number.isSafeInteger(parsed) ? parsed : problems.mustBe("an integer in the range Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER");
|
|
23
|
-
}
|
|
24
|
-
]);
|
|
25
|
-
// https://www.regular-expressions.info/email.html
|
|
26
|
-
const email = rootType(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/, {
|
|
27
|
-
mustBe: "a valid email"
|
|
28
|
-
});
|
|
29
|
-
// https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
|
|
30
|
-
const uuid = rootType(/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/, {
|
|
31
|
-
mustBe: "a valid UUID"
|
|
32
|
-
});
|
|
33
|
-
// https://semver.org/
|
|
34
|
-
const semver = rootType(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/, {
|
|
35
|
-
mustBe: "a valid semantic version (see https://semver.org/)"
|
|
36
|
-
});
|
|
37
|
-
const json = rootType([
|
|
38
|
-
tsKeywords.string,
|
|
39
|
-
"|>",
|
|
40
|
-
(s)=>JSON.parse(s)
|
|
41
|
-
], {
|
|
42
|
-
mustBe: "a JSON-parsable string"
|
|
43
|
-
});
|
|
44
|
-
/**
|
|
45
|
-
* @keywords keywords: {
|
|
46
|
-
"alpha": "only letters",
|
|
47
|
-
"alphanumeric": "only letters and digits",
|
|
48
|
-
"lowercase": "only lowercase letters",
|
|
49
|
-
"uppercase": "only uppercase letters",
|
|
50
|
-
"creditCard": "a valid credit card number",
|
|
51
|
-
"email": "a valid email",
|
|
52
|
-
"uuid": "a valid UUID",
|
|
53
|
-
"parsedNumber": "a well-formed numeric string",
|
|
54
|
-
"parsedInteger": "a well-formed integer string",
|
|
55
|
-
"parsedDate": "a valid date",
|
|
56
|
-
"semver": "a valid semantic version",
|
|
57
|
-
"json": "a JSON-parsable string",
|
|
58
|
-
"integer": "an integer"
|
|
59
|
-
}
|
|
60
|
-
* @docgenScope
|
|
61
|
-
* @docgenTable
|
|
62
|
-
*/ export const validationScope = scope({
|
|
63
|
-
// Character sets
|
|
64
|
-
alpha: [
|
|
65
|
-
/^[A-Za-z]*$/,
|
|
66
|
-
":",
|
|
67
|
-
{
|
|
68
|
-
mustBe: "only letters"
|
|
69
|
-
}
|
|
70
|
-
],
|
|
71
|
-
alphanumeric: [
|
|
72
|
-
/^[A-Za-z\d]*$/,
|
|
73
|
-
":",
|
|
74
|
-
{
|
|
75
|
-
mustBe: "only letters and digits"
|
|
76
|
-
}
|
|
77
|
-
],
|
|
78
|
-
lowercase: [
|
|
79
|
-
/^[a-z]*$/,
|
|
80
|
-
":",
|
|
81
|
-
{
|
|
82
|
-
mustBe: "only lowercase letters"
|
|
83
|
-
}
|
|
84
|
-
],
|
|
85
|
-
uppercase: [
|
|
86
|
-
/^[A-Z]*$/,
|
|
87
|
-
":",
|
|
88
|
-
{
|
|
89
|
-
mustBe: "only uppercase letters"
|
|
90
|
-
}
|
|
91
|
-
],
|
|
92
|
-
creditCard,
|
|
93
|
-
email,
|
|
94
|
-
uuid,
|
|
95
|
-
parsedNumber,
|
|
96
|
-
parsedInteger,
|
|
97
|
-
parsedDate,
|
|
98
|
-
semver,
|
|
99
|
-
json,
|
|
100
|
-
integer: [
|
|
101
|
-
"node",
|
|
102
|
-
{
|
|
103
|
-
number: {
|
|
104
|
-
divisor: 1
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
]
|
|
108
|
-
}, {
|
|
109
|
-
name: "validation",
|
|
110
|
-
standard: false
|
|
111
|
-
});
|
|
112
|
-
export const validation = validationScope.compile();
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
function _checkPrivateRedeclaration(obj, privateCollection) {
|
|
2
|
-
if (privateCollection.has(obj)) {
|
|
3
|
-
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
function _classApplyDescriptorGet(receiver, descriptor) {
|
|
7
|
-
if (descriptor.get) {
|
|
8
|
-
return descriptor.get.call(receiver);
|
|
9
|
-
}
|
|
10
|
-
return descriptor.value;
|
|
11
|
-
}
|
|
12
|
-
function _classApplyDescriptorSet(receiver, descriptor, value) {
|
|
13
|
-
if (descriptor.set) {
|
|
14
|
-
descriptor.set.call(receiver, value);
|
|
15
|
-
} else {
|
|
16
|
-
if (!descriptor.writable) {
|
|
17
|
-
throw new TypeError("attempted to set read only private field");
|
|
18
|
-
}
|
|
19
|
-
descriptor.value = value;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function _classExtractFieldDescriptor(receiver, privateMap, action) {
|
|
23
|
-
if (!privateMap.has(receiver)) {
|
|
24
|
-
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
25
|
-
}
|
|
26
|
-
return privateMap.get(receiver);
|
|
27
|
-
}
|
|
28
|
-
function _classPrivateFieldGet(receiver, privateMap) {
|
|
29
|
-
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
|
|
30
|
-
return _classApplyDescriptorGet(receiver, descriptor);
|
|
31
|
-
}
|
|
32
|
-
function _classPrivateFieldInit(obj, privateMap, value) {
|
|
33
|
-
_checkPrivateRedeclaration(obj, privateMap);
|
|
34
|
-
privateMap.set(obj, value);
|
|
35
|
-
}
|
|
36
|
-
function _classPrivateFieldSet(receiver, privateMap, value) {
|
|
37
|
-
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set");
|
|
38
|
-
_classApplyDescriptorSet(receiver, descriptor, value);
|
|
39
|
-
return value;
|
|
40
|
-
}
|
|
41
|
-
function _defineProperty(obj, key, value) {
|
|
42
|
-
if (key in obj) {
|
|
43
|
-
Object.defineProperty(obj, key, {
|
|
44
|
-
value: value,
|
|
45
|
-
enumerable: true,
|
|
46
|
-
configurable: true,
|
|
47
|
-
writable: true
|
|
48
|
-
});
|
|
49
|
-
} else {
|
|
50
|
-
obj[key] = value;
|
|
51
|
-
}
|
|
52
|
-
return obj;
|
|
53
|
-
}
|
|
54
|
-
import { Scanner } from "../parse/string/shift/scanner.js";
|
|
55
|
-
import { DataWrapper } from "../utils/data.js";
|
|
56
|
-
import { domainDescriptions } from "../utils/domains.js";
|
|
57
|
-
import { objectKeysOf } from "../utils/generics.js";
|
|
58
|
-
import { isWellFormedInteger } from "../utils/numericLiterals.js";
|
|
59
|
-
import { getExactConstructorObjectKind, objectKindDescriptions } from "../utils/objectKinds.js";
|
|
60
|
-
import { Path } from "../utils/paths.js";
|
|
61
|
-
import { stringify } from "../utils/serialize.js";
|
|
62
|
-
export class ArkTypeError extends TypeError {
|
|
63
|
-
constructor(problems){
|
|
64
|
-
super(`${problems}`);
|
|
65
|
-
_defineProperty(this, "cause", void 0);
|
|
66
|
-
this.cause = problems;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
export class Problem {
|
|
70
|
-
toString() {
|
|
71
|
-
return this.message;
|
|
72
|
-
}
|
|
73
|
-
get message() {
|
|
74
|
-
return this.writers.addContext(this.reason, this.path);
|
|
75
|
-
}
|
|
76
|
-
get reason() {
|
|
77
|
-
return this.writers.writeReason(this.mustBe, new DataWrapper(this.data));
|
|
78
|
-
}
|
|
79
|
-
get mustBe() {
|
|
80
|
-
return typeof this.writers.mustBe === "string" ? this.writers.mustBe : this.writers.mustBe(this.source);
|
|
81
|
-
}
|
|
82
|
-
constructor(code, path, data, source, writers){
|
|
83
|
-
_defineProperty(this, "code", void 0);
|
|
84
|
-
_defineProperty(this, "path", void 0);
|
|
85
|
-
_defineProperty(this, "data", void 0);
|
|
86
|
-
_defineProperty(this, "source", void 0);
|
|
87
|
-
_defineProperty(this, "writers", void 0);
|
|
88
|
-
_defineProperty(this, "parts", void 0);
|
|
89
|
-
this.code = code;
|
|
90
|
-
this.path = path;
|
|
91
|
-
this.data = data;
|
|
92
|
-
this.source = source;
|
|
93
|
-
this.writers = writers;
|
|
94
|
-
if (this.code === "multi") {
|
|
95
|
-
this.parts = this.source;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
var _state = /*#__PURE__*/ new WeakMap();
|
|
100
|
-
class ProblemArray extends Array {
|
|
101
|
-
mustBe(description, opts) {
|
|
102
|
-
return this.add("custom", description, opts);
|
|
103
|
-
}
|
|
104
|
-
add(code, source, opts) {
|
|
105
|
-
// copy the path to avoid future mutations affecting it
|
|
106
|
-
const path = Path.from(opts?.path ?? _classPrivateFieldGet(this, _state).path);
|
|
107
|
-
const data = // we have to check for the presence of the key explicitly since the
|
|
108
|
-
// data could be undefined or null
|
|
109
|
-
opts && "data" in opts ? opts.data : _classPrivateFieldGet(this, _state).data;
|
|
110
|
-
const problem = new Problem(// avoid a bunch of errors from TS trying to discriminate the
|
|
111
|
-
// problem input based on the code
|
|
112
|
-
code, path, data, source, _classPrivateFieldGet(this, _state).getProblemConfig(code));
|
|
113
|
-
this.addProblem(problem);
|
|
114
|
-
return problem;
|
|
115
|
-
}
|
|
116
|
-
addProblem(problem) {
|
|
117
|
-
const pathKey = `${problem.path}`;
|
|
118
|
-
const existing = this.byPath[pathKey];
|
|
119
|
-
if (existing) {
|
|
120
|
-
if (existing.parts) {
|
|
121
|
-
existing.parts.push(problem);
|
|
122
|
-
} else {
|
|
123
|
-
const problemIntersection = new Problem("multi", existing.path, existing.data, [
|
|
124
|
-
existing,
|
|
125
|
-
problem
|
|
126
|
-
], _classPrivateFieldGet(this, _state).getProblemConfig("multi"));
|
|
127
|
-
const existingIndex = this.indexOf(existing);
|
|
128
|
-
// If existing is found (which it always should be unless this was externally mutated),
|
|
129
|
-
// replace it with the new problem intersection. In case it isn't for whatever reason,
|
|
130
|
-
// just append the intersection.
|
|
131
|
-
this[existingIndex === -1 ? this.length : existingIndex] = problemIntersection;
|
|
132
|
-
this.byPath[pathKey] = problemIntersection;
|
|
133
|
-
}
|
|
134
|
-
} else {
|
|
135
|
-
this.byPath[pathKey] = problem;
|
|
136
|
-
this.push(problem);
|
|
137
|
-
}
|
|
138
|
-
this.count++;
|
|
139
|
-
}
|
|
140
|
-
get summary() {
|
|
141
|
-
return `${this}`;
|
|
142
|
-
}
|
|
143
|
-
toString() {
|
|
144
|
-
return this.join("\n");
|
|
145
|
-
}
|
|
146
|
-
throw() {
|
|
147
|
-
throw new ArkTypeError(this);
|
|
148
|
-
}
|
|
149
|
-
constructor(state){
|
|
150
|
-
super();
|
|
151
|
-
_defineProperty(this, "byPath", {});
|
|
152
|
-
_defineProperty(this, "count", 0);
|
|
153
|
-
_classPrivateFieldInit(this, _state, {
|
|
154
|
-
writable: true,
|
|
155
|
-
value: void 0
|
|
156
|
-
});
|
|
157
|
-
_classPrivateFieldSet(this, _state, state);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
export const Problems = ProblemArray;
|
|
161
|
-
const capitalize = (s)=>s[0].toUpperCase() + s.slice(1);
|
|
162
|
-
export const domainsToDescriptions = (domains)=>domains.map((objectKind)=>domainDescriptions[objectKind]);
|
|
163
|
-
export const objectKindsToDescriptions = (kinds)=>kinds.map((objectKind)=>objectKindDescriptions[objectKind]);
|
|
164
|
-
export const describeBranches = (descriptions)=>{
|
|
165
|
-
if (descriptions.length === 0) {
|
|
166
|
-
return "never";
|
|
167
|
-
}
|
|
168
|
-
if (descriptions.length === 1) {
|
|
169
|
-
return descriptions[0];
|
|
170
|
-
}
|
|
171
|
-
let description = "";
|
|
172
|
-
for(let i = 0; i < descriptions.length - 1; i++){
|
|
173
|
-
description += descriptions[i];
|
|
174
|
-
if (i < descriptions.length - 2) {
|
|
175
|
-
description += ", ";
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
description += ` or ${descriptions[descriptions.length - 1]}`;
|
|
179
|
-
return description;
|
|
180
|
-
};
|
|
181
|
-
const writeDefaultReason = (mustBe, was)=>`must be ${mustBe}${was && ` (was ${was})`}`;
|
|
182
|
-
const addDefaultContext = (reason, path)=>path.length === 0 ? capitalize(reason) : path.length === 1 && isWellFormedInteger(path[0]) ? `Item at index ${path[0]} ${reason}` : `${path} ${reason}`;
|
|
183
|
-
const defaultProblemConfig = {
|
|
184
|
-
divisor: {
|
|
185
|
-
mustBe: (divisor)=>divisor === 1 ? `an integer` : `a multiple of ${divisor}`
|
|
186
|
-
},
|
|
187
|
-
class: {
|
|
188
|
-
mustBe: (expected)=>{
|
|
189
|
-
const possibleObjectKind = getExactConstructorObjectKind(expected);
|
|
190
|
-
return possibleObjectKind ? objectKindDescriptions[possibleObjectKind] : `an instance of ${expected.name}`;
|
|
191
|
-
},
|
|
192
|
-
writeReason: (mustBe, data)=>writeDefaultReason(mustBe, data.className)
|
|
193
|
-
},
|
|
194
|
-
domain: {
|
|
195
|
-
mustBe: (domain)=>domainDescriptions[domain],
|
|
196
|
-
writeReason: (mustBe, data)=>writeDefaultReason(mustBe, data.domain)
|
|
197
|
-
},
|
|
198
|
-
missing: {
|
|
199
|
-
mustBe: ()=>"defined",
|
|
200
|
-
writeReason: (mustBe)=>writeDefaultReason(mustBe, "")
|
|
201
|
-
},
|
|
202
|
-
extraneous: {
|
|
203
|
-
mustBe: ()=>"removed",
|
|
204
|
-
writeReason: (mustBe)=>writeDefaultReason(mustBe, "")
|
|
205
|
-
},
|
|
206
|
-
bound: {
|
|
207
|
-
mustBe: (bound)=>`${Scanner.comparatorDescriptions[bound.comparator]} ${bound.limit}${bound.units ? ` ${bound.units}` : ""}`,
|
|
208
|
-
writeReason: (mustBe, data)=>writeDefaultReason(mustBe, `${data.size}`)
|
|
209
|
-
},
|
|
210
|
-
regex: {
|
|
211
|
-
mustBe: (expression)=>`a string matching ${expression}`
|
|
212
|
-
},
|
|
213
|
-
value: {
|
|
214
|
-
mustBe: stringify
|
|
215
|
-
},
|
|
216
|
-
branches: {
|
|
217
|
-
mustBe: (branchProblems)=>describeBranches(branchProblems.map((problem)=>`${problem.path} must be ${problem.parts ? describeBranches(problem.parts.map((part)=>part.mustBe)) : problem.mustBe}`)),
|
|
218
|
-
writeReason: (mustBe, data)=>`${mustBe} (was ${data})`,
|
|
219
|
-
addContext: (reason, path)=>path.length ? `At ${path}, ${reason}` : reason
|
|
220
|
-
},
|
|
221
|
-
multi: {
|
|
222
|
-
mustBe: (problems)=>"• " + problems.map((_)=>_.mustBe).join("\n• "),
|
|
223
|
-
writeReason: (mustBe, data)=>`${data} must be...\n${mustBe}`,
|
|
224
|
-
addContext: (reason, path)=>path.length ? `At ${path}, ${reason}` : reason
|
|
225
|
-
},
|
|
226
|
-
custom: {
|
|
227
|
-
mustBe: (mustBe)=>mustBe
|
|
228
|
-
},
|
|
229
|
-
cases: {
|
|
230
|
-
mustBe: (cases)=>describeBranches(cases)
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
export const problemCodes = objectKeysOf(defaultProblemConfig);
|
|
234
|
-
const compileDefaultProblemWriters = ()=>{
|
|
235
|
-
const result = {};
|
|
236
|
-
let code;
|
|
237
|
-
for (code of problemCodes){
|
|
238
|
-
result[code] = {
|
|
239
|
-
mustBe: defaultProblemConfig[code].mustBe,
|
|
240
|
-
writeReason: defaultProblemConfig[code].writeReason ?? writeDefaultReason,
|
|
241
|
-
addContext: defaultProblemConfig[code].addContext ?? addDefaultContext
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
return result;
|
|
245
|
-
};
|
|
246
|
-
export const defaultProblemWriters = compileDefaultProblemWriters();
|
|
247
|
-
export const compileProblemWriters = (input)=>{
|
|
248
|
-
if (!input) {
|
|
249
|
-
return defaultProblemWriters;
|
|
250
|
-
}
|
|
251
|
-
const result = {};
|
|
252
|
-
for (const code of problemCodes){
|
|
253
|
-
result[code] = {
|
|
254
|
-
mustBe: input[code]?.mustBe ?? defaultProblemConfig[code].mustBe,
|
|
255
|
-
writeReason: input[code]?.writeReason ?? defaultProblemConfig[code].writeReason ?? input.writeReason ?? writeDefaultReason,
|
|
256
|
-
addContext: input[code]?.addContext ?? defaultProblemConfig[code].addContext ?? input.addContext ?? addDefaultContext
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
return result;
|
|
260
|
-
};
|