arktype 1.0.10-alpha → 1.0.12-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 (85) 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 +57 -32
  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 +23 -3
  65. package/dist/mjs/traverse/traverse.js +26 -1
  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/traverse/problems.d.ts +1 -1
  84. package/dist/types/utils/generics.d.ts +1 -1
  85. package/package.json +15 -16
package/README.md CHANGED
@@ -19,7 +19,7 @@
19
19
  <!-- @snipEnd -->
20
20
 
21
21
  ```ts @blockFrom:dev/examples/type.ts
22
- import { type } from "arktype"
22
+ import { type } from "../../src/main.js"
23
23
 
24
24
  // Definitions are statically parsed and inferred as TS.
25
25
  export const user = type({
@@ -52,10 +52,10 @@ Check out [how it works](#how), [try it in-browser](https://arktype.io/docs/#you
52
52
  <sub>(or whatever package manager you prefer)</sub>
53
53
  <br />
54
54
 
55
- <img src="./dev/arktype.io/static/img/deno.svg" alt="Deno Icon" height="16px" /> <code>import { type } from "https://deno.land/x/arktype/main.ts"</code>
56
-
57
55
  Our types are tested in [strict-mode](https://www.typescriptlang.org/tsconfig#strict) with TypeScript versions `4.8`, `4.9`, and `5.0`.
58
56
 
57
+ If you're using VSCode, setting `"editor.quickSuggestions"` to `{"strings": true}` will improve its autocomplete suggestions.
58
+
59
59
  _Our APIs have mostly stabilized, but details may still change during the alpha/beta stages of our 1.0 release. If you have suggestions that may require a breaking change, now is the time to let us know!_ ⛵
60
60
 
61
61
  <!-- @snipEnd -->
@@ -65,7 +65,7 @@ _Our APIs have mostly stabilized, but details may still change during the alpha/
65
65
  [Try this example in-browser.](https://arktype.io/docs/scopes)
66
66
 
67
67
  ```ts @blockFrom:dev/examples/scope.ts
68
- import { scope } from "arktype"
68
+ import { scope } from "../../src/main.js"
69
69
 
70
70
  // Scopes are collections of types that can reference each other.
71
71
  export const types = scope({
@@ -105,6 +105,24 @@ In the meantime, check out the examples here and use the type hints you get to l
105
105
 
106
106
  <!--@snipEnd -->
107
107
 
108
+ ## Integrations
109
+
110
+ ### tRPC
111
+
112
+ ArkType can easily be used with tRPC via the `assert` prop:
113
+
114
+ ```ts
115
+ ...
116
+ t.procedure
117
+ .input(
118
+ type({
119
+ name: "string",
120
+ "age?": "number"
121
+ }).assert
122
+ )
123
+ ...
124
+ ```
125
+
108
126
  ## How?
109
127
 
110
128
  ArkType's isomorphic parser has parallel static and dynamic implementations. This means as soon as you type a definition in your editor, you'll know the eventual result at runtime.
package/dist/cjs/main.js CHANGED
@@ -9,28 +9,30 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- scope: ()=>_scopeTs.scope,
13
- type: ()=>_arkTs.type,
14
- ark: ()=>_arkTs.ark,
15
- arkScope: ()=>_arkTs.arkScope,
16
- intersection: ()=>_expressionsTs.intersection,
17
- union: ()=>_expressionsTs.union,
18
- arrayOf: ()=>_expressionsTs.arrayOf,
19
- instanceOf: ()=>_expressionsTs.instanceOf,
20
- valueOf: ()=>_expressionsTs.valueOf,
21
- morph: ()=>_expressionsTs.morph,
22
- narrow: ()=>_expressionsTs.narrow,
23
- keyOf: ()=>_expressionsTs.keyOf,
24
- jsObjectsScope: ()=>_jsObjectsTs.jsObjectsScope,
25
- tsKeywordsScope: ()=>_tsKeywordsTs.tsKeywordsScope,
26
- validationScope: ()=>_validationTs.validationScope,
27
- Problems: ()=>_problemsTs.Problems,
28
- Problem: ()=>_problemsTs.Problem
12
+ scope: ()=>_scopeJs.scope,
13
+ type: ()=>_arkJs.type,
14
+ ark: ()=>_arkJs.ark,
15
+ arkScope: ()=>_arkJs.arkScope,
16
+ arrayOf: ()=>_expressionsJs.arrayOf,
17
+ instanceOf: ()=>_expressionsJs.instanceOf,
18
+ intersection: ()=>_expressionsJs.intersection,
19
+ keyOf: ()=>_expressionsJs.keyOf,
20
+ morph: ()=>_expressionsJs.morph,
21
+ narrow: ()=>_expressionsJs.narrow,
22
+ union: ()=>_expressionsJs.union,
23
+ valueOf: ()=>_expressionsJs.valueOf,
24
+ jsObjectsScope: ()=>_jsObjectsJs.jsObjectsScope,
25
+ tsKeywordsScope: ()=>_tsKeywordsJs.tsKeywordsScope,
26
+ validationScope: ()=>_validationJs.validationScope,
27
+ Problems: ()=>_problemsJs.Problems,
28
+ Problem: ()=>_problemsJs.Problem,
29
+ parseConfigTuple: ()=>_configJs.parseConfigTuple
29
30
  });
