arktype 1.0.15-alpha → 1.0.17-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/package.json +3 -0
  3. package/dist/cjs/src/main.js +38 -0
  4. package/dist/cjs/src/nodes/branch.js +140 -0
  5. package/dist/cjs/src/nodes/compose.js +157 -0
  6. package/dist/{nodes → cjs/src/nodes}/discriminate.js +92 -100
  7. package/dist/cjs/src/nodes/node.js +139 -0
  8. package/dist/cjs/src/nodes/predicate.js +86 -0
  9. package/dist/cjs/src/nodes/rules/class.js +25 -0
  10. package/dist/cjs/src/nodes/rules/collapsibleSet.js +48 -0
  11. package/dist/cjs/src/nodes/rules/divisor.js +29 -0
  12. package/dist/cjs/src/nodes/rules/props.js +160 -0
  13. package/dist/cjs/src/nodes/rules/range.js +105 -0
  14. package/dist/cjs/src/nodes/rules/regex.js +26 -0
  15. package/dist/cjs/src/nodes/rules/rules.js +123 -0
  16. package/dist/cjs/src/parse/ast/ast.js +4 -0
  17. package/dist/cjs/src/parse/ast/bound.js +16 -0
  18. package/dist/cjs/src/parse/ast/config.js +13 -0
  19. package/dist/cjs/src/parse/ast/distributableFunction.js +48 -0
  20. package/dist/cjs/src/parse/ast/divisor.js +9 -0
  21. package/dist/cjs/src/parse/ast/intersection.js +30 -0
  22. package/dist/cjs/src/parse/ast/keyof.js +111 -0
  23. package/dist/cjs/src/parse/ast/morph.js +58 -0
  24. package/dist/cjs/src/parse/ast/narrow.js +22 -0
  25. package/dist/cjs/src/parse/ast/node.js +4 -0
  26. package/dist/cjs/src/parse/ast/tuple.js +94 -0
  27. package/dist/cjs/src/parse/ast/union.js +9 -0
  28. package/dist/cjs/src/parse/ast/utils.js +4 -0
  29. package/dist/cjs/src/parse/definition.js +61 -0
  30. package/dist/cjs/src/parse/record.js +37 -0
  31. package/dist/cjs/src/parse/string/reduce/dynamic.js +167 -0
  32. package/dist/cjs/src/parse/string/reduce/shared.js +23 -0
  33. package/dist/cjs/src/parse/string/reduce/static.js +4 -0
  34. package/dist/cjs/src/parse/string/shift/operand/enclosed.js +54 -0
  35. package/dist/cjs/src/parse/string/shift/operand/operand.js +11 -0
  36. package/dist/cjs/src/parse/string/shift/operand/unenclosed.js +53 -0
  37. package/dist/cjs/src/parse/string/shift/operator/bounds.js +87 -0
  38. package/dist/cjs/src/parse/string/shift/operator/divisor.js +35 -0
  39. package/dist/cjs/src/parse/string/shift/operator/operator.js +26 -0
  40. package/dist/cjs/src/parse/string/shift/scanner.js +114 -0
  41. package/dist/cjs/src/parse/string/string.js +43 -0
  42. package/dist/cjs/src/scopes/ark.js +45 -0
  43. package/dist/cjs/src/scopes/cache.js +52 -0
  44. package/dist/cjs/src/scopes/expressions.js +29 -0
  45. package/dist/cjs/src/scopes/jsObjects.js +93 -0
  46. package/dist/cjs/src/scopes/scope.js +323 -0
  47. package/dist/cjs/src/scopes/tsKeywords.js +113 -0
  48. package/dist/cjs/src/scopes/type.js +50 -0
  49. package/dist/cjs/src/scopes/validation/creditCard.js +47 -0
  50. package/dist/cjs/src/scopes/validation/date.js +62 -0
  51. package/dist/cjs/src/scopes/validation/validation.js +108 -0
  52. package/dist/cjs/src/traverse/problems.js +281 -0
  53. package/dist/cjs/src/traverse/traverse.js +390 -0
  54. package/dist/cjs/src/utils/chainableNoOpProxy.js +23 -0
  55. package/dist/cjs/src/utils/data.js +53 -0
  56. package/dist/cjs/src/utils/domains.js +30 -0
  57. package/dist/cjs/src/utils/errors.js +26 -0
  58. package/dist/cjs/src/utils/freeze.js +15 -0
  59. package/dist/cjs/src/utils/generics.js +63 -0
  60. package/dist/cjs/src/utils/numericLiterals.js +75 -0
  61. package/dist/cjs/src/utils/objectKinds.js +69 -0
  62. package/dist/cjs/src/utils/paths.js +32 -0
  63. package/dist/cjs/src/utils/serialize.js +74 -0
  64. package/dist/cjs/src/utils/unionToTuple.js +4 -0
  65. package/dist/mjs/package.json +3 -0
  66. package/dist/mjs/src/main.js +8 -0
  67. package/dist/mjs/src/nodes/branch.js +123 -0
  68. package/dist/mjs/src/nodes/compose.js +135 -0
  69. package/dist/mjs/src/nodes/discriminate.js +247 -0
  70. package/dist/mjs/src/nodes/node.js +117 -0
  71. package/dist/mjs/src/nodes/predicate.js +69 -0
  72. package/dist/mjs/src/nodes/rules/class.js +11 -0
  73. package/dist/mjs/src/nodes/rules/collapsibleSet.js +34 -0
  74. package/dist/mjs/src/nodes/rules/divisor.js +15 -0
  75. package/dist/mjs/src/nodes/rules/props.js +142 -0
  76. package/dist/mjs/src/nodes/rules/range.js +86 -0
  77. package/dist/mjs/src/nodes/rules/regex.js +11 -0
  78. package/dist/mjs/src/nodes/rules/rules.js +106 -0
  79. package/dist/mjs/src/parse/ast/ast.js +1 -0
  80. package/dist/mjs/src/parse/ast/bound.js +2 -0
  81. package/dist/mjs/src/parse/ast/config.js +9 -0
  82. package/dist/mjs/src/parse/ast/distributableFunction.js +34 -0
  83. package/dist/mjs/src/parse/ast/divisor.js +1 -0
  84. package/dist/mjs/src/parse/ast/intersection.js +16 -0
  85. package/dist/mjs/src/parse/ast/keyof.js +103 -0
  86. package/dist/mjs/src/parse/ast/morph.js +44 -0
  87. package/dist/mjs/src/parse/ast/narrow.js +14 -0
  88. package/dist/mjs/src/parse/ast/node.js +1 -0
  89. package/dist/mjs/src/parse/ast/tuple.js +80 -0
  90. package/dist/mjs/src/parse/ast/union.js +1 -0
  91. package/dist/mjs/src/parse/ast/utils.js +1 -0
  92. package/dist/mjs/src/parse/definition.js +46 -0
  93. package/dist/mjs/src/parse/record.js +29 -0
  94. package/dist/mjs/src/parse/string/reduce/dynamic.js +159 -0
  95. package/dist/mjs/src/parse/string/reduce/shared.js +6 -0
  96. package/dist/mjs/src/parse/string/reduce/static.js +1 -0
  97. package/dist/mjs/src/parse/string/shift/operand/enclosed.js +39 -0
  98. package/dist/mjs/src/parse/string/shift/operand/operand.js +3 -0
  99. package/dist/mjs/src/parse/string/shift/operand/unenclosed.js +36 -0
  100. package/dist/mjs/src/parse/string/shift/operator/bounds.js +70 -0
  101. package/dist/mjs/src/parse/string/shift/operator/divisor.js +21 -0
  102. package/dist/mjs/src/parse/string/shift/operator/operator.js +13 -0
  103. package/dist/mjs/src/parse/string/shift/scanner.js +106 -0
  104. package/dist/mjs/src/parse/string/string.js +28 -0
  105. package/dist/mjs/src/scopes/ark.js +28 -0
  106. package/dist/mjs/src/scopes/cache.js +38 -0
  107. package/dist/{scopes → mjs/src/scopes}/expressions.js +9 -20
  108. package/dist/mjs/src/scopes/jsObjects.js +82 -0
  109. package/dist/mjs/src/scopes/scope.js +303 -0
  110. package/dist/mjs/src/scopes/tsKeywords.js +116 -0
  111. package/dist/mjs/src/scopes/type.js +35 -0
  112. package/dist/{scopes → mjs/src/scopes}/validation/creditCard.js +11 -15
  113. package/dist/{scopes → mjs/src/scopes}/validation/date.js +16 -21
  114. package/dist/mjs/src/scopes/validation/validation.js +112 -0
  115. package/dist/mjs/src/traverse/problems.js +260 -0
  116. package/dist/mjs/src/traverse/traverse.js +373 -0
  117. package/dist/{utils → mjs/src/utils}/chainableNoOpProxy.js +2 -6
  118. package/dist/mjs/src/utils/data.js +38 -0
  119. package/dist/mjs/src/utils/domains.js +15 -0
  120. package/dist/mjs/src/utils/errors.js +10 -0
  121. package/dist/mjs/src/utils/freeze.js +7 -0
  122. package/dist/mjs/src/utils/generics.js +38 -0
  123. package/dist/mjs/src/utils/numericLiterals.js +72 -0
  124. package/dist/mjs/src/utils/objectKinds.js +55 -0
  125. package/dist/{utils → mjs/src/utils}/paths.js +3 -8
  126. package/dist/mjs/src/utils/serialize.js +58 -0
  127. package/dist/mjs/src/utils/unionToTuple.js +1 -0
  128. package/dist/tsconfig.temp.tsbuildinfo +1 -1
  129. package/dist/{utils → types/utils}/generics.d.ts +2 -2
  130. package/package.json +14 -5
  131. package/dist/main.js +0 -29
  132. package/dist/nodes/branch.js +0 -135
  133. package/dist/nodes/compose.js +0 -99
  134. package/dist/nodes/node.js +0 -134
  135. package/dist/nodes/predicate.js +0 -88
  136. package/dist/nodes/rules/class.js +0 -23
  137. package/dist/nodes/rules/collapsibleSet.js +0 -34
  138. package/dist/nodes/rules/divisor.js +0 -19
  139. package/dist/nodes/rules/props.js +0 -130
  140. package/dist/nodes/rules/range.js +0 -108
  141. package/dist/nodes/rules/regex.js +0 -17
  142. package/dist/nodes/rules/rules.js +0 -102
  143. package/dist/parse/ast/ast.js +0 -2
  144. package/dist/parse/ast/bound.js +0 -7
  145. package/dist/parse/ast/config.js +0 -14
  146. package/dist/parse/ast/distributableFunction.js +0 -40
  147. package/dist/parse/ast/divisor.js +0 -5
  148. package/dist/parse/ast/intersection.js +0 -21
  149. package/dist/parse/ast/keyof.js +0 -107
  150. package/dist/parse/ast/morph.js +0 -50
  151. package/dist/parse/ast/narrow.js +0 -17
  152. package/dist/parse/ast/node.js +0 -2
  153. package/dist/parse/ast/tuple.js +0 -72
  154. package/dist/parse/ast/union.js +0 -5
  155. package/dist/parse/ast/utils.js +0 -2
  156. package/dist/parse/definition.js +0 -47
  157. package/dist/parse/record.js +0 -31
  158. package/dist/parse/string/reduce/dynamic.js +0 -159
  159. package/dist/parse/string/reduce/shared.js +0 -13
  160. package/dist/parse/string/reduce/static.js +0 -2
  161. package/dist/parse/string/shift/operand/enclosed.js +0 -37
  162. package/dist/parse/string/shift/operand/operand.js +0 -15
  163. package/dist/parse/string/shift/operand/unenclosed.js +0 -45
  164. package/dist/parse/string/shift/operator/bounds.js +0 -83
  165. package/dist/parse/string/shift/operator/divisor.js +0 -23
  166. package/dist/parse/string/shift/operator/operator.js +0 -34
  167. package/dist/parse/string/shift/scanner.js +0 -97
  168. package/dist/parse/string/string.js +0 -35
  169. package/dist/scopes/ark.js +0 -27
  170. package/dist/scopes/cache.js +0 -28
  171. package/dist/scopes/jsObjects.js +0 -20
  172. package/dist/scopes/scope.js +0 -184
  173. package/dist/scopes/tsKeywords.js +0 -49
  174. package/dist/scopes/type.js +0 -40
  175. package/dist/scopes/validation/validation.js +0 -74
  176. package/dist/traverse/problems.js +0 -234
  177. package/dist/traverse/traverse.js +0 -330
  178. package/dist/utils/data.js +0 -39
  179. package/dist/utils/domains.js +0 -27
  180. package/dist/utils/errors.js +0 -17
  181. package/dist/utils/freeze.js +0 -16
  182. package/dist/utils/generics.js +0 -53
  183. package/dist/utils/numericLiterals.js +0 -88
  184. package/dist/utils/objectKinds.js +0 -69
  185. package/dist/utils/serialize.js +0 -71
  186. package/dist/utils/unionToTuple.js +0 -2
  187. /package/dist/{main.d.ts → types/main.d.ts} +0 -0
  188. /package/dist/{nodes → types/nodes}/branch.d.ts +0 -0
  189. /package/dist/{nodes → types/nodes}/compose.d.ts +0 -0
  190. /package/dist/{nodes → types/nodes}/discriminate.d.ts +0 -0
  191. /package/dist/{nodes → types/nodes}/node.d.ts +0 -0
  192. /package/dist/{nodes → types/nodes}/predicate.d.ts +0 -0
  193. /package/dist/{nodes → types/nodes}/rules/class.d.ts +0 -0
  194. /package/dist/{nodes → types/nodes}/rules/collapsibleSet.d.ts +0 -0
  195. /package/dist/{nodes → types/nodes}/rules/divisor.d.ts +0 -0
  196. /package/dist/{nodes → types/nodes}/rules/props.d.ts +0 -0
  197. /package/dist/{nodes → types/nodes}/rules/range.d.ts +0 -0
  198. /package/dist/{nodes → types/nodes}/rules/regex.d.ts +0 -0
  199. /package/dist/{nodes → types/nodes}/rules/rules.d.ts +0 -0
  200. /package/dist/{parse → types/parse}/ast/ast.d.ts +0 -0
  201. /package/dist/{parse → types/parse}/ast/bound.d.ts +0 -0
  202. /package/dist/{parse → types/parse}/ast/config.d.ts +0 -0
  203. /package/dist/{parse → types/parse}/ast/distributableFunction.d.ts +0 -0
  204. /package/dist/{parse → types/parse}/ast/divisor.d.ts +0 -0
  205. /package/dist/{parse → types/parse}/ast/intersection.d.ts +0 -0
  206. /package/dist/{parse → types/parse}/ast/keyof.d.ts +0 -0
  207. /package/dist/{parse → types/parse}/ast/morph.d.ts +0 -0
  208. /package/dist/{parse → types/parse}/ast/narrow.d.ts +0 -0
  209. /package/dist/{parse → types/parse}/ast/node.d.ts +0 -0
  210. /package/dist/{parse → types/parse}/ast/tuple.d.ts +0 -0
  211. /package/dist/{parse → types/parse}/ast/union.d.ts +0 -0
  212. /package/dist/{parse → types/parse}/ast/utils.d.ts +0 -0
  213. /package/dist/{parse → types/parse}/definition.d.ts +0 -0
  214. /package/dist/{parse → types/parse}/record.d.ts +0 -0
  215. /package/dist/{parse → types/parse}/string/reduce/dynamic.d.ts +0 -0
  216. /package/dist/{parse → types/parse}/string/reduce/shared.d.ts +0 -0
  217. /package/dist/{parse → types/parse}/string/reduce/static.d.ts +0 -0
  218. /package/dist/{parse → types/parse}/string/shift/operand/enclosed.d.ts +0 -0
  219. /package/dist/{parse → types/parse}/string/shift/operand/operand.d.ts +0 -0
  220. /package/dist/{parse → types/parse}/string/shift/operand/unenclosed.d.ts +0 -0
  221. /package/dist/{parse → types/parse}/string/shift/operator/bounds.d.ts +0 -0
  222. /package/dist/{parse → types/parse}/string/shift/operator/divisor.d.ts +0 -0
  223. /package/dist/{parse → types/parse}/string/shift/operator/operator.d.ts +0 -0
  224. /package/dist/{parse → types/parse}/string/shift/scanner.d.ts +0 -0
  225. /package/dist/{parse → types/parse}/string/string.d.ts +0 -0
  226. /package/dist/{scopes → types/scopes}/ark.d.ts +0 -0
  227. /package/dist/{scopes → types/scopes}/cache.d.ts +0 -0
  228. /package/dist/{scopes → types/scopes}/expressions.d.ts +0 -0
  229. /package/dist/{scopes → types/scopes}/jsObjects.d.ts +0 -0
  230. /package/dist/{scopes → types/scopes}/scope.d.ts +0 -0
  231. /package/dist/{scopes → types/scopes}/tsKeywords.d.ts +0 -0
  232. /package/dist/{scopes → types/scopes}/type.d.ts +0 -0
  233. /package/dist/{scopes → types/scopes}/validation/creditCard.d.ts +0 -0
  234. /package/dist/{scopes → types/scopes}/validation/date.d.ts +0 -0
  235. /package/dist/{scopes → types/scopes}/validation/validation.d.ts +0 -0
  236. /package/dist/{traverse → types/traverse}/problems.d.ts +0 -0
  237. /package/dist/{traverse → types/traverse}/traverse.d.ts +0 -0
  238. /package/dist/{utils → types/utils}/chainableNoOpProxy.d.ts +0 -0
  239. /package/dist/{utils → types/utils}/data.d.ts +0 -0
  240. /package/dist/{utils → types/utils}/domains.d.ts +0 -0
  241. /package/dist/{utils → types/utils}/errors.d.ts +0 -0
  242. /package/dist/{utils → types/utils}/freeze.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
