arktype 1.0.16-alpha → 1.0.18-alpha
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 +3 -3
- package/dist/cjs/main.js +38 -0
- package/dist/cjs/nodes/branch.js +140 -0
- package/dist/cjs/nodes/compose.js +157 -0
- package/dist/{nodes → cjs/nodes}/discriminate.js +92 -100
- package/dist/cjs/nodes/node.js +139 -0
- package/dist/cjs/nodes/predicate.js +86 -0
- package/dist/cjs/nodes/rules/class.js +25 -0
- package/dist/cjs/nodes/rules/collapsibleSet.js +48 -0
- package/dist/cjs/nodes/rules/divisor.js +29 -0
- package/dist/cjs/nodes/rules/props.js +160 -0
- package/dist/cjs/nodes/rules/range.js +105 -0
- package/dist/cjs/nodes/rules/regex.js +26 -0
- package/dist/cjs/nodes/rules/rules.js +123 -0
- package/dist/cjs/parse/ast/ast.js +4 -0
- package/dist/cjs/parse/ast/bound.js +16 -0
- package/dist/cjs/parse/ast/config.js +13 -0
- package/dist/cjs/parse/ast/distributableFunction.js +48 -0
- package/dist/cjs/parse/ast/divisor.js +9 -0
- package/dist/cjs/parse/ast/intersection.js +30 -0
- package/dist/cjs/parse/ast/keyof.js +111 -0
- package/dist/cjs/parse/ast/morph.js +58 -0
- package/dist/cjs/parse/ast/narrow.js +22 -0
- package/dist/cjs/parse/ast/node.js +4 -0
- package/dist/cjs/parse/ast/tuple.js +94 -0
- package/dist/cjs/parse/ast/union.js +9 -0
- package/dist/cjs/parse/ast/utils.js +4 -0
- package/dist/cjs/parse/definition.js +61 -0
- package/dist/cjs/parse/record.js +37 -0
- package/dist/cjs/parse/string/reduce/dynamic.js +167 -0
- package/dist/cjs/parse/string/reduce/shared.js +23 -0
- package/dist/cjs/parse/string/reduce/static.js +4 -0
- package/dist/cjs/parse/string/shift/operand/enclosed.js +54 -0
- package/dist/cjs/parse/string/shift/operand/operand.js +11 -0
- package/dist/cjs/parse/string/shift/operand/unenclosed.js +53 -0
- package/dist/cjs/parse/string/shift/operator/bounds.js +87 -0
- package/dist/cjs/parse/string/shift/operator/divisor.js +35 -0
- package/dist/cjs/parse/string/shift/operator/operator.js +26 -0
- package/dist/cjs/parse/string/shift/scanner.js +114 -0
- package/dist/cjs/parse/string/string.js +43 -0
- package/dist/cjs/scopes/ark.js +45 -0
- package/dist/cjs/scopes/cache.js +52 -0
- package/dist/cjs/scopes/expressions.js +29 -0
- package/dist/cjs/scopes/jsObjects.js +93 -0
- package/dist/cjs/scopes/scope.js +323 -0
- package/dist/cjs/scopes/tsKeywords.js +113 -0
- package/dist/cjs/scopes/type.js +50 -0
- package/dist/cjs/scopes/validation/creditCard.js +47 -0
- package/dist/cjs/scopes/validation/date.js +62 -0
- package/dist/cjs/scopes/validation/validation.js +108 -0
- package/dist/cjs/traverse/problems.js +281 -0
- package/dist/cjs/traverse/traverse.js +390 -0
- package/dist/cjs/utils/chainableNoOpProxy.js +23 -0
- package/dist/cjs/utils/data.js +53 -0
- package/dist/cjs/utils/domains.js +30 -0
- package/dist/cjs/utils/errors.js +26 -0
- package/dist/cjs/utils/freeze.js +15 -0
- package/dist/cjs/utils/generics.js +63 -0
- package/dist/cjs/utils/numericLiterals.js +75 -0
- package/dist/cjs/utils/objectKinds.js +69 -0
- package/dist/cjs/utils/paths.js +32 -0
- package/dist/cjs/utils/serialize.js +74 -0
- package/dist/cjs/utils/unionToTuple.js +4 -0
- package/dist/mjs/main.js +8 -0
- package/dist/mjs/nodes/branch.js +123 -0
- package/dist/mjs/nodes/compose.js +135 -0
- package/dist/mjs/nodes/discriminate.js +247 -0
- package/dist/mjs/nodes/node.js +117 -0
- package/dist/mjs/nodes/predicate.js +69 -0
- package/dist/mjs/nodes/rules/class.js +11 -0
- package/dist/mjs/nodes/rules/collapsibleSet.js +34 -0
- package/dist/mjs/nodes/rules/divisor.js +15 -0
- package/dist/mjs/nodes/rules/props.js +142 -0
- package/dist/mjs/nodes/rules/range.js +86 -0
- package/dist/mjs/nodes/rules/regex.js +11 -0
- package/dist/mjs/nodes/rules/rules.js +106 -0
- package/dist/mjs/package.json +3 -0
- package/dist/mjs/parse/ast/ast.js +1 -0
- package/dist/mjs/parse/ast/bound.js +2 -0
- package/dist/mjs/parse/ast/config.js +9 -0
- package/dist/mjs/parse/ast/distributableFunction.js +34 -0
- package/dist/mjs/parse/ast/divisor.js +1 -0
- package/dist/mjs/parse/ast/intersection.js +16 -0
- package/dist/mjs/parse/ast/keyof.js +103 -0
- package/dist/mjs/parse/ast/morph.js +44 -0
- package/dist/mjs/parse/ast/narrow.js +14 -0
- package/dist/mjs/parse/ast/node.js +1 -0
- package/dist/mjs/parse/ast/tuple.js +80 -0
- package/dist/mjs/parse/ast/union.js +1 -0
- package/dist/mjs/parse/ast/utils.js +1 -0
- package/dist/mjs/parse/definition.js +46 -0
- package/dist/mjs/parse/record.js +29 -0
- package/dist/mjs/parse/string/reduce/dynamic.js +159 -0
- package/dist/mjs/parse/string/reduce/shared.js +6 -0
- package/dist/mjs/parse/string/reduce/static.js +1 -0
- package/dist/mjs/parse/string/shift/operand/enclosed.js +39 -0
- package/dist/mjs/parse/string/shift/operand/operand.js +3 -0
- package/dist/mjs/parse/string/shift/operand/unenclosed.js +36 -0
- package/dist/mjs/parse/string/shift/operator/bounds.js +70 -0
- package/dist/mjs/parse/string/shift/operator/divisor.js +21 -0
- package/dist/mjs/parse/string/shift/operator/operator.js +13 -0
- package/dist/mjs/parse/string/shift/scanner.js +106 -0
- package/dist/mjs/parse/string/string.js +28 -0
- package/dist/mjs/scopes/ark.js +28 -0
- package/dist/mjs/scopes/cache.js +38 -0
- package/dist/{scopes → mjs/scopes}/expressions.js +9 -20
- package/dist/mjs/scopes/jsObjects.js +82 -0
- package/dist/mjs/scopes/scope.js +303 -0
- package/dist/mjs/scopes/tsKeywords.js +116 -0
- package/dist/mjs/scopes/type.js +35 -0
- package/dist/{scopes → mjs/scopes}/validation/creditCard.js +11 -15
- package/dist/{scopes → mjs/scopes}/validation/date.js +16 -21
- package/dist/mjs/scopes/validation/validation.js +112 -0
- package/dist/mjs/traverse/problems.js +260 -0
- package/dist/mjs/traverse/traverse.js +373 -0
- package/dist/{utils → mjs/utils}/chainableNoOpProxy.js +2 -6
- package/dist/mjs/utils/data.js +38 -0
- package/dist/mjs/utils/domains.js +15 -0
- package/dist/mjs/utils/errors.js +10 -0
- package/dist/mjs/utils/freeze.js +7 -0
- package/dist/mjs/utils/generics.js +38 -0
- package/dist/mjs/utils/numericLiterals.js +72 -0
- package/dist/mjs/utils/objectKinds.js +55 -0
- package/dist/{utils → mjs/utils}/paths.js +3 -8
- package/dist/mjs/utils/serialize.js +58 -0
- package/dist/mjs/utils/unionToTuple.js +1 -0
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/package.json +14 -6
- package/dist/main.js +0 -29
- package/dist/nodes/branch.js +0 -135
- package/dist/nodes/compose.js +0 -99
- package/dist/nodes/node.js +0 -134
- package/dist/nodes/predicate.js +0 -88
- package/dist/nodes/rules/class.js +0 -23
- package/dist/nodes/rules/collapsibleSet.js +0 -34
- package/dist/nodes/rules/divisor.js +0 -19
- package/dist/nodes/rules/props.js +0 -130
- package/dist/nodes/rules/range.js +0 -108
- package/dist/nodes/rules/regex.js +0 -17
- package/dist/nodes/rules/rules.js +0 -102
- package/dist/parse/ast/ast.js +0 -2
- package/dist/parse/ast/bound.js +0 -7
- package/dist/parse/ast/config.js +0 -14
- package/dist/parse/ast/distributableFunction.js +0 -40
- package/dist/parse/ast/divisor.js +0 -5
- package/dist/parse/ast/intersection.js +0 -21
- package/dist/parse/ast/keyof.js +0 -107
- package/dist/parse/ast/morph.js +0 -50
- package/dist/parse/ast/narrow.js +0 -17
- package/dist/parse/ast/node.js +0 -2
- package/dist/parse/ast/tuple.js +0 -72
- package/dist/parse/ast/union.js +0 -5
- package/dist/parse/ast/utils.js +0 -2
- package/dist/parse/definition.js +0 -47
- package/dist/parse/record.js +0 -31
- package/dist/parse/string/reduce/dynamic.js +0 -159
- package/dist/parse/string/reduce/shared.js +0 -13
- package/dist/parse/string/reduce/static.js +0 -2
- package/dist/parse/string/shift/operand/enclosed.js +0 -37
- package/dist/parse/string/shift/operand/operand.js +0 -15
- package/dist/parse/string/shift/operand/unenclosed.js +0 -45
- package/dist/parse/string/shift/operator/bounds.js +0 -83
- package/dist/parse/string/shift/operator/divisor.js +0 -23
- package/dist/parse/string/shift/operator/operator.js +0 -34
- package/dist/parse/string/shift/scanner.js +0 -97
- package/dist/parse/string/string.js +0 -35
- package/dist/scopes/ark.js +0 -27
- package/dist/scopes/cache.js +0 -28
- package/dist/scopes/jsObjects.js +0 -20
- package/dist/scopes/scope.js +0 -184
- package/dist/scopes/tsKeywords.js +0 -49
- package/dist/scopes/type.js +0 -40
- package/dist/scopes/validation/validation.js +0 -74
- package/dist/traverse/problems.js +0 -234
- package/dist/traverse/traverse.js +0 -330
- package/dist/utils/data.js +0 -39
- package/dist/utils/domains.js +0 -27
- package/dist/utils/errors.js +0 -17
- package/dist/utils/freeze.js +0 -16
- package/dist/utils/generics.js +0 -53
- package/dist/utils/numericLiterals.js +0 -88
- package/dist/utils/objectKinds.js +0 -69
- package/dist/utils/serialize.js +0 -71
- package/dist/utils/unionToTuple.js +0 -2
- /package/dist/{package.json → cjs/package.json} +0 -0
- /package/dist/{main.d.ts → types/main.d.ts} +0 -0
- /package/dist/{nodes → types/nodes}/branch.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/compose.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/discriminate.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/node.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/predicate.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/rules/class.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/rules/collapsibleSet.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/rules/divisor.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/rules/props.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/rules/range.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/rules/regex.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/rules/rules.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/ast.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/bound.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/config.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/distributableFunction.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/divisor.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/intersection.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/keyof.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/morph.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/narrow.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/node.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/tuple.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/union.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/utils.d.ts +0 -0
- /package/dist/{parse → types/parse}/definition.d.ts +0 -0
- /package/dist/{parse → types/parse}/record.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/reduce/dynamic.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/reduce/shared.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/reduce/static.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/shift/operand/enclosed.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/shift/operand/operand.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/shift/operand/unenclosed.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/shift/operator/bounds.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/shift/operator/divisor.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/shift/operator/operator.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/shift/scanner.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/string.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/ark.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/cache.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/expressions.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/jsObjects.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/scope.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/tsKeywords.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/type.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/validation/creditCard.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/validation/date.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/validation/validation.d.ts +0 -0
- /package/dist/{traverse → types/traverse}/problems.d.ts +0 -0
- /package/dist/{traverse → types/traverse}/traverse.d.ts +0 -0
- /package/dist/{utils → types/utils}/chainableNoOpProxy.d.ts +0 -0
- /package/dist/{utils → types/utils}/data.d.ts +0 -0
- /package/dist/{utils → types/utils}/domains.d.ts +0 -0
- /package/dist/{utils → types/utils}/errors.d.ts +0 -0
- /package/dist/{utils → types/utils}/freeze.d.ts +0 -0
- /package/dist/{utils → types/utils}/generics.d.ts +0 -0
- /package/dist/{utils → types/utils}/numericLiterals.d.ts +0 -0
- /package/dist/{utils → types/utils}/objectKinds.d.ts +0 -0
- /package/dist/{utils → types/utils}/paths.d.ts +0 -0
- /package/dist/{utils → types/utils}/serialize.d.ts +0 -0
- /package/dist/{utils → types/utils}/unionToTuple.d.ts +0 -0
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkRequiredProp = exports.checkEntries = exports.traverse = exports.TraversalState = exports.traverseRoot = void 0;
|
|
4
|
-
const discriminate_js_1 = require("../nodes/discriminate.js");
|
|
5
|
-
const class_js_1 = require("../nodes/rules/class.js");
|
|
6
|
-
const divisor_js_1 = require("../nodes/rules/divisor.js");
|
|
7
|
-
const range_js_1 = require("../nodes/rules/range.js");
|
|
8
|
-
const regex_js_1 = require("../nodes/rules/regex.js");
|
|
9
|
-
const rules_js_1 = require("../nodes/rules/rules.js");
|
|
10
|
-
const domains_js_1 = require("../utils/domains.js");
|
|
11
|
-
const errors_js_1 = require("../utils/errors.js");
|
|
12
|
-
const generics_js_1 = require("../utils/generics.js");
|
|
13
|
-
const numericLiterals_js_1 = require("../utils/numericLiterals.js");
|
|
14
|
-
const paths_js_1 = require("../utils/paths.js");
|
|
15
|
-
const problems_js_1 = require("./problems.js");
|
|
16
|
-
const initializeTraversalConfig = () => ({
|
|
17
|
-
mustBe: [],
|
|
18
|
-
writeReason: [],
|
|
19
|
-
addContext: [],
|
|
20
|
-
keys: []
|
|
21
|
-
});
|
|
22
|
-
const problemWriterKeys = [
|
|
23
|
-
"mustBe",
|
|
24
|
-
"writeReason",
|
|
25
|
-
"addContext"
|
|
26
|
-
];
|
|
27
|
-
const traverseRoot = (t, data) => {
|
|
28
|
-
const state = new TraversalState(data, t);
|
|
29
|
-
(0, exports.traverse)(t.flat, state);
|
|
30
|
-
const result = new CheckResult(state);
|
|
31
|
-
if (state.problems.count) {
|
|
32
|
-
result.problems = state.problems;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
for (const [o, k] of state.entriesToPrune) {
|
|
36
|
-
delete o[k];
|
|
37
|
-
}
|
|
38
|
-
result.data = state.data;
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
41
|
-
};
|
|
42
|
-
exports.traverseRoot = traverseRoot;
|
|
43
|
-
const CheckResult = class {
|
|
44
|
-
data;
|
|
45
|
-
problems;
|
|
46
|
-
};
|
|
47
|
-
class TraversalState {
|
|
48
|
-
data;
|
|
49
|
-
type;
|
|
50
|
-
path = new paths_js_1.Path();
|
|
51
|
-
problems = new problems_js_1.Problems(this);
|
|
52
|
-
entriesToPrune = [];
|
|
53
|
-
failFast = false;
|
|
54
|
-
traversalConfig = initializeTraversalConfig();
|
|
55
|
-
rootScope;
|
|
56
|
-
#seen = {};
|
|
57
|
-
constructor(data, type) {
|
|
58
|
-
this.data = data;
|
|
59
|
-
this.type = type;
|
|
60
|
-
this.rootScope = type.scope;
|
|
61
|
-
}
|
|
62
|
-
getProblemConfig(code) {
|
|
63
|
-
const result = {};
|
|
64
|
-
for (const k of problemWriterKeys) {
|
|
65
|
-
result[k] =
|
|
66
|
-
this.traversalConfig[k][0] ??
|
|
67
|
-
this.rootScope.config.codes[code][k];
|
|
68
|
-
}
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
traverseConfig(configEntries, node) {
|
|
72
|
-
for (const entry of configEntries) {
|
|
73
|
-
this.traversalConfig[entry[0]].unshift(entry[1]);
|
|
74
|
-
}
|
|
75
|
-
const isValid = (0, exports.traverse)(node, this);
|
|
76
|
-
for (const entry of configEntries) {
|
|
77
|
-
this.traversalConfig[entry[0]].shift();
|
|
78
|
-
}
|
|
79
|
-
return isValid;
|
|
80
|
-
}
|
|
81
|
-
traverseKey(key, node) {
|
|
82
|
-
const lastData = this.data;
|
|
83
|
-
this.data = this.data[key];
|
|
84
|
-
this.path.push(key);
|
|
85
|
-
const isValid = (0, exports.traverse)(node, this);
|
|
86
|
-
this.path.pop();
|
|
87
|
-
if (lastData[key] !== this.data) {
|
|
88
|
-
lastData[key] = this.data;
|
|
89
|
-
}
|
|
90
|
-
this.data = lastData;
|
|
91
|
-
return isValid;
|
|
92
|
-
}
|
|
93
|
-
traverseResolution(name) {
|
|
94
|
-
const resolution = this.type.scope.resolve(name);
|
|
95
|
-
const id = resolution.qualifiedName;
|
|
96
|
-
// this assignment helps with narrowing
|
|
97
|
-
const data = this.data;
|
|
98
|
-
const isObject = (0, domains_js_1.hasDomain)(data, "object");
|
|
99
|
-
if (isObject) {
|
|
100
|
-
const seenByCurrentType = this.#seen[id];
|
|
101
|
-
if (seenByCurrentType) {
|
|
102
|
-
if (seenByCurrentType.includes(data)) {
|
|
103
|
-
// if data has already been checked by this alias as part of
|
|
104
|
-
// a resolution higher up on the call stack, it must be valid
|
|
105
|
-
// or we wouldn't be here
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
seenByCurrentType.push(data);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
this.#seen[id] = [data];
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
const lastType = this.type;
|
|
115
|
-
this.type = resolution;
|
|
116
|
-
const isValid = (0, exports.traverse)(resolution.flat, this);
|
|
117
|
-
this.type = lastType;
|
|
118
|
-
if (isObject) {
|
|
119
|
-
this.#seen[id].pop();
|
|
120
|
-
}
|
|
121
|
-
return isValid;
|
|
122
|
-
}
|
|
123
|
-
traverseBranches(branches) {
|
|
124
|
-
const lastFailFast = this.failFast;
|
|
125
|
-
this.failFast = true;
|
|
126
|
-
const lastProblems = this.problems;
|
|
127
|
-
const branchProblems = new problems_js_1.Problems(this);
|
|
128
|
-
this.problems = branchProblems;
|
|
129
|
-
const lastPath = this.path;
|
|
130
|
-
const lastKeysToPrune = this.entriesToPrune;
|
|
131
|
-
let hasValidBranch = false;
|
|
132
|
-
for (const branch of branches) {
|
|
133
|
-
this.path = new paths_js_1.Path();
|
|
134
|
-
this.entriesToPrune = [];
|
|
135
|
-
if ((0, exports.checkEntries)(branch, this)) {
|
|
136
|
-
hasValidBranch = true;
|
|
137
|
-
lastKeysToPrune.push(...this.entriesToPrune);
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
this.path = lastPath;
|
|
142
|
-
this.entriesToPrune = lastKeysToPrune;
|
|
143
|
-
this.problems = lastProblems;
|
|
144
|
-
this.failFast = lastFailFast;
|
|
145
|
-
return hasValidBranch || !this.problems.add("branches", branchProblems);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
exports.TraversalState = TraversalState;
|
|
149
|
-
const traverse = (node, state) => typeof node === "string"
|
|
150
|
-
? (0, domains_js_1.domainOf)(state.data) === node || !state.problems.add("domain", node)
|
|
151
|
-
: (0, exports.checkEntries)(node, state);
|
|
152
|
-
exports.traverse = traverse;
|
|
153
|
-
const checkEntries = (entries, state) => {
|
|
154
|
-
let isValid = true;
|
|
155
|
-
for (let i = 0; i < entries.length; i++) {
|
|
156
|
-
const [k, v] = entries[i];
|
|
157
|
-
const entryAllowsData = entryCheckers[k](v, state);
|
|
158
|
-
isValid &&= entryAllowsData;
|
|
159
|
-
if (!isValid) {
|
|
160
|
-
if (state.failFast) {
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
if (i < entries.length - 1 &&
|
|
164
|
-
rules_js_1.precedenceMap[k] < rules_js_1.precedenceMap[entries[i + 1][0]]) {
|
|
165
|
-
// if we've encountered a problem, there is at least one entry
|
|
166
|
-
// remaining, and the next entry is of a higher precedence level
|
|
167
|
-
// than the current entry, return immediately
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return isValid;
|
|
173
|
-
};
|
|
174
|
-
exports.checkEntries = checkEntries;
|
|
175
|
-
const checkRequiredProp = (prop, state) => {
|
|
176
|
-
if (prop[0] in state.data) {
|
|
177
|
-
return state.traverseKey(prop[0], prop[1]);
|
|
178
|
-
}
|
|
179
|
-
state.problems.add("missing", undefined, {
|
|
180
|
-
path: state.path.concat(prop[0]),
|
|
181
|
-
data: undefined
|
|
182
|
-
});
|
|
183
|
-
return false;
|
|
184
|
-
};
|
|
185
|
-
exports.checkRequiredProp = checkRequiredProp;
|
|
186
|
-
const createPropChecker = (kind) => (props, state) => {
|
|
187
|
-
let isValid = true;
|
|
188
|
-
const remainingUnseenRequired = { ...props.required };
|
|
189
|
-
for (const k in state.data) {
|
|
190
|
-
if (props.required[k]) {
|
|
191
|
-
isValid = state.traverseKey(k, props.required[k]) && isValid;
|
|
192
|
-
delete remainingUnseenRequired[k];
|
|
193
|
-
}
|
|
194
|
-
else if (props.optional[k]) {
|
|
195
|
-
isValid = state.traverseKey(k, props.optional[k]) && isValid;
|
|
196
|
-
}
|
|
197
|
-
else if (props.index && numericLiterals_js_1.wellFormedIntegerMatcher.test(k)) {
|
|
198
|
-
isValid = state.traverseKey(k, props.index) && isValid;
|
|
199
|
-
}
|
|
200
|
-
else if (kind === "distilledProps") {
|
|
201
|
-
if (state.failFast) {
|
|
202
|
-
// If we're in a union (i.e. failFast is enabled) in
|
|
203
|
-
// distilled mode, we need to wait to prune distilled keys
|
|
204
|
-
// to avoid mutating data based on a branch that will not be
|
|
205
|
-
// included in the final result. Instead, we push the object
|
|
206
|
-
// and key to state to handle after traversal is complete.
|
|
207
|
-
state.entriesToPrune.push([state.data, k]);
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
// If we're not in a union, we can safely distill right away
|
|
211
|
-
delete state.data[k];
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
isValid = false;
|
|
216
|
-
state.problems.add("extraneous", state.data[k], {
|
|
217
|
-
path: state.path.concat(k)
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
if (!isValid && state.failFast) {
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
const unseenRequired = Object.keys(remainingUnseenRequired);
|
|
225
|
-
if (unseenRequired.length) {
|
|
226
|
-
for (const k of unseenRequired) {
|
|
227
|
-
state.problems.add("missing", undefined, {
|
|
228
|
-
path: state.path.concat(k)
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
return isValid;
|
|
234
|
-
};
|
|
235
|
-
const entryCheckers = {
|
|
236
|
-
regex: regex_js_1.checkRegex,
|
|
237
|
-
divisor: divisor_js_1.checkDivisor,
|
|
238
|
-
domains: (domains, state) => {
|
|
239
|
-
const entries = domains[(0, domains_js_1.domainOf)(state.data)];
|
|
240
|
-
return entries
|
|
241
|
-
? (0, exports.checkEntries)(entries, state)
|
|
242
|
-
: !state.problems.add("cases", (0, problems_js_1.domainsToDescriptions)((0, generics_js_1.objectKeysOf)(domains)));
|
|
243
|
-
},
|
|
244
|
-
domain: (domain, state) => (0, domains_js_1.domainOf)(state.data) === domain ||
|
|
245
|
-
!state.problems.add("domain", domain),
|
|
246
|
-
bound: range_js_1.checkBound,
|
|
247
|
-
optionalProp: (prop, state) => {
|
|
248
|
-
if (prop[0] in state.data) {
|
|
249
|
-
return state.traverseKey(prop[0], prop[1]);
|
|
250
|
-
}
|
|
251
|
-
return true;
|
|
252
|
-
},
|
|
253
|
-
// these checks work the same way, the keys are only distinct so that
|
|
254
|
-
// prerequisite props can have a higher precedence
|
|
255
|
-
requiredProp: exports.checkRequiredProp,
|
|
256
|
-
prerequisiteProp: exports.checkRequiredProp,
|
|
257
|
-
indexProp: (node, state) => {
|
|
258
|
-
if (!Array.isArray(state.data)) {
|
|
259
|
-
state.problems.add("class", Array);
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
let isValid = true;
|
|
263
|
-
for (let i = 0; i < state.data.length; i++) {
|
|
264
|
-
isValid = state.traverseKey(`${i}`, node) && isValid;
|
|
265
|
-
if (!isValid && state.failFast) {
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return isValid;
|
|
270
|
-
},
|
|
271
|
-
branches: (branches, state) => state.traverseBranches(branches),
|
|
272
|
-
switch: (rule, state) => {
|
|
273
|
-
const dataAtPath = (0, paths_js_1.getPath)(state.data, rule.path);
|
|
274
|
-
const caseKey = (0, discriminate_js_1.serializeCase)(rule.kind, dataAtPath);
|
|
275
|
-
if ((0, generics_js_1.hasKey)(rule.cases, caseKey)) {
|
|
276
|
-
return (0, exports.checkEntries)(rule.cases[caseKey], state);
|
|
277
|
-
}
|
|
278
|
-
const caseKeys = (0, generics_js_1.objectKeysOf)(rule.cases);
|
|
279
|
-
const missingCasePath = state.path.concat(rule.path);
|
|
280
|
-
const caseDescriptions = rule.kind === "value"
|
|
281
|
-
? caseKeys
|
|
282
|
-
: rule.kind === "domain"
|
|
283
|
-
? (0, problems_js_1.domainsToDescriptions)(caseKeys)
|
|
284
|
-
: rule.kind === "class"
|
|
285
|
-
? (0, problems_js_1.objectKindsToDescriptions)(caseKeys)
|
|
286
|
-
: (0, errors_js_1.throwInternalError)(`Unexpectedly encountered rule kind '${rule.kind}' during traversal`);
|
|
287
|
-
state.problems.add("cases", caseDescriptions, {
|
|
288
|
-
path: missingCasePath,
|
|
289
|
-
data: dataAtPath
|
|
290
|
-
});
|
|
291
|
-
return false;
|
|
292
|
-
},
|
|
293
|
-
alias: (name, state) => state.traverseResolution(name),
|
|
294
|
-
class: class_js_1.checkClass,
|
|
295
|
-
narrow: (narrow, state) => {
|
|
296
|
-
const lastProblemsCount = state.problems.count;
|
|
297
|
-
const result = narrow(state.data, state.problems);
|
|
298
|
-
if (!result && state.problems.count === lastProblemsCount) {
|
|
299
|
-
state.problems.mustBe(narrow.name ? `valid according to ${narrow.name}` : "valid");
|
|
300
|
-
}
|
|
301
|
-
return result;
|
|
302
|
-
},
|
|
303
|
-
config: ({ config, node }, state) => state.traverseConfig(config, node),
|
|
304
|
-
value: (value, state) => state.data === value || !state.problems.add("value", value),
|
|
305
|
-
morph: (morph, state) => {
|
|
306
|
-
const out = morph(state.data, state.problems);
|
|
307
|
-
if (state.problems.length) {
|
|
308
|
-
return false;
|
|
309
|
-
}
|
|
310
|
-
if (out instanceof problems_js_1.Problem) {
|
|
311
|
-
// if a problem was returned from the morph but not added, add it
|
|
312
|
-
state.problems.addProblem(out);
|
|
313
|
-
return false;
|
|
314
|
-
}
|
|
315
|
-
if (out instanceof CheckResult) {
|
|
316
|
-
if (out.problems) {
|
|
317
|
-
for (const problem of out.problems) {
|
|
318
|
-
state.problems.addProblem(problem);
|
|
319
|
-
}
|
|
320
|
-
return false;
|
|
321
|
-
}
|
|
322
|
-
state.data = out.data;
|
|
323
|
-
return true;
|
|
324
|
-
}
|
|
325
|
-
state.data = out;
|
|
326
|
-
return true;
|
|
327
|
-
},
|
|
328
|
-
distilledProps: createPropChecker("distilledProps"),
|
|
329
|
-
strictProps: createPropChecker("strictProps")
|
|
330
|
-
};
|
package/dist/utils/data.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataWrapper = exports.unitsOf = exports.sizeOf = void 0;
|
|
4
|
-
const domains_js_1 = require("./domains.js");
|
|
5
|
-
const serialize_js_1 = require("./serialize.js");
|
|
6
|
-
const sizeOf = (data) => typeof data === "string" || Array.isArray(data)
|
|
7
|
-
? data.length
|
|
8
|
-
: typeof data === "number"
|
|
9
|
-
? data
|
|
10
|
-
: 0;
|
|
11
|
-
exports.sizeOf = sizeOf;
|
|
12
|
-
const unitsOf = (data) => typeof data === "string"
|
|
13
|
-
? "characters"
|
|
14
|
-
: Array.isArray(data)
|
|
15
|
-
? "items long"
|
|
16
|
-
: "";
|
|
17
|
-
exports.unitsOf = unitsOf;
|
|
18
|
-
class DataWrapper {
|
|
19
|
-
value;
|
|
20
|
-
constructor(value) {
|
|
21
|
-
this.value = value;
|
|
22
|
-
}
|
|
23
|
-
toString() {
|
|
24
|
-
return (0, serialize_js_1.stringify)(this.value);
|
|
25
|
-
}
|
|
26
|
-
get domain() {
|
|
27
|
-
return (0, domains_js_1.domainOf)(this.value);
|
|
28
|
-
}
|
|
29
|
-
get size() {
|
|
30
|
-
return (0, exports.sizeOf)(this.value);
|
|
31
|
-
}
|
|
32
|
-
get units() {
|
|
33
|
-
return (0, exports.unitsOf)(this.value);
|
|
34
|
-
}
|
|
35
|
-
get className() {
|
|
36
|
-
return Object(this.value).constructor.name;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.DataWrapper = DataWrapper;
|
package/dist/utils/domains.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.domainDescriptions = exports.domainOf = exports.hasDomain = void 0;
|
|
4
|
-
const hasDomain = (data, domain) => (0, exports.domainOf)(data) === domain;
|
|
5
|
-
exports.hasDomain = hasDomain;
|
|
6
|
-
const domainOf = (data) => {
|
|
7
|
-
const builtinType = typeof data;
|
|
8
|
-
return (builtinType === "object"
|
|
9
|
-
? data === null
|
|
10
|
-
? "null"
|
|
11
|
-
: "object"
|
|
12
|
-
: builtinType === "function"
|
|
13
|
-
? "object"
|
|
14
|
-
: builtinType);
|
|
15
|
-
};
|
|
16
|
-
exports.domainOf = domainOf;
|
|
17
|
-
/** Each domain's completion for the phrase "Must be _____" */
|
|
18
|
-
exports.domainDescriptions = {
|
|
19
|
-
bigint: "a bigint",
|
|
20
|
-
boolean: "boolean",
|
|
21
|
-
null: "null",
|
|
22
|
-
number: "a number",
|
|
23
|
-
object: "an object",
|
|
24
|
-
string: "a string",
|
|
25
|
-
symbol: "a symbol",
|
|
26
|
-
undefined: "undefined"
|
|
27
|
-
};
|
package/dist/utils/errors.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwParseError = exports.ParseError = exports.throwInternalError = exports.InternalArktypeError = void 0;
|
|
4
|
-
class InternalArktypeError extends Error {
|
|
5
|
-
}
|
|
6
|
-
exports.InternalArktypeError = InternalArktypeError;
|
|
7
|
-
const throwInternalError = (message) => {
|
|
8
|
-
throw new InternalArktypeError(message);
|
|
9
|
-
};
|
|
10
|
-
exports.throwInternalError = throwInternalError;
|
|
11
|
-
class ParseError extends Error {
|
|
12
|
-
}
|
|
13
|
-
exports.ParseError = ParseError;
|
|
14
|
-
const throwParseError = (message) => {
|
|
15
|
-
throw new ParseError(message);
|
|
16
|
-
};
|
|
17
|
-
exports.throwParseError = throwParseError;
|
package/dist/utils/freeze.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deepFreeze = void 0;
|
|
4
|
-
const deepFreeze = (value) => (Object.isFrozen(value)
|
|
5
|
-
? value
|
|
6
|
-
: Array.isArray(value)
|
|
7
|
-
? Object.freeze(value.map(exports.deepFreeze))
|
|
8
|
-
: // Object.isFrozen will always be true for non-objects, so we can safely cast to Dictionary
|
|
9
|
-
deepFreezeDictionary(value));
|
|
10
|
-
exports.deepFreeze = deepFreeze;
|
|
11
|
-
const deepFreezeDictionary = (value) => {
|
|
12
|
-
for (const k in value) {
|
|
13
|
-
(0, exports.deepFreeze)(value[k]);
|
|
14
|
-
}
|
|
15
|
-
return value;
|
|
16
|
-
};
|
package/dist/utils/generics.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.listFrom = exports.hasNominalId = exports.getNominalId = exports.nominal = exports.hasKeys = exports.keyCount = exports.hasSingleKey = exports.hasKey = exports.prototypeKeysOf = exports.objectKeysOf = exports.entriesOf = exports.isKeyOf = exports.asConst = void 0;
|
|
4
|
-
const domains_js_1 = require("./domains.js");
|
|
5
|
-
const asConst = (t) => t;
|
|
6
|
-
exports.asConst = asConst;
|
|
7
|
-
const isKeyOf = (k, obj) => k in obj;
|
|
8
|
-
exports.isKeyOf = isKeyOf;
|
|
9
|
-
const entriesOf = (o) => Object.entries(o);
|
|
10
|
-
exports.entriesOf = entriesOf;
|
|
11
|
-
const objectKeysOf = (o) => Object.keys(o);
|
|
12
|
-
exports.objectKeysOf = objectKeysOf;
|
|
13
|
-
/** Mimics output of TS's keyof operator at runtime */
|
|
14
|
-
const prototypeKeysOf = (value) => {
|
|
15
|
-
const result = [];
|
|
16
|
-
while (value !== Object.prototype &&
|
|
17
|
-
value !== null &&
|
|
18
|
-
value !== undefined) {
|
|
19
|
-
for (const k of Object.getOwnPropertyNames(value)) {
|
|
20
|
-
if (!result.includes(k)) {
|
|
21
|
-
result.push(k);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
for (const symbol of Object.getOwnPropertySymbols(value)) {
|
|
25
|
-
if (!result.includes(symbol)) {
|
|
26
|
-
result.push(symbol);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
value = Object.getPrototypeOf(value);
|
|
30
|
-
}
|
|
31
|
-
return result;
|
|
32
|
-
};
|
|
33
|
-
exports.prototypeKeysOf = prototypeKeysOf;
|
|
34
|
-
const hasKey = (o, k) => {
|
|
35
|
-
const valueAtKey = o?.[k];
|
|
36
|
-
return valueAtKey !== undefined && valueAtKey !== null;
|
|
37
|
-
};
|
|
38
|
-
exports.hasKey = hasKey;
|
|
39
|
-
const hasSingleKey = (o, k) => k in o && Object.keys(o).length === 1;
|
|
40
|
-
exports.hasSingleKey = hasSingleKey;
|
|
41
|
-
const keyCount = (o) => Object.keys(o).length;
|
|
42
|
-
exports.keyCount = keyCount;
|
|
43
|
-
const hasKeys = (value) => (0, domains_js_1.hasDomain)(value, "object") ? Object.keys(value).length !== 0 : false;
|
|
44
|
-
exports.hasKeys = hasKeys;
|
|
45
|
-
const id = Symbol("id");
|
|
46
|
-
const nominal = (o, name) => Object.assign(o, { [id]: name });
|
|
47
|
-
exports.nominal = nominal;
|
|
48
|
-
const getNominalId = (data) => (0, domains_js_1.hasDomain)(data, "object") && id in data ? data[id] : undefined;
|
|
49
|
-
exports.getNominalId = getNominalId;
|
|
50
|
-
const hasNominalId = (data, name) => (0, exports.getNominalId)(data) === name;
|
|
51
|
-
exports.hasNominalId = hasNominalId;
|
|
52
|
-
const listFrom = (data) => (Array.isArray(data) ? data : [data]);
|
|
53
|
-
exports.listFrom = listFrom;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tryParseWellFormedBigint = exports.tryParseWellFormedInteger = exports.tryParseWellFormedNumber = exports.writeMalformedNumericLiteralMessage = exports.wellFormedNonNegativeIntegerMatcher = exports.isWellFormedInteger = exports.wellFormedIntegerMatcher = exports.wellFormedNumberMatcher = void 0;
|
|
4
|
-
const errors_js_1 = require("./errors.js");
|
|
5
|
-
/**
|
|
6
|
-
* The goal of the number literal and bigint literal regular expressions is to:
|
|
7
|
-
*
|
|
8
|
-
* 1. Ensure definitions form a bijection with the values they represent.
|
|
9
|
-
* 2. Attempt to mirror TypeScript's own format for stringification of numeric
|
|
10
|
-
* values such that the regex should match a given definition if any only if
|
|
11
|
-
* a precise literal type will be inferred (in TS4.8+).
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Matches a well-formatted numeric expression according to the following rules:
|
|
15
|
-
* 1. Must include an integer portion (i.e. '.321' must be written as '0.321')
|
|
16
|
-
* 2. The first digit of the value must not be 0, unless the entire integer portion is 0
|
|
17
|
-
* 3. If the value includes a decimal, its last digit may not be 0
|
|
18
|
-
* 4. The value may not be "-0"
|
|
19
|
-
*/
|
|
20
|
-
exports.wellFormedNumberMatcher = /^(?!^-0$)-?(?:0|[1-9]\d*)(?:\.\d*[1-9])?$/;
|
|
21
|
-
const isWellFormedNumber = (s) => exports.wellFormedNumberMatcher.test(s);
|
|
22
|
-
const numberLikeMatcher = /^-?\d*\.?\d*$/;
|
|
23
|
-
const isNumberLike = (s) => s.length !== 0 && numberLikeMatcher.test(s);
|
|
24
|
-
/**
|
|
25
|
-
* Matches a well-formatted integer according to the following rules:
|
|
26
|
-
* 1. Must begin with an integer, the first digit of which cannot be 0 unless the entire value is 0
|
|
27
|
-
* 2. The value may not be "-0"
|
|
28
|
-
*/
|
|
29
|
-
exports.wellFormedIntegerMatcher = /^(?:0|(?:-?[1-9]\d*))$/;
|
|
30
|
-
const isWellFormedInteger = (s) => exports.wellFormedIntegerMatcher.test(s);
|
|
31
|
-
exports.isWellFormedInteger = isWellFormedInteger;
|
|
32
|
-
exports.wellFormedNonNegativeIntegerMatcher = /^(?:0|(?:[1-9]\d*))$/;
|
|
33
|
-
const integerLikeMatcher = /^-?\d+$/;
|
|
34
|
-
const isIntegerLike = (s) => integerLikeMatcher.test(s);
|
|
35
|
-
const numericLiteralDescriptions = {
|
|
36
|
-
number: "a number",
|
|
37
|
-
bigint: "a bigint",
|
|
38
|
-
integer: "an integer"
|
|
39
|
-
};
|
|
40
|
-
const writeMalformedNumericLiteralMessage = (def, kind) => `'${def}' was parsed as ${numericLiteralDescriptions[kind]} but could not be narrowed to a literal value. Avoid unnecessary leading or trailing zeros and other abnormal notation`;
|
|
41
|
-
exports.writeMalformedNumericLiteralMessage = writeMalformedNumericLiteralMessage;
|
|
42
|
-
const isWellFormed = (def, kind) => kind === "number" ? isWellFormedNumber(def) : (0, exports.isWellFormedInteger)(def);
|
|
43
|
-
const parseKind = (def, kind) => kind === "number" ? Number(def) : Number.parseInt(def);
|
|
44
|
-
const isKindLike = (def, kind) => kind === "number" ? isNumberLike(def) : isIntegerLike(def);
|
|
45
|
-
const tryParseWellFormedNumber = (token, errorOnFail) => parseWellFormed(token, "number", errorOnFail);
|
|
46
|
-
exports.tryParseWellFormedNumber = tryParseWellFormedNumber;
|
|
47
|
-
const tryParseWellFormedInteger = (token, errorOnFail) => parseWellFormed(token, "integer", errorOnFail);
|
|
48
|
-
exports.tryParseWellFormedInteger = tryParseWellFormedInteger;
|
|
49
|
-
const parseWellFormed = (token, kind, errorOnFail) => {
|
|
50
|
-
const value = parseKind(token, kind);
|
|
51
|
-
if (!Number.isNaN(value)) {
|
|
52
|
-
if (isWellFormed(token, kind)) {
|
|
53
|
-
return value;
|
|
54
|
-
}
|
|
55
|
-
if (isKindLike(token, kind)) {
|
|
56
|
-
// If the definition looks like the correct numeric kind but is
|
|
57
|
-
// not well-formed, always throw.
|
|
58
|
-
return (0, errors_js_1.throwParseError)((0, exports.writeMalformedNumericLiteralMessage)(token, kind));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return (errorOnFail
|
|
62
|
-
? (0, errors_js_1.throwParseError)(errorOnFail === true
|
|
63
|
-
? `Failed to parse ${numericLiteralDescriptions[kind]} from '${token}'`
|
|
64
|
-
: errorOnFail)
|
|
65
|
-
: undefined);
|
|
66
|
-
};
|
|
67
|
-
const tryParseWellFormedBigint = (def) => {
|
|
68
|
-
if (def[def.length - 1] !== "n") {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const maybeIntegerLiteral = def.slice(0, -1);
|
|
72
|
-
let value;
|
|
73
|
-
try {
|
|
74
|
-
value = BigInt(maybeIntegerLiteral);
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
if (exports.wellFormedIntegerMatcher.test(maybeIntegerLiteral)) {
|
|
80
|
-
return value;
|
|
81
|
-
}
|
|
82
|
-
if (integerLikeMatcher.test(maybeIntegerLiteral)) {
|
|
83
|
-
// If the definition looks like a bigint but is
|
|
84
|
-
// not well-formed, throw.
|
|
85
|
-
return (0, errors_js_1.throwParseError)((0, exports.writeMalformedNumericLiteralMessage)(def, "bigint"));
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
exports.tryParseWellFormedBigint = tryParseWellFormedBigint;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getExactConstructorObjectKind = exports.objectKindDescriptions = exports.isArray = exports.hasObjectKind = exports.objectKindOf = exports.defaultObjectKinds = void 0;
|
|
4
|
-
const domains_js_1 = require("./domains.js");
|
|
5
|
-
const generics_js_1 = require("./generics.js");
|
|
6
|
-
// Built-in object constructors based on a subset of:
|
|
7
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
|
|
8
|
-
exports.defaultObjectKinds = {
|
|
9
|
-
Array,
|
|
10
|
-
Date,
|
|
11
|
-
Error,
|
|
12
|
-
Function,
|
|
13
|
-
Map,
|
|
14
|
-
RegExp,
|
|
15
|
-
Set,
|
|
16
|
-
Object,
|
|
17
|
-
String,
|
|
18
|
-
Number,
|
|
19
|
-
Boolean,
|
|
20
|
-
WeakMap,
|
|
21
|
-
WeakSet,
|
|
22
|
-
Promise
|
|
23
|
-
};
|
|
24
|
-
const objectKindOf = (data, kinds) => {
|
|
25
|
-
if ((0, domains_js_1.domainOf)(data) !== "object") {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
const kindSet = kinds ?? exports.defaultObjectKinds;
|
|
29
|
-
let prototype = Object.getPrototypeOf(data);
|
|
30
|
-
while (prototype?.constructor &&
|
|
31
|
-
(!kindSet[prototype.constructor.name] ||
|
|
32
|
-
!(data instanceof kindSet[prototype.constructor.name]))) {
|
|
33
|
-
prototype = Object.getPrototypeOf(prototype);
|
|
34
|
-
}
|
|
35
|
-
return prototype?.constructor?.name;
|
|
36
|
-
};
|
|
37
|
-
exports.objectKindOf = objectKindOf;
|
|
38
|
-
const hasObjectKind = (data, kind, kinds) => (0, exports.objectKindOf)(data, kinds) === kind;
|
|
39
|
-
exports.hasObjectKind = hasObjectKind;
|
|
40
|
-
const isArray = (data) => Array.isArray(data);
|
|
41
|
-
exports.isArray = isArray;
|
|
42
|
-
/** Each defaultObjectKind's completion for the phrase "Must be _____" */
|
|
43
|
-
exports.objectKindDescriptions = {
|
|
44
|
-
Object: "an object",
|
|
45
|
-
Array: "an array",
|
|
46
|
-
Function: "a function",
|
|
47
|
-
Date: "a Date",
|
|
48
|
-
RegExp: "a RegExp",
|
|
49
|
-
Error: "an Error",
|
|
50
|
-
Map: "a Map",
|
|
51
|
-
Set: "a Set",
|
|
52
|
-
String: "a String object",
|
|
53
|
-
Number: "a Number object",
|
|
54
|
-
Boolean: "a Boolean object",
|
|
55
|
-
Promise: "a Promise",
|
|
56
|
-
WeakMap: "a WeakMap",
|
|
57
|
-
WeakSet: "a WeakSet"
|
|
58
|
-
};
|
|
59
|
-
// this will only return an object kind if it's the root constructor
|
|
60
|
-
// example TypeError would return undefined not 'Error'
|
|
61
|
-
const getExactConstructorObjectKind = (constructor) => {
|
|
62
|
-
const constructorName = Object(constructor).name;
|
|
63
|
-
return constructorName &&
|
|
64
|
-
(0, generics_js_1.isKeyOf)(constructorName, exports.defaultObjectKinds) &&
|
|
65
|
-
exports.defaultObjectKinds[constructorName] === constructor
|
|
66
|
-
? constructorName
|
|
67
|
-
: undefined;
|
|
68
|
-
};
|
|
69
|
-
exports.getExactConstructorObjectKind = getExactConstructorObjectKind;
|