@atproto/lex-schema 0.0.4 → 0.0.6

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 (299) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/dist/core/$type.d.ts +7 -0
  3. package/dist/core/$type.d.ts.map +1 -1
  4. package/dist/core/$type.js.map +1 -1
  5. package/dist/core/property-key.d.ts.map +1 -0
  6. package/dist/core/property-key.js.map +1 -0
  7. package/dist/core/result.d.ts +7 -6
  8. package/dist/core/result.d.ts.map +1 -1
  9. package/dist/core/result.js +9 -8
  10. package/dist/core/result.js.map +1 -1
  11. package/dist/{validation → core}/schema.d.ts +21 -2
  12. package/dist/core/schema.d.ts.map +1 -0
  13. package/dist/{validation → core}/schema.js +25 -2
  14. package/dist/core/schema.js.map +1 -0
  15. package/dist/core/string-format.d.ts +37 -26
  16. package/dist/core/string-format.d.ts.map +1 -1
  17. package/dist/core/string-format.js +66 -59
  18. package/dist/core/string-format.js.map +1 -1
  19. package/dist/core/types.d.ts +3 -0
  20. package/dist/core/types.d.ts.map +1 -1
  21. package/dist/core/types.js.map +1 -1
  22. package/dist/core/validation-error.d.ts +19 -0
  23. package/dist/core/validation-error.d.ts.map +1 -0
  24. package/dist/{validation → core}/validation-error.js +13 -6
  25. package/dist/core/validation-error.js.map +1 -0
  26. package/dist/{validation → core}/validation-issue.d.ts +43 -0
  27. package/dist/core/validation-issue.d.ts.map +1 -0
  28. package/dist/{validation → core}/validation-issue.js +55 -2
  29. package/dist/core/validation-issue.js.map +1 -0
  30. package/dist/{validation → core}/validator.d.ts +5 -4
  31. package/dist/core/validator.d.ts.map +1 -0
  32. package/dist/{validation → core}/validator.js +16 -13
  33. package/dist/core/validator.js.map +1 -0
  34. package/dist/core.d.ts +5 -0
  35. package/dist/core.d.ts.map +1 -1
  36. package/dist/core.js +5 -0
  37. package/dist/core.js.map +1 -1
  38. package/dist/external.d.ts +21 -21
  39. package/dist/external.d.ts.map +1 -1
  40. package/dist/external.js +39 -55
  41. package/dist/external.js.map +1 -1
  42. package/dist/helpers.d.ts +41 -0
  43. package/dist/helpers.d.ts.map +1 -0
  44. package/dist/helpers.js +13 -0
  45. package/dist/helpers.js.map +1 -0
  46. package/dist/schema/_parameters.d.ts +1 -1
  47. package/dist/schema/_parameters.d.ts.map +1 -1
  48. package/dist/schema/_parameters.js.map +1 -1
  49. package/dist/schema/array.d.ts +1 -1
  50. package/dist/schema/array.d.ts.map +1 -1
  51. package/dist/schema/array.js +2 -2
  52. package/dist/schema/array.js.map +1 -1
  53. package/dist/schema/blob.d.ts +2 -1
  54. package/dist/schema/blob.d.ts.map +1 -1
  55. package/dist/schema/blob.js +34 -20
  56. package/dist/schema/blob.js.map +1 -1
  57. package/dist/schema/boolean.d.ts +1 -1
  58. package/dist/schema/boolean.d.ts.map +1 -1
  59. package/dist/schema/boolean.js +2 -2
  60. package/dist/schema/boolean.js.map +1 -1
  61. package/dist/schema/bytes.d.ts +1 -1
  62. package/dist/schema/bytes.d.ts.map +1 -1
  63. package/dist/schema/bytes.js +2 -2
  64. package/dist/schema/bytes.js.map +1 -1
  65. package/dist/schema/cid.d.ts +1 -1
  66. package/dist/schema/cid.d.ts.map +1 -1
  67. package/dist/schema/cid.js +2 -2
  68. package/dist/schema/cid.js.map +1 -1
  69. package/dist/schema/custom.d.ts +1 -1
  70. package/dist/schema/custom.d.ts.map +1 -1
  71. package/dist/schema/custom.js +3 -3
  72. package/dist/schema/custom.js.map +1 -1
  73. package/dist/schema/dict.d.ts +1 -1
  74. package/dist/schema/dict.d.ts.map +1 -1
  75. package/dist/schema/dict.js +2 -2
  76. package/dist/schema/dict.js.map +1 -1
  77. package/dist/schema/discriminated-union.d.ts +1 -1
  78. package/dist/schema/discriminated-union.d.ts.map +1 -1
  79. package/dist/schema/discriminated-union.js +2 -2
  80. package/dist/schema/discriminated-union.js.map +1 -1
  81. package/dist/schema/enum.d.ts +1 -1
  82. package/dist/schema/enum.d.ts.map +1 -1
  83. package/dist/schema/enum.js +2 -2
  84. package/dist/schema/enum.js.map +1 -1
  85. package/dist/schema/integer.d.ts +1 -1
  86. package/dist/schema/integer.d.ts.map +1 -1
  87. package/dist/schema/integer.js +4 -4
  88. package/dist/schema/integer.js.map +1 -1
  89. package/dist/schema/intersection.d.ts +1 -2
  90. package/dist/schema/intersection.d.ts.map +1 -1
  91. package/dist/schema/intersection.js +2 -2
  92. package/dist/schema/intersection.js.map +1 -1
  93. package/dist/schema/literal.d.ts +1 -1
  94. package/dist/schema/literal.d.ts.map +1 -1
  95. package/dist/schema/literal.js +2 -2
  96. package/dist/schema/literal.js.map +1 -1
  97. package/dist/schema/never.d.ts +1 -1
  98. package/dist/schema/never.d.ts.map +1 -1
  99. package/dist/schema/never.js +2 -2
  100. package/dist/schema/never.js.map +1 -1
  101. package/dist/schema/null.d.ts +1 -1
  102. package/dist/schema/null.d.ts.map +1 -1
  103. package/dist/schema/null.js +2 -2
  104. package/dist/schema/null.js.map +1 -1
  105. package/dist/schema/nullable.d.ts +1 -1
  106. package/dist/schema/nullable.d.ts.map +1 -1
  107. package/dist/schema/nullable.js +2 -2
  108. package/dist/schema/nullable.js.map +1 -1
  109. package/dist/schema/object.d.ts +1 -2
  110. package/dist/schema/object.d.ts.map +1 -1
  111. package/dist/schema/object.js +2 -2
  112. package/dist/schema/object.js.map +1 -1
  113. package/dist/schema/optional.d.ts +1 -1
  114. package/dist/schema/optional.d.ts.map +1 -1
  115. package/dist/schema/optional.js +2 -2
  116. package/dist/schema/optional.js.map +1 -1
  117. package/dist/schema/params.d.ts +1 -3
  118. package/dist/schema/params.d.ts.map +1 -1
  119. package/dist/schema/params.js +2 -2
  120. package/dist/schema/params.js.map +1 -1
  121. package/dist/schema/payload.d.ts +17 -15
  122. package/dist/schema/payload.d.ts.map +1 -1
  123. package/dist/schema/payload.js +28 -0
  124. package/dist/schema/payload.js.map +1 -1
  125. package/dist/schema/procedure.d.ts +3 -6
  126. package/dist/schema/procedure.d.ts.map +1 -1
  127. package/dist/schema/procedure.js +1 -0
  128. package/dist/schema/procedure.js.map +1 -1
  129. package/dist/schema/query.d.ts +3 -5
  130. package/dist/schema/query.d.ts.map +1 -1
  131. package/dist/schema/query.js +1 -0
  132. package/dist/schema/query.js.map +1 -1
  133. package/dist/schema/record.d.ts +14 -14
  134. package/dist/schema/record.d.ts.map +1 -1
  135. package/dist/schema/record.js +2 -2
  136. package/dist/schema/record.js.map +1 -1
  137. package/dist/schema/ref.d.ts +1 -1
  138. package/dist/schema/ref.d.ts.map +1 -1
  139. package/dist/schema/ref.js +2 -2
  140. package/dist/schema/ref.js.map +1 -1
  141. package/dist/schema/refine.d.ts +18 -1
  142. package/dist/schema/refine.d.ts.map +1 -1
  143. package/dist/schema/refine.js +2 -2
  144. package/dist/schema/refine.js.map +1 -1
  145. package/dist/schema/regexp.d.ts +1 -1
  146. package/dist/schema/regexp.d.ts.map +1 -1
  147. package/dist/schema/regexp.js +2 -2
  148. package/dist/schema/regexp.js.map +1 -1
  149. package/dist/schema/string.d.ts +1 -2
  150. package/dist/schema/string.d.ts.map +1 -1
  151. package/dist/schema/string.js +1 -2
  152. package/dist/schema/string.js.map +1 -1
  153. package/dist/schema/subscription.d.ts +4 -8
  154. package/dist/schema/subscription.d.ts.map +1 -1
  155. package/dist/schema/subscription.js.map +1 -1
  156. package/dist/schema/token.d.ts +1 -1
  157. package/dist/schema/token.d.ts.map +1 -1
  158. package/dist/schema/token.js +2 -2
  159. package/dist/schema/token.js.map +1 -1
  160. package/dist/schema/typed-object.d.ts +8 -8
  161. package/dist/schema/typed-object.d.ts.map +1 -1
  162. package/dist/schema/typed-object.js +2 -2
  163. package/dist/schema/typed-object.js.map +1 -1
  164. package/dist/schema/typed-ref.d.ts +1 -1
  165. package/dist/schema/typed-ref.d.ts.map +1 -1
  166. package/dist/schema/typed-ref.js +2 -2
  167. package/dist/schema/typed-ref.js.map +1 -1
  168. package/dist/schema/typed-union.d.ts +2 -3
  169. package/dist/schema/typed-union.d.ts.map +1 -1
  170. package/dist/schema/typed-union.js +2 -2
  171. package/dist/schema/typed-union.js.map +1 -1
  172. package/dist/schema/union.d.ts +1 -1
  173. package/dist/schema/union.d.ts.map +1 -1
  174. package/dist/schema/union.js +3 -6
  175. package/dist/schema/union.js.map +1 -1
  176. package/dist/schema/unknown-object.d.ts +1 -2
  177. package/dist/schema/unknown-object.d.ts.map +1 -1
  178. package/dist/schema/unknown-object.js +2 -2
  179. package/dist/schema/unknown-object.js.map +1 -1
  180. package/dist/schema/unknown.d.ts +1 -1
  181. package/dist/schema/unknown.d.ts.map +1 -1
  182. package/dist/schema/unknown.js +2 -2
  183. package/dist/schema/unknown.js.map +1 -1
  184. package/dist/util/assertion-util.d.ts +8 -0
  185. package/dist/util/assertion-util.d.ts.map +1 -0
  186. package/dist/util/assertion-util.js +31 -0
  187. package/dist/util/assertion-util.js.map +1 -0
  188. package/dist/util/memoize.d.ts +3 -0
  189. package/dist/util/memoize.d.ts.map +1 -0
  190. package/dist/util/memoize.js +52 -0
  191. package/dist/util/memoize.js.map +1 -0
  192. package/package.json +6 -6
  193. package/src/core/$type.ts +4 -0
  194. package/src/core/result.ts +9 -8
  195. package/src/{validation → core}/schema.ts +29 -4
  196. package/src/core/string-format.ts +88 -68
  197. package/src/core/types.ts +4 -0
  198. package/src/{validation → core}/validation-error.ts +14 -6
  199. package/src/{validation → core}/validation-issue.ts +64 -2
  200. package/src/{validation → core}/validator.ts +17 -13
  201. package/src/core.ts +5 -0
  202. package/src/external.ts +75 -55
  203. package/src/helpers.test.ts +487 -0
  204. package/src/helpers.ts +75 -0
  205. package/src/schema/_parameters.test.ts +1 -0
  206. package/src/schema/_parameters.ts +1 -1
  207. package/src/schema/array.test.ts +1 -0
  208. package/src/schema/array.ts +1 -1
  209. package/src/schema/blob.test.ts +3 -4
  210. package/src/schema/blob.ts +32 -24
  211. package/src/schema/boolean.test.ts +1 -0
  212. package/src/schema/boolean.ts +1 -1
  213. package/src/schema/bytes.test.ts +1 -0
  214. package/src/schema/bytes.ts +1 -1
  215. package/src/schema/cid.test.ts +1 -0
  216. package/src/schema/cid.ts +1 -1
  217. package/src/schema/custom.test.ts +8 -7
  218. package/src/schema/custom.ts +2 -2
  219. package/src/schema/dict.test.ts +1 -0
  220. package/src/schema/dict.ts +1 -1
  221. package/src/schema/discriminated-union.test.ts +1 -0
  222. package/src/schema/discriminated-union.ts +1 -1
  223. package/src/schema/enum.test.ts +1 -0
  224. package/src/schema/enum.ts +1 -1
  225. package/src/schema/integer.test.ts +1 -0
  226. package/src/schema/integer.ts +3 -3
  227. package/src/schema/intersection.test.ts +1 -0
  228. package/src/schema/intersection.ts +2 -2
  229. package/src/schema/literal.test.ts +1 -0
  230. package/src/schema/literal.ts +1 -1
  231. package/src/schema/never.test.ts +1 -0
  232. package/src/schema/never.ts +1 -1
  233. package/src/schema/null.test.ts +1 -0
  234. package/src/schema/null.ts +1 -1
  235. package/src/schema/nullable.test.ts +1 -0
  236. package/src/schema/nullable.ts +1 -1
  237. package/src/schema/object.test.ts +1 -0
  238. package/src/schema/object.ts +3 -3
  239. package/src/schema/optional.test.ts +1 -0
  240. package/src/schema/optional.ts +1 -1
  241. package/src/schema/params.test.ts +1 -0
  242. package/src/schema/params.ts +3 -10
  243. package/src/schema/payload.test.ts +1 -0
  244. package/src/schema/payload.ts +67 -34
  245. package/src/schema/permission-set.test.ts +37 -36
  246. package/src/schema/permission.test.ts +1 -0
  247. package/src/schema/procedure.test.ts +2 -62
  248. package/src/schema/procedure.ts +8 -20
  249. package/src/schema/query.test.ts +23 -69
  250. package/src/schema/query.ts +7 -14
  251. package/src/schema/record.test.ts +1 -0
  252. package/src/schema/record.ts +13 -6
  253. package/src/schema/ref.test.ts +2 -1
  254. package/src/schema/ref.ts +1 -1
  255. package/src/schema/refine.test.ts +1 -0
  256. package/src/schema/refine.ts +19 -2
  257. package/src/schema/regexp.test.ts +1 -0
  258. package/src/schema/regexp.ts +1 -1
  259. package/src/schema/string.test.ts +1 -0
  260. package/src/schema/string.ts +8 -2
  261. package/src/schema/subscription.test.ts +31 -93
  262. package/src/schema/subscription.ts +11 -25
  263. package/src/schema/token.test.ts +1 -0
  264. package/src/schema/token.ts +1 -1
  265. package/src/schema/typed-object.test.ts +1 -0
  266. package/src/schema/typed-object.ts +10 -5
  267. package/src/schema/typed-ref.test.ts +1 -0
  268. package/src/schema/typed-ref.ts +1 -1
  269. package/src/schema/typed-union.test.ts +1 -0
  270. package/src/schema/typed-union.ts +4 -4
  271. package/src/schema/union.test.ts +1 -0
  272. package/src/schema/union.ts +2 -5
  273. package/src/schema/unknown-object.test.ts +1 -0
  274. package/src/schema/unknown-object.ts +1 -2
  275. package/src/schema/unknown.test.ts +1 -0
  276. package/src/schema/unknown.ts +1 -1
  277. package/src/util/array-agg.test.ts +1 -0
  278. package/src/util/assertion-util.ts +40 -0
  279. package/src/util/memoize.ts +57 -0
  280. package/tsconfig.tests.json +2 -2
  281. package/dist/validation/property-key.d.ts.map +0 -1
  282. package/dist/validation/property-key.js.map +0 -1
  283. package/dist/validation/schema.d.ts.map +0 -1
  284. package/dist/validation/schema.js.map +0 -1
  285. package/dist/validation/validation-error.d.ts +0 -9
  286. package/dist/validation/validation-error.d.ts.map +0 -1
  287. package/dist/validation/validation-error.js.map +0 -1
  288. package/dist/validation/validation-issue.d.ts.map +0 -1
  289. package/dist/validation/validation-issue.js.map +0 -1
  290. package/dist/validation/validator.d.ts.map +0 -1
  291. package/dist/validation/validator.js.map +0 -1
  292. package/dist/validation.d.ts +0 -6
  293. package/dist/validation.d.ts.map +0 -1
  294. package/dist/validation.js +0 -9
  295. package/dist/validation.js.map +0 -1
  296. package/src/validation.ts +0 -5
  297. /package/dist/{validation → core}/property-key.d.ts +0 -0
  298. /package/dist/{validation → core}/property-key.js +0 -0
  299. /package/src/{validation → core}/property-key.ts +0 -0
