arktype 1.0.9-alpha → 1.0.11-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +53 -39
  2. package/dist/cjs/main.js +26 -18
  3. package/dist/cjs/nodes/branch.js +18 -18
  4. package/dist/cjs/nodes/compose.js +28 -11
  5. package/dist/cjs/nodes/discriminate.js +27 -27
  6. package/dist/cjs/nodes/node.js +24 -24
  7. package/dist/cjs/nodes/predicate.js +17 -17
  8. package/dist/cjs/nodes/rules/class.js +5 -5
  9. package/dist/cjs/nodes/rules/collapsibleSet.js +3 -3
  10. package/dist/cjs/nodes/rules/divisor.js +2 -2
  11. package/dist/cjs/nodes/rules/props.js +19 -19
  12. package/dist/cjs/nodes/rules/range.js +6 -6
  13. package/dist/cjs/nodes/rules/regex.js +3 -3
  14. package/dist/cjs/nodes/rules/rules.js +20 -20
  15. package/dist/cjs/parse/ast/config.js +2 -2
  16. package/dist/cjs/parse/ast/distributableFunction.js +9 -9
  17. package/dist/cjs/parse/ast/intersection.js +5 -5
  18. package/dist/cjs/parse/ast/keyof.js +31 -30
  19. package/dist/cjs/parse/ast/morph.js +10 -10
  20. package/dist/cjs/parse/ast/narrow.js +6 -6
  21. package/dist/cjs/parse/ast/tuple.js +21 -21
  22. package/dist/cjs/parse/definition.js +18 -20
  23. package/dist/cjs/parse/record.js +4 -4
  24. package/dist/cjs/parse/string/reduce/dynamic.js +44 -26
  25. package/dist/cjs/parse/string/reduce/shared.js +2 -2
  26. package/dist/cjs/parse/string/shift/operand/enclosed.js +2 -2
  27. package/dist/cjs/parse/string/shift/operand/operand.js +3 -3
  28. package/dist/cjs/parse/string/shift/operand/unenclosed.js +3 -3
  29. package/dist/cjs/parse/string/shift/operator/bounds.js +18 -18
  30. package/dist/cjs/parse/string/shift/operator/divisor.js +6 -6
  31. package/dist/cjs/parse/string/shift/operator/operator.js +6 -6
  32. package/dist/cjs/parse/string/shift/scanner.js +16 -1
  33. package/dist/cjs/parse/string/string.js +8 -8
  34. package/dist/cjs/scopes/ark.js +15 -15
  35. package/dist/cjs/scopes/cache.js +16 -3
  36. package/dist/cjs/scopes/expressions.js +9 -9
  37. package/dist/cjs/scopes/jsObjects.js +2 -42
  38. package/dist/cjs/scopes/scope.js +59 -31
  39. package/dist/cjs/scopes/tsKeywords.js +2 -2
  40. package/dist/cjs/scopes/type.js +6 -5
  41. package/dist/cjs/scopes/validation/creditCard.js +2 -2
  42. package/dist/cjs/scopes/validation/date.js +4 -4
  43. package/dist/cjs/scopes/validation/validation.js +17 -17
  44. package/dist/cjs/traverse/problems.js +41 -21
  45. package/dist/cjs/traverse/traverse.js +56 -31
  46. package/dist/cjs/utils/data.js +18 -4
  47. package/dist/cjs/utils/generics.js +3 -3
  48. package/dist/cjs/utils/numericLiterals.js +4 -4
  49. package/dist/cjs/utils/objectKinds.js +4 -4
  50. package/dist/cjs/utils/serialize.js +6 -6
  51. package/dist/mjs/main.js +5 -1
  52. package/dist/mjs/nodes/compose.js +17 -0
  53. package/dist/mjs/parse/ast/config.js +5 -1
  54. package/dist/mjs/parse/ast/keyof.js +2 -1
  55. package/dist/mjs/parse/definition.js +0 -1
  56. package/dist/mjs/parse/string/reduce/dynamic.js +18 -0
  57. package/dist/mjs/parse/string/shift/scanner.js +16 -1
  58. package/dist/mjs/scopes/cache.js +14 -1
  59. package/dist/mjs/scopes/expressions.js +88 -8
  60. package/dist/mjs/scopes/jsObjects.js +4 -41
  61. package/dist/mjs/scopes/scope.js +30 -2
  62. package/dist/mjs/scopes/tsKeywords.js +18 -1
  63. package/dist/mjs/scopes/type.js +1 -0
  64. package/dist/mjs/scopes/validation/validation.js +19 -1
  65. package/dist/mjs/traverse/problems.js +22 -2
  66. package/dist/mjs/traverse/traverse.js +25 -0
  67. package/dist/mjs/utils/data.js +14 -0
  68. package/dist/tsconfig.temp.tsbuildinfo +1 -1
  69. package/dist/types/main.d.ts +8 -1
  70. package/dist/types/nodes/node.d.ts +6 -0
  71. package/dist/types/parse/ast/bound.d.ts +14 -0
  72. package/dist/types/parse/ast/config.d.ts +5 -0
  73. package/dist/types/parse/ast/divisor.d.ts +5 -0
  74. package/dist/types/parse/definition.d.ts +2 -4
  75. package/dist/types/parse/string/reduce/static.d.ts +12 -2
  76. package/dist/types/parse/string/shift/operand/operand.d.ts +3 -3
  77. package/dist/types/parse/string/shift/operand/unenclosed.d.ts +5 -5
  78. package/dist/types/parse/string/string.d.ts +1 -2
  79. package/dist/types/scopes/ark.d.ts +10 -22
  80. package/dist/types/scopes/expressions.d.ts +88 -0
  81. package/dist/types/scopes/jsObjects.d.ts +4 -10
  82. package/dist/types/scopes/tsKeywords.d.ts +18 -0
  83. package/dist/types/scopes/type.d.ts +4 -2
  84. package/dist/types/scopes/validation/validation.d.ts +19 -0
  85. package/dist/types/utils/generics.d.ts +2 -2
  86. package/package.json +17 -18
