@atproto/lex-schema 0.0.4 → 0.0.5

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 (109) hide show
  1. package/CHANGELOG.md +37 -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/result.d.ts +7 -6
  6. package/dist/core/result.d.ts.map +1 -1
  7. package/dist/core/result.js +9 -8
  8. package/dist/core/result.js.map +1 -1
  9. package/dist/core/string-format.d.ts +37 -26
  10. package/dist/core/string-format.d.ts.map +1 -1
  11. package/dist/core/string-format.js +66 -59
  12. package/dist/core/string-format.js.map +1 -1
  13. package/dist/core/types.d.ts +3 -0
  14. package/dist/core/types.d.ts.map +1 -1
  15. package/dist/core/types.js.map +1 -1
  16. package/dist/external.d.ts +7 -6
  17. package/dist/external.d.ts.map +1 -1
  18. package/dist/external.js +1 -0
  19. package/dist/external.js.map +1 -1
  20. package/dist/helpers.d.ts +36 -0
  21. package/dist/helpers.d.ts.map +1 -0
  22. package/dist/helpers.js +3 -0
  23. package/dist/helpers.js.map +1 -0
  24. package/dist/schema/blob.d.ts +1 -0
  25. package/dist/schema/blob.d.ts.map +1 -1
  26. package/dist/schema/blob.js +32 -18
  27. package/dist/schema/blob.js.map +1 -1
  28. package/dist/schema/custom.js +1 -1
  29. package/dist/schema/custom.js.map +1 -1
  30. package/dist/schema/integer.js +1 -1
  31. package/dist/schema/integer.js.map +1 -1
  32. package/dist/schema/params.d.ts +0 -1
  33. package/dist/schema/params.d.ts.map +1 -1
  34. package/dist/schema/params.js.map +1 -1
  35. package/dist/schema/payload.d.ts +17 -15
  36. package/dist/schema/payload.d.ts.map +1 -1
  37. package/dist/schema/payload.js +28 -0
  38. package/dist/schema/payload.js.map +1 -1
  39. package/dist/schema/procedure.d.ts +3 -6
  40. package/dist/schema/procedure.d.ts.map +1 -1
  41. package/dist/schema/procedure.js +1 -0
  42. package/dist/schema/procedure.js.map +1 -1
  43. package/dist/schema/query.d.ts +3 -5
  44. package/dist/schema/query.d.ts.map +1 -1
  45. package/dist/schema/query.js +1 -0
  46. package/dist/schema/query.js.map +1 -1
  47. package/dist/schema/record.d.ts +13 -12
  48. package/dist/schema/record.d.ts.map +1 -1
  49. package/dist/schema/record.js.map +1 -1
  50. package/dist/schema/refine.js +1 -1
  51. package/dist/schema/refine.js.map +1 -1
  52. package/dist/schema/subscription.d.ts +4 -7
  53. package/dist/schema/subscription.d.ts.map +1 -1
  54. package/dist/schema/subscription.js.map +1 -1
  55. package/dist/schema/typed-object.d.ts +7 -6
  56. package/dist/schema/typed-object.d.ts.map +1 -1
  57. package/dist/schema/typed-object.js.map +1 -1
  58. package/dist/schema/union.d.ts.map +1 -1
  59. package/dist/schema/union.js +1 -4
  60. package/dist/schema/union.js.map +1 -1
  61. package/dist/util/assertion-util.d.ts +8 -0
  62. package/dist/util/assertion-util.d.ts.map +1 -0
  63. package/dist/util/assertion-util.js +31 -0
  64. package/dist/util/assertion-util.js.map +1 -0
  65. package/dist/validation/schema.d.ts +21 -2
  66. package/dist/validation/schema.d.ts.map +1 -1
  67. package/dist/validation/schema.js +25 -2
  68. package/dist/validation/schema.js.map +1 -1
  69. package/dist/validation/validation-error.d.ts.map +1 -1
  70. package/dist/validation/validation-error.js +3 -3
  71. package/dist/validation/validation-error.js.map +1 -1
  72. package/dist/validation/validation-issue.js +10 -2
  73. package/dist/validation/validation-issue.js.map +1 -1
  74. package/dist/validation/validator.d.ts +4 -3
  75. package/dist/validation/validator.d.ts.map +1 -1
  76. package/dist/validation/validator.js +13 -10
  77. package/dist/validation/validator.js.map +1 -1
  78. package/package.json +2 -2
  79. package/src/core/$type.ts +4 -0
  80. package/src/core/result.ts +9 -8
  81. package/src/core/string-format.ts +88 -68
  82. package/src/core/types.ts +4 -0
  83. package/src/external.ts +9 -8
  84. package/src/helpers.test.ts +486 -0
  85. package/src/helpers.ts +61 -0
  86. package/src/schema/blob.test.ts +2 -4
  87. package/src/schema/blob.ts +31 -23
  88. package/src/schema/custom.test.ts +5 -5
  89. package/src/schema/custom.ts +1 -1
  90. package/src/schema/integer.ts +1 -1
  91. package/src/schema/params.ts +0 -7
  92. package/src/schema/payload.ts +67 -34
  93. package/src/schema/permission-set.test.ts +36 -36
  94. package/src/schema/procedure.test.ts +1 -62
  95. package/src/schema/procedure.ts +8 -20
  96. package/src/schema/query.test.ts +22 -69
  97. package/src/schema/query.ts +7 -14
  98. package/src/schema/record.ts +8 -4
  99. package/src/schema/refine.ts +1 -1
  100. package/src/schema/subscription.test.ts +30 -93
  101. package/src/schema/subscription.ts +11 -24
  102. package/src/schema/typed-object.ts +7 -3
  103. package/src/schema/union.ts +1 -4
  104. package/src/util/assertion-util.ts +40 -0
  105. package/src/validation/schema.ts +29 -4
  106. package/src/validation/validation-error.ts +4 -4
  107. package/src/validation/validation-issue.ts +12 -2
  108. package/src/validation/validator.ts +16 -12
  109. package/tsconfig.tests.json +1 -1
