arktype 3.0.0-beta.2 → 3.0.0-rc.1

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 (100) hide show
  1. package/README.md +55 -20
  2. package/out/_internal/regex/quantify.d.ts +17 -1
  3. package/out/_internal/schema/refinements/range.d.ts +2 -1
  4. package/out/_internal/schema/roots/domain.d.ts +1 -0
  5. package/out/_internal/schema/roots/root.d.ts +3 -1
  6. package/out/_internal/schema/roots/union.d.ts +8 -3
  7. package/out/_internal/schema/shared/compile.d.ts +2 -0
  8. package/out/_internal/schema/shared/declare.d.ts +9 -6
  9. package/out/_internal/schema/shared/errors.d.ts +3 -0
  10. package/out/_internal/schema/shared/issues.d.ts +5 -1
  11. package/out/_internal/schema/shared/issuesLean.d.ts +4 -0
  12. package/out/_internal/schema/shared/issuesNone.d.ts +1 -0
  13. package/out/_internal/schema/shared/issuesNoneLean.d.ts +1 -0
  14. package/out/_internal/schema/shared/standardFailure.d.ts +1 -0
  15. package/out/_internal/schema/shared/toJsonSchema.d.ts +16 -3
  16. package/out/_internal/schema/shared/transform.d.ts +1 -0
  17. package/out/_internal/sets/constraint.d.ts +2 -0
  18. package/out/_internal/sets/fromJsonSchema.d.ts +3 -1
  19. package/out/_internal/util/registry.d.ts +1 -1
  20. package/out/attributes.d.ts +12 -8
  21. package/out/chunk-2FVJ5JBN.js +161 -0
  22. package/out/{chunk-QBX4MEQR.js → chunk-3HZC67MT.js} +15 -15
  23. package/out/{chunk-5TN5JRP7.js → chunk-3KBOPH3J.js} +63 -41
  24. package/out/{chunk-GPNWBJL3.js → chunk-3WYMLH45.js} +17 -11
  25. package/out/{chunk-NIZDOWFU.js → chunk-46PLKNON.js} +2 -2
  26. package/out/{chunk-7JXN4WJX.js → chunk-4FTHWK63.js} +1 -1
  27. package/out/{chunk-EA2DNEDI.js → chunk-4HREHNIV.js} +12 -12
  28. package/out/{chunk-ZFB6DQWY.js → chunk-4J7H2ELX.js} +6 -11
  29. package/out/{chunk-7SVIUP6X.js → chunk-4MUH2MO4.js} +2 -2
  30. package/out/{chunk-J7CKAEDX.js → chunk-4NZCLVBD.js} +1 -1
  31. package/out/{chunk-RAM6G3F6.js → chunk-54U3D6OV.js} +26 -25
  32. package/out/{chunk-HA3POWOU.js → chunk-5FNHK7CC.js} +6 -5
  33. package/out/{chunk-KVQCLBJR.js → chunk-7SUZFAHZ.js} +241 -66
  34. package/out/{chunk-YMYPW3L5.js → chunk-AMNHRY72.js} +3 -3
  35. package/out/{chunk-UH6XKS3C.js → chunk-BQR65UPE.js} +30 -9
  36. package/out/{chunk-V4TZHFNK.js → chunk-BWKJV74G.js} +1 -1
  37. package/out/{chunk-7N3JEHA4.js → chunk-CXHXN7DF.js} +1 -1
  38. package/out/{chunk-FY4M7GE7.js → chunk-E4OQHHFS.js} +4 -4
  39. package/out/{chunk-CGWRW4JZ.js → chunk-ERGIJZFA.js} +4 -4
  40. package/out/{chunk-OA5Q2JLI.js → chunk-H44UG6HG.js} +8 -4
  41. package/out/{chunk-A7A6FDBS.js → chunk-I65VSWGS.js} +50 -44
  42. package/out/{chunk-C5JGK6GT.js → chunk-J2BFVWVY.js} +20 -3
  43. package/out/{chunk-W77ROLOT.js → chunk-JIILWIU4.js} +1 -1
  44. package/out/{chunk-5WRZ25AB.js → chunk-LMUBBBHJ.js} +4 -4
  45. package/out/{chunk-CQU7WIIR.js → chunk-P3HEEGB5.js} +6 -6
  46. package/out/{chunk-JZ4KBCMM.js → chunk-RKJNLXEQ.js} +21 -13
  47. package/out/{chunk-XMEK4I7J.js → chunk-TM22D5DL.js} +887 -266
  48. package/out/{chunk-PIFOURNM.js → chunk-TQYLOZRT.js} +11 -4
  49. package/out/{chunk-YN3XRJ7H.js → chunk-UJJGG4VQ.js} +1 -1
  50. package/out/{chunk-NIYAI7AF.js → chunk-US6BWOGJ.js} +3 -3
  51. package/out/{chunk-57LF5Y5P.js → chunk-W2XOI5DY.js} +1 -1
  52. package/out/{chunk-KDMHK4KP.js → chunk-XVLEFUSY.js} +2 -2
  53. package/out/{chunk-SGFGLENC.js → chunk-YPN67JMD.js} +3 -3
  54. package/out/cli.d.ts +5 -1
  55. package/out/cli.js +301 -49
  56. package/out/codecs.d.ts +4 -3
  57. package/out/codecs.js +18 -18
  58. package/out/config.js +8 -8
  59. package/out/declare.d.ts +2 -4
  60. package/out/errors.js +8 -8
  61. package/out/fn.d.ts +2 -2
  62. package/out/fromJsonSchema.d.ts +1 -1
  63. package/out/generic.d.ts +7 -4
  64. package/out/i18n.js +5 -5
  65. package/out/index.js +19 -19
  66. package/out/internal.js +32 -32
  67. package/out/island.js +18 -18
  68. package/out/islandDependency.js +33 -33
  69. package/out/jsonSchema/infer.d.ts +16 -6
  70. package/out/jsonSchema/validate.d.ts +16 -4
  71. package/out/keywords/functions.d.ts +4 -169
  72. package/out/keywords/keywords.d.ts +1 -1
  73. package/out/keywords/phrases.d.ts +3 -168
  74. package/out/keywords/ts.js +14 -14
  75. package/out/locales/de.js +6 -6
  76. package/out/locales/en.js +15 -15
  77. package/out/match.d.ts +12 -9
  78. package/out/mutatesInput.js +14 -14
  79. package/out/nary.d.ts +219 -193
  80. package/out/parser/definition.d.ts +2 -2
  81. package/out/parser/shift/operator/default.d.ts +2 -2
  82. package/out/parser/tupleExpressions.d.ts +2 -0
  83. package/out/precompiled.js +11 -11
  84. package/out/runtime.d.ts +1 -1
  85. package/out/runtime.js +5 -5
  86. package/out/schema.js +11 -11
  87. package/out/schemaInternal.js +29 -17
  88. package/out/schemaRuntime.js +4 -4
  89. package/out/schemaRuntimeLean.js +60 -36
  90. package/out/schemaRuntimeNone.js +52 -31
  91. package/out/schemaRuntimeNoneLean.js +52 -31
  92. package/out/type.d.ts +3 -3
  93. package/out/util.js +14 -11
  94. package/out/variants/base.d.ts +9 -8
  95. package/out/variants/object.d.ts +14 -6
  96. package/package.json +4 -4
  97. package/skills/arktype/SKILL.md +17 -17
  98. package/skills/arktype/references/migrating.md +13 -13
  99. package/skills/arktype/references/precompile.md +4 -4
  100. package/out/chunk-CSVAPWDE.js +0 -83