30
- const _scopeTs = require("./scopes/scope.js");
31
- const _arkTs = require("./scopes/ark.js");
32
- const _expressionsTs = require("./scopes/expressions.js");
33
- const _jsObjectsTs = require("./scopes/jsObjects.js");
34
- const _tsKeywordsTs = require("./scopes/tsKeywords.js");
35
- const _validationTs = require("./scopes/validation/validation.js");
36
- const _problemsTs = require("./traverse/problems.js");
31
+ const _scopeJs = require("./scopes/scope.js");
32
+ const _arkJs = require("./scopes/ark.js");
33
+ const _expressionsJs = require("./scopes/expressions.js");
34
+ const _jsObjectsJs = require("./scopes/jsObjects.js");
35
+ const _tsKeywordsJs = require("./scopes/tsKeywords.js");
36
+ const _validationJs = require("./scopes/validation/validation.js");
37
+ const _problemsJs = require("./traverse/problems.js");
38
+ const _configJs = require("./parse/ast/config.js");
@@ -15,11 +15,11 @@ _export(exports, {
15
15
  flattenBranch: ()=>flattenBranch,
16
16
  branchIntersection: ()=>branchIntersection
17
17
  });
18
- const _intersectionTs = require("../parse/ast/intersection.js");
19
- const _domainsTs = require("../utils/domains.js");
20
- const _errorsTs = require("../utils/errors.js");
21
- const _composeTs = require("./compose.js");
22
- const _rulesTs = require("./rules/rules.js");
18
+ const _intersectionJs = require("../parse/ast/intersection.js");
19
+ const _domainsJs = require("../utils/domains.js");
20
+ const _errorsJs = require("../utils/errors.js");
21
+ const _composeJs = require("./compose.js");
22
+ const _rulesJs = require("./rules/rules.js");
23
23
  const isBranchComparison = (comparison)=>comparison?.lBranches !== undefined;
