@atproto/lex-schema 0.0.13 → 0.0.15

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 (81) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/core/schema.d.ts +27 -35
  3. package/dist/core/schema.d.ts.map +1 -1
  4. package/dist/core/schema.js +73 -54
  5. package/dist/core/schema.js.map +1 -1
  6. package/dist/core/standard-schema.d.ts +14 -0
  7. package/dist/core/standard-schema.d.ts.map +1 -0
  8. package/dist/core/standard-schema.js +27 -0
  9. package/dist/core/standard-schema.js.map +1 -0
  10. package/dist/core/string-format.d.ts +4 -28
  11. package/dist/core/string-format.d.ts.map +1 -1
  12. package/dist/core/string-format.js +23 -17
  13. package/dist/core/string-format.js.map +1 -1
  14. package/dist/core/validation-error.d.ts +14 -6
  15. package/dist/core/validation-error.d.ts.map +1 -1
  16. package/dist/core/validation-error.js +18 -8
  17. package/dist/core/validation-error.js.map +1 -1
  18. package/dist/core/validation-issue.d.ts +15 -15
  19. package/dist/core/validation-issue.d.ts.map +1 -1
  20. package/dist/core/validation-issue.js +33 -29
  21. package/dist/core/validation-issue.js.map +1 -1
  22. package/dist/core/validator.d.ts +21 -18
  23. package/dist/core/validator.d.ts.map +1 -1
  24. package/dist/core/validator.js +5 -4
  25. package/dist/core/validator.js.map +1 -1
  26. package/dist/core.d.ts +0 -1
  27. package/dist/core.d.ts.map +1 -1
  28. package/dist/core.js +0 -1
  29. package/dist/core.js.map +1 -1
  30. package/dist/schema/custom.d.ts +1 -1
  31. package/dist/schema/custom.d.ts.map +1 -1
  32. package/dist/schema/custom.js.map +1 -1
  33. package/dist/schema/never.d.ts +1 -1
  34. package/dist/schema/nullable.d.ts +1 -1
  35. package/dist/schema/params.d.ts.map +1 -1
  36. package/dist/schema/params.js +4 -1
  37. package/dist/schema/params.js.map +1 -1
  38. package/dist/schema/record.d.ts +12 -6
  39. package/dist/schema/record.d.ts.map +1 -1
  40. package/dist/schema/record.js +21 -12
  41. package/dist/schema/record.js.map +1 -1
  42. package/dist/schema/ref.d.ts +1 -1
  43. package/dist/schema/ref.d.ts.map +1 -1
  44. package/dist/schema/ref.js.map +1 -1
  45. package/dist/schema/refine.d.ts +1 -1
  46. package/dist/schema/refine.d.ts.map +1 -1
  47. package/dist/schema/refine.js.map +1 -1
  48. package/dist/schema/typed-object.d.ts +12 -4
  49. package/dist/schema/typed-object.d.ts.map +1 -1
  50. package/dist/schema/typed-object.js +21 -12
  51. package/dist/schema/typed-object.js.map +1 -1
  52. package/dist/schema/typed-ref.d.ts +1 -1
  53. package/dist/schema/typed-union.d.ts +1 -1
  54. package/dist/schema/union.d.ts +2 -2
  55. package/dist/schema/union.d.ts.map +1 -1
  56. package/dist/schema/union.js +1 -1
  57. package/dist/schema/union.js.map +1 -1
  58. package/package.json +4 -3
  59. package/src/core/schema.ts +78 -69
  60. package/src/core/standard-schema.test.ts +124 -0
  61. package/src/core/standard-schema.ts +31 -0
  62. package/src/core/string-format.ts +26 -33
  63. package/src/core/validation-error.ts +25 -10
  64. package/src/core/validation-issue.ts +32 -32
  65. package/src/core/validator.ts +16 -12
  66. package/src/core.ts +0 -1
  67. package/src/schema/array.test.ts +2 -2
  68. package/src/schema/custom.ts +1 -7
  69. package/src/schema/params.test.ts +18 -2
  70. package/src/schema/params.ts +5 -2
  71. package/src/schema/record.ts +27 -22
  72. package/src/schema/ref.ts +1 -5
  73. package/src/schema/refine.ts +0 -1
  74. package/src/schema/typed-object.test.ts +38 -0
  75. package/src/schema/typed-object.ts +29 -24
  76. package/src/schema/union.ts +2 -2
  77. package/dist/core/property-key.d.ts +0 -2
  78. package/dist/core/property-key.d.ts.map +0 -1
  79. package/dist/core/property-key.js +0 -3
  80. package/dist/core/property-key.js.map +0 -1
  81. package/src/core/property-key.ts +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"string-format.d.ts","sourceRoot":"","sources":["../../src/core/string-format.ts"],"names":[],"mappings":"AACA,OAAO,EACL,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,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,EACzE,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,CAAC,GACR,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAIvC;AAED;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,EACrE,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,CAAC,GACR,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAGtB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,EACrE,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,CAAC,GACR,SAAS,GAAG,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAEpC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,EAEtB,SAAS,YAAY,EAAE,CAAA"}
