@atproto/lex-schema 0.0.11 → 0.0.13

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 (261) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/core/$type.d.ts +149 -0
  3. package/dist/core/$type.d.ts.map +1 -1
  4. package/dist/core/$type.js +44 -0
  5. package/dist/core/$type.js.map +1 -1
  6. package/dist/core/record-key.d.ts +44 -0
  7. package/dist/core/record-key.d.ts.map +1 -1
  8. package/dist/core/record-key.js +30 -0
  9. package/dist/core/record-key.js.map +1 -1
  10. package/dist/core/result.d.ts +85 -4
  11. package/dist/core/result.d.ts.map +1 -1
  12. package/dist/core/result.js +60 -4
  13. package/dist/core/result.js.map +1 -1
  14. package/dist/core/schema.d.ts +232 -5
  15. package/dist/core/schema.d.ts.map +1 -1
  16. package/dist/core/schema.js +197 -4
  17. package/dist/core/schema.js.map +1 -1
  18. package/dist/core/string-format.d.ts +244 -11
  19. package/dist/core/string-format.d.ts.map +1 -1
  20. package/dist/core/string-format.js +150 -0
  21. package/dist/core/string-format.js.map +1 -1
  22. package/dist/core/types.d.ts +90 -3
  23. package/dist/core/types.d.ts.map +1 -1
  24. package/dist/core/types.js.map +1 -1
  25. package/dist/core/validation-error.d.ts +60 -0
  26. package/dist/core/validation-error.d.ts.map +1 -1
  27. package/dist/core/validation-error.js +60 -0
  28. package/dist/core/validation-error.js.map +1 -1
  29. package/dist/core/validation-issue.d.ts +61 -0
  30. package/dist/core/validation-issue.d.ts.map +1 -1
  31. package/dist/core/validation-issue.js +54 -1
  32. package/dist/core/validation-issue.js.map +1 -1
  33. package/dist/core/validator.d.ts +356 -11
  34. package/dist/core/validator.d.ts.map +1 -1
  35. package/dist/core/validator.js +203 -4
  36. package/dist/core/validator.js.map +1 -1
  37. package/dist/helpers.d.ts +12 -28
  38. package/dist/helpers.d.ts.map +1 -1
  39. package/dist/helpers.js.map +1 -1
  40. package/dist/schema/array.d.ts +46 -0
  41. package/dist/schema/array.d.ts.map +1 -1
  42. package/dist/schema/array.js +16 -1
  43. package/dist/schema/array.js.map +1 -1
  44. package/dist/schema/blob.d.ts +50 -2
  45. package/dist/schema/blob.d.ts.map +1 -1
  46. package/dist/schema/blob.js +44 -2
  47. package/dist/schema/blob.js.map +1 -1
  48. package/dist/schema/boolean.d.ts +29 -0
  49. package/dist/schema/boolean.d.ts.map +1 -1
  50. package/dist/schema/boolean.js +30 -1
  51. package/dist/schema/boolean.js.map +1 -1
  52. package/dist/schema/bytes.d.ts +39 -0
  53. package/dist/schema/bytes.d.ts.map +1 -1
  54. package/dist/schema/bytes.js +34 -1
  55. package/dist/schema/bytes.js.map +1 -1
  56. package/dist/schema/cid.d.ts +39 -0
  57. package/dist/schema/cid.d.ts.map +1 -1
  58. package/dist/schema/cid.js +35 -1
  59. package/dist/schema/cid.js.map +1 -1
  60. package/dist/schema/custom.d.ts +67 -1
  61. package/dist/schema/custom.d.ts.map +1 -1
  62. package/dist/schema/custom.js +55 -0
  63. package/dist/schema/custom.js.map +1 -1
  64. package/dist/schema/dict.d.ts +45 -0
  65. package/dist/schema/dict.d.ts.map +1 -1
  66. package/dist/schema/dict.js +46 -1
  67. package/dist/schema/dict.js.map +1 -1
  68. package/dist/schema/discriminated-union.d.ts +59 -0
  69. package/dist/schema/discriminated-union.d.ts.map +1 -1
  70. package/dist/schema/discriminated-union.js +47 -1
  71. package/dist/schema/discriminated-union.js.map +1 -1
  72. package/dist/schema/enum.d.ts +49 -0
  73. package/dist/schema/enum.d.ts.map +1 -1
  74. package/dist/schema/enum.js +49 -0
  75. package/dist/schema/enum.js.map +1 -1
  76. package/dist/schema/integer.d.ts +43 -0
  77. package/dist/schema/integer.d.ts.map +1 -1
  78. package/dist/schema/integer.js +38 -1
  79. package/dist/schema/integer.js.map +1 -1
  80. package/dist/schema/intersection.d.ts +55 -0
  81. package/dist/schema/intersection.d.ts.map +1 -1
  82. package/dist/schema/intersection.js +50 -0
  83. package/dist/schema/intersection.js.map +1 -1
  84. package/dist/schema/lex-map.d.ts +37 -0
  85. package/dist/schema/lex-map.d.ts.map +1 -0
  86. package/dist/schema/lex-map.js +60 -0
  87. package/dist/schema/lex-map.js.map +1 -0
  88. package/dist/schema/lex-value.d.ts +35 -0
  89. package/dist/schema/lex-value.d.ts.map +1 -0
  90. package/dist/schema/lex-value.js +87 -0
  91. package/dist/schema/lex-value.js.map +1 -0
  92. package/dist/schema/literal.d.ts +45 -0
  93. package/dist/schema/literal.d.ts.map +1 -1
  94. package/dist/schema/literal.js +45 -0
  95. package/dist/schema/literal.js.map +1 -1
  96. package/dist/schema/never.d.ts +43 -0
  97. package/dist/schema/never.d.ts.map +1 -1
  98. package/dist/schema/never.js +44 -1
  99. package/dist/schema/never.js.map +1 -1
  100. package/dist/schema/null.d.ts +30 -0
  101. package/dist/schema/null.d.ts.map +1 -1
  102. package/dist/schema/null.js +31 -1
  103. package/dist/schema/null.js.map +1 -1
  104. package/dist/schema/nullable.d.ts +42 -0
  105. package/dist/schema/nullable.d.ts.map +1 -1
  106. package/dist/schema/nullable.js +42 -0
  107. package/dist/schema/nullable.js.map +1 -1
  108. package/dist/schema/object.d.ts +57 -0
  109. package/dist/schema/object.d.ts.map +1 -1
  110. package/dist/schema/object.js +53 -1
  111. package/dist/schema/object.js.map +1 -1
  112. package/dist/schema/optional.d.ts +43 -0
  113. package/dist/schema/optional.d.ts.map +1 -1
  114. package/dist/schema/optional.js +43 -0
  115. package/dist/schema/optional.js.map +1 -1
  116. package/dist/schema/params.d.ts +96 -12
  117. package/dist/schema/params.d.ts.map +1 -1
  118. package/dist/schema/params.js +155 -21
  119. package/dist/schema/params.js.map +1 -1
  120. package/dist/schema/payload.d.ts +111 -15
  121. package/dist/schema/payload.d.ts.map +1 -1
  122. package/dist/schema/payload.js +73 -3
  123. package/dist/schema/payload.js.map +1 -1
  124. package/dist/schema/permission-set.d.ts +58 -0
  125. package/dist/schema/permission-set.d.ts.map +1 -1
  126. package/dist/schema/permission-set.js +50 -0
  127. package/dist/schema/permission-set.js.map +1 -1
  128. package/dist/schema/permission.d.ts +42 -0
  129. package/dist/schema/permission.d.ts.map +1 -1
  130. package/dist/schema/permission.js +39 -0
  131. package/dist/schema/permission.js.map +1 -1
  132. package/dist/schema/procedure.d.ts +64 -0
  133. package/dist/schema/procedure.d.ts.map +1 -1
  134. package/dist/schema/procedure.js +64 -0
  135. package/dist/schema/procedure.js.map +1 -1
  136. package/dist/schema/query.d.ts +55 -0
  137. package/dist/schema/query.d.ts.map +1 -1
  138. package/dist/schema/query.js +55 -0
  139. package/dist/schema/query.js.map +1 -1
  140. package/dist/schema/record.d.ts +76 -25
  141. package/dist/schema/record.d.ts.map +1 -1
  142. package/dist/schema/record.js +21 -0
  143. package/dist/schema/record.js.map +1 -1
  144. package/dist/schema/ref.d.ts +51 -0
  145. package/dist/schema/ref.d.ts.map +1 -1
  146. package/dist/schema/ref.js +18 -0
  147. package/dist/schema/ref.js.map +1 -1
  148. package/dist/schema/refine.d.ts +58 -9
  149. package/dist/schema/refine.d.ts.map +1 -1
  150. package/dist/schema/refine.js.map +1 -1
  151. package/dist/schema/regexp.d.ts +45 -0
  152. package/dist/schema/regexp.d.ts.map +1 -1
  153. package/dist/schema/regexp.js +46 -1
  154. package/dist/schema/regexp.js.map +1 -1
  155. package/dist/schema/string.d.ts +72 -6
  156. package/dist/schema/string.d.ts.map +1 -1
  157. package/dist/schema/string.js +56 -8
  158. package/dist/schema/string.js.map +1 -1
  159. package/dist/schema/subscription.d.ts +72 -2
  160. package/dist/schema/subscription.d.ts.map +1 -1
  161. package/dist/schema/subscription.js +59 -0
  162. package/dist/schema/subscription.js.map +1 -1
  163. package/dist/schema/token.d.ts +48 -0
  164. package/dist/schema/token.d.ts.map +1 -1
  165. package/dist/schema/token.js +49 -1
  166. package/dist/schema/token.js.map +1 -1
  167. package/dist/schema/typed-object.d.ts +73 -23
  168. package/dist/schema/typed-object.d.ts.map +1 -1
  169. package/dist/schema/typed-object.js +20 -1
  170. package/dist/schema/typed-object.js.map +1 -1
  171. package/dist/schema/typed-ref.d.ts +54 -0
  172. package/dist/schema/typed-ref.d.ts.map +1 -1
  173. package/dist/schema/typed-ref.js +16 -0
  174. package/dist/schema/typed-ref.js.map +1 -1
  175. package/dist/schema/typed-union.d.ts +51 -1
  176. package/dist/schema/typed-union.d.ts.map +1 -1
  177. package/dist/schema/typed-union.js +52 -2
  178. package/dist/schema/typed-union.js.map +1 -1
  179. package/dist/schema/union.d.ts +46 -0
  180. package/dist/schema/union.d.ts.map +1 -1
  181. package/dist/schema/union.js +41 -0
  182. package/dist/schema/union.js.map +1 -1
  183. package/dist/schema/unknown.d.ts +34 -0
  184. package/dist/schema/unknown.d.ts.map +1 -1
  185. package/dist/schema/unknown.js +34 -0
  186. package/dist/schema/unknown.js.map +1 -1
  187. package/dist/schema/with-default.d.ts +45 -0
  188. package/dist/schema/with-default.d.ts.map +1 -1
  189. package/dist/schema/with-default.js +45 -0
  190. package/dist/schema/with-default.js.map +1 -1
  191. package/dist/schema.d.ts +2 -1
  192. package/dist/schema.d.ts.map +1 -1
  193. package/dist/schema.js +2 -1
  194. package/dist/schema.js.map +1 -1
  195. package/dist/util/if-any.d.ts +2 -0
  196. package/dist/util/if-any.d.ts.map +1 -0
  197. package/dist/util/if-any.js +3 -0
  198. package/dist/util/if-any.js.map +1 -0
  199. package/package.json +3 -3
  200. package/src/core/$type.ts +150 -18
  201. package/src/core/record-key.ts +44 -0
  202. package/src/core/result.ts +86 -4
  203. package/src/core/schema.ts +244 -9
  204. package/src/core/string-format.ts +259 -13
  205. package/src/core/types.ts +91 -3
  206. package/src/core/validation-error.ts +60 -0
  207. package/src/core/validation-issue.ts +68 -2
  208. package/src/core/validator.ts +373 -12
  209. package/src/helpers.test.ts +110 -29
  210. package/src/helpers.ts +54 -25
  211. package/src/schema/array.test.ts +94 -79
  212. package/src/schema/array.ts +48 -1
  213. package/src/schema/blob.ts +50 -1
  214. package/src/schema/boolean.ts +31 -1
  215. package/src/schema/bytes.ts +41 -1
  216. package/src/schema/cid.ts +41 -1
  217. package/src/schema/custom.ts +68 -1
  218. package/src/schema/dict.ts +47 -1
  219. package/src/schema/discriminated-union.ts +61 -1
  220. package/src/schema/enum.ts +50 -0
  221. package/src/schema/integer.ts +45 -1
  222. package/src/schema/intersection.ts +56 -0
  223. package/src/schema/{unknown-object.test.ts → lex-map.test.ts} +9 -9
  224. package/src/schema/lex-map.ts +63 -0
  225. package/src/schema/lex-value.test.ts +81 -0
  226. package/src/schema/lex-value.ts +86 -0
  227. package/src/schema/literal.ts +46 -0
  228. package/src/schema/never.ts +45 -1
  229. package/src/schema/null.ts +32 -1
  230. package/src/schema/nullable.ts +43 -0
  231. package/src/schema/object.ts +59 -1
  232. package/src/schema/optional.ts +44 -0
  233. package/src/schema/params.test.ts +133 -38
  234. package/src/schema/params.ts +237 -37
  235. package/src/schema/payload.test.ts +3 -3
  236. package/src/schema/payload.ts +145 -42
  237. package/src/schema/permission-set.ts +58 -0
  238. package/src/schema/permission.ts +42 -0
  239. package/src/schema/procedure.ts +64 -0
  240. package/src/schema/query.ts +55 -0
  241. package/src/schema/record.ts +82 -16
  242. package/src/schema/ref.ts +52 -0
  243. package/src/schema/refine.ts +58 -9
  244. package/src/schema/regexp.ts +47 -1
  245. package/src/schema/string.test.ts +99 -2
  246. package/src/schema/string.ts +108 -15
  247. package/src/schema/subscription.ts +72 -2
  248. package/src/schema/token.ts +50 -1
  249. package/src/schema/typed-object.ts +81 -16
  250. package/src/schema/typed-ref.ts +55 -0
  251. package/src/schema/typed-union.ts +58 -3
  252. package/src/schema/union.ts +47 -0
  253. package/src/schema/unknown.ts +35 -0
  254. package/src/schema/with-default.ts +46 -0
  255. package/src/schema.ts +2 -1
  256. package/src/util/if-any.ts +3 -0
  257. package/dist/schema/unknown-object.d.ts +0 -8
  258. package/dist/schema/unknown-object.d.ts.map +0 -1
  259. package/dist/schema/unknown-object.js +0 -19
  260. package/dist/schema/unknown-object.js.map +0 -1
  261. package/src/schema/unknown-object.ts +0 -19