@@ -15,31 +15,31 @@ _export(exports, {
15
15
  spaces: ()=>spaces,
16
16
  type: ()=>type
17
17
  });
18
- const _jsObjectsTs = require("./jsObjects.js");
19
- const _scopeTs = require("./scope.js");
20
- const _tsKeywordsTs = require("./tsKeywords.js");
21
- const _validationTs = require("./validation/validation.js");
22
- const arkScope = (0, _scopeTs.scope)({}, {
18
+ const _jsObjectsJs = require("./jsObjects.js");
19
+ const _scopeJs = require("./scope.js");
20
+ const _tsKeywordsJs = require("./tsKeywords.js");
21
+ const _validationJs = require("./validation/validation.js");
22
+ const arkScope = (0, _scopeJs.scope)({}, {
23
23
  name: "standard",
24
24
  includes: [
25
- _tsKeywordsTs.tsKeywords,
26
- _jsObjectsTs.jsObjects,
27
- _validationTs.validation
25
+ _tsKeywordsJs.tsKeywords,
26
+ _jsObjectsJs.jsObjects,
27
+ _validationJs.validation
28
28
  ],
29
29
  standard: false
30
30
  });
31
31
  const ark = arkScope.compile();
32
32
  const scopes = {
33
- root: _scopeTs.rootScope,
34
- tsKeywords: _tsKeywordsTs.tsKeywordsScope,
35
- jsObjects: _jsObjectsTs.jsObjectsScope,
36
- validation: _validationTs.validationScope,
33
+ root: _scopeJs.rootScope,
34
+ tsKeywords: _tsKeywordsJs.tsKeywordsScope,
35
+ jsObjects: _jsObjectsJs.jsObjectsScope,
36
+ validation: _validationJs.validationScope,
37
37
  ark: arkScope
38
38
  };
39
39
  const spaces = {
40
- tsKeywords: _tsKeywordsTs.tsKeywords,
41
- jsObjects: _jsObjectsTs.jsObjects,
42
- validation: _validationTs.validation,
40
+ tsKeywords: _tsKeywordsJs.tsKeywords,
41
+ jsObjects: _jsObjectsJs.jsObjects,
42
+ validation: _validationJs.validation,
43
43
  ark
44
44
  };
45
45
  const type = arkScope.type;
@@ -12,7 +12,20 @@ _export(exports, {
12
12
  Cache: ()=>Cache,
13
13
  FreezingCache: ()=>FreezingCache
14
14
  });
15
- const _freezeTs = require("../utils/freeze.js");
15
+ const _freezeJs = require("../utils/freeze.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
+ }
16
29
  class Cache {
17
30
  get root() {
18
31
  return this.cache;
@@ -28,12 +41,12 @@ class Cache {
28
41
  return item;
29
42
  }
30
43
  constructor(){
31
- this.cache = {};
44
+ _defineProperty(this, "cache", {});
32
45
  }
33
46
  }
34
47
  class FreezingCache extends Cache {
35
48
  set(name, item) {
36
- this.cache[name] = (0, _freezeTs.deepFreeze)(item);
49
+ this.cache[name] = (0, _freezeJs.deepFreeze)(item);
37
50
  return item;
38
51
  }
39
52
  }
@@ -18,12 +18,12 @@ _export(exports, {
18
18
  narrow: ()=>narrow,
19
19
  morph: ()=>morph
20
20
  });
21
- const _arkTs = require("./ark.js");
22
- const intersection = _arkTs.scopes.ark.intersection;
23
- const union = _arkTs.scopes.ark.union;
24
- const arrayOf = _arkTs.scopes.ark.arrayOf;
25
- const keyOf = _arkTs.scopes.ark.keyOf;
26
- const instanceOf = _arkTs.scopes.ark.instanceOf;
27
- const valueOf = _arkTs.scopes.ark.valueOf;
28
- const narrow = _arkTs.scopes.ark.narrow;
29
- const morph = _arkTs.scopes.ark.morph;
21
+ const _arkJs = require("./ark.js");
22
+ const intersection = _arkJs.scopes.ark.intersection;
23
+ const union = _arkJs.scopes.ark.union;
24
+ const arrayOf = _arkJs.scopes.ark.arrayOf;
25
+ const keyOf = _arkJs.scopes.ark.keyOf;
26
+ const instanceOf = _arkJs.scopes.ark.instanceOf;
27
+ const valueOf = _arkJs.scopes.ark.valueOf;
28
+ const narrow = _arkJs.scopes.ark.narrow;
29
+ const morph = _arkJs.scopes.ark.morph;
@@ -12,8 +12,8 @@ _export(exports, {
12
12
  jsObjectsScope: ()=>jsObjectsScope,
13
13
  jsObjects: ()=>jsObjects
14
14
  });
15
- const _scopeTs = require("./scope.js");
16
- const jsObjectsScope = (0, _scopeTs.scope)({
15
+ const _scopeJs = require("./scope.js");
16
+ const jsObjectsScope = (0, _scopeJs.scope)({
17
17
  Function: [
18
18
  "node",
19
19
  {
@@ -22,14 +22,6 @@ const jsObjectsScope = (0, _scopeTs.scope)({
22
22
  }
23
23
  }
24
24
  ],
25
- Array: [
26
- "node",
27
- {
28
- object: {
29
- class: Array
30
- }
31
- }
32
- ],
33
25
  Date: [
34
26
  "node",
35
27
  {
@@ -70,38 +62,6 @@ const jsObjectsScope = (0, _scopeTs.scope)({
70
62
  }
71
63
  }
72
64
  ],
73
- Object: [
74
- "node",
75
- {
76
- object: {
77
- class: Object
78
- }
79
- }
80
- ],
81
- String: [
82
- "node",
83
- {
84
- object: {
85
- class: String
86
- }
87
- }
88
- ],
89
- Number: [
90
- "node",
91
- {
92
- object: {
93
- class: Number
94
- }
95
- }
96
- ],
97
- Boolean: [
98
- "node",
99
- {
100
- object: {
101
- class: Boolean
102
- }
103
- }
104
- ],
105
65
  WeakMap: [
106
66
  "node",
107
67
  {
@@ -18,16 +18,16 @@ _export(exports, {
18
18
  writeShallowCycleErrorMessage: ()=>writeShallowCycleErrorMessage,
19
19
  writeDuplicateAliasesMessage: ()=>writeDuplicateAliasesMessage
20
20
  });
21
- const _nodeTs = require("../nodes/node.js");
22
- const _definitionTs = require("../parse/definition.js");
23
- const _problemsTs = require("../traverse/problems.js");
24
- const _chainableNoOpProxyTs = require("../utils/chainableNoOpProxy.js");
25
- const _errorsTs = require("../utils/errors.js");
26
- const _freezeTs = require("../utils/freeze.js");
27
- const _genericsTs = require("../utils/generics.js");
28
- const _pathsTs = require("../utils/paths.js");
29
- const _cacheTs = require("./cache.js");
30
- const _typeTs = require("./type.js");
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
31
  function _checkPrivateRedeclaration(obj, privateCollection) {
32
32
  if (privateCollection.has(obj)) {
33
33
  throw new TypeError("Cannot initialize the same private elements twice on an object");
@@ -78,9 +78,21 @@ function _classPrivateMethodInit(obj, privateSet) {
78
78
  _checkPrivateRedeclaration(obj, privateSet);
79
79
  privateSet.add(obj);
80
80
  }
81
- var _ctx_type, _ctx_type1;
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
+ }
82
94
  const compileScopeOptions = (opts)=>({
83
- codes: (0, _problemsTs.compileProblemWriters)(opts.codes),
95
+ codes: (0, _problemsJs.compileProblemWriters)(opts.codes),
84
96
  keys: opts.keys ?? "loose"
85
97
  });
86
98
  let anonymousScopeCount = 0;
@@ -98,11 +110,12 @@ class Scope {
98
110
  return `${this.name}.${id}`;
99
111
  }
100
112
  addAnonymousTypeReference(referencedType, ctx) {
113
+ var _ctx_type;
101
114
  (_ctx_type = ctx.type).includesMorph || (_ctx_type.includesMorph = referencedType.includesMorph);
102
115
  return referencedType.node;
103
116
  }
104
117
  get infer() {
105
- return _chainableNoOpProxyTs.chainableNoOpProxy;
118
+ return _chainableNoOpProxyJs.chainableNoOpProxy;
106
119
  }
107
120
  compile() {
108
121
  if (!spaceRegistry[this.name]) {
@@ -114,13 +127,14 @@ class Scope {
114
127
  return _classPrivateFieldGet(this, _exports).root;
115
128
  }
116
129
  addParsedReferenceIfResolvable(name, ctx) {
130
+ var _ctx_type;
117
131
  const resolution = _classPrivateMethodGet(this, _resolveRecurse, resolveRecurse).call(this, name, "undefined", [
118
132
  name
119
133
  ]);
120
134
  if (!resolution) {
121
135
  return false;
122
136
  }
123
- (_ctx_type1 = ctx.type).includesMorph || (_ctx_type1.includesMorph = resolution.includesMorph);
137
+ (_ctx_type = ctx.type).includesMorph || (_ctx_type.includesMorph = resolution.includesMorph);
124
138
  return true;
125
139
  }
126
140
  resolve(name) {
@@ -133,7 +147,7 @@ class Scope {
133
147
  }
134
148
  resolveTypeNode(node) {
135
149
  const resolution = this.resolveNode(node);
136
- return (0, _nodeTs.isConfigNode)(resolution) ? resolution.node : resolution;
150
+ return (0, _nodeJs.isConfigNode)(resolution) ? resolution.node : resolution;
137
151
  }
138
152
  isResolvable(name) {
139
153
  return _classPrivateFieldGet(this, _resolutions).has(name) || this.aliases[name];
@@ -143,6 +157,10 @@ class Scope {
143
157
  _classPrivateMethodInit(this, _cacheSpaces);
144
158
  _classPrivateMethodInit(this, _initializeContext);
145
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);
146
164
  _classPrivateFieldInit(this, _resolutions, {
147
165
  writable: true,
148
166
  value: void 0
@@ -151,10 +169,20 @@ class Scope {
151
169
  writable: true,
152
170
  value: void 0
153
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);
154
182
  this.aliases = aliases;
155
- this.parseCache = new _cacheTs.FreezingCache();
156
- _classPrivateFieldSet(this, _resolutions, new _cacheTs.Cache());
157
- _classPrivateFieldSet(this, _exports, new _cacheTs.Cache());
183
+ this.parseCache = new _cacheJs.FreezingCache();
184
+ _classPrivateFieldSet(this, _resolutions, new _cacheJs.Cache());
185
+ _classPrivateFieldSet(this, _exports, new _cacheJs.Cache());
158
186
  this.expressions = {
159
187
  intersection: (l, r, opts)=>this.type([
160
188
  l,
@@ -206,14 +234,14 @@ class Scope {
206
234
  this.narrow = this.expressions.narrow;
207
235
  this.morph = this.expressions.morph;
208
236
  this.type = Object.assign((def, config = {})=>{
209
- const t = (0, _typeTs.initializeType)("λtype", def, config, this);
237
+ const t = (0, _typeJs.initializeType)("λtype", def, config, this);
210
238
  const ctx = _classPrivateMethodGet(this, _initializeContext, initializeContext).call(this, t);
211
- const root = (0, _definitionTs.parseDefinition)(def, ctx);
212
- t.node = (0, _freezeTs.deepFreeze)((0, _genericsTs.hasKeys)(config) ? {
239
+ const root = (0, _definitionJs.parseDefinition)(def, ctx);
240
+ t.node = (0, _freezeJs.deepFreeze)((0, _genericsJs.hasKeys)(config) ? {
213
241
  config,
214
242
  node: this.resolveTypeNode(root)
215
243
  } : root);
216
- t.flat = (0, _freezeTs.deepFreeze)((0, _nodeTs.flattenType)(t));
244
+ t.flat = (0, _freezeJs.deepFreeze)((0, _nodeJs.flattenType)(t));
217
245
  return t;
218
246
  }, {
219
247
  from: this.expressions.node
@@ -234,7 +262,7 @@ class Scope {
234
262
  }
235
263
  }
236
264
  function register(opts) {
237
- const name = opts.name ? scopeRegistry[opts.name] ? (0, _errorsTs.throwParseError)(`A scope named '${opts.name}' already exists`) : opts.name : `scope${++anonymousScopeCount}`;
265
+ const name = opts.name ? scopeRegistry[opts.name] ? (0, _errorsJs.throwParseError)(`A scope named '${opts.name}' already exists`) : opts.name : `scope${++anonymousScopeCount}`;
238
266
  scopeRegistry[name] = this;
239
267
  return name;
240
268
  }
@@ -242,7 +270,7 @@ function cacheSpaces(spaces, kind) {
242
270
  for (const space of spaces){
243
271
  for(const name in space){
244
272
  if (_classPrivateFieldGet(this, _resolutions).has(name) || name in this.aliases) {
245
- (0, _errorsTs.throwParseError)(writeDuplicateAliasesMessage(name));
273
+ (0, _errorsJs.throwParseError)(writeDuplicateAliasesMessage(name));
246
274
  }
247
275
  _classPrivateFieldGet(this, _resolutions).set(name, space[name]);
248
276
  if (kind === "includes") {
@@ -254,7 +282,7 @@ function cacheSpaces(spaces, kind) {
254
282
  function initializeContext(type) {
255
283
  return {
256
284
  type,
257
- path: new _pathsTs.Path()
285
+ path: new _pathsJs.Path()
258
286
  };
259
287
  }
260
288
  function resolveRecurse(name, onUnresolvable, seen) {
@@ -264,22 +292,22 @@ function resolveRecurse(name, onUnresolvable, seen) {
264
292
  }
265
293
  const aliasDef = this.aliases[name];
266
294
  if (!aliasDef) {
267
- return onUnresolvable === "throw" ? (0, _errorsTs.throwInternalError)(`Unexpectedly failed to resolve alias '${name}'`) : undefined;
295
+ return onUnresolvable === "throw" ? (0, _errorsJs.throwInternalError)(`Unexpectedly failed to resolve alias '${name}'`) : undefined;
268
296
  }
269
- const t = (0, _typeTs.initializeType)(name, aliasDef, {}, this);
297
+ const t = (0, _typeJs.initializeType)(name, aliasDef, {}, this);
270
298
  const ctx = _classPrivateMethodGet(this, _initializeContext, initializeContext).call(this, t);
271
299
  _classPrivateFieldGet(this, _resolutions).set(name, t);
272
300
  _classPrivateFieldGet(this, _exports).set(name, t);
273
- let node = (0, _definitionTs.parseDefinition)(aliasDef, ctx);
301
+ let node = (0, _definitionJs.parseDefinition)(aliasDef, ctx);
274
302
  if (typeof node === "string") {
275
303
  if (seen.includes(node)) {
276
- return (0, _errorsTs.throwParseError)(writeShallowCycleErrorMessage(name, seen));
304
+ return (0, _errorsJs.throwParseError)(writeShallowCycleErrorMessage(name, seen));
277
305
  }
278
306
  seen.push(node);
279
307
  node = _classPrivateMethodGet(this, _resolveRecurse, resolveRecurse).call(this, node, "throw", seen).node;
280
308
  }
281
- t.node = (0, _freezeTs.deepFreeze)(node);
282
- t.flat = (0, _freezeTs.deepFreeze)((0, _nodeTs.flattenType)(t));
309
+ t.node = (0, _freezeJs.deepFreeze)(node);
310
+ t.flat = (0, _freezeJs.deepFreeze)((0, _nodeJs.flattenType)(t));
283
311
  return t;
284
312
  }
285
313
  const scope = (aliases, opts = {})=>new Scope(aliases, opts);
@@ -12,7 +12,7 @@ _export(exports, {
12
12
  tsKeywordsScope: ()=>tsKeywordsScope,
13
13
  tsKeywords: ()=>tsKeywords
14
14
  });
15
- const _scopeTs = require("./scope.js");
15
+ const _scopeJs = require("./scope.js");
16
16
  const always = {
17
17
  bigint: true,
18
18
  boolean: true,
@@ -23,7 +23,7 @@ const always = {
23
23
  symbol: true,
24
24
  undefined: true
25
25
  };
26
- const tsKeywordsScope = (0, _scopeTs.scope)({
26
+ const tsKeywordsScope = (0, _scopeJs.scope)({
27
27
  any: [
28
28
  "node",
29
29
  always
@@ -13,8 +13,8 @@ _export(exports, {
13
13
  isType: ()=>isType,
14
14
  isAnonymousName: ()=>isAnonymousName
15
15
  });
16
- const _traverseTs = require("../traverse/traverse.js");
17
- const _chainableNoOpProxyTs = require("../utils/chainableNoOpProxy.js");
16
+ const _traverseJs = require("../traverse/traverse.js");
17
+ const _chainableNoOpProxyJs = require("../utils/chainableNoOpProxy.js");
18
18
  const initializeType = (name, definition, config, scope)=>{
19
19
  const root = {
20
20
  // temporarily initialize node/flat to aliases that will be included in
@@ -31,7 +31,8 @@ const initializeType = (name, definition, config, scope)=>{
31
31
  const result = namedTraverse(data);
32
32
  return result.problems ? result.problems.throw() : result.data;
33
33
  },
34
- infer: _chainableNoOpProxyTs.chainableNoOpProxy,
34
+ infer: _chainableNoOpProxyJs.chainableNoOpProxy,
35
+ inferIn: _chainableNoOpProxyJs.chainableNoOpProxy,
35
36
  qualifiedName: isAnonymousName(name) ? scope.getAnonymousQualifiedName(name) : `${scope.name}.${name}`,
36
37
  definition,
37
38
  scope,
@@ -40,10 +41,10 @@ const initializeType = (name, definition, config, scope)=>{
40
41
  };
41
42
  // define within a key to dynamically assign a name to the function
42
43
  const namedTraverse = {
43
- [name]: (data)=>(0, _traverseTs.traverseRoot)(namedTraverse, data)
44
+ [name]: (data)=>(0, _traverseJs.traverseRoot)(namedTraverse, data)
44
45
  }[name];
45
46
  const t = Object.assign(namedTraverse, root);
46
47
  return t;
47
48
  };
48
- const isType = (value)=>value?.infer === _chainableNoOpProxyTs.chainableNoOpProxy;
49
+ const isType = (value)=>value?.infer === _chainableNoOpProxyJs.chainableNoOpProxy;
49
50
  const isAnonymousName = (name)=>name[0] === "λ";
@@ -12,7 +12,7 @@ _export(exports, {
12
12
  isLuhnValid: ()=>isLuhnValid,
13
13
  creditCard: ()=>creditCard
14
14
  });
15
- const _scopeTs = require("../scope.js");
15
+ const _scopeJs = require("../scope.js");
16
16
  const isLuhnValid = (creditCardInput)=>{
17
17
  const sanitized = creditCardInput.replace(/[- ]+/g, "");
18
18
  let sum = 0;
@@ -38,7 +38,7 @@ const isLuhnValid = (creditCardInput)=>{
38
38
  };
39
39
  // https://github.com/validatorjs/validator.js/blob/master/src/lib/isCreditCard.js
40
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, _scopeTs.rootType)([
41
+ const creditCard = (0, _scopeJs.rootType)([
42
42
  creditCardMatcher,
43
43
  "=>",
44
44
  (s, problems)=>isLuhnValid(s) || !problems.mustBe("a valid credit card number")
@@ -12,8 +12,8 @@ _export(exports, {
12
12
  tryParseDate: ()=>tryParseDate,
13
13
  parsedDate: ()=>parsedDate
14
14
  });
15
- const _scopeTs = require("../scope.js");
16
- const _tsKeywordsTs = require("../tsKeywords.js");
15
+ const _scopeJs = require("../scope.js");
16
+ const _tsKeywordsJs = require("../tsKeywords.js");
17
17
  const dayDelimiterMatcher = /^[./-]$/;
18
18
  // ISO 8601 date/time modernized from https://github.com/validatorjs/validator.js/blob/master/src/lib/isISO8601.js
19
19
  // Based on https://tc39.es/ecma262/#sec-date-time-string-format, the T
@@ -52,8 +52,8 @@ const tryParseDate = (data, opts)=>{
52
52
  }
53
53
  return writeFormattedMustBe(opts.format);
54
54
  };
55
- const parsedDate = (0, _scopeTs.rootType)([
56
- _tsKeywordsTs.tsKeywords.string,
55
+ const parsedDate = (0, _scopeJs.rootType)([
56
+ _tsKeywordsJs.tsKeywords.string,
57
57
  "|>",
58
58
  (s, problems)=>{
59
59
  const result = tryParseDate(s);
@@ -12,46 +12,46 @@ _export(exports, {
12
12
  validationScope: ()=>validationScope,
13
13
  validation: ()=>validation
14
14
  });
15
- const _numericLiteralsTs = require("../../utils/numericLiterals.js");
16
- const _scopeTs = require("../scope.js");
17
- const _tsKeywordsTs = require("../tsKeywords.js");
18
- const _creditCardTs = require("./creditCard.js");
19
- const _dateTs = require("./date.js");
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
20
  // Non-trivial expressions should have an explanation or attribution
21
- const parsedNumber = (0, _scopeTs.rootType)([
22
- _numericLiteralsTs.wellFormedNumberMatcher,
21
+ const parsedNumber = (0, _scopeJs.rootType)([
22
+ _numericLiteralsJs.wellFormedNumberMatcher,
23
23
  "|>",
24
24
  (s)=>parseFloat(s)
25
25
  ], {
26
26
  mustBe: "a well-formed numeric string"
27
27
  });
28
- const parsedInteger = (0, _scopeTs.rootType)([
29
- _numericLiteralsTs.wellFormedIntegerMatcher,
28
+ const parsedInteger = (0, _scopeJs.rootType)([
29
+ _numericLiteralsJs.wellFormedIntegerMatcher,
30
30
  "|>",
31
31
  (s)=>parseInt(s)
32
32
  ], {
33
33
  mustBe: "a well-formed integer string"
34
34
  });
35
35
  // https://www.regular-expressions.info/email.html
36
- const email = (0, _scopeTs.rootType)(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/, {
36
+ const email = (0, _scopeJs.rootType)(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/, {
37
37
  mustBe: "a valid email"
38
38
  });
39
39
  // https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
40
- const uuid = (0, _scopeTs.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}$/, {
40
+ 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}$/, {
41
41
  mustBe: "a valid UUID"
42
42
  });
43
43
  // https://semver.org/
44
- const semver = (0, _scopeTs.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-]+)*))?$/, {
44
+ 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-]+)*))?$/, {
45
45
  mustBe: "a valid semantic version (see https://semver.org/)"
46
46
  });
47
- const json = (0, _scopeTs.rootType)([
48
- _tsKeywordsTs.tsKeywords.string,
47
+ const json = (0, _scopeJs.rootType)([
48
+ _tsKeywordsJs.tsKeywords.string,
49
49
  "|>",
50
50
  (s)=>JSON.parse(s)
51
51
  ], {
52
52
  mustBe: "a JSON-parsable string"
53
53
  });
54
- const validationScope = (0, _scopeTs.scope)({
54
+ const validationScope = (0, _scopeJs.scope)({
55
55
  // Character sets
56
56
  alpha: [
57
57
  /^[A-Za-z]*$/,
@@ -81,12 +81,12 @@ const validationScope = (0, _scopeTs.scope)({
81
81
  mustBe: "only uppercase letters"
82
82
  }
83
83
  ],
84
- creditCard: _creditCardTs.creditCard,
84
+ creditCard: _creditCardJs.creditCard,
85
85
  email,
86
86
  uuid,
87
87
  parsedNumber,
88
88
  parsedInteger,
89
- parsedDate: _dateTs.parsedDate,
89
+ parsedDate: _dateJs.parsedDate,
90
90
  semver,
91
91
  json,
92
92
  integer: [