@atproto/lex-schema 0.1.1 → 0.1.3

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 (65) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/core/record-key.d.ts +10 -0
  3. package/dist/core/record-key.d.ts.map +1 -1
  4. package/dist/core/record-key.js.map +1 -1
  5. package/dist/core/result.d.ts +1 -125
  6. package/dist/core/result.d.ts.map +1 -1
  7. package/dist/core/result.js +1 -128
  8. package/dist/core/result.js.map +1 -1
  9. package/dist/core/validation-error.d.ts +0 -18
  10. package/dist/core/validation-error.d.ts.map +1 -1
  11. package/dist/core/validation-error.js +0 -30
  12. package/dist/core/validation-error.js.map +1 -1
  13. package/dist/core/validator.d.ts +8 -15
  14. package/dist/core/validator.d.ts.map +1 -1
  15. package/dist/core/validator.js +3 -14
  16. package/dist/core/validator.js.map +1 -1
  17. package/dist/helpers.d.ts +35 -2
  18. package/dist/helpers.d.ts.map +1 -1
  19. package/dist/helpers.js +33 -0
  20. package/dist/helpers.js.map +1 -1
  21. package/dist/schema/array.d.ts +1 -1
  22. package/dist/schema/blob.d.ts +1 -1
  23. package/dist/schema/boolean.d.ts +1 -1
  24. package/dist/schema/bytes.d.ts +1 -1
  25. package/dist/schema/cid.d.ts +1 -1
  26. package/dist/schema/custom.d.ts +1 -1
  27. package/dist/schema/dict.d.ts +1 -1
  28. package/dist/schema/enum.d.ts +1 -1
  29. package/dist/schema/integer.d.ts +1 -1
  30. package/dist/schema/intersection.d.ts +1 -1
  31. package/dist/schema/lex-map.d.ts +1 -1
  32. package/dist/schema/lex-value.d.ts +1 -1
  33. package/dist/schema/literal.d.ts +1 -1
  34. package/dist/schema/null.d.ts +1 -1
  35. package/dist/schema/nullable.d.ts +1 -1
  36. package/dist/schema/object.d.ts +1 -1
  37. package/dist/schema/optional.d.ts +1 -1
  38. package/dist/schema/params.d.ts +2 -2
  39. package/dist/schema/params.d.ts.map +1 -1
  40. package/dist/schema/record.d.ts +4 -4
  41. package/dist/schema/record.d.ts.map +1 -1
  42. package/dist/schema/record.js +4 -3
  43. package/dist/schema/record.js.map +1 -1
  44. package/dist/schema/regexp.d.ts +1 -1
  45. package/dist/schema/string.d.ts +1 -1
  46. package/dist/schema/token.d.ts +2 -1
  47. package/dist/schema/token.d.ts.map +1 -1
  48. package/dist/schema/token.js +6 -1
  49. package/dist/schema/token.js.map +1 -1
  50. package/dist/schema/typed-union.d.ts +1 -1
  51. package/dist/schema/union.d.ts.map +1 -1
  52. package/dist/schema/union.js +3 -3
  53. package/dist/schema/union.js.map +1 -1
  54. package/dist/schema/unknown.d.ts +1 -1
  55. package/package.json +2 -2
  56. package/src/core/record-key.ts +20 -1
  57. package/src/core/result.ts +8 -155
  58. package/src/core/validation-error.ts +1 -33
  59. package/src/core/validator.ts +10 -21
  60. package/src/helpers.test.ts +126 -1
  61. package/src/helpers.ts +108 -1
  62. package/src/schema/record.test.ts +9 -30
  63. package/src/schema/record.ts +9 -16
  64. package/src/schema/token.ts +9 -1
  65. package/src/schema/union.ts +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atproto/lex-schema
2
2
 
3
+ ## 0.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#5037](https://github.com/bluesky-social/atproto/pull/5037) [`7b8ca6e`](https://github.com/bluesky-social/atproto/commit/7b8ca6e0aace79cca38e880429317fde8268ba50) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `atUri()` helper for safely building `AtUriString` values from raw components or record schemas. Also fixes validation of `'any'` record-key strings.
8
+
9
+ ## 0.1.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#5006](https://github.com/bluesky-social/atproto/pull/5006) [`60721e6`](https://github.com/bluesky-social/atproto/commit/60721e69c8db193eb817c4238ac447505ac855bc) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `$token` accessor for `token` lexicon values schemas
14
+
3
15
  ## 0.1.1
4
16
 
5
17
  ### Patch Changes
@@ -1,3 +1,4 @@
1
+ import { NsidString, TidString } from '@atproto/syntax';
1
2
  /**
2
3
  * The valid record key constraint types in a lexicon definition.
3
4
  *
@@ -45,4 +46,13 @@ export declare function isLexiconRecordKey<T>(key: T): key is T & LexiconRecordK
45
46
  * ```
46
47
  */