@@ -1,12 +1,55 @@
1
1
  import { Schema, ValidationContext } from '../core.js';
2
+ /**
3
+ * Configuration options for integer schema validation.
4
+ *
5
+ * @property minimum - Minimum allowed value (inclusive)
6
+ * @property maximum - Maximum allowed value (inclusive)
7
+ */
2
8
  export type IntegerSchemaOptions = {
3
9
  minimum?: number;
4
10
  maximum?: number;
5
11
  };
12
+ /**
13
+ * Schema for validating integer values with optional range constraints.
14
+ *
15
+ * Only accepts safe integers (values that can be exactly represented in JavaScript).
16
+ * Use {@link IntegerSchemaOptions} to constrain the allowed range.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const schema = new IntegerSchema({ minimum: 0, maximum: 100 })
21
+ * const result = schema.validate(42)
22
+ * ```
23
+ */
6
24
  export declare class IntegerSchema extends Schema<number> {
7
25
  readonly options?: IntegerSchemaOptions | undefined;
26
+ readonly type: "integer";
8
27
  constructor(options?: IntegerSchemaOptions | undefined);
9
28
  validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<number>;
10
29
  }
30
+ /**
31
+ * Creates an integer schema with optional minimum and maximum constraints.
32
+ *
33
+ * Validates that the input is a safe integer (can be exactly represented in JavaScript)
34
+ * and optionally falls within a specified range.
35
+ *
36
+ * @param options - Optional configuration for minimum and maximum values
37
+ * @returns A new {@link IntegerSchema} instance
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * // Basic integer
42
+ * const countSchema = l.integer()
43
+ *
44
+ * // With minimum value
45
+ * const positiveSchema = l.integer({ minimum: 1 })
46
+ *
47
+ * // With range constraints
48
+ * const percentSchema = l.integer({ minimum: 0, maximum: 100 })
49
+ *
50
+ * // Age validation
51
+ * const ageSchema = l.integer({ minimum: 0, maximum: 150 })
52
+ * ```
53
+ */
11
54
  export declare const integer: (options?: IntegerSchemaOptions) => IntegerSchema;
