@atproto/lex-schema 0.0.10 → 0.0.12

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 (239) hide show
  1. package/CHANGELOG.md +26 -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 +229 -2
  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 +61 -1
  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 +51 -0
  32. package/dist/core/validation-issue.js.map +1 -1
  33. package/dist/core/validator.d.ts +347 -10
  34. package/dist/core/validator.d.ts.map +1 -1
  35. package/dist/core/validator.js +184 -3
  36. package/dist/core/validator.js.map +1 -1
  37. package/dist/helpers.d.ts +13 -25
  38. package/dist/helpers.d.ts.map +1 -1
  39. package/dist/helpers.js +2 -2
  40. package/dist/helpers.js.map +1 -1
  41. package/dist/schema/array.d.ts +45 -0
  42. package/dist/schema/array.d.ts.map +1 -1
  43. package/dist/schema/array.js +14 -0
  44. package/dist/schema/array.js.map +1 -1
  45. package/dist/schema/blob.d.ts +46 -0
  46. package/dist/schema/blob.d.ts.map +1 -1
  47. package/dist/schema/blob.js +39 -0
  48. package/dist/schema/blob.js.map +1 -1
  49. package/dist/schema/boolean.d.ts +28 -0
  50. package/dist/schema/boolean.d.ts.map +1 -1
  51. package/dist/schema/boolean.js +28 -0
  52. package/dist/schema/boolean.js.map +1 -1
  53. package/dist/schema/bytes.d.ts +38 -0
  54. package/dist/schema/bytes.d.ts.map +1 -1
  55. package/dist/schema/bytes.js +32 -0
  56. package/dist/schema/bytes.js.map +1 -1
  57. package/dist/schema/cid.d.ts +38 -0
  58. package/dist/schema/cid.d.ts.map +1 -1
  59. package/dist/schema/cid.js +33 -0
  60. package/dist/schema/cid.js.map +1 -1
  61. package/dist/schema/custom.d.ts +66 -1
  62. package/dist/schema/custom.d.ts.map +1 -1
  63. package/dist/schema/custom.js +54 -0
  64. package/dist/schema/custom.js.map +1 -1
  65. package/dist/schema/dict.d.ts +44 -0
  66. package/dist/schema/dict.d.ts.map +1 -1
  67. package/dist/schema/dict.js +44 -0
  68. package/dist/schema/dict.js.map +1 -1
  69. package/dist/schema/discriminated-union.d.ts +58 -0
  70. package/dist/schema/discriminated-union.d.ts.map +1 -1
  71. package/dist/schema/discriminated-union.js +45 -0
  72. package/dist/schema/discriminated-union.js.map +1 -1
  73. package/dist/schema/enum.d.ts +48 -0
  74. package/dist/schema/enum.d.ts.map +1 -1
  75. package/dist/schema/enum.js +48 -0
  76. package/dist/schema/enum.js.map +1 -1
  77. package/dist/schema/integer.d.ts +42 -0
  78. package/dist/schema/integer.d.ts.map +1 -1
  79. package/dist/schema/integer.js +36 -0
  80. package/dist/schema/integer.js.map +1 -1
  81. package/dist/schema/intersection.d.ts +54 -0
  82. package/dist/schema/intersection.d.ts.map +1 -1
  83. package/dist/schema/intersection.js +49 -0
  84. package/dist/schema/intersection.js.map +1 -1
  85. package/dist/schema/literal.d.ts +44 -0
  86. package/dist/schema/literal.d.ts.map +1 -1
  87. package/dist/schema/literal.js +44 -0
  88. package/dist/schema/literal.js.map +1 -1
  89. package/dist/schema/never.d.ts +42 -0
  90. package/dist/schema/never.d.ts.map +1 -1
  91. package/dist/schema/never.js +42 -0
  92. package/dist/schema/never.js.map +1 -1
  93. package/dist/schema/null.d.ts +29 -0
  94. package/dist/schema/null.d.ts.map +1 -1
  95. package/dist/schema/null.js +29 -0
  96. package/dist/schema/null.js.map +1 -1
  97. package/dist/schema/nullable.d.ts +41 -0
  98. package/dist/schema/nullable.d.ts.map +1 -1
  99. package/dist/schema/nullable.js +41 -0
  100. package/dist/schema/nullable.js.map +1 -1
  101. package/dist/schema/object.d.ts +56 -0
  102. package/dist/schema/object.d.ts.map +1 -1
  103. package/dist/schema/object.js +51 -0
  104. package/dist/schema/object.js.map +1 -1
  105. package/dist/schema/optional.d.ts +42 -0
  106. package/dist/schema/optional.d.ts.map +1 -1
  107. package/dist/schema/optional.js +42 -0
  108. package/dist/schema/optional.js.map +1 -1
  109. package/dist/schema/params.d.ts +89 -7
  110. package/dist/schema/params.d.ts.map +1 -1
  111. package/dist/schema/params.js +84 -10
  112. package/dist/schema/params.js.map +1 -1
  113. package/dist/schema/payload.d.ts +111 -15
  114. package/dist/schema/payload.d.ts.map +1 -1
  115. package/dist/schema/payload.js +70 -0
  116. package/dist/schema/payload.js.map +1 -1
  117. package/dist/schema/permission-set.d.ts +58 -0
  118. package/dist/schema/permission-set.d.ts.map +1 -1
  119. package/dist/schema/permission-set.js +50 -0
  120. package/dist/schema/permission-set.js.map +1 -1
  121. package/dist/schema/permission.d.ts +42 -0
  122. package/dist/schema/permission.d.ts.map +1 -1
  123. package/dist/schema/permission.js +39 -0
  124. package/dist/schema/permission.js.map +1 -1
  125. package/dist/schema/procedure.d.ts +64 -0
  126. package/dist/schema/procedure.d.ts.map +1 -1
  127. package/dist/schema/procedure.js +64 -0
  128. package/dist/schema/procedure.js.map +1 -1
  129. package/dist/schema/query.d.ts +55 -0
  130. package/dist/schema/query.d.ts.map +1 -1
  131. package/dist/schema/query.js +55 -0
  132. package/dist/schema/query.js.map +1 -1
  133. package/dist/schema/record.d.ts +63 -8
  134. package/dist/schema/record.d.ts.map +1 -1
  135. package/dist/schema/record.js +20 -0
  136. package/dist/schema/record.js.map +1 -1
  137. package/dist/schema/ref.d.ts +50 -0
  138. package/dist/schema/ref.d.ts.map +1 -1
  139. package/dist/schema/ref.js +17 -0
  140. package/dist/schema/ref.js.map +1 -1
  141. package/dist/schema/refine.d.ts +58 -9
  142. package/dist/schema/refine.d.ts.map +1 -1
  143. package/dist/schema/refine.js.map +1 -1
  144. package/dist/schema/regexp.d.ts +44 -0
  145. package/dist/schema/regexp.d.ts.map +1 -1
  146. package/dist/schema/regexp.js +44 -0
  147. package/dist/schema/regexp.js.map +1 -1
  148. package/dist/schema/string.d.ts +50 -0
  149. package/dist/schema/string.d.ts.map +1 -1
  150. package/dist/schema/string.js +41 -0
  151. package/dist/schema/string.js.map +1 -1
  152. package/dist/schema/subscription.d.ts +72 -2
  153. package/dist/schema/subscription.d.ts.map +1 -1
  154. package/dist/schema/subscription.js +59 -0
  155. package/dist/schema/subscription.js.map +1 -1
  156. package/dist/schema/token.d.ts +47 -0
  157. package/dist/schema/token.d.ts.map +1 -1
  158. package/dist/schema/token.js +47 -0
  159. package/dist/schema/token.js.map +1 -1
  160. package/dist/schema/typed-object.d.ts +62 -8
  161. package/dist/schema/typed-object.d.ts.map +1 -1
  162. package/dist/schema/typed-object.js +18 -0
  163. package/dist/schema/typed-object.js.map +1 -1
  164. package/dist/schema/typed-ref.d.ts +53 -0
  165. package/dist/schema/typed-ref.d.ts.map +1 -1
  166. package/dist/schema/typed-ref.js +15 -0
  167. package/dist/schema/typed-ref.js.map +1 -1
  168. package/dist/schema/typed-union.d.ts +50 -1
  169. package/dist/schema/typed-union.d.ts.map +1 -1
  170. package/dist/schema/typed-union.js +50 -1
  171. package/dist/schema/typed-union.js.map +1 -1
  172. package/dist/schema/union.d.ts +45 -0
  173. package/dist/schema/union.d.ts.map +1 -1
  174. package/dist/schema/union.js +40 -0
  175. package/dist/schema/union.js.map +1 -1
  176. package/dist/schema/unknown-object.d.ts +34 -0
  177. package/dist/schema/unknown-object.d.ts.map +1 -1
  178. package/dist/schema/unknown-object.js +31 -0
  179. package/dist/schema/unknown-object.js.map +1 -1
  180. package/dist/schema/unknown.d.ts +33 -0
  181. package/dist/schema/unknown.d.ts.map +1 -1
  182. package/dist/schema/unknown.js +33 -0
  183. package/dist/schema/unknown.js.map +1 -1
  184. package/dist/schema/with-default.d.ts +44 -0
  185. package/dist/schema/with-default.d.ts.map +1 -1
  186. package/dist/schema/with-default.js +44 -0
  187. package/dist/schema/with-default.js.map +1 -1
  188. package/package.json +4 -4
  189. package/src/core/$type.ts +150 -18
  190. package/src/core/record-key.ts +44 -0
  191. package/src/core/result.ts +86 -4
  192. package/src/core/schema.ts +236 -7
  193. package/src/core/string-format.ts +259 -13
  194. package/src/core/types.ts +91 -3
  195. package/src/core/validation-error.ts +60 -0
  196. package/src/core/validation-issue.ts +65 -0
  197. package/src/core/validator.ts +351 -10
  198. package/src/helpers.test.ts +110 -29
  199. package/src/helpers.ts +14 -14
  200. package/src/schema/array.test.ts +94 -79
  201. package/src/schema/array.ts +45 -0
  202. package/src/schema/blob.ts +46 -0
  203. package/src/schema/boolean.ts +28 -0
  204. package/src/schema/bytes.ts +38 -0
  205. package/src/schema/cid.ts +38 -0
  206. package/src/schema/custom.ts +66 -1
  207. package/src/schema/dict.ts +44 -0
  208. package/src/schema/discriminated-union.ts +58 -0
  209. package/src/schema/enum.ts +48 -0
  210. package/src/schema/integer.ts +42 -0
  211. package/src/schema/intersection.ts +54 -0
  212. package/src/schema/literal.ts +44 -0
  213. package/src/schema/never.ts +42 -0
  214. package/src/schema/null.ts +29 -0
  215. package/src/schema/nullable.ts +41 -0
  216. package/src/schema/object.ts +56 -0
  217. package/src/schema/optional.ts +42 -0
  218. package/src/schema/params.test.ts +58 -2
  219. package/src/schema/params.ts +124 -16
  220. package/src/schema/payload.test.ts +3 -3
  221. package/src/schema/payload.ts +142 -38
  222. package/src/schema/permission-set.ts +58 -0
  223. package/src/schema/permission.ts +42 -0
  224. package/src/schema/procedure.ts +64 -0
  225. package/src/schema/query.ts +55 -0
  226. package/src/schema/record.ts +63 -8
  227. package/src/schema/ref.ts +50 -0
  228. package/src/schema/refine.ts +58 -9
  229. package/src/schema/regexp.ts +44 -0
  230. package/src/schema/string.ts +50 -0
  231. package/src/schema/subscription.ts +72 -2
  232. package/src/schema/token.ts +47 -0
  233. package/src/schema/typed-object.ts +62 -8
  234. package/src/schema/typed-ref.ts +53 -0
  235. package/src/schema/typed-union.ts +55 -2
  236. package/src/schema/union.ts +45 -0
  237. package/src/schema/unknown-object.ts +34 -0
  238. package/src/schema/unknown.ts +33 -0
  239. package/src/schema/with-default.ts +44 -0
