arktype 0.1.2 → 0.1.3
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/dist/cjs/main.js +127 -15
- package/dist/cjs/nodes/branches.js +7 -7
- package/dist/cjs/nodes/compose.js +3 -2
- package/dist/cjs/nodes/discriminate.js +5 -4
- package/dist/cjs/nodes/functors.js +3 -3
- package/dist/cjs/nodes/node.js +1 -1
- package/dist/cjs/nodes/predicate.js +19 -14
- package/dist/cjs/nodes/rules/collapsibleSet.js +3 -4
- package/dist/cjs/nodes/rules/objectKind.js +78 -0
- package/dist/cjs/nodes/rules/range.js +2 -2
- package/dist/cjs/nodes/rules/rules.js +4 -4
- package/dist/cjs/parse/definition.js +26 -6
- package/dist/cjs/parse/string/shift/operator/bounds.js +1 -1
- package/dist/cjs/parse/tuple/morph.js +2 -2
- package/dist/cjs/parse/tuple/tuple.js +1 -1
- package/dist/cjs/traverse/problems.js +18 -32
- package/dist/cjs/traverse/traverse.js +12 -12
- package/dist/cjs/utils/domains.js +10 -47
- package/dist/cjs/utils/generics.js +1 -3
- package/dist/cjs/utils/objectKinds.js +64 -0
- package/dist/cjs/utils/size.js +16 -0
- package/dist/mjs/main.js +127 -15
- package/dist/mjs/nodes/branches.js +7 -7
- package/dist/mjs/nodes/compose.js +3 -2
- package/dist/mjs/nodes/discriminate.js +6 -5
- package/dist/mjs/nodes/functors.js +3 -3
- package/dist/mjs/nodes/node.js +1 -1
- package/dist/mjs/nodes/predicate.js +20 -15
- package/dist/mjs/nodes/rules/collapsibleSet.js +3 -4
- package/dist/mjs/nodes/rules/{subdomain.js → objectKind.js} +10 -10
- package/dist/mjs/nodes/rules/range.js +1 -1
- package/dist/mjs/nodes/rules/rules.js +4 -4
- package/dist/mjs/parse/definition.js +27 -7
- package/dist/mjs/parse/string/shift/operator/bounds.js +1 -1
- package/dist/mjs/parse/tuple/morph.js +2 -2
- package/dist/mjs/parse/tuple/tuple.js +1 -1
- package/dist/mjs/traverse/problems.js +18 -31
- package/dist/mjs/traverse/traverse.js +12 -12
- package/dist/mjs/utils/domains.js +9 -42
- package/dist/mjs/utils/generics.js +0 -1
- package/dist/mjs/utils/objectKinds.js +48 -0
- package/dist/mjs/utils/size.js +2 -0
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/dist/types/main.d.ts +73 -9
- package/dist/types/nodes/branches.d.ts +4 -4
- package/dist/types/nodes/compose.d.ts +12 -5
- package/dist/types/nodes/discriminate.d.ts +3 -2
- package/dist/types/nodes/infer.d.ts +11 -10
- package/dist/types/nodes/predicate.d.ts +2 -2
- package/dist/types/nodes/rules/objectKind.d.ts +15 -0
- package/dist/types/nodes/rules/range.d.ts +1 -1
- package/dist/types/nodes/rules/rules.d.ts +4 -4
- package/dist/types/parse/definition.d.ts +6 -5
- package/dist/types/parse/string/ast.d.ts +4 -2
- package/dist/types/parse/string/reduce/shared.d.ts +1 -1
- package/dist/types/parse/string/shift/operator/bounds.d.ts +1 -1
- package/dist/types/traverse/problems.d.ts +25 -41
- package/dist/types/traverse/traverse.d.ts +24 -4
- package/dist/types/utils/domains.d.ts +11 -37
- package/dist/types/utils/generics.d.ts +0 -1
- package/dist/types/utils/objectKinds.d.ts +83 -0
- package/dist/types/utils/size.d.ts +3 -0
- package/package.json +4 -4
- package/dist/cjs/nodes/rules/subdomain.js +0 -78
- package/dist/types/nodes/rules/subdomain.d.ts +0 -15
package/dist/cjs/main.js
CHANGED
|
@@ -109,7 +109,7 @@ const scopeRegistry = {};
|
|
|
109
109
|
var _resolutions = /*#__PURE__*/ new WeakMap(), _exports = /*#__PURE__*/ new WeakMap(), _anonymousTypeCount = /*#__PURE__*/ new WeakMap(), _register = /*#__PURE__*/ new WeakSet(), _cacheSpaces = /*#__PURE__*/ new WeakSet(), _initializeContext = /*#__PURE__*/ new WeakSet(), _compiled = /*#__PURE__*/ new WeakMap(), _resolveRecurse = /*#__PURE__*/ new WeakSet();
|
|
110
110
|
class Scope {
|
|
111
111
|
createAnonymousTypeName() {
|
|
112
|
-
return `
|
|
112
|
+
return `type${++_classPrivateFieldUpdate(this, _anonymousTypeCount).value}`;
|
|
113
113
|
}
|
|
114
114
|
get infer() {
|
|
115
115
|
return _chainableNoOpProxyJs.chainableNoOpProxy;
|
|
@@ -242,10 +242,10 @@ function resolveRecurse(name, onUnresolvable, seen) {
|
|
|
242
242
|
}
|
|
243
243
|
// TODO: merge scope options
|
|
244
244
|
const initializeType = (definition, opts, scope)=>{
|
|
245
|
-
const name = opts.name ??
|
|
245
|
+
const name = opts.name ?? "type";
|
|
246
246
|
const meta = {
|
|
247
247
|
name,
|
|
248
|
-
id: `${scope.name}.${name}`,
|
|
248
|
+
id: `${scope.name}.${opts.name ? name : scope.createAnonymousTypeName()}`,
|
|
249
249
|
definition,
|
|
250
250
|
scope,
|
|
251
251
|
problems: (0, _problemsTs.compileProblemOptions)(opts.problems),
|
|
@@ -322,7 +322,7 @@ const always = {
|
|
|
322
322
|
undefined: true
|
|
323
323
|
};
|
|
324
324
|
const scope = (aliases, opts = {})=>new Scope(aliases, opts);
|
|
325
|
-
const
|
|
325
|
+
const tsKeywords = scope({
|
|
326
326
|
any: [
|
|
327
327
|
"node",
|
|
328
328
|
always
|
|
@@ -404,21 +404,130 @@ const ts = scope({
|
|
|
404
404
|
{
|
|
405
405
|
undefined: true
|
|
406
406
|
}
|
|
407
|
-
]
|
|
408
|
-
|
|
407
|
+
]
|
|
408
|
+
}, {
|
|
409
|
+
name: "ts",
|
|
410
|
+
standard: false
|
|
411
|
+
});
|
|
412
|
+
const tsKeywordsSpace = tsKeywords.compile();
|
|
413
|
+
const jsObjects = scope({
|
|
409
414
|
Function: [
|
|
410
415
|
"node",
|
|
411
416
|
{
|
|
412
417
|
object: {
|
|
413
|
-
|
|
418
|
+
objectKind: "Function"
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
],
|
|
422
|
+
Array: [
|
|
423
|
+
"node",
|
|
424
|
+
{
|
|
425
|
+
object: {
|
|
426
|
+
objectKind: "Array"
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
],
|
|
430
|
+
Date: [
|
|
431
|
+
"node",
|
|
432
|
+
{
|
|
433
|
+
object: {
|
|
434
|
+
objectKind: "Date"
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
],
|
|
438
|
+
Error: [
|
|
439
|
+
"node",
|
|
440
|
+
{
|
|
441
|
+
object: {
|
|
442
|
+
objectKind: "Error"
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
],
|
|
446
|
+
Map: [
|
|
447
|
+
"node",
|
|
448
|
+
{
|
|
449
|
+
object: {
|
|
450
|
+
objectKind: "Map"
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
],
|
|
454
|
+
RegExp: [
|
|
455
|
+
"node",
|
|
456
|
+
{
|
|
457
|
+
object: {
|
|
458
|
+
objectKind: "RegExp"
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
],
|
|
462
|
+
Set: [
|
|
463
|
+
"node",
|
|
464
|
+
{
|
|
465
|
+
object: {
|
|
466
|
+
objectKind: "Set"
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
],
|
|
470
|
+
Object: [
|
|
471
|
+
"node",
|
|
472
|
+
{
|
|
473
|
+
object: {
|
|
474
|
+
objectKind: "Object"
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
],
|
|
478
|
+
String: [
|
|
479
|
+
"node",
|
|
480
|
+
{
|
|
481
|
+
object: {
|
|
482
|
+
objectKind: "String"
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
],
|
|
486
|
+
Number: [
|
|
487
|
+
"node",
|
|
488
|
+
{
|
|
489
|
+
object: {
|
|
490
|
+
objectKind: "Number"
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
],
|
|
494
|
+
Boolean: [
|
|
495
|
+
"node",
|
|
496
|
+
{
|
|
497
|
+
object: {
|
|
498
|
+
objectKind: "Boolean"
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
],
|
|
502
|
+
WeakMap: [
|
|
503
|
+
"node",
|
|
504
|
+
{
|
|
505
|
+
object: {
|
|
506
|
+
objectKind: "WeakMap"
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
],
|
|
510
|
+
WeakSet: [
|
|
511
|
+
"node",
|
|
512
|
+
{
|
|
513
|
+
object: {
|
|
514
|
+
objectKind: "WeakSet"
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
],
|
|
518
|
+
Promise: [
|
|
519
|
+
"node",
|
|
520
|
+
{
|
|
521
|
+
object: {
|
|
522
|
+
objectKind: "Promise"
|
|
414
523
|
}
|
|
415
524
|
}
|
|
416
525
|
]
|
|
417
526
|
}, {
|
|
418
|
-
name: "
|
|
527
|
+
name: "jsObjects",
|
|
419
528
|
standard: false
|
|
420
529
|
});
|
|
421
|
-
const
|
|
530
|
+
const jsObjectsSpace = jsObjects.compile();
|
|
422
531
|
const validation = scope({
|
|
423
532
|
email: /^(.+)@(.+)\.(.+)$/,
|
|
424
533
|
alphanumeric: /^[dA-Za-z]+$/,
|
|
@@ -437,24 +546,27 @@ const validation = scope({
|
|
|
437
546
|
name: "validation",
|
|
438
547
|
standard: false
|
|
439
548
|
});
|
|
440
|
-
const
|
|
549
|
+
const validationSpace = validation.compile();
|
|
441
550
|
const standard = scope({}, {
|
|
442
551
|
name: "standard",
|
|
443
552
|
includes: [
|
|
444
|
-
|
|
445
|
-
|
|
553
|
+
tsKeywordsSpace,
|
|
554
|
+
jsObjectsSpace,
|
|
555
|
+
validationSpace
|
|
446
556
|
],
|
|
447
557
|
standard: false
|
|
448
558
|
});
|
|
449
559
|
const standardTypes = standard.compile();
|
|
450
560
|
const scopes = {
|
|
451
|
-
|
|
561
|
+
tsKeywords,
|
|
562
|
+
jsObjects,
|
|
452
563
|
validation,
|
|
453
564
|
standard
|
|
454
565
|
};
|
|
455
566
|
const spaces = {
|
|
456
|
-
|
|
457
|
-
|
|
567
|
+
tsKeywords: tsKeywordsSpace,
|
|
568
|
+
jsObjects: jsObjectsSpace,
|
|
569
|
+
validation: validationSpace,
|
|
458
570
|
standard: standardTypes
|
|
459
571
|
};
|
|
460
572
|
const type = scopes.standard.type;
|
|
@@ -16,13 +16,13 @@ const _domainsTs = require("../utils/domains.js");
|
|
|
16
16
|
const _errorsTs = require("../utils/errors.js");
|
|
17
17
|
const _composeTs = require("./compose.js");
|
|
18
18
|
const _rulesTs = require("./rules/rules.js");
|
|
19
|
-
const isBranchComparison = (comparison)=>comparison?.
|
|
19
|
+
const isBranchComparison = (comparison)=>comparison?.lBranches !== undefined;
|
|
20
20
|
const compareBranches = (lConditions, rConditions, state)=>{
|
|
21
21
|
const result = {
|
|
22
|
-
lConditions,
|
|
23
|
-
rConditions,
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
lBranches: lConditions,
|
|
23
|
+
rBranches: rConditions,
|
|
24
|
+
lExtendsR: [],
|
|
25
|
+
rExtendsL: [],
|
|
26
26
|
equalities: [],
|
|
27
27
|
distinctIntersections: []
|
|
28
28
|
};
|
|
@@ -42,14 +42,14 @@ const compareBranches = (lConditions, rConditions, state)=>{
|
|
|
42
42
|
// doesn't tell us about any redundancies or add a distinct pair
|
|
43
43
|
return null;
|
|
44
44
|
} else if (subresult === l) {
|
|
45
|
-
result.
|
|
45
|
+
result.lExtendsR.push(lIndex);
|
|
46
46
|
// If l is a subtype of the current r branch, intersections
|
|
47
47
|
// with the remaining branches of r won't lead to distinct
|
|
48
48
|
// branches, so we set a flag indicating we can skip them.
|
|
49
49
|
lImpliesR = true;
|
|
50
50
|
return null;
|
|
51
51
|
} else if (subresult === r) {
|
|
52
|
-
result.
|
|
52
|
+
result.rExtendsL.push(rIndex);
|
|
53
53
|
// If r is a subtype of the current l branch, it is removed
|
|
54
54
|
// from pairsByR because future intersections won't lead to
|
|
55
55
|
// distinct branches.
|
|
@@ -68,13 +68,14 @@ const composeIntersection = (reducer)=>(l, r, state)=>l === undefined ? r === un
|
|
|
68
68
|
const throwUndefinedOperandsError = ()=>(0, _errorsTs.throwInternalError)(`Unexpected operation two undefined operands`);
|
|
69
69
|
const disjointDescriptionWriters = {
|
|
70
70
|
domain: ({ l , r })=>`${l.join(", ")} and ${r.join(", ")}`,
|
|
71
|
-
|
|
71
|
+
objectKind: ({ l , r })=>`${l} and ${r}`,
|
|
72
72
|
range: ({ l , r })=>`${stringifyRange(l)} and ${stringifyRange(r)}`,
|
|
73
73
|
class: ({ l , r })=>`classes ${l.name} and ${r.name}`,
|
|
74
74
|
tupleLength: ({ l , r })=>`tuples of length ${l} and ${r}`,
|
|
75
75
|
value: ({ l , r })=>`literal values ${(0, _serializeTs.serialize)(l)} and ${(0, _serializeTs.serialize)(r)}`,
|
|
76
76
|
leftAssignability: ({ l , r })=>`literal value ${(0, _serializeTs.serialize)(l.value)} and ${(0, _serializeTs.serialize)(r)}`,
|
|
77
|
-
rightAssignability: ({ l , r })=>`literal value ${(0, _serializeTs.serialize)(r.value)} and ${(0, _serializeTs.serialize)(l)}
|
|
77
|
+
rightAssignability: ({ l , r })=>`literal value ${(0, _serializeTs.serialize)(r.value)} and ${(0, _serializeTs.serialize)(l)}`,
|
|
78
|
+
union: ({ l , r })=>`branches ${(0, _serializeTs.serialize)(l)} and branches ${(0, _serializeTs.serialize)(r)}`
|
|
78
79
|
};
|
|
79
80
|
const stringifyRange = (range)=>"limit" in range ? `the range of exactly ${range.limit}` : range.min ? range.max ? `the range bounded by ${range.min.comparator}${range.min.limit} and ${range.max.comparator}${range.max.limit}` : `${range.min.comparator}${range.min.limit}` : range.max ? `${range.max.comparator}${range.max.limit}` : "the unbounded range";
|
|
80
81
|
var _disjoints = /*#__PURE__*/ new WeakMap();
|
|
@@ -17,6 +17,7 @@ const _astTs = require("../parse/string/ast.js");
|
|
|
17
17
|
const _domainsTs = require("../utils/domains.js");
|
|
18
18
|
const _errorsTs = require("../utils/errors.js");
|
|
19
19
|
const _genericsTs = require("../utils/generics.js");
|
|
20
|
+
const _objectKindsTs = require("../utils/objectKinds.js");
|
|
20
21
|
const _pathsTs = require("../utils/paths.js");
|
|
21
22
|
const _serializeTs = require("../utils/serialize.js");
|
|
22
23
|
const _composeTs = require("./compose.js");
|
|
@@ -59,7 +60,7 @@ const discriminate = (originalBranches, remainingIndices, discriminants, ctx)=>{
|
|
|
59
60
|
};
|
|
60
61
|
const discriminantKinds = {
|
|
61
62
|
domain: true,
|
|
62
|
-
|
|
63
|
+
objectKind: true,
|
|
63
64
|
value: true
|
|
64
65
|
};
|
|
65
66
|
const calculateDiscriminants = (branches, ctx)=>{
|
|
@@ -76,7 +77,7 @@ const calculateDiscriminants = (branches, ctx)=>{
|
|
|
76
77
|
const intersectionState = new _composeTs.IntersectionState(ctx.type, "|");
|
|
77
78
|
(0, _rulesTs.branchIntersection)(branches[lIndex], branches[rIndex], intersectionState);
|
|
78
79
|
for(const path in intersectionState.disjoints){
|
|
79
|
-
// designed to match
|
|
80
|
+
// designed to match objectKind path segments like "${number}"
|
|
80
81
|
if (path.includes("${")) {
|
|
81
82
|
continue;
|
|
82
83
|
}
|
|
@@ -191,9 +192,9 @@ const serializeIfPrimitive = (data)=>{
|
|
|
191
192
|
};
|
|
192
193
|
const caseSerializers = {
|
|
193
194
|
value: (data)=>serializeIfPrimitive(data) ?? "default",
|
|
194
|
-
|
|
195
|
+
objectKind: (data)=>(0, _objectKindsTs.objectKindOf)(data) ?? "default",
|
|
195
196
|
domain: _domainsTs.domainOf
|
|
196
197
|
};
|
|
197
198
|
const serializeCase = (kind, data)=>caseSerializers[kind](data);
|
|
198
199
|
const branchIncludesMorph = (branch, $)=>"morph" in branch ? true : "props" in branch ? Object.values(branch.props).some((prop)=>nodeIncludesMorph((0, _propsTs.isOptional)(prop) ? prop[1] : prop, $)) : false;
|
|
199
|
-
const nodeIncludesMorph = (node, $)=>typeof node === "string" ? $.resolve(node).meta.includesMorph : Object.values(node).some((predicate)=>predicate === true ? false : (0,
|
|
200
|
+
const nodeIncludesMorph = (node, $)=>typeof node === "string" ? $.resolve(node).meta.includesMorph : Object.values(node).some((predicate)=>predicate === true ? false : (0, _objectKindsTs.isArray)(predicate) ? predicate.some((branch)=>branchIncludesMorph(branch, $)) : branchIncludesMorph(predicate, $));
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "functors", {
|
|
|
9
9
|
const functors = {
|
|
10
10
|
Array: (node)=>({
|
|
11
11
|
object: {
|
|
12
|
-
|
|
12
|
+
objectKind: [
|
|
13
13
|
"Array",
|
|
14
14
|
node
|
|
15
15
|
]
|
|
@@ -17,7 +17,7 @@ const functors = {
|
|
|
17
17
|
}),
|
|
18
18
|
Set: (node)=>({
|
|
19
19
|
object: {
|
|
20
|
-
|
|
20
|
+
objectKind: [
|
|
21
21
|
"Set",
|
|
22
22
|
node
|
|
23
23
|
]
|
|
@@ -25,7 +25,7 @@ const functors = {
|
|
|
25
25
|
}),
|
|
26
26
|
Map: (k, v)=>({
|
|
27
27
|
object: {
|
|
28
|
-
|
|
28
|
+
objectKind: [
|
|
29
29
|
"Map",
|
|
30
30
|
k,
|
|
31
31
|
v
|
package/dist/cjs/nodes/node.js
CHANGED
|
@@ -61,7 +61,7 @@ const union = (l, r, type)=>{
|
|
|
61
61
|
}
|
|
62
62
|
return result;
|
|
63
63
|
};
|
|
64
|
-
const hasImpliedDomain = (flatPredicate)=>flatPredicate[0] && (flatPredicate[0][0] === "
|
|
64
|
+
const hasImpliedDomain = (flatPredicate)=>flatPredicate[0] && (flatPredicate[0][0] === "objectKind" || flatPredicate[0][0] === "value");
|
|
65
65
|
const flattenType = (type)=>{
|
|
66
66
|
const ctx = {
|
|
67
67
|
type,
|
|
@@ -16,8 +16,8 @@ _export(exports, {
|
|
|
16
16
|
isLiteralCondition: ()=>isLiteralCondition,
|
|
17
17
|
resolutionExtendsDomain: ()=>resolutionExtendsDomain
|
|
18
18
|
});
|
|
19
|
-
const _domainsTs = require("../utils/domains.js");
|
|
20
19
|
const _genericsTs = require("../utils/generics.js");
|
|
20
|
+
const _objectKindsTs = require("../utils/objectKinds.js");
|
|
21
21
|
const _branchesTs = require("./branches.js");
|
|
22
22
|
const _composeTs = require("./compose.js");
|
|
23
23
|
const _discriminateTs = require("./discriminate.js");
|
|
@@ -27,7 +27,7 @@ const comparePredicates = (l, r, context)=>{
|
|
|
27
27
|
if (l === true && r === true) {
|
|
28
28
|
return (0, _composeTs.equality)();
|
|
29
29
|
}
|
|
30
|
-
if (!(0,
|
|
30
|
+
if (!(0, _objectKindsTs.isArray)(l) && !(0, _objectKindsTs.isArray)(r)) {
|
|
31
31
|
const result = (0, _rulesTs.branchIntersection)(emptyRulesIfTrue(l), emptyRulesIfTrue(r), context);
|
|
32
32
|
return result === l ? l : result === r ? r : result;
|
|
33
33
|
}
|
|
@@ -37,10 +37,10 @@ const comparePredicates = (l, r, context)=>{
|
|
|
37
37
|
if (comparison.equalities.length === lBranches.length && comparison.equalities.length === rBranches.length) {
|
|
38
38
|
return (0, _composeTs.equality)();
|
|
39
39
|
}
|
|
40
|
-
if (comparison.
|
|
40
|
+
if (comparison.lExtendsR.length + comparison.equalities.length === lBranches.length) {
|
|
41
41
|
return l;
|
|
42
42
|
}
|
|
43
|
-
if (comparison.
|
|
43
|
+
if (comparison.rExtendsL.length + comparison.equalities.length === rBranches.length) {
|
|
44
44
|
return r;
|
|
45
45
|
}
|
|
46
46
|
return comparison;
|
|
@@ -51,12 +51,16 @@ const predicateIntersection = (domain, l, r, state)=>{
|
|
|
51
51
|
if (!(0, _branchesTs.isBranchComparison)(comparison)) {
|
|
52
52
|
return comparison;
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
const resultBranches = [
|
|
55
55
|
...comparison.distinctIntersections,
|
|
56
|
-
...comparison.equalities.map((indices)=>comparison.
|
|
57
|
-
...comparison.
|
|
58
|
-
...comparison.
|
|
59
|
-
]
|
|
56
|
+
...comparison.equalities.map((indices)=>comparison.lBranches[indices[0]]),
|
|
57
|
+
...comparison.lExtendsR.map((lIndex)=>comparison.lBranches[lIndex]),
|
|
58
|
+
...comparison.rExtendsL.map((rIndex)=>comparison.rBranches[rIndex])
|
|
59
|
+
];
|
|
60
|
+
if (resultBranches.length === 0) {
|
|
61
|
+
state.addDisjoint("union", comparison.lBranches, comparison.rBranches);
|
|
62
|
+
}
|
|
63
|
+
return resultBranches.length === 1 ? resultBranches[0] : resultBranches;
|
|
60
64
|
};
|
|
61
65
|
const predicateUnion = (domain, l, r, type)=>{
|
|
62
66
|
const state = new _composeTs.IntersectionState(type, "|");
|
|
@@ -69,16 +73,17 @@ const predicateUnion = (domain, l, r, type)=>{
|
|
|
69
73
|
emptyRulesIfTrue(r)
|
|
70
74
|
];
|
|
71
75
|
}
|
|
72
|
-
|
|
73
|
-
...comparison.
|
|
74
|
-
...comparison.
|
|
75
|
-
]
|
|
76
|
+
const resultBranches = [
|
|
77
|
+
...comparison.lBranches.filter((_, lIndex)=>!comparison.lExtendsR.includes(lIndex) && !comparison.equalities.some((indexPair)=>indexPair[0] === lIndex)),
|
|
78
|
+
...comparison.rBranches.filter((_, rIndex)=>!comparison.rExtendsL.includes(rIndex) && !comparison.equalities.some((indexPair)=>indexPair[1] === rIndex))
|
|
79
|
+
];
|
|
80
|
+
return resultBranches.length === 1 ? resultBranches[0] : resultBranches;
|
|
76
81
|
};
|
|
77
82
|
const flattenPredicate = (predicate, context)=>{
|
|
78
83
|
if (predicate === true) {
|
|
79
84
|
return [];
|
|
80
85
|
}
|
|
81
|
-
return (0,
|
|
86
|
+
return (0, _objectKindsTs.isArray)(predicate) ? (0, _discriminateTs.flattenBranches)(predicate, context) : (0, _rulesTs.flattenBranch)(predicate, context);
|
|
82
87
|
};
|
|
83
88
|
const isLiteralCondition = (predicate)=>typeof predicate === "object" && "value" in predicate;
|
|
84
89
|
const resolutionExtendsDomain = (resolution, domain)=>{
|
|
@@ -12,11 +12,10 @@ _export(exports, {
|
|
|
12
12
|
collapsibleListUnion: ()=>collapsibleListUnion,
|
|
13
13
|
listUnion: ()=>listUnion
|
|
14
14
|
});
|
|
15
|
-
const _domainsTs = require("../../utils/domains.js");
|
|
16
15
|
const _composeTs = require("../compose.js");
|
|
17
16
|
const collapsibleListUnion = (l, r)=>{
|
|
18
|
-
if (
|
|
19
|
-
if (
|
|
17
|
+
if (Array.isArray(l)) {
|
|
18
|
+
if (Array.isArray(r)) {
|
|
20
19
|
const result = listUnion(l, r);
|
|
21
20
|
return result.length === l.length ? result.length === r.length ? (0, _composeTs.equality)() : l : result.length === r.length ? r : result;
|
|
22
21
|
}
|
|
@@ -25,7 +24,7 @@ const collapsibleListUnion = (l, r)=>{
|
|
|
25
24
|
r
|
|
26
25
|
];
|
|
27
26
|
}
|
|
28
|
-
if (
|
|
27
|
+
if (Array.isArray(r)) {
|
|
29
28
|
return r.includes(l) ? r : [
|
|
30
29
|
...r,
|
|
31
30
|
l
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
objectKindIntersection: ()=>objectKindIntersection,
|
|
13
|
+
objectKindPathSegments: ()=>objectKindPathSegments,
|
|
14
|
+
flattenObjectKind: ()=>flattenObjectKind
|
|
15
|
+
});
|
|
16
|
+
const _errorsJs = require("../../utils/errors.js");
|
|
17
|
+
const _composeJs = require("../compose.js");
|
|
18
|
+
const _nodeJs = require("../node.js");
|
|
19
|
+
const objectKindIntersection = (0, _composeJs.composeIntersection)((l, r, state)=>{
|
|
20
|
+
if (typeof l === "string") {
|
|
21
|
+
if (typeof r === "string") {
|
|
22
|
+
return l === r ? (0, _composeJs.equality)() : state.addDisjoint("objectKind", l, r);
|
|
23
|
+
}
|
|
24
|
+
return l === r[0] ? r : state.addDisjoint("objectKind", l, r[0]);
|
|
25
|
+
}
|
|
26
|
+
if (typeof r === "string") {
|
|
27
|
+
return l[0] === r ? l : state.addDisjoint("objectKind", l[0], r);
|
|
28
|
+
}
|
|
29
|
+
if (l[0] !== r[0]) {
|
|
30
|
+
return state.addDisjoint("objectKind", l[0], r[0]);
|
|
31
|
+
}
|
|
32
|
+
const result = [
|
|
33
|
+
l[0]
|
|
34
|
+
];
|
|
35
|
+
let lImpliesR = true;
|
|
36
|
+
let rImpliesL = true;
|
|
37
|
+
for(let i = 1; i < l.length; i++){
|
|
38
|
+
const lNode = l[i];
|
|
39
|
+
const rNode = r[i];
|
|
40
|
+
state.path.push(objectKindParameterToPathSegment(l[0], i));
|
|
41
|
+
const parameterResult = (0, _nodeJs.nodeIntersection)(lNode, rNode, state);
|
|
42
|
+
state.path.pop();
|
|
43
|
+
if ((0, _composeJs.isEquality)(parameterResult)) {
|
|
44
|
+
result[i] = lNode;
|
|
45
|
+
} else if (parameterResult === l) {
|
|
46
|
+
result[i] = lNode;
|
|
47
|
+
rImpliesL = false;
|
|
48
|
+
} else if (parameterResult === r) {
|
|
49
|
+
result[i] = rNode;
|
|
50
|
+
lImpliesR = false;
|
|
51
|
+
} else if ((0, _composeJs.isDisjoint)(parameterResult)) {
|
|
52
|
+
return parameterResult;
|
|
53
|
+
} else {
|
|
54
|
+
result[i] = parameterResult;
|
|
55
|
+
lImpliesR = false;
|
|
56
|
+
rImpliesL = false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return lImpliesR ? rImpliesL ? (0, _composeJs.equality)() : l : rImpliesL ? r : result;
|
|
60
|
+
});
|
|
61
|
+
const objectKindParameterToPathSegment = (objectKind, i)=>objectKind === "Array" ? "${number}" : objectKind === "Set" ? "${item}" : objectKind === "Map" ? i === 1 ? "${key}" : "${value}" : (0, _errorsJs.throwInternalError)(`Unexpected parameterized objectKind '${objectKind}'`);
|
|
62
|
+
const objectKindPathSegments = {
|
|
63
|
+
"${number}": true,
|
|
64
|
+
"${item}": true,
|
|
65
|
+
"${key}": true,
|
|
66
|
+
"${value}": true
|
|
67
|
+
};
|
|
68
|
+
const flattenObjectKind = (entries, rule, ctx)=>entries.push([
|
|
69
|
+
"objectKind",
|
|
70
|
+
typeof rule === "string" ? rule : rule[0] === "Map" ? [
|
|
71
|
+
rule[0],
|
|
72
|
+
(0, _nodeJs.flattenNode)(rule[1], ctx),
|
|
73
|
+
(0, _nodeJs.flattenNode)(rule[2], ctx)
|
|
74
|
+
] : [
|
|
75
|
+
rule[0],
|
|
76
|
+
(0, _nodeJs.flattenNode)(rule[1], ctx)
|
|
77
|
+
]
|
|
78
|
+
]);
|
|
@@ -17,7 +17,7 @@ _export(exports, {
|
|
|
17
17
|
checkBound: ()=>checkBound,
|
|
18
18
|
compareStrictness: ()=>compareStrictness
|
|
19
19
|
});
|
|
20
|
-
const
|
|
20
|
+
const _sizeTs = require("../../utils/size.js");
|
|
21
21
|
const _composeTs = require("../compose.js");
|
|
22
22
|
const minComparators = {
|
|
23
23
|
">": true,
|
|
@@ -94,7 +94,7 @@ const flattenRange = (entries, range, ctx)=>{
|
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
const checkBound = (data, bound, state)=>{
|
|
97
|
-
if (!comparatorCheckers[bound.comparator]((0,
|
|
97
|
+
if (!comparatorCheckers[bound.comparator]((0, _sizeTs.sizeOf)(data), bound.limit)) {
|
|
98
98
|
state.problems.add("bound", data, bound);
|
|
99
99
|
}
|
|
100
100
|
};
|
|
@@ -23,10 +23,10 @@ const _composeTs = require("../compose.js");
|
|
|
23
23
|
const _classTs = require("./class.js");
|
|
24
24
|
const _collapsibleSetTs = require("./collapsibleSet.js");
|
|
25
25
|
const _divisorTs = require("./divisor.js");
|
|
26
|
+
const _objectKindTs = require("./objectKind.js");
|
|
26
27
|
const _propsTs = require("./props.js");
|
|
27
28
|
const _rangeTs = require("./range.js");
|
|
28
29
|
const _regexTs = require("./regex.js");
|
|
29
|
-
const _subdomainTs = require("./subdomain.js");
|
|
30
30
|
const rulesOf = (branch)=>branch.input ?? branch;
|
|
31
31
|
const branchIntersection = (l, r, state)=>{
|
|
32
32
|
const lRules = rulesOf(l);
|
|
@@ -58,7 +58,7 @@ const branchIntersection = (l, r, state)=>{
|
|
|
58
58
|
const rulesIntersection = (l, r, state)=>"value" in l ? "value" in r ? l.value === r.value ? (0, _composeTs.equality)() : state.addDisjoint("value", l.value, r.value) : literalSatisfiesRules(l.value, r, state) ? l : state.addDisjoint("leftAssignability", l, r) : "value" in r ? literalSatisfiesRules(r.value, l, state) ? r : state.addDisjoint("rightAssignability", l, r) : narrowableRulesIntersection(l, r, state);
|
|
59
59
|
const narrowIntersection = (0, _composeTs.composeIntersection)(_collapsibleSetTs.collapsibleListUnion);
|
|
60
60
|
const narrowableRulesIntersection = (0, _composeTs.composeKeyedIntersection)({
|
|
61
|
-
|
|
61
|
+
objectKind: _objectKindTs.objectKindIntersection,
|
|
62
62
|
divisor: _divisorTs.divisorIntersection,
|
|
63
63
|
regex: _regexTs.regexIntersection,
|
|
64
64
|
props: _propsTs.propsIntersection,
|
|
@@ -69,7 +69,7 @@ const narrowableRulesIntersection = (0, _composeTs.composeKeyedIntersection)({
|
|
|
69
69
|
onEmpty: "bubble"
|
|
70
70
|
});
|
|
71
71
|
const ruleFlatteners = {
|
|
72
|
-
|
|
72
|
+
objectKind: _objectKindTs.flattenObjectKind,
|
|
73
73
|
regex: (entries, rule)=>{
|
|
74
74
|
for (const source of (0, _genericsTs.listFrom)(rule)){
|
|
75
75
|
entries.push([
|
|
@@ -113,7 +113,7 @@ const precedenceMap = {
|
|
|
113
113
|
value: 0,
|
|
114
114
|
domains: 0,
|
|
115
115
|
branches: 0,
|
|
116
|
-
|
|
116
|
+
objectKind: 0,
|
|
117
117
|
switch: 0,
|
|
118
118
|
alias: 0,
|
|
119
119
|
// Shallow: All shallow checks will be performed even if one or more fail
|
|
@@ -17,16 +17,36 @@ _export(exports, {
|
|
|
17
17
|
const _mainTs = require("../main.js");
|
|
18
18
|
const _domainsTs = require("../utils/domains.js");
|
|
19
19
|
const _errorsTs = require("../utils/errors.js");
|
|
20
|
+
const _objectKindsTs = require("../utils/objectKinds.js");
|
|
21
|
+
const _serializeTs = require("../utils/serialize.js");
|
|
20
22
|
const _recordTs = require("./record.js");
|
|
21
23
|
const _stringTs = require("./string/string.js");
|
|
22
24
|
const _tupleTs = require("./tuple/tuple.js");
|
|
23
25
|
const parseDefinition = (def, ctx)=>{
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const domain = (0, _domainsTs.domainOf)(def);
|
|
27
|
+
if (domain === "string") {
|
|
28
|
+
return (0, _stringTs.parseString)(def, ctx);
|
|
29
|
+
}
|
|
30
|
+
if (domain !== "object") {
|
|
31
|
+
return (0, _errorsTs.throwParseError)(writeBadDefinitionTypeMessage(domain));
|
|
32
|
+
}
|
|
33
|
+
const objectKind = (0, _objectKindsTs.objectKindOf)(def);
|
|
34
|
+
switch(objectKind){
|
|
35
|
+
case "Object":
|
|
36
|
+
return (0, _recordTs.parseRecord)(def, ctx);
|
|
37
|
+
case "Array":
|
|
38
|
+
return (0, _tupleTs.parseTuple)(def, ctx);
|
|
39
|
+
case "RegExp":
|
|
40
|
+
return {
|
|
41
|
+
string: {
|
|
42
|
+
regex: def.source
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
case "Function":
|
|
46
|
+
return (0, _mainTs.isType)(def) ? def.node : (0, _errorsTs.throwParseError)(writeBadDefinitionTypeMessage("Function"));
|
|
47
|
+
default:
|
|
48
|
+
return (0, _errorsTs.throwParseError)(writeBadDefinitionTypeMessage(objectKind ?? (0, _serializeTs.stringify)(def)));
|
|
49
|
+
}
|
|
30
50
|
};
|
|
31
51
|
const as = Symbol("as");
|
|
32
52
|
const unknownDefinitionMessage = "Cannot statically parse a definition inferred as unknown. Consider using 'as inferred<...>' to cast it.";
|
|
@@ -71,7 +71,7 @@ const distributeRange = (range, s)=>{
|
|
|
71
71
|
if (resolution.object === true) {
|
|
72
72
|
return false;
|
|
73
73
|
}
|
|
74
|
-
return (0, _genericsTs.listFrom)(resolution.object).every((branch)=>(0, _genericsTs.hasKey)(branch, "
|
|
74
|
+
return (0, _genericsTs.listFrom)(resolution.object).every((branch)=>(0, _genericsTs.hasKey)(branch, "objectKind") && (branch.objectKind === "Array" || branch.objectKind[0] === "Array"));
|
|
75
75
|
default:
|
|
76
76
|
return false;
|
|
77
77
|
}
|
|
@@ -12,8 +12,8 @@ _export(exports, {
|
|
|
12
12
|
parseMorphTuple: ()=>parseMorphTuple,
|
|
13
13
|
writeMalformedMorphExpressionMessage: ()=>writeMalformedMorphExpressionMessage
|
|
14
14
|
});
|
|
15
|
-
const _domainsTs = require("../../utils/domains.js");
|
|
16
15
|
const _errorsTs = require("../../utils/errors.js");
|
|
16
|
+
const _objectKindsTs = require("../../utils/objectKinds.js");
|
|
17
17
|
const _serializeTs = require("../../utils/serialize.js");
|
|
18
18
|
const _definitionTs = require("../definition.js");
|
|
19
19
|
const parseMorphTuple = (def, ctx)=>{
|
|
@@ -33,7 +33,7 @@ const parseMorphTuple = (def, ctx)=>{
|
|
|
33
33
|
morph
|
|
34
34
|
};
|
|
35
35
|
} else if (typeof predicate === "object") {
|
|
36
|
-
result[domain] = (0,
|
|
36
|
+
result[domain] = (0, _objectKindsTs.isArray)(predicate) ? predicate.map((branch)=>applyMorph(branch, morph)) : applyMorph(predicate, morph);
|
|
37
37
|
} else {
|
|
38
38
|
(0, _errorsTs.throwInternalError)(`Unexpected predicate value for domain '${domain}': ${(0, _serializeTs.stringify)(predicate)}`);
|
|
39
39
|
}
|