1
+ {"version":3,"file":"string-format.d.ts","sourceRoot":"","sources":["../../src/core/string-format.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,SAAS,EACT,YAAY,EACZ,UAAU,EACV,eAAe,EACf,SAAS,EACT,SAAS,EAWV,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAWnD,OAAO,EACL,KAAK,kBAAkB,EACvB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAErE,OAAO,EACL,KAAK,cAAc,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM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SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,EACrE,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,CAAC,GACR,SAAS,GAAG,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAEpC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,EAEtB,SAAS,YAAY,EAAE,CAAA"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.STRING_FORMATS = exports.isUriString = exports.isTidString = exports.isRecordKeyString = exports.isNsidString = exports.isLanguageString = exports.isHandleString = exports.isDidString = exports.isDatetimeString = exports.isCidString = exports.isAtUriString = exports.isAtIdentifierString = void 0;
3
+ exports.STRING_FORMATS = exports.isUriString = exports.isTidString = exports.isRecordKeyString = exports.isNsidString = exports.isLanguageString = exports.isHandleString = exports.isDidString = exports.isCidString = exports.isAtUriString = exports.toDatetimeString = exports.currentDatetimeString = exports.isDatetimeString = exports.ifDatetimeString = exports.asDatetimeString = exports.isHandleIdentifier = exports.isDidIdentifier = exports.isAtIdentifierString = exports.ifAtIdentifierString = exports.asAtIdentifierString = void 0;
4
4
  exports.isStringFormat = isStringFormat;
5
5
  exports.assertStringFormat = assertStringFormat;
6
6
  exports.asStringFormat = asStringFormat;
@@ -10,13 +10,26 @@ const syntax_1 = require("@atproto/syntax");
10
10
  // -----------------------------------------------------------------------------
11
11
  // Individual string format types and type guards
12
12
  // -----------------------------------------------------------------------------
13
- /**
14
- * Type guard that checks if a value is a valid AT identifier (DID or handle).
15
- *
16
- * @param value - The value to check
17
- * @returns `true` if the value is a valid AT identifier
18
- */
19
- exports.isAtIdentifierString = syntax_1.isValidAtIdentifier;
13
+ // Re-exporting from @atproto/syntax without modification to preserve types and
14
+ // documentation for types and utilities that are already well-defined there.
15
+ // @TODO rework other string formats in @atproto/syntax to follow this pattern
16
+ // and re-export here, e.g. language tags, NSIDs, record keys, etc.
17
+ var syntax_2 = require("@atproto/syntax");
18
+ Object.defineProperty(exports, "asAtIdentifierString", { enumerable: true, get: function () { return syntax_2.asAtIdentifierString; } });
19
+ Object.defineProperty(exports, "ifAtIdentifierString", { enumerable: true, get: function () { return syntax_2.ifAtIdentifierString; } });
20
+ Object.defineProperty(exports, "isAtIdentifierString", { enumerable: true, get: function () { return syntax_2.isAtIdentifierString; } });
21
+ // AtIdentifierString utilities
22
+ var syntax_3 = require("@atproto/syntax");
23
+ Object.defineProperty(exports, "isDidIdentifier", { enumerable: true, get: function () { return syntax_3.isDidIdentifier; } });
24
+ Object.defineProperty(exports, "isHandleIdentifier", { enumerable: true, get: function () { return syntax_3.isHandleIdentifier; } });
25
+ var syntax_4 = require("@atproto/syntax");
26
+ Object.defineProperty(exports, "asDatetimeString", { enumerable: true, get: function () { return syntax_4.asDatetimeString; } });
27
+ Object.defineProperty(exports, "ifDatetimeString", { enumerable: true, get: function () { return syntax_4.ifDatetimeString; } });
28
+ Object.defineProperty(exports, "isDatetimeString", { enumerable: true, get: function () { return syntax_4.isDatetimeString; } });
29
+ // DatetimeString utilities
30
+ var syntax_5 = require("@atproto/syntax");
31
+ Object.defineProperty(exports, "currentDatetimeString", { enumerable: true, get: function () { return syntax_5.currentDatetimeString; } });
32
+ Object.defineProperty(exports, "toDatetimeString", { enumerable: true, get: function () { return syntax_5.toDatetimeString; } });
20
33
  /**
21
34
  * Type guard that checks if a value is a valid AT URI.
22
35
  *
@@ -31,13 +44,6 @@ exports.isAtUriString = syntax_1.isValidAtUri;
31
44
  * @returns `true` if the value is a valid CID string
32
45
  */
33
46
  exports.isCidString = ((v) => (0, lex_data_1.validateCidString)(v));
34
- /**
35
- * Type guard that checks if a value is a valid datetime string.
36
- *
37
- * @param value - The value to check
38
- * @returns `true` if the value is a valid datetime string
39
- */
40
- exports.isDatetimeString = syntax_1.isValidDatetime;
41
47
  /**
42
48
  * Type guard that checks if a value is a valid DID string.
43
49
  *
@@ -89,10 +95,10 @@ exports.isTidString = syntax_1.isValidTid;
89
95
  exports.isUriString = syntax_1.isValidUri;
90
96
  const stringFormatVerifiers = /*#__PURE__*/ Object.freeze({
91
97
  __proto__: null,
92
- 'at-identifier': exports.isAtIdentifierString,
98
+ 'at-identifier': syntax_1.isAtIdentifierString,
93
99
  'at-uri': exports.isAtUriString,
94
100
  cid: exports.isCidString,
95
- datetime: exports.isDatetimeString,
101
+ datetime: syntax_1.isDatetimeString,
96
102
  did: exports.isDidString,
97
103
  handle: exports.isHandleString,
98
104
  language: exports.isLanguageString,
@@ -1 +1 @@
1
- {"version":3,"file":"string-format.js","sourceRoot":"","sources":["../../src/core/string-format.ts"],"names":[],"mappings":";;;AA2RA,wCASC;AAkBD,gDAOC;AAqBD,wCAMC;AAuBD,wCAKC;AApXD,gDAAqD;AACrD,4CAoBwB;AAGxB,gFAAgF;AAChF,iDAAiD;AACjD,gFAAgF;AAEhF;;;;;GAKG;AACU,QAAA,oBAAoB,GAAgC,4BAAW,CAAA;AAU5E;;;;;GAKG;AACU,QAAA,aAAa,GAAyB,qBAAY,CAAA;AAU/D;;;;;GAKG;AACU,QAAA,WAAW,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,4BAAiB,EAAC,CAAC,CAAC,CAAuB,CAAA;AAU9E;;;;;GAKG;AACU,QAAA,gBAAgB,GAA4B,wBAAe,CAAA;AAUxE;;;;;GAKG;AACU,QAAA,WAAW,GAAuB,mBAAU,CAAA;AAYzD;;;;;GAKG;AACU,QAAA,cAAc,GAA0B,sBAAa,CAAA;AAUlE;;;;;GAKG;AACU,QAAA,gBAAgB,GAAG,wBAA0C,CAAA;AAQ1E;;;;;GAKG;AACU,QAAA,YAAY,GAAwB,oBAAW,CAAA;AAY5D;;;;;GAKG;AACU,QAAA,iBAAiB,GAA6B,yBAAgB,CAAA;AAU3E;;;;;GAKG;AACU,QAAA,WAAW,GAAuB,mBAAU,CAAA;AAYzD;;;;;GAKG;AACU,QAAA,WAAW,GAAuB,mBAAU,CAAA;AAiCzD,MAAM,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,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;AAC1D,CAAC;AAED;;;;;;;;;GASG;AACU,QAAA,cAAc,GAAiB,MAAM,CAAC,MAAM;AACvD,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CACtB,CAAA","sourcesContent":["import { validateCidString } from '@atproto/lex-data'\nimport {\n AtIdentifierString,\n AtUriString,\n DatetimeString,\n DidString,\n HandleString,\n NsidString,\n RecordKeyString,\n TidString,\n UriString,\n isValidAtIdentifier as isValidAtId,\n isValidAtUri,\n isValidDatetime,\n isValidDid,\n isValidHandle,\n isValidLanguage,\n isValidNsid,\n isValidRecordKey,\n isValidTid,\n isValidUri,\n} from '@atproto/syntax'\nimport { CheckFn } from '../util/assertion-util.js'\n\n// -----------------------------------------------------------------------------\n// Individual string format types and type guards\n// -----------------------------------------------------------------------------\n\n/**\n * Type guard that checks if a value is a valid AT identifier (DID or handle).\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid AT identifier\n */\nexport const isAtIdentifierString: CheckFn<AtIdentifierString> = isValidAtId\nexport type {\n /**\n * An AT identifier string - either a DID or a handle.\n *\n * @example `\"did:plc:1234...\"` or `\"alice.bsky.social\"`\n */\n AtIdentifierString,\n}\n\n/**\n * Type guard that checks if a value is a valid AT URI.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid AT URI\n */\nexport const isAtUriString: CheckFn<AtUriString> = isValidAtUri\nexport type {\n /**\n * An AT URI string pointing to a resource in the AT Protocol network.\n *\n * @example `\"at://did:plc:1234.../app.bsky.feed.post/3k2...\"`\n */\n AtUriString,\n}\n\n/**\n * Type guard that checks if a value is a valid CID string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid CID string\n */\nexport const isCidString = ((v) => validateCidString(v)) as CheckFn<CidString>\n/**\n * A Content Identifier (CID) string.\n *\n * CIDs are self-describing content addresses used to identify data by its hash.\n *\n * @example `\"bafyreig...\"`\n */\nexport type CidString = string\n\n/**\n * Type guard that checks if a value is a valid datetime string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid datetime string\n */\nexport const isDatetimeString: CheckFn<DatetimeString> = isValidDatetime\nexport type {\n /**\n * An ISO 8601 datetime string.\n *\n * @example `\"2024-01-15T12:30:00.000Z\"`\n */\n DatetimeString,\n}\n\n/**\n * Type guard that checks if a value is a valid DID string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid DID string\n */\nexport const isDidString: CheckFn<DidString> = isValidDid\nexport type {\n /**\n * A Decentralized Identifier (DID) string.\n *\n * DIDs are globally unique identifiers that don't require a central authority.\n *\n * @example `\"did:plc:1234abcd...\"` or `\"did:web:example.com\"`\n */\n DidString,\n}\n\n/**\n * Type guard that checks if a value is a valid handle string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid handle string\n */\nexport const isHandleString: CheckFn<HandleString> = isValidHandle\nexport type {\n /**\n * A handle string - a human-readable identifier for users.\n *\n * @example `\"alice.bsky.social\"` or `\"bob.example.com\"`\n */\n HandleString,\n}\n\n/**\n * Type guard that checks if a value is a valid BCP-47 language tag.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid language string\n */\nexport const isLanguageString = isValidLanguage as CheckFn<LanguageString>\n/**\n * A BCP-47 language tag string.\n *\n * @example `\"en\"`, `\"en-US\"`, `\"zh-Hans\"`\n */\nexport type LanguageString = string\n\n/**\n * Type guard that checks if a value is a valid NSID string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid NSID string\n */\nexport const isNsidString: CheckFn<NsidString> = isValidNsid\nexport type {\n /**\n * A Namespaced Identifier (NSID) string identifying a lexicon.\n *\n * NSIDs use reverse-domain notation to identify schemas.\n *\n * @example `\"app.bsky.feed.post\"`, `\"com.atproto.repo.createRecord\"`\n */\n NsidString,\n}\n\n/**\n * Type guard that checks if a value is a valid record key string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid record key string\n */\nexport const isRecordKeyString: CheckFn<RecordKeyString> = isValidRecordKey\nexport type {\n /**\n * A record key string identifying a record within a collection.\n *\n * @example `\"3k2...\"` (TID format) or `\"self\"` (literal key)\n */\n RecordKeyString,\n}\n\n/**\n * Type guard that checks if a value is a valid TID string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid TID string\n */\nexport const isTidString: CheckFn<TidString> = isValidTid\nexport type {\n /**\n * A Timestamp Identifier (TID) string.\n *\n * TIDs are time-based identifiers used for record keys.\n *\n * @example `\"3k2...\"`\n */\n TidString,\n}\n\n/**\n * Type guard that checks if a value is a valid URI string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid URI string\n */\nexport const isUriString: CheckFn<UriString> = isValidUri\nexport type {\n /**\n * A standard URI string.\n *\n * @example `\"https://example.com/path\"`\n */\n UriString,\n}\n\n// -----------------------------------------------------------------------------\n// String format registry\n// -----------------------------------------------------------------------------\n\ntype StringFormats = {\n 'at-identifier': AtIdentifierString\n 'at-uri': AtUriString\n cid: CidString\n datetime: DatetimeString\n did: DidString\n handle: HandleString\n language: LanguageString\n nsid: NsidString\n 'record-key': RecordKeyString\n tid: TidString\n uri: UriString\n}\n\n/**\n * Union type of all valid string format names.\n */\nexport type StringFormat = Extract<keyof StringFormats, string>\n\nconst stringFormatVerifiers: {\n readonly [K in StringFormat]: CheckFn<StringFormats[K]>\n} = /*#__PURE__*/ Object.freeze({\n __proto__: null,\n\n 'at-identifier': isAtIdentifierString,\n 'at-uri': isAtUriString,\n cid: isCidString,\n datetime: isDatetimeString,\n did: isDidString,\n handle: isHandleString,\n language: isLanguageString,\n nsid: isNsidString,\n 'record-key': isRecordKeyString,\n tid: isTidString,\n uri: isUriString,\n})\n\n/**\n * Infers the string type for a given format name.\n *\n * @typeParam F - The format name\n *\n * @example\n * ```typescript\n * type Did = InferStringFormat<'did'>\n * // Result: DidString\n * ```\n */\nexport type InferStringFormat<F extends StringFormat> = F extends StringFormat\n ? StringFormats[F]\n : never\n\n/**\n * Type guard that checks if a string matches a specific format.\n *\n * @typeParam I - The input string type\n * @typeParam F - The format to check\n * @param input - The string to validate\n * @param format - The format name to validate against\n * @returns `true` if the string matches the format\n *\n * @example\n * ```typescript\n * const value: string = 'did:plc:1234...'\n * if (isStringFormat(value, 'did')) {\n * // value is typed as DidString\n * console.log('Valid DID:', value)\n * }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isStringFormat<I extends string, F extends StringFormat>(\n input: I,\n format: F,\n): input is I & StringFormats[F] {\n const formatVerifier = stringFormatVerifiers[format]\n // Fool-proof\n if (!formatVerifier) throw new TypeError(`Unknown string format: ${format}`)\n\n return formatVerifier(input)\n}\n\n/**\n * Asserts that a string matches a specific format, throwing if invalid.\n *\n * @typeParam I - The input string type\n * @typeParam F - The format to check\n * @param input - The string to validate\n * @param format - The format name to validate against\n * @throws {TypeError} If the string doesn't match the format\n *\n * @example\n * ```typescript\n * assertStringFormat(value, 'handle')\n * // value is now typed as HandleString\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function assertStringFormat<I extends string, F extends StringFormat>(\n input: I,\n format: F,\n): asserts input is I & StringFormats[F] {\n if (!isStringFormat(input, format)) {\n throw new TypeError(`Invalid string format (${format}): ${input}`)\n }\n}\n\n/**\n * Validates and returns a string as the specified format type, throwing if invalid.\n *\n * This is useful when you need to convert a string to a format type in an expression.\n *\n * @typeParam I - The input string type\n * @typeParam F - The format to validate against\n * @param input - The string to validate\n * @param format - The format name to validate against\n * @returns The input typed as the format type\n * @throws {TypeError} If the string doesn't match the format\n *\n * @example\n * ```typescript\n * const did = asStringFormat(userInput, 'did')\n * // did is typed as DidString\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function asStringFormat<I extends string, F extends StringFormat>(\n input: I,\n format: F,\n): I & StringFormats[F] {\n assertStringFormat(input, format)\n return input\n}\n\n/**\n * Returns the string as the format type if valid, otherwise returns `undefined`.\n *\n * This is useful for optional validation where you want to handle invalid values\n * without throwing.\n *\n * @typeParam I - The input string type\n * @typeParam F - The format to validate against\n * @param input - The string to validate\n * @param format - The format name to validate against\n * @returns The typed string if valid, otherwise `undefined`\n *\n * @example\n * ```typescript\n * const did = ifStringFormat(maybeInvalid, 'did')\n * if (did) {\n * // did is typed as DidString\n * }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function ifStringFormat<I extends string, F extends StringFormat>(\n input: I,\n format: F,\n): undefined | (I & StringFormats[F]) {\n return isStringFormat(input, format) ? input : undefined\n}\n\n/**\n * Array of all valid string format names.\n *\n * @example\n * ```typescript\n * for (const format of STRING_FORMATS) {\n * console.log(format) // 'at-identifier', 'at-uri', 'cid', ...\n * }\n * ```\n */\nexport const STRING_FORMATS = /*#__PURE__*/ Object.freeze(\n /*#__PURE__*/ Object.keys(stringFormatVerifiers),\n) as readonly StringFormat[]\n"]}
1
+ {"version":3,"file":"string-format.js","sourceRoot":"","sources":["../../src/core/string-format.ts"],"names":[],"mappings":";;;AAoRA,wCASC;AAkBD,gDAOC;AAqBD,wCAMC;AAuBD,wCAKC;AA7WD,gDAAqD;AACrD,4CAoBwB;AAGxB,gFAAgF;AAChF,iDAAiD;AACjD,gFAAgF;AAEhF,+EAA+E;AAC/E,6EAA6E;AAC7E,8EAA8E;AAC9E,mEAAmE;AAEnE,0CAKwB;AAHtB,8GAAA,oBAAoB,OAAA;AACpB,8GAAA,oBAAoB,OAAA;AACpB,8GAAA,oBAAoB,OAAA;AAGtB,+BAA+B;AAC/B,0CAAqE;AAA5D,yGAAA,eAAe,OAAA;AAAE,4GAAA,kBAAkB,OAAA;AAE5C,0CAKwB;AAHtB,0GAAA,gBAAgB,OAAA;AAChB,0GAAA,gBAAgB,OAAA;AAChB,0GAAA,gBAAgB,OAAA;AAGlB,2BAA2B;AAC3B,0CAAyE;AAAhE,+GAAA,qBAAqB,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAEhD;;;;;GAKG;AACU,QAAA,aAAa,GAAyB,qBAAY,CAAA;AAU/D;;;;;GAKG;AACU,QAAA,WAAW,GAAG,C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AkB,CAChC,KAAQ,EACR,MAAS;IAET,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,SAAS,CAAC,0BAA0B,MAAM,MAAM,KAAK,EAAE,CAAC,CAAA;IACpE,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAwB;AACxB,SAAgB,cAAc,CAC5B,KAAQ,EACR,MAAS;IAET,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IACjC,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAwB;AACxB,SAAgB,cAAc,CAC5B,KAAQ,EACR,MAAS;IAET,OAAO,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;AAC1D,CAAC;AAED;;;;;;;;;GASG;AACU,QAAA,cAAc,GAAiB,MAAM,CAAC,MAAM;AACvD,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CACtB,CAAA","sourcesContent":["import { validateCidString } from '@atproto/lex-data'\nimport {\n AtIdentifierString,\n AtUriString,\n DatetimeString,\n DidString,\n HandleString,\n NsidString,\n RecordKeyString,\n TidString,\n UriString,\n isAtIdentifierString,\n isDatetimeString,\n isValidAtUri,\n isValidDid,\n isValidHandle,\n isValidLanguage,\n isValidNsid,\n isValidRecordKey,\n isValidTid,\n isValidUri,\n} from '@atproto/syntax'\nimport { CheckFn } from '../util/assertion-util.js'\n\n// -----------------------------------------------------------------------------\n// Individual string format types and type guards\n// -----------------------------------------------------------------------------\n\n// Re-exporting from @atproto/syntax without modification to preserve types and\n// documentation for types and utilities that are already well-defined there.\n// @TODO rework other string formats in @atproto/syntax to follow this pattern\n// and re-export here, e.g. language tags, NSIDs, record keys, etc.\n\nexport {\n type AtIdentifierString,\n asAtIdentifierString,\n ifAtIdentifierString,\n isAtIdentifierString,\n} from '@atproto/syntax'\n\n// AtIdentifierString utilities\nexport { isDidIdentifier, isHandleIdentifier } from '@atproto/syntax'\n\nexport {\n type DatetimeString,\n asDatetimeString,\n ifDatetimeString,\n isDatetimeString,\n} from '@atproto/syntax'\n\n// DatetimeString utilities\nexport { currentDatetimeString, toDatetimeString } from '@atproto/syntax'\n\n/**\n * Type guard that checks if a value is a valid AT URI.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid AT URI\n */\nexport const isAtUriString: CheckFn<AtUriString> = isValidAtUri\nexport type {\n /**\n * An AT URI string pointing to a resource in the AT Protocol network.\n *\n * @example `\"at://did:plc:1234.../app.bsky.feed.post/3k2...\"`\n */\n AtUriString,\n}\n\n/**\n * Type guard that checks if a value is a valid CID string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid CID string\n */\nexport const isCidString = ((v) => validateCidString(v)) as CheckFn<CidString>\n/**\n * A Content Identifier (CID) string.\n *\n * CIDs are self-describing content addresses used to identify data by its hash.\n *\n * @example `\"bafyreig...\"`\n */\nexport type CidString = string\n\n/**\n * Type guard that checks if a value is a valid DID string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid DID string\n */\nexport const isDidString: CheckFn<DidString> = isValidDid\nexport type {\n /**\n * A Decentralized Identifier (DID) string.\n *\n * DIDs are globally unique identifiers that don't require a central authority.\n *\n * @example `\"did:plc:1234abcd...\"` or `\"did:web:example.com\"`\n */\n DidString,\n}\n\n/**\n * Type guard that checks if a value is a valid handle string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid handle string\n */\nexport const isHandleString: CheckFn<HandleString> = isValidHandle\nexport type {\n /**\n * A handle string - a human-readable identifier for users.\n *\n * @example `\"alice.bsky.social\"` or `\"bob.example.com\"`\n */\n HandleString,\n}\n\n/**\n * Type guard that checks if a value is a valid BCP-47 language tag.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid language string\n */\nexport const isLanguageString = isValidLanguage as CheckFn<LanguageString>\n/**\n * A BCP-47 language tag string.\n *\n * @example `\"en\"`, `\"en-US\"`, `\"zh-Hans\"`\n */\nexport type LanguageString = string\n\n/**\n * Type guard that checks if a value is a valid NSID string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid NSID string\n */\nexport const isNsidString: CheckFn<NsidString> = isValidNsid\nexport type {\n /**\n * A Namespaced Identifier (NSID) string identifying a lexicon.\n *\n * NSIDs use reverse-domain notation to identify schemas.\n *\n * @example `\"app.bsky.feed.post\"`, `\"com.atproto.repo.createRecord\"`\n */\n NsidString,\n}\n\n/**\n * Type guard that checks if a value is a valid record key string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid record key string\n */\nexport const isRecordKeyString: CheckFn<RecordKeyString> = isValidRecordKey\nexport type {\n /**\n * A record key string identifying a record within a collection.\n *\n * @example `\"3k2...\"` (TID format) or `\"self\"` (literal key)\n */\n RecordKeyString,\n}\n\n/**\n * Type guard that checks if a value is a valid TID string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid TID string\n */\nexport const isTidString: CheckFn<TidString> = isValidTid\nexport type {\n /**\n * A Timestamp Identifier (TID) string.\n *\n * TIDs are time-based identifiers used for record keys.\n *\n * @example `\"3k2...\"`\n */\n TidString,\n}\n\n/**\n * Type guard that checks if a value is a valid URI string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid URI string\n */\nexport const isUriString: CheckFn<UriString> = isValidUri\nexport type {\n /**\n * A standard URI string.\n *\n * @example `\"https://example.com/path\"`\n */\n UriString,\n}\n\n// -----------------------------------------------------------------------------\n// String format registry\n// -----------------------------------------------------------------------------\n\ntype StringFormats = {\n 'at-identifier': AtIdentifierString\n 'at-uri': AtUriString\n cid: CidString\n datetime: DatetimeString\n did: DidString\n handle: HandleString\n language: LanguageString\n nsid: NsidString\n 'record-key': RecordKeyString\n tid: TidString\n uri: UriString\n}\n\n/**\n * Union type of all valid string format names.\n */\nexport type StringFormat = Extract<keyof StringFormats, string>\n\nconst stringFormatVerifiers: {\n readonly [K in StringFormat]: CheckFn<StringFormats[K]>\n} = /*#__PURE__*/ Object.freeze({\n __proto__: null,\n\n 'at-identifier': isAtIdentifierString,\n 'at-uri': isAtUriString,\n cid: isCidString,\n datetime: isDatetimeString,\n did: isDidString,\n handle: isHandleString,\n language: isLanguageString,\n nsid: isNsidString,\n 'record-key': isRecordKeyString,\n tid: isTidString,\n uri: isUriString,\n})\n\n/**\n * Infers the string type for a given format name.\n *\n * @typeParam F - The format name\n *\n * @example\n * ```typescript\n * type Did = InferStringFormat<'did'>\n * // Result: DidString\n * ```\n */\nexport type InferStringFormat<F extends StringFormat> = F extends StringFormat\n ? StringFormats[F]\n : never\n\n/**\n * Type guard that checks if a string matches a specific format.\n *\n * @typeParam I - The input string type\n * @typeParam F - The format to check\n * @param input - The string to validate\n * @param format - The format name to validate against\n * @returns `true` if the string matches the format\n *\n * @example\n * ```typescript\n * const value: string = 'did:plc:1234...'\n * if (isStringFormat(value, 'did')) {\n * // value is typed as DidString\n * console.log('Valid DID:', value)\n * }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isStringFormat<I extends string, F extends StringFormat>(\n input: I,\n format: F,\n): input is I & StringFormats[F] {\n const formatVerifier = stringFormatVerifiers[format]\n // Fool-proof\n if (!formatVerifier) throw new TypeError(`Unknown string format: ${format}`)\n\n return formatVerifier(input)\n}\n\n/**\n * Asserts that a string matches a specific format, throwing if invalid.\n *\n * @typeParam I - The input string type\n * @typeParam F - The format to check\n * @param input - The string to validate\n * @param format - The format name to validate against\n * @throws {TypeError} If the string doesn't match the format\n *\n * @example\n * ```typescript\n * assertStringFormat(value, 'handle')\n * // value is now typed as HandleString\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function assertStringFormat<I extends string, F extends StringFormat>(\n input: I,\n format: F,\n): asserts input is I & StringFormats[F] {\n if (!isStringFormat(input, format)) {\n throw new TypeError(`Invalid string format (${format}): ${input}`)\n }\n}\n\n/**\n * Validates and returns a string as the specified format type, throwing if invalid.\n *\n * This is useful when you need to convert a string to a format type in an expression.\n *\n * @typeParam I - The input string type\n * @typeParam F - The format to validate against\n * @param input - The string to validate\n * @param format - The format name to validate against\n * @returns The input typed as the format type\n * @throws {TypeError} If the string doesn't match the format\n *\n * @example\n * ```typescript\n * const did = asStringFormat(userInput, 'did')\n * // did is typed as DidString\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function asStringFormat<I extends string, F extends StringFormat>(\n input: I,\n format: F,\n): I & StringFormats[F] {\n assertStringFormat(input, format)\n return input\n}\n\n/**\n * Returns the string as the format type if valid, otherwise returns `undefined`.\n *\n * This is useful for optional validation where you want to handle invalid values\n * without throwing.\n *\n * @typeParam I - The input string type\n * @typeParam F - The format to validate against\n * @param input - The string to validate\n * @param format - The format name to validate against\n * @returns The typed string if valid, otherwise `undefined`\n *\n * @example\n * ```typescript\n * const did = ifStringFormat(maybeInvalid, 'did')\n * if (did) {\n * // did is typed as DidString\n * }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function ifStringFormat<I extends string, F extends StringFormat>(\n input: I,\n format: F,\n): undefined | (I & StringFormats[F]) {\n return isStringFormat(input, format) ? input : undefined\n}\n\n/**\n * Array of all valid string format names.\n *\n * @example\n * ```typescript\n * for (const format of STRING_FORMATS) {\n * console.log(format) // 'at-identifier', 'at-uri', 'cid', ...\n * }\n * ```\n */\nexport const STRING_FORMATS = /*#__PURE__*/ Object.freeze(\n /*#__PURE__*/ Object.keys(stringFormatVerifiers),\n) as readonly StringFormat[]\n"]}
@@ -13,7 +13,7 @@ import { Issue } from './validation-issue.js';
13
13
  *
14
14
  * @example
15
15
  * ```typescript
16
- * const error = new ValidationError([
16
+ * const error = new LexValidationError([
17
17
  * new IssueInvalidType(['user', 'age'], 'hello', ['number'])
18
18
  * ])
19
19
  * console.log(error.message)
@@ -23,8 +23,12 @@ import { Issue } from './validation-issue.js';
23
23
  * console.log(error.toJSON())
24
24
  * // { error: 'InvalidRequest', message: '...', issues: [...] }
25
25
  * ```
26
+ *
27
+ * @note this class implements {@link ResultFailure} to allow it to be used
28
+ * directly as a failure reason in validation results, avoiding the need for
29
+ * wrapping it in an additional object.
26
30
  */
27
- export declare class ValidationError extends LexError {
31
+ export declare class LexValidationError extends LexError<'InvalidRequest'> implements ResultFailure<LexValidationError> {
28
32
  name: string;
29
33
  /**
30
34
  * The list of validation issues that caused this error.
@@ -43,15 +47,19 @@ export declare class ValidationError extends LexError {
43
47
  * @param options - Standard Error options (e.g., `cause`)
44
48
  */
45
49
  constructor(issues: Issue[], options?: ErrorOptions);
50
+ /** @see {ResultFailure.success} */
51
+ readonly success: false;
52
+ /** @see {ResultFailure.reason} */
53
+ get reason(): this;
46
54
  /**
47
55
  * Converts the error to a JSON-serializable object.
48
56
  *
49
- * @returns An object containing the error details and all issues in JSON format
57
+ * @returns An object containing the error details and issues details
50
58
  */
51
59
  toJSON(): {
52
60
  issues: {
53
61
  code: string;
54
- path: readonly import("./property-key.js").PropertyKey[];
62
+ path: readonly PropertyKey[];
55
63
  message: string;
56
64
  }[];
57
65
  error: import("@atproto/lex-data").LexErrorCode;
@@ -70,10 +78,10 @@ export declare class ValidationError extends LexError {
70
78
  * ```typescript
71
79
  * const failures = schemas.map(s => s.safeValidate(data)).filter(r => !r.success)
72
80
  * if (failures.length === schemas.length) {
73
- * throw ValidationError.fromFailures(failures)
81
+ * throw LexValidationError.fromFailures(failures)
74
82
  * }
75
83
  * ```
76
84
  */
77
- static fromFailures(failures: ResultFailure<ValidationError>[]): ValidationError;
85
+ static fromFailures(failures: readonly ResultFailure<LexValidationError>[]): LexValidationError;
78
86
  }
79
87
  //# sourceMappingURL=validation-error.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation-error.d.ts","sourceRoot":"","sources":["../../src/core/validation-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE5C,OAAO,EAAE,aAAa,EAAiB,MAAM,aAAa,CAAA;AAC1D,OA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"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidationError = void 0;
3
+ exports.LexValidationError = void 0;
4
4
  const lex_data_1 = require("@atproto/lex-data");
5
5
  const array_agg_js_1 = require("../util/array-agg.js");
6
6
  const result_js_1 = require("./result.js");
@@ -17,7 +17,7 @@ const validation_issue_js_1 = require("./validation-issue.js");
17
17
  *
18
18
  * @example
19
19
  * ```typescript
20
- * const error = new ValidationError([
20
+ * const error = new LexValidationError([
21
21
  * new IssueInvalidType(['user', 'age'], 'hello', ['number'])
22
22
  * ])
23
23
  * console.log(error.message)
@@ -27,9 +27,13 @@ const validation_issue_js_1 = require("./validation-issue.js");
27
27
  * console.log(error.toJSON())
28
28
  * // { error: 'InvalidRequest', message: '...', issues: [...] }
29
29
  * ```
30
+ *
31
+ * @note this class implements {@link ResultFailure} to allow it to be used
32
+ * directly as a failure reason in validation results, avoiding the need for
33
+ * wrapping it in an additional object.
30
34
  */
31
- class ValidationError extends lex_data_1.LexError {
32
- name = 'ValidationError';
35
+ class LexValidationError extends lex_data_1.LexError {
36
+ name = 'LexValidationError';
33
37
  /**
34
38
  * The list of validation issues that caused this error.
35
39
  *
@@ -51,10 +55,16 @@ class ValidationError extends lex_data_1.LexError {
51
55
  super('InvalidRequest', issuesAgg.join(', '), options);
52
56
  this.issues = issuesAgg;
53
57
  }
58
+ /** @see {ResultFailure.success} */
59
+ success = false;
60
+ /** @see {ResultFailure.reason} */
61
+ get reason() {
62
+ return this;
63
+ }
54
64
  /**
55
65
  * Converts the error to a JSON-serializable object.
56
66
  *
57
- * @returns An object containing the error details and all issues in JSON format
67
+ * @returns An object containing the error details and issues details
58
68
  */
59
69
  toJSON() {
60
70
  return {
@@ -75,7 +85,7 @@ class ValidationError extends lex_data_1.LexError {
75
85
  * ```typescript
76
86
  * const failures = schemas.map(s => s.safeValidate(data)).filter(r => !r.success)
77
87
  * if (failures.length === schemas.length) {
78
- * throw ValidationError.fromFailures(failures)
88
+ * throw LexValidationError.fromFailures(failures)
79
89
  * }
80
90
  * ```
81
91
  */
@@ -83,13 +93,13 @@ class ValidationError extends lex_data_1.LexError {
83
93
  if (failures.length === 1)
84
94
  return (0, result_js_1.failureReason)(failures[0]);
85
95
  const issues = failures.flatMap(extractFailureIssues);
86
- return new ValidationError(issues, {
96
+ return new LexValidationError(issues, {
87
97
  // Keep the original errors as the cause chain
88
98
  cause: failures.map(result_js_1.failureReason),
89
99
  });
90
100
  }
91
101
  }
92
- exports.ValidationError = ValidationError;
102
+ exports.LexValidationError = LexValidationError;
93
103
  function extractFailureIssues(result) {
94
104
  return result.reason.issues;
95
105
  }
@@ -1 +1 @@
1
- {"version":3,"file":"validation-error.js","sourceRoot":"","sources":["../../src/core/validation-error.ts"],"names":[],"mappings":";;;AAAA,gDAA4C;AAC5C,uDAA+C;AAC/C,2CAA0D;AAC1D,+DAI8B;AAE9B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,eAAgB,SAAQ,mBAAQ;IAC3C,IAAI,GAAG,iBAAiB,CAAA;IAExB;;;;;OAKG;IACM,MAAM,CAAS;IAExB;;;;;;;;OAQG;IACH,YAAY,MAAe,EAAE,OAAsB;QACjD,MAAM,SAAS,GAAG,eAAe,CAAC,MAAM,CAAC,CAAA;QACzC,KAAK,CAAC,gBAAgB,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAA;QACtD,IAAI,CAAC,MAAM,GAAG,SAAS,CAAA;IACzB,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,OAAO;YACL,GAAG,KAAK,CAAC,MAAM,EAAE;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;SACnD,CAAA;IACH,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,YAAY,CACjB,QAA0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3D,CACJ;QACD,+CAA+C;QAC/C,GAAG,IAAA,uBAAQ,EACT,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,YAAY,uCAAiB,CAAC,EAC5D,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,EAC9C,CAAC,MAAM,EAAE,EAAE,CACT,IAAI,uCAAiB,CACnB,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EACd,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,EACf,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CACzD,CACJ;QACD,4BAA4B;QAC5B,GAAG,MAAM,CAAC,MAAM,CACd,CAAC,KAAK,EAAE,EAAE,CACR,CAAC,CAAC,KAAK,YAAY,sCAAgB,CAAC;YACpC,CAAC,CAAC,KAAK,YAAY,uCAAiB,CAAC,CACxC;KACF,CAAA;AACH,CAAC;AAED,wBAAwB;AACxB,SAAS,oBAAoB,CAC3B,CAAyB,EACzB,CAAyB;IAEzB,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAA;IACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAA;IACjC,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { LexError } from '@atproto/lex-data'\nimport { arrayAgg } from '../util/array-agg.js'\nimport { ResultFailure, failureReason } from './result.js'\nimport {\n Issue,\n IssueInvalidType,\n IssueInvalidValue,\n} from './validation-issue.js'\n\n/**\n * Error thrown when validation fails.\n *\n * Contains detailed information about all validation issues encountered,\n * including the path to each invalid value and descriptions of what was\n * expected vs what was received.\n *\n * Extends {@link LexError} with the error name \"InvalidRequest\" for\n * consistency with the AT Protocol error handling conventions.\n *\n * @example\n * ```typescript\n * const error = new ValidationError([\n * new IssueInvalidType(['user', 'age'], 'hello', ['number'])\n * ])\n * console.log(error.message)\n * // \"Expected number value type at $.user.age (got string)\"\n *\n * console.log(error.issues.length) // 1\n * console.log(error.toJSON())\n * // { error: 'InvalidRequest', message: '...', issues: [...] }\n * ```\n */\nexport class ValidationError extends LexError {\n name = 'ValidationError'\n\n /**\n * The list of validation issues that caused this error.\n *\n * Issues are aggregated when possible (e.g., multiple invalid type issues\n * at the same path are combined into a single issue listing all expected types).\n */\n readonly issues: Issue[]\n\n /**\n * Creates a new validation error from a list of issues.\n *\n * Issues are automatically aggregated to combine related issues at the same\n * path (e.g., multiple type expectations from a union schema).\n *\n * @param issues - The validation issues that caused this error\n * @param options - Standard Error options (e.g., `cause`)\n */\n constructor(issues: Issue[], options?: ErrorOptions) {\n const issuesAgg = aggregateIssues(issues)\n super('InvalidRequest', issuesAgg.join(', '), options)\n this.issues = issuesAgg\n }\n\n /**\n * Converts the error to a JSON-serializable object.\n *\n * @returns An object containing the error details and all issues in JSON format\n */\n toJSON() {\n return {\n ...super.toJSON(),\n issues: this.issues.map((issue) => issue.toJSON()),\n }\n }\n\n /**\n * Creates a validation error by combining multiple validation failures.\n *\n * This is useful when validating against multiple possible schemas (e.g., unions)\n * and all branches fail. The resulting error contains issues from all failures.\n *\n * @param failures - The validation failures to combine\n * @returns A single validation error containing all issues from the failures\n *\n * @example\n * ```typescript\n * const failures = schemas.map(s => s.safeValidate(data)).filter(r => !r.success)\n * if (failures.length === schemas.length) {\n * throw ValidationError.fromFailures(failures)\n * }\n * ```\n */\n static fromFailures(\n failures: ResultFailure<ValidationError>[],\n ): ValidationError {\n if (failures.length === 1) return failureReason(failures[0])\n const issues = failures.flatMap(extractFailureIssues)\n return new ValidationError(issues, {\n // Keep the original errors as the cause chain\n cause: failures.map(failureReason),\n })\n }\n}\n\nfunction extractFailureIssues(result: ResultFailure<ValidationError>) {\n return result.reason.issues\n}\n\nfunction aggregateIssues(issues: Issue[]): Issue[] {\n // Quick path for common cases\n if (issues.length <= 1) return issues\n if (issues.length === 2 && issues[0].code !== issues[1].code) return issues\n\n return [\n // Aggregate invalid_type with identical paths\n ...arrayAgg(\n issues.filter((issue) => issue instanceof IssueInvalidType),\n (a, b) => comparePropertyPaths(a.path, b.path),\n (issues) =>\n new IssueInvalidType(\n issues[0].path,\n issues[0].input,\n Array.from(new Set(issues.flatMap((iss) => iss.expected))),\n ),\n ),\n // Aggregate invalid_value with identical paths\n ...arrayAgg(\n issues.filter((issue) => issue instanceof IssueInvalidValue),\n (a, b) => comparePropertyPaths(a.path, b.path),\n (issues) =>\n new IssueInvalidValue(\n issues[0].path,\n issues[0].input,\n Array.from(new Set(issues.flatMap((iss) => iss.values))),\n ),\n ),\n // Pass through other issues\n ...issues.filter(\n (issue) =>\n !(issue instanceof IssueInvalidType) &&\n !(issue instanceof IssueInvalidValue),\n ),\n ]\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nfunction comparePropertyPaths(\n a: readonly PropertyKey[],\n b: readonly PropertyKey[],\n) {\n if (a.length !== b.length) return false\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false\n }\n return true\n}\n"]}
1
+ {"version":3,"file":"validation-error.js","sourceRoot":"","sources":["../../src/core/validation-error.ts"],"names":[],"mappings":";;;AAAA,gDAA4C;AAC5C,uDAA+C;AAC/C,2CAA0D;AAC1D,+DAI8B;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAa,kBACX,SAAQ,mBAA0B;IAGlC,IAAI,GAAG,oBAAoB,CAAA;IAE3B;;;;;OAKG;IACM,MAAM,CAAS;IAExB;;;;;;;;OAQG;IACH,YAAY,MAAe,EA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sCAAgB,CAAC;YACpC,CAAC,CAAC,KAAK,YAAY,uCAAiB,CAAC,CACxC;KACF,CAAA;AACH,CAAC;AAED,wBAAwB;AACxB,SAAS,oBAAoB,CAC3B,CAAyB,EACzB,CAAyB;IAEzB,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAA;IACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAA;IACjC,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { LexError } from '@atproto/lex-data'\nimport { arrayAgg } from '../util/array-agg.js'\nimport { ResultFailure, failureReason } from './result.js'\nimport {\n Issue,\n IssueInvalidType,\n IssueInvalidValue,\n} from './validation-issue.js'\n\n/**\n * Error thrown when validation fails.\n *\n * Contains detailed information about all validation issues encountered,\n * including the path to each invalid value and descriptions of what was\n * expected vs what was received.\n *\n * Extends {@link LexError} with the error name \"InvalidRequest\" for\n * consistency with the AT Protocol error handling conventions.\n *\n * @example\n * ```typescript\n * const error = new LexValidationError([\n * new IssueInvalidType(['user', 'age'], 'hello', ['number'])\n * ])\n * console.log(error.message)\n * // \"Expected number value type at $.user.age (got string)\"\n *\n * console.log(error.issues.length) // 1\n * console.log(error.toJSON())\n * // { error: 'InvalidRequest', message: '...', issues: [...] }\n * ```\n *\n * @note this class implements {@link ResultFailure} to allow it to be used\n * directly as a failure reason in validation results, avoiding the need for\n * wrapping it in an additional object.\n */\nexport class LexValidationError\n extends LexError<'InvalidRequest'>\n implements ResultFailure<LexValidationError>\n{\n name = 'LexValidationError'\n\n /**\n * The list of validation issues that caused this error.\n *\n * Issues are aggregated when possible (e.g., multiple invalid type issues\n * at the same path are combined into a single issue listing all expected types).\n */\n readonly issues: Issue[]\n\n /**\n * Creates a new validation error from a list of issues.\n *\n * Issues are automatically aggregated to combine related issues at the same\n * path (e.g., multiple type expectations from a union schema).\n *\n * @param issues - The validation issues that caused this error\n * @param options - Standard Error options (e.g., `cause`)\n */\n constructor(issues: Issue[], options?: ErrorOptions) {\n const issuesAgg = aggregateIssues(issues)\n super('InvalidRequest', issuesAgg.join(', '), options)\n this.issues = issuesAgg\n }\n\n /** @see {ResultFailure.success} */\n readonly success = false as const\n\n /** @see {ResultFailure.reason} */\n get reason() {\n return this\n }\n\n /**\n * Converts the error to a JSON-serializable object.\n *\n * @returns An object containing the error details and issues details\n */\n override toJSON() {\n return {\n ...super.toJSON(),\n issues: this.issues.map((issue) => issue.toJSON()),\n }\n }\n\n /**\n * Creates a validation error by combining multiple validation failures.\n *\n * This is useful when validating against multiple possible schemas (e.g., unions)\n * and all branches fail. The resulting error contains issues from all failures.\n *\n * @param failures - The validation failures to combine\n * @returns A single validation error containing all issues from the failures\n *\n * @example\n * ```typescript\n * const failures = schemas.map(s => s.safeValidate(data)).filter(r => !r.success)\n * if (failures.length === schemas.length) {\n * throw LexValidationError.fromFailures(failures)\n * }\n * ```\n */\n static fromFailures(\n failures: readonly ResultFailure<LexValidationError>[],\n ): LexValidationError {\n if (failures.length === 1) return failureReason(failures[0])\n const issues = failures.flatMap(extractFailureIssues)\n return new LexValidationError(issues, {\n // Keep the original errors as the cause chain\n cause: failures.map(failureReason),\n })\n }\n}\n\nfunction extractFailureIssues(result: ResultFailure<LexValidationError>) {\n return result.reason.issues\n}\n\nfunction aggregateIssues(issues: Issue[]): Issue[] {\n // Quick path for common cases\n if (issues.length <= 1) return issues\n if (issues.length === 2 && issues[0].code !== issues[1].code) return issues\n\n return [\n // Aggregate invalid_type with identical paths\n ...arrayAgg(\n issues.filter((issue) => issue instanceof IssueInvalidType),\n (a, b) => comparePropertyPaths(a.path, b.path),\n (issues) =>\n new IssueInvalidType(\n issues[0].path,\n issues[0].input,\n Array.from(new Set(issues.flatMap((iss) => iss.expected))),\n ),\n ),\n // Aggregate invalid_value with identical paths\n ...arrayAgg(\n issues.filter((issue) => issue instanceof IssueInvalidValue),\n (a, b) => comparePropertyPaths(a.path, b.path),\n (issues) =>\n new IssueInvalidValue(\n issues[0].path,\n issues[0].input,\n Array.from(new Set(issues.flatMap((iss) => iss.values))),\n ),\n ),\n // Pass through other issues\n ...issues.filter(\n (issue) =>\n !(issue instanceof IssueInvalidType) &&\n !(issue instanceof IssueInvalidValue),\n ),\n ]\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nfunction comparePropertyPaths(\n a: readonly PropertyKey[],\n b: readonly PropertyKey[],\n) {\n if (a.length !== b.length) return false\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false\n }\n return true\n}\n"]}
@@ -1,4 +1,3 @@
1
- import { PropertyKey } from './property-key.js';
2
1
  /**
3
2
  * Abstract base class for all validation issues.
4
3
  *
@@ -7,18 +6,20 @@ import { PropertyKey } from './property-key.js';
7
6
  * - The path to the invalid value in the data structure
8
7
  * - The actual input value that failed validation
9
8
  *
10
- * Subclasses add specific properties relevant to each issue type and
11
- * implement the {@link toString} method for human-readable error messages.
9
+ * Subclasses add specific properties relevant to each issue type and implement
10
+ * the {@link message} property for human-readable error messages (that don't
11
+ * contain the error path)
12
12
  */
13
13
  export declare abstract class Issue {
14
14
  readonly code: string;
15
15
  readonly path: readonly PropertyKey[];
16
16
  readonly input: unknown;
17
+ abstract readonly message: string;
17
18
  constructor(code: string, path: readonly PropertyKey[], input: unknown);
18
19
  /**
19
20
  * Returns a human-readable description of the validation issue.
20
21
  */
21
- abstract toString(): string;
22
+ toString(): string;
22
23
  /**
23
24
  * Converts the issue to a JSON-serializable object.
24
25
  *
@@ -40,7 +41,6 @@ export declare class IssueCustom extends Issue {
40
41
  readonly input: unknown;
41
42
  readonly message: string;
42
43
  constructor(path: readonly PropertyKey[], input: unknown, message: string);
43
- toString(): string;
44
44
  }
45
45
  /**
46
46
  * Issue for string values that don't match an expected format.
@@ -49,17 +49,17 @@ export declare class IssueCustom extends Issue {
49
49
  */
50
50
  export declare class IssueInvalidFormat extends Issue {
51
51
  readonly format: string;
52
- readonly message?: string | undefined;
53
- constructor(path: readonly PropertyKey[], input: unknown, format: string, message?: string | undefined);
54
- toString(): string;
52
+ readonly detail?: string | undefined;
53
+ constructor(path: readonly PropertyKey[], input: unknown, format: string, detail?: string | undefined);
54
+ get message(): string;
55
+ /** Returns a human-readable description of the expected format. */
56
+ get formatDescription(): string;
55
57
  toJSON(): {
56
58
  format: string;
57
59
  code: string;
58
60
  path: readonly PropertyKey[];
59
61
  message: string;
60
62
  };
61
- /** Returns a human-readable description of the expected format. */
62
- get formatDescription(): string;
63
63
  }
64
64
  /**
65
65
  * Issue for values that have an unexpected type.
@@ -70,7 +70,7 @@ export declare class IssueInvalidFormat extends Issue {
70
70
  export declare class IssueInvalidType extends Issue {
71
71
  readonly expected: readonly string[];
72
72
  constructor(path: readonly PropertyKey[], input: unknown, expected: readonly string[]);
73
- toString(): string;
73
+ get message(): string;
74
74
  toJSON(): {
75
75
  expected: readonly string[];
76
76
  code: string;
@@ -87,7 +87,7 @@ export declare class IssueInvalidType extends Issue {
87
87
  export declare class IssueInvalidValue extends Issue {
88
88
  readonly values: readonly unknown[];
89
89
  constructor(path: readonly PropertyKey[], input: unknown, values: readonly unknown[]);
90
- toString(): string;
90
+ get message(): string;
91
91
  toJSON(): {
92
92
  values: readonly unknown[];
93
93
  code: string;
@@ -101,7 +101,7 @@ export declare class IssueInvalidValue extends Issue {
101
101
  export declare class IssueRequiredKey extends Issue {
102
102
  readonly key: PropertyKey;
103
103
  constructor(path: readonly PropertyKey[], input: unknown, key: PropertyKey);
104
- toString(): string;
104
+ get message(): string;
105
105
  toJSON(): {
106
106
  key: PropertyKey;
107
107
  code: string;
@@ -128,7 +128,7 @@ export declare class IssueTooBig extends Issue {
128
128
  readonly type: MeasurableType;
129
129
  readonly actual: number;
130
130
  constructor(path: readonly PropertyKey[], input: unknown, maximum: number, type: MeasurableType, actual: number);
131
- toString(): string;
131
+ get message(): string;
132
132
  toJSON(): {
133
133
  type: MeasurableType;
134
134
  maximum: number;
@@ -145,7 +145,7 @@ export declare class IssueTooSmall extends Issue {
145
145
  readonly type: MeasurableType;
146
146
  readonly actual: number;
147
147
  constructor(path: readonly PropertyKey[], input: unknown, minimum: number, type: MeasurableType, actual: number);
148
- toString(): string;
148
+ get message(): string;
149
149
  toJSON(): {
150
150
  type: MeasurableType;
151
151
  minimum: number;
@@ -1 +1 @@
1
- {"version":3,"file":"validation-issue.d.ts","sourceRoot":"","sources":["../../src/core/validation-issue.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/C;;;;;;;;;;GAUG;AACH,8BAAsB,KAAK;IAEvB,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,IAAI,EAAE,SAAS,WAAW,EAAE;IACrC,QAAQ,CAAC,KAAK,EAAE,OAAO;gBAFd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,SAAS,WAAW,EAAE,EAC5B,KAAK,EAAE,OAAO;IAGzB;;OAEG;IACH,QAAQ,CAAC,QAAQ,IAAI,MAAM;IAE3B;;;;OAIG;IACH,MAAM;;;;;CAOP;AAED;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAElC,QAAQ,CAAC,IAAI,EAAE,SAAS,WAAW,EAAE;IACrC,QAAQ,CAAC,KAAK,EAAE,OAAO;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM;gBAFf,IAAI,EAAE,SAAS,WAAW,EAAE,EAC5B,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,MAAM;IAK1B,QAAQ;CAGT;AAED;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAIzC,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM;gBAHzB,IAAI,EAAE,SAAS,W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AAQ,CAAC,IAAI,EAAE,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM;gBAJvB,IAAI,EAAE,SAAS,WAAW,EAAE,EAC5B,KAAK,EAAE,OAAO,EACL,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,MAAM;IAKzB,IAAa,OAAO,IAAI,MAAM,CAE7B;IAED,MAAM;;;;;;;CAOP;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;IAIpC,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,QAAQ,CAAC,IAAI,EAAE,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM;gBAJvB,IAAI,EAAE,SAAS,WAAW,EAAE,EAC5B,KAAK,EAAE,OAAO,EACL,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,MAAM;IAKzB,IAAa,OAAO,IAAI,MAAM,CAE7B;IAED,MAAM;;;;;;;CAOP"}
@@ -10,8 +10,9 @@ const lex_data_1 = require("@atproto/lex-data");
10
10
  * - The path to the invalid value in the data structure
11
11
  * - The actual input value that failed validation
12
12
  *
13
- * Subclasses add specific properties relevant to each issue type and
14
- * implement the {@link toString} method for human-readable error messages.
13
+ * Subclasses add specific properties relevant to each issue type and implement
14
+ * the {@link message} property for human-readable error messages (that don't
15
+ * contain the error path)
15
16
  */
16
17
  class Issue {
17
18
  code;
@@ -22,6 +23,12 @@ class Issue {
22
23
  this.path = path;
23
24
  this.input = input;
24
25
  }
26
+ /**
27
+ * Returns a human-readable description of the validation issue.
28
+ */
29
+ toString() {
30
+ return `${this.message}${stringifyPath(this.path)}`;
31
+ }
25
32
  /**
26
33
  * Converts the issue to a JSON-serializable object.
27
34
  *
@@ -31,7 +38,7 @@ class Issue {
31
38
  return {
32
39
  code: this.code,
33
40
  path: this.path,
34
- message: this.toString(),
41
+ message: this.message,
35
42
  };
36
43
  }
37
44
  }
@@ -51,9 +58,6 @@ class IssueCustom extends Issue {
51
58
  this.input = input;
52
59
  this.message = message;
53
60
  }
54
- toString() {
55
- return `${this.message}${stringifyPath(this.path)}`;
56
- }
57
61
  }
58
62
  exports.IssueCustom = IssueCustom;
59
63
  /**
@@ -63,20 +67,14 @@ exports.IssueCustom = IssueCustom;
63
67
  */
64
68
  class IssueInvalidFormat extends Issue {
65
69
  format;
66
- message;
67
- constructor(path, input, format, message) {
70
+ detail;
71
+ constructor(path, input, format, detail) {
68
72
  super('invalid_format', path, input);
69
73
  this.format = format;
70
- this.message = message;
74
+ this.detail = detail;
71
75
  }
72
- toString() {
73
- return `Invalid ${this.formatDescription}${this.message ? ` (${this.message})` : ''}${stringifyPath(this.path)} (got ${stringifyValue(this.input)})`;
74
- }
75
- toJSON() {
76
- return {
77
- ...super.toJSON(),
78
- format: this.format,
79
- };
76
+ get message() {
77
+ return `Invalid ${this.formatDescription}${this.detail ? ` (${this.detail}, ` : ' ('}got ${stringifyValue(this.input)})`;
80
78
  }
81
79
  /** Returns a human-readable description of the expected format. */
82
80
  get formatDescription() {
@@ -97,6 +95,12 @@ class IssueInvalidFormat extends Issue {
97
95
  return this.format;
98
96
  }
99
97
  }
98
+ toJSON() {
99
+ return {
100
+ ...super.toJSON(),
101
+ format: this.format,
102
+ };
103
+ }
100
104
  }
101
105
  exports.IssueInvalidFormat = IssueInvalidFormat;
102
106
  /**
@@ -111,8 +115,8 @@ class IssueInvalidType extends Issue {
111
115
  super('invalid_type', path, input);
112
116
  this.expected = expected;
113
117
  }
114
- toString() {
115
- return `Expected ${oneOf(this.expected.map(stringifyExpectedType))} value type${stringifyPath(this.path)} (got ${stringifyType(this.input)})`;
118
+ get message() {
119
+ return `Expected ${oneOf(this.expected.map(stringifyExpectedType))} value type (got ${stringifyType(this.input)})`;
116
120
  }
117
121
  toJSON() {
118
122
  return {
@@ -134,8 +138,8 @@ class IssueInvalidValue extends Issue {
134
138
  super('invalid_value', path, input);
135
139
  this.values = values;
136
140
  }
137
- toString() {
138
- return `Expected ${oneOf(this.values.map(stringifyValue))}${stringifyPath(this.path)} (got ${stringifyValue(this.input)})`;
141
+ get message() {
142
+ return `Expected ${oneOf(this.values.map(stringifyValue))} (got ${stringifyValue(this.input)})`;
139
143
  }
140
144
  toJSON() {
141
145
  return {
@@ -154,8 +158,8 @@ class IssueRequiredKey extends Issue {
154
158
  super('required_key', path, input);
155
159
  this.key = key;
156
160
  }
157
- toString() {
158
- return `Missing required key "${String(this.key)}"${stringifyPath(this.path)}`;
161
+ get message() {
162
+ return `Missing required key "${String(this.key)}"`;
159
163
  }
160
164
  toJSON() {
161
165
  return {
@@ -178,8 +182,8 @@ class IssueTooBig extends Issue {
178
182
  this.type = type;
179
183
  this.actual = actual;
180
184
  }
181
- toString() {
182
- return `${this.type} too big (maximum ${this.maximum})${stringifyPath(this.path)} (got ${this.actual})`;
185
+ get message() {
186
+ return `${this.type} too big (maximum ${this.maximum}, got ${this.actual})`;
183
187
  }
184
188
  toJSON() {
185
189
  return {
@@ -203,8 +207,8 @@ class IssueTooSmall extends Issue {
203
207
  this.type = type;
204
208
  this.actual = actual;
205
209
  }
206
- toString() {
207
- return `${this.type} too small (minimum ${this.minimum})${stringifyPath(this.path)} (got ${this.actual})`;
210
+ get message() {
211
+ return `${this.type} too small (minimum ${this.minimum}, got ${this.actual})`;
208
212
  }
209
213
  toJSON() {
210
214
  return {
@@ -231,8 +235,8 @@ function buildJsonPath(path) {
231
235
  return `$${path.map(toJsonPathSegment).join('')}`;
232
236
  }
233
237
  function toJsonPathSegment(segment) {
234
- if (typeof segment === 'number') {
235
- return `[${segment}]`;
238
+ if (typeof segment === 'number' || typeof segment === 'symbol') {
239
+ return `[${String(segment)}]`;
236
240
  }
237
241
  else if (/^[a-zA-Z_$][a-zA-Z0-9_]*$/.test(segment)) {
238
242
  return `.${segment}`;