@atproto/lex-document 0.1.2 → 0.1.3
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 +11 -0
- package/dist/lexicon-indexer.d.ts +1 -1
- package/dist/lexicon-indexer.d.ts.map +1 -1
- package/dist/lexicon-indexer.js.map +1 -1
- package/dist/lexicon-iterable-indexer.d.ts +2 -3
- package/dist/lexicon-iterable-indexer.d.ts.map +1 -1
- package/dist/lexicon-iterable-indexer.js +0 -1
- package/dist/lexicon-iterable-indexer.js.map +1 -1
- package/dist/lexicon-schema-builder.d.ts +3 -3
- package/dist/lexicon-schema-builder.d.ts.map +1 -1
- package/dist/lexicon-schema-builder.js.map +1 -1
- package/package.json +6 -10
- package/src/core-js.d.ts +0 -2
- package/src/index.ts +0 -7
- package/src/lexicon-document.test.ts +0 -113
- package/src/lexicon-document.ts +0 -754
- package/src/lexicon-indexer.ts +0 -60
- package/src/lexicon-iterable-indexer.ts +0 -132
- package/src/lexicon-schema-builder.test.ts +0 -297
- package/src/lexicon-schema-builder.ts +0 -501
- package/tsconfig.build.json +0 -12
- package/tsconfig.json +0 -7
- package/tsconfig.tests.json +0 -8
package/src/lexicon-document.ts
DELETED
|
@@ -1,754 +0,0 @@
|
|
|
1
|
-
import { l } from '@atproto/lex-schema'
|
|
2
|
-
|
|
3
|
-
// https://atproto.com/specs/lexicon
|
|
4
|
-
|
|
5
|
-
// "Concrete" Types
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Schema for validating Lexicon boolean type definitions.
|
|
9
|
-
*
|
|
10
|
-
* Validates boolean field definitions that may include a default value,
|
|
11
|
-
* a constant value, and an optional description.
|
|
12
|
-
*/
|
|
13
|
-
export const lexiconBooleanSchema = l.object({
|
|
14
|
-
type: l.literal('boolean'),
|
|
15
|
-
default: l.optional(l.boolean()),
|
|
16
|
-
const: l.optional(l.boolean()),
|
|
17
|
-
description: l.optional(l.string()),
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* TypeScript type for a Lexicon boolean definition.
|
|
22
|
-
*
|
|
23
|
-
* Represents the structure of a boolean field in a Lexicon document,
|
|
24
|
-
* including optional default, const, and description properties.
|
|
25
|
-
*
|
|
26
|
-
* @see {@link lexiconBooleanSchema} for the schema definition
|
|
27
|
-
*/
|
|
28
|
-
export type LexiconBoolean = l.Infer<typeof lexiconBooleanSchema>
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Schema for validating Lexicon integer type definitions.
|
|
32
|
-
*
|
|
33
|
-
* Validates integer field definitions with support for default values,
|
|
34
|
-
* minimum/maximum constraints, enumerated values, and constant values.
|
|
35
|
-
*/
|
|
36
|
-
export const lexiconIntegerSchema = l.object({
|
|
37
|
-
type: l.literal('integer'),
|
|
38
|
-
default: l.optional(l.integer()),
|
|
39
|
-
minimum: l.optional(l.integer()),
|
|
40
|
-
maximum: l.optional(l.integer()),
|
|
41
|
-
enum: l.optional(l.array(l.integer())),
|
|
42
|
-
const: l.optional(l.integer()),
|
|
43
|
-
description: l.optional(l.string()),
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* TypeScript type for a Lexicon integer definition.
|
|
48
|
-
*
|
|
49
|
-
* Represents the structure of an integer field in a Lexicon document,
|
|
50
|
-
* including optional constraints like minimum, maximum, enum, and const.
|
|
51
|
-
*
|
|
52
|
-
* @see {@link lexiconIntegerSchema} for the schema definition
|
|
53
|
-
*/
|
|
54
|
-
export type LexiconInteger = l.Infer<typeof lexiconIntegerSchema>
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Schema for validating Lexicon string type definitions.
|
|
58
|
-
*
|
|
59
|
-
* Validates string field definitions with support for format validation,
|
|
60
|
-
* length constraints (both character and grapheme-based), enumerated values,
|
|
61
|
-
* known values, and constant values.
|
|
62
|
-
*/
|
|
63
|
-
export const lexiconStringSchema = l.object({
|
|
64
|
-
type: l.literal('string'),
|
|
65
|
-
format: l.optional(l.enum<l.StringFormat>(l.STRING_FORMATS)),
|
|
66
|
-
default: l.optional(l.string()),
|
|
67
|
-
minLength: l.optional(l.integer()),
|
|
68
|
-
maxLength: l.optional(l.integer()),
|
|
69
|
-
minGraphemes: l.optional(l.integer()),
|
|
70
|
-
maxGraphemes: l.optional(l.integer()),
|
|
71
|
-
enum: l.optional(l.array(l.string())),
|
|
72
|
-
const: l.optional(l.string()),
|
|
73
|
-
knownValues: l.optional(l.array(l.string())),
|
|
74
|
-
description: l.optional(l.string()),
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* TypeScript type for a Lexicon string definition.
|
|
79
|
-
*
|
|
80
|
-
* Represents the structure of a string field in a Lexicon document,
|
|
81
|
-
* including optional format, length constraints, enum, const, and knownValues.
|
|
82
|
-
*
|
|
83
|
-
* @see {@link lexiconStringSchema} for the schema definition
|
|
84
|
-
*/
|
|
85
|
-
export type LexiconString = l.Infer<typeof lexiconStringSchema>
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Schema for validating Lexicon bytes type definitions.
|
|
89
|
-
*
|
|
90
|
-
* Validates binary data field definitions with optional length constraints.
|
|
91
|
-
* Used for raw byte arrays in DAG-CBOR encoding.
|
|
92
|
-
*/
|
|
93
|
-
export const lexiconBytesSchema = l.object({
|
|
94
|
-
type: l.literal('bytes'),
|
|
95
|
-
maxLength: l.optional(l.integer()),
|
|
96
|
-
minLength: l.optional(l.integer()),
|
|
97
|
-
description: l.optional(l.string()),
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* TypeScript type for a Lexicon bytes definition.
|
|
102
|
-
*
|
|
103
|
-
* Represents the structure of a binary data field in a Lexicon document,
|
|
104
|
-
* including optional minLength and maxLength constraints.
|
|
105
|
-
*
|
|
106
|
-
* @see {@link lexiconBytesSchema} for the schema definition
|
|
107
|
-
*/
|
|
108
|
-
export type LexiconBytes = l.Infer<typeof lexiconBytesSchema>
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Schema for validating Lexicon CID link type definitions.
|
|
112
|
-
*
|
|
113
|
-
* Validates Content Identifier (CID) link field definitions.
|
|
114
|
-
* CIDs are used to reference content-addressed data in IPFS/IPLD.
|
|
115
|
-
*/
|
|
116
|
-
export const lexiconCidLinkSchema = l.object({
|
|
117
|
-
type: l.literal('cid-link'),
|
|
118
|
-
description: l.optional(l.string()),
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* TypeScript type for a Lexicon CID link definition.
|
|
123
|
-
*
|
|
124
|
-
* Represents the structure of a CID link field in a Lexicon document.
|
|
125
|
-
*
|
|
126
|
-
* @see {@link lexiconCidLinkSchema} for the schema definition
|
|
127
|
-
*/
|
|
128
|
-
export type LexiconCid = l.Infer<typeof lexiconCidLinkSchema>
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Schema for validating Lexicon blob type definitions.
|
|
132
|
-
*
|
|
133
|
-
* Validates blob field definitions with optional MIME type acceptance list
|
|
134
|
-
* and maximum size constraints. Blobs represent uploaded file references.
|
|
135
|
-
*/
|
|
136
|
-
export const lexiconBlobSchema = l.object({
|
|
137
|
-
type: l.literal('blob'),
|
|
138
|
-
accept: l.optional(l.array(l.string())),
|
|
139
|
-
maxSize: l.optional(l.integer()),
|
|
140
|
-
description: l.optional(l.string()),
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* TypeScript type for a Lexicon blob definition.
|
|
145
|
-
*
|
|
146
|
-
* Represents the structure of a blob field in a Lexicon document,
|
|
147
|
-
* including optional accept list and maxSize constraints.
|
|
148
|
-
*
|
|
149
|
-
* @see {@link lexiconBlobSchema} for the schema definition
|
|
150
|
-
*/
|
|
151
|
-
export type LexiconBlob = l.Infer<typeof lexiconBlobSchema>
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Array of all concrete (primitive) Lexicon type schemas.
|
|
155
|
-
* Includes boolean, integer, string, bytes, cid-link, and blob types.
|
|
156
|
-
*/
|
|
157
|
-
const CONCRETE_TYPES = [
|
|
158
|
-
lexiconBooleanSchema,
|
|
159
|
-
lexiconIntegerSchema,
|
|
160
|
-
lexiconStringSchema,
|
|
161
|
-
// Lexicon (DAG-CBOR)
|
|
162
|
-
lexiconBytesSchema,
|
|
163
|
-
lexiconCidLinkSchema,
|
|
164
|
-
// Lexicon Specific
|
|
165
|
-
lexiconBlobSchema,
|
|
166
|
-
] as const
|
|
167
|
-
|
|
168
|
-
// Meta types
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Schema for validating Lexicon unknown type definitions.
|
|
172
|
-
*
|
|
173
|
-
* Validates unknown field definitions which accept any valid data.
|
|
174
|
-
* Used when the schema cannot determine the type ahead of time.
|
|
175
|
-
*/
|
|
176
|
-
export const lexiconUnknownSchema = l.object({
|
|
177
|
-
type: l.literal('unknown'),
|
|
178
|
-
description: l.optional(l.string()),
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* TypeScript type for a Lexicon unknown definition.
|
|
183
|
-
*
|
|
184
|
-
* Represents the structure of an unknown field in a Lexicon document.
|
|
185
|
-
*
|
|
186
|
-
* @see {@link lexiconUnknownSchema} for the schema definition
|
|
187
|
-
*/
|
|
188
|
-
export type LexiconUnknown = l.Infer<typeof lexiconUnknownSchema>
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Schema for validating Lexicon token type definitions.
|
|
192
|
-
*
|
|
193
|
-
* Validates token definitions which represent symbolic constants.
|
|
194
|
-
* Tokens are used to define enumeration-like values that can be
|
|
195
|
-
* referenced across different lexicons.
|
|
196
|
-
*/
|
|
197
|
-
export const lexiconTokenSchema = l.object({
|
|
198
|
-
type: l.literal('token'),
|
|
199
|
-
description: l.optional(l.string()),
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* TypeScript type for a Lexicon token definition.
|
|
204
|
-
*
|
|
205
|
-
* Represents the structure of a token in a Lexicon document.
|
|
206
|
-
*
|
|
207
|
-
* @see {@link lexiconTokenSchema} for the schema definition
|
|
208
|
-
*/
|
|
209
|
-
export type LexiconToken = l.Infer<typeof lexiconTokenSchema>
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Schema for validating Lexicon reference type definitions.
|
|
213
|
-
*
|
|
214
|
-
* Validates reference definitions which point to other type definitions
|
|
215
|
-
* within the same or different Lexicon documents. References use the
|
|
216
|
-
* format "nsid#defName" for cross-document refs or "#defName" for local refs.
|
|
217
|
-
*/
|
|
218
|
-
export const lexiconRefSchema = l.object({
|
|
219
|
-
type: l.literal('ref'),
|
|
220
|
-
ref: l.string(),
|
|
221
|
-
description: l.optional(l.string()),
|
|
222
|
-
})
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* TypeScript type for a Lexicon reference definition.
|
|
226
|
-
*
|
|
227
|
-
* Represents the structure of a reference field in a Lexicon document,
|
|
228
|
-
* including the ref string pointing to another definition.
|
|
229
|
-
*
|
|
230
|
-
* @see {@link lexiconRefSchema} for the schema definition
|
|
231
|
-
*/
|
|
232
|
-
export type LexiconRef = l.Infer<typeof lexiconRefSchema>
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Schema for validating Lexicon union reference type definitions.
|
|
236
|
-
*
|
|
237
|
-
* Validates union definitions which can reference multiple possible types.
|
|
238
|
-
* The union can be closed (only listed types allowed) or open (allows
|
|
239
|
-
* additional unlisted types).
|
|
240
|
-
*/
|
|
241
|
-
export const lexiconRefUnionSchema = l.object({
|
|
242
|
-
type: l.literal('union'),
|
|
243
|
-
refs: l.array(l.string()),
|
|
244
|
-
closed: l.optional(l.boolean()),
|
|
245
|
-
description: l.optional(l.string()),
|
|
246
|
-
})
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* TypeScript type for a Lexicon union reference definition.
|
|
250
|
-
*
|
|
251
|
-
* Represents the structure of a union field in a Lexicon document,
|
|
252
|
-
* including an array of reference strings and optional closed flag.
|
|
253
|
-
*
|
|
254
|
-
* @see {@link lexiconRefUnionSchema} for the schema definition
|
|
255
|
-
*/
|
|
256
|
-
export type LexiconRefUnion = l.Infer<typeof lexiconRefUnionSchema>
|
|
257
|
-
|
|
258
|
-
// Complex Types
|
|
259
|
-
|
|
260
|
-
const ARRAY_ITEMS_SCHEMAS = [
|
|
261
|
-
...CONCRETE_TYPES,
|
|
262
|
-
// Meta
|
|
263
|
-
lexiconUnknownSchema,
|
|
264
|
-
lexiconRefSchema,
|
|
265
|
-
lexiconRefUnionSchema,
|
|
266
|
-
] as const
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* TypeScript type representing valid item types for Lexicon arrays.
|
|
270
|
-
*
|
|
271
|
-
* Union of all types that can appear as items within a Lexicon array definition.
|
|
272
|
-
*/
|
|
273
|
-
export type LexiconArrayItems = l.Infer<(typeof ARRAY_ITEMS_SCHEMAS)[number]>
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Schema for validating Lexicon array type definitions.
|
|
277
|
-
*
|
|
278
|
-
* Validates array field definitions with specified item type and
|
|
279
|
-
* optional length constraints.
|
|
280
|
-
*/
|
|
281
|
-
export const lexiconArraySchema = l.object({
|
|
282
|
-
type: l.literal('array'),
|
|
283
|
-
items: l.discriminatedUnion('type', ARRAY_ITEMS_SCHEMAS),
|
|
284
|
-
minLength: l.optional(l.integer()),
|
|
285
|
-
maxLength: l.optional(l.integer()),
|
|
286
|
-
description: l.optional(l.string()),
|
|
287
|
-
})
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* TypeScript type for a Lexicon array definition.
|
|
291
|
-
*
|
|
292
|
-
* Represents the structure of an array field in a Lexicon document,
|
|
293
|
-
* including the items schema and optional length constraints.
|
|
294
|
-
*
|
|
295
|
-
* @see {@link lexiconArraySchema} for the schema definition
|
|
296
|
-
*/
|
|
297
|
-
export type LexiconArray = l.Infer<typeof lexiconArraySchema>
|
|
298
|
-
|
|
299
|
-
const requirePropertiesRefinement: l.RefinementCheck<{
|
|
300
|
-
required?: string[]
|
|
301
|
-
properties: Record<string, unknown>
|
|
302
|
-
}> = {
|
|
303
|
-
check: (v) => !v.required || v.required.every((k) => k in v.properties),
|
|
304
|
-
message: 'All required parameters must be defined in properties',
|
|
305
|
-
path: 'required',
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Schema for validating Lexicon object type definitions.
|
|
310
|
-
*
|
|
311
|
-
* Validates object definitions with named properties, required field lists,
|
|
312
|
-
* and nullable field lists. Includes refinement to ensure all required
|
|
313
|
-
* properties are defined in the properties map.
|
|
314
|
-
*/
|
|
315
|
-
export const lexiconObjectSchema = l.refine(
|
|
316
|
-
l.object({
|
|
317
|
-
type: l.literal('object'),
|
|
318
|
-
properties: l.dict(
|
|
319
|
-
l.string(),
|
|
320
|
-
l.discriminatedUnion('type', [
|
|
321
|
-
...ARRAY_ITEMS_SCHEMAS,
|
|
322
|
-
lexiconArraySchema,
|
|
323
|
-
]),
|
|
324
|
-
),
|
|
325
|
-
required: l.optional(l.array(l.string())),
|
|
326
|
-
nullable: l.optional(l.array(l.string())),
|
|
327
|
-
description: l.optional(l.string()),
|
|
328
|
-
}),
|
|
329
|
-
requirePropertiesRefinement,
|
|
330
|
-
)
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* TypeScript type for a Lexicon object definition.
|
|
334
|
-
*
|
|
335
|
-
* Represents the structure of an object type in a Lexicon document,
|
|
336
|
-
* including properties map, required array, and nullable array.
|
|
337
|
-
*
|
|
338
|
-
* @see {@link lexiconObjectSchema} for the schema definition
|
|
339
|
-
*/
|
|
340
|
-
export type LexiconObject = l.Infer<typeof lexiconObjectSchema>
|
|
341
|
-
|
|
342
|
-
// Records
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Schema for validating Lexicon record key definitions.
|
|
346
|
-
*
|
|
347
|
-
* Validates record key type specifications. Valid values are:
|
|
348
|
-
* - "any": Any valid record key
|
|
349
|
-
* - "nsid": Namespaced identifier
|
|
350
|
-
* - "tid": Timestamp identifier
|
|
351
|
-
* - "literal:<string>": A specific literal string value
|
|
352
|
-
*/
|
|
353
|
-
export const lexiconRecordKeySchema = l.custom(
|
|
354
|
-
l.isLexiconRecordKey,
|
|
355
|
-
'Invalid record key definition (must be "any", "nsid", "tid", or "literal:<string>")',
|
|
356
|
-
)
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* TypeScript type for valid Lexicon record key values.
|
|
360
|
-
*
|
|
361
|
-
* Can be "any", "nsid", "tid", or "literal:<string>".
|
|
362
|
-
*
|
|
363
|
-
* @see {@link lexiconRecordKeySchema} for the schema definition
|
|
364
|
-
*/
|
|
365
|
-
export type LexiconRecordKey = l.LexiconRecordKey
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Schema for validating Lexicon record type definitions.
|
|
369
|
-
*
|
|
370
|
-
* Validates record definitions which define the structure of data
|
|
371
|
-
* stored in AT Protocol repositories. Records have a key type
|
|
372
|
-
* and an object schema defining the record's data structure.
|
|
373
|
-
*/
|
|
374
|
-
export const lexiconRecordSchema = l.object({
|
|
375
|
-
type: l.literal('record'),
|
|
376
|
-
record: lexiconObjectSchema,
|
|
377
|
-
description: l.optional(l.string()),
|
|
378
|
-
key: lexiconRecordKeySchema,
|
|
379
|
-
})
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* TypeScript type for a Lexicon record definition.
|
|
383
|
-
*
|
|
384
|
-
* Represents the structure of a record type in a Lexicon document,
|
|
385
|
-
* including the key type and the object schema for the record data.
|
|
386
|
-
*
|
|
387
|
-
* @see {@link lexiconRecordSchema} for the schema definition
|
|
388
|
-
*/
|
|
389
|
-
export type LexiconRecord = l.Infer<typeof lexiconRecordSchema>
|
|
390
|
-
|
|
391
|
-
// XRPC Methods
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* Schema for validating Lexicon XRPC method parameters.
|
|
395
|
-
*
|
|
396
|
-
* Validates the parameters definition for query and procedure methods.
|
|
397
|
-
* Parameters can only be primitive types (boolean, integer, string)
|
|
398
|
-
* or arrays of primitives.
|
|
399
|
-
*/
|
|
400
|
-
export const lexiconParameters = l.refine(
|
|
401
|
-
l.object({
|
|
402
|
-
type: l.literal('params'),
|
|
403
|
-
properties: l.dict(
|
|
404
|
-
l.string(),
|
|
405
|
-
l.discriminatedUnion('type', [
|
|
406
|
-
lexiconBooleanSchema,
|
|
407
|
-
lexiconIntegerSchema,
|
|
408
|
-
lexiconStringSchema,
|
|
409
|
-
l.object({
|
|
410
|
-
type: l.literal('array'),
|
|
411
|
-
items: l.discriminatedUnion('type', [
|
|
412
|
-
lexiconBooleanSchema,
|
|
413
|
-
lexiconIntegerSchema,
|
|
414
|
-
lexiconStringSchema,
|
|
415
|
-
]),
|
|
416
|
-
minLength: l.optional(l.integer()),
|
|
417
|
-
maxLength: l.optional(l.integer()),
|
|
418
|
-
description: l.optional(l.string()),
|
|
419
|
-
}),
|
|
420
|
-
]),
|
|
421
|
-
),
|
|
422
|
-
required: l.optional(l.array(l.string())),
|
|
423
|
-
description: l.optional(l.string()),
|
|
424
|
-
}),
|
|
425
|
-
requirePropertiesRefinement,
|
|
426
|
-
)
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* TypeScript type for Lexicon XRPC method parameters.
|
|
430
|
-
*
|
|
431
|
-
* Represents the structure of parameters for query and procedure methods.
|
|
432
|
-
*
|
|
433
|
-
* @see {@link lexiconParameters} for the schema definition
|
|
434
|
-
*/
|
|
435
|
-
export type LexiconParameters = l.Infer<typeof lexiconParameters>
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
* Schema for validating Lexicon XRPC method payloads.
|
|
439
|
-
*
|
|
440
|
-
* Validates input/output payload definitions for procedures and queries.
|
|
441
|
-
* Payloads specify the encoding (MIME type) and optional schema for
|
|
442
|
-
* the request or response body.
|
|
443
|
-
*/
|
|
444
|
-
export const lexiconPayload = l.object({
|
|
445
|
-
encoding: l.refine(l.string(), {
|
|
446
|
-
check: (v) => !v.includes(',') && !v.includes(';') && !v.includes(' '),
|
|
447
|
-
message:
|
|
448
|
-
'Invalid encoding string (must be a single MIME type without parameters)',
|
|
449
|
-
}),
|
|
450
|
-
schema: l.optional(
|
|
451
|
-
l.discriminatedUnion('type', [
|
|
452
|
-
lexiconRefSchema,
|
|
453
|
-
lexiconRefUnionSchema,
|
|
454
|
-
lexiconObjectSchema,
|
|
455
|
-
]),
|
|
456
|
-
),
|
|
457
|
-
description: l.optional(l.string()),
|
|
458
|
-
})
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* TypeScript type for a Lexicon XRPC payload definition.
|
|
462
|
-
*
|
|
463
|
-
* Represents the structure of an input or output payload,
|
|
464
|
-
* including encoding type and optional schema.
|
|
465
|
-
*
|
|
466
|
-
* @see {@link lexiconPayload} for the schema definition
|
|
467
|
-
*/
|
|
468
|
-
export type LexiconPayload = l.Infer<typeof lexiconPayload>
|
|
469
|
-
|
|
470
|
-
/**
|
|
471
|
-
* Schema for validating Lexicon XRPC error definitions.
|
|
472
|
-
*
|
|
473
|
-
* Validates error definitions that can be returned by XRPC methods.
|
|
474
|
-
* Each error has a name and optional description.
|
|
475
|
-
*/
|
|
476
|
-
export const lexiconError = l.object({
|
|
477
|
-
name: l.string({ minLength: 1 }),
|
|
478
|
-
description: l.optional(l.string()),
|
|
479
|
-
})
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
* TypeScript type for a Lexicon XRPC error definition.
|
|
483
|
-
*
|
|
484
|
-
* Represents an error that can be returned by an XRPC method.
|
|
485
|
-
*
|
|
486
|
-
* @see {@link lexiconError} for the schema definition
|
|
487
|
-
*/
|
|
488
|
-
export type LexiconError = l.Infer<typeof lexiconError>
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* Schema for validating Lexicon query (GET) method definitions.
|
|
492
|
-
*
|
|
493
|
-
* Validates query method definitions which represent read-only HTTP GET
|
|
494
|
-
* operations. Queries can have parameters, an output payload, and
|
|
495
|
-
* defined error types.
|
|
496
|
-
*/
|
|
497
|
-
export const lexiconQuerySchema = l.object({
|
|
498
|
-
type: l.literal('query'),
|
|
499
|
-
parameters: l.optional(lexiconParameters),
|
|
500
|
-
output: l.optional(lexiconPayload),
|
|
501
|
-
errors: l.optional(l.array(lexiconError)),
|
|
502
|
-
description: l.optional(l.string()),
|
|
503
|
-
})
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* TypeScript type for a Lexicon query method definition.
|
|
507
|
-
*
|
|
508
|
-
* Represents the structure of an XRPC query (GET) method.
|
|
509
|
-
*
|
|
510
|
-
* @see {@link lexiconQuerySchema} for the schema definition
|
|
511
|
-
*/
|
|
512
|
-
export type LexiconQuery = l.Infer<typeof lexiconQuerySchema>
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* Schema for validating Lexicon procedure (POST) method definitions.
|
|
516
|
-
*
|
|
517
|
-
* Validates procedure method definitions which represent HTTP POST
|
|
518
|
-
* operations that may modify state. Procedures can have parameters,
|
|
519
|
-
* input payload, output payload, and defined error types.
|
|
520
|
-
*/
|
|
521
|
-
export const lexiconProcedureSchema = l.object({
|
|
522
|
-
type: l.literal('procedure'),
|
|
523
|
-
parameters: l.optional(lexiconParameters),
|
|
524
|
-
input: l.optional(lexiconPayload),
|
|
525
|
-
output: l.optional(lexiconPayload),
|
|
526
|
-
errors: l.optional(l.array(lexiconError)),
|
|
527
|
-
description: l.optional(l.string()),
|
|
528
|
-
})
|
|
529
|
-
|
|
530
|
-
/**
|
|
531
|
-
* TypeScript type for a Lexicon procedure method definition.
|
|
532
|
-
*
|
|
533
|
-
* Represents the structure of an XRPC procedure (POST) method.
|
|
534
|
-
*
|
|
535
|
-
* @see {@link lexiconProcedureSchema} for the schema definition
|
|
536
|
-
*/
|
|
537
|
-
export type LexiconProcedure = l.Infer<typeof lexiconProcedureSchema>
|
|
538
|
-
|
|
539
|
-
export const lexiconMessageSchema = l.object({
|
|
540
|
-
description: l.optional(l.string()),
|
|
541
|
-
schema: lexiconRefUnionSchema,
|
|
542
|
-
})
|
|
543
|
-
|
|
544
|
-
export type LexiconMessage = l.Infer<typeof lexiconMessageSchema>
|
|
545
|
-
|
|
546
|
-
/**
|
|
547
|
-
* Schema for validating Lexicon subscription (WebSocket) method definitions.
|
|
548
|
-
*
|
|
549
|
-
* Validates subscription method definitions which represent real-time
|
|
550
|
-
* streaming connections over WebSocket. Subscriptions have parameters,
|
|
551
|
-
* a message schema defining the streamed data format, and error types.
|
|
552
|
-
*/
|
|
553
|
-
export const lexiconSubscriptionSchema = l.object({
|
|
554
|
-
type: l.literal('subscription'),
|
|
555
|
-
description: l.optional(l.string()),
|
|
556
|
-
parameters: l.optional(lexiconParameters),
|
|
557
|
-
message: lexiconMessageSchema,
|
|
558
|
-
errors: l.optional(l.array(lexiconError)),
|
|
559
|
-
})
|
|
560
|
-
|
|
561
|
-
/**
|
|
562
|
-
* TypeScript type for a Lexicon subscription method definition.
|
|
563
|
-
*
|
|
564
|
-
* Represents the structure of an XRPC subscription (WebSocket) method.
|
|
565
|
-
*
|
|
566
|
-
* @see {@link lexiconSubscriptionSchema} for the schema definition
|
|
567
|
-
*/
|
|
568
|
-
export type LexiconSubscription = l.Infer<typeof lexiconSubscriptionSchema>
|
|
569
|
-
|
|
570
|
-
// Permissions
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* Schema for validating language codes in Lexicon permission definitions.
|
|
574
|
-
*/
|
|
575
|
-
export const lexiconLanguageSchema = l.string({ format: 'language' })
|
|
576
|
-
|
|
577
|
-
/**
|
|
578
|
-
* TypeScript type for a BCP 47 language code string.
|
|
579
|
-
*
|
|
580
|
-
* @see {@link lexiconLanguageSchema} for the schema definition
|
|
581
|
-
*/
|
|
582
|
-
export type LexiconLanguage = l.Infer<typeof lexiconLanguageSchema>
|
|
583
|
-
|
|
584
|
-
/**
|
|
585
|
-
* Schema for validating language-keyed string dictionaries.
|
|
586
|
-
* Used for localized text in permission definitions.
|
|
587
|
-
*/
|
|
588
|
-
export const lexiconLanguageDict = l.dict(lexiconLanguageSchema, l.string())
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* TypeScript type for a language-keyed dictionary of localized strings.
|
|
592
|
-
*
|
|
593
|
-
* @see {@link lexiconLanguageDict} for the schema definition
|
|
594
|
-
*/
|
|
595
|
-
export type LexiconLanguageDict = l.Infer<typeof lexiconLanguageDict>
|
|
596
|
-
|
|
597
|
-
/**
|
|
598
|
-
* Schema for validating individual Lexicon permission definitions.
|
|
599
|
-
*/
|
|
600
|
-
export const lexiconPermissionSchema = l.intersection(
|
|
601
|
-
l.object({
|
|
602
|
-
type: l.literal('permission'),
|
|
603
|
-
resource: l.string({ minLength: 1 }),
|
|
604
|
-
}),
|
|
605
|
-
l.dict(l.string(), l.paramSchema),
|
|
606
|
-
)
|
|
607
|
-
|
|
608
|
-
/**
|
|
609
|
-
* TypeScript type for a Lexicon permission definition.
|
|
610
|
-
*
|
|
611
|
-
* Represents a single permission with a resource identifier
|
|
612
|
-
* and optional additional parameters.
|
|
613
|
-
*
|
|
614
|
-
* @see {@link lexiconPermissionSchema} for the schema definition
|
|
615
|
-
*/
|
|
616
|
-
export type LexiconPermission = l.Infer<typeof lexiconPermissionSchema>
|
|
617
|
-
|
|
618
|
-
/**
|
|
619
|
-
* Schema for validating Lexicon permission set definitions.
|
|
620
|
-
*/
|
|
621
|
-
export const lexiconPermissionSetSchema = l.object({
|
|
622
|
-
type: l.literal('permission-set'),
|
|
623
|
-
permissions: l.array(lexiconPermissionSchema),
|
|
624
|
-
title: l.optional(l.string()),
|
|
625
|
-
'title:lang': l.optional(lexiconLanguageDict),
|
|
626
|
-
detail: l.optional(l.string()),
|
|
627
|
-
'detail:lang': l.optional(lexiconLanguageDict),
|
|
628
|
-
description: l.optional(l.string()),
|
|
629
|
-
})
|
|
630
|
-
|
|
631
|
-
/**
|
|
632
|
-
* TypeScript type for a Lexicon permission set definition.
|
|
633
|
-
*
|
|
634
|
-
* Represents a collection of permissions with optional
|
|
635
|
-
* localized title and detail text.
|
|
636
|
-
*
|
|
637
|
-
* @see {@link lexiconPermissionSetSchema} for the schema definition
|
|
638
|
-
*/
|
|
639
|
-
export type LexiconPermissionSet = l.Infer<typeof lexiconPermissionSetSchema>
|
|
640
|
-
|
|
641
|
-
const NAMED_LEXICON_SCHEMAS = [
|
|
642
|
-
...CONCRETE_TYPES,
|
|
643
|
-
lexiconArraySchema,
|
|
644
|
-
lexiconObjectSchema,
|
|
645
|
-
lexiconTokenSchema,
|
|
646
|
-
] as const
|
|
647
|
-
|
|
648
|
-
/**
|
|
649
|
-
* TypeScript type for any named Lexicon definition.
|
|
650
|
-
*
|
|
651
|
-
* Union of all definition types that can appear in the defs section
|
|
652
|
-
* of a Lexicon document (excluding main-only types).
|
|
653
|
-
*/
|
|
654
|
-
export type NamedLexiconDefinition = l.Infer<
|
|
655
|
-
(typeof NAMED_LEXICON_SCHEMAS)[number]
|
|
656
|
-
>
|
|
657
|
-
|
|
658
|
-
const MAIN_LEXICON_SCHEMAS = [
|
|
659
|
-
lexiconPermissionSetSchema,
|
|
660
|
-
lexiconProcedureSchema,
|
|
661
|
-
lexiconQuerySchema,
|
|
662
|
-
lexiconRecordSchema,
|
|
663
|
-
lexiconSubscriptionSchema,
|
|
664
|
-
...NAMED_LEXICON_SCHEMAS,
|
|
665
|
-
] as const
|
|
666
|
-
|
|
667
|
-
/**
|
|
668
|
-
* TypeScript type for main Lexicon definitions.
|
|
669
|
-
*
|
|
670
|
-
* Union of all definition types that can appear as the "main" entry
|
|
671
|
-
* in a Lexicon document's defs section.
|
|
672
|
-
*/
|
|
673
|
-
export type MainLexiconDefinition = l.Infer<
|
|
674
|
-
(typeof MAIN_LEXICON_SCHEMAS)[number]
|
|
675
|
-
>
|
|
676
|
-
|
|
677
|
-
/**
|
|
678
|
-
* Schema for validating Lexicon document identifiers (NSIDs).
|
|
679
|
-
*
|
|
680
|
-
* Validates that the identifier follows the Namespaced Identifier format
|
|
681
|
-
* (e.g., "com.atproto.repo.createRecord").
|
|
682
|
-
*/
|
|
683
|
-
export const lexiconIdentifierSchema = l.string({ format: 'nsid' })
|
|
684
|
-
|
|
685
|
-
/**
|
|
686
|
-
* TypeScript type for a Lexicon document identifier.
|
|
687
|
-
*
|
|
688
|
-
* A Namespaced Identifier (NSID) string in reverse-domain format.
|
|
689
|
-
*
|
|
690
|
-
* @see {@link lexiconIdentifierSchema} for the schema definition
|
|
691
|
-
*/
|
|
692
|
-
export type LexiconIdentifier = l.Infer<typeof lexiconIdentifierSchema>
|
|
693
|
-
|
|
694
|
-
/**
|
|
695
|
-
* Schema for validating complete Lexicon document structures.
|
|
696
|
-
*
|
|
697
|
-
* Validates the top-level structure of a Lexicon document, including:
|
|
698
|
-
* - `lexicon`: Must be 1 (the current Lexicon version)
|
|
699
|
-
* - `id`: The document's NSID
|
|
700
|
-
* - `revision`: Optional version number
|
|
701
|
-
* - `description`: Optional document description
|
|
702
|
-
* - `defs`: Map of definition names to their schemas
|
|
703
|
-
*
|
|
704
|
-
* The "main" definition (if present) can be any main-only type,
|
|
705
|
-
* while other definitions are limited to named types.
|
|
706
|
-
*
|
|
707
|
-
* @example
|
|
708
|
-
* ```ts
|
|
709
|
-
* const result = lexiconDocumentSchema.parse({
|
|
710
|
-
* lexicon: 1,
|
|
711
|
-
* id: 'com.example.getProfile',
|
|
712
|
-
* defs: {
|
|
713
|
-
* main: {
|
|
714
|
-
* type: 'query',
|
|
715
|
-
* output: {
|
|
716
|
-
* encoding: 'application/json',
|
|
717
|
-
* schema: { type: 'ref', ref: '#profile' }
|
|
718
|
-
* }
|
|
719
|
-
* },
|
|
720
|
-
* profile: {
|
|
721
|
-
* type: 'object',
|
|
722
|
-
* properties: {
|
|
723
|
-
* name: { type: 'string' }
|
|
724
|
-
* }
|
|
725
|
-
* }
|
|
726
|
-
* }
|
|
727
|
-
* })
|
|
728
|
-
* ```
|
|
729
|
-
*/
|
|
730
|
-
export const lexiconDocumentSchema = l.object({
|
|
731
|
-
lexicon: l.literal(1),
|
|
732
|
-
id: lexiconIdentifierSchema,
|
|
733
|
-
revision: l.optional(l.integer()),
|
|
734
|
-
description: l.optional(l.string()),
|
|
735
|
-
defs: l.intersection(
|
|
736
|
-
l.object({
|
|
737
|
-
main: l.optional(l.discriminatedUnion('type', MAIN_LEXICON_SCHEMAS)),
|
|
738
|
-
}),
|
|
739
|
-
l.dict(
|
|
740
|
-
l.string({ minLength: 1 }),
|
|
741
|
-
l.discriminatedUnion('type', NAMED_LEXICON_SCHEMAS),
|
|
742
|
-
),
|
|
743
|
-
),
|
|
744
|
-
})
|
|
745
|
-
|
|
746
|
-
/**
|
|
747
|
-
* TypeScript type for a complete Lexicon document.
|
|
748
|
-
*
|
|
749
|
-
* Represents the full structure of a Lexicon JSON document,
|
|
750
|
-
* including the version, identifier, and all type definitions.
|
|
751
|
-
*
|
|
752
|
-
* @see {@link lexiconDocumentSchema} for the schema definition
|
|
753
|
-
*/
|
|
754
|
-
export type LexiconDocument = l.Infer<typeof lexiconDocumentSchema>
|