arktype 1.0.16-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/src/main.js +38 -0
  3. package/dist/cjs/src/nodes/branch.js +140 -0
  4. package/dist/cjs/src/nodes/compose.js +157 -0
  5. package/dist/{nodes → cjs/src/nodes}/discriminate.js +92 -100
  6. package/dist/cjs/src/nodes/node.js +139 -0
  7. package/dist/cjs/src/nodes/predicate.js +86 -0
  8. package/dist/cjs/src/nodes/rules/class.js +25 -0
  9. package/dist/cjs/src/nodes/rules/collapsibleSet.js +48 -0
  10. package/dist/cjs/src/nodes/rules/divisor.js +29 -0
  11. package/dist/cjs/src/nodes/rules/props.js +160 -0
  12. package/dist/cjs/src/nodes/rules/range.js +105 -0
  13. package/dist/cjs/src/nodes/rules/regex.js +26 -0
  14. package/dist/cjs/src/nodes/rules/rules.js +123 -0
  15. package/dist/cjs/src/parse/ast/ast.js +4 -0
  16. package/dist/cjs/src/parse/ast/bound.js +16 -0
  17. package/dist/cjs/src/parse/ast/config.js +13 -0
  18. package/dist/cjs/src/parse/ast/distributableFunction.js +48 -0
  19. package/dist/cjs/src/parse/ast/divisor.js +9 -0
  20. package/dist/cjs/src/parse/ast/intersection.js +30 -0
  21. package/dist/cjs/src/parse/ast/keyof.js +111 -0
  22. package/dist/cjs/src/parse/ast/morph.js +58 -0
  23. package/dist/cjs/src/parse/ast/narrow.js +22 -0
  24. package/dist/cjs/src/parse/ast/node.js +4 -0
  25. package/dist/cjs/src/parse/ast/tuple.js +94 -0
  26. package/dist/cjs/src/parse/ast/union.js +9 -0
  27. package/dist/cjs/src/parse/ast/utils.js +4 -0
  28. package/dist/cjs/src/parse/definition.js +61 -0
  29. package/dist/cjs/src/parse/record.js +37 -0
  30. package/dist/cjs/src/parse/string/reduce/dynamic.js +167 -0
  31. package/dist/cjs/src/parse/string/reduce/shared.js +23 -0
  32. package/dist/cjs/src/parse/string/reduce/static.js +4 -0
  33. package/dist/cjs/src/parse/string/shift/operand/enclosed.js +54 -0
  34. package/dist/cjs/src/parse/string/shift/operand/operand.js +11 -0
  35. package/dist/cjs/src/parse/string/shift/operand/unenclosed.js +53 -0
  36. package/dist/cjs/src/parse/string/shift/operator/bounds.js +87 -0
  37. package/dist/cjs/src/parse/string/shift/operator/divisor.js +35 -0
  38. package/dist/cjs/src/parse/string/shift/operator/operator.js +26 -0
  39. package/dist/cjs/src/parse/string/shift/scanner.js +114 -0
  40. package/dist/cjs/src/parse/string/string.js +43 -0
  41. package/dist/cjs/src/scopes/ark.js +45 -0
  42. package/dist/cjs/src/scopes/cache.js +52 -0
  43. package/dist/cjs/src/scopes/expressions.js +29 -0
  44. package/dist/cjs/src/scopes/jsObjects.js +93 -0
  45. package/dist/cjs/src/scopes/scope.js +323 -0
  46. package/dist/cjs/src/scopes/tsKeywords.js +113 -0
  47. package/dist/cjs/src/scopes/type.js +50 -0
  48. package/dist/cjs/src/scopes/validation/creditCard.js +47 -0
  49. package/dist/cjs/src/scopes/validation/date.js +62 -0
  50. package/dist/cjs/src/scopes/validation/validation.js +108 -0
  51. package/dist/cjs/src/traverse/problems.js +281 -0
  52. package/dist/cjs/src/traverse/traverse.js +390 -0
  53. package/dist/cjs/src/utils/chainableNoOpProxy.js +23 -0
  54. package/dist/cjs/src/utils/data.js +53 -0
  55. package/dist/cjs/src/utils/domains.js +30 -0
  56. package/dist/cjs/src/utils/errors.js +26 -0
  57. package/dist/cjs/src/utils/freeze.js +15 -0
  58. package/dist/cjs/src/utils/generics.js +63 -0
  59. package/dist/cjs/src/utils/numericLiterals.js +75 -0
  60. package/dist/cjs/src/utils/objectKinds.js +69 -0
  61. package/dist/cjs/src/utils/paths.js +32 -0
  62. package/dist/cjs/src/utils/serialize.js +74 -0
  63. package/dist/cjs/src/utils/unionToTuple.js +4 -0
  64. package/dist/mjs/package.json +3 -0
  65. package/dist/mjs/src/main.js +8 -0
  66. package/dist/mjs/src/nodes/branch.js +123 -0
  67. package/dist/mjs/src/nodes/compose.js +135 -0
  68. package/dist/mjs/src/nodes/discriminate.js +247 -0
  69. package/dist/mjs/src/nodes/node.js +117 -0
  70. package/dist/mjs/src/nodes/predicate.js +69 -0
  71. package/dist/mjs/src/nodes/rules/class.js +11 -0
  72. package/dist/mjs/src/nodes/rules/collapsibleSet.js +34 -0
  73. package/dist/mjs/src/nodes/rules/divisor.js +15 -0
  74. package/dist/mjs/src/nodes/rules/props.js +142 -0
  75. package/dist/mjs/src/nodes/rules/range.js +86 -0
  76. package/dist/mjs/src/nodes/rules/regex.js +11 -0
  77. package/dist/mjs/src/nodes/rules/rules.js +106 -0
  78. package/dist/mjs/src/parse/ast/ast.js +1 -0
  79. package/dist/mjs/src/parse/ast/bound.js +2 -0
  80. package/dist/mjs/src/parse/ast/config.js +9 -0
  81. package/dist/mjs/src/parse/ast/distributableFunction.js +34 -0
  82. package/dist/mjs/src/parse/ast/divisor.js +1 -0
  83. package/dist/mjs/src/parse/ast/intersection.js +16 -0
  84. package/dist/mjs/src/parse/ast/keyof.js +103 -0
  85. package/dist/mjs/src/parse/ast/morph.js +44 -0
  86. package/dist/mjs/src/parse/ast/narrow.js +14 -0
  87. package/dist/mjs/src/parse/ast/node.js +1 -0
  88. package/dist/mjs/src/parse/ast/tuple.js +80 -0
  89. package/dist/mjs/src/parse/ast/union.js +1 -0
  90. package/dist/mjs/src/parse/ast/utils.js +1 -0
  91. package/dist/mjs/src/parse/definition.js +46 -0
  92. package/dist/mjs/src/parse/record.js +29 -0
  93. package/dist/mjs/src/parse/string/reduce/dynamic.js +159 -0
  94. package/dist/mjs/src/parse/string/reduce/shared.js +6 -0
  95. package/dist/mjs/src/parse/string/reduce/static.js +1 -0
  96. package/dist/mjs/src/parse/string/shift/operand/enclosed.js +39 -0
  97. package/dist/mjs/src/parse/string/shift/operand/operand.js +3 -0
  98. package/dist/mjs/src/parse/string/shift/operand/unenclosed.js +36 -0
  99. package/dist/mjs/src/parse/string/shift/operator/bounds.js +70 -0
  100. package/dist/mjs/src/parse/string/shift/operator/divisor.js +21 -0
  101. package/dist/mjs/src/parse/string/shift/operator/operator.js +13 -0
  102. package/dist/mjs/src/parse/string/shift/scanner.js +106 -0
  103. package/dist/mjs/src/parse/string/string.js +28 -0
  104. package/dist/mjs/src/scopes/ark.js +28 -0
  105. package/dist/mjs/src/scopes/cache.js +38 -0
  106. package/dist/{scopes → mjs/src/scopes}/expressions.js +9 -20
  107. package/dist/mjs/src/scopes/jsObjects.js +82 -0
  108. package/dist/mjs/src/scopes/scope.js +303 -0
  109. package/dist/mjs/src/scopes/tsKeywords.js +116 -0
  110. package/dist/mjs/src/scopes/type.js +35 -0
  111. package/dist/{scopes → mjs/src/scopes}/validation/creditCard.js +11 -15
  112. package/dist/{scopes → mjs/src/scopes}/validation/date.js +16 -21
  113. package/dist/mjs/src/scopes/validation/validation.js +112 -0
  114. package/dist/mjs/src/traverse/problems.js +260 -0
  115. package/dist/mjs/src/traverse/traverse.js +373 -0
  116. package/dist/{utils → mjs/src/utils}/chainableNoOpProxy.js +2 -6
  117. package/dist/mjs/src/utils/data.js +38 -0
  118. package/dist/mjs/src/utils/domains.js +15 -0
  119. package/dist/mjs/src/utils/errors.js +10 -0
  120. package/dist/mjs/src/utils/freeze.js +7 -0
  121. package/dist/mjs/src/utils/generics.js +38 -0
  122. package/dist/mjs/src/utils/numericLiterals.js +72 -0
  123. package/dist/mjs/src/utils/objectKinds.js +55 -0
  124. package/dist/{utils → mjs/src/utils}/paths.js +3 -8
  125. package/dist/mjs/src/utils/serialize.js +58 -0
  126. package/dist/mjs/src/utils/unionToTuple.js +1 -0
  127. package/dist/tsconfig.temp.tsbuildinfo +1 -1
  128. package/package.json +13 -5
  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
