arktype 1.0.16-alpha → 1.0.18-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 (247) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/main.js +38 -0
  3. package/dist/cjs/nodes/branch.js +140 -0
  4. package/dist/cjs/nodes/compose.js +157 -0
  5. package/dist/{nodes → cjs/nodes}/discriminate.js +92 -100
  6. package/dist/cjs/nodes/node.js +139 -0
  7. package/dist/cjs/nodes/predicate.js +86 -0
  8. package/dist/cjs/nodes/rules/class.js +25 -0
  9. package/dist/cjs/nodes/rules/collapsibleSet.js +48 -0
  10. package/dist/cjs/nodes/rules/divisor.js +29 -0
  11. package/dist/cjs/nodes/rules/props.js +160 -0
  12. package/dist/cjs/nodes/rules/range.js +105 -0
  13. package/dist/cjs/nodes/rules/regex.js +26 -0
  14. package/dist/cjs/nodes/rules/rules.js +123 -0
  15. package/dist/cjs/parse/ast/ast.js +4 -0
  16. package/dist/cjs/parse/ast/bound.js +16 -0
  17. package/dist/cjs/parse/ast/config.js +13 -0
  18. package/dist/cjs/parse/ast/distributableFunction.js +48 -0
  19. package/dist/cjs/parse/ast/divisor.js +9 -0
  20. package/dist/cjs/parse/ast/intersection.js +30 -0
  21. package/dist/cjs/parse/ast/keyof.js +111 -0
  22. package/dist/cjs/parse/ast/morph.js +58 -0
  23. package/dist/cjs/parse/ast/narrow.js +22 -0
  24. package/dist/cjs/parse/ast/node.js +4 -0
  25. package/dist/cjs/parse/ast/tuple.js +94 -0
  26. package/dist/cjs/parse/ast/union.js +9 -0
  27. package/dist/cjs/parse/ast/utils.js +4 -0
  28. package/dist/cjs/parse/definition.js +61 -0
  29. package/dist/cjs/parse/record.js +37 -0
  30. package/dist/cjs/parse/string/reduce/dynamic.js +167 -0
  31. package/dist/cjs/parse/string/reduce/shared.js +23 -0
  32. package/dist/cjs/parse/string/reduce/static.js +4 -0
  33. package/dist/cjs/parse/string/shift/operand/enclosed.js +54 -0
  34. package/dist/cjs/parse/string/shift/operand/operand.js +11 -0
  35. package/dist/cjs/parse/string/shift/operand/unenclosed.js +53 -0
  36. package/dist/cjs/parse/string/shift/operator/bounds.js +87 -0
  37. package/dist/cjs/parse/string/shift/operator/divisor.js +35 -0
  38. package/dist/cjs/parse/string/shift/operator/operator.js +26 -0
  39. package/dist/cjs/parse/string/shift/scanner.js +114 -0
  40. package/dist/cjs/parse/string/string.js +43 -0
  41. package/dist/cjs/scopes/ark.js +45 -0
  42. package/dist/cjs/scopes/cache.js +52 -0
  43. package/dist/cjs/scopes/expressions.js +29 -0
  44. package/dist/cjs/scopes/jsObjects.js +93 -0
  45. package/dist/cjs/scopes/scope.js +323 -0
  46. package/dist/cjs/scopes/tsKeywords.js +113 -0
  47. package/dist/cjs/scopes/type.js +50 -0
  48. package/dist/cjs/scopes/validation/creditCard.js +47 -0
  49. package/dist/cjs/scopes/validation/date.js +62 -0
  50. package/dist/cjs/scopes/validation/validation.js +108 -0
  51. package/dist/cjs/traverse/problems.js +281 -0
  52. package/dist/cjs/traverse/traverse.js +390 -0
  53. package/dist/cjs/utils/chainableNoOpProxy.js +23 -0
  54. package/dist/cjs/utils/data.js +53 -0
  55. package/dist/cjs/utils/domains.js +30 -0
  56. package/dist/cjs/utils/errors.js +26 -0
  57. package/dist/cjs/utils/freeze.js +15 -0
  58. package/dist/cjs/utils/generics.js +63 -0
  59. package/dist/cjs/utils/numericLiterals.js +75 -0
  60. package/dist/cjs/utils/objectKinds.js +69 -0
  61. package/dist/cjs/utils/paths.js +32 -0
  62. package/dist/cjs/utils/serialize.js +74 -0
  63. package/dist/cjs/utils/unionToTuple.js +4 -0
  64. package/dist/mjs/main.js +8 -0
  65. package/dist/mjs/nodes/branch.js +123 -0
  66. package/dist/mjs/nodes/compose.js +135 -0
  67. package/dist/mjs/nodes/discriminate.js +247 -0
  68. package/dist/mjs/nodes/node.js +117 -0
  69. package/dist/mjs/nodes/predicate.js +69 -0
  70. package/dist/mjs/nodes/rules/class.js +11 -0
  71. package/dist/mjs/nodes/rules/collapsibleSet.js +34 -0
  72. package/dist/mjs/nodes/rules/divisor.js +15 -0
  73. package/dist/mjs/nodes/rules/props.js +142 -0
  74. package/dist/mjs/nodes/rules/range.js +86 -0
  75. package/dist/mjs/nodes/rules/regex.js +11 -0
  76. package/dist/mjs/nodes/rules/rules.js +106 -0
  77. package/dist/mjs/package.json +3 -0
  78. package/dist/mjs/parse/ast/ast.js +1 -0
  79. package/dist/mjs/parse/ast/bound.js +2 -0
  80. package/dist/mjs/parse/ast/config.js +9 -0
  81. package/dist/mjs/parse/ast/distributableFunction.js +34 -0
  82. package/dist/mjs/parse/ast/divisor.js +1 -0
  83. package/dist/mjs/parse/ast/intersection.js +16 -0
  84. package/dist/mjs/parse/ast/keyof.js +103 -0
  85. package/dist/mjs/parse/ast/morph.js +44 -0
  86. package/dist/mjs/parse/ast/narrow.js +14 -0
  87. package/dist/mjs/parse/ast/node.js +1 -0
  88. package/dist/mjs/parse/ast/tuple.js +80 -0
  89. package/dist/mjs/parse/ast/union.js +1 -0
  90. package/dist/mjs/parse/ast/utils.js +1 -0
  91. package/dist/mjs/parse/definition.js +46 -0
  92. package/dist/mjs/parse/record.js +29 -0
  93. package/dist/mjs/parse/string/reduce/dynamic.js +159 -0
  94. package/dist/mjs/parse/string/reduce/shared.js +6 -0
  95. package/dist/mjs/parse/string/reduce/static.js +1 -0
  96. package/dist/mjs/parse/string/shift/operand/enclosed.js +39 -0
  97. package/dist/mjs/parse/string/shift/operand/operand.js +3 -0
  98. package/dist/mjs/parse/string/shift/operand/unenclosed.js +36 -0
  99. package/dist/mjs/parse/string/shift/operator/bounds.js +70 -0
  100. package/dist/mjs/parse/string/shift/operator/divisor.js +21 -0
  101. package/dist/mjs/parse/string/shift/operator/operator.js +13 -0
  102. package/dist/mjs/parse/string/shift/scanner.js +106 -0
  103. package/dist/mjs/parse/string/string.js +28 -0
  104. package/dist/mjs/scopes/ark.js +28 -0
  105. package/dist/mjs/scopes/cache.js +38 -0
  106. package/dist/{scopes → mjs/scopes}/expressions.js +9 -20
  107. package/dist/mjs/scopes/jsObjects.js +82 -0
  108. package/dist/mjs/scopes/scope.js +303 -0
  109. package/dist/mjs/scopes/tsKeywords.js +116 -0
  110. package/dist/mjs/scopes/type.js +35 -0
  111. package/dist/{scopes → mjs/scopes}/validation/creditCard.js +11 -15
  112. package/dist/{scopes → mjs/scopes}/validation/date.js +16 -21
  113. package/dist/mjs/scopes/validation/validation.js +112 -0
  114. package/dist/mjs/traverse/problems.js +260 -0
  115. package/dist/mjs/traverse/traverse.js +373 -0
  116. package/dist/{utils → mjs/utils}/chainableNoOpProxy.js +2 -6
  117. package/dist/mjs/utils/data.js +38 -0
  118. package/dist/mjs/utils/domains.js +15 -0
  119. package/dist/mjs/utils/errors.js +10 -0
  120. package/dist/mjs/utils/freeze.js +7 -0
  121. package/dist/mjs/utils/generics.js +38 -0
  122. package/dist/mjs/utils/numericLiterals.js +72 -0
  123. package/dist/mjs/utils/objectKinds.js +55 -0
  124. package/dist/{utils → mjs/utils}/paths.js +3 -8
  125. package/dist/mjs/utils/serialize.js +58 -0
  126. package/dist/mjs/utils/unionToTuple.js +1 -0
  127. package/dist/tsconfig.temp.tsbuildinfo +1 -1
  128. package/package.json +14 -6
  129. package/dist/main.js +0 -29
  130. package/dist/nodes/branch.js +0 -135
  131. package/dist/nodes/compose.js +0 -99
  132. package/dist/nodes/node.js +0 -134
  133. package/dist/nodes/predicate.js +0 -88
  134. package/dist/nodes/rules/class.js +0 -23
  135. package/dist/nodes/rules/collapsibleSet.js +0 -34
  136. package/dist/nodes/rules/divisor.js +0 -19
  137. package/dist/nodes/rules/props.js +0 -130
  138. package/dist/nodes/rules/range.js +0 -108
  139. package/dist/nodes/rules/regex.js +0 -17
  140. package/dist/nodes/rules/rules.js +0 -102
  141. package/dist/parse/ast/ast.js +0 -2
  142. package/dist/parse/ast/bound.js +0 -7
  143. package/dist/parse/ast/config.js +0 -14
  144. package/dist/parse/ast/distributableFunction.js +0 -40
  145. package/dist/parse/ast/divisor.js +0 -5
  146. package/dist/parse/ast/intersection.js +0 -21
  147. package/dist/parse/ast/keyof.js +0 -107
  148. package/dist/parse/ast/morph.js +0 -50
  149. package/dist/parse/ast/narrow.js +0 -17
  150. package/dist/parse/ast/node.js +0 -2
  151. package/dist/parse/ast/tuple.js +0 -72
  152. package/dist/parse/ast/union.js +0 -5
  153. package/dist/parse/ast/utils.js +0 -2
  154. package/dist/parse/definition.js +0 -47
  155. package/dist/parse/record.js +0 -31
  156. package/dist/parse/string/reduce/dynamic.js +0 -159
  157. package/dist/parse/string/reduce/shared.js +0 -13
  158. package/dist/parse/string/reduce/static.js +0 -2
  159. package/dist/parse/string/shift/operand/enclosed.js +0 -37
  160. package/dist/parse/string/shift/operand/operand.js +0 -15
  161. package/dist/parse/string/shift/operand/unenclosed.js +0 -45
  162. package/dist/parse/string/shift/operator/bounds.js +0 -83
  163. package/dist/parse/string/shift/operator/divisor.js +0 -23
  164. package/dist/parse/string/shift/operator/operator.js +0 -34
  165. package/dist/parse/string/shift/scanner.js +0 -97
  166. package/dist/parse/string/string.js +0 -35
  167. package/dist/scopes/ark.js +0 -27
  168. package/dist/scopes/cache.js +0 -28
  169. package/dist/scopes/jsObjects.js +0 -20
  170. package/dist/scopes/scope.js +0 -184
  171. package/dist/scopes/tsKeywords.js +0 -49
  172. package/dist/scopes/type.js +0 -40
  173. package/dist/scopes/validation/validation.js +0 -74
  174. package/dist/traverse/problems.js +0 -234
  175. package/dist/traverse/traverse.js +0 -330
  176. package/dist/utils/data.js +0 -39
  177. package/dist/utils/domains.js +0 -27
  178. package/dist/utils/errors.js +0 -17
  179. package/dist/utils/freeze.js +0 -16
  180. package/dist/utils/generics.js +0 -53
  181. package/dist/utils/numericLiterals.js +0 -88
  182. package/dist/utils/objectKinds.js +0 -69
  183. package/dist/utils/serialize.js +0 -71
  184. package/dist/utils/unionToTuple.js +0 -2
  185. /package/dist/{package.json → cjs/package.json} +0 -0
  186. /package/dist/{main.d.ts → types/main.d.ts} +0 -0
  187. /package/dist/{nodes → types/nodes}/branch.d.ts +0 -0
  188. /package/dist/{nodes → types/nodes}/compose.d.ts +0 -0
  189. /package/dist/{nodes → types/nodes}/discriminate.d.ts +0 -0
  190. /package/dist/{nodes → types/nodes}/node.d.ts +0 -0
  191. /package/dist/{nodes → types/nodes}/predicate.d.ts +0 -0
  192. /package/dist/{nodes → types/nodes}/rules/class.d.ts +0 -0
  193. /package/dist/{nodes → types/nodes}/rules/collapsibleSet.d.ts +0 -0
  194. /package/dist/{nodes → types/nodes}/rules/divisor.d.ts +0 -0
  195. /package/dist/{nodes → types/nodes}/rules/props.d.ts +0 -0
  196. /package/dist/{nodes → types/nodes}/rules/range.d.ts +0 -0
  197. /package/dist/{nodes → types/nodes}/rules/regex.d.ts +0 -0
  198. /package/dist/{nodes → types/nodes}/rules/rules.d.ts +0 -0
  199. /package/dist/{parse → types/parse}/ast/ast.d.ts +0 -0
  200. /package/dist/{parse → types/parse}/ast/bound.d.ts +0 -0
  201. /package/dist/{parse → types/parse}/ast/config.d.ts +0 -0
  202. /package/dist/{parse → types/parse}/ast/distributableFunction.d.ts +0 -0
  203. /package/dist/{parse → types/parse}/ast/divisor.d.ts +0 -0
  204. /package/dist/{parse → types/parse}/ast/intersection.d.ts +0 -0
  205. /package/dist/{parse → types/parse}/ast/keyof.d.ts +0 -0
  206. /package/dist/{parse → types/parse}/ast/morph.d.ts +0 -0
  207. /package/dist/{parse → types/parse}/ast/narrow.d.ts +0 -0
  208. /package/dist/{parse → types/parse}/ast/node.d.ts +0 -0
  209. /package/dist/{parse → types/parse}/ast/tuple.d.ts +0 -0
  210. /package/dist/{parse → types/parse}/ast/union.d.ts +0 -0
  211. /package/dist/{parse → types/parse}/ast/utils.d.ts +0 -0
  212. /package/dist/{parse → types/parse}/definition.d.ts +0 -0
  213. /package/dist/{parse → types/parse}/record.d.ts +0 -0
  214. /package/dist/{parse → types/parse}/string/reduce/dynamic.d.ts +0 -0
  215. /package/dist/{parse → types/parse}/string/reduce/shared.d.ts +0 -0
  216. /package/dist/{parse → types/parse}/string/reduce/static.d.ts +0 -0
  217. /package/dist/{parse → types/parse}/string/shift/operand/enclosed.d.ts +0 -0
  218. /package/dist/{parse → types/parse}/string/shift/operand/operand.d.ts +0 -0
  219. /package/dist/{parse → types/parse}/string/shift/operand/unenclosed.d.ts +0 -0
  220. /package/dist/{parse → types/parse}/string/shift/operator/bounds.d.ts +0 -0
  221. /package/dist/{parse → types/parse}/string/shift/operator/divisor.d.ts +0 -0
  222. /package/dist/{parse → types/parse}/string/shift/operator/operator.d.ts +0 -0
  223. /package/dist/{parse → types/parse}/string/shift/scanner.d.ts +0 -0
  224. /package/dist/{parse → types/parse}/string/string.d.ts +0 -0
  225. /package/dist/{scopes → types/scopes}/ark.d.ts +0 -0
  226. /package/dist/{scopes → types/scopes}/cache.d.ts +0 -0
  227. /package/dist/{scopes → types/scopes}/expressions.d.ts +0 -0
  228. /package/dist/{scopes → types/scopes}/jsObjects.d.ts +0 -0
  229. /package/dist/{scopes → types/scopes}/scope.d.ts +0 -0
  230. /package/dist/{scopes → types/scopes}/tsKeywords.d.ts +0 -0
  231. /package/dist/{scopes → types/scopes}/type.d.ts +0 -0
  232. /package/dist/{scopes → types/scopes}/validation/creditCard.d.ts +0 -0
  233. /package/dist/{scopes → types/scopes}/validation/date.d.ts +0 -0
  234. /package/dist/{scopes → types/scopes}/validation/validation.d.ts +0 -0
  235. /package/dist/{traverse → types/traverse}/problems.d.ts +0 -0
  236. /package/dist/{traverse → types/traverse}/traverse.d.ts +0 -0
  237. /package/dist/{utils → types/utils}/chainableNoOpProxy.d.ts +0 -0
  238. /package/dist/{utils → types/utils}/data.d.ts +0 -0
  239. /package/dist/{utils → types/utils}/domains.d.ts +0 -0
  240. /package/dist/{utils → types/utils}/errors.d.ts +0 -0
  241. /package/dist/{utils → types/utils}/freeze.d.ts +0 -0
  242. /package/dist/{utils → types/utils}/generics.d.ts +0 -0
  243. /package/dist/{utils → types/utils}/numericLiterals.d.ts +0 -0
  244. /package/dist/{utils → types/utils}/objectKinds.d.ts +0 -0
  245. /package/dist/{utils → types/utils}/paths.d.ts +0 -0
  246. /package/dist/{utils → types/utils}/serialize.d.ts +0 -0
  247. /package/dist/{utils → types/utils}/unionToTuple.d.ts +0 -0
