@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/schema/query.test.ts
DELETED
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { integer } from './integer.js'
|
|
3
|
-
import { ObjectSchema, object } from './object.js'
|
|
4
|
-
import { optional } from './optional.js'
|
|
5
|
-
import { ParamsSchema, params } from './params.js'
|
|
6
|
-
import { Payload, payload } from './payload.js'
|
|
7
|
-
import { Query, query } from './query.js'
|
|
8
|
-
import { string } from './string.js'
|
|
9
|
-
import { withDefault } from './with-default.js'
|
|
10
|
-
|
|
11
|
-
describe('Query', () => {
|
|
12
|
-
describe('constructor', () => {
|
|
13
|
-
it('creates a Query instance with all parameters', () => {
|
|
14
|
-
const nsid = 'app.bsky.feed.getFeedSkeleton'
|
|
15
|
-
const parameters = params({
|
|
16
|
-
feed: string({ format: 'at-uri' }),
|
|
17
|
-
limit: optional(integer({ minimum: 1, maximum: 100 })),
|
|
18
|
-
})
|
|
19
|
-
const output = payload(
|
|
20
|
-
'application/json',
|
|
21
|
-
object({
|
|
22
|
-
feed: string({ format: 'at-uri' }),
|
|
23
|
-
}),
|
|
24
|
-
)
|
|
25
|
-
const errors = ['NotFound', 'RateLimitExceeded'] as const
|
|
26
|
-
|
|
27
|
-
const myQuery = query(nsid, parameters, output, errors)
|
|
28
|
-
|
|
29
|
-
expect(myQuery).toBeInstanceOf(Query)
|
|
30
|
-
expect(myQuery.nsid).toBe(nsid)
|
|
31
|
-
expect(myQuery.parameters).toBe(parameters)
|
|
32
|
-
expect(myQuery.output).toBe(output)
|
|
33
|
-
expect(myQuery.errors).toBe(errors)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('creates a Query instance without errors', () => {
|
|
37
|
-
const nsid = 'app.bsky.feed.getFeedSkeleton'
|
|
38
|
-
const parameters = params({
|
|
39
|
-
feed: string({ format: 'at-uri' }),
|
|
40
|
-
})
|
|
41
|
-
const output = payload(
|
|
42
|
-
'application/json',
|
|
43
|
-
object({
|
|
44
|
-
feed: string({ format: 'at-uri' }),
|
|
45
|
-
}),
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
const myQuery = query(nsid, parameters, output, undefined)
|
|
49
|
-
|
|
50
|
-
expect(myQuery).toBeInstanceOf(Query)
|
|
51
|
-
expect(myQuery.nsid).toBe(nsid)
|
|
52
|
-
expect(myQuery.parameters).toBe(parameters)
|
|
53
|
-
expect(myQuery.output).toBe(output)
|
|
54
|
-
expect(myQuery.errors).toBeUndefined()
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it('creates a Query instance with empty parameters', () => {
|
|
58
|
-
const nsid = 'app.bsky.actor.getProfile'
|
|
59
|
-
const parameters = params()
|
|
60
|
-
const output = payload(
|
|
61
|
-
'application/json',
|
|
62
|
-
object({
|
|
63
|
-
did: string({ format: 'did' }),
|
|
64
|
-
}),
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
const myQuery = query(nsid, parameters, output, undefined)
|
|
68
|
-
|
|
69
|
-
expect(myQuery).toBeInstanceOf(Query)
|
|
70
|
-
expect(myQuery.parameters).toBe(parameters)
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
describe('properties', () => {
|
|
75
|
-
it('has nsid property', () => {
|
|
76
|
-
const nsid = 'app.bsky.feed.getFeedSkeleton'
|
|
77
|
-
const parameters = params()
|
|
78
|
-
const output = payload('application/json', undefined)
|
|
79
|
-
|
|
80
|
-
const myQuery = query(nsid, parameters, output, undefined)
|
|
81
|
-
|
|
82
|
-
expect(myQuery.nsid).toBe(nsid)
|
|
83
|
-
expect(myQuery.nsid).toBe('app.bsky.feed.getFeedSkeleton')
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
it('has parameters property', () => {
|
|
87
|
-
const nsid = 'app.bsky.feed.getFeedSkeleton'
|
|
88
|
-
const parameters = params({
|
|
89
|
-
feed: string({ format: 'at-uri' }),
|
|
90
|
-
})
|
|
91
|
-
const output = payload('application/json', undefined)
|
|
92
|
-
|
|
93
|
-
const myQuery = query(nsid, parameters, output, undefined)
|
|
94
|
-
|
|
95
|
-
expect(myQuery.parameters).toBe(parameters)
|
|
96
|
-
expect(myQuery.parameters).toBeInstanceOf(ParamsSchema)
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
it('has output property', () => {
|
|
100
|
-
const nsid = 'app.bsky.feed.getFeedSkeleton'
|
|
101
|
-
const parameters = params()
|
|
102
|
-
const output = payload('application/json', undefined)
|
|
103
|
-
|
|
104
|
-
const myQuery = query(nsid, parameters, output, undefined)
|
|
105
|
-
|
|
106
|
-
expect(myQuery.output).toBe(output)
|
|
107
|
-
expect(myQuery.output).toBeInstanceOf(Payload)
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
it('has errors property', () => {
|
|
111
|
-
const nsid = 'app.bsky.feed.getFeedSkeleton'
|
|
112
|
-
const parameters = params()
|
|
113
|
-
const output = payload('application/json', undefined)
|
|
114
|
-
const errors = ['NotFound', 'RateLimitExceeded'] as const
|
|
115
|
-
|
|
116
|
-
const myQuery = query(nsid, parameters, output, errors)
|
|
117
|
-
|
|
118
|
-
expect(myQuery.errors).toBe(errors)
|
|
119
|
-
expect(myQuery.errors).toEqual(['NotFound', 'RateLimitExceeded'])
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
describe('with complex parameters', () => {
|
|
124
|
-
it('creates a Query with multiple parameter types', () => {
|
|
125
|
-
const nsid = 'app.bsky.feed.searchPosts'
|
|
126
|
-
const parameters = params({
|
|
127
|
-
q: string({ minLength: 1 }),
|
|
128
|
-
limit: optional(integer({ minimum: 1, maximum: 100 })),
|
|
129
|
-
cursor: optional(string()),
|
|
130
|
-
author: optional(string({ format: 'did' })),
|
|
131
|
-
})
|
|
132
|
-
const output = payload(
|
|
133
|
-
'application/json',
|
|
134
|
-
object({
|
|
135
|
-
cursor: optional(string()),
|
|
136
|
-
posts: object({}),
|
|
137
|
-
}),
|
|
138
|
-
)
|
|
139
|
-
const errors = ['BadRequest', 'RateLimitExceeded'] as const
|
|
140
|
-
|
|
141
|
-
const myQuery = query(nsid, parameters, output, errors)
|
|
142
|
-
|
|
143
|
-
expect(myQuery).toBeInstanceOf(Query)
|
|
144
|
-
expect(myQuery.parameters).toBe(parameters)
|
|
145
|
-
expect(myQuery.errors).toEqual(['BadRequest', 'RateLimitExceeded'])
|
|
146
|
-
})
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
describe('with various output payloads', () => {
|
|
150
|
-
it('creates a Query with undefined output payload', () => {
|
|
151
|
-
const nsid = 'app.bsky.actor.getProfile'
|
|
152
|
-
const parameters = params({
|
|
153
|
-
actor: string({ format: 'at-identifier' }),
|
|
154
|
-
})
|
|
155
|
-
const output = payload(undefined, undefined)
|
|
156
|
-
|
|
157
|
-
const myQuery = query(nsid, parameters, output, undefined)
|
|
158
|
-
|
|
159
|
-
expect(myQuery).toBeInstanceOf(Query)
|
|
160
|
-
expect(myQuery.output.encoding).toBeUndefined()
|
|
161
|
-
expect(myQuery.output.schema).toBeUndefined()
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
it('creates a Query with JSON payload', () => {
|
|
165
|
-
const nsid = 'app.bsky.actor.getProfile'
|
|
166
|
-
const parameters = params({
|
|
167
|
-
actor: string({ format: 'at-identifier' }),
|
|
168
|
-
})
|
|
169
|
-
const output = payload(
|
|
170
|
-
'application/json',
|
|
171
|
-
object({
|
|
172
|
-
did: string({ format: 'did' }),
|
|
173
|
-
handle: string({ format: 'handle' }),
|
|
174
|
-
}),
|
|
175
|
-
)
|
|
176
|
-
|
|
177
|
-
const myQuery = query(nsid, parameters, output, undefined)
|
|
178
|
-
|
|
179
|
-
expect(myQuery).toBeInstanceOf(Query)
|
|
180
|
-
expect(myQuery.output.encoding).toBe('application/json')
|
|
181
|
-
expect(myQuery.output.schema).toBeInstanceOf(ObjectSchema)
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
it('creates a Query with text payload', () => {
|
|
185
|
-
const nsid = 'app.bsky.feed.getPost'
|
|
186
|
-
const parameters = params({
|
|
187
|
-
uri: string({ format: 'at-uri' }),
|
|
188
|
-
})
|
|
189
|
-
const output = payload('text/plain', undefined)
|
|
190
|
-
|
|
191
|
-
const myQuery = query(nsid, parameters, output, undefined)
|
|
192
|
-
|
|
193
|
-
expect(myQuery).toBeInstanceOf(Query)
|
|
194
|
-
expect(myQuery.output.encoding).toBe('text/plain')
|
|
195
|
-
})
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
describe('with different error configurations', () => {
|
|
199
|
-
it('creates a Query with a single error', () => {
|
|
200
|
-
const nsid = 'app.bsky.feed.getPost'
|
|
201
|
-
const parameters = params()
|
|
202
|
-
const output = payload('application/json', undefined)
|
|
203
|
-
const errors = ['NotFound'] as const
|
|
204
|
-
|
|
205
|
-
const myQuery = query(nsid, parameters, output, errors)
|
|
206
|
-
|
|
207
|
-
expect(myQuery.errors).toEqual(['NotFound'])
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
it('creates a Query with multiple errors', () => {
|
|
211
|
-
const nsid = 'app.bsky.feed.getPost'
|
|
212
|
-
const parameters = params()
|
|
213
|
-
const output = payload('application/json', undefined)
|
|
214
|
-
const errors = ['NotFound', 'Unauthorized', 'RateLimitExceeded'] as const
|
|
215
|
-
|
|
216
|
-
const myQuery = query(nsid, parameters, output, errors)
|
|
217
|
-
|
|
218
|
-
expect(myQuery.errors).toEqual([
|
|
219
|
-
'NotFound',
|
|
220
|
-
'Unauthorized',
|
|
221
|
-
'RateLimitExceeded',
|
|
222
|
-
])
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
it('creates a Query with empty errors array', () => {
|
|
226
|
-
const nsid = 'app.bsky.feed.getPost'
|
|
227
|
-
const parameters = params()
|
|
228
|
-
const output = payload('application/json', undefined)
|
|
229
|
-
const errors = [] as const
|
|
230
|
-
|
|
231
|
-
const myQuery = query(nsid, parameters, output, errors)
|
|
232
|
-
|
|
233
|
-
expect(myQuery.errors).toEqual([])
|
|
234
|
-
})
|
|
235
|
-
})
|
|
236
|
-
|
|
237
|
-
describe('edge cases', () => {
|
|
238
|
-
it('handles very long NSID', () => {
|
|
239
|
-
const nsid = 'com.example.very.long.namespace.identifier.method.name'
|
|
240
|
-
const parameters = params()
|
|
241
|
-
const output = payload('application/json', undefined)
|
|
242
|
-
|
|
243
|
-
const myQuery = query(nsid, parameters, output, undefined)
|
|
244
|
-
|
|
245
|
-
expect(myQuery.nsid).toBe(nsid)
|
|
246
|
-
})
|
|
247
|
-
|
|
248
|
-
it('handles myQuery with all optional parameters', () => {
|
|
249
|
-
const nsid = 'app.bsky.feed.search'
|
|
250
|
-
const parameters = params({
|
|
251
|
-
q: optional(string()),
|
|
252
|
-
limit: optional(integer()),
|
|
253
|
-
cursor: optional(string()),
|
|
254
|
-
})
|
|
255
|
-
const output = payload('application/json', undefined)
|
|
256
|
-
|
|
257
|
-
const myQuery = query(nsid, parameters, output, undefined)
|
|
258
|
-
|
|
259
|
-
expect(myQuery.parameters).toBe(parameters)
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
it('handles myQuery with complex nested output schema', () => {
|
|
263
|
-
const nsid = 'app.bsky.feed.getTimeline'
|
|
264
|
-
const parameters = params()
|
|
265
|
-
const output = payload(
|
|
266
|
-
'application/json',
|
|
267
|
-
object({
|
|
268
|
-
cursor: optional(string()),
|
|
269
|
-
feed: object({
|
|
270
|
-
post: object({
|
|
271
|
-
uri: string({ format: 'at-uri' }),
|
|
272
|
-
cid: string({ format: 'cid' }),
|
|
273
|
-
}),
|
|
274
|
-
}),
|
|
275
|
-
}),
|
|
276
|
-
)
|
|
277
|
-
|
|
278
|
-
const myQuery = query(nsid, parameters, output, undefined)
|
|
279
|
-
|
|
280
|
-
expect(myQuery.output.schema).toBeInstanceOf(ObjectSchema)
|
|
281
|
-
})
|
|
282
|
-
})
|
|
283
|
-
|
|
284
|
-
describe('real-world myQuery examples', () => {
|
|
285
|
-
it('creates a getFeedSkeleton myQuery', () => {
|
|
286
|
-
const nsid = 'app.bsky.feed.getFeedSkeleton'
|
|
287
|
-
const parameters = params({
|
|
288
|
-
feed: string({ format: 'at-uri' }),
|
|
289
|
-
limit: optional(withDefault(integer({ minimum: 1, maximum: 100 }), 50)),
|
|
290
|
-
cursor: optional(string()),
|
|
291
|
-
})
|
|
292
|
-
const output = payload(
|
|
293
|
-
'application/json',
|
|
294
|
-
object({
|
|
295
|
-
cursor: optional(string()),
|
|
296
|
-
feed: object({}),
|
|
297
|
-
}),
|
|
298
|
-
)
|
|
299
|
-
|
|
300
|
-
const myQuery = query(nsid, parameters, output, undefined)
|
|
301
|
-
|
|
302
|
-
expect(myQuery.nsid).toBe('app.bsky.feed.getFeedSkeleton')
|
|
303
|
-
})
|
|
304
|
-
|
|
305
|
-
it('creates a searchPosts myQuery', () => {
|
|
306
|
-
const nsid = 'app.bsky.feed.searchPosts'
|
|
307
|
-
const parameters = params({
|
|
308
|
-
q: string({ minLength: 1, maxLength: 300 }),
|
|
309
|
-
limit: optional(withDefault(integer({ minimum: 1, maximum: 100 }), 25)),
|
|
310
|
-
cursor: optional(string()),
|
|
311
|
-
})
|
|
312
|
-
const output = payload(
|
|
313
|
-
'application/json',
|
|
314
|
-
object({
|
|
315
|
-
cursor: optional(string()),
|
|
316
|
-
hitsTotal: optional(integer()),
|
|
317
|
-
posts: object({}),
|
|
318
|
-
}),
|
|
319
|
-
)
|
|
320
|
-
const errors = ['BadRequest'] as const
|
|
321
|
-
|
|
322
|
-
const myQuery = query(nsid, parameters, output, errors)
|
|
323
|
-
|
|
324
|
-
expect(myQuery.nsid).toBe('app.bsky.feed.searchPosts')
|
|
325
|
-
expect(myQuery.errors).toEqual(['BadRequest'])
|
|
326
|
-
})
|
|
327
|
-
|
|
328
|
-
it('creates a getProfile myQuery', () => {
|
|
329
|
-
const nsid = 'app.bsky.actor.getProfile'
|
|
330
|
-
const parameters = params({
|
|
331
|
-
actor: string({ format: 'at-identifier' }),
|
|
332
|
-
})
|
|
333
|
-
const output = payload(
|
|
334
|
-
'application/json',
|
|
335
|
-
object({
|
|
336
|
-
did: string({ format: 'did' }),
|
|
337
|
-
handle: string({ format: 'handle' }),
|
|
338
|
-
displayName: optional(string({ maxGraphemes: 64 })),
|
|
339
|
-
description: optional(string({ maxGraphemes: 256 })),
|
|
340
|
-
}),
|
|
341
|
-
)
|
|
342
|
-
|
|
343
|
-
const myQuery = query(nsid, parameters, output, undefined)
|
|
344
|
-
|
|
345
|
-
expect(myQuery.nsid).toBe('app.bsky.actor.getProfile')
|
|
346
|
-
})
|
|
347
|
-
})
|
|
348
|
-
})
|
package/src/schema/query.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { NsidString } from '../core.js'
|
|
2
|
-
import { ParamsSchema } from './params.js'
|
|
3
|
-
import { Payload } from './payload.js'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Represents a Lexicon query (HTTP GET) endpoint definition.
|
|
7
|
-
*
|
|
8
|
-
* Queries are read-only operations that retrieve data from a server.
|
|
9
|
-
* They have parameters (passed as URL query parameters), an output
|
|
10
|
-
* payload, and optional error types.
|
|
11
|
-
*
|
|
12
|
-
* @template TNsid - The NSID identifying this query
|
|
13
|
-
* @template TParameters - The parameters schema type
|
|
14
|
-
* @template TOutputPayload - The output payload type
|
|
15
|
-
* @template TErrors - Array of error type strings, or undefined
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* const getPostQuery = new Query(
|
|
20
|
-
* 'app.bsky.feed.getPost',
|
|
21
|
-
* l.params({ uri: l.string({ format: 'at-uri' }) }),
|
|
22
|
-
* l.payload('application/json', postSchema),
|
|
23
|
-
* ['NotFound']
|
|
24
|
-
* )
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export class Query<
|
|
28
|
-
const TNsid extends NsidString = NsidString,
|
|
29
|
-
const TParameters extends ParamsSchema = ParamsSchema,
|
|
30
|
-
const TOutputPayload extends Payload = Payload,
|
|
31
|
-
const TErrors extends undefined | readonly string[] =
|
|
32
|
-
| undefined
|
|
33
|
-
| readonly string[],
|
|
34
|
-
> {
|
|
35
|
-
readonly type = 'query' as const
|
|
36
|
-
|
|
37
|
-
constructor(
|
|
38
|
-
readonly nsid: TNsid,
|
|
39
|
-
readonly parameters: TParameters,
|
|
40
|
-
readonly output: TOutputPayload,
|
|
41
|
-
readonly errors: TErrors,
|
|
42
|
-
) {}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Creates a query definition for a Lexicon GET endpoint.
|
|
47
|
-
*
|
|
48
|
-
* Queries retrieve data without side effects. Parameters are sent as
|
|
49
|
-
* URL query string parameters.
|
|
50
|
-
*
|
|
51
|
-
* @param nsid - The NSID identifying this query endpoint
|
|
52
|
-
* @param parameters - Schema for URL query parameters
|
|
53
|
-
* @param output - Expected response payload schema
|
|
54
|
-
* @param errors - Optional array of error type strings
|
|
55
|
-
* @returns A new {@link Query} instance
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```ts
|
|
59
|
-
* // Simple query with JSON output
|
|
60
|
-
* const getProfile = l.query(
|
|
61
|
-
* 'app.bsky.actor.getProfile',
|
|
62
|
-
* l.params({ actor: l.string({ format: 'at-identifier' }) }),
|
|
63
|
-
* l.jsonPayload({ displayName: l.string(), handle: l.string() }),
|
|
64
|
-
* )
|
|
65
|
-
*
|
|
66
|
-
* // Query with pagination and errors
|
|
67
|
-
* const getTimeline = l.query(
|
|
68
|
-
* 'app.bsky.feed.getTimeline',
|
|
69
|
-
* l.params({
|
|
70
|
-
* limit: l.optional(l.integer({ minimum: 1, maximum: 100 })),
|
|
71
|
-
* cursor: l.optional(l.string()),
|
|
72
|
-
* }),
|
|
73
|
-
* l.jsonPayload({ feed: l.array(feedItemSchema), cursor: l.optional(l.string()) }),
|
|
74
|
-
* ['BlockedActor', 'BlockedByActor'],
|
|
75
|
-
* )
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
79
|
-
export function query<
|
|
80
|
-
const N extends NsidString,
|
|
81
|
-
const P extends ParamsSchema,
|
|
82
|
-
const O extends Payload,
|
|
83
|
-
const E extends undefined | readonly string[] = undefined,
|
|
84
|
-
>(nsid: N, parameters: P, output: O, errors: E = undefined as E) {
|
|
85
|
-
return new Query<N, P, O, E>(nsid, parameters, output, errors)
|
|
86
|
-
}
|