arktype 1.0.15-alpha → 1.0.17-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/package.json +3 -0
- package/dist/cjs/src/main.js +38 -0
- package/dist/cjs/src/nodes/branch.js +140 -0
- package/dist/cjs/src/nodes/compose.js +157 -0
- package/dist/{nodes → cjs/src/nodes}/discriminate.js +92 -100
- package/dist/cjs/src/nodes/node.js +139 -0
- package/dist/cjs/src/nodes/predicate.js +86 -0
- package/dist/cjs/src/nodes/rules/class.js +25 -0
- package/dist/cjs/src/nodes/rules/collapsibleSet.js +48 -0
- package/dist/cjs/src/nodes/rules/divisor.js +29 -0
- package/dist/cjs/src/nodes/rules/props.js +160 -0
- package/dist/cjs/src/nodes/rules/range.js +105 -0
- package/dist/cjs/src/nodes/rules/regex.js +26 -0
- package/dist/cjs/src/nodes/rules/rules.js +123 -0
- package/dist/cjs/src/parse/ast/ast.js +4 -0
- package/dist/cjs/src/parse/ast/bound.js +16 -0
- package/dist/cjs/src/parse/ast/config.js +13 -0
- package/dist/cjs/src/parse/ast/distributableFunction.js +48 -0
- package/dist/cjs/src/parse/ast/divisor.js +9 -0
- package/dist/cjs/src/parse/ast/intersection.js +30 -0
- package/dist/cjs/src/parse/ast/keyof.js +111 -0
- package/dist/cjs/src/parse/ast/morph.js +58 -0
- package/dist/cjs/src/parse/ast/narrow.js +22 -0
- package/dist/cjs/src/parse/ast/node.js +4 -0
- package/dist/cjs/src/parse/ast/tuple.js +94 -0
- package/dist/cjs/src/parse/ast/union.js +9 -0
- package/dist/cjs/src/parse/ast/utils.js +4 -0
- package/dist/cjs/src/parse/definition.js +61 -0
- package/dist/cjs/src/parse/record.js +37 -0
- package/dist/cjs/src/parse/string/reduce/dynamic.js +167 -0
- package/dist/cjs/src/parse/string/reduce/shared.js +23 -0
- package/dist/cjs/src/parse/string/reduce/static.js +4 -0
- package/dist/cjs/src/parse/string/shift/operand/enclosed.js +54 -0
- package/dist/cjs/src/parse/string/shift/operand/operand.js +11 -0
- package/dist/cjs/src/parse/string/shift/operand/unenclosed.js +53 -0
- package/dist/cjs/src/parse/string/shift/operator/bounds.js +87 -0
- package/dist/cjs/src/parse/string/shift/operator/divisor.js +35 -0
- package/dist/cjs/src/parse/string/shift/operator/operator.js +26 -0
- package/dist/cjs/src/parse/string/shift/scanner.js +114 -0
- package/dist/cjs/src/parse/string/string.js +43 -0
- package/dist/cjs/src/scopes/ark.js +45 -0
- package/dist/cjs/src/scopes/cache.js +52 -0
- package/dist/cjs/src/scopes/expressions.js +29 -0
- package/dist/cjs/src/scopes/jsObjects.js +93 -0
- package/dist/cjs/src/scopes/scope.js +323 -0
- package/dist/cjs/src/scopes/tsKeywords.js +113 -0
- package/dist/cjs/src/scopes/type.js +50 -0
- package/dist/cjs/src/scopes/validation/creditCard.js +47 -0
- package/dist/cjs/src/scopes/validation/date.js +62 -0
- package/dist/cjs/src/scopes/validation/validation.js +108 -0
- package/dist/cjs/src/traverse/problems.js +281 -0
- package/dist/cjs/src/traverse/traverse.js +390 -0
- package/dist/cjs/src/utils/chainableNoOpProxy.js +23 -0
- package/dist/cjs/src/utils/data.js +53 -0
- package/dist/cjs/src/utils/domains.js +30 -0
- package/dist/cjs/src/utils/errors.js +26 -0
- package/dist/cjs/src/utils/freeze.js +15 -0
- package/dist/cjs/src/utils/generics.js +63 -0
- package/dist/cjs/src/utils/numericLiterals.js +75 -0
- package/dist/cjs/src/utils/objectKinds.js +69 -0
- package/dist/cjs/src/utils/paths.js +32 -0
- package/dist/cjs/src/utils/serialize.js +74 -0
- package/dist/cjs/src/utils/unionToTuple.js +4 -0
- package/dist/mjs/package.json +3 -0
- package/dist/mjs/src/main.js +8 -0
- package/dist/mjs/src/nodes/branch.js +123 -0
- package/dist/mjs/src/nodes/compose.js +135 -0
- package/dist/mjs/src/nodes/discriminate.js +247 -0
- package/dist/mjs/src/nodes/node.js +117 -0
- package/dist/mjs/src/nodes/predicate.js +69 -0
- package/dist/mjs/src/nodes/rules/class.js +11 -0
- package/dist/mjs/src/nodes/rules/collapsibleSet.js +34 -0
- package/dist/mjs/src/nodes/rules/divisor.js +15 -0
- package/dist/mjs/src/nodes/rules/props.js +142 -0
- package/dist/mjs/src/nodes/rules/range.js +86 -0
- package/dist/mjs/src/nodes/rules/regex.js +11 -0
- package/dist/mjs/src/nodes/rules/rules.js +106 -0
- package/dist/mjs/src/parse/ast/ast.js +1 -0
- package/dist/mjs/src/parse/ast/bound.js +2 -0
- package/dist/mjs/src/parse/ast/config.js +9 -0
- package/dist/mjs/src/parse/ast/distributableFunction.js +34 -0
- package/dist/mjs/src/parse/ast/divisor.js +1 -0
- package/dist/mjs/src/parse/ast/intersection.js +16 -0
- package/dist/mjs/src/parse/ast/keyof.js +103 -0
- package/dist/mjs/src/parse/ast/morph.js +44 -0
- package/dist/mjs/src/parse/ast/narrow.js +14 -0
- package/dist/mjs/src/parse/ast/node.js +1 -0
- package/dist/mjs/src/parse/ast/tuple.js +80 -0
- package/dist/mjs/src/parse/ast/union.js +1 -0
- package/dist/mjs/src/parse/ast/utils.js +1 -0
- package/dist/mjs/src/parse/definition.js +46 -0
- package/dist/mjs/src/parse/record.js +29 -0
- package/dist/mjs/src/parse/string/reduce/dynamic.js +159 -0
- package/dist/mjs/src/parse/string/reduce/shared.js +6 -0
- package/dist/mjs/src/parse/string/reduce/static.js +1 -0
- package/dist/mjs/src/parse/string/shift/operand/enclosed.js +39 -0
- package/dist/mjs/src/parse/string/shift/operand/operand.js +3 -0
- package/dist/mjs/src/parse/string/shift/operand/unenclosed.js +36 -0
- package/dist/mjs/src/parse/string/shift/operator/bounds.js +70 -0
- package/dist/mjs/src/parse/string/shift/operator/divisor.js +21 -0
- package/dist/mjs/src/parse/string/shift/operator/operator.js +13 -0
- package/dist/mjs/src/parse/string/shift/scanner.js +106 -0
- package/dist/mjs/src/parse/string/string.js +28 -0
- package/dist/mjs/src/scopes/ark.js +28 -0
- package/dist/mjs/src/scopes/cache.js +38 -0
- package/dist/{scopes → mjs/src/scopes}/expressions.js +9 -20
- package/dist/mjs/src/scopes/jsObjects.js +82 -0
- package/dist/mjs/src/scopes/scope.js +303 -0
- package/dist/mjs/src/scopes/tsKeywords.js +116 -0
- package/dist/mjs/src/scopes/type.js +35 -0
- package/dist/{scopes → mjs/src/scopes}/validation/creditCard.js +11 -15
- package/dist/{scopes → mjs/src/scopes}/validation/date.js +16 -21
- package/dist/mjs/src/scopes/validation/validation.js +112 -0
- package/dist/mjs/src/traverse/problems.js +260 -0
- package/dist/mjs/src/traverse/traverse.js +373 -0
- package/dist/{utils → mjs/src/utils}/chainableNoOpProxy.js +2 -6
- package/dist/mjs/src/utils/data.js +38 -0
- package/dist/mjs/src/utils/domains.js +15 -0
- package/dist/mjs/src/utils/errors.js +10 -0
- package/dist/mjs/src/utils/freeze.js +7 -0
- package/dist/mjs/src/utils/generics.js +38 -0
- package/dist/mjs/src/utils/numericLiterals.js +72 -0
- package/dist/mjs/src/utils/objectKinds.js +55 -0
- package/dist/{utils → mjs/src/utils}/paths.js +3 -8
- package/dist/mjs/src/utils/serialize.js +58 -0
- package/dist/mjs/src/utils/unionToTuple.js +1 -0
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/dist/{utils → types/utils}/generics.d.ts +2 -2
- package/package.json +14 -5
- 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/{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}/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
package/dist/scopes/scope.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeDuplicateAliasesMessage = exports.writeShallowCycleErrorMessage = exports.rootType = exports.rootScope = exports.scope = exports.Scope = exports.isConfigTuple = exports.compileScopeOptions = void 0;
|
|
4
|
-
const node_js_1 = require("../nodes/node.js");
|
|
5
|
-
const definition_js_1 = require("../parse/definition.js");
|
|
6
|
-
const problems_js_1 = require("../traverse/problems.js");
|
|
7
|
-
const chainableNoOpProxy_js_1 = require("../utils/chainableNoOpProxy.js");
|
|
8
|
-
const errors_js_1 = require("../utils/errors.js");
|
|
9
|
-
const freeze_js_1 = require("../utils/freeze.js");
|
|
10
|
-
const generics_js_1 = require("../utils/generics.js");
|
|
11
|
-
const paths_js_1 = require("../utils/paths.js");
|
|
12
|
-
const cache_js_1 = require("./cache.js");
|
|
13
|
-
const type_js_1 = require("./type.js");
|
|
14
|
-
const compileScopeOptions = (opts) => ({
|
|
15
|
-
codes: (0, problems_js_1.compileProblemWriters)(opts.codes),
|
|
16
|
-
keys: opts.keys ?? "loose"
|
|
17
|
-
});
|
|
18
|
-
exports.compileScopeOptions = compileScopeOptions;
|
|
19
|
-
let anonymousScopeCount = 0;
|
|
20
|
-
const scopeRegistry = {};
|
|
21
|
-
const spaceRegistry = {};
|
|
22
|
-
const isConfigTuple = (def) => Array.isArray(def) && def[1] === ":";
|
|
23
|
-
exports.isConfigTuple = isConfigTuple;
|
|
24
|
-
class Scope {
|
|
25
|
-
aliases;
|
|
26
|
-
name;
|
|
27
|
-
config;
|
|
28
|
-
parseCache = new cache_js_1.FreezingCache();
|
|
29
|
-
#resolutions = new cache_js_1.Cache();
|
|
30
|
-
#exports = new cache_js_1.Cache();
|
|
31
|
-
constructor(aliases, opts = {}) {
|
|
32
|
-
this.aliases = aliases;
|
|
33
|
-
this.name = this.#register(opts);
|
|
34
|
-
if (opts.standard !== false) {
|
|
35
|
-
this.#cacheSpaces([spaceRegistry["standard"]], "imports");
|
|
36
|
-
}
|
|
37
|
-
if (opts.imports) {
|
|
38
|
-
this.#cacheSpaces(opts.imports, "imports");
|
|
39
|
-
}
|
|
40
|
-
if (opts.includes) {
|
|
41
|
-
this.#cacheSpaces(opts.includes, "includes");
|
|
42
|
-
}
|
|
43
|
-
this.config = (0, exports.compileScopeOptions)(opts);
|
|
44
|
-
}
|
|
45
|
-
#register(opts) {
|
|
46
|
-
const name = opts.name
|
|
47
|
-
? scopeRegistry[opts.name]
|
|
48
|
-
? (0, errors_js_1.throwParseError)(`A scope named '${opts.name}' already exists`)
|
|
49
|
-
: opts.name
|
|
50
|
-
: `scope${++anonymousScopeCount}`;
|
|
51
|
-
scopeRegistry[name] = this;
|
|
52
|
-
return name;
|
|
53
|
-
}
|
|
54
|
-
#cacheSpaces(spaces, kind) {
|
|
55
|
-
for (const space of spaces) {
|
|
56
|
-
for (const name in space) {
|
|
57
|
-
if (this.#resolutions.has(name) || name in this.aliases) {
|
|
58
|
-
(0, errors_js_1.throwParseError)((0, exports.writeDuplicateAliasesMessage)(name));
|
|
59
|
-
}
|
|
60
|
-
this.#resolutions.set(name, space[name]);
|
|
61
|
-
if (kind === "includes") {
|
|
62
|
-
this.#exports.set(name, space[name]);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
#initializeContext(type) {
|
|
68
|
-
return {
|
|
69
|
-
type,
|
|
70
|
-
path: new paths_js_1.Path()
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
getAnonymousQualifiedName(base) {
|
|
74
|
-
let increment = 0;
|
|
75
|
-
let id = base;
|
|
76
|
-
while (this.isResolvable(id)) {
|
|
77
|
-
id = `${base}${increment++}`;
|
|
78
|
-
}
|
|
79
|
-
return `${this.name}.${id}`;
|
|
80
|
-
}
|
|
81
|
-
addAnonymousTypeReference(referencedType, ctx) {
|
|
82
|
-
ctx.type.includesMorph ||= referencedType.includesMorph;
|
|
83
|
-
return referencedType.node;
|
|
84
|
-
}
|
|
85
|
-
get infer() {
|
|
86
|
-
return chainableNoOpProxy_js_1.chainableNoOpProxy;
|
|
87
|
-
}
|
|
88
|
-
compile() {
|
|
89
|
-
if (!spaceRegistry[this.name]) {
|
|
90
|
-
for (const name in this.aliases) {
|
|
91
|
-
this.resolve(name);
|
|
92
|
-
}
|
|
93
|
-
spaceRegistry[this.name] = this.#exports.root;
|
|
94
|
-
}
|
|
95
|
-
return this.#exports.root;
|
|
96
|
-
}
|
|
97
|
-
addParsedReferenceIfResolvable(name, ctx) {
|
|
98
|
-
const resolution = this.#resolveRecurse(name, "undefined", [name]);
|
|
99
|
-
if (!resolution) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
ctx.type.includesMorph ||= resolution.includesMorph;
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
resolve(name) {
|
|
106
|
-
return this.#resolveRecurse(name, "throw", [name]);
|
|
107
|
-
}
|
|
108
|
-
#resolveRecurse(name, onUnresolvable, seen) {
|
|
109
|
-
const maybeCacheResult = this.#resolutions.get(name);
|
|
110
|
-
if (maybeCacheResult) {
|
|
111
|
-
return maybeCacheResult;
|
|
112
|
-
}
|
|
113
|
-
const aliasDef = this.aliases[name];
|
|
114
|
-
if (!aliasDef) {
|
|
115
|
-
return (onUnresolvable === "throw"
|
|
116
|
-
? (0, errors_js_1.throwInternalError)(`Unexpectedly failed to resolve alias '${name}'`)
|
|
117
|
-
: undefined);
|
|
118
|
-
}
|
|
119
|
-
const t = (0, type_js_1.initializeType)(name, aliasDef, {}, this);
|
|
120
|
-
const ctx = this.#initializeContext(t);
|
|
121
|
-
this.#resolutions.set(name, t);
|
|
122
|
-
this.#exports.set(name, t);
|
|
123
|
-
let node = (0, definition_js_1.parseDefinition)(aliasDef, ctx);
|
|
124
|
-
if (typeof node === "string") {
|
|
125
|
-
if (seen.includes(node)) {
|
|
126
|
-
return (0, errors_js_1.throwParseError)((0, exports.writeShallowCycleErrorMessage)(name, seen));
|
|
127
|
-
}
|
|
128
|
-
seen.push(node);
|
|
129
|
-
node = this.#resolveRecurse(node, "throw", seen).node;
|
|
130
|
-
}
|
|
131
|
-
t.node = (0, freeze_js_1.deepFreeze)(node);
|
|
132
|
-
t.flat = (0, freeze_js_1.deepFreeze)((0, node_js_1.flattenType)(t));
|
|
133
|
-
return t;
|
|
134
|
-
}
|
|
135
|
-
resolveNode(node) {
|
|
136
|
-
return typeof node === "string"
|
|
137
|
-
? this.resolveNode(this.resolve(node).node)
|
|
138
|
-
: node;
|
|
139
|
-
}
|
|
140
|
-
resolveTypeNode(node) {
|
|
141
|
-
const resolution = this.resolveNode(node);
|
|
142
|
-
return (0, node_js_1.isConfigNode)(resolution) ? resolution.node : resolution;
|
|
143
|
-
}
|
|
144
|
-
expressions = {
|
|
145
|
-
intersection: (l, r, opts) => this.type([l, "&", r], opts),
|
|
146
|
-
union: (l, r, opts) => this.type([l, "|", r], opts),
|
|
147
|
-
arrayOf: (def, opts) => this.type([def, "[]"], opts),
|
|
148
|
-
keyOf: (def, opts) => this.type(["keyof", def], opts),
|
|
149
|
-
node: (def, opts) => this.type(["node", def], opts),
|
|
150
|
-
instanceOf: (def, opts) => this.type(["instanceof", def], opts),
|
|
151
|
-
valueOf: (def, opts) => this.type(["===", def], opts),
|
|
152
|
-
narrow: (def, fn, opts) => this.type([def, "=>", fn], opts),
|
|
153
|
-
morph: (def, fn, opts) => this.type([def, "|>", fn], opts)
|
|
154
|
-
};
|
|
155
|
-
intersection = this.expressions.intersection;
|
|
156
|
-
union = this.expressions.union;
|
|
157
|
-
arrayOf = this.expressions.arrayOf;
|
|
158
|
-
keyOf = this.expressions.keyOf;
|
|
159
|
-
valueOf = this.expressions.valueOf;
|
|
160
|
-
instanceOf = this.expressions.instanceOf;
|
|
161
|
-
narrow = this.expressions.narrow;
|
|
162
|
-
morph = this.expressions.morph;
|
|
163
|
-
type = Object.assign((def, config = {}) => {
|
|
164
|
-
const t = (0, type_js_1.initializeType)("λtype", def, config, this);
|
|
165
|
-
const ctx = this.#initializeContext(t);
|
|
166
|
-
const root = (0, definition_js_1.parseDefinition)(def, ctx);
|
|
167
|
-
t.node = (0, freeze_js_1.deepFreeze)((0, generics_js_1.hasKeys)(config)
|
|
168
|
-
? { config, node: this.resolveTypeNode(root) }
|
|
169
|
-
: root);
|
|
170
|
-
t.flat = (0, freeze_js_1.deepFreeze)((0, node_js_1.flattenType)(t));
|
|
171
|
-
return t;
|
|
172
|
-
}, { from: this.expressions.node });
|
|
173
|
-
isResolvable(name) {
|
|
174
|
-
return this.#resolutions.has(name) || this.aliases[name];
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
exports.Scope = Scope;
|
|
178
|
-
exports.scope = ((aliases, opts = {}) => new Scope(aliases, opts));
|
|
179
|
-
exports.rootScope = (0, exports.scope)({}, { name: "root", standard: false });
|
|
180
|
-
exports.rootType = exports.rootScope.type;
|
|
181
|
-
const writeShallowCycleErrorMessage = (name, seen) => `Alias '${name}' has a shallow resolution cycle: ${[...seen, name].join("=>")}`;
|
|
182
|
-
exports.writeShallowCycleErrorMessage = writeShallowCycleErrorMessage;
|
|
183
|
-
const writeDuplicateAliasesMessage = (name) => `Alias '${name}' is already defined`;
|
|
184
|
-
exports.writeDuplicateAliasesMessage = writeDuplicateAliasesMessage;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tsKeywords = exports.tsKeywordsScope = void 0;
|
|
4
|
-
const scope_js_1 = require("./scope.js");
|
|
5
|
-
const always = {
|
|
6
|
-
bigint: true,
|
|
7
|
-
boolean: true,
|
|
8
|
-
null: true,
|
|
9
|
-
number: true,
|
|
10
|
-
object: true,
|
|
11
|
-
string: true,
|
|
12
|
-
symbol: true,
|
|
13
|
-
undefined: true
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* @keywords keywords: {"any": "any",
|
|
17
|
-
"bigint": "a bigint",
|
|
18
|
-
"boolean": "a boolean",
|
|
19
|
-
"false": "false",
|
|
20
|
-
"never": "never",
|
|
21
|
-
"null": "null",
|
|
22
|
-
"number": "a number",
|
|
23
|
-
"object": "an object",
|
|
24
|
-
"string": "a string",
|
|
25
|
-
"symbol": "a symbol",
|
|
26
|
-
"true": "true",
|
|
27
|
-
"unknown": "unknown",
|
|
28
|
-
"void": "void",
|
|
29
|
-
"undefined": "undefined"}
|
|
30
|
-
* @docgenScope
|
|
31
|
-
* @docgenTable
|
|
32
|
-
*/
|
|
33
|
-
exports.tsKeywordsScope = (0, scope_js_1.scope)({
|
|
34
|
-
any: ["node", always],
|
|
35
|
-
bigint: ["node", { bigint: true }],
|
|
36
|
-
boolean: ["node", { boolean: true }],
|
|
37
|
-
false: ["node", { boolean: { value: false } }],
|
|
38
|
-
never: ["node", {}],
|
|
39
|
-
null: ["node", { null: true }],
|
|
40
|
-
number: ["node", { number: true }],
|
|
41
|
-
object: ["node", { object: true }],
|
|
42
|
-
string: ["node", { string: true }],
|
|
43
|
-
symbol: ["node", { symbol: true }],
|
|
44
|
-
true: ["node", { boolean: { value: true } }],
|
|
45
|
-
unknown: ["node", always],
|
|
46
|
-
void: ["node", { undefined: true }],
|
|
47
|
-
undefined: ["node", { undefined: true }]
|
|
48
|
-
}, { name: "ts", standard: false });
|
|
49
|
-
exports.tsKeywords = exports.tsKeywordsScope.compile();
|
package/dist/scopes/type.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isAnonymousName = exports.isType = exports.initializeType = void 0;
|
|
4
|
-
const traverse_js_1 = require("../traverse/traverse.js");
|
|
5
|
-
const chainableNoOpProxy_js_1 = require("../utils/chainableNoOpProxy.js");
|
|
6
|
-
const initializeType = (name, definition, config, scope) => {
|
|
7
|
-
const root = {
|
|
8
|
-
// temporarily initialize node/flat to aliases that will be included in
|
|
9
|
-
// the final type in case of cyclic resolutions
|
|
10
|
-
node: name,
|
|
11
|
-
flat: [["alias", name]],
|
|
12
|
-
allows: (data) => !namedTraverse(data).problems,
|
|
13
|
-
assert: (data) => {
|
|
14
|
-
const result = namedTraverse(data);
|
|
15
|
-
return result.problems ? result.problems.throw() : result.data;
|
|
16
|
-
},
|
|
17
|
-
infer: chainableNoOpProxy_js_1.chainableNoOpProxy,
|
|
18
|
-
inferIn: chainableNoOpProxy_js_1.chainableNoOpProxy,
|
|
19
|
-
qualifiedName: (0, exports.isAnonymousName)(name)
|
|
20
|
-
? scope.getAnonymousQualifiedName(name)
|
|
21
|
-
: `${scope.name}.${name}`,
|
|
22
|
-
definition,
|
|
23
|
-
scope,
|
|
24
|
-
includesMorph: false,
|
|
25
|
-
config
|
|
26
|
-
// the "as" symbol from inferred is not used at runtime, so we check
|
|
27
|
-
// that the rest of the type is correct then cast it
|
|
28
|
-
};
|
|
29
|
-
// define within a key to dynamically assign a name to the function
|
|
30
|
-
const namedTraverse = {
|
|
31
|
-
[name]: (data) => (0, traverse_js_1.traverseRoot)(namedTraverse, data)
|
|
32
|
-
}[name];
|
|
33
|
-
const t = Object.assign(namedTraverse, root);
|
|
34
|
-
return t;
|
|
35
|
-
};
|
|
36
|
-
exports.initializeType = initializeType;
|
|
37
|
-
const isType = (value) => value?.infer === chainableNoOpProxy_js_1.chainableNoOpProxy;
|
|
38
|
-
exports.isType = isType;
|
|
39
|
-
const isAnonymousName = (name) => name[0] === "λ";
|
|
40
|
-
exports.isAnonymousName = isAnonymousName;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validation = exports.validationScope = void 0;
|
|
4
|
-
const numericLiterals_js_1 = require("../../utils/numericLiterals.js");
|
|
5
|
-
const scope_js_1 = require("../scope.js");
|
|
6
|
-
const tsKeywords_js_1 = require("../tsKeywords.js");
|
|
7
|
-
const creditCard_js_1 = require("./creditCard.js");
|
|
8
|
-
const date_js_1 = require("./date.js");
|
|
9
|
-
// Non-trivial expressions should have an explanation or attribution
|
|
10
|
-
const parsedNumber = (0, scope_js_1.rootType)([numericLiterals_js_1.wellFormedNumberMatcher, "|>", (s) => parseFloat(s)], { mustBe: "a well-formed numeric string" });
|
|
11
|
-
const parsedInteger = (0, scope_js_1.rootType)([
|
|
12
|
-
tsKeywords_js_1.tsKeywords.string,
|
|
13
|
-
"|>",
|
|
14
|
-
(s, problems) => {
|
|
15
|
-
if (!(0, numericLiterals_js_1.isWellFormedInteger)(s)) {
|
|
16
|
-
return problems.mustBe("a well-formed integer string");
|
|
17
|
-
}
|
|
18
|
-
const parsed = parseInt(s);
|
|
19
|
-
return Number.isSafeInteger(parsed)
|
|
20
|
-
? parsed
|
|
21
|
-
: problems.mustBe("an integer in the range Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER");
|
|
22
|
-
}
|
|
23
|
-
]);
|
|
24
|
-
// https://www.regular-expressions.info/email.html
|
|
25
|
-
const email = (0, scope_js_1.rootType)(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/, {
|
|
26
|
-
mustBe: "a valid email"
|
|
27
|
-
});
|
|
28
|
-
// https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
|
|
29
|
-
const uuid = (0, scope_js_1.rootType)(/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/, { mustBe: "a valid UUID" });
|
|
30
|
-
// https://semver.org/
|
|
31
|
-
const semver = (0, scope_js_1.rootType)(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/, { mustBe: "a valid semantic version (see https://semver.org/)" });
|
|
32
|
-
const json = (0, scope_js_1.rootType)([tsKeywords_js_1.tsKeywords.string, "|>", (s) => JSON.parse(s)], {
|
|
33
|
-
mustBe: "a JSON-parsable string"
|
|
34
|
-
});
|
|
35
|
-
/**
|
|
36
|
-
* @keywords keywords: {
|
|
37
|
-
"alpha": "only letters",
|
|
38
|
-
"alphanumeric": "only letters and digits",
|
|
39
|
-
"lowercase": "only lowercase letters",
|
|
40
|
-
"uppercase": "only uppercase letters",
|
|
41
|
-
"creditCard": "a valid credit card number",
|
|
42
|
-
"email": "a valid email",
|
|
43
|
-
"uuid": "a valid UUID",
|
|
44
|
-
"parsedNumber": "a well-formed numeric string",
|
|
45
|
-
"parsedInteger": "a well-formed integer string",
|
|
46
|
-
"parsedDate": "a valid date",
|
|
47
|
-
"semver": "a valid semantic version",
|
|
48
|
-
"json": "a JSON-parsable string",
|
|
49
|
-
"integer": "an integer"
|
|
50
|
-
}
|
|
51
|
-
* @docgenScope
|
|
52
|
-
* @docgenTable
|
|
53
|
-
*/
|
|
54
|
-
exports.validationScope = (0, scope_js_1.scope)({
|
|
55
|
-
// Character sets
|
|
56
|
-
alpha: [/^[A-Za-z]*$/, ":", { mustBe: "only letters" }],
|
|
57
|
-
alphanumeric: [
|
|
58
|
-
/^[A-Za-z\d]*$/,
|
|
59
|
-
":",
|
|
60
|
-
{ mustBe: "only letters and digits" }
|
|
61
|
-
],
|
|
62
|
-
lowercase: [/^[a-z]*$/, ":", { mustBe: "only lowercase letters" }],
|
|
63
|
-
uppercase: [/^[A-Z]*$/, ":", { mustBe: "only uppercase letters" }],
|
|
64
|
-
creditCard: creditCard_js_1.creditCard,
|
|
65
|
-
email,
|
|
66
|
-
uuid,
|
|
67
|
-
parsedNumber,
|
|
68
|
-
parsedInteger,
|
|
69
|
-
parsedDate: date_js_1.parsedDate,
|
|
70
|
-
semver,
|
|
71
|
-
json,
|
|
72
|
-
integer: ["node", { number: { divisor: 1 } }]
|
|
73
|
-
}, { name: "validation", standard: false });
|
|
74
|
-
exports.validation = exports.validationScope.compile();
|
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compileProblemWriters = exports.defaultProblemWriters = exports.problemCodes = exports.describeBranches = exports.objectKindsToDescriptions = exports.domainsToDescriptions = exports.Problems = exports.Problem = exports.ArkTypeError = void 0;
|
|
4
|
-
const scanner_js_1 = require("../parse/string/shift/scanner.js");
|
|
5
|
-
const data_js_1 = require("../utils/data.js");
|
|
6
|
-
const domains_js_1 = require("../utils/domains.js");
|
|
7
|
-
const generics_js_1 = require("../utils/generics.js");
|
|
8
|
-
const numericLiterals_js_1 = require("../utils/numericLiterals.js");
|
|
9
|
-
const objectKinds_js_1 = require("../utils/objectKinds.js");
|
|
10
|
-
const paths_js_1 = require("../utils/paths.js");
|
|
11
|
-
const serialize_js_1 = require("../utils/serialize.js");
|
|
12
|
-
class ArkTypeError extends TypeError {
|
|
13
|
-
cause;
|
|
14
|
-
constructor(problems) {
|
|
15
|
-
super(`${problems}`);
|
|
16
|
-
this.cause = problems;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.ArkTypeError = ArkTypeError;
|
|
20
|
-
class Problem {
|
|
21
|
-
code;
|
|
22
|
-
path;
|
|
23
|
-
data;
|
|
24
|
-
source;
|
|
25
|
-
writers;
|
|
26
|
-
parts;
|
|
27
|
-
constructor(code, path, data, source, writers) {
|
|
28
|
-
this.code = code;
|
|
29
|
-
this.path = path;
|
|
30
|
-
this.data = data;
|
|
31
|
-
this.source = source;
|
|
32
|
-
this.writers = writers;
|
|
33
|
-
if (this.code === "multi") {
|
|
34
|
-
this.parts = this.source;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
toString() {
|
|
38
|
-
return this.message;
|
|
39
|
-
}
|
|
40
|
-
get message() {
|
|
41
|
-
return this.writers.addContext(this.reason, this.path);
|
|
42
|
-
}
|
|
43
|
-
get reason() {
|
|
44
|
-
return this.writers.writeReason(this.mustBe, new data_js_1.DataWrapper(this.data));
|
|
45
|
-
}
|
|
46
|
-
get mustBe() {
|
|
47
|
-
return typeof this.writers.mustBe === "string"
|
|
48
|
-
? this.writers.mustBe
|
|
49
|
-
: this.writers.mustBe(this.source);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.Problem = Problem;
|
|
53
|
-
class ProblemArray extends Array {
|
|
54
|
-
byPath = {};
|
|
55
|
-
count = 0;
|
|
56
|
-
#state;
|
|
57
|
-
constructor(state) {
|
|
58
|
-
super();
|
|
59
|
-
this.#state = state;
|
|
60
|
-
}
|
|
61
|
-
mustBe(description, opts) {
|
|
62
|
-
return this.add("custom", description, opts);
|
|
63
|
-
}
|
|
64
|
-
add(code, source, opts) {
|
|
65
|
-
// copy the path to avoid future mutations affecting it
|
|
66
|
-
const path = paths_js_1.Path.from(opts?.path ?? this.#state.path);
|
|
67
|
-
const data =
|
|
68
|
-
// we have to check for the presence of the key explicitly since the
|
|
69
|
-
// data could be undefined or null
|
|
70
|
-
opts && "data" in opts
|
|
71
|
-
? opts.data
|
|
72
|
-
: this.#state.data;
|
|
73
|
-
const problem = new Problem(
|
|
74
|
-
// avoid a bunch of errors from TS trying to discriminate the
|
|
75
|
-
// problem input based on the code
|
|
76
|
-
code, path, data, source, this.#state.getProblemConfig(code));
|
|
77
|
-
this.addProblem(problem);
|
|
78
|
-
return problem;
|
|
79
|
-
}
|
|
80
|
-
addProblem(problem) {
|
|
81
|
-
const pathKey = `${problem.path}`;
|
|
82
|
-
const existing = this.byPath[pathKey];
|
|
83
|
-
if (existing) {
|
|
84
|
-
if (existing.parts) {
|
|
85
|
-
existing.parts.push(problem);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
const problemIntersection = new Problem("multi", existing.path, existing.data, [existing, problem], this.#state.getProblemConfig("multi"));
|
|
89
|
-
const existingIndex = this.indexOf(existing);
|
|
90
|
-
// If existing is found (which it always should be unless this was externally mutated),
|
|
91
|
-
// replace it with the new problem intersection. In case it isn't for whatever reason,
|
|
92
|
-
// just append the intersection.
|
|
93
|
-
this[existingIndex === -1 ? this.length : existingIndex] =
|
|
94
|
-
problemIntersection;
|
|
95
|
-
this.byPath[pathKey] = problemIntersection;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
this.byPath[pathKey] = problem;
|
|
100
|
-
this.push(problem);
|
|
101
|
-
}
|
|
102
|
-
this.count++;
|
|
103
|
-
}
|
|
104
|
-
get summary() {
|
|
105
|
-
return `${this}`;
|
|
106
|
-
}
|
|
107
|
-
toString() {
|
|
108
|
-
return this.join("\n");
|
|
109
|
-
}
|
|
110
|
-
throw() {
|
|
111
|
-
throw new ArkTypeError(this);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
exports.Problems = ProblemArray;
|
|
115
|
-
const capitalize = (s) => s[0].toUpperCase() + s.slice(1);
|
|
116
|
-
const domainsToDescriptions = (domains) => domains.map((objectKind) => domains_js_1.domainDescriptions[objectKind]);
|
|
117
|
-
exports.domainsToDescriptions = domainsToDescriptions;
|
|
118
|
-
const objectKindsToDescriptions = (kinds) => kinds.map((objectKind) => objectKinds_js_1.objectKindDescriptions[objectKind]);
|
|
119
|
-
exports.objectKindsToDescriptions = objectKindsToDescriptions;
|
|
120
|
-
const describeBranches = (descriptions) => {
|
|
121
|
-
if (descriptions.length === 0) {
|
|
122
|
-
return "never";
|
|
123
|
-
}
|
|
124
|
-
if (descriptions.length === 1) {
|
|
125
|
-
return descriptions[0];
|
|
126
|
-
}
|
|
127
|
-
let description = "";
|
|
128
|
-
for (let i = 0; i < descriptions.length - 1; i++) {
|
|
129
|
-
description += descriptions[i];
|
|
130
|
-
if (i < descriptions.length - 2) {
|
|
131
|
-
description += ", ";
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
description += ` or ${descriptions[descriptions.length - 1]}`;
|
|
135
|
-
return description;
|
|
136
|
-
};
|
|
137
|
-
exports.describeBranches = describeBranches;
|
|
138
|
-
const writeDefaultReason = (mustBe, was) => `must be ${mustBe}${was && ` (was ${was})`}`;
|
|
139
|
-
const addDefaultContext = (reason, path) => path.length === 0
|
|
140
|
-
? capitalize(reason)
|
|
141
|
-
: path.length === 1 && (0, numericLiterals_js_1.isWellFormedInteger)(path[0])
|
|
142
|
-
? `Item at index ${path[0]} ${reason}`
|
|
143
|
-
: `${path} ${reason}`;
|
|
144
|
-
const defaultProblemConfig = {
|
|
145
|
-
divisor: {
|
|
146
|
-
mustBe: (divisor) => divisor === 1 ? `an integer` : `a multiple of ${divisor}`
|
|
147
|
-
},
|
|
148
|
-
class: {
|
|
149
|
-
mustBe: (expected) => {
|
|
150
|
-
const possibleObjectKind = (0, objectKinds_js_1.getExactConstructorObjectKind)(expected);
|
|
151
|
-
return possibleObjectKind
|
|
152
|
-
? objectKinds_js_1.objectKindDescriptions[possibleObjectKind]
|
|
153
|
-
: `an instance of ${expected.name}`;
|
|
154
|
-
},
|
|
155
|
-
writeReason: (mustBe, data) => writeDefaultReason(mustBe, data.className)
|
|
156
|
-
},
|
|
157
|
-
domain: {
|
|
158
|
-
mustBe: (domain) => domains_js_1.domainDescriptions[domain],
|
|
159
|
-
writeReason: (mustBe, data) => writeDefaultReason(mustBe, data.domain)
|
|
160
|
-
},
|
|
161
|
-
missing: {
|
|
162
|
-
mustBe: () => "defined",
|
|
163
|
-
writeReason: (mustBe) => writeDefaultReason(mustBe, "")
|
|
164
|
-
},
|
|
165
|
-
extraneous: {
|
|
166
|
-
mustBe: () => "removed",
|
|
167
|
-
writeReason: (mustBe) => writeDefaultReason(mustBe, "")
|
|
168
|
-
},
|
|
169
|
-
bound: {
|
|
170
|
-
mustBe: (bound) => `${scanner_js_1.Scanner.comparatorDescriptions[bound.comparator]} ${bound.limit}${bound.units ? ` ${bound.units}` : ""}`,
|
|
171
|
-
writeReason: (mustBe, data) => writeDefaultReason(mustBe, `${data.size}`)
|
|
172
|
-
},
|
|
173
|
-
regex: {
|
|
174
|
-
mustBe: (expression) => `a string matching ${expression}`
|
|
175
|
-
},
|
|
176
|
-
value: {
|
|
177
|
-
mustBe: serialize_js_1.stringify
|
|
178
|
-
},
|
|
179
|
-
branches: {
|
|
180
|
-
mustBe: (branchProblems) => (0, exports.describeBranches)(branchProblems.map((problem) => `${problem.path} must be ${problem.parts
|
|
181
|
-
? (0, exports.describeBranches)(problem.parts.map((part) => part.mustBe))
|
|
182
|
-
: problem.mustBe}`)),
|
|
183
|
-
writeReason: (mustBe, data) => `${mustBe} (was ${data})`,
|
|
184
|
-
addContext: (reason, path) => path.length ? `At ${path}, ${reason}` : reason
|
|
185
|
-
},
|
|
186
|
-
multi: {
|
|
187
|
-
mustBe: (problems) => "• " + problems.map((_) => _.mustBe).join("\n• "),
|
|
188
|
-
writeReason: (mustBe, data) => `${data} must be...\n${mustBe}`,
|
|
189
|
-
addContext: (reason, path) => path.length ? `At ${path}, ${reason}` : reason
|
|
190
|
-
},
|
|
191
|
-
custom: {
|
|
192
|
-
mustBe: (mustBe) => mustBe
|
|
193
|
-
},
|
|
194
|
-
cases: {
|
|
195
|
-
mustBe: (cases) => (0, exports.describeBranches)(cases)
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
exports.problemCodes = (0, generics_js_1.objectKeysOf)(defaultProblemConfig);
|
|
199
|
-
const compileDefaultProblemWriters = () => {
|
|
200
|
-
const result = {};
|
|
201
|
-
let code;
|
|
202
|
-
for (code of exports.problemCodes) {
|
|
203
|
-
result[code] = {
|
|
204
|
-
mustBe: defaultProblemConfig[code].mustBe,
|
|
205
|
-
writeReason: defaultProblemConfig[code].writeReason ??
|
|
206
|
-
writeDefaultReason,
|
|
207
|
-
addContext: defaultProblemConfig[code].addContext ?? addDefaultContext
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
return result;
|
|
211
|
-
};
|
|
212
|
-
exports.defaultProblemWriters = compileDefaultProblemWriters();
|
|
213
|
-
const compileProblemWriters = (input) => {
|
|
214
|
-
if (!input) {
|
|
215
|
-
return exports.defaultProblemWriters;
|
|
216
|
-
}
|
|
217
|
-
const result = {};
|
|
218
|
-
for (const code of exports.problemCodes) {
|
|
219
|
-
result[code] = {
|
|
220
|
-
mustBe: input[code]?.mustBe ??
|
|
221
|
-
defaultProblemConfig[code].mustBe,
|
|
222
|
-
writeReason: input[code]?.writeReason ??
|
|
223
|
-
defaultProblemConfig[code].writeReason ??
|
|
224
|
-
input.writeReason ??
|
|
225
|
-
writeDefaultReason,
|
|
226
|
-
addContext: input[code]?.addContext ??
|
|
227
|
-
defaultProblemConfig[code].addContext ??
|
|
228
|
-
input.addContext ??
|
|
229
|
-
addDefaultContext
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
return result;
|
|
233
|
-
};
|
|
234
|
-
exports.compileProblemWriters = compileProblemWriters;
|