arktype 3.0.0-beta.0 → 3.0.0-beta.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 (51) hide show
  1. package/README.md +162 -10
  2. package/out/attributes.d.ts +4 -2
  3. package/out/checkers.d.ts +37 -2
  4. package/out/{chunk-Z4F45ZTE.js → chunk-2U2AWCI3.js} +3 -3
  5. package/out/{chunk-5NJWD7CO.js → chunk-5U2ZMDNI.js} +215 -140
  6. package/out/{chunk-KJ3C5GTL.js → chunk-DLWCO4RV.js} +1 -1
  7. package/out/{chunk-H4VRNKMB.js → chunk-E3DZXEZK.js} +1 -1
  8. package/out/{chunk-EJZJUYPI.js → chunk-EVCML554.js} +2 -2
  9. package/out/{chunk-KI2MOYNT.js → chunk-GPNK5353.js} +184 -32
  10. package/out/{chunk-LUXERINN.js → chunk-RAZ3TXOE.js} +40 -38
  11. package/out/chunk-SWOOCAHN.js +4 -0
  12. package/out/{chunk-ARTS74PX.js → chunk-UETB6YE2.js} +1 -1
  13. package/out/{chunk-JHDPSG5Y.js → chunk-UK5UGFOX.js} +6 -6
  14. package/out/{chunk-WEPQK3AY.js → chunk-VV6YDN2D.js} +441 -145
  15. package/out/codecs.js +5 -5
  16. package/out/config.d.ts +6 -3
  17. package/out/i18n.d.ts +1 -1
  18. package/out/i18n.js +1 -1
  19. package/out/index.d.ts +1 -1
  20. package/out/index.js +5 -5
  21. package/out/internal.d.ts +1 -0
  22. package/out/internal.js +11 -11
  23. package/out/island.js +2 -2
  24. package/out/islandDependency.js +11 -11
  25. package/out/keywords/functions.d.ts +24 -24
  26. package/out/keywords/keywords.d.ts +2 -2
  27. package/out/keywords/phrases.d.ts +23 -23
  28. package/out/keywords/ts.js +2 -2
  29. package/out/locale.d.ts +1 -1
  30. package/out/locales/de.js +1 -1
  31. package/out/locales/en.js +3 -3
  32. package/out/match.d.ts +5 -3
  33. package/out/mutatesInput.js +2 -2
  34. package/out/parser/definition.d.ts +54 -3
  35. package/out/parser/shift/operand/unenclosed.d.ts +3 -1
  36. package/out/parser/shift/operand/unresolvable.d.ts +68 -0
  37. package/out/parser/shift/operator/bounds.d.ts +4 -1
  38. package/out/runtime.d.ts +34 -25
  39. package/out/runtime.js +2 -2
  40. package/out/runtimeDevelopment.js +63 -4
  41. package/out/scope.d.ts +4 -4
  42. package/out/standalone/artifact.d.ts +4 -0
  43. package/out/standalone/baking.d.ts +8 -1
  44. package/out/standalone/sites.d.ts +6 -3
  45. package/out/standalone/values.d.ts +2 -0
  46. package/out/type.d.ts +42 -5
  47. package/package.json +49 -6
  48. package/skills/arktype/SKILL.md +211 -92
  49. package/skills/arktype/references/migrating.md +990 -255
  50. package/skills/arktype/references/precompile.md +8 -5
  51. package/out/chunk-EDEN5UWG.js +0 -4
@@ -4,7 +4,7 @@ import {
4
4
  parseIsoDate,
5
5
  parseJson,
6
6
  parseUrl
7
- } from "./chunk-JHDPSG5Y.js";
7
+ } from "./chunk-UK5UGFOX.js";
8
8
 
9
9
  // out/mutatesInput.js
10
10
  import { inputOnlyMorphs } from "@ark/schema/mutatesInput";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  raisedErrorPhrases
3
- } from "./chunk-JHDPSG5Y.js";
3
+ } from "./chunk-UK5UGFOX.js";
4
4
 
5
5
  // out/keywords/phrases.js
6
6
  import { en } from "@ark/schema";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  type
3
- } from "./chunk-Z4F45ZTE.js";
3
+ } from "./chunk-2U2AWCI3.js";
4
4
  import {
5
5
  capitalizeString,
6
6
  keepFormatted,
@@ -19,7 +19,7 @@ import {
19
19
  writeEpoch,
20
20
  writeIsoDate,
21
21
  writeUrl
22
- } from "./chunk-JHDPSG5Y.js";
22
+ } from "./chunk-UK5UGFOX.js";
23
23
 
24
24
  // out/codecs.js
25
25
  import { inverses } from "@ark/schema/codecs";
@@ -4,15 +4,15 @@ import {
4
4
  import {
5
5
  emptyCollectionDefaults,
6
6
  stringifyJson
7
- } from "./chunk-JHDPSG5Y.js";
7
+ } from "./chunk-UK5UGFOX.js";
8
8
 
9
9
  // out/keywords/ts.js
10
10
  import { genericNode, intrinsic as intrinsic4, isResolvable, node as node2 } from "@ark/schema";
11
11
  import { cached as cached2, Hkt as Hkt2, throwParseError as throwParseError13 } from "@ark/util";
12
12
 
13
13
  // out/scope.js
14
- import { $ark as $ark5, BaseScope, hasArkKind as hasArkKind3, LazyGenericRoot, parseGeneric, RootModule, isFinalResolution } from "@ark/schema";
15
- import { Scanner as Scanner2, defineLazily as defineLazily2, enumValues, flatMorph, hasOwn as hasOwn3, isArray as isArray5, isThunk as isThunk3, throwParseError as throwParseError12 } from "@ark/util";
14
+ import { $ark as $ark5, BaseScope, hasArkKind as hasArkKind4, LazyGenericRoot, parseGeneric, RootModule, isFinalResolution } from "@ark/schema";
15
+ import { Scanner as Scanner2, defineLazily as defineLazily2, enumValues, flatMorph, hasOwn as hasOwn5, isArray as isArray5, isThunk as isThunk3, throwParseError as throwParseError12 } from "@ark/util";
16
16
  import { setEngine } from "arksets/internal";
