arktype 1.0.13-alpha → 1.0.15-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 +68 -11
- package/dist/main.js +29 -0
- package/dist/nodes/branch.js +135 -0
- package/dist/nodes/compose.js +99 -0
- package/dist/{cjs/nodes → nodes}/discriminate.js +100 -92
- package/dist/nodes/node.js +134 -0
- package/dist/nodes/predicate.js +88 -0
- package/dist/nodes/rules/class.js +23 -0
- package/dist/nodes/rules/collapsibleSet.js +34 -0
- package/dist/nodes/rules/divisor.js +19 -0
- package/dist/nodes/rules/props.js +130 -0
- package/dist/nodes/rules/range.js +108 -0
- package/dist/nodes/rules/regex.js +17 -0
- package/dist/nodes/rules/rules.js +102 -0
- package/dist/parse/ast/ast.js +2 -0
- package/dist/{types/parse → parse}/ast/bound.d.ts +4 -1
- package/dist/parse/ast/bound.js +7 -0
- package/dist/parse/ast/config.js +14 -0
- package/dist/parse/ast/distributableFunction.js +40 -0
- package/dist/parse/ast/divisor.js +5 -0
- package/dist/parse/ast/intersection.js +21 -0
- package/dist/parse/ast/keyof.js +107 -0
- package/dist/parse/ast/morph.js +50 -0
- package/dist/parse/ast/narrow.js +17 -0
- package/dist/{types/parse → parse}/ast/node.d.ts +3 -1
- package/dist/parse/ast/node.js +2 -0
- package/dist/parse/ast/tuple.js +72 -0
- package/dist/parse/ast/union.js +5 -0
- package/dist/parse/ast/utils.js +2 -0
- package/dist/parse/definition.js +47 -0
- package/dist/parse/record.js +31 -0
- package/dist/parse/string/reduce/dynamic.js +159 -0
- package/dist/parse/string/reduce/shared.js +13 -0
- package/dist/parse/string/reduce/static.js +2 -0
- package/dist/parse/string/shift/operand/enclosed.js +37 -0
- package/dist/parse/string/shift/operand/operand.js +15 -0
- package/dist/parse/string/shift/operand/unenclosed.js +45 -0
- package/dist/parse/string/shift/operator/bounds.js +83 -0
- package/dist/parse/string/shift/operator/divisor.js +23 -0
- package/dist/parse/string/shift/operator/operator.js +34 -0
- package/dist/parse/string/shift/scanner.js +97 -0
- package/dist/parse/string/string.js +35 -0
- package/dist/scopes/ark.js +27 -0
- package/dist/scopes/cache.js +28 -0
- package/dist/{mjs/scopes → scopes}/expressions.js +20 -9
- package/dist/scopes/jsObjects.js +20 -0
- package/dist/scopes/scope.js +184 -0
- package/dist/scopes/tsKeywords.js +49 -0
- package/dist/scopes/type.js +40 -0
- package/dist/{mjs/scopes → scopes}/validation/creditCard.js +15 -11
- package/dist/{mjs/scopes → scopes}/validation/date.js +21 -16
- package/dist/scopes/validation/validation.js +74 -0
- package/dist/traverse/problems.js +234 -0
- package/dist/traverse/traverse.js +330 -0
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/dist/{mjs/utils → utils}/chainableNoOpProxy.js +6 -2
- package/dist/utils/data.js +39 -0
- package/dist/utils/domains.js +27 -0
- package/dist/utils/errors.js +17 -0
- package/dist/utils/freeze.js +16 -0
- package/dist/utils/generics.js +53 -0
- package/dist/utils/numericLiterals.js +88 -0
- package/dist/utils/objectKinds.js +69 -0
- package/dist/{mjs/utils → utils}/paths.js +8 -3
- package/dist/utils/serialize.js +71 -0
- package/dist/utils/unionToTuple.js +2 -0
- package/package.json +25 -39
- package/dist/cjs/main.js +0 -38
- package/dist/cjs/nodes/branch.js +0 -140
- package/dist/cjs/nodes/compose.js +0 -157
- 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 -160
- 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 -9
- 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 -104
- package/dist/cjs/traverse/problems.js +0 -281
- package/dist/cjs/traverse/traverse.js +0 -387
- 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 -135
- package/dist/mjs/nodes/discriminate.js +0 -247
- 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 -142
- 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 -1
- 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/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 -108
- package/dist/mjs/traverse/problems.js +0 -260
- package/dist/mjs/traverse/traverse.js +0 -370
- 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/serialize.js +0 -58
- package/dist/mjs/utils/unionToTuple.js +0 -1
- /package/dist/{types/main.d.ts → main.d.ts} +0 -0
- /package/dist/{types/nodes → nodes}/branch.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/compose.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/discriminate.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/node.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/predicate.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/class.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/collapsibleSet.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/divisor.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/props.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/range.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/regex.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/rules.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/ast.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/config.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/distributableFunction.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/divisor.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/intersection.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/keyof.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/morph.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/narrow.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/tuple.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/union.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/utils.d.ts +0 -0
- /package/dist/{types/parse → parse}/definition.d.ts +0 -0
- /package/dist/{types/parse → parse}/record.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/reduce/dynamic.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/reduce/shared.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/reduce/static.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operand/enclosed.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operand/operand.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operand/unenclosed.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operator/bounds.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operator/divisor.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operator/operator.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/scanner.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/string.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/ark.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/cache.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/expressions.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/jsObjects.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/scope.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/tsKeywords.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/type.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/validation/creditCard.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/validation/date.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/validation/validation.d.ts +0 -0
- /package/dist/{types/traverse → traverse}/problems.d.ts +0 -0
- /package/dist/{types/traverse → traverse}/traverse.d.ts +0 -0
- /package/dist/{types/utils → utils}/chainableNoOpProxy.d.ts +0 -0
- /package/dist/{types/utils → utils}/data.d.ts +0 -0
- /package/dist/{types/utils → utils}/domains.d.ts +0 -0
- /package/dist/{types/utils → utils}/errors.d.ts +0 -0
- /package/dist/{types/utils → utils}/freeze.d.ts +0 -0
- /package/dist/{types/utils → utils}/generics.d.ts +0 -0
- /package/dist/{types/utils → utils}/numericLiterals.d.ts +0 -0
- /package/dist/{types/utils → utils}/objectKinds.d.ts +0 -0
- /package/dist/{types/utils → utils}/paths.d.ts +0 -0
- /package/dist/{types/utils → utils}/serialize.d.ts +0 -0
- /package/dist/{types/utils → utils}/unionToTuple.d.ts +0 -0
|
@@ -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
|
-
};
|
|
@@ -1,370 +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 { serializeCase } from "../nodes/discriminate.js";
|
|
55
|
-
import { checkClass } from "../nodes/rules/class.js";
|
|
56
|
-
import { checkDivisor } from "../nodes/rules/divisor.js";
|
|
57
|
-
import { checkBound } from "../nodes/rules/range.js";
|
|
58
|
-
import { checkRegex } from "../nodes/rules/regex.js";
|
|
59
|
-
import { precedenceMap } from "../nodes/rules/rules.js";
|
|
60
|
-
import { domainOf, hasDomain } from "../utils/domains.js";
|
|
61
|
-
import { throwInternalError } from "../utils/errors.js";
|
|
62
|
-
import { hasKey, objectKeysOf } from "../utils/generics.js";
|
|
63
|
-
import { getPath, Path } from "../utils/paths.js";
|
|
64
|
-
import { domainsToDescriptions, objectKindsToDescriptions, Problem, Problems } from "./problems.js";
|
|
65
|
-
const initializeTraversalConfig = ()=>({
|
|
66
|
-
mustBe: [],
|
|
67
|
-
writeReason: [],
|
|
68
|
-
addContext: [],
|
|
69
|
-
keys: []
|
|
70
|
-
});
|
|
71
|
-
const problemWriterKeys = [
|
|
72
|
-
"mustBe",
|
|
73
|
-
"writeReason",
|
|
74
|
-
"addContext"
|
|
75
|
-
];
|
|
76
|
-
export const traverseRoot = (t, data)=>{
|
|
77
|
-
const state = new TraversalState(data, t);
|
|
78
|
-
traverse(t.flat, state);
|
|
79
|
-
const result = new CheckResult(state);
|
|
80
|
-
if (state.problems.count) {
|
|
81
|
-
result.problems = state.problems;
|
|
82
|
-
} else {
|
|
83
|
-
for (const [o, k] of state.entriesToPrune){
|
|
84
|
-
delete o[k];
|
|
85
|
-
}
|
|
86
|
-
result.data = state.data;
|
|
87
|
-
}
|
|
88
|
-
return result;
|
|
89
|
-
};
|
|
90
|
-
const CheckResult = class {
|
|
91
|
-
constructor(){
|
|
92
|
-
_defineProperty(this, "data", void 0);
|
|
93
|
-
_defineProperty(this, "problems", void 0);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
var _seen = /*#__PURE__*/ new WeakMap();
|
|
97
|
-
export class TraversalState {
|
|
98
|
-
getProblemConfig(code) {
|
|
99
|
-
const result = {};
|
|
100
|
-
for (const k of problemWriterKeys){
|
|
101
|
-
result[k] = this.traversalConfig[k][0] ?? this.rootScope.config.codes[code][k];
|
|
102
|
-
}
|
|
103
|
-
return result;
|
|
104
|
-
}
|
|
105
|
-
traverseConfig(configEntries, node) {
|
|
106
|
-
for (const entry of configEntries){
|
|
107
|
-
this.traversalConfig[entry[0]].unshift(entry[1]);
|
|
108
|
-
}
|
|
109
|
-
const isValid = traverse(node, this);
|
|
110
|
-
for (const entry of configEntries){
|
|
111
|
-
this.traversalConfig[entry[0]].shift();
|
|
112
|
-
}
|
|
113
|
-
return isValid;
|
|
114
|
-
}
|
|
115
|
-
traverseKey(key, node) {
|
|
116
|
-
const lastData = this.data;
|
|
117
|
-
this.data = this.data[key];
|
|
118
|
-
this.path.push(key);
|
|
119
|
-
const isValid = traverse(node, this);
|
|
120
|
-
this.path.pop();
|
|
121
|
-
if (lastData[key] !== this.data) {
|
|
122
|
-
lastData[key] = this.data;
|
|
123
|
-
}
|
|
124
|
-
this.data = lastData;
|
|
125
|
-
return isValid;
|
|
126
|
-
}
|
|
127
|
-
traverseResolution(name) {
|
|
128
|
-
const resolution = this.type.scope.resolve(name);
|
|
129
|
-
const id = resolution.qualifiedName;
|
|
130
|
-
// this assignment helps with narrowing
|
|
131
|
-
const data = this.data;
|
|
132
|
-
const isObject = hasDomain(data, "object");
|
|
133
|
-
if (isObject) {
|
|
134
|
-
const seenByCurrentType = _classPrivateFieldGet(this, _seen)[id];
|
|
135
|
-
if (seenByCurrentType) {
|
|
136
|
-
if (seenByCurrentType.includes(data)) {
|
|
137
|
-
// if data has already been checked by this alias as part of
|
|
138
|
-
// a resolution higher up on the call stack, it must be valid
|
|
139
|
-
// or we wouldn't be here
|
|
140
|
-
return true;
|
|
141
|
-
}
|
|
142
|
-
seenByCurrentType.push(data);
|
|
143
|
-
} else {
|
|
144
|
-
_classPrivateFieldGet(this, _seen)[id] = [
|
|
145
|
-
data
|
|
146
|
-
];
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
const lastType = this.type;
|
|
150
|
-
this.type = resolution;
|
|
151
|
-
const isValid = traverse(resolution.flat, this);
|
|
152
|
-
this.type = lastType;
|
|
153
|
-
if (isObject) {
|
|
154
|
-
_classPrivateFieldGet(this, _seen)[id].pop();
|
|
155
|
-
}
|
|
156
|
-
return isValid;
|
|
157
|
-
}
|
|
158
|
-
traverseBranches(branches) {
|
|
159
|
-
const lastFailFast = this.failFast;
|
|
160
|
-
this.failFast = true;
|
|
161
|
-
const lastProblems = this.problems;
|
|
162
|
-
const branchProblems = new Problems(this);
|
|
163
|
-
this.problems = branchProblems;
|
|
164
|
-
const lastPath = this.path;
|
|
165
|
-
const lastKeysToPrune = this.entriesToPrune;
|
|
166
|
-
let hasValidBranch = false;
|
|
167
|
-
for (const branch of branches){
|
|
168
|
-
this.path = new Path();
|
|
169
|
-
this.entriesToPrune = [];
|
|
170
|
-
if (checkEntries(branch, this)) {
|
|
171
|
-
hasValidBranch = true;
|
|
172
|
-
lastKeysToPrune.push(...this.entriesToPrune);
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
this.path = lastPath;
|
|
177
|
-
this.entriesToPrune = lastKeysToPrune;
|
|
178
|
-
this.problems = lastProblems;
|
|
179
|
-
this.failFast = lastFailFast;
|
|
180
|
-
return hasValidBranch || !this.problems.add("branches", branchProblems);
|
|
181
|
-
}
|
|
182
|
-
constructor(data, type){
|
|
183
|
-
_defineProperty(this, "data", void 0);
|
|
184
|
-
_defineProperty(this, "type", void 0);
|
|
185
|
-
_defineProperty(this, "path", void 0);
|
|
186
|
-
_defineProperty(this, "problems", void 0);
|
|
187
|
-
_defineProperty(this, "entriesToPrune", void 0);
|
|
188
|
-
_defineProperty(this, "failFast", void 0);
|
|
189
|
-
_defineProperty(this, "traversalConfig", void 0);
|
|
190
|
-
_defineProperty(this, "rootScope", void 0);
|
|
191
|
-
_classPrivateFieldInit(this, _seen, {
|
|
192
|
-
writable: true,
|
|
193
|
-
value: void 0
|
|
194
|
-
});
|
|
195
|
-
this.data = data;
|
|
196
|
-
this.type = type;
|
|
197
|
-
this.path = new Path();
|
|
198
|
-
this.problems = new Problems(this);
|
|
199
|
-
this.entriesToPrune = [];
|
|
200
|
-
this.failFast = false;
|
|
201
|
-
this.traversalConfig = initializeTraversalConfig();
|
|
202
|
-
_classPrivateFieldSet(this, _seen, {});
|
|
203
|
-
this.rootScope = type.scope;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
export const traverse = (node, state)=>typeof node === "string" ? domainOf(state.data) === node || !state.problems.add("domain", node) : checkEntries(node, state);
|
|
207
|
-
export const checkEntries = (entries, state)=>{
|
|
208
|
-
let isValid = true;
|
|
209
|
-
for(let i = 0; i < entries.length; i++){
|
|
210
|
-
const [k, v] = entries[i];
|
|
211
|
-
const entryAllowsData = entryCheckers[k](v, state);
|
|
212
|
-
isValid && (isValid = entryAllowsData);
|
|
213
|
-
if (!isValid) {
|
|
214
|
-
if (state.failFast) {
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
if (i < entries.length - 1 && precedenceMap[k] < precedenceMap[entries[i + 1][0]]) {
|
|
218
|
-
// if we've encountered a problem, there is at least one entry
|
|
219
|
-
// remaining, and the next entry is of a higher precedence level
|
|
220
|
-
// than the current entry, return immediately
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return isValid;
|
|
226
|
-
};
|
|
227
|
-
export const checkRequiredProp = (prop, state)=>{
|
|
228
|
-
if (prop[0] in state.data) {
|
|
229
|
-
return state.traverseKey(prop[0], prop[1]);
|
|
230
|
-
}
|
|
231
|
-
state.problems.add("missing", undefined, {
|
|
232
|
-
path: state.path.concat(prop[0]),
|
|
233
|
-
data: undefined
|
|
234
|
-
});
|
|
235
|
-
return false;
|
|
236
|
-
};
|
|
237
|
-
const createPropChecker = (kind)=>(props, state)=>{
|
|
238
|
-
let isValid = true;
|
|
239
|
-
const remainingUnseenRequired = {
|
|
240
|
-
...props.required
|
|
241
|
-
};
|
|
242
|
-
for(const k in state.data){
|
|
243
|
-
if (props.required[k]) {
|
|
244
|
-
isValid = state.traverseKey(k, props.required[k]) && isValid;
|
|
245
|
-
delete remainingUnseenRequired[k];
|
|
246
|
-
} else if (props.optional[k]) {
|
|
247
|
-
isValid = state.traverseKey(k, props.optional[k]) && isValid;
|
|
248
|
-
} else if (kind === "distilledProps") {
|
|
249
|
-
if (state.failFast) {
|
|
250
|
-
// If we're in a union (i.e. failFast is enabled) in
|
|
251
|
-
// distilled mode, we need to wait to prune distilled keys
|
|
252
|
-
// to avoid mutating data based on a branch that will not be
|
|
253
|
-
// included in the final result. Instead, we push the object
|
|
254
|
-
// and key to state to handle after traversal is complete.
|
|
255
|
-
state.entriesToPrune.push([
|
|
256
|
-
state.data,
|
|
257
|
-
k
|
|
258
|
-
]);
|
|
259
|
-
} else {
|
|
260
|
-
// If we're not in a union, we can safely distill right away
|
|
261
|
-
delete state.data[k];
|
|
262
|
-
}
|
|
263
|
-
} else {
|
|
264
|
-
isValid = false;
|
|
265
|
-
state.problems.add("extraneous", state.data[k], {
|
|
266
|
-
path: state.path.concat(k)
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
if (!isValid && state.failFast) {
|
|
270
|
-
return false;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
const unseenRequired = Object.keys(remainingUnseenRequired);
|
|
274
|
-
if (unseenRequired.length) {
|
|
275
|
-
for (const k of unseenRequired){
|
|
276
|
-
state.problems.add("missing", undefined, {
|
|
277
|
-
path: state.path.concat(k)
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
return false;
|
|
281
|
-
}
|
|
282
|
-
return isValid;
|
|
283
|
-
};
|
|
284
|
-
const entryCheckers = {
|
|
285
|
-
regex: checkRegex,
|
|
286
|
-
divisor: checkDivisor,
|
|
287
|
-
domains: (domains, state)=>{
|
|
288
|
-
const entries = domains[domainOf(state.data)];
|
|
289
|
-
return entries ? checkEntries(entries, state) : !state.problems.add("cases", domainsToDescriptions(objectKeysOf(domains)));
|
|
290
|
-
},
|
|
291
|
-
domain: (domain, state)=>domainOf(state.data) === domain || !state.problems.add("domain", domain),
|
|
292
|
-
bound: checkBound,
|
|
293
|
-
optionalProp: (prop, state)=>{
|
|
294
|
-
if (prop[0] in state.data) {
|
|
295
|
-
return state.traverseKey(prop[0], prop[1]);
|
|
296
|
-
}
|
|
297
|
-
return true;
|
|
298
|
-
},
|
|
299
|
-
// these checks work the same way, the keys are only distinct so that
|
|
300
|
-
// prerequisite props can have a higher precedence
|
|
301
|
-
requiredProp: checkRequiredProp,
|
|
302
|
-
prerequisiteProp: checkRequiredProp,
|
|
303
|
-
indexProp: (node, state)=>{
|
|
304
|
-
if (!Array.isArray(state.data)) {
|
|
305
|
-
state.problems.add("class", Array);
|
|
306
|
-
return false;
|
|
307
|
-
}
|
|
308
|
-
let isValid = true;
|
|
309
|
-
for(let i = 0; i < state.data.length; i++){
|
|
310
|
-
isValid = state.traverseKey(`${i}`, node) && isValid;
|
|
311
|
-
if (!isValid && state.failFast) {
|
|
312
|
-
return false;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return isValid;
|
|
316
|
-
},
|
|
317
|
-
branches: (branches, state)=>state.traverseBranches(branches),
|
|
318
|
-
switch: (rule, state)=>{
|
|
319
|
-
const dataAtPath = getPath(state.data, rule.path);
|
|
320
|
-
const caseKey = serializeCase(rule.kind, dataAtPath);
|
|
321
|
-
if (hasKey(rule.cases, caseKey)) {
|
|
322
|
-
return checkEntries(rule.cases[caseKey], state);
|
|
323
|
-
}
|
|
324
|
-
const caseKeys = objectKeysOf(rule.cases);
|
|
325
|
-
const missingCasePath = state.path.concat(rule.path);
|
|
326
|
-
const caseDescriptions = rule.kind === "value" ? caseKeys : rule.kind === "domain" ? domainsToDescriptions(caseKeys) : rule.kind === "class" ? objectKindsToDescriptions(caseKeys) : throwInternalError(`Unexpectedly encountered rule kind '${rule.kind}' during traversal`);
|
|
327
|
-
state.problems.add("cases", caseDescriptions, {
|
|
328
|
-
path: missingCasePath,
|
|
329
|
-
data: dataAtPath
|
|
330
|
-
});
|
|
331
|
-
return false;
|
|
332
|
-
},
|
|
333
|
-
alias: (name, state)=>state.traverseResolution(name),
|
|
334
|
-
class: checkClass,
|
|
335
|
-
narrow: (narrow, state)=>{
|
|
336
|
-
const lastProblemsCount = state.problems.count;
|
|
337
|
-
const result = narrow(state.data, state.problems);
|
|
338
|
-
if (!result && state.problems.count === lastProblemsCount) {
|
|
339
|
-
state.problems.mustBe(narrow.name ? `valid according to ${narrow.name}` : "valid");
|
|
340
|
-
}
|
|
341
|
-
return result;
|
|
342
|
-
},
|
|
343
|
-
config: ({ config , node }, state)=>state.traverseConfig(config, node),
|
|
344
|
-
value: (value, state)=>state.data === value || !state.problems.add("value", value),
|
|
345
|
-
morph: (morph, state)=>{
|
|
346
|
-
const out = morph(state.data, state.problems);
|
|
347
|
-
if (state.problems.length) {
|
|
348
|
-
return false;
|
|
349
|
-
}
|
|
350
|
-
if (out instanceof Problem) {
|
|
351
|
-
// if a problem was returned from the morph but not added, add it
|
|
352
|
-
state.problems.addProblem(out);
|
|
353
|
-
return false;
|
|
354
|
-
}
|
|
355
|
-
if (out instanceof CheckResult) {
|
|
356
|
-
if (out.problems) {
|
|
357
|
-
for (const problem of out.problems){
|
|
358
|
-
state.problems.addProblem(problem);
|
|
359
|
-
}
|
|
360
|
-
return false;
|
|
361
|
-
}
|
|
362
|
-
state.data = out.data;
|
|
363
|
-
return true;
|
|
364
|
-
}
|
|
365
|
-
state.data = out;
|
|
366
|
-
return true;
|
|
367
|
-
},
|
|
368
|
-
distilledProps: createPropChecker("distilledProps"),
|
|
369
|
-
strictProps: createPropChecker("strictProps")
|
|
370
|
-
};
|
package/dist/mjs/utils/data.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
function _defineProperty(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
import { domainOf } from "./domains.js";
|
|
15
|
-
import { stringify } from "./serialize.js";
|
|
16
|
-
export const sizeOf = (data)=>typeof data === "string" || Array.isArray(data) ? data.length : typeof data === "number" ? data : 0;
|
|
17
|
-
export const unitsOf = (data)=>typeof data === "string" ? "characters" : Array.isArray(data) ? "items long" : "";
|
|
18
|
-
export class DataWrapper {
|
|
19
|
-
toString() {
|
|
20
|
-
return stringify(this.value);
|
|
21
|
-
}
|
|
22
|
-
get domain() {
|
|
23
|
-
return domainOf(this.value);
|
|
24
|
-
}
|
|
25
|
-
get size() {
|
|
26
|
-
return sizeOf(this.value);
|
|
27
|
-
}
|
|
28
|
-
get units() {
|
|
29
|
-
return unitsOf(this.value);
|
|
30
|
-
}
|
|
31
|
-
get className() {
|
|
32
|
-
return Object(this.value).constructor.name;
|
|
33
|
-
}
|
|
34
|
-
constructor(value){
|
|
35
|
-
_defineProperty(this, "value", void 0);
|
|
36
|
-
this.value = value;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export const hasDomain = (data, domain)=>domainOf(data) === domain;
|
|
2
|
-
export const domainOf = (data)=>{
|
|
3
|
-
const builtinType = typeof data;
|
|
4
|
-
return builtinType === "object" ? data === null ? "null" : "object" : builtinType === "function" ? "object" : builtinType;
|
|
5
|
-
};
|
|
6
|
-
/** Each domain's completion for the phrase "Must be _____" */ export const domainDescriptions = {
|
|
7
|
-
bigint: "a bigint",
|
|
8
|
-
boolean: "boolean",
|
|
9
|
-
null: "null",
|
|
10
|
-
number: "a number",
|
|
11
|
-
object: "an object",
|
|
12
|
-
string: "a string",
|
|
13
|
-
symbol: "a symbol",
|
|
14
|
-
undefined: "undefined"
|
|
15
|
-
};
|
package/dist/mjs/utils/errors.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export class InternalArktypeError extends Error {
|
|
2
|
-
}
|
|
3
|
-
export const throwInternalError = (message)=>{
|
|
4
|
-
throw new InternalArktypeError(message);
|
|
5
|
-
};
|
|
6
|
-
export class ParseError extends Error {
|
|
7
|
-
}
|
|
8
|
-
export const throwParseError = (message)=>{
|
|
9
|
-
throw new ParseError(message);
|
|
10
|
-
};
|