arktype 1.0.10-alpha → 1.0.12-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +22 -4
  2. package/dist/cjs/main.js +26 -24
  3. package/dist/cjs/nodes/branch.js +18 -18
  4. package/dist/cjs/nodes/compose.js +28 -11
  5. package/dist/cjs/nodes/discriminate.js +27 -27
  6. package/dist/cjs/nodes/node.js +24 -24
  7. package/dist/cjs/nodes/predicate.js +17 -17
  8. package/dist/cjs/nodes/rules/class.js +5 -5
  9. package/dist/cjs/nodes/rules/collapsibleSet.js +3 -3
  10. package/dist/cjs/nodes/rules/divisor.js +2 -2
  11. package/dist/cjs/nodes/rules/props.js +19 -19
  12. package/dist/cjs/nodes/rules/range.js +6 -6
  13. package/dist/cjs/nodes/rules/regex.js +3 -3
  14. package/dist/cjs/nodes/rules/rules.js +20 -20
  15. package/dist/cjs/parse/ast/config.js +2 -2
  16. package/dist/cjs/parse/ast/distributableFunction.js +9 -9
  17. package/dist/cjs/parse/ast/intersection.js +5 -5
  18. package/dist/cjs/parse/ast/keyof.js +31 -30
  19. package/dist/cjs/parse/ast/morph.js +10 -10
  20. package/dist/cjs/parse/ast/narrow.js +6 -6
  21. package/dist/cjs/parse/ast/tuple.js +21 -21
  22. package/dist/cjs/parse/definition.js +18 -20
  23. package/dist/cjs/parse/record.js +4 -4
  24. package/dist/cjs/parse/string/reduce/dynamic.js +44 -26
  25. package/dist/cjs/parse/string/reduce/shared.js +2 -2
  26. package/dist/cjs/parse/string/shift/operand/enclosed.js +2 -2
  27. package/dist/cjs/parse/string/shift/operand/operand.js +3 -3
  28. package/dist/cjs/parse/string/shift/operand/unenclosed.js +3 -3
  29. package/dist/cjs/parse/string/shift/operator/bounds.js +18 -18
  30. package/dist/cjs/parse/string/shift/operator/divisor.js +6 -6
  31. package/dist/cjs/parse/string/shift/operator/operator.js +6 -6
  32. package/dist/cjs/parse/string/shift/scanner.js +16 -1
  33. package/dist/cjs/parse/string/string.js +8 -8
  34. package/dist/cjs/scopes/ark.js +15 -15
  35. package/dist/cjs/scopes/cache.js +16 -3
  36. package/dist/cjs/scopes/expressions.js +9 -9
  37. package/dist/cjs/scopes/jsObjects.js +2 -42
  38. package/dist/cjs/scopes/scope.js +59 -31
  39. package/dist/cjs/scopes/tsKeywords.js +2 -2
  40. package/dist/cjs/scopes/type.js +6 -6
  41. package/dist/cjs/scopes/validation/creditCard.js +2 -2
  42. package/dist/cjs/scopes/validation/date.js +4 -4
  43. package/dist/cjs/scopes/validation/validation.js +17 -17
  44. package/dist/cjs/traverse/problems.js +41 -21
  45. package/dist/cjs/traverse/traverse.js +57 -32
  46. package/dist/cjs/utils/data.js +18 -4
  47. package/dist/cjs/utils/generics.js +3 -3
  48. package/dist/cjs/utils/numericLiterals.js +4 -4
  49. package/dist/cjs/utils/objectKinds.js +4 -4
  50. package/dist/cjs/utils/serialize.js +6 -6
  51. package/dist/mjs/main.js +2 -1
  52. package/dist/mjs/nodes/compose.js +17 -0
  53. package/dist/mjs/parse/ast/config.js +5 -1
  54. package/dist/mjs/parse/ast/keyof.js +2 -1
  55. package/dist/mjs/parse/definition.js +0 -1
  56. package/dist/mjs/parse/string/reduce/dynamic.js +18 -0
  57. package/dist/mjs/parse/string/shift/scanner.js +16 -1
  58. package/dist/mjs/scopes/cache.js +14 -1
  59. package/dist/mjs/scopes/expressions.js +88 -8
  60. package/dist/mjs/scopes/jsObjects.js +2 -41
  61. package/dist/mjs/scopes/scope.js +30 -2
  62. package/dist/mjs/scopes/tsKeywords.js +2 -1
  63. package/dist/mjs/scopes/validation/validation.js +2 -1
  64. package/dist/mjs/traverse/problems.js +23 -3
  65. package/dist/mjs/traverse/traverse.js +26 -1
  66. package/dist/mjs/utils/data.js +14 -0
  67. package/dist/tsconfig.temp.tsbuildinfo +1 -1
  68. package/dist/types/main.d.ts +5 -1
  69. package/dist/types/nodes/node.d.ts +6 -0
  70. package/dist/types/parse/ast/bound.d.ts +14 -0
  71. package/dist/types/parse/ast/config.d.ts +5 -0
  72. package/dist/types/parse/ast/divisor.d.ts +5 -0
  73. package/dist/types/parse/definition.d.ts +2 -6
  74. package/dist/types/parse/string/reduce/static.d.ts +12 -2
  75. package/dist/types/parse/string/shift/operand/operand.d.ts +3 -3
  76. package/dist/types/parse/string/shift/operand/unenclosed.d.ts +5 -5
  77. package/dist/types/parse/string/string.d.ts +1 -2
  78. package/dist/types/scopes/ark.d.ts +10 -22
  79. package/dist/types/scopes/expressions.d.ts +88 -0
  80. package/dist/types/scopes/jsObjects.d.ts +2 -11
  81. package/dist/types/scopes/tsKeywords.d.ts +2 -1
  82. package/dist/types/scopes/validation/validation.d.ts +2 -1
  83. package/dist/types/traverse/problems.d.ts +1 -1
  84. package/dist/types/utils/generics.d.ts +1 -1
  85. package/package.json +15 -16