17
17
 
18
18
  // out/generic.js
@@ -118,8 +118,8 @@ var enclosingCharDescriptions = {
118
118
  var writeUnterminatedEnclosedMessage = (fragment, enclosingStart) => `${enclosingStart}${fragment} requires a closing ${enclosingCharDescriptions[enclosingTokens[enclosingStart]]}`;
119
119
 
120
120
  // out/parser/shift/operand/unenclosed.js
121
- import { hasArkKind, writeUnresolvableMessage } from "@ark/schema";
122
- import { hasOwn, nonFiniteNumbers, printable, throwParseError as throwParseError3, tryParseWellFormedBigint, tryParseWellFormedNumber, whitespaceChars as whitespaceChars3 } from "@ark/util";
121
+ import { hasArkKind as hasArkKind2, writeUnresolvableMessage } from "@ark/schema";
122
+ import { hasOwn as hasOwn2, nonFiniteNumbers, printable, throwParseError as throwParseError3, tryParseWellFormedBigint, tryParseWellFormedNumber, whitespaceChars as whitespaceChars3 } from "@ark/util";
123
123
 
124
124
  // out/parser/ast/validate.js
125
125
  var writePrefixedPrivateReferenceMessage = (name) => `Private type references should not include '#'. Use '${name}' instead.`;
@@ -296,6 +296,7 @@ var parseRightBound = function (s, comparator) {
296
296
  if (s.rightBounded?.root === previousRoot) {
297
297
  return s.error(writeDoubleRightBoundMessage(s.rightBounded.operand.expression));
298
298
  }
299
+ const followsArray = comparator === "<" && /(?:^|[^\w$.])Array\s*<$/.test(s.sc.scanned);
299
300
  const previousScannerIndex = s.sc.location;
300
301
  s.sc.skipSpace();
301
302
  let limit = limitOf(s, shiftUntilTerminator(s.sc));
@@ -305,8 +306,9 @@ var parseRightBound = function (s, comparator) {
305
306
  s.parseOperand();
306
307
  const limitNode = s.unsetRoot();
307
308
  limitToken = s.sc.sliceChars(previousScannerIndex, s.sc.location).trim();
308
- if (!limitNode?.is("unit") || typeof limitNode.unit !== "number" && !(limitNode.unit instanceof Date) || typeof limitNode.unit === "number" && !Number.isFinite(limitNode.unit))
309
- return s.error(writeInvalidLimitMessage(comparator, limitToken, "right"));
309
+ if (!limitNode?.is("unit") || typeof limitNode.unit !== "number" && !(limitNode.unit instanceof Date) || typeof limitNode.unit === "number" && !Number.isFinite(limitNode.unit)) {
310
+ return s.error(writeInvalidLimitMessage(comparator, limitToken, "right") + (followsArray ? arrayIsNotGenericHint : ""));
311
+ }
310
312
  limit = limitNode.unit;
311
313
  }
312
314
  s.root = previousRoot;
@@ -326,6 +328,7 @@ var parseRightBound = function (s, comparator) {
326
328
  s.branches.lBound = null;
327
329
  s.rightBounded = { root: s.root, operand: previousRoot };
328
330
  };
331
+ var arrayIsNotGenericHint = ". Array isn't generic here: write an array of strings as string[]";
329
332
  var writeInvalidLimitMessage = function (comparator, limit, boundKind) { return `Comparator ${boundKind === "left" ? invertedComparators[comparator] : comparator} must be ${boundKind === "left" ? "preceded" : "followed"} by a corresponding literal (was ${limit})` };
330
333
 
331
334
  // out/parser/shift/operand/genericArgs.js
@@ -346,6 +349,118 @@ var _parseGenericArgs = function (name, g, s, argNodes) {
346
349
  };
347
350
  var writeInvalidGenericArgCountMessage = function (name, params, argDefs) { return `${name}<${params.join(", ")}> requires exactly ${params.length} args (got ${argDefs.length}${argDefs.length === 0 ? "" : `: ${argDefs.join(", ")}`})` };
348
351
 
352
+ // out/parser/shift/operand/unresolvable.js
353
+ import { hasArkKind } from "@ark/schema";
354
+ import { editsBetween, hasOwn } from "@ark/util";
355
+ var foreignAliases = {
356
+ // TypeScript
357
+ any: "unknown.any",
358
+ void: "undefined",
359
+ String: "string",
360
+ Number: "number",
361
+ Boolean: "boolean",
362
+ BigInt: "bigint",
363
+ Symbol: "symbol",
364
+ Object: "object",
365
+ function: "Function",
366
+ array: "unknown[]",
367
+ // other languages, and JSON Schema's `integer`
368
+ str: "string",
369
+ bool: "boolean",
370
+ num: "number",
371
+ int: "number.integer",
372
+ integer: "number.integer",
373
+ float: "number",
374
+ double: "number",
375
+ decimal: "number",
376
+ "number.int": "number.integer",
377
+ "number.float": "number",
378
+ "number.positive": "number > 0",
379
+ "number.negative": "number < 0",
380
+ "number.nonnegative": "number >= 0",
381
+ "string.nonempty": "string > 0",
382
+ // Zod's formats, and JSON Schema's
383
+ date: "Date",
384
+ datetime: "string.date.iso",
385
+ "string.datetime": "string.date.iso",
386
+ timestamp: "number.epoch",
387
+ email: "string.email",
388
+ uuid: "string.uuid",
389
+ guid: "string.uuid",
390
+ "string.guid": "string.uuid",
391
+ url: "string.url",
392
+ uri: "string.url",
393
+ "string.uri": "string.url",
394
+ ip: "string.ip",
395
+ ipv4: "string.ip.v4",
396
+ ipv6: "string.ip.v6",
397
+ "string.ipv4": "string.ip.v4",
398
+ "string.ipv6": "string.ip.v6",
399
+ json: "string.json",
400
+ base64: "string.base64",
401
+ hex: "string.hex",
402
+ regex: "RegExp",
403
+ regexp: "RegExp",
404
+ nan: "number.NaN"
405
+ };
406
+ var writeUnresolvableHint = function (name, $, args) {
407
+ if (hasOwn(foreignAliases, name))
408
+ return writeDidYouMean([foreignAliases[name]]);
409
+ if (/^[\d-]/.test(name))
410
+ return "";
411
+ const scopes = [args ?? {}, $.aliases, $.ambient];
412
+ const path = name.split(".");
413
+ let submodule;
414
+ let depth = 0;
415
+ for (; depth < path.length - 1; depth++) {
416
+ const from = submodule ?? scopes.find((aliases) => hasOwn(aliases, path[depth]));
417
+ const next2 = from && hasOwn(from, path[depth]) ? from[path[depth]] : null;
418
+ if (!hasArkKind(next2, "module"))
419
+ break;
420
+ submodule = next2;
421
+ }
422
+ if (!submodule)
423
+ return writeDidYouMean(nearest(name, scopes.flatMap(namesIn)));
424
+ const prefix = `${path.slice(0, depth).join(".")}.`;
425
+ const rest = path.slice(depth).join(".");
426
+ const keys = Object.keys(submodule).filter((k) => k !== "root");
427
+ const started = rest && keys.filter((k) => k.startsWith(rest));
428
+ const suggested = started && started.length ? started : nearest(rest, namesIn(submodule));
429
+ return suggested.length ? writeDidYouMean(suggested.map((k) => prefix + k)) : `. '${prefix.slice(0, -1)}' has ${keys.join(", ")}.`;
430
+ };
431
+ var writeDidYouMean = function (names) {
432
+ if (names.length === 0)
433
+ return "";
434
+ const quoted = names.slice(0, 3).map((name) => `'${name}'`);
435
+ const last = quoted.pop();
436
+ return `. Did you mean ${quoted.length ? `${quoted.join(", ")} or ${last}` : last}?`;
437
+ };
438
+ var namesIn = function (aliases) { return Object.keys(aliases).flatMap((k) => {
439
+ if (k === "root")
440
+ return [];
441
+ const v = aliases[k];
442
+ if (!hasArkKind(v, "module"))
443
+ return [k];
444
+ const nested = namesIn(v).map((name) => `${k}.${name}`);
445
+ return hasOwn(v, "root") ? [k, ...nested] : nested;
446
+ }) };
447
+ var nearest = function (name, candidates) {
448
+ const lower = name.toLowerCase();
449
+ let limit = name.length < 3 ? 0 : name.length < 5 ? 1 : 2;
450
+ let found = [];
451
+ for (const candidate of new Set(candidates)) {
452
+ const full = candidate.toLowerCase();
453
+ const distance = Math.min(editsBetween(lower, full), editsBetween(lower, full.slice(full.lastIndexOf(".") + 1)));
454
+ if (distance > limit)
455
+ continue;
456
+ if (distance < limit)
457
+ found = [];
458
+ limit = distance;
459
+ found.push(candidate);
460
+ }
461
+ return found;
462
+ };
463
+
349
464
  // out/parser/shift/operand/unenclosed.js
350
465
  var parseUnenclosed = function (s) {
351
466
  const token = shiftUntilTerminator(s.sc);
@@ -361,7 +476,7 @@ var limitOf = function (s, token) {
361
476
  const limit = tryParseWellFormedNumber(token);
362
477
  if (limit === void 0 || !Number.isFinite(limit))
363
478
  return;
364
- if (s.ctx.args && hasOwn(s.ctx.args, token))
479
+ if (s.ctx.args && hasOwn2(s.ctx.args, token))
365
480
  return;
366
481
  return s.ctx.$.maybeResolve(token) === void 0 ? limit : void 0;
367
482
  };
@@ -386,25 +501,25 @@ var parseGenericInstantiation = function (name, g, s) {
386
501
  const parsedArgs = parseGenericArgs(name, g, s);
387
502
  return g(...parsedArgs);
388
503
  };
389
- var unenclosedToNode = function (s, token) { return maybeParseReference(s, token) ?? maybeParseUnenclosedLiteral(s, token) ?? s.error(token === "" ? s.sc.peek === "#" ? writePrefixedPrivateReferenceMessage(shiftUntilTerminator(s.shiftedBy(1).sc)) : writeMissingOperandMessage(s) : writeUnresolvableMessage(token)) };
504
+ var unenclosedToNode = function (s, token) { return maybeParseReference(s, token) ?? maybeParseUnenclosedLiteral(s, token) ?? s.error(token === "" ? s.sc.peek === "#" ? writePrefixedPrivateReferenceMessage(shiftUntilTerminator(s.shiftedBy(1).sc)) : writeMissingOperandMessage(s) : writeUnresolvableMessage(token) + writeUnresolvableHint(token, s.ctx.$, s.ctx.args)) };
390
505
  var maybeParseReference = function (s, token) {
391
- if (s.ctx.args && hasOwn(s.ctx.args, token)) {
506
+ if (s.ctx.args && hasOwn2(s.ctx.args, token)) {
392
507
  const arg = s.ctx.args[token];
393
508
  if (typeof arg !== "string")
394
509
  return arg;
395
510
  return s.ctx.$.node("alias", { reference: arg }, { reduced: true });
396
511
  }
397
512
  const resolution = s.ctx.$.maybeResolve(token);
398
- if (hasArkKind(resolution, "root"))
513
+ if (hasArkKind2(resolution, "root"))
399
514
  return resolution;
400
515
  if (resolution === void 0)
401
516
  return;
402
- if (hasArkKind(resolution, "generic"))
517
+ if (hasArkKind2(resolution, "generic"))
403
518
  return parseGenericInstantiation(token, resolution, s);
404
519
  return throwParseError3(`Unexpected resolution ${printable(resolution)}`);
405
520
  };
406
521
  var maybeParseUnenclosedLiteral = function (s, token) {
407
- const maybeNumber = hasOwn(nonFiniteNumbers, token) ? nonFiniteNumbers[token] : tryParseWellFormedNumber(token);
522
+ const maybeNumber = hasOwn2(nonFiniteNumbers, token) ? nonFiniteNumbers[token] : tryParseWellFormedNumber(token);
408
523
  if (maybeNumber !== void 0)
409
524
  return s.ctx.$.node("unit", { unit: maybeNumber });
410
525
  const maybeBigint = tryParseWellFormedBigint(token);
@@ -778,8 +893,8 @@ var chainedAtMessage = `A key matcher must be specified before the first case i.
778
893
  var doubleAtMessage = `At most one key matcher may be specified per expression`;
779
894
 
780
895
  // out/parser/definition.js
781
- import { $ark as $ark3, BaseRoot, constraintInputOf, hasArkKind as hasArkKind2, foreignTypesByMorph, inProgress as inProgress2 } from "@ark/schema";
782
- import { domainOf as domainOf2, hasDomain, isArray as isArray4, isInstanceOf, isStandardSchema, isThunk, objectKindOf, printable as printable3, throwError, throwParseError as throwParseError11, uncapitalize } from "@ark/util";
896
+ import { $ark as $ark3, asTemplated, BaseRoot, constraintInputOf, hasArkKind as hasArkKind3, foreignTypesByMorph, inProgress as inProgress2, isCustomIssue } from "@ark/schema";
897
+ import { domainOf as domainOf2, hasDomain, hasOwn as hasOwn4, isArray as isArray4, isInstanceOf, isStandardSchema, isThunk, objectKindOf, printable as printable3, throwError, throwParseError as throwParseError11 } from "@ark/util";
783
898
 
784
899
  // out/parser/objectLiteral.js
785
900
  import { checkDefault, intrinsic as intrinsic2, normalizeIndex, ownKeysOf, requiredPropOf } from "@ark/schema";
@@ -914,7 +1029,7 @@ var writeInvalidSpreadTypeMessage = (def) => `Spread operand must resolve to an
914
1029
 
915
1030
  // out/parser/tupleExpressions.js
916
1031
  import { Disjoint } from "@ark/schema";
917
- import { hasOwn as hasOwn2, objectKindOrDomainOf, throwParseError as throwParseError9 } from "@ark/util";
1032
+ import { hasOwn as hasOwn3, objectKindOrDomainOf, throwParseError as throwParseError9 } from "@ark/util";
918
1033
  import { intersectNodesRoot, pipeNodesRoot } from "arksets/internal";
919
1034
  var maybeParseTupleExpression = function (def, ctx) { return isIndexZeroExpression(def) ? indexZeroParsers[def[0]](def, ctx) : isIndexOneExpression(def) ? indexOneParsers[def[1]](def, ctx) : null };
920
1035
  var parseKeyOfTuple = (def, ctx) => ctx.$.parseOwn(def[1], ctx).keyof();
@@ -978,7 +1093,7 @@ var indexZeroParsers = defineIndexZeroParsers({
978
1093
  "===": (def, ctx) => ctx.$.units(def.slice(1))
979
1094
  });
980
1095
  var isIndexZeroExpression = (def) => isOperatorOf(def[0], indexZeroParsers);
981
- var isOperatorOf = (element, parsers) => typeof element === "string" && hasOwn2(parsers, element);
1096
+ var isOperatorOf = (element, parsers) => typeof element === "string" && hasOwn3(parsers, element);
982
1097
  var writeInvalidConstructorMessage = (actual) => `Expected a constructor following 'instanceof' operator (was ${actual})`;
983
1098
 
984
1099
  // out/parser/tupleLiteral.js
@@ -1124,7 +1239,7 @@ var parseObject = function (def, ctx) {
1124
1239
  const objectKind = objectKindOf(def);
1125
1240
  switch (objectKind) {
1126
1241
  case void 0:
1127
- if (hasArkKind2(def, "root")) {
1242
+ if (hasArkKind3(def, "root")) {
1128
1243
  return isInstanceOf(def, BaseRoot) ? def : parseStandardSchema(def, ctx, true);
1129
1244
  }
1130
1245
  if (isStandardSchema(def))
@@ -1142,8 +1257,8 @@ var parseObject = function (def, ctx) {
1142
1257
  case "Function": {
1143
1258
  if (isStandardSchema(def))
1144
1259
  return parseStandardSchema(def, ctx);
1145
- const resolvedDef = isThunk(def) ? def() : def;
1146
- if (hasArkKind2(resolvedDef, "root"))
1260
+ const resolvedDef = isThunk(def) ? resolveThunk(def) : def;
1261
+ if (hasArkKind3(resolvedDef, "root"))
1147
1262
  return parseObject(resolvedDef, ctx);
1148
1263
  return throwParseError11(writeBadDefinitionTypeMessage("Function"));
1149
1264
  }
@@ -1151,6 +1266,20 @@ var parseObject = function (def, ctx) {
1151
1266
  return throwParseError11(writeBadDefinitionTypeMessage(objectKind ?? printable3(def)));
1152
1267
  }
1153
1268
  };
1269
+ var resolveThunk = function (def) {
1270
+ const source = Function.prototype.toString.call(def);
1271
+ if (/^class\b/.test(source))
1272
+ return def;
1273
+ if (!/\[native code]\s*}$/.test(source))
1274
+ return def();
1275
+ try {
1276
+ return def();
1277
+ } catch (e) {
1278
+ if (e instanceof TypeError)
1279
+ return def;
1280
+ throw e;
1281
+ }
1282
+ };
1154
1283
  var parseStandardSchema = function (def, ctx, isForeign) {
1155
1284
  const validate = (v, ctx2) => {
1156
1285
  const result = def["~standard"].validate(v);
@@ -1160,14 +1289,24 @@ var parseStandardSchema = function (def, ctx, isForeign) {
1160
1289
  if (!result.issues)
1161
1290
  return result.value;
1162
1291
  if (result.issues.length === 0)
1163
- return ctx2.error({ problem: "is invalid" });
1292
+ return ctx2.error({ expected: "valid", message: "is invalid" });
1293
+ const { vendor, _c: isCustomError } = def["~standard"];
1294
+ const fromArk = vendor === "arktype";
1164
1295
  for (const issue of result.issues) {
1165
- const { problem } = issue;
1166
- ctx2.error({
1167
- // an arktype 2 message starts with the path its issue already has
1168
- problem: isForeign && typeof problem === "string" ? problem : uncapitalize(issue.message),
1169
- relativePath: (issue.path ?? []).map((k) => typeof k === "object" ? k.key : k)
1296
+ const relativePath = (issue.path ?? []).map((k) => typeof k === "object" ? k.key : k);
1297
+ const { problem, _c, _l, _m } = issue;
1298
+ const fromArk2 = isForeign && typeof problem === "string";
1299
+ const error = ctx2.error({
1300
+ message: fromArk2 ? problem : issue.message,
1301
+ relativePath
1170
1302
  });
1303
+ if (fromArk2 || fromArk && _c === void 0 && (isCustomError ? !isCustomError(issue) : !isCustomIssue(issue))) {
1304
+ asTemplated(
1305
+ error,
1306
+ // a union listing its branches' errors names their whole paths
1307
+ _m ? _m.call(issue, ctx2.path)._l : ctx2.path.length === 0 ? _l : void 0
1308
+ );
1309
+ }
1171
1310
  }
1172
1311
  };
1173
1312
  if (isForeign)
@@ -1176,7 +1315,17 @@ var parseStandardSchema = function (def, ctx, isForeign) {
1176
1315
  };
1177
1316
  var writeAsyncStandardSchemaMessage = (vendor) => `Standard Schema definitions must validate synchronously (${vendor} returned a Promise)`;
1178
1317
  var parseTuple = (def, ctx) => maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx);
1179
- var writeBadDefinitionTypeMessage = (actual) => `Type definitions must be strings or objects (was ${actual})`;
1318
+ var writeBadDefinitionTypeMessage = function (actual) { return `Type definitions must be strings or objects (was ${actual})${hasOwn4(badDefinitionHints, actual) ? badDefinitionHints[actual] : ""}` };
1319
+ var literalValueHint = ". Write a literal value in a string, or pass it to type.unit()";
1320
+ var badDefinitionHints = {
1321
+ Function: ". Write a class as type.instanceOf(MyClass) or a keyword like Date, and a predicate as .narrow(fn)",
1322
+ number: literalValueHint,
1323
+ bigint: literalValueHint,
1324
+ boolean: literalValueHint,
1325
+ null: literalValueHint,
1326
+ undefined: literalValueHint,
1327
+ symbol: literalValueHint
1328
+ };
1180
1329
 
1181
1330
  // out/type.js
1182
1331
  import { ArkErrors, BaseRoot as BaseRoot3, finalizeExport, GenericRoot as GenericRoot2 } from "@ark/schema";
@@ -2068,12 +2217,12 @@ var InternalScope = class InternalScope extends BaseScope {
2068
2217
  }
2069
2218
  keywordConfigOf(qualifiedName) {
2070
2219
  const { keywords } = this.cfg;
2071
- return hasOwn3(keywords, qualifiedName) ? keywords[qualifiedName] : void 0;
2220
+ return hasOwn5(keywords, qualifiedName) ? keywords[qualifiedName] : void 0;
2072
2221
  }
2073
2222
  preparseEntry(alias, def) {
2074
2223
  const firstParamIndex = alias.indexOf("<");
2075
2224
  if (firstParamIndex === -1) {
2076
- if (hasArkKind3(def, "module") || hasArkKind3(def, "generic"))
2225
+ if (hasArkKind4(def, "module") || hasArkKind4(def, "generic"))
2077
2226
  return [alias, def];
2078
2227
  const qualifiedName = this.name === "ark" ? alias : alias === "root" ? this.name : `${this.name}.${alias}`;
2079
2228
  const configured = (def2) => {
@@ -2086,7 +2235,7 @@ var InternalScope = class InternalScope extends BaseScope {
2086
2235
  alias,
2087
2236
  () => {
2088
2237
  const resolution = def();
2089
- if (hasArkKind3(resolution, "generic"))
2238
+ if (hasArkKind4(resolution, "generic"))
2090
2239
  return resolution;
2091
2240
  return configured(resolution);
2092
2241
  }
@@ -2096,7 +2245,7 @@ var InternalScope = class InternalScope extends BaseScope {
2096
2245
  throwParseError12(`'>' must be the last character of a generic declaration in a scope`);
2097
2246
  }
2098
2247
  const name = alias.slice(0, firstParamIndex);
2099
- if (hasArkKind3(def, "generic"))
2248
+ if (hasArkKind4(def, "generic"))
2100
2249
  throwParseError12(writeParameterizedGenericKeyMessage(name));
2101
2250
  const paramString = alias.slice(firstParamIndex + 1, -1);
2102
2251
  const genericName = name[0] === "#" ? name.slice(1) : name;
@@ -2115,7 +2264,7 @@ var InternalScope = class InternalScope extends BaseScope {
2115
2264
  }));
2116
2265
  }
2117
2266
  normValue(resolution) {
2118
- if (isThunk3(resolution) && !hasArkKind3(resolution, "generic"))
2267
+ if (isThunk3(resolution) && !hasArkKind4(resolution, "generic"))
2119
2268
  return resolution();
2120
2269
  return resolution;
2121
2270
  }
@@ -2301,9 +2450,12 @@ export {
2301
2450
  writeIncompatibleRangeMessage,
2302
2451
  getBoundKinds,
2303
2452
  parseRightBound,
2453
+ arrayIsNotGenericHint,
2304
2454
  writeInvalidLimitMessage,
2305
2455
  parseGenericArgs,
2306
2456
  writeInvalidGenericArgCountMessage,
2457
+ foreignAliases,
2458
+ writeUnresolvableHint,
2307
2459
  parseUnenclosed,
2308
2460
  limitOf,
2309
2461
  parseGenericInstantiation,
@@ -1,5 +1,5 @@
1
1
  // out/locales/de.js
2
- import { actualAtPathOf, describeCause, describeMissing, distinctExpectedOf, groupByPath, labelOf, writeKeywordExpected } from "@ark/schema/i18n";
2
+ import { actualAtPathOf, describeCause, describeMissing, distinctExpectedOf, groupByPath, labelOf, printedActualOf, writeKeywordExpected } from "@ark/schema/i18n";
3
3
  import { domainOf, getBuiltinNameOfConstructor, isValidDate, timeOf, listPattern, objectKindOrDomainOf, printable } from "@ark/util";
4
4
  var listSeparatedBy = (middle) => listPattern({ two: " oder ", middle, end: " oder " }, { two: " und ", middle, end: " und " });
5
5
  var commaList = /* @__PURE__ */ listSeparatedBy(", ");
@@ -41,8 +41,11 @@ var date = function (d) {
41
41
  var theDate = (date2, locale) => `der ${locale.date(date2)}`;
42
42
  var print = function (value, locale) { return value instanceof Date && isValidDate(value) ? theDate(value, locale) : locale.verbatim(typeof value === "number" ? locale.number(value) : printable(value)) };
43
43
  var printKind = function (data, locale) { return typeof data === "function" ? locale.nouns.Function : typeof data !== "object" || data === null ? print(data, locale) : locale.nouns[Array.isArray(data) ? "Array" : "object"] };
44
- var was = (actual) => actual && `, ist aber ${actual}`;
45
- var mustBe = (expected, actual) => `muss ${expected} sein${was(actual)}`;
44
+ var was = (e) => {
45
+ const actual = printedActualOf(e);
46
+ return actual && `, ist aber ${actual}`;
47
+ };
48
+ var mustBe = (expected, e) => `muss ${expected} sein${was(e)}`;
46
49
  var absent = "nicht vorhanden";
47
50
  var elements = (n, locale, dative) => `${locale.number(n)} ${locale.plural(n) === "one" ? "Element" : dative ? "Elementen" : "Elemente"}`;
48
51
  var length = function (n, data, locale, bound2 = "") { return typeof data === "string" ? `${bound2}${locale.number(n)} Zeichen lang` : `ein Array mit ${bound2}${elements(n, locale, true)}` };
@@ -53,28 +56,28 @@ var lengthBounds = {
53
56
  };
54
57
  var lengthExpected = function (e, locale) { return e.rule === 0 ? typeof e.data === "string" ? "leer" : "ein leeres Array" : length(e.rule, e.data, locale, `${lengthBounds[e.code]} `) };
55
58
  var lengthActual = (data, e, locale) => data.length ? length(data.length, data, locale) : e.code === "minLength" ? "" : "leer";
56
- var lengthProblem = function (e, locale) {
59
+ var lengthMessage = function (e, locale) {
57
60
  if (e.code === "minLength" && e.rule === 1)
58
- return `darf nicht leer sein${was(e.actual)}`;
61
+ return `darf nicht leer sein${was(e)}`;
59
62
  if (typeof e.data === "string")
60
- return mustBe(lengthExpected(e, locale), e.actual);
63
+ return mustBe(lengthExpected(e, locale), e);
61
64
  const rule = e.rule === 0 ? "muss leer sein" : `muss ${lengthBounds[e.code]} ${elements(e.rule, locale)} enthalten`;
62
- return e.data.length && e.actual === lengthActual(e.data, e, locale) ? `${rule}, enthält aber ${elements(e.data.length, locale)}` : `${rule}${was(e.actual)}`;
65
+ return `${rule}${was(e)}`;
63
66
  };
64
67
  var lengthWriters = {
65
68
  expected: lengthExpected,
66
69
  actual: lengthActual,
67
- problem: lengthProblem
70
+ message: lengthMessage
68
71
  };
69
72
  var subjectOf = function (propString, label, locale) { return label === void 0 ? propString[0] === "[" ? `Wert an ${locale.verbatim(propString)}` : locale.verbatim(propString) : /\[\d/.test(propString) ? `„${locale.verbatim(label)}“ an ${locale.verbatim(propString)}` : `„${locale.verbatim(label)}“` };
70
73
  var bound = function (e, locale) { return e.rule === 0 && e.exclusive ? e.code === "min" ? "positiv" : "negativ" : e.code === "min" ? `${e.exclusive ? "größer als" : "mindestens"} ${locale.number(e.rule)}` : `${e.exclusive ? "kleiner als" : "höchstens"} ${locale.number(e.rule)}` };
71
- var boundProblem = function (e, locale) { return e.rule === 0 && !e.exclusive ? `darf nicht ${e.code === "min" ? "negativ" : "positiv"} sein${was(e.actual)}` : mustBe(bound(e, locale), e.actual) };
74
+ var boundMessage = function (e, locale) { return e.rule === 0 && !e.exclusive ? `darf nicht ${e.code === "min" ? "negativ" : "positiv"} sein${was(e)}` : mustBe(bound(e, locale), e) };
72
75
  var dateWriters = function (relation) {
73
76
  const expected = (e, locale) => `${relation} ${theDate(e.rule, locale)}`;
74
77
  return {
75
78
  expected,
76
79
  actual: (data, e, locale) => print(data, locale),
77
- problem: (e, locale) => mustBe(expected(e, locale), e.actual)
80
+ message: (e, locale) => mustBe(expected(e, locale), e)
78
81
  };
79
82
  };
80
83
  var divisorOf = (rule, locale) => rule === 1 ? "eine ganze Zahl" : rule === 2 ? "gerade" : `ein Vielfaches von ${locale.number(rule)}`;
@@ -87,7 +90,7 @@ var describeProto = function (proto, locale) {
87
90
  const builtinName = getBuiltinNameOfConstructor(proto);
88
91
  return builtinName ? locale.nouns[builtinName] : `eine Instanz von ${locale.verbatim(proto.name)}`;
89
92
  };
90
- var jsonProblem = function (e, locale) { return e.code === "predicate" && e.cause !== void 0 ? `muss eine JSON-Zeichenkette sein (${describeCause(e.cause)})` : locale.problem(e, locale) };
93
+ var jsonMessage = function (e, locale) { return e.code === "predicate" && e.cause !== void 0 ? `muss eine JSON-Zeichenkette sein (${describeCause(e.cause)})` : locale.message(e, locale) };
91
94
  var epoch = "ein gültiger Unix-Zeitstempel als ganze Zahl";
92
95
  var keywordPhrases = {
93
96
  "FormData.parsed": "ein Objekt mit geparsten Formulardaten",
@@ -115,11 +118,11 @@ var keywordPhrases = {
115
118
  "string.ip": "eine IP-Adresse",
116
119
  "string.ip.v4": "eine IPv4-Adresse",
117
120
  "string.ip.v6": "eine IPv6-Adresse",
118
- "string.json": { noun: "eine JSON-Zeichenkette", problem: jsonProblem },
121
+ "string.json": { noun: "eine JSON-Zeichenkette", message: jsonMessage },
119
122
  "string.json.parse": {
120
123
  noun: "eine JSON-Zeichenkette",
121
124
  actual: (data, e, locale) => data === "" ? "leer" : print(data, locale),
122
- problem: jsonProblem
125
+ message: jsonMessage
123
126
  },
124
127
  "string.lower.preformatted": "kleingeschrieben",
125
128
  "string.normalize.NFC.preformatted": "NFC-normalisiert",
@@ -130,7 +133,7 @@ var keywordPhrases = {
130
133
  "string.numeric.parse": "endlich",
131
134
  "string.regex": {
132
135
  noun: "ein Regex-Muster",
133
- problem: function (e, locale) { return e.code === "predicate" && e.cause !== void 0 ? `muss ein Regex-Muster sein (${describeCause(e.cause)})` : locale.problem(e, locale) }
136
+ message: function (e, locale) { return e.code === "predicate" && e.cause !== void 0 ? `muss ein Regex-Muster sein (${describeCause(e.cause)})` : locale.message(e, locale) }
134
137
  },
135
138
  "string.semver": "eine semantische Version (siehe https://semver.org/)",
136
139
  "string.trim.preformatted": "ohne Leerraum am Anfang und Ende",
@@ -207,25 +210,25 @@ var de = {
207
210
  },
208
211
  keywordPhrases,
209
212
  actual: (data, e, locale) => printKind(data, locale),
210
- problem: (e) => mustBe(e.expected, e.actual),
211
- message: (e, locale) => e.path.length === 0 ? e.problem : `${subjectOf(e.propString, labelOf(e), locale)} ${e.problem}`,
213
+ message: (e) => mustBe(e.expected, e),
214
+ line: (e, locale) => `${subjectOf(e.propString, labelOf(e), locale)}${e.custom ? ":" : ""} ${e.message}`,
212
215
  domain: {
213
216
  expected: (e, locale) => locale.nouns[e.domain],
214
217
  actual: (data, e, locale) => typeof data === "number" && !Number.isFinite(data) ? `${data}` : locale.nouns[domainOf(data)],
215
- problem: (e, locale) => mustBe(locale.nouns[e.domain], e.actual)
218
+ message: (e, locale) => mustBe(locale.nouns[e.domain], e)
216
219
  },
217
220
  unit: {
218
221
  expected: (e, locale) => print(e.unit, locale),
219
222
  actual: (data, e, locale) => data instanceof Date && isValidDate(data) ? theDate(data, locale) : printKind(data, locale),
220
- problem: function (e, locale) {
223
+ message: function (e, locale) {
221
224
  const unit = print(e.unit, locale);
222
- return unit === e.actual ? `muss referenzgleich mit ${unit} sein (wird zum selben Wert serialisiert)` : mustBe(unit, e.actual);
225
+ return unit === printedActualOf(e) ? `muss referenzgleich mit ${unit} sein (wird zum selben Wert serialisiert)` : mustBe(unit, e);
223
226
  }
224
227
  },
225
228
  proto: {
226
229
  expected: (e, locale) => describeProto(e.proto, locale),
227
230
  actual: function (data, e, locale) { return !(data instanceof Date) || isValidDate(data) ? locale.nouns[objectKindOrDomainOf(data)] : timeOf(data) === void 0 ? locale.nouns.object : "ein ungültiges Date-Objekt" },
228
- problem: (e, locale) => mustBe(describeProto(e.proto, locale), e.actual)
231
+ message: (e, locale) => mustBe(describeProto(e.proto, locale), e)
229
232
  },
230
233
  union: {
231
234
  expected: function (e, locale) {
@@ -235,33 +238,32 @@ var de = {
235
238
  return locale.list(groups.map((group) => {
236
239
  const subject = group.propString && `${subjectOf(group.propString, group.label, locale)} `;
237
240
  const expected = locale.list(group.expected, "or");
238
- const actual = group.actual ?? printKind(group.data, locale);
239
- if (actual === absent)
241
+ if (group.actual === absent)
240
242
  return `${subject}fehlt (muss ${expected} sein)`;
241
- return groups.length === 1 ? `${subject}${mustBe(expected, actual)}` : `${subject}muss ${expected} sein${actual && ` (ist ${actual})`}`;
243
+ const actual = group.actual !== void 0 && e.errors.every((error) => error.propString !== group.propString || printedActualOf(error) === group.actual) ? group.actual : "";
244
+ return `${subject}muss ${expected} sein${actual && (groups.length === 1 ? `, ist aber ${actual}` : ` (ist ${actual})`)}`;
242
245
  }), "or");
243
246
  },
244
247
  actual: (data, e, locale) => actualAtPathOf(e) ?? printKind(data, locale),
245
- problem: (e) => e.errors.length ? e.expected : mustBe(e.expected, e.actual),
246
- message: (e, locale) => e.errors.length === 0 ? locale.message(e, locale) : e.problem
248
+ message: (e) => e.errors.length ? e.expected : mustBe(e.expected, e)
247
249
  },
248
250
  intersection: {
249
251
  expected: (e) => distinctExpectedOf(e.errors).length > 1 ? ` ◦ ${distinctExpectedOf(e.errors).join("\n ◦ ")}` : e.errors[0].expected,
250
- problem: function (e) { return distinctExpectedOf(e.errors).length > 1 ? `(${e.actual}) muss alles Folgende sein:
251
- ${e.expected}` : mustBe(e.expected, e.actual) }
252
+ message: function (e) { return distinctExpectedOf(e.errors).length > 1 ? `(${printedActualOf(e)}) muss alles Folgende sein:
253
+ ${e.expected}` : mustBe(e.expected, e) }
252
254
  },
253
- min: { expected: bound, problem: boundProblem },
254
- max: { expected: bound, problem: boundProblem },
255
+ min: { expected: bound, message: boundMessage },
256
+ max: { expected: bound, message: boundMessage },
255
257
  minLength: lengthWriters,
256
258
  maxLength: lengthWriters,
257
259
  exactLength: lengthWriters,
258
260
  divisor: {
259
261
  expected: (e, locale) => divisorOf(e.rule, locale),
260
- problem: (e, locale) => mustBe(divisorOf(e.rule, locale), e.actual)
262
+ message: (e, locale) => mustBe(divisorOf(e.rule, locale), e)
261
263
  },
262
264
  pattern: {
263
265
  expected: (e, locale) => `passend zum Muster ${locale.verbatim(e.rule)}`,
264
- problem: (e, locale) => `muss dem Muster ${locale.verbatim(e.rule)} entsprechen${was(e.actual)}`
266
+ message: (e, locale) => `muss dem Muster ${locale.verbatim(e.rule)} entsprechen${was(e)}`
265
267
  },
266
268
  before: dateWriters("spätestens"),
267
269
  after: dateWriters("frühestens"),
@@ -269,21 +271,21 @@ ${e.expected}` : mustBe(e.expected, e.actual) }
269
271
  // "ungleich" takes a dative
270
272
  expected: (e, locale) => `ungleich ${print(e.rule, locale).replace(/^der /, "dem ")}`,
271
273
  actual: (data, e, locale) => print(data, locale),
272
- problem: (e) => mustBe(e.expected, e.actual)
274
+ message: (e) => mustBe(e.expected, e)
273
275
  },
274
276
  notEqualLength: {
275
277
  expected: function (e, locale) { return typeof e.data === "string" ? `nicht ${length(e.rule, e.data, locale)}` : `kein Array mit ${elements(e.rule, locale, true)}` },
276
278
  actual: (data, e, locale) => length(data.length, data, locale),
277
279
  // "muss nicht" means "need not"
278
- problem: function (e, locale) { return `darf nicht ${typeof e.data === "string" ? `${length(e.rule, e.data, locale)} sein` : `${elements(e.rule, locale)} enthalten`}${was(e.actual)}` }
280
+ message: function (e, locale) { return `darf nicht ${typeof e.data === "string" ? `${length(e.rule, e.data, locale)} sein` : `${elements(e.rule, locale)} enthalten`}${was(e)}` }
279
281
  },
280
282
  predicate: {
281
283
  expected: predicateOf,
282
284
  actual: (data, e, locale) => e.morph ? `wegen eines Fehlers abgebrochen:
283
285
  ${describeCause(e.cause)}` : printKind(data, locale),
284
- problem: function (e, locale) {
286
+ message: function (e, locale) {
285
287
  if (!e.morph)
286
- return mustBe(predicateOf(e, locale), e.actual);
288
+ return mustBe(predicateOf(e, locale), e);
287
289
  const name = e.morph.name && `von ${locale.verbatim(e.morph.name)} `;
288
290
  return `konnte ${name}nicht verarbeitet werden:
289
291
  ${describeCause(e.cause)}`;
@@ -292,17 +294,17 @@ ${e.expected}` : mustBe(e.expected, e.actual) }
292
294
  required: {
293
295
  expected: (e, locale) => describeMissing(e.missing, locale),
294
296
  actual: absent,
295
- problem: (e, locale) => e.missing.code === "intersection" ? "fehlt" : `fehlt (muss ${describeMissing(e.missing, locale)} sein)`
297
+ message: (e, locale) => e.missing.code === "intersection" ? "fehlt" : `fehlt (muss ${describeMissing(e.missing, locale)} sein)`
296
298
  },
297
299
  undeclared: {
298
300
  expected: "entfernt",
299
301
  actual: "",
300
- problem: "ist nicht erlaubt"
302
+ message: "ist nicht erlaubt"
301
303
  },
302
304
  discriminant: {
303
305
  expected: casesOf,
304
306
  actual: (data, e, locale) => e.absent ? absent : e.discriminantKind === "domain" ? locale.nouns[domainOf(data)] : printKind(data, locale),
305
- problem: (e, locale) => e.absent ? `fehlt (muss ${casesOf(e, locale)} sein)` : mustBe(casesOf(e, locale), e.actual)
307
+ message: (e, locale) => e.absent ? `fehlt (muss ${casesOf(e, locale)} sein)` : mustBe(casesOf(e, locale), e)
306
308
  }
307
309
  };
308
310
 
@@ -0,0 +1,4 @@
1
+ // out/i18n.js
2
+ export { describeCause, describeMissing, groupByPath, labelOf, printedActualOf, writeKeywordExpected } from "@ark/schema/i18n";
3
+ export { isolate, listPattern } from "@ark/util";
4
+
@@ -1,5 +1,5 @@
1
1
  // out/index.js
2
- export { annotatingFallback, ArkErrors, byAncestorPath, byPath, flatByPath, firstIssue, flatProblemsByPath, messageIn, Traversal, TraversalError } from "@ark/schema";
2
+ export { annotatingFallback, ArkErrors, byAncestorPath, byPath, flatByPath, firstIssue, flatMessagesByPath, messageIn, Traversal, TraversalError } from "@ark/schema";
3
3
  export { Hkt, inferred, ParseError } from "@ark/util";
4
4
  export { regex } from "arkregex";
5
5