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