@@ -1 +1 @@
1
- {"version":3,"file":"refine.js","sourceRoot":"","sources":["../../src/schema/refine.ts"],"names":[],"mappings":";;AAkEA,wBAiBC;AAnFD,wCAOmB;AA0DnB,wBAAwB;AACxB,SAAgB,MAAM,CACpB,MAAkB,EAClB,UAA+B;IAE/B,wEAAwE;IACxE,4EAA4E;IAC5E,4EAA4E;IAC5E,6BAA6B;IAC7B,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;QAC3B,iBAAiB,EAAE;YACjB,8DAA8D;YAC9D,KAAK,EAAE,wBAAwB,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;YAC5D,UAAU,EAAE,KAAK;YACjB,QAAQ,EAAE,KAAK;YACf,YAAY,EAAE,IAAI;SACnB;KACF,CAAC,CAAA;AACJ,CAAC;AAED,wBAAwB;AACxB,SAAS,wBAAwB,CAK/B,KAAc,EACd,GAAsB;IAEtB,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IAC/C,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,OAAO,MAAM,CAAA;IAElC,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IACvE,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;QACjD,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,qBAAW,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAA;IACzE,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import {\n InferInput,\n IssueCustom,\n PropertyKey,\n ValidationContext,\n ValidationResult,\n Validator,\n} from '../core.js'\nimport { CustomAssertionContext } from './custom.js'\n\nexport type RefinementCheck<T> = {\n check: (value: T, ctx: CustomAssertionContext) => boolean\n message: string\n path?: PropertyKey | readonly PropertyKey[]\n}\n\nexport type RefinementAssertion<T, Out extends T> = {\n check: (this: null, value: T, ctx: CustomAssertionContext) => value is Out\n message: string\n path?: PropertyKey | readonly PropertyKey[]\n}\n\nexport type InferRefinement<R> =\n R extends RefinementCheck<infer T>\n ? T\n : R extends RefinementAssertion<infer T, any>\n ? T\n : never\n\nexport type Refinement<T = any, Out extends T = T> =\n | RefinementCheck<T>\n | RefinementAssertion<T, Out>\n\n/**\n * Create a refined schema based on an existing schema and a refinement check.\n *\n * @param schema - The base schema to refine.\n * @param refinement - The refinement check to apply.\n * @returns A new schema that includes the refinement.\n * @example\n *\n * ```ts\n * const PositiveInt = refine(l.integer(), {\n * check: (value) => value > 0,\n * message: 'Value must be a positive integer',\n * })\n * const result = PositiveInt.validate(-5)\n * // result.success === false\n * ```\n */\nexport function refine<\n const TValidator extends Validator,\n TInput extends InferInput<TValidator>,\n>(\n schema: TValidator,\n refinement: RefinementAssertion<InferInput<TValidator>, TInput>,\n): TValidator & Validator<TInput>\nexport function refine<const TValidator extends Validator>(\n schema: TValidator,\n refinement: RefinementCheck<InferInput<TValidator>>,\n): TValidator\nexport function refine<\n TRefinement extends Refinement,\n const TValidator extends Validator<InferRefinement<TRefinement>>,\n>(schema: TValidator, refinement: TRefinement): TValidator\n/*@__NO_SIDE_EFFECTS__*/\nexport function refine<const TValidator extends Validator>(\n schema: TValidator,\n refinement: Refinement<unknown>,\n): TValidator {\n // This is basically the same as monkey patching the \"validateInContext\"\n // method to the schema, but done in a way that does not mutate the original\n // schema. This is safe to do because Validators don't update their internal\n // state over their lifetime.\n return Object.create(schema, {\n validateInContext: {\n // We do not use an arrow function to avoid creating a closure\n value: validateInContextUnbound.bind({ schema, refinement }),\n enumerable: false,\n writable: false,\n configurable: true,\n },\n })\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nfunction validateInContextUnbound<S extends Validator>(\n this: {\n schema: S\n refinement: Refinement<InferInput<S>>\n },\n input: unknown,\n ctx: ValidationContext,\n): ValidationResult<InferInput<S>> {\n const result = ctx.validate(input, this.schema)\n if (!result.success) return result\n\n const checkResult = this.refinement.check.call(null, result.value, ctx)\n if (!checkResult) {\n const path = ctx.concatPath(this.refinement.path)\n return ctx.issue(new IssueCustom(path, input, this.refinement.message))\n }\n\n return result\n}\n"]}
1
+ {"version":3,"file":"refine.js","sourceRoot":"","sources":["../../src/schema/refine.ts"],"names":[],"mappings":";;AAmHA,wBAiBC;AApID,wCAOmB;AA2GnB,wBAAwB;AACxB,SAAgB,MAAM,CACpB,MAAkB,EAClB,UAA+B;IAE/B,wEAAwE;IACxE,4EAA4E;IAC5E,4EAA4E;IAC5E,6BAA6B;IAC7B,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;QAC3B,iBAAiB,EAAE;YACjB,8DAA8D;YAC9D,KAAK,EAAE,wBAAwB,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;YAC5D,UAAU,EAAE,KAAK;YACjB,QAAQ,EAAE,KAAK;YACf,YAAY,EAAE,IAAI;SACnB;KACF,CAAC,CAAA;AACJ,CAAC;AAED,wBAAwB;AACxB,SAAS,wBAAwB,CAK/B,KAAc,EACd,GAAsB;IAEtB,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IAC/C,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,OAAO,MAAM,CAAA;IAElC,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IACvE,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;QACjD,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,qBAAW,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAA;IACzE,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import {\n InferInput,\n IssueCustom,\n PropertyKey,\n ValidationContext,\n ValidationResult,\n Validator,\n} from '../core.js'\nimport { CustomAssertionContext } from './custom.js'\n\n/**\n * Configuration for a refinement check that validates a condition.\n *\n * @template T - The type being validated\n * @property check - Function that returns true if the value passes the check\n * @property message - Error message when the check fails\n * @property path - Optional path to associate with the error\n */\nexport type RefinementCheck<T> = {\n check: (value: T, ctx: CustomAssertionContext) => boolean\n message: string\n path?: PropertyKey | readonly PropertyKey[]\n}\n\n/**\n * Configuration for a refinement assertion that narrows the type.\n *\n * @template T - The input type being validated\n * @template Out - The narrowed output type\n * @property check - Type guard function that narrows the type\n * @property message - Error message when the assertion fails\n * @property path - Optional path to associate with the error\n */\nexport type RefinementAssertion<T, Out extends T> = {\n check: (this: null, value: T, ctx: CustomAssertionContext) => value is Out\n message: string\n path?: PropertyKey | readonly PropertyKey[]\n}\n\n/**\n * Infers the input type from a refinement configuration.\n *\n * @template R - The refinement type\n */\nexport type InferRefinement<R> =\n R extends RefinementCheck<infer T>\n ? T\n : R extends RefinementAssertion<infer T, any>\n ? T\n : never\n\n/**\n * Union type of refinement check or assertion.\n *\n * @template T - The input type being validated\n * @template Out - The output type (same as T for checks, narrowed for assertions)\n */\nexport type Refinement<T = any, Out extends T = T> =\n | RefinementCheck<T>\n | RefinementAssertion<T, Out>\n\n/**\n * Creates a refined schema by adding additional validation constraints.\n *\n * Wraps an existing schema with an additional check function. The base schema\n * is validated first, then the refinement check is applied to the result.\n *\n * @param schema - The base schema to refine\n * @param refinement - The refinement check or assertion to apply\n * @returns A new schema that includes the refinement\n *\n * @example\n * ```ts\n * // Simple check refinement\n * const positiveInt = l.refine(l.integer(), {\n * check: (value) => value > 0,\n * message: 'Value must be positive',\n * })\n *\n * positiveInt.parse(5) // 5\n * positiveInt.parse(-1) // throws\n *\n * // Type-narrowing assertion\n * const nonEmptyString = l.refine(l.string(), {\n * check: (value): value is string & { length: number } => value.length > 0,\n * message: 'String must not be empty',\n * })\n *\n * // With custom path for nested errors\n * const validDateRange = l.refine(\n * l.object({ start: l.string(), end: l.string() }),\n * {\n * check: (v) => new Date(v.start) < new Date(v.end),\n * message: 'Start date must be before end date',\n * path: ['end'],\n * }\n * )\n * ```\n */\nexport function refine<\n const TValidator extends Validator,\n TInput extends InferInput<TValidator>,\n>(\n schema: TValidator,\n refinement: RefinementAssertion<InferInput<TValidator>, TInput>,\n): TValidator & Validator<TInput>\nexport function refine<const TValidator extends Validator>(\n schema: TValidator,\n refinement: RefinementCheck<InferInput<TValidator>>,\n): TValidator\nexport function refine<\n TRefinement extends Refinement,\n const TValidator extends Validator<InferRefinement<TRefinement>>,\n>(schema: TValidator, refinement: TRefinement): TValidator\n/*@__NO_SIDE_EFFECTS__*/\nexport function refine<const TValidator extends Validator>(\n schema: TValidator,\n refinement: Refinement<unknown>,\n): TValidator {\n // This is basically the same as monkey patching the \"validateInContext\"\n // method to the schema, but done in a way that does not mutate the original\n // schema. This is safe to do because Validators don't update their internal\n // state over their lifetime.\n return Object.create(schema, {\n validateInContext: {\n // We do not use an arrow function to avoid creating a closure\n value: validateInContextUnbound.bind({ schema, refinement }),\n enumerable: false,\n writable: false,\n configurable: true,\n },\n })\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nfunction validateInContextUnbound<S extends Validator>(\n this: {\n schema: S\n refinement: Refinement<InferInput<S>>\n },\n input: unknown,\n ctx: ValidationContext,\n): ValidationResult<InferInput<S>> {\n const result = ctx.validate(input, this.schema)\n if (!result.success) return result\n\n const checkResult = this.refinement.check.call(null, result.value, ctx)\n if (!checkResult) {\n const path = ctx.concatPath(this.refinement.path)\n return ctx.issue(new IssueCustom(path, input, this.refinement.message))\n }\n\n return result\n}\n"]}
@@ -1,8 +1,52 @@
1
1
  import { Schema, ValidationContext } from '../core.js';