12
55
  //# sourceMappingURL=integer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"integer.d.ts","sourceRoot":"","sources":["../../src/schema/integer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGtD,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,qBAAa,aAAc,SAAQ,MAAM,CAAC,MAAM,CAAC;IACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,oBAAoB;gBAA9B,OAAO,CAAC,EAAE,oBAAoB,YAAA;IAInD,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAezD;AASD,eAAO,MAAM,OAAO,aACR,oBAAoB,kBAG9B,CAAA"}
1
+ {"version":3,"file":"integer.d.ts","sourceRoot":"","sources":["../../src/schema/integer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGtD;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,aAAc,SAAQ,MAAM,CAAC,MAAM,CAAC;IAGnC,QAAQ,CAAC,OAAO,CAAC,EAAE,oBAAoB;IAFnD,QAAQ,CAAC,IAAI,EAAG,SAAS,CAAS;gBAEb,OAAO,CAAC,EAAE,oBAAoB,YAAA;IAInD,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAezD;AASD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,OAAO,aACR,oBAAoB,kBAG9B,CAAA"}
@@ -3,15 +3,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.integer = exports.IntegerSchema = void 0;
4
4
  const core_js_1 = require("../core.js");
5
5
  const memoize_js_1 = require("../util/memoize.js");
6
+ /**
7
+ * Schema for validating integer values with optional range constraints.
8
+ *
9
+ * Only accepts safe integers (values that can be exactly represented in JavaScript).
10
+ * Use {@link IntegerSchemaOptions} to constrain the allowed range.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const schema = new IntegerSchema({ minimum: 0, maximum: 100 })
15
+ * const result = schema.validate(42)
16
+ * ```
17
+ */
6
18
  class IntegerSchema extends core_js_1.Schema {
7
19
  options;
20
+ type = 'integer';
8
21
  constructor(options) {
9
22
  super();
10
23
  this.options = options;
11
24
  }
12
25
  validateInContext(input, ctx) {
13
26
  if (!isInteger(input)) {
14
- return ctx.issueInvalidType(input, 'integer');
27
+ return ctx.issueUnexpectedType(input, 'integer');
15
28
  }
16
29
  if (this.options?.minimum != null && input < this.options.minimum) {
17
30
  return ctx.issueTooSmall(input, 'integer', this.options.minimum, input);
@@ -29,6 +42,30 @@ exports.IntegerSchema = IntegerSchema;
29
42
  function isInteger(input) {
30
43
  return Number.isSafeInteger(input);
31
44
  }
45
+ /**
46
+ * Creates an integer schema with optional minimum and maximum constraints.
47
+ *
48
+ * Validates that the input is a safe integer (can be exactly represented in JavaScript)
49
+ * and optionally falls within a specified range.
50
+ *
51
+ * @param options - Optional configuration for minimum and maximum values
52
+ * @returns A new {@link IntegerSchema} instance
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * // Basic integer
57
+ * const countSchema = l.integer()
58
+ *
59
+ * // With minimum value
60
+ * const positiveSchema = l.integer({ minimum: 1 })
61
+ *
62
+ * // With range constraints
63
+ * const percentSchema = l.integer({ minimum: 0, maximum: 100 })
64
+ *
65
+ * // Age validation
66
+ * const ageSchema = l.integer({ minimum: 0, maximum: 150 })
67
+ * ```
68
+ */
32
69
  exports.integer = (0, memoize_js_1.memoizedOptions)(function (options) {
33
70
  return new IntegerSchema(options);
34
71
  });
@@ -1 +1 @@
1
- {"version":3,"file":"integer.js","sourceRoot":"","sources":["../../src/schema/integer.ts"],"names":[],"mappings":";;;AAAA,wCAAsD;AACtD,mDAAoD;AAOpD,MAAa,aAAc,SAAQ,gBAAc;IAC1B;IAArB,YAAqB,OAA8B;QACjD,KAAK,EAAE,CAAA;QADY,YAAO,GAAP,OAAO,CAAuB;IAEnD,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACtB,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;QAC/C,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAClE,OAAO,GAAG,CAAC,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QACzE,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAClE,OAAO,GAAG,CAAC,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QACvE,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;CACF;AApBD,sCAoBC;AAED;;GAEG;AACH,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;AACpC,CAAC;AAEY,QAAA,OAAO,GAAiB,IAAA,4BAAe,EAAC,UACnD,OAA8B;IAE9B,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAA;AACnC,CAAC,CAAC,CAAA","sourcesContent":["import { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\nexport type IntegerSchemaOptions = {\n minimum?: number\n maximum?: number\n}\n\nexport class IntegerSchema extends Schema<number> {\n constructor(readonly options?: IntegerSchemaOptions) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (!isInteger(input)) {\n return ctx.issueInvalidType(input, 'integer')\n }\n\n if (this.options?.minimum != null && input < this.options.minimum) {\n return ctx.issueTooSmall(input, 'integer', this.options.minimum, input)\n }\n\n if (this.options?.maximum != null && input > this.options.maximum) {\n return ctx.issueTooBig(input, 'integer', this.options.maximum, input)\n }\n\n return ctx.success(input)\n }\n}\n\n/**\n * Simple wrapper around {@link Number.isSafeInteger} that acts as a type guard.\n */\nfunction isInteger(input: unknown): input is number {\n return Number.isSafeInteger(input)\n}\n\nexport const integer = /*#__PURE__*/ memoizedOptions(function (\n options?: IntegerSchemaOptions,\n) {\n return new IntegerSchema(options)\n})\n"]}
1
+ {"version":3,"file":"integer.js","sourceRoot":"","sources":["../../src/schema/integer.ts"],"names":[],"mappings":";;;AAAA,wCAAsD;AACtD,mDAAoD;AAapD;;;;;;;;;;;GAWG;AACH,MAAa,aAAc,SAAQ,gBAAc;IAG1B;IAFZ,IAAI,GAAG,SAAkB,CAAA;IAElC,YAAqB,OAA8B;QACjD,KAAK,EAAE,CAAA;QADY,YAAO,GAAP,OAAO,CAAuB;IAEnD,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACtB,OAAO,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;QAClD,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAClE,OAAO,GAAG,CAAC,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QACzE,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAClE,OAAO,GAAG,CAAC,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QACvE,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;CACF;AAtBD,sCAsBC;AAED;;GAEG;AACH,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;AACpC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACU,QAAA,OAAO,GAAiB,IAAA,4BAAe,EAAC,UACnD,OAA8B;IAE9B,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAA;AACnC,CAAC,CAAC,CAAA","sourcesContent":["import { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\n/**\n * Configuration options for integer schema validation.\n *\n * @property minimum - Minimum allowed value (inclusive)\n * @property maximum - Maximum allowed value (inclusive)\n */\nexport type IntegerSchemaOptions = {\n minimum?: number\n maximum?: number\n}\n\n/**\n * Schema for validating integer values with optional range constraints.\n *\n * Only accepts safe integers (values that can be exactly represented in JavaScript).\n * Use {@link IntegerSchemaOptions} to constrain the allowed range.\n *\n * @example\n * ```ts\n * const schema = new IntegerSchema({ minimum: 0, maximum: 100 })\n * const result = schema.validate(42)\n * ```\n */\nexport class IntegerSchema extends Schema<number> {\n readonly type = 'integer' as const\n\n constructor(readonly options?: IntegerSchemaOptions) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (!isInteger(input)) {\n return ctx.issueUnexpectedType(input, 'integer')\n }\n\n if (this.options?.minimum != null && input < this.options.minimum) {\n return ctx.issueTooSmall(input, 'integer', this.options.minimum, input)\n }\n\n if (this.options?.maximum != null && input > this.options.maximum) {\n return ctx.issueTooBig(input, 'integer', this.options.maximum, input)\n }\n\n return ctx.success(input)\n }\n}\n\n/**\n * Simple wrapper around {@link Number.isSafeInteger} that acts as a type guard.\n */\nfunction isInteger(input: unknown): input is number {\n return Number.isSafeInteger(input)\n}\n\n/**\n * Creates an integer schema with optional minimum and maximum constraints.\n *\n * Validates that the input is a safe integer (can be exactly represented in JavaScript)\n * and optionally falls within a specified range.\n *\n * @param options - Optional configuration for minimum and maximum values\n * @returns A new {@link IntegerSchema} instance\n *\n * @example\n * ```ts\n * // Basic integer\n * const countSchema = l.integer()\n *\n * // With minimum value\n * const positiveSchema = l.integer({ minimum: 1 })\n *\n * // With range constraints\n * const percentSchema = l.integer({ minimum: 0, maximum: 100 })\n *\n * // Age validation\n * const ageSchema = l.integer({ minimum: 0, maximum: 150 })\n * ```\n */\nexport const integer = /*#__PURE__*/ memoizedOptions(function (\n options?: IntegerSchemaOptions,\n) {\n return new IntegerSchema(options)\n})\n"]}
@@ -2,10 +2,15 @@ import { InferInput, InferOutput, Schema, Simplify, ValidationContext } from '..
2
2
  import { DictSchema } from './dict.js';
3
3
  import { ObjectSchema } from './object.js';
4
4
  /**
5
+ * Type utility for computing the intersection of two object types.
6
+ *
5
7
  * Allows to more accurately represent the intersection of two object types
6
8
  * where both types may share some keys, and one of them uses an index
7
9
  * signature.
8
10
  *
11
+ * @template A - First object type (typically from ObjectSchema)
12
+ * @template B - Second object type (typically from DictSchema)
13
+ *
9
14
  * @see {@link https://www.typescriptlang.org/play/?#code/C4TwDgpgBAglC8UDeUBmB7dAuKByARgIYBOuUAvlAGTJQDaA+lAJYB2UAzsMWwOYC6OVgFcAtvgjEKAKGkATCAGMANiWiL0rLlEI4YsjVuBQA1hBA4uPVrwRQARBnT2Dm7QDdCy4dESE6ZiD8UAD0IVAi4pJQABQcABbowspyUBIORMT2AJSyEAAeYOjExqCQUACSrMCSHErAzJoAPNJQsFAFNaxyHFAASkrFck1WfAA0UMKsJqzoAO6sAHxjrVAAQh35XT39g8TDozYTUzPzSyuLdqtwVKttMYHoqO00j88bnRDdvawQ7pJ3NpQAD860BbRwSHBQLadAA0ix2G91oJ1vDggAfWABcxPF5QOH8aFtci5aRlaAwVDMfIQVKIKo1Yh1RQNZq0Jw4AgkMjkCYoRiIzjcPioyISKTkRayBQqNRQQzaQgAMRpdL01NpclcRignm8EFVWrsKrVchxQVC4XF0SxmSAA Playground link}
10
15
  */
11
16
  export type Intersect<A, B> = B[keyof B] extends never ? A : keyof A & keyof B extends never ? // If A and B don't overlap, just return A & B
@@ -13,11 +18,61 @@ A & B : // Otherwise, properly represent the fact that accessing using an
13
18
  A & {
14
19
  [K in keyof B]: B[K] | A[keyof A & K];
15
20
  };
21
+ /**
22
+ * Schema for combining an object schema with a dictionary schema.
23
+ *
24
+ * Validates that the input matches both the fixed object shape and allows
25
+ * additional properties that match the dictionary schema. Properties defined
26
+ * in the object schema are validated by the object, and remaining properties
27
+ * are validated by the dictionary.
28
+ *
29
+ * @template Left - The ObjectSchema type for fixed properties
30
+ * @template Right - The DictSchema type for additional properties
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const schema = new IntersectionSchema(
35
+ * l.object({ name: l.string() }),
36
+ * l.dict(l.string(), l.integer())
37
+ * )
38
+ * // Validates: { name: 'test', score: 100, count: 5 }
39
+ * ```
40
+ */
16
41
  export declare class IntersectionSchema<const Left extends ObjectSchema = any, const Right extends DictSchema = any> extends Schema<Simplify<Intersect<InferInput<Left>, InferInput<Right>>>, Simplify<Intersect<InferOutput<Left>, InferOutput<Right>>>> {
17
42
  protected readonly left: Left;
18
43
  protected readonly right: Right;
44
+ readonly type: "intersection";
19
45
  constructor(left: Left, right: Right);
20
46
  validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<Record<string, unknown>>;
21
47
  }
48
+ /**
49
+ * Creates an intersection schema combining fixed object properties with dynamic dictionary properties.
50
+ *
51
+ * Useful for objects that have a known set of properties plus additional
52
+ * arbitrary properties that follow a pattern.
53
+ *
54
+ * @param left - Object schema defining the fixed, known properties
55
+ * @param right - Dictionary schema for validating additional properties
56
+ * @returns A new {@link IntersectionSchema} instance
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * // Object with fixed and dynamic properties
61
+ * const configSchema = l.intersection(
62
+ * l.object({
63
+ * version: l.integer(),
64
+ * name: l.string(),
65
+ * }),
66
+ * l.dict(l.string(), l.string()) // Additional string properties
67
+ * )
68
+ *
69
+ * configSchema.parse({
70
+ * version: 1,
71
+ * name: 'my-config',
72
+ * customField: 'value',
73
+ * anotherField: 'another',
74
+ * })
75
+ * ```
76
+ */
22
77
  export declare function intersection<const Left extends ObjectSchema, const Right extends DictSchema>(left: Left, right: Right): IntersectionSchema<Left, Right>;
23
78
  //# sourceMappingURL=intersection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"intersection.d.ts","sourceRoot":"","sources":["../../src/schema/intersection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,MAAM,EACN,QAAQ,EACR,iBAAiB,EAClB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,KAAK,GAClD,CAAC,GACD,MAAM,CAAC,GAAG,MAAM,CAAC,SAAS,KAAK,GAE7B,AADA,8CAA8C;AAC9C,CAAC,GAAG,CAAC,GAGL,AAFA,iEAAiE;AAEjE,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;CAAE,CAAA;AAEnD,qBAAa,kBAAkB,CAC7B,KAAK,CAAC,IAAI,SAAS,YAAY,GAAG,GAAG,EACrC,KAAK,CAAC,KAAK,SAAS,UAAU,GAAG,GAAG,CACpC,SAAQ,MAAM,CACd,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EACxD,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAC3D;IAEG,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI;IAC7B,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK;gBADZ,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK;IAKjC,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAQzD;AAGD,wBAAgB,YAAY,CAC1B,KAAK,CAAC,IAAI,SAAS,YAAY,EAC/B,KAAK,CAAC,KAAK,SAAS,UAAU,EAC9B,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,mCAEzB"}
1
+ {"version":3,"file":"intersection.d.ts","sourceRoot":"","sources":["../../src/schema/intersection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,MAAM,EACN,QAAQ,EACR,iBAAiB,EAClB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,KAAK,GAClD,CAAC,GACD,MAAM,CAAC,GAAG,MAAM,CAAC,SAAS,KAAK,GAE7B,AADA,8CAA8C;AAC9C,CAAC,GAAG,CAAC,GAGL,AAFA,iEAAiE;AAEjE,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;CAAE,CAAA;AAEnD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,kBAAkB,CAC7B,KAAK,CAAC,IAAI,SAAS,YAAY,GAAG,GAAG,EACrC,KAAK,CAAC,KAAK,SAAS,UAAU,GAAG,GAAG,CACpC,SAAQ,MAAM,CACd,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EACxD,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAC3D;IAIG,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI;IAC7B,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK;IAJjC,QAAQ,CAAC,IAAI,EAAG,cAAc,CAAS;gBAGlB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK;IAKjC,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAQzD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,wBAAgB,YAAY,CAC1B,KAAK,CAAC,IAAI,SAAS,YAAY,EAC/B,KAAK,CAAC,KAAK,SAAS,UAAU,EAC9B,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,mCAEzB"}
@@ -3,9 +3,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IntersectionSchema = void 0;
4
4
  exports.intersection = intersection;
5
5
  const core_js_1 = require("../core.js");
6
+ /**
7
+ * Schema for combining an object schema with a dictionary schema.
8
+ *
9
+ * Validates that the input matches both the fixed object shape and allows
10
+ * additional properties that match the dictionary schema. Properties defined
11
+ * in the object schema are validated by the object, and remaining properties
12
+ * are validated by the dictionary.
13
+ *
14
+ * @template Left - The ObjectSchema type for fixed properties
15
+ * @template Right - The DictSchema type for additional properties
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const schema = new IntersectionSchema(
20
+ * l.object({ name: l.string() }),
21
+ * l.dict(l.string(), l.integer())
22
+ * )
23
+ * // Validates: { name: 'test', score: 100, count: 5 }
24
+ * ```
25
+ */
6
26
  class IntersectionSchema extends core_js_1.Schema {
7
27
  left;
8
28
  right;
29
+ type = 'intersection';
9
30
  constructor(left, right) {
10
31
  super();
11
32
  this.left = left;
@@ -21,6 +42,35 @@ class IntersectionSchema extends core_js_1.Schema {
21
42
  }
22
43
  }
23
44
  exports.IntersectionSchema = IntersectionSchema;
45
+ /**
46
+ * Creates an intersection schema combining fixed object properties with dynamic dictionary properties.
47
+ *
48
+ * Useful for objects that have a known set of properties plus additional
49
+ * arbitrary properties that follow a pattern.
50
+ *
51
+ * @param left - Object schema defining the fixed, known properties
52
+ * @param right - Dictionary schema for validating additional properties
53
+ * @returns A new {@link IntersectionSchema} instance
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * // Object with fixed and dynamic properties
58
+ * const configSchema = l.intersection(
59
+ * l.object({
60
+ * version: l.integer(),
61
+ * name: l.string(),
62
+ * }),
63
+ * l.dict(l.string(), l.string()) // Additional string properties
64
+ * )
65
+ *
66
+ * configSchema.parse({
67
+ * version: 1,
68
+ * name: 'my-config',
69
+ * customField: 'value',
70
+ * anotherField: 'another',
71
+ * })
72
+ * ```
73
+ */
24
74
  /*@__NO_SIDE_EFFECTS__*/
25
75
  function intersection(left, right) {
26
76
  return new IntersectionSchema(left, right);
@@ -1 +1 @@
1
- {"version":3,"file":"intersection.js","sourceRoot":"","sources":["../../src/schema/intersection.ts"],"names":[],"mappings":";;;AAmDA,oCAKC;AAxDD,wCAMmB;AAoBnB,MAAa,kBAGX,SAAQ,gBAGT;IAEsB;IACA;IAFrB,YACqB,IAAU,EACV,KAAY;QAE/B,KAAK,EAAE,CAAA;QAHY,SAAI,GAAJ,IAAI,CAAM;QACV,UAAK,GAAL,KAAK,CAAO;IAGjC,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,MAAM,UAAU,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;QACjD,IAAI,CAAC,UAAU,CAAC,OAAO;YAAE,OAAO,UAAU,CAAA;QAE1C,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,UAAU,CAAC,KAAK,EAAE,GAAG,EAAE;YACzD,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,aAAa;SACrC,CAAC,CAAA;IACJ,CAAC;CACF;AAtBD,gDAsBC;AAED,wBAAwB;AACxB,SAAgB,YAAY,CAG1B,IAAU,EAAE,KAAY;IACxB,OAAO,IAAI,kBAAkB,CAAc,IAAI,EAAE,KAAK,CAAC,CAAA;AACzD,CAAC","sourcesContent":["import {\n InferInput,\n InferOutput,\n Schema,\n Simplify,\n ValidationContext,\n} from '../core.js'\nimport { DictSchema } from './dict.js'\nimport { ObjectSchema } from './object.js'\n\n/**\n * Allows to more accurately represent the intersection of two object types\n * where both types may share some keys, and one of them uses an index\n * signature.\n *\n * @see {@link https://www.typescriptlang.org/play/?#code/C4TwDgpgBAglC8UDeUBmB7dAuKByARgIYBOuUAvlAGTJQDaA+lAJYB2UAzsMWwOYC6OVgFcAtvgjEKAKGkATCAGMANiWiL0rLlEI4YsjVuBQA1hBA4uPVrwRQARBnT2Dm7QDdCy4dESE6ZiD8UAD0IVAi4pJQABQcABbowspyUBIORMT2AJSyEAAeYOjExqCQUACSrMCSHErAzJoAPNJQsFAFNaxyHFAASkrFck1WfAA0UMKsJqzoAO6sAHxjrVAAQh35XT39g8TDozYTUzPzSyuLdqtwVKttMYHoqO00j88bnRDdvawQ7pJ3NpQAD860BbRwSHBQLadAA0ix2G91oJ1vDggAfWABcxPF5QOH8aFtci5aRlaAwVDMfIQVKIKo1Yh1RQNZq0Jw4AgkMjkCYoRiIzjcPioyISKTkRayBQqNRQQzaQgAMRpdL01NpclcRignm8EFVWrsKrVchxQVC4XF0SxmSAA Playground link}\n */\nexport type Intersect<A, B> = B[keyof B] extends never\n ? A\n : keyof A & keyof B extends never\n ? // If A and B don't overlap, just return A & B\n A & B\n : // Otherwise, properly represent the fact that accessing using an\n // index signature could return a value from either A or B\n A & { [K in keyof B]: B[K] | A[keyof A & K] }\n\nexport class IntersectionSchema<\n const Left extends ObjectSchema = any,\n const Right extends DictSchema = any,\n> extends Schema<\n Simplify<Intersect<InferInput<Left>, InferInput<Right>>>,\n Simplify<Intersect<InferOutput<Left>, InferOutput<Right>>>\n> {\n constructor(\n protected readonly left: Left,\n protected readonly right: Right,\n ) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n const leftResult = ctx.validate(input, this.left)\n if (!leftResult.success) return leftResult\n\n return this.right.validateInContext(leftResult.value, ctx, {\n ignoredKeys: this.left.validatorsMap,\n })\n }\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nexport function intersection<\n const Left extends ObjectSchema,\n const Right extends DictSchema,\n>(left: Left, right: Right) {\n return new IntersectionSchema<Left, Right>(left, right)\n}\n"]}
1
+ {"version":3,"file":"intersection.js","sourceRoot":"","sources":["../../src/schema/intersection.ts"],"names":[],"mappings":";;;AA2GA,oCAKC;AAhHD,wCAMmB;AAyBnB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,kBAGX,SAAQ,gBAGT;IAIsB;IACA;IAJZ,IAAI,GAAG,cAAuB,CAAA;IAEvC,YACqB,IAAU,EACV,KAAY;QAE/B,KAAK,EAAE,CAAA;QAHY,SAAI,GAAJ,IAAI,CAAM;QACV,UAAK,GAAL,KAAK,CAAO;IAGjC,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,MAAM,UAAU,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;QACjD,IAAI,CAAC,UAAU,CAAC,OAAO;YAAE,OAAO,UAAU,CAAA;QAE1C,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,UAAU,CAAC,KAAK,EAAE,GAAG,EAAE;YACzD,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,aAAa;SACrC,CAAC,CAAA;IACJ,CAAC;CACF;AAxBD,gDAwBC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAwB;AACxB,SAAgB,YAAY,CAG1B,IAAU,EAAE,KAAY;IACxB,OAAO,IAAI,kBAAkB,CAAc,IAAI,EAAE,KAAK,CAAC,CAAA;AACzD,CAAC","sourcesContent":["import {\n InferInput,\n InferOutput,\n Schema,\n Simplify,\n ValidationContext,\n} from '../core.js'\nimport { DictSchema } from './dict.js'\nimport { ObjectSchema } from './object.js'\n\n/**\n * Type utility for computing the intersection of two object types.\n *\n * Allows to more accurately represent the intersection of two object types\n * where both types may share some keys, and one of them uses an index\n * signature.\n *\n * @template A - First object type (typically from ObjectSchema)\n * @template B - Second object type (typically from DictSchema)\n *\n * @see {@link https://www.typescriptlang.org/play/?#code/C4TwDgpgBAglC8UDeUBmB7dAuKByARgIYBOuUAvlAGTJQDaA+lAJYB2UAzsMWwOYC6OVgFcAtvgjEKAKGkATCAGMANiWiL0rLlEI4YsjVuBQA1hBA4uPVrwRQARBnT2Dm7QDdCy4dESE6ZiD8UAD0IVAi4pJQABQcABbowspyUBIORMT2AJSyEAAeYOjExqCQUACSrMCSHErAzJoAPNJQsFAFNaxyHFAASkrFck1WfAA0UMKsJqzoAO6sAHxjrVAAQh35XT39g8TDozYTUzPzSyuLdqtwVKttMYHoqO00j88bnRDdvawQ7pJ3NpQAD860BbRwSHBQLadAA0ix2G91oJ1vDggAfWABcxPF5QOH8aFtci5aRlaAwVDMfIQVKIKo1Yh1RQNZq0Jw4AgkMjkCYoRiIzjcPioyISKTkRayBQqNRQQzaQgAMRpdL01NpclcRignm8EFVWrsKrVchxQVC4XF0SxmSAA Playground link}\n */\nexport type Intersect<A, B> = B[keyof B] extends never\n ? A\n : keyof A & keyof B extends never\n ? // If A and B don't overlap, just return A & B\n A & B\n : // Otherwise, properly represent the fact that accessing using an\n // index signature could return a value from either A or B\n A & { [K in keyof B]: B[K] | A[keyof A & K] }\n\n/**\n * Schema for combining an object schema with a dictionary schema.\n *\n * Validates that the input matches both the fixed object shape and allows\n * additional properties that match the dictionary schema. Properties defined\n * in the object schema are validated by the object, and remaining properties\n * are validated by the dictionary.\n *\n * @template Left - The ObjectSchema type for fixed properties\n * @template Right - The DictSchema type for additional properties\n *\n * @example\n * ```ts\n * const schema = new IntersectionSchema(\n * l.object({ name: l.string() }),\n * l.dict(l.string(), l.integer())\n * )\n * // Validates: { name: 'test', score: 100, count: 5 }\n * ```\n */\nexport class IntersectionSchema<\n const Left extends ObjectSchema = any,\n const Right extends DictSchema = any,\n> extends Schema<\n Simplify<Intersect<InferInput<Left>, InferInput<Right>>>,\n Simplify<Intersect<InferOutput<Left>, InferOutput<Right>>>\n> {\n readonly type = 'intersection' as const\n\n constructor(\n protected readonly left: Left,\n protected readonly right: Right,\n ) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n const leftResult = ctx.validate(input, this.left)\n if (!leftResult.success) return leftResult\n\n return this.right.validateInContext(leftResult.value, ctx, {\n ignoredKeys: this.left.validatorsMap,\n })\n }\n}\n\n/**\n * Creates an intersection schema combining fixed object properties with dynamic dictionary properties.\n *\n * Useful for objects that have a known set of properties plus additional\n * arbitrary properties that follow a pattern.\n *\n * @param left - Object schema defining the fixed, known properties\n * @param right - Dictionary schema for validating additional properties\n * @returns A new {@link IntersectionSchema} instance\n *\n * @example\n * ```ts\n * // Object with fixed and dynamic properties\n * const configSchema = l.intersection(\n * l.object({\n * version: l.integer(),\n * name: l.string(),\n * }),\n * l.dict(l.string(), l.string()) // Additional string properties\n * )\n *\n * configSchema.parse({\n * version: 1,\n * name: 'my-config',\n * customField: 'value',\n * anotherField: 'another',\n * })\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function intersection<\n const Left extends ObjectSchema,\n const Right extends DictSchema,\n>(left: Left, right: Right) {\n return new IntersectionSchema<Left, Right>(left, right)\n}\n"]}
@@ -0,0 +1,37 @@
1
+ import { LexMap } from '@atproto/lex-data';
2
+ import { Schema, ValidationContext } from '../core.js';
3
+ export type { LexMap };
4
+ /**
5
+ * AT Protocol lexicon schema definitions with "type": "unknown" are represented
6
+ * as plain objects with string keys and values that are valid AT Protocol data
7
+ * types (string, integer, boolean, null, bytes, cid, array, or object). This
8
+ * type alias corresponds to the expected structure of such "unknown" schema
9
+ * values.
10
+ */
11
+ export declare class LexMapSchema extends Schema<LexMap> {
12
+ readonly type: "lexMap";
13
+ validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<Record<string, unknown>>;
14
+ }
15
+ /**
16
+ * Creates a schema that accepts any plain object with string keys and values
17
+ * that are valid AT Protocol data types (string, integer, boolean, null, bytes,
18
+ * cid, array, or object).
19
+ *
20
+ * @see {@link LexMap} from `@atproto/lex-data` for the type definition of valid AT Protocol data types
21
+ * @returns A new {@link LexMapSchema} instance
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * // Accept any object shape
26
+ * const schema = l.lexMap()
27
+ *
28
+ * schema.validate({ any: 'props' }) // success
29
+ * schema.validate([1, 2, 3]) // fails - only plain objects are accepted
30
+ * schema.validate({ foo: new Date() }) // fails - Date is not a valid LexValue
31
+ * schema.validate({ foo: 1.2 }) // fails - 1.2 is not a valid LexValue (not an integer)
32
+ * ```
33
+ */
34
+ export declare const lexMap: () => LexMapSchema;
35
+ /** @deprecated Use {@link lexMap} instead */
36
+ export declare const unknownObject: () => LexMapSchema;
37
+ //# sourceMappingURL=lex-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lex-map.d.ts","sourceRoot":"","sources":["../../src/schema/lex-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAMtD,YAAY,EAAE,MAAM,EAAE,CAAA;AAEtB;;;;;;GAMG;AACH,qBAAa,YAAa,SAAQ,MAAM,CAAC,MAAM,CAAC;IAC9C,QAAQ,CAAC,IAAI,EAAG,QAAQ,CAAS;IAEjC,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAiBzD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,MAAM,oBAEjB,CAAA;AAEF,6CAA6C;AAC7C,eAAO,MAAM,aAAa,oBAAS,CAAA"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unknownObject = exports.lexMap = exports.LexMapSchema = void 0;
4
+ const lex_data_1 = require("@atproto/lex-data");
5
+ const core_js_1 = require("../core.js");
6
+ const memoize_js_1 = require("../util/memoize.js");
7
+ const lex_value_js_1 = require("./lex-value.js");
8
+ const propertyValueSchema = /*#__PURE__*/ (0, lex_value_js_1.lexValue)();
9
+ /**
10
+ * AT Protocol lexicon schema definitions with "type": "unknown" are represented
11
+ * as plain objects with string keys and values that are valid AT Protocol data
12
+ * types (string, integer, boolean, null, bytes, cid, array, or object). This
13
+ * type alias corresponds to the expected structure of such "unknown" schema
14
+ * values.
15
+ */
16
+ class LexMapSchema extends core_js_1.Schema {
17
+ type = 'lexMap';
18
+ validateInContext(input, ctx) {
19
+ if (!(0, lex_data_1.isPlainObject)(input)) {
20
+ return ctx.issueUnexpectedType(input, 'object');
21
+ }
22
+ for (const key of Object.keys(input)) {
23
+ // @NOTE We use a lexValue() schema here to recursively validate all
24
+ // nested values, which ensures that the error reporting includes the
25
+ // correct path and type information for any invalid nested values. This
26
+ // allows for more informative error descriptions than a simple "isLexMap"
27
+ // check.
28
+ const r = ctx.validateChild(input, key, propertyValueSchema); // recursively validate all properties
29
+ if (!r.success)
30
+ return r;
31
+ }
32
+ return ctx.success(input);
33
+ }
34
+ }
35
+ exports.LexMapSchema = LexMapSchema;
36
+ /**
37
+ * Creates a schema that accepts any plain object with string keys and values
38
+ * that are valid AT Protocol data types (string, integer, boolean, null, bytes,
39
+ * cid, array, or object).
40
+ *
41
+ * @see {@link LexMap} from `@atproto/lex-data` for the type definition of valid AT Protocol data types
42
+ * @returns A new {@link LexMapSchema} instance
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * // Accept any object shape
47
+ * const schema = l.lexMap()
48
+ *
49
+ * schema.validate({ any: 'props' }) // success
50
+ * schema.validate([1, 2, 3]) // fails - only plain objects are accepted
51
+ * schema.validate({ foo: new Date() }) // fails - Date is not a valid LexValue
52
+ * schema.validate({ foo: 1.2 }) // fails - 1.2 is not a valid LexValue (not an integer)
53
+ * ```
54
+ */
55
+ exports.lexMap = (0, memoize_js_1.memoizedOptions)(function () {
56
+ return new LexMapSchema();
57
+ });
58
+ /** @deprecated Use {@link lexMap} instead */
59
+ exports.unknownObject = exports.lexMap;
60
+ //# sourceMappingURL=lex-map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lex-map.js","sourceRoot":"","sources":["../../src/schema/lex-map.ts"],"names":[],"mappings":";;;AAAA,gDAAyD;AACzD,wCAAsD;AACtD,mDAAoD;AACpD,iDAAyC;AAEzC,MAAM,mBAAmB,GAAG,aAAa,CAAC,IAAA,uBAAQ,GAAE,CAAA;AAIpD;;;;;;GAMG;AACH,MAAa,YAAa,SAAQ,gBAAc;IACrC,IAAI,GAAG,QAAiB,CAAA;IAEjC,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,CAAC,IAAA,wBAAa,EAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QACjD,CAAC;QAED,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACrC,oEAAoE;YACpE,qEAAqE;YACrE,wEAAwE;YACxE,0EAA0E;YAC1E,SAAS;YACT,MAAM,CAAC,GAAG,GAAG,CAAC,aAAa,CAAC,KAAK,EAAE,GAAG,EAAE,mBAAmB,CAAC,CAAA,CAAC,sCAAsC;YACnG,IAAI,CAAC,CAAC,CAAC,OAAO;gBAAE,OAAO,CAAC,CAAA;QAC1B,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;CACF;AApBD,oCAoBC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACU,QAAA,MAAM,GAAiB,IAAA,4BAAe,EAAC;IAClD,OAAO,IAAI,YAAY,EAAE,CAAA;AAC3B,CAAC,CAAC,CAAA;AAEF,6CAA6C;AAChC,QAAA,aAAa,GAAG,cAAM,CAAA","sourcesContent":["import { LexMap, isPlainObject } from '@atproto/lex-data'\nimport { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\nimport { lexValue } from './lex-value.js'\n\nconst propertyValueSchema = /*#__PURE__*/ lexValue()\n\nexport type { LexMap }\n\n/**\n * AT Protocol lexicon schema definitions with \"type\": \"unknown\" are represented\n * as plain objects with string keys and values that are valid AT Protocol data\n * types (string, integer, boolean, null, bytes, cid, array, or object). This\n * type alias corresponds to the expected structure of such \"unknown\" schema\n * values.\n */\nexport class LexMapSchema extends Schema<LexMap> {\n readonly type = 'lexMap' as const\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (!isPlainObject(input)) {\n return ctx.issueUnexpectedType(input, 'object')\n }\n\n for (const key of Object.keys(input)) {\n // @NOTE We use a lexValue() schema here to recursively validate all\n // nested values, which ensures that the error reporting includes the\n // correct path and type information for any invalid nested values. This\n // allows for more informative error descriptions than a simple \"isLexMap\"\n // check.\n const r = ctx.validateChild(input, key, propertyValueSchema) // recursively validate all properties\n if (!r.success) return r\n }\n\n return ctx.success(input)\n }\n}\n\n/**\n * Creates a schema that accepts any plain object with string keys and values\n * that are valid AT Protocol data types (string, integer, boolean, null, bytes,\n * cid, array, or object).\n *\n * @see {@link LexMap} from `@atproto/lex-data` for the type definition of valid AT Protocol data types\n * @returns A new {@link LexMapSchema} instance\n *\n * @example\n * ```ts\n * // Accept any object shape\n * const schema = l.lexMap()\n *\n * schema.validate({ any: 'props' }) // success\n * schema.validate([1, 2, 3]) // fails - only plain objects are accepted\n * schema.validate({ foo: new Date() }) // fails - Date is not a valid LexValue\n * schema.validate({ foo: 1.2 }) // fails - 1.2 is not a valid LexValue (not an integer)\n * ```\n */\nexport const lexMap = /*#__PURE__*/ memoizedOptions(function () {\n return new LexMapSchema()\n})\n\n/** @deprecated Use {@link lexMap} instead */\nexport const unknownObject = lexMap\n"]}
@@ -0,0 +1,35 @@
1
+ import { LexValue } from '@atproto/lex-data';
2
+ import { Schema, ValidationContext } from '../core.js';
3
+ export type { LexValue };
4
+ /**
5
+ * AT Protocol lexicon values are any valid AT Protocol data types: string,
6
+ * integer, boolean, null, bytes, cid, array, or object.
7
+ */
8
+ export declare class LexValueSchema extends Schema<LexValue> {
9
+ readonly type: "lexValue";
10
+ validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<any[] | Record<string, unknown> | import("@atproto/lex-data").LexScalar>;
11
+ }
12
+ /**
13
+ * Creates a schema that accepts any valid AT Protocol data type: string,
14
+ * integer, boolean, null, bytes, cid, array, or plain object. Arrays and
15
+ * objects are recursively validated to ensure all nested values are also valid
16
+ * AT Protocol data types.
17
+ *
18
+ * @see {@link LexValue} from `@atproto/lex-data` for the type definition of valid AT Protocol data types
19
+ * @returns A new {@link LexValueSchema} instance
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const schema = l.lexValue()
24
+ *
25
+ * schema.validate('hello') // success
26
+ * schema.validate(42) // success
27
+ * schema.validate(null) // success
28
+ * schema.validate([1, 'two', null]) // success
29
+ * schema.validate({ any: 'props' }) // success
30
+ * schema.validate(new Date()) // fails - Date is not a valid LexValue
31
+ * schema.validate({ foo: 1.2 }) // fails - 1.2 is not a valid LexValue (not an integer)
32
+ * ```
33
+ */
34
+ export declare const lexValue: () => LexValueSchema;
35
+ //# sourceMappingURL=lex-value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lex-value.d.ts","sourceRoot":"","sources":["../../src/schema/lex-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA8B,MAAM,mBAAmB,CAAA;AACxE,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGtD,YAAY,EAAE,QAAQ,EAAE,CAAA;AAexB;;;GAGG;AACH,qBAAa,cAAe,SAAQ,MAAM,CAAC,QAAQ,CAAC;IAClD,QAAQ,CAAC,IAAI,EAAG,UAAU,CAAS;IAEnC,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAiCzD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,QAAQ,sBAEnB,CAAA"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lexValue = exports.LexValueSchema = void 0;
4
+ const lex_data_1 = require("@atproto/lex-data");
5
+ const core_js_1 = require("../core.js");
6
+ const memoize_js_1 = require("../util/memoize.js");
7
+ const EXPECTED_TYPES = Object.freeze([
8
+ // Scalar types
9
+ 'null',
10
+ 'boolean',
11
+ 'integer',
12
+ 'string',
13
+ 'cid',
14
+ 'bytes',
15
+ // Recursive types
16
+ 'array',
17
+ 'object',
18
+ ]);
19
+ /**
20
+ * AT Protocol lexicon values are any valid AT Protocol data types: string,
21
+ * integer, boolean, null, bytes, cid, array, or object.
22
+ */
23
+ class LexValueSchema extends core_js_1.Schema {
24
+ type = 'lexValue';
25
+ validateInContext(input, ctx) {
26
+ // @NOTE We are *not* using "isLexValue" here to allow for more specific
27
+ // error messages about the path and type of the invalid value. The
28
+ // "isLexValue" check is effectively performed by the recursive validation
29
+ // of child properties below.
30
+ // @NOTE There are two limitations to the fact that we are not using
31
+ // "isLexValue" here:
32
+ // 1. We cannot detect circular references in objects or arrays, which would
33
+ // cause infinite recursion. However, circular references are not valid
34
+ // AT Protocol data types, so this is not a concern for valid input. This
35
+ // could easily be addressed in the "validateChild" method by keeping
36
+ // track of "parent" objects.
37
+ // 2. We are limited in the recursion depth we can validate due to potential
38
+ // recursion depth limits in JavaScript. However, this is also not a
39
+ // concern for most valid input, as extremely deep nesting is unlikely in
40
+ // typical use cases.
41
+ if ((0, lex_data_1.isPlainObject)(input)) {
42
+ for (const key of Object.keys(input)) {
43
+ const r = ctx.validateChild(input, key, this); // recursively validate all properties
44
+ if (!r.success)
45
+ return r;
46
+ }
47
+ }
48
+ else if (Array.isArray(input)) {
49
+ for (let i = 0; i < input.length; i++) {
50
+ const r = ctx.validateChild(input, i, this); // recursively validate all array items
51
+ if (!r.success)
52
+ return r;
53
+ }
54
+ }
55
+ else if (!(0, lex_data_1.isLexScalar)(input)) {
56
+ return ctx.issueInvalidType(input, EXPECTED_TYPES);
57
+ }
58
+ return ctx.success(input);
59
+ }
60
+ }
61
+ exports.LexValueSchema = LexValueSchema;
62
+ /**
63
+ * Creates a schema that accepts any valid AT Protocol data type: string,
64
+ * integer, boolean, null, bytes, cid, array, or plain object. Arrays and
65
+ * objects are recursively validated to ensure all nested values are also valid
66
+ * AT Protocol data types.
67
+ *
68
+ * @see {@link LexValue} from `@atproto/lex-data` for the type definition of valid AT Protocol data types
69
+ * @returns A new {@link LexValueSchema} instance
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * const schema = l.lexValue()
74
+ *
75
+ * schema.validate('hello') // success
76
+ * schema.validate(42) // success
77
+ * schema.validate(null) // success
78
+ * schema.validate([1, 'two', null]) // success
79
+ * schema.validate({ any: 'props' }) // success
80
+ * schema.validate(new Date()) // fails - Date is not a valid LexValue
81
+ * schema.validate({ foo: 1.2 }) // fails - 1.2 is not a valid LexValue (not an integer)
82
+ * ```
83
+ */
84
+ exports.lexValue = (0, memoize_js_1.memoizedOptions)(function () {
85
+ return new LexValueSchema();
86
+ });
87
+ //# sourceMappingURL=lex-value.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lex-value.js","sourceRoot":"","sources":["../../src/schema/lex-value.ts"],"names":[],"mappings":";;;AAAA,gDAAwE;AACxE,wCAAsD;AACtD,mDAAoD;AAIpD,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;IACnC,eAAe;IACf,MAAM;IACN,SAAS;IACT,SAAS;IACT,QAAQ;IACR,KAAK;IACL,OAAO;IACP,kBAAkB;IAClB,OAAO;IACP,QAAQ;CACA,CAAC,CAAA;AAEX;;;GAGG;AACH,MAAa,cAAe,SAAQ,gBAAgB;IACzC,IAAI,GAAG,UAAmB,CAAA;IAEnC,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,wEAAwE;QACxE,mEAAmE;QACnE,0EAA0E;QAC1E,6BAA6B;QAE7B,oEAAoE;QACpE,qBAAqB;QACrB,4EAA4E;QAC5E,0EAA0E;QAC1E,4EAA4E;QAC5E,wEAAwE;QACxE,gCAAgC;QAChC,4EAA4E;QAC5E,uEAAuE;QACvE,4EAA4E;QAC5E,wBAAwB;QACxB,IAAI,IAAA,wBAAa,EAAC,KAAK,CAAC,EAAE,CAAC;YACzB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBACrC,MAAM,CAAC,GAAG,GAAG,CAAC,aAAa,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA,CAAC,sCAAsC;gBACpF,IAAI,CAAC,CAAC,CAAC,OAAO;oBAAE,OAAO,CAAC,CAAA;YAC1B,CAAC;QACH,CAAC;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACtC,MAAM,CAAC,GAAG,GAAG,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,CAAA,CAAC,uCAAuC;gBACnF,IAAI,CAAC,CAAC,CAAC,OAAO;oBAAE,OAAO,CAAC,CAAA;YAC1B,CAAC;QACH,CAAC;aAAM,IAAI,CAAC,IAAA,sBAAW,EAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,cAAc,CAAC,CAAA;QACpD,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;CACF;AApCD,wCAoCC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACU,QAAA,QAAQ,GAAiB,IAAA,4BAAe,EAAC;IACpD,OAAO,IAAI,cAAc,EAAE,CAAA;AAC7B,CAAC,CAAC,CAAA","sourcesContent":["import { LexValue, isLexScalar, isPlainObject } from '@atproto/lex-data'\nimport { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\nexport type { LexValue }\n\nconst EXPECTED_TYPES = Object.freeze([\n // Scalar types\n 'null',\n 'boolean',\n 'integer',\n 'string',\n 'cid',\n 'bytes',\n // Recursive types\n 'array',\n 'object',\n] as const)\n\n/**\n * AT Protocol lexicon values are any valid AT Protocol data types: string,\n * integer, boolean, null, bytes, cid, array, or object.\n */\nexport class LexValueSchema extends Schema<LexValue> {\n readonly type = 'lexValue' as const\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n // @NOTE We are *not* using \"isLexValue\" here to allow for more specific\n // error messages about the path and type of the invalid value. The\n // \"isLexValue\" check is effectively performed by the recursive validation\n // of child properties below.\n\n // @NOTE There are two limitations to the fact that we are not using\n // \"isLexValue\" here:\n // 1. We cannot detect circular references in objects or arrays, which would\n // cause infinite recursion. However, circular references are not valid\n // AT Protocol data types, so this is not a concern for valid input. This\n // could easily be addressed in the \"validateChild\" method by keeping\n // track of \"parent\" objects.\n // 2. We are limited in the recursion depth we can validate due to potential\n // recursion depth limits in JavaScript. However, this is also not a\n // concern for most valid input, as extremely deep nesting is unlikely in\n // typical use cases.\n if (isPlainObject(input)) {\n for (const key of Object.keys(input)) {\n const r = ctx.validateChild(input, key, this) // recursively validate all properties\n if (!r.success) return r\n }\n } else if (Array.isArray(input)) {\n for (let i = 0; i < input.length; i++) {\n const r = ctx.validateChild(input, i, this) // recursively validate all array items\n if (!r.success) return r\n }\n } else if (!isLexScalar(input)) {\n return ctx.issueInvalidType(input, EXPECTED_TYPES)\n }\n\n return ctx.success(input)\n }\n}\n\n/**\n * Creates a schema that accepts any valid AT Protocol data type: string,\n * integer, boolean, null, bytes, cid, array, or plain object. Arrays and\n * objects are recursively validated to ensure all nested values are also valid\n * AT Protocol data types.\n *\n * @see {@link LexValue} from `@atproto/lex-data` for the type definition of valid AT Protocol data types\n * @returns A new {@link LexValueSchema} instance\n *\n * @example\n * ```ts\n * const schema = l.lexValue()\n *\n * schema.validate('hello') // success\n * schema.validate(42) // success\n * schema.validate(null) // success\n * schema.validate([1, 'two', null]) // success\n * schema.validate({ any: 'props' }) // success\n * schema.validate(new Date()) // fails - Date is not a valid LexValue\n * schema.validate({ foo: 1.2 }) // fails - 1.2 is not a valid LexValue (not an integer)\n * ```\n */\nexport const lexValue = /*#__PURE__*/ memoizedOptions(function () {\n return new LexValueSchema()\n})\n"]}
@@ -1,8 +1,53 @@
1
1
  import { Schema, ValidationContext } from '../core.js';
2
+ /**
3
+ * Schema that only accepts a specific literal value.
4
+ *
5
+ * Validates that the input is exactly equal to the specified value using
6
+ * strict equality (===).
7
+ *
8
+ * @template TValue - The literal type (null, string, number, or boolean)
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const schema = new LiteralSchema('admin')
13
+ * schema.validate('admin') // success
14
+ * schema.validate('user') // fails
15
+ * ```
16
+ */
2
17
  export declare class LiteralSchema<const TValue extends null | string | number | boolean> extends Schema<TValue> {
3
18
  readonly value: TValue;
19
+ readonly type: "literal";
4
20
  constructor(value: TValue);
5
21
  validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<TValue>;
6
22
  }
23
+ /**
24
+ * Creates a literal schema that only accepts the exact specified value.
25
+ *
26
+ * Useful for discriminator fields in unions, constant values, or type narrowing.
27
+ *
28
+ * @param value - The exact value that must be matched
29
+ * @returns A new {@link LiteralSchema} instance
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * // String literal
34
+ * const roleSchema = l.literal('admin')
35
+ *
36
+ * // Number literal
37
+ * const versionSchema = l.literal(1)
38
+ *
39
+ * // Boolean literal
40
+ * const enabledSchema = l.literal(true)
41
+ *
42
+ * // Null literal
43
+ * const nullSchema = l.literal(null)
44
+ *
45
+ * // In discriminated unions
46
+ * const actionSchema = l.discriminatedUnion('type', [
47
+ * l.object({ type: l.literal('create'), data: l.unknown() }),
48
+ * l.object({ type: l.literal('delete'), id: l.string() }),
49
+ * ])
50
+ * ```
51
+ */
7
52
  export declare function literal<const V extends null | string | number | boolean>(value: V): LiteralSchema<V>;
8
53
  //# sourceMappingURL=literal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"literal.d.ts","sourceRoot":"","sources":["../../src/schema/literal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEtD,qBAAa,aAAa,CACxB,KAAK,CAAC,MAAM,SAAS,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CACrD,SAAQ,MAAM,CAAC,MAAM,CAAC;IACV,QAAQ,CAAC,KAAK,EAAE,MAAM;gBAAb,KAAK,EAAE,MAAM;IAIlC,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAOzD;AAGD,wBAAgB,OAAO,CAAC,KAAK,CAAC,CAAC,SAAS,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,EACtE,KAAK,EAAE,CAAC,oBAGT"}
1
+ {"version":3,"file":"literal.d.ts","sourceRoot":"","sources":["../../src/schema/literal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEtD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,aAAa,CACxB,KAAK,CAAC,MAAM,SAAS,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CACrD,SAAQ,MAAM,CAAC,MAAM,CAAC;IAGV,QAAQ,CAAC,KAAK,EAAE,MAAM;IAFlC,QAAQ,CAAC,IAAI,EAAG,SAAS,CAAS;gBAEb,KAAK,EAAE,MAAM;IAIlC,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAOzD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,wBAAgB,OAAO,CAAC,KAAK,CAAC,CAAC,SAAS,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,EACtE,KAAK,EAAE,CAAC,oBAGT"}