@@ -0,0 +1,58 @@
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
+ parseMorphTuple: ()=>parseMorphTuple,
13
+ writeMalformedMorphExpressionMessage: ()=>writeMalformedMorphExpressionMessage
14
+ });
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
+ const parseMorphTuple = (def, ctx)=>{
21
+ if (typeof def[2] !== "function") {
22
+ return (0, _errorsJs.throwParseError)(writeMalformedMorphExpressionMessage(def[2]));
23
+ }
24
+ const node = (0, _definitionJs.parseDefinition)(def[0], ctx);
25
+ const resolution = ctx.type.scope.resolveTypeNode(node);
26
+ const morph = def[2];
27
+ ctx.type.includesMorph = true;
28
+ let domain;
29
+ const result = {};
30
+ for(domain in resolution){
31
+ const predicate = resolution[domain];
32
+ if (predicate === true) {
33
+ result[domain] = {
34
+ rules: {},
35
+ morph
36
+ };
37
+ } else if (typeof predicate === "object") {
38
+ result[domain] = (0, _objectKindsJs.isArray)(predicate) ? predicate.map((branch)=>applyMorph(branch, morph)) : applyMorph(predicate, morph);
39
+ } else {
40
+ (0, _errorsJs.throwInternalError)(`Unexpected predicate value for domain '${domain}': ${(0, _serializeJs.stringify)(predicate)}`);
41
+ }
42
+ }
43
+ return result;
44
+ };
45
+ const applyMorph = (branch, morph)=>(0, _branchJs.isTransformationBranch)(branch) ? {
46
+ ...branch,
47
+ morph: branch.morph ? Array.isArray(branch.morph) ? [
48
+ ...branch.morph,
49
+ morph
50
+ ] : [
51
+ branch.morph,
52
+ morph
53
+ ] : morph
54
+ } : {
55
+ rules: branch,
56
+ morph
57
+ };
58
+ const writeMalformedMorphExpressionMessage = (value)=>`Morph expression requires a function following '|>' (was ${typeof value})`;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "parseNarrowTuple", {
6
+ enumerable: true,
7
+ get: ()=>parseNarrowTuple
8
+ });
9
+ const _nodeJs = require("../../nodes/node.js");
10
+ const _definitionJs = require("../definition.js");
11
+ const _distributableFunctionJs = require("./distributableFunction.js");
12
+ const parseNarrowTuple = (def, ctx)=>{
13
+ const inputNode = (0, _definitionJs.parseDefinition)(def[0], ctx);
14
+ const resolution = ctx.type.scope.resolveNode(inputNode);
15
+ const hasConfig = (0, _nodeJs.isConfigNode)(resolution);
16
+ const typeNode = hasConfig ? resolution.node : resolution;
17
+ const result = (0, _nodeJs.rootIntersection)(inputNode, (0, _distributableFunctionJs.distributeFunctionToNode)(def[2], typeNode, ctx, "narrow"), ctx.type);
18
+ return hasConfig ? {
19
+ config: resolution.config,
20
+ node: result
21
+ } : result;
22
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -0,0 +1,94 @@
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
+ parseTuple: ()=>parseTuple,
13
+ writeMalformedFunctionalExpressionMessage: ()=>writeMalformedFunctionalExpressionMessage
14
+ });
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
+ const parseTuple = (def, ctx)=>{
25
+ if (isIndexOneExpression(def)) {
26
+ return indexOneParsers[def[1]](def, ctx);
27
+ }
28
+ if (isIndexZeroExpression(def)) {
29
+ return prefixParsers[def[0]](def, ctx);
30
+ }
31
+ const props = {
32
+ // length is created as a prerequisite prop, ensuring if it is invalid,
33
+ // no other props will be checked, which is usually desirable for tuple
34
+ // definitions.
35
+ length: [
36
+ "!",
37
+ {
38
+ number: {
39
+ value: def.length
40
+ }
41
+ }
42
+ ]
43
+ };
44
+ for(let i = 0; i < def.length; i++){
45
+ ctx.path.push(`${i}`);
46
+ props[i] = (0, _definitionJs.parseDefinition)(def[i], ctx);
47
+ ctx.path.pop();
48
+ }
49
+ return {
50
+ object: {
51
+ class: Array,
52
+ props
53
+ }
54
+ };
55
+ };
56
+ const parseBranchTuple = (def, ctx)=>{
57
+ if (def[2] === undefined) {
58
+ return (0, _errorsJs.throwParseError)((0, _unenclosedJs.writeMissingRightOperandMessage)(def[1], ""));
59
+ }
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
+ };
64
+ const parseArrayTuple = (def, scope)=>(0, _nodeJs.toArrayNode)((0, _definitionJs.parseDefinition)(def[0], scope));
65
+ const writeMalformedFunctionalExpressionMessage = (operator, rightDef)=>`Expression requires a function following '${operator}' (was ${typeof rightDef})`;
66
+ const isIndexOneExpression = (def)=>indexOneParsers[def[1]] !== undefined;
67
+ const indexOneParsers = {
68
+ "|": parseBranchTuple,
69
+ "&": parseBranchTuple,
70
+ "[]": parseArrayTuple,
71
+ "=>": _narrowJs.parseNarrowTuple,
72
+ "|>": _morphJs.parseMorphTuple,
73
+ ":": _configJs.parseConfigTuple
74
+ };
75
+ const prefixParsers = {
76
+ keyof: _keyofJs.parseKeyOfTuple,
77
+ instanceof: (def)=>{
78
+ if (typeof def[1] !== "function") {
79
+ return (0, _errorsJs.throwParseError)(`Expected a constructor following 'instanceof' operator (was ${typeof def[1]}).`);
80
+ }
81
+ return {
82
+ object: {
83
+ class: def[1]
84
+ }
85
+ };
86
+ },
87
+ "===": (def)=>({
88
+ [(0, _domainsJs.domainOf)(def[1])]: {
89
+ value: def[1]
90
+ }
91
+ }),
92
+ node: (def)=>def[1]
93
+ };
94
+ const isIndexZeroExpression = (def)=>prefixParsers[def[0]] !== undefined;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "writeUndiscriminatableMorphUnionMessage", {
6
+ enumerable: true,
7
+ get: ()=>writeUndiscriminatableMorphUnionMessage
8
+ });
9
+ const writeUndiscriminatableMorphUnionMessage = (path)=>`${path === "/" ? "A" : `At ${path}, a`} union including one or more morphs must be discriminatable`;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -0,0 +1,61 @@
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
+ parseDefinition: ()=>parseDefinition,
13
+ as: ()=>as,
14
+ writeBadDefinitionTypeMessage: ()=>writeBadDefinitionTypeMessage
15
+ });
16
+ const _typeJs = require("../scopes/type.js");
17
+ const _domainsJs = require("../utils/domains.js");
18
+ const _errorsJs = require("../utils/errors.js");
19
+ const _objectKindsJs = require("../utils/objectKinds.js");
20
+ const _serializeJs = require("../utils/serialize.js");
21
+ const _tupleJs = require("./ast/tuple.js");
22
+ const _recordJs = require("./record.js");
23
+ const _stringJs = require("./string/string.js");
24
+ const parseDefinition = (def, ctx)=>{
25
+ const domain = (0, _domainsJs.domainOf)(def);
26
+ if (domain === "string") {
27
+ return (0, _stringJs.parseString)(def, ctx);
28
+ }
29
+ if (domain !== "object") {
30
+ return (0, _errorsJs.throwParseError)(writeBadDefinitionTypeMessage(domain));
31
+ }
32
+ const objectKind = (0, _objectKindsJs.objectKindOf)(def);
33
+ switch(objectKind){
34
+ case "Object":
35
+ return (0, _recordJs.parseRecord)(def, ctx);
36
+ case "Array":
37
+ return (0, _tupleJs.parseTuple)(def, ctx);
38
+ case "RegExp":
39
+ return {
40
+ string: {
41
+ regex: def.source
42
+ }
43
+ };
44
+ case "Function":
45
+ if ((0, _typeJs.isType)(def)) {
46
+ return ctx.type.scope.addAnonymousTypeReference(def, ctx);
47
+ }
48
+ if (isThunk(def)) {
49
+ const returned = def();
50
+ if ((0, _typeJs.isType)(returned)) {
51
+ return ctx.type.scope.addAnonymousTypeReference(returned, ctx);
52
+ }
53
+ }
54
+ return (0, _errorsJs.throwParseError)(writeBadDefinitionTypeMessage("Function"));
55
+ default:
56
+ return (0, _errorsJs.throwParseError)(writeBadDefinitionTypeMessage(objectKind ?? (0, _serializeJs.stringify)(def)));
57
+ }
58
+ };
59
+ const as = Symbol("as");
60
+ const isThunk = (def)=>typeof def === "function" && def.length === 0;
61
+ const writeBadDefinitionTypeMessage = (actual)=>`Type definitions must be strings or objects (was ${actual})`;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "parseRecord", {
6
+ enumerable: true,
7
+ get: ()=>parseRecord
8
+ });
9
+ const _definitionJs = require("./definition.js");
10
+ const _scannerJs = require("./string/shift/scanner.js");
11
+ const parseRecord = (def, ctx)=>{
12
+ const props = {};
13
+ for(const definitionKey in def){
14
+ let keyName = definitionKey;
15
+ let isOptional = false;
16
+ if (definitionKey[definitionKey.length - 1] === "?") {
17
+ if (definitionKey[definitionKey.length - 2] === _scannerJs.Scanner.escapeToken) {
18
+ keyName = `${definitionKey.slice(0, -2)}?`;
19
+ } else {
20
+ keyName = definitionKey.slice(0, -1);
21
+ isOptional = true;
22
+ }
23
+ }
24
+ ctx.path.push(keyName);
25
+ const propNode = (0, _definitionJs.parseDefinition)(def[definitionKey], ctx);
26
+ ctx.path.pop();
27
+ props[keyName] = isOptional ? [
28
+ "?",
29
+ propNode
30
+ ] : propNode;
31
+ }
32
+ return {
33
+ object: {
34
+ props
35
+ }
36
+ };
37
+ };
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "DynamicState", {
6
+ enumerable: true,
7
+ get: ()=>DynamicState
8
+ });
9
+ const _nodeJs = require("../../../nodes/node.js");
10
+ const _rangeJs = require("../../../nodes/rules/range.js");
11
+ const _errorsJs = require("../../../utils/errors.js");
12
+ const _genericsJs = require("../../../utils/generics.js");
13
+ const _serializeJs = require("../../../utils/serialize.js");
14
+ const _scannerJs = require("../shift/scanner.js");
15
+ const _sharedJs = require("./shared.js");
16
+ function _defineProperty(obj, key, value) {
17
+ if (key in obj) {
18
+ Object.defineProperty(obj, key, {
19
+ value: value,
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true
23
+ });
24
+ } else {
25
+ obj[key] = value;
26
+ }
27
+ return obj;
28
+ }
29
+ class DynamicState {
30
+ error(message) {
31
+ return (0, _errorsJs.throwParseError)(message);
32
+ }
33
+ hasRoot() {
34
+ return this.root !== undefined;
35
+ }
36
+ resolveRoot() {
37
+ this.assertHasRoot();
38
+ return this.ctx.type.scope.resolveTypeNode(this.root);
39
+ }
40
+ rootToString() {
41
+ this.assertHasRoot();
42
+ return (0, _serializeJs.stringify)(this.root);
43
+ }
44
+ ejectRootIfLimit() {
45
+ this.assertHasRoot();
46
+ const resolution = typeof this.root === "string" ? this.ctx.type.scope.resolveNode(this.root) : this.root;
47
+ if ((0, _nodeJs.isLiteralNode)(resolution, "number")) {
48
+ const limit = resolution.number.value;
49
+ this.root = undefined;
50
+ return limit;
51
+ }
52
+ }
53
+ ejectRangeIfOpen() {
54
+ if (this.branches.range) {
55
+ const range = this.branches.range;
56
+ delete this.branches.range;
57
+ return range;
58
+ }
59
+ }
60
+ assertHasRoot() {
61
+ if (this.root === undefined) {
62
+ return (0, _errorsJs.throwInternalError)("Unexpected interaction with unset root");
63
+ }
64
+ }
65
+ assertUnsetRoot() {
66
+ if (this.root !== undefined) {
67
+ return (0, _errorsJs.throwInternalError)("Unexpected attempt to overwrite root");
68
+ }
69
+ }
70
+ setRoot(node) {
71
+ this.assertUnsetRoot();
72
+ this.root = node;
73
+ }
74
+ rootToArray() {
75
+ this.root = (0, _nodeJs.toArrayNode)(this.ejectRoot());
76
+ }
77
+ intersect(node) {
78
+ this.root = (0, _nodeJs.rootIntersection)(this.ejectRoot(), node, this.ctx.type);
79
+ }
80
+ ejectRoot() {
81
+ this.assertHasRoot();
82
+ const root = this.root;
83
+ this.root = undefined;
84
+ return root;
85
+ }
86
+ ejectFinalizedRoot() {
87
+ this.assertHasRoot();
88
+ const root = this.root;
89
+ this.root = ejectedProxy;
90
+ return root;
91
+ }
92
+ finalize() {
93
+ if (this.groups.length) {
94
+ return this.error(_sharedJs.unclosedGroupMessage);
95
+ }
96
+ this.finalizeBranches();
97
+ this.scanner.finalized = true;
98
+ }
99
+ reduceLeftBound(limit, comparator) {
100
+ const invertedComparator = _scannerJs.Scanner.invertedComparators[comparator];
101
+ if (!(0, _genericsJs.isKeyOf)(invertedComparator, _rangeJs.minComparators)) {
102
+ return this.error((0, _sharedJs.writeUnpairableComparatorMessage)(comparator));
103
+ }
104
+ if (this.branches.range) {
105
+ return this.error((0, _sharedJs.writeMultipleLeftBoundsMessage)(`${this.branches.range.limit}`, this.branches.range.comparator, `${limit}`, invertedComparator));
106
+ }
107
+ this.branches.range = {
108
+ limit,
109
+ comparator: invertedComparator
110
+ };
111
+ }
112
+ finalizeBranches() {
113
+ this.assertRangeUnset();
114
+ if (this.branches.union) {
115
+ this.pushRootToBranch("|");
116
+ this.setRoot(this.branches.union);
117
+ } else if (this.branches.intersection) {
118
+ this.setRoot((0, _nodeJs.rootIntersection)(this.branches.intersection, this.ejectRoot(), this.ctx.type));
119
+ }
120
+ }
121
+ finalizeGroup() {
122
+ this.finalizeBranches();
123
+ const topBranchState = this.groups.pop();
124
+ if (!topBranchState) {
125
+ return this.error((0, _sharedJs.writeUnmatchedGroupCloseMessage)(this.scanner.unscanned));
126
+ }
127
+ this.branches = topBranchState;
128
+ }
129
+ pushRootToBranch(token) {
130
+ this.assertRangeUnset();
131
+ this.branches.intersection = this.branches.intersection ? (0, _nodeJs.rootIntersection)(this.branches.intersection, this.ejectRoot(), this.ctx.type) : this.ejectRoot();
132
+ if (token === "|") {
133
+ this.branches.union = this.branches.union ? (0, _nodeJs.rootUnion)(this.branches.union, this.branches.intersection, this.ctx.type) : this.branches.intersection;
134
+ delete this.branches.intersection;
135
+ }
136
+ }
137
+ assertRangeUnset() {
138
+ if (this.branches.range) {
139
+ return this.error((0, _sharedJs.writeOpenRangeMessage)(`${this.branches.range.limit}`, this.branches.range.comparator));
140
+ }
141
+ }
142
+ reduceGroupOpen() {
143
+ this.groups.push(this.branches);
144
+ this.branches = {};
145
+ }
146
+ previousOperator() {
147
+ return this.branches.range?.comparator ?? this.branches.intersection ? "&" : this.branches.union ? "|" : undefined;
148
+ }
149
+ shiftedByOne() {
150
+ this.scanner.shift();
151
+ return this;
152
+ }
153
+ constructor(def, ctx){
154
+ _defineProperty(this, "ctx", void 0);
155
+ _defineProperty(this, "scanner", void 0);
156
+ _defineProperty(this, "root", void 0);
157
+ _defineProperty(this, "branches", void 0);
158
+ _defineProperty(this, "groups", void 0);
159
+ this.ctx = ctx;
160
+ this.branches = {};
161
+ this.groups = [];
162
+ this.scanner = new _scannerJs.Scanner(def);
163
+ }
164
+ }
165
+ const ejectedProxy = new Proxy({}, {
166
+ get: ()=>(0, _errorsJs.throwInternalError)(`Unexpected attempt to access ejected attributes`)
167
+ });
@@ -0,0 +1,23 @@
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
+ writeUnmatchedGroupCloseMessage: ()=>writeUnmatchedGroupCloseMessage,
13
+ unclosedGroupMessage: ()=>unclosedGroupMessage,
14
+ writeOpenRangeMessage: ()=>writeOpenRangeMessage,
15
+ writeUnpairableComparatorMessage: ()=>writeUnpairableComparatorMessage,
16
+ writeMultipleLeftBoundsMessage: ()=>writeMultipleLeftBoundsMessage
17
+ });
18
+ const _scannerJs = require("../shift/scanner.js");
19
+ const writeUnmatchedGroupCloseMessage = (unscanned)=>`Unmatched )${unscanned === "" ? "" : ` before ${unscanned}`}`;
20
+ const unclosedGroupMessage = "Missing )";
21
+ const writeOpenRangeMessage = (min, comparator)=>`Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`;
22
+ const writeUnpairableComparatorMessage = (comparator)=>`Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
23
+ const writeMultipleLeftBoundsMessage = (openLimit, openComparator, limit, comparator)=>`An expression may have at most one left bound (parsed ${openLimit}${_scannerJs.Scanner.invertedComparators[openComparator]}, ${limit}${_scannerJs.Scanner.invertedComparators[comparator]})`;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -0,0 +1,54 @@
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
+ parseEnclosed: ()=>parseEnclosed,
13
+ enclosingChar: ()=>enclosingChar,
14
+ writeUnterminatedEnclosedMessage: ()=>writeUnterminatedEnclosedMessage
15
+ });
16
+ const _regexJs = require("../../../../nodes/rules/regex.js");
17
+ const parseEnclosed = (s, enclosing)=>{
18
+ const token = s.scanner.shiftUntil(untilLookaheadIsClosing[enclosing]);
19
+ if (s.scanner.lookahead === "") {
20
+ return s.error(writeUnterminatedEnclosedMessage(token, enclosing));
21
+ }
22
+ // Shift the scanner one additional time for the second enclosing token
23
+ if (s.scanner.shift() === "/") {
24
+ // Cache the regex instance to throw right way if its invalid
25
+ (0, _regexJs.getRegex)(token);
26
+ s.setRoot({
27
+ string: {
28
+ regex: token
29
+ }
30
+ });
31
+ } else {
32
+ s.setRoot({
33
+ string: {
34
+ value: token
35
+ }
36
+ });
37
+ }
38
+ };
39
+ const enclosingChar = {
40
+ "'": 1,
41
+ '"': 1,
42
+ "/": 1
43
+ };
44
+ const untilLookaheadIsClosing = {
45
+ "'": (scanner)=>scanner.lookahead === `'`,
46
+ '"': (scanner)=>scanner.lookahead === `"`,
47
+ "/": (scanner)=>scanner.lookahead === `/`
48
+ };
49
+ const enclosingCharDescriptions = {
50
+ '"': "double-quote",
51
+ "'": "single-quote",
52
+ "/": "forward slash"
53
+ };
54
+ const writeUnterminatedEnclosedMessage = (fragment, enclosing)=>`${enclosing}${fragment} requires a closing ${enclosingCharDescriptions[enclosing]}`;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "parseOperand", {
6
+ enumerable: true,
7
+ get: ()=>parseOperand
8
+ });
9
+ const _enclosedJs = require("./enclosed.js");
10
+ const _unenclosedJs = require("./unenclosed.js");
11
+ const parseOperand = (s)=>s.scanner.lookahead === "" ? s.error((0, _unenclosedJs.writeMissingOperandMessage)(s)) : s.scanner.lookahead === "(" ? s.shiftedByOne().reduceGroupOpen() : s.scanner.lookaheadIsIn(_enclosedJs.enclosingChar) ? (0, _enclosedJs.parseEnclosed)(s, s.scanner.shift()) : s.scanner.lookahead === " " ? parseOperand(s.shiftedByOne()) : (0, _unenclosedJs.parseUnenclosed)(s);
@@ -0,0 +1,53 @@
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
+ parseUnenclosed: ()=>parseUnenclosed,
13
+ writeUnresolvableMessage: ()=>writeUnresolvableMessage,
14
+ writeMissingOperandMessage: ()=>writeMissingOperandMessage,
15
+ writeMissingRightOperandMessage: ()=>writeMissingRightOperandMessage,
16
+ writeExpressionExpectedMessage: ()=>writeExpressionExpectedMessage
17
+ });
18
+ const _numericLiteralsJs = require("../../../../utils/numericLiterals.js");
19
+ const parseUnenclosed = (s)=>{
20
+ const token = s.scanner.shiftUntilNextTerminator();
21
+ s.setRoot(unenclosedToNode(s, token));
22
+ };
23
+ const unenclosedToNode = (s, token)=>{
24
+ if (s.ctx.type.scope.addParsedReferenceIfResolvable(token, s.ctx)) {
25
+ return token;
26
+ }
27
+ return maybeParseUnenclosedLiteral(token) ?? s.error(token === "" ? writeMissingOperandMessage(s) : writeUnresolvableMessage(token));
28
+ };
29
+ const maybeParseUnenclosedLiteral = (token)=>{
30
+ const maybeNumber = (0, _numericLiteralsJs.tryParseWellFormedNumber)(token);
31
+ if (maybeNumber !== undefined) {
32
+ return {
33
+ number: {
34
+ value: maybeNumber
35
+ }
36
+ };
37
+ }
38
+ const maybeBigint = (0, _numericLiteralsJs.tryParseWellFormedBigint)(token);
39
+ if (maybeBigint !== undefined) {
40
+ return {
41
+ bigint: {
42
+ value: maybeBigint
43
+ }
44
+ };
45
+ }
46
+ };
47
+ const writeUnresolvableMessage = (token)=>`'${token}' is unresolvable`;
48
+ const writeMissingOperandMessage = (s)=>{
49
+ const operator = s.previousOperator();
50
+ return operator ? writeMissingRightOperandMessage(operator, s.scanner.unscanned) : writeExpressionExpectedMessage(s.scanner.unscanned);
51
+ };
52
+ const writeMissingRightOperandMessage = (token, unscanned)=>`Token '${token}' requires a right operand${unscanned ? ` before '${unscanned}'` : ""}`;
53
+ const writeExpressionExpectedMessage = (unscanned)=>`Expected an expression${unscanned ? ` before '${unscanned}'` : ""}`;