@@ -0,0 +1,323 @@
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
+ compileScopeOptions: ()=>compileScopeOptions,
13
+ isConfigTuple: ()=>isConfigTuple,
14
+ Scope: ()=>Scope,
15
+ scope: ()=>scope,
16
+ rootScope: ()=>rootScope,
17
+ rootType: ()=>rootType,
18
+ writeShallowCycleErrorMessage: ()=>writeShallowCycleErrorMessage,
19
+ writeDuplicateAliasesMessage: ()=>writeDuplicateAliasesMessage
20
+ });
21
+ const _nodeJs = require("../nodes/node.js");
22
+ const _definitionJs = require("../parse/definition.js");
23
+ const _problemsJs = require("../traverse/problems.js");
24
+ const _chainableNoOpProxyJs = require("../utils/chainableNoOpProxy.js");
25
+ const _errorsJs = require("../utils/errors.js");
26
+ const _freezeJs = require("../utils/freeze.js");
27
+ const _genericsJs = require("../utils/generics.js");
28
+ const _pathsJs = require("../utils/paths.js");
29
+ const _cacheJs = require("./cache.js");
30
+ const _typeJs = require("./type.js");
31
+ function _checkPrivateRedeclaration(obj, privateCollection) {
32
+ if (privateCollection.has(obj)) {
33
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
34
+ }
35
+ }
36
+ function _classApplyDescriptorGet(receiver, descriptor) {
37
+ if (descriptor.get) {
38
+ return descriptor.get.call(receiver);
39
+ }
40
+ return descriptor.value;
41
+ }
42
+ function _classApplyDescriptorSet(receiver, descriptor, value) {
43
+ if (descriptor.set) {
44
+ descriptor.set.call(receiver, value);
45
+ } else {
46
+ if (!descriptor.writable) {
47
+ throw new TypeError("attempted to set read only private field");
48
+ }
49
+ descriptor.value = value;
50
+ }
51
+ }
52
+ function _classExtractFieldDescriptor(receiver, privateMap, action) {
53
+ if (!privateMap.has(receiver)) {
54
+ throw new TypeError("attempted to " + action + " private field on non-instance");
55
+ }
56
+ return privateMap.get(receiver);
57
+ }
58
+ function _classPrivateFieldGet(receiver, privateMap) {
59
+ var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
60
+ return _classApplyDescriptorGet(receiver, descriptor);
61
+ }
62
+ function _classPrivateFieldInit(obj, privateMap, value) {
63
+ _checkPrivateRedeclaration(obj, privateMap);
64
+ privateMap.set(obj, value);
65
+ }
66
+ function _classPrivateFieldSet(receiver, privateMap, value) {
67
+ var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set");
68
+ _classApplyDescriptorSet(receiver, descriptor, value);
69
+ return value;
70
+ }
71
+ function _classPrivateMethodGet(receiver, privateSet, fn) {
72
+ if (!privateSet.has(receiver)) {
73
+ throw new TypeError("attempted to get private field on non-instance");
74
+ }
75
+ return fn;
76
+ }
77
+ function _classPrivateMethodInit(obj, privateSet) {
78
+ _checkPrivateRedeclaration(obj, privateSet);
79
+ privateSet.add(obj);
80
+ }
81
+ function _defineProperty(obj, key, value) {
82
+ if (key in obj) {
83
+ Object.defineProperty(obj, key, {
84
+ value: value,
85
+ enumerable: true,
86
+ configurable: true,
87
+ writable: true
88
+ });
89
+ } else {
90
+ obj[key] = value;
91
+ }
92
+ return obj;
93
+ }
94
+ const compileScopeOptions = (opts)=>({
95
+ codes: (0, _problemsJs.compileProblemWriters)(opts.codes),
96
+ keys: opts.keys ?? "loose"
97
+ });
98
+ let anonymousScopeCount = 0;
99
+ const scopeRegistry = {};
100
+ const spaceRegistry = {};
101
+ const isConfigTuple = (def)=>Array.isArray(def) && def[1] === ":";
102
+ var _resolutions = /*#__PURE__*/ new WeakMap(), _exports = /*#__PURE__*/ new WeakMap(), _register = /*#__PURE__*/ new WeakSet(), _cacheSpaces = /*#__PURE__*/ new WeakSet(), _initializeContext = /*#__PURE__*/ new WeakSet(), _resolveRecurse = /*#__PURE__*/ new WeakSet();
103
+ class Scope {
104
+ getAnonymousQualifiedName(base) {
105
+ let increment = 0;
106
+ let id = base;
107
+ while(this.isResolvable(id)){
108
+ id = `${base}${increment++}`;
109
+ }
110
+ return `${this.name}.${id}`;
111
+ }
112
+ addAnonymousTypeReference(referencedType, ctx) {
113
+ var _ctx_type;
114
+ (_ctx_type = ctx.type).includesMorph || (_ctx_type.includesMorph = referencedType.includesMorph);
115
+ return referencedType.node;
116
+ }
117
+ get infer() {
118
+ return _chainableNoOpProxyJs.chainableNoOpProxy;
119
+ }
120
+ compile() {
121
+ if (!spaceRegistry[this.name]) {
122
+ for(const name in this.aliases){
123
+ this.resolve(name);
124
+ }
125
+ spaceRegistry[this.name] = _classPrivateFieldGet(this, _exports).root;
126
+ }
127
+ return _classPrivateFieldGet(this, _exports).root;
128
+ }
129
+ addParsedReferenceIfResolvable(name, ctx) {
130
+ var _ctx_type;
131
+ const resolution = _classPrivateMethodGet(this, _resolveRecurse, resolveRecurse).call(this, name, "undefined", [
132
+ name
133
+ ]);
134
+ if (!resolution) {
135
+ return false;
136
+ }
137
+ (_ctx_type = ctx.type).includesMorph || (_ctx_type.includesMorph = resolution.includesMorph);
138
+ return true;
139
+ }
140
+ resolve(name) {
141
+ return _classPrivateMethodGet(this, _resolveRecurse, resolveRecurse).call(this, name, "throw", [
142
+ name
143
+ ]);
144
+ }
145
+ resolveNode(node) {
146
+ return typeof node === "string" ? this.resolveNode(this.resolve(node).node) : node;
147
+ }
148
+ resolveTypeNode(node) {
149
+ const resolution = this.resolveNode(node);
150
+ return (0, _nodeJs.isConfigNode)(resolution) ? resolution.node : resolution;
151
+ }
152
+ isResolvable(name) {
153
+ return _classPrivateFieldGet(this, _resolutions).has(name) || this.aliases[name];
154
+ }
155
+ constructor(aliases, opts = {}){
156
+ _classPrivateMethodInit(this, _register);
157
+ _classPrivateMethodInit(this, _cacheSpaces);
158
+ _classPrivateMethodInit(this, _initializeContext);
159
+ _classPrivateMethodInit(this, _resolveRecurse);
160
+ _defineProperty(this, "aliases", void 0);
161
+ _defineProperty(this, "name", void 0);
162
+ _defineProperty(this, "config", void 0);
163
+ _defineProperty(this, "parseCache", void 0);
164
+ _classPrivateFieldInit(this, _resolutions, {
165
+ writable: true,
166
+ value: void 0
167
+ });
168
+ _classPrivateFieldInit(this, _exports, {
169
+ writable: true,
170
+ value: void 0
171
+ });
172
+ _defineProperty(this, "expressions", void 0);
173
+ _defineProperty(this, "intersection", void 0);
174
+ _defineProperty(this, "union", void 0);
175
+ _defineProperty(this, "arrayOf", void 0);
176
+ _defineProperty(this, "keyOf", void 0);
177
+ _defineProperty(this, "valueOf", void 0);
178
+ _defineProperty(this, "instanceOf", void 0);
179
+ _defineProperty(this, "narrow", void 0);
180
+ _defineProperty(this, "morph", void 0);
181
+ _defineProperty(this, "type", void 0);
182
+ this.aliases = aliases;
183
+ this.parseCache = new _cacheJs.FreezingCache();
184
+ _classPrivateFieldSet(this, _resolutions, new _cacheJs.Cache());
185
+ _classPrivateFieldSet(this, _exports, new _cacheJs.Cache());
186
+ this.expressions = {
187
+ intersection: (l, r, opts)=>this.type([
188
+ l,
189
+ "&",
190
+ r
191
+ ], opts),
192
+ union: (l, r, opts)=>this.type([
193
+ l,
194
+ "|",
195
+ r
196
+ ], opts),
197
+ arrayOf: (def, opts)=>this.type([
198
+ def,
199
+ "[]"
200
+ ], opts),
201
+ keyOf: (def, opts)=>this.type([
202
+ "keyof",
203
+ def
204
+ ], opts),
205
+ node: (def, opts)=>this.type([
206
+ "node",
207
+ def
208
+ ], opts),
209
+ instanceOf: (def, opts)=>this.type([
210
+ "instanceof",
211
+ def
212
+ ], opts),
213
+ valueOf: (def, opts)=>this.type([
214
+ "===",
215
+ def
216
+ ], opts),
217
+ narrow: (def, fn, opts)=>this.type([
218
+ def,
219
+ "=>",
220
+ fn
221
+ ], opts),
222
+ morph: (def, fn, opts)=>this.type([
223
+ def,
224
+ "|>",
225
+ fn
226
+ ], opts)
227
+ };
228
+ this.intersection = this.expressions.intersection;
229
+ this.union = this.expressions.union;
230
+ this.arrayOf = this.expressions.arrayOf;
231
+ this.keyOf = this.expressions.keyOf;
232
+ this.valueOf = this.expressions.valueOf;
233
+ this.instanceOf = this.expressions.instanceOf;
234
+ this.narrow = this.expressions.narrow;
235
+ this.morph = this.expressions.morph;
236
+ this.type = Object.assign((def, config = {})=>{
237
+ const t = (0, _typeJs.initializeType)("λtype", def, config, this);
238
+ const ctx = _classPrivateMethodGet(this, _initializeContext, initializeContext).call(this, t);
239
+ const root = (0, _definitionJs.parseDefinition)(def, ctx);
240
+ t.node = (0, _freezeJs.deepFreeze)((0, _genericsJs.hasKeys)(config) ? {
241
+ config,
242
+ node: this.resolveTypeNode(root)
243
+ } : root);
244
+ t.flat = (0, _freezeJs.deepFreeze)((0, _nodeJs.flattenType)(t));
245
+ return t;
246
+ }, {
247
+ from: this.expressions.node
248
+ });
249
+ this.name = _classPrivateMethodGet(this, _register, register).call(this, opts);
250
+ if (opts.standard !== false) {
251
+ _classPrivateMethodGet(this, _cacheSpaces, cacheSpaces).call(this, [
252
+ spaceRegistry["standard"]
253
+ ], "imports");
254
+ }
255
+ if (opts.imports) {
256
+ _classPrivateMethodGet(this, _cacheSpaces, cacheSpaces).call(this, opts.imports, "imports");
257
+ }
258
+ if (opts.includes) {
259
+ _classPrivateMethodGet(this, _cacheSpaces, cacheSpaces).call(this, opts.includes, "includes");
260
+ }
261
+ this.config = compileScopeOptions(opts);
262
+ }
263
+ }
264
+ function register(opts) {
265
+ const name = opts.name ? scopeRegistry[opts.name] ? (0, _errorsJs.throwParseError)(`A scope named '${opts.name}' already exists`) : opts.name : `scope${++anonymousScopeCount}`;
266
+ scopeRegistry[name] = this;
267
+ return name;
268
+ }
269
+ function cacheSpaces(spaces, kind) {
270
+ for (const space of spaces){
271
+ for(const name in space){
272
+ if (_classPrivateFieldGet(this, _resolutions).has(name) || name in this.aliases) {
273
+ (0, _errorsJs.throwParseError)(writeDuplicateAliasesMessage(name));
274
+ }
275
+ _classPrivateFieldGet(this, _resolutions).set(name, space[name]);
276
+ if (kind === "includes") {
277
+ _classPrivateFieldGet(this, _exports).set(name, space[name]);
278
+ }
279
+ }
280
+ }
281
+ }
282
+ function initializeContext(type) {
283
+ return {
284
+ type,
285
+ path: new _pathsJs.Path()
286
+ };
287
+ }
288
+ function resolveRecurse(name, onUnresolvable, seen) {
289
+ const maybeCacheResult = _classPrivateFieldGet(this, _resolutions).get(name);
290
+ if (maybeCacheResult) {
291
+ return maybeCacheResult;
292
+ }
293
+ const aliasDef = this.aliases[name];
294
+ if (!aliasDef) {
295
+ return onUnresolvable === "throw" ? (0, _errorsJs.throwInternalError)(`Unexpectedly failed to resolve alias '${name}'`) : undefined;
296
+ }
297
+ const t = (0, _typeJs.initializeType)(name, aliasDef, {}, this);
298
+ const ctx = _classPrivateMethodGet(this, _initializeContext, initializeContext).call(this, t);
299
+ _classPrivateFieldGet(this, _resolutions).set(name, t);
300
+ _classPrivateFieldGet(this, _exports).set(name, t);
301
+ let node = (0, _definitionJs.parseDefinition)(aliasDef, ctx);
302
+ if (typeof node === "string") {
303
+ if (seen.includes(node)) {
304
+ return (0, _errorsJs.throwParseError)(writeShallowCycleErrorMessage(name, seen));
305
+ }
306
+ seen.push(node);
307
+ node = _classPrivateMethodGet(this, _resolveRecurse, resolveRecurse).call(this, node, "throw", seen).node;
308
+ }
309
+ t.node = (0, _freezeJs.deepFreeze)(node);
310
+ t.flat = (0, _freezeJs.deepFreeze)((0, _nodeJs.flattenType)(t));
311
+ return t;
312
+ }
313
+ const scope = (aliases, opts = {})=>new Scope(aliases, opts);
314
+ const rootScope = scope({}, {
315
+ name: "root",
316
+ standard: false
317
+ });
318
+ const rootType = rootScope.type;
319
+ const writeShallowCycleErrorMessage = (name, seen)=>`Alias '${name}' has a shallow resolution cycle: ${[
320
+ ...seen,
321
+ name
322
+ ].join("=>")}`;
323
+ const writeDuplicateAliasesMessage = (name)=>`Alias '${name}' is already defined`;
@@ -0,0 +1,113 @@
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
+ tsKeywordsScope: ()=>tsKeywordsScope,
13
+ tsKeywords: ()=>tsKeywords
14
+ });
15
+ const _scopeJs = require("./scope.js");
16
+ const always = {
17
+ bigint: true,
18
+ boolean: true,
19
+ null: true,
20
+ number: true,
21
+ object: true,
22
+ string: true,
23
+ symbol: true,
24
+ undefined: true
25
+ };
26
+ const tsKeywordsScope = (0, _scopeJs.scope)({
27
+ any: [
28
+ "node",
29
+ always
30
+ ],
31
+ bigint: [
32
+ "node",
33
+ {
34
+ bigint: true
35
+ }
36
+ ],
37
+ boolean: [
38
+ "node",
39
+ {
40
+ boolean: true
41
+ }
42
+ ],
43
+ false: [
44
+ "node",
45
+ {
46
+ boolean: {
47
+ value: false
48
+ }
49
+ }
50
+ ],
51
+ never: [
52
+ "node",
53
+ {}
54
+ ],
55
+ null: [
56
+ "node",
57
+ {
58
+ null: true
59
+ }
60
+ ],
61
+ number: [
62
+ "node",
63
+ {
64
+ number: true
65
+ }
66
+ ],
67
+ object: [
68
+ "node",
69
+ {
70
+ object: true
71
+ }
72
+ ],
73
+ string: [
74
+ "node",
75
+ {
76
+ string: true
77
+ }
78
+ ],
79
+ symbol: [
80
+ "node",
81
+ {
82
+ symbol: true
83
+ }
84
+ ],
85
+ true: [
86
+ "node",
87
+ {
88
+ boolean: {
89
+ value: true
90
+ }
91
+ }
92
+ ],
93
+ unknown: [
94
+ "node",
95
+ always
96
+ ],
97
+ void: [
98
+ "node",
99
+ {
100
+ undefined: true
101
+ }
102
+ ],
103
+ undefined: [
104
+ "node",
105
+ {
106
+ undefined: true
107
+ }
108
+ ]
109
+ }, {
110
+ name: "ts",
111
+ standard: false
112
+ });
113
+ const tsKeywords = tsKeywordsScope.compile();
@@ -0,0 +1,50 @@
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
+ initializeType: ()=>initializeType,
13
+ isType: ()=>isType,
14
+ isAnonymousName: ()=>isAnonymousName
15
+ });
16
+ const _traverseJs = require("../traverse/traverse.js");
17
+ const _chainableNoOpProxyJs = require("../utils/chainableNoOpProxy.js");
18
+ const initializeType = (name, definition, config, scope)=>{
19
+ const root = {
20
+ // temporarily initialize node/flat to aliases that will be included in
21
+ // the final type in case of cyclic resolutions
22
+ node: name,
23
+ flat: [
24
+ [
25
+ "alias",
26
+ name
27
+ ]
28
+ ],
29
+ allows: (data)=>!namedTraverse(data).problems,
30
+ assert: (data)=>{
31
+ const result = namedTraverse(data);
32
+ return result.problems ? result.problems.throw() : result.data;
33
+ },
34
+ infer: _chainableNoOpProxyJs.chainableNoOpProxy,
35
+ inferIn: _chainableNoOpProxyJs.chainableNoOpProxy,
36
+ qualifiedName: isAnonymousName(name) ? scope.getAnonymousQualifiedName(name) : `${scope.name}.${name}`,
37
+ definition,
38
+ scope,
39
+ includesMorph: false,
40
+ config
41
+ };
42
+ // define within a key to dynamically assign a name to the function
43
+ const namedTraverse = {
44
+ [name]: (data)=>(0, _traverseJs.traverseRoot)(namedTraverse, data)
45
+ }[name];
46
+ const t = Object.assign(namedTraverse, root);
47
+ return t;
48
+ };
49
+ const isType = (value)=>value?.infer === _chainableNoOpProxyJs.chainableNoOpProxy;
50
+ const isAnonymousName = (name)=>name[0] === "λ";
@@ -0,0 +1,47 @@
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
+ isLuhnValid: ()=>isLuhnValid,
13
+ creditCard: ()=>creditCard
14
+ });
15
+ const _scopeJs = require("../scope.js");
16
+ const isLuhnValid = (creditCardInput)=>{
17
+ const sanitized = creditCardInput.replace(/[- ]+/g, "");
18
+ let sum = 0;
19
+ let digit;
20
+ let tmpNum;
21
+ let shouldDouble;
22
+ for(let i = sanitized.length - 1; i >= 0; i--){
23
+ digit = sanitized.substring(i, i + 1);
24
+ tmpNum = parseInt(digit, 10);
25
+ if (shouldDouble) {
26
+ tmpNum *= 2;
27
+ if (tmpNum >= 10) {
28
+ sum += tmpNum % 10 + 1;
29
+ } else {
30
+ sum += tmpNum;
31
+ }
32
+ } else {
33
+ sum += tmpNum;
34
+ }
35
+ shouldDouble = !shouldDouble;
36
+ }
37
+ return !!(sum % 10 === 0 ? sanitized : false);
38
+ };
39
+ // https://github.com/validatorjs/validator.js/blob/master/src/lib/isCreditCard.js
40
+ const creditCardMatcher = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14}|^(81[0-9]{14,17}))$/;
41
+ const creditCard = (0, _scopeJs.rootType)([
42
+ creditCardMatcher,
43
+ "=>",
44
+ (s, problems)=>isLuhnValid(s) || !problems.mustBe("a valid credit card number")
45
+ ], {
46
+ mustBe: "a valid credit card number"
47
+ });
@@ -0,0 +1,62 @@
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
+ tryParseDate: ()=>tryParseDate,
13
+ parsedDate: ()=>parsedDate
14
+ });
15
+ const _scopeJs = require("../scope.js");
16
+ const _tsKeywordsJs = require("../tsKeywords.js");
17
+ const dayDelimiterMatcher = /^[./-]$/;
18
+ // ISO 8601 date/time modernized from https://github.com/validatorjs/validator.js/blob/master/src/lib/isISO8601.js
19
+ // Based on https://tc39.es/ecma262/#sec-date-time-string-format, the T
20
+ // delimiter for date/time is mandatory. Regex from validator.js strict matcher:
21
+ const iso8601Matcher = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
22
+ const isValidDateInstance = (date)=>!isNaN(date);
23
+ const writeFormattedMustBe = (format)=>`a ${format}-formatted date`;
24
+ const tryParseDate = (data, opts)=>{
25
+ if (!opts?.format) {
26
+ const result = new Date(data);
27
+ return isValidDateInstance(result) ? result : "a valid date";
28
+ }
29
+ if (opts.format === "iso8601") {
30
+ return iso8601Matcher.test(data) ? new Date(data) : writeFormattedMustBe("iso8601");
31
+ }
32
+ const dataParts = data.split(dayDelimiterMatcher);
33
+ // will be the first delimiter matched, if there is one
34
+ const delimiter = data[dataParts[0].length];
35
+ const formatParts = delimiter ? opts.format.split(delimiter) : [
36
+ opts.format
37
+ ];
38
+ if (dataParts.length !== formatParts.length) {
39
+ return writeFormattedMustBe(opts.format);
40
+ }
41
+ const parsedParts = {};
42
+ for(let i = 0; i < formatParts.length; i++){
43
+ if (dataParts[i].length !== formatParts[i].length && // if format is "m" or "d", data is allowed to be 1 or 2 characters
44
+ !(formatParts[i].length === 1 && dataParts[i].length === 2)) {
45
+ return writeFormattedMustBe(opts.format);
46
+ }
47
+ parsedParts[formatParts[i][0]] = dataParts[i];
48
+ }
49
+ const date = new Date(`${parsedParts.m}/${parsedParts.d}/${parsedParts.y}`);
50
+ if (`${date.getDate()}` === parsedParts.d) {
51
+ return date;
52
+ }
53
+ return writeFormattedMustBe(opts.format);
54
+ };
55
+ const parsedDate = (0, _scopeJs.rootType)([
56
+ _tsKeywordsJs.tsKeywords.string,
57
+ "|>",
58
+ (s, problems)=>{
59
+ const result = tryParseDate(s);
60
+ return typeof result === "string" ? problems.mustBe(result) : result;
61
+ }
62
+ ]);
@@ -0,0 +1,108 @@
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
+ validationScope: ()=>validationScope,
13
+ validation: ()=>validation
14
+ });
15
+ const _numericLiteralsJs = require("../../utils/numericLiterals.js");
16
+ const _scopeJs = require("../scope.js");
17
+ const _tsKeywordsJs = require("../tsKeywords.js");
18
+ const _creditCardJs = require("./creditCard.js");
19
+ const _dateJs = require("./date.js");
20
+ // Non-trivial expressions should have an explanation or attribution
21
+ const parsedNumber = (0, _scopeJs.rootType)([
22
+ _numericLiteralsJs.wellFormedNumberMatcher,
23
+ "|>",
24
+ (s)=>parseFloat(s)
25
+ ], {
26
+ mustBe: "a well-formed numeric string"
27
+ });
28
+ const parsedInteger = (0, _scopeJs.rootType)([
29
+ _tsKeywordsJs.tsKeywords.string,
30
+ "|>",
31
+ (s, problems)=>{
32
+ if (!(0, _numericLiteralsJs.isWellFormedInteger)(s)) {
33
+ return problems.mustBe("a well-formed integer string");
34
+ }
35
+ const parsed = parseInt(s);
36
+ return Number.isSafeInteger(parsed) ? parsed : problems.mustBe("an integer in the range Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER");
37
+ }
38
+ ]);
39
+ // https://www.regular-expressions.info/email.html
40
+ const email = (0, _scopeJs.rootType)(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/, {
41
+ mustBe: "a valid email"
42
+ });
43
+ // https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
44
+ const uuid = (0, _scopeJs.rootType)(/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/, {
45
+ mustBe: "a valid UUID"
46
+ });
47
+ // https://semver.org/
48
+ const semver = (0, _scopeJs.rootType)(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/, {
49
+ mustBe: "a valid semantic version (see https://semver.org/)"
50
+ });
51
+ const json = (0, _scopeJs.rootType)([
52
+ _tsKeywordsJs.tsKeywords.string,
53
+ "|>",
54
+ (s)=>JSON.parse(s)
55
+ ], {
56
+ mustBe: "a JSON-parsable string"
57
+ });
58
+ const validationScope = (0, _scopeJs.scope)({
59
+ // Character sets
60
+ alpha: [
61
+ /^[A-Za-z]*$/,
62
+ ":",
63
+ {
64
+ mustBe: "only letters"
65
+ }
66
+ ],
67
+ alphanumeric: [
68
+ /^[A-Za-z\d]*$/,
69
+ ":",
70
+ {
71
+ mustBe: "only letters and digits"
72
+ }
73
+ ],
74
+ lowercase: [
75
+ /^[a-z]*$/,
76
+ ":",
77
+ {
78
+ mustBe: "only lowercase letters"
79
+ }
80
+ ],
81
+ uppercase: [
82
+ /^[A-Z]*$/,
83
+ ":",
84
+ {
85
+ mustBe: "only uppercase letters"
86
+ }
87
+ ],
88
+ creditCard: _creditCardJs.creditCard,
89
+ email,
90
+ uuid,
91
+ parsedNumber,
92
+ parsedInteger,
93
+ parsedDate: _dateJs.parsedDate,
94
+ semver,
95
+ json,
96
+ integer: [
97
+ "node",
98
+ {
99
+ number: {
100
+ divisor: 1
101
+ }
102
+ }
103
+ ]
104
+ }, {
105
+ name: "validation",
106
+ standard: false
107
+ });
108
+ const validation = validationScope.compile();