@@ -1,39 +1,48 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serializeCase = exports.serializeDefinitionIfAllowed = exports.flattenBranches = void 0;
4
- const union_js_1 = require("../parse/ast/union.js");
5
- const domains_js_1 = require("../utils/domains.js");
6
- const errors_js_1 = require("../utils/errors.js");
7
- const generics_js_1 = require("../utils/generics.js");
8
- const objectKinds_js_1 = require("../utils/objectKinds.js");
9
- const paths_js_1 = require("../utils/paths.js");
10
- const serialize_js_1 = require("../utils/serialize.js");
11
- const branch_js_1 = require("./branch.js");
12
- const compose_js_1 = require("./compose.js");
13
- const props_js_1 = require("./rules/props.js");
14
- const flattenBranches = (branches, ctx) => {
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
+ flattenBranches: ()=>flattenBranches,
13
+ serializeDefinitionIfAllowed: ()=>serializeDefinitionIfAllowed,
14
+ serializeCase: ()=>serializeCase
15
+ });
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
+ const flattenBranches = (branches, ctx)=>{
15
27
  const discriminants = calculateDiscriminants(branches, ctx);
16
- const indices = branches.map((_, i) => i);
28
+ const indices = branches.map((_, i)=>i);
17
29
  return discriminate(branches, indices, discriminants, ctx);
18
30
  };
