@atproto/lexicon 0.4.12 → 0.4.14
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 +12 -0
- package/dist/types.d.ts +305 -305
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +38 -79
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/types.ts +130 -171
- package/tests/general.test.ts +3 -2
package/src/types.ts
CHANGED
|
@@ -5,27 +5,23 @@ import { requiredPropertiesRefinement } from './util'
|
|
|
5
5
|
// primitives
|
|
6
6
|
// =
|
|
7
7
|
|
|
8
|
-
export const lexBoolean = z
|
|
9
|
-
.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
})
|
|
15
|
-
.strict()
|
|
8
|
+
export const lexBoolean = z.object({
|
|
9
|
+
type: z.literal('boolean'),
|
|
10
|
+
description: z.string().optional(),
|
|
11
|
+
default: z.boolean().optional(),
|
|
12
|
+
const: z.boolean().optional(),
|
|
13
|
+
})
|
|
16
14
|
export type LexBoolean = z.infer<typeof lexBoolean>
|
|
17
15
|
|
|
18
|
-
export const lexInteger = z
|
|
19
|
-
.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
})
|
|
28
|
-
.strict()
|
|
16
|
+
export const lexInteger = z.object({
|
|
17
|
+
type: z.literal('integer'),
|
|
18
|
+
description: z.string().optional(),
|
|
19
|
+
default: z.number().int().optional(),
|
|
20
|
+
minimum: z.number().int().optional(),
|
|
21
|
+
maximum: z.number().int().optional(),
|
|
22
|
+
enum: z.number().int().array().optional(),
|
|
23
|
+
const: z.number().int().optional(),
|
|
24
|
+
})
|
|
29
25
|
export type LexInteger = z.infer<typeof lexInteger>
|
|
30
26
|
|
|
31
27
|
export const lexStringFormat = z.enum([
|
|
@@ -43,29 +39,25 @@ export const lexStringFormat = z.enum([
|
|
|
43
39
|
])
|
|
44
40
|
export type LexStringFormat = z.infer<typeof lexStringFormat>
|
|
45
41
|
|
|
46
|
-
export const lexString = z
|
|
47
|
-
.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
})
|
|
60
|
-
.strict()
|
|
42
|
+
export const lexString = z.object({
|
|
43
|
+
type: z.literal('string'),
|
|
44
|
+
format: lexStringFormat.optional(),
|
|
45
|
+
description: z.string().optional(),
|
|
46
|
+
default: z.string().optional(),
|
|
47
|
+
minLength: z.number().int().optional(),
|
|
48
|
+
maxLength: z.number().int().optional(),
|
|
49
|
+
minGraphemes: z.number().int().optional(),
|
|
50
|
+
maxGraphemes: z.number().int().optional(),
|
|
51
|
+
enum: z.string().array().optional(),
|
|
52
|
+
const: z.string().optional(),
|
|
53
|
+
knownValues: z.string().array().optional(),
|
|
54
|
+
})
|
|
61
55
|
export type LexString = z.infer<typeof lexString>
|
|
62
56
|
|
|
63
|
-
export const lexUnknown = z
|
|
64
|
-
.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
})
|
|
68
|
-
.strict()
|
|
57
|
+
export const lexUnknown = z.object({
|
|
58
|
+
type: z.literal('unknown'),
|
|
59
|
+
description: z.string().optional(),
|
|
60
|
+
})
|
|
69
61
|
export type LexUnknown = z.infer<typeof lexUnknown>
|
|
70
62
|
|
|
71
63
|
export const lexPrimitive = z.discriminatedUnion('type', [
|
|
@@ -79,22 +71,18 @@ export type LexPrimitive = z.infer<typeof lexPrimitive>
|
|
|
79
71
|
// ipld types
|
|
80
72
|
// =
|
|
81
73
|
|
|
82
|
-
export const lexBytes = z
|
|
83
|
-
.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
})
|
|
89
|
-
.strict()
|
|
74
|
+
export const lexBytes = z.object({
|
|
75
|
+
type: z.literal('bytes'),
|
|
76
|
+
description: z.string().optional(),
|
|
77
|
+
maxLength: z.number().optional(),
|
|
78
|
+
minLength: z.number().optional(),
|
|
79
|
+
})
|
|
90
80
|
export type LexBytes = z.infer<typeof lexBytes>
|
|
91
81
|
|
|
92
|
-
export const lexCidLink = z
|
|
93
|
-
.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
})
|
|
97
|
-
.strict()
|
|
82
|
+
export const lexCidLink = z.object({
|
|
83
|
+
type: z.literal('cid-link'),
|
|
84
|
+
description: z.string().optional(),
|
|
85
|
+
})
|
|
98
86
|
export type LexCidLink = z.infer<typeof lexCidLink>
|
|
99
87
|
|
|
100
88
|
export const lexIpldType = z.discriminatedUnion('type', [lexBytes, lexCidLink])
|
|
@@ -103,23 +91,19 @@ export type LexIpldType = z.infer<typeof lexIpldType>
|
|
|
103
91
|
// references
|
|
104
92
|
// =
|
|
105
93
|
|
|
106
|
-
export const lexRef = z
|
|
107
|
-
.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
})
|
|
112
|
-
.strict()
|
|
94
|
+
export const lexRef = z.object({
|
|
95
|
+
type: z.literal('ref'),
|
|
96
|
+
description: z.string().optional(),
|
|
97
|
+
ref: z.string(),
|
|
98
|
+
})
|
|
113
99
|
export type LexRef = z.infer<typeof lexRef>
|
|
114
100
|
|
|
115
|
-
export const lexRefUnion = z
|
|
116
|
-
.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
})
|
|
122
|
-
.strict()
|
|
101
|
+
export const lexRefUnion = z.object({
|
|
102
|
+
type: z.literal('union'),
|
|
103
|
+
description: z.string().optional(),
|
|
104
|
+
refs: z.string().array(),
|
|
105
|
+
closed: z.boolean().optional(),
|
|
106
|
+
})
|
|
123
107
|
export type LexRefUnion = z.infer<typeof lexRefUnion>
|
|
124
108
|
|
|
125
109
|
export const lexRefVariant = z.discriminatedUnion('type', [lexRef, lexRefUnion])
|
|
@@ -128,59 +112,51 @@ export type LexRefVariant = z.infer<typeof lexRefVariant>
|
|
|
128
112
|
// blobs
|
|
129
113
|
// =
|
|
130
114
|
|
|
131
|
-
export const lexBlob = z
|
|
132
|
-
.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
})
|
|
138
|
-
.strict()
|
|
115
|
+
export const lexBlob = z.object({
|
|
116
|
+
type: z.literal('blob'),
|
|
117
|
+
description: z.string().optional(),
|
|
118
|
+
accept: z.string().array().optional(),
|
|
119
|
+
maxSize: z.number().optional(),
|
|
120
|
+
})
|
|
139
121
|
export type LexBlob = z.infer<typeof lexBlob>
|
|
140
122
|
|
|
141
123
|
// complex types
|
|
142
124
|
// =
|
|
143
125
|
|
|
144
|
-
export const lexArray = z
|
|
145
|
-
.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
})
|
|
166
|
-
.strict()
|
|
126
|
+
export const lexArray = z.object({
|
|
127
|
+
type: z.literal('array'),
|
|
128
|
+
description: z.string().optional(),
|
|
129
|
+
items: z.discriminatedUnion('type', [
|
|
130
|
+
// lexPrimitive
|
|
131
|
+
lexBoolean,
|
|
132
|
+
lexInteger,
|
|
133
|
+
lexString,
|
|
134
|
+
lexUnknown,
|
|
135
|
+
// lexIpldType
|
|
136
|
+
lexBytes,
|
|
137
|
+
lexCidLink,
|
|
138
|
+
// lexRefVariant
|
|
139
|
+
lexRef,
|
|
140
|
+
lexRefUnion,
|
|
141
|
+
// other
|
|
142
|
+
lexBlob,
|
|
143
|
+
]),
|
|
144
|
+
minLength: z.number().int().optional(),
|
|
145
|
+
maxLength: z.number().int().optional(),
|
|
146
|
+
})
|
|
167
147
|
export type LexArray = z.infer<typeof lexArray>
|
|
168
148
|
|
|
169
149
|
export const lexPrimitiveArray = lexArray.merge(
|
|
170
|
-
z
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
})
|
|
174
|
-
.strict(),
|
|
150
|
+
z.object({
|
|
151
|
+
items: lexPrimitive,
|
|
152
|
+
}),
|
|
175
153
|
)
|
|
176
154
|
export type LexPrimitiveArray = z.infer<typeof lexPrimitiveArray>
|
|
177
155
|
|
|
178
|
-
export const lexToken = z
|
|
179
|
-
.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
})
|
|
183
|
-
.strict()
|
|
156
|
+
export const lexToken = z.object({
|
|
157
|
+
type: z.literal('token'),
|
|
158
|
+
description: z.string().optional(),
|
|
159
|
+
})
|
|
184
160
|
export type LexToken = z.infer<typeof lexToken>
|
|
185
161
|
|
|
186
162
|
export const lexObject = z
|
|
@@ -209,7 +185,6 @@ export const lexObject = z
|
|
|
209
185
|
]),
|
|
210
186
|
),
|
|
211
187
|
})
|
|
212
|
-
.strict()
|
|
213
188
|
.superRefine(requiredPropertiesRefinement)
|
|
214
189
|
export type LexObject = z.infer<typeof lexObject>
|
|
215
190
|
|
|
@@ -233,84 +208,69 @@ export const lexXrpcParameters = z
|
|
|
233
208
|
]),
|
|
234
209
|
),
|
|
235
210
|
})
|
|
236
|
-
.strict()
|
|
237
211
|
.superRefine(requiredPropertiesRefinement)
|
|
238
212
|
export type LexXrpcParameters = z.infer<typeof lexXrpcParameters>
|
|
239
213
|
|
|
240
|
-
export const lexXrpcBody = z
|
|
241
|
-
.
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
})
|
|
247
|
-
.strict()
|
|
214
|
+
export const lexXrpcBody = z.object({
|
|
215
|
+
description: z.string().optional(),
|
|
216
|
+
encoding: z.string(),
|
|
217
|
+
// @NOTE using discriminatedUnion with a refined schema requires zod >= 4
|
|
218
|
+
schema: z.union([lexRefVariant, lexObject]).optional(),
|
|
219
|
+
})
|
|
248
220
|
export type LexXrpcBody = z.infer<typeof lexXrpcBody>
|
|
249
221
|
|
|
250
|
-
export const lexXrpcSubscriptionMessage = z
|
|
251
|
-
.
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
})
|
|
256
|
-
.strict()
|
|
222
|
+
export const lexXrpcSubscriptionMessage = z.object({
|
|
223
|
+
description: z.string().optional(),
|
|
224
|
+
// @NOTE using discriminatedUnion with a refined schema requires zod >= 4
|
|
225
|
+
schema: z.union([lexRefVariant, lexObject]).optional(),
|
|
226
|
+
})
|
|
257
227
|
export type LexXrpcSubscriptionMessage = z.infer<
|
|
258
228
|
typeof lexXrpcSubscriptionMessage
|
|
259
229
|
>
|
|
260
230
|
|
|
261
|
-
export const lexXrpcError = z
|
|
262
|
-
.
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
})
|
|
266
|
-
.strict()
|
|
231
|
+
export const lexXrpcError = z.object({
|
|
232
|
+
name: z.string(),
|
|
233
|
+
description: z.string().optional(),
|
|
234
|
+
})
|
|
267
235
|
export type LexXrpcError = z.infer<typeof lexXrpcError>
|
|
268
236
|
|
|
269
|
-
export const lexXrpcQuery = z
|
|
270
|
-
.
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
})
|
|
277
|
-
.strict()
|
|
237
|
+
export const lexXrpcQuery = z.object({
|
|
238
|
+
type: z.literal('query'),
|
|
239
|
+
description: z.string().optional(),
|
|
240
|
+
parameters: lexXrpcParameters.optional(),
|
|
241
|
+
output: lexXrpcBody.optional(),
|
|
242
|
+
errors: lexXrpcError.array().optional(),
|
|
243
|
+
})
|
|
278
244
|
export type LexXrpcQuery = z.infer<typeof lexXrpcQuery>
|
|
279
245
|
|
|
280
|
-
export const lexXrpcProcedure = z
|
|
281
|
-
.
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
})
|
|
289
|
-
.strict()
|
|
246
|
+
export const lexXrpcProcedure = z.object({
|
|
247
|
+
type: z.literal('procedure'),
|
|
248
|
+
description: z.string().optional(),
|
|
249
|
+
parameters: lexXrpcParameters.optional(),
|
|
250
|
+
input: lexXrpcBody.optional(),
|
|
251
|
+
output: lexXrpcBody.optional(),
|
|
252
|
+
errors: lexXrpcError.array().optional(),
|
|
253
|
+
})
|
|
290
254
|
export type LexXrpcProcedure = z.infer<typeof lexXrpcProcedure>
|
|
291
255
|
|
|
292
|
-
export const lexXrpcSubscription = z
|
|
293
|
-
.
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
})
|
|
300
|
-
.strict()
|
|
256
|
+
export const lexXrpcSubscription = z.object({
|
|
257
|
+
type: z.literal('subscription'),
|
|
258
|
+
description: z.string().optional(),
|
|
259
|
+
parameters: lexXrpcParameters.optional(),
|
|
260
|
+
message: lexXrpcSubscriptionMessage.optional(),
|
|
261
|
+
errors: lexXrpcError.array().optional(),
|
|
262
|
+
})
|
|
301
263
|
export type LexXrpcSubscription = z.infer<typeof lexXrpcSubscription>
|
|
302
264
|
|
|
303
265
|
// database
|
|
304
266
|
// =
|
|
305
267
|
|
|
306
|
-
export const lexRecord = z
|
|
307
|
-
.
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
})
|
|
313
|
-
.strict()
|
|
268
|
+
export const lexRecord = z.object({
|
|
269
|
+
type: z.literal('record'),
|
|
270
|
+
description: z.string().optional(),
|
|
271
|
+
key: z.string().optional(),
|
|
272
|
+
record: lexObject,
|
|
273
|
+
})
|
|
314
274
|
export type LexRecord = z.infer<typeof lexRecord>
|
|
315
275
|
|
|
316
276
|
// core
|
|
@@ -420,7 +380,6 @@ export const lexiconDoc = z
|
|
|
420
380
|
description: z.string().optional(),
|
|
421
381
|
defs: z.record(lexUserType),
|
|
422
382
|
})
|
|
423
|
-
.strict()
|
|
424
383
|
.superRefine((doc, ctx) => {
|
|
425
384
|
for (const defId in doc.defs) {
|
|
426
385
|
const def = doc.defs[defId]
|
package/tests/general.test.ts
CHANGED
|
@@ -100,13 +100,14 @@ describe('General validation', () => {
|
|
|
100
100
|
parseLexiconDoc(schema)
|
|
101
101
|
}).toThrow('Required field \\"foo\\" not defined')
|
|
102
102
|
})
|
|
103
|
-
it('
|
|
103
|
+
it('allows unknown fields to be present', () => {
|
|
104
104
|
const schema = {
|
|
105
105
|
lexicon: 1,
|
|
106
106
|
id: 'com.example.unknownFields',
|
|
107
107
|
defs: {
|
|
108
108
|
test: {
|
|
109
109
|
type: 'object',
|
|
110
|
+
properties: {},
|
|
110
111
|
foo: 3,
|
|
111
112
|
},
|
|
112
113
|
},
|
|
@@ -114,7 +115,7 @@ describe('General validation', () => {
|
|
|
114
115
|
|
|
115
116
|
expect(() => {
|
|
116
117
|
parseLexiconDoc(schema)
|
|
117
|
-
}).toThrow(
|
|
118
|
+
}).not.toThrow()
|
|
118
119
|
})
|
|
119
120
|
it('fails lexicon parsing when uri is invalid', () => {
|
|
120
121
|
const schema: LexiconDoc = {
|