@@ -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,8 +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,
35
- inferIn: _chainableNoOpProxyTs.chainableNoOpProxy,
34
+ infer: _chainableNoOpProxyJs.chainableNoOpProxy,
35
+ inferIn: _chainableNoOpProxyJs.chainableNoOpProxy,
36
36
  qualifiedName: isAnonymousName(name) ? scope.getAnonymousQualifiedName(name) : `${scope.name}.${name}`,
37
37
  definition,
38
38
  scope,
@@ -41,10 +41,10 @@ const initializeType = (name, definition, config, scope)=>{
41
41
  };
42
42
  // define within a key to dynamically assign a name to the function
43
43
  const namedTraverse = {
44
- [name]: (data)=>(0, _traverseTs.traverseRoot)(namedTraverse, data)
44
+ [name]: (data)=>(0, _traverseJs.traverseRoot)(namedTraverse, data)
45
45
  }[name];
46
46
  const t = Object.assign(namedTraverse, root);
47
47
  return t;
48
48
  };
49
- const isType = (value)=>value?.infer === _chainableNoOpProxyTs.chainableNoOpProxy;
49
+ const isType = (value)=>value?.infer === _chainableNoOpProxyJs.chainableNoOpProxy;
50
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: [
@@ -19,14 +19,14 @@ _export(exports, {
19
19
  defaultProblemWriters: ()=>defaultProblemWriters,
20
20
  compileProblemWriters: ()=>compileProblemWriters
21
21
  });
22
- const _scannerTs = require("../parse/string/shift/scanner.js");
23
- const _dataTs = require("../utils/data.js");
24
- const _domainsTs = require("../utils/domains.js");
25
- const _genericsTs = require("../utils/generics.js");
26
- const _numericLiteralsTs = require("../utils/numericLiterals.js");
27
- const _objectKindsTs = require("../utils/objectKinds.js");
28
- const _pathsTs = require("../utils/paths.js");
29
- const _serializeTs = require("../utils/serialize.js");
22
+ const _scannerJs = require("../parse/string/shift/scanner.js");
23
+ const _dataJs = require("../utils/data.js");
24
+ const _domainsJs = require("../utils/domains.js");
25
+ const _genericsJs = require("../utils/generics.js");
26
+ const _numericLiteralsJs = require("../utils/numericLiterals.js");
27
+ const _objectKindsJs = require("../utils/objectKinds.js");
28
+ const _pathsJs = require("../utils/paths.js");
29
+ const _serializeJs = require("../utils/serialize.js");
30
30
  function _checkPrivateRedeclaration(obj, privateCollection) {
31
31
  if (privateCollection.has(obj)) {
32
32
  throw new TypeError("Cannot initialize the same private elements twice on an object");
@@ -67,9 +67,23 @@ function _classPrivateFieldSet(receiver, privateMap, value) {
67
67
  _classApplyDescriptorSet(receiver, descriptor, value);
68
68
  return value;
69
69
  }
70
+ function _defineProperty(obj, key, value) {
71
+ if (key in obj) {
72
+ Object.defineProperty(obj, key, {
73
+ value: value,
74
+ enumerable: true,
75
+ configurable: true,
76
+ writable: true
77
+ });
78
+ } else {
79
+ obj[key] = value;
80
+ }
81
+ return obj;
82
+ }
70
83
  class ArkTypeError extends TypeError {
71
84
  constructor(problems){
72
85
  super(`${problems}`);
86
+ _defineProperty(this, "cause", void 0);
73
87
  this.cause = problems;
74
88
  }
75
89
  }
@@ -81,12 +95,18 @@ class Problem {
81
95
  return this.writers.addContext(this.reason, this.path);
82
96
  }
83
97
  get reason() {
84
- return this.writers.writeReason(this.mustBe, new _dataTs.DataWrapper(this.data));
98
+ return this.writers.writeReason(this.mustBe, new _dataJs.DataWrapper(this.data));
85
99
  }
86
100
  get mustBe() {
87
101
  return typeof this.writers.mustBe === "string" ? this.writers.mustBe : this.writers.mustBe(this.source);
88
102
  }
89
103
  constructor(code, path, data, source, writers){
104
+ _defineProperty(this, "code", void 0);
105
+ _defineProperty(this, "path", void 0);
106
+ _defineProperty(this, "data", void 0);
107
+ _defineProperty(this, "source", void 0);
108
+ _defineProperty(this, "writers", void 0);
109
+ _defineProperty(this, "parts", void 0);
90
110
  this.code = code;
91
111
  this.path = path;
92
112
  this.data = data;
@@ -104,7 +124,7 @@ class ProblemArray extends Array {
104
124
  }
105
125
  add(code, source, opts) {
106
126
  // copy the path to avoid future mutations affecting it
107
- const path = opts?.path ?? _pathsTs.Path.from(_classPrivateFieldGet(this, _state).path);
127
+ const path = _pathsJs.Path.from(opts?.path ?? _classPrivateFieldGet(this, _state).path);
108
128
  const data = // we have to check for the presence of the key explicitly since the
109
129
  // data could be undefined or null
110
130
  opts && "data" in opts ? opts.data : _classPrivateFieldGet(this, _state).data;
@@ -149,8 +169,8 @@ class ProblemArray extends Array {
149
169
  }
150
170
  constructor(state){
151
171
  super();
152
- this.byPath = {};
153
- this.count = 0;
172
+ _defineProperty(this, "byPath", {});
173
+ _defineProperty(this, "count", 0);
154
174
  _classPrivateFieldInit(this, _state, {
155
175
  writable: true,
156
176
  value: void 0
@@ -160,8 +180,8 @@ class ProblemArray extends Array {
160
180
  }
161
181
  const Problems = ProblemArray;
162
182
  const capitalize = (s)=>s[0].toUpperCase() + s.slice(1);
163
- const domainsToDescriptions = (domains)=>domains.map((objectKind)=>_domainsTs.domainDescriptions[objectKind]);
164
- const objectKindsToDescriptions = (kinds)=>kinds.map((objectKind)=>_objectKindsTs.objectKindDescriptions[objectKind]);
183
+ const domainsToDescriptions = (domains)=>domains.map((objectKind)=>_domainsJs.domainDescriptions[objectKind]);
184
+ const objectKindsToDescriptions = (kinds)=>kinds.map((objectKind)=>_objectKindsJs.objectKindDescriptions[objectKind]);
165
185
  const describeBranches = (descriptions)=>{
166
186
  if (descriptions.length === 0) {
167
187
  return "never";
@@ -180,20 +200,20 @@ const describeBranches = (descriptions)=>{
180
200
  return description;
181
201
  };
182
202
  const writeDefaultReason = (mustBe, was)=>`must be ${mustBe}${was && ` (was ${was})`}`;
183
- const addDefaultContext = (reason, path)=>path.length === 0 ? capitalize(reason) : path.length === 1 && (0, _numericLiteralsTs.isWellFormedInteger)(path[0]) ? `Item at index ${path[0]} ${reason}` : `${path} ${reason}`;
203
+ const addDefaultContext = (reason, path)=>path.length === 0 ? capitalize(reason) : path.length === 1 && (0, _numericLiteralsJs.isWellFormedInteger)(path[0]) ? `Item at index ${path[0]} ${reason}` : `${path} ${reason}`;
184
204
  const defaultProblemConfig = {
185
205
  divisor: {
186
206
  mustBe: (divisor)=>divisor === 1 ? `an integer` : `a multiple of ${divisor}`
187
207
  },
188
208
  class: {
189
209
  mustBe: (expected)=>{
190
- const possibleObjectKind = (0, _objectKindsTs.getExactConstructorObjectKind)(expected);
191
- return possibleObjectKind ? _objectKindsTs.objectKindDescriptions[possibleObjectKind] : `an instance of ${expected.name}`;
210
+ const possibleObjectKind = (0, _objectKindsJs.getExactConstructorObjectKind)(expected);
211
+ return possibleObjectKind ? _objectKindsJs.objectKindDescriptions[possibleObjectKind] : `an instance of ${expected.name}`;
192
212
  },
193
213
  writeReason: (mustBe, data)=>writeDefaultReason(mustBe, data.className)
194
214
  },
195
215
  domain: {
196
- mustBe: (domain)=>_domainsTs.domainDescriptions[domain],
216
+ mustBe: (domain)=>_domainsJs.domainDescriptions[domain],
197
217
  writeReason: (mustBe, data)=>writeDefaultReason(mustBe, data.domain)
198
218
  },
199
219
  missing: {
@@ -205,14 +225,14 @@ const defaultProblemConfig = {
205
225
  writeReason: (mustBe)=>writeDefaultReason(mustBe, "")
206
226
  },
207
227
  bound: {
208
- mustBe: (bound)=>`${_scannerTs.Scanner.comparatorDescriptions[bound.comparator]} ${bound.limit}${bound.units ? ` ${bound.units}` : ""}`,
228
+ mustBe: (bound)=>`${_scannerJs.Scanner.comparatorDescriptions[bound.comparator]} ${bound.limit}${bound.units ? ` ${bound.units}` : ""}`,
209
229
  writeReason: (mustBe, data)=>writeDefaultReason(mustBe, `${data.size}`)
210
230
  },
211
231
  regex: {
212
232
  mustBe: (expression)=>`a string matching ${expression}`
213
233
  },
214
234
  value: {
215
- mustBe: _serializeTs.stringify
235
+ mustBe: _serializeJs.stringify
216
236
  },
217
237
  branches: {
218
238
  mustBe: (branchProblems)=>describeBranches(branchProblems.map((problem)=>`${problem.path} must be ${problem.parts ? describeBranches(problem.parts.map((part)=>part.mustBe)) : problem.mustBe}`)),
@@ -231,7 +251,7 @@ const defaultProblemConfig = {
231
251
  mustBe: (cases)=>describeBranches(cases)
232
252
  }
233
253
  };
234
- const problemCodes = (0, _genericsTs.objectKeysOf)(defaultProblemConfig);
254
+ const problemCodes = (0, _genericsJs.objectKeysOf)(defaultProblemConfig);
235
255
  const compileDefaultProblemWriters = ()=>{
236
256
  const result = {};
237
257
  let code;