47
48
  export declare function asLexiconRecordKey(key: unknown): LexiconRecordKey;
49
+ /**
50
+ * Maps a lexicon record key definition to its corresponding string subtype.
51
+ *
52
+ * - `'any'` maps to `string`
53
+ * - `'nsid'` maps to `NsidString`
54
+ * - `'tid'` maps to `TidString`
55
+ * - `'literal:...'` maps to the literal string value
56
+ */
57
+ export type RecordKeyValue<Key extends LexiconRecordKey = LexiconRecordKey> = Key extends 'any' ? string : Key extends 'tid' ? TidString : Key extends 'nsid' ? NsidString : Key extends `literal:${infer L extends string}` ? L : never;
48
58
  //# sourceMappingURL=record-key.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"record-key.d.ts","sourceRoot":"","sources":["../../src/core/record-key.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,WAAW,MAAM,EAAE,CAAA;AAE3E;;;;;;;;;;;;;;GAcG;AAEH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,gBAAgB,CAUzE;AAED;;;;;;;;;;;;;;GAcG;AAEH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,CAGjE"}
1
+ {"version":3,"file":"record-key.d.ts","sourceRoot":"","sources":["../../src/core/record-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAoB,MAAM,iBAAiB,CAAA;AAEzE;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,WAAW,MAA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AC,CAAA;AACvD,CAAC","sourcesContent":["import { isValidRecordKey } from '@atproto/syntax'\n\n/**\n * The valid record key constraint types in a lexicon definition.\n *\n * - `'any'` - Accepts any valid record key\n * - `'nsid'` - Record key must be a valid NSID\n * - `'tid'` - Record key must be a valid TID\n * - `'literal:...'` - Record key must be the exact specified value\n *\n * @example\n * ```typescript\n * const constraint: LexiconRecordKey = 'tid'\n * const literalConstraint: LexiconRecordKey = 'literal:self'\n * ```\n */\nexport type LexiconRecordKey = 'any' | 'nsid' | 'tid' | `literal:${string}`\n\n/**\n * Type guard that checks if a value is a valid lexicon record key constraint.\n *\n * @typeParam T - The input type\n * @param key - The value to check\n * @returns `true` if the value is a valid record key constraint\n *\n * @example\n * ```typescript\n * if (isLexiconRecordKey(value)) {\n * // value is typed as LexiconRecordKey\n * console.log('Valid constraint:', value)\n * }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isLexiconRecordKey<T>(key: T): key is T & LexiconRecordKey {\n return (\n key === 'any' ||\n key === 'nsid' ||\n key === 'tid' ||\n (typeof key === 'string' &&\n key.startsWith('literal:') &&\n key.length > 8 &&\n isValidRecordKey(key.slice(8)))\n )\n}\n\n/**\n * Validates and returns a value as a lexicon record key constraint, throwing if invalid.\n *\n * @param key - The value to validate\n * @returns The value typed as {@link LexiconRecordKey}\n * @throws {Error} If the value is not a valid record key constraint\n *\n * @example\n * ```typescript\n * const constraint = asLexiconRecordKey('tid')\n * // constraint is typed as LexiconRecordKey\n *\n * asLexiconRecordKey('invalid') // throws Error\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function asLexiconRecordKey(key: unknown): LexiconRecordKey {\n if (isLexiconRecordKey(key)) return key\n throw new Error(`Invalid record key: ${String(key)}`)\n}\n"]}
1
+ {"version":3,"file":"record-key.js","sourceRoot":"","sources":["../../src/core/record-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAkBzE;;;;;;;;;;;;;;GAcG;AACH,wBAAwB;AACxB,MAAM,UAAU,kBAAkB,CAAI,GAAM;IAC1C,OAAO,CACL,GAAG,KAAK,KAAK;QACb,GAAG,KAAK,MAAM;QACd,GAAG,KAAK,KAAK;QACb,CAAC,OAAO,GAAG,KAAK,QAAQ;YACtB,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC;YAC1B,GAAG,CAAC,MAAM,GAAG,CAAC;YACd,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAClC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAwB;AACxB,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC7C,IAAI,kBAAkB,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAA;IACvC,MAAM,IAAI,KAAK,CAAC,uBAAuB,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;AACvD,CAAC","sourcesContent":["import { NsidString, TidString, isValidRecordKey } from '@atproto/syntax'\n\n/**\n * The valid record key constraint types in a lexicon definition.\n *\n * - `'any'` - Accepts any valid record key\n * - `'nsid'` - Record key must be a valid NSID\n * - `'tid'` - Record key must be a valid TID\n * - `'literal:...'` - Record key must be the exact specified value\n *\n * @example\n * ```typescript\n * const constraint: LexiconRecordKey = 'tid'\n * const literalConstraint: LexiconRecordKey = 'literal:self'\n * ```\n */\nexport type LexiconRecordKey = 'any' | 'nsid' | 'tid' | `literal:${string}`\n\n/**\n * Type guard that checks if a value is a valid lexicon record key constraint.\n *\n * @typeParam T - The input type\n * @param key - The value to check\n * @returns `true` if the value is a valid record key constraint\n *\n * @example\n * ```typescript\n * if (isLexiconRecordKey(value)) {\n * // value is typed as LexiconRecordKey\n * console.log('Valid constraint:', value)\n * }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isLexiconRecordKey<T>(key: T): key is T & LexiconRecordKey {\n return (\n key === 'any' ||\n key === 'nsid' ||\n key === 'tid' ||\n (typeof key === 'string' &&\n key.startsWith('literal:') &&\n key.length > 8 &&\n isValidRecordKey(key.slice(8)))\n )\n}\n\n/**\n * Validates and returns a value as a lexicon record key constraint, throwing if invalid.\n *\n * @param key - The value to validate\n * @returns The value typed as {@link LexiconRecordKey}\n * @throws {Error} If the value is not a valid record key constraint\n *\n * @example\n * ```typescript\n * const constraint = asLexiconRecordKey('tid')\n * // constraint is typed as LexiconRecordKey\n *\n * asLexiconRecordKey('invalid') // throws Error\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function asLexiconRecordKey(key: unknown): LexiconRecordKey {\n if (isLexiconRecordKey(key)) return key\n throw new Error(`Invalid record key: ${String(key)}`)\n}\n\n/**\n * Maps a lexicon record key definition to its corresponding string subtype.\n *\n * - `'any'` maps to `string`\n * - `'nsid'` maps to `NsidString`\n * - `'tid'` maps to `TidString`\n * - `'literal:...'` maps to the literal string value\n */\nexport type RecordKeyValue<Key extends LexiconRecordKey = LexiconRecordKey> =\n Key extends 'any'\n ? string\n : Key extends 'tid'\n ? TidString\n : Key extends 'nsid'\n ? NsidString\n : Key extends `literal:${infer L extends string}`\n ? L\n : never\n"]}
@@ -1,6 +1,7 @@
1
1
  export type ResultSuccess<V = any> = {
2
2
  success: true;
3
3
  value: V;
4
+ reason?: undefined;
4
5
  };
5
6
  /**
6
7
  * Represents a failed result containing an error reason.
@@ -11,129 +12,4 @@ export type ResultFailure<E = Error> = {
11
12
  success: false;
12
13
  reason: E;
13
14
  };
14
- /**
15
- * A discriminated union type representing either a success or failure outcome.
16
- *
17
- * Check the `success` property to determine the outcome and access the
18
- * appropriate property (`value` for success, `reason` for failure).
19
- *
20
- * @typeParam V - The type of the success value
21
- * @typeParam E - The type of the error reason
22
- *
23
- * @example
24
- * ```typescript
25
- * function parseJson(text: string): Result<unknown, SyntaxError> {
26
- * try {
27
- * return success(JSON.parse(text))
28
- * } catch (e) {
29
- * return failure(e as SyntaxError)
30
- * }
31
- * }
32
- * ```
33
- */
34
- export type Result<V = any, E = Error> = ResultSuccess<V> | ResultFailure<E>;
35
- /**
36
- * Creates a successful result wrapping the given value.
37
- *
38
- * @typeParam V - The type of the value
39
- * @param value - The success value to wrap
40
- * @returns {ResultSuccess} A success result containing the value
41
- *
42
- * @example
43
- * ```typescript
44
- * const result = success(42)
45
- * console.log(result.success) // true
46
- * console.log(result.value) // 42
47
- * ```
48
- */
49
- export declare function success<V>(value: V): ResultSuccess<V>;
50
- /**
51
- * Creates a failed result wrapping the given error reason.
52
- *
53
- * @typeParam E - The type of the error reason
54
- * @param reason - The error reason to wrap
55
- * @returns {ResultFailure} A failure result containing the error
56
- *
57
- * @example
58
- * ```typescript
59
- * const result = failure(new Error('Something went wrong'))
60
- * console.log(result.success) // false
61
- * console.log(result.reason.message) // "Something went wrong"
62
- * ```
63
- */
64
- export declare function failure<E>(reason: E): ResultFailure<E>;
65
- /**
66
- * Extracts the error reason from a failure result.
67
- *
68
- * @typeParam T - The type of the error reason
69
- * @param result - A failure result
70
- * @returns {T} The error reason
71
- *
72
- * @example
73
- * ```typescript
74
- * const result = failure(new Error('oops'))
75
- * const error = failureReason(result)
76
- * console.log(error.message) // "oops"
77
- * ```
78
- */
79
- export declare function failureReason<T>(result: ResultFailure<T>): T;
80
- /**
81
- * Extracts the value from a success result.
82
- *
83
- * @typeParam T - The type of the success value
84
- * @param result - A success result
85
- * @returns {T} The success value
86
- *
87
- * @example
88
- * ```typescript
89
- * const result = success(42)
90
- * const value = successValue(result)
91
- * console.log(value) // 42
92
- * ```
93
- */
94
- export declare function successValue<T>(result: ResultSuccess<T>): T;
95
- /**
96
- * Catches any error and wraps it in a {@link ResultFailure<Error>}.
97
- *
98
- * @param err - The error to catch.
99
- * @returns {ResultFailure} A failure result containing the error.
100
- * @example
101
- *
102
- * ```ts
103
- * declare function someFunction(): Promise<string>
104
- *
105
- * const result = await someFunction().then(success, catchall)
106
- * if (result.success) {
107
- * console.log(result.value) // string
108
- * } else {
109
- * console.error(result.reason instanceof Error) // true
110
- * console.error(result.reason.message) // string
111
- * }
112
- * ```
113
- */
114
- export declare function catchall(err: unknown): ResultFailure<Error>;
115
- /**
116
- * Creates a catcher function for the given constructor that wraps caught errors
117
- * in a {@link ResultFailure}.
118
- *
119
- * @example
120
- *
121
- * ```ts
122
- * class FooError extends Error {}
123
- * class BarError extends Error {}
124
- *
125
- * declare function someFunction(): Promise<string>
126
- *
127
- * const result = await someFunction()
128
- * .then(success)
129
- * .catch(createCatcher(FooError))
130
- * .catch(createCatcher(BarError))
131
- *
132
- * if (result.success) {
133
- * console.log(result.value) // string
134
- * } else {
135
- * console.error(result.reason) // FooError | BarError
136
- * }
137
- */
138
- export declare function createCatcher<T>(Ctor: new (...args: any[]) => T): (err: unknown) => ResultFailure<T>;
139
15
  //# sourceMappingURL=result.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/core/result.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,GAAG,IAAI;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAA;AAEhE;;;;GAIG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,KAAK,IAAI;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,CAAC,CAAA;CAAE,CAAA;AAEpE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,KAAK,IAAI,aAAa,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAA;AAE5E;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAErD;AAED;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAEtD;AAED;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAE5D;AAED;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAE3D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AAEH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,CAG3D;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,IACtD,KAAK,OAAO,KAAG,aAAa,CAAC,CAAC,CAAC,CAIxC"}
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/core/result.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,GAAG,IAAI;IACnC,OAAO,EAAE,IAAI,CAAA;IACb,KAAK,EAAE,CAAC,CAAA;IACR,MAAM,CAAC,EAAE,SAAS,CAAA;CACnB,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,KAAK,IAAI;IACrC,OAAO,EAAE,KAAK,CAAA;IACd,MAAM,EAAE,CAAC,CAAA;CACV,CAAA"}
@@ -1,129 +1,2 @@
1
- /**
2
- * Creates a successful result wrapping the given value.
3
- *
4
- * @typeParam V - The type of the value
5
- * @param value - The success value to wrap
6
- * @returns {ResultSuccess} A success result containing the value
7
- *
8
- * @example
9
- * ```typescript
10
- * const result = success(42)
11
- * console.log(result.success) // true
12
- * console.log(result.value) // 42
13
- * ```
14
- */
15
- /*@__NO_SIDE_EFFECTS__*/
16
- export function success(value) {
17
- return { success: true, value };
18
- }
19
- /**
20
- * Creates a failed result wrapping the given error reason.
21
- *
22
- * @typeParam E - The type of the error reason
23
- * @param reason - The error reason to wrap
24
- * @returns {ResultFailure} A failure result containing the error
25
- *
26
- * @example
27
- * ```typescript
28
- * const result = failure(new Error('Something went wrong'))
29
- * console.log(result.success) // false
30
- * console.log(result.reason.message) // "Something went wrong"
31
- * ```
32
- */
33
- /*@__NO_SIDE_EFFECTS__*/
34
- export function failure(reason) {
35
- return { success: false, reason };
36
- }
37
- /**
38
- * Extracts the error reason from a failure result.
39
- *
40
- * @typeParam T - The type of the error reason
41
- * @param result - A failure result
42
- * @returns {T} The error reason
43
- *
44
- * @example
45
- * ```typescript
46
- * const result = failure(new Error('oops'))
47
- * const error = failureReason(result)
48
- * console.log(error.message) // "oops"
49
- * ```
50
- */
51
- /*@__NO_SIDE_EFFECTS__*/
52
- export function failureReason(result) {
53
- return result.reason;
54
- }
55
- /**
56
- * Extracts the value from a success result.
57
- *
58
- * @typeParam T - The type of the success value
59
- * @param result - A success result
60
- * @returns {T} The success value
61
- *
62
- * @example
63
- * ```typescript
64
- * const result = success(42)
65
- * const value = successValue(result)
66
- * console.log(value) // 42
67
- * ```
68
- */
69
- /*@__NO_SIDE_EFFECTS__*/
70
- export function successValue(result) {
71
- return result.value;
72
- }
73
- /**
74
- * Catches any error and wraps it in a {@link ResultFailure<Error>}.
75
- *
76
- * @param err - The error to catch.
77
- * @returns {ResultFailure} A failure result containing the error.
78
- * @example
79
- *
80
- * ```ts
81
- * declare function someFunction(): Promise<string>
82
- *
83
- * const result = await someFunction().then(success, catchall)
84
- * if (result.success) {
85
- * console.log(result.value) // string
86
- * } else {
87
- * console.error(result.reason instanceof Error) // true
88
- * console.error(result.reason.message) // string
89
- * }
90
- * ```
91
- */
92
- /*@__NO_SIDE_EFFECTS__*/
93
- export function catchall(err) {
94
- if (err instanceof Error)
95
- return failure(err);
96
- return failure(new Error('Unknown error', { cause: err }));
97
- }
98
- /**
99
- * Creates a catcher function for the given constructor that wraps caught errors
100
- * in a {@link ResultFailure}.
101
- *
102
- * @example
103
- *
104
- * ```ts
105
- * class FooError extends Error {}
106
- * class BarError extends Error {}
107
- *
108
- * declare function someFunction(): Promise<string>
109
- *
110
- * const result = await someFunction()
111
- * .then(success)
112
- * .catch(createCatcher(FooError))
113
- * .catch(createCatcher(BarError))
114
- *
115
- * if (result.success) {
116
- * console.log(result.value) // string
117
- * } else {
118
- * console.error(result.reason) // FooError | BarError
119
- * }
120
- */
121
- /*@__NO_SIDE_EFFECTS__*/
122
- export function createCatcher(Ctor) {
123
- return (err) => {
124
- if (err instanceof Ctor)
125
- return failure(err);
126
- throw err;
127
- };
128
- }
1
+ export {};
129
2
  //# sourceMappingURL=result.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/core/result.ts"],"names":[],"mappings":"AA+BA;;;;;;;;;;;;;GAaG;AACH,wBAAwB;AACxB,MAAM,UAAU,OAAO,CAAI,KAAQ;IACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;AACjC,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAwB;AACxB,MAAM,UAAU,OAAO,CAAI,MAAS;IAClC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA;AACnC,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAwB;AACxB,MAAM,UAAU,aAAa,CAAI,MAAwB;IACvD,OAAO,MAAM,CAAC,MAAM,CAAA;AACtB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAwB;AACxB,MAAM,UAAU,YAAY,CAAI,MAAwB;IACtD,OAAO,MAAM,CAAC,KAAK,CAAA;AACrB,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAwB;AACxB,MAAM,UAAU,QAAQ,CAAC,GAAY;IACnC,IAAI,GAAG,YAAY,KAAK;QAAE,OAAO,OAAO,CAAC,GAAG,CAAC,CAAA;IAC7C,OAAO,OAAO,CAAC,IAAI,KAAK,CAAC,eAAe,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;AAC5D,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAwB;AACxB,MAAM,UAAU,aAAa,CAAI,IAA+B;IAC9D,OAAO,CAAC,GAAY,EAAoB,EAAE;QACxC,IAAI,GAAG,YAAY,IAAI;YAAE,OAAO,OAAO,CAAC,GAAG,CAAC,CAAA;QAC5C,MAAM,GAAG,CAAA;IACX,CAAC,CAAA;AACH,CAAC","sourcesContent":["export type ResultSuccess<V = any> = { success: true; value: V }\n\n/**\n * Represents a failed result containing an error reason.\n *\n * @typeParam E - The type of the error reason\n */\nexport type ResultFailure<E = Error> = { success: false; reason: E }\n\n/**\n * A discriminated union type representing either a success or failure outcome.\n *\n * Check the `success` property to determine the outcome and access the\n * appropriate property (`value` for success, `reason` for failure).\n *\n * @typeParam V - The type of the success value\n * @typeParam E - The type of the error reason\n *\n * @example\n * ```typescript\n * function parseJson(text: string): Result<unknown, SyntaxError> {\n * try {\n * return success(JSON.parse(text))\n * } catch (e) {\n * return failure(e as SyntaxError)\n * }\n * }\n * ```\n */\nexport type Result<V = any, E = Error> = ResultSuccess<V> | ResultFailure<E>\n\n/**\n * Creates a successful result wrapping the given value.\n *\n * @typeParam V - The type of the value\n * @param value - The success value to wrap\n * @returns {ResultSuccess} A success result containing the value\n *\n * @example\n * ```typescript\n * const result = success(42)\n * console.log(result.success) // true\n * console.log(result.value) // 42\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function success<V>(value: V): ResultSuccess<V> {\n return { success: true, value }\n}\n\n/**\n * Creates a failed result wrapping the given error reason.\n *\n * @typeParam E - The type of the error reason\n * @param reason - The error reason to wrap\n * @returns {ResultFailure} A failure result containing the error\n *\n * @example\n * ```typescript\n * const result = failure(new Error('Something went wrong'))\n * console.log(result.success) // false\n * console.log(result.reason.message) // \"Something went wrong\"\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function failure<E>(reason: E): ResultFailure<E> {\n return { success: false, reason }\n}\n\n/**\n * Extracts the error reason from a failure result.\n *\n * @typeParam T - The type of the error reason\n * @param result - A failure result\n * @returns {T} The error reason\n *\n * @example\n * ```typescript\n * const result = failure(new Error('oops'))\n * const error = failureReason(result)\n * console.log(error.message) // \"oops\"\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function failureReason<T>(result: ResultFailure<T>): T {\n return result.reason\n}\n\n/**\n * Extracts the value from a success result.\n *\n * @typeParam T - The type of the success value\n * @param result - A success result\n * @returns {T} The success value\n *\n * @example\n * ```typescript\n * const result = success(42)\n * const value = successValue(result)\n * console.log(value) // 42\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function successValue<T>(result: ResultSuccess<T>): T {\n return result.value\n}\n\n/**\n * Catches any error and wraps it in a {@link ResultFailure<Error>}.\n *\n * @param err - The error to catch.\n * @returns {ResultFailure} A failure result containing the error.\n * @example\n *\n * ```ts\n * declare function someFunction(): Promise<string>\n *\n * const result = await someFunction().then(success, catchall)\n * if (result.success) {\n * console.log(result.value) // string\n * } else {\n * console.error(result.reason instanceof Error) // true\n * console.error(result.reason.message) // string\n * }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function catchall(err: unknown): ResultFailure<Error> {\n if (err instanceof Error) return failure(err)\n return failure(new Error('Unknown error', { cause: err }))\n}\n\n/**\n * Creates a catcher function for the given constructor that wraps caught errors\n * in a {@link ResultFailure}.\n *\n * @example\n *\n * ```ts\n * class FooError extends Error {}\n * class BarError extends Error {}\n *\n * declare function someFunction(): Promise<string>\n *\n * const result = await someFunction()\n * .then(success)\n * .catch(createCatcher(FooError))\n * .catch(createCatcher(BarError))\n *\n * if (result.success) {\n * console.log(result.value) // string\n * } else {\n * console.error(result.reason) // FooError | BarError\n * }\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function createCatcher<T>(Ctor: new (...args: any[]) => T) {\n return (err: unknown): ResultFailure<T> => {\n if (err instanceof Ctor) return failure(err)\n throw err\n }\n}\n"]}
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/core/result.ts"],"names":[],"mappings":"","sourcesContent":["export type ResultSuccess<V = any> = {\n success: true\n value: V\n reason?: undefined\n}\n\n/**\n * Represents a failed result containing an error reason.\n *\n * @typeParam E - The type of the error reason\n */\nexport type ResultFailure<E = Error> = {\n success: false\n reason: E\n}\n"]}
@@ -65,23 +65,5 @@ export declare class LexValidationError extends LexError<'InvalidRequest'> imple
65
65
  error: import("@atproto/lex-data").LexErrorCode;
66
66
  message?: string;
67
67
  };
68
- /**
69
- * Creates a validation error by combining multiple validation failures.
70
- *
71
- * This is useful when validating against multiple possible schemas (e.g., unions)
72
- * and all branches fail. The resulting error contains issues from all failures.
73
- *
74
- * @param failures - The validation failures to combine
75
- * @returns A single validation error containing all issues from the failures
76
- *
77
- * @example
78
- * ```typescript
79
- * const failures = schemas.map(s => s.safeValidate(data)).filter(r => !r.success)
80
- * if (failures.length === schemas.length) {
81
- * throw LexValidationError.fromFailures(failures)
82
- * }
83
- * ```
84
- */
85
- static fromFailures(failures: readonly ResultFailure<LexValidationError>[]): LexValidationError;
86
68
  }
