@atproto/lex-document 0.0.11 → 0.0.13
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 +22 -0
- package/dist/lexicon-document.d.ts +402 -4
- package/dist/lexicon-document.d.ts.map +1 -1
- package/dist/lexicon-document.js +202 -11
- package/dist/lexicon-document.js.map +1 -1
- package/dist/lexicon-indexer.d.ts +51 -0
- package/dist/lexicon-indexer.d.ts.map +1 -1
- package/dist/lexicon-indexer.js.map +1 -1
- package/dist/lexicon-iterable-indexer.d.ts +51 -1
- package/dist/lexicon-iterable-indexer.d.ts.map +1 -1
- package/dist/lexicon-iterable-indexer.js +51 -1
- package/dist/lexicon-iterable-indexer.js.map +1 -1
- package/dist/lexicon-schema-builder.d.ts +110 -17
- package/dist/lexicon-schema-builder.d.ts.map +1 -1
- package/dist/lexicon-schema-builder.js +102 -10
- package/dist/lexicon-schema-builder.js.map +1 -1
- package/package.json +4 -4
- package/src/lexicon-document.ts +427 -7
- package/src/lexicon-indexer.ts +52 -0
- package/src/lexicon-iterable-indexer.ts +51 -1
- package/src/lexicon-schema-builder.ts +127 -24
package/src/lexicon-document.ts
CHANGED
|
@@ -4,14 +4,35 @@ import { l } from '@atproto/lex-schema'
|
|
|
4
4
|
|
|
5
5
|
// "Concrete" Types
|
|
6
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
|
+
*/
|
|
7
13
|
export const lexiconBooleanSchema = l.object({
|
|
8
14
|
type: l.literal('boolean'),
|
|
9
15
|
default: l.optional(l.boolean()),
|
|
10
16
|
const: l.optional(l.boolean()),
|
|
11
17
|
description: l.optional(l.string()),
|
|
12
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
|
+
*/
|
|
13
28
|
export type LexiconBoolean = l.Infer<typeof lexiconBooleanSchema>
|
|
14
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
|
+
*/
|
|
15
36
|
export const lexiconIntegerSchema = l.object({
|
|
16
37
|
type: l.literal('integer'),
|
|
17
38
|
default: l.optional(l.integer()),
|
|
@@ -21,8 +42,24 @@ export const lexiconIntegerSchema = l.object({
|
|
|
21
42
|
const: l.optional(l.integer()),
|
|
22
43
|
description: l.optional(l.string()),
|
|
23
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
|
+
*/
|
|
24
54
|
export type LexiconInteger = l.Infer<typeof lexiconIntegerSchema>
|
|
25
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
|
+
*/
|
|
26
63
|
export const lexiconStringSchema = l.object({
|
|
27
64
|
type: l.literal('string'),
|
|
28
65
|
format: l.optional(l.enum<l.StringFormat>(l.STRING_FORMATS)),
|
|
@@ -36,30 +73,87 @@ export const lexiconStringSchema = l.object({
|
|
|
36
73
|
knownValues: l.optional(l.array(l.string())),
|
|
37
74
|
description: l.optional(l.string()),
|
|
38
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
|
+
*/
|
|
39
85
|
export type LexiconString = l.Infer<typeof lexiconStringSchema>
|
|
40
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
|
+
*/
|
|
41
93
|
export const lexiconBytesSchema = l.object({
|
|
42
94
|
type: l.literal('bytes'),
|
|
43
95
|
maxLength: l.optional(l.integer()),
|
|
44
96
|
minLength: l.optional(l.integer()),
|
|
45
97
|
description: l.optional(l.string()),
|
|
46
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
|
+
*/
|
|
47
108
|
export type LexiconBytes = l.Infer<typeof lexiconBytesSchema>
|
|
48
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
|
+
*/
|
|
49
116
|
export const lexiconCidLinkSchema = l.object({
|
|
50
117
|
type: l.literal('cid-link'),
|
|
51
118
|
description: l.optional(l.string()),
|
|
52
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
|
+
*/
|
|
53
128
|
export type LexiconCid = l.Infer<typeof lexiconCidLinkSchema>
|
|
54
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
|
+
*/
|
|
55
136
|
export const lexiconBlobSchema = l.object({
|
|
56
137
|
type: l.literal('blob'),
|
|
57
138
|
accept: l.optional(l.array(l.string())),
|
|
58
139
|
maxSize: l.optional(l.integer()),
|
|
59
140
|
description: l.optional(l.string()),
|
|
60
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
|
+
*/
|
|
61
151
|
export type LexiconBlob = l.Infer<typeof lexiconBlobSchema>
|
|
62
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Array of all concrete (primitive) Lexicon type schemas.
|
|
155
|
+
* Includes boolean, integer, string, bytes, cid-link, and blob types.
|
|
156
|
+
*/
|
|
63
157
|
const CONCRETE_TYPES = [
|
|
64
158
|
lexiconBooleanSchema,
|
|
65
159
|
lexiconIntegerSchema,
|
|
@@ -73,31 +167,92 @@ const CONCRETE_TYPES = [
|
|
|
73
167
|
|
|
74
168
|
// Meta types
|
|
75
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
|
+
*/
|
|
76
176
|
export const lexiconUnknownSchema = l.object({
|
|
77
177
|
type: l.literal('unknown'),
|
|
78
178
|
description: l.optional(l.string()),
|
|
79
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
|
+
*/
|
|
80
188
|
export type LexiconUnknown = l.Infer<typeof lexiconUnknownSchema>
|
|
81
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
|
+
*/
|
|
82
197
|
export const lexiconTokenSchema = l.object({
|
|
83
198
|
type: l.literal('token'),
|
|
84
199
|
description: l.optional(l.string()),
|
|
85
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
|
+
*/
|
|
86
209
|
export type LexiconToken = l.Infer<typeof lexiconTokenSchema>
|
|
87
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
|
+
*/
|
|
88
218
|
export const lexiconRefSchema = l.object({
|
|
89
219
|
type: l.literal('ref'),
|
|
90
220
|
ref: l.string(),
|
|
91
221
|
description: l.optional(l.string()),
|
|
92
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
|
+
*/
|
|
93
232
|
export type LexiconRef = l.Infer<typeof lexiconRefSchema>
|
|
94
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
|
+
*/
|
|
95
241
|
export const lexiconRefUnionSchema = l.object({
|
|
96
242
|
type: l.literal('union'),
|
|
97
243
|
refs: l.array(l.string()),
|
|
98
244
|
closed: l.optional(l.boolean()),
|
|
99
245
|
description: l.optional(l.string()),
|
|
100
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
|
+
*/
|
|
101
256
|
export type LexiconRefUnion = l.Infer<typeof lexiconRefUnionSchema>
|
|
102
257
|
|
|
103
258
|
// Complex Types
|
|
@@ -110,8 +265,19 @@ const ARRAY_ITEMS_SCHEMAS = [
|
|
|
110
265
|
lexiconRefUnionSchema,
|
|
111
266
|
] as const
|
|
112
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
|
+
*/
|
|
113
273
|
export type LexiconArrayItems = l.Infer<(typeof ARRAY_ITEMS_SCHEMAS)[number]>
|
|
114
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
|
+
*/
|
|
115
281
|
export const lexiconArraySchema = l.object({
|
|
116
282
|
type: l.literal('array'),
|
|
117
283
|
items: l.discriminatedUnion('type', ARRAY_ITEMS_SCHEMAS),
|
|
@@ -119,6 +285,15 @@ export const lexiconArraySchema = l.object({
|
|
|
119
285
|
maxLength: l.optional(l.integer()),
|
|
120
286
|
description: l.optional(l.string()),
|
|
121
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
|
+
*/
|
|
122
297
|
export type LexiconArray = l.Infer<typeof lexiconArraySchema>
|
|
123
298
|
|
|
124
299
|
const requirePropertiesRefinement: l.RefinementCheck<{
|
|
@@ -130,6 +305,13 @@ const requirePropertiesRefinement: l.RefinementCheck<{
|
|
|
130
305
|
path: 'required',
|
|
131
306
|
}
|
|
132
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
|
+
*/
|
|
133
315
|
export const lexiconObjectSchema = l.refine(
|
|
134
316
|
l.object({
|
|
135
317
|
type: l.literal('object'),
|
|
@@ -146,27 +328,75 @@ export const lexiconObjectSchema = l.refine(
|
|
|
146
328
|
}),
|
|
147
329
|
requirePropertiesRefinement,
|
|
148
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
|
+
*/
|
|
149
340
|
export type LexiconObject = l.Infer<typeof lexiconObjectSchema>
|
|
150
341
|
|
|
151
342
|
// Records
|
|
152
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
|
+
*/
|
|
153
353
|
export const lexiconRecordKeySchema = l.custom(
|
|
154
354
|
l.isLexiconRecordKey,
|
|
155
355
|
'Invalid record key definition (must be "any", "nsid", "tid", or "literal:<string>")',
|
|
156
356
|
)
|
|
157
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
|
+
*/
|
|
158
365
|
export type LexiconRecordKey = l.LexiconRecordKey
|
|
159
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
|
+
*/
|
|
160
374
|
export const lexiconRecordSchema = l.object({
|
|
161
375
|
type: l.literal('record'),
|
|
162
376
|
record: lexiconObjectSchema,
|
|
163
377
|
description: l.optional(l.string()),
|
|
164
378
|
key: lexiconRecordKeySchema,
|
|
165
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
|
+
*/
|
|
166
389
|
export type LexiconRecord = l.Infer<typeof lexiconRecordSchema>
|
|
167
390
|
|
|
168
391
|
// XRPC Methods
|
|
169
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
|
+
*/
|
|
170
400
|
export const lexiconParameters = l.refine(
|
|
171
401
|
l.object({
|
|
172
402
|
type: l.literal('params'),
|
|
@@ -194,8 +424,23 @@ export const lexiconParameters = l.refine(
|
|
|
194
424
|
}),
|
|
195
425
|
requirePropertiesRefinement,
|
|
196
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
|
+
*/
|
|
197
435
|
export type LexiconParameters = l.Infer<typeof lexiconParameters>
|
|
198
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
|
+
*/
|
|
199
444
|
export const lexiconPayload = l.object({
|
|
200
445
|
encoding: l.string(),
|
|
201
446
|
schema: l.optional(
|
|
@@ -207,14 +452,44 @@ export const lexiconPayload = l.object({
|
|
|
207
452
|
),
|
|
208
453
|
description: l.optional(l.string()),
|
|
209
454
|
})
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* TypeScript type for a Lexicon XRPC payload definition.
|
|
458
|
+
*
|
|
459
|
+
* Represents the structure of an input or output payload,
|
|
460
|
+
* including encoding type and optional schema.
|
|
461
|
+
*
|
|
462
|
+
* @see {@link lexiconPayload} for the schema definition
|
|
463
|
+
*/
|
|
210
464
|
export type LexiconPayload = l.Infer<typeof lexiconPayload>
|
|
211
465
|
|
|
466
|
+
/**
|
|
467
|
+
* Schema for validating Lexicon XRPC error definitions.
|
|
468
|
+
*
|
|
469
|
+
* Validates error definitions that can be returned by XRPC methods.
|
|
470
|
+
* Each error has a name and optional description.
|
|
471
|
+
*/
|
|
212
472
|
export const lexiconError = l.object({
|
|
213
473
|
name: l.string({ minLength: 1 }),
|
|
214
474
|
description: l.optional(l.string()),
|
|
215
475
|
})
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* TypeScript type for a Lexicon XRPC error definition.
|
|
479
|
+
*
|
|
480
|
+
* Represents an error that can be returned by an XRPC method.
|
|
481
|
+
*
|
|
482
|
+
* @see {@link lexiconError} for the schema definition
|
|
483
|
+
*/
|
|
216
484
|
export type LexiconError = l.Infer<typeof lexiconError>
|
|
217
485
|
|
|
486
|
+
/**
|
|
487
|
+
* Schema for validating Lexicon query (GET) method definitions.
|
|
488
|
+
*
|
|
489
|
+
* Validates query method definitions which represent read-only HTTP GET
|
|
490
|
+
* operations. Queries can have parameters, an output payload, and
|
|
491
|
+
* defined error types.
|
|
492
|
+
*/
|
|
218
493
|
export const lexiconQuerySchema = l.object({
|
|
219
494
|
type: l.literal('query'),
|
|
220
495
|
parameters: l.optional(lexiconParameters),
|
|
@@ -222,8 +497,23 @@ export const lexiconQuerySchema = l.object({
|
|
|
222
497
|
errors: l.optional(l.array(lexiconError)),
|
|
223
498
|
description: l.optional(l.string()),
|
|
224
499
|
})
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* TypeScript type for a Lexicon query method definition.
|
|
503
|
+
*
|
|
504
|
+
* Represents the structure of an XRPC query (GET) method.
|
|
505
|
+
*
|
|
506
|
+
* @see {@link lexiconQuerySchema} for the schema definition
|
|
507
|
+
*/
|
|
225
508
|
export type LexiconQuery = l.Infer<typeof lexiconQuerySchema>
|
|
226
509
|
|
|
510
|
+
/**
|
|
511
|
+
* Schema for validating Lexicon procedure (POST) method definitions.
|
|
512
|
+
*
|
|
513
|
+
* Validates procedure method definitions which represent HTTP POST
|
|
514
|
+
* operations that may modify state. Procedures can have parameters,
|
|
515
|
+
* input payload, output payload, and defined error types.
|
|
516
|
+
*/
|
|
227
517
|
export const lexiconProcedureSchema = l.object({
|
|
228
518
|
type: l.literal('procedure'),
|
|
229
519
|
parameters: l.optional(lexiconParameters),
|
|
@@ -232,8 +522,23 @@ export const lexiconProcedureSchema = l.object({
|
|
|
232
522
|
errors: l.optional(l.array(lexiconError)),
|
|
233
523
|
description: l.optional(l.string()),
|
|
234
524
|
})
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* TypeScript type for a Lexicon procedure method definition.
|
|
528
|
+
*
|
|
529
|
+
* Represents the structure of an XRPC procedure (POST) method.
|
|
530
|
+
*
|
|
531
|
+
* @see {@link lexiconProcedureSchema} for the schema definition
|
|
532
|
+
*/
|
|
235
533
|
export type LexiconProcedure = l.Infer<typeof lexiconProcedureSchema>
|
|
236
534
|
|
|
535
|
+
/**
|
|
536
|
+
* Schema for validating Lexicon subscription (WebSocket) method definitions.
|
|
537
|
+
*
|
|
538
|
+
* Validates subscription method definitions which represent real-time
|
|
539
|
+
* streaming connections over WebSocket. Subscriptions have parameters,
|
|
540
|
+
* a message schema defining the streamed data format, and error types.
|
|
541
|
+
*/
|
|
237
542
|
export const lexiconSubscriptionSchema = l.object({
|
|
238
543
|
type: l.literal('subscription'),
|
|
239
544
|
description: l.optional(l.string()),
|
|
@@ -245,19 +550,46 @@ export const lexiconSubscriptionSchema = l.object({
|
|
|
245
550
|
errors: l.optional(l.array(lexiconError)),
|
|
246
551
|
})
|
|
247
552
|
|
|
553
|
+
/**
|
|
554
|
+
* TypeScript type for a Lexicon subscription method definition.
|
|
555
|
+
*
|
|
556
|
+
* Represents the structure of an XRPC subscription (WebSocket) method.
|
|
557
|
+
*
|
|
558
|
+
* @see {@link lexiconSubscriptionSchema} for the schema definition
|
|
559
|
+
*/
|
|
248
560
|
export type LexiconSubscription = l.Infer<typeof lexiconSubscriptionSchema>
|
|
249
561
|
|
|
250
562
|
// Permissions
|
|
251
563
|
|
|
252
|
-
|
|
564
|
+
/**
|
|
565
|
+
* Schema for validating language codes in Lexicon permission definitions.
|
|
566
|
+
*/
|
|
567
|
+
export const lexiconLanguageSchema = l.string({ format: 'language' })
|
|
253
568
|
|
|
569
|
+
/**
|
|
570
|
+
* TypeScript type for a BCP 47 language code string.
|
|
571
|
+
*
|
|
572
|
+
* @see {@link lexiconLanguageSchema} for the schema definition
|
|
573
|
+
*/
|
|
254
574
|
export type LexiconLanguage = l.Infer<typeof lexiconLanguageSchema>
|
|
255
575
|
|
|
256
|
-
|
|
257
|
-
|
|
576
|
+
/**
|
|
577
|
+
* Schema for validating language-keyed string dictionaries.
|
|
578
|
+
* Used for localized text in permission definitions.
|
|
579
|
+
*/
|
|
580
|
+
export const lexiconLanguageDict = l.dict(lexiconLanguageSchema, l.string())
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* TypeScript type for a language-keyed dictionary of localized strings.
|
|
584
|
+
*
|
|
585
|
+
* @see {@link lexiconLanguageDict} for the schema definition
|
|
586
|
+
*/
|
|
258
587
|
export type LexiconLanguageDict = l.Infer<typeof lexiconLanguageDict>
|
|
259
588
|
|
|
260
|
-
|
|
589
|
+
/**
|
|
590
|
+
* Schema for validating individual Lexicon permission definitions.
|
|
591
|
+
*/
|
|
592
|
+
export const lexiconPermissionSchema = l.intersection(
|
|
261
593
|
l.object({
|
|
262
594
|
type: l.literal('permission'),
|
|
263
595
|
resource: l.string({ minLength: 1 }),
|
|
@@ -265,9 +597,20 @@ const lexiconPermissionSchema = l.intersection(
|
|
|
265
597
|
l.dict(l.string(), l.paramSchema),
|
|
266
598
|
)
|
|
267
599
|
|
|
600
|
+
/**
|
|
601
|
+
* TypeScript type for a Lexicon permission definition.
|
|
602
|
+
*
|
|
603
|
+
* Represents a single permission with a resource identifier
|
|
604
|
+
* and optional additional parameters.
|
|
605
|
+
*
|
|
606
|
+
* @see {@link lexiconPermissionSchema} for the schema definition
|
|
607
|
+
*/
|
|
268
608
|
export type LexiconPermission = l.Infer<typeof lexiconPermissionSchema>
|
|
269
609
|
|
|
270
|
-
|
|
610
|
+
/**
|
|
611
|
+
* Schema for validating Lexicon permission set definitions.
|
|
612
|
+
*/
|
|
613
|
+
export const lexiconPermissionSetSchema = l.object({
|
|
271
614
|
type: l.literal('permission-set'),
|
|
272
615
|
permissions: l.array(lexiconPermissionSchema),
|
|
273
616
|
title: l.optional(l.string()),
|
|
@@ -277,9 +620,16 @@ const lexiconPermissionSetSchema = l.object({
|
|
|
277
620
|
description: l.optional(l.string()),
|
|
278
621
|
})
|
|
279
622
|
|
|
623
|
+
/**
|
|
624
|
+
* TypeScript type for a Lexicon permission set definition.
|
|
625
|
+
*
|
|
626
|
+
* Represents a collection of permissions with optional
|
|
627
|
+
* localized title and detail text.
|
|
628
|
+
*
|
|
629
|
+
* @see {@link lexiconPermissionSetSchema} for the schema definition
|
|
630
|
+
*/
|
|
280
631
|
export type LexiconPermissionSet = l.Infer<typeof lexiconPermissionSetSchema>
|
|
281
632
|
|
|
282
|
-
// Schemas that can appear anywhere in the defs
|
|
283
633
|
const NAMED_LEXICON_SCHEMAS = [
|
|
284
634
|
...CONCRETE_TYPES,
|
|
285
635
|
lexiconArraySchema,
|
|
@@ -287,11 +637,16 @@ const NAMED_LEXICON_SCHEMAS = [
|
|
|
287
637
|
lexiconTokenSchema,
|
|
288
638
|
] as const
|
|
289
639
|
|
|
640
|
+
/**
|
|
641
|
+
* TypeScript type for any named Lexicon definition.
|
|
642
|
+
*
|
|
643
|
+
* Union of all definition types that can appear in the defs section
|
|
644
|
+
* of a Lexicon document (excluding main-only types).
|
|
645
|
+
*/
|
|
290
646
|
export type NamedLexiconDefinition = l.Infer<
|
|
291
647
|
(typeof NAMED_LEXICON_SCHEMAS)[number]
|
|
292
648
|
>
|
|
293
649
|
|
|
294
|
-
// Schemas that can only appear as "main" def
|
|
295
650
|
const MAIN_LEXICON_SCHEMAS = [
|
|
296
651
|
lexiconPermissionSetSchema,
|
|
297
652
|
lexiconProcedureSchema,
|
|
@@ -301,13 +656,69 @@ const MAIN_LEXICON_SCHEMAS = [
|
|
|
301
656
|
...NAMED_LEXICON_SCHEMAS,
|
|
302
657
|
] as const
|
|
303
658
|
|
|
659
|
+
/**
|
|
660
|
+
* TypeScript type for main Lexicon definitions.
|
|
661
|
+
*
|
|
662
|
+
* Union of all definition types that can appear as the "main" entry
|
|
663
|
+
* in a Lexicon document's defs section.
|
|
664
|
+
*/
|
|
304
665
|
export type MainLexiconDefinition = l.Infer<
|
|
305
666
|
(typeof MAIN_LEXICON_SCHEMAS)[number]
|
|
306
667
|
>
|
|
307
668
|
|
|
669
|
+
/**
|
|
670
|
+
* Schema for validating Lexicon document identifiers (NSIDs).
|
|
671
|
+
*
|
|
672
|
+
* Validates that the identifier follows the Namespaced Identifier format
|
|
673
|
+
* (e.g., "com.atproto.repo.createRecord").
|
|
674
|
+
*/
|
|
308
675
|
export const lexiconIdentifierSchema = l.string({ format: 'nsid' })
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* TypeScript type for a Lexicon document identifier.
|
|
679
|
+
*
|
|
680
|
+
* A Namespaced Identifier (NSID) string in reverse-domain format.
|
|
681
|
+
*
|
|
682
|
+
* @see {@link lexiconIdentifierSchema} for the schema definition
|
|
683
|
+
*/
|
|
309
684
|
export type LexiconIdentifier = l.Infer<typeof lexiconIdentifierSchema>
|
|
310
685
|
|
|
686
|
+
/**
|
|
687
|
+
* Schema for validating complete Lexicon document structures.
|
|
688
|
+
*
|
|
689
|
+
* Validates the top-level structure of a Lexicon document, including:
|
|
690
|
+
* - `lexicon`: Must be 1 (the current Lexicon version)
|
|
691
|
+
* - `id`: The document's NSID
|
|
692
|
+
* - `revision`: Optional version number
|
|
693
|
+
* - `description`: Optional document description
|
|
694
|
+
* - `defs`: Map of definition names to their schemas
|
|
695
|
+
*
|
|
696
|
+
* The "main" definition (if present) can be any main-only type,
|
|
697
|
+
* while other definitions are limited to named types.
|
|
698
|
+
*
|
|
699
|
+
* @example
|
|
700
|
+
* ```ts
|
|
701
|
+
* const result = lexiconDocumentSchema.parse({
|
|
702
|
+
* lexicon: 1,
|
|
703
|
+
* id: 'com.example.getProfile',
|
|
704
|
+
* defs: {
|
|
705
|
+
* main: {
|
|
706
|
+
* type: 'query',
|
|
707
|
+
* output: {
|
|
708
|
+
* encoding: 'application/json',
|
|
709
|
+
* schema: { type: 'ref', ref: '#profile' }
|
|
710
|
+
* }
|
|
711
|
+
* },
|
|
712
|
+
* profile: {
|
|
713
|
+
* type: 'object',
|
|
714
|
+
* properties: {
|
|
715
|
+
* name: { type: 'string' }
|
|
716
|
+
* }
|
|
717
|
+
* }
|
|
718
|
+
* }
|
|
719
|
+
* })
|
|
720
|
+
* ```
|
|
721
|
+
*/
|
|
311
722
|
export const lexiconDocumentSchema = l.object({
|
|
312
723
|
lexicon: l.literal(1),
|
|
313
724
|
id: lexiconIdentifierSchema,
|
|
@@ -323,4 +734,13 @@ export const lexiconDocumentSchema = l.object({
|
|
|
323
734
|
),
|
|
324
735
|
),
|
|
325
736
|
})
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* TypeScript type for a complete Lexicon document.
|
|
740
|
+
*
|
|
741
|
+
* Represents the full structure of a Lexicon JSON document,
|
|
742
|
+
* including the version, identifier, and all type definitions.
|
|
743
|
+
*
|
|
744
|
+
* @see {@link lexiconDocumentSchema} for the schema definition
|
|
745
|
+
*/
|
|
326
746
|
export type LexiconDocument = l.Infer<typeof lexiconDocumentSchema>
|