@atproto/lex-schema 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/core/$type.d.ts +2 -2
- package/dist/core/$type.d.ts.map +1 -1
- package/dist/core/$type.js.map +1 -1
- package/dist/core/record-key.d.ts +1 -1
- package/dist/core/record-key.d.ts.map +1 -1
- package/dist/core/record-key.js.map +1 -1
- package/dist/core/schema.d.ts +3 -2
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +1 -1
- package/dist/core/schema.js.map +1 -1
- package/dist/core/standard-schema.d.ts +2 -2
- package/dist/core/standard-schema.d.ts.map +1 -1
- package/dist/core/standard-schema.js.map +1 -1
- package/dist/core/string-format.d.ts +2 -2
- package/dist/core/string-format.d.ts.map +1 -1
- package/dist/core/string-format.js.map +1 -1
- package/dist/core/validation-error.d.ts +1 -1
- package/dist/core/validation-error.d.ts.map +1 -1
- package/dist/core/validation-error.js +1 -1
- package/dist/core/validation-error.js.map +1 -1
- package/dist/core/validator.d.ts +1 -1
- package/dist/core/validator.d.ts.map +1 -1
- package/dist/core/validator.js +1 -1
- package/dist/core/validator.js.map +1 -1
- package/dist/helpers.d.ts +2 -2
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +2 -2
- package/dist/helpers.js.map +1 -1
- package/dist/schema/array.d.ts +1 -1
- package/dist/schema/array.d.ts.map +1 -1
- package/dist/schema/array.js +1 -1
- package/dist/schema/array.js.map +1 -1
- package/dist/schema/blob.d.ts +1 -1
- package/dist/schema/blob.d.ts.map +1 -1
- package/dist/schema/blob.js +2 -2
- package/dist/schema/blob.js.map +1 -1
- package/dist/schema/boolean.js +1 -1
- package/dist/schema/boolean.js.map +1 -1
- package/dist/schema/bytes.js +1 -1
- package/dist/schema/bytes.js.map +1 -1
- package/dist/schema/cid.d.ts +1 -1
- package/dist/schema/cid.d.ts.map +1 -1
- package/dist/schema/cid.js +3 -3
- package/dist/schema/cid.js.map +1 -1
- package/dist/schema/custom.js +1 -1
- package/dist/schema/custom.js.map +1 -1
- package/dist/schema/dict.d.ts +1 -1
- 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 +1 -1
- package/dist/schema/discriminated-union.d.ts.map +1 -1
- package/dist/schema/discriminated-union.js +2 -1
- package/dist/schema/discriminated-union.js.map +1 -1
- package/dist/schema/enum.js +1 -1
- package/dist/schema/enum.js.map +1 -1
- package/dist/schema/integer.js +1 -1
- package/dist/schema/integer.js.map +1 -1
- package/dist/schema/intersection.d.ts +1 -1
- package/dist/schema/intersection.d.ts.map +1 -1
- package/dist/schema/intersection.js +3 -1
- package/dist/schema/intersection.js.map +1 -1
- package/dist/schema/lex-map.d.ts +1 -1
- package/dist/schema/lex-map.d.ts.map +1 -1
- package/dist/schema/lex-map.js +1 -1
- package/dist/schema/lex-map.js.map +1 -1
- package/dist/schema/lex-value.d.ts +1 -1
- package/dist/schema/lex-value.d.ts.map +1 -1
- package/dist/schema/lex-value.js +1 -1
- package/dist/schema/lex-value.js.map +1 -1
- package/dist/schema/literal.js +1 -1
- package/dist/schema/literal.js.map +1 -1
- package/dist/schema/never.js +1 -1
- package/dist/schema/never.js.map +1 -1
- package/dist/schema/null.js +1 -1
- package/dist/schema/null.js.map +1 -1
- package/dist/schema/nullable.d.ts +1 -1
- package/dist/schema/nullable.d.ts.map +1 -1
- package/dist/schema/nullable.js +1 -1
- package/dist/schema/nullable.js.map +1 -1
- package/dist/schema/object.d.ts +2 -1
- package/dist/schema/object.d.ts.map +1 -1
- package/dist/schema/object.js +1 -1
- package/dist/schema/object.js.map +1 -1
- package/dist/schema/optional.d.ts +2 -1
- package/dist/schema/optional.d.ts.map +1 -1
- package/dist/schema/optional.js +2 -1
- package/dist/schema/optional.js.map +1 -1
- package/dist/schema/params.d.ts +1 -1
- package/dist/schema/params.d.ts.map +1 -1
- package/dist/schema/params.js +1 -1
- package/dist/schema/params.js.map +1 -1
- package/dist/schema/payload.d.ts +3 -2
- package/dist/schema/payload.d.ts.map +1 -1
- package/dist/schema/payload.js +2 -1
- package/dist/schema/payload.js.map +1 -1
- package/dist/schema/permission-set.d.ts +1 -1
- package/dist/schema/permission-set.d.ts.map +1 -1
- package/dist/schema/permission-set.js +1 -0
- package/dist/schema/permission-set.js.map +1 -1
- package/dist/schema/permission.d.ts +1 -1
- package/dist/schema/permission.d.ts.map +1 -1
- package/dist/schema/permission.js.map +1 -1
- package/dist/schema/procedure.d.ts +1 -1
- package/dist/schema/procedure.d.ts.map +1 -1
- package/dist/schema/procedure.js +2 -0
- package/dist/schema/procedure.js.map +1 -1
- package/dist/schema/query.d.ts +1 -1
- package/dist/schema/query.d.ts.map +1 -1
- package/dist/schema/query.js +2 -0
- package/dist/schema/query.js.map +1 -1
- package/dist/schema/record.d.ts +2 -2
- package/dist/schema/record.d.ts.map +1 -1
- package/dist/schema/record.js +1 -1
- package/dist/schema/record.js.map +1 -1
- package/dist/schema/ref.d.ts +1 -1
- package/dist/schema/ref.d.ts.map +1 -1
- package/dist/schema/ref.js +1 -1
- package/dist/schema/ref.js.map +1 -1
- package/dist/schema/refine.d.ts +2 -2
- package/dist/schema/refine.d.ts.map +1 -1
- package/dist/schema/refine.js +1 -1
- package/dist/schema/refine.js.map +1 -1
- package/dist/schema/regexp.js +1 -1
- package/dist/schema/regexp.js.map +1 -1
- package/dist/schema/string.d.ts +2 -2
- package/dist/schema/string.d.ts.map +1 -1
- package/dist/schema/string.js +1 -1
- package/dist/schema/string.js.map +1 -1
- package/dist/schema/subscription.d.ts +3 -2
- package/dist/schema/subscription.d.ts.map +1 -1
- package/dist/schema/subscription.js +2 -0
- package/dist/schema/subscription.js.map +1 -1
- package/dist/schema/token.d.ts +1 -1
- package/dist/schema/token.d.ts.map +1 -1
- package/dist/schema/token.js +1 -1
- package/dist/schema/token.js.map +1 -1
- package/dist/schema/typed-object.d.ts +2 -2
- package/dist/schema/typed-object.d.ts.map +1 -1
- package/dist/schema/typed-object.js +1 -1
- package/dist/schema/typed-object.js.map +1 -1
- package/dist/schema/typed-ref.d.ts +1 -1
- 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 +1 -1
- package/dist/schema/typed-union.d.ts.map +1 -1
- package/dist/schema/typed-union.js +3 -1
- package/dist/schema/typed-union.js.map +1 -1
- package/dist/schema/union.d.ts +1 -1
- 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.js +1 -1
- package/dist/schema/unknown.js.map +1 -1
- package/dist/schema/with-default.d.ts +1 -1
- package/dist/schema/with-default.d.ts.map +1 -1
- package/dist/schema/with-default.js +1 -1
- package/dist/schema/with-default.js.map +1 -1
- package/package.json +6 -10
- package/src/core/$type.test.ts +0 -24
- package/src/core/$type.ts +0 -199
- package/src/core/record-key.ts +0 -85
- package/src/core/result.ts +0 -15
- package/src/core/schema.ts +0 -412
- package/src/core/standard-schema.test.ts +0 -124
- package/src/core/standard-schema.ts +0 -31
- package/src/core/string-format.ts +0 -411
- package/src/core/types.ts +0 -120
- package/src/core/validation-error.ts +0 -134
- package/src/core/validation-issue.ts +0 -340
- package/src/core/validator.ts +0 -636
- package/src/core.ts +0 -9
- package/src/external.ts +0 -3
- package/src/helpers.test.ts +0 -694
- package/src/helpers.ts +0 -222
- package/src/index.ts +0 -3
- package/src/schema/array.test.ts +0 -251
- package/src/schema/array.ts +0 -126
- package/src/schema/blob.test.ts +0 -733
- package/src/schema/blob.ts +0 -150
- package/src/schema/boolean.test.ts +0 -118
- package/src/schema/boolean.ts +0 -46
- package/src/schema/bytes.test.ts +0 -227
- package/src/schema/bytes.ts +0 -81
- package/src/schema/cid.test.ts +0 -125
- package/src/schema/cid.ts +0 -69
- package/src/schema/custom.test.ts +0 -414
- package/src/schema/custom.ts +0 -106
- package/src/schema/dict.test.ts +0 -181
- package/src/schema/dict.ts +0 -122
- package/src/schema/discriminated-union.test.ts +0 -676
- package/src/schema/discriminated-union.ts +0 -196
- package/src/schema/enum.test.ts +0 -398
- package/src/schema/enum.ts +0 -77
- package/src/schema/integer.test.ts +0 -314
- package/src/schema/integer.ts +0 -86
- package/src/schema/intersection.test.ts +0 -33
- package/src/schema/intersection.ts +0 -113
- package/src/schema/lex-map.test.ts +0 -593
- package/src/schema/lex-map.ts +0 -63
- package/src/schema/lex-value.test.ts +0 -81
- package/src/schema/lex-value.ts +0 -86
- package/src/schema/literal.test.ts +0 -533
- package/src/schema/literal.ts +0 -70
- package/src/schema/never.test.ts +0 -175
- package/src/schema/never.ts +0 -56
- package/src/schema/null.test.ts +0 -80
- package/src/schema/null.ts +0 -49
- package/src/schema/nullable.test.ts +0 -470
- package/src/schema/nullable.ts +0 -74
- package/src/schema/object.test.ts +0 -69
- package/src/schema/object.ts +0 -136
- package/src/schema/optional.test.ts +0 -479
- package/src/schema/optional.ts +0 -92
- package/src/schema/params.test.ts +0 -1118
- package/src/schema/params.ts +0 -371
- package/src/schema/payload.test.ts +0 -340
- package/src/schema/payload.ts +0 -204
- package/src/schema/permission-set.test.ts +0 -613
- package/src/schema/permission-set.ts +0 -86
- package/src/schema/permission.test.ts +0 -537
- package/src/schema/permission.ts +0 -63
- package/src/schema/procedure.test.ts +0 -324
- package/src/schema/procedure.ts +0 -98
- package/src/schema/query.test.ts +0 -348
- package/src/schema/query.ts +0 -86
- package/src/schema/record.test.ts +0 -812
- package/src/schema/record.ts +0 -217
- package/src/schema/ref.test.ts +0 -349
- package/src/schema/ref.ts +0 -103
- package/src/schema/refine.test.ts +0 -579
- package/src/schema/refine.ts +0 -153
- package/src/schema/regexp.test.ts +0 -577
- package/src/schema/regexp.ts +0 -82
- package/src/schema/string.test.ts +0 -773
- package/src/schema/string.ts +0 -229
- package/src/schema/subscription.test.ts +0 -499
- package/src/schema/subscription.ts +0 -108
- package/src/schema/token.test.ts +0 -152
- package/src/schema/token.ts +0 -103
- package/src/schema/typed-object.test.ts +0 -745
- package/src/schema/typed-object.ts +0 -181
- package/src/schema/typed-ref.test.ts +0 -796
- package/src/schema/typed-ref.ts +0 -126
- package/src/schema/typed-union.test.ts +0 -355
- package/src/schema/typed-union.ts +0 -130
- package/src/schema/union.test.ts +0 -191
- package/src/schema/union.ts +0 -89
- package/src/schema/unknown.test.ts +0 -313
- package/src/schema/unknown.ts +0 -47
- package/src/schema/with-default.ts +0 -81
- package/src/schema.ts +0 -43
- package/src/util/array-agg.test.ts +0 -42
- package/src/util/array-agg.ts +0 -44
- package/src/util/assertion-util.ts +0 -1
- package/src/util/if-any.ts +0 -3
- package/src/util/lazy-property.ts +0 -14
- package/src/util/memoize.ts +0 -37
- package/tsconfig.build.json +0 -12
- package/tsconfig.json +0 -7
- package/tsconfig.tests.json +0 -8
package/src/helpers.test.ts
DELETED
|
@@ -1,694 +0,0 @@
|
|
|
1
|
-
import { describe, expect, expectTypeOf, it, test } from 'vitest'
|
|
2
|
-
import * as l from './external.js'
|
|
3
|
-
|
|
4
|
-
class BinaryValue {
|
|
5
|
-
declare readonly ['__binaryValue']: BinaryValue
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const expectType = <T>(_: T) => {}
|
|
9
|
-
const binaryValue = new BinaryValue()
|
|
10
|
-
|
|
11
|
-
describe('InferMethodParams', () => {
|
|
12
|
-
describe('query', () => {
|
|
13
|
-
test('infers parameter types', () => {
|
|
14
|
-
const _query = l.query(
|
|
15
|
-
'com.example.query',
|
|
16
|
-
l.params({
|
|
17
|
-
feed: l.string({ format: 'at-uri' }),
|
|
18
|
-
limit: l.optional(l.integer()),
|
|
19
|
-
}),
|
|
20
|
-
l.payload('application/json', undefined),
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
type Params = l.InferMethodParams<typeof _query>
|
|
24
|
-
|
|
25
|
-
expectType<Params>({
|
|
26
|
-
feed: 'at://did:plc:abc123/app.bsky.feed.post/xyz',
|
|
27
|
-
limit: 50,
|
|
28
|
-
})
|
|
29
|
-
// @ts-expect-error
|
|
30
|
-
expectType<Params>({ feed: 123, limit: 50 })
|
|
31
|
-
// @ts-expect-error
|
|
32
|
-
expectType<Params>({ limit: 50 })
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
describe('procedure', () => {
|
|
37
|
-
test('infers parameter types', () => {
|
|
38
|
-
const _procedure = l.procedure(
|
|
39
|
-
'com.example.list',
|
|
40
|
-
l.params({ limit: l.string() }),
|
|
41
|
-
l.payload(),
|
|
42
|
-
l.payload(),
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
type Params = l.InferMethodParams<typeof _procedure>
|
|
46
|
-
|
|
47
|
-
expectType<Params>({ limit: '10' })
|
|
48
|
-
// @ts-expect-error
|
|
49
|
-
expectType<Params>({ limit: 10 })
|
|
50
|
-
// @ts-expect-error
|
|
51
|
-
expectType<Params>({ limit: binaryValue })
|
|
52
|
-
// @ts-expect-error
|
|
53
|
-
expectType<Params>(binaryValue)
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
describe('subscription', () => {
|
|
58
|
-
test('infers parameter types', () => {
|
|
59
|
-
const _subscription = l.subscription(
|
|
60
|
-
'com.example.subscribe',
|
|
61
|
-
l.params({
|
|
62
|
-
cursor: l.optional(l.integer()),
|
|
63
|
-
}),
|
|
64
|
-
l.lexMap(),
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
type Params = l.InferMethodParams<typeof _subscription>
|
|
68
|
-
|
|
69
|
-
expectType<Params>({ cursor: 100 })
|
|
70
|
-
// @ts-expect-error
|
|
71
|
-
expectType<Params>({ cursor: '100' })
|
|
72
|
-
// @ts-expect-error
|
|
73
|
-
expectType<Params>({ cursor: binaryValue })
|
|
74
|
-
})
|
|
75
|
-
})
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
describe('InferMethodInput', () => {
|
|
79
|
-
describe('procedure', () => {
|
|
80
|
-
test('with payload schema', () => {
|
|
81
|
-
const _procedure = l.procedure(
|
|
82
|
-
'com.example.create',
|
|
83
|
-
l.params(),
|
|
84
|
-
l.jsonPayload({ text: l.string() }),
|
|
85
|
-
l.payload(),
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
type Input = l.InferMethodInput<typeof _procedure, BinaryValue>
|
|
89
|
-
|
|
90
|
-
expectType<Input>({ encoding: 'application/json', body: { text: 'hi' } })
|
|
91
|
-
// @ts-expect-error
|
|
92
|
-
expectType<Input>({ encoding: 'application/json', body: { text: 123 } })
|
|
93
|
-
// @ts-expect-error
|
|
94
|
-
expectType<Input>({ encoding: 'text/plain', body: { text: 'hi' } })
|
|
95
|
-
// @ts-expect-error
|
|
96
|
-
expectType<Input>({ encoding: 'text/plain', body: 'hello' })
|
|
97
|
-
// @ts-expect-error
|
|
98
|
-
expectType<Input>({ encoding: 'text/plain', body: new Uint8Array() })
|
|
99
|
-
// @ts-expect-error
|
|
100
|
-
expectType<Input>({ encoding: 'text/plain', body: binaryValue })
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
test('without payload schema', () => {
|
|
104
|
-
const _procedure = l.procedure(
|
|
105
|
-
'com.example.create',
|
|
106
|
-
l.params(),
|
|
107
|
-
l.payload('*/*', undefined),
|
|
108
|
-
l.payload(),
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
type Input = l.InferMethodInput<typeof _procedure, BinaryValue>
|
|
112
|
-
|
|
113
|
-
expectType<Input>({ encoding: 'image/png', body: binaryValue })
|
|
114
|
-
// @ts-expect-error
|
|
115
|
-
expectType<Input>({ encoding: 'image/png', body: new Uint8Array() })
|
|
116
|
-
// @ts-expect-error
|
|
117
|
-
expectType<Input>({ encoding: 'image/png', body: [] })
|
|
118
|
-
// @ts-expect-error
|
|
119
|
-
expectType<Input>({ encoding: 'image/png', body: 'foo' })
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
describe('InferMethodInputBody', () => {
|
|
125
|
-
describe('procedure', () => {
|
|
126
|
-
test('with payload schema', () => {
|
|
127
|
-
const _procedure = l.procedure(
|
|
128
|
-
'com.example.create',
|
|
129
|
-
l.params(),
|
|
130
|
-
l.jsonPayload({ text: l.string() }),
|
|
131
|
-
l.payload(),
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
type InputBody = l.InferMethodInputBody<typeof _procedure, BinaryValue>
|
|
135
|
-
|
|
136
|
-
expectType<InputBody>({ text: 'hello' })
|
|
137
|
-
// @ts-expect-error
|
|
138
|
-
expectType<InputBody>({ text: 123 })
|
|
139
|
-
// @ts-expect-error
|
|
140
|
-
expectType<InputBody>(binaryValue)
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
test('without payload schema', () => {
|
|
144
|
-
const _procedure = l.procedure(
|
|
145
|
-
'com.example.upload',
|
|
146
|
-
l.params(),
|
|
147
|
-
l.payload('*/*', undefined),
|
|
148
|
-
l.payload(),
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
type InputBody = l.InferMethodInputBody<typeof _procedure, BinaryValue>
|
|
152
|
-
|
|
153
|
-
expectType<InputBody>(binaryValue)
|
|
154
|
-
// @ts-expect-error
|
|
155
|
-
expectType<InputBody>(new Uint8Array())
|
|
156
|
-
// @ts-expect-error
|
|
157
|
-
expectType<InputBody>({ text: 'hello' })
|
|
158
|
-
})
|
|
159
|
-
})
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
describe('InferMethodInputEncoding', () => {
|
|
163
|
-
describe('procedure', () => {
|
|
164
|
-
test('with payload schema', () => {
|
|
165
|
-
const _procedure = l.procedure(
|
|
166
|
-
'com.example.create',
|
|
167
|
-
l.params(),
|
|
168
|
-
l.jsonPayload({ text: l.string() }),
|
|
169
|
-
l.payload(),
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
type InputEncoding = l.InferMethodInputEncoding<typeof _procedure>
|
|
173
|
-
|
|
174
|
-
expectType<InputEncoding>('application/json')
|
|
175
|
-
// @ts-expect-error
|
|
176
|
-
expectType<InputEncoding>('text/plain')
|
|
177
|
-
// @ts-expect-error
|
|
178
|
-
expectType<InputEncoding>(123)
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
test('without payload schema', () => {
|
|
182
|
-
const _procedure = l.procedure(
|
|
183
|
-
'com.example.upload',
|
|
184
|
-
l.params(),
|
|
185
|
-
l.payload('*/*', undefined),
|
|
186
|
-
l.payload(),
|
|
187
|
-
)
|
|
188
|
-
|
|
189
|
-
type InputEncoding = l.InferMethodInputEncoding<typeof _procedure>
|
|
190
|
-
|
|
191
|
-
expectType<InputEncoding>('image/png')
|
|
192
|
-
expectType<InputEncoding>('application/octet-stream')
|
|
193
|
-
// @ts-expect-error
|
|
194
|
-
expectType<InputEncoding>(123)
|
|
195
|
-
})
|
|
196
|
-
})
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
describe('InferMethodOutput', () => {
|
|
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
|
-
|
|
232
|
-
test('with payload schema', () => {
|
|
233
|
-
const _query = l.query(
|
|
234
|
-
'com.example.query',
|
|
235
|
-
l.params(),
|
|
236
|
-
l.jsonPayload({ items: l.array(l.string()) }),
|
|
237
|
-
)
|
|
238
|
-
|
|
239
|
-
type Output = l.InferMethodOutput<typeof _query, BinaryValue>
|
|
240
|
-
|
|
241
|
-
expectType<Output>({ encoding: 'application/json', body: { items: [] } })
|
|
242
|
-
// @ts-expect-error
|
|
243
|
-
expectType<Output>({ encoding: 'application/json', body: { items: [1] } })
|
|
244
|
-
// @ts-expect-error
|
|
245
|
-
expectType<Output>({ encoding: 'text/plain', body: { items: [] } })
|
|
246
|
-
})
|
|
247
|
-
|
|
248
|
-
test('without payload schema', () => {
|
|
249
|
-
const _query = l.query(
|
|
250
|
-
'com.example.query',
|
|
251
|
-
l.params(),
|
|
252
|
-
l.payload('*/*', undefined),
|
|
253
|
-
)
|
|
254
|
-
|
|
255
|
-
type Output = l.InferMethodOutput<typeof _query, BinaryValue>
|
|
256
|
-
|
|
257
|
-
expectType<Output>({ encoding: 'image/png', body: binaryValue })
|
|
258
|
-
// @ts-expect-error
|
|
259
|
-
expectType<Output>({ encoding: 'image/png', body: new Uint8Array() })
|
|
260
|
-
// @ts-expect-error
|
|
261
|
-
expectType<Output>({ encoding: 'image/png', body: 'string' })
|
|
262
|
-
})
|
|
263
|
-
})
|
|
264
|
-
|
|
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
|
-
|
|
299
|
-
test('with payload schema', () => {
|
|
300
|
-
const _procedure = l.procedure(
|
|
301
|
-
'com.example.create',
|
|
302
|
-
l.params(),
|
|
303
|
-
l.payload(),
|
|
304
|
-
l.payload(
|
|
305
|
-
'application/json',
|
|
306
|
-
l.object({ uri: l.string({ format: 'at-uri' }) }),
|
|
307
|
-
),
|
|
308
|
-
undefined,
|
|
309
|
-
)
|
|
310
|
-
|
|
311
|
-
type Output = l.InferMethodOutput<typeof _procedure, BinaryValue>
|
|
312
|
-
|
|
313
|
-
expectType<Output>({
|
|
314
|
-
encoding: 'application/json',
|
|
315
|
-
body: { uri: 'at://did:plc:abc/post/123' },
|
|
316
|
-
})
|
|
317
|
-
// @ts-expect-error
|
|
318
|
-
expectType<Output>({ encoding: 'application/json', body: { uri: 123 } })
|
|
319
|
-
// @ts-expect-error
|
|
320
|
-
expectType<Output>({ encoding: 'text/plain', body: { uri: 'at://...' } })
|
|
321
|
-
// @ts-expect-error
|
|
322
|
-
expectType<Output>({ encoding: 'text/plain', body: 'Hello' })
|
|
323
|
-
})
|
|
324
|
-
|
|
325
|
-
test('without payload schema', () => {
|
|
326
|
-
const _procedure = l.procedure(
|
|
327
|
-
'com.example.export',
|
|
328
|
-
l.params(),
|
|
329
|
-
l.payload(),
|
|
330
|
-
l.payload('*/*', undefined),
|
|
331
|
-
undefined,
|
|
332
|
-
)
|
|
333
|
-
|
|
334
|
-
type Output = l.InferMethodOutput<typeof _procedure, BinaryValue>
|
|
335
|
-
|
|
336
|
-
expectType<Output>({
|
|
337
|
-
encoding: 'application/zip',
|
|
338
|
-
body: binaryValue,
|
|
339
|
-
})
|
|
340
|
-
expectType<Output>({
|
|
341
|
-
encoding: 'application/zip',
|
|
342
|
-
// @ts-expect-error
|
|
343
|
-
body: new Uint8Array(),
|
|
344
|
-
})
|
|
345
|
-
// @ts-expect-error
|
|
346
|
-
expectType<Output>({ encoding: 'application/zip', body: 'string' })
|
|
347
|
-
})
|
|
348
|
-
})
|
|
349
|
-
})
|
|
350
|
-
|
|
351
|
-
describe('InferMethodOutputBody', () => {
|
|
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
|
-
|
|
374
|
-
test('with payload schema', () => {
|
|
375
|
-
const _query = l.query(
|
|
376
|
-
'com.example.query',
|
|
377
|
-
l.params(),
|
|
378
|
-
l.payload(
|
|
379
|
-
'application/json',
|
|
380
|
-
l.object({
|
|
381
|
-
cursor: l.optional(l.string()),
|
|
382
|
-
feed: l.string({ format: 'at-uri' }),
|
|
383
|
-
}),
|
|
384
|
-
),
|
|
385
|
-
)
|
|
386
|
-
|
|
387
|
-
type OutputBody = l.InferMethodOutputBody<typeof _query, BinaryValue>
|
|
388
|
-
|
|
389
|
-
expectType<OutputBody>({
|
|
390
|
-
cursor: 'abc123',
|
|
391
|
-
feed: 'at://did:plc:abc123/app.bsky.feed.post/xyz',
|
|
392
|
-
})
|
|
393
|
-
// @ts-expect-error
|
|
394
|
-
expectType<OutputBody>({ cursor: 123, feed: 'at://...' })
|
|
395
|
-
// @ts-expect-error
|
|
396
|
-
expectType<OutputBody>({ feed: 123 })
|
|
397
|
-
})
|
|
398
|
-
|
|
399
|
-
test('without payload schema', () => {
|
|
400
|
-
const _query = l.query(
|
|
401
|
-
'com.example.query',
|
|
402
|
-
l.params(),
|
|
403
|
-
l.payload('*/*', undefined),
|
|
404
|
-
)
|
|
405
|
-
|
|
406
|
-
type OutputBody = l.InferMethodOutputBody<typeof _query, BinaryValue>
|
|
407
|
-
|
|
408
|
-
expectType<OutputBody>(binaryValue)
|
|
409
|
-
// @ts-expect-error
|
|
410
|
-
expectType<OutputBody>(new Uint8Array())
|
|
411
|
-
// @ts-expect-error
|
|
412
|
-
expectType<OutputBody>({ data: 'foo' })
|
|
413
|
-
})
|
|
414
|
-
})
|
|
415
|
-
|
|
416
|
-
describe('procedure', () => {
|
|
417
|
-
test('with payload schema', () => {
|
|
418
|
-
const _procedure = l.procedure(
|
|
419
|
-
'com.example.get',
|
|
420
|
-
l.params(),
|
|
421
|
-
l.payload(),
|
|
422
|
-
l.payload(
|
|
423
|
-
'application/json',
|
|
424
|
-
l.object({ uri: l.string({ format: 'at-uri' }) }),
|
|
425
|
-
),
|
|
426
|
-
undefined,
|
|
427
|
-
)
|
|
428
|
-
|
|
429
|
-
type OutputBody = l.InferMethodOutputBody<typeof _procedure, BinaryValue>
|
|
430
|
-
|
|
431
|
-
expectType<OutputBody>({ uri: 'at://did:plc:abc/post/123' })
|
|
432
|
-
// @ts-expect-error
|
|
433
|
-
expectType<OutputBody>({ uri: 123 })
|
|
434
|
-
// @ts-expect-error
|
|
435
|
-
expectType<OutputBody>(binaryValue)
|
|
436
|
-
})
|
|
437
|
-
|
|
438
|
-
test('without payload schema', () => {
|
|
439
|
-
const _procedure = l.procedure(
|
|
440
|
-
'com.example.export',
|
|
441
|
-
l.params(),
|
|
442
|
-
l.payload(),
|
|
443
|
-
l.payload('*/*', undefined),
|
|
444
|
-
undefined,
|
|
445
|
-
)
|
|
446
|
-
|
|
447
|
-
type OutputBody = l.InferMethodOutputBody<typeof _procedure, BinaryValue>
|
|
448
|
-
|
|
449
|
-
expectType<OutputBody>(binaryValue)
|
|
450
|
-
// @ts-expect-error
|
|
451
|
-
expectType<OutputBody>(new Uint8Array())
|
|
452
|
-
// @ts-expect-error
|
|
453
|
-
expectType<OutputBody>({ data: 'foo' })
|
|
454
|
-
})
|
|
455
|
-
})
|
|
456
|
-
})
|
|
457
|
-
|
|
458
|
-
describe('InferMethodOutputEncoding', () => {
|
|
459
|
-
describe('query', () => {
|
|
460
|
-
test('with payload schema', () => {
|
|
461
|
-
const _query = l.query(
|
|
462
|
-
'com.example.query',
|
|
463
|
-
l.params(),
|
|
464
|
-
l.jsonPayload({ data: l.string() }),
|
|
465
|
-
)
|
|
466
|
-
|
|
467
|
-
type OutputEncoding = l.InferMethodOutputEncoding<typeof _query>
|
|
468
|
-
|
|
469
|
-
expectType<OutputEncoding>('application/json')
|
|
470
|
-
// @ts-expect-error
|
|
471
|
-
expectType<OutputEncoding>('text/plain')
|
|
472
|
-
// @ts-expect-error
|
|
473
|
-
expectType<OutputEncoding>(123)
|
|
474
|
-
})
|
|
475
|
-
|
|
476
|
-
test('without payload schema', () => {
|
|
477
|
-
const _query = l.query(
|
|
478
|
-
'com.example.query',
|
|
479
|
-
l.params(),
|
|
480
|
-
l.payload('*/*', undefined),
|
|
481
|
-
)
|
|
482
|
-
|
|
483
|
-
type OutputEncoding = l.InferMethodOutputEncoding<typeof _query>
|
|
484
|
-
|
|
485
|
-
expectType<OutputEncoding>('image/png')
|
|
486
|
-
expectType<OutputEncoding>('application/octet-stream')
|
|
487
|
-
// @ts-expect-error
|
|
488
|
-
expectType<OutputEncoding>(123)
|
|
489
|
-
})
|
|
490
|
-
})
|
|
491
|
-
|
|
492
|
-
describe('procedure', () => {
|
|
493
|
-
test('with payload schema', () => {
|
|
494
|
-
const _procedure = l.procedure(
|
|
495
|
-
'com.example.create',
|
|
496
|
-
l.params(),
|
|
497
|
-
l.payload(),
|
|
498
|
-
l.jsonPayload({ id: l.string() }),
|
|
499
|
-
undefined,
|
|
500
|
-
)
|
|
501
|
-
|
|
502
|
-
type OutputEncoding = l.InferMethodOutputEncoding<typeof _procedure>
|
|
503
|
-
|
|
504
|
-
expectType<OutputEncoding>('application/json')
|
|
505
|
-
// @ts-expect-error
|
|
506
|
-
expectType<OutputEncoding>('text/plain')
|
|
507
|
-
// @ts-expect-error
|
|
508
|
-
expectType<OutputEncoding>(123)
|
|
509
|
-
})
|
|
510
|
-
|
|
511
|
-
test('without payload schema', () => {
|
|
512
|
-
const _procedure = l.procedure(
|
|
513
|
-
'com.example.export',
|
|
514
|
-
l.params(),
|
|
515
|
-
l.payload(),
|
|
516
|
-
l.payload('*/*', undefined),
|
|
517
|
-
undefined,
|
|
518
|
-
)
|
|
519
|
-
|
|
520
|
-
type OutputEncoding = l.InferMethodOutputEncoding<typeof _procedure>
|
|
521
|
-
|
|
522
|
-
expectType<OutputEncoding>('application/zip')
|
|
523
|
-
expectType<OutputEncoding>('application/octet-stream')
|
|
524
|
-
// @ts-expect-error
|
|
525
|
-
expectType<OutputEncoding>(123)
|
|
526
|
-
})
|
|
527
|
-
})
|
|
528
|
-
})
|
|
529
|
-
|
|
530
|
-
describe('InferMethodMessage', () => {
|
|
531
|
-
describe('subscription', () => {
|
|
532
|
-
test('with message schema', () => {
|
|
533
|
-
const _subscription = l.subscription(
|
|
534
|
-
'com.example.subscribe',
|
|
535
|
-
l.params(),
|
|
536
|
-
l.object({
|
|
537
|
-
seq: l.integer(),
|
|
538
|
-
event: l.string(),
|
|
539
|
-
}),
|
|
540
|
-
)
|
|
541
|
-
|
|
542
|
-
type Message = l.InferMethodMessage<typeof _subscription>
|
|
543
|
-
|
|
544
|
-
expectType<Message>({ seq: 1, event: 'create' })
|
|
545
|
-
// @ts-expect-error
|
|
546
|
-
expectType<Message>({ seq: '1', event: 'create' })
|
|
547
|
-
// @ts-expect-error
|
|
548
|
-
expectType<Message>({ seq: 1 })
|
|
549
|
-
// @ts-expect-error
|
|
550
|
-
expectType<Message>(binaryValue)
|
|
551
|
-
})
|
|
552
|
-
|
|
553
|
-
test('without message schema', () => {
|
|
554
|
-
const _subscription = l.subscription(
|
|
555
|
-
'com.example.subscribe',
|
|
556
|
-
l.params(),
|
|
557
|
-
l.integer(),
|
|
558
|
-
)
|
|
559
|
-
|
|
560
|
-
type Message = l.InferMethodMessage<typeof _subscription>
|
|
561
|
-
|
|
562
|
-
// @ts-expect-error "unknown" is turned into LexValue
|
|
563
|
-
expectType<Message>(undefined)
|
|
564
|
-
// @ts-expect-error Not a LexValue
|
|
565
|
-
expectType<Message>({ any: 'value' })
|
|
566
|
-
expectType<Message>(123)
|
|
567
|
-
})
|
|
568
|
-
})
|
|
569
|
-
})
|
|
570
|
-
|
|
571
|
-
describe(l.atUri, () => {
|
|
572
|
-
describe('string collection', () => {
|
|
573
|
-
const did = 'did:example:alice'
|
|
574
|
-
|
|
575
|
-
it('builds a valid record URI', () => {
|
|
576
|
-
const uri = l.atUri(did, 'com.ex.foo', 'bar')
|
|
577
|
-
expect(uri).toBe('at://did:example:alice/com.ex.foo/bar')
|
|
578
|
-
expectTypeOf(uri).toEqualTypeOf<`at://did:example:alice/com.ex.foo/bar`>()
|
|
579
|
-
})
|
|
580
|
-
|
|
581
|
-
it('validates record key values', () => {
|
|
582
|
-
expect(() => {
|
|
583
|
-
// @ts-expect-error
|
|
584
|
-
l.atUri(did, 'com.ex.foo', '.')
|
|
585
|
-
}).toThrow()
|
|
586
|
-
expect(() => {
|
|
587
|
-
// @ts-expect-error
|
|
588
|
-
l.atUri(did, 'com.ex.foo', '..')
|
|
589
|
-
}).toThrow()
|
|
590
|
-
})
|
|
591
|
-
|
|
592
|
-
it('expects a second argument', () => {
|
|
593
|
-
expect(() => {
|
|
594
|
-
// @ts-expect-error
|
|
595
|
-
l.atUri(did, 'com.ex.foo')
|
|
596
|
-
}).toThrow()
|
|
597
|
-
})
|
|
598
|
-
})
|
|
599
|
-
|
|
600
|
-
describe('literal', () => {
|
|
601
|
-
const schema = l.record('literal:bar', 'com.ex.foo', l.object({}))
|
|
602
|
-
const did = 'did:example:alice'
|
|
603
|
-
|
|
604
|
-
it('allows omitting the record key for literal keys', () => {
|
|
605
|
-
const uri = l.atUri(did, schema)
|
|
606
|
-
expect(uri).toBe('at://did:example:alice/com.ex.foo/bar')
|
|
607
|
-
expectTypeOf(uri).toEqualTypeOf<`at://did:example:alice/com.ex.foo/bar`>()
|
|
608
|
-
})
|
|
609
|
-
|
|
610
|
-
it('still allows providing the record key for literal keys', () => {
|
|
611
|
-
expectTypeOf(
|
|
612
|
-
l.atUri(did, schema, 'bar'),
|
|
613
|
-
).toEqualTypeOf<`at://did:example:alice/com.ex.foo/bar`>()
|
|
614
|
-
})
|
|
615
|
-
|
|
616
|
-
it('validates invalid record keys', () => {
|
|
617
|
-
expect(() => {
|
|
618
|
-
// @ts-expect-error
|
|
619
|
-
l.atUri(did, schema, 'wrong')
|
|
620
|
-
}).toThrow()
|
|
621
|
-
})
|
|
622
|
-
})
|
|
623
|
-
|
|
624
|
-
describe('tid', () => {
|
|
625
|
-
const schema = l.record('tid', 'com.ex.foo', l.object({}))
|
|
626
|
-
const did = 'did:example:alice'
|
|
627
|
-
|
|
628
|
-
it('builds a valid record URI', () => {
|
|
629
|
-
const uri = l.atUri(did, schema, '3jzfcijpj2z2a')
|
|
630
|
-
expectTypeOf(
|
|
631
|
-
uri,
|
|
632
|
-
).toEqualTypeOf<`at://did:example:alice/com.ex.foo/3jzfcijpj2z2a`>()
|
|
633
|
-
expect(uri).toBe('at://did:example:alice/com.ex.foo/3jzfcijpj2z2a')
|
|
634
|
-
})
|
|
635
|
-
|
|
636
|
-
it('expects a second argument for non-literal keys', () => {
|
|
637
|
-
expect(() => {
|
|
638
|
-
// @ts-expect-error
|
|
639
|
-
l.atUri(did, schema)
|
|
640
|
-
}).toThrow()
|
|
641
|
-
})
|
|
642
|
-
|
|
643
|
-
it('validates the record key value', () => {
|
|
644
|
-
expect(() => {
|
|
645
|
-
l.atUri(did, schema, 'invalid-tid')
|
|
646
|
-
}).toThrow()
|
|
647
|
-
})
|
|
648
|
-
})
|
|
649
|
-
|
|
650
|
-
describe('any', () => {
|
|
651
|
-
const schema = l.record('any', 'com.ex.foo', l.object({}))
|
|
652
|
-
const did = 'did:example:alice'
|
|
653
|
-
|
|
654
|
-
it('builds a valid record URI valid keys', () => {
|
|
655
|
-
const uri = l.atUri(did, schema, 'customKey')
|
|
656
|
-
expect(uri).toBe('at://did:example:alice/com.ex.foo/customKey')
|
|
657
|
-
expectTypeOf(
|
|
658
|
-
uri,
|
|
659
|
-
).toEqualTypeOf<`at://did:example:alice/com.ex.foo/customKey`>()
|
|
660
|
-
})
|
|
661
|
-
|
|
662
|
-
it('rejects invalid record key values', () => {
|
|
663
|
-
expect(() => {
|
|
664
|
-
// @ts-expect-error
|
|
665
|
-
l.atUri(did, schema, '.')
|
|
666
|
-
}).toThrow()
|
|
667
|
-
expect(() => {
|
|
668
|
-
// @ts-expect-error
|
|
669
|
-
l.atUri(did, schema, '..')
|
|
670
|
-
}).toThrow()
|
|
671
|
-
})
|
|
672
|
-
|
|
673
|
-
it('expects a second argument', () => {
|
|
674
|
-
expect(() => {
|
|
675
|
-
// @ts-expect-error
|
|
676
|
-
l.atUri(did, schema)
|
|
677
|
-
}).toThrow()
|
|
678
|
-
})
|
|
679
|
-
|
|
680
|
-
describe('edge cases', () => {
|
|
681
|
-
it('limits the record key to 512 characters', () => {
|
|
682
|
-
const uri = l.atUri(did, schema, 'a'.repeat(512))
|
|
683
|
-
|
|
684
|
-
expect(uri).toBe(`at://did:example:alice/com.ex.foo/${'a'.repeat(512)}`)
|
|
685
|
-
expectTypeOf(
|
|
686
|
-
uri,
|
|
687
|
-
).toEqualTypeOf<`at://did:example:alice/com.ex.foo/${string}`>()
|
|
688
|
-
expect(() => {
|
|
689
|
-
l.atUri(did, schema, 'a'.repeat(513))
|
|
690
|
-
}).toThrow()
|
|
691
|
-
})
|
|
692
|
-
})
|
|
693
|
-
})
|
|
694
|
-
})
|