arktype 1.0.10-alpha → 1.0.11-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.
Files changed (84) hide show
  1. package/README.md +22 -4
  2. package/dist/cjs/main.js +26 -24
  3. package/dist/cjs/nodes/branch.js +18 -18
  4. package/dist/cjs/nodes/compose.js +28 -11
  5. package/dist/cjs/nodes/discriminate.js +27 -27
  6. package/dist/cjs/nodes/node.js +24 -24
  7. package/dist/cjs/nodes/predicate.js +17 -17
  8. package/dist/cjs/nodes/rules/class.js +5 -5
  9. package/dist/cjs/nodes/rules/collapsibleSet.js +3 -3
  10. package/dist/cjs/nodes/rules/divisor.js +2 -2
  11. package/dist/cjs/nodes/rules/props.js +19 -19
  12. package/dist/cjs/nodes/rules/range.js +6 -6
  13. package/dist/cjs/nodes/rules/regex.js +3 -3
  14. package/dist/cjs/nodes/rules/rules.js +20 -20
  15. package/dist/cjs/parse/ast/config.js +2 -2
  16. package/dist/cjs/parse/ast/distributableFunction.js +9 -9
  17. package/dist/cjs/parse/ast/intersection.js +5 -5
  18. package/dist/cjs/parse/ast/keyof.js +31 -30
  19. package/dist/cjs/parse/ast/morph.js +10 -10
  20. package/dist/cjs/parse/ast/narrow.js +6 -6
  21. package/dist/cjs/parse/ast/tuple.js +21 -21
  22. package/dist/cjs/parse/definition.js +18 -20
  23. package/dist/cjs/parse/record.js +4 -4
  24. package/dist/cjs/parse/string/reduce/dynamic.js +44 -26
  25. package/dist/cjs/parse/string/reduce/shared.js +2 -2
  26. package/dist/cjs/parse/string/shift/operand/enclosed.js +2 -2
  27. package/dist/cjs/parse/string/shift/operand/operand.js +3 -3
  28. package/dist/cjs/parse/string/shift/operand/unenclosed.js +3 -3
  29. package/dist/cjs/parse/string/shift/operator/bounds.js +18 -18
  30. package/dist/cjs/parse/string/shift/operator/divisor.js +6 -6
  31. package/dist/cjs/parse/string/shift/operator/operator.js +6 -6
  32. package/dist/cjs/parse/string/shift/scanner.js +16 -1
  33. package/dist/cjs/parse/string/string.js +8 -8
  34. package/dist/cjs/scopes/ark.js +15 -15
  35. package/dist/cjs/scopes/cache.js +16 -3
  36. package/dist/cjs/scopes/expressions.js +9 -9
  37. package/dist/cjs/scopes/jsObjects.js +2 -42
  38. package/dist/cjs/scopes/scope.js +59 -31
  39. package/dist/cjs/scopes/tsKeywords.js +2 -2
  40. package/dist/cjs/scopes/type.js +6 -6
  41. package/dist/cjs/scopes/validation/creditCard.js +2 -2
  42. package/dist/cjs/scopes/validation/date.js +4 -4
  43. package/dist/cjs/scopes/validation/validation.js +17 -17
  44. package/dist/cjs/traverse/problems.js +41 -21
  45. package/dist/cjs/traverse/traverse.js +56 -31
  46. package/dist/cjs/utils/data.js +18 -4
  47. package/dist/cjs/utils/generics.js +3 -3
  48. package/dist/cjs/utils/numericLiterals.js +4 -4
  49. package/dist/cjs/utils/objectKinds.js +4 -4
  50. package/dist/cjs/utils/serialize.js +6 -6
  51. package/dist/mjs/main.js +2 -1
  52. package/dist/mjs/nodes/compose.js +17 -0
  53. package/dist/mjs/parse/ast/config.js +5 -1
  54. package/dist/mjs/parse/ast/keyof.js +2 -1
  55. package/dist/mjs/parse/definition.js +0 -1
  56. package/dist/mjs/parse/string/reduce/dynamic.js +18 -0
  57. package/dist/mjs/parse/string/shift/scanner.js +16 -1
  58. package/dist/mjs/scopes/cache.js +14 -1
  59. package/dist/mjs/scopes/expressions.js +88 -8
  60. package/dist/mjs/scopes/jsObjects.js +2 -41
  61. package/dist/mjs/scopes/scope.js +30 -2
  62. package/dist/mjs/scopes/tsKeywords.js +2 -1
  63. package/dist/mjs/scopes/validation/validation.js +2 -1
  64. package/dist/mjs/traverse/problems.js +22 -2
  65. package/dist/mjs/traverse/traverse.js +25 -0
  66. package/dist/mjs/utils/data.js +14 -0
  67. package/dist/tsconfig.temp.tsbuildinfo +1 -1
  68. package/dist/types/main.d.ts +5 -1
  69. package/dist/types/nodes/node.d.ts +6 -0
  70. package/dist/types/parse/ast/bound.d.ts +14 -0
  71. package/dist/types/parse/ast/config.d.ts +5 -0
  72. package/dist/types/parse/ast/divisor.d.ts +5 -0
  73. package/dist/types/parse/definition.d.ts +2 -6
  74. package/dist/types/parse/string/reduce/static.d.ts +12 -2
  75. package/dist/types/parse/string/shift/operand/operand.d.ts +3 -3
  76. package/dist/types/parse/string/shift/operand/unenclosed.d.ts +5 -5
  77. package/dist/types/parse/string/string.d.ts +1 -2
  78. package/dist/types/scopes/ark.d.ts +10 -22
  79. package/dist/types/scopes/expressions.d.ts +88 -0
  80. package/dist/types/scopes/jsObjects.d.ts +2 -11
  81. package/dist/types/scopes/tsKeywords.d.ts +2 -1
  82. package/dist/types/scopes/validation/validation.d.ts +2 -1
  83. package/dist/types/utils/generics.d.ts +1 -1
  84. package/package.json +15 -16