@@ -1,16 +1,16 @@
1
- import { asNsid } from '../core.js'
1
+ import { asNsidString } from '../core.js'
2
2
  import { IntegerSchema } from './integer.js'
3
3
  import { ObjectSchema } from './object.js'
4
4
  import { OptionalSchema } from './optional.js'
5
5
  import { ParamsSchema } from './params.js'
6
6
  import { Payload } from './payload.js'
7
- import { InferQueryOutputBody, InferQueryParameters, Query } from './query.js'
7
+ import { Query } from './query.js'
8
8
  import { StringSchema } from './string.js'
9
9
 
10
10
  describe('Query', () => {
11
11
  describe('constructor', () => {
12
12
  it('creates a Query instance with all parameters', () => {
13
- const nsid = asNsid('app.bsky.feed.getFeedSkeleton')
13
+ const nsid = asNsidString('app.bsky.feed.getFeedSkeleton')
14
14
  const parameters = new ParamsSchema({
15
15
  feed: new StringSchema({ format: 'at-uri' }),
16
16
  limit: new OptionalSchema(
@@ -35,7 +35,7 @@ describe('Query', () => {
35
35
  })
36
36
 
37
37
  it('creates a Query instance without errors', () => {
38
- const nsid = asNsid('app.bsky.feed.getFeedSkeleton')
38
+ const nsid = asNsidString('app.bsky.feed.getFeedSkeleton')
39
39
  const parameters = new ParamsSchema({
40
40
  feed: new StringSchema({ format: 'at-uri' }),
41
41
  })
@@ -56,7 +56,7 @@ describe('Query', () => {
56
56
  })
57
57
 
58
58
  it('creates a Query instance with empty parameters', () => {
59
- const nsid = asNsid('app.bsky.actor.getProfile')
59
+ const nsid = asNsidString('app.bsky.actor.getProfile')
60
60
  const parameters = new ParamsSchema({})
61
61
  const output = new Payload(
62
62
  'application/json',
@@ -74,7 +74,7 @@ describe('Query', () => {
74
74
 
75
75
  describe('properties', () => {
76
76
  it('has nsid property', () => {
77
- const nsid = asNsid('app.bsky.feed.getFeedSkeleton')
77
+ const nsid = asNsidString('app.bsky.feed.getFeedSkeleton')
78
78
  const parameters = new ParamsSchema({})
79
79
  const output = new Payload('application/json', undefined)
80
80
 
@@ -85,7 +85,7 @@ describe('Query', () => {
85
85
  })
86
86
 
87
87
  it('has parameters property', () => {
88
- const nsid = asNsid('app.bsky.feed.getFeedSkeleton')
88
+ const nsid = asNsidString('app.bsky.feed.getFeedSkeleton')
89
89
  const parameters = new ParamsSchema({
90
90
  feed: new StringSchema({ format: 'at-uri' }),
91
91
  })
@@ -98,7 +98,7 @@ describe('Query', () => {
98
98
  })
99
99
 
100
100
  it('has output property', () => {
101
- const nsid = asNsid('app.bsky.feed.getFeedSkeleton')
101
+ const nsid = asNsidString('app.bsky.feed.getFeedSkeleton')
102
102
  const parameters = new ParamsSchema({})
103
103
  const output = new Payload('application/json', undefined)
104
104
 
@@ -109,7 +109,7 @@ describe('Query', () => {
109
109
  })
110
110
 
111
111
  it('has errors property', () => {
112
- const nsid = asNsid('app.bsky.feed.getFeedSkeleton')
112
+ const nsid = asNsidString('app.bsky.feed.getFeedSkeleton')
113
113
  const parameters = new ParamsSchema({})
114
114
  const output = new Payload('application/json', undefined)
115
115
  const errors = ['NotFound', 'RateLimitExceeded'] as const
@@ -123,7 +123,7 @@ describe('Query', () => {
123
123
 
124
124
  describe('with complex parameters', () => {
125
125
  it('creates a Query with multiple parameter types', () => {
126
- const nsid = asNsid('app.bsky.feed.searchPosts')
126
+ const nsid = asNsidString('app.bsky.feed.searchPosts')
127
127
  const parameters = new ParamsSchema({
128
128
  q: new StringSchema({ minLength: 1 }),
129
129
  limit: new OptionalSchema(
@@ -151,7 +151,7 @@ describe('Query', () => {
151
151
 
152
152
  describe('with various output payloads', () => {
153
153
  it('creates a Query with undefined output payload', () => {
154
- const nsid = asNsid('app.bsky.actor.getProfile')
154
+ const nsid = asNsidString('app.bsky.actor.getProfile')
155
155
  const parameters = new ParamsSchema({
156
156
  actor: new StringSchema({ format: 'at-identifier' }),
157
157
  })
@@ -165,7 +165,7 @@ describe('Query', () => {
165
165
  })
166
166
 
167
167
  it('creates a Query with JSON payload', () => {
168
- const nsid = asNsid('app.bsky.actor.getProfile')
168
+ const nsid = asNsidString('app.bsky.actor.getProfile')
169
169
  const parameters = new ParamsSchema({
170
170
  actor: new StringSchema({ format: 'at-identifier' }),
171
171
  })
@@ -185,7 +185,7 @@ describe('Query', () => {
185
185
  })
186
186
 
187
187
  it('creates a Query with text payload', () => {
188
- const nsid = asNsid('app.bsky.feed.getPost')
188
+ const nsid = asNsidString('app.bsky.feed.getPost')
189
189
  const parameters = new ParamsSchema({
190
190
  uri: new StringSchema({ format: 'at-uri' }),
191
191
  })
@@ -200,7 +200,7 @@ describe('Query', () => {
200
200
 
201
201
  describe('with different error configurations', () => {
202
202
  it('creates a Query with a single error', () => {
203
- const nsid = asNsid('app.bsky.feed.getPost')
203
+ const nsid = asNsidString('app.bsky.feed.getPost')
204
204
  const parameters = new ParamsSchema({})
205
205
  const output = new Payload('application/json', undefined)
206
206
  const errors = ['NotFound'] as const
@@ -211,7 +211,7 @@ describe('Query', () => {
211
211
  })
212
212
 
213
213
  it('creates a Query with multiple errors', () => {
214
- const nsid = asNsid('app.bsky.feed.getPost')
214
+ const nsid = asNsidString('app.bsky.feed.getPost')
215
215
  const parameters = new ParamsSchema({})
216
216
  const output = new Payload('application/json', undefined)
217
217
  const errors = ['NotFound', 'Unauthorized', 'RateLimitExceeded'] as const
@@ -226,7 +226,7 @@ describe('Query', () => {
226
226
  })
227
227
 
228
228
  it('creates a Query with empty errors array', () => {
229
- const nsid = asNsid('app.bsky.feed.getPost')
229
+ const nsid = asNsidString('app.bsky.feed.getPost')
230
230
  const parameters = new ParamsSchema({})
231
231
  const output = new Payload('application/json', undefined)
232
232
  const errors = [] as const
@@ -237,56 +237,9 @@ describe('Query', () => {
237
237
  })
238
238
  })
239
239
 
240
- describe('type inference', () => {
241
- it('InferQueryParameters correctly infers parameter types', () => {
242
- const nsid = asNsid('app.bsky.feed.getFeedSkeleton')
243
- const parameters = new ParamsSchema({
244
- feed: new StringSchema({ format: 'at-uri' }),
245
- limit: new OptionalSchema(new IntegerSchema({})),
246
- })
247
- const output = new Payload('application/json', undefined)
248
-
249
- const query = new Query(nsid, parameters, output, undefined)
250
-
251
- type Params = InferQueryParameters<typeof query>
252
-
253
- // Type-level test - this should compile without errors
254
- const params: Params = {
255
- feed: 'at://did:plc:abc123/app.bsky.feed.post/xyz',
256
- limit: 50,
257
- }
258
-
259
- expect(params.feed).toBeDefined()
260
- })
261
-
262
- it('InferQueryOutputBody correctly infers output body type', () => {
263
- const nsid = asNsid('app.bsky.feed.getFeedSkeleton')
264
- const parameters = new ParamsSchema({})
265
- const output = new Payload(
266
- 'application/json',
267
- new ObjectSchema({
268
- cursor: new OptionalSchema(new StringSchema({})),
269
- feed: new StringSchema({ format: 'at-uri' }),
270
- }),
271
- )
272
-
273
- const query = new Query(nsid, parameters, output, undefined)
274
-
275
- type OutputBody = InferQueryOutputBody<typeof query>
276
-
277
- // Type-level test - this should compile without errors
278
- const outputBody: OutputBody = {
279
- cursor: 'abc123',
280
- feed: 'at://did:plc:abc123/app.bsky.feed.post/xyz',
281
- }
282
-
283
- expect(outputBody.feed).toBeDefined()
284
- })
285
- })
286
-
287
240
  describe('edge cases', () => {
288
241
  it('handles very long NSID', () => {
289
- const nsid = asNsid(
242
+ const nsid = asNsidString(
290
243
  'com.example.very.long.namespace.identifier.method.name',
291
244
  )
292
245
  const parameters = new ParamsSchema({})
@@ -298,7 +251,7 @@ describe('Query', () => {
298
251
  })
299
252
 
300
253
  it('handles query with all optional parameters', () => {
301
- const nsid = asNsid('app.bsky.feed.search')
254
+ const nsid = asNsidString('app.bsky.feed.search')
302
255
  const parameters = new ParamsSchema({
303
256
  q: new OptionalSchema(new StringSchema({})),
304
257
  limit: new OptionalSchema(new IntegerSchema({})),
@@ -312,7 +265,7 @@ describe('Query', () => {
312
265
  })
313
266
 
314
267
  it('handles query with complex nested output schema', () => {
315
- const nsid = asNsid('app.bsky.feed.getTimeline')
268
+ const nsid = asNsidString('app.bsky.feed.getTimeline')
316
269
  const parameters = new ParamsSchema({})
317
270
  const output = new Payload(
318
271
  'application/json',
@@ -335,7 +288,7 @@ describe('Query', () => {
335
288
 
336
289
  describe('real-world query examples', () => {
337
290
  it('creates a getFeedSkeleton query', () => {
338
- const nsid = asNsid('app.bsky.feed.getFeedSkeleton')
291
+ const nsid = asNsidString('app.bsky.feed.getFeedSkeleton')
339
292
  const parameters = new ParamsSchema({
340
293
  feed: new StringSchema({ format: 'at-uri' }),
341
294
  limit: new OptionalSchema(
@@ -357,7 +310,7 @@ describe('Query', () => {
357
310
  })
358
311
 
359
312
  it('creates a searchPosts query', () => {
360
- const nsid = asNsid('app.bsky.feed.searchPosts')
313
+ const nsid = asNsidString('app.bsky.feed.searchPosts')
361
314
  const parameters = new ParamsSchema({
362
315
  q: new StringSchema({ minLength: 1, maxLength: 300 }),
363
316
  limit: new OptionalSchema(
@@ -382,7 +335,7 @@ describe('Query', () => {
382
335
  })
383
336
 
384
337
  it('creates a getProfile query', () => {
385
- const nsid = asNsid('app.bsky.actor.getProfile')
338
+ const nsid = asNsidString('app.bsky.actor.getProfile')
386
339
  const parameters = new ParamsSchema({
387
340
  actor: new StringSchema({ format: 'at-identifier' }),
388
341
  })
@@ -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,
@@ -8,19 +8,20 @@ import {
8
8
  } from '../validation.js'
9
9
  import { LiteralSchema } from './literal.js'
10
10
  import { StringSchema } from './string.js'
11
+ import { TypedObject } from './typed-union.js'
11
12
 
12
13
  export type InferRecordKey<R extends RecordSchema> =
13
14
  R extends RecordSchema<infer K> ? RecordKeySchemaOutput<K> : never
14
15
 
15
16
  export type RecordSchemaOutput<
16
17
  T extends NsidString,
17
- S extends Validator<{ [_ in string]?: unknown }>,
18
- > = Simplify<Omit<Infer<S>, '$type'> & { $type: T }>
18
+ S extends Validator<{ [k: string]: unknown }>,
19
+ > = Simplify<{ $type: T } & Omit<Infer<S>, '$type'>>
19
20
 
20
21
  export class RecordSchema<
21
22
  K extends LexiconRecordKey = any,
22
23
  T extends NsidString = any,
23
- S extends Validator<{ [_ in string]?: unknown }> = any,
24
+ S extends Validator<{ [k: string]: unknown }> = any,
24
25
  > extends Schema<RecordSchemaOutput<T, S>> {
25
26
  keySchema: RecordKeySchema<K>
26
27
 
@@ -35,7 +36,10 @@ export class RecordSchema<
35
36
 
36
37
  isTypeOf<X extends { $type?: unknown }>(
37
38
  value: X,
38
- ): value is X extends { $type: T } ? X : X & { $type: T } {
39
+ ): value is Exclude<
40
+ X extends { $type?: T } ? X : X & { $type?: T },
41
+ TypedObject
42
+ > {
39
43
  return value.$type === this.$type
40
44
  }
41
45
 
@@ -78,7 +78,7 @@ function validateInContextUnbound<S extends Validator>(
78
78
  const checkResult = this.refinement.check.call(null, result.value, ctx)
79
79
  if (!checkResult) {
80
80
  const path = ctx.concatPath(this.refinement.path)
81
- return ctx.failure(new IssueCustom(path, input, this.refinement.message))
81
+ return ctx.issue(new IssueCustom(path, input, this.refinement.message))
82
82
  }
83
83
 
84
84
  return result
@@ -1,4 +1,4 @@
1
- import { asNsid } from '../core.js'
1
+ import { asNsidString } from '../core.js'
2
2
  import { IntegerSchema } from './integer.js'
3
3
  import { ObjectSchema } from './object.js'
4
4
  import { OptionalSchema } from './optional.js'
@@ -14,7 +14,7 @@ import {
14
14
  describe('Subscription', () => {
15
15
  describe('constructor', () => {
16
16
  it('creates a Subscription instance with all parameters', () => {
17
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
17
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
18
18
  const parameters = new ParamsSchema({
19
19
  cursor: new OptionalSchema(new IntegerSchema({})),
20
20
  })
@@ -34,7 +34,7 @@ describe('Subscription', () => {
34
34
  })
35
35
 
36
36
  it('creates a Subscription instance without errors', () => {
37
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
37
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
38
38
  const parameters = new ParamsSchema({
39
39
  cursor: new OptionalSchema(new IntegerSchema({})),
40
40
  })
@@ -57,7 +57,7 @@ describe('Subscription', () => {
57
57
  })
58
58
 
59
59
  it('creates a Subscription instance with empty parameters', () => {
60
- const nsid = asNsid('app.bsky.notification.subscribe')
60
+ const nsid = asNsidString('app.bsky.notification.subscribe')
61
61
  const parameters = new ParamsSchema({})
62
62
  const message = new ObjectSchema({
63
63
  type: new StringSchema({}),
@@ -73,26 +73,11 @@ describe('Subscription', () => {
73
73
  expect(subscription).toBeInstanceOf(Subscription)
74
74
  expect(subscription.parameters).toBe(parameters)
75
75
  })
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
76
  })
92
77
 
93
78
  describe('type property', () => {
94
79
  it('has type set to "subscription"', () => {
95
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
80
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
96
81
  const parameters = new ParamsSchema({})
97
82
  const message = new ObjectSchema({
98
83
  seq: new IntegerSchema({}),
@@ -109,7 +94,7 @@ describe('Subscription', () => {
109
94
  })
110
95
 
111
96
  it('type is a constant value', () => {
112
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
97
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
113
98
  const parameters = new ParamsSchema({})
114
99
  const message = new ObjectSchema({
115
100
  seq: new IntegerSchema({}),
@@ -130,7 +115,7 @@ describe('Subscription', () => {
130
115
 
131
116
  describe('properties', () => {
132
117
  it('has nsid property', () => {
133
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
118
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
134
119
  const parameters = new ParamsSchema({})
135
120
  const message = new ObjectSchema({
136
121
  seq: new IntegerSchema({}),
@@ -148,7 +133,7 @@ describe('Subscription', () => {
148
133
  })
149
134
 
150
135
  it('has parameters property', () => {
151
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
136
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
152
137
  const parameters = new ParamsSchema({})
153
138
  const message = new ObjectSchema({
154
139
  seq: new IntegerSchema({}),
@@ -166,7 +151,7 @@ describe('Subscription', () => {
166
151
  })
167
152
 
168
153
  it('has message property', () => {
169
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
154
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
170
155
  const parameters = new ParamsSchema({})
171
156
  const message = new ObjectSchema({
172
157
  seq: new IntegerSchema({}),
@@ -184,7 +169,7 @@ describe('Subscription', () => {
184
169
  })
185
170
 
186
171
  it('has errors property', () => {
187
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
172
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
188
173
  const parameters = new ParamsSchema({})
189
174
  const message = new ObjectSchema({
190
175
  seq: new IntegerSchema({}),
@@ -200,7 +185,7 @@ describe('Subscription', () => {
200
185
 
201
186
  describe('with complex parameters', () => {
202
187
  it('creates a Subscription with multiple parameter types', () => {
203
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
188
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
204
189
  const parameters = new ParamsSchema({
205
190
  cursor: new OptionalSchema(new IntegerSchema({ minimum: 0 })),
206
191
  includeDeletes: new OptionalSchema(
@@ -223,7 +208,7 @@ describe('Subscription', () => {
223
208
 
224
209
  describe('with various message types', () => {
225
210
  it('creates a Subscription with ObjectSchema message', () => {
226
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
211
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
227
212
  const parameters = new ParamsSchema({})
228
213
  const message = new ObjectSchema({
229
214
  seq: new IntegerSchema({}),
@@ -242,7 +227,7 @@ describe('Subscription', () => {
242
227
  })
243
228
 
244
229
  it('creates a Subscription with RefSchema message', () => {
245
- const nsid = asNsid('app.bsky.feed.subscribe')
230
+ const nsid = asNsidString('app.bsky.feed.subscribe')
246
231
  const parameters = new ParamsSchema({})
247
232
  const message = new RefSchema(() => new StringSchema({}))
248
233
 
@@ -256,26 +241,11 @@ describe('Subscription', () => {
256
241
  expect(subscription).toBeInstanceOf(Subscription)
257
242
  expect(subscription.message).toBeInstanceOf(RefSchema)
258
243
  })
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
244
  })
275
245
 
276
246
  describe('with different error configurations', () => {
277
247
  it('creates a Subscription with a single error', () => {
278
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
248
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
279
249
  const parameters = new ParamsSchema({})
280
250
  const message = new ObjectSchema({})
281
251
  const errors = ['ConsumerTooSlow'] as const
@@ -286,7 +256,7 @@ describe('Subscription', () => {
286
256
  })
287
257
 
288
258
  it('creates a Subscription with multiple errors', () => {
289
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
259
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
290
260
  const parameters = new ParamsSchema({})
291
261
  const message = new ObjectSchema({})
292
262
  const errors = [
@@ -305,7 +275,7 @@ describe('Subscription', () => {
305
275
  })
306
276
 
307
277
  it('creates a Subscription with empty errors array', () => {
308
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
278
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
309
279
  const parameters = new ParamsSchema({})
310
280
  const message = new ObjectSchema({})
311
281
  const errors = [] as const
@@ -318,7 +288,7 @@ describe('Subscription', () => {
318
288
 
319
289
  describe('type inference', () => {
320
290
  it('InferSubscriptionParameters correctly infers parameter types', () => {
321
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
291
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
322
292
  const parameters = new ParamsSchema({
323
293
  cursor: new OptionalSchema(new IntegerSchema({})),
324
294
  })
@@ -344,7 +314,7 @@ describe('Subscription', () => {
344
314
  })
345
315
 
346
316
  it('InferSubscriptionMessage correctly infers message type', () => {
347
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
317
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
348
318
  const parameters = new ParamsSchema({})
349
319
  const message = new ObjectSchema({
350
320
  seq: new IntegerSchema({}),
@@ -369,30 +339,11 @@ describe('Subscription', () => {
369
339
  expect(msg.seq).toBeDefined()
370
340
  expect(msg.data).toBeDefined()
371
341
  })
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
342
  })
392
343
 
393
344
  describe('edge cases', () => {
394
345
  it('handles very long NSID', () => {
395
- const nsid = asNsid(
346
+ const nsid = asNsidString(
396
347
  'com.example.very.long.namespace.identifier.subscription.name',
397
348
  )
398
349
  const parameters = new ParamsSchema({})
@@ -409,7 +360,7 @@ describe('Subscription', () => {
409
360
  })
410
361
 
411
362
  it('handles subscription with all optional parameters', () => {
412
- const nsid = asNsid('app.bsky.feed.subscribe')
363
+ const nsid = asNsidString('app.bsky.feed.subscribe')
413
364
  const parameters = new ParamsSchema({
414
365
  cursor: new OptionalSchema(new IntegerSchema({})),
415
366
  includeDeletes: new OptionalSchema(new IntegerSchema({})),
@@ -428,7 +379,7 @@ describe('Subscription', () => {
428
379
  })
429
380
 
430
381
  it('handles subscription with complex nested message schema', () => {
431
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
382
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
432
383
  const parameters = new ParamsSchema({})
433
384
  const message = new ObjectSchema({
434
385
  seq: new IntegerSchema({}),
@@ -454,7 +405,7 @@ describe('Subscription', () => {
454
405
 
455
406
  describe('real-world subscription examples', () => {
456
407
  it('creates a subscribeLabels subscription', () => {
457
- const nsid = asNsid('com.atproto.label.subscribeLabels')
408
+ const nsid = asNsidString('com.atproto.label.subscribeLabels')
458
409
  const parameters = new ParamsSchema({
459
410
  cursor: new OptionalSchema(new IntegerSchema({ minimum: 0 })),
460
411
  })
@@ -492,7 +443,7 @@ describe('Subscription', () => {
492
443
  })
493
444
 
494
445
  it('creates a notification subscription', () => {
495
- const nsid = asNsid('app.bsky.notification.subscribe')
446
+ const nsid = asNsidString('app.bsky.notification.subscribe')
496
447
  const parameters = new ParamsSchema({
497
448
  cursor: new OptionalSchema(new StringSchema({})),
498
449
  })
@@ -516,7 +467,7 @@ describe('Subscription', () => {
516
467
 
517
468
  describe('with mixed parameter and message types', () => {
518
469
  it('handles required and optional parameters with complex message', () => {
519
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
470
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
520
471
  const parameters = new ParamsSchema({
521
472
  cursor: new OptionalSchema(new IntegerSchema({ minimum: 0 })),
522
473
  includeDeletes: new OptionalSchema(
@@ -552,7 +503,7 @@ describe('Subscription', () => {
552
503
 
553
504
  describe('validation through nested schemas', () => {
554
505
  it('parameters can validate input through ParamsSchema', () => {
555
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
506
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
556
507
  const parameters = new ParamsSchema({
557
508
  cursor: new IntegerSchema({ minimum: 0 }),
558
509
  })
@@ -574,7 +525,7 @@ describe('Subscription', () => {
574
525
  })
575
526
 
576
527
  it('message can validate input through ObjectSchema', () => {
577
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
528
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
578
529
  const parameters = new ParamsSchema({})
579
530
  const message = new ObjectSchema({
580
531
  seq: new IntegerSchema({ minimum: 0 }),
@@ -605,7 +556,7 @@ describe('Subscription', () => {
605
556
 
606
557
  describe('property access', () => {
607
558
  it('can access nsid after construction', () => {
608
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
559
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
609
560
  const parameters = new ParamsSchema({})
610
561
  const message = new ObjectSchema({})
611
562
 
@@ -621,7 +572,7 @@ describe('Subscription', () => {
621
572
  })
622
573
 
623
574
  it('can access type after construction', () => {
624
- const nsid = asNsid('com.atproto.sync.subscribeRepos')
575
+ const nsid = asNsidString('com.atproto.sync.subscribeRepos')
625
576
  const parameters = new ParamsSchema({})
626
577
  const message = new ObjectSchema({})
627
578
 
@@ -639,7 +590,7 @@ describe('Subscription', () => {
639
590
 
640
591
  describe('different message schema types', () => {
641
592
  it('constructs with ObjectSchema message', () => {
642
- const nsid = asNsid('app.bsky.test')
593
+ const nsid = asNsidString('app.bsky.test')
643
594
  const parameters = new ParamsSchema({})
644
595
  const message = new ObjectSchema({
645
596
  field: new StringSchema({}),
@@ -657,7 +608,7 @@ describe('Subscription', () => {
657
608
  })
658
609
 
659
610
  it('constructs with RefSchema message', () => {
660
- const nsid = asNsid('app.bsky.test')
611
+ const nsid = asNsidString('app.bsky.test')
661
612
  const parameters = new ParamsSchema({})
662
613
  const message = new RefSchema(() => new ObjectSchema({}))
663
614
 
@@ -671,19 +622,5 @@ describe('Subscription', () => {
671
622
  expect(subscription.message).toBeInstanceOf(RefSchema)
672
623
  expect(subscription.message).toBe(message)
673
624
  })
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
625
  })
689
626
  })