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,82 +0,0 @@
|
|
|
1
|
-
import { scope } from "./scope.js";
|
|
2
|
-
/**
|
|
3
|
-
* @docgenScope
|
|
4
|
-
* @docgenTable
|
|
5
|
-
*/ export const jsObjectsScope = scope({
|
|
6
|
-
Function: [
|
|
7
|
-
"node",
|
|
8
|
-
{
|
|
9
|
-
object: {
|
|
10
|
-
class: Function
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
],
|
|
14
|
-
Date: [
|
|
15
|
-
"node",
|
|
16
|
-
{
|
|
17
|
-
object: {
|
|
18
|
-
class: Date
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
],
|
|
22
|
-
Error: [
|
|
23
|
-
"node",
|
|
24
|
-
{
|
|
25
|
-
object: {
|
|
26
|
-
class: Error
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
],
|
|
30
|
-
Map: [
|
|
31
|
-
"node",
|
|
32
|
-
{
|
|
33
|
-
object: {
|
|
34
|
-
class: Map
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
],
|
|
38
|
-
RegExp: [
|
|
39
|
-
"node",
|
|
40
|
-
{
|
|
41
|
-
object: {
|
|
42
|
-
class: RegExp
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
],
|
|
46
|
-
Set: [
|
|
47
|
-
"node",
|
|
48
|
-
{
|
|
49
|
-
object: {
|
|
50
|
-
class: Set
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
],
|
|
54
|
-
WeakMap: [
|
|
55
|
-
"node",
|
|
56
|
-
{
|
|
57
|
-
object: {
|
|
58
|
-
class: WeakMap
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
],
|
|
62
|
-
WeakSet: [
|
|
63
|
-
"node",
|
|
64
|
-
{
|
|
65
|
-
object: {
|
|
66
|
-
class: WeakSet
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
],
|
|
70
|
-
Promise: [
|
|
71
|
-
"node",
|
|
72
|
-
{
|
|
73
|
-
object: {
|
|
74
|
-
class: Promise
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
]
|
|
78
|
-
}, {
|
|
79
|
-
name: "jsObjects",
|
|
80
|
-
standard: false
|
|
81
|
-
});
|
|
82
|
-
export const jsObjects = jsObjectsScope.compile();
|
package/dist/mjs/scopes/scope.js
DELETED
|
@@ -1,303 +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 _classPrivateMethodGet(receiver, privateSet, fn) {
|
|
42
|
-
if (!privateSet.has(receiver)) {
|
|
43
|
-
throw new TypeError("attempted to get private field on non-instance");
|
|
44
|
-
}
|
|
45
|
-
return fn;
|
|
46
|
-
}
|
|
47
|
-
function _classPrivateMethodInit(obj, privateSet) {
|
|
48
|
-
_checkPrivateRedeclaration(obj, privateSet);
|
|
49
|
-
privateSet.add(obj);
|
|
50
|
-
}
|
|
51
|
-
function _defineProperty(obj, key, value) {
|
|
52
|
-
if (key in obj) {
|
|
53
|
-
Object.defineProperty(obj, key, {
|
|
54
|
-
value: value,
|
|
55
|
-
enumerable: true,
|
|
56
|
-
configurable: true,
|
|
57
|
-
writable: true
|
|
58
|
-
});
|
|
59
|
-
} else {
|
|
60
|
-
obj[key] = value;
|
|
61
|
-
}
|
|
62
|
-
return obj;
|
|
63
|
-
}
|
|
64
|
-
import { flattenType, isConfigNode } from "../nodes/node.js";
|
|
65
|
-
import { parseDefinition } from "../parse/definition.js";
|
|
66
|
-
import { compileProblemWriters } from "../traverse/problems.js";
|
|
67
|
-
import { chainableNoOpProxy } from "../utils/chainableNoOpProxy.js";
|
|
68
|
-
import { throwInternalError, throwParseError } from "../utils/errors.js";
|
|
69
|
-
import { deepFreeze } from "../utils/freeze.js";
|
|
70
|
-
import { hasKeys } from "../utils/generics.js";
|
|
71
|
-
import { Path } from "../utils/paths.js";
|
|
72
|
-
import { Cache, FreezingCache } from "./cache.js";
|
|
73
|
-
import { initializeType } from "./type.js";
|
|
74
|
-
export const compileScopeOptions = (opts)=>({
|
|
75
|
-
codes: compileProblemWriters(opts.codes),
|
|
76
|
-
keys: opts.keys ?? "loose"
|
|
77
|
-
});
|
|
78
|
-
let anonymousScopeCount = 0;
|
|
79
|
-
const scopeRegistry = {};
|
|
80
|
-
const spaceRegistry = {};
|
|
81
|
-
export const isConfigTuple = (def)=>Array.isArray(def) && def[1] === ":";
|
|
82
|
-
var _resolutions = /*#__PURE__*/ new WeakMap(), _exports = /*#__PURE__*/ new WeakMap(), _register = /*#__PURE__*/ new WeakSet(), _cacheSpaces = /*#__PURE__*/ new WeakSet(), _initializeContext = /*#__PURE__*/ new WeakSet(), _resolveRecurse = /*#__PURE__*/ new WeakSet();
|
|
83
|
-
export class Scope {
|
|
84
|
-
getAnonymousQualifiedName(base) {
|
|
85
|
-
let increment = 0;
|
|
86
|
-
let id = base;
|
|
87
|
-
while(this.isResolvable(id)){
|
|
88
|
-
id = `${base}${increment++}`;
|
|
89
|
-
}
|
|
90
|
-
return `${this.name}.${id}`;
|
|
91
|
-
}
|
|
92
|
-
addAnonymousTypeReference(referencedType, ctx) {
|
|
93
|
-
var _ctx_type;
|
|
94
|
-
(_ctx_type = ctx.type).includesMorph || (_ctx_type.includesMorph = referencedType.includesMorph);
|
|
95
|
-
return referencedType.node;
|
|
96
|
-
}
|
|
97
|
-
get infer() {
|
|
98
|
-
return chainableNoOpProxy;
|
|
99
|
-
}
|
|
100
|
-
compile() {
|
|
101
|
-
if (!spaceRegistry[this.name]) {
|
|
102
|
-
for(const name in this.aliases){
|
|
103
|
-
this.resolve(name);
|
|
104
|
-
}
|
|
105
|
-
spaceRegistry[this.name] = _classPrivateFieldGet(this, _exports).root;
|
|
106
|
-
}
|
|
107
|
-
return _classPrivateFieldGet(this, _exports).root;
|
|
108
|
-
}
|
|
109
|
-
addParsedReferenceIfResolvable(name, ctx) {
|
|
110
|
-
var _ctx_type;
|
|
111
|
-
const resolution = _classPrivateMethodGet(this, _resolveRecurse, resolveRecurse).call(this, name, "undefined", [
|
|
112
|
-
name
|
|
113
|
-
]);
|
|
114
|
-
if (!resolution) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
(_ctx_type = ctx.type).includesMorph || (_ctx_type.includesMorph = resolution.includesMorph);
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
resolve(name) {
|
|
121
|
-
return _classPrivateMethodGet(this, _resolveRecurse, resolveRecurse).call(this, name, "throw", [
|
|
122
|
-
name
|
|
123
|
-
]);
|
|
124
|
-
}
|
|
125
|
-
resolveNode(node) {
|
|
126
|
-
return typeof node === "string" ? this.resolveNode(this.resolve(node).node) : node;
|
|
127
|
-
}
|
|
128
|
-
resolveTypeNode(node) {
|
|
129
|
-
const resolution = this.resolveNode(node);
|
|
130
|
-
return isConfigNode(resolution) ? resolution.node : resolution;
|
|
131
|
-
}
|
|
132
|
-
isResolvable(name) {
|
|
133
|
-
return _classPrivateFieldGet(this, _resolutions).has(name) || this.aliases[name];
|
|
134
|
-
}
|
|
135
|
-
constructor(aliases, opts = {}){
|
|
136
|
-
_classPrivateMethodInit(this, _register);
|
|
137
|
-
_classPrivateMethodInit(this, _cacheSpaces);
|
|
138
|
-
_classPrivateMethodInit(this, _initializeContext);
|
|
139
|
-
_classPrivateMethodInit(this, _resolveRecurse);
|
|
140
|
-
_defineProperty(this, "aliases", void 0);
|
|
141
|
-
_defineProperty(this, "name", void 0);
|
|
142
|
-
_defineProperty(this, "config", void 0);
|
|
143
|
-
_defineProperty(this, "parseCache", void 0);
|
|
144
|
-
_classPrivateFieldInit(this, _resolutions, {
|
|
145
|
-
writable: true,
|
|
146
|
-
value: void 0
|
|
147
|
-
});
|
|
148
|
-
_classPrivateFieldInit(this, _exports, {
|
|
149
|
-
writable: true,
|
|
150
|
-
value: void 0
|
|
151
|
-
});
|
|
152
|
-
_defineProperty(this, "expressions", void 0);
|
|
153
|
-
_defineProperty(this, "intersection", void 0);
|
|
154
|
-
_defineProperty(this, "union", void 0);
|
|
155
|
-
_defineProperty(this, "arrayOf", void 0);
|
|
156
|
-
_defineProperty(this, "keyOf", void 0);
|
|
157
|
-
_defineProperty(this, "valueOf", void 0);
|
|
158
|
-
_defineProperty(this, "instanceOf", void 0);
|
|
159
|
-
_defineProperty(this, "narrow", void 0);
|
|
160
|
-
_defineProperty(this, "morph", void 0);
|
|
161
|
-
_defineProperty(this, "type", void 0);
|
|
162
|
-
this.aliases = aliases;
|
|
163
|
-
this.parseCache = new FreezingCache();
|
|
164
|
-
_classPrivateFieldSet(this, _resolutions, new Cache());
|
|
165
|
-
_classPrivateFieldSet(this, _exports, new Cache());
|
|
166
|
-
this.expressions = {
|
|
167
|
-
intersection: (l, r, opts)=>this.type([
|
|
168
|
-
l,
|
|
169
|
-
"&",
|
|
170
|
-
r
|
|
171
|
-
], opts),
|
|
172
|
-
union: (l, r, opts)=>this.type([
|
|
173
|
-
l,
|
|
174
|
-
"|",
|
|
175
|
-
r
|
|
176
|
-
], opts),
|
|
177
|
-
arrayOf: (def, opts)=>this.type([
|
|
178
|
-
def,
|
|
179
|
-
"[]"
|
|
180
|
-
], opts),
|
|
181
|
-
keyOf: (def, opts)=>this.type([
|
|
182
|
-
"keyof",
|
|
183
|
-
def
|
|
184
|
-
], opts),
|
|
185
|
-
node: (def, opts)=>this.type([
|
|
186
|
-
"node",
|
|
187
|
-
def
|
|
188
|
-
], opts),
|
|
189
|
-
instanceOf: (def, opts)=>this.type([
|
|
190
|
-
"instanceof",
|
|
191
|
-
def
|
|
192
|
-
], opts),
|
|
193
|
-
valueOf: (def, opts)=>this.type([
|
|
194
|
-
"===",
|
|
195
|
-
def
|
|
196
|
-
], opts),
|
|
197
|
-
narrow: (def, fn, opts)=>this.type([
|
|
198
|
-
def,
|
|
199
|
-
"=>",
|
|
200
|
-
fn
|
|
201
|
-
], opts),
|
|
202
|
-
morph: (def, fn, opts)=>this.type([
|
|
203
|
-
def,
|
|
204
|
-
"|>",
|
|
205
|
-
fn
|
|
206
|
-
], opts)
|
|
207
|
-
};
|
|
208
|
-
this.intersection = this.expressions.intersection;
|
|
209
|
-
this.union = this.expressions.union;
|
|
210
|
-
this.arrayOf = this.expressions.arrayOf;
|
|
211
|
-
this.keyOf = this.expressions.keyOf;
|
|
212
|
-
this.valueOf = this.expressions.valueOf;
|
|
213
|
-
this.instanceOf = this.expressions.instanceOf;
|
|
214
|
-
this.narrow = this.expressions.narrow;
|
|
215
|
-
this.morph = this.expressions.morph;
|
|
216
|
-
this.type = Object.assign((def, config = {})=>{
|
|
217
|
-
const t = initializeType("λtype", def, config, this);
|
|
218
|
-
const ctx = _classPrivateMethodGet(this, _initializeContext, initializeContext).call(this, t);
|
|
219
|
-
const root = parseDefinition(def, ctx);
|
|
220
|
-
t.node = deepFreeze(hasKeys(config) ? {
|
|
221
|
-
config,
|
|
222
|
-
node: this.resolveTypeNode(root)
|
|
223
|
-
} : root);
|
|
224
|
-
t.flat = deepFreeze(flattenType(t));
|
|
225
|
-
return t;
|
|
226
|
-
}, {
|
|
227
|
-
from: this.expressions.node
|
|
228
|
-
});
|
|
229
|
-
this.name = _classPrivateMethodGet(this, _register, register).call(this, opts);
|
|
230
|
-
if (opts.standard !== false) {
|
|
231
|
-
_classPrivateMethodGet(this, _cacheSpaces, cacheSpaces).call(this, [
|
|
232
|
-
spaceRegistry["standard"]
|
|
233
|
-
], "imports");
|
|
234
|
-
}
|
|
235
|
-
if (opts.imports) {
|
|
236
|
-
_classPrivateMethodGet(this, _cacheSpaces, cacheSpaces).call(this, opts.imports, "imports");
|
|
237
|
-
}
|
|
238
|
-
if (opts.includes) {
|
|
239
|
-
_classPrivateMethodGet(this, _cacheSpaces, cacheSpaces).call(this, opts.includes, "includes");
|
|
240
|
-
}
|
|
241
|
-
this.config = compileScopeOptions(opts);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
function register(opts) {
|
|
245
|
-
const name = opts.name ? scopeRegistry[opts.name] ? throwParseError(`A scope named '${opts.name}' already exists`) : opts.name : `scope${++anonymousScopeCount}`;
|
|
246
|
-
scopeRegistry[name] = this;
|
|
247
|
-
return name;
|
|
248
|
-
}
|
|
249
|
-
function cacheSpaces(spaces, kind) {
|
|
250
|
-
for (const space of spaces){
|
|
251
|
-
for(const name in space){
|
|
252
|
-
if (_classPrivateFieldGet(this, _resolutions).has(name) || name in this.aliases) {
|
|
253
|
-
throwParseError(writeDuplicateAliasesMessage(name));
|
|
254
|
-
}
|
|
255
|
-
_classPrivateFieldGet(this, _resolutions).set(name, space[name]);
|
|
256
|
-
if (kind === "includes") {
|
|
257
|
-
_classPrivateFieldGet(this, _exports).set(name, space[name]);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
function initializeContext(type) {
|
|
263
|
-
return {
|
|
264
|
-
type,
|
|
265
|
-
path: new Path()
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
function resolveRecurse(name, onUnresolvable, seen) {
|
|
269
|
-
const maybeCacheResult = _classPrivateFieldGet(this, _resolutions).get(name);
|
|
270
|
-
if (maybeCacheResult) {
|
|
271
|
-
return maybeCacheResult;
|
|
272
|
-
}
|
|
273
|
-
const aliasDef = this.aliases[name];
|
|
274
|
-
if (!aliasDef) {
|
|
275
|
-
return onUnresolvable === "throw" ? throwInternalError(`Unexpectedly failed to resolve alias '${name}'`) : undefined;
|
|
276
|
-
}
|
|
277
|
-
const t = initializeType(name, aliasDef, {}, this);
|
|
278
|
-
const ctx = _classPrivateMethodGet(this, _initializeContext, initializeContext).call(this, t);
|
|
279
|
-
_classPrivateFieldGet(this, _resolutions).set(name, t);
|
|
280
|
-
_classPrivateFieldGet(this, _exports).set(name, t);
|
|
281
|
-
let node = parseDefinition(aliasDef, ctx);
|
|
282
|
-
if (typeof node === "string") {
|
|
283
|
-
if (seen.includes(node)) {
|
|
284
|
-
return throwParseError(writeShallowCycleErrorMessage(name, seen));
|
|
285
|
-
}
|
|
286
|
-
seen.push(node);
|
|
287
|
-
node = _classPrivateMethodGet(this, _resolveRecurse, resolveRecurse).call(this, node, "throw", seen).node;
|
|
288
|
-
}
|
|
289
|
-
t.node = deepFreeze(node);
|
|
290
|
-
t.flat = deepFreeze(flattenType(t));
|
|
291
|
-
return t;
|
|
292
|
-
}
|
|
293
|
-
export const scope = (aliases, opts = {})=>new Scope(aliases, opts);
|
|
294
|
-
export const rootScope = scope({}, {
|
|
295
|
-
name: "root",
|
|
296
|
-
standard: false
|
|
297
|
-
});
|
|
298
|
-
export const rootType = rootScope.type;
|
|
299
|
-
export const writeShallowCycleErrorMessage = (name, seen)=>`Alias '${name}' has a shallow resolution cycle: ${[
|
|
300
|
-
...seen,
|
|
301
|
-
name
|
|
302
|
-
].join("=>")}`;
|
|
303
|
-
export const writeDuplicateAliasesMessage = (name)=>`Alias '${name}' is already defined`;
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { scope } from "./scope.js";
|
|
2
|
-
const always = {
|
|
3
|
-
bigint: true,
|
|
4
|
-
boolean: true,
|
|
5
|
-
null: true,
|
|
6
|
-
number: true,
|
|
7
|
-
object: true,
|
|
8
|
-
string: true,
|
|
9
|
-
symbol: true,
|
|
10
|
-
undefined: true
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* @keywords keywords: {"any": "any",
|
|
14
|
-
"bigint": "a bigint",
|
|
15
|
-
"boolean": "a boolean",
|
|
16
|
-
"false": "false",
|
|
17
|
-
"never": "never",
|
|
18
|
-
"null": "null",
|
|
19
|
-
"number": "a number",
|
|
20
|
-
"object": "an object",
|
|
21
|
-
"string": "a string",
|
|
22
|
-
"symbol": "a symbol",
|
|
23
|
-
"true": "true",
|
|
24
|
-
"unknown": "unknown",
|
|
25
|
-
"void": "void",
|
|
26
|
-
"undefined": "undefined"}
|
|
27
|
-
* @docgenScope
|
|
28
|
-
* @docgenTable
|
|
29
|
-
*/ export const tsKeywordsScope = scope({
|
|
30
|
-
any: [
|
|
31
|
-
"node",
|
|
32
|
-
always
|
|
33
|
-
],
|
|
34
|
-
bigint: [
|
|
35
|
-
"node",
|
|
36
|
-
{
|
|
37
|
-
bigint: true
|
|
38
|
-
}
|
|
39
|
-
],
|
|
40
|
-
boolean: [
|
|
41
|
-
"node",
|
|
42
|
-
{
|
|
43
|
-
boolean: true
|
|
44
|
-
}
|
|
45
|
-
],
|
|
46
|
-
false: [
|
|
47
|
-
"node",
|
|
48
|
-
{
|
|
49
|
-
boolean: {
|
|
50
|
-
value: false
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
],
|
|
54
|
-
never: [
|
|
55
|
-
"node",
|
|
56
|
-
{}
|
|
57
|
-
],
|
|
58
|
-
null: [
|
|
59
|
-
"node",
|
|
60
|
-
{
|
|
61
|
-
null: true
|
|
62
|
-
}
|
|
63
|
-
],
|
|
64
|
-
number: [
|
|
65
|
-
"node",
|
|
66
|
-
{
|
|
67
|
-
number: true
|
|
68
|
-
}
|
|
69
|
-
],
|
|
70
|
-
object: [
|
|
71
|
-
"node",
|
|
72
|
-
{
|
|
73
|
-
object: true
|
|
74
|
-
}
|
|
75
|
-
],
|
|
76
|
-
string: [
|
|
77
|
-
"node",
|
|
78
|
-
{
|
|
79
|
-
string: true
|
|
80
|
-
}
|
|
81
|
-
],
|
|
82
|
-
symbol: [
|
|
83
|
-
"node",
|
|
84
|
-
{
|
|
85
|
-
symbol: true
|
|
86
|
-
}
|
|
87
|
-
],
|
|
88
|
-
true: [
|
|
89
|
-
"node",
|
|
90
|
-
{
|
|
91
|
-
boolean: {
|
|
92
|
-
value: true
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
],
|
|
96
|
-
unknown: [
|
|
97
|
-
"node",
|
|
98
|
-
always
|
|
99
|
-
],
|
|
100
|
-
void: [
|
|
101
|
-
"node",
|
|
102
|
-
{
|
|
103
|
-
undefined: true
|
|
104
|
-
}
|
|
105
|
-
],
|
|
106
|
-
undefined: [
|
|
107
|
-
"node",
|
|
108
|
-
{
|
|
109
|
-
undefined: true
|
|
110
|
-
}
|
|
111
|
-
]
|
|
112
|
-
}, {
|
|
113
|
-
name: "ts",
|
|
114
|
-
standard: false
|
|
115
|
-
});
|
|
116
|
-
export const tsKeywords = tsKeywordsScope.compile();
|
package/dist/mjs/scopes/type.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { traverseRoot } from "../traverse/traverse.js";
|
|
2
|
-
import { chainableNoOpProxy } from "../utils/chainableNoOpProxy.js";
|
|
3
|
-
export const initializeType = (name, definition, config, scope)=>{
|
|
4
|
-
const root = {
|
|
5
|
-
// temporarily initialize node/flat to aliases that will be included in
|
|
6
|
-
// the final type in case of cyclic resolutions
|
|
7
|
-
node: name,
|
|
8
|
-
flat: [
|
|
9
|
-
[
|
|
10
|
-
"alias",
|
|
11
|
-
name
|
|
12
|
-
]
|
|
13
|
-
],
|
|
14
|
-
allows: (data)=>!namedTraverse(data).problems,
|
|
15
|
-
assert: (data)=>{
|
|
16
|
-
const result = namedTraverse(data);
|
|
17
|
-
return result.problems ? result.problems.throw() : result.data;
|
|
18
|
-
},
|
|
19
|
-
infer: chainableNoOpProxy,
|
|
20
|
-
inferIn: chainableNoOpProxy,
|
|
21
|
-
qualifiedName: isAnonymousName(name) ? scope.getAnonymousQualifiedName(name) : `${scope.name}.${name}`,
|
|
22
|
-
definition,
|
|
23
|
-
scope,
|
|
24
|
-
includesMorph: false,
|
|
25
|
-
config
|
|
26
|
-
};
|
|
27
|
-
// define within a key to dynamically assign a name to the function
|
|
28
|
-
const namedTraverse = {
|
|
29
|
-
[name]: (data)=>traverseRoot(namedTraverse, data)
|
|
30
|
-
}[name];
|
|
31
|
-
const t = Object.assign(namedTraverse, root);
|
|
32
|
-
return t;
|
|
33
|
-
};
|
|
34
|
-
export const isType = (value)=>value?.infer === chainableNoOpProxy;
|
|
35
|
-
export const isAnonymousName = (name)=>name[0] === "λ";
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { wellFormedIntegerMatcher, wellFormedNumberMatcher } from "../../utils/numericLiterals.js";
|
|
2
|
-
import { rootType, scope } from "../scope.js";
|
|
3
|
-
import { tsKeywords } from "../tsKeywords.js";
|
|
4
|
-
import { creditCard } from "./creditCard.js";
|
|
5
|
-
import { parsedDate } from "./date.js";
|
|
6
|
-
// Non-trivial expressions should have an explanation or attribution
|
|
7
|
-
const parsedNumber = rootType([
|
|
8
|
-
wellFormedNumberMatcher,
|
|
9
|
-
"|>",
|
|
10
|
-
(s)=>parseFloat(s)
|
|
11
|
-
], {
|
|
12
|
-
mustBe: "a well-formed numeric string"
|
|
13
|
-
});
|
|
14
|
-
const parsedInteger = rootType([
|
|
15
|
-
wellFormedIntegerMatcher,
|
|
16
|
-
"|>",
|
|
17
|
-
(s)=>parseInt(s)
|
|
18
|
-
], {
|
|
19
|
-
mustBe: "a well-formed integer string"
|
|
20
|
-
});
|
|
21
|
-
// https://www.regular-expressions.info/email.html
|
|
22
|
-
const email = rootType(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/, {
|
|
23
|
-
mustBe: "a valid email"
|
|
24
|
-
});
|
|
25
|
-
// https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
|
|
26
|
-
const uuid = rootType(/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/, {
|
|
27
|
-
mustBe: "a valid UUID"
|
|
28
|
-
});
|
|
29
|
-
// https://semver.org/
|
|
30
|
-
const semver = rootType(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/, {
|
|
31
|
-
mustBe: "a valid semantic version (see https://semver.org/)"
|
|
32
|
-
});
|
|
33
|
-
const json = rootType([
|
|
34
|
-
tsKeywords.string,
|
|
35
|
-
"|>",
|
|
36
|
-
(s)=>JSON.parse(s)
|
|
37
|
-
], {
|
|
38
|
-
mustBe: "a JSON-parsable string"
|
|
39
|
-
});
|
|
40
|
-
/**
|
|
41
|
-
* @keywords keywords: {
|
|
42
|
-
"alpha": "only letters",
|
|
43
|
-
"alphanumeric": "only letters and digits",
|
|
44
|
-
"lowercase": "only lowercase letters",
|
|
45
|
-
"uppercase": "only uppercase letters",
|
|
46
|
-
"creditCard": "a valid credit card number",
|
|
47
|
-
"email": "a valid email",
|
|
48
|
-
"uuid": "a valid UUID",
|
|
49
|
-
"parsedNumber": "a well-formed numeric string",
|
|
50
|
-
"parsedInteger": "a well-formed integer string",
|
|
51
|
-
"parsedDate": "a valid date",
|
|
52
|
-
"semver": "a valid semantic version",
|
|
53
|
-
"json": "a JSON-parsable string",
|
|
54
|
-
"integer": "an integer"
|
|
55
|
-
}
|
|
56
|
-
* @docgenScope
|
|
57
|
-
* @docgenTable
|
|
58
|
-
*/ export const validationScope = scope({
|
|
59
|
-
// Character sets
|
|
60
|
-
alpha: [
|
|
61
|
-
/^[A-Za-z]*$/,
|
|
62
|
-
":",
|
|
63
|
-
{
|
|
64
|
-
mustBe: "only letters"
|
|
65
|
-
}
|
|
66
|
-
],
|
|
67
|
-
alphanumeric: [
|
|
68
|
-
/^[A-Za-z\d]*$/,
|
|
69
|
-
":",
|
|
70
|
-
{
|
|
71
|
-
mustBe: "only letters and digits"
|
|
72
|
-
}
|
|
73
|
-
],
|
|
74
|
-
lowercase: [
|
|
75
|
-
/^[a-z]*$/,
|
|
76
|
-
":",
|
|
77
|
-
{
|
|
78
|
-
mustBe: "only lowercase letters"
|
|
79
|
-
}
|
|
80
|
-
],
|
|
81
|
-
uppercase: [
|
|
82
|
-
/^[A-Z]*$/,
|
|
83
|
-
":",
|
|
84
|
-
{
|
|
85
|
-
mustBe: "only uppercase letters"
|
|
86
|
-
}
|
|
87
|
-
],
|
|
88
|
-
creditCard,
|
|
89
|
-
email,
|
|
90
|
-
uuid,
|
|
91
|
-
parsedNumber,
|
|
92
|
-
parsedInteger,
|
|
93
|
-
parsedDate,
|
|
94
|
-
semver,
|
|
95
|
-
json,
|
|
96
|
-
integer: [
|
|
97
|
-
"node",
|
|
98
|
-
{
|
|
99
|
-
number: {
|
|
100
|
-
divisor: 1
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
]
|
|
104
|
-
}, {
|
|
105
|
-
name: "validation",
|
|
106
|
-
standard: false
|
|
107
|
-
});
|
|
108
|
-
export const validation = validationScope.compile();
|