@atproto/lex-schema 0.0.2 → 0.0.4
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.
- package/CHANGELOG.md +75 -0
- package/dist/core/$type.d.ts +6 -3
- package/dist/core/$type.d.ts.map +1 -1
- package/dist/core/$type.js +1 -0
- package/dist/core/$type.js.map +1 -1
- package/dist/core/record-key.d.ts +3 -3
- package/dist/core/record-key.d.ts.map +1 -1
- package/dist/core/record-key.js +12 -6
- package/dist/core/record-key.js.map +1 -1
- package/dist/core/result.d.ts.map +1 -1
- package/dist/core/result.js +6 -0
- package/dist/core/result.js.map +1 -1
- package/dist/core/string-format.d.ts +30 -27
- package/dist/core/string-format.d.ts.map +1 -1
- package/dist/core/string-format.js +56 -42
- package/dist/core/string-format.js.map +1 -1
- package/dist/core/types.d.ts +9 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/external.d.ts +31 -28
- package/dist/external.d.ts.map +1 -1
- package/dist/external.js +33 -17
- package/dist/external.js.map +1 -1
- package/dist/schema/_parameters.d.ts +2 -2
- package/dist/schema/_parameters.d.ts.map +1 -1
- package/dist/schema/array.d.ts +5 -6
- package/dist/schema/array.d.ts.map +1 -1
- package/dist/schema/array.js +5 -6
- package/dist/schema/array.js.map +1 -1
- package/dist/schema/blob.d.ts +2 -3
- package/dist/schema/blob.d.ts.map +1 -1
- package/dist/schema/blob.js +1 -2
- package/dist/schema/blob.js.map +1 -1
- package/dist/schema/boolean.d.ts +4 -5
- package/dist/schema/boolean.d.ts.map +1 -1
- package/dist/schema/boolean.js +2 -3
- package/dist/schema/boolean.js.map +1 -1
- package/dist/schema/bytes.d.ts +3 -4
- package/dist/schema/bytes.d.ts.map +1 -1
- package/dist/schema/bytes.js +2 -3
- package/dist/schema/bytes.js.map +1 -1
- package/dist/schema/cid.d.ts +13 -6
- package/dist/schema/cid.d.ts.map +1 -1
- package/dist/schema/cid.js +2 -4
- package/dist/schema/cid.js.map +1 -1
- package/dist/schema/custom.d.ts +3 -4
- package/dist/schema/custom.d.ts.map +1 -1
- package/dist/schema/custom.js +4 -3
- package/dist/schema/custom.js.map +1 -1
- package/dist/schema/dict.d.ts +3 -3
- package/dist/schema/dict.d.ts.map +1 -1
- package/dist/schema/dict.js +1 -1
- package/dist/schema/dict.js.map +1 -1
- package/dist/schema/discriminated-union.d.ts +15 -24
- package/dist/schema/discriminated-union.d.ts.map +1 -1
- package/dist/schema/discriminated-union.js +40 -64
- package/dist/schema/discriminated-union.js.map +1 -1
- package/dist/schema/enum.d.ts +8 -4
- package/dist/schema/enum.d.ts.map +1 -1
- package/dist/schema/enum.js +5 -3
- package/dist/schema/enum.js.map +1 -1
- package/dist/schema/integer.d.ts +3 -4
- package/dist/schema/integer.d.ts.map +1 -1
- package/dist/schema/integer.js +3 -4
- package/dist/schema/integer.js.map +1 -1
- package/dist/schema/intersection.d.ts +22 -14
- package/dist/schema/intersection.d.ts.map +1 -1
- package/dist/schema/intersection.js +12 -22
- package/dist/schema/intersection.js.map +1 -1
- package/dist/schema/literal.d.ts +7 -3
- package/dist/schema/literal.d.ts.map +1 -1
- package/dist/schema/literal.js +5 -3
- package/dist/schema/literal.js.map +1 -1
- package/dist/schema/never.d.ts +2 -2
- package/dist/schema/never.d.ts.map +1 -1
- package/dist/schema/never.js +1 -1
- package/dist/schema/never.js.map +1 -1
- package/dist/schema/null.d.ts +2 -3
- package/dist/schema/null.d.ts.map +1 -1
- package/dist/schema/null.js +1 -2
- package/dist/schema/null.js.map +1 -1
- package/dist/schema/nullable.d.ts +7 -0
- package/dist/schema/nullable.d.ts.map +1 -0
- package/dist/schema/nullable.js +19 -0
- package/dist/schema/nullable.js.map +1 -0
- package/dist/schema/object.d.ts +10 -44
- package/dist/schema/object.d.ts.map +1 -1
- package/dist/schema/object.js +10 -46
- package/dist/schema/object.js.map +1 -1
- package/dist/schema/optional.d.ts +7 -0
- package/dist/schema/optional.d.ts.map +1 -0
- package/dist/schema/optional.js +25 -0
- package/dist/schema/optional.js.map +1 -0
- package/dist/schema/params.d.ts +14 -19
- package/dist/schema/params.d.ts.map +1 -1
- package/dist/schema/params.js +10 -24
- package/dist/schema/params.js.map +1 -1
- package/dist/schema/payload.d.ts +4 -4
- package/dist/schema/payload.d.ts.map +1 -1
- package/dist/schema/payload.js.map +1 -1
- package/dist/schema/permission-set.d.ts +6 -6
- package/dist/schema/permission-set.d.ts.map +1 -1
- package/dist/schema/permission-set.js +1 -2
- package/dist/schema/permission-set.js.map +1 -1
- package/dist/schema/permission.d.ts +0 -1
- package/dist/schema/permission.d.ts.map +1 -1
- package/dist/schema/permission.js +0 -1
- package/dist/schema/permission.js.map +1 -1
- package/dist/schema/procedure.d.ts +8 -9
- package/dist/schema/procedure.d.ts.map +1 -1
- package/dist/schema/procedure.js +0 -1
- package/dist/schema/procedure.js.map +1 -1
- package/dist/schema/query.d.ts +7 -8
- package/dist/schema/query.d.ts.map +1 -1
- package/dist/schema/query.js +0 -1
- package/dist/schema/query.js.map +1 -1
- package/dist/schema/record.d.ts +34 -28
- package/dist/schema/record.d.ts.map +1 -1
- package/dist/schema/record.js +1 -2
- package/dist/schema/record.js.map +1 -1
- package/dist/schema/ref.d.ts +2 -3
- package/dist/schema/ref.d.ts.map +1 -1
- package/dist/schema/ref.js +1 -2
- package/dist/schema/ref.js.map +1 -1
- package/dist/schema/refine.d.ts +18 -0
- package/dist/schema/refine.d.ts.map +1 -0
- package/dist/schema/refine.js +33 -0
- package/dist/schema/refine.js.map +1 -0
- package/dist/schema/regexp.d.ts +7 -0
- package/dist/schema/regexp.d.ts.map +1 -0
- package/dist/schema/regexp.js +22 -0
- package/dist/schema/regexp.js.map +1 -0
- package/dist/schema/string.d.ts +4 -8
- package/dist/schema/string.d.ts.map +1 -1
- package/dist/schema/string.js +6 -3
- package/dist/schema/string.js.map +1 -1
- package/dist/schema/subscription.d.ts +7 -6
- package/dist/schema/subscription.d.ts.map +1 -1
- package/dist/schema/subscription.js.map +1 -1
- package/dist/schema/token.d.ts +2 -3
- package/dist/schema/token.d.ts.map +1 -1
- package/dist/schema/token.js +1 -2
- package/dist/schema/token.js.map +1 -1
- package/dist/schema/typed-object.d.ts +29 -27
- package/dist/schema/typed-object.d.ts.map +1 -1
- package/dist/schema/typed-object.js +1 -2
- package/dist/schema/typed-object.js.map +1 -1
- package/dist/schema/typed-ref.d.ts +2 -2
- package/dist/schema/typed-ref.d.ts.map +1 -1
- package/dist/schema/typed-ref.js +1 -1
- package/dist/schema/typed-ref.js.map +1 -1
- package/dist/schema/typed-union.d.ts +3 -4
- package/dist/schema/typed-union.d.ts.map +1 -1
- package/dist/schema/typed-union.js +3 -10
- package/dist/schema/typed-union.js.map +1 -1
- package/dist/schema/union.d.ts +2 -2
- package/dist/schema/union.d.ts.map +1 -1
- package/dist/schema/union.js +1 -1
- package/dist/schema/union.js.map +1 -1
- package/dist/schema/unknown-object.d.ts +2 -3
- package/dist/schema/unknown-object.d.ts.map +1 -1
- package/dist/schema/unknown-object.js +1 -2
- package/dist/schema/unknown-object.js.map +1 -1
- package/dist/schema/unknown.d.ts +2 -2
- package/dist/schema/unknown.d.ts.map +1 -1
- package/dist/schema/unknown.js +1 -1
- package/dist/schema/unknown.js.map +1 -1
- package/dist/schema.d.ts +4 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +6 -1
- package/dist/schema.js.map +1 -1
- package/dist/util/array-agg.d.ts.map +1 -1
- package/dist/util/array-agg.js +1 -0
- package/dist/util/array-agg.js.map +1 -1
- package/dist/util/lazy-property.d.ts +2 -0
- package/dist/util/lazy-property.d.ts.map +1 -0
- package/dist/util/lazy-property.js +14 -0
- package/dist/util/lazy-property.js.map +1 -0
- package/dist/validation/schema.d.ts +24 -0
- package/dist/validation/schema.d.ts.map +1 -0
- package/dist/validation/schema.js +57 -0
- package/dist/validation/schema.js.map +1 -0
- package/dist/validation/validation-error.d.ts +3 -3
- package/dist/validation/validation-error.d.ts.map +1 -1
- package/dist/validation/validation-error.js +32 -4
- package/dist/validation/validation-error.js.map +1 -1
- package/dist/validation/validation-issue.d.ts +32 -24
- package/dist/validation/validation-issue.d.ts.map +1 -1
- package/dist/validation/validation-issue.js +136 -92
- package/dist/validation/validation-issue.js.map +1 -1
- package/dist/validation/validator.d.ts +20 -50
- package/dist/validation/validator.d.ts.map +1 -1
- package/dist/validation/validator.js +40 -134
- package/dist/validation/validator.js.map +1 -1
- package/dist/validation.d.ts +1 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +1 -0
- package/dist/validation.js.map +1 -1
- package/package.json +8 -4
- package/src/core/$type.ts +7 -4
- package/src/core/record-key.ts +12 -5
- package/src/core/result.ts +6 -0
- package/src/core/string-format.ts +97 -61
- package/src/core/types.ts +12 -6
- package/src/external.ts +92 -70
- package/src/schema/_parameters.test.ts +416 -0
- package/src/schema/array.test.ts +237 -0
- package/src/schema/array.ts +17 -11
- package/src/schema/blob.test.ts +506 -0
- package/src/schema/blob.ts +3 -5
- package/src/schema/boolean.test.ts +116 -0
- package/src/schema/boolean.ts +5 -7
- package/src/schema/bytes.test.ts +226 -0
- package/src/schema/bytes.ts +4 -6
- package/src/schema/cid.test.ts +155 -0
- package/src/schema/cid.ts +14 -8
- package/src/schema/custom.test.ts +413 -0
- package/src/schema/custom.ts +10 -8
- package/src/schema/dict.test.ts +198 -0
- package/src/schema/dict.ts +6 -8
- package/src/schema/discriminated-union.test.ts +675 -0
- package/src/schema/discriminated-union.ts +68 -95
- package/src/schema/enum.test.ts +396 -0
- package/src/schema/enum.ts +12 -5
- package/src/schema/integer.test.ts +312 -0
- package/src/schema/integer.ts +5 -7
- package/src/schema/intersection.test.ts +32 -0
- package/src/schema/intersection.ts +37 -40
- package/src/schema/literal.test.ts +531 -0
- package/src/schema/literal.ts +12 -5
- package/src/schema/never.test.ts +174 -0
- package/src/schema/never.ts +3 -10
- package/src/schema/null.test.ts +79 -0
- package/src/schema/null.ts +3 -5
- package/src/schema/nullable.test.ts +480 -0
- package/src/schema/nullable.ts +23 -0
- package/src/schema/object.test.ts +47 -115
- package/src/schema/object.ts +19 -123
- package/src/schema/optional.test.ts +485 -0
- package/src/schema/optional.ts +31 -0
- package/src/schema/params.test.ts +582 -0
- package/src/schema/params.ts +37 -55
- package/src/schema/payload.test.ts +345 -0
- package/src/schema/payload.ts +5 -5
- package/src/schema/permission-set.test.ts +679 -0
- package/src/schema/permission-set.ts +6 -8
- package/src/schema/permission.test.ts +536 -0
- package/src/schema/permission.ts +0 -2
- package/src/schema/procedure.test.ts +443 -0
- package/src/schema/procedure.ts +11 -13
- package/src/schema/query.test.ts +408 -0
- package/src/schema/query.ts +9 -11
- package/src/schema/record.test.ts +694 -0
- package/src/schema/record.ts +38 -36
- package/src/schema/ref.test.ts +365 -0
- package/src/schema/ref.ts +8 -5
- package/src/schema/refine.test.ts +578 -0
- package/src/schema/refine.ts +85 -0
- package/src/schema/regexp.test.ts +580 -0
- package/src/schema/regexp.ts +22 -0
- package/src/schema/string.test.ts +612 -0
- package/src/schema/string.ts +11 -17
- package/src/schema/subscription.test.ts +689 -0
- package/src/schema/subscription.ts +13 -8
- package/src/schema/token.test.ts +428 -0
- package/src/schema/token.ts +3 -5
- package/src/schema/typed-object.test.ts +612 -0
- package/src/schema/typed-object.ts +23 -20
- package/src/schema/typed-ref.test.ts +823 -0
- package/src/schema/typed-ref.ts +10 -5
- package/src/schema/typed-union.test.ts +378 -0
- package/src/schema/typed-union.ts +6 -15
- package/src/schema/union.test.ts +200 -0
- package/src/schema/union.ts +5 -4
- package/src/schema/unknown-object.test.ts +592 -0
- package/src/schema/unknown-object.ts +3 -5
- package/src/schema/unknown.test.ts +312 -0
- package/src/schema/unknown.ts +3 -3
- package/src/schema.ts +7 -1
- package/src/util/array-agg.ts +1 -0
- package/src/util/lazy-property.ts +14 -0
- package/src/validation/schema.ts +92 -0
- package/src/validation/validation-error.ts +60 -9
- package/src/validation/validation-issue.ts +141 -144
- package/src/validation/validator.ts +67 -206
- package/src/validation.ts +1 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +7 -0
- package/tsconfig.tests.json +9 -0
|
@@ -0,0 +1,689 @@
|
|
|
1
|
+
import { asNsid } from '../core.js'
|
|
2
|
+
import { IntegerSchema } from './integer.js'
|
|
3
|
+
import { ObjectSchema } from './object.js'
|
|
4
|
+
import { OptionalSchema } from './optional.js'
|
|
5
|
+
import { ParamsSchema } from './params.js'
|
|
6
|
+
import { RefSchema } from './ref.js'
|
|
7
|
+
import { StringSchema } from './string.js'
|
|
8
|
+
import {
|
|
9
|
+
InferSubscriptionMessage,
|
|
10
|
+
InferSubscriptionParameters,
|
|
11
|
+
Subscription,
|
|
12
|
+
} from './subscription.js'
|
|
13
|
+
|
|
14
|
+
describe('Subscription', () => {
|
|
15
|
+
describe('constructor', () => {
|
|
16
|
+
it('creates a Subscription instance with all parameters', () => {
|
|
17
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
18
|
+
const parameters = new ParamsSchema({
|
|
19
|
+
cursor: new OptionalSchema(new IntegerSchema({})),
|
|
20
|
+
})
|
|
21
|
+
const message = new ObjectSchema({
|
|
22
|
+
seq: new IntegerSchema({}),
|
|
23
|
+
data: new StringSchema({}),
|
|
24
|
+
})
|
|
25
|
+
const errors = ['ConsumerTooSlow', 'FutureCursor'] as const
|
|
26
|
+
|
|
27
|
+
const subscription = new Subscription(nsid, parameters, message, errors)
|
|
28
|
+
|
|
29
|
+
expect(subscription).toBeInstanceOf(Subscription)
|
|
30
|
+
expect(subscription.nsid).toBe(nsid)
|
|
31
|
+
expect(subscription.parameters).toBe(parameters)
|
|
32
|
+
expect(subscription.message).toBe(message)
|
|
33
|
+
expect(subscription.errors).toBe(errors)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('creates a Subscription instance without errors', () => {
|
|
37
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
38
|
+
const parameters = new ParamsSchema({
|
|
39
|
+
cursor: new OptionalSchema(new IntegerSchema({})),
|
|
40
|
+
})
|
|
41
|
+
const message = new ObjectSchema({
|
|
42
|
+
seq: new IntegerSchema({}),
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const subscription = new Subscription(
|
|
46
|
+
nsid,
|
|
47
|
+
parameters,
|
|
48
|
+
message,
|
|
49
|
+
undefined,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
expect(subscription).toBeInstanceOf(Subscription)
|
|
53
|
+
expect(subscription.nsid).toBe(nsid)
|
|
54
|
+
expect(subscription.parameters).toBe(parameters)
|
|
55
|
+
expect(subscription.message).toBe(message)
|
|
56
|
+
expect(subscription.errors).toBeUndefined()
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('creates a Subscription instance with empty parameters', () => {
|
|
60
|
+
const nsid = asNsid('app.bsky.notification.subscribe')
|
|
61
|
+
const parameters = new ParamsSchema({})
|
|
62
|
+
const message = new ObjectSchema({
|
|
63
|
+
type: new StringSchema({}),
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
const subscription = new Subscription(
|
|
67
|
+
nsid,
|
|
68
|
+
parameters,
|
|
69
|
+
message,
|
|
70
|
+
undefined,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
expect(subscription).toBeInstanceOf(Subscription)
|
|
74
|
+
expect(subscription.parameters).toBe(parameters)
|
|
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
|
+
})
|
|
92
|
+
|
|
93
|
+
describe('type property', () => {
|
|
94
|
+
it('has type set to "subscription"', () => {
|
|
95
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
96
|
+
const parameters = new ParamsSchema({})
|
|
97
|
+
const message = new ObjectSchema({
|
|
98
|
+
seq: new IntegerSchema({}),
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const subscription = new Subscription(
|
|
102
|
+
nsid,
|
|
103
|
+
parameters,
|
|
104
|
+
message,
|
|
105
|
+
undefined,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
expect(subscription.type).toBe('subscription')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('type is a constant value', () => {
|
|
112
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
113
|
+
const parameters = new ParamsSchema({})
|
|
114
|
+
const message = new ObjectSchema({
|
|
115
|
+
seq: new IntegerSchema({}),
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
const subscription = new Subscription(
|
|
119
|
+
nsid,
|
|
120
|
+
parameters,
|
|
121
|
+
message,
|
|
122
|
+
undefined,
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
expect(subscription.type).toBe('subscription')
|
|
126
|
+
// TypeScript enforces readonly at compile time
|
|
127
|
+
expect(typeof subscription.type).toBe('string')
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
describe('properties', () => {
|
|
132
|
+
it('has nsid property', () => {
|
|
133
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
134
|
+
const parameters = new ParamsSchema({})
|
|
135
|
+
const message = new ObjectSchema({
|
|
136
|
+
seq: new IntegerSchema({}),
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
const subscription = new Subscription(
|
|
140
|
+
nsid,
|
|
141
|
+
parameters,
|
|
142
|
+
message,
|
|
143
|
+
undefined,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
expect(subscription.nsid).toBe(nsid)
|
|
147
|
+
expect(typeof subscription.nsid).toBe('string')
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('has parameters property', () => {
|
|
151
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
152
|
+
const parameters = new ParamsSchema({})
|
|
153
|
+
const message = new ObjectSchema({
|
|
154
|
+
seq: new IntegerSchema({}),
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const subscription = new Subscription(
|
|
158
|
+
nsid,
|
|
159
|
+
parameters,
|
|
160
|
+
message,
|
|
161
|
+
undefined,
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
expect(subscription.parameters).toBe(parameters)
|
|
165
|
+
expect(subscription.parameters).toBeInstanceOf(ParamsSchema)
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('has message property', () => {
|
|
169
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
170
|
+
const parameters = new ParamsSchema({})
|
|
171
|
+
const message = new ObjectSchema({
|
|
172
|
+
seq: new IntegerSchema({}),
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
const subscription = new Subscription(
|
|
176
|
+
nsid,
|
|
177
|
+
parameters,
|
|
178
|
+
message,
|
|
179
|
+
undefined,
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
expect(subscription.message).toBe(message)
|
|
183
|
+
expect(subscription.message).toBeInstanceOf(ObjectSchema)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
it('has errors property', () => {
|
|
187
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
188
|
+
const parameters = new ParamsSchema({})
|
|
189
|
+
const message = new ObjectSchema({
|
|
190
|
+
seq: new IntegerSchema({}),
|
|
191
|
+
})
|
|
192
|
+
const errors = ['ConsumerTooSlow'] as const
|
|
193
|
+
|
|
194
|
+
const subscription = new Subscription(nsid, parameters, message, errors)
|
|
195
|
+
|
|
196
|
+
expect(subscription.errors).toBe(errors)
|
|
197
|
+
expect(Array.isArray(subscription.errors)).toBe(true)
|
|
198
|
+
})
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
describe('with complex parameters', () => {
|
|
202
|
+
it('creates a Subscription with multiple parameter types', () => {
|
|
203
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
204
|
+
const parameters = new ParamsSchema({
|
|
205
|
+
cursor: new OptionalSchema(new IntegerSchema({ minimum: 0 })),
|
|
206
|
+
includeDeletes: new OptionalSchema(
|
|
207
|
+
new IntegerSchema({ minimum: 0, maximum: 1 }),
|
|
208
|
+
),
|
|
209
|
+
})
|
|
210
|
+
const message = new ObjectSchema({
|
|
211
|
+
seq: new IntegerSchema({}),
|
|
212
|
+
data: new StringSchema({}),
|
|
213
|
+
})
|
|
214
|
+
const errors = ['ConsumerTooSlow', 'FutureCursor'] as const
|
|
215
|
+
|
|
216
|
+
const subscription = new Subscription(nsid, parameters, message, errors)
|
|
217
|
+
|
|
218
|
+
expect(subscription).toBeInstanceOf(Subscription)
|
|
219
|
+
expect(subscription.parameters).toBe(parameters)
|
|
220
|
+
expect(subscription.errors).toEqual(['ConsumerTooSlow', 'FutureCursor'])
|
|
221
|
+
})
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
describe('with various message types', () => {
|
|
225
|
+
it('creates a Subscription with ObjectSchema message', () => {
|
|
226
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
227
|
+
const parameters = new ParamsSchema({})
|
|
228
|
+
const message = new ObjectSchema({
|
|
229
|
+
seq: new IntegerSchema({}),
|
|
230
|
+
data: new StringSchema({}),
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
const subscription = new Subscription(
|
|
234
|
+
nsid,
|
|
235
|
+
parameters,
|
|
236
|
+
message,
|
|
237
|
+
undefined,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
expect(subscription).toBeInstanceOf(Subscription)
|
|
241
|
+
expect(subscription.message).toBeInstanceOf(ObjectSchema)
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
it('creates a Subscription with RefSchema message', () => {
|
|
245
|
+
const nsid = asNsid('app.bsky.feed.subscribe')
|
|
246
|
+
const parameters = new ParamsSchema({})
|
|
247
|
+
const message = new RefSchema(() => new StringSchema({}))
|
|
248
|
+
|
|
249
|
+
const subscription = new Subscription(
|
|
250
|
+
nsid,
|
|
251
|
+
parameters,
|
|
252
|
+
message,
|
|
253
|
+
undefined,
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
expect(subscription).toBeInstanceOf(Subscription)
|
|
257
|
+
expect(subscription.message).toBeInstanceOf(RefSchema)
|
|
258
|
+
})
|
|
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
|
+
})
|
|
275
|
+
|
|
276
|
+
describe('with different error configurations', () => {
|
|
277
|
+
it('creates a Subscription with a single error', () => {
|
|
278
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
279
|
+
const parameters = new ParamsSchema({})
|
|
280
|
+
const message = new ObjectSchema({})
|
|
281
|
+
const errors = ['ConsumerTooSlow'] as const
|
|
282
|
+
|
|
283
|
+
const subscription = new Subscription(nsid, parameters, message, errors)
|
|
284
|
+
|
|
285
|
+
expect(subscription.errors).toEqual(['ConsumerTooSlow'])
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
it('creates a Subscription with multiple errors', () => {
|
|
289
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
290
|
+
const parameters = new ParamsSchema({})
|
|
291
|
+
const message = new ObjectSchema({})
|
|
292
|
+
const errors = [
|
|
293
|
+
'ConsumerTooSlow',
|
|
294
|
+
'FutureCursor',
|
|
295
|
+
'InvalidCursor',
|
|
296
|
+
] as const
|
|
297
|
+
|
|
298
|
+
const subscription = new Subscription(nsid, parameters, message, errors)
|
|
299
|
+
|
|
300
|
+
expect(subscription.errors).toEqual([
|
|
301
|
+
'ConsumerTooSlow',
|
|
302
|
+
'FutureCursor',
|
|
303
|
+
'InvalidCursor',
|
|
304
|
+
])
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
it('creates a Subscription with empty errors array', () => {
|
|
308
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
309
|
+
const parameters = new ParamsSchema({})
|
|
310
|
+
const message = new ObjectSchema({})
|
|
311
|
+
const errors = [] as const
|
|
312
|
+
|
|
313
|
+
const subscription = new Subscription(nsid, parameters, message, errors)
|
|
314
|
+
|
|
315
|
+
expect(subscription.errors).toEqual([])
|
|
316
|
+
})
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
describe('type inference', () => {
|
|
320
|
+
it('InferSubscriptionParameters correctly infers parameter types', () => {
|
|
321
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
322
|
+
const parameters = new ParamsSchema({
|
|
323
|
+
cursor: new OptionalSchema(new IntegerSchema({})),
|
|
324
|
+
})
|
|
325
|
+
const message = new ObjectSchema({
|
|
326
|
+
seq: new IntegerSchema({}),
|
|
327
|
+
})
|
|
328
|
+
|
|
329
|
+
const subscription = new Subscription(
|
|
330
|
+
nsid,
|
|
331
|
+
parameters,
|
|
332
|
+
message,
|
|
333
|
+
undefined,
|
|
334
|
+
)
|
|
335
|
+
|
|
336
|
+
type Params = InferSubscriptionParameters<typeof subscription>
|
|
337
|
+
|
|
338
|
+
// Type-level test - this should compile without errors
|
|
339
|
+
const params: Params = {
|
|
340
|
+
cursor: 12345,
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
expect(params.cursor).toBeDefined()
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
it('InferSubscriptionMessage correctly infers message type', () => {
|
|
347
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
348
|
+
const parameters = new ParamsSchema({})
|
|
349
|
+
const message = new ObjectSchema({
|
|
350
|
+
seq: new IntegerSchema({}),
|
|
351
|
+
data: new StringSchema({}),
|
|
352
|
+
})
|
|
353
|
+
|
|
354
|
+
const subscription = new Subscription(
|
|
355
|
+
nsid,
|
|
356
|
+
parameters,
|
|
357
|
+
message,
|
|
358
|
+
undefined,
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
type Message = InferSubscriptionMessage<typeof subscription>
|
|
362
|
+
|
|
363
|
+
// Type-level test - this should compile without errors
|
|
364
|
+
const msg: Message = {
|
|
365
|
+
seq: 12345,
|
|
366
|
+
data: 'test data',
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
expect(msg.seq).toBeDefined()
|
|
370
|
+
expect(msg.data).toBeDefined()
|
|
371
|
+
})
|
|
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
|
+
})
|
|
392
|
+
|
|
393
|
+
describe('edge cases', () => {
|
|
394
|
+
it('handles very long NSID', () => {
|
|
395
|
+
const nsid = asNsid(
|
|
396
|
+
'com.example.very.long.namespace.identifier.subscription.name',
|
|
397
|
+
)
|
|
398
|
+
const parameters = new ParamsSchema({})
|
|
399
|
+
const message = new ObjectSchema({})
|
|
400
|
+
|
|
401
|
+
const subscription = new Subscription(
|
|
402
|
+
nsid,
|
|
403
|
+
parameters,
|
|
404
|
+
message,
|
|
405
|
+
undefined,
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
expect(subscription.nsid).toBe(nsid)
|
|
409
|
+
})
|
|
410
|
+
|
|
411
|
+
it('handles subscription with all optional parameters', () => {
|
|
412
|
+
const nsid = asNsid('app.bsky.feed.subscribe')
|
|
413
|
+
const parameters = new ParamsSchema({
|
|
414
|
+
cursor: new OptionalSchema(new IntegerSchema({})),
|
|
415
|
+
includeDeletes: new OptionalSchema(new IntegerSchema({})),
|
|
416
|
+
includeEdits: new OptionalSchema(new IntegerSchema({})),
|
|
417
|
+
})
|
|
418
|
+
const message = new ObjectSchema({})
|
|
419
|
+
|
|
420
|
+
const subscription = new Subscription(
|
|
421
|
+
nsid,
|
|
422
|
+
parameters,
|
|
423
|
+
message,
|
|
424
|
+
undefined,
|
|
425
|
+
)
|
|
426
|
+
|
|
427
|
+
expect(subscription.parameters).toBe(parameters)
|
|
428
|
+
})
|
|
429
|
+
|
|
430
|
+
it('handles subscription with complex nested message schema', () => {
|
|
431
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
432
|
+
const parameters = new ParamsSchema({})
|
|
433
|
+
const message = new ObjectSchema({
|
|
434
|
+
seq: new IntegerSchema({}),
|
|
435
|
+
blocks: new ObjectSchema({
|
|
436
|
+
cid: new StringSchema({ format: 'cid' }),
|
|
437
|
+
data: new ObjectSchema({
|
|
438
|
+
uri: new StringSchema({ format: 'at-uri' }),
|
|
439
|
+
content: new StringSchema({}),
|
|
440
|
+
}),
|
|
441
|
+
}),
|
|
442
|
+
})
|
|
443
|
+
|
|
444
|
+
const subscription = new Subscription(
|
|
445
|
+
nsid,
|
|
446
|
+
parameters,
|
|
447
|
+
message,
|
|
448
|
+
undefined,
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
expect(subscription.message).toBeInstanceOf(ObjectSchema)
|
|
452
|
+
})
|
|
453
|
+
})
|
|
454
|
+
|
|
455
|
+
describe('real-world subscription examples', () => {
|
|
456
|
+
it('creates a subscribeLabels subscription', () => {
|
|
457
|
+
const nsid = asNsid('com.atproto.label.subscribeLabels')
|
|
458
|
+
const parameters = new ParamsSchema({
|
|
459
|
+
cursor: new OptionalSchema(new IntegerSchema({ minimum: 0 })),
|
|
460
|
+
})
|
|
461
|
+
const message = new ObjectSchema({
|
|
462
|
+
seq: new IntegerSchema({}),
|
|
463
|
+
labels: new ObjectSchema({
|
|
464
|
+
uri: new StringSchema({ format: 'uri' }),
|
|
465
|
+
val: new StringSchema({}),
|
|
466
|
+
}),
|
|
467
|
+
})
|
|
468
|
+
|
|
469
|
+
const subscription = new Subscription(
|
|
470
|
+
nsid,
|
|
471
|
+
parameters,
|
|
472
|
+
message,
|
|
473
|
+
undefined,
|
|
474
|
+
)
|
|
475
|
+
|
|
476
|
+
expect(subscription.type).toBe('subscription')
|
|
477
|
+
expect(subscription.nsid).toBe('com.atproto.label.subscribeLabels')
|
|
478
|
+
expect(subscription.parameters.matches({ cursor: 10 })).toBe(true)
|
|
479
|
+
expect(subscription.parameters.matches({ cursor: -10 })).toBe(false)
|
|
480
|
+
expect(
|
|
481
|
+
subscription.message.matches({
|
|
482
|
+
seq: 1,
|
|
483
|
+
labels: { uri: 'http://foo.com', val: 'test' },
|
|
484
|
+
}),
|
|
485
|
+
).toBe(true)
|
|
486
|
+
expect(
|
|
487
|
+
subscription.message.matches({
|
|
488
|
+
seq: 1,
|
|
489
|
+
labels: { uri: 'http://foo.com', val: 3 },
|
|
490
|
+
}),
|
|
491
|
+
).toBe(false)
|
|
492
|
+
})
|
|
493
|
+
|
|
494
|
+
it('creates a notification subscription', () => {
|
|
495
|
+
const nsid = asNsid('app.bsky.notification.subscribe')
|
|
496
|
+
const parameters = new ParamsSchema({
|
|
497
|
+
cursor: new OptionalSchema(new StringSchema({})),
|
|
498
|
+
})
|
|
499
|
+
const message = new ObjectSchema({
|
|
500
|
+
type: new StringSchema({}),
|
|
501
|
+
uri: new StringSchema({ format: 'at-uri' }),
|
|
502
|
+
cid: new StringSchema({ format: 'cid' }),
|
|
503
|
+
})
|
|
504
|
+
|
|
505
|
+
const subscription = new Subscription(
|
|
506
|
+
nsid,
|
|
507
|
+
parameters,
|
|
508
|
+
message,
|
|
509
|
+
undefined,
|
|
510
|
+
)
|
|
511
|
+
|
|
512
|
+
expect(subscription.type).toBe('subscription')
|
|
513
|
+
expect(subscription.nsid).toBe('app.bsky.notification.subscribe')
|
|
514
|
+
})
|
|
515
|
+
})
|
|
516
|
+
|
|
517
|
+
describe('with mixed parameter and message types', () => {
|
|
518
|
+
it('handles required and optional parameters with complex message', () => {
|
|
519
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
520
|
+
const parameters = new ParamsSchema({
|
|
521
|
+
cursor: new OptionalSchema(new IntegerSchema({ minimum: 0 })),
|
|
522
|
+
includeDeletes: new OptionalSchema(
|
|
523
|
+
new IntegerSchema({ minimum: 0, maximum: 1 }),
|
|
524
|
+
),
|
|
525
|
+
})
|
|
526
|
+
const message = new ObjectSchema({
|
|
527
|
+
seq: new IntegerSchema({}),
|
|
528
|
+
rebase: new OptionalSchema(
|
|
529
|
+
new IntegerSchema({ minimum: 0, maximum: 1 }),
|
|
530
|
+
),
|
|
531
|
+
tooBig: new OptionalSchema(
|
|
532
|
+
new IntegerSchema({ minimum: 0, maximum: 1 }),
|
|
533
|
+
),
|
|
534
|
+
repo: new StringSchema({ format: 'did' }),
|
|
535
|
+
commit: new StringSchema({ format: 'cid' }),
|
|
536
|
+
blocks: new StringSchema({}),
|
|
537
|
+
ops: new ObjectSchema({}),
|
|
538
|
+
})
|
|
539
|
+
|
|
540
|
+
const subscription = new Subscription(
|
|
541
|
+
nsid,
|
|
542
|
+
parameters,
|
|
543
|
+
message,
|
|
544
|
+
undefined,
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
expect(subscription.type).toBe('subscription')
|
|
548
|
+
expect(subscription.parameters).toBe(parameters)
|
|
549
|
+
expect(subscription.message).toBe(message)
|
|
550
|
+
})
|
|
551
|
+
})
|
|
552
|
+
|
|
553
|
+
describe('validation through nested schemas', () => {
|
|
554
|
+
it('parameters can validate input through ParamsSchema', () => {
|
|
555
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
556
|
+
const parameters = new ParamsSchema({
|
|
557
|
+
cursor: new IntegerSchema({ minimum: 0 }),
|
|
558
|
+
})
|
|
559
|
+
const message = new ObjectSchema({})
|
|
560
|
+
|
|
561
|
+
const subscription = new Subscription(
|
|
562
|
+
nsid,
|
|
563
|
+
parameters,
|
|
564
|
+
message,
|
|
565
|
+
undefined,
|
|
566
|
+
)
|
|
567
|
+
|
|
568
|
+
// Test that the parameters schema can validate
|
|
569
|
+
const validResult = subscription.parameters.safeParse({ cursor: 100 })
|
|
570
|
+
expect(validResult.success).toBe(true)
|
|
571
|
+
|
|
572
|
+
const invalidResult = subscription.parameters.safeParse({ cursor: -1 })
|
|
573
|
+
expect(invalidResult.success).toBe(false)
|
|
574
|
+
})
|
|
575
|
+
|
|
576
|
+
it('message can validate input through ObjectSchema', () => {
|
|
577
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
578
|
+
const parameters = new ParamsSchema({})
|
|
579
|
+
const message = new ObjectSchema({
|
|
580
|
+
seq: new IntegerSchema({ minimum: 0 }),
|
|
581
|
+
data: new StringSchema({ minLength: 1 }),
|
|
582
|
+
})
|
|
583
|
+
|
|
584
|
+
const subscription = new Subscription(
|
|
585
|
+
nsid,
|
|
586
|
+
parameters,
|
|
587
|
+
message,
|
|
588
|
+
undefined,
|
|
589
|
+
)
|
|
590
|
+
|
|
591
|
+
// Test that the message schema can validate
|
|
592
|
+
const validResult = subscription.message.safeParse({
|
|
593
|
+
seq: 100,
|
|
594
|
+
data: 'test',
|
|
595
|
+
})
|
|
596
|
+
expect(validResult.success).toBe(true)
|
|
597
|
+
|
|
598
|
+
const invalidResult = subscription.message.safeParse({
|
|
599
|
+
seq: -1,
|
|
600
|
+
data: '',
|
|
601
|
+
})
|
|
602
|
+
expect(invalidResult.success).toBe(false)
|
|
603
|
+
})
|
|
604
|
+
})
|
|
605
|
+
|
|
606
|
+
describe('property access', () => {
|
|
607
|
+
it('can access nsid after construction', () => {
|
|
608
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
609
|
+
const parameters = new ParamsSchema({})
|
|
610
|
+
const message = new ObjectSchema({})
|
|
611
|
+
|
|
612
|
+
const subscription = new Subscription(
|
|
613
|
+
nsid,
|
|
614
|
+
parameters,
|
|
615
|
+
message,
|
|
616
|
+
undefined,
|
|
617
|
+
)
|
|
618
|
+
|
|
619
|
+
expect(subscription.nsid).toBe(nsid)
|
|
620
|
+
expect(subscription.nsid).toBe('com.atproto.sync.subscribeRepos')
|
|
621
|
+
})
|
|
622
|
+
|
|
623
|
+
it('can access type after construction', () => {
|
|
624
|
+
const nsid = asNsid('com.atproto.sync.subscribeRepos')
|
|
625
|
+
const parameters = new ParamsSchema({})
|
|
626
|
+
const message = new ObjectSchema({})
|
|
627
|
+
|
|
628
|
+
const subscription = new Subscription(
|
|
629
|
+
nsid,
|
|
630
|
+
parameters,
|
|
631
|
+
message,
|
|
632
|
+
undefined,
|
|
633
|
+
)
|
|
634
|
+
|
|
635
|
+
expect(subscription.type).toBe('subscription')
|
|
636
|
+
expect(typeof subscription.type).toBe('string')
|
|
637
|
+
})
|
|
638
|
+
})
|
|
639
|
+
|
|
640
|
+
describe('different message schema types', () => {
|
|
641
|
+
it('constructs with ObjectSchema message', () => {
|
|
642
|
+
const nsid = asNsid('app.bsky.test')
|
|
643
|
+
const parameters = new ParamsSchema({})
|
|
644
|
+
const message = new ObjectSchema({
|
|
645
|
+
field: new StringSchema({}),
|
|
646
|
+
})
|
|
647
|
+
|
|
648
|
+
const subscription = new Subscription(
|
|
649
|
+
nsid,
|
|
650
|
+
parameters,
|
|
651
|
+
message,
|
|
652
|
+
undefined,
|
|
653
|
+
)
|
|
654
|
+
|
|
655
|
+
expect(subscription.message).toBeInstanceOf(ObjectSchema)
|
|
656
|
+
expect(subscription.message).toBe(message)
|
|
657
|
+
})
|
|
658
|
+
|
|
659
|
+
it('constructs with RefSchema message', () => {
|
|
660
|
+
const nsid = asNsid('app.bsky.test')
|
|
661
|
+
const parameters = new ParamsSchema({})
|
|
662
|
+
const message = new RefSchema(() => new ObjectSchema({}))
|
|
663
|
+
|
|
664
|
+
const subscription = new Subscription(
|
|
665
|
+
nsid,
|
|
666
|
+
parameters,
|
|
667
|
+
message,
|
|
668
|
+
undefined,
|
|
669
|
+
)
|
|
670
|
+
|
|
671
|
+
expect(subscription.message).toBeInstanceOf(RefSchema)
|
|
672
|
+
expect(subscription.message).toBe(message)
|
|
673
|
+
})
|
|
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
|
+
})
|
|
689
|
+
})
|