@atproto/lex-document 0.0.12 → 0.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/lex-document",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "license": "MIT",
5
5
  "description": "Lexicon document validation tools for AT",
6
6
  "keywords": [
@@ -32,17 +32,17 @@
32
32
  "types": "./dist/index.d.ts",
33
33
  "browser": "./dist/index.js",
34
34
  "import": "./dist/index.js",
35
- "require": "./dist/index.js"
35
+ "default": "./dist/index.js"
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
39
  "core-js": "^3",
40
40
  "tslib": "^2.8.1",
41
- "@atproto/lex-schema": "^0.0.11"
41
+ "@atproto/lex-schema": "^0.0.13"
42
42
  },
43
43
  "devDependencies": {
44
44
  "vitest": "^4.0.16",
45
- "@atproto/lex-data": "^0.0.10"
45
+ "@atproto/lex-data": "^0.0.12"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "tsc --build tsconfig.build.json",
@@ -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,10 +424,29 @@ 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
- encoding: l.string(),
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
+ }),
201
450
  schema: l.optional(
202
451
  l.discriminatedUnion('type', [
203
452
  lexiconRefSchema,
@@ -207,14 +456,44 @@ export const lexiconPayload = l.object({
207
456
  ),
208
457
  description: l.optional(l.string()),
209
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
+ */
210
468
  export type LexiconPayload = l.Infer<typeof lexiconPayload>
211
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
+ */
212
476
  export const lexiconError = l.object({
213
477
  name: l.string({ minLength: 1 }),
214
478
  description: l.optional(l.string()),
215
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
+ */
216
488
  export type LexiconError = l.Infer<typeof lexiconError>
217
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
+ */
218
497
  export const lexiconQuerySchema = l.object({
219
498
  type: l.literal('query'),
220
499
  parameters: l.optional(lexiconParameters),
@@ -222,8 +501,23 @@ export const lexiconQuerySchema = l.object({
222
501
  errors: l.optional(l.array(lexiconError)),
223
502
  description: l.optional(l.string()),
224
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
+ */
225
512
  export type LexiconQuery = l.Infer<typeof lexiconQuerySchema>
226
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
+ */
227
521
  export const lexiconProcedureSchema = l.object({
228
522
  type: l.literal('procedure'),
229
523
  parameters: l.optional(lexiconParameters),
@@ -232,8 +526,23 @@ export const lexiconProcedureSchema = l.object({
232
526
  errors: l.optional(l.array(lexiconError)),
233
527
  description: l.optional(l.string()),
234
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
+ */
235
537
  export type LexiconProcedure = l.Infer<typeof lexiconProcedureSchema>
236
538
 
539
+ /**
540
+ * Schema for validating Lexicon subscription (WebSocket) method definitions.
541
+ *
542
+ * Validates subscription method definitions which represent real-time
543
+ * streaming connections over WebSocket. Subscriptions have parameters,
544
+ * a message schema defining the streamed data format, and error types.
545
+ */
237
546
  export const lexiconSubscriptionSchema = l.object({
238
547
  type: l.literal('subscription'),
239
548
  description: l.optional(l.string()),
@@ -245,19 +554,46 @@ export const lexiconSubscriptionSchema = l.object({
245
554
  errors: l.optional(l.array(lexiconError)),
246
555
  })
247
556
 
557
+ /**
558
+ * TypeScript type for a Lexicon subscription method definition.
559
+ *
560
+ * Represents the structure of an XRPC subscription (WebSocket) method.
561
+ *
562
+ * @see {@link lexiconSubscriptionSchema} for the schema definition
563
+ */
248
564
  export type LexiconSubscription = l.Infer<typeof lexiconSubscriptionSchema>
249
565
 
250
566
  // Permissions
251
567
 
252
- const lexiconLanguageSchema = l.string({ format: 'language' })
568
+ /**
569
+ * Schema for validating language codes in Lexicon permission definitions.
570
+ */
571
+ export const lexiconLanguageSchema = l.string({ format: 'language' })
253
572
 
573
+ /**
574
+ * TypeScript type for a BCP 47 language code string.
575
+ *
576
+ * @see {@link lexiconLanguageSchema} for the schema definition
577
+ */
254
578
  export type LexiconLanguage = l.Infer<typeof lexiconLanguageSchema>
255
579
 
256
- const lexiconLanguageDict = l.dict(lexiconLanguageSchema, l.string())
257
-
580
+ /**
581
+ * Schema for validating language-keyed string dictionaries.
582
+ * Used for localized text in permission definitions.
583
+ */
584
+ export const lexiconLanguageDict = l.dict(lexiconLanguageSchema, l.string())
585
+
586
+ /**
587
+ * TypeScript type for a language-keyed dictionary of localized strings.
588
+ *
589
+ * @see {@link lexiconLanguageDict} for the schema definition
590
+ */
258
591
  export type LexiconLanguageDict = l.Infer<typeof lexiconLanguageDict>
259
592
 
260
- const lexiconPermissionSchema = l.intersection(
593
+ /**
594
+ * Schema for validating individual Lexicon permission definitions.
595
+ */
596
+ export const lexiconPermissionSchema = l.intersection(
261
597
  l.object({
262
598
  type: l.literal('permission'),
263
599
  resource: l.string({ minLength: 1 }),
@@ -265,9 +601,20 @@ const lexiconPermissionSchema = l.intersection(
265
601
  l.dict(l.string(), l.paramSchema),
266
602
  )
267
603
 
604
+ /**
605
+ * TypeScript type for a Lexicon permission definition.
606
+ *
607
+ * Represents a single permission with a resource identifier
608
+ * and optional additional parameters.
609
+ *
610
+ * @see {@link lexiconPermissionSchema} for the schema definition
611
+ */
268
612
  export type LexiconPermission = l.Infer<typeof lexiconPermissionSchema>
269
613
 
270
- const lexiconPermissionSetSchema = l.object({
614
+ /**
615
+ * Schema for validating Lexicon permission set definitions.
616
+ */
617
+ export const lexiconPermissionSetSchema = l.object({
271
618
  type: l.literal('permission-set'),
272
619
  permissions: l.array(lexiconPermissionSchema),
273
620
  title: l.optional(l.string()),
@@ -277,9 +624,16 @@ const lexiconPermissionSetSchema = l.object({
277
624
  description: l.optional(l.string()),
278
625
  })
279
626
 
627
+ /**
628
+ * TypeScript type for a Lexicon permission set definition.
629
+ *
630
+ * Represents a collection of permissions with optional
631
+ * localized title and detail text.
632
+ *
633
+ * @see {@link lexiconPermissionSetSchema} for the schema definition
634
+ */
280
635
  export type LexiconPermissionSet = l.Infer<typeof lexiconPermissionSetSchema>
281
636
 
282
- // Schemas that can appear anywhere in the defs
283
637
  const NAMED_LEXICON_SCHEMAS = [
284
638
  ...CONCRETE_TYPES,
285
639
  lexiconArraySchema,
@@ -287,11 +641,16 @@ const NAMED_LEXICON_SCHEMAS = [
287
641
  lexiconTokenSchema,
288
642
  ] as const
289
643
 
644
+ /**
645
+ * TypeScript type for any named Lexicon definition.
646
+ *
647
+ * Union of all definition types that can appear in the defs section
648
+ * of a Lexicon document (excluding main-only types).
649
+ */
290
650
  export type NamedLexiconDefinition = l.Infer<
291
651
  (typeof NAMED_LEXICON_SCHEMAS)[number]
292
652
  >
293
653
 
294
- // Schemas that can only appear as "main" def
295
654
  const MAIN_LEXICON_SCHEMAS = [
296
655
  lexiconPermissionSetSchema,
297
656
  lexiconProcedureSchema,
@@ -301,13 +660,69 @@ const MAIN_LEXICON_SCHEMAS = [
301
660
  ...NAMED_LEXICON_SCHEMAS,
302
661
  ] as const
303
662
 
663
+ /**
664
+ * TypeScript type for main Lexicon definitions.
665
+ *
666
+ * Union of all definition types that can appear as the "main" entry
667
+ * in a Lexicon document's defs section.
668
+ */
304
669
  export type MainLexiconDefinition = l.Infer<
305
670
  (typeof MAIN_LEXICON_SCHEMAS)[number]
306
671
  >
307
672
 
673
+ /**
674
+ * Schema for validating Lexicon document identifiers (NSIDs).
675
+ *
676
+ * Validates that the identifier follows the Namespaced Identifier format
677
+ * (e.g., "com.atproto.repo.createRecord").
678
+ */
308
679
  export const lexiconIdentifierSchema = l.string({ format: 'nsid' })
680
+
681
+ /**
682
+ * TypeScript type for a Lexicon document identifier.
683
+ *
684
+ * A Namespaced Identifier (NSID) string in reverse-domain format.
685
+ *
686
+ * @see {@link lexiconIdentifierSchema} for the schema definition
687
+ */
309
688
  export type LexiconIdentifier = l.Infer<typeof lexiconIdentifierSchema>
310
689
 
690
+ /**
691
+ * Schema for validating complete Lexicon document structures.
692
+ *
693
+ * Validates the top-level structure of a Lexicon document, including:
694
+ * - `lexicon`: Must be 1 (the current Lexicon version)
695
+ * - `id`: The document's NSID
696
+ * - `revision`: Optional version number
697
+ * - `description`: Optional document description
698
+ * - `defs`: Map of definition names to their schemas
699
+ *
700
+ * The "main" definition (if present) can be any main-only type,
701
+ * while other definitions are limited to named types.
702
+ *
703
+ * @example
704
+ * ```ts
705
+ * const result = lexiconDocumentSchema.parse({
706
+ * lexicon: 1,
707
+ * id: 'com.example.getProfile',
708
+ * defs: {
709
+ * main: {
710
+ * type: 'query',
711
+ * output: {
712
+ * encoding: 'application/json',
713
+ * schema: { type: 'ref', ref: '#profile' }
714
+ * }
715
+ * },
716
+ * profile: {
717
+ * type: 'object',
718
+ * properties: {
719
+ * name: { type: 'string' }
720
+ * }
721
+ * }
722
+ * }
723
+ * })
724
+ * ```
725
+ */
311
726
  export const lexiconDocumentSchema = l.object({
312
727
  lexicon: l.literal(1),
313
728
  id: lexiconIdentifierSchema,
@@ -323,4 +738,13 @@ export const lexiconDocumentSchema = l.object({
323
738
  ),
324
739
  ),
325
740
  })
741
+
742
+ /**
743
+ * TypeScript type for a complete Lexicon document.
744
+ *
745
+ * Represents the full structure of a Lexicon JSON document,
746
+ * including the version, identifier, and all type definitions.
747
+ *
748
+ * @see {@link lexiconDocumentSchema} for the schema definition
749
+ */
326
750
  export type LexiconDocument = l.Infer<typeof lexiconDocumentSchema>