@@ -1,22 +1,15 @@
1
1
  import { NsidString } from '../core.js'
2
- import { Infer } from '../validation.js'
3
2
  import { ParamsSchema } from './params.js'
4
- import { InferPayloadBody, Payload } from './payload.js'
5
-
6
- export type InferQueryParameters<Q extends Query> =
7
- Q extends Query<any, infer P extends ParamsSchema, any> ? Infer<P> : never
8
-
9
- export type InferQueryOutputBody<Q extends Query> =
10
- Q extends Query<any, any, infer O extends Payload>
11
- ? InferPayloadBody<O>
12
- : never
3
+ import { Payload } from './payload.js'
13
4
 
14
5
  export class Query<
15
- TNsid extends NsidString = any,
16
- TParameters extends ParamsSchema = any,
17
- TOutputPayload extends Payload = any,
18
- TErrors extends undefined | readonly string[] = any,
6
+ TNsid extends NsidString = NsidString,
7
+ TParameters extends ParamsSchema = ParamsSchema,
8
+ TOutputPayload extends Payload = Payload,
9
+ TErrors extends undefined | readonly string[] = undefined | readonly string[],
19
10
  > {
11
+ readonly type = 'query' as const
12
+
20
13
  constructor(
21
14
  readonly nsid: TNsid,
22
15
  readonly parameters: TParameters,
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest'
1
2
  import { ObjectSchema } from './object.js'
2
3
  import { RecordSchema } from './record.js'
3
4
  import { StringSchema } from './string.js'
@@ -1,26 +1,30 @@
1
- import { LexiconRecordKey, NsidString, Simplify, TidString } from '../core.js'
2
1
  import {
3
2
  Infer,
3
+ LexiconRecordKey,
4
+ NsidString,
4
5
  Schema,
6
+ Simplify,
7
+ TidString,
5
8
  ValidationResult,
6
9
  Validator,
7
10
  ValidatorContext,
8
- } from '../validation.js'
11
+ } from '../core.js'
9
12
  import { LiteralSchema } from './literal.js'
10
13
  import { StringSchema } from './string.js'
14
+ import { TypedObject } from './typed-union.js'
11
15
 
12
16
  export type InferRecordKey<R extends RecordSchema> =
13
17
  R extends RecordSchema<infer K> ? RecordKeySchemaOutput<K> : never
14
18
 
15
19
  export type RecordSchemaOutput<
16
20
  T extends NsidString,
17
- S extends Validator<{ [_ in string]?: unknown }>,
18
- > = Simplify<Omit<Infer<S>, '$type'> & { $type: T }>
21
+ S extends Validator<{ [k: string]: unknown }>,
22
+ > = Simplify<{ $type: T } & Omit<Infer<S>, '$type'>>
19
23
 
20
24
  export class RecordSchema<
21
25
  K extends LexiconRecordKey = any,
22
26
  T extends NsidString = any,
23
- S extends Validator<{ [_ in string]?: unknown }> = any,
27
+ S extends Validator<{ [k: string]: unknown }> = any,
24
28
  > extends Schema<RecordSchemaOutput<T, S>> {
25
29
  keySchema: RecordKeySchema<K>
26
30
 
@@ -35,7 +39,10 @@ export class RecordSchema<
35
39
 
36
40
  isTypeOf<X extends { $type?: unknown }>(
37
41
  value: X,
38
- ): value is X extends { $type: T } ? X : X & { $type: T } {
42
+ ): value is Exclude<
43
+ X extends { $type?: T } ? X : X & { $type?: T },
44
+ TypedObject
45
+ > {
39
46
  return value.$type === this.$type
40
47
  }
41
48
 
@@ -1,4 +1,5 @@
1
- import { Schema } from '../validation.js'
1
+ import { describe, expect, it } from 'vitest'
2
+ import { Schema } from '../core.js'
2
3
  import { IntegerSchema } from './integer.js'
3
4
  import { ObjectSchema } from './object.js'
4
5
  import { OptionalSchema } from './optional.js'
package/src/schema/ref.ts CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  ValidationResult,
4
4
  Validator,
5
5
  ValidatorContext,
6
- } from '../validation.js'
6
+ } from '../core.js'
7
7
 
