@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
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { object } from './object.js'
|
|
3
|
-
import { params } from './params.js'
|
|
4
|
-
import { payload } from './payload.js'
|
|
5
|
-
import { procedure } from './procedure.js'
|
|
6
|
-
import { string } from './string.js'
|
|
7
|
-
|
|
8
|
-
describe('Procedure', () => {
|
|
9
|
-
describe('basic construction', () => {
|
|
10
|
-
it('creates a procedure with all parameters', () => {
|
|
11
|
-
const errors = ['InvalidRequest', 'Unauthorized'] as const
|
|
12
|
-
|
|
13
|
-
const createPost = procedure(
|
|
14
|
-
'com.example.createPost',
|
|
15
|
-
params(),
|
|
16
|
-
payload('application/json', undefined),
|
|
17
|
-
payload('application/json', undefined),
|
|
18
|
-
errors,
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
expect(createPost.nsid).toBe('com.example.createPost')
|
|
22
|
-
expect(createPost.parameters).toEqual(params())
|
|
23
|
-
expect(createPost.input).toEqual(payload('application/json', undefined))
|
|
24
|
-
expect(createPost.output).toEqual(payload('application/json', undefined))
|
|
25
|
-
expect(createPost.errors).toBe(errors)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('creates a procedure without errors', () => {
|
|
29
|
-
const doSomething = procedure(
|
|
30
|
-
'com.example.doSomething',
|
|
31
|
-
params(),
|
|
32
|
-
payload('application/json', undefined),
|
|
33
|
-
payload('application/json', undefined),
|
|
34
|
-
undefined,
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
expect(doSomething.nsid).toBe('com.example.doSomething')
|
|
38
|
-
expect(doSomething.parameters).toEqual(params())
|
|
39
|
-
expect(doSomething.input).toEqual(payload('application/json', undefined))
|
|
40
|
-
expect(doSomething.output).toEqual(payload('application/json', undefined))
|
|
41
|
-
expect(doSomething.errors).toBeUndefined()
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('creates a procedure with empty errors array', () => {
|
|
45
|
-
const performAction = procedure(
|
|
46
|
-
'com.example.performAction',
|
|
47
|
-
params(),
|
|
48
|
-
payload('application/json', undefined),
|
|
49
|
-
payload('application/json', undefined),
|
|
50
|
-
[] as const,
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
expect(performAction.errors).toEqual([])
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
describe('with parameters schema', () => {
|
|
58
|
-
it('creates a procedure with query parameters', () => {
|
|
59
|
-
const listPosts = procedure(
|
|
60
|
-
'com.example.listPosts',
|
|
61
|
-
params({
|
|
62
|
-
limit: string(),
|
|
63
|
-
cursor: string(),
|
|
64
|
-
}),
|
|
65
|
-
payload(undefined, undefined),
|
|
66
|
-
payload('application/json', undefined),
|
|
67
|
-
undefined,
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
expect(listPosts.parameters.shape).toHaveProperty('limit')
|
|
71
|
-
expect(listPosts.parameters.shape).toHaveProperty('cursor')
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it('creates a procedure with empty parameters', () => {
|
|
75
|
-
const myProcedure = procedure(
|
|
76
|
-
'com.example.action',
|
|
77
|
-
params(),
|
|
78
|
-
payload('application/json', undefined),
|
|
79
|
-
payload('application/json', undefined),
|
|
80
|
-
undefined,
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
expect(Object.keys(myProcedure.parameters.shape)).toHaveLength(0)
|
|
84
|
-
})
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
describe('with input payload', () => {
|
|
88
|
-
it('creates a procedure with JSON input', () => {
|
|
89
|
-
const inputSchema = object({
|
|
90
|
-
text: string(),
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
const myProcedure = procedure(
|
|
94
|
-
'com.example.createPost',
|
|
95
|
-
params(),
|
|
96
|
-
payload('application/json', inputSchema),
|
|
97
|
-
payload('application/json', undefined),
|
|
98
|
-
undefined,
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
expect(myProcedure.input.encoding).toBe('application/json')
|
|
102
|
-
expect(myProcedure.input.schema).toBe(inputSchema)
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it('creates a procedure with text input', () => {
|
|
106
|
-
const myProcedure = procedure(
|
|
107
|
-
'com.example.uploadText',
|
|
108
|
-
params(),
|
|
109
|
-
payload('text/plain', undefined),
|
|
110
|
-
payload('application/json', undefined),
|
|
111
|
-
undefined,
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
expect(myProcedure.input.encoding).toBe('text/plain')
|
|
115
|
-
expect(myProcedure.input.schema).toBeUndefined()
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
it('creates a procedure with binary input', () => {
|
|
119
|
-
const myProcedure = procedure(
|
|
120
|
-
'com.example.uploadBlob',
|
|
121
|
-
params(),
|
|
122
|
-
payload('application/octet-stream', undefined),
|
|
123
|
-
payload('application/json', undefined),
|
|
124
|
-
undefined,
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
expect(myProcedure.input.encoding).toBe('application/octet-stream')
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
it('creates a procedure with no input', () => {
|
|
131
|
-
const myProcedure = procedure(
|
|
132
|
-
'com.example.action',
|
|
133
|
-
params(),
|
|
134
|
-
payload(undefined, undefined),
|
|
135
|
-
payload('application/json', undefined),
|
|
136
|
-
undefined,
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
expect(myProcedure.input.encoding).toBeUndefined()
|
|
140
|
-
expect(myProcedure.input.schema).toBeUndefined()
|
|
141
|
-
})
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
describe('with output payload', () => {
|
|
145
|
-
it('creates a procedure with JSON output', () => {
|
|
146
|
-
const outputSchema = object({
|
|
147
|
-
uri: string(),
|
|
148
|
-
cid: string(),
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
const myProcedure = procedure(
|
|
152
|
-
'com.example.getPost',
|
|
153
|
-
params(),
|
|
154
|
-
payload(undefined, undefined),
|
|
155
|
-
payload('application/json', outputSchema),
|
|
156
|
-
undefined,
|
|
157
|
-
)
|
|
158
|
-
|
|
159
|
-
expect(myProcedure.output.encoding).toBe('application/json')
|
|
160
|
-
expect(myProcedure.output.schema).toBe(outputSchema)
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
it('creates a procedure with text output', () => {
|
|
164
|
-
const myProcedure = procedure(
|
|
165
|
-
'com.example.export',
|
|
166
|
-
params(),
|
|
167
|
-
payload(undefined, undefined),
|
|
168
|
-
payload('text/plain', undefined),
|
|
169
|
-
undefined,
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
expect(myProcedure.output.encoding).toBe('text/plain')
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
it('creates a procedure with binary output', () => {
|
|
176
|
-
const myProcedure = procedure(
|
|
177
|
-
'com.example.download',
|
|
178
|
-
params(),
|
|
179
|
-
payload(undefined, undefined),
|
|
180
|
-
payload('application/octet-stream', undefined),
|
|
181
|
-
undefined,
|
|
182
|
-
)
|
|
183
|
-
|
|
184
|
-
expect(myProcedure.output.encoding).toBe('application/octet-stream')
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
it('creates a procedure with no output', () => {
|
|
188
|
-
const myProcedure = procedure(
|
|
189
|
-
'com.example.deletePost',
|
|
190
|
-
params(),
|
|
191
|
-
payload('application/json', undefined),
|
|
192
|
-
payload(undefined, undefined),
|
|
193
|
-
undefined,
|
|
194
|
-
)
|
|
195
|
-
|
|
196
|
-
expect(myProcedure.output.encoding).toBeUndefined()
|
|
197
|
-
expect(myProcedure.output.schema).toBeUndefined()
|
|
198
|
-
})
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
describe('with error definitions', () => {
|
|
202
|
-
it('creates a procedure with single error', () => {
|
|
203
|
-
const myProcedure = procedure(
|
|
204
|
-
'com.example.action',
|
|
205
|
-
params(),
|
|
206
|
-
payload('application/json', undefined),
|
|
207
|
-
payload('application/json', undefined),
|
|
208
|
-
['InvalidRequest'] as const,
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
expect(myProcedure.errors).toEqual(['InvalidRequest'])
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
it('creates a procedure with multiple errors', () => {
|
|
215
|
-
const myProcedure = procedure(
|
|
216
|
-
'com.example.createPost',
|
|
217
|
-
params(),
|
|
218
|
-
payload('application/json', undefined),
|
|
219
|
-
payload('application/json', undefined),
|
|
220
|
-
['InvalidRequest', 'Unauthorized', 'RateLimitExceeded'] as const,
|
|
221
|
-
)
|
|
222
|
-
|
|
223
|
-
expect(myProcedure.errors).toHaveLength(3)
|
|
224
|
-
expect(myProcedure.errors).toContain('InvalidRequest')
|
|
225
|
-
expect(myProcedure.errors).toContain('Unauthorized')
|
|
226
|
-
expect(myProcedure.errors).toContain('RateLimitExceeded')
|
|
227
|
-
})
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
describe('property access', () => {
|
|
231
|
-
it('provides access to all properties', () => {
|
|
232
|
-
const errors = ['Error1', 'Error2'] as const
|
|
233
|
-
|
|
234
|
-
const myProcedure = procedure(
|
|
235
|
-
'com.example.test',
|
|
236
|
-
params(),
|
|
237
|
-
payload('application/json', undefined),
|
|
238
|
-
payload('application/json', undefined),
|
|
239
|
-
errors,
|
|
240
|
-
)
|
|
241
|
-
|
|
242
|
-
expect(myProcedure.nsid).toBe('com.example.test')
|
|
243
|
-
expect(myProcedure.parameters).toEqual(params())
|
|
244
|
-
expect(myProcedure.input).toEqual(payload('application/json', undefined))
|
|
245
|
-
expect(myProcedure.output).toEqual(payload('application/json', undefined))
|
|
246
|
-
expect(myProcedure.errors).toBe(errors)
|
|
247
|
-
})
|
|
248
|
-
|
|
249
|
-
it('maintains reference equality for complex properties', () => {
|
|
250
|
-
const parameters = params({ test: string() })
|
|
251
|
-
const inputSchema = object({ field: string() })
|
|
252
|
-
const outputSchema = object({ result: string() })
|
|
253
|
-
const input = payload('application/json', inputSchema)
|
|
254
|
-
const output = payload('application/json', outputSchema)
|
|
255
|
-
|
|
256
|
-
const myProcedure = procedure(
|
|
257
|
-
'com.example.test',
|
|
258
|
-
parameters,
|
|
259
|
-
input,
|
|
260
|
-
output,
|
|
261
|
-
undefined,
|
|
262
|
-
)
|
|
263
|
-
|
|
264
|
-
// Verify references are maintained
|
|
265
|
-
expect(myProcedure.parameters).toBe(parameters)
|
|
266
|
-
expect(myProcedure.input).toBe(input)
|
|
267
|
-
expect(myProcedure.output).toBe(output)
|
|
268
|
-
expect(myProcedure.input.schema).toBe(inputSchema)
|
|
269
|
-
expect(myProcedure.output.schema).toBe(outputSchema)
|
|
270
|
-
})
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
describe('complex scenarios', () => {
|
|
274
|
-
it('creates a fully-featured procedure', () => {
|
|
275
|
-
const inputSchema = object({
|
|
276
|
-
text: string(),
|
|
277
|
-
mentions: string(),
|
|
278
|
-
})
|
|
279
|
-
const outputSchema = object({
|
|
280
|
-
messageId: string(),
|
|
281
|
-
timestamp: string(),
|
|
282
|
-
})
|
|
283
|
-
const errors = [
|
|
284
|
-
'ConversationNotFound',
|
|
285
|
-
'MessageTooLong',
|
|
286
|
-
'RateLimitExceeded',
|
|
287
|
-
] as const
|
|
288
|
-
|
|
289
|
-
const myProcedure = procedure(
|
|
290
|
-
'com.example.chat.sendMessage',
|
|
291
|
-
params({
|
|
292
|
-
conversationId: string(),
|
|
293
|
-
}),
|
|
294
|
-
payload('application/json', inputSchema),
|
|
295
|
-
payload('application/json', outputSchema),
|
|
296
|
-
errors,
|
|
297
|
-
)
|
|
298
|
-
|
|
299
|
-
expect(myProcedure.nsid).toBe('com.example.chat.sendMessage')
|
|
300
|
-
expect(myProcedure.parameters.shape).toHaveProperty('conversationId')
|
|
301
|
-
expect(myProcedure.input.encoding).toBe('application/json')
|
|
302
|
-
expect(myProcedure.input.schema).toBe(inputSchema)
|
|
303
|
-
expect(myProcedure.output.encoding).toBe('application/json')
|
|
304
|
-
expect(myProcedure.output.schema).toBe(outputSchema)
|
|
305
|
-
expect(myProcedure.errors).toEqual(errors)
|
|
306
|
-
})
|
|
307
|
-
|
|
308
|
-
it('creates a minimal procedure', () => {
|
|
309
|
-
const myProcedure = procedure(
|
|
310
|
-
'com.example.ping',
|
|
311
|
-
params(),
|
|
312
|
-
payload(undefined, undefined),
|
|
313
|
-
payload(undefined, undefined),
|
|
314
|
-
undefined,
|
|
315
|
-
)
|
|
316
|
-
|
|
317
|
-
expect(myProcedure.nsid).toBe('com.example.ping')
|
|
318
|
-
expect(Object.keys(myProcedure.parameters.shape)).toHaveLength(0)
|
|
319
|
-
expect(myProcedure.input.encoding).toBeUndefined()
|
|
320
|
-
expect(myProcedure.output.encoding).toBeUndefined()
|
|
321
|
-
expect(myProcedure.errors).toBeUndefined()
|
|
322
|
-
})
|
|
323
|
-
})
|
|
324
|
-
})
|
package/src/schema/procedure.ts
DELETED
|
@@ -1,98 +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 procedure (HTTP POST) endpoint definition.
|
|
7
|
-
*
|
|
8
|
-
* Procedures are operations that may modify state on the server.
|
|
9
|
-
* They have parameters, an input payload (request body), an output
|
|
10
|
-
* payload (response body), and optional error types.
|
|
11
|
-
*
|
|
12
|
-
* @template TNsid - The NSID identifying this procedure
|
|
13
|
-
* @template TParameters - The parameters schema type
|
|
14
|
-
* @template TInputPayload - The request body payload type
|
|
15
|
-
* @template TOutputPayload - The response body payload type
|
|
16
|
-
* @template TErrors - Array of error type strings, or undefined
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* const createPost = new Procedure(
|
|
21
|
-
* 'app.bsky.feed.post',
|
|
22
|
-
* l.params({}),
|
|
23
|
-
* l.jsonPayload({ text: l.string() }),
|
|
24
|
-
* l.jsonPayload({ uri: l.string(), cid: l.string() }),
|
|
25
|
-
* ['InvalidRecord']
|
|
26
|
-
* )
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export class Procedure<
|
|
30
|
-
const TNsid extends NsidString = NsidString,
|
|
31
|
-
const TParameters extends ParamsSchema = ParamsSchema,
|
|
32
|
-
const TInputPayload extends Payload = Payload,
|
|
33
|
-
const TOutputPayload extends Payload = Payload,
|
|
34
|
-
const TErrors extends undefined | readonly string[] =
|
|
35
|
-
| undefined
|
|
36
|
-
| readonly string[],
|
|
37
|
-
> {
|
|
38
|
-
readonly type = 'procedure' as const
|
|
39
|
-
|
|
40
|
-
constructor(
|
|
41
|
-
readonly nsid: TNsid,
|
|
42
|
-
readonly parameters: TParameters,
|
|
43
|
-
readonly input: TInputPayload,
|
|
44
|
-
readonly output: TOutputPayload,
|
|
45
|
-
readonly errors: TErrors,
|
|
46
|
-
) {}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Creates a procedure definition for a Lexicon POST endpoint.
|
|
51
|
-
*
|
|
52
|
-
* Procedures can modify server state. They accept both URL parameters
|
|
53
|
-
* and a request body (input payload).
|
|
54
|
-
*
|
|
55
|
-
* @param nsid - The NSID identifying this procedure endpoint
|
|
56
|
-
* @param parameters - Schema for URL query parameters
|
|
57
|
-
* @param input - Schema for request body payload
|
|
58
|
-
* @param output - Schema for response body payload
|
|
59
|
-
* @param errors - Optional array of error type strings
|
|
60
|
-
* @returns A new {@link Procedure} instance
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* // Create record procedure
|
|
65
|
-
* const createRecord = l.procedure(
|
|
66
|
-
* 'com.atproto.repo.createRecord',
|
|
67
|
-
* l.params({}),
|
|
68
|
-
* l.jsonPayload({
|
|
69
|
-
* repo: l.string({ format: 'at-identifier' }),
|
|
70
|
-
* collection: l.string({ format: 'nsid' }),
|
|
71
|
-
* record: l.unknown(),
|
|
72
|
-
* }),
|
|
73
|
-
* l.jsonPayload({
|
|
74
|
-
* uri: l.string({ format: 'at-uri' }),
|
|
75
|
-
* cid: l.string({ format: 'cid' }),
|
|
76
|
-
* }),
|
|
77
|
-
* ['InvalidRecord', 'RepoNotFound'],
|
|
78
|
-
* )
|
|
79
|
-
*
|
|
80
|
-
* // Procedure with binary input
|
|
81
|
-
* const uploadBlob = l.procedure(
|
|
82
|
-
* 'com.atproto.repo.uploadBlob',
|
|
83
|
-
* l.params({}),
|
|
84
|
-
* l.payload('*\/*', undefined), // Accept any content type
|
|
85
|
-
* l.jsonPayload({ blob: l.blob() }),
|
|
86
|
-
* )
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
90
|
-
export function procedure<
|
|
91
|
-
const N extends NsidString,
|
|
92
|
-
const P extends ParamsSchema,
|
|
93
|
-
const I extends Payload,
|
|
94
|
-
const O extends Payload,
|
|
95
|
-
const E extends undefined | readonly string[] = undefined,
|
|
96
|
-
>(nsid: N, parameters: P, input: I, output: O, errors: E = undefined as E) {
|
|
97
|
-
return new Procedure<N, P, I, O, E>(nsid, parameters, input, output, errors)
|
|
98
|
-
}
|