87
69
  //# 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,OAAO,EACL,KAAK,EAGN,MAAM,uBAAuB,CAAA;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,kBACX,SAAQ,QAAQ,CAAC,gBAAgB,CACjC,YAAW,aAAa,CAAC,kBAAkB,CAAC;IAE5C,IAAI,SAAuB;IAE3B;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAA;IAEjC;;;;;;;;OAQG;gBACS,MAAM,EAAE,KAAK,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY;IAMnD,mCAAmC;IACnC,QAAQ,CAAC,OAAO,EAAG,KAAK,CAAS;IAEjC,kCAAkC;IAClC,IAAI,MAAM,SAET;IAED;;;;OAIG;IACM,MAAM;;;;;;;;;IAOf;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,YAAY,CACjB,QAAQ,EAAE,SAAS,aAAa,CAAC,kBAAkB,CAAC,EAAE,GACrD,kBAAkB;CAQtB"}
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,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EACL,KAAK,EAGN,MAAM,uBAAuB,CAAA;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,kBACX,SAAQ,QAAQ,CAAC,gBAAgB,CACjC,YAAW,aAAa,CAAC,kBAAkB,CAAC;IAE5C,IAAI,SAAuB;IAE3B;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAA;IAEjC;;;;;;;;OAQG;gBACS,MAAM,EAAE,KAAK,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY;IAMnD,mCAAmC;IACnC,QAAQ,CAAC,OAAO,EAAG,KAAK,CAAS;IAEjC,kCAAkC;IAClC,IAAI,MAAM,SAET;IAED;;;;OAIG;IACM,MAAM;;;;;;;;;CAMhB"}
@@ -1,6 +1,5 @@
1
1
  import { LexError } from '@atproto/lex-data';