8
8
  export type RefSchemaGetter<V> = () => Validator<V>
9
9
 
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest'
1
2
  import { IntegerSchema } from './integer.js'
2
3
  import { ObjectSchema } from './object.js'
3
4
  import { refine } from './refine.js'
@@ -5,7 +5,7 @@ import {
5
5
  ValidationResult,
6
6
  Validator,
7
7
  ValidatorContext,
8
- } from '../validation.js'
8
+ } from '../core.js'
9
9
  import { CustomAssertionContext } from './custom.js'
10
10
 
11
11
  export type RefinementCheck<T> = {
@@ -31,6 +31,23 @@ export type Refinement<T = any, Out extends T = T> =
31
31
  | RefinementCheck<T>
32
32
  | RefinementAssertion<T, Out>
33
33
 
34
+ /**
35
+ * Create a refined schema based on an existing schema and a refinement check.
36
+ *
37
+ * @param schema - The base schema to refine.
38
+ * @param refinement - The refinement check to apply.
39
+ * @returns A new schema that includes the refinement.
40
+ * @example
41
+ *
42
+ * ```ts
43
+ * const PositiveInt = refine(l.integer(), {
44
+ * check: (value) => value > 0,
45
+ * message: 'Value must be a positive integer',
46
+ * })
47
+ * const result = PositiveInt.validate(-5)
48
+ * // result.success === false
49
+ * ```
50
+ */
34
51
  export function refine<S extends Validator, Out extends Infer<S>>(
35
52
  schema: S,
36
53
  refinement: RefinementAssertion<Infer<S>, Out>,
@@ -78,7 +95,7 @@ function validateInContextUnbound<S extends Validator>(
78
95
  const checkResult = this.refinement.check.call(null, result.value, ctx)
79
96
  if (!checkResult) {
80
97
  const path = ctx.concatPath(this.refinement.path)
81
- return ctx.failure(new IssueCustom(path, input, this.refinement.message))
98
+ return ctx.issue(new IssueCustom(path, input, this.refinement.message))
82
99
  }
83
100
 
84
101
  return result
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest'
1
2
  import { RegexpSchema } from './regexp.js'
2
3
 
3
4
  describe('RegexpSchema', () => {
@@ -1,4 +1,4 @@
1
- import { Schema, ValidationResult, ValidatorContext } from '../validation'
1
+ import { Schema, ValidationResult, ValidatorContext } from '../core.js'
2
2
 
3
3
  export class RegexpSchema<T extends string> extends Schema<T> {
4
4
  constructor(public readonly pattern: RegExp) {
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest'
1
2
  import { StringSchema } from './string.js'
2
3
  import { TokenSchema } from './token.js'
3
4
 
@@ -1,6 +1,12 @@
1
1
  import { asCid, graphemeLen, utf8Len } from '@atproto/lex-data'
2
- import { InferStringFormat, StringFormat, assertStringFormat } from '../core.js'
3
- import { Schema, ValidationResult, ValidatorContext } from '../validation.js'
2
+ import {
3
+ InferStringFormat,
4
+ Schema,
5
+ StringFormat,
6
+ ValidationResult,
7
+ ValidatorContext,
8
+ assertStringFormat,
9
+ } from '../core.js'
4
10
  import { TokenSchema } from './token.js'
5
11
 
6
12
  export type StringSchemaOptions = {
@@ -1,4 +1,5 @@
1
- import { asNsid } from '../core.js'
1
+ import { describe, expect, it } from 'vitest'
2
+ import { asNsidString } from '../core.js'
2
3
  import { IntegerSchema } from './integer.js'
3
4
  import { ObjectSchema } from './object.js'
4
5
  import { OptionalSchema } from './optional.js'
@@ -14,7 +15,7 @@ import {
14
15
  describe('Subscription', () => {
15
16
  describe('constructor', () => {
16
17
  it('creates a Subscription instance with all parameters', () => {
17
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
18
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
18
19
  const parameters = new ParamsSchema({
19
20
  cursor: new OptionalSchema(new IntegerSchema({})),
20
21
  })
@@ -34,7 +35,7 @@ describe('Subscription', () => {
34
35
  })
35
36
 
36
37
  it('creates a Subscription instance without errors', () => {
37
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
38
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
38
39
  const parameters = new ParamsSchema({
39
40
  cursor: new OptionalSchema(new IntegerSchema({})),
40
41
  })
@@ -57,7 +58,7 @@ describe('Subscription', () => {
57
58
  })
58
59
 
59
60
  it('creates a Subscription instance with empty parameters', () => {
60
- const nsid = asNsid('app.bsky.notification.subscribe')
61
+ const nsid = asNsidString('app.bsky.notification.subscribe')
61
62
  const parameters = new ParamsSchema({})
62
63
  const message = new ObjectSchema({
63
64
  type: new StringSchema({}),
@@ -73,26 +74,11 @@ describe('Subscription', () => {
73
74
  expect(subscription).toBeInstanceOf(Subscription)
74
75
  expect(subscription.parameters).toBe(parameters)
75
76
  })
76
-
77
- it('creates a Subscription instance with undefined message', () => {
78
- const nsid = asNsid('app.bsky.feed.subscribe')
79
- const parameters = new ParamsSchema({})
80
-
81
- const subscription = new Subscription(
82
- nsid,
83
- parameters,
84
- undefined,
85
- undefined,
86
- )
87
-
88
- expect(subscription).toBeInstanceOf(Subscription)
89
- expect(subscription.message).toBeUndefined()
90
- })
91
77
  })
92
78
 
93
79
  describe('type property', () => {
94
80
  it('has type set to "subscription"', () => {
95
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
81
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
96
82
  const parameters = new ParamsSchema({})
97
83
  const message = new ObjectSchema({
98
84
  seq: new IntegerSchema({}),
@@ -109,7 +95,7 @@ describe('Subscription', () => {
109
95
  })
110
96
 
111
97
  it('type is a constant value', () => {
112
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
98
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
113
99
  const parameters = new ParamsSchema({})
114
100
  const message = new ObjectSchema({
115
101
  seq: new IntegerSchema({}),
@@ -130,7 +116,7 @@ describe('Subscription', () => {
130
116
 
131
117
  describe('properties', () => {
132
118
  it('has nsid property', () => {
133
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
119
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
134
120
  const parameters = new ParamsSchema({})
135
121
  const message = new ObjectSchema({
136
122
  seq: new IntegerSchema({}),
@@ -148,7 +134,7 @@ describe('Subscription', () => {
148
134
  })
149
135
 
150
136
  it('has parameters property', () => {
151
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
137
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
152
138
  const parameters = new ParamsSchema({})
153
139
  const message = new ObjectSchema({
154
140
  seq: new IntegerSchema({}),
@@ -166,7 +152,7 @@ describe('Subscription', () => {
166
152
  })
167
153
 
168
154
  it('has message property', () => {
169
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
155
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
170
156
  const parameters = new ParamsSchema({})
171
157
  const message = new ObjectSchema({
172
158
  seq: new IntegerSchema({}),
@@ -184,7 +170,7 @@ describe('Subscription', () => {
184
170
  })
185
171
 
186
172
  it('has errors property', () => {
187
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
173
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
188
174
  const parameters = new ParamsSchema({})
189
175
  const message = new ObjectSchema({
190
176
  seq: new IntegerSchema({}),
@@ -200,7 +186,7 @@ describe('Subscription', () => {
200
186
 
201
187
  describe('with complex parameters', () => {
202
188
  it('creates a Subscription with multiple parameter types', () => {
203
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
189
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
204
190
  const parameters = new ParamsSchema({
205
191
  cursor: new OptionalSchema(new IntegerSchema({ minimum: 0 })),
206
192
  includeDeletes: new OptionalSchema(
@@ -223,7 +209,7 @@ describe('Subscription', () => {
223
209
 
224
210
  describe('with various message types', () => {
225
211
  it('creates a Subscription with ObjectSchema message', () => {
226
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
212
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
227
213
  const parameters = new ParamsSchema({})
228
214
  const message = new ObjectSchema({
229
215
  seq: new IntegerSchema({}),
@@ -242,7 +228,7 @@ describe('Subscription', () => {
242
228
  })
243
229
 
244
230
  it('creates a Subscription with RefSchema message', () => {
245
- const nsid = asNsid('app.bsky.feed.subscribe')
231
+ const nsid = asNsidString('app.bsky.feed.subscribe')
246
232
  const parameters = new ParamsSchema({})
247
233
  const message = new RefSchema(() => new StringSchema({}))
248
234
 
@@ -256,26 +242,11 @@ describe('Subscription', () => {
256
242
  expect(subscription).toBeInstanceOf(Subscription)
257
243
  expect(subscription.message).toBeInstanceOf(RefSchema)
258
244
  })
259
-
260
- it('creates a Subscription with undefined message', () => {
261
- const nsid = asNsid('app.bsky.feed.subscribe')
262
- const parameters = new ParamsSchema({})
263
-
264
- const subscription = new Subscription(
265
- nsid,
266
- parameters,
267
- undefined,
268
- undefined,
269
- )
270
-
271
- expect(subscription).toBeInstanceOf(Subscription)
272
- expect(subscription.message).toBeUndefined()
273
- })
274
245
  })
275
246
 
276
247
  describe('with different error configurations', () => {
277
248
  it('creates a Subscription with a single error', () => {
278
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
249
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
279
250
  const parameters = new ParamsSchema({})
280
251
  const message = new ObjectSchema({})
281
252
  const errors = ['ConsumerTooSlow'] as const
@@ -286,7 +257,7 @@ describe('Subscription', () => {
286
257
  })
287
258
 
288
259
  it('creates a Subscription with multiple errors', () => {
289
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
260
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
290
261
  const parameters = new ParamsSchema({})
291
262
  const message = new ObjectSchema({})
292
263
  const errors = [
@@ -305,7 +276,7 @@ describe('Subscription', () => {
305
276
  })
306
277
 
307
278
  it('creates a Subscription with empty errors array', () => {
308
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
279
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
309
280
  const parameters = new ParamsSchema({})
310
281
  const message = new ObjectSchema({})
311
282
  const errors = [] as const
@@ -318,7 +289,7 @@ describe('Subscription', () => {
318
289
 
319
290
  describe('type inference', () => {
320
291
  it('InferSubscriptionParameters correctly infers parameter types', () => {
321
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
292
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
322
293
  const parameters = new ParamsSchema({
323
294
  cursor: new OptionalSchema(new IntegerSchema({})),
324
295
  })
@@ -344,7 +315,7 @@ describe('Subscription', () => {
344
315
  })
345
316
 
346
317
  it('InferSubscriptionMessage correctly infers message type', () => {
347
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
318
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
348
319
  const parameters = new ParamsSchema({})
349
320
  const message = new ObjectSchema({
350
321
  seq: new IntegerSchema({}),
@@ -369,30 +340,11 @@ describe('Subscription', () => {
369
340
  expect(msg.seq).toBeDefined()
370
341
  expect(msg.data).toBeDefined()
371
342
  })
372
-
373
- it('InferSubscriptionMessage returns unknown for undefined message', () => {
374
- const nsid = asNsid('app.bsky.feed.subscribe')
375
- const parameters = new ParamsSchema({})
376
-
377
- const subscription = new Subscription(
378
- nsid,
379
- parameters,
380
- undefined,
381
- undefined,
382
- )
383
-
384
- type Message = InferSubscriptionMessage<typeof subscription>
385
-
386
- // Type-level test - unknown should accept any value
387
- const msg: Message = { anything: 'value' }
388
-
389
- expect(msg).toBeDefined()
390
- })
391
343
  })
392
344
 
393
345
  describe('edge cases', () => {
394
346
  it('handles very long NSID', () => {
395
- const nsid = asNsid(
347
+ const nsid = asNsidString(
396
348
  'com.example.very.long.namespace.identifier.subscription.name',
397
349
  )
398
350
  const parameters = new ParamsSchema({})
@@ -409,7 +361,7 @@ describe('Subscription', () => {
409
361
  })
410
362
 
411
363
  it('handles subscription with all optional parameters', () => {
412
- const nsid = asNsid('app.bsky.feed.subscribe')
364
+ const nsid = asNsidString('app.bsky.feed.subscribe')
413
365
  const parameters = new ParamsSchema({
414
366
  cursor: new OptionalSchema(new IntegerSchema({})),
415
367
  includeDeletes: new OptionalSchema(new IntegerSchema({})),
@@ -428,7 +380,7 @@ describe('Subscription', () => {
428
380
  })
429
381
 
430
382
  it('handles subscription with complex nested message schema', () => {
431
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
383
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
432
384
  const parameters = new ParamsSchema({})
433
385
  const message = new ObjectSchema({
434
386
  seq: new IntegerSchema({}),
@@ -454,7 +406,7 @@ describe('Subscription', () => {
454
406
 
455
407
  describe('real-world subscription examples', () => {
456
408
  it('creates a subscribeLabels subscription', () => {
457
- const nsid = asNsid('com.atproto.label.subscribeLabels')
409
+ const nsid = asNsidString('com.atproto.label.subscribeLabels')
458
410
  const parameters = new ParamsSchema({
459
411
  cursor: new OptionalSchema(new IntegerSchema({ minimum: 0 })),
460
412
  })
@@ -492,7 +444,7 @@ describe('Subscription', () => {
492
444
  })
493
445
 
494
446
  it('creates a notification subscription', () => {
495
- const nsid = asNsid('app.bsky.notification.subscribe')
447
+ const nsid = asNsidString('app.bsky.notification.subscribe')
496
448
  const parameters = new ParamsSchema({
497
449
  cursor: new OptionalSchema(new StringSchema({})),
498
450
  })
@@ -516,7 +468,7 @@ describe('Subscription', () => {
516
468
 
517
469
  describe('with mixed parameter and message types', () => {
518
470
  it('handles required and optional parameters with complex message', () => {
519
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
471
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
520
472
  const parameters = new ParamsSchema({
521
473
  cursor: new OptionalSchema(new IntegerSchema({ minimum: 0 })),
522
474
  includeDeletes: new OptionalSchema(
@@ -552,7 +504,7 @@ describe('Subscription', () => {
552
504
 
553
505
  describe('validation through nested schemas', () => {
554
506
  it('parameters can validate input through ParamsSchema', () => {
555
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
507
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
556
508
  const parameters = new ParamsSchema({
557
509
  cursor: new IntegerSchema({ minimum: 0 }),
558
510
  })
@@ -574,7 +526,7 @@ describe('Subscription', () => {
574
526
  })
575
527
 
576
528
  it('message can validate input through ObjectSchema', () => {
577
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
529
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
578
530
  const parameters = new ParamsSchema({})
579
531
  const message = new ObjectSchema({
580
532
  seq: new IntegerSchema({ minimum: 0 }),
@@ -605,7 +557,7 @@ describe('Subscription', () => {
605
557
 
606
558
  describe('property access', () => {
607
559
  it('can access nsid after construction', () => {
608
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
560
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
609
561
  const parameters = new ParamsSchema({})
610
562
  const message = new ObjectSchema({})
611
563
 
@@ -621,7 +573,7 @@ describe('Subscription', () => {
621
573
  })
622
574
 
623
575
  it('can access type after construction', () => {
624
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
576
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
625
577
  const parameters = new ParamsSchema({})
626
578
  const message = new ObjectSchema({})
627
579
 
@@ -639,7 +591,7 @@ describe('Subscription', () => {
639
591
 
640
592
  describe('different message schema types', () => {
641
593
  it('constructs with ObjectSchema message', () => {
642
- const nsid = asNsid('app.bsky.test')
594
+ const nsid = asNsidString('app.bsky.test')
643
595
  const parameters = new ParamsSchema({})
644
596
  const message = new ObjectSchema({
645
597
  field: new StringSchema({}),
@@ -657,7 +609,7 @@ describe('Subscription', () => {
657
609
  })
658
610
 
659
611
  it('constructs with RefSchema message', () => {
660
- const nsid = asNsid('app.bsky.test')
612
+ const nsid = asNsidString('app.bsky.test')
661
613
  const parameters = new ParamsSchema({})
662
614
  const message = new RefSchema(() => new ObjectSchema({}))
663
615
 
@@ -671,19 +623,5 @@ describe('Subscription', () => {
671
623
  expect(subscription.message).toBeInstanceOf(RefSchema)
672
624
  expect(subscription.message).toBe(message)
673
625
  })
674
-
675
- it('constructs with undefined message', () => {
676
- const nsid = asNsid('app.bsky.test')
677
- const parameters = new ParamsSchema({})
678
-
679
- const subscription = new Subscription(
680
- nsid,
681
- parameters,
682
- undefined,
683
- undefined,
684
- )
685
-
686
- expect(subscription.message).toBeUndefined()
687
- })
688
626
  })
689
627
  })
@@ -1,33 +1,19 @@
1
- import { NsidString } from '../core.js'
2
- import { Infer } from '../validation.js'
3
- import { ObjectSchema } from './object.js'
1
+ import { Infer, NsidString, Schema } from '../core.js'
4
2
  import { ParamsSchema } from './params.js'
5
- import { RefSchema } from './ref.js'
6
- import { TypedUnionSchema } from './typed-union.js'
7
3
 
8
- export type InferSubscriptionParameters<S extends Subscription> =
9
- S extends Subscription<any, infer P extends ParamsSchema, any>
10
- ? Infer<P>
11
- : never
4
+ export type InferSubscriptionParameters<S extends Subscription> = Infer<
5
+ S['parameters']
6
+ >
12
7
 
13
- export type InferSubscriptionMessage<S extends Subscription> =
14
- S extends Subscription<
15
- any,
16
- any,
17
- infer M extends RefSchema | TypedUnionSchema | ObjectSchema
18
- >
19
- ? Infer<M>
20
- : unknown
8
+ export type InferSubscriptionMessage<S extends Subscription> = Infer<
9
+ S['message']
10
+ >
21
11
 
22
12
  export class Subscription<
23
- TNsid extends NsidString = any,
24
- TParameters extends ParamsSchema = any,
25
- TMessage extends
26
- | undefined
27
- | RefSchema
28
- | TypedUnionSchema
29
- | ObjectSchema = any,
30
- TErrors extends undefined | readonly string[] = any,
13
+ TNsid extends NsidString = NsidString,
14
+ TParameters extends ParamsSchema = ParamsSchema,
15
+ TMessage extends Schema = Schema,
16
+ TErrors extends undefined | readonly string[] = undefined | readonly string[],
31
17
  > {
32
18
  readonly type = 'subscription' as const
33
19
 
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest'
1
2
  import { TokenSchema } from './token.js'
2
3
 
3
4
  describe('TokenSchema', () => {
@@ -1,4 +1,4 @@
1
- import { Schema, ValidationResult, ValidatorContext } from '../validation.js'
1
+ import { Schema, ValidationResult, ValidatorContext } from '../core.js'
2
2
 
3
3
  export class TokenSchema<V extends string = any> extends Schema<V> {
4
4
  constructor(protected readonly value: V) {
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest'
1
2
  import { EnumSchema } from './enum.js'
2
3
  import { IntegerSchema } from './integer.js'
3
4
  import { NullableSchema } from './nullable.js'
@@ -1,21 +1,23 @@
1
1
  import { isPlainObject } from '@atproto/lex-data'
2
- import { $Type, Simplify } from '../core.js'
3
2
  import {
3
+ $Type,
4
4
  Infer,
5
5
  Schema,
6
+ Simplify,
6
7
  ValidationResult,
7
8
  Validator,
8
9
  ValidatorContext,
9
- } from '../validation.js'
10
+ } from '../core.js'
11
+ import { TypedObject } from './typed-union.js'
10
12
 
11
13
  export type TypedObjectSchemaOutput<
12
14
  T extends $Type,
13
- S extends Validator<{ [_ in string]?: unknown }>,
15
+ S extends Validator<{ [k: string]: unknown }>,
14
16
  > = Simplify<Infer<S> & { $type?: T }>
15
17
 
16
18
  export class TypedObjectSchema<
17
19
  const T extends $Type = any,
18
- const S extends Validator<{ [_ in string]?: unknown }> = any,
20
+ const S extends Validator<{ [k: string]: unknown }> = any,
19
21
  > extends Schema<TypedObjectSchemaOutput<T, S>> {
20
22
  constructor(
21
23
  readonly $type: T,
@@ -26,7 +28,10 @@ export class TypedObjectSchema<
26
28
 
27
29
  isTypeOf<X extends Record<string, unknown>>(
28
30
  value: X,
29
- ): value is X extends { $type?: T } ? X : X & { $type?: T } {
31
+ ): value is Exclude<
32
+ X extends { $type?: T } ? X : X & { $type?: T },
33
+ TypedObject
34
+ > {
30
35
  return value.$type === undefined || value.$type === this.$type
31
36
  }
32
37
 
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest'
1
2
  import { IntegerSchema } from './integer.js'
2
3
  import { ObjectSchema } from './object.js'
3
4
  import { StringSchema } from './string.js'
@@ -3,7 +3,7 @@ import {
3
3
  ValidationResult,
4
4
  Validator,
5
5
  ValidatorContext,
6
- } from '../validation.js'
6
+ } from '../core.js'
7
7
 
8
8
  // Basically a RecordSchema or TypedObjectSchema
9
9
  export type TypedRefSchemaValidator<V extends { $type?: string } = any> =
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest'
1
2
  import { IntegerSchema } from './integer.js'
2
3
  import { ObjectSchema } from './object.js'
3
4
  import { StringSchema } from './string.js'