2
+ /**
3
+ * Schema for validating strings against a regular expression pattern.
4
+ *
5
+ * Validates that the input is a string and matches the provided pattern.
6
+ * The pattern is tested using RegExp.test().
7
+ *
8
+ * @template TValue - The string type (can be narrowed with branded types)
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const schema = new RegexpSchema(/^[a-z]+$/)
13
+ * schema.validate('hello') // success
14
+ * schema.validate('Hello') // fails - uppercase not allowed
15
+ * ```
16
+ */
2
17
  export declare class RegexpSchema<TValue extends string = string> extends Schema<TValue> {
3
18
  readonly pattern: RegExp;
4
19
  constructor(pattern: RegExp);
5
20
  validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<TValue>;
6
21
  }
22
+ /**
23
+ * Creates a regexp schema that validates strings against a pattern.
24
+ *
25
+ * Useful for custom string formats not covered by the built-in format
26
+ * validators.
27
+ *
28
+ * @param pattern - Regular expression pattern to match against
29
+ * @returns A new {@link RegexpSchema} instance
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * // Simple pattern
34
+ * const slugSchema = l.regexp(/^[a-z0-9-]+$/)
35
+ *
36
+ * // With anchors for exact match
37
+ * const uuidSchema = l.regexp(
38
+ * /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
39
+ * )
40
+ *
41
+ * // Semantic versioning
42
+ * const semverSchema = l.regexp(/^\d+\.\d+\.\d+(-[\w.]+)?(\+[\w.]+)?$/)
43
+ *
44
+ * // Use in object
45
+ * const configSchema = l.object({
46
+ * name: l.regexp(/^[a-z][a-z0-9-]*$/), // kebab-case identifier
47
+ * version: semverSchema,
48
+ * })
49
+ * ```
50
+ */
7
51
  export declare function regexp<TInput extends string = string>(pattern: RegExp): RegexpSchema<TInput>;
8
52
  //# sourceMappingURL=regexp.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../src/schema/regexp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEtD,qBAAa,YAAY,CACvB,MAAM,SAAS,MAAM,GAAG,MAAM,CAC9B,SAAQ,MAAM,CAAC,MAAM,CAAC;aACM,OAAO,EAAE,MAAM;gBAAf,OAAO,EAAE,MAAM;IAI3C,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAWzD;AAGD,wBAAgB,MAAM,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,wBAErE"}
1
+ {"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../src/schema/regexp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEtD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,YAAY,CACvB,MAAM,SAAS,MAAM,GAAG,MAAM,CAC9B,SAAQ,MAAM,CAAC,MAAM,CAAC;aACM,OAAO,EAAE,MAAM;gBAAf,OAAO,EAAE,MAAM;IAI3C,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAWzD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,wBAAgB,MAAM,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,wBAErE"}
@@ -3,6 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RegexpSchema = void 0;
4
4
  exports.regexp = regexp;
5
5
  const core_js_1 = require("../core.js");