2
2
  import { arrayAgg } from '../util/array-agg.js';
3
- import { failureReason } from './result.js';
4
3
  import { IssueInvalidType, IssueInvalidValue, } from './validation-issue.js';
5
4
  /**
6
5
  * Error thrown when validation fails.
@@ -62,35 +61,6 @@ export class LexValidationError extends LexError {
62
61
  issues: this.issues.map((issue) => issue.toJSON()),
63
62
  };
64
63
  }
65
- /**
66
- * Creates a validation error by combining multiple validation failures.
67
- *
68
- * This is useful when validating against multiple possible schemas (e.g., unions)
69
- * and all branches fail. The resulting error contains issues from all failures.
70
- *
71
- * @param failures - The validation failures to combine
72
- * @returns A single validation error containing all issues from the failures
73
- *
74
- * @example
75
- * ```typescript
76
- * const failures = schemas.map(s => s.safeValidate(data)).filter(r => !r.success)
77
- * if (failures.length === schemas.length) {
78
- * throw LexValidationError.fromFailures(failures)
79
- * }
80
- * ```
81
- */
82
- static fromFailures(failures) {
83
- if (failures.length === 1)
84
- return failureReason(failures[0]);
85
- const issues = failures.flatMap(extractFailureIssues);
86
- return new LexValidationError(issues, {
87
- // Keep the original errors as the cause chain
88
- cause: failures.map(failureReason),
89
- });
90
- }
91
- }
92
- function extractFailureIssues(result) {
93
- return result.reason.issues;
94
64
  }