24
24
  const compareBranches = (lConditions, rConditions, state)=>{
25
25
  const result = {
@@ -42,7 +42,7 @@ const compareBranches = (lConditions, rConditions, state)=>{
42
42
  }
43
43
  const r = rPairs.condition;
44
44
  const subresult = branchIntersection(l, r, state);
45
- if ((0, _composeTs.isDisjoint)(subresult)) {
45
+ if ((0, _composeJs.isDisjoint)(subresult)) {
46
46
  // doesn't tell us about any redundancies or add a distinct pair
47
47
  return null;
48
48
  } else if (subresult === l) {
@@ -59,7 +59,7 @@ const compareBranches = (lConditions, rConditions, state)=>{
59
59
  // distinct branches.
60
60
  rPairs.distinct = null;
61
61
  return null;
62
- } else if ((0, _composeTs.isEquality)(subresult)) {
62
+ } else if ((0, _composeJs.isEquality)(subresult)) {
63
63
  // Combination of l and r subtype cases.
64
64
  result.equalities.push([
65
65
  lIndex,
@@ -68,13 +68,13 @@ const compareBranches = (lConditions, rConditions, state)=>{
68
68
  lImpliesR = true;
69
69
  rPairs.distinct = null;
70
70
  return null;
71
- } else if ((0, _domainsTs.hasDomain)(subresult, "object")) {
71
+ } else if ((0, _domainsJs.hasDomain)(subresult, "object")) {
72
72
  // Neither branch is a subtype of the other, return
73
73
  // the result of the intersection as a candidate
74
74
  // branch for the final union
75
75
  return subresult;
76
76
  }
77
- return (0, _errorsTs.throwInternalError)(`Unexpected predicate intersection result of type '${(0, _domainsTs.domainOf)(subresult)}'`);
77
+ return (0, _errorsJs.throwInternalError)(`Unexpected predicate intersection result of type '${(0, _domainsJs.domainOf)(subresult)}'`);
78
78
  });
79
79
  if (!lImpliesR) {
80
80
  for(let i = 0; i < pairs.length; i++){
@@ -90,7 +90,7 @@ const compareBranches = (lConditions, rConditions, state)=>{
90
90
  const isTransformationBranch = (branch)=>"rules" in branch;
91
91
  const flattenBranch = (branch, ctx)=>{
92
92
  if (isTransformationBranch(branch)) {
93
- const result = (0, _rulesTs.flattenRules)(branch.rules, ctx);
93
+ const result = (0, _rulesJs.flattenRules)(branch.rules, ctx);
94
94
  if (branch.morph) {
95
95
  if (typeof branch.morph === "function") {
96
96
  result.push([
@@ -108,31 +108,31 @@ const flattenBranch = (branch, ctx)=>{
108
108
  }
109
109
  return result;
110
110
  }
111
- return (0, _rulesTs.flattenRules)(branch, ctx);
111
+ return (0, _rulesJs.flattenRules)(branch, ctx);
112
112
  };
113
113
  const rulesOf = (branch)=>branch.rules ?? branch;
114
114
  const branchIntersection = (l, r, state)=>{
115
115
  const lRules = rulesOf(l);
116
116
  const rRules = rulesOf(r);
117
- const rulesResult = (0, _rulesTs.rulesIntersection)(lRules, rRules, state);
117
+ const rulesResult = (0, _rulesJs.rulesIntersection)(lRules, rRules, state);
118
118
  if ("morph" in l) {
119
119
  if ("morph" in r) {
120
120
  if (l.morph === r.morph) {
121
- return (0, _composeTs.isEquality)(rulesResult) || (0, _composeTs.isDisjoint)(rulesResult) ? rulesResult : {
121
+ return (0, _composeJs.isEquality)(rulesResult) || (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
122
122
  rules: rulesResult,
123
123
  morph: l.morph
124
124
  };
125
125
  }
126
- return state.lastOperator === "&" ? (0, _errorsTs.throwParseError)((0, _intersectionTs.writeImplicitNeverMessage)(state.path, "Intersection", "of morphs")) : {};
126
+ return state.lastOperator === "&" ? (0, _errorsJs.throwParseError)((0, _intersectionJs.writeImplicitNeverMessage)(state.path, "Intersection", "of morphs")) : {};
127
127
  }
128
- return (0, _composeTs.isDisjoint)(rulesResult) ? rulesResult : {
129
- rules: (0, _composeTs.isEquality)(rulesResult) ? l.rules : rulesResult,
128
+ return (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
129
+ rules: (0, _composeJs.isEquality)(rulesResult) ? l.rules : rulesResult,
130
130
  morph: l.morph
131
131
  };
132
132
  }
133
133
  if ("morph" in r) {
134
- return (0, _composeTs.isDisjoint)(rulesResult) ? rulesResult : {
135
- rules: (0, _composeTs.isEquality)(rulesResult) ? r.rules : rulesResult,
134
+ return (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
135
+ rules: (0, _composeJs.isEquality)(rulesResult) ? r.rules : rulesResult,
136
136
  morph: r.morph
137
137
  };
138
138
  }
@@ -20,10 +20,10 @@ _export(exports, {
20
20
  isEquality: ()=>isEquality,
21
21
  composeKeyedIntersection: ()=>composeKeyedIntersection
22
22
  });
23
- const _errorsTs = require("../utils/errors.js");
24
- const _genericsTs = require("../utils/generics.js");
25
- const _pathsTs = require("../utils/paths.js");
26
- const _serializeTs = require("../utils/serialize.js");
23
+ const _errorsJs = require("../utils/errors.js");
24
+ const _genericsJs = require("../utils/generics.js");
25
+ const _pathsJs = require("../utils/paths.js");
26
+ const _serializeJs = require("../utils/serialize.js");
27
27
  function _checkPrivateRedeclaration(obj, privateCollection) {
28
28
  if (privateCollection.has(obj)) {
29
29
  throw new TypeError("Cannot initialize the same private elements twice on an object");
@@ -64,17 +64,30 @@ function _classPrivateFieldSet(receiver, privateMap, value) {
64
64
  _classApplyDescriptorSet(receiver, descriptor, value);
65
65
  return value;
66
66
  }
67
- const composeIntersection = (reducer)=>(l, r, state)=>l === undefined ? r === undefined ? (0, _errorsTs.throwInternalError)(undefinedOperandsMessage) : r : r === undefined ? l : reducer(l, r, state);
67
+ function _defineProperty(obj, key, value) {
68
+ if (key in obj) {
69
+ Object.defineProperty(obj, key, {
70
+ value: value,
71
+ enumerable: true,
72
+ configurable: true,
73
+ writable: true
74
+ });
75
+ } else {
76
+ obj[key] = value;
77
+ }
78
+ return obj;
79
+ }
80
+ const composeIntersection = (reducer)=>(l, r, state)=>l === undefined ? r === undefined ? (0, _errorsJs.throwInternalError)(undefinedOperandsMessage) : r : r === undefined ? l : reducer(l, r, state);
68
81
  const undefinedOperandsMessage = `Unexpected operation two undefined operands`;
69
82
  const disjointDescriptionWriters = {
70
83
  domain: ({ l , r })=>`${l.join(", ")} and ${r.join(", ")}`,
71
84
  range: ({ l , r })=>`${stringifyRange(l)} and ${stringifyRange(r)}`,
72
85
  class: ({ l , r })=>`classes ${typeof l === "string" ? l : l.name} and ${typeof r === "string" ? r : r.name}`,
73
86
  tupleLength: ({ l , r })=>`tuples of length ${l} and ${r}`,
74
- value: ({ l , r })=>`literal values ${(0, _serializeTs.stringify)(l)} and ${(0, _serializeTs.stringify)(r)}`,
75
- leftAssignability: ({ l , r })=>`literal value ${(0, _serializeTs.stringify)(l.value)} and ${(0, _serializeTs.stringify)(r)}`,
76
- rightAssignability: ({ l , r })=>`literal value ${(0, _serializeTs.stringify)(r.value)} and ${(0, _serializeTs.stringify)(l)}`,
77
- union: ({ l , r })=>`branches ${(0, _serializeTs.stringify)(l)} and branches ${(0, _serializeTs.stringify)(r)}`
87
+ value: ({ l , r })=>`literal values ${(0, _serializeJs.stringify)(l)} and ${(0, _serializeJs.stringify)(r)}`,
88
+ leftAssignability: ({ l , r })=>`literal value ${(0, _serializeJs.stringify)(l.value)} and ${(0, _serializeJs.stringify)(r)}`,
89
+ rightAssignability: ({ l , r })=>`literal value ${(0, _serializeJs.stringify)(r.value)} and ${(0, _serializeJs.stringify)(l)}`,
90
+ union: ({ l , r })=>`branches ${(0, _serializeJs.stringify)(l)} and branches ${(0, _serializeJs.stringify)(r)}`
78
91
  };
79
92
  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
93
  var _disjoints = /*#__PURE__*/ new WeakMap();
@@ -91,13 +104,17 @@ class IntersectionState {
91
104
  return empty;
92
105
  }
93
106
  constructor(type, lastOperator){
107
+ _defineProperty(this, "type", void 0);
108
+ _defineProperty(this, "lastOperator", void 0);
109
+ _defineProperty(this, "path", void 0);
110
+ _defineProperty(this, "domain", void 0);
94
111
  _classPrivateFieldInit(this, _disjoints, {
95
112
  writable: true,
96
113
  value: void 0
97
114
  });
98
115
  this.type = type;
99
116
  this.lastOperator = lastOperator;
100
- this.path = new _pathsTs.Path();
117
+ this.path = new _pathsJs.Path();
101
118
  _classPrivateFieldSet(this, _disjoints, {});
102
119
  }
103
120
  }
@@ -109,7 +126,7 @@ const equality = ()=>equal;
109
126
  const isEquality = (result)=>result === equal;
110
127
  const composeKeyedIntersection = (reducer, config)=>(l, r, state)=>{
111
128
  const result = {};
112
- const keys = (0, _genericsTs.objectKeysOf)({
129
+ const keys = (0, _genericsJs.objectKeysOf)({
113
130
  ...l,
114
131
  ...r
115
132
  });
@@ -13,16 +13,16 @@ _export(exports, {
13
13
  serializeDefinitionIfAllowed: ()=>serializeDefinitionIfAllowed,
14
14
  serializeCase: ()=>serializeCase
15
15
  });
16
- const _unionTs = require("../parse/ast/union.js");
17
- const _domainsTs = require("../utils/domains.js");
18
- const _errorsTs = require("../utils/errors.js");
19
- const _genericsTs = require("../utils/generics.js");
20
- const _objectKindsTs = require("../utils/objectKinds.js");
21
- const _pathsTs = require("../utils/paths.js");
22
- const _serializeTs = require("../utils/serialize.js");
23
- const _branchTs = require("./branch.js");
24
- const _composeTs = require("./compose.js");
25
- const _propsTs = require("./rules/props.js");
16
+ const _unionJs = require("../parse/ast/union.js");
17
+ const _domainsJs = require("../utils/domains.js");
18
+ const _errorsJs = require("../utils/errors.js");
19
+ const _genericsJs = require("../utils/generics.js");
20
+ const _objectKindsJs = require("../utils/objectKinds.js");
21
+ const _pathsJs = require("../utils/paths.js");
22
+ const _serializeJs = require("../utils/serialize.js");
23
+ const _branchJs = require("./branch.js");
24
+ const _composeJs = require("./compose.js");
25
+ const _propsJs = require("./rules/props.js");
26
26
  const flattenBranches = (branches, ctx)=>{
27
27
  const discriminants = calculateDiscriminants(branches, ctx);
28
28
  const indices = branches.map((_, i)=>i);
@@ -30,14 +30,14 @@ const flattenBranches = (branches, ctx)=>{
30
30
  };
31
31
  const discriminate = (originalBranches, remainingIndices, discriminants, ctx)=>{
32
32
  if (remainingIndices.length === 1) {
33
- return (0, _branchTs.flattenBranch)(originalBranches[remainingIndices[0]], ctx);
33
+ return (0, _branchJs.flattenBranch)(originalBranches[remainingIndices[0]], ctx);
34
34
  }
35
35
  const bestDiscriminant = findBestDiscriminant(remainingIndices, discriminants);
36
36
  if (!bestDiscriminant) {
37
37
  return [
38
38
  [
39
39
  "branches",
40
- remainingIndices.map((i)=>branchIncludesMorph(originalBranches[i], ctx.type.scope) ? (0, _errorsTs.throwParseError)((0, _unionTs.writeUndiscriminatableMorphUnionMessage)(`${ctx.path}`)) : (0, _branchTs.flattenBranch)(originalBranches[i], ctx))
40
+ remainingIndices.map((i)=>branchIncludesMorph(originalBranches[i], ctx.type.scope) ? (0, _errorsJs.throwParseError)((0, _unionJs.writeUndiscriminatableMorphUnionMessage)(`${ctx.path}`)) : (0, _branchJs.flattenBranch)(originalBranches[i], ctx))
41
41
  ]
42
42
  ];
43
43
  }
@@ -94,7 +94,7 @@ const pruneDiscriminant = (entries, segments, discriminant, ctx)=>{
94
94
  // check for branch keys, which must be traversed even if there are no
95
95
  // segments left
96
96
  if (k === "domains") {
97
- /* c8 ignore next */ if ((0, _genericsTs.keyCount)(v) !== 1 || !v.object) {
97
+ /* c8 ignore next */ if ((0, _genericsJs.keyCount)(v) !== 1 || !v.object) {
98
98
  return throwInternalPruneFailure(discriminant);
99
99
  }
100
100
  pruneDiscriminant(v.object, segments, discriminant, ctx);
@@ -113,7 +113,7 @@ const pruneDiscriminant = (entries, segments, discriminant, ctx)=>{
113
113
  }
114
114
  return throwInternalPruneFailure(discriminant);
115
115
  };
116
- const throwInternalPruneFailure = (discriminant)=>(0, _errorsTs.throwInternalError)(`Unexpectedly failed to discriminate ${discriminant.kind} at path '${discriminant.path}'`);
116
+ const throwInternalPruneFailure = (discriminant)=>(0, _errorsJs.throwInternalError)(`Unexpectedly failed to discriminate ${discriminant.kind} at path '${discriminant.path}'`);
117
117
  const discriminantKinds = {
118
118
  domain: true,
119
119
  class: true,
@@ -129,14 +129,14 @@ const calculateDiscriminants = (branches, ctx)=>{
129
129
  const pairKey = `${lIndex}/${rIndex}`;
130
130
  const pairDisjoints = [];
131
131
  discriminants.disjointsByPair[pairKey] = pairDisjoints;
132
- const intersectionState = new _composeTs.IntersectionState(ctx.type, "|");
133
- (0, _branchTs.branchIntersection)(branches[lIndex], branches[rIndex], intersectionState);
132
+ const intersectionState = new _composeJs.IntersectionState(ctx.type, "|");
133
+ (0, _branchJs.branchIntersection)(branches[lIndex], branches[rIndex], intersectionState);
134
134
  for(const path in intersectionState.disjoints){
135
- if (path.includes(_propsTs.mappedKeys.index)) {
135
+ if (path.includes(_propsJs.mappedKeys.index)) {
136
136
  continue;
137
137
  }
138
138
  const { l , r , kind } = intersectionState.disjoints[path];
139
- if (!(0, _genericsTs.isKeyOf)(kind, discriminantKinds)) {
139
+ if (!(0, _genericsJs.isKeyOf)(kind, discriminantKinds)) {
140
140
  continue;
141
141
  }
142
142
  const lSerialized = serializeDefinitionIfAllowed(kind, l);
@@ -180,7 +180,7 @@ const calculateDiscriminants = (branches, ctx)=>{
180
180
  return discriminants;
181
181
  };
182
182
  const parseQualifiedDisjoint = (qualifiedDisjoint)=>{
183
- const path = _pathsTs.Path.fromString(qualifiedDisjoint);
183
+ const path = _pathsJs.Path.fromString(qualifiedDisjoint);
184
184
  return [
185
185
  path,
186
186
  path.pop()
@@ -214,7 +214,7 @@ const findBestDiscriminant = (remainingIndices, discriminants)=>{
214
214
  filteredCases[caseKey] = filteredIndices;
215
215
  score++;
216
216
  }
217
- const defaultCaseKeys = (0, _genericsTs.objectKeysOf)(defaultCases);
217
+ const defaultCaseKeys = (0, _genericsJs.objectKeysOf)(defaultCases);
218
218
  if (defaultCaseKeys.length) {
219
219
  filteredCases["default"] = defaultCaseKeys.map((k)=>parseInt(k));
220
220
  }
@@ -243,20 +243,20 @@ const serializeDefinitionIfAllowed = (kind, definition)=>{
243
243
  case "domain":
244
244
  return definition;
245
245
  case "class":
246
- return (0, _objectKindsTs.getExactConstructorObjectKind)(definition);
246
+ return (0, _objectKindsJs.getExactConstructorObjectKind)(definition);
247
247
  default:
248
248
  return;
249
249
  }
250
250
  };
251
251
  const serializeIfPrimitive = (data)=>{
252
- const domain = (0, _domainsTs.domainOf)(data);
253
- return domain === "object" || domain === "symbol" ? undefined : (0, _serializeTs.serializePrimitive)(data);
252
+ const domain = (0, _domainsJs.domainOf)(data);
253
+ return domain === "object" || domain === "symbol" ? undefined : (0, _serializeJs.serializePrimitive)(data);
254
254
  };
255
255
  const serializeData = {
256
256
  value: (data)=>serializeIfPrimitive(data) ?? "default",
257
- class: (data)=>(0, _objectKindsTs.objectKindOf)(data) ?? "default",
258
- domain: _domainsTs.domainOf
257
+ class: (data)=>(0, _objectKindsJs.objectKindOf)(data) ?? "default",
258
+ domain: _domainsJs.domainOf
259
259
  };
260
260
  const serializeCase = (kind, data)=>serializeData[kind](data);
261
- const branchIncludesMorph = (branch, $)=>"morph" in branch ? true : "props" in branch ? Object.values(branch.props).some((prop)=>nodeIncludesMorph((0, _propsTs.propToNode)(prop), $)) : false;
262
- const nodeIncludesMorph = (node, $)=>typeof node === "string" ? $.resolve(node).includesMorph : Object.values($.resolveTypeNode(node)).some((predicate)=>predicate === true ? false : (0, _objectKindsTs.isArray)(predicate) ? predicate.some((branch)=>branchIncludesMorph(branch, $)) : branchIncludesMorph(predicate, $));
261
+ const branchIncludesMorph = (branch, $)=>"morph" in branch ? true : "props" in branch ? Object.values(branch.props).some((prop)=>nodeIncludesMorph((0, _propsJs.propToNode)(prop), $)) : false;
262
+ const nodeIncludesMorph = (node, $)=>typeof node === "string" ? $.resolve(node).includesMorph : Object.values($.resolveTypeNode(node)).some((predicate)=>predicate === true ? false : (0, _objectKindsJs.isArray)(predicate) ? predicate.some((branch)=>branchIncludesMorph(branch, $)) : branchIncludesMorph(predicate, $));
@@ -20,50 +20,50 @@ _export(exports, {
20
20
  resolutionExtendsDomain: ()=>resolutionExtendsDomain,
21
21
  toArrayNode: ()=>toArrayNode
22
22
  });
23
- const _intersectionTs = require("../parse/ast/intersection.js");
24
- const _errorsTs = require("../utils/errors.js");
25
- const _genericsTs = require("../utils/generics.js");
26
- const _pathsTs = require("../utils/paths.js");
27
- const _composeTs = require("./compose.js");
28
- const _predicateTs = require("./predicate.js");
29
- const _propsTs = require("./rules/props.js");
23
+ const _intersectionJs = require("../parse/ast/intersection.js");
24
+ const _errorsJs = require("../utils/errors.js");
25
+ const _genericsJs = require("../utils/generics.js");
26
+ const _pathsJs = require("../utils/paths.js");
27
+ const _composeJs = require("./compose.js");
28
+ const _predicateJs = require("./predicate.js");
29
+ const _propsJs = require("./rules/props.js");
30
30
  const isConfigNode = (node)=>"config" in node;
31
31
  const nodeIntersection = (l, r, state)=>{
32
32
  state.domain = undefined;
33
33
  const lDomains = state.type.scope.resolveTypeNode(l);
34
34
  const rDomains = state.type.scope.resolveTypeNode(r);
35
35
  const result = typeNodeIntersection(lDomains, rDomains, state);
36
- if (typeof result === "object" && !(0, _genericsTs.hasKeys)(result)) {
37
- return (0, _genericsTs.hasKeys)(state.disjoints) ? (0, _composeTs.anonymousDisjoint)() : state.addDisjoint("domain", (0, _genericsTs.objectKeysOf)(lDomains), (0, _genericsTs.objectKeysOf)(rDomains));
36
+ if (typeof result === "object" && !(0, _genericsJs.hasKeys)(result)) {
37
+ return (0, _genericsJs.hasKeys)(state.disjoints) ? (0, _composeJs.anonymousDisjoint)() : state.addDisjoint("domain", (0, _genericsJs.objectKeysOf)(lDomains), (0, _genericsJs.objectKeysOf)(rDomains));
38
38
  }
39
39
  return result === lDomains ? l : result === rDomains ? r : result;
40
40
  };
41
- const typeNodeIntersection = (0, _composeTs.composeKeyedIntersection)((domain, l, r, context)=>{
41
+ const typeNodeIntersection = (0, _composeJs.composeKeyedIntersection)((domain, l, r, context)=>{
42
42
  if (l === undefined) {
43
- return r === undefined ? (0, _errorsTs.throwInternalError)(_composeTs.undefinedOperandsMessage) : undefined;
43
+ return r === undefined ? (0, _errorsJs.throwInternalError)(_composeJs.undefinedOperandsMessage) : undefined;
44
44
  }
45
45
  if (r === undefined) {
46
46
  return undefined;
47
47
  }
48
- return (0, _predicateTs.predicateIntersection)(domain, l, r, context);
48
+ return (0, _predicateJs.predicateIntersection)(domain, l, r, context);
49
49
  }, {
50
50
  onEmpty: "omit"
51
51
  });
52
52
  const rootIntersection = (l, r, type)=>{
53
- const state = new _composeTs.IntersectionState(type, "&");
53
+ const state = new _composeJs.IntersectionState(type, "&");
54
54
  const result = nodeIntersection(l, r, state);
55
- return (0, _composeTs.isDisjoint)(result) ? (0, _errorsTs.throwParseError)((0, _intersectionTs.compileDisjointReasonsMessage)(state.disjoints)) : (0, _composeTs.isEquality)(result) ? l : result;
55
+ return (0, _composeJs.isDisjoint)(result) ? (0, _errorsJs.throwParseError)((0, _intersectionJs.compileDisjointReasonsMessage)(state.disjoints)) : (0, _composeJs.isEquality)(result) ? l : result;
56
56
  };
57
57
  const rootUnion = (l, r, type)=>{
58
58
  const lDomains = type.scope.resolveTypeNode(l);
59
59
  const rDomains = type.scope.resolveTypeNode(r);
60
60
  const result = {};
61
- const domains = (0, _genericsTs.objectKeysOf)({
61
+ const domains = (0, _genericsJs.objectKeysOf)({
62
62
  ...lDomains,
63
63
  ...rDomains
64
64
  });
65
65
  for (const domain of domains){
66
- result[domain] = (0, _genericsTs.hasKey)(lDomains, domain) ? (0, _genericsTs.hasKey)(rDomains, domain) ? (0, _predicateTs.predicateUnion)(domain, lDomains[domain], rDomains[domain], type) : lDomains[domain] : (0, _genericsTs.hasKey)(rDomains, domain) ? rDomains[domain] : (0, _errorsTs.throwInternalError)(_composeTs.undefinedOperandsMessage);
66
+ result[domain] = (0, _genericsJs.hasKey)(lDomains, domain) ? (0, _genericsJs.hasKey)(rDomains, domain) ? (0, _predicateJs.predicateUnion)(domain, lDomains[domain], rDomains[domain], type) : lDomains[domain] : (0, _genericsJs.hasKey)(rDomains, domain) ? rDomains[domain] : (0, _errorsJs.throwInternalError)(_composeJs.undefinedOperandsMessage);
67
67
  }
68
68
  return result;
69
69
  };
@@ -71,7 +71,7 @@ const hasImpliedDomain = (flatPredicate)=>flatPredicate[0] && (flatPredicate[0][
71
71
  const flattenType = (type)=>{
72
72
  const ctx = {
73
73
  type,
74
- path: new _pathsTs.Path(),
74
+ path: new _pathsJs.Path(),
75
75
  lastDomain: "undefined"
76
76
  };
77
77
  return flattenNode(type.node, ctx);
@@ -86,14 +86,14 @@ const flattenNode = (node, ctx)=>{
86
86
  [
87
87
  "config",
88
88
  {
89
- config: (0, _genericsTs.entriesOf)(node.config),
89
+ config: (0, _genericsJs.entriesOf)(node.config),
90
90
  node: flattenedTypeNode
91
91
  }
92
92
  ]
93
93
  ] : flattenedTypeNode;
94
94
  };
95
95
  const flattenTypeNode = (node, ctx)=>{
96
- const domains = (0, _genericsTs.objectKeysOf)(node);
96
+ const domains = (0, _genericsJs.objectKeysOf)(node);
97
97
  if (domains.length === 1) {
98
98
  const domain = domains[0];
99
99
  const predicate = node[domain];
@@ -101,7 +101,7 @@ const flattenTypeNode = (node, ctx)=>{
101
101
  return domain;
102
102
  }
103
103
  ctx.lastDomain = domain;
104
- const flatPredicate = (0, _predicateTs.flattenPredicate)(predicate, ctx);
104
+ const flatPredicate = (0, _predicateJs.flattenPredicate)(predicate, ctx);
105
105
  return hasImpliedDomain(flatPredicate) ? flatPredicate : [
106
106
  [
107
107
  "domain",
@@ -113,7 +113,7 @@ const flattenTypeNode = (node, ctx)=>{
113
113
  const result = {};
114
114
  for (const domain of domains){
115
115
  ctx.lastDomain = domain;
116
- result[domain] = (0, _predicateTs.flattenPredicate)(node[domain], ctx);
116
+ result[domain] = (0, _predicateJs.flattenPredicate)(node[domain], ctx);
117
117
  }
118
118
  return [
119
119
  [
@@ -123,17 +123,17 @@ const flattenTypeNode = (node, ctx)=>{
123
123
  ];
124
124
  };
125
125
  const isLiteralNode = (node, domain)=>{
126
- return resolutionExtendsDomain(node, domain) && (0, _predicateTs.isLiteralCondition)(node[domain]);
126
+ return resolutionExtendsDomain(node, domain) && (0, _predicateJs.isLiteralCondition)(node[domain]);
127
127
  };
128
128
  const resolutionExtendsDomain = (resolution, domain)=>{
129
- const domains = (0, _genericsTs.objectKeysOf)(resolution);
129
+ const domains = (0, _genericsJs.objectKeysOf)(resolution);
130
130
  return domains.length === 1 && domains[0] === domain;
131
131
  };
132
132
  const toArrayNode = (node)=>({
133
133
  object: {
134
134
  class: Array,
135
135
  props: {
136
- [_propsTs.mappedKeys.index]: node
136
+ [_propsJs.mappedKeys.index]: node
137
137
  }
138
138
  }
139
139
  });
@@ -15,25 +15,25 @@ _export(exports, {
15
15
  flattenPredicate: ()=>flattenPredicate,
16
16
  isLiteralCondition: ()=>isLiteralCondition
17
17
  });
18
- const _genericsTs = require("../utils/generics.js");
19
- const _objectKindsTs = require("../utils/objectKinds.js");
20
- const _branchTs = require("./branch.js");
21
- const _composeTs = require("./compose.js");
22
- const _discriminateTs = require("./discriminate.js");
18
+ const _genericsJs = require("../utils/generics.js");
19
+ const _objectKindsJs = require("../utils/objectKinds.js");
20
+ const _branchJs = require("./branch.js");
21
+ const _composeJs = require("./compose.js");
22
+ const _discriminateJs = require("./discriminate.js");
23
23
  const emptyRulesIfTrue = (predicate)=>predicate === true ? {} : predicate;
24
24
  const comparePredicates = (l, r, context)=>{
25
25
  if (l === true && r === true) {
26
- return (0, _composeTs.equality)();
26
+ return (0, _composeJs.equality)();
27
27
  }
28
- if (!(0, _objectKindsTs.isArray)(l) && !(0, _objectKindsTs.isArray)(r)) {
29
- const result = (0, _branchTs.branchIntersection)(emptyRulesIfTrue(l), emptyRulesIfTrue(r), context);
28
+ if (!(0, _objectKindsJs.isArray)(l) && !(0, _objectKindsJs.isArray)(r)) {
29
+ const result = (0, _branchJs.branchIntersection)(emptyRulesIfTrue(l), emptyRulesIfTrue(r), context);
30
30
  return result === l ? l : result === r ? r : result;
31
31
  }
32
- const lBranches = (0, _genericsTs.listFrom)(emptyRulesIfTrue(l));
33
- const rBranches = (0, _genericsTs.listFrom)(emptyRulesIfTrue(r));
34
- const comparison = (0, _branchTs.compareBranches)(lBranches, rBranches, context);
32
+ const lBranches = (0, _genericsJs.listFrom)(emptyRulesIfTrue(l));
33
+ const rBranches = (0, _genericsJs.listFrom)(emptyRulesIfTrue(r));
34
+ const comparison = (0, _branchJs.compareBranches)(lBranches, rBranches, context);
35
35
  if (comparison.equalities.length === lBranches.length && comparison.equalities.length === rBranches.length) {
36
- return (0, _composeTs.equality)();
36
+ return (0, _composeJs.equality)();
37
37
  }
38
38
  if (comparison.lExtendsR.length + comparison.equalities.length === lBranches.length) {
39
39
  return l;
@@ -46,7 +46,7 @@ const comparePredicates = (l, r, context)=>{
46
46
  const predicateIntersection = (domain, l, r, state)=>{
47
47
  state.domain = domain;
48
48
  const comparison = comparePredicates(l, r, state);
49
- if (!(0, _branchTs.isBranchComparison)(comparison)) {
49
+ if (!(0, _branchJs.isBranchComparison)(comparison)) {
50
50
  return comparison;
51
51
  }
52
52
  const resultBranches = [
@@ -61,10 +61,10 @@ const predicateIntersection = (domain, l, r, state)=>{
61
61
  return resultBranches.length === 1 ? resultBranches[0] : resultBranches;
62
62
  };
63
63
  const predicateUnion = (domain, l, r, type)=>{
64
- const state = new _composeTs.IntersectionState(type, "|");
64
+ const state = new _composeJs.IntersectionState(type, "|");
65
65
  const comparison = comparePredicates(l, r, state);
66
- if (!(0, _branchTs.isBranchComparison)(comparison)) {
67
- return (0, _composeTs.isEquality)(comparison) || comparison === l ? r : comparison === r ? l : // subtype of the other, it consists of two opposite literals
66
+ if (!(0, _branchJs.isBranchComparison)(comparison)) {
67
+ return (0, _composeJs.isEquality)(comparison) || comparison === l ? r : comparison === r ? l : // subtype of the other, it consists of two opposite literals
68
68
  // and can be simplified to a non-literal boolean.
69
69
  domain === "boolean" ? true : [
70
70
  emptyRulesIfTrue(l),
@@ -81,6 +81,6 @@ const flattenPredicate = (predicate, context)=>{
81
81
  if (predicate === true) {
82
82
  return [];
83
83
  }
84
- return (0, _objectKindsTs.isArray)(predicate) ? (0, _discriminateTs.flattenBranches)(predicate, context) : (0, _branchTs.flattenBranch)(predicate, context);
84
+ return (0, _objectKindsJs.isArray)(predicate) ? (0, _discriminateJs.flattenBranches)(predicate, context) : (0, _branchJs.flattenBranch)(predicate, context);
85
85
  };
86
86
  const isLiteralCondition = (predicate)=>typeof predicate === "object" && "value" in predicate;
@@ -12,14 +12,14 @@ _export(exports, {
12
12
  classIntersection: ()=>classIntersection,
13
13
  checkClass: ()=>checkClass
14
14
  });
15
- const _objectKindsTs = require("../../utils/objectKinds.js");
16
- const _composeTs = require("../compose.js");
17
- const classIntersection = (0, _composeTs.composeIntersection)((l, r, state)=>{
18
- return l === r ? (0, _composeTs.equality)() : l instanceof r ? l : r instanceof l ? r : state.addDisjoint("class", l, r);
15
+ const _objectKindsJs = require("../../utils/objectKinds.js");
16
+ const _composeJs = require("../compose.js");
17
+ const classIntersection = (0, _composeJs.composeIntersection)((l, r, state)=>{
18
+ return l === r ? (0, _composeJs.equality)() : l instanceof r ? l : r instanceof l ? r : state.addDisjoint("class", l, r);
19
19
  });
20
20
  const checkClass = (expectedClass, state)=>{
21
21
  if (typeof expectedClass === "string") {
22
- return (0, _objectKindsTs.objectKindOf)(state.data) === expectedClass || !state.problems.add("class", expectedClass);
22
+ return (0, _objectKindsJs.objectKindOf)(state.data) === expectedClass || !state.problems.add("class", expectedClass);
23
23
  }
24
24
  return state.data instanceof expectedClass || !state.problems.add("class", expectedClass);
25
25
  };