@@ -140,7 +140,7 @@ var objectKindOf = (data) => {
140
140
  if (prototype === Object.prototype)
141
141
  return void 0;
142
142
  const constructors = builtinsOf();
143
- while (prototype?.constructor && (!isKeyOf(prototype.constructor.name, constructors) || constructors[prototype.constructor.name]?.prototype !== prototype))
143
+ while (prototype?.constructor && (!hasOwn(constructors, prototype.constructor.name) || constructors[prototype.constructor.name]?.prototype !== prototype))
144
144
  prototype = Object.getPrototypeOf(prototype);
145
145
  const name = prototype?.constructor?.name;
146
146
  if (name === void 0 || name === "Object")
@@ -251,9 +251,9 @@ var _serialize = (data, opts, seen) => {
251
251
  if (toJson)
252
252
  return Reflect.apply(toJson, o, []);
253
253
  if (typeof o === "function")
254
- return printableOpts.onFunction(o);
254
+ return opts.onFunction?.(o) ?? printableOpts.onFunction(o);
255
255
  if (seen.includes(o))
256
- return "(cycle)";
256
+ return opts.onCycle?.(o) ?? "(cycle)";
257
257
  const nextSeen = [...seen, o];
258
258
  if (isArray(o))
259
259
  return o.map((item) => _serialize(item, opts, nextSeen));
@@ -261,12 +261,13 @@ var _serialize = (data, opts, seen) => {
261
261
  return o.toDateString();
262
262
  const result = {};
263
263
  for (const [k, v] of ownEntriesOf(o, opts)) {
264
- result[typeof k === "symbol" ? opts.onSymbol?.(k) ?? k.toString() : k] = _serialize(v, opts, nextSeen);
264
+ const key = typeof k === "symbol" ? opts.onSymbol?.(k) ?? k.toString() : k;
265
+ defineValue(result, key, _serialize(v, opts, nextSeen));
265
266
  }
266
267
  return result;
267
268
  }
268
269
  case "symbol":
269
- return printableOpts.onSymbol(data);
270
+ return opts.onSymbol?.(data) ?? printableOpts.onSymbol(data);
270
271
  case "bigint":
271
272
  return opts.onBigInt?.(data) ?? `${data}n`;
272
273
  case "undefined":
@@ -278,6 +279,8 @@ var _serialize = (data, opts, seen) => {
278
279
  }
279
280
  };
280
281
  var describeCollapsibleDate = (date) => {
282
+ if (!isValidDate(date))
283
+ return "Invalid Date";
281
284
  const year = date.getUTCFullYear();
282
285
  const month = date.getUTCMonth();
283
286
  const dayOfMonth = date.getUTCDate();
@@ -476,11 +479,18 @@ var ArkErrors = class {
476
479
  return this._.length;
477
480
  }
478
481
  get issues() {
479
- return this._.reduce((issues, issue) => (issue.message ??= "is invalid", issues), this._);
482
+ for (const issue of this._) {
483
+ issue.expected ??= "valid";
484
+ issue.message ??= "is invalid";
485
+ }
486
+ return this._.toJSON ? this._ : Object.defineProperty(this._, "toJSON", issuesToJson);
480
487
  }
481
488
  get summary() {
482
489
  return this._.reduce((summary, issue) => summary + (summary && "\n") + lineOf(issue), "");
483
490
  }
491
+ summaryIn() {
492
+ return this.summary;
493
+ }
484
494
  // as issues.ts's: constructed by TraversalError wherever its bundle keeps
485
495
  // the class, and otherwise an Error with the same name, message and errors
486
496
  throw() {
@@ -495,11 +505,7 @@ var ArkErrors = class {
495
505
  // what it says and where, never its data, which may be private, a bigint
496
506
  // or circular
497
507
  toJSON() {
498
- return this.issues.map(({ code, path, message }) => ({
499
- code,
500
- path: path.map((k) => typeof k === "symbol" ? String(k) : k),
501
- message
502
- }));
508
+ return this.issues.map(jsonIssueOf);
503
509
  }
504
510
  toString() {
505
511
  return this.summary;
@@ -508,6 +514,19 @@ var ArkErrors = class {
508
514
  return this.issues[Symbol.iterator]();
509
515
  }
510
516
  };
517
+ var jsonIssueOf = ({ code, path, expected, message }) => ({
518
+ code,
519
+ path: path.map((k) => typeof k === "symbol" ? String(k) : k),
520
+ ...expected !== void 0 && { expected },
521
+ message
522
+ });
523
+ var issuesToJson = {
524
+ value() {
525
+ return this.map(jsonIssueOf);
526
+ },
527
+ writable: true,
528
+ configurable: true
529
+ };
511
530
  var definedThrown;
512
531
  var ThrownErrors = /* @__PURE__ */ (() => definedThrown = class TraversalError extends Error {
513
532
  constructor(errors) {
@@ -711,9 +730,15 @@ var copyOf = (data) => {
711
730
  return { ...data };
712
731
  return Object.prototype.toString.call(data) === "[object Object]" ? Object.setPrototypeOf({ ...data }, prototype) : data;
713
732
  };
733
+ var setOwnValue = (out, k, value) => {
734
+ if (k === "__proto__")
735
+ defineValue(out, k, value);
736
+ else
737
+ out[k] = value;
738
+ };
714
739
  var keepOwn = (out, data, k) => {
715
740
  if (!(k in out) && hasOwn(data, k))
716
- out[k] = data[k];
741
+ setOwnValue(out, k, data[k]);
717
742
  };
718
743
  var copyDeclared = (data, declared, changes) => {
719
744
  "use strict";
@@ -724,7 +749,7 @@ var copyDeclared = (data, declared, changes) => {
724
749
  continue;
725
750
  if (out === data)
726
751
  out = copyOf(data);
727
- out[changes[i]] = changes[i + 2];
752
+ setOwnValue(out, changes[i], changes[i + 2]);
728
753
  }
729
754
  if (out !== data)
730
755
  for (const k of declared)
@@ -753,7 +778,7 @@ var mergeTransformed = (input, l, r) => {
753
778
  delete merged[k];
754
779
  for (const k in r) {
755
780
  if (!(k in input) || !Object.is(r[k], input[k]))
756
- merged[k] = r[k];
781
+ setOwnValue(merged, k, r[k]);
757
782
  }
758
783
  return merged;
759
784
  };
@@ -976,11 +1001,9 @@ var Traversal = class extends InternalTraversal {
976
1001
  // a code of its own is written without what its rule describes
977
1002
  expected: supplied.expected ?? supplied.description ?? (code === "predicate" || supplied.morph ? describePredicate(supplied) : "valid")
978
1003
  };
979
- if (supplied.message !== void 0) {
1004
+ if (supplied.message !== void 0)
980
1005
  issue.message = supplied.message;
981
- if (supplied.message === "is invalid" && supplied.expected === "valid")
982
- issue.expected = void 0;
983
- } else if (supplied.cause !== void 0 && (supplied.meta?.keyword || supplied.morph)) {
1006
+ else if (supplied.cause !== void 0 && supplied.morph) {
984
1007
  try {
985
1008
  issue.message = `must be ${issue.expected} (${String(supplied.cause)})`;
986
1009
  } catch {
@@ -1496,33 +1519,30 @@ var travKey = (key, fn, ctx) => {
1496
1519
  };
1497
1520
  var computeDefaultValueMorph = (key, value, defaultInput, node = value, isThunkInput = isThunk(defaultInput)) => {
1498
1521
  const thunk = isThunkInput ? defaultInput : void 0;
1499
- if (!thunk && !node.alters && !node.hasAlias) {
1500
- return (data) => {
1501
- data[key] = defaultInput;
1502
- return data;
1503
- };
1504
- }
1522
+ const write = (data, v) => {
1523
+ setOwnValue(data, key, v);
1524
+ return data;
1525
+ };
1526
+ if (!thunk && !node.alters && !node.hasAlias)
1527
+ return (data) => write(data, defaultInput);
1505
1528
  if (!node.allowsCtx && !node.ctxMorph) {
1506
1529
  return (data) => {
1507
1530
  const input = thunk ? thunk() : defaultInput;
1508
1531
  const output = value.traverse(input);
1509
1532
  if (output instanceof ArkErrors)
1510
1533
  return new TransformErrors(output, input).addTo(void 0, key);
1511
- data[key] = output;
1512
- return data;
1534
+ return write(data, output);
1513
1535
  };
1514
1536
  }
1515
1537
  let transformingDefault = false;
1516
1538
  return (data, ctx) => {
1517
1539
  if (transformingDefault)
1518
1540
  return data;
1519
- if (!thunk && !node.tfs) {
1520
- data[key] = defaultInput;
1521
- return data;
1522
- }
1541
+ if (!thunk && !node.tfs)
1542
+ return write(data, defaultInput);
1523
1543
  transformingDefault = true;
1524
1544
  try {
1525
- data[key] = travKey(key, () => value(thunk ? thunk() : defaultInput, ctx), ctx);
1545
+ write(data, travKey(key, () => value(thunk ? thunk() : defaultInput, ctx), ctx));
1526
1546
  } finally {
1527
1547
  transformingDefault = false;
1528
1548
  }
@@ -1719,6 +1739,7 @@ export {
1719
1739
  rejects,
1720
1740
  runtimeConfig,
1721
1741
  runtimeScope,
1742
+ setOwnValue,
1722
1743
  shareConfig,
1723
1744
  sharedMessageOf,
1724
1745
  silentCtx,
@@ -139,7 +139,7 @@ var objectKindOf = (data) => {
139
139
  if (prototype === Object.prototype)
140
140
  return void 0;
141
141
  const constructors = builtinsOf();
142
- while (prototype?.constructor && (!isKeyOf(prototype.constructor.name, constructors) || constructors[prototype.constructor.name]?.prototype !== prototype))
142
+ while (prototype?.constructor && (!hasOwn(constructors, prototype.constructor.name) || constructors[prototype.constructor.name]?.prototype !== prototype))
143
143
  prototype = Object.getPrototypeOf(prototype);
144
144
  const name = prototype?.constructor?.name;
145
145
  if (name === void 0 || name === "Object")
@@ -250,9 +250,9 @@ var _serialize = (data, opts, seen) => {
250
250
  if (toJson)
251
251
  return Reflect.apply(toJson, o, []);
252
252
  if (typeof o === "function")
253
- return printableOpts.onFunction(o);
253
+ return opts.onFunction?.(o) ?? printableOpts.onFunction(o);
254
254
  if (seen.includes(o))
255
- return "(cycle)";
255
+ return opts.onCycle?.(o) ?? "(cycle)";
256
256
  const nextSeen = [...seen, o];
257
257
  if (isArray(o))
258
258
  return o.map((item) => _serialize(item, opts, nextSeen));
@@ -260,12 +260,13 @@ var _serialize = (data, opts, seen) => {
260
260
  return o.toDateString();
261
261
  const result = {};
262
262
  for (const [k, v] of ownEntriesOf(o, opts)) {
263
- result[typeof k === "symbol" ? opts.onSymbol?.(k) ?? k.toString() : k] = _serialize(v, opts, nextSeen);
263
+ const key = typeof k === "symbol" ? opts.onSymbol?.(k) ?? k.toString() : k;
264
+ defineValue(result, key, _serialize(v, opts, nextSeen));
264
265
  }
265
266
  return result;
266
267
  }
267
268
  case "symbol":
268
- return printableOpts.onSymbol(data);
269
+ return opts.onSymbol?.(data) ?? printableOpts.onSymbol(data);
269
270
  case "bigint":
270
271
  return opts.onBigInt?.(data) ?? `${data}n`;
271
272
  case "undefined":
@@ -277,6 +278,8 @@ var _serialize = (data, opts, seen) => {
277
278
  }
278
279
  };
279
280
  var describeCollapsibleDate = (date) => {
281
+ if (!isValidDate(date))
282
+ return "Invalid Date";
280
283
  const year = date.getUTCFullYear();
281
284
  const month = date.getUTCMonth();
282
285
  const dayOfMonth = date.getUTCDate();
@@ -472,11 +475,18 @@ var ArkErrors = class {
472
475
  return this._.length;
473
476
  }
474
477
  get issues() {
475
- return this._.reduce((issues, issue) => (issue.message ??= "is invalid", issues), this._);
478
+ for (const issue of this._) {
479
+ issue.expected ??= "valid";
480
+ issue.message ??= "is invalid";
481
+ }
482
+ return this._.toJSON ? this._ : Object.defineProperty(this._, "toJSON", issuesToJson);
476
483
  }
477
484
  get summary() {
478
485
  return this._.reduce((summary, issue) => summary + (summary && "\n") + lineOf(issue), "");
479
486
  }
487
+ summaryIn() {
488
+ return this.summary;
489
+ }
480
490
  // as issuesNone.ts's
481
491
  throw() {
482
492
  if (namesTraversalError)
@@ -488,11 +498,7 @@ var ArkErrors = class {
488
498
  throw Object.defineProperty(thrown, "arkErrors", { value: this });
489
499
  }
490
500
  toJSON() {
491
- return this.issues.map(({ code, path, message }) => ({
492
- code,
493
- path: path.map((k) => typeof k === "symbol" ? String(k) : k),
494
- message
495
- }));
501
+ return this.issues.map(jsonIssueOf);
496
502
  }
497
503
  toString() {
498
504
  return this.summary;
@@ -501,6 +507,19 @@ var ArkErrors = class {
501
507
  return this.issues[Symbol.iterator]();
502
508
  }
503
509
  };
510
+ var jsonIssueOf = ({ code, path, expected, message }) => ({
511
+ code,
512
+ path: path.map((k) => typeof k === "symbol" ? String(k) : k),
513
+ ...expected !== void 0 && { expected },
514
+ message
515
+ });
516
+ var issuesToJson = {
517
+ value() {
518
+ return this.map(jsonIssueOf);
519
+ },
520
+ writable: true,
521
+ configurable: true
522
+ };
504
523
  var definedThrown;
505
524
  var ThrownErrors = /* @__PURE__ */ (() => definedThrown = class TraversalError extends Error {
506
525
  constructor(errors) {
@@ -704,9 +723,15 @@ var copyOf = (data) => {
704
723
  return { ...data };
705
724
  return Object.prototype.toString.call(data) === "[object Object]" ? Object.setPrototypeOf({ ...data }, prototype) : data;
706
725
  };
726
+ var setOwnValue = (out, k, value) => {
727
+ if (k === "__proto__")
728
+ defineValue(out, k, value);
729
+ else
730
+ out[k] = value;
731
+ };
707
732
  var keepOwn = (out, data, k) => {
708
733
  if (!(k in out) && hasOwn(data, k))
709
- out[k] = data[k];
734
+ setOwnValue(out, k, data[k]);
710
735
  };
711
736
  var copyDeclared = (data, declared, changes) => {
712
737
  "use strict";
@@ -717,7 +742,7 @@ var copyDeclared = (data, declared, changes) => {
717
742
  continue;
718
743
  if (out === data)
719
744
  out = copyOf(data);
720
- out[changes[i]] = changes[i + 2];
745
+ setOwnValue(out, changes[i], changes[i + 2]);
721
746
  }
722
747
  if (out !== data)
723
748
  for (const k of declared)
@@ -746,7 +771,7 @@ var mergeTransformed = (input, l, r) => {
746
771
  delete merged[k];
747
772
  for (const k in r) {
748
773
  if (!(k in input) || !Object.is(r[k], input[k]))
749
- merged[k] = r[k];
774
+ setOwnValue(merged, k, r[k]);
750
775
  }
751
776
  return merged;
752
777
  };
@@ -969,11 +994,9 @@ var Traversal = class extends InternalTraversal {
969
994
  // a code of its own is written without what its rule describes
970
995
  expected: supplied.expected ?? supplied.description ?? (code === "predicate" || supplied.morph ? describePredicate(supplied) : "valid")
971
996
  };
972
- if (supplied.message !== void 0) {
997
+ if (supplied.message !== void 0)
973
998
  issue.message = supplied.message;
974
- if (supplied.message === "is invalid" && supplied.expected === "valid")
975
- issue.expected = void 0;
976
- } else if (supplied.cause !== void 0 && (supplied.meta?.keyword || supplied.morph)) {
999
+ else if (supplied.cause !== void 0 && supplied.morph) {
977
1000
  try {
978
1001
  issue.message = `must be ${issue.expected} (${String(supplied.cause)})`;
979
1002
  } catch {
@@ -1489,33 +1512,30 @@ var travKey = (key, fn, ctx) => {
1489
1512
  };
1490
1513
  var computeDefaultValueMorph = (key, value, defaultInput, node = value, isThunkInput = isThunk(defaultInput)) => {
1491
1514
  const thunk = isThunkInput ? defaultInput : void 0;
1492
- if (!thunk && !node.alters && !node.hasAlias) {
1493
- return (data) => {
1494
- data[key] = defaultInput;
1495
- return data;
1496
- };
1497
- }
1515
+ const write = (data, v) => {
1516
+ setOwnValue(data, key, v);
1517
+ return data;
1518
+ };
1519
+ if (!thunk && !node.alters && !node.hasAlias)
1520
+ return (data) => write(data, defaultInput);
1498
1521
  if (!node.allowsCtx && !node.ctxMorph) {
1499
1522
  return (data) => {
1500
1523
  const input = thunk ? thunk() : defaultInput;
1501
1524
  const output = value.traverse(input);
1502
1525
  if (output instanceof ArkErrors)
1503
1526
  return new TransformErrors(output, input).addTo(void 0, key);
1504
- data[key] = output;
1505
- return data;
1527
+ return write(data, output);
1506
1528
  };
1507
1529
  }
1508
1530
  let transformingDefault = false;
1509
1531
  return (data, ctx) => {
1510
1532
  if (transformingDefault)
1511
1533
  return data;
1512
- if (!thunk && !node.tfs) {
1513
- data[key] = defaultInput;
1514
- return data;
1515
- }
1534
+ if (!thunk && !node.tfs)
1535
+ return write(data, defaultInput);
1516
1536
  transformingDefault = true;
1517
1537
  try {
1518
- data[key] = travKey(key, () => value(thunk ? thunk() : defaultInput, ctx), ctx);
1538
+ write(data, travKey(key, () => value(thunk ? thunk() : defaultInput, ctx), ctx));
1519
1539
  } finally {
1520
1540
  transformingDefault = false;
1521
1541
  }
@@ -1712,6 +1732,7 @@ export {
1712
1732
  rejects,
1713
1733
  runtimeConfig,
1714
1734
  runtimeScope,
1735
+ setOwnValue,
1715
1736
  shareConfig,
1716
1737
  sharedMessageOf,
1717
1738
  silentCtx,
package/out/type.d.ts CHANGED
@@ -7,7 +7,7 @@ import type { Generic, GenericParser, ParameterString, baseGenericConstraints, p
7
7
  import type { Ark, keywords, type } from "./keywords/keywords.ts";
8
8
  import type { MatchParser } from "./match.ts";
9
9
  import type { NaryIntersectionParser, NaryMergeParser, NaryPipeParser, NaryUnionParser } from "./nary.ts";
10
- import type { validateDefinition } from "./parser/definition.ts";
10
+ import type { inferDefinition, validateDefinition } from "./parser/definition.ts";
11
11
  import type { ArgTwoOperator, IndexZeroOperator, TupleInfixOperator } from "./parser/tupleExpressions.ts";
12
12
  import { type bindThis, type InternalScope, type ModuleParser, type Scope, type ScopeParser } from "./scope.ts";
13
13
  import type { BaseType } from "./variants/base.ts";
@@ -37,8 +37,8 @@ import type { instantiateType } from "./variants/instantiate.ts";
37
37
  export interface ValidatedArgs<in out zero, in out one, in out rest extends array, in out $> {
38
38
  params: zero extends ParameterString ? validateParameterString<zero, $> : never;
39
39
  body: zero extends ParameterString ? validateDefinition<one, $, baseGenericConstraints<parseValidGenericParams<zero, $>>> : never;
40
- predicate: Predicate<distill.Out<type.infer<zero, $>>>;
41
- morph: Morph<distill.Out<type.infer<zero, $>>, unknown>;
40
+ predicate: Predicate<distill.Out<inferDefinition<zero, $>>>;
41
+ morph: Morph<distill.Out<inferDefinition<zero, $>>, unknown>;
42
42
  operand: validateDefinition<rest[0], $, bindThis<rest[0]>>;
43
43
  predicateRest: [
44
44
  ValidatedArgs<zero, one, rest, $>[zero extends unknown ? "predicate" : never]
package/out/util.js CHANGED
@@ -1,12 +1,12 @@
1
- export { brand, inferred, narrow } from "./chunk-J7CKAEDX.js";
1
+ export { brand, inferred, narrow } from "./chunk-4NZCLVBD.js";
2
2
  export { Hkt, Scanner, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage } from "./chunk-BDJVONP7.js";
3
- export { WeakCache, defineLazily, holdsWeakly, lazily } from "./chunk-YN3XRJ7H.js";
4
- export { ipv4Matcher, ipv6Matcher, isIpv4, isIpv6, isIso8601, isUuid, iso8601Matcher, uuidMatcher } from "./chunk-NIYAI7AF.js";
3
+ export { WeakCache, defineLazily, holdsWeakly, lazily } from "./chunk-UJJGG4VQ.js";
4
+ export { ipv4Matcher, ipv6Matcher, isIpv4, isIpv6, isIso8601, isUuid, iso8601Matcher, uuidMatcher } from "./chunk-US6BWOGJ.js";
5
5
  export { Backslash, alphabet, anchoredSource, capitalize, deanchoredRegex, deanchoredSource, editsBetween, emojiToUnicode, hashOf, uncapitalize, whitespaceChars } from "./chunk-TACLEIDM.js";
6
- export { arkUtilVersion, initialRegistryContents, nameOf, register, registeredNameOf, registry } from "./chunk-C5JGK6GT.js";
6
+ export { arkUtilVersion, initialRegistryContents, nameOf, register, registeredNameOf, registry } from "./chunk-J2BFVWVY.js";
7
7
  export { isolate, listPattern } from "./chunk-3SH2BQ4T.js";
8
- import { NoopBase, ancestorsOf, defineProperties, getBuiltinNameOfConstructor, hasDomain, includes, isArray, noSuggest } from "./chunk-QBX4MEQR.js";
9
- export { Callable, CastableBase, DynamicBase, DynamicFunction, FileConstructor, InnerDynamicBase, InternalArktypeError, ParseError, ZeroWidthSpace, append, appendStringifiedKey, appendUnique, arityOf, arkKind, arkKindOf, arrayEquals, baseNameOf, builtinConstructors, cached, conflatenate, conflatenateAll, constructorExtends, constructorNameOf, dateGetTime, defineValue, describeCollapsibleDate, domainDescriptions, domainOf, ecmascriptConstructors, ecmascriptDescriptions, entriesOf, enumValues, envHasCsp, expressionOf, flatMorph, fromEntries, functionNameOf, getDuplicatesOf, getPath, groupBy, hasDefinedKey, hasKey, hasObjectKind, hasOwn, integerLikeMatcher, intersectUniqueLists, invert, isDate, isDateObject, isDigitCode, isDotAccessible, isEmptyObject, isInstanceOf, isKeyOf, isNumericString, isPlainObjectOrArray, isRegExpObject, isStandardSchema, isThunk, isValidDate, isWellFormedInteger, isWellFormedNumber, join, jsTypeOfDescriptions, keysOf, liftArray, nearestFloat, nonFiniteNumbers, numberLikeMatcher, numericStringMatcher, objectKindDescriptions, objectKindOf, objectKindOrDomainOf, omit, ownEntriesOf, pathAt, pick, platformConstructors, platformDescriptions, print, printDecimal, printKind, printSymbol, printable, prototypeOf, range, readsOnlyData, returnsReports, serializePrimitive, snapshot, splitByKeys, spliterate, stringAndSymbolicEntriesOf, stringifyPath, testsOrRejects, throwError, throwInternalError, throwParseError, timeOf, toJsonMethodOf, tryCatch, tryParseDate, tryParseInteger, tryParseNumber, tryParseWellFormedBigint, tryParseWellFormedNumber, typedArrayConstructors, typedArrayDescriptions, unset, wellFormedIntegerMatcher, wellFormedNumberMatcher, withAlphabetizedKeys, writeInvalidDateMessage, writeMalformedNumericLiteralMessage } from "./chunk-QBX4MEQR.js";
8
+ import { NoopBase, ancestorsOf, defineProperties, getBuiltinNameOfConstructor, hasDomain, includes, isArray, noSuggest, timeOf } from "./chunk-3HZC67MT.js";
9
+ export { Callable, CastableBase, DynamicBase, DynamicFunction, FileConstructor, InnerDynamicBase, InternalArktypeError, ParseError, ZeroWidthSpace, append, appendStringifiedKey, appendUnique, arityOf, arkKind, arkKindOf, arrayEquals, baseNameOf, builtinConstructors, cached, conflatenate, conflatenateAll, constructorExtends, constructorNameOf, dateGetTime, defineValue, describeCollapsibleDate, domainDescriptions, domainOf, ecmascriptConstructors, ecmascriptDescriptions, entriesOf, enumValues, envHasCsp, expressionOf, flatMorph, fromEntries, functionNameOf, getDuplicatesOf, getPath, groupBy, hasDefinedKey, hasKey, hasObjectKind, hasOwn, integerLikeMatcher, intersectUniqueLists, invert, isDate, isDateObject, isDigitCode, isDotAccessible, isEmptyObject, isInstanceOf, isKeyOf, isNumericString, isPlainObjectOrArray, isRegExpObject, isStandardSchema, isThunk, isValidDate, isWellFormedInteger, isWellFormedNumber, join, jsTypeOfDescriptions, keysOf, liftArray, nearestFloat, nonFiniteNumbers, numberLikeMatcher, numericStringMatcher, objectKindDescriptions, objectKindOf, objectKindOrDomainOf, omit, ownEntriesOf, pathAt, pick, platformConstructors, platformDescriptions, print, printDecimal, printKind, printSymbol, printable, prototypeOf, range, readsOnlyData, returnsReports, serializePrimitive, snapshot, splitByKeys, spliterate, stringAndSymbolicEntriesOf, stringifyPath, testsOrRejects, throwError, throwInternalError, throwParseError, toJsonMethodOf, tryCatch, tryParseDate, tryParseInteger, tryParseNumber, tryParseWellFormedBigint, tryParseWellFormedNumber, typedArrayConstructors, typedArrayDescriptions, unset, wellFormedIntegerMatcher, wellFormedNumberMatcher, withAlphabetizedKeys, writeInvalidDateMessage, writeMalformedNumericLiteralMessage } from "./chunk-3HZC67MT.js";
10
10
  import "./chunk-I2KLQ2HA.js";
11
11
 
12
12
  // ../util/out/clone.js
@@ -17,9 +17,11 @@ var _clone = (input, seen) => {
17
17
  return input;
18
18
  if (seen?.has(input))
19
19
  return seen.get(input);
20
- const builtinConstructorName = getBuiltinNameOfConstructor(input.constructor);
21
- if (builtinConstructorName === "Date")
22
- return new Date(input.getTime());
20
+ if (input instanceof Date && getBuiltinNameOfConstructor(input.constructor) === "Date") {
21
+ const time = timeOf(input);
22
+ if (time !== void 0)
23
+ return new Date(time);
24
+ }
23
25
  const inputIsArray = isArray(input);
24
26
  if (!inputIsArray && Object.prototype.toString.call(input) !== "[object Object]")
25
27
  return input;
@@ -27,7 +29,7 @@ var _clone = (input, seen) => {
27
29
  const propertyDescriptors = Object.getOwnPropertyDescriptors(input);
28
30
  if (seen) {
29
31
  seen.set(input, cloned);
30
- for (const k in propertyDescriptors) {
32
+ for (const k of Reflect.ownKeys(propertyDescriptors)) {
31
33
  const desc = propertyDescriptors[k];
32
34
  if ("get" in desc || "set" in desc)
33
35
  continue;
@@ -130,5 +132,6 @@ export {
130
132
  isArray,
131
133
  isomorphic,
132
134
  noSuggest,
133
- shallowClone
135
+ shallowClone,
136
+ timeOf
134
137
  };
@@ -1,9 +1,10 @@
1
1
  import type { ArkEnv, BaseNode, BaseRoot, Disjoint, JsonSchema, MessageConfig, NodeSelector, Predicate, StandardSchemaV1, ToJsonSchema, TypeMeta, UndeclaredKeyBehavior } from "../_internal/schema/index.js";
2
2
  import type { anyOrNever, array, Callable, ErrorMessage, inferred, JsonStructure, unset } from "../_internal/util/index.js";
3
- import type { defaultFor, distill, inferIntersection, inferPipe, InferredMorph, Out, To } from "../attributes.ts";
3
+ import type { defaultFor, distill, distillEncoded, inferIntersection, inferPipe, InferredMorph, Out, To } from "../attributes.ts";
4
4
  import type { ArkAmbient } from "../config.ts";
5
5
  import type { type } from "../keywords/keywords.ts";
6
6
  import type { NaryPipeParser } from "../nary.ts";
7
+ import type { inferDefinition } from "../parser/definition.ts";
7
8
  import type { Scope } from "../scope.ts";
8
9
  import type { ArrayType } from "./array.ts";
9
10
  import type { instantiateType } from "./instantiate.ts";
@@ -422,7 +423,7 @@ export interface Inferred<out t = unknown, in out $ = {}> {
422
423
  * // parse a string and validate the result as a user
423
424
  * const parseUser = type("string").pipe(s => JSON.parse(s)).to({ name: "string" })
424
425
  */
425
- to<const def, r = instantiateType<inferPipe<t, type.infer<def, $>>, $>>(def: type.validate<def, $>): r extends infer _ ? _ : never;
426
+ to<const def, r = instantiateType<inferPipe<t, inferDefinition<def, $>>, $>>(def: type.validate<def, $>): r extends infer _ ? _ : never;
426
427
  /**
427
428
  * #### query internal node references
428
429
  *
@@ -455,7 +456,7 @@ interface Type<out t = unknown, in out $ = {}> extends Callable<(data: unknown)
455
456
  * // ParseError: Intersection at foo of number and string results in an unsatisfiable type
456
457
  * const Bad = type({ foo: "number" }).and({ foo: "string" })
457
458
  */
458
- and<const def, r = instantiateType<inferIntersection<t, type.infer<def, $>>, $>>(def: type.validate<def, $>): r extends infer _ ? _ : never;
459
+ and<const def, r = instantiateType<inferIntersection<t, inferDefinition<def, $>>, $>>(def: type.validate<def, $>): r extends infer _ ? _ : never;
459
460
  /**
460
461
  * #### union with the parsed Type
461
462
  *
@@ -465,7 +466,7 @@ interface Type<out t = unknown, in out $ = {}> extends Callable<(data: unknown)
465
466
  * // Type<string | { box: string }>
466
467
  * const T = type("string").or({ box: "string" })
467
468
  */
468
- or<const def, r = instantiateType<t | type.infer<def, $>, $>>(def: type.validate<def, $>): r extends infer _ ? _ : never;
469
+ or<const def, r = instantiateType<t | inferDefinition<def, $>, $>>(def: type.validate<def, $>): r extends infer _ ? _ : never;
469
470
  /**
470
471
  * #### intersect the parsed Type, returning an introspectable {@link Disjoint} if the result is unsatisfiable
471
472
  *
@@ -478,7 +479,7 @@ interface Type<out t = unknown, in out $ = {}> extends Callable<(data: unknown)
478
479
  * // logs "Intersection of > 10 and < 5 results in an unsatisfiable type"
479
480
  * if (!(Bad instanceof Type)) console.log(Bad.summary)
480
481
  */
481
- intersect<const def, r = instantiateType<inferIntersection<t, type.infer<def, $>>, $>>(def: type.validate<def, $>): r extends infer _ ? _ | Disjoint : never;
482
+ intersect<const def, r = instantiateType<inferIntersection<t, inferDefinition<def, $>>, $>>(def: type.validate<def, $>): r extends infer _ ? _ | Disjoint : never;
482
483
  /**
483
484
  * #### check if the parsed Type's constraints are identical
484
485
  *
@@ -550,7 +551,7 @@ interface Type<out t = unknown, in out $ = {}> extends Callable<(data: unknown)
550
551
  * // Type<true | 0 | 2>
551
552
  * const T = type("boolean | 0 | 'one' | 2 | bigint").extract("number | 0n | true")
552
553
  */
553
- extract<const def, r = instantiateType<t extends type.infer<def, $> ? t : never, $>>(r: type.validate<def, $>): r extends infer _ extends r ? _ : never;
554
+ extract<const def, r = instantiateType<t extends inferDefinition<def, $> ? t : never, $>>(r: type.validate<def, $>): r extends infer _ extends r ? _ : never;
554
555
  /**
555
556
  * #### exclude branches {@link extend}ing the parsed Type
556
557
  *
@@ -559,7 +560,7 @@ interface Type<out t = unknown, in out $ = {}> extends Callable<(data: unknown)
559
560
  * // Type<false | 'one' | bigint>
560
561
  * const T = type("boolean | 0 | 'one' | 2 | bigint").exclude("number | 0n | true")
561
562
  */
562
- exclude<const def, r = instantiateType<t extends type.infer<def, $> ? never : t, $>>(r: type.validate<def, $>): r extends infer _ ? _ : never;
563
+ exclude<const def, r = instantiateType<t extends inferDefinition<def, $> ? never : t, $>>(r: type.validate<def, $>): r extends infer _ ? _ : never;
563
564
  /**
564
565
  * @experimental
565
566
  * Map and optionally reduce branches of a union. Types that are not unions
@@ -596,7 +597,7 @@ interface Type<out t = unknown, in out $ = {}> extends Callable<(data: unknown)
596
597
  Symbol: never;
597
598
  }
598
599
  type inferEncoder<t> = {
599
- encode(In: distill.Out<t>): To<distill.In<t>>;
600
+ encode(In: distill.Out<t>): To<distillEncoded<t>>;
600
601
  }["encode"];
601
602
  export interface ChainedPipeParser<$, t> extends NaryPipeParser<$, t> {
602
603
  try: NaryPipeParser<$, t>;
@@ -1,7 +1,8 @@
1
1
  import type { ArkEnv, BaseMappedPropInner, OptionalMappedPropInner, Prop } from "../_internal/schema/index.js";
2
- import type { arkGet, arkIndexableOf, arkKeyOf, array, ErrorType, inferred, intersectUnion, JsonStructure, Key, listable, merge, optionalKeyOf, show, toArkKey } from "../_internal/util/index.js";
2
+ import type { anyOrNever, arkGet, arkIndexableOf, arkKeyOf, array, ErrorType, inferred, intersectUnion, JsonStructure, Key, listable, merge, optionalKeyOf, show, toArkKey } from "../_internal/util/index.js";
3
3
  import type { Default, InferredMorph, required, withDefault } from "../attributes.ts";
4
4
  import type { type } from "../keywords/keywords.ts";
5
+ import type { inferDefinition } from "../parser/definition.ts";
5
6
  import type { ArrayType } from "./array.ts";
6
7
  import type { BaseType } from "./base.ts";
7
8
  import type { instantiateType } from "./instantiate.ts";
@@ -17,9 +18,9 @@ interface Type<out t extends object = object, in out $ = {}> extends BaseType<t,
17
18
  * Get the `Type` of a property of this `Type<object>`.
18
19
  * @example type({ foo: "string" }).get("foo") // Type<string>
19
20
  */
20
- get<const k1 extends arkIndexableOf<t>, r = instantiateType<arkGet<t, k1>, $>>(k1: k1 | type.cast<k1>): r extends infer _ ? _ : never;
21
- get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<arkGet<t, k1>>, r = instantiateType<arkGet<arkGet<t, k1>, k2>, $>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>): r extends infer _ ? _ : never;
22
- get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<arkGet<t, k1>>, const k3 extends arkIndexableOf<arkGet<arkGet<t, k1>, k2>>, r = instantiateType<arkGet<arkGet<arkGet<t, k1>, k2>, k3>, $>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>, k3: k3 | type.cast<k3>): r extends infer _ ? _ : never;
21
+ get<const k1 extends arkIndexableOf<t>, r = instantiateType<gotAt<t, k1>, $>>(k1: k1 | type.cast<k1>): r extends infer _ ? _ : never;
22
+ get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<definedAt<t, k1>>, r = instantiateType<gotAt<definedAt<t, k1>, k2> | undefinedAt<t, k1>, $>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>): r extends infer _ ? _ : never;
23
+ get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<definedAt<t, k1>>, const k3 extends arkIndexableOf<definedAt<definedAt<t, k1>, k2>>, r = instantiateType<gotAt<definedAt<definedAt<t, k1>, k2>, k3> | undefinedAt<definedAt<t, k1>, k2> | undefinedAt<t, k1>, $>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>, k3: k3 | type.cast<k3>): r extends infer _ ? _ : never;
23
24
  /**
24
25
  * Create a copy of this `Type` with only the specified properties.
25
26
  *
@@ -53,7 +54,7 @@ interface Type<out t extends object = object, in out $ = {}> extends BaseType<t,
53
54
  *
54
55
  * @example type({ a: "1", b: "2" }).merge({ b: "3", c: "4" }) // Type<{ a: 1; b: 3; c: 4 }>
55
56
  */
56
- merge<const def, inferredDef = type.infer<def, $>, r = Type<merge<t, inferredDef>, $>>(def: type.validate<def, $> & (type.infer<def, $> extends object ? unknown : ErrorType<[NonObjectMergeErrorMessage, actual: inferredDef]>)): r extends infer _ ? _ : never;
57
+ merge<const def, inferredDef = inferDefinition<def, $>, r = Type<merge<t, inferredDef>, $>>(def: type.validate<def, $> & (inferDefinition<def, $> extends object ? unknown : ErrorType<[NonObjectMergeErrorMessage, actual: inferredDef]>)): r extends infer _ ? _ : never;
57
58
  /**
58
59
  * Create a copy of this `Type` with all properties required.
59
60
  *
@@ -99,7 +100,14 @@ interface Type<out t extends object = object, in out $ = {}> extends BaseType<t,
99
100
  */
100
101
  props: readonly typePropOf<t, $>[];
101
102
  }
102
- type typePropOf<o, $> = o extends unknown ? keyof o extends infer k ? k extends keyof o ? typeProp<o, k, $> : never : never : never;
103
+ type gotAt<o, k extends arkIndexableOf<o>> = undefaulted<arkGet<o, k>>;
104
+ type undefaulted<v> = [
105
+ v
106
+ ] extends [anyOrNever] ? v : v extends Default<infer t> ? t | undefined : v extends (...args: never) => anyOrNever ? v : v extends InferredMorph<Default<infer i, never>, infer out> ? ((In: i) => out) | undefined : v;
107
+ type definedAt<o, k extends arkIndexableOf<o>> = Exclude<gotAt<o, k>, undefined>;
108
+ type undefinedAt<o, k extends arkIndexableOf<o>> = undefined extends gotAt<o, k> ? undefined : never;
109
+ type typePropOf<o, $> = o extends unknown ? propKeyOf<o> extends infer k ? k extends keyof o ? typeProp<o, k, $> : never : never : never;
110
+ type propKeyOf<o> = o extends array ? Exclude<keyof o, keyof unknown[] | `${number}`> : keyof o;
103
111
  type typeProp<o, k extends keyof o, $, v = propValueOf<o, k>> = [
104
112
  v
105
113
  ] extends [Default<infer t, infer defaultValue>] ? DefaultedTypeProp<k & Key, t, defaultValue, $> : [v] extends ([
package/package.json CHANGED
@@ -15,8 +15,8 @@
15
15
  "json-schema",
16
16
  "precompile"
17
17
  ],
18
- "version": "3.0.0-beta.2",
19
- "arkAotVersion": "3.0.0-beta.2",
18
+ "version": "3.0.0-rc.1",
19
+ "arkAotVersion": "3.0.0-rc.1",
20
20
  "license": "MIT",
21
21
  "homepage": "https://arktype.io",
22
22
  "repository": {
@@ -361,9 +361,9 @@
361
361
  ],
362
362
  "devDependencies": {
363
363
  "zod": "4.6.7",
364
- "@ark/util": "3.0.0-beta.2",
364
+ "@ark/util": "3.0.0-rc.1",
365
365
  "@ark/schema": "0.57.0-beta.1",
366
- "arkregex": "0.0.16-beta.2",
366
+ "arkregex": "0.0.16-rc.1",
367
367
  "arksets": "0.0.1-beta.1"
368
368
  },
369
369
  "publishConfig": {