95
65
  function aggregateIssues(issues) {
96
66
  // Quick path for common cases
@@ -1 +1 @@
1
- {"version":3,"file":"validation-error.js","sourceRoot":"","sources":["../../src/core/validation-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAiB,aAAa,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAEL,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,uBAAuB,CAAA;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,kBACX,SAAQ,QAA0B;IAalC;;;;;;;;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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AAI,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 integer value type (got \"some-string\") at $.user.age\"\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: readonly 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
+ {"version":3,"file":"validation-error.js","sourceRoot":"","sources":["../../src/core/validation-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAE/C,OAAO,EAEL,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,uBAAuB,CAAA;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,kBACX,SAAQ,QAA0B;IAalC;;;;;;;;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;QArBxD,SAAI,GAAG,oBAAoB,CAAA;QAyB3B,mCAAmC;QAC1B,YAAO,GAAG,KAAc,CAAA;QAJ/B,IAAI,CAAC,MAAM,GAAG,SAAS,CAAA;IACzB,CAAC;IAKD,kCAAkC;IAClC,IAAI,MAAM;QACR,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;OAIG;IACM,MAAM;QACb,OAAO;YACL,GAAG,KAAK,CAAC,MAAM,EAAE;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,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AI,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,gBAAgB,CAAC;YACpC,CAAC,CAAC,KAAK,YAAY,iBAAiB,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 } 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 integer value type (got \"some-string\") at $.user.age\"\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: readonly 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\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,18 +1,18 @@
1
- import { ResultSuccess } from './result.js';
1
+ import type * as Result from './result.js';
2
2
  import { LexValidationError } from './validation-error.js';
3
3
  import { Issue, MeasurableType } from './validation-issue.js';
4
4
  /**
5
5
  * Represents a successful validation result.
6
6
  *
7
- * @typeParam Value - The type of the validated value
7
+ * @typeParam TValue - The type of the validated value
8
+ * @extends Result.ResultSuccess<TValue>
8
9
  */
9
- export type ValidationSuccess<Value = unknown> = ResultSuccess<Value>;
10
+ export type ValidationSuccess<TValue = unknown> = Result.ResultSuccess<TValue>;
10
11
  /**
11
12
  * Represents a failed validation result containing a {@link LexValidationError}.
12
13
  *
13
- * @extends ResultFailure<LexValidationError>
14
- * @see {@link ResultFailure}
15
14
  * @see {@link LexValidationError}
15
+ * @extends Result.ResultFailure<LexValidationError>
16
16
  */
17
17
  export type ValidationFailure = LexValidationError;
18
18
  /**
@@ -307,20 +307,13 @@ export declare class ValidationContext {
307
307
  */
308
308
  addIssue(issue: Issue): void;
309
309
  /**
310
- * Creates a successful validation result with the given value.
310
+ * Helper method to create a successful validation result.
311
311
  *
312
312
  * @typeParam V - The value type
313
313
  * @param value - The validated value
314
314
  * @returns A successful validation result
315
315
  */
316
- success<V>(value: V): ValidationResult<V>;
317
- /**
318
- * Creates a failed validation result with the given error.
319
- *
320
- * @param reason - The validation error
321
- * @returns A failed validation result
322
- */
323
- failure(reason: LexValidationError): ValidationFailure;
316
+ success<V>(value: V): ValidationSuccess<V>;
324
317
  /**
325
318
  * Creates a failed validation result from a single issue.
326
319
  *
@@ -329,7 +322,7 @@ export declare class ValidationContext {
329
322
  * @param issue - The validation issue that caused the failure
330
323
  * @returns A failed validation result
331
324
  */
332
- issue(issue: Issue): LexValidationError;
325
+ issue(issue: Issue): ValidationFailure;
333
326
  /**
334
327
  * Creates a failure for an invalid value that doesn't match expected values.
335
328
  *
@@ -1 +1 @@
1
- {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/core/validator.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,aAAa,EAAW,MAAM,aAAa,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,EACL,KAAK,EAOL,cAAc,EACf,MAAM,uBAAuB,CAAA;AAE9B;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,KAAK,GAAG,OAAO,IAAI,aAAa,CAAC,KAAK,CAAC,CAAA;AAErE;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,CAAA;AAElD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,gBAAgB,CAAC,KAAK,GAAG,OAAO,IACxC,iBAAiB,CAAC,KAAK,CAAC,GACxB,iBAAiB,CAAA;AAErB;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAA;AAEjE;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAA;AAEnE;;;;GAIG;AACH,YAAY,EAAE,UAAU,IAAI,KAAK,EAAE,CAAA;AAEnC,MAAM,WAAW,SAAS,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,MAAM;IAC3D;;;;;;OAMG;IACH,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE;QAClB,KAAK,EAAE,MAAM,CAAA;QACb,MAAM,EAAE,OAAO,CAAA;KAChB,CAAA;IAED;;;;;;;;;;;;;;;;;;;;;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,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM;IAI/D;;;;;;;;OAQG;IACH,WAAW,CACT,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,cAAc,EACpB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM;IAKhB;;;;;;;;OAQG;IACH,aAAa,CACX,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,cAAc,EACpB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM;IAKhB;;;;;;;;;;;OAWG;IACH,yBAAyB,CAAC,CAAC,EACzB,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,MAAM,CAAC,GAAG,WAAW,EAC/B,MAAM,EAAE,SAAS,OAAO,EAAE;IAO5B;;;;;;;;;;;OAWG;IACH,wBAAwB,CAAC,CAAC,EACxB,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,MAAM,CAAC,GAAG,WAAW,EAC/B,QAAQ,EAAE,MAAM;CAMnB;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,SAAS;IAC3D,MAAM,IAAI,MAAM,CAAC,SAAS,SAAS,CAAA;CACpC,GACG,eAAe,CAAC,CAAC,CAAC,GAClB,CAAC,CAAA;AAEL;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,gBAAgB,CAAC,GAAG,CAAC,SAAS;IAC7C;;;;OAIG;IACH,MAAM,IAAI,SAAS,CAAA;CACpB"}
@@ -1,5 +1,3 @@
1
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- import { success } from './result.js';
3
1
  import { LexValidationError } from './validation-error.js';
4
2
  import { IssueInvalidFormat, IssueInvalidType, IssueInvalidValue, IssueRequiredKey, IssueTooBig, IssueTooSmall, } from './validation-issue.js';
5
3
  /**
@@ -164,23 +162,14 @@ export class ValidationContext {
164
162
  this.issues.push(issue);
165
163
  }
166
164
  /**
167
- * Creates a successful validation result with the given value.
165
+ * Helper method to create a successful validation result.
168
166
  *
169
167
  * @typeParam V - The value type
170
168
  * @param value - The validated value
171
169
  * @returns A successful validation result
172
170
  */
173
171
  success(value) {
174
- return success(value);
175
- }
176
- /**
177
- * Creates a failed validation result with the given error.
178
- *
179
- * @param reason - The validation error
180
- * @returns A failed validation result
181
- */
182
- failure(reason) {
183
- return reason;
172
+ return { success: true, value };
184
173
  }
185
174
  /**
186
175
  * Creates a failed validation result from a single issue.
@@ -191,7 +180,7 @@ export class ValidationContext {
191
180
  * @returns A failed validation result
192
181
  */
193
182
  issue(issue) {
194
- return this.failure(new LexValidationError([...this.issues, issue]));
183
+ return new LexValidationError([...this.issues, issue]);
195
184
  }
196
185
  /**
197
186
  * Creates a failure for an invalid value that doesn't match expected values.