@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,5 +1,12 @@
1
- import { BlobRef, BlobRefCheckOptions, LegacyBlobRef } from '@atproto/lex-data';
1
+ import { BlobRef, BlobRefCheckOptions, LegacyBlobRef, isBlobRef, isLegacyBlobRef } from '@atproto/lex-data';
2
2
  import { Schema, ValidationContext } from '../core.js';
3
+ /**
4
+ * Configuration options for blob schema validation.
5
+ *
6
+ * @property allowLegacy - Whether to allow legacy blob references format
7
+ * @property accept - List of accepted MIME types (supports wildcards like 'image/*' or '*\/*')
8
+ * @property maxSize - Maximum blob size in bytes
9
+ */
3
10
  export type BlobSchemaOptions = BlobRefCheckOptions & {
4
11
  /**
5
12
  * Whether to allow legacy blob references format
@@ -16,14 +23,55 @@ export type BlobSchemaOptions = BlobRefCheckOptions & {
16
23
  maxSize?: number;
17
24
  };
18
25
  export type { BlobRef, LegacyBlobRef };
26
+ export { isBlobRef, isLegacyBlobRef };
27
+ /**
28
+ * Schema for validating blob references in AT Protocol.
29
+ *
30
+ * Validates BlobRef objects which contain a CID reference to binary data,
31
+ * along with metadata like MIME type and size. Can optionally accept
32
+ * legacy blob reference format.
33
+ *
34
+ * @template TOptions - The configuration options type
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const schema = new BlobSchema({ accept: ['image/*'], maxSize: 1000000 })
39
+ * const result = schema.validate(blobRef)
40
+ * ```
41
+ */
19
42
  export declare class BlobSchema<const TOptions extends BlobSchemaOptions = NonNullable<unknown>> extends Schema<TOptions extends {
20
43
  allowLegacy: true;
21
44
  } ? BlobRef | LegacyBlobRef : BlobRef> {
22
45
  readonly options?: TOptions | undefined;
46
+ readonly type: "blob";
23
47
  constructor(options?: TOptions | undefined);
24
- validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<BlobRef | LegacyBlobRef>;
48
+ validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<LegacyBlobRef | BlobRef>;
25
49
  matchesMime(mime: string): boolean;
26
50
  }
51
+ /**
52
+ * Creates a blob schema for validating blob references with optional constraints.
53
+ *
54
+ * Blob references are used in AT Protocol to reference binary data stored
55
+ * separately from records. They contain a CID, MIME type, and size information.
56
+ *
57
+ * @param options - Optional configuration for MIME type filtering and size limits
58
+ * @returns A new {@link BlobSchema} instance
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * // Basic blob reference
63
+ * const fileSchema = l.blob()
64
+ *
65
+ * // Image files only
66
+ * const imageSchema = l.blob({ accept: ['image/png', 'image/jpeg', 'image/gif'] })
67
+ *
68
+ * // Any image type with size limit
69
+ * const avatarSchema = l.blob({ accept: ['image/*'], maxSize: 1000000 })
70
+ *
71
+ * // Allow legacy format
72
+ * const legacySchema = l.blob({ allowLegacy: true })
73
+ * ```
74
+ */
27
75
  export declare const blob: <O extends BlobSchemaOptions = {
28
76
  allowLegacy?: false;
29
77
  }>(options?: O) => BlobSchema<O>;
@@ -1 +1 @@
1
- {"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../../src/schema/blob.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,aAAa,EAGd,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGtD,MAAM,MAAM,iBAAiB,GAAG,mBAAmB,GAAG;IACpD;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,CAAA;AAEtC,qBAAa,UAAU,CACrB,KAAK,CAAC,QAAQ,SAAS,iBAAiB,GAAG,WAAW,CAAC,OAAO,CAAC,CAC/D,SAAQ,MAAM,CACd,QAAQ,SAAS;IAAE,WAAW,EAAE,IAAI,CAAA;CAAE,GAAG,OAAO,GAAG,aAAa,GAAG,OA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,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;IA2BxD,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAKnC;AAaD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,IAAI,GACf,CAAC,SAAS,iBAAiB;kBAAmB,KAAK;aACzC,CAAC,kBAEX,CAAA"}
@@ -1,11 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.blob = exports.BlobSchema = void 0;
3
+ exports.blob = exports.BlobSchema = exports.isLegacyBlobRef = exports.isBlobRef = void 0;
4
4
  const lex_data_1 = require("@atproto/lex-data");
5
+ Object.defineProperty(exports, "isBlobRef", { enumerable: true, get: function () { return lex_data_1.isBlobRef; } });
6
+ Object.defineProperty(exports, "isLegacyBlobRef", { enumerable: true, get: function () { return lex_data_1.isLegacyBlobRef; } });
5
7
  const core_js_1 = require("../core.js");
6
8
  const memoize_js_1 = require("../util/memoize.js");
9
+ /**
10
+ * Schema for validating blob references in AT Protocol.
11
+ *
12
+ * Validates BlobRef objects which contain a CID reference to binary data,
13
+ * along with metadata like MIME type and size. Can optionally accept
14
+ * legacy blob reference format.
15
+ *
16
+ * @template TOptions - The configuration options type
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const schema = new BlobSchema({ accept: ['image/*'], maxSize: 1000000 })
21
+ * const result = schema.validate(blobRef)
22
+ * ```
23
+ */
7
24
  class BlobSchema extends core_js_1.Schema {
8
25
  options;
26
+ type = 'blob';
9
27
  constructor(options) {
10
28
  super();
11
29
  this.options = options;
@@ -19,7 +37,7 @@ class BlobSchema extends core_js_1.Schema {
19
37
  ? input
20
38
  : null;
21
39
  if (!blob) {
22
- return ctx.issueInvalidType(input, 'blob');
40
+ return ctx.issueUnexpectedType(input, 'blob');
23
41
  }
24
42
  const accept = this.options?.accept;
25
43
  if (accept && !matchesMime(blob.mimeType, accept)) {
@@ -51,6 +69,30 @@ function matchesMime(mime, accepted) {
51
69
  }
52
70
  return false;
53
71
  }
72
+ /**
73
+ * Creates a blob schema for validating blob references with optional constraints.
74
+ *
75
+ * Blob references are used in AT Protocol to reference binary data stored
76
+ * separately from records. They contain a CID, MIME type, and size information.
77
+ *
78
+ * @param options - Optional configuration for MIME type filtering and size limits
79
+ * @returns A new {@link BlobSchema} instance
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * // Basic blob reference
84
+ * const fileSchema = l.blob()
85
+ *
86
+ * // Image files only
87
+ * const imageSchema = l.blob({ accept: ['image/png', 'image/jpeg', 'image/gif'] })
88
+ *
89
+ * // Any image type with size limit
90
+ * const avatarSchema = l.blob({ accept: ['image/*'], maxSize: 1000000 })
91
+ *
92
+ * // Allow legacy format
93
+ * const legacySchema = l.blob({ allowLegacy: true })
94
+ * ```
95
+ */
54
96
  exports.blob = (0, memoize_js_1.memoizedOptions)(function (options) {
55
97
  return new BlobSchema(options);
56
98
  });
@@ -1 +1 @@
1
- {"version":3,"file":"blob.js","sourceRoot":"","sources":["../../src/schema/blob.ts"],"names":[],"mappings":";;;AAAA,gDAM0B;AAC1B,wCAAsD;AACtD,mDAAoD;AAoBpD,MAAa,UAEX,SAAQ,gBAET;IACsB;IAArB,YAAqB,OAAkB;QACrC,KAAK,EAAE,CAAA;QADY,YAAO,GAAP,OAAO,CAAW;IAEvC,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,MAAM,IAAI,GACP,KAAa,EAAE,KAAK,KAAK,SAAS;YACjC,CAAC,CAAC,IAAA,oBAAS,EAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC;gBAC9B,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,IAAI;YACR,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,IAAI,IAAA,0BAAe,EAAC,KAAK,CAAC;gBAC5D,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,IAAI,CAAA;QAEZ,IAAI,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AAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAChE,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAEY,QAAA,IAAI,GAAiB,IAAA,4BAAe,EAAC,UAEhD,OAAW;IACX,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAA;AAChC,CAAC,CAAC,CAAA","sourcesContent":["import {\n BlobRef,\n BlobRefCheckOptions,\n LegacyBlobRef,\n isBlobRef,\n isLegacyBlobRef,\n} from '@atproto/lex-data'\nimport { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\nexport type BlobSchemaOptions = BlobRefCheckOptions & {\n /**\n * Whether to allow legacy blob references format\n * @see {@link LegacyBlobRef}\n */\n allowLegacy?: boolean\n /**\n * List of accepted mime types\n */\n accept?: string[]\n /**\n * Maximum size in bytes\n */\n maxSize?: number\n}\n\nexport type { BlobRef, LegacyBlobRef }\n\nexport class BlobSchema<\n const TOptions extends BlobSchemaOptions = NonNullable<unknown>,\n> extends Schema<\n TOptions extends { allowLegacy: true } ? BlobRef | LegacyBlobRef : BlobRef\n> {\n constructor(readonly options?: TOptions) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n const blob: null | BlobRef | LegacyBlobRef =\n (input as any)?.$type !== undefined\n ? isBlobRef(input, this.options)\n ? input\n : null\n : this.options?.allowLegacy === true && isLegacyBlobRef(input)\n ? input\n : null\n\n if (!blob) {\n return ctx.issueInvalidType(input, 'blob')\n }\n\n const accept = this.options?.accept\n if (accept && !matchesMime(blob.mimeType, accept)) {\n return ctx.issueInvalidPropertyValue(blob, 'mimeType', accept)\n }\n\n const maxSize = this.options?.maxSize\n if (maxSize != null && 'size' in blob && blob.size > maxSize) {\n return ctx.issueTooBig(blob, 'blob', maxSize, blob.size)\n }\n\n return ctx.success(blob)\n }\n\n matchesMime(mime: string): boolean {\n const accept = this.options?.accept\n if (!accept) return true\n return matchesMime(mime, accept)\n }\n}\n\nfunction matchesMime(mime: string, accepted: string[]): boolean {\n if (accepted.includes('*/*')) return true\n if (accepted.includes(mime)) return true\n for (const value of accepted) {\n if (value.endsWith('/*') && mime.startsWith(value.slice(0, -1))) {\n return true\n }\n }\n return false\n}\n\nexport const blob = /*#__PURE__*/ memoizedOptions(function <\n O extends BlobSchemaOptions = { allowLegacy?: false },\n>(options?: O) {\n return new BlobSchema(options)\n})\n"]}
1
+ {"version":3,"file":"blob.js","sourceRoot":"","sources":["../../src/schema/blob.ts"],"names":[],"mappings":";;;AAAA,gDAM0B;AA4BjB,0FA9BP,oBAAS,OA8BO;AAAE,gGA7BlB,0BAAe,OA6BkB;AA3BnC,wCAAsD;AACtD,mDAAoD;AA4BpD;;;;;;;;;;;;;;GAcG;AACH,MAAa,UAEX,SAAQ,gBAET;IAGsB;IAFZ,IAAI,GAAG,MAAe,CAAA;IAE/B,YAAqB,OAAkB;QACrC,KAAK,EAAE,CAAA;QADY,YAAO,GAAP,OAAO,CAAW;IAEvC,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,MAAM,IAAI,GACP,KAAa,EAAE,KAAK,KAAK,SAAS;YACjC,CAAC,CAAC,IAAA,oBAAS,EAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC;gBAC9B,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,IAAI;YACR,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,IAAI,IAAA,0BAAe,EAAC,KAAK,CAAC;gBAC5D,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,IAAI,CAAA;QAEZ,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC/C,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,CAAA;QACnC,IAAI,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;;;;;GAuBG;AACU,QAAA,IAAI,GAAiB,IAAA,4BAAe,EAAC,UAEhD,OAAW;IACX,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAA;AAChC,CAAC,CAAC,CAAA","sourcesContent":["import {\n BlobRef,\n BlobRefCheckOptions,\n LegacyBlobRef,\n isBlobRef,\n isLegacyBlobRef,\n} from '@atproto/lex-data'\nimport { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\n/**\n * Configuration options for blob schema validation.\n *\n * @property allowLegacy - Whether to allow legacy blob references format\n * @property accept - List of accepted MIME types (supports wildcards like 'image/*' or '*\\/*')\n * @property maxSize - Maximum blob size in bytes\n */\nexport type BlobSchemaOptions = BlobRefCheckOptions & {\n /**\n * Whether to allow legacy blob references format\n * @see {@link LegacyBlobRef}\n */\n allowLegacy?: boolean\n /**\n * List of accepted mime types\n */\n accept?: string[]\n /**\n * Maximum size in bytes\n */\n maxSize?: number\n}\n\nexport type { BlobRef, LegacyBlobRef }\nexport { isBlobRef, isLegacyBlobRef }\n\n/**\n * Schema for validating blob references in AT Protocol.\n *\n * Validates BlobRef objects which contain a CID reference to binary data,\n * along with metadata like MIME type and size. Can optionally accept\n * legacy blob reference format.\n *\n * @template TOptions - The configuration options type\n *\n * @example\n * ```ts\n * const schema = new BlobSchema({ accept: ['image/*'], maxSize: 1000000 })\n * const result = schema.validate(blobRef)\n * ```\n */\nexport class BlobSchema<\n const TOptions extends BlobSchemaOptions = NonNullable<unknown>,\n> extends Schema<\n TOptions extends { allowLegacy: true } ? BlobRef | LegacyBlobRef : BlobRef\n> {\n readonly type = 'blob' as const\n\n constructor(readonly options?: TOptions) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n const blob: null | BlobRef | LegacyBlobRef =\n (input as any)?.$type !== undefined\n ? isBlobRef(input, this.options)\n ? input\n : null\n : this.options?.allowLegacy === true && isLegacyBlobRef(input)\n ? input\n : null\n\n if (!blob) {\n return ctx.issueUnexpectedType(input, 'blob')\n }\n\n const accept = this.options?.accept\n if (accept && !matchesMime(blob.mimeType, accept)) {\n return ctx.issueInvalidPropertyValue(blob, 'mimeType', accept)\n }\n\n const maxSize = this.options?.maxSize\n if (maxSize != null && 'size' in blob && blob.size > maxSize) {\n return ctx.issueTooBig(blob, 'blob', maxSize, blob.size)\n }\n\n return ctx.success(blob)\n }\n\n matchesMime(mime: string): boolean {\n const accept = this.options?.accept\n if (!accept) return true\n return matchesMime(mime, accept)\n }\n}\n\nfunction matchesMime(mime: string, accepted: string[]): boolean {\n if (accepted.includes('*/*')) return true\n if (accepted.includes(mime)) return true\n for (const value of accepted) {\n if (value.endsWith('/*') && mime.startsWith(value.slice(0, -1))) {\n return true\n }\n }\n return false\n}\n\n/**\n * Creates a blob schema for validating blob references with optional constraints.\n *\n * Blob references are used in AT Protocol to reference binary data stored\n * separately from records. They contain a CID, MIME type, and size information.\n *\n * @param options - Optional configuration for MIME type filtering and size limits\n * @returns A new {@link BlobSchema} instance\n *\n * @example\n * ```ts\n * // Basic blob reference\n * const fileSchema = l.blob()\n *\n * // Image files only\n * const imageSchema = l.blob({ accept: ['image/png', 'image/jpeg', 'image/gif'] })\n *\n * // Any image type with size limit\n * const avatarSchema = l.blob({ accept: ['image/*'], maxSize: 1000000 })\n *\n * // Allow legacy format\n * const legacySchema = l.blob({ allowLegacy: true })\n * ```\n */\nexport const blob = /*#__PURE__*/ memoizedOptions(function <\n O extends BlobSchemaOptions = { allowLegacy?: false },\n>(options?: O) {\n return new BlobSchema(options)\n})\n"]}
@@ -1,6 +1,35 @@
1
1
  import { Schema, ValidationContext } from '../core.js';
2
+ /**
3
+ * Schema for validating boolean values.
4
+ *
5
+ * Only accepts JavaScript `true` or `false` values. Does not perform
6
+ * any coercion from strings or numbers.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const schema = new BooleanSchema()
11
+ * schema.validate(true) // success
12
+ * schema.validate(false) // success
13
+ * schema.validate('true') // fails - no string coercion
14
+ * ```
15
+ */
2
16
  export declare class BooleanSchema extends Schema<boolean> {
17
+ readonly type: "boolean";
3
18
  validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<boolean>;
4
19
  }
20
+ /**
21
+ * Creates a boolean schema that validates true/false values.
22
+ *
23
+ * @returns A new {@link BooleanSchema} instance
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const enabledSchema = l.boolean()
28
+ *
29
+ * enabledSchema.parse(true) // true
30
+ * enabledSchema.parse(false) // false
31
+ * enabledSchema.parse('true') // throws - strings not accepted
32
+ * ```
33
+ */
5
34
  export declare const boolean: () => BooleanSchema;
6
35
  //# sourceMappingURL=boolean.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../../src/schema/boolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGtD,qBAAa,aAAc,SAAQ,MAAM,CAAC,OAAO,CAAC;IAChD,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAOzD;AAED,eAAO,MAAM,OAAO,qBAElB,CAAA"}
1
+ {"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../../src/schema/boolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGtD;;;;;;;;;;;;;GAaG;AACH,qBAAa,aAAc,SAAQ,MAAM,CAAC,OAAO,CAAC;IAChD,QAAQ,CAAC,IAAI,EAAG,SAAS,CAAS;IAElC,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAOzD;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,OAAO,qBAElB,CAAA"}
@@ -3,15 +3,44 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.boolean = exports.BooleanSchema = 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 boolean values.
8
+ *
9
+ * Only accepts JavaScript `true` or `false` values. Does not perform
10
+ * any coercion from strings or numbers.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const schema = new BooleanSchema()
15
+ * schema.validate(true) // success
16
+ * schema.validate(false) // success
17
+ * schema.validate('true') // fails - no string coercion
18
+ * ```
19
+ */
6
20
  class BooleanSchema extends core_js_1.Schema {
21
+ type = 'boolean';
7
22
  validateInContext(input, ctx) {
8
23
  if (typeof input === 'boolean') {
9
24
  return ctx.success(input);
10
25
  }
11
- return ctx.issueInvalidType(input, 'boolean');
26
+ return ctx.issueUnexpectedType(input, 'boolean');
12
27
  }
13
28
  }
14
29
  exports.BooleanSchema = BooleanSchema;
30
+ /**
31
+ * Creates a boolean schema that validates true/false values.
32
+ *
33
+ * @returns A new {@link BooleanSchema} instance
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const enabledSchema = l.boolean()
38
+ *
39
+ * enabledSchema.parse(true) // true
40
+ * enabledSchema.parse(false) // false
41
+ * enabledSchema.parse('true') // throws - strings not accepted
42
+ * ```
43
+ */
15
44
  exports.boolean = (0, memoize_js_1.memoizedOptions)(function () {
16
45
  return new BooleanSchema();
17
46
  });
@@ -1 +1 @@
1
- {"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src/schema/boolean.ts"],"names":[],"mappings":";;;AAAA,wCAAsD;AACtD,mDAAoD;AAEpD,MAAa,aAAc,SAAQ,gBAAe;IAChD,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;YAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC3B,CAAC;QAED,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;IAC/C,CAAC;CACF;AARD,sCAQC;AAEY,QAAA,OAAO,GAAiB,IAAA,4BAAe,EAAC;IACnD,OAAO,IAAI,aAAa,EAAE,CAAA;AAC5B,CAAC,CAAC,CAAA","sourcesContent":["import { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\nexport class BooleanSchema extends Schema<boolean> {\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (typeof input === 'boolean') {\n return ctx.success(input)\n }\n\n return ctx.issueInvalidType(input, 'boolean')\n }\n}\n\nexport const boolean = /*#__PURE__*/ memoizedOptions(function () {\n return new BooleanSchema()\n})\n"]}
1
+ {"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src/schema/boolean.ts"],"names":[],"mappings":";;;AAAA,wCAAsD;AACtD,mDAAoD;AAEpD;;;;;;;;;;;;;GAaG;AACH,MAAa,aAAc,SAAQ,gBAAe;IACvC,IAAI,GAAG,SAAkB,CAAA;IAElC,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;YAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC3B,CAAC;QAED,OAAO,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;IAClD,CAAC;CACF;AAVD,sCAUC;AAED;;;;;;;;;;;;;GAaG;AACU,QAAA,OAAO,GAAiB,IAAA,4BAAe,EAAC;IACnD,OAAO,IAAI,aAAa,EAAE,CAAA;AAC5B,CAAC,CAAC,CAAA","sourcesContent":["import { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\n/**\n * Schema for validating boolean values.\n *\n * Only accepts JavaScript `true` or `false` values. Does not perform\n * any coercion from strings or numbers.\n *\n * @example\n * ```ts\n * const schema = new BooleanSchema()\n * schema.validate(true) // success\n * schema.validate(false) // success\n * schema.validate('true') // fails - no string coercion\n * ```\n */\nexport class BooleanSchema extends Schema<boolean> {\n readonly type = 'boolean' as const\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (typeof input === 'boolean') {\n return ctx.success(input)\n }\n\n return ctx.issueUnexpectedType(input, 'boolean')\n }\n}\n\n/**\n * Creates a boolean schema that validates true/false values.\n *\n * @returns A new {@link BooleanSchema} instance\n *\n * @example\n * ```ts\n * const enabledSchema = l.boolean()\n *\n * enabledSchema.parse(true) // true\n * enabledSchema.parse(false) // false\n * enabledSchema.parse('true') // throws - strings not accepted\n * ```\n */\nexport const boolean = /*#__PURE__*/ memoizedOptions(function () {\n return new BooleanSchema()\n})\n"]}
@@ -1,12 +1,51 @@
1
1
  import { Schema, ValidationContext } from '../core.js';
2
+ /**
3
+ * Configuration options for bytes schema validation.
4
+ *
5
+ * @property minLength - Minimum length in bytes
6
+ * @property maxLength - Maximum length in bytes
7
+ */
2
8
  export type BytesSchemaOptions = {
3
9
  minLength?: number;
4
10
  maxLength?: number;
5
11
  };
12
+ /**
13
+ * Schema for validating binary data as Uint8Array with optional length constraints.
14
+ *
15
+ * In "parse" mode, coerces various binary formats (Buffer, ArrayBuffer, etc.)
16
+ * into Uint8Array. In "validate" mode, only accepts Uint8Array directly.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const schema = new BytesSchema({ maxLength: 1024 })
21
+ * const result = schema.validate(new Uint8Array([1, 2, 3]))
22
+ * ```
23
+ */
6
24
  export declare class BytesSchema extends Schema<Uint8Array> {
7
25
  readonly options: BytesSchemaOptions;
26
+ readonly type: "bytes";
8
27
  constructor(options?: BytesSchemaOptions);
9
28
  validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<Uint8Array<ArrayBufferLike>>;
10
29
  }
30
+ /**
31
+ * Creates a bytes schema for validating binary data with optional length constraints.
32
+ *
33
+ * Validates Uint8Array values and can coerce other binary formats in parse mode.
34
+ *
35
+ * @param options - Optional configuration for minimum and maximum byte length
36
+ * @returns A new {@link BytesSchema} instance
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * // Basic bytes schema
41
+ * const dataSchema = l.bytes()
42
+ *
43
+ * // With size constraints
44
+ * const avatarSchema = l.bytes({ maxLength: 1000000 }) // 1MB max
45
+ *
46
+ * // With minimum size
47
+ * const hashSchema = l.bytes({ minLength: 32, maxLength: 32 }) // Exactly 32 bytes
48
+ * ```
49
+ */
11
50
  export declare const bytes: (options?: BytesSchemaOptions) => BytesSchema;
12
51
  //# sourceMappingURL=bytes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../src/schema/bytes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGtD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,qBAAa,WAAY,SAAQ,MAAM,CAAC,UAAU,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,kBAAkB;gBAA3B,OAAO,GAAE,kBAAuB;IAIrD,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAoBzD;AAED,eAAO,MAAM,KAAK,aACN,kBAAkB,gBAG5B,CAAA"}
1
+ {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../src/schema/bytes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGtD;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,WAAY,SAAQ,MAAM,CAAC,UAAU,CAAC;IAGrC,QAAQ,CAAC,OAAO,EAAE,kBAAkB;IAFhD,QAAQ,CAAC,IAAI,EAAG,OAAO,CAAS;gBAEX,OAAO,GAAE,kBAAuB;IAIrD,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAoBzD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,KAAK,aACN,kBAAkB,gBAG5B,CAAA"}
@@ -4,8 +4,21 @@ exports.bytes = exports.BytesSchema = void 0;
4
4
  const lex_data_1 = require("@atproto/lex-data");
5
5
  const core_js_1 = require("../core.js");
6
6
  const memoize_js_1 = require("../util/memoize.js");
7
+ /**
8
+ * Schema for validating binary data as Uint8Array with optional length constraints.
9
+ *
10
+ * In "parse" mode, coerces various binary formats (Buffer, ArrayBuffer, etc.)
11
+ * into Uint8Array. In "validate" mode, only accepts Uint8Array directly.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const schema = new BytesSchema({ maxLength: 1024 })
16
+ * const result = schema.validate(new Uint8Array([1, 2, 3]))
17
+ * ```
18
+ */
7
19
  class BytesSchema extends core_js_1.Schema {
8
20
  options;
21
+ type = 'bytes';
9
22
  constructor(options = {}) {
10
23
  super();
11
24
  this.options = options;
@@ -14,7 +27,7 @@ class BytesSchema extends core_js_1.Schema {
14
27
  // In "parse" mode, coerce different binary formats into Uint8Array
15
28
  const bytes = ctx.options.mode === 'parse' ? (0, lex_data_1.asUint8Array)(input) : (0, lex_data_1.ifUint8Array)(input);
16
29
  if (!bytes) {
17
- return ctx.issueInvalidType(input, 'bytes');
30
+ return ctx.issueUnexpectedType(input, 'bytes');
18
31
  }
19
32
  const { minLength } = this.options;
20
33
  if (minLength != null && bytes.length < minLength) {
@@ -28,6 +41,26 @@ class BytesSchema extends core_js_1.Schema {
28
41
  }
29
42
  }
30
43
  exports.BytesSchema = BytesSchema;
44
+ /**
45
+ * Creates a bytes schema for validating binary data with optional length constraints.
46
+ *
47
+ * Validates Uint8Array values and can coerce other binary formats in parse mode.
48
+ *
49
+ * @param options - Optional configuration for minimum and maximum byte length
50
+ * @returns A new {@link BytesSchema} instance
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * // Basic bytes schema
55
+ * const dataSchema = l.bytes()
56
+ *
57
+ * // With size constraints
58
+ * const avatarSchema = l.bytes({ maxLength: 1000000 }) // 1MB max
59
+ *
60
+ * // With minimum size
61
+ * const hashSchema = l.bytes({ minLength: 32, maxLength: 32 }) // Exactly 32 bytes
62
+ * ```
63
+ */
31
64
  exports.bytes = (0, memoize_js_1.memoizedOptions)(function (options) {
32
65
  return new BytesSchema(options);
33
66
  });
@@ -1 +1 @@
1
- {"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/schema/bytes.ts"],"names":[],"mappings":";;;AAAA,gDAA8D;AAC9D,wCAAsD;AACtD,mDAAoD;AAOpD,MAAa,WAAY,SAAQ,gBAAkB;IAC5B;IAArB,YAAqB,UAA8B,EAAE;QACnD,KAAK,EAAE,CAAA;QADY,YAAO,GAAP,OAAO,CAAyB;IAErD,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,mEAAmE;QACnE,MAAM,KAAK,GACT,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,IAAA,uBAAY,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAA,uBAAY,EAAC,KAAK,CAAC,CAAA;QAC1E,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAC7C,CAAC;QAED,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;QAClC,IAAI,SAAS,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;YAClD,OAAO,GAAG,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QACnE,CAAC;QAED,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;QAClC,IAAI,SAAS,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;YAClD,OAAO,GAAG,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QACjE,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;CACF;AAzBD,kCAyBC;AAEY,QAAA,KAAK,GAAiB,IAAA,4BAAe,EAAC,UACjD,OAA4B;IAE5B,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAA;AACjC,CAAC,CAAC,CAAA","sourcesContent":["import { asUint8Array, ifUint8Array } from '@atproto/lex-data'\nimport { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\nexport type BytesSchemaOptions = {\n minLength?: number\n maxLength?: number\n}\n\nexport class BytesSchema extends Schema<Uint8Array> {\n constructor(readonly options: BytesSchemaOptions = {}) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n // In \"parse\" mode, coerce different binary formats into Uint8Array\n const bytes =\n ctx.options.mode === 'parse' ? asUint8Array(input) : ifUint8Array(input)\n if (!bytes) {\n return ctx.issueInvalidType(input, 'bytes')\n }\n\n const { minLength } = this.options\n if (minLength != null && bytes.length < minLength) {\n return ctx.issueTooSmall(bytes, 'bytes', minLength, bytes.length)\n }\n\n const { maxLength } = this.options\n if (maxLength != null && bytes.length > maxLength) {\n return ctx.issueTooBig(bytes, 'bytes', maxLength, bytes.length)\n }\n\n return ctx.success(bytes)\n }\n}\n\nexport const bytes = /*#__PURE__*/ memoizedOptions(function (\n options?: BytesSchemaOptions,\n) {\n return new BytesSchema(options)\n})\n"]}
1
+ {"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/schema/bytes.ts"],"names":[],"mappings":";;;AAAA,gDAA8D;AAC9D,wCAAsD;AACtD,mDAAoD;AAapD;;;;;;;;;;;GAWG;AACH,MAAa,WAAY,SAAQ,gBAAkB;IAG5B;IAFZ,IAAI,GAAG,OAAgB,CAA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'\nimport { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\n/**\n * Configuration options for bytes schema validation.\n *\n * @property minLength - Minimum length in bytes\n * @property maxLength - Maximum length in bytes\n */\nexport type BytesSchemaOptions = {\n minLength?: number\n maxLength?: number\n}\n\n/**\n * Schema for validating binary data as Uint8Array with optional length constraints.\n *\n * In \"parse\" mode, coerces various binary formats (Buffer, ArrayBuffer, etc.)\n * into Uint8Array. In \"validate\" mode, only accepts Uint8Array directly.\n *\n * @example\n * ```ts\n * const schema = new BytesSchema({ maxLength: 1024 })\n * const result = schema.validate(new Uint8Array([1, 2, 3]))\n * ```\n */\nexport class BytesSchema extends Schema<Uint8Array> {\n readonly type = 'bytes' as const\n\n constructor(readonly options: BytesSchemaOptions = {}) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n // In \"parse\" mode, coerce different binary formats into Uint8Array\n const bytes =\n ctx.options.mode === 'parse' ? asUint8Array(input) : ifUint8Array(input)\n if (!bytes) {\n return ctx.issueUnexpectedType(input, 'bytes')\n }\n\n const { minLength } = this.options\n if (minLength != null && bytes.length < minLength) {\n return ctx.issueTooSmall(bytes, 'bytes', minLength, bytes.length)\n }\n\n const { maxLength } = this.options\n if (maxLength != null && bytes.length > maxLength) {\n return ctx.issueTooBig(bytes, 'bytes', maxLength, bytes.length)\n }\n\n return ctx.success(bytes)\n }\n}\n\n/**\n * Creates a bytes schema for validating binary data with optional length constraints.\n *\n * Validates Uint8Array values and can coerce other binary formats in parse mode.\n *\n * @param options - Optional configuration for minimum and maximum byte length\n * @returns A new {@link BytesSchema} instance\n *\n * @example\n * ```ts\n * // Basic bytes schema\n * const dataSchema = l.bytes()\n *\n * // With size constraints\n * const avatarSchema = l.bytes({ maxLength: 1000000 }) // 1MB max\n *\n * // With minimum size\n * const hashSchema = l.bytes({ minLength: 32, maxLength: 32 }) // Exactly 32 bytes\n * ```\n */\nexport const bytes = /*#__PURE__*/ memoizedOptions(function (\n options?: BytesSchemaOptions,\n) {\n return new BytesSchema(options)\n})\n"]}
@@ -1,13 +1,52 @@
1
1
  import { CheckCidOptions, Cid, InferCheckedCid } from '@atproto/lex-data';
2
2
  import { Schema, ValidationContext } from '../core.js';
3
3
  export type { Cid };
4
+ /**
5
+ * Configuration options for CID schema validation.
6
+ *
7
+ * @see CheckCidOptions from @atproto/lex-data for available options
8
+ */
4
9
  export type CidSchemaOptions = CheckCidOptions;
10
+ /**
11
+ * Schema for validating Content Identifiers (CIDs).
12
+ *
13
+ * CIDs are self-describing content-addressed identifiers used in AT Protocol
14
+ * to reference data by its cryptographic hash. This schema validates that
15
+ * the input is a valid CID object.
16
+ *
17
+ * @template TOptions - The configuration options type
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const schema = new CidSchema()
22
+ * const result = schema.validate(someCid)
23
+ * ```
24
+ */
5
25
  export declare class CidSchema<const TOptions extends CidSchemaOptions = {
6
26
  flavor: undefined;
7
27
  }> extends Schema<InferCheckedCid<TOptions>> {
8
28
  readonly options?: TOptions | undefined;
29
+ readonly type: "cid";
9
30
  constructor(options?: TOptions | undefined);
10
31
  validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<Cid<0 | 1, number, number>>;
11
32
  }
33
+ /**
34
+ * Creates a CID schema for validating Content Identifiers.
35
+ *
36
+ * CIDs are used throughout AT Protocol to reference content by its hash.
37
+ * This is commonly used for referencing blobs, commits, and other data.
38
+ *
39
+ * @param options - Optional configuration for CID validation
40
+ * @returns A new {@link CidSchema} instance
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * // Basic CID validation
45
+ * const cidSchema = l.cid()
46
+ *
47
+ * // Validate a CID from a blob reference
48
+ * const result = cidSchema.validate(blobRef.ref)
49
+ * ```
50
+ */
12
51
  export declare const cid: <O extends CidSchemaOptions = {}>(options?: O) => CidSchema<O>;
13
52
  //# sourceMappingURL=cid.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cid.d.ts","sourceRoot":"","sources":["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AET,OAAO,CAAC,EAAE,QAAQ,YAAA;IAIvC,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAOzD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,GAAG,GACd,CAAC,SAAS,gBAAgB,iBAChB,CAAC,iBAEX,CAAA"}
@@ -4,20 +4,54 @@ exports.cid = exports.CidSchema = void 0;
4
4
  const lex_data_1 = require("@atproto/lex-data");
5
5
  const core_js_1 = require("../core.js");
6
6
  const memoize_js_1 = require("../util/memoize.js");
7
+ /**
8
+ * Schema for validating Content Identifiers (CIDs).
9
+ *
10
+ * CIDs are self-describing content-addressed identifiers used in AT Protocol
11
+ * to reference data by its cryptographic hash. This schema validates that
12
+ * the input is a valid CID object.
13
+ *
14
+ * @template TOptions - The configuration options type
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const schema = new CidSchema()
19
+ * const result = schema.validate(someCid)
20
+ * ```
21
+ */
7
22
  class CidSchema extends core_js_1.Schema {
8
23
  options;
24
+ type = 'cid';
9
25
  constructor(options) {
10
26
  super();
11
27
  this.options = options;
12
28
  }
13
29
  validateInContext(input, ctx) {
14
30
  if (!(0, lex_data_1.isCid)(input, this.options)) {
15
- return ctx.issueInvalidType(input, 'cid');
31
+ return ctx.issueUnexpectedType(input, 'cid');
16
32
  }
17
33
  return ctx.success(input);
18
34
  }
19
35
  }
20
36
  exports.CidSchema = CidSchema;
37
+ /**
38
+ * Creates a CID schema for validating Content Identifiers.
39
+ *
40
+ * CIDs are used throughout AT Protocol to reference content by its hash.
41
+ * This is commonly used for referencing blobs, commits, and other data.
42
+ *
43
+ * @param options - Optional configuration for CID validation
44
+ * @returns A new {@link CidSchema} instance
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * // Basic CID validation
49
+ * const cidSchema = l.cid()
50
+ *
51
+ * // Validate a CID from a blob reference
52
+ * const result = cidSchema.validate(blobRef.ref)
53
+ * ```
54
+ */
21
55
  exports.cid = (0, memoize_js_1.memoizedOptions)(function (options) {
22
56
  return new CidSchema(options);
23
57
  });
@@ -1 +1 @@
1
- {"version":3,"file":"cid.js","sourceRoot":"","sources":["../../src/schema/cid.ts"],"names":[],"mappings":";;;AAAA,gDAAgF;AAChF,wCAAsD;AACtD,mDAAoD;AAMpD,MAAa,SAEX,SAAQ,gBAAiC;IACpB;IAArB,YAAqB,OAAkB;QACrC,KAAK,EAAE,CAAA;QADY,YAAO,GAAP,OAAO,CAAW;IAEvC,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,CAAC,IAAA,gBAAK,EAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAChC,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;QAC3C,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;CACF;AAdD,8BAcC;AAEY,QAAA,GAAG,GAAiB,IAAA,4BAAe,EAAC,UAE/C,OAAW;IACX,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC,CAAA;AAC/B,CAAC,CAAC,CAAA","sourcesContent":["import { CheckCidOptions, Cid, InferCheckedCid, isCid } from '@atproto/lex-data'\nimport { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\nexport type { Cid }\n\nexport type CidSchemaOptions = CheckCidOptions\n\nexport class CidSchema<\n const TOptions extends CidSchemaOptions = { flavor: undefined },\n> extends Schema<InferCheckedCid<TOptions>> {\n constructor(readonly options?: TOptions) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (!isCid(input, this.options)) {\n return ctx.issueInvalidType(input, 'cid')\n }\n\n return ctx.success(input)\n }\n}\n\nexport const cid = /*#__PURE__*/ memoizedOptions(function <\n O extends CidSchemaOptions = NonNullable<unknown>,\n>(options?: O) {\n return new CidSchema(options)\n})\n"]}
1
+ {"version":3,"file":"cid.js","sourceRoot":"","sources":["../../src/schema/cid.ts"],"names":[],"mappings":";;;AAAA,gDAAgF;AAChF,wCAAsD;AACtD,mDAAoD;AAWpD;;;;;;;;;;;;;;GAcG;AACH,MAAa,SAEX,SAAQ,gBAAiC;IAGpB;IAFZ,IAAI,GAAG,KAAc,CAAA;IAE9B,YAAqB,OAAkB;QACrC,KAAK,EAAE,CAAA;QADY,YAAO,GAAP,OAAO,CAAW;IAEvC,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,CAAC,IAAA,gBAAK,EAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAChC,OAAO,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;QAC9C,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;CACF;AAhBD,8BAgBC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACU,QAAA,GAAG,GAAiB,IAAA,4BAAe,EAAC,UAE/C,OAAW;IACX,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC,CAAA;AAC/B,CAAC,CAAC,CAAA","sourcesContent":["import { CheckCidOptions, Cid, InferCheckedCid, isCid } from '@atproto/lex-data'\nimport { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\nexport type { Cid }\n\n/**\n * Configuration options for CID schema validation.\n *\n * @see CheckCidOptions from @atproto/lex-data for available options\n */\nexport type CidSchemaOptions = CheckCidOptions\n\n/**\n * Schema for validating Content Identifiers (CIDs).\n *\n * CIDs are self-describing content-addressed identifiers used in AT Protocol\n * to reference data by its cryptographic hash. This schema validates that\n * the input is a valid CID object.\n *\n * @template TOptions - The configuration options type\n *\n * @example\n * ```ts\n * const schema = new CidSchema()\n * const result = schema.validate(someCid)\n * ```\n */\nexport class CidSchema<\n const TOptions extends CidSchemaOptions = { flavor: undefined },\n> extends Schema<InferCheckedCid<TOptions>> {\n readonly type = 'cid' as const\n\n constructor(readonly options?: TOptions) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (!isCid(input, this.options)) {\n return ctx.issueUnexpectedType(input, 'cid')\n }\n\n return ctx.success(input)\n }\n}\n\n/**\n * Creates a CID schema for validating Content Identifiers.\n *\n * CIDs are used throughout AT Protocol to reference content by its hash.\n * This is commonly used for referencing blobs, commits, and other data.\n *\n * @param options - Optional configuration for CID validation\n * @returns A new {@link CidSchema} instance\n *\n * @example\n * ```ts\n * // Basic CID validation\n * const cidSchema = l.cid()\n *\n * // Validate a CID from a blob reference\n * const result = cidSchema.validate(blobRef.ref)\n * ```\n */\nexport const cid = /*#__PURE__*/ memoizedOptions(function <\n O extends CidSchemaOptions = NonNullable<unknown>,\n>(options?: O) {\n return new CidSchema(options)\n})\n"]}
@@ -1,15 +1,81 @@
1
1
  import { Issue, PropertyKey, Schema, ValidationContext } from '../core.js';
2
+ /**
3
+ * Context object provided to custom assertion functions.
4
+ *
5
+ * @property path - Current validation path as an array of property keys
6
+ * @property addIssue - Function to add additional validation issues
7
+ */
2
8
  export type CustomAssertionContext = {
3
9
  path: PropertyKey[];
4
10
  addIssue(issue: Issue): void;
5
11
  };
12
+ /**
13
+ * Type guard function for custom schema validation.
14
+ *
15
+ * @template TValue - The type to validate/narrow to
16
+ */
6
17
  export type CustomAssertion<TValue> = (this: null, input: unknown, ctx: CustomAssertionContext) => input is TValue;
7
- export declare class CustomSchema<const TValue = unknown> extends Schema<TValue> {
18
+ /**
19
+ * Schema with a custom validation function.
20
+ *
21
+ * Allows defining completely custom validation logic using a type guard
22
+ * assertion function. The function receives the input and validation context,
23
+ * and must return whether the input is valid.
24
+ *
25
+ * @template TValue - The validated output type
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const schema = new CustomSchema(
30
+ * (input): input is Date => input instanceof Date,
31
+ * 'Expected a Date instance'
32
+ * )
33
+ * ```
34
+ */
35
+ export declare class CustomSchema<out TValue = unknown> extends Schema<TValue> {
8
36
  private readonly assertion;
9
37
  private readonly message;
10
38
  private readonly path?;
39
+ readonly type: "custom";
11
40
  constructor(assertion: CustomAssertion<TValue>, message: string, path?: (PropertyKey | readonly PropertyKey[]) | undefined);
12
41
  validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<TValue>;
13
42
  }
43
+ /**
44
+ * Creates a custom schema with a user-defined validation function.
45
+ *
46
+ * Use this when the built-in schemas don't cover your validation needs.
47
+ * The assertion function must be a type guard that narrows the input type.
48
+ *
49
+ * @param assertion - Type guard function that validates the input
50
+ * @param message - Error message when validation fails
51
+ * @param path - Optional path to associate with validation errors
52
+ * @returns A new {@link CustomSchema} instance
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * // Validate Date instances
57
+ * const dateSchema = l.custom(
58
+ * (input): input is Date => input instanceof Date && !isNaN(input.getTime()),
59
+ * 'Expected a valid Date'
60
+ * )
61
+ *
62
+ * // Validate specific object shape
63
+ * const pointSchema = l.custom(
64
+ * (input): input is { x: number; y: number } =>
65
+ * typeof input === 'object' &&
66
+ * input !== null &&
67
+ * typeof (input as any).x === 'number' &&
68
+ * typeof (input as any).y === 'number',
69
+ * 'Expected a point with x and y coordinates'
70
+ * )
71
+ *
72
+ * // With custom path
73
+ * const validConfig = l.custom(
74
+ * (input): input is Config => validateConfig(input),
75
+ * 'Invalid configuration',
76
+ * ['config']
77
+ * )
78
+ * ```
79
+ */
14
80
  export declare function custom<TValue>(assertion: CustomAssertion<TValue>, message: string, path?: PropertyKey | readonly PropertyKey[]): CustomSchema<TValue>;
15
81
  //# sourceMappingURL=custom.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../src/schema/custom.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAEL,WAAW,EACX,MAAM,EACN,iBAAiB,EAClB,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,WAAW,E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