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
@@ -15,17 +15,17 @@ _export(exports, {
15
15
  checkEntries: ()=>checkEntries,
16
16
  checkRequiredProp: ()=>checkRequiredProp
17
17
  });
18
- const _discriminateTs = require("../nodes/discriminate.js");
19
- const _classTs = require("../nodes/rules/class.js");
20
- const _divisorTs = require("../nodes/rules/divisor.js");
21
- const _rangeTs = require("../nodes/rules/range.js");
22
- const _regexTs = require("../nodes/rules/regex.js");
23
- const _rulesTs = require("../nodes/rules/rules.js");
24
- const _domainsTs = require("../utils/domains.js");
25
- const _errorsTs = require("../utils/errors.js");
26
- const _genericsTs = require("../utils/generics.js");
27
- const _pathsTs = require("../utils/paths.js");
28
- const _problemsTs = require("./problems.js");
18
+ const _discriminateJs = require("../nodes/discriminate.js");
19
+ const _classJs = require("../nodes/rules/class.js");
20
+ const _divisorJs = require("../nodes/rules/divisor.js");
21
+ const _rangeJs = require("../nodes/rules/range.js");
22
+ const _regexJs = require("../nodes/rules/regex.js");
23
+ const _rulesJs = require("../nodes/rules/rules.js");
24
+ const _domainsJs = require("../utils/domains.js");
25
+ const _errorsJs = require("../utils/errors.js");
26
+ const _genericsJs = require("../utils/generics.js");
27
+ const _pathsJs = require("../utils/paths.js");
28
+ const _problemsJs = require("./problems.js");
29
29
  function _checkPrivateRedeclaration(obj, privateCollection) {
30
30
  if (privateCollection.has(obj)) {
31
31
  throw new TypeError("Cannot initialize the same private elements twice on an object");
@@ -66,6 +66,19 @@ function _classPrivateFieldSet(receiver, privateMap, value) {
66
66
  _classApplyDescriptorSet(receiver, descriptor, value);
67
67
  return value;
68
68
  }
69
+ function _defineProperty(obj, key, value) {
70
+ if (key in obj) {
71
+ Object.defineProperty(obj, key, {
72
+ value: value,
73
+ enumerable: true,
74
+ configurable: true,
75
+ writable: true
76
+ });
77
+ } else {
78
+ obj[key] = value;
79
+ }
80
+ return obj;
81
+ }
69
82
  const initializeTraversalConfig = ()=>({
70
83
  mustBe: [],
71
84
  writeReason: [],
@@ -92,6 +105,10 @@ const traverseRoot = (t, data)=>{
92
105
  return result;
93
106
  };
94
107
  const CheckResult = class {
108
+ constructor(){
109
+ _defineProperty(this, "data", void 0);
110
+ _defineProperty(this, "problems", void 0);
111
+ }
95
112
  };
96
113
  var _seen = /*#__PURE__*/ new WeakMap();
97
114
  class TraversalState {
@@ -129,7 +146,7 @@ class TraversalState {
129
146
  const id = resolution.qualifiedName;
130
147
  // this assignment helps with narrowing
131
148
  const data = this.data;
132
- const isObject = (0, _domainsTs.hasDomain)(data, "object");
149
+ const isObject = (0, _domainsJs.hasDomain)(data, "object");
133
150
  if (isObject) {
134
151
  const seenByCurrentType = _classPrivateFieldGet(this, _seen)[id];
135
152
  if (seenByCurrentType) {
@@ -159,13 +176,13 @@ class TraversalState {
159
176
  const lastFailFast = this.failFast;
160
177
  this.failFast = true;
161
178
  const lastProblems = this.problems;
162
- const branchProblems = new _problemsTs.Problems(this);
179
+ const branchProblems = new _problemsJs.Problems(this);
163
180
  this.problems = branchProblems;
164
181
  const lastPath = this.path;
165
182
  const lastKeysToPrune = this.entriesToPrune;
166
183
  let hasValidBranch = false;
167
184
  for (const branch of branches){
168
- this.path = new _pathsTs.Path();
185
+ this.path = new _pathsJs.Path();
169
186
  this.entriesToPrune = [];
170
187
  if (checkEntries(branch, this)) {
171
188
  hasValidBranch = true;
@@ -180,14 +197,22 @@ class TraversalState {
180
197
  return hasValidBranch || !this.problems.add("branches", branchProblems);
181
198
  }
182
199
  constructor(data, type){
200
+ _defineProperty(this, "data", void 0);
201
+ _defineProperty(this, "type", void 0);
202
+ _defineProperty(this, "path", void 0);
203
+ _defineProperty(this, "problems", void 0);
204
+ _defineProperty(this, "entriesToPrune", void 0);
205
+ _defineProperty(this, "failFast", void 0);
206
+ _defineProperty(this, "traversalConfig", void 0);
207
+ _defineProperty(this, "rootScope", void 0);
183
208
  _classPrivateFieldInit(this, _seen, {
184
209
  writable: true,
185
210
  value: void 0
186
211
  });
187
212
  this.data = data;
188
213
  this.type = type;
189
- this.path = new _pathsTs.Path();
190
- this.problems = new _problemsTs.Problems(this);
214
+ this.path = new _pathsJs.Path();
215
+ this.problems = new _problemsJs.Problems(this);
191
216
  this.entriesToPrune = [];
192
217
  this.failFast = false;
193
218
  this.traversalConfig = initializeTraversalConfig();
@@ -195,7 +220,7 @@ class TraversalState {
195
220
  this.rootScope = type.scope;
196
221
  }
197
222
  }
198
- const traverse = (node, state)=>typeof node === "string" ? (0, _domainsTs.domainOf)(state.data) === node || !state.problems.add("domain", node) : checkEntries(node, state);
223
+ const traverse = (node, state)=>typeof node === "string" ? (0, _domainsJs.domainOf)(state.data) === node || !state.problems.add("domain", node) : checkEntries(node, state);
199
224
  const checkEntries = (entries, state)=>{
200
225
  let isValid = true;
201
226
  for(let i = 0; i < entries.length; i++){
@@ -206,7 +231,7 @@ const checkEntries = (entries, state)=>{
206
231
  if (state.failFast) {
207
232
  return false;
208
233
  }
209
- if (i < entries.length - 1 && _rulesTs.precedenceMap[k] < _rulesTs.precedenceMap[entries[i + 1][0]]) {
234
+ if (i < entries.length - 1 && _rulesJs.precedenceMap[k] < _rulesJs.precedenceMap[entries[i + 1][0]]) {
210
235
  // if we've encountered a problem, there is at least one entry
211
236
  // remaining, and the next entry is of a higher precedence level
212
237
  // than the current entry, return immediately
@@ -274,14 +299,14 @@ const createPropChecker = (kind)=>(props, state)=>{
274
299
  return isValid;
275
300
  };
276
301
  const entryCheckers = {
277
- regex: _regexTs.checkRegex,
278
- divisor: _divisorTs.checkDivisor,
302
+ regex: _regexJs.checkRegex,
303
+ divisor: _divisorJs.checkDivisor,
279
304
  domains: (domains, state)=>{
280
- const entries = domains[(0, _domainsTs.domainOf)(state.data)];
281
- return entries ? checkEntries(entries, state) : !state.problems.add("cases", (0, _problemsTs.domainsToDescriptions)((0, _genericsTs.objectKeysOf)(domains)));
305
+ const entries = domains[(0, _domainsJs.domainOf)(state.data)];
306
+ return entries ? checkEntries(entries, state) : !state.problems.add("cases", (0, _problemsJs.domainsToDescriptions)((0, _genericsJs.objectKeysOf)(domains)));
282
307
  },
283
- domain: (domain, state)=>(0, _domainsTs.domainOf)(state.data) === domain || !state.problems.add("domain", domain),
284
- bound: _rangeTs.checkBound,
308
+ domain: (domain, state)=>(0, _domainsJs.domainOf)(state.data) === domain || !state.problems.add("domain", domain),
309
+ bound: _rangeJs.checkBound,
285
310
  optionalProp: (prop, state)=>{
286
311
  if (prop[0] in state.data) {
287
312
  return state.traverseKey(prop[0], prop[1]);
@@ -299,7 +324,7 @@ const entryCheckers = {
299
324
  }
300
325
  let isValid = true;
301
326
  for(let i = 0; i < state.data.length; i++){
302
- isValid && (isValid = state.traverseKey(`${i}`, node));
327
+ isValid = state.traverseKey(`${i}`, node) && isValid;
303
328
  if (!isValid && state.failFast) {
304
329
  return false;
305
330
  }
@@ -308,14 +333,14 @@ const entryCheckers = {
308
333
  },
309
334
  branches: (branches, state)=>state.traverseBranches(branches),
310
335
  switch: (rule, state)=>{
311
- const dataAtPath = (0, _pathsTs.getPath)(state.data, rule.path);
312
- const caseKey = (0, _discriminateTs.serializeCase)(rule.kind, dataAtPath);
313
- if ((0, _genericsTs.hasKey)(rule.cases, caseKey)) {
336
+ const dataAtPath = (0, _pathsJs.getPath)(state.data, rule.path);
337
+ const caseKey = (0, _discriminateJs.serializeCase)(rule.kind, dataAtPath);
338
+ if ((0, _genericsJs.hasKey)(rule.cases, caseKey)) {
314
339
  return checkEntries(rule.cases[caseKey], state);
315
340
  }
316
- const caseKeys = (0, _genericsTs.objectKeysOf)(rule.cases);
341
+ const caseKeys = (0, _genericsJs.objectKeysOf)(rule.cases);
317
342
  const missingCasePath = state.path.concat(rule.path);
318
- const caseDescriptions = rule.kind === "value" ? caseKeys : rule.kind === "domain" ? (0, _problemsTs.domainsToDescriptions)(caseKeys) : rule.kind === "class" ? (0, _problemsTs.objectKindsToDescriptions)(caseKeys) : (0, _errorsTs.throwInternalError)(`Unexpectedly encountered rule kind '${rule.kind}' during traversal`);
343
+ const caseDescriptions = rule.kind === "value" ? caseKeys : rule.kind === "domain" ? (0, _problemsJs.domainsToDescriptions)(caseKeys) : rule.kind === "class" ? (0, _problemsJs.objectKindsToDescriptions)(caseKeys) : (0, _errorsJs.throwInternalError)(`Unexpectedly encountered rule kind '${rule.kind}' during traversal`);
319
344
  state.problems.add("cases", caseDescriptions, {
320
345
  path: missingCasePath,
321
346
  data: dataAtPath
@@ -323,7 +348,7 @@ const entryCheckers = {
323
348
  return false;
324
349
  },
325
350
  alias: (name, state)=>state.traverseResolution(name),
326
- class: _classTs.checkClass,
351
+ class: _classJs.checkClass,
327
352
  narrow: (narrow, state)=>{
328
353
  const lastProblemsCount = state.problems.count;
329
354
  const result = narrow(state.data, state.problems);
@@ -339,7 +364,7 @@ const entryCheckers = {
339
364
  if (state.problems.length) {
340
365
  return false;
341
366
  }
342
- if (out instanceof _problemsTs.Problem) {
367
+ if (out instanceof _problemsJs.Problem) {
343
368
  // if a problem was returned from the morph but not added, add it
344
369
  state.problems.addProblem(out);
345
370
  return false;
@@ -13,16 +13,29 @@ _export(exports, {
13
13
  unitsOf: ()=>unitsOf,
14
14
  DataWrapper: ()=>DataWrapper
15
15
  });
16
- const _domainsTs = require("./domains.js");
17
- const _serializeTs = require("./serialize.js");
16
+ const _domainsJs = require("./domains.js");
17
+ const _serializeJs = require("./serialize.js");
18
+ function _defineProperty(obj, key, value) {
19
+ if (key in obj) {
20
+ Object.defineProperty(obj, key, {
21
+ value: value,
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true
25
+ });
26
+ } else {
27
+ obj[key] = value;
28
+ }
29
+ return obj;
30
+ }
18
31
  const sizeOf = (data)=>typeof data === "string" || Array.isArray(data) ? data.length : typeof data === "number" ? data : 0;
19
32
  const unitsOf = (data)=>typeof data === "string" ? "characters" : Array.isArray(data) ? "items long" : "";
20
33
  class DataWrapper {
21
34
  toString() {
22
- return (0, _serializeTs.stringify)(this.value);
35
+ return (0, _serializeJs.stringify)(this.value);
23
36
  }
24
37
  get domain() {
25
- return (0, _domainsTs.domainOf)(this.value);
38
+ return (0, _domainsJs.domainOf)(this.value);
26
39
  }
27
40
  get size() {
28
41
  return sizeOf(this.value);
@@ -34,6 +47,7 @@ class DataWrapper {
34
47
  return Object(this.value).constructor.name;
35
48
  }
36
49
  constructor(value){
50
+ _defineProperty(this, "value", void 0);
37
51
  this.value = value;
38
52
  }
39
53
  }
@@ -23,7 +23,7 @@ _export(exports, {
23
23
  hasNominalId: ()=>hasNominalId,
24
24
  listFrom: ()=>listFrom
25
25
  });
26
- const _domainsTs = require("./domains.js");
26
+ const _domainsJs = require("./domains.js");
27
27
  const asConst = (t)=>t;
28
28
  const isKeyOf = (k, obj)=>k in obj;
29
29
  const entriesOf = (o)=>Object.entries(o);
@@ -51,12 +51,12 @@ const hasKey = (o, k)=>{
51
51
  };
52
52
  const hasSingleKey = (o, k)=>k in o && Object.keys(o).length === 1;
53
53
  const keyCount = (o)=>Object.keys(o).length;
54
- const hasKeys = (value)=>(0, _domainsTs.hasDomain)(value, "object") ? Object.keys(value).length !== 0 : false;
54
+ const hasKeys = (value)=>(0, _domainsJs.hasDomain)(value, "object") ? Object.keys(value).length !== 0 : false;
55
55
  const id = Symbol("id");
56
56
  const nominal = (o, name)=>Object.assign(o, {
57
57
  [id]: name
58
58
  });
59
- const getNominalId = (data)=>(0, _domainsTs.hasDomain)(data, "object") && id in data ? data[id] : undefined;
59
+ const getNominalId = (data)=>(0, _domainsJs.hasDomain)(data, "object") && id in data ? data[id] : undefined;
60
60
  const hasNominalId = (data, name)=>getNominalId(data) === name;
61
61
  const listFrom = (data)=>Array.isArray(data) ? data : [
62
62
  data
@@ -18,7 +18,7 @@ _export(exports, {
18
18
  tryParseWellFormedInteger: ()=>tryParseWellFormedInteger,
19
19
  tryParseWellFormedBigint: ()=>tryParseWellFormedBigint
20
20
  });
21
- const _errorsTs = require("./errors.js");
21
+ const _errorsJs = require("./errors.js");
22
22
  const wellFormedNumberMatcher = /^(?!^-0$)-?(?:0|[1-9]\d*)(?:\.\d*[1-9])?$/;
23
23
  const isWellFormedNumber = (s)=>wellFormedNumberMatcher.test(s);
24
24
  const numberLikeMatcher = /^-?\d*\.?\d*$/;
@@ -48,10 +48,10 @@ const parseWellFormed = (token, kind, errorOnFail)=>{
48
48
  if (isKindLike(token, kind)) {
49
49
  // If the definition looks like the correct numeric kind but is
50
50
  // not well-formed, always throw.
51
- return (0, _errorsTs.throwParseError)(writeMalformedNumericLiteralMessage(token, kind));
51
+ return (0, _errorsJs.throwParseError)(writeMalformedNumericLiteralMessage(token, kind));
52
52
  }
53
53
  }
54
- return errorOnFail ? (0, _errorsTs.throwParseError)(errorOnFail === true ? `Failed to parse ${numericLiteralDescriptions[kind]} from '${token}'` : errorOnFail) : undefined;
54
+ return errorOnFail ? (0, _errorsJs.throwParseError)(errorOnFail === true ? `Failed to parse ${numericLiteralDescriptions[kind]} from '${token}'` : errorOnFail) : undefined;
55
55
  };
56
56
  const tryParseWellFormedBigint = (def)=>{
57
57
  if (def[def.length - 1] !== "n") {
@@ -70,6 +70,6 @@ const tryParseWellFormedBigint = (def)=>{
70
70
  if (integerLikeMatcher.test(maybeIntegerLiteral)) {
71
71
  // If the definition looks like a bigint but is
72
72
  // not well-formed, throw.
73
- return (0, _errorsTs.throwParseError)(writeMalformedNumericLiteralMessage(def, "bigint"));
73
+ return (0, _errorsJs.throwParseError)(writeMalformedNumericLiteralMessage(def, "bigint"));
74
74
  }
75
75
  };
@@ -16,8 +16,8 @@ _export(exports, {
16
16
  objectKindDescriptions: ()=>objectKindDescriptions,
17
17
  getExactConstructorObjectKind: ()=>getExactConstructorObjectKind
18
18
  });
19
- const _domainsTs = require("./domains.js");
20
- const _genericsTs = require("./generics.js");
19
+ const _domainsJs = require("./domains.js");
20
+ const _genericsJs = require("./generics.js");
21
21
  const defaultObjectKinds = {
22
22
  Array,
23
23
  Date,
@@ -35,7 +35,7 @@ const defaultObjectKinds = {
35
35
  Promise
36
36
  };
37
37
  const objectKindOf = (data, kinds)=>{
38
- if ((0, _domainsTs.domainOf)(data) !== "object") {
38
+ if ((0, _domainsJs.domainOf)(data) !== "object") {
39
39
  return undefined;
40
40
  }
41
41
  const kindSet = kinds ?? defaultObjectKinds;
@@ -65,5 +65,5 @@ const objectKindDescriptions = {
65
65
  };
66
66
  const getExactConstructorObjectKind = (constructor)=>{
67
67
  const constructorName = Object(constructor).name;
68
- return constructorName && (0, _genericsTs.isKeyOf)(constructorName, defaultObjectKinds) && defaultObjectKinds[constructorName] === constructor ? constructorName : undefined;
68
+ return constructorName && (0, _genericsJs.isKeyOf)(constructorName, defaultObjectKinds) && defaultObjectKinds[constructorName] === constructor ? constructorName : undefined;
69
69
  };
@@ -14,12 +14,12 @@ _export(exports, {
14
14
  serializePrimitive: ()=>serializePrimitive,
15
15
  deserializePrimitive: ()=>deserializePrimitive
16
16
  });
17
- const _domainsTs = require("./domains.js");
18
- const _genericsTs = require("./generics.js");
19
- const _numericLiteralsTs = require("./numericLiterals.js");
17
+ const _domainsJs = require("./domains.js");
18
+ const _genericsJs = require("./generics.js");
19
+ const _numericLiteralsJs = require("./numericLiterals.js");
20
20
  const snapshot = (data, opts = {})=>serializeRecurse(data, opts, []);
21
21
  const stringify = (data, indent)=>{
22
- switch((0, _domainsTs.domainOf)(data)){
22
+ switch((0, _domainsJs.domainOf)(data)){
23
23
  case "object":
24
24
  return JSON.stringify(serializeRecurse(data, stringifyOpts, []), null, indent);
25
25
  case "symbol":
@@ -34,7 +34,7 @@ const stringifyOpts = {
34
34
  onFunction: (v)=>`(function${v.name && ` ${v.name}`})`
35
35
  };
36
36
  const serializeRecurse = (data, context, seen)=>{
37
- switch((0, _domainsTs.domainOf)(data)){
37
+ switch((0, _domainsJs.domainOf)(data)){
38
38
  case "object":
39
39
  if (typeof data === "function") {
40
40
  return stringifyOpts.onFunction(data);
@@ -65,7 +65,7 @@ const serializeRecurse = (data, context, seen)=>{
65
65
  }
66
66
  };
67
67
  const serializePrimitive = (value)=>typeof value === "string" ? `'${value}'` : typeof value === "bigint" ? `${value}n` : `${value}`;
68
- const deserializePrimitive = (serialized)=>(0, _genericsTs.isKeyOf)(serialized, serializedKeywords) ? serializedKeywords[serialized] : serialized[0] === "'" ? serialized.slice(1, -1) : (0, _numericLiteralsTs.tryParseWellFormedBigint)(serialized) ?? (0, _numericLiteralsTs.tryParseWellFormedNumber)(serialized, true);
68
+ const deserializePrimitive = (serialized)=>(0, _genericsJs.isKeyOf)(serialized, serializedKeywords) ? serializedKeywords[serialized] : serialized[0] === "'" ? serialized.slice(1, -1) : (0, _numericLiteralsJs.tryParseWellFormedBigint)(serialized) ?? (0, _numericLiteralsJs.tryParseWellFormedNumber)(serialized, true);
69
69
  const serializedKeywords = {
70
70
  true: true,
71
71
  false: false,
package/dist/mjs/main.js CHANGED
@@ -1,7 +1,8 @@
1
1
  export { scope } from "./scopes/scope.js";
2
2
  export { type, ark, arkScope } from "./scopes/ark.js";
3
- export { intersection, union, arrayOf, instanceOf, valueOf, morph, narrow, keyOf } from "./scopes/expressions.js";
3
+ export { arrayOf, instanceOf, intersection, keyOf, morph, narrow, union, valueOf } from "./scopes/expressions.js";
4
4
  export { jsObjectsScope } from "./scopes/jsObjects.js";
5
5
  export { tsKeywordsScope } from "./scopes/tsKeywords.js";
6
6
  export { validationScope } from "./scopes/validation/validation.js";
7
7
  export { Problems, Problem } from "./traverse/problems.js";
8
+ export { parseConfigTuple } from "./parse/ast/config.js";
@@ -38,6 +38,19 @@ function _classPrivateFieldSet(receiver, privateMap, value) {
38
38
  _classApplyDescriptorSet(receiver, descriptor, value);
39
39
  return value;
40
40
  }
41
+ function _defineProperty(obj, key, value) {
42
+ if (key in obj) {
43
+ Object.defineProperty(obj, key, {
44
+ value: value,
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true
48
+ });
49
+ } else {
50
+ obj[key] = value;
51
+ }
52
+ return obj;
53
+ }
41
54
  import { throwInternalError } from "../utils/errors.js";
42
55
  import { objectKeysOf } from "../utils/generics.js";
43
56
  import { Path } from "../utils/paths.js";
@@ -69,6 +82,10 @@ export class IntersectionState {
69
82
  return empty;
70
83
  }
71
84
  constructor(type, lastOperator){
85
+ _defineProperty(this, "type", void 0);
86
+ _defineProperty(this, "lastOperator", void 0);
87
+ _defineProperty(this, "path", void 0);
88
+ _defineProperty(this, "domain", void 0);
72
89
  _classPrivateFieldInit(this, _disjoints, {
73
90
  writable: true,
74
91
  value: void 0
@@ -1,5 +1,9 @@
1
1
  import { parseDefinition } from "../definition.js";
2
- export const parseConfigTuple = (def, ctx)=>({
2
+ /**
3
+ * @operator {@link parseConfigTuple | :}
4
+ * @docgenTable
5
+ * @tuple ["type", ":", config]
6
+ */ export const parseConfigTuple = (def, ctx)=>({
3
7
  node: ctx.type.scope.resolveTypeNode(parseDefinition(def[0], ctx)),
4
8
  config: def[2]
5
9
  });
@@ -1,4 +1,3 @@
1
- var _keyNode, _keyType, _keyNode1, _keyNode2;
2
1
  import { mappedKeys } from "../../nodes/rules/props.js";
3
2
  import { throwInternalError } from "../../utils/errors.js";
4
3
  import { deepFreeze } from "../../utils/freeze.js";
@@ -31,11 +30,13 @@ export const parseKeyOfTuple = (def, ctx)=>{
31
30
  for (const key of sharedKeys){
32
31
  const keyType = typeof key;
33
32
  if (keyType === "string" || keyType === "number" || keyType === "symbol") {
33
+ var _keyNode, _keyType;
34
34
  (_keyNode = keyNode)[_keyType = keyType] ?? (_keyNode[_keyType] = []);
35
35
  keyNode[keyType].push({
36
36
  value: key
37
37
  });
38
38
  } else if (key === wellFormedNonNegativeIntegerMatcher) {
39
+ var _keyNode1, _keyNode2;
39
40
  (_keyNode1 = keyNode).string ?? (_keyNode1.string = []);
40
41
  keyNode.string.push(arrayIndexStringBranch);
41
42
  (_keyNode2 = keyNode).number ?? (_keyNode2.number = []);
@@ -42,6 +42,5 @@ export const parseDefinition = (def, ctx)=>{
42
42
  }
43
43
  };
44
44
  export const as = Symbol("as");
45
- export const unknownDefinitionMessage = "Cannot statically parse a definition inferred as unknown. Consider using 'as Infer<...>' to cast it.";
46
45
  const isThunk = (def)=>typeof def === "function" && def.length === 0;
47
46
  export const writeBadDefinitionTypeMessage = (actual)=>`Type definitions must be strings or objects (was ${actual})`;
@@ -1,3 +1,16 @@
1
+ function _defineProperty(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
1
14
  import { isLiteralNode, rootIntersection, rootUnion, toArrayNode } from "../../../nodes/node.js";
2
15
  import { minComparators } from "../../../nodes/rules/range.js";
3
16
  import { throwInternalError, throwParseError } from "../../../utils/errors.js";
@@ -130,6 +143,11 @@ export class DynamicState {
130
143
  return this;
131
144
  }
132
145
  constructor(def, ctx){
146
+ _defineProperty(this, "ctx", void 0);
147
+ _defineProperty(this, "scanner", void 0);
148
+ _defineProperty(this, "root", void 0);
149
+ _defineProperty(this, "branches", void 0);
150
+ _defineProperty(this, "groups", void 0);
133
151
  this.ctx = ctx;
134
152
  this.branches = {};
135
153
  this.groups = [];
@@ -1,3 +1,16 @@
1
+ function _defineProperty(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
1
14
  export class Scanner {
2
15
  /** Get lookahead and advance scanner by one */ shift() {
3
16
  return this.chars[this.i++] ?? "";
@@ -33,7 +46,9 @@ export class Scanner {
33
46
  return this.lookahead in tokens;
34
47
  }
35
48
  constructor(def){
36
- this.finalized = false;
49
+ _defineProperty(this, "chars", void 0);
50
+ _defineProperty(this, "i", void 0);
51
+ _defineProperty(this, "finalized", false);
37
52
  this.chars = [
38
53
  ...def
39
54
  ];
@@ -1,3 +1,16 @@
1
+ function _defineProperty(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
1
14
  import { deepFreeze } from "../utils/freeze.js";
2
15
  export class Cache {
3
16
  get root() {
@@ -14,7 +27,7 @@ export class Cache {
14
27
  return item;
15
28
  }
16
29
  constructor(){
17
- this.cache = {};
30
+ _defineProperty(this, "cache", {});
18
31
  }
19
32
  }
20
33
  export class FreezingCache extends Cache {
@@ -1,9 +1,89 @@
1
1
  import { scopes } from "./ark.js";
2
- export const intersection = scopes.ark.intersection;
3
- export const union = scopes.ark.union;
4
- export const arrayOf = scopes.ark.arrayOf;
5
- export const keyOf = scopes.ark.keyOf;
6
- export const instanceOf = scopes.ark.instanceOf;
7
- export const valueOf = scopes.ark.valueOf;
8
- export const narrow = scopes.ark.narrow;
9
- export const morph = scopes.ark.morph;
2
+ /**
3
+ * @operator {@link intersection | &}
4
+ * @docgenTable
5
+ * @string "L&R"
6
+ * @tuple [L, "&", R]
7
+ * @helper intersection(L,R)
8
+ * @example string
9
+ * const intersection = type("/@arktype\.io$/ & email")
10
+ * @example tuple
11
+ * const tupleIntersection = type(["/@arktype\.io$/", "&", "email"])
12
+ * @example helper
13
+ * const helperIntersection = intersection("/@arktype\.io$/","email")
14
+ */ export const intersection = scopes.ark.intersection;
15
+ /**
16
+ * @operator {@link union | |}
17
+ * @docgenTable
18
+ * @string "L|R"
19
+ * @tuple [L, "|" , R]
20
+ * @helper union(L,R)
21
+ * @example string
22
+ * const union = type("string|number")
23
+ * @example tuple
24
+ * const tupleUnion = type(["string", "|", "number"])
25
+ * @example helper
26
+ * const helperUnion = union("string", "number")
27
+ */ export const union = scopes.ark.union;
28
+ /**
29
+ * @operator {@link arrayOf}
30
+ * @docgenTable
31
+ * @string "T[]"
32
+ * @tuple [T, "[]"]
33
+ * @helper arrayOf(T)
34
+ * @example string
35
+ * const numberArray = type("number[]")
36
+ * @example tuple
37
+ * const tupleArray = type(["number", "[]"])
38
+ * @example helper
39
+ * const helperArray = arrayOf("number")
40
+ */ export const arrayOf = scopes.ark.arrayOf;
41
+ /**
42
+ * @operator {@link keyOf}
43
+ * @docgenTable
44
+ * @tuple "["keyOf", T]"
45
+ * @helper keyOf(T)
46
+ * @example tuple
47
+ * const tupleKeyOf = type(["keyOf", {a:"string"}])
48
+ * @example helper
49
+ * const helperKeyOf = keyOf({a:"string"})
50
+ */ export const keyOf = scopes.ark.keyOf;
51
+ /**
52
+ * @operator {@link instanceOf}
53
+ * @docgenTable
54
+ * @tuple ["instanceOf", T]
55
+ * @helper instanceOf(T)
56
+ * @example tuple
57
+ * const tupleInstanceOf = type(["instanceOf", Date])
58
+ * @example helper
59
+ * const helperInstanceOf = instanceOf(Date)
60
+ */ export const instanceOf = scopes.ark.instanceOf;
61
+ /**
62
+ * @operator {@link valueOf | ===}
63
+ * @docgenTable
64
+ * @tuple ["===", T]
65
+ * @helper valueOf(T)
66
+ * @example tuple
67
+ * const tupleValueOf = type(["valueOf", {a:"string"}])
68
+ * @example helper
69
+ * const helperValueOf = valueOf({a:"string"})
70
+ */ export const valueOf = scopes.ark.valueOf;
71
+ /**
72
+ * @operator {@link narrow | =>}
73
+ * @docgenTable
74
+ * @tuple ["type", "=>" , condition]
75
+ * @example tuple
76
+ * const narrow = type( ["number", "=>" , (n) => n % 2 === 0])
77
+ * @example
78
+ * const isEven = (x: unknown): x is number => x % 2 === 0
79
+ */ export const narrow = scopes.ark.narrow;
80
+ /**
81
+ * @operator {@link morph | |>}
82
+ * @docgenTable
83
+ * @tuple [inputType, "|>", (data) => output]
84
+ * @helper morph(inputType, (data) => output)
85
+ * @example tuple
86
+ * const tupleMorph = type( ["string", "|>" , (data) => `morphed ${data}`])
87
+ * @example helper
88
+ * const helperMorph = morph("string", (data) => `morphed ${data}`)
89
+ */ export const morph = scopes.ark.morph;