@@ -12,12 +12,12 @@ _export(exports, {
12
12
  collapsibleListUnion: ()=>collapsibleListUnion,
13
13
  listUnion: ()=>listUnion
14
14
  });
15
- const _composeTs = require("../compose.js");
15
+ const _composeJs = require("../compose.js");
16
16
  const collapsibleListUnion = (l, r)=>{
17
17
  if (Array.isArray(l)) {
18
18
  if (Array.isArray(r)) {
19
19
  const result = listUnion(l, r);
20
- return result.length === l.length ? result.length === r.length ? (0, _composeTs.equality)() : l : result.length === r.length ? r : result;
20
+ return result.length === l.length ? result.length === r.length ? (0, _composeJs.equality)() : l : result.length === r.length ? r : result;
21
21
  }
22
22
  return l.includes(r) ? l : [
23
23
  ...l,
@@ -30,7 +30,7 @@ const collapsibleListUnion = (l, r)=>{
30
30
  l
31
31
  ];
32
32
  }
33
- return l === r ? (0, _composeTs.equality)() : [
33
+ return l === r ? (0, _composeJs.equality)() : [
34
34
  l,
35
35
  r
36
36
  ];
@@ -12,8 +12,8 @@ _export(exports, {
12
12
  divisorIntersection: ()=>divisorIntersection,
13
13
  checkDivisor: ()=>checkDivisor
14
14
  });
15
- const _composeTs = require("../compose.js");
16
- const divisorIntersection = (0, _composeTs.composeIntersection)((l, r)=>l === r ? (0, _composeTs.equality)() : Math.abs(l * r / greatestCommonDivisor(l, r)));
15
+ const _composeJs = require("../compose.js");
16
+ const divisorIntersection = (0, _composeJs.composeIntersection)((l, r)=>l === r ? (0, _composeJs.equality)() : Math.abs(l * r / greatestCommonDivisor(l, r)));
17
17
  // https://en.wikipedia.org/wiki/Euclidean_algorithm
18
18
  const greatestCommonDivisor = (l, r)=>{
19
19
  let previous;
@@ -16,8 +16,8 @@ _export(exports, {
16
16
  propsIntersection: ()=>propsIntersection,
17
17
  flattenProps: ()=>flattenProps
18
18
  });
19
- const _composeTs = require("../compose.js");
20
- const _nodeTs = require("../node.js");
19
+ const _composeJs = require("../compose.js");
20
+ const _nodeJs = require("../node.js");
21
21
  const isOptional = (prop)=>prop[0] === "?";
22
22
  const isPrerequisite = (prop)=>prop[0] === "!";
23
23
  const mappedKeys = {
@@ -25,11 +25,11 @@ const mappedKeys = {
25
25
  };
26
26
  const propToNode = (prop)=>isOptional(prop) || isPrerequisite(prop) ? prop[1] : prop;
27
27
  const getTupleLengthIfPresent = (result)=>{
28
- if (typeof result.length === "object" && isPrerequisite(result.length) && typeof result.length[1] !== "string" && (0, _nodeTs.isLiteralNode)(result.length[1], "number")) {
28
+ if (typeof result.length === "object" && isPrerequisite(result.length) && typeof result.length[1] !== "string" && (0, _nodeJs.isLiteralNode)(result.length[1], "number")) {
29
29
  return result.length[1].number.value;
30
30
  }
31
31
  };
32
- const propsIntersection = (0, _composeTs.composeIntersection)((l, r, state)=>{
32
+ const propsIntersection = (0, _composeJs.composeIntersection)((l, r, state)=>{
33
33
  const result = propKeysIntersection(l, r, state);
34
34
  if (typeof result === "symbol") {
35
35
  return result;
@@ -51,28 +51,28 @@ const propsIntersection = (0, _composeTs.composeIntersection)((l, r, state)=>{
51
51
  }
52
52
  const existingNodeAtIndex = propToNode(updatedResult[i]);
53
53
  state.path.push(`${i}`);
54
- const updatedResultAtIndex = (0, _nodeTs.nodeIntersection)(existingNodeAtIndex, indexNode, state);
54
+ const updatedResultAtIndex = (0, _nodeJs.nodeIntersection)(existingNodeAtIndex, indexNode, state);
55
55
  state.path.pop();
56
- if ((0, _composeTs.isDisjoint)(updatedResultAtIndex)) {
56
+ if ((0, _composeJs.isDisjoint)(updatedResultAtIndex)) {
57
57
  return updatedResultAtIndex;
58
- } else if (!(0, _composeTs.isEquality)(updatedResultAtIndex) && updatedResultAtIndex !== existingNodeAtIndex) {
58
+ } else if (!(0, _composeJs.isEquality)(updatedResultAtIndex) && updatedResultAtIndex !== existingNodeAtIndex) {
59
59
  updatedResult[i] = updatedResultAtIndex;
60
60
  }
61
61
  }
62
62
  return updatedResult;
63
63
  });
64
- const propKeysIntersection = (0, _composeTs.composeKeyedIntersection)((propKey, l, r, context)=>{
64
+ const propKeysIntersection = (0, _composeJs.composeKeyedIntersection)((propKey, l, r, context)=>{
65
65
  if (l === undefined) {
66
- return r === undefined ? (0, _composeTs.equality)() : r;
66
+ return r === undefined ? (0, _composeJs.equality)() : r;
67
67
  }
68
68
  if (r === undefined) {
69
69
  return l;
70
70
  }
71
71
  context.path.push(propKey);
72
- const result = (0, _nodeTs.nodeIntersection)(propToNode(l), propToNode(r), context);
72
+ const result = (0, _nodeJs.nodeIntersection)(propToNode(l), propToNode(r), context);
73
73
  context.path.pop();
74
74
  const resultIsOptional = isOptional(l) && isOptional(r);
75
- if ((0, _composeTs.isDisjoint)(result) && resultIsOptional) {
75
+ if ((0, _composeJs.isDisjoint)(result) && resultIsOptional) {
76
76
  // If an optional key has an empty intersection, the type can
77
77
  // still be satisfied as long as the key is not included. Set
78
78
  // the node to never rather than invalidating the type.
@@ -94,14 +94,14 @@ const flattenLooseProps = (entries, props, ctx)=>{
94
94
  if (k === mappedKeys.index) {
95
95
  entries.push([
96
96
  "indexProp",
97
- (0, _nodeTs.flattenNode)(propToNode(prop), ctx)
97
+ (0, _nodeJs.flattenNode)(propToNode(prop), ctx)
98
98
  ]);
99
99
  } else if (isOptional(prop)) {
100
100
  entries.push([
101
101
  "optionalProp",
102
102
  [
103
103
  k,
104
- (0, _nodeTs.flattenNode)(prop[1], ctx)
104
+ (0, _nodeJs.flattenNode)(prop[1], ctx)
105
105
  ]
106
106
  ]);
107
107
  } else if (isPrerequisite(prop)) {
@@ -109,7 +109,7 @@ const flattenLooseProps = (entries, props, ctx)=>{
109
109
  "prerequisiteProp",
110
110
  [
111
111
  k,
112
- (0, _nodeTs.flattenNode)(prop[1], ctx)
112
+ (0, _nodeJs.flattenNode)(prop[1], ctx)
113
113
  ]
114
114
  ]);
115
115
  } else {
@@ -117,7 +117,7 @@ const flattenLooseProps = (entries, props, ctx)=>{
117
117
  "requiredProp",
118
118
  [
119
119
  k,
120
- (0, _nodeTs.flattenNode)(prop, ctx)
120
+ (0, _nodeJs.flattenNode)(prop, ctx)
121
121
  ]
122
122
  ]);
123
123
  }
@@ -136,20 +136,20 @@ const flattenPropsRecord = (kind, entries, props, ctx)=>{
136
136
  const prop = props[k];
137
137
  ctx.path.push(k);
138
138
  if (k === mappedKeys.index) {
139
- result.index = (0, _nodeTs.flattenNode)(propToNode(prop), ctx);
139
+ result.index = (0, _nodeJs.flattenNode)(propToNode(prop), ctx);
140
140
  } else if (isOptional(prop)) {
141
- result.optional[k] = (0, _nodeTs.flattenNode)(prop[1], ctx);
141
+ result.optional[k] = (0, _nodeJs.flattenNode)(prop[1], ctx);
142
142
  } else if (isPrerequisite(prop)) {
143
143
  // we still have to push prerequisite props as normal entries so they can be checked first
144
144
  entries.push([
145
145
  "prerequisiteProp",
146
146
  [
147
147
  k,
148
- (0, _nodeTs.flattenNode)(prop[1], ctx)
148
+ (0, _nodeJs.flattenNode)(prop[1], ctx)
149
149
  ]
150
150
  ]);
151
151
  } else {
152
- result.required[k] = (0, _nodeTs.flattenNode)(prop, ctx);
152
+ result.required[k] = (0, _nodeJs.flattenNode)(prop, ctx);
153
153
  }
154
154
  ctx.path.pop();
155
155
  }
@@ -17,8 +17,8 @@ _export(exports, {
17
17
  checkBound: ()=>checkBound,
18
18
  compareStrictness: ()=>compareStrictness
19
19
  });
20
- const _dataTs = require("../../utils/data.js");
21
- const _composeTs = require("../compose.js");
20
+ const _dataJs = require("../../utils/data.js");
21
+ const _composeJs = require("../compose.js");
22
22
  const minComparators = {
23
23
  ">": true,
24
24
  ">=": true
@@ -28,10 +28,10 @@ const maxComparators = {
28
28
  "<=": true
29
29
  };
30
30
  const isEqualityRange = (range)=>"comparator" in range;
31
- const rangeIntersection = (0, _composeTs.composeIntersection)((l, r, state)=>{
31
+ const rangeIntersection = (0, _composeJs.composeIntersection)((l, r, state)=>{
32
32
  if (isEqualityRange(l)) {
33
33
  if (isEqualityRange(r)) {
34
- return l.limit === r.limit ? (0, _composeTs.equality)() : state.addDisjoint("range", l, r);
34
+ return l.limit === r.limit ? (0, _composeJs.equality)() : state.addDisjoint("range", l, r);
35
35
  }
36
36
  return rangeAllows(r, l.limit) ? l : state.addDisjoint("range", l, r);
37
37
  }
@@ -58,7 +58,7 @@ const rangeIntersection = (0, _composeTs.composeIntersection)((l, r, state)=>{
58
58
  }
59
59
  return r;
60
60
  }
61
- return stricterMax === "l" ? l : stricterMax === "r" ? r : (0, _composeTs.equality)();
61
+ return stricterMax === "l" ? l : stricterMax === "r" ? r : (0, _composeJs.equality)();
62
62
  });
63
63
  const rangeAllows = (range, n)=>isEqualityRange(range) ? n === range.limit : minAllows(range.min, n) && maxAllows(range.max, n);
64
64
  const minAllows = (min, n)=>!min || n > min.limit || n === min.limit && !isExclusive(min.comparator);
@@ -93,7 +93,7 @@ const flattenRange = (entries, range, ctx)=>{
93
93
  ]);
94
94
  }
95
95
  };
96
- const checkBound = (bound, state)=>comparatorCheckers[bound.comparator]((0, _dataTs.sizeOf)(state.data), bound.limit) || !state.problems.add("bound", bound);
96
+ const checkBound = (bound, state)=>comparatorCheckers[bound.comparator]((0, _dataJs.sizeOf)(state.data), bound.limit) || !state.problems.add("bound", bound);
97
97
  const comparatorCheckers = {
98
98
  "<": (size, limit)=>size < limit,
99
99
  ">": (size, limit)=>size > limit,
@@ -13,8 +13,8 @@ _export(exports, {
13
13
  checkRegex: ()=>checkRegex,
14
14
  regexIntersection: ()=>regexIntersection
15
15
  });
16
- const _composeTs = require("../compose.js");
17
- const _collapsibleSetTs = require("./collapsibleSet.js");
16
+ const _composeJs = require("../compose.js");
17
+ const _collapsibleSetJs = require("./collapsibleSet.js");
18
18
  const regexCache = {};
19
19
  const getRegex = (source)=>{
20
20
  if (!regexCache[source]) {
@@ -23,4 +23,4 @@ const getRegex = (source)=>{
23
23
  return regexCache[source];
24
24
  };
25
25
  const checkRegex = (source, state)=>getRegex(source).test(state.data) || !state.problems.add("regex", `/${source}/`);
26
- const regexIntersection = (0, _composeTs.composeIntersection)(_collapsibleSetTs.collapsibleListUnion);
26
+ const regexIntersection = (0, _composeJs.composeIntersection)(_collapsibleSetJs.collapsibleListUnion);
@@ -15,22 +15,22 @@ _export(exports, {
15
15
  precedenceMap: ()=>precedenceMap,
16
16
  literalSatisfiesRules: ()=>literalSatisfiesRules
17
17
  });
18
- const _genericsTs = require("../../utils/generics.js");
19
- const _composeTs = require("../compose.js");
20
- const _classTs = require("./class.js");
21
- const _collapsibleSetTs = require("./collapsibleSet.js");
22
- const _divisorTs = require("./divisor.js");
23
- const _propsTs = require("./props.js");
24
- const _rangeTs = require("./range.js");
25
- const _regexTs = require("./regex.js");
26
- 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);
27
- const narrowIntersection = (0, _composeTs.composeIntersection)(_collapsibleSetTs.collapsibleListUnion);
28
- const narrowableRulesIntersection = (0, _composeTs.composeKeyedIntersection)({
29
- divisor: _divisorTs.divisorIntersection,
30
- regex: _regexTs.regexIntersection,
31
- props: _propsTs.propsIntersection,
32
- class: _classTs.classIntersection,
33
- range: _rangeTs.rangeIntersection,
18
+ const _genericsJs = require("../../utils/generics.js");
19
+ const _composeJs = require("../compose.js");
20
+ const _classJs = require("./class.js");
21
+ const _collapsibleSetJs = require("./collapsibleSet.js");
22
+ const _divisorJs = require("./divisor.js");
23
+ const _propsJs = require("./props.js");
24
+ const _rangeJs = require("./range.js");
25
+ const _regexJs = require("./regex.js");
26
+ const rulesIntersection = (l, r, state)=>"value" in l ? "value" in r ? l.value === r.value ? (0, _composeJs.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);
27
+ const narrowIntersection = (0, _composeJs.composeIntersection)(_collapsibleSetJs.collapsibleListUnion);
28
+ const narrowableRulesIntersection = (0, _composeJs.composeKeyedIntersection)({
29
+ divisor: _divisorJs.divisorIntersection,
30
+ regex: _regexJs.regexIntersection,
31
+ props: _propsJs.propsIntersection,
32
+ class: _classJs.classIntersection,
33
+ range: _rangeJs.rangeIntersection,
34
34
  narrow: narrowIntersection
35
35
  }, {
36
36
  onEmpty: "bubble"
@@ -49,7 +49,7 @@ const flattenRules = (rules, ctx)=>{
49
49
  };
50
50
  const ruleFlatteners = {
51
51
  regex: (entries, rule)=>{
52
- for (const source of (0, _genericsTs.listFrom)(rule)){
52
+ for (const source of (0, _genericsJs.listFrom)(rule)){
53
53
  entries.push([
54
54
  "regex",
55
55
  source
@@ -62,16 +62,16 @@ const ruleFlatteners = {
62
62
  rule
63
63
  ]);
64
64
  },
65
- range: _rangeTs.flattenRange,
65
+ range: _rangeJs.flattenRange,
66
66
  class: (entries, rule)=>{
67
67
  entries.push([
68
68
  "class",
69
69
  rule
70
70
  ]);
71
71
  },
72
- props: _propsTs.flattenProps,
72
+ props: _propsJs.flattenProps,
73
73
  narrow: (entries, rule)=>{
74
- for (const narrow of (0, _genericsTs.listFrom)(rule)){
74
+ for (const narrow of (0, _genericsJs.listFrom)(rule)){
75
75
  entries.push([
76
76
  "narrow",
77
77
  narrow
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "parseConfigTuple", {
6
6
  enumerable: true,
7
7
  get: ()=>parseConfigTuple
8
8
  });
9
- const _definitionTs = require("../definition.js");
9
+ const _definitionJs = require("../definition.js");
10
10
  const parseConfigTuple = (def, ctx)=>({
11
- node: ctx.type.scope.resolveTypeNode((0, _definitionTs.parseDefinition)(def[0], ctx)),
11
+ node: ctx.type.scope.resolveTypeNode((0, _definitionJs.parseDefinition)(def[0], ctx)),
12
12
  config: def[2]
13
13
  });
@@ -12,15 +12,15 @@ _export(exports, {
12
12
  writeMalformedDistributableFunctionMessage: ()=>writeMalformedDistributableFunctionMessage,
13
13
  distributeFunctionToNode: ()=>distributeFunctionToNode
14
14
  });
15
- const _domainsTs = require("../../utils/domains.js");
16
- const _errorsTs = require("../../utils/errors.js");
17
- const _genericsTs = require("../../utils/generics.js");
18
- const _serializeTs = require("../../utils/serialize.js");
19
- const writeMalformedDistributableFunctionMessage = (def)=>`Expected a Function or Record<Domain, Function> operand (${(0, _serializeTs.stringify)(def)} was invalid)`;
15
+ const _domainsJs = require("../../utils/domains.js");
16
+ const _errorsJs = require("../../utils/errors.js");
17
+ const _genericsJs = require("../../utils/generics.js");
18
+ const _serializeJs = require("../../utils/serialize.js");
19
+ const writeMalformedDistributableFunctionMessage = (def)=>`Expected a Function or Record<Domain, Function> operand (${(0, _serializeJs.stringify)(def)} was invalid)`;
20
20
  const distributeFunctionToNode = (distributableFunction, node, ctx, ruleKey)=>{
21
- const domains = (0, _genericsTs.objectKeysOf)(node);
22
- if (!(0, _domainsTs.hasDomain)(distributableFunction, "object")) {
23
- return (0, _errorsTs.throwParseError)(writeMalformedDistributableFunctionMessage(distributableFunction));
21
+ const domains = (0, _genericsJs.objectKeysOf)(node);
22
+ if (!(0, _domainsJs.hasDomain)(distributableFunction, "object")) {
23
+ return (0, _errorsJs.throwParseError)(writeMalformedDistributableFunctionMessage(distributableFunction));
24
24
  }
25
25
  const distributed = {};
26
26
  if (typeof distributableFunction === "function") {
@@ -39,7 +39,7 @@ const distributeFunctionToNode = (distributableFunction, node, ctx, ruleKey)=>{
39
39
  [ruleKey]: distributableFunction[domain]
40
40
  };
41
41
  if (typeof functionInDomain[ruleKey] !== "function") {
42
- return (0, _errorsTs.throwParseError)(writeMalformedDistributableFunctionMessage(functionInDomain));
42
+ return (0, _errorsJs.throwParseError)(writeMalformedDistributableFunctionMessage(functionInDomain));
43
43
  }
44
44
  distributed[domain] = functionInDomain;
45
45
  }
@@ -12,18 +12,18 @@ _export(exports, {
12
12
  compileDisjointReasonsMessage: ()=>compileDisjointReasonsMessage,
13
13
  writeImplicitNeverMessage: ()=>writeImplicitNeverMessage
14
14
  });
15
- const _composeTs = require("../../nodes/compose.js");
16
- const _genericsTs = require("../../utils/generics.js");
15
+ const _composeJs = require("../../nodes/compose.js");
16
+ const _genericsJs = require("../../utils/generics.js");
17
17
  const compileDisjointReasonsMessage = (disjoints)=>{
18
- const paths = (0, _genericsTs.objectKeysOf)(disjoints);
18
+ const paths = (0, _genericsJs.objectKeysOf)(disjoints);
19
19
  if (paths.length === 1) {
20
20
  const path = paths[0];
21
- return `${path === "/" ? "" : `At ${path}: `}Intersection of ${_composeTs.disjointDescriptionWriters[disjoints[path].kind](disjoints[path])} results in an unsatisfiable type`;
21
+ return `${path === "/" ? "" : `At ${path}: `}Intersection of ${_composeJs.disjointDescriptionWriters[disjoints[path].kind](disjoints[path])} results in an unsatisfiable type`;
22
22
  }
23
23
  let message = `
24
24
  "Intersection results in unsatisfiable types at the following paths:\n`;
25
25
  for(const path in disjoints){
26
- message += ` ${path}: ${_composeTs.disjointDescriptionWriters[disjoints[path].kind](disjoints[path])}\n`;
26
+ message += ` ${path}: ${_composeJs.disjointDescriptionWriters[disjoints[path].kind](disjoints[path])}\n`;
27
27
  }
28
28
  return message;
29
29
  };
@@ -6,20 +6,19 @@ Object.defineProperty(exports, "parseKeyOfTuple", {
6
6
  enumerable: true,
7
7
  get: ()=>parseKeyOfTuple
8
8
  });
9
- const _propsTs = require("../../nodes/rules/props.js");
10
- const _errorsTs = require("../../utils/errors.js");
11
- const _freezeTs = require("../../utils/freeze.js");
12
- const _genericsTs = require("../../utils/generics.js");
13
- const _numericLiteralsTs = require("../../utils/numericLiterals.js");
14
- const _objectKindsTs = require("../../utils/objectKinds.js");
15
- const _serializeTs = require("../../utils/serialize.js");
16
- const _definitionTs = require("../definition.js");
17
- const _intersectionTs = require("./intersection.js");
18
- var _keyNode, _keyType, _keyNode1, _keyNode2;
19
- const arrayIndexStringBranch = (0, _freezeTs.deepFreeze)({
20
- regex: _numericLiteralsTs.wellFormedNonNegativeIntegerMatcher.source
9
+ const _propsJs = require("../../nodes/rules/props.js");
10
+ const _errorsJs = require("../../utils/errors.js");
11
+ const _freezeJs = require("../../utils/freeze.js");
12
+ const _genericsJs = require("../../utils/generics.js");
13
+ const _numericLiteralsJs = require("../../utils/numericLiterals.js");
14
+ const _objectKindsJs = require("../../utils/objectKinds.js");
15
+ const _serializeJs = require("../../utils/serialize.js");
16
+ const _definitionJs = require("../definition.js");
17
+ const _intersectionJs = require("./intersection.js");
18
+ const arrayIndexStringBranch = (0, _freezeJs.deepFreeze)({
19
+ regex: _numericLiteralsJs.wellFormedNonNegativeIntegerMatcher.source
21
20
  });
22
- const arrayIndexNumberBranch = (0, _freezeTs.deepFreeze)({
21
+ const arrayIndexNumberBranch = (0, _freezeJs.deepFreeze)({
23
22
  range: {
24
23
  min: {
25
24
  comparator: ">=",
@@ -29,27 +28,29 @@ const arrayIndexNumberBranch = (0, _freezeTs.deepFreeze)({
29
28
  divisor: 1
30
29
  });
31
30
  const parseKeyOfTuple = (def, ctx)=>{
32
- const resolution = ctx.type.scope.resolveNode((0, _definitionTs.parseDefinition)(def[1], ctx));
33
- const predicateKeys = (0, _genericsTs.objectKeysOf)(resolution).map((domain)=>keysOfPredicate(domain, resolution[domain]));
31
+ const resolution = ctx.type.scope.resolveNode((0, _definitionJs.parseDefinition)(def[1], ctx));
32
+ const predicateKeys = (0, _genericsJs.objectKeysOf)(resolution).map((domain)=>keysOfPredicate(domain, resolution[domain]));
34
33
  const sharedKeys = sharedKeysOf(predicateKeys);
35
34
  if (!sharedKeys.length) {
36
- return (0, _intersectionTs.writeImplicitNeverMessage)(ctx.path, "keyof");
35
+ return (0, _intersectionJs.writeImplicitNeverMessage)(ctx.path, "keyof");
37
36
  }
38
37
  const keyNode = {};
39
38
  for (const key of sharedKeys){
40
39
  const keyType = typeof key;
41
40
  if (keyType === "string" || keyType === "number" || keyType === "symbol") {
41
+ var _keyNode, _keyType;
42
42
  (_keyNode = keyNode)[_keyType = keyType] ?? (_keyNode[_keyType] = []);
43
43
  keyNode[keyType].push({
44
44
  value: key
45
45
  });
46
- } else if (key === _numericLiteralsTs.wellFormedNonNegativeIntegerMatcher) {
46
+ } else if (key === _numericLiteralsJs.wellFormedNonNegativeIntegerMatcher) {
47
+ var _keyNode1, _keyNode2;
47
48
  (_keyNode1 = keyNode).string ?? (_keyNode1.string = []);
48
49
  keyNode.string.push(arrayIndexStringBranch);
49
50
  (_keyNode2 = keyNode).number ?? (_keyNode2.number = []);
50
51
  keyNode.number.push(arrayIndexNumberBranch);
51
52
  } else {
52
- return (0, _errorsTs.throwInternalError)(`Unexpected keyof key '${(0, _serializeTs.stringify)(key)}'`);
53
+ return (0, _errorsJs.throwInternalError)(`Unexpected keyof key '${(0, _serializeJs.stringify)(key)}'`);
53
54
  }
54
55
  }
55
56
  return Object.fromEntries(Object.entries(keyNode).map(([domain, branches])=>[
@@ -58,17 +59,17 @@ const parseKeyOfTuple = (def, ctx)=>{
58
59
  ]));
59
60
  };
60
61
  const baseKeysByDomain = {
61
- bigint: (0, _genericsTs.prototypeKeysOf)(0n),
62
- boolean: (0, _genericsTs.prototypeKeysOf)(false),
62
+ bigint: (0, _genericsJs.prototypeKeysOf)(0n),
63
+ boolean: (0, _genericsJs.prototypeKeysOf)(false),
63
64
  null: [],
64
- number: (0, _genericsTs.prototypeKeysOf)(0),
65
+ number: (0, _genericsJs.prototypeKeysOf)(0),
65
66
  // TS doesn't include the Object prototype in keyof, so keyof object is never
66
67
  object: [],
67
- string: (0, _genericsTs.prototypeKeysOf)(""),
68
- symbol: (0, _genericsTs.prototypeKeysOf)(Symbol()),
68
+ string: (0, _genericsJs.prototypeKeysOf)(""),
69
+ symbol: (0, _genericsJs.prototypeKeysOf)(Symbol()),
69
70
  undefined: []
70
71
  };
71
- const keysOfPredicate = (domain, predicate)=>domain !== "object" || predicate === true ? baseKeysByDomain[domain] : sharedKeysOf((0, _genericsTs.listFrom)(predicate).map((branch)=>keysOfObjectBranch(branch)));
72
+ const keysOfPredicate = (domain, predicate)=>domain !== "object" || predicate === true ? baseKeysByDomain[domain] : sharedKeysOf((0, _genericsJs.listFrom)(predicate).map((branch)=>keysOfObjectBranch(branch)));
72
73
  const sharedKeysOf = (keyBranches)=>{
73
74
  if (!keyBranches.length) {
74
75
  return [];
@@ -86,21 +87,21 @@ const keysOfObjectBranch = (branch)=>{
86
87
  const result = [];
87
88
  if ("props" in branch) {
88
89
  for (const key of Object.keys(branch.props)){
89
- if (key === _propsTs.mappedKeys.index) {
90
+ if (key === _propsJs.mappedKeys.index) {
90
91
  // if any number is a valid key push this RegExp
91
- result.push(_numericLiteralsTs.wellFormedNonNegativeIntegerMatcher);
92
+ result.push(_numericLiteralsJs.wellFormedNonNegativeIntegerMatcher);
92
93
  } else if (!result.includes(key)) {
93
94
  result.push(key);
94
- if (_numericLiteralsTs.wellFormedNonNegativeIntegerMatcher.test(key)) {
95
+ if (_numericLiteralsJs.wellFormedNonNegativeIntegerMatcher.test(key)) {
95
96
  // allow numeric access to keys
96
- result.push((0, _numericLiteralsTs.tryParseWellFormedInteger)(key, `Unexpectedly failed to parse an integer from key '${key}'`));
97
+ result.push((0, _numericLiteralsJs.tryParseWellFormedInteger)(key, `Unexpectedly failed to parse an integer from key '${key}'`));
97
98
  }
98
99
  }
99
100
  }
100
101
  }
101
102
  if ("class" in branch) {
102
- const constructor = typeof branch.class === "string" ? _objectKindsTs.defaultObjectKinds[branch.class] : branch.class;
103
- for (const key of (0, _genericsTs.prototypeKeysOf)(constructor.prototype)){
103
+ const constructor = typeof branch.class === "string" ? _objectKindsJs.defaultObjectKinds[branch.class] : branch.class;
104
+ for (const key of (0, _genericsJs.prototypeKeysOf)(constructor.prototype)){
104
105
  if (!result.includes(key)) {
105
106
  result.push(key);
106
107
  }
@@ -12,16 +12,16 @@ _export(exports, {
12
12
  parseMorphTuple: ()=>parseMorphTuple,
13
13
  writeMalformedMorphExpressionMessage: ()=>writeMalformedMorphExpressionMessage
14
14
  });
15
- const _branchTs = require("../../nodes/branch.js");
16
- const _errorsTs = require("../../utils/errors.js");
17
- const _objectKindsTs = require("../../utils/objectKinds.js");
18
- const _serializeTs = require("../../utils/serialize.js");
19
- const _definitionTs = require("../definition.js");
15
+ const _branchJs = require("../../nodes/branch.js");
16
+ const _errorsJs = require("../../utils/errors.js");
17
+ const _objectKindsJs = require("../../utils/objectKinds.js");
18
+ const _serializeJs = require("../../utils/serialize.js");
19
+ const _definitionJs = require("../definition.js");
20
20
  const parseMorphTuple = (def, ctx)=>{
21
21
  if (typeof def[2] !== "function") {
22
- return (0, _errorsTs.throwParseError)(writeMalformedMorphExpressionMessage(def[2]));
22
+ return (0, _errorsJs.throwParseError)(writeMalformedMorphExpressionMessage(def[2]));
23
23
  }
24
- const node = (0, _definitionTs.parseDefinition)(def[0], ctx);
24
+ const node = (0, _definitionJs.parseDefinition)(def[0], ctx);
25
25
  const resolution = ctx.type.scope.resolveTypeNode(node);
26
26
  const morph = def[2];
27
27
  ctx.type.includesMorph = true;
@@ -35,14 +35,14 @@ const parseMorphTuple = (def, ctx)=>{
35
35
  morph
36
36
  };
37
37
  } else if (typeof predicate === "object") {
38
- result[domain] = (0, _objectKindsTs.isArray)(predicate) ? predicate.map((branch)=>applyMorph(branch, morph)) : applyMorph(predicate, morph);
38
+ result[domain] = (0, _objectKindsJs.isArray)(predicate) ? predicate.map((branch)=>applyMorph(branch, morph)) : applyMorph(predicate, morph);
39
39
  } else {
40
- (0, _errorsTs.throwInternalError)(`Unexpected predicate value for domain '${domain}': ${(0, _serializeTs.stringify)(predicate)}`);
40
+ (0, _errorsJs.throwInternalError)(`Unexpected predicate value for domain '${domain}': ${(0, _serializeJs.stringify)(predicate)}`);
41
41
  }
42
42
  }
43
43
  return result;
44
44
  };
45
- const applyMorph = (branch, morph)=>(0, _branchTs.isTransformationBranch)(branch) ? {
45
+ const applyMorph = (branch, morph)=>(0, _branchJs.isTransformationBranch)(branch) ? {
46
46
  ...branch,
47
47
  morph: branch.morph ? Array.isArray(branch.morph) ? [
48
48
  ...branch.morph,
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "parseNarrowTuple", {
6
6
  enumerable: true,
7
7
  get: ()=>parseNarrowTuple
8
8
  });
9
- const _nodeTs = require("../../nodes/node.js");
10
- const _definitionTs = require("../definition.js");
11
- const _distributableFunctionTs = require("./distributableFunction.js");
9
+ const _nodeJs = require("../../nodes/node.js");
10
+ const _definitionJs = require("../definition.js");
11
+ const _distributableFunctionJs = require("./distributableFunction.js");
12
12
  const parseNarrowTuple = (def, ctx)=>{
13
- const inputNode = (0, _definitionTs.parseDefinition)(def[0], ctx);
13
+ const inputNode = (0, _definitionJs.parseDefinition)(def[0], ctx);
14
14
  const resolution = ctx.type.scope.resolveNode(inputNode);
15
- const hasConfig = (0, _nodeTs.isConfigNode)(resolution);
15
+ const hasConfig = (0, _nodeJs.isConfigNode)(resolution);
16
16
  const typeNode = hasConfig ? resolution.node : resolution;
17
- const result = (0, _nodeTs.rootIntersection)(inputNode, (0, _distributableFunctionTs.distributeFunctionToNode)(def[2], typeNode, ctx, "narrow"), ctx.type);
17
+ const result = (0, _nodeJs.rootIntersection)(inputNode, (0, _distributableFunctionJs.distributeFunctionToNode)(def[2], typeNode, ctx, "narrow"), ctx.type);
18
18
  return hasConfig ? {
19
19
  config: resolution.config,
20
20
  node: result
@@ -12,15 +12,15 @@ _export(exports, {
12
12
  parseTuple: ()=>parseTuple,
13
13
  writeMalformedFunctionalExpressionMessage: ()=>writeMalformedFunctionalExpressionMessage
14
14
  });
15
- const _nodeTs = require("../../nodes/node.js");
16
- const _domainsTs = require("../../utils/domains.js");
17
- const _errorsTs = require("../../utils/errors.js");
18
- const _definitionTs = require("../definition.js");
19
- const _unenclosedTs = require("../string/shift/operand/unenclosed.js");
20
- const _configTs = require("./config.js");
21
- const _keyofTs = require("./keyof.js");
22
- const _morphTs = require("./morph.js");
23
- const _narrowTs = require("./narrow.js");
15
+ const _nodeJs = require("../../nodes/node.js");
16
+ const _domainsJs = require("../../utils/domains.js");
17
+ const _errorsJs = require("../../utils/errors.js");
18
+ const _definitionJs = require("../definition.js");
19
+ const _unenclosedJs = require("../string/shift/operand/unenclosed.js");
20
+ const _configJs = require("./config.js");
21
+ const _keyofJs = require("./keyof.js");
22
+ const _morphJs = require("./morph.js");
23
+ const _narrowJs = require("./narrow.js");
24
24
  const parseTuple = (def, ctx)=>{
25
25
  if (isIndexOneExpression(def)) {
26
26
  return indexOneParsers[def[1]](def, ctx);
@@ -43,7 +43,7 @@ const parseTuple = (def, ctx)=>{
43
43
  };
44
44
  for(let i = 0; i < def.length; i++){
45
45
  ctx.path.push(`${i}`);
46
- props[i] = (0, _definitionTs.parseDefinition)(def[i], ctx);
46
+ props[i] = (0, _definitionJs.parseDefinition)(def[i], ctx);
47
47
  ctx.path.pop();
48
48
  }
49
49
  return {
@@ -55,28 +55,28 @@ const parseTuple = (def, ctx)=>{
55
55
  };
56
56
  const parseBranchTuple = (def, ctx)=>{
57
57
  if (def[2] === undefined) {
58
- return (0, _errorsTs.throwParseError)((0, _unenclosedTs.writeMissingRightOperandMessage)(def[1], ""));
58
+ return (0, _errorsJs.throwParseError)((0, _unenclosedJs.writeMissingRightOperandMessage)(def[1], ""));
59
59
  }
60
- const l = (0, _definitionTs.parseDefinition)(def[0], ctx);
61
- const r = (0, _definitionTs.parseDefinition)(def[2], ctx);
62
- return def[1] === "&" ? (0, _nodeTs.rootIntersection)(l, r, ctx.type) : (0, _nodeTs.rootUnion)(l, r, ctx.type);
60
+ const l = (0, _definitionJs.parseDefinition)(def[0], ctx);
61
+ const r = (0, _definitionJs.parseDefinition)(def[2], ctx);
62
+ return def[1] === "&" ? (0, _nodeJs.rootIntersection)(l, r, ctx.type) : (0, _nodeJs.rootUnion)(l, r, ctx.type);
63
63
  };
64
- const parseArrayTuple = (def, scope)=>(0, _nodeTs.toArrayNode)((0, _definitionTs.parseDefinition)(def[0], scope));
64
+ const parseArrayTuple = (def, scope)=>(0, _nodeJs.toArrayNode)((0, _definitionJs.parseDefinition)(def[0], scope));
65
65
  const writeMalformedFunctionalExpressionMessage = (operator, rightDef)=>`Expression requires a function following '${operator}' (was ${typeof rightDef})`;
66
66
  const isIndexOneExpression = (def)=>indexOneParsers[def[1]] !== undefined;
67
67
  const indexOneParsers = {
68
68
  "|": parseBranchTuple,
69
69
  "&": parseBranchTuple,
70
70
  "[]": parseArrayTuple,
71
- "=>": _narrowTs.parseNarrowTuple,
72
- "|>": _morphTs.parseMorphTuple,
73
- ":": _configTs.parseConfigTuple
71
+ "=>": _narrowJs.parseNarrowTuple,
72
+ "|>": _morphJs.parseMorphTuple,
73
+ ":": _configJs.parseConfigTuple
74
74
  };
75
75
  const prefixParsers = {
76
- keyof: _keyofTs.parseKeyOfTuple,
76
+ keyof: _keyofJs.parseKeyOfTuple,
77
77
  instanceof: (def)=>{
78
78
  if (typeof def[1] !== "function") {
79
- return (0, _errorsTs.throwParseError)(`Expected a constructor following 'instanceof' operator (was ${typeof def[1]}).`);
79
+ return (0, _errorsJs.throwParseError)(`Expected a constructor following 'instanceof' operator (was ${typeof def[1]}).`);
80
80
  }
81
81
  return {
82
82
  object: {
@@ -85,7 +85,7 @@ const prefixParsers = {
85
85
  };
86
86
  },
87
87
  "===": (def)=>({
88
- [(0, _domainsTs.domainOf)(def[1])]: {
88
+ [(0, _domainsJs.domainOf)(def[1])]: {
89
89
  value: def[1]
90
90
  }
91
91
  }),