@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/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
- .object({
10
- type: z.literal('boolean'),
11
- description: z.string().optional(),
12
- default: z.boolean().optional(),
13
- const: z.boolean().optional(),
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
- .object({
20
- type: z.literal('integer'),
21
- description: z.string().optional(),
22
- default: z.number().int().optional(),
23
- minimum: z.number().int().optional(),
24
- maximum: z.number().int().optional(),
25
- enum: z.number().int().array().optional(),
26
- const: z.number().int().optional(),
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
- .object({
48
- type: z.literal('string'),
49
- format: lexStringFormat.optional(),
50
- description: z.string().optional(),
51
- default: z.string().optional(),
52
- minLength: z.number().int().optional(),
53
- maxLength: z.number().int().optional(),
54
- minGraphemes: z.number().int().optional(),
55
- maxGraphemes: z.number().int().optional(),
56
- enum: z.string().array().optional(),
57
- const: z.string().optional(),
58
- knownValues: z.string().array().optional(),
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
- .object({
65
- type: z.literal('unknown'),
66
- description: z.string().optional(),
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
- .object({
84
- type: z.literal('bytes'),
85
- description: z.string().optional(),
86
- maxLength: z.number().optional(),
87
- minLength: z.number().optional(),
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
- .object({
94
- type: z.literal('cid-link'),
95
- description: z.string().optional(),
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
- .object({
108
- type: z.literal('ref'),
109
- description: z.string().optional(),
110
- ref: z.string(),
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
- .object({
117
- type: z.literal('union'),
118
- description: z.string().optional(),
119
- refs: z.string().array(),
120
- closed: z.boolean().optional(),
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
- .object({
133
- type: z.literal('blob'),
134
- description: z.string().optional(),
135
- accept: z.string().array().optional(),
136
- maxSize: z.number().optional(),
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
- .object({
146
- type: z.literal('array'),
147
- description: z.string().optional(),
148
- items: z.discriminatedUnion('type', [
149
- // lexPrimitive
150
- lexBoolean,
151
- lexInteger,
152
- lexString,
153
- lexUnknown,
154
- // lexIpldType
155
- lexBytes,
156
- lexCidLink,
157
- // lexRefVariant
158
- lexRef,
159
- lexRefUnion,
160
- // other
161
- lexBlob,
162
- ]),
163
- minLength: z.number().int().optional(),
164
- maxLength: z.number().int().optional(),
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
- .object({
172
- items: lexPrimitive,
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
- .object({
180
- type: z.literal('token'),
181
- description: z.string().optional(),
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
- .object({
242
- description: z.string().optional(),
243
- encoding: z.string(),
244
- // @NOTE using discriminatedUnion with a refined schema requires zod >= 4
245
- schema: z.union([lexRefVariant, lexObject]).optional(),
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
- .object({
252
- description: z.string().optional(),
253
- // @NOTE using discriminatedUnion with a refined schema requires zod >= 4
254
- schema: z.union([lexRefVariant, lexObject]).optional(),
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
- .object({
263
- name: z.string(),
264
- description: z.string().optional(),
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
- .object({
271
- type: z.literal('query'),
272
- description: z.string().optional(),
273
- parameters: lexXrpcParameters.optional(),
274
- output: lexXrpcBody.optional(),
275
- errors: lexXrpcError.array().optional(),
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
- .object({
282
- type: z.literal('procedure'),
283
- description: z.string().optional(),
284
- parameters: lexXrpcParameters.optional(),
285
- input: lexXrpcBody.optional(),
286
- output: lexXrpcBody.optional(),
287
- errors: lexXrpcError.array().optional(),
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
- .object({
294
- type: z.literal('subscription'),
295
- description: z.string().optional(),
296
- parameters: lexXrpcParameters.optional(),
297
- message: lexXrpcSubscriptionMessage.optional(),
298
- errors: lexXrpcError.array().optional(),
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
- .object({
308
- type: z.literal('record'),
309
- description: z.string().optional(),
310
- key: z.string().optional(),
311
- record: lexObject,
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]
@@ -100,13 +100,14 @@ describe('General validation', () => {
100
100
  parseLexiconDoc(schema)
101
101
  }).toThrow('Required field \\"foo\\" not defined')
102
102
  })
103
- it('fails when unknown fields are present', () => {
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("Unrecognized key(s) in object: 'foo'")
118
+ }).not.toThrow()
118
119
  })
119
120
  it('fails lexicon parsing when uri is invalid', () => {
120
121
  const schema: LexiconDoc = {