arktype 1.0.14-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/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 -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 -104
- 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 -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 -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/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 -373
- 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/bound.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,281 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
ArkTypeError: ()=>ArkTypeError,
|
|
13
|
-
Problem: ()=>Problem,
|
|
14
|
-
Problems: ()=>Problems,
|
|
15
|
-
domainsToDescriptions: ()=>domainsToDescriptions,
|
|
16
|
-
objectKindsToDescriptions: ()=>objectKindsToDescriptions,
|
|
17
|
-
describeBranches: ()=>describeBranches,
|
|
18
|
-
problemCodes: ()=>problemCodes,
|
|
19
|
-
defaultProblemWriters: ()=>defaultProblemWriters,
|
|
20
|
-
compileProblemWriters: ()=>compileProblemWriters
|
|
21
|
-
});
|
|
22
|
-
const _scannerJs = require("../parse/string/shift/scanner.js");
|
|
23
|
-
const _dataJs = require("../utils/data.js");
|
|
24
|
-
const _domainsJs = require("../utils/domains.js");
|
|
25
|
-
const _genericsJs = require("../utils/generics.js");
|
|
26
|
-
const _numericLiteralsJs = require("../utils/numericLiterals.js");
|
|
27
|
-
const _objectKindsJs = require("../utils/objectKinds.js");
|
|
28
|
-
const _pathsJs = require("../utils/paths.js");
|
|
29
|
-
const _serializeJs = require("../utils/serialize.js");
|
|
30
|
-
function _checkPrivateRedeclaration(obj, privateCollection) {
|
|
31
|
-
if (privateCollection.has(obj)) {
|
|
32
|
-
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function _classApplyDescriptorGet(receiver, descriptor) {
|
|
36
|
-
if (descriptor.get) {
|
|
37
|
-
return descriptor.get.call(receiver);
|
|
38
|
-
}
|
|
39
|
-
return descriptor.value;
|
|
40
|
-
}
|
|
41
|
-
function _classApplyDescriptorSet(receiver, descriptor, value) {
|
|
42
|
-
if (descriptor.set) {
|
|
43
|
-
descriptor.set.call(receiver, value);
|
|
44
|
-
} else {
|
|
45
|
-
if (!descriptor.writable) {
|
|
46
|
-
throw new TypeError("attempted to set read only private field");
|
|
47
|
-
}
|
|
48
|
-
descriptor.value = value;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function _classExtractFieldDescriptor(receiver, privateMap, action) {
|
|
52
|
-
if (!privateMap.has(receiver)) {
|
|
53
|
-
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
54
|
-
}
|
|
55
|
-
return privateMap.get(receiver);
|
|
56
|
-
}
|
|
57
|
-
function _classPrivateFieldGet(receiver, privateMap) {
|
|
58
|
-
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
|
|
59
|
-
return _classApplyDescriptorGet(receiver, descriptor);
|
|
60
|
-
}
|
|
61
|
-
function _classPrivateFieldInit(obj, privateMap, value) {
|
|
62
|
-
_checkPrivateRedeclaration(obj, privateMap);
|
|
63
|
-
privateMap.set(obj, value);
|
|
64
|
-
}
|
|
65
|
-
function _classPrivateFieldSet(receiver, privateMap, value) {
|
|
66
|
-
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set");
|
|
67
|
-
_classApplyDescriptorSet(receiver, descriptor, value);
|
|
68
|
-
return value;
|
|
69
|
-
}
|
|
70
|
-
function _defineProperty(obj, key, value) {
|
|
71
|
-
if (key in obj) {
|
|
72
|
-
Object.defineProperty(obj, key, {
|
|
73
|
-
value: value,
|
|
74
|
-
enumerable: true,
|
|
75
|
-
configurable: true,
|
|
76
|
-
writable: true
|
|
77
|
-
});
|
|
78
|
-
} else {
|
|
79
|
-
obj[key] = value;
|
|
80
|
-
}
|
|
81
|
-
return obj;
|
|
82
|
-
}
|
|
83
|
-
class ArkTypeError extends TypeError {
|
|
84
|
-
constructor(problems){
|
|
85
|
-
super(`${problems}`);
|
|
86
|
-
_defineProperty(this, "cause", void 0);
|
|
87
|
-
this.cause = problems;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
class Problem {
|
|
91
|
-
toString() {
|
|
92
|
-
return this.message;
|
|
93
|
-
}
|
|
94
|
-
get message() {
|
|
95
|
-
return this.writers.addContext(this.reason, this.path);
|
|
96
|
-
}
|
|
97
|
-
get reason() {
|
|
98
|
-
return this.writers.writeReason(this.mustBe, new _dataJs.DataWrapper(this.data));
|
|
99
|
-
}
|
|
100
|
-
get mustBe() {
|
|
101
|
-
return typeof this.writers.mustBe === "string" ? this.writers.mustBe : this.writers.mustBe(this.source);
|
|
102
|
-
}
|
|
103
|
-
constructor(code, path, data, source, writers){
|
|
104
|
-
_defineProperty(this, "code", void 0);
|
|
105
|
-
_defineProperty(this, "path", void 0);
|
|
106
|
-
_defineProperty(this, "data", void 0);
|
|
107
|
-
_defineProperty(this, "source", void 0);
|
|
108
|
-
_defineProperty(this, "writers", void 0);
|
|
109
|
-
_defineProperty(this, "parts", void 0);
|
|
110
|
-
this.code = code;
|
|
111
|
-
this.path = path;
|
|
112
|
-
this.data = data;
|
|
113
|
-
this.source = source;
|
|
114
|
-
this.writers = writers;
|
|
115
|
-
if (this.code === "multi") {
|
|
116
|
-
this.parts = this.source;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
var _state = /*#__PURE__*/ new WeakMap();
|
|
121
|
-
class ProblemArray extends Array {
|
|
122
|
-
mustBe(description, opts) {
|
|
123
|
-
return this.add("custom", description, opts);
|
|
124
|
-
}
|
|
125
|
-
add(code, source, opts) {
|
|
126
|
-
// copy the path to avoid future mutations affecting it
|
|
127
|
-
const path = _pathsJs.Path.from(opts?.path ?? _classPrivateFieldGet(this, _state).path);
|
|
128
|
-
const data = // we have to check for the presence of the key explicitly since the
|
|
129
|
-
// data could be undefined or null
|
|
130
|
-
opts && "data" in opts ? opts.data : _classPrivateFieldGet(this, _state).data;
|
|
131
|
-
const problem = new Problem(// avoid a bunch of errors from TS trying to discriminate the
|
|
132
|
-
// problem input based on the code
|
|
133
|
-
code, path, data, source, _classPrivateFieldGet(this, _state).getProblemConfig(code));
|
|
134
|
-
this.addProblem(problem);
|
|
135
|
-
return problem;
|
|
136
|
-
}
|
|
137
|
-
addProblem(problem) {
|
|
138
|
-
const pathKey = `${problem.path}`;
|
|
139
|
-
const existing = this.byPath[pathKey];
|
|
140
|
-
if (existing) {
|
|
141
|
-
if (existing.parts) {
|
|
142
|
-
existing.parts.push(problem);
|
|
143
|
-
} else {
|
|
144
|
-
const problemIntersection = new Problem("multi", existing.path, existing.data, [
|
|
145
|
-
existing,
|
|
146
|
-
problem
|
|
147
|
-
], _classPrivateFieldGet(this, _state).getProblemConfig("multi"));
|
|
148
|
-
const existingIndex = this.indexOf(existing);
|
|
149
|
-
// If existing is found (which it always should be unless this was externally mutated),
|
|
150
|
-
// replace it with the new problem intersection. In case it isn't for whatever reason,
|
|
151
|
-
// just append the intersection.
|
|
152
|
-
this[existingIndex === -1 ? this.length : existingIndex] = problemIntersection;
|
|
153
|
-
this.byPath[pathKey] = problemIntersection;
|
|
154
|
-
}
|
|
155
|
-
} else {
|
|
156
|
-
this.byPath[pathKey] = problem;
|
|
157
|
-
this.push(problem);
|
|
158
|
-
}
|
|
159
|
-
this.count++;
|
|
160
|
-
}
|
|
161
|
-
get summary() {
|
|
162
|
-
return `${this}`;
|
|
163
|
-
}
|
|
164
|
-
toString() {
|
|
165
|
-
return this.join("\n");
|
|
166
|
-
}
|
|
167
|
-
throw() {
|
|
168
|
-
throw new ArkTypeError(this);
|
|
169
|
-
}
|
|
170
|
-
constructor(state){
|
|
171
|
-
super();
|
|
172
|
-
_defineProperty(this, "byPath", {});
|
|
173
|
-
_defineProperty(this, "count", 0);
|
|
174
|
-
_classPrivateFieldInit(this, _state, {
|
|
175
|
-
writable: true,
|
|
176
|
-
value: void 0
|
|
177
|
-
});
|
|
178
|
-
_classPrivateFieldSet(this, _state, state);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
const Problems = ProblemArray;
|
|
182
|
-
const capitalize = (s)=>s[0].toUpperCase() + s.slice(1);
|
|
183
|
-
const domainsToDescriptions = (domains)=>domains.map((objectKind)=>_domainsJs.domainDescriptions[objectKind]);
|
|
184
|
-
const objectKindsToDescriptions = (kinds)=>kinds.map((objectKind)=>_objectKindsJs.objectKindDescriptions[objectKind]);
|
|
185
|
-
const describeBranches = (descriptions)=>{
|
|
186
|
-
if (descriptions.length === 0) {
|
|
187
|
-
return "never";
|
|
188
|
-
}
|
|
189
|
-
if (descriptions.length === 1) {
|
|
190
|
-
return descriptions[0];
|
|
191
|
-
}
|
|
192
|
-
let description = "";
|
|
193
|
-
for(let i = 0; i < descriptions.length - 1; i++){
|
|
194
|
-
description += descriptions[i];
|
|
195
|
-
if (i < descriptions.length - 2) {
|
|
196
|
-
description += ", ";
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
description += ` or ${descriptions[descriptions.length - 1]}`;
|
|
200
|
-
return description;
|
|
201
|
-
};
|
|
202
|
-
const writeDefaultReason = (mustBe, was)=>`must be ${mustBe}${was && ` (was ${was})`}`;
|
|
203
|
-
const addDefaultContext = (reason, path)=>path.length === 0 ? capitalize(reason) : path.length === 1 && (0, _numericLiteralsJs.isWellFormedInteger)(path[0]) ? `Item at index ${path[0]} ${reason}` : `${path} ${reason}`;
|
|
204
|
-
const defaultProblemConfig = {
|
|
205
|
-
divisor: {
|
|
206
|
-
mustBe: (divisor)=>divisor === 1 ? `an integer` : `a multiple of ${divisor}`
|
|
207
|
-
},
|
|
208
|
-
class: {
|
|
209
|
-
mustBe: (expected)=>{
|
|
210
|
-
const possibleObjectKind = (0, _objectKindsJs.getExactConstructorObjectKind)(expected);
|
|
211
|
-
return possibleObjectKind ? _objectKindsJs.objectKindDescriptions[possibleObjectKind] : `an instance of ${expected.name}`;
|
|
212
|
-
},
|
|
213
|
-
writeReason: (mustBe, data)=>writeDefaultReason(mustBe, data.className)
|
|
214
|
-
},
|
|
215
|
-
domain: {
|
|
216
|
-
mustBe: (domain)=>_domainsJs.domainDescriptions[domain],
|
|
217
|
-
writeReason: (mustBe, data)=>writeDefaultReason(mustBe, data.domain)
|
|
218
|
-
},
|
|
219
|
-
missing: {
|
|
220
|
-
mustBe: ()=>"defined",
|
|
221
|
-
writeReason: (mustBe)=>writeDefaultReason(mustBe, "")
|
|
222
|
-
},
|
|
223
|
-
extraneous: {
|
|
224
|
-
mustBe: ()=>"removed",
|
|
225
|
-
writeReason: (mustBe)=>writeDefaultReason(mustBe, "")
|
|
226
|
-
},
|
|
227
|
-
bound: {
|
|
228
|
-
mustBe: (bound)=>`${_scannerJs.Scanner.comparatorDescriptions[bound.comparator]} ${bound.limit}${bound.units ? ` ${bound.units}` : ""}`,
|
|
229
|
-
writeReason: (mustBe, data)=>writeDefaultReason(mustBe, `${data.size}`)
|
|
230
|
-
},
|
|
231
|
-
regex: {
|
|
232
|
-
mustBe: (expression)=>`a string matching ${expression}`
|
|
233
|
-
},
|
|
234
|
-
value: {
|
|
235
|
-
mustBe: _serializeJs.stringify
|
|
236
|
-
},
|
|
237
|
-
branches: {
|
|
238
|
-
mustBe: (branchProblems)=>describeBranches(branchProblems.map((problem)=>`${problem.path} must be ${problem.parts ? describeBranches(problem.parts.map((part)=>part.mustBe)) : problem.mustBe}`)),
|
|
239
|
-
writeReason: (mustBe, data)=>`${mustBe} (was ${data})`,
|
|
240
|
-
addContext: (reason, path)=>path.length ? `At ${path}, ${reason}` : reason
|
|
241
|
-
},
|
|
242
|
-
multi: {
|
|
243
|
-
mustBe: (problems)=>"• " + problems.map((_)=>_.mustBe).join("\n• "),
|
|
244
|
-
writeReason: (mustBe, data)=>`${data} must be...\n${mustBe}`,
|
|
245
|
-
addContext: (reason, path)=>path.length ? `At ${path}, ${reason}` : reason
|
|
246
|
-
},
|
|
247
|
-
custom: {
|
|
248
|
-
mustBe: (mustBe)=>mustBe
|
|
249
|
-
},
|
|
250
|
-
cases: {
|
|
251
|
-
mustBe: (cases)=>describeBranches(cases)
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
const problemCodes = (0, _genericsJs.objectKeysOf)(defaultProblemConfig);
|
|
255
|
-
const compileDefaultProblemWriters = ()=>{
|
|
256
|
-
const result = {};
|
|
257
|
-
let code;
|
|
258
|
-
for (code of problemCodes){
|
|
259
|
-
result[code] = {
|
|
260
|
-
mustBe: defaultProblemConfig[code].mustBe,
|
|
261
|
-
writeReason: defaultProblemConfig[code].writeReason ?? writeDefaultReason,
|
|
262
|
-
addContext: defaultProblemConfig[code].addContext ?? addDefaultContext
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
return result;
|
|
266
|
-
};
|
|
267
|
-
const defaultProblemWriters = compileDefaultProblemWriters();
|
|
268
|
-
const compileProblemWriters = (input)=>{
|
|
269
|
-
if (!input) {
|
|
270
|
-
return defaultProblemWriters;
|
|
271
|
-
}
|
|
272
|
-
const result = {};
|
|
273
|
-
for (const code of problemCodes){
|
|
274
|
-
result[code] = {
|
|
275
|
-
mustBe: input[code]?.mustBe ?? defaultProblemConfig[code].mustBe,
|
|
276
|
-
writeReason: input[code]?.writeReason ?? defaultProblemConfig[code].writeReason ?? input.writeReason ?? writeDefaultReason,
|
|
277
|
-
addContext: input[code]?.addContext ?? defaultProblemConfig[code].addContext ?? input.addContext ?? addDefaultContext
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
return result;
|
|
281
|
-
};
|
|
@@ -1,390 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
traverseRoot: ()=>traverseRoot,
|
|
13
|
-
TraversalState: ()=>TraversalState,
|
|
14
|
-
traverse: ()=>traverse,
|
|
15
|
-
checkEntries: ()=>checkEntries,
|
|
16
|
-
checkRequiredProp: ()=>checkRequiredProp
|
|
17
|
-
});
|
|
18
|
-
const _discriminateJs = require("../nodes/discriminate.js");
|
|
19
|
-
const _classJs = require("../nodes/rules/class.js");
|
|
20
|
-
const _divisorJs = require("../nodes/rules/divisor.js");
|
|
21
|
-
const _rangeJs = require("../nodes/rules/range.js");
|
|
22
|
-
const _regexJs = require("../nodes/rules/regex.js");
|
|
23
|
-
const _rulesJs = require("../nodes/rules/rules.js");
|
|
24
|
-
const _domainsJs = require("../utils/domains.js");
|
|
25
|
-
const _errorsJs = require("../utils/errors.js");
|
|
26
|
-
const _genericsJs = require("../utils/generics.js");
|
|
27
|
-
const _numericLiteralsJs = require("../utils/numericLiterals.js");
|
|
28
|
-
const _pathsJs = require("../utils/paths.js");
|
|
29
|
-
const _problemsJs = require("./problems.js");
|
|
30
|
-
function _checkPrivateRedeclaration(obj, privateCollection) {
|
|
31
|
-
if (privateCollection.has(obj)) {
|
|
32
|
-
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function _classApplyDescriptorGet(receiver, descriptor) {
|
|
36
|
-
if (descriptor.get) {
|
|
37
|
-
return descriptor.get.call(receiver);
|
|
38
|
-
}
|
|
39
|
-
return descriptor.value;
|
|
40
|
-
}
|
|
41
|
-
function _classApplyDescriptorSet(receiver, descriptor, value) {
|
|
42
|
-
if (descriptor.set) {
|
|
43
|
-
descriptor.set.call(receiver, value);
|
|
44
|
-
} else {
|
|
45
|
-
if (!descriptor.writable) {
|
|
46
|
-
throw new TypeError("attempted to set read only private field");
|
|
47
|
-
}
|
|
48
|
-
descriptor.value = value;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function _classExtractFieldDescriptor(receiver, privateMap, action) {
|
|
52
|
-
if (!privateMap.has(receiver)) {
|
|
53
|
-
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
54
|
-
}
|
|
55
|
-
return privateMap.get(receiver);
|
|
56
|
-
}
|
|
57
|
-
function _classPrivateFieldGet(receiver, privateMap) {
|
|
58
|
-
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
|
|
59
|
-
return _classApplyDescriptorGet(receiver, descriptor);
|
|
60
|
-
}
|
|
61
|
-
function _classPrivateFieldInit(obj, privateMap, value) {
|
|
62
|
-
_checkPrivateRedeclaration(obj, privateMap);
|
|
63
|
-
privateMap.set(obj, value);
|
|
64
|
-
}
|
|
65
|
-
function _classPrivateFieldSet(receiver, privateMap, value) {
|
|
66
|
-
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set");
|
|
67
|
-
_classApplyDescriptorSet(receiver, descriptor, value);
|
|
68
|
-
return value;
|
|
69
|
-
}
|
|
70
|
-
function _defineProperty(obj, key, value) {
|
|
71
|
-
if (key in obj) {
|
|
72
|
-
Object.defineProperty(obj, key, {
|
|
73
|
-
value: value,
|
|
74
|
-
enumerable: true,
|
|
75
|
-
configurable: true,
|
|
76
|
-
writable: true
|
|
77
|
-
});
|
|
78
|
-
} else {
|
|
79
|
-
obj[key] = value;
|
|
80
|
-
}
|
|
81
|
-
return obj;
|
|
82
|
-
}
|
|
83
|
-
const initializeTraversalConfig = ()=>({
|
|
84
|
-
mustBe: [],
|
|
85
|
-
writeReason: [],
|
|
86
|
-
addContext: [],
|
|
87
|
-
keys: []
|
|
88
|
-
});
|
|
89
|
-
const problemWriterKeys = [
|
|
90
|
-
"mustBe",
|
|
91
|
-
"writeReason",
|
|
92
|
-
"addContext"
|
|
93
|
-
];
|
|
94
|
-
const traverseRoot = (t, data)=>{
|
|
95
|
-
const state = new TraversalState(data, t);
|
|
96
|
-
traverse(t.flat, state);
|
|
97
|
-
const result = new CheckResult(state);
|
|
98
|
-
if (state.problems.count) {
|
|
99
|
-
result.problems = state.problems;
|
|
100
|
-
} else {
|
|
101
|
-
for (const [o, k] of state.entriesToPrune){
|
|
102
|
-
delete o[k];
|
|
103
|
-
}
|
|
104
|
-
result.data = state.data;
|
|
105
|
-
}
|
|
106
|
-
return result;
|
|
107
|
-
};
|
|
108
|
-
const CheckResult = class {
|
|
109
|
-
constructor(){
|
|
110
|
-
_defineProperty(this, "data", void 0);
|
|
111
|
-
_defineProperty(this, "problems", void 0);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
var _seen = /*#__PURE__*/ new WeakMap();
|
|
115
|
-
class TraversalState {
|
|
116
|
-
getProblemConfig(code) {
|
|
117
|
-
const result = {};
|
|
118
|
-
for (const k of problemWriterKeys){
|
|
119
|
-
result[k] = this.traversalConfig[k][0] ?? this.rootScope.config.codes[code][k];
|
|
120
|
-
}
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
|
-
traverseConfig(configEntries, node) {
|
|
124
|
-
for (const entry of configEntries){
|
|
125
|
-
this.traversalConfig[entry[0]].unshift(entry[1]);
|
|
126
|
-
}
|
|
127
|
-
const isValid = traverse(node, this);
|
|
128
|
-
for (const entry of configEntries){
|
|
129
|
-
this.traversalConfig[entry[0]].shift();
|
|
130
|
-
}
|
|
131
|
-
return isValid;
|
|
132
|
-
}
|
|
133
|
-
traverseKey(key, node) {
|
|
134
|
-
const lastData = this.data;
|
|
135
|
-
this.data = this.data[key];
|
|
136
|
-
this.path.push(key);
|
|
137
|
-
const isValid = traverse(node, this);
|
|
138
|
-
this.path.pop();
|
|
139
|
-
if (lastData[key] !== this.data) {
|
|
140
|
-
lastData[key] = this.data;
|
|
141
|
-
}
|
|
142
|
-
this.data = lastData;
|
|
143
|
-
return isValid;
|
|
144
|
-
}
|
|
145
|
-
traverseResolution(name) {
|
|
146
|
-
const resolution = this.type.scope.resolve(name);
|
|
147
|
-
const id = resolution.qualifiedName;
|
|
148
|
-
// this assignment helps with narrowing
|
|
149
|
-
const data = this.data;
|
|
150
|
-
const isObject = (0, _domainsJs.hasDomain)(data, "object");
|
|
151
|
-
if (isObject) {
|
|
152
|
-
const seenByCurrentType = _classPrivateFieldGet(this, _seen)[id];
|
|
153
|
-
if (seenByCurrentType) {
|
|
154
|
-
if (seenByCurrentType.includes(data)) {
|
|
155
|
-
// if data has already been checked by this alias as part of
|
|
156
|
-
// a resolution higher up on the call stack, it must be valid
|
|
157
|
-
// or we wouldn't be here
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
seenByCurrentType.push(data);
|
|
161
|
-
} else {
|
|
162
|
-
_classPrivateFieldGet(this, _seen)[id] = [
|
|
163
|
-
data
|
|
164
|
-
];
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
const lastType = this.type;
|
|
168
|
-
this.type = resolution;
|
|
169
|
-
const isValid = traverse(resolution.flat, this);
|
|
170
|
-
this.type = lastType;
|
|
171
|
-
if (isObject) {
|
|
172
|
-
_classPrivateFieldGet(this, _seen)[id].pop();
|
|
173
|
-
}
|
|
174
|
-
return isValid;
|
|
175
|
-
}
|
|
176
|
-
traverseBranches(branches) {
|
|
177
|
-
const lastFailFast = this.failFast;
|
|
178
|
-
this.failFast = true;
|
|
179
|
-
const lastProblems = this.problems;
|
|
180
|
-
const branchProblems = new _problemsJs.Problems(this);
|
|
181
|
-
this.problems = branchProblems;
|
|
182
|
-
const lastPath = this.path;
|
|
183
|
-
const lastKeysToPrune = this.entriesToPrune;
|
|
184
|
-
let hasValidBranch = false;
|
|
185
|
-
for (const branch of branches){
|
|
186
|
-
this.path = new _pathsJs.Path();
|
|
187
|
-
this.entriesToPrune = [];
|
|
188
|
-
if (checkEntries(branch, this)) {
|
|
189
|
-
hasValidBranch = true;
|
|
190
|
-
lastKeysToPrune.push(...this.entriesToPrune);
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
this.path = lastPath;
|
|
195
|
-
this.entriesToPrune = lastKeysToPrune;
|
|
196
|
-
this.problems = lastProblems;
|
|
197
|
-
this.failFast = lastFailFast;
|
|
198
|
-
return hasValidBranch || !this.problems.add("branches", branchProblems);
|
|
199
|
-
}
|
|
200
|
-
constructor(data, type){
|
|
201
|
-
_defineProperty(this, "data", void 0);
|
|
202
|
-
_defineProperty(this, "type", void 0);
|
|
203
|
-
_defineProperty(this, "path", void 0);
|
|
204
|
-
_defineProperty(this, "problems", void 0);
|
|
205
|
-
_defineProperty(this, "entriesToPrune", void 0);
|
|
206
|
-
_defineProperty(this, "failFast", void 0);
|
|
207
|
-
_defineProperty(this, "traversalConfig", void 0);
|
|
208
|
-
_defineProperty(this, "rootScope", void 0);
|
|
209
|
-
_classPrivateFieldInit(this, _seen, {
|
|
210
|
-
writable: true,
|
|
211
|
-
value: void 0
|
|
212
|
-
});
|
|
213
|
-
this.data = data;
|
|
214
|
-
this.type = type;
|
|
215
|
-
this.path = new _pathsJs.Path();
|
|
216
|
-
this.problems = new _problemsJs.Problems(this);
|
|
217
|
-
this.entriesToPrune = [];
|
|
218
|
-
this.failFast = false;
|
|
219
|
-
this.traversalConfig = initializeTraversalConfig();
|
|
220
|
-
_classPrivateFieldSet(this, _seen, {});
|
|
221
|
-
this.rootScope = type.scope;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
const traverse = (node, state)=>typeof node === "string" ? (0, _domainsJs.domainOf)(state.data) === node || !state.problems.add("domain", node) : checkEntries(node, state);
|
|
225
|
-
const checkEntries = (entries, state)=>{
|
|
226
|
-
let isValid = true;
|
|
227
|
-
for(let i = 0; i < entries.length; i++){
|
|
228
|
-
const [k, v] = entries[i];
|
|
229
|
-
const entryAllowsData = entryCheckers[k](v, state);
|
|
230
|
-
isValid && (isValid = entryAllowsData);
|
|
231
|
-
if (!isValid) {
|
|
232
|
-
if (state.failFast) {
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
if (i < entries.length - 1 && _rulesJs.precedenceMap[k] < _rulesJs.precedenceMap[entries[i + 1][0]]) {
|
|
236
|
-
// if we've encountered a problem, there is at least one entry
|
|
237
|
-
// remaining, and the next entry is of a higher precedence level
|
|
238
|
-
// than the current entry, return immediately
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return isValid;
|
|
244
|
-
};
|
|
245
|
-
const checkRequiredProp = (prop, state)=>{
|
|
246
|
-
if (prop[0] in state.data) {
|
|
247
|
-
return state.traverseKey(prop[0], prop[1]);
|
|
248
|
-
}
|
|
249
|
-
state.problems.add("missing", undefined, {
|
|
250
|
-
path: state.path.concat(prop[0]),
|
|
251
|
-
data: undefined
|
|
252
|
-
});
|
|
253
|
-
return false;
|
|
254
|
-
};
|
|
255
|
-
const createPropChecker = (kind)=>(props, state)=>{
|
|
256
|
-
let isValid = true;
|
|
257
|
-
const remainingUnseenRequired = {
|
|
258
|
-
...props.required
|
|
259
|
-
};
|
|
260
|
-
for(const k in state.data){
|
|
261
|
-
if (props.required[k]) {
|
|
262
|
-
isValid = state.traverseKey(k, props.required[k]) && isValid;
|
|
263
|
-
delete remainingUnseenRequired[k];
|
|
264
|
-
} else if (props.optional[k]) {
|
|
265
|
-
isValid = state.traverseKey(k, props.optional[k]) && isValid;
|
|
266
|
-
} else if (props.index && _numericLiteralsJs.wellFormedIntegerMatcher.test(k)) {
|
|
267
|
-
isValid = state.traverseKey(k, props.index) && isValid;
|
|
268
|
-
} else if (kind === "distilledProps") {
|
|
269
|
-
if (state.failFast) {
|
|
270
|
-
// If we're in a union (i.e. failFast is enabled) in
|
|
271
|
-
// distilled mode, we need to wait to prune distilled keys
|
|
272
|
-
// to avoid mutating data based on a branch that will not be
|
|
273
|
-
// included in the final result. Instead, we push the object
|
|
274
|
-
// and key to state to handle after traversal is complete.
|
|
275
|
-
state.entriesToPrune.push([
|
|
276
|
-
state.data,
|
|
277
|
-
k
|
|
278
|
-
]);
|
|
279
|
-
} else {
|
|
280
|
-
// If we're not in a union, we can safely distill right away
|
|
281
|
-
delete state.data[k];
|
|
282
|
-
}
|
|
283
|
-
} else {
|
|
284
|
-
isValid = false;
|
|
285
|
-
state.problems.add("extraneous", state.data[k], {
|
|
286
|
-
path: state.path.concat(k)
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
if (!isValid && state.failFast) {
|
|
290
|
-
return false;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
const unseenRequired = Object.keys(remainingUnseenRequired);
|
|
294
|
-
if (unseenRequired.length) {
|
|
295
|
-
for (const k of unseenRequired){
|
|
296
|
-
state.problems.add("missing", undefined, {
|
|
297
|
-
path: state.path.concat(k)
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
return false;
|
|
301
|
-
}
|
|
302
|
-
return isValid;
|
|
303
|
-
};
|
|
304
|
-
const entryCheckers = {
|
|
305
|
-
regex: _regexJs.checkRegex,
|
|
306
|
-
divisor: _divisorJs.checkDivisor,
|
|
307
|
-
domains: (domains, state)=>{
|
|
308
|
-
const entries = domains[(0, _domainsJs.domainOf)(state.data)];
|
|
309
|
-
return entries ? checkEntries(entries, state) : !state.problems.add("cases", (0, _problemsJs.domainsToDescriptions)((0, _genericsJs.objectKeysOf)(domains)));
|
|
310
|
-
},
|
|
311
|
-
domain: (domain, state)=>(0, _domainsJs.domainOf)(state.data) === domain || !state.problems.add("domain", domain),
|
|
312
|
-
bound: _rangeJs.checkBound,
|
|
313
|
-
optionalProp: (prop, state)=>{
|
|
314
|
-
if (prop[0] in state.data) {
|
|
315
|
-
return state.traverseKey(prop[0], prop[1]);
|
|
316
|
-
}
|
|
317
|
-
return true;
|
|
318
|
-
},
|
|
319
|
-
// these checks work the same way, the keys are only distinct so that
|
|
320
|
-
// prerequisite props can have a higher precedence
|
|
321
|
-
requiredProp: checkRequiredProp,
|
|
322
|
-
prerequisiteProp: checkRequiredProp,
|
|
323
|
-
indexProp: (node, state)=>{
|
|
324
|
-
if (!Array.isArray(state.data)) {
|
|
325
|
-
state.problems.add("class", Array);
|
|
326
|
-
return false;
|
|
327
|
-
}
|
|
328
|
-
let isValid = true;
|
|
329
|
-
for(let i = 0; i < state.data.length; i++){
|
|
330
|
-
isValid = state.traverseKey(`${i}`, node) && isValid;
|
|
331
|
-
if (!isValid && state.failFast) {
|
|
332
|
-
return false;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return isValid;
|
|
336
|
-
},
|
|
337
|
-
branches: (branches, state)=>state.traverseBranches(branches),
|
|
338
|
-
switch: (rule, state)=>{
|
|
339
|
-
const dataAtPath = (0, _pathsJs.getPath)(state.data, rule.path);
|
|
340
|
-
const caseKey = (0, _discriminateJs.serializeCase)(rule.kind, dataAtPath);
|
|
341
|
-
if ((0, _genericsJs.hasKey)(rule.cases, caseKey)) {
|
|
342
|
-
return checkEntries(rule.cases[caseKey], state);
|
|
343
|
-
}
|
|
344
|
-
const caseKeys = (0, _genericsJs.objectKeysOf)(rule.cases);
|
|
345
|
-
const missingCasePath = state.path.concat(rule.path);
|
|
346
|
-
const caseDescriptions = rule.kind === "value" ? caseKeys : rule.kind === "domain" ? (0, _problemsJs.domainsToDescriptions)(caseKeys) : rule.kind === "class" ? (0, _problemsJs.objectKindsToDescriptions)(caseKeys) : (0, _errorsJs.throwInternalError)(`Unexpectedly encountered rule kind '${rule.kind}' during traversal`);
|
|
347
|
-
state.problems.add("cases", caseDescriptions, {
|
|
348
|
-
path: missingCasePath,
|
|
349
|
-
data: dataAtPath
|
|
350
|
-
});
|
|
351
|
-
return false;
|
|
352
|
-
},
|
|
353
|
-
alias: (name, state)=>state.traverseResolution(name),
|
|
354
|
-
class: _classJs.checkClass,
|
|
355
|
-
narrow: (narrow, state)=>{
|
|
356
|
-
const lastProblemsCount = state.problems.count;
|
|
357
|
-
const result = narrow(state.data, state.problems);
|
|
358
|
-
if (!result && state.problems.count === lastProblemsCount) {
|
|
359
|
-
state.problems.mustBe(narrow.name ? `valid according to ${narrow.name}` : "valid");
|
|
360
|
-
}
|
|
361
|
-
return result;
|
|
362
|
-
},
|
|
363
|
-
config: ({ config , node }, state)=>state.traverseConfig(config, node),
|
|
364
|
-
value: (value, state)=>state.data === value || !state.problems.add("value", value),
|
|
365
|
-
morph: (morph, state)=>{
|
|
366
|
-
const out = morph(state.data, state.problems);
|
|
367
|
-
if (state.problems.length) {
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
|
-
if (out instanceof _problemsJs.Problem) {
|
|
371
|
-
// if a problem was returned from the morph but not added, add it
|
|
372
|
-
state.problems.addProblem(out);
|
|
373
|
-
return false;
|
|
374
|
-
}
|
|
375
|
-
if (out instanceof CheckResult) {
|
|
376
|
-
if (out.problems) {
|
|
377
|
-
for (const problem of out.problems){
|
|
378
|
-
state.problems.addProblem(problem);
|
|
379
|
-
}
|
|
380
|
-
return false;
|
|
381
|
-
}
|
|
382
|
-
state.data = out.data;
|
|
383
|
-
return true;
|
|
384
|
-
}
|
|
385
|
-
state.data = out;
|
|
386
|
-
return true;
|
|
387
|
-
},
|
|
388
|
-
distilledProps: createPropChecker("distilledProps"),
|
|
389
|
-
strictProps: createPropChecker("strictProps")
|
|
390
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Can be used to allow arbitrarily chained property access and function calls.
|
|
3
|
-
* This is useful for expressions whose meaning is not attached to a value,
|
|
4
|
-
* e.g. to allow the extraction of types using typeof without depending on
|
|
5
|
-
* the existence of a real object that conforms to that type's structure:
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* const myType: MyType = chainableNoOpProxy
|
|
9
|
-
*
|
|
10
|
-
* // The following types are equivalent
|
|
11
|
-
* type ExtractedType = typeof myType.a.b.c
|
|
12
|
-
* type DirectlyExtractedType = MyType["a"]["b"]["c"]
|
|
13
|
-
*/ "use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(exports, "chainableNoOpProxy", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: ()=>chainableNoOpProxy
|
|
20
|
-
});
|
|
21
|
-
const chainableNoOpProxy = new Proxy(()=>chainableNoOpProxy, {
|
|
22
|
-
get: ()=>chainableNoOpProxy
|
|
23
|
-
});
|