6
+ /**
7
+ * Schema for validating strings against a regular expression pattern.
8
+ *
9
+ * Validates that the input is a string and matches the provided pattern.
10
+ * The pattern is tested using RegExp.test().
11
+ *
12
+ * @template TValue - The string type (can be narrowed with branded types)
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const schema = new RegexpSchema(/^[a-z]+$/)
17
+ * schema.validate('hello') // success
18
+ * schema.validate('Hello') // fails - uppercase not allowed
19
+ * ```
20
+ */
6
21
  class RegexpSchema extends core_js_1.Schema {
7
22
  pattern;
8
23
  constructor(pattern) {
@@ -20,6 +35,35 @@ class RegexpSchema extends core_js_1.Schema {
20
35
  }
21
36
  }
22
37
  exports.RegexpSchema = RegexpSchema;
38
+ /**
39
+ * Creates a regexp schema that validates strings against a pattern.
40
+ *
41
+ * Useful for custom string formats not covered by the built-in format
42
+ * validators.
43
+ *
44
+ * @param pattern - Regular expression pattern to match against
45
+ * @returns A new {@link RegexpSchema} instance
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * // Simple pattern
50
+ * const slugSchema = l.regexp(/^[a-z0-9-]+$/)
51
+ *
52
+ * // With anchors for exact match
53
+ * const uuidSchema = l.regexp(
54
+ * /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
55
+ * )
56
+ *
57
+ * // Semantic versioning
58
+ * const semverSchema = l.regexp(/^\d+\.\d+\.\d+(-[\w.]+)?(\+[\w.]+)?$/)
59
+ *
60
+ * // Use in object
61
+ * const configSchema = l.object({
62
+ * name: l.regexp(/^[a-z][a-z0-9-]*$/), // kebab-case identifier
63
+ * version: semverSchema,
64
+ * })
65
+ * ```
66
+ */
23
67
  /*@__NO_SIDE_EFFECTS__*/
24
68
  function regexp(pattern) {
25
69
  return new RegexpSchema(pattern);
@@ -1 +1 @@
1
- {"version":3,"file":"regexp.js","sourceRoot":"","sources":["../../src/schema/regexp.ts"],"names":[],"mappings":";;;AAuBA,wBAEC;AAzBD,wCAAsD;AAEtD,MAAa,YAEX,SAAQ,gBAAc;IACM;IAA5B,YAA4B,OAAe;QACzC,KAAK,EAAE,CAAA;QADmB,YAAO,GAAP,OAAO,CAAQ;IAE3C,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QAC9C,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,OAAO,GAAG,CAAC,kBAAkB,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC/D,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAe,CAAC,CAAA;IACrC,CAAC;CACF;AAlBD,oCAkBC;AAED,wBAAwB;AACxB,SAAgB,MAAM,CAAiC,OAAe;IACpE,OAAO,IAAI,YAAY,CAAS,OAAO,CAAC,CAAA;AAC1C,CAAC","sourcesContent":["import { Schema, ValidationContext } from '../core.js'\n\nexport class RegexpSchema<\n TValue extends string = string,\n> extends Schema<TValue> {\n constructor(public readonly pattern: RegExp) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (typeof input !== 'string') {\n return ctx.issueInvalidType(input, 'string')\n }\n\n if (!this.pattern.test(input)) {\n return ctx.issueInvalidFormat(input, this.pattern.toString())\n }\n\n return ctx.success(input as TValue)\n }\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nexport function regexp<TInput extends string = string>(pattern: RegExp) {\n return new RegexpSchema<TInput>(pattern)\n}\n"]}
1
+ {"version":3,"file":"regexp.js","sourceRoot":"","sources":["../../src/schema/regexp.ts"],"names":[],"mappings":";;;AAmEA,wBAEC;AArED,wCAAsD;AAEtD;;;;;;;;;;;;;;GAcG;AACH,MAAa,YAEX,SAAQ,gBAAc;IACM;IAA5B,YAA4B,OAAe;QACzC,KAAK,EAAE,CAAA;QADmB,YAAO,GAAP,OAAO,CAAQ;IAE3C,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QAC9C,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,OAAO,GAAG,CAAC,kBAAkB,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC/D,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAe,CAAC,CAAA;IACrC,CAAC;CACF;AAlBD,oCAkBC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAwB;AACxB,SAAgB,MAAM,CAAiC,OAAe;IACpE,OAAO,IAAI,YAAY,CAAS,OAAO,CAAC,CAAA;AAC1C,CAAC","sourcesContent":["import { Schema, ValidationContext } from '../core.js'\n\n/**\n * Schema for validating strings against a regular expression pattern.\n *\n * Validates that the input is a string and matches the provided pattern.\n * The pattern is tested using RegExp.test().\n *\n * @template TValue - The string type (can be narrowed with branded types)\n *\n * @example\n * ```ts\n * const schema = new RegexpSchema(/^[a-z]+$/)\n * schema.validate('hello') // success\n * schema.validate('Hello') // fails - uppercase not allowed\n * ```\n */\nexport class RegexpSchema<\n TValue extends string = string,\n> extends Schema<TValue> {\n constructor(public readonly pattern: RegExp) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (typeof input !== 'string') {\n return ctx.issueInvalidType(input, 'string')\n }\n\n if (!this.pattern.test(input)) {\n return ctx.issueInvalidFormat(input, this.pattern.toString())\n }\n\n return ctx.success(input as TValue)\n }\n}\n\n/**\n * Creates a regexp schema that validates strings against a pattern.\n *\n * Useful for custom string formats not covered by the built-in format\n * validators.\n *\n * @param pattern - Regular expression pattern to match against\n * @returns A new {@link RegexpSchema} instance\n *\n * @example\n * ```ts\n * // Simple pattern\n * const slugSchema = l.regexp(/^[a-z0-9-]+$/)\n *\n * // With anchors for exact match\n * const uuidSchema = l.regexp(\n * /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i\n * )\n *\n * // Semantic versioning\n * const semverSchema = l.regexp(/^\\d+\\.\\d+\\.\\d+(-[\\w.]+)?(\\+[\\w.]+)?$/)\n *\n * // Use in object\n * const configSchema = l.object({\n * name: l.regexp(/^[a-z][a-z0-9-]*$/), // kebab-case identifier\n * version: semverSchema,\n * })\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function regexp<TInput extends string = string>(pattern: RegExp) {\n return new RegexpSchema<TInput>(pattern)\n}\n"]}
@@ -1,4 +1,13 @@
1
1
  import { InferStringFormat, Schema, StringFormat, ValidationContext } from '../core.js';
2
+ /**
3
+ * Configuration options for string schema validation.
4
+ *
5
+ * @property format - Expected string format (e.g., 'datetime', 'uri', 'at-uri', 'did', 'handle', 'nsid', 'cid', 'tid', 'record-key', 'at-identifier', 'language')
6
+ * @property minLength - Minimum length in UTF-8 bytes
7
+ * @property maxLength - Maximum length in UTF-8 bytes
8
+ * @property minGraphemes - Minimum number of grapheme clusters
9
+ * @property maxGraphemes - Maximum number of grapheme clusters
10
+ */
2
11
  export type StringSchemaOptions = {
3
12
  format?: StringFormat;
4
13
  minLength?: number;
@@ -6,6 +15,20 @@ export type StringSchemaOptions = {
6
15
  minGraphemes?: number;
7
16
  maxGraphemes?: number;
8
17
  };
18
+ /**
19
+ * Schema for validating string values with optional format and length constraints.
20
+ *
21
+ * Supports various string formats defined in the Lexicon specification, as well as
22
+ * length constraints measured in UTF-8 bytes or grapheme clusters.
23
+ *
24
+ * @template TOptions - The configuration options type
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const schema = new StringSchema({ format: 'datetime', maxLength: 64 })
29
+ * const result = schema.validate('2024-01-15T10:30:00Z')
30
+ * ```
31
+ */
9
32
  export declare class StringSchema<const TOptions extends StringSchemaOptions = StringSchemaOptions> extends Schema<TOptions extends {
10
33
  format: infer F extends StringFormat;
11
34
  } ? InferStringFormat<F> : string> {
@@ -14,5 +37,32 @@ export declare class StringSchema<const TOptions extends StringSchemaOptions = S
14
37
  validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<string>;
15
38
  }
16
39
  export declare function coerceToString(input: unknown): string | null;
40
+ /**
41
+ * Creates a string schema with optional format and length constraints.
42
+ *
43
+ * Strings can be validated against various formats (datetime, uri, did, handle, etc.)
44
+ * and constrained by length in UTF-8 bytes or grapheme clusters.
45
+ *
46
+ * @param options - Optional configuration for format and length constraints
47
+ * @returns A new {@link StringSchema} instance
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * // Basic string
52
+ * const nameSchema = l.string()
53
+ *
54
+ * // With format validation
55
+ * const dateSchema = l.string({ format: 'datetime' })
56
+ *
57
+ * // With length constraints (UTF-8 bytes)
58
+ * const bioSchema = l.string({ maxLength: 256 })
59
+ *
60
+ * // With grapheme constraints (user-perceived characters)
61
+ * const displayNameSchema = l.string({ maxGraphemes: 64 })
62
+ *
63
+ * // Combining constraints
64
+ * const handleSchema = l.string({ format: 'handle', minLength: 3, maxLength: 253 })
65
+ * ```
66
+ */
17
67
  export declare const string: <const O extends StringSchemaOptions = {}>(options?: StringSchemaOptions & O) => StringSchema<O>;
18
68
  //# sourceMappingURL=string.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/schema/string.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,MAAM,EACN,YAAY,EACZ,iBAAiB,EAElB,MAAM,YAAY,CAAA;AAInB,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,qBAAa,YAAY,CACvB,KAAK,CAAC,QAAQ,SAAS,mBAAmB,GAAG,mBAAmB,CAChE,SAAQ,MAAM,CACd,QAAQ,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC,SAAS,YAAY,CAAA;CAAE,GACrD,iBAAiB,CAAC,CAAC,CAAC,GACpB,MAAM,CACX;IACa,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ;gBAAlB,OAAO,CAAC,EAAE,QAAQ,YAAA;IAIvC,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAqDzD;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAsC5D;AAED,eAAO,MAAM,MAAM,SACX,CAAC,SAAS,mBAAmB,iBACzB,mBAAmB,GAAG,CAAC,oBAEjC,CAAA"}
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/schema/string.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,MAAM,EACN,YAAY,EACZ,iBAAiB,EAElB,MAAM,YAAY,CAAA;AAInB;;;;;;;;GAQG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAY,CACvB,KAAK,CAAC,QAAQ,SAAS,mBAAmB,GAAG,mBAAmB,CAChE,SAAQ,MAAM,CACd,QAAQ,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC,SAAS,YAAY,CAAA;CAAE,GACrD,iBAAiB,CAAC,CAAC,CAAC,GACpB,MAAM,CACX;IACa,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ;gBAAlB,OAAO,CAAC,EAAE,QAAQ,YAAA;IAIvC,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAqDzD;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAsC5D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,MAAM,SACX,CAAC,SAAS,mBAAmB,iBACzB,mBAAmB,GAAG,CAAC,oBAEjC,CAAA"}
@@ -6,6 +6,20 @@ const lex_data_1 = require("@atproto/lex-data");
6
6
  const core_js_1 = require("../core.js");
7
7
  const memoize_js_1 = require("../util/memoize.js");
8
8
  const token_js_1 = require("./token.js");
9
+ /**
10
+ * Schema for validating string values with optional format and length constraints.
11
+ *
12
+ * Supports various string formats defined in the Lexicon specification, as well as
13
+ * length constraints measured in UTF-8 bytes or grapheme clusters.
14
+ *
15
+ * @template TOptions - The configuration options type
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const schema = new StringSchema({ format: 'datetime', maxLength: 64 })
20
+ * const result = schema.validate('2024-01-15T10:30:00Z')
21
+ * ```
22
+ */
9
23
  class StringSchema extends core_js_1.Schema {
10
24
  options;
11
25
  constructor(options) {
@@ -97,6 +111,33 @@ function coerceToString(input) {
97
111
  return null;
98
112
  }
99
113
  }
114
+ /**
115
+ * Creates a string schema with optional format and length constraints.
116
+ *
117
+ * Strings can be validated against various formats (datetime, uri, did, handle, etc.)
118
+ * and constrained by length in UTF-8 bytes or grapheme clusters.
119
+ *
120
+ * @param options - Optional configuration for format and length constraints
121
+ * @returns A new {@link StringSchema} instance
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * // Basic string
126
+ * const nameSchema = l.string()
127
+ *
128
+ * // With format validation
129
+ * const dateSchema = l.string({ format: 'datetime' })
130
+ *
131
+ * // With length constraints (UTF-8 bytes)
132
+ * const bioSchema = l.string({ maxLength: 256 })
133
+ *
134
+ * // With grapheme constraints (user-perceived characters)
135
+ * const displayNameSchema = l.string({ maxGraphemes: 64 })
136
+ *
137
+ * // Combining constraints
138
+ * const handleSchema = l.string({ format: 'handle', minLength: 3, maxLength: 253 })
139
+ * ```
140
+ */
100
141
  exports.string = (0, memoize_js_1.memoizedOptions)(function (options) {
101
142
  return new StringSchema(options);
102
143
  });
@@ -1 +1 @@
1
- {"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/schema/string.ts"],"names":[],"mappings":";;;AAqFA,wCAsCC;AA3HD,gDAA+D;AAC/D,wCAMmB;AACnB,mDAAoD;AACpD,yCAAwC;AAUxC,MAAa,YAEX,SAAQ,gBAIT;IACsB;IAArB,YAAqB,OAAkB;QACrC,KAAK,EAAE,CAAA;QADY,YAAO,GAAP,OAAO,CAAW;IAEvC,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,MAAM,GAAG,GAAG,cAAc,CAAC,KAAK,CAAC,CAAA;QACjC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;YACh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M,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;oBAAE,OAAO,IAAI,CAAA;gBAC9C,OAAO,KAAK,CAAC,WAAW,EAAE,CAAA;YAC5B,CAAC;YAED,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;gBACzB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAA;YACzB,CAAC;YAED,MAAM,GAAG,GAAG,IAAA,gBAAK,EAAC,KAAK,CAAC,CAAA;YACxB,IAAI,GAAG;gBAAE,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAA;YAE9B,IAAI,KAAK,YAAY,MAAM,EAAE,CAAC;gBAC5B,OAAO,KAAK,CAAC,OAAO,EAAE,CAAA;YACxB,CAAC;QACH,CAAC;QAED,gBAAgB;QAChB;YACE,OAAO,IAAI,CAAA;IACf,CAAC;AACH,CAAC;AAEY,QAAA,MAAM,GAAiB,IAAA,4BAAe,EAAC,UAElD,OAAiC;IACjC,OAAO,IAAI,YAAY,CAAI,OAAO,CAAC,CAAA;AACrC,CAAC,CAAC,CAAA","sourcesContent":["import { graphemeLen, ifCid, utf8Len } from '@atproto/lex-data'\nimport {\n InferStringFormat,\n Schema,\n StringFormat,\n ValidationContext,\n isStringFormat,\n} from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\nimport { TokenSchema } from './token.js'\n\nexport type StringSchemaOptions = {\n format?: StringFormat\n minLength?: number\n maxLength?: number\n minGraphemes?: number\n maxGraphemes?: number\n}\n\nexport class StringSchema<\n const TOptions extends StringSchemaOptions = StringSchemaOptions,\n> extends Schema<\n TOptions extends { format: infer F extends StringFormat }\n ? InferStringFormat<F>\n : string\n> {\n constructor(readonly options?: TOptions) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n const str = coerceToString(input)\n if (str == null) {\n return ctx.issueInvalidType(input, 'string')\n }\n\n let lazyUtf8Len: number\n\n const minLength = this.options?.minLength\n if (minLength != null) {\n if ((lazyUtf8Len ??= utf8Len(str)) < minLength) {\n return ctx.issueTooSmall(str, 'string', minLength, lazyUtf8Len)\n }\n }\n\n const maxLength = this.options?.maxLength\n if (maxLength != null) {\n // Optimization: we can avoid computing the UTF-8 length if the maximum\n // possible length, in bytes, of the input JS string is smaller than the\n // maxLength (in UTF-8 string bytes).\n if (str.length * 3 <= maxLength) {\n // Input string so small it can't possibly exceed maxLength\n } else if ((lazyUtf8Len ??= utf8Len(str)) > maxLength) {\n return ctx.issueTooBig(str, 'string', maxLength, lazyUtf8Len)\n }\n }\n\n let lazyGraphLen: number\n\n const minGraphemes = this.options?.minGraphemes\n if (minGraphemes != null) {\n // Optimization: avoid counting graphemes if the length check already fails\n if (str.length < minGraphemes) {\n return ctx.issueTooSmall(str, 'grapheme', minGraphemes, str.length)\n } else if ((lazyGraphLen ??= graphemeLen(str)) < minGraphemes) {\n return ctx.issueTooSmall(str, 'grapheme', minGraphemes, lazyGraphLen)\n }\n }\n\n const maxGraphemes = this.options?.maxGraphemes\n if (maxGraphemes != null) {\n if ((lazyGraphLen ??= graphemeLen(str)) > maxGraphemes) {\n return ctx.issueTooBig(str, 'grapheme', maxGraphemes, lazyGraphLen)\n }\n }\n\n const format = this.options?.format\n if (format != null && !isStringFormat(str, format)) {\n return ctx.issueInvalidFormat(str, format)\n }\n\n return ctx.success(str)\n }\n}\n\nexport function coerceToString(input: unknown): string | null {\n switch (typeof input) {\n // @NOTE We do *not* coerce numbers/booleans to strings because that can\n // lead to them being accepted as string instead of being coerced to\n // number/boolean when the input is a string and the expected result is\n // number/boolean (e.g. in params).\n case 'string':\n return input\n case 'object': {\n if (input == null) return null\n\n // @NOTE Allow using TokenSchema instances in places expecting strings,\n // converting them to their string value.\n if (input instanceof TokenSchema) {\n return input.toString()\n }\n\n if (input instanceof Date) {\n if (Number.isNaN(input.getTime())) return null\n return input.toISOString()\n }\n\n if (input instanceof URL) {\n return input.toString()\n }\n\n const cid = ifCid(input)\n if (cid) return cid.toString()\n\n if (input instanceof String) {\n return input.valueOf()\n }\n }\n\n // falls through\n default:\n return null\n }\n}\n\nexport const string = /*#__PURE__*/ memoizedOptions(function <\n const O extends StringSchemaOptions = NonNullable<unknown>,\n>(options?: StringSchemaOptions & O) {\n return new StringSchema<O>(options)\n})\n"]}
1
+ {"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/schema/string.ts"],"names":[],"mappings":";;;AA4GA,wCAsCC;AAlJD,gDAA+D;AAC/D,wCAMmB;AACnB,mDAAoD;AACpD,yCAAwC;AAmBxC;;;;;;;;;;;;;GAaG;AACH,MAAa,YAEX,SAAQ,gBAIT;IACsB;IAArB,YAAqB,OAAkB;QACrC,KAAK,EAAE,CAAA;QADY,YAAO,GAAP,OAAO,CAAW;IAEvC,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,MAAM,GAAG,GAAG,cAAc,CAAC,KAAK,CAAC,CAAA;QACjC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;YAChB,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QAC9C,CAAC;QAED,IAAI,WAAmB,CAAA;QAEvB,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,EAAE,SAAS,CAAA;QACzC,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;YACtB,IAAI,CAAC,WAAW,KAAK,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC;gBAC/C,OAAO,GAAG,CAAC,aAAa,CAAC,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,CAAC,CAAA;YACjE,CAAC;QACH,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,EAAE,SAAS,CAAA;QACzC,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;YACtB,uEAAuE;YACvE,wEAAwE;YACxE,qCAAqC;YACrC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,EAAE,CAAC;gBAChC,2DAA2D;YAC7D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AY,CAAI,OAAO,CAAC,CAAA;AACrC,CAAC,CAAC,CAAA","sourcesContent":["import { graphemeLen, ifCid, utf8Len } from '@atproto/lex-data'\nimport {\n InferStringFormat,\n Schema,\n StringFormat,\n ValidationContext,\n isStringFormat,\n} from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\nimport { TokenSchema } from './token.js'\n\n/**\n * Configuration options for string schema validation.\n *\n * @property format - Expected string format (e.g., 'datetime', 'uri', 'at-uri', 'did', 'handle', 'nsid', 'cid', 'tid', 'record-key', 'at-identifier', 'language')\n * @property minLength - Minimum length in UTF-8 bytes\n * @property maxLength - Maximum length in UTF-8 bytes\n * @property minGraphemes - Minimum number of grapheme clusters\n * @property maxGraphemes - Maximum number of grapheme clusters\n */\nexport type StringSchemaOptions = {\n format?: StringFormat\n minLength?: number\n maxLength?: number\n minGraphemes?: number\n maxGraphemes?: number\n}\n\n/**\n * Schema for validating string values with optional format and length constraints.\n *\n * Supports various string formats defined in the Lexicon specification, as well as\n * length constraints measured in UTF-8 bytes or grapheme clusters.\n *\n * @template TOptions - The configuration options type\n *\n * @example\n * ```ts\n * const schema = new StringSchema({ format: 'datetime', maxLength: 64 })\n * const result = schema.validate('2024-01-15T10:30:00Z')\n * ```\n */\nexport class StringSchema<\n const TOptions extends StringSchemaOptions = StringSchemaOptions,\n> extends Schema<\n TOptions extends { format: infer F extends StringFormat }\n ? InferStringFormat<F>\n : string\n> {\n constructor(readonly options?: TOptions) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n const str = coerceToString(input)\n if (str == null) {\n return ctx.issueInvalidType(input, 'string')\n }\n\n let lazyUtf8Len: number\n\n const minLength = this.options?.minLength\n if (minLength != null) {\n if ((lazyUtf8Len ??= utf8Len(str)) < minLength) {\n return ctx.issueTooSmall(str, 'string', minLength, lazyUtf8Len)\n }\n }\n\n const maxLength = this.options?.maxLength\n if (maxLength != null) {\n // Optimization: we can avoid computing the UTF-8 length if the maximum\n // possible length, in bytes, of the input JS string is smaller than the\n // maxLength (in UTF-8 string bytes).\n if (str.length * 3 <= maxLength) {\n // Input string so small it can't possibly exceed maxLength\n } else if ((lazyUtf8Len ??= utf8Len(str)) > maxLength) {\n return ctx.issueTooBig(str, 'string', maxLength, lazyUtf8Len)\n }\n }\n\n let lazyGraphLen: number\n\n const minGraphemes = this.options?.minGraphemes\n if (minGraphemes != null) {\n // Optimization: avoid counting graphemes if the length check already fails\n if (str.length < minGraphemes) {\n return ctx.issueTooSmall(str, 'grapheme', minGraphemes, str.length)\n } else if ((lazyGraphLen ??= graphemeLen(str)) < minGraphemes) {\n return ctx.issueTooSmall(str, 'grapheme', minGraphemes, lazyGraphLen)\n }\n }\n\n const maxGraphemes = this.options?.maxGraphemes\n if (maxGraphemes != null) {\n if ((lazyGraphLen ??= graphemeLen(str)) > maxGraphemes) {\n return ctx.issueTooBig(str, 'grapheme', maxGraphemes, lazyGraphLen)\n }\n }\n\n const format = this.options?.format\n if (format != null && !isStringFormat(str, format)) {\n return ctx.issueInvalidFormat(str, format)\n }\n\n return ctx.success(str)\n }\n}\n\nexport function coerceToString(input: unknown): string | null {\n switch (typeof input) {\n // @NOTE We do *not* coerce numbers/booleans to strings because that can\n // lead to them being accepted as string instead of being coerced to\n // number/boolean when the input is a string and the expected result is\n // number/boolean (e.g. in params).\n case 'string':\n return input\n case 'object': {\n if (input == null) return null\n\n // @NOTE Allow using TokenSchema instances in places expecting strings,\n // converting them to their string value.\n if (input instanceof TokenSchema) {\n return input.toString()\n }\n\n if (input instanceof Date) {\n if (Number.isNaN(input.getTime())) return null\n return input.toISOString()\n }\n\n if (input instanceof URL) {\n return input.toString()\n }\n\n const cid = ifCid(input)\n if (cid) return cid.toString()\n\n if (input instanceof String) {\n return input.valueOf()\n }\n }\n\n // falls through\n default:\n return null\n }\n}\n\n/**\n * Creates a string schema with optional format and length constraints.\n *\n * Strings can be validated against various formats (datetime, uri, did, handle, etc.)\n * and constrained by length in UTF-8 bytes or grapheme clusters.\n *\n * @param options - Optional configuration for format and length constraints\n * @returns A new {@link StringSchema} instance\n *\n * @example\n * ```ts\n * // Basic string\n * const nameSchema = l.string()\n *\n * // With format validation\n * const dateSchema = l.string({ format: 'datetime' })\n *\n * // With length constraints (UTF-8 bytes)\n * const bioSchema = l.string({ maxLength: 256 })\n *\n * // With grapheme constraints (user-perceived characters)\n * const displayNameSchema = l.string({ maxGraphemes: 64 })\n *\n * // Combining constraints\n * const handleSchema = l.string({ format: 'handle', minLength: 3, maxLength: 253 })\n * ```\n */\nexport const string = /*#__PURE__*/ memoizedOptions(function <\n const O extends StringSchemaOptions = NonNullable<unknown>,\n>(options?: StringSchemaOptions & O) {\n return new StringSchema<O>(options)\n})\n"]}
@@ -1,8 +1,41 @@
1
+ import { LexValue } from '@atproto/lex-data';
1
2
  import { Infer, NsidString, Schema } from '../core.js';
2
3
  import { ParamsSchema } from './params.js';
4
+ /**
5
+ * Infers the parameters type from a Subscription definition.
6
+ *
7
+ * @template S - The Subscription type
8
+ */
3
9
  export type InferSubscriptionParameters<S extends Subscription> = Infer<S['parameters']>;
10
+ /**
11
+ * Infers the message type from a Subscription definition.
12
+ *
13
+ * @template S - The Subscription type
14
+ */
4
15
  export type InferSubscriptionMessage<S extends Subscription> = Infer<S['message']>;
5
- export declare class Subscription<const TNsid extends NsidString = NsidString, const TParameters extends ParamsSchema = ParamsSchema, const TMessage extends Schema = Schema, const TErrors extends undefined | readonly string[] = undefined | readonly string[]> {
16
+ /**
17
+ * Represents a Lexicon subscription (WebSocket) endpoint definition.
18
+ *
19
+ * Subscriptions are real-time event streams delivered over WebSocket.
20
+ * They have parameters for initializing the connection and a message
21
+ * schema for validating incoming events.
22
+ *
23
+ * @template TNsid - The NSID identifying this subscription
24
+ * @template TParameters - The connection parameters schema type
25
+ * @template TMessage - The message schema type
26
+ * @template TErrors - Array of error type strings, or undefined
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const firehose = new Subscription(
31
+ * 'com.atproto.sync.subscribeRepos',
32
+ * l.params({ cursor: l.optional(l.integer()) }),
33
+ * repoEventSchema,
34
+ * ['FutureCursor']
35
+ * )
36
+ * ```
37
+ */
38
+ export declare class Subscription<const TNsid extends NsidString = NsidString, const TParameters extends ParamsSchema = ParamsSchema, const TMessage extends Schema<LexValue> = Schema<LexValue>, const TErrors extends undefined | readonly string[] = undefined | readonly string[]> {
6
39
  readonly nsid: TNsid;
7
40
  readonly parameters: TParameters;
8
41
  readonly message: TMessage;
@@ -10,5 +43,42 @@ export declare class Subscription<const TNsid extends NsidString = NsidString, c
10
43
  readonly type: "subscription";
11
44
  constructor(nsid: TNsid, parameters: TParameters, message: TMessage, errors: TErrors);
12
45
  }
13
- export declare function subscription<const N extends NsidString, const P extends ParamsSchema, const M extends Schema, const E extends undefined | readonly string[] = undefined>(nsid: N, parameters: P, message: M, errors?: E): Subscription<N, P, M, E>;
46
+ /**
47
+ * Creates a subscription definition for a Lexicon WebSocket endpoint.
48
+ *
49
+ * Subscriptions enable real-time event streaming. The connection is
50
+ * initialized with parameters, and the server sends messages matching
51
+ * the message schema.
52
+ *
53
+ * @param nsid - The NSID identifying this subscription endpoint
54
+ * @param parameters - Schema for connection parameters
55
+ * @param message - Schema for validating incoming messages
56
+ * @param errors - Optional array of error type strings
57
+ * @returns A new {@link Subscription} instance
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * // Repository event stream
62
+ * const subscribeRepos = l.subscription(
63
+ * 'com.atproto.sync.subscribeRepos',
64
+ * l.params({
65
+ * cursor: l.optional(l.integer()),
66
+ * }),
67
+ * l.typedUnion([
68
+ * l.typedRef(() => commitEventSchema),
69
+ * l.typedRef(() => handleEventSchema),
70
+ * l.typedRef(() => identityEventSchema),
71
+ * ], false),
72
+ * ['FutureCursor', 'ConsumerTooSlow'],
73
+ * )
74
+ *
75
+ * // Label stream
76
+ * const subscribeLabels = l.subscription(
77
+ * 'com.atproto.label.subscribeLabels',
78
+ * l.params({ cursor: l.optional(l.integer()) }),
79
+ * labelEventSchema,
80
+ * )
81
+ * ```
82
+ */
83
+ export declare function subscription<const N extends NsidString, const P extends ParamsSchema, const M extends Schema<LexValue>, const E extends undefined | readonly string[] = undefined>(nsid: N, parameters: P, message: M, errors?: E): Subscription<N, P, M, E>;
14
84
  //# sourceMappingURL=subscription.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../../src/schema/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,MAAM,MAAM,2BAA2B,CAAC,CAAC,SAAS,YAAY,IAAI,KAAK,CACrE,CAAC,CAAC,YAAY,CAAC,CAChB,CAAA;AAED,MAAM,MAAM,wBAAwB,CAAC,CAAC,SAAS,YAAY,IAAI,KAAK,CAClE,CAAC,CAAC,SAAS,CAAC,CACb,CAAA;AAED,qBAAa,YAAY,CACvB,KAAK,CAAC,KAAK,SAAS,UAAU,GAAG,UAAU,EAC3C,KAAK,CAAC,WAAW,SAAS,YAAY,GAAG,YAAY,EACrD,KAAK,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,EACtC,KAAK,CAAC,OAAO,SAAS,SAAS,GAAG,SAAS,MAAM,EAAE,GAC/C,SAAS,GACT,SAAS,MAAM,EAAE;IAKnB,QAAQ,CAAC,IAAI,EAAE,KAAK;IACpB,QAAQ,CAAC,UAAU,EAAE,WAAW;IAChC,QAAQ,CAAC,OAAO,EAAE,QAAQ;IAC1B,QAAQ,CAAC,MAAM,EAAE,OAAO;IAN1B,QAAQ,CAAC,IAAI,EAAG,cAAc,CAAS;gBAG5B,IAAI,EAAE,KAAK,EACX,UAAU,EAAE,WAAW,EACvB,OAAO,EAAE,QAAQ,EACjB,MAAM,EAAE,OAAO;CAE3B;AAGD,wBAAgB,YAAY,CAC1B,KAAK,CAAC,CAAC,SAAS,UAAU,EAC1B,KAAK,CAAC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IAAI,EAAG,cAAc,CAAS;gBAG5B,IAAI,EAAE,KAAK,EACX,UAAU,EAAE,WAAW,EACvB,OAAO,EAAE,QAAQ,EACjB,MAAM,EAAE,OAAO;CAE3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,wBAAgB,YAAY,CAC1B,KAAK,CAAC,CAAC,SAAS,UAAU,EAC1B,KAAK,CAAC,CAAC,SAAS,YAAY,EAC5B,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,QAAQ,CAAC,EAChC,KAAK,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,EACzD,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAE,CAAkB,4BAE/D"}
@@ -2,6 +2,28 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Subscription = void 0;
4
4
  exports.subscription = subscription;
5
+ /**
6
+ * Represents a Lexicon subscription (WebSocket) endpoint definition.
7
+ *
8
+ * Subscriptions are real-time event streams delivered over WebSocket.
9
+ * They have parameters for initializing the connection and a message
10
+ * schema for validating incoming events.
11
+ *
12
+ * @template TNsid - The NSID identifying this subscription
13
+ * @template TParameters - The connection parameters schema type
14
+ * @template TMessage - The message schema type
15
+ * @template TErrors - Array of error type strings, or undefined
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const firehose = new Subscription(
20
+ * 'com.atproto.sync.subscribeRepos',
21
+ * l.params({ cursor: l.optional(l.integer()) }),
22
+ * repoEventSchema,
23
+ * ['FutureCursor']
24
+ * )
25
+ * ```
26
+ */
5
27
  class Subscription {
6
28
  nsid;
7
29
  parameters;
@@ -16,6 +38,43 @@ class Subscription {
16
38
  }
17
39
  }
18
40
  exports.Subscription = Subscription;
41
+ /**
42
+ * Creates a subscription definition for a Lexicon WebSocket endpoint.
43
+ *
44
+ * Subscriptions enable real-time event streaming. The connection is
45
+ * initialized with parameters, and the server sends messages matching
46
+ * the message schema.
47
+ *
48
+ * @param nsid - The NSID identifying this subscription endpoint
49
+ * @param parameters - Schema for connection parameters
50
+ * @param message - Schema for validating incoming messages
51
+ * @param errors - Optional array of error type strings
52
+ * @returns A new {@link Subscription} instance
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * // Repository event stream
57
+ * const subscribeRepos = l.subscription(
58
+ * 'com.atproto.sync.subscribeRepos',
59
+ * l.params({
60
+ * cursor: l.optional(l.integer()),
61
+ * }),
62
+ * l.typedUnion([
63
+ * l.typedRef(() => commitEventSchema),
64
+ * l.typedRef(() => handleEventSchema),
65
+ * l.typedRef(() => identityEventSchema),
66
+ * ], false),
67
+ * ['FutureCursor', 'ConsumerTooSlow'],
68
+ * )
69
+ *
70
+ * // Label stream
71
+ * const subscribeLabels = l.subscription(
72
+ * 'com.atproto.label.subscribeLabels',
73
+ * l.params({ cursor: l.optional(l.integer()) }),
74
+ * labelEventSchema,
75
+ * )
76
+ * ```
77
+ */
19
78
  /*@__NO_SIDE_EFFECTS__*/
20
79
  function subscription(nsid, parameters, message, errors = undefined) {
21
80
  return new Subscription(nsid, parameters, message, errors);
@@ -1 +1 @@
1
- {"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../src/schema/subscription.ts"],"names":[],"mappings":";;;AA8BA,oCAOC;AA1BD,MAAa,YAAY;IAWZ;IACA;IACA;IACA;IANF,IAAI,GAAG,cAAuB,CAAA;IAEvC,YACW,IAAW,EACX,UAAuB,EACvB,OAAiB,EACjB,MAAe;QAHf,SAAI,GAAJ,IAAI,CAAO;QACX,eAAU,GAAV,UAAU,CAAa;QACvB,YAAO,GAAP,OAAO,CAAU;QACjB,WAAM,GAAN,MAAM,CAAS;IACvB,CAAC;CACL;AAhBD,oCAgBC;AAED,wBAAwB;AACxB,SAAgB,YAAY,CAK1B,IAAO,EAAE,UAAa,EAAE,OAAU,EAAE,SAAY,SAAc;IAC9D,OAAO,IAAI,YAAY,CAAa,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;AACxE,CAAC","sourcesContent":["import { Infer, NsidString, Schema } from '../core.js'\nimport { ParamsSchema } from './params.js'\n\nexport type InferSubscriptionParameters<S extends Subscription> = Infer<\n S['parameters']\n>\n\nexport type InferSubscriptionMessage<S extends Subscription> = Infer<\n S['message']\n>\n\nexport class Subscription<\n const TNsid extends NsidString = NsidString,\n const TParameters extends ParamsSchema = ParamsSchema,\n const TMessage extends Schema = Schema,\n const TErrors extends undefined | readonly string[] =\n | undefined\n | readonly string[],\n> {\n readonly type = 'subscription' as const\n\n constructor(\n readonly nsid: TNsid,\n readonly parameters: TParameters,\n readonly message: TMessage,\n readonly errors: TErrors,\n ) {}\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nexport function subscription<\n const N extends NsidString,\n const P extends ParamsSchema,\n const M extends Schema,\n const E extends undefined | readonly string[] = undefined,\n>(nsid: N, parameters: P, message: M, errors: E = undefined as E) {\n return new Subscription<N, P, M, E>(nsid, parameters, message, errors)\n}\n"]}
1
+ {"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../src/schema/subscription.ts"],"names":[],"mappings":";;;AAoGA,oCAOC;AArFD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,YAAY;IAWZ;IACA;IACA;IACA;IANF,IAAI,GAAG,cAAuB,CAAA;IAEvC,YACW,IAAW,EACX,UAAuB,EACvB,OAAiB,EACjB,MAAe;QAHf,SAAI,GAAJ,IAAI,CAAO;QACX,eAAU,GAAV,UAAU,CAAa;QACvB,YAAO,GAAP,OAAO,CAAU;QACjB,WAAM,GAAN,MAAM,CAAS;IACvB,CAAC;CACL;AAhBD,oCAgBC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAwB;AACxB,SAAgB,YAAY,CAK1B,IAAO,EAAE,UAAa,EAAE,OAAU,EAAE,SAAY,SAAc;IAC9D,OAAO,IAAI,YAAY,CAAa,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;AACxE,CAAC","sourcesContent":["import { LexValue } from '@atproto/lex-data'\nimport { Infer, NsidString, Schema } from '../core.js'\nimport { ParamsSchema } from './params.js'\n\n/**\n * Infers the parameters type from a Subscription definition.\n *\n * @template S - The Subscription type\n */\nexport type InferSubscriptionParameters<S extends Subscription> = Infer<\n S['parameters']\n>\n\n/**\n * Infers the message type from a Subscription definition.\n *\n * @template S - The Subscription type\n */\nexport type InferSubscriptionMessage<S extends Subscription> = Infer<\n S['message']\n>\n\n/**\n * Represents a Lexicon subscription (WebSocket) endpoint definition.\n *\n * Subscriptions are real-time event streams delivered over WebSocket.\n * They have parameters for initializing the connection and a message\n * schema for validating incoming events.\n *\n * @template TNsid - The NSID identifying this subscription\n * @template TParameters - The connection parameters schema type\n * @template TMessage - The message schema type\n * @template TErrors - Array of error type strings, or undefined\n *\n * @example\n * ```ts\n * const firehose = new Subscription(\n * 'com.atproto.sync.subscribeRepos',\n * l.params({ cursor: l.optional(l.integer()) }),\n * repoEventSchema,\n * ['FutureCursor']\n * )\n * ```\n */\nexport class Subscription<\n const TNsid extends NsidString = NsidString,\n const TParameters extends ParamsSchema = ParamsSchema,\n const TMessage extends Schema<LexValue> = Schema<LexValue>,\n const TErrors extends undefined | readonly string[] =\n | undefined\n | readonly string[],\n> {\n readonly type = 'subscription' as const\n\n constructor(\n readonly nsid: TNsid,\n readonly parameters: TParameters,\n readonly message: TMessage,\n readonly errors: TErrors,\n ) {}\n}\n\n/**\n * Creates a subscription definition for a Lexicon WebSocket endpoint.\n *\n * Subscriptions enable real-time event streaming. The connection is\n * initialized with parameters, and the server sends messages matching\n * the message schema.\n *\n * @param nsid - The NSID identifying this subscription endpoint\n * @param parameters - Schema for connection parameters\n * @param message - Schema for validating incoming messages\n * @param errors - Optional array of error type strings\n * @returns A new {@link Subscription} instance\n *\n * @example\n * ```ts\n * // Repository event stream\n * const subscribeRepos = l.subscription(\n * 'com.atproto.sync.subscribeRepos',\n * l.params({\n * cursor: l.optional(l.integer()),\n * }),\n * l.typedUnion([\n * l.typedRef(() => commitEventSchema),\n * l.typedRef(() => handleEventSchema),\n * l.typedRef(() => identityEventSchema),\n * ], false),\n * ['FutureCursor', 'ConsumerTooSlow'],\n * )\n *\n * // Label stream\n * const subscribeLabels = l.subscription(\n * 'com.atproto.label.subscribeLabels',\n * l.params({ cursor: l.optional(l.integer()) }),\n * labelEventSchema,\n * )\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function subscription<\n const N extends NsidString,\n const P extends ParamsSchema,\n const M extends Schema<LexValue>,\n const E extends undefined | readonly string[] = undefined,\n>(nsid: N, parameters: P, message: M, errors: E = undefined as E) {\n return new Subscription<N, P, M, E>(nsid, parameters, message, errors)\n}\n"]}
@@ -1,4 +1,19 @@
1
1
  import { NsidString, Schema, ValidationContext } from '../core.js';
2
+ /**
3
+ * Schema for Lexicon token values.
4
+ *
5
+ * Tokens are named constants in Lexicon, identified by their NSID and hash.
6
+ * They validate to their string value (e.g., 'app.bsky.feed.defs#requestLess').
7
+ * TokenSchema instances can also be used as values themselves.
8
+ *
9
+ * @template TValue - The token string literal type
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const schema = new TokenSchema('app.bsky.feed.defs#requestLess')
14
+ * schema.validate('app.bsky.feed.defs#requestLess') // success
15
+ * ```
16
+ */
2
17
  export declare class TokenSchema<const TValue extends string = string> extends Schema<TValue> {
3
18
  readonly value: TValue;
4
19
  constructor(value: TValue);
@@ -6,5 +21,37 @@ export declare class TokenSchema<const TValue extends string = string> extends S
6
21
  toJSON(): string;
7
22
  toString(): string;
8
23
  }
24
+ /**
25
+ * Creates a token schema for Lexicon named constants.
26
+ *
27
+ * Tokens are used in Lexicon as named constants or enum-like values.
28
+ * The token instance can be used both as a schema validator and as
29
+ * the token value itself (it serializes to its string value).
30
+ *
31
+ * @param nsid - The NSID part of the token
32
+ * @param hash - The hash part of the token (defaults to 'main')
33
+ * @returns A new {@link TokenSchema} instance
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * // Define tokens
38
+ * const requestLess = l.token('app.bsky.feed.defs', 'requestLess')
39
+ * const requestMore = l.token('app.bsky.feed.defs', 'requestMore')
40
+ *
41
+ * // Use as a value
42
+ * console.log(requestLess.toString()) // 'app.bsky.feed.defs#requestLess'
43
+ *
44
+ * // Use in union for validation
45
+ * const feedbackSchema = l.union([requestLess, requestMore])
46
+ *
47
+ * // Validate
48
+ * feedbackSchema.parse('app.bsky.feed.defs#requestLess') // success
49
+ *
50
+ * // Token instances can be used as values in other schemas
51
+ * const feedbackRequest = l.object({
52
+ * feedback: requestLess, // Accepts the token value
53
+ * })
54
+ * ```
55
+ */
9
56
  export declare function token<const N extends NsidString, const H extends string = 'main'>(nsid: N, hash?: H): TokenSchema<import("../core.js").$Type<N, H>>;
10
57
  //# sourceMappingURL=token.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/schema/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,UAAU,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEzE,qBAAa,WAAW,CACtB,KAAK,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,CACpC,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;IAqBxD,MAAM,IAAI,MAAM;IAIhB,QAAQ,IAAI,MAAM;CAGnB;AAGD,wBAAgB,KAAK,CACnB,KAAK,CAAC,CAAC,SAAS,UAAU,EAC1B,KAAK,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAC/B,IAAI,EAAE,CAAC,EAAE,IAAI,GAAE,CAAe,iDAE/B"}
1
+ {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/schema/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,UAAU,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEzE;;;;;;;;;;;;;;GAcG;AACH,qBAAa,WAAW,CACtB,KAAK,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,CACpC,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;IAqBxD,MAAM,IAAI,MAAM;IAIhB,QAAQ,IAAI,MAAM;CAGnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,wBAAgB,KAAK,CACnB,KAAK,CAAC,CAAC,SAAS,UAAU,EAC1B,KAAK,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAC/B,IAAI,EAAE,CAAC,EAAE,IAAI,GAAE,CAAe,iDAE/B"}
@@ -3,6 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TokenSchema = void 0;
4
4
  exports.token = token;
5
5
  const core_js_1 = require("../core.js");
6
+ /**
7
+ * Schema for Lexicon token values.
8
+ *
9
+ * Tokens are named constants in Lexicon, identified by their NSID and hash.
10
+ * They validate to their string value (e.g., 'app.bsky.feed.defs#requestLess').
11
+ * TokenSchema instances can also be used as values themselves.
12
+ *
13
+ * @template TValue - The token string literal type
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const schema = new TokenSchema('app.bsky.feed.defs#requestLess')
18
+ * schema.validate('app.bsky.feed.defs#requestLess') // success
19
+ * ```
20
+ */
6
21
  class TokenSchema extends core_js_1.Schema {
7
22
  value;
8
23
  constructor(value) {
@@ -33,6 +48,38 @@ class TokenSchema extends core_js_1.Schema {
33
48
  }
34
49
  }
35
50
  exports.TokenSchema = TokenSchema;
51
+ /**
52
+ * Creates a token schema for Lexicon named constants.
53
+ *
54
+ * Tokens are used in Lexicon as named constants or enum-like values.
55
+ * The token instance can be used both as a schema validator and as
56
+ * the token value itself (it serializes to its string value).
57
+ *
58
+ * @param nsid - The NSID part of the token
59
+ * @param hash - The hash part of the token (defaults to 'main')
60
+ * @returns A new {@link TokenSchema} instance
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * // Define tokens
65
+ * const requestLess = l.token('app.bsky.feed.defs', 'requestLess')
66
+ * const requestMore = l.token('app.bsky.feed.defs', 'requestMore')
67
+ *
68
+ * // Use as a value
69
+ * console.log(requestLess.toString()) // 'app.bsky.feed.defs#requestLess'
70
+ *
71
+ * // Use in union for validation
72
+ * const feedbackSchema = l.union([requestLess, requestMore])
73
+ *
74
+ * // Validate
75
+ * feedbackSchema.parse('app.bsky.feed.defs#requestLess') // success
76
+ *
77
+ * // Token instances can be used as values in other schemas
78
+ * const feedbackRequest = l.object({
79
+ * feedback: requestLess, // Accepts the token value
80
+ * })
81
+ * ```
82
+ */
36
83
  /*@__NO_SIDE_EFFECTS__*/
37
84
  function token(nsid, hash = 'main') {
38
85
  return new TokenSchema((0, core_js_1.$type)(nsid, hash));