19
- exports.flattenBranches = flattenBranches;
20
- const discriminate = (originalBranches, remainingIndices, discriminants, ctx) => {
31
+ const discriminate = (originalBranches, remainingIndices, discriminants, ctx)=>{
21
32
  if (remainingIndices.length === 1) {
22
- return (0, branch_js_1.flattenBranch)(originalBranches[remainingIndices[0]], ctx);
33
+ return (0, _branchJs.flattenBranch)(originalBranches[remainingIndices[0]], ctx);
23
34
  }
24
35
  const bestDiscriminant = findBestDiscriminant(remainingIndices, discriminants);
25
36
  if (!bestDiscriminant) {
26
37
  return [
27
38
  [
28
39
  "branches",
29
- remainingIndices.map((i) => branchIncludesMorph(originalBranches[i], ctx.type.scope)
30
- ? (0, errors_js_1.throwParseError)((0, union_js_1.writeUndiscriminatableMorphUnionMessage)(`${ctx.path}`))
31
- : (0, branch_js_1.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))
32
41
  ]
33
42
  ];
34
43
  }
35
44
  const cases = {};
36
- for (const caseKey in bestDiscriminant.indexCases) {
45
+ for(const caseKey in bestDiscriminant.indexCases){
37
46
  const nextIndices = bestDiscriminant.indexCases[caseKey];
38
47
  cases[caseKey] = discriminate(originalBranches, nextIndices, discriminants, ctx);
39
48
  if (caseKey !== "default") {
@@ -51,30 +60,24 @@ const discriminate = (originalBranches, remainingIndices, discriminants, ctx) =>
51
60
  ]
52
61
  ];
53
62
  };
54
- const pruneDiscriminant = (entries, segments, discriminant, ctx) => {
55
- for (let i = 0; i < entries.length; i++) {
63
+ const pruneDiscriminant = (entries, segments, discriminant, ctx)=>{
64
+ for(let i = 0; i < entries.length; i++){
56
65
  const [k, v] = entries[i];
57
66
  if (!segments.length) {
58
67
  if (discriminant.kind === "domain") {
59
68
  if (k === "domain" || k === "domains") {
60
69
  entries.splice(i, 1);
61
70
  return;
62
- }
63
- else if (k === "class" || k === "value") {
71
+ } else if (k === "class" || k === "value") {
64
72
  // these keys imply a domain, but also add additional
65
73
  // information, so can't be pruned
66
74
  return;
67
75
  }
68
- }
69
- else if (discriminant.kind === k) {
76
+ } else if (discriminant.kind === k) {
70
77
  entries.splice(i, 1);
71
78
  return;
72
79
  }
73
- }
74
- else if ((k === "requiredProp" ||
75
- k === "prerequisiteProp" ||
76
- k === "optionalProp") &&
77
- v[0] === segments[0]) {
80
+ } else if ((k === "requiredProp" || k === "prerequisiteProp" || k === "optionalProp") && v[0] === segments[0]) {
78
81
  if (typeof v[1] === "string") {
79
82
  if (discriminant.kind !== "domain") {
80
83
  return throwInternalPruneFailure(discriminant);
@@ -91,21 +94,18 @@ const pruneDiscriminant = (entries, segments, discriminant, ctx) => {
91
94
  // check for branch keys, which must be traversed even if there are no
92
95
  // segments left
93
96
  if (k === "domains") {
94
- /* c8 ignore next */
95
- if ((0, generics_js_1.keyCount)(v) !== 1 || !v.object) {
97
+ /* c8 ignore next */ if ((0, _genericsJs.keyCount)(v) !== 1 || !v.object) {
96
98
  return throwInternalPruneFailure(discriminant);
97
99
  }
98
100
  pruneDiscriminant(v.object, segments, discriminant, ctx);
99
101
  return;
100
- }
101
- else if (k === "switch") {
102
- for (const caseKey in v.cases) {
102
+ } else if (k === "switch") {
103
+ for(const caseKey in v.cases){
103
104
  pruneDiscriminant(v.cases[caseKey], segments, discriminant, ctx);
104
105
  }
105
106
  return;
106
- }
107
- else if (k === "branches") {
108
- for (const branch of v) {
107
+ } else if (k === "branches") {
108
+ for (const branch of v){
109
109
  pruneDiscriminant(branch, segments, discriminant, ctx);
110
110
  }
111
111
  return;
@@ -113,37 +113,34 @@ const pruneDiscriminant = (entries, segments, discriminant, ctx) => {
113
113
  }
114
114
  return throwInternalPruneFailure(discriminant);
115
115
  };
116
- const throwInternalPruneFailure = (discriminant) => (0, errors_js_1.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,
120
120
  value: true
121
121
  };
122
- const calculateDiscriminants = (branches, ctx) => {
122
+ const calculateDiscriminants = (branches, ctx)=>{
123
123
  const discriminants = {
124
124
  disjointsByPair: {},
125
125
  casesByDisjoint: {}
126
126
  };
127
- for (let lIndex = 0; lIndex < branches.length - 1; lIndex++) {
128
- for (let rIndex = lIndex + 1; rIndex < branches.length; rIndex++) {
127
+ for(let lIndex = 0; lIndex < branches.length - 1; lIndex++){
128
+ for(let rIndex = lIndex + 1; rIndex < branches.length; rIndex++){
129
129
  const pairKey = `${lIndex}/${rIndex}`;
130
130
  const pairDisjoints = [];
131
131
  discriminants.disjointsByPair[pairKey] = pairDisjoints;
132
- const intersectionState = new compose_js_1.IntersectionState(ctx.type, "|");
133
- (0, branch_js_1.branchIntersection)(branches[lIndex], branches[rIndex], intersectionState);
134
- for (const path in intersectionState.disjoints) {
135
- if (path.includes(props_js_1.mappedKeys.index)) {
136
- // containers could be empty and therefore their elements cannot be used to discriminate
137
- // allowing this via a special case where both are length >0 tracked here:
138
- // https://github.com/arktypeio/arktype/issues/593
132
+ const intersectionState = new _composeJs.IntersectionState(ctx.type, "|");
133
+ (0, _branchJs.branchIntersection)(branches[lIndex], branches[rIndex], intersectionState);
134
+ for(const path in intersectionState.disjoints){
135
+ if (path.includes(_propsJs.mappedKeys.index)) {
139
136
  continue;
140
137
  }
141
- const { l, r, kind } = intersectionState.disjoints[path];
142
- if (!(0, generics_js_1.isKeyOf)(kind, discriminantKinds)) {
138
+ const { l , r , kind } = intersectionState.disjoints[path];
139
+ if (!(0, _genericsJs.isKeyOf)(kind, discriminantKinds)) {
143
140
  continue;
144
141
  }
145
- const lSerialized = (0, exports.serializeDefinitionIfAllowed)(kind, l);
146
- const rSerialized = (0, exports.serializeDefinitionIfAllowed)(kind, r);
142
+ const lSerialized = serializeDefinitionIfAllowed(kind, l);
143
+ const rSerialized = serializeDefinitionIfAllowed(kind, r);
147
144
  if (lSerialized === undefined || rSerialized === undefined) {
148
145
  continue;
149
146
  }
@@ -151,24 +148,30 @@ const calculateDiscriminants = (branches, ctx) => {
151
148
  pairDisjoints.push(qualifiedDisjoint);
152
149
  if (!discriminants.casesByDisjoint[qualifiedDisjoint]) {
153
150
  discriminants.casesByDisjoint[qualifiedDisjoint] = {
154
- [lSerialized]: [lIndex],
155
- [rSerialized]: [rIndex]
151
+ [lSerialized]: [
152
+ lIndex
153
+ ],
154
+ [rSerialized]: [
155
+ rIndex
156
+ ]
156
157
  };
157
158
  continue;
158
159
  }
159
160
  const cases = discriminants.casesByDisjoint[qualifiedDisjoint];
160
161
  const existingLBranch = cases[lSerialized];
161
162
  if (!existingLBranch) {
162
- cases[lSerialized] = [lIndex];
163
- }
164
- else if (!existingLBranch.includes(lIndex)) {
163
+ cases[lSerialized] = [
164
+ lIndex
165
+ ];
166
+ } else if (!existingLBranch.includes(lIndex)) {
165
167
  existingLBranch.push(lIndex);
166
168
  }
167
169
  const existingRBranch = cases[rSerialized];
168
170
  if (!existingRBranch) {
169
- cases[rSerialized] = [rIndex];
170
- }
171
- else if (!existingRBranch.includes(rIndex)) {
171
+ cases[rSerialized] = [
172
+ rIndex
173
+ ];
174
+ } else if (!existingRBranch.includes(rIndex)) {
172
175
  existingRBranch.push(rIndex);
173
176
  }
174
177
  }
@@ -176,26 +179,29 @@ const calculateDiscriminants = (branches, ctx) => {
176
179
  }
177
180
  return discriminants;
178
181
  };
179
- const parseQualifiedDisjoint = (qualifiedDisjoint) => {
180
- const path = paths_js_1.Path.fromString(qualifiedDisjoint);
181
- return [path, path.pop()];
182
+ const parseQualifiedDisjoint = (qualifiedDisjoint)=>{
183
+ const path = _pathsJs.Path.fromString(qualifiedDisjoint);
184
+ return [
185
+ path,
186
+ path.pop()
187
+ ];
182
188
  };
183
- const findBestDiscriminant = (remainingIndices, discriminants) => {
189
+ const findBestDiscriminant = (remainingIndices, discriminants)=>{
184
190
  let bestDiscriminant;
185
- for (let i = 0; i < remainingIndices.length - 1; i++) {
191
+ for(let i = 0; i < remainingIndices.length - 1; i++){
186
192
  const lIndex = remainingIndices[i];
187
- for (let j = i + 1; j < remainingIndices.length; j++) {
193
+ for(let j = i + 1; j < remainingIndices.length; j++){
188
194
  const rIndex = remainingIndices[j];
189
195
  const candidates = discriminants.disjointsByPair[`${lIndex}/${rIndex}`];
190
- for (const qualifiedDisjoint of candidates) {
196
+ for (const qualifiedDisjoint of candidates){
191
197
  const indexCases = discriminants.casesByDisjoint[qualifiedDisjoint];
192
198
  const filteredCases = {};
193
199
  const defaultCases = [
194
200
  ...remainingIndices
195
201
  ];
196
202
  let score = 0;
197
- for (const caseKey in indexCases) {
198
- const filteredIndices = indexCases[caseKey].filter((i) => {
203
+ for(const caseKey in indexCases){
204
+ const filteredIndices = indexCases[caseKey].filter((i)=>{
199
205
  const remainingIndex = remainingIndices.indexOf(i);
200
206
  if (remainingIndex !== -1) {
201
207
  delete defaultCases[remainingIndex];
@@ -208,9 +214,9 @@ const findBestDiscriminant = (remainingIndices, discriminants) => {
208
214
  filteredCases[caseKey] = filteredIndices;
209
215
  score++;
210
216
  }
211
- const defaultCaseKeys = (0, generics_js_1.objectKeysOf)(defaultCases);
217
+ const defaultCaseKeys = (0, _genericsJs.objectKeysOf)(defaultCases);
212
218
  if (defaultCaseKeys.length) {
213
- filteredCases["default"] = defaultCaseKeys.map((k) => parseInt(k));
219
+ filteredCases["default"] = defaultCaseKeys.map((k)=>parseInt(k));
214
220
  }
215
221
  if (!bestDiscriminant || score > bestDiscriminant.score) {
216
222
  const [path, kind] = parseQualifiedDisjoint(qualifiedDisjoint);
@@ -230,41 +236,27 @@ const findBestDiscriminant = (remainingIndices, discriminants) => {
230
236
  }
231
237
  return bestDiscriminant;
232
238
  };
233
- const serializeDefinitionIfAllowed = (kind, definition) => {
234
- switch (kind) {
239
+ const serializeDefinitionIfAllowed = (kind, definition)=>{
240
+ switch(kind){
235
241
  case "value":
236
242
  return serializeIfPrimitive(definition);
237
243
  case "domain":
238
244
  return definition;
239
245
  case "class":
240
- return (0, objectKinds_js_1.getExactConstructorObjectKind)(definition);
246
+ return (0, _objectKindsJs.getExactConstructorObjectKind)(definition);
241
247
  default:
242
248
  return;
243
249
  }
244
250
  };
245
- exports.serializeDefinitionIfAllowed = serializeDefinitionIfAllowed;
246
- const serializeIfPrimitive = (data) => {
247
- const domain = (0, domains_js_1.domainOf)(data);
248
- return domain === "object" || domain === "symbol"
249
- ? undefined
250
- : (0, serialize_js_1.serializePrimitive)(data);
251
+ const serializeIfPrimitive = (data)=>{
252
+ const domain = (0, _domainsJs.domainOf)(data);
253
+ return domain === "object" || domain === "symbol" ? undefined : (0, _serializeJs.serializePrimitive)(data);
251
254
  };
252
255
  const serializeData = {
253
- value: (data) => serializeIfPrimitive(data) ?? "default",
254
- class: (data) => (0, objectKinds_js_1.objectKindOf)(data) ?? "default",
255
- domain: domains_js_1.domainOf
256
+ value: (data)=>serializeIfPrimitive(data) ?? "default",
257
+ class: (data)=>(0, _objectKindsJs.objectKindOf)(data) ?? "default",
258
+ domain: _domainsJs.domainOf
256
259
  };
257
- const serializeCase = (kind, data) => serializeData[kind](data);
258
- exports.serializeCase = serializeCase;
259
- const branchIncludesMorph = (branch, $) => "morph" in branch
260
- ? true
261
- : "props" in branch
262
- ? Object.values(branch.props).some((prop) => nodeIncludesMorph((0, props_js_1.propToNode)(prop), $))
263
- : false;
264
- const nodeIncludesMorph = (node, $) => typeof node === "string"
265
- ? $.resolve(node).includesMorph
266
- : Object.values($.resolveTypeNode(node)).some((predicate) => predicate === true
267
- ? false
268
- : (0, objectKinds_js_1.isArray)(predicate)
269
- ? predicate.some((branch) => branchIncludesMorph(branch, $))
270
- : branchIncludesMorph(predicate, $));
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, _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, $));
@@ -0,0 +1,139 @@
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
+ isConfigNode: ()=>isConfigNode,
13
+ nodeIntersection: ()=>nodeIntersection,
14
+ rootIntersection: ()=>rootIntersection,
15
+ rootUnion: ()=>rootUnion,
16
+ flattenType: ()=>flattenType,
17
+ flattenNode: ()=>flattenNode,
18
+ flattenTypeNode: ()=>flattenTypeNode,
19
+ isLiteralNode: ()=>isLiteralNode,
20
+ resolutionExtendsDomain: ()=>resolutionExtendsDomain,
21
+ toArrayNode: ()=>toArrayNode
22
+ });
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
+ const isConfigNode = (node)=>"config" in node;
31
+ const nodeIntersection = (l, r, state)=>{
32
+ state.domain = undefined;
33
+ const lDomains = state.type.scope.resolveTypeNode(l);
34
+ const rDomains = state.type.scope.resolveTypeNode(r);
35
+ const result = typeNodeIntersection(lDomains, rDomains, state);
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
+ }
39
+ return result === lDomains ? l : result === rDomains ? r : result;
40
+ };
41
+ const typeNodeIntersection = (0, _composeJs.composeKeyedIntersection)((domain, l, r, context)=>{
42
+ if (l === undefined) {
43
+ return r === undefined ? (0, _errorsJs.throwInternalError)(_composeJs.undefinedOperandsMessage) : undefined;
44
+ }
45
+ if (r === undefined) {
46
+ return undefined;
47
+ }
48
+ return (0, _predicateJs.predicateIntersection)(domain, l, r, context);
49
+ }, {
50
+ onEmpty: "omit"
51
+ });
52
+ const rootIntersection = (l, r, type)=>{
53
+ const state = new _composeJs.IntersectionState(type, "&");
54
+ const result = nodeIntersection(l, r, state);
55
+ return (0, _composeJs.isDisjoint)(result) ? (0, _errorsJs.throwParseError)((0, _intersectionJs.compileDisjointReasonsMessage)(state.disjoints)) : (0, _composeJs.isEquality)(result) ? l : result;
56
+ };
57
+ const rootUnion = (l, r, type)=>{
58
+ const lDomains = type.scope.resolveTypeNode(l);
59
+ const rDomains = type.scope.resolveTypeNode(r);
60
+ const result = {};
61
+ const domains = (0, _genericsJs.objectKeysOf)({
62
+ ...lDomains,
63
+ ...rDomains
64
+ });
65
+ for (const domain of domains){
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
+ }
68
+ return result;
69
+ };
70
+ const hasImpliedDomain = (flatPredicate)=>flatPredicate[0] && (flatPredicate[0][0] === "value" || flatPredicate[0][0] === "class");
71
+ const flattenType = (type)=>{
72
+ const ctx = {
73
+ type,
74
+ path: new _pathsJs.Path(),
75
+ lastDomain: "undefined"
76
+ };
77
+ return flattenNode(type.node, ctx);
78
+ };
79
+ const flattenNode = (node, ctx)=>{
80
+ if (typeof node === "string") {
81
+ return ctx.type.scope.resolve(node).flat;
82
+ }
83
+ const hasConfig = isConfigNode(node);
84
+ const flattenedTypeNode = flattenTypeNode(hasConfig ? node.node : node, ctx);
85
+ return hasConfig ? [
86
+ [
87
+ "config",
88
+ {
89
+ config: (0, _genericsJs.entriesOf)(node.config),
90
+ node: flattenedTypeNode
91
+ }
92
+ ]
93
+ ] : flattenedTypeNode;
94
+ };
95
+ const flattenTypeNode = (node, ctx)=>{
96
+ const domains = (0, _genericsJs.objectKeysOf)(node);
97
+ if (domains.length === 1) {
98
+ const domain = domains[0];
99
+ const predicate = node[domain];
100
+ if (predicate === true) {
101
+ return domain;
102
+ }
103
+ ctx.lastDomain = domain;
104
+ const flatPredicate = (0, _predicateJs.flattenPredicate)(predicate, ctx);
105
+ return hasImpliedDomain(flatPredicate) ? flatPredicate : [
106
+ [
107
+ "domain",
108
+ domain
109
+ ],
110
+ ...flatPredicate
111
+ ];
112
+ }
113
+ const result = {};
114
+ for (const domain of domains){
115
+ ctx.lastDomain = domain;
116
+ result[domain] = (0, _predicateJs.flattenPredicate)(node[domain], ctx);
117
+ }
118
+ return [
119
+ [
120
+ "domains",
121
+ result
122
+ ]
123
+ ];
124
+ };
125
+ const isLiteralNode = (node, domain)=>{
126
+ return resolutionExtendsDomain(node, domain) && (0, _predicateJs.isLiteralCondition)(node[domain]);
127
+ };
128
+ const resolutionExtendsDomain = (resolution, domain)=>{
129
+ const domains = (0, _genericsJs.objectKeysOf)(resolution);
130
+ return domains.length === 1 && domains[0] === domain;
131
+ };
132
+ const toArrayNode = (node)=>({
133
+ object: {
134
+ class: Array,
135
+ props: {
136
+ [_propsJs.mappedKeys.index]: node
137
+ }
138
+ }
139
+ });
@@ -0,0 +1,86 @@
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
+ comparePredicates: ()=>comparePredicates,
13
+ predicateIntersection: ()=>predicateIntersection,
14
+ predicateUnion: ()=>predicateUnion,
15
+ flattenPredicate: ()=>flattenPredicate,
16
+ isLiteralCondition: ()=>isLiteralCondition
17
+ });
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
+ const emptyRulesIfTrue = (predicate)=>predicate === true ? {} : predicate;
24
+ const comparePredicates = (l, r, context)=>{
25
+ if (l === true && r === true) {
26
+ return (0, _composeJs.equality)();
27
+ }
28
+ if (!(0, _objectKindsJs.isArray)(l) && !(0, _objectKindsJs.isArray)(r)) {
29
+ const result = (0, _branchJs.branchIntersection)(emptyRulesIfTrue(l), emptyRulesIfTrue(r), context);
30
+ return result === l ? l : result === r ? r : result;
31
+ }
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
+ if (comparison.equalities.length === lBranches.length && comparison.equalities.length === rBranches.length) {
36
+ return (0, _composeJs.equality)();
37
+ }
38
+ if (comparison.lExtendsR.length + comparison.equalities.length === lBranches.length) {
39
+ return l;
40
+ }
41
+ if (comparison.rExtendsL.length + comparison.equalities.length === rBranches.length) {
42
+ return r;
43
+ }
44
+ return comparison;
45
+ };
46
+ const predicateIntersection = (domain, l, r, state)=>{
47
+ state.domain = domain;
48
+ const comparison = comparePredicates(l, r, state);
49
+ if (!(0, _branchJs.isBranchComparison)(comparison)) {
50
+ return comparison;
51
+ }
52
+ const resultBranches = [
53
+ ...comparison.distinctIntersections,
54
+ ...comparison.equalities.map((indices)=>comparison.lBranches[indices[0]]),
55
+ ...comparison.lExtendsR.map((lIndex)=>comparison.lBranches[lIndex]),
56
+ ...comparison.rExtendsL.map((rIndex)=>comparison.rBranches[rIndex])
57
+ ];
58
+ if (resultBranches.length === 0) {
59
+ state.addDisjoint("union", comparison.lBranches, comparison.rBranches);
60
+ }
61
+ return resultBranches.length === 1 ? resultBranches[0] : resultBranches;
62
+ };
63
+ const predicateUnion = (domain, l, r, type)=>{
64
+ const state = new _composeJs.IntersectionState(type, "|");
65
+ const comparison = comparePredicates(l, r, state);
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
+ // and can be simplified to a non-literal boolean.
69
+ domain === "boolean" ? true : [
70
+ emptyRulesIfTrue(l),
71
+ emptyRulesIfTrue(r)
72
+ ];
73
+ }
74
+ const resultBranches = [
75
+ ...comparison.lBranches.filter((_, lIndex)=>!comparison.lExtendsR.includes(lIndex) && !comparison.equalities.some((indexPair)=>indexPair[0] === lIndex)),
76
+ ...comparison.rBranches.filter((_, rIndex)=>!comparison.rExtendsL.includes(rIndex) && !comparison.equalities.some((indexPair)=>indexPair[1] === rIndex))
77
+ ];
78
+ return resultBranches.length === 1 ? resultBranches[0] : resultBranches;
79
+ };
80
+ const flattenPredicate = (predicate, context)=>{
81
+ if (predicate === true) {
82
+ return [];
83
+ }
84
+ return (0, _objectKindsJs.isArray)(predicate) ? (0, _discriminateJs.flattenBranches)(predicate, context) : (0, _branchJs.flattenBranch)(predicate, context);
85
+ };
86
+ const isLiteralCondition = (predicate)=>typeof predicate === "object" && "value" in predicate;
@@ -0,0 +1,25 @@
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
+ classIntersection: ()=>classIntersection,
13
+ checkClass: ()=>checkClass
14
+ });
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
+ });
20
+ const checkClass = (expectedClass, state)=>{
21
+ if (typeof expectedClass === "string") {
22
+ return (0, _objectKindsJs.objectKindOf)(state.data) === expectedClass || !state.problems.add("class", expectedClass);
23
+ }
24
+ return state.data instanceof expectedClass || !state.problems.add("class", expectedClass);
25
+ };
@@ -0,0 +1,48 @@
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
+ collapsibleListUnion: ()=>collapsibleListUnion,
13
+ listUnion: ()=>listUnion
14
+ });
15
+ const _composeJs = require("../compose.js");
16
+ const collapsibleListUnion = (l, r)=>{
17
+ if (Array.isArray(l)) {
18
+ if (Array.isArray(r)) {
19
+ const result = listUnion(l, r);
20
+ return result.length === l.length ? result.length === r.length ? (0, _composeJs.equality)() : l : result.length === r.length ? r : result;
21
+ }
22
+ return l.includes(r) ? l : [
23
+ ...l,
24
+ r
25
+ ];
26
+ }
27
+ if (Array.isArray(r)) {
28
+ return r.includes(l) ? r : [
29
+ ...r,
30
+ l
31
+ ];
32
+ }
33
+ return l === r ? (0, _composeJs.equality)() : [
34
+ l,
35
+ r
36
+ ];
37
+ };
38
+ const listUnion = (l, r)=>{
39
+ const result = [
40
+ ...l
41
+ ];
42
+ for (const expression of r){
43
+ if (!l.includes(expression)) {
44
+ result.push(expression);
45
+ }
46
+ }
47
+ return result;
48
+ };
@@ -0,0 +1,29 @@
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
+ divisorIntersection: ()=>divisorIntersection,
13
+ checkDivisor: ()=>checkDivisor
14
+ });
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
+ // https://en.wikipedia.org/wiki/Euclidean_algorithm
18
+ const greatestCommonDivisor = (l, r)=>{
19
+ let previous;
20
+ let greatestCommonDivisor = l;
21
+ let current = r;
22
+ while(current !== 0){
23
+ previous = current;
24
+ current = greatestCommonDivisor % current;
25
+ greatestCommonDivisor = previous;
26
+ }
27
+ return greatestCommonDivisor;
28
+ };
29
+ const checkDivisor = (divisor, state)=>state.data % divisor === 0 || !state.problems.add("divisor", divisor);