@atproto/lex-schema 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/core/$type.d.ts +149 -0
  3. package/dist/core/$type.d.ts.map +1 -1
  4. package/dist/core/$type.js +44 -0
  5. package/dist/core/$type.js.map +1 -1
  6. package/dist/core/record-key.d.ts +44 -0
  7. package/dist/core/record-key.d.ts.map +1 -1
  8. package/dist/core/record-key.js +30 -0
  9. package/dist/core/record-key.js.map +1 -1
  10. package/dist/core/result.d.ts +85 -4
  11. package/dist/core/result.d.ts.map +1 -1
  12. package/dist/core/result.js +60 -4
  13. package/dist/core/result.js.map +1 -1
  14. package/dist/core/schema.d.ts +232 -5
  15. package/dist/core/schema.d.ts.map +1 -1
  16. package/dist/core/schema.js +197 -4
  17. package/dist/core/schema.js.map +1 -1
  18. package/dist/core/string-format.d.ts +244 -11
  19. package/dist/core/string-format.d.ts.map +1 -1
  20. package/dist/core/string-format.js +150 -0
  21. package/dist/core/string-format.js.map +1 -1
  22. package/dist/core/types.d.ts +90 -3
  23. package/dist/core/types.d.ts.map +1 -1
  24. package/dist/core/types.js.map +1 -1
  25. package/dist/core/validation-error.d.ts +60 -0
  26. package/dist/core/validation-error.d.ts.map +1 -1
  27. package/dist/core/validation-error.js +60 -0
  28. package/dist/core/validation-error.js.map +1 -1
  29. package/dist/core/validation-issue.d.ts +61 -0
  30. package/dist/core/validation-issue.d.ts.map +1 -1
  31. package/dist/core/validation-issue.js +54 -1
  32. package/dist/core/validation-issue.js.map +1 -1
  33. package/dist/core/validator.d.ts +356 -11
  34. package/dist/core/validator.d.ts.map +1 -1
  35. package/dist/core/validator.js +203 -4
  36. package/dist/core/validator.js.map +1 -1
  37. package/dist/helpers.d.ts +12 -28
  38. package/dist/helpers.d.ts.map +1 -1
  39. package/dist/helpers.js.map +1 -1
  40. package/dist/schema/array.d.ts +46 -0
  41. package/dist/schema/array.d.ts.map +1 -1
  42. package/dist/schema/array.js +16 -1
  43. package/dist/schema/array.js.map +1 -1
  44. package/dist/schema/blob.d.ts +50 -2
  45. package/dist/schema/blob.d.ts.map +1 -1
  46. package/dist/schema/blob.js +44 -2
  47. package/dist/schema/blob.js.map +1 -1
  48. package/dist/schema/boolean.d.ts +29 -0
  49. package/dist/schema/boolean.d.ts.map +1 -1
  50. package/dist/schema/boolean.js +30 -1
  51. package/dist/schema/boolean.js.map +1 -1
  52. package/dist/schema/bytes.d.ts +39 -0
  53. package/dist/schema/bytes.d.ts.map +1 -1
  54. package/dist/schema/bytes.js +34 -1
  55. package/dist/schema/bytes.js.map +1 -1
  56. package/dist/schema/cid.d.ts +39 -0
  57. package/dist/schema/cid.d.ts.map +1 -1
  58. package/dist/schema/cid.js +35 -1
  59. package/dist/schema/cid.js.map +1 -1
  60. package/dist/schema/custom.d.ts +67 -1
  61. package/dist/schema/custom.d.ts.map +1 -1
  62. package/dist/schema/custom.js +55 -0
  63. package/dist/schema/custom.js.map +1 -1
  64. package/dist/schema/dict.d.ts +45 -0
  65. package/dist/schema/dict.d.ts.map +1 -1
  66. package/dist/schema/dict.js +46 -1
  67. package/dist/schema/dict.js.map +1 -1
  68. package/dist/schema/discriminated-union.d.ts +59 -0
  69. package/dist/schema/discriminated-union.d.ts.map +1 -1
  70. package/dist/schema/discriminated-union.js +47 -1
  71. package/dist/schema/discriminated-union.js.map +1 -1
  72. package/dist/schema/enum.d.ts +49 -0
  73. package/dist/schema/enum.d.ts.map +1 -1
  74. package/dist/schema/enum.js +49 -0
  75. package/dist/schema/enum.js.map +1 -1
  76. package/dist/schema/integer.d.ts +43 -0
  77. package/dist/schema/integer.d.ts.map +1 -1
  78. package/dist/schema/integer.js +38 -1
  79. package/dist/schema/integer.js.map +1 -1
  80. package/dist/schema/intersection.d.ts +55 -0
  81. package/dist/schema/intersection.d.ts.map +1 -1
  82. package/dist/schema/intersection.js +50 -0
  83. package/dist/schema/intersection.js.map +1 -1
  84. package/dist/schema/lex-map.d.ts +37 -0
  85. package/dist/schema/lex-map.d.ts.map +1 -0
  86. package/dist/schema/lex-map.js +60 -0
  87. package/dist/schema/lex-map.js.map +1 -0
  88. package/dist/schema/lex-value.d.ts +35 -0
  89. package/dist/schema/lex-value.d.ts.map +1 -0
  90. package/dist/schema/lex-value.js +87 -0
  91. package/dist/schema/lex-value.js.map +1 -0
  92. package/dist/schema/literal.d.ts +45 -0
  93. package/dist/schema/literal.d.ts.map +1 -1
  94. package/dist/schema/literal.js +45 -0
  95. package/dist/schema/literal.js.map +1 -1
  96. package/dist/schema/never.d.ts +43 -0
  97. package/dist/schema/never.d.ts.map +1 -1
  98. package/dist/schema/never.js +44 -1
  99. package/dist/schema/never.js.map +1 -1
  100. package/dist/schema/null.d.ts +30 -0
  101. package/dist/schema/null.d.ts.map +1 -1
  102. package/dist/schema/null.js +31 -1
  103. package/dist/schema/null.js.map +1 -1
  104. package/dist/schema/nullable.d.ts +42 -0
  105. package/dist/schema/nullable.d.ts.map +1 -1
  106. package/dist/schema/nullable.js +42 -0
  107. package/dist/schema/nullable.js.map +1 -1
  108. package/dist/schema/object.d.ts +57 -0
  109. package/dist/schema/object.d.ts.map +1 -1
  110. package/dist/schema/object.js +53 -1
  111. package/dist/schema/object.js.map +1 -1
  112. package/dist/schema/optional.d.ts +43 -0
  113. package/dist/schema/optional.d.ts.map +1 -1
  114. package/dist/schema/optional.js +43 -0
  115. package/dist/schema/optional.js.map +1 -1
  116. package/dist/schema/params.d.ts +96 -12
  117. package/dist/schema/params.d.ts.map +1 -1
  118. package/dist/schema/params.js +155 -21
  119. package/dist/schema/params.js.map +1 -1
  120. package/dist/schema/payload.d.ts +111 -15
  121. package/dist/schema/payload.d.ts.map +1 -1
  122. package/dist/schema/payload.js +73 -3
  123. package/dist/schema/payload.js.map +1 -1
  124. package/dist/schema/permission-set.d.ts +58 -0
  125. package/dist/schema/permission-set.d.ts.map +1 -1
  126. package/dist/schema/permission-set.js +50 -0
  127. package/dist/schema/permission-set.js.map +1 -1
  128. package/dist/schema/permission.d.ts +42 -0
  129. package/dist/schema/permission.d.ts.map +1 -1
  130. package/dist/schema/permission.js +39 -0
  131. package/dist/schema/permission.js.map +1 -1
  132. package/dist/schema/procedure.d.ts +64 -0
  133. package/dist/schema/procedure.d.ts.map +1 -1
  134. package/dist/schema/procedure.js +64 -0
  135. package/dist/schema/procedure.js.map +1 -1
  136. package/dist/schema/query.d.ts +55 -0
  137. package/dist/schema/query.d.ts.map +1 -1
  138. package/dist/schema/query.js +55 -0
  139. package/dist/schema/query.js.map +1 -1
  140. package/dist/schema/record.d.ts +76 -25
  141. package/dist/schema/record.d.ts.map +1 -1
  142. package/dist/schema/record.js +21 -0
  143. package/dist/schema/record.js.map +1 -1
  144. package/dist/schema/ref.d.ts +51 -0
  145. package/dist/schema/ref.d.ts.map +1 -1
  146. package/dist/schema/ref.js +18 -0
  147. package/dist/schema/ref.js.map +1 -1
  148. package/dist/schema/refine.d.ts +58 -9
  149. package/dist/schema/refine.d.ts.map +1 -1
  150. package/dist/schema/refine.js.map +1 -1
  151. package/dist/schema/regexp.d.ts +45 -0
  152. package/dist/schema/regexp.d.ts.map +1 -1
  153. package/dist/schema/regexp.js +46 -1
  154. package/dist/schema/regexp.js.map +1 -1
  155. package/dist/schema/string.d.ts +72 -6
  156. package/dist/schema/string.d.ts.map +1 -1
  157. package/dist/schema/string.js +56 -8
  158. package/dist/schema/string.js.map +1 -1
  159. package/dist/schema/subscription.d.ts +72 -2
  160. package/dist/schema/subscription.d.ts.map +1 -1
  161. package/dist/schema/subscription.js +59 -0
  162. package/dist/schema/subscription.js.map +1 -1
  163. package/dist/schema/token.d.ts +48 -0
  164. package/dist/schema/token.d.ts.map +1 -1
  165. package/dist/schema/token.js +49 -1
  166. package/dist/schema/token.js.map +1 -1
  167. package/dist/schema/typed-object.d.ts +73 -23
  168. package/dist/schema/typed-object.d.ts.map +1 -1
  169. package/dist/schema/typed-object.js +20 -1
  170. package/dist/schema/typed-object.js.map +1 -1
  171. package/dist/schema/typed-ref.d.ts +54 -0
  172. package/dist/schema/typed-ref.d.ts.map +1 -1
  173. package/dist/schema/typed-ref.js +16 -0
  174. package/dist/schema/typed-ref.js.map +1 -1
  175. package/dist/schema/typed-union.d.ts +51 -1
  176. package/dist/schema/typed-union.d.ts.map +1 -1
  177. package/dist/schema/typed-union.js +52 -2
  178. package/dist/schema/typed-union.js.map +1 -1
  179. package/dist/schema/union.d.ts +46 -0
  180. package/dist/schema/union.d.ts.map +1 -1
  181. package/dist/schema/union.js +41 -0
  182. package/dist/schema/union.js.map +1 -1
  183. package/dist/schema/unknown.d.ts +34 -0
  184. package/dist/schema/unknown.d.ts.map +1 -1
  185. package/dist/schema/unknown.js +34 -0
  186. package/dist/schema/unknown.js.map +1 -1
  187. package/dist/schema/with-default.d.ts +45 -0
  188. package/dist/schema/with-default.d.ts.map +1 -1
  189. package/dist/schema/with-default.js +45 -0
  190. package/dist/schema/with-default.js.map +1 -1
  191. package/dist/schema.d.ts +2 -1
  192. package/dist/schema.d.ts.map +1 -1
  193. package/dist/schema.js +2 -1
  194. package/dist/schema.js.map +1 -1
  195. package/dist/util/if-any.d.ts +2 -0
  196. package/dist/util/if-any.d.ts.map +1 -0
  197. package/dist/util/if-any.js +3 -0
  198. package/dist/util/if-any.js.map +1 -0
  199. package/package.json +3 -3
  200. package/src/core/$type.ts +150 -18
  201. package/src/core/record-key.ts +44 -0
  202. package/src/core/result.ts +86 -4
  203. package/src/core/schema.ts +244 -9
  204. package/src/core/string-format.ts +259 -13
  205. package/src/core/types.ts +91 -3
  206. package/src/core/validation-error.ts +60 -0
  207. package/src/core/validation-issue.ts +68 -2
  208. package/src/core/validator.ts +373 -12
  209. package/src/helpers.test.ts +110 -29
  210. package/src/helpers.ts +54 -25
  211. package/src/schema/array.test.ts +94 -79
  212. package/src/schema/array.ts +48 -1
  213. package/src/schema/blob.ts +50 -1
  214. package/src/schema/boolean.ts +31 -1
  215. package/src/schema/bytes.ts +41 -1
  216. package/src/schema/cid.ts +41 -1
  217. package/src/schema/custom.ts +68 -1
  218. package/src/schema/dict.ts +47 -1
  219. package/src/schema/discriminated-union.ts +61 -1
  220. package/src/schema/enum.ts +50 -0
  221. package/src/schema/integer.ts +45 -1
  222. package/src/schema/intersection.ts +56 -0
  223. package/src/schema/{unknown-object.test.ts → lex-map.test.ts} +9 -9
  224. package/src/schema/lex-map.ts +63 -0
  225. package/src/schema/lex-value.test.ts +81 -0
  226. package/src/schema/lex-value.ts +86 -0
  227. package/src/schema/literal.ts +46 -0
  228. package/src/schema/never.ts +45 -1
  229. package/src/schema/null.ts +32 -1
  230. package/src/schema/nullable.ts +43 -0
  231. package/src/schema/object.ts +59 -1
  232. package/src/schema/optional.ts +44 -0
  233. package/src/schema/params.test.ts +133 -38
  234. package/src/schema/params.ts +237 -37
  235. package/src/schema/payload.test.ts +3 -3
  236. package/src/schema/payload.ts +145 -42
  237. package/src/schema/permission-set.ts +58 -0
  238. package/src/schema/permission.ts +42 -0
  239. package/src/schema/procedure.ts +64 -0
  240. package/src/schema/query.ts +55 -0
  241. package/src/schema/record.ts +82 -16
  242. package/src/schema/ref.ts +52 -0
  243. package/src/schema/refine.ts +58 -9
  244. package/src/schema/regexp.ts +47 -1
  245. package/src/schema/string.test.ts +99 -2
  246. package/src/schema/string.ts +108 -15
  247. package/src/schema/subscription.ts +72 -2
  248. package/src/schema/token.ts +50 -1
  249. package/src/schema/typed-object.ts +81 -16
  250. package/src/schema/typed-ref.ts +55 -0
  251. package/src/schema/typed-union.ts +58 -3
  252. package/src/schema/union.ts +47 -0
  253. package/src/schema/unknown.ts +35 -0
  254. package/src/schema/with-default.ts +46 -0
  255. package/src/schema.ts +2 -1
  256. package/src/util/if-any.ts +3 -0
  257. package/dist/schema/unknown-object.d.ts +0 -8
  258. package/dist/schema/unknown-object.d.ts.map +0 -1
  259. package/dist/schema/unknown-object.js +0 -19
  260. package/dist/schema/unknown-object.js.map +0 -1
  261. package/src/schema/unknown-object.ts +0 -19
@@ -38,9 +38,8 @@ describe('InferMethodParams', () => {
38
38
  const procedure = l.procedure(
39
39
  'com.example.list',
40
40
  l.params({ limit: l.string() }),
41
- l.payload(undefined, undefined),
42
- l.payload(undefined, undefined),
43
- undefined,
41
+ l.payload(),
42
+ l.payload(),
44
43
  )
45
44
 
46
45
  type Params = l.InferMethodParams<typeof procedure>
@@ -62,7 +61,7 @@ describe('InferMethodParams', () => {
62
61
  l.params({
63
62
  cursor: l.optional(l.integer()),
64
63
  }),
65
- l.unknown(),
64
+ l.lexMap(),
66
65
  )
67
66
 
68
67
  type Params = l.InferMethodParams<typeof subscription>
@@ -82,9 +81,8 @@ describe('InferMethodInput', () => {
82
81
  const procedure = l.procedure(
83
82
  'com.example.create',
84
83
  l.params(),
85
- l.payload('application/json', l.object({ text: l.string() })),
86
- l.payload(undefined, undefined),
87
- undefined,
84
+ l.jsonPayload({ text: l.string() }),
85
+ l.payload(),
88
86
  )
89
87
 
90
88
  type Input = l.InferMethodInput<typeof procedure, BinaryValue>
@@ -93,6 +91,8 @@ describe('InferMethodInput', () => {
93
91
  // @ts-expect-error
94
92
  expectType<Input>({ encoding: 'application/json', body: { text: 123 } })
95
93
  // @ts-expect-error
94
+ expectType<Input>({ encoding: 'text/plain', body: { text: 'hi' } })
95
+ // @ts-expect-error
96
96
  expectType<Input>({ encoding: 'text/plain', body: 'hello' })
97
97
  // @ts-expect-error
98
98
  expectType<Input>({ encoding: 'text/plain', body: new Uint8Array() })
@@ -105,8 +105,7 @@ describe('InferMethodInput', () => {
105
105
  'com.example.create',
106
106
  l.params(),
107
107
  l.payload('*/*', undefined),
108
- l.payload(undefined, undefined),
109
- undefined,
108
+ l.payload(),
110
109
  )
111
110
 
112
111
  type Input = l.InferMethodInput<typeof procedure, BinaryValue>
@@ -128,9 +127,8 @@ describe('InferMethodInputBody', () => {
128
127
  const procedure = l.procedure(
129
128
  'com.example.create',
130
129
  l.params(),
131
- l.payload('application/json', l.object({ text: l.string() })),
132
- l.payload(undefined, undefined),
133
- undefined,
130
+ l.jsonPayload({ text: l.string() }),
131
+ l.payload(),
134
132
  )
135
133
 
136
134
  type InputBody = l.InferMethodInputBody<typeof procedure, BinaryValue>
@@ -147,8 +145,7 @@ describe('InferMethodInputBody', () => {
147
145
  'com.example.upload',
148
146
  l.params(),
149
147
  l.payload('*/*', undefined),
150
- l.payload(undefined, undefined),
151
- undefined,
148
+ l.payload(),
152
149
  )
153
150
 
154
151
  type InputBody = l.InferMethodInputBody<typeof procedure, BinaryValue>
@@ -168,9 +165,8 @@ describe('InferMethodInputEncoding', () => {
168
165
  const procedure = l.procedure(
169
166
  'com.example.create',
170
167
  l.params(),
171
- l.payload('application/json', l.object({ text: l.string() })),
172
- l.payload(undefined, undefined),
173
- undefined,
168
+ l.jsonPayload({ text: l.string() }),
169
+ l.payload(),
174
170
  )
175
171
 
176
172
  type InputEncoding = l.InferMethodInputEncoding<typeof procedure>
@@ -187,8 +183,7 @@ describe('InferMethodInputEncoding', () => {
187
183
  'com.example.upload',
188
184
  l.params(),
189
185
  l.payload('*/*', undefined),
190
- l.payload(undefined, undefined),
191
- undefined,
186
+ l.payload(),
192
187
  )
193
188
 
194
189
  type InputEncoding = l.InferMethodInputEncoding<typeof procedure>
@@ -203,11 +198,42 @@ describe('InferMethodInputEncoding', () => {
203
198
 
204
199
  describe('InferMethodOutput', () => {
205
200
  describe('query', () => {
201
+ test('generic output', () => {
202
+ const query = l.query(
203
+ 'com.example.query',
204
+ l.params(),
205
+ l.payload(),
206
+ ) as unknown as l.Query
207
+ const unknownValue = {} as unknown
208
+ const lexValue = {} as l.LexValue
209
+
210
+ type Output = l.InferMethodOutput<typeof query, BinaryValue>
211
+
212
+ expectType<Output>(undefined)
213
+ expectType<Output>({ body: binaryValue, encoding: 'text/plain' })
214
+ expectType<Output>({ body: lexValue, encoding: 'application/json' })
215
+
216
+ expectType<Output>({
217
+ // @ts-expect-error
218
+ body: unknownValue,
219
+ encoding: 'application/octet-stream',
220
+ })
221
+
222
+ class Foo {
223
+ constructor(readonly field: number = 3) {}
224
+ }
225
+ expectType<Output>({
226
+ // @ts-expect-error
227
+ body: new Foo(),
228
+ encoding: 'application/octet-stream',
229
+ })
230
+ })
231
+
206
232
  test('with payload schema', () => {
207
233
  const query = l.query(
208
234
  'com.example.query',
209
235
  l.params(),
210
- l.payload('application/json', l.object({ items: l.array(l.string()) })),
236
+ l.jsonPayload({ items: l.array(l.string()) }),
211
237
  )
212
238
 
213
239
  type Output = l.InferMethodOutput<typeof query, BinaryValue>
@@ -237,11 +263,44 @@ describe('InferMethodOutput', () => {
237
263
  })
238
264
 
239
265
  describe('procedure', () => {
266
+ test('generic output', () => {
267
+ const procedure = l.procedure(
268
+ 'com.example.procedure',
269
+ l.params(),
270
+ l.payload(),
271
+ l.payload(),
272
+ ) as unknown as l.Procedure
273
+ const unknownValue = {} as unknown
274
+ const lexValue = {} as l.LexValue
275
+
276
+ type Output = l.InferMethodOutput<typeof procedure, BinaryValue>
277
+
278
+ expectType<Output>(undefined)
279
+ expectType<Output>({ body: binaryValue, encoding: 'text/plain' })
280
+ expectType<Output>({ body: lexValue, encoding: 'application/json' })
281
+ expectType<Output>({ body: { foo: 'bar' }, encoding: 'application/json' })
282
+
283
+ expectType<Output>({
284
+ // @ts-expect-error
285
+ body: unknownValue,
286
+ encoding: 'application/octet-stream',
287
+ })
288
+
289
+ class Foo {
290
+ constructor(readonly field: number = 3) {}
291
+ }
292
+ expectType<Output>({
293
+ // @ts-expect-error
294
+ body: new Foo(),
295
+ encoding: 'application/octet-stream',
296
+ })
297
+ })
298
+
240
299
  test('with payload schema', () => {
241
300
  const procedure = l.procedure(
242
301
  'com.example.create',
243
302
  l.params(),
244
- l.payload(undefined, undefined),
303
+ l.payload(),
245
304
  l.payload(
246
305
  'application/json',
247
306
  l.object({ uri: l.string({ format: 'at-uri' }) }),
@@ -267,7 +326,7 @@ describe('InferMethodOutput', () => {
267
326
  const procedure = l.procedure(
268
327
  'com.example.export',
269
328
  l.params(),
270
- l.payload(undefined, undefined),
329
+ l.payload(),
271
330
  l.payload('*/*', undefined),
272
331
  undefined,
273
332
  )
@@ -291,6 +350,27 @@ describe('InferMethodOutput', () => {
291
350
 
292
351
  describe('InferMethodOutputBody', () => {
293
352
  describe('query', () => {
353
+ test('generic output', () => {
354
+ const query = l.query(
355
+ 'com.example.query',
356
+ l.params(),
357
+ l.payload(),
358
+ ) as unknown as l.Query
359
+ const lexValue = {} as l.LexValue
360
+
361
+ type OutputBody = l.InferMethodOutputBody<typeof query, BinaryValue>
362
+
363
+ expectType<OutputBody>(undefined)
364
+ expectType<OutputBody>(binaryValue)
365
+ expectType<OutputBody>(lexValue)
366
+
367
+ class Foo {
368
+ constructor(readonly field: number = 3) {}
369
+ }
370
+ // @ts-expect-error
371
+ expectType<OutputBody>(new Foo())
372
+ })
373
+
294
374
  test('with payload schema', () => {
295
375
  const query = l.query(
296
376
  'com.example.query',
@@ -338,7 +418,7 @@ describe('InferMethodOutputBody', () => {
338
418
  const procedure = l.procedure(
339
419
  'com.example.get',
340
420
  l.params(),
341
- l.payload(undefined, undefined),
421
+ l.payload(),
342
422
  l.payload(
343
423
  'application/json',
344
424
  l.object({ uri: l.string({ format: 'at-uri' }) }),
@@ -359,7 +439,7 @@ describe('InferMethodOutputBody', () => {
359
439
  const procedure = l.procedure(
360
440
  'com.example.export',
361
441
  l.params(),
362
- l.payload(undefined, undefined),
442
+ l.payload(),
363
443
  l.payload('*/*', undefined),
364
444
  undefined,
365
445
  )
@@ -381,7 +461,7 @@ describe('InferMethodOutputEncoding', () => {
381
461
  const query = l.query(
382
462
  'com.example.query',
383
463
  l.params(),
384
- l.payload('application/json', l.object({ data: l.string() })),
464
+ l.jsonPayload({ data: l.string() }),
385
465
  )
386
466
 
387
467
  type OutputEncoding = l.InferMethodOutputEncoding<typeof query>
@@ -414,8 +494,8 @@ describe('InferMethodOutputEncoding', () => {
414
494
  const procedure = l.procedure(
415
495
  'com.example.create',
416
496
  l.params(),
417
- l.payload(undefined, undefined),
418
- l.payload('application/json', l.object({ id: l.string() })),
497
+ l.payload(),
498
+ l.jsonPayload({ id: l.string() }),
419
499
  undefined,
420
500
  )
421
501
 
@@ -432,7 +512,7 @@ describe('InferMethodOutputEncoding', () => {
432
512
  const procedure = l.procedure(
433
513
  'com.example.export',
434
514
  l.params(),
435
- l.payload(undefined, undefined),
515
+ l.payload(),
436
516
  l.payload('*/*', undefined),
437
517
  undefined,
438
518
  )
@@ -474,13 +554,14 @@ describe('InferMethodMessage', () => {
474
554
  const subscription = l.subscription(
475
555
  'com.example.subscribe',
476
556
  l.params(),
477
- l.unknown(),
557
+ l.integer(),
478
558
  )
479
559
 
480
560
  type Message = l.InferMethodMessage<typeof subscription>
481
561
 
482
562
  // @ts-expect-error "unknown" is turned into LexValue
483
563
  expectType<Message>(undefined)
564
+ // @ts-expect-error Not a LexValue
484
565
  expectType<Message>({ any: 'value' })
485
566
  expectType<Message>(123)
486
567
  })
package/src/helpers.ts CHANGED
@@ -1,10 +1,9 @@
1
- import { LexErrorData, LexValue } from '@atproto/lex-data'
1
+ import { LexErrorData } from '@atproto/lex-data'
2
2
  import { InferOutput, Restricted, Schema } from './core.js'
3
3
  import {
4
4
  InferPayload,
5
5
  InferPayloadBody,
6
6
  InferPayloadEncoding,
7
- Payload,
8
7
  Procedure,
9
8
  Query,
10
9
  Subscription,
@@ -27,51 +26,81 @@ export function getMain<T extends object>(ns: Main<T>): T {
27
26
  * `ReadableStream`, etc.). This type is a placeholder to represent binary data
28
27
  * when not explicitly provided.
29
28
  */
30
- type BinaryData = Restricted<'Binary data'>
29
+ export type BinaryData = Restricted<'Binary data'>
31
30
 
32
- export type InferMethodParams<M extends Procedure | Query | Subscription> =
33
- InferOutput<M['parameters']>
31
+ export type InferMethodParams<
32
+ M extends Procedure | Query | Subscription = Procedure | Query | Subscription,
33
+ > =
34
+ M extends Procedure<any, infer TParams, any, any, any>
35
+ ? InferOutput<TParams>
36
+ : M extends Query<any, infer TParams, any, any>
37
+ ? InferOutput<TParams>
38
+ : M extends Subscription<any, infer TParams, any, any>
39
+ ? InferOutput<TParams>
40
+ : never
34
41
 
35
42
  export type InferMethodInput<
36
- M extends Procedure | Query | Subscription,
43
+ M extends Procedure | Query | Subscription = Procedure | Query | Subscription,
37
44
  B = BinaryData,
38
- > = M extends { input: Payload } ? InferPayload<M['input'], B> : undefined
45
+ > =
46
+ M extends Procedure<any, any, infer TInput, any, any>
47
+ ? InferPayload<TInput, B>
48
+ : undefined
39
49
 
40
50
  export type InferMethodInputBody<
41
- M extends Procedure | Query | Subscription,
51
+ M extends Procedure | Query | Subscription = Procedure | Query | Subscription,
42
52
  B = BinaryData,
43
- > = M extends { input: Payload } ? InferPayloadBody<M['input'], B> : undefined
53
+ > =
54
+ M extends Procedure<any, any, infer TInput, any, any>
55
+ ? InferPayloadBody<TInput, B>
56
+ : undefined
44
57
 
45
58
  export type InferMethodInputEncoding<
46
- M extends Procedure | Query | Subscription,
47
- > = M extends { input: Payload } ? InferPayloadEncoding<M['input']> : undefined
59
+ M extends Procedure | Query | Subscription = Procedure | Query | Subscription,
60
+ > =
61
+ M extends Procedure<any, any, infer TInput, any, any>
62
+ ? InferPayloadEncoding<TInput>
63
+ : undefined
48
64
 
49
65
  export type InferMethodOutput<
50
- M extends Procedure | Query | Subscription,
66
+ M extends Procedure | Query | Subscription = Procedure | Query | Subscription,
51
67
  B = BinaryData,
52
- > = M extends { output: Payload } ? InferPayload<M['output'], B> : undefined
68
+ > =
69
+ M extends Procedure<any, any, any, infer TOutput, any>
70
+ ? InferPayload<TOutput, B>
71
+ : M extends Query<any, any, infer TOutput, any>
72
+ ? InferPayload<TOutput, B>
73
+ : undefined
53
74
 
54
75
  export type InferMethodOutputBody<
55
- M extends Procedure | Query | Subscription,
76
+ M extends Procedure | Query | Subscription = Procedure | Query | Subscription,
56
77
  B = BinaryData,
57
- > = M extends { output: Payload } ? InferPayloadBody<M['output'], B> : undefined
78
+ > =
79
+ M extends Procedure<any, any, any, infer TOutput, any>
80
+ ? InferPayloadBody<TOutput, B>
81
+ : M extends Query<any, any, infer TOutput, any>
82
+ ? InferPayloadBody<TOutput, B>
83
+ : undefined
58
84
 
59
85
  export type InferMethodOutputEncoding<
60
- M extends Procedure | Query | Subscription,
61
- > = M extends { output: Payload }
62
- ? InferPayloadEncoding<M['output']>
63
- : undefined
86
+ M extends Procedure | Query | Subscription = Procedure | Query | Subscription,
87
+ > =
88
+ M extends Procedure<any, any, any, infer TOutput, any>
89
+ ? InferPayloadEncoding<TOutput>
90
+ : M extends Query<any, any, infer TOutput, any>
91
+ ? InferPayloadEncoding<TOutput>
92
+ : undefined
64
93
 
65
94
  export type InferMethodMessage<
66
- //
67
- M extends Procedure | Query | Subscription,
68
- > = M extends { message: Schema }
69
- ? LexValue & InferOutput<M['message']>
70
- : undefined
95
+ M extends Procedure | Query | Subscription = Procedure | Query | Subscription,
96
+ > =
97
+ M extends Subscription<any, any, infer TMessage, any>
98
+ ? InferOutput<TMessage>
99
+ : undefined
71
100
 
72
101
  export type InferMethodError<
73
102
  //
74
- M extends Procedure | Query | Subscription,
103
+ M extends Procedure | Query | Subscription = Procedure | Query | Subscription,
75
104
  > = M extends { errors: readonly (infer E extends string)[] } ? E : never
76
105
 
77
106
  export const lexErrorDataSchema = object({