@atproto/lex-document 0.0.21 → 0.1.0
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 +17 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -9
- package/dist/index.js.map +1 -1
- package/dist/lexicon-document.js +161 -164
- package/dist/lexicon-document.js.map +1 -1
- package/dist/lexicon-indexer.js +1 -2
- package/dist/lexicon-iterable-indexer.js +1 -6
- package/dist/lexicon-iterable-indexer.js.map +1 -1
- package/dist/lexicon-schema-builder.js +54 -59
- package/dist/lexicon-schema-builder.js.map +1 -1
- package/package.json +7 -8
- package/src/core-js.d.ts +2 -0
- package/src/index.ts +2 -2
- package/tsconfig.tests.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atproto/lex-document
|
|
2
2
|
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#4929](https://github.com/bluesky-social/atproto/pull/4929) [`f01c59f`](https://github.com/bluesky-social/atproto/commit/f01c59f5bd3f75fb8b47a9eecd4858b84033fb7c) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Drop support for Node.js 18 and 20. Node.js 22 is now the minimum supported version. Docker images now use Node.js 24.
|
|
8
|
+
|
|
9
|
+
- [#4943](https://github.com/bluesky-social/atproto/pull/4943) [`c459153`](https://github.com/bluesky-social/atproto/commit/c459153395a30ce89e050892c8fab7dc98e019b9) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Convert to pure ESM. All packages now ship `"type": "module"` with ES module output and Node16 module resolution.
|
|
10
|
+
|
|
11
|
+
Node.js 22's `require()` compatibility layer can still load these packages in CommonJS code.
|
|
12
|
+
|
|
13
|
+
- [#4930](https://github.com/bluesky-social/atproto/pull/4930) [`908bece`](https://github.com/bluesky-social/atproto/commit/908bece169258bff5ad121e5eec157d6ded6f705) Thanks [@devinivy](https://github.com/devinivy)! - Build with TypeScript 6.0.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`f01c59f`](https://github.com/bluesky-social/atproto/commit/f01c59f5bd3f75fb8b47a9eecd4858b84033fb7c), [`c459153`](https://github.com/bluesky-social/atproto/commit/c459153395a30ce89e050892c8fab7dc98e019b9), [`908bece`](https://github.com/bluesky-social/atproto/commit/908bece169258bff5ad121e5eec157d6ded6f705)]:
|
|
18
|
+
- @atproto/lex-schema@0.1.0
|
|
19
|
+
|
|
3
20
|
## 0.0.21
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import 'core-js/
|
|
2
|
-
import 'core-js/
|
|
1
|
+
import 'core-js/es/symbol/async-dispose.js';
|
|
2
|
+
import 'core-js/es/symbol/dispose.js';
|
|
3
3
|
export * from './lexicon-document.js';
|
|
4
4
|
export * from './lexicon-indexer.js';
|
|
5
5
|
export * from './lexicon-schema-builder.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,oCAAoC,CAAA;AAC3C,OAAO,8BAA8B,CAAA;AAErC,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,+BAA+B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
tslib_1.__exportStar(require("./lexicon-indexer.js"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./lexicon-schema-builder.js"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./lexicon-iterable-indexer.js"), exports);
|
|
1
|
+
import 'core-js/es/symbol/async-dispose.js';
|
|
2
|
+
import 'core-js/es/symbol/dispose.js';
|
|
3
|
+
export * from './lexicon-document.js';
|
|
4
|
+
export * from './lexicon-indexer.js';
|
|
5
|
+
export * from './lexicon-schema-builder.js';
|
|
6
|
+
export * from './lexicon-iterable-indexer.js';
|
|
10
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,oCAAoC,CAAA;AAC3C,OAAO,8BAA8B,CAAA;AAErC,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,+BAA+B,CAAA","sourcesContent":["import 'core-js/es/symbol/async-dispose.js'\nimport 'core-js/es/symbol/dispose.js'\n\nexport * from './lexicon-document.js'\nexport * from './lexicon-indexer.js'\nexport * from './lexicon-schema-builder.js'\nexport * from './lexicon-iterable-indexer.js'\n"]}
|
package/dist/lexicon-document.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lexiconDocumentSchema = exports.lexiconIdentifierSchema = exports.lexiconPermissionSetSchema = exports.lexiconPermissionSchema = exports.lexiconLanguageDict = exports.lexiconLanguageSchema = exports.lexiconSubscriptionSchema = exports.lexiconProcedureSchema = exports.lexiconQuerySchema = exports.lexiconError = exports.lexiconPayload = exports.lexiconParameters = exports.lexiconRecordSchema = exports.lexiconRecordKeySchema = exports.lexiconObjectSchema = exports.lexiconArraySchema = exports.lexiconRefUnionSchema = exports.lexiconRefSchema = exports.lexiconTokenSchema = exports.lexiconUnknownSchema = exports.lexiconBlobSchema = exports.lexiconCidLinkSchema = exports.lexiconBytesSchema = exports.lexiconStringSchema = exports.lexiconIntegerSchema = exports.lexiconBooleanSchema = void 0;
|
|
4
|
-
const lex_schema_1 = require("@atproto/lex-schema");
|
|
1
|
+
import { l } from '@atproto/lex-schema';
|
|
5
2
|
// https://atproto.com/specs/lexicon
|
|
6
3
|
// "Concrete" Types
|
|
7
4
|
/**
|
|
@@ -10,11 +7,11 @@ const lex_schema_1 = require("@atproto/lex-schema");
|
|
|
10
7
|
* Validates boolean field definitions that may include a default value,
|
|
11
8
|
* a constant value, and an optional description.
|
|
12
9
|
*/
|
|
13
|
-
|
|
14
|
-
type:
|
|
15
|
-
default:
|
|
16
|
-
const:
|
|
17
|
-
description:
|
|
10
|
+
export const lexiconBooleanSchema = l.object({
|
|
11
|
+
type: l.literal('boolean'),
|
|
12
|
+
default: l.optional(l.boolean()),
|
|
13
|
+
const: l.optional(l.boolean()),
|
|
14
|
+
description: l.optional(l.string()),
|
|
18
15
|
});
|
|
19
16
|
/**
|
|
20
17
|
* Schema for validating Lexicon integer type definitions.
|
|
@@ -22,14 +19,14 @@ exports.lexiconBooleanSchema = lex_schema_1.l.object({
|
|
|
22
19
|
* Validates integer field definitions with support for default values,
|
|
23
20
|
* minimum/maximum constraints, enumerated values, and constant values.
|
|
24
21
|
*/
|
|
25
|
-
|
|
26
|
-
type:
|
|
27
|
-
default:
|
|
28
|
-
minimum:
|
|
29
|
-
maximum:
|
|
30
|
-
enum:
|
|
31
|
-
const:
|
|
32
|
-
description:
|
|
22
|
+
export const lexiconIntegerSchema = l.object({
|
|
23
|
+
type: l.literal('integer'),
|
|
24
|
+
default: l.optional(l.integer()),
|
|
25
|
+
minimum: l.optional(l.integer()),
|
|
26
|
+
maximum: l.optional(l.integer()),
|
|
27
|
+
enum: l.optional(l.array(l.integer())),
|
|
28
|
+
const: l.optional(l.integer()),
|
|
29
|
+
description: l.optional(l.string()),
|
|
33
30
|
});
|
|
34
31
|
/**
|
|
35
32
|
* Schema for validating Lexicon string type definitions.
|
|
@@ -38,18 +35,18 @@ exports.lexiconIntegerSchema = lex_schema_1.l.object({
|
|
|
38
35
|
* length constraints (both character and grapheme-based), enumerated values,
|
|
39
36
|
* known values, and constant values.
|
|
40
37
|
*/
|
|
41
|
-
|
|
42
|
-
type:
|
|
43
|
-
format:
|
|
44
|
-
default:
|
|
45
|
-
minLength:
|
|
46
|
-
maxLength:
|
|
47
|
-
minGraphemes:
|
|
48
|
-
maxGraphemes:
|
|
49
|
-
enum:
|
|
50
|
-
const:
|
|
51
|
-
knownValues:
|
|
52
|
-
description:
|
|
38
|
+
export const lexiconStringSchema = l.object({
|
|
39
|
+
type: l.literal('string'),
|
|
40
|
+
format: l.optional(l.enum(l.STRING_FORMATS)),
|
|
41
|
+
default: l.optional(l.string()),
|
|
42
|
+
minLength: l.optional(l.integer()),
|
|
43
|
+
maxLength: l.optional(l.integer()),
|
|
44
|
+
minGraphemes: l.optional(l.integer()),
|
|
45
|
+
maxGraphemes: l.optional(l.integer()),
|
|
46
|
+
enum: l.optional(l.array(l.string())),
|
|
47
|
+
const: l.optional(l.string()),
|
|
48
|
+
knownValues: l.optional(l.array(l.string())),
|
|
49
|
+
description: l.optional(l.string()),
|
|
53
50
|
});
|
|
54
51
|
/**
|
|
55
52
|
* Schema for validating Lexicon bytes type definitions.
|
|
@@ -57,11 +54,11 @@ exports.lexiconStringSchema = lex_schema_1.l.object({
|
|
|
57
54
|
* Validates binary data field definitions with optional length constraints.
|
|
58
55
|
* Used for raw byte arrays in DAG-CBOR encoding.
|
|
59
56
|
*/
|
|
60
|
-
|
|
61
|
-
type:
|
|
62
|
-
maxLength:
|
|
63
|
-
minLength:
|
|
64
|
-
description:
|
|
57
|
+
export const lexiconBytesSchema = l.object({
|
|
58
|
+
type: l.literal('bytes'),
|
|
59
|
+
maxLength: l.optional(l.integer()),
|
|
60
|
+
minLength: l.optional(l.integer()),
|
|
61
|
+
description: l.optional(l.string()),
|
|
65
62
|
});
|
|
66
63
|
/**
|
|
67
64
|
* Schema for validating Lexicon CID link type definitions.
|
|
@@ -69,9 +66,9 @@ exports.lexiconBytesSchema = lex_schema_1.l.object({
|
|
|
69
66
|
* Validates Content Identifier (CID) link field definitions.
|
|
70
67
|
* CIDs are used to reference content-addressed data in IPFS/IPLD.
|
|
71
68
|
*/
|
|
72
|
-
|
|
73
|
-
type:
|
|
74
|
-
description:
|
|
69
|
+
export const lexiconCidLinkSchema = l.object({
|
|
70
|
+
type: l.literal('cid-link'),
|
|
71
|
+
description: l.optional(l.string()),
|
|
75
72
|
});
|
|
76
73
|
/**
|
|
77
74
|
* Schema for validating Lexicon blob type definitions.
|
|
@@ -79,25 +76,25 @@ exports.lexiconCidLinkSchema = lex_schema_1.l.object({
|
|
|
79
76
|
* Validates blob field definitions with optional MIME type acceptance list
|
|
80
77
|
* and maximum size constraints. Blobs represent uploaded file references.
|
|
81
78
|
*/
|
|
82
|
-
|
|
83
|
-
type:
|
|
84
|
-
accept:
|
|
85
|
-
maxSize:
|
|
86
|
-
description:
|
|
79
|
+
export const lexiconBlobSchema = l.object({
|
|
80
|
+
type: l.literal('blob'),
|
|
81
|
+
accept: l.optional(l.array(l.string())),
|
|
82
|
+
maxSize: l.optional(l.integer()),
|
|
83
|
+
description: l.optional(l.string()),
|
|
87
84
|
});
|
|
88
85
|
/**
|
|
89
86
|
* Array of all concrete (primitive) Lexicon type schemas.
|
|
90
87
|
* Includes boolean, integer, string, bytes, cid-link, and blob types.
|
|
91
88
|
*/
|
|
92
89
|
const CONCRETE_TYPES = [
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
lexiconBooleanSchema,
|
|
91
|
+
lexiconIntegerSchema,
|
|
92
|
+
lexiconStringSchema,
|
|
96
93
|
// Lexicon (DAG-CBOR)
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
lexiconBytesSchema,
|
|
95
|
+
lexiconCidLinkSchema,
|
|
99
96
|
// Lexicon Specific
|
|
100
|
-
|
|
97
|
+
lexiconBlobSchema,
|
|
101
98
|
];
|
|
102
99
|
// Meta types
|
|
103
100
|
/**
|
|
@@ -106,9 +103,9 @@ const CONCRETE_TYPES = [
|
|
|
106
103
|
* Validates unknown field definitions which accept any valid data.
|
|
107
104
|
* Used when the schema cannot determine the type ahead of time.
|
|
108
105
|
*/
|
|
109
|
-
|
|
110
|
-
type:
|
|
111
|
-
description:
|
|
106
|
+
export const lexiconUnknownSchema = l.object({
|
|
107
|
+
type: l.literal('unknown'),
|
|
108
|
+
description: l.optional(l.string()),
|
|
112
109
|
});
|
|
113
110
|
/**
|
|
114
111
|
* Schema for validating Lexicon token type definitions.
|
|
@@ -117,9 +114,9 @@ exports.lexiconUnknownSchema = lex_schema_1.l.object({
|
|
|
117
114
|
* Tokens are used to define enumeration-like values that can be
|
|
118
115
|
* referenced across different lexicons.
|
|
119
116
|
*/
|
|
120
|
-
|
|
121
|
-
type:
|
|
122
|
-
description:
|
|
117
|
+
export const lexiconTokenSchema = l.object({
|
|
118
|
+
type: l.literal('token'),
|
|
119
|
+
description: l.optional(l.string()),
|
|
123
120
|
});
|
|
124
121
|
/**
|
|
125
122
|
* Schema for validating Lexicon reference type definitions.
|
|
@@ -128,10 +125,10 @@ exports.lexiconTokenSchema = lex_schema_1.l.object({
|
|
|
128
125
|
* within the same or different Lexicon documents. References use the
|
|
129
126
|
* format "nsid#defName" for cross-document refs or "#defName" for local refs.
|
|
130
127
|
*/
|
|
131
|
-
|
|
132
|
-
type:
|
|
133
|
-
ref:
|
|
134
|
-
description:
|
|
128
|
+
export const lexiconRefSchema = l.object({
|
|
129
|
+
type: l.literal('ref'),
|
|
130
|
+
ref: l.string(),
|
|
131
|
+
description: l.optional(l.string()),
|
|
135
132
|
});
|
|
136
133
|
/**
|
|
137
134
|
* Schema for validating Lexicon union reference type definitions.
|
|
@@ -140,19 +137,19 @@ exports.lexiconRefSchema = lex_schema_1.l.object({
|
|
|
140
137
|
* The union can be closed (only listed types allowed) or open (allows
|
|
141
138
|
* additional unlisted types).
|
|
142
139
|
*/
|
|
143
|
-
|
|
144
|
-
type:
|
|
145
|
-
refs:
|
|
146
|
-
closed:
|
|
147
|
-
description:
|
|
140
|
+
export const lexiconRefUnionSchema = l.object({
|
|
141
|
+
type: l.literal('union'),
|
|
142
|
+
refs: l.array(l.string()),
|
|
143
|
+
closed: l.optional(l.boolean()),
|
|
144
|
+
description: l.optional(l.string()),
|
|
148
145
|
});
|
|
149
146
|
// Complex Types
|
|
150
147
|
const ARRAY_ITEMS_SCHEMAS = [
|
|
151
148
|
...CONCRETE_TYPES,
|
|
152
149
|
// Meta
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
150
|
+
lexiconUnknownSchema,
|
|
151
|
+
lexiconRefSchema,
|
|
152
|
+
lexiconRefUnionSchema,
|
|
156
153
|
];
|
|
157
154
|
/**
|
|
158
155
|
* Schema for validating Lexicon array type definitions.
|
|
@@ -160,12 +157,12 @@ const ARRAY_ITEMS_SCHEMAS = [
|
|
|
160
157
|
* Validates array field definitions with specified item type and
|
|
161
158
|
* optional length constraints.
|
|
162
159
|
*/
|
|
163
|
-
|
|
164
|
-
type:
|
|
165
|
-
items:
|
|
166
|
-
minLength:
|
|
167
|
-
maxLength:
|
|
168
|
-
description:
|
|
160
|
+
export const lexiconArraySchema = l.object({
|
|
161
|
+
type: l.literal('array'),
|
|
162
|
+
items: l.discriminatedUnion('type', ARRAY_ITEMS_SCHEMAS),
|
|
163
|
+
minLength: l.optional(l.integer()),
|
|
164
|
+
maxLength: l.optional(l.integer()),
|
|
165
|
+
description: l.optional(l.string()),
|
|
169
166
|
});
|
|
170
167
|
const requirePropertiesRefinement = {
|
|
171
168
|
check: (v) => !v.required || v.required.every((k) => k in v.properties),
|
|
@@ -179,15 +176,15 @@ const requirePropertiesRefinement = {
|
|
|
179
176
|
* and nullable field lists. Includes refinement to ensure all required
|
|
180
177
|
* properties are defined in the properties map.
|
|
181
178
|
*/
|
|
182
|
-
|
|
183
|
-
type:
|
|
184
|
-
properties:
|
|
179
|
+
export const lexiconObjectSchema = l.refine(l.object({
|
|
180
|
+
type: l.literal('object'),
|
|
181
|
+
properties: l.dict(l.string(), l.discriminatedUnion('type', [
|
|
185
182
|
...ARRAY_ITEMS_SCHEMAS,
|
|
186
|
-
|
|
183
|
+
lexiconArraySchema,
|
|
187
184
|
])),
|
|
188
|
-
required:
|
|
189
|
-
nullable:
|
|
190
|
-
description:
|
|
185
|
+
required: l.optional(l.array(l.string())),
|
|
186
|
+
nullable: l.optional(l.array(l.string())),
|
|
187
|
+
description: l.optional(l.string()),
|
|
191
188
|
}), requirePropertiesRefinement);
|
|
192
189
|
// Records
|
|
193
190
|
/**
|
|
@@ -199,7 +196,7 @@ exports.lexiconObjectSchema = lex_schema_1.l.refine(lex_schema_1.l.object({
|
|
|
199
196
|
* - "tid": Timestamp identifier
|
|
200
197
|
* - "literal:<string>": A specific literal string value
|
|
201
198
|
*/
|
|
202
|
-
|
|
199
|
+
export const lexiconRecordKeySchema = l.custom(l.isLexiconRecordKey, 'Invalid record key definition (must be "any", "nsid", "tid", or "literal:<string>")');
|
|
203
200
|
/**
|
|
204
201
|
* Schema for validating Lexicon record type definitions.
|
|
205
202
|
*
|
|
@@ -207,11 +204,11 @@ exports.lexiconRecordKeySchema = lex_schema_1.l.custom(lex_schema_1.l.isLexiconR
|
|
|
207
204
|
* stored in AT Protocol repositories. Records have a key type
|
|
208
205
|
* and an object schema defining the record's data structure.
|
|
209
206
|
*/
|
|
210
|
-
|
|
211
|
-
type:
|
|
212
|
-
record:
|
|
213
|
-
description:
|
|
214
|
-
key:
|
|
207
|
+
export const lexiconRecordSchema = l.object({
|
|
208
|
+
type: l.literal('record'),
|
|
209
|
+
record: lexiconObjectSchema,
|
|
210
|
+
description: l.optional(l.string()),
|
|
211
|
+
key: lexiconRecordKeySchema,
|
|
215
212
|
});
|
|
216
213
|
// XRPC Methods
|
|
217
214
|
/**
|
|
@@ -221,26 +218,26 @@ exports.lexiconRecordSchema = lex_schema_1.l.object({
|
|
|
221
218
|
* Parameters can only be primitive types (boolean, integer, string)
|
|
222
219
|
* or arrays of primitives.
|
|
223
220
|
*/
|
|
224
|
-
|
|
225
|
-
type:
|
|
226
|
-
properties:
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
type:
|
|
232
|
-
items:
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
221
|
+
export const lexiconParameters = l.refine(l.object({
|
|
222
|
+
type: l.literal('params'),
|
|
223
|
+
properties: l.dict(l.string(), l.discriminatedUnion('type', [
|
|
224
|
+
lexiconBooleanSchema,
|
|
225
|
+
lexiconIntegerSchema,
|
|
226
|
+
lexiconStringSchema,
|
|
227
|
+
l.object({
|
|
228
|
+
type: l.literal('array'),
|
|
229
|
+
items: l.discriminatedUnion('type', [
|
|
230
|
+
lexiconBooleanSchema,
|
|
231
|
+
lexiconIntegerSchema,
|
|
232
|
+
lexiconStringSchema,
|
|
236
233
|
]),
|
|
237
|
-
minLength:
|
|
238
|
-
maxLength:
|
|
239
|
-
description:
|
|
234
|
+
minLength: l.optional(l.integer()),
|
|
235
|
+
maxLength: l.optional(l.integer()),
|
|
236
|
+
description: l.optional(l.string()),
|
|
240
237
|
}),
|
|
241
238
|
])),
|
|
242
|
-
required:
|
|
243
|
-
description:
|
|
239
|
+
required: l.optional(l.array(l.string())),
|
|
240
|
+
description: l.optional(l.string()),
|
|
244
241
|
}), requirePropertiesRefinement);
|
|
245
242
|
/**
|
|
246
243
|
* Schema for validating Lexicon XRPC method payloads.
|
|
@@ -249,17 +246,17 @@ exports.lexiconParameters = lex_schema_1.l.refine(lex_schema_1.l.object({
|
|
|
249
246
|
* Payloads specify the encoding (MIME type) and optional schema for
|
|
250
247
|
* the request or response body.
|
|
251
248
|
*/
|
|
252
|
-
|
|
253
|
-
encoding:
|
|
249
|
+
export const lexiconPayload = l.object({
|
|
250
|
+
encoding: l.refine(l.string(), {
|
|
254
251
|
check: (v) => !v.includes(',') && !v.includes(';') && !v.includes(' '),
|
|
255
252
|
message: 'Invalid encoding string (must be a single MIME type without parameters)',
|
|
256
253
|
}),
|
|
257
|
-
schema:
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
254
|
+
schema: l.optional(l.discriminatedUnion('type', [
|
|
255
|
+
lexiconRefSchema,
|
|
256
|
+
lexiconRefUnionSchema,
|
|
257
|
+
lexiconObjectSchema,
|
|
261
258
|
])),
|
|
262
|
-
description:
|
|
259
|
+
description: l.optional(l.string()),
|
|
263
260
|
});
|
|
264
261
|
/**
|
|
265
262
|
* Schema for validating Lexicon XRPC error definitions.
|
|
@@ -267,9 +264,9 @@ exports.lexiconPayload = lex_schema_1.l.object({
|
|
|
267
264
|
* Validates error definitions that can be returned by XRPC methods.
|
|
268
265
|
* Each error has a name and optional description.
|
|
269
266
|
*/
|
|
270
|
-
|
|
271
|
-
name:
|
|
272
|
-
description:
|
|
267
|
+
export const lexiconError = l.object({
|
|
268
|
+
name: l.string({ minLength: 1 }),
|
|
269
|
+
description: l.optional(l.string()),
|
|
273
270
|
});
|
|
274
271
|
/**
|
|
275
272
|
* Schema for validating Lexicon query (GET) method definitions.
|
|
@@ -278,12 +275,12 @@ exports.lexiconError = lex_schema_1.l.object({
|
|
|
278
275
|
* operations. Queries can have parameters, an output payload, and
|
|
279
276
|
* defined error types.
|
|
280
277
|
*/
|
|
281
|
-
|
|
282
|
-
type:
|
|
283
|
-
parameters:
|
|
284
|
-
output:
|
|
285
|
-
errors:
|
|
286
|
-
description:
|
|
278
|
+
export const lexiconQuerySchema = l.object({
|
|
279
|
+
type: l.literal('query'),
|
|
280
|
+
parameters: l.optional(lexiconParameters),
|
|
281
|
+
output: l.optional(lexiconPayload),
|
|
282
|
+
errors: l.optional(l.array(lexiconError)),
|
|
283
|
+
description: l.optional(l.string()),
|
|
287
284
|
});
|
|
288
285
|
/**
|
|
289
286
|
* Schema for validating Lexicon procedure (POST) method definitions.
|
|
@@ -292,13 +289,13 @@ exports.lexiconQuerySchema = lex_schema_1.l.object({
|
|
|
292
289
|
* operations that may modify state. Procedures can have parameters,
|
|
293
290
|
* input payload, output payload, and defined error types.
|
|
294
291
|
*/
|
|
295
|
-
|
|
296
|
-
type:
|
|
297
|
-
parameters:
|
|
298
|
-
input:
|
|
299
|
-
output:
|
|
300
|
-
errors:
|
|
301
|
-
description:
|
|
292
|
+
export const lexiconProcedureSchema = l.object({
|
|
293
|
+
type: l.literal('procedure'),
|
|
294
|
+
parameters: l.optional(lexiconParameters),
|
|
295
|
+
input: l.optional(lexiconPayload),
|
|
296
|
+
output: l.optional(lexiconPayload),
|
|
297
|
+
errors: l.optional(l.array(lexiconError)),
|
|
298
|
+
description: l.optional(l.string()),
|
|
302
299
|
});
|
|
303
300
|
/**
|
|
304
301
|
* Schema for validating Lexicon subscription (WebSocket) method definitions.
|
|
@@ -307,57 +304,57 @@ exports.lexiconProcedureSchema = lex_schema_1.l.object({
|
|
|
307
304
|
* streaming connections over WebSocket. Subscriptions have parameters,
|
|
308
305
|
* a message schema defining the streamed data format, and error types.
|
|
309
306
|
*/
|
|
310
|
-
|
|
311
|
-
type:
|
|
312
|
-
description:
|
|
313
|
-
parameters:
|
|
314
|
-
message:
|
|
315
|
-
description:
|
|
316
|
-
schema:
|
|
307
|
+
export const lexiconSubscriptionSchema = l.object({
|
|
308
|
+
type: l.literal('subscription'),
|
|
309
|
+
description: l.optional(l.string()),
|
|
310
|
+
parameters: l.optional(lexiconParameters),
|
|
311
|
+
message: l.object({
|
|
312
|
+
description: l.optional(l.string()),
|
|
313
|
+
schema: lexiconRefUnionSchema,
|
|
317
314
|
}),
|
|
318
|
-
errors:
|
|
315
|
+
errors: l.optional(l.array(lexiconError)),
|
|
319
316
|
});
|
|
320
317
|
// Permissions
|
|
321
318
|
/**
|
|
322
319
|
* Schema for validating language codes in Lexicon permission definitions.
|
|
323
320
|
*/
|
|
324
|
-
|
|
321
|
+
export const lexiconLanguageSchema = l.string({ format: 'language' });
|
|
325
322
|
/**
|
|
326
323
|
* Schema for validating language-keyed string dictionaries.
|
|
327
324
|
* Used for localized text in permission definitions.
|
|
328
325
|
*/
|
|
329
|
-
|
|
326
|
+
export const lexiconLanguageDict = l.dict(lexiconLanguageSchema, l.string());
|
|
330
327
|
/**
|
|
331
328
|
* Schema for validating individual Lexicon permission definitions.
|
|
332
329
|
*/
|
|
333
|
-
|
|
334
|
-
type:
|
|
335
|
-
resource:
|
|
336
|
-
}),
|
|
330
|
+
export const lexiconPermissionSchema = l.intersection(l.object({
|
|
331
|
+
type: l.literal('permission'),
|
|
332
|
+
resource: l.string({ minLength: 1 }),
|
|
333
|
+
}), l.dict(l.string(), l.paramSchema));
|
|
337
334
|
/**
|
|
338
335
|
* Schema for validating Lexicon permission set definitions.
|
|
339
336
|
*/
|
|
340
|
-
|
|
341
|
-
type:
|
|
342
|
-
permissions:
|
|
343
|
-
title:
|
|
344
|
-
'title:lang':
|
|
345
|
-
detail:
|
|
346
|
-
'detail:lang':
|
|
347
|
-
description:
|
|
337
|
+
export const lexiconPermissionSetSchema = l.object({
|
|
338
|
+
type: l.literal('permission-set'),
|
|
339
|
+
permissions: l.array(lexiconPermissionSchema),
|
|
340
|
+
title: l.optional(l.string()),
|
|
341
|
+
'title:lang': l.optional(lexiconLanguageDict),
|
|
342
|
+
detail: l.optional(l.string()),
|
|
343
|
+
'detail:lang': l.optional(lexiconLanguageDict),
|
|
344
|
+
description: l.optional(l.string()),
|
|
348
345
|
});
|
|
349
346
|
const NAMED_LEXICON_SCHEMAS = [
|
|
350
347
|
...CONCRETE_TYPES,
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
348
|
+
lexiconArraySchema,
|
|
349
|
+
lexiconObjectSchema,
|
|
350
|
+
lexiconTokenSchema,
|
|
354
351
|
];
|
|
355
352
|
const MAIN_LEXICON_SCHEMAS = [
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
353
|
+
lexiconPermissionSetSchema,
|
|
354
|
+
lexiconProcedureSchema,
|
|
355
|
+
lexiconQuerySchema,
|
|
356
|
+
lexiconRecordSchema,
|
|
357
|
+
lexiconSubscriptionSchema,
|
|
361
358
|
...NAMED_LEXICON_SCHEMAS,
|
|
362
359
|
];
|
|
363
360
|
/**
|
|
@@ -366,7 +363,7 @@ const MAIN_LEXICON_SCHEMAS = [
|
|
|
366
363
|
* Validates that the identifier follows the Namespaced Identifier format
|
|
367
364
|
* (e.g., "com.atproto.repo.createRecord").
|
|
368
365
|
*/
|
|
369
|
-
|
|
366
|
+
export const lexiconIdentifierSchema = l.string({ format: 'nsid' });
|
|
370
367
|
/**
|
|
371
368
|
* Schema for validating complete Lexicon document structures.
|
|
372
369
|
*
|
|
@@ -403,13 +400,13 @@ exports.lexiconIdentifierSchema = lex_schema_1.l.string({ format: 'nsid' });
|
|
|
403
400
|
* })
|
|
404
401
|
* ```
|
|
405
402
|
*/
|
|
406
|
-
|
|
407
|
-
lexicon:
|
|
408
|
-
id:
|
|
409
|
-
revision:
|
|
410
|
-
description:
|
|
411
|
-
defs:
|
|
412
|
-
main:
|
|
413
|
-
}),
|
|
403
|
+
export const lexiconDocumentSchema = l.object({
|
|
404
|
+
lexicon: l.literal(1),
|
|
405
|
+
id: lexiconIdentifierSchema,
|
|
406
|
+
revision: l.optional(l.integer()),
|
|
407
|
+
description: l.optional(l.string()),
|
|
408
|
+
defs: l.intersection(l.object({
|
|
409
|
+
main: l.optional(l.discriminatedUnion('type', MAIN_LEXICON_SCHEMAS)),
|
|
410
|
+
}), l.dict(l.string({ minLength: 1 }), l.discriminatedUnion('type', NAMED_LEXICON_SCHEMAS))),
|
|
414
411
|
});
|
|
415
412
|
//# sourceMappingURL=lexicon-document.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-document.js","sourceRoot":"","sources":["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AM,CAAC;QACP,IAAI,EAAE,cAAC,CAAC,QAAQ,CAAC,cAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;KACrE,CAAC,EACF,cAAC,CAAC,IAAI,CACJ,cAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,EAC1B,cAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE,qBAAqB,CAAC,CACpD,CACF;CACF,CAAC,CAAA","sourcesContent":["import { l } from '@atproto/lex-schema'\n\n// https://atproto.com/specs/lexicon\n\n// \"Concrete\" Types\n\n/**\n * Schema for validating Lexicon boolean type definitions.\n *\n * Validates boolean field definitions that may include a default value,\n * a constant value, and an optional description.\n */\nexport const lexiconBooleanSchema = l.object({\n type: l.literal('boolean'),\n default: l.optional(l.boolean()),\n const: l.optional(l.boolean()),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon boolean definition.\n *\n * Represents the structure of a boolean field in a Lexicon document,\n * including optional default, const, and description properties.\n *\n * @see {@link lexiconBooleanSchema} for the schema definition\n */\nexport type LexiconBoolean = l.Infer<typeof lexiconBooleanSchema>\n\n/**\n * Schema for validating Lexicon integer type definitions.\n *\n * Validates integer field definitions with support for default values,\n * minimum/maximum constraints, enumerated values, and constant values.\n */\nexport const lexiconIntegerSchema = l.object({\n type: l.literal('integer'),\n default: l.optional(l.integer()),\n minimum: l.optional(l.integer()),\n maximum: l.optional(l.integer()),\n enum: l.optional(l.array(l.integer())),\n const: l.optional(l.integer()),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon integer definition.\n *\n * Represents the structure of an integer field in a Lexicon document,\n * including optional constraints like minimum, maximum, enum, and const.\n *\n * @see {@link lexiconIntegerSchema} for the schema definition\n */\nexport type LexiconInteger = l.Infer<typeof lexiconIntegerSchema>\n\n/**\n * Schema for validating Lexicon string type definitions.\n *\n * Validates string field definitions with support for format validation,\n * length constraints (both character and grapheme-based), enumerated values,\n * known values, and constant values.\n */\nexport const lexiconStringSchema = l.object({\n type: l.literal('string'),\n format: l.optional(l.enum<l.StringFormat>(l.STRING_FORMATS)),\n default: l.optional(l.string()),\n minLength: l.optional(l.integer()),\n maxLength: l.optional(l.integer()),\n minGraphemes: l.optional(l.integer()),\n maxGraphemes: l.optional(l.integer()),\n enum: l.optional(l.array(l.string())),\n const: l.optional(l.string()),\n knownValues: l.optional(l.array(l.string())),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon string definition.\n *\n * Represents the structure of a string field in a Lexicon document,\n * including optional format, length constraints, enum, const, and knownValues.\n *\n * @see {@link lexiconStringSchema} for the schema definition\n */\nexport type LexiconString = l.Infer<typeof lexiconStringSchema>\n\n/**\n * Schema for validating Lexicon bytes type definitions.\n *\n * Validates binary data field definitions with optional length constraints.\n * Used for raw byte arrays in DAG-CBOR encoding.\n */\nexport const lexiconBytesSchema = l.object({\n type: l.literal('bytes'),\n maxLength: l.optional(l.integer()),\n minLength: l.optional(l.integer()),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon bytes definition.\n *\n * Represents the structure of a binary data field in a Lexicon document,\n * including optional minLength and maxLength constraints.\n *\n * @see {@link lexiconBytesSchema} for the schema definition\n */\nexport type LexiconBytes = l.Infer<typeof lexiconBytesSchema>\n\n/**\n * Schema for validating Lexicon CID link type definitions.\n *\n * Validates Content Identifier (CID) link field definitions.\n * CIDs are used to reference content-addressed data in IPFS/IPLD.\n */\nexport const lexiconCidLinkSchema = l.object({\n type: l.literal('cid-link'),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon CID link definition.\n *\n * Represents the structure of a CID link field in a Lexicon document.\n *\n * @see {@link lexiconCidLinkSchema} for the schema definition\n */\nexport type LexiconCid = l.Infer<typeof lexiconCidLinkSchema>\n\n/**\n * Schema for validating Lexicon blob type definitions.\n *\n * Validates blob field definitions with optional MIME type acceptance list\n * and maximum size constraints. Blobs represent uploaded file references.\n */\nexport const lexiconBlobSchema = l.object({\n type: l.literal('blob'),\n accept: l.optional(l.array(l.string())),\n maxSize: l.optional(l.integer()),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon blob definition.\n *\n * Represents the structure of a blob field in a Lexicon document,\n * including optional accept list and maxSize constraints.\n *\n * @see {@link lexiconBlobSchema} for the schema definition\n */\nexport type LexiconBlob = l.Infer<typeof lexiconBlobSchema>\n\n/**\n * Array of all concrete (primitive) Lexicon type schemas.\n * Includes boolean, integer, string, bytes, cid-link, and blob types.\n */\nconst CONCRETE_TYPES = [\n lexiconBooleanSchema,\n lexiconIntegerSchema,\n lexiconStringSchema,\n // Lexicon (DAG-CBOR)\n lexiconBytesSchema,\n lexiconCidLinkSchema,\n // Lexicon Specific\n lexiconBlobSchema,\n] as const\n\n// Meta types\n\n/**\n * Schema for validating Lexicon unknown type definitions.\n *\n * Validates unknown field definitions which accept any valid data.\n * Used when the schema cannot determine the type ahead of time.\n */\nexport const lexiconUnknownSchema = l.object({\n type: l.literal('unknown'),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon unknown definition.\n *\n * Represents the structure of an unknown field in a Lexicon document.\n *\n * @see {@link lexiconUnknownSchema} for the schema definition\n */\nexport type LexiconUnknown = l.Infer<typeof lexiconUnknownSchema>\n\n/**\n * Schema for validating Lexicon token type definitions.\n *\n * Validates token definitions which represent symbolic constants.\n * Tokens are used to define enumeration-like values that can be\n * referenced across different lexicons.\n */\nexport const lexiconTokenSchema = l.object({\n type: l.literal('token'),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon token definition.\n *\n * Represents the structure of a token in a Lexicon document.\n *\n * @see {@link lexiconTokenSchema} for the schema definition\n */\nexport type LexiconToken = l.Infer<typeof lexiconTokenSchema>\n\n/**\n * Schema for validating Lexicon reference type definitions.\n *\n * Validates reference definitions which point to other type definitions\n * within the same or different Lexicon documents. References use the\n * format \"nsid#defName\" for cross-document refs or \"#defName\" for local refs.\n */\nexport const lexiconRefSchema = l.object({\n type: l.literal('ref'),\n ref: l.string(),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon reference definition.\n *\n * Represents the structure of a reference field in a Lexicon document,\n * including the ref string pointing to another definition.\n *\n * @see {@link lexiconRefSchema} for the schema definition\n */\nexport type LexiconRef = l.Infer<typeof lexiconRefSchema>\n\n/**\n * Schema for validating Lexicon union reference type definitions.\n *\n * Validates union definitions which can reference multiple possible types.\n * The union can be closed (only listed types allowed) or open (allows\n * additional unlisted types).\n */\nexport const lexiconRefUnionSchema = l.object({\n type: l.literal('union'),\n refs: l.array(l.string()),\n closed: l.optional(l.boolean()),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon union reference definition.\n *\n * Represents the structure of a union field in a Lexicon document,\n * including an array of reference strings and optional closed flag.\n *\n * @see {@link lexiconRefUnionSchema} for the schema definition\n */\nexport type LexiconRefUnion = l.Infer<typeof lexiconRefUnionSchema>\n\n// Complex Types\n\nconst ARRAY_ITEMS_SCHEMAS = [\n ...CONCRETE_TYPES,\n // Meta\n lexiconUnknownSchema,\n lexiconRefSchema,\n lexiconRefUnionSchema,\n] as const\n\n/**\n * TypeScript type representing valid item types for Lexicon arrays.\n *\n * Union of all types that can appear as items within a Lexicon array definition.\n */\nexport type LexiconArrayItems = l.Infer<(typeof ARRAY_ITEMS_SCHEMAS)[number]>\n\n/**\n * Schema for validating Lexicon array type definitions.\n *\n * Validates array field definitions with specified item type and\n * optional length constraints.\n */\nexport const lexiconArraySchema = l.object({\n type: l.literal('array'),\n items: l.discriminatedUnion('type', ARRAY_ITEMS_SCHEMAS),\n minLength: l.optional(l.integer()),\n maxLength: l.optional(l.integer()),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon array definition.\n *\n * Represents the structure of an array field in a Lexicon document,\n * including the items schema and optional length constraints.\n *\n * @see {@link lexiconArraySchema} for the schema definition\n */\nexport type LexiconArray = l.Infer<typeof lexiconArraySchema>\n\nconst requirePropertiesRefinement: l.RefinementCheck<{\n required?: string[]\n properties: Record<string, unknown>\n}> = {\n check: (v) => !v.required || v.required.every((k) => k in v.properties),\n message: 'All required parameters must be defined in properties',\n path: 'required',\n}\n\n/**\n * Schema for validating Lexicon object type definitions.\n *\n * Validates object definitions with named properties, required field lists,\n * and nullable field lists. Includes refinement to ensure all required\n * properties are defined in the properties map.\n */\nexport const lexiconObjectSchema = l.refine(\n l.object({\n type: l.literal('object'),\n properties: l.dict(\n l.string(),\n l.discriminatedUnion('type', [\n ...ARRAY_ITEMS_SCHEMAS,\n lexiconArraySchema,\n ]),\n ),\n required: l.optional(l.array(l.string())),\n nullable: l.optional(l.array(l.string())),\n description: l.optional(l.string()),\n }),\n requirePropertiesRefinement,\n)\n\n/**\n * TypeScript type for a Lexicon object definition.\n *\n * Represents the structure of an object type in a Lexicon document,\n * including properties map, required array, and nullable array.\n *\n * @see {@link lexiconObjectSchema} for the schema definition\n */\nexport type LexiconObject = l.Infer<typeof lexiconObjectSchema>\n\n// Records\n\n/**\n * Schema for validating Lexicon record key definitions.\n *\n * Validates record key type specifications. Valid values are:\n * - \"any\": Any valid record key\n * - \"nsid\": Namespaced identifier\n * - \"tid\": Timestamp identifier\n * - \"literal:<string>\": A specific literal string value\n */\nexport const lexiconRecordKeySchema = l.custom(\n l.isLexiconRecordKey,\n 'Invalid record key definition (must be \"any\", \"nsid\", \"tid\", or \"literal:<string>\")',\n)\n\n/**\n * TypeScript type for valid Lexicon record key values.\n *\n * Can be \"any\", \"nsid\", \"tid\", or \"literal:<string>\".\n *\n * @see {@link lexiconRecordKeySchema} for the schema definition\n */\nexport type LexiconRecordKey = l.LexiconRecordKey\n\n/**\n * Schema for validating Lexicon record type definitions.\n *\n * Validates record definitions which define the structure of data\n * stored in AT Protocol repositories. Records have a key type\n * and an object schema defining the record's data structure.\n */\nexport const lexiconRecordSchema = l.object({\n type: l.literal('record'),\n record: lexiconObjectSchema,\n description: l.optional(l.string()),\n key: lexiconRecordKeySchema,\n})\n\n/**\n * TypeScript type for a Lexicon record definition.\n *\n * Represents the structure of a record type in a Lexicon document,\n * including the key type and the object schema for the record data.\n *\n * @see {@link lexiconRecordSchema} for the schema definition\n */\nexport type LexiconRecord = l.Infer<typeof lexiconRecordSchema>\n\n// XRPC Methods\n\n/**\n * Schema for validating Lexicon XRPC method parameters.\n *\n * Validates the parameters definition for query and procedure methods.\n * Parameters can only be primitive types (boolean, integer, string)\n * or arrays of primitives.\n */\nexport const lexiconParameters = l.refine(\n l.object({\n type: l.literal('params'),\n properties: l.dict(\n l.string(),\n l.discriminatedUnion('type', [\n lexiconBooleanSchema,\n lexiconIntegerSchema,\n lexiconStringSchema,\n l.object({\n type: l.literal('array'),\n items: l.discriminatedUnion('type', [\n lexiconBooleanSchema,\n lexiconIntegerSchema,\n lexiconStringSchema,\n ]),\n minLength: l.optional(l.integer()),\n maxLength: l.optional(l.integer()),\n description: l.optional(l.string()),\n }),\n ]),\n ),\n required: l.optional(l.array(l.string())),\n description: l.optional(l.string()),\n }),\n requirePropertiesRefinement,\n)\n\n/**\n * TypeScript type for Lexicon XRPC method parameters.\n *\n * Represents the structure of parameters for query and procedure methods.\n *\n * @see {@link lexiconParameters} for the schema definition\n */\nexport type LexiconParameters = l.Infer<typeof lexiconParameters>\n\n/**\n * Schema for validating Lexicon XRPC method payloads.\n *\n * Validates input/output payload definitions for procedures and queries.\n * Payloads specify the encoding (MIME type) and optional schema for\n * the request or response body.\n */\nexport const lexiconPayload = l.object({\n encoding: l.refine(l.string(), {\n check: (v) => !v.includes(',') && !v.includes(';') && !v.includes(' '),\n message:\n 'Invalid encoding string (must be a single MIME type without parameters)',\n }),\n schema: l.optional(\n l.discriminatedUnion('type', [\n lexiconRefSchema,\n lexiconRefUnionSchema,\n lexiconObjectSchema,\n ]),\n ),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon XRPC payload definition.\n *\n * Represents the structure of an input or output payload,\n * including encoding type and optional schema.\n *\n * @see {@link lexiconPayload} for the schema definition\n */\nexport type LexiconPayload = l.Infer<typeof lexiconPayload>\n\n/**\n * Schema for validating Lexicon XRPC error definitions.\n *\n * Validates error definitions that can be returned by XRPC methods.\n * Each error has a name and optional description.\n */\nexport const lexiconError = l.object({\n name: l.string({ minLength: 1 }),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon XRPC error definition.\n *\n * Represents an error that can be returned by an XRPC method.\n *\n * @see {@link lexiconError} for the schema definition\n */\nexport type LexiconError = l.Infer<typeof lexiconError>\n\n/**\n * Schema for validating Lexicon query (GET) method definitions.\n *\n * Validates query method definitions which represent read-only HTTP GET\n * operations. Queries can have parameters, an output payload, and\n * defined error types.\n */\nexport const lexiconQuerySchema = l.object({\n type: l.literal('query'),\n parameters: l.optional(lexiconParameters),\n output: l.optional(lexiconPayload),\n errors: l.optional(l.array(lexiconError)),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon query method definition.\n *\n * Represents the structure of an XRPC query (GET) method.\n *\n * @see {@link lexiconQuerySchema} for the schema definition\n */\nexport type LexiconQuery = l.Infer<typeof lexiconQuerySchema>\n\n/**\n * Schema for validating Lexicon procedure (POST) method definitions.\n *\n * Validates procedure method definitions which represent HTTP POST\n * operations that may modify state. Procedures can have parameters,\n * input payload, output payload, and defined error types.\n */\nexport const lexiconProcedureSchema = l.object({\n type: l.literal('procedure'),\n parameters: l.optional(lexiconParameters),\n input: l.optional(lexiconPayload),\n output: l.optional(lexiconPayload),\n errors: l.optional(l.array(lexiconError)),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon procedure method definition.\n *\n * Represents the structure of an XRPC procedure (POST) method.\n *\n * @see {@link lexiconProcedureSchema} for the schema definition\n */\nexport type LexiconProcedure = l.Infer<typeof lexiconProcedureSchema>\n\n/**\n * Schema for validating Lexicon subscription (WebSocket) method definitions.\n *\n * Validates subscription method definitions which represent real-time\n * streaming connections over WebSocket. Subscriptions have parameters,\n * a message schema defining the streamed data format, and error types.\n */\nexport const lexiconSubscriptionSchema = l.object({\n type: l.literal('subscription'),\n description: l.optional(l.string()),\n parameters: l.optional(lexiconParameters),\n message: l.object({\n description: l.optional(l.string()),\n schema: lexiconRefUnionSchema,\n }),\n errors: l.optional(l.array(lexiconError)),\n})\n\n/**\n * TypeScript type for a Lexicon subscription method definition.\n *\n * Represents the structure of an XRPC subscription (WebSocket) method.\n *\n * @see {@link lexiconSubscriptionSchema} for the schema definition\n */\nexport type LexiconSubscription = l.Infer<typeof lexiconSubscriptionSchema>\n\n// Permissions\n\n/**\n * Schema for validating language codes in Lexicon permission definitions.\n */\nexport const lexiconLanguageSchema = l.string({ format: 'language' })\n\n/**\n * TypeScript type for a BCP 47 language code string.\n *\n * @see {@link lexiconLanguageSchema} for the schema definition\n */\nexport type LexiconLanguage = l.Infer<typeof lexiconLanguageSchema>\n\n/**\n * Schema for validating language-keyed string dictionaries.\n * Used for localized text in permission definitions.\n */\nexport const lexiconLanguageDict = l.dict(lexiconLanguageSchema, l.string())\n\n/**\n * TypeScript type for a language-keyed dictionary of localized strings.\n *\n * @see {@link lexiconLanguageDict} for the schema definition\n */\nexport type LexiconLanguageDict = l.Infer<typeof lexiconLanguageDict>\n\n/**\n * Schema for validating individual Lexicon permission definitions.\n */\nexport const lexiconPermissionSchema = l.intersection(\n l.object({\n type: l.literal('permission'),\n resource: l.string({ minLength: 1 }),\n }),\n l.dict(l.string(), l.paramSchema),\n)\n\n/**\n * TypeScript type for a Lexicon permission definition.\n *\n * Represents a single permission with a resource identifier\n * and optional additional parameters.\n *\n * @see {@link lexiconPermissionSchema} for the schema definition\n */\nexport type LexiconPermission = l.Infer<typeof lexiconPermissionSchema>\n\n/**\n * Schema for validating Lexicon permission set definitions.\n */\nexport const lexiconPermissionSetSchema = l.object({\n type: l.literal('permission-set'),\n permissions: l.array(lexiconPermissionSchema),\n title: l.optional(l.string()),\n 'title:lang': l.optional(lexiconLanguageDict),\n detail: l.optional(l.string()),\n 'detail:lang': l.optional(lexiconLanguageDict),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon permission set definition.\n *\n * Represents a collection of permissions with optional\n * localized title and detail text.\n *\n * @see {@link lexiconPermissionSetSchema} for the schema definition\n */\nexport type LexiconPermissionSet = l.Infer<typeof lexiconPermissionSetSchema>\n\nconst NAMED_LEXICON_SCHEMAS = [\n ...CONCRETE_TYPES,\n lexiconArraySchema,\n lexiconObjectSchema,\n lexiconTokenSchema,\n] as const\n\n/**\n * TypeScript type for any named Lexicon definition.\n *\n * Union of all definition types that can appear in the defs section\n * of a Lexicon document (excluding main-only types).\n */\nexport type NamedLexiconDefinition = l.Infer<\n (typeof NAMED_LEXICON_SCHEMAS)[number]\n>\n\nconst MAIN_LEXICON_SCHEMAS = [\n lexiconPermissionSetSchema,\n lexiconProcedureSchema,\n lexiconQuerySchema,\n lexiconRecordSchema,\n lexiconSubscriptionSchema,\n ...NAMED_LEXICON_SCHEMAS,\n] as const\n\n/**\n * TypeScript type for main Lexicon definitions.\n *\n * Union of all definition types that can appear as the \"main\" entry\n * in a Lexicon document's defs section.\n */\nexport type MainLexiconDefinition = l.Infer<\n (typeof MAIN_LEXICON_SCHEMAS)[number]\n>\n\n/**\n * Schema for validating Lexicon document identifiers (NSIDs).\n *\n * Validates that the identifier follows the Namespaced Identifier format\n * (e.g., \"com.atproto.repo.createRecord\").\n */\nexport const lexiconIdentifierSchema = l.string({ format: 'nsid' })\n\n/**\n * TypeScript type for a Lexicon document identifier.\n *\n * A Namespaced Identifier (NSID) string in reverse-domain format.\n *\n * @see {@link lexiconIdentifierSchema} for the schema definition\n */\nexport type LexiconIdentifier = l.Infer<typeof lexiconIdentifierSchema>\n\n/**\n * Schema for validating complete Lexicon document structures.\n *\n * Validates the top-level structure of a Lexicon document, including:\n * - `lexicon`: Must be 1 (the current Lexicon version)\n * - `id`: The document's NSID\n * - `revision`: Optional version number\n * - `description`: Optional document description\n * - `defs`: Map of definition names to their schemas\n *\n * The \"main\" definition (if present) can be any main-only type,\n * while other definitions are limited to named types.\n *\n * @example\n * ```ts\n * const result = lexiconDocumentSchema.parse({\n * lexicon: 1,\n * id: 'com.example.getProfile',\n * defs: {\n * main: {\n * type: 'query',\n * output: {\n * encoding: 'application/json',\n * schema: { type: 'ref', ref: '#profile' }\n * }\n * },\n * profile: {\n * type: 'object',\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * }\n * })\n * ```\n */\nexport const lexiconDocumentSchema = l.object({\n lexicon: l.literal(1),\n id: lexiconIdentifierSchema,\n revision: l.optional(l.integer()),\n description: l.optional(l.string()),\n defs: l.intersection(\n l.object({\n main: l.optional(l.discriminatedUnion('type', MAIN_LEXICON_SCHEMAS)),\n }),\n l.dict(\n l.string({ minLength: 1 }),\n l.discriminatedUnion('type', NAMED_LEXICON_SCHEMAS),\n ),\n ),\n})\n\n/**\n * TypeScript type for a complete Lexicon document.\n *\n * Represents the full structure of a Lexicon JSON document,\n * including the version, identifier, and all type definitions.\n *\n * @see {@link lexiconDocumentSchema} for the schema definition\n */\nexport type LexiconDocument = l.Infer<typeof lexiconDocumentSchema>\n"]}
|
|
1
|
+
{"version":3,"file":"lexicon-document.js","sourceRoot":"","sources":["../src/lexicon-document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AAEvC,oCAAoC;AAEpC,mBAAmB;AAEnB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;IAC1B,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IAChC,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IAC9B,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;C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C,CAAC,IAAI,CACJ,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,EAC1B,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE,qBAAqB,CAAC,CACpD,CACF;CACF,CAAC,CAAA","sourcesContent":["import { l } from '@atproto/lex-schema'\n\n// https://atproto.com/specs/lexicon\n\n// \"Concrete\" Types\n\n/**\n * Schema for validating Lexicon boolean type definitions.\n *\n * Validates boolean field definitions that may include a default value,\n * a constant value, and an optional description.\n */\nexport const lexiconBooleanSchema = l.object({\n type: l.literal('boolean'),\n default: l.optional(l.boolean()),\n const: l.optional(l.boolean()),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon boolean definition.\n *\n * Represents the structure of a boolean field in a Lexicon document,\n * including optional default, const, and description properties.\n *\n * @see {@link lexiconBooleanSchema} for the schema definition\n */\nexport type LexiconBoolean = l.Infer<typeof lexiconBooleanSchema>\n\n/**\n * Schema for validating Lexicon integer type definitions.\n *\n * Validates integer field definitions with support for default values,\n * minimum/maximum constraints, enumerated values, and constant values.\n */\nexport const lexiconIntegerSchema = l.object({\n type: l.literal('integer'),\n default: l.optional(l.integer()),\n minimum: l.optional(l.integer()),\n maximum: l.optional(l.integer()),\n enum: l.optional(l.array(l.integer())),\n const: l.optional(l.integer()),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon integer definition.\n *\n * Represents the structure of an integer field in a Lexicon document,\n * including optional constraints like minimum, maximum, enum, and const.\n *\n * @see {@link lexiconIntegerSchema} for the schema definition\n */\nexport type LexiconInteger = l.Infer<typeof lexiconIntegerSchema>\n\n/**\n * Schema for validating Lexicon string type definitions.\n *\n * Validates string field definitions with support for format validation,\n * length constraints (both character and grapheme-based), enumerated values,\n * known values, and constant values.\n */\nexport const lexiconStringSchema = l.object({\n type: l.literal('string'),\n format: l.optional(l.enum<l.StringFormat>(l.STRING_FORMATS)),\n default: l.optional(l.string()),\n minLength: l.optional(l.integer()),\n maxLength: l.optional(l.integer()),\n minGraphemes: l.optional(l.integer()),\n maxGraphemes: l.optional(l.integer()),\n enum: l.optional(l.array(l.string())),\n const: l.optional(l.string()),\n knownValues: l.optional(l.array(l.string())),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon string definition.\n *\n * Represents the structure of a string field in a Lexicon document,\n * including optional format, length constraints, enum, const, and knownValues.\n *\n * @see {@link lexiconStringSchema} for the schema definition\n */\nexport type LexiconString = l.Infer<typeof lexiconStringSchema>\n\n/**\n * Schema for validating Lexicon bytes type definitions.\n *\n * Validates binary data field definitions with optional length constraints.\n * Used for raw byte arrays in DAG-CBOR encoding.\n */\nexport const lexiconBytesSchema = l.object({\n type: l.literal('bytes'),\n maxLength: l.optional(l.integer()),\n minLength: l.optional(l.integer()),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon bytes definition.\n *\n * Represents the structure of a binary data field in a Lexicon document,\n * including optional minLength and maxLength constraints.\n *\n * @see {@link lexiconBytesSchema} for the schema definition\n */\nexport type LexiconBytes = l.Infer<typeof lexiconBytesSchema>\n\n/**\n * Schema for validating Lexicon CID link type definitions.\n *\n * Validates Content Identifier (CID) link field definitions.\n * CIDs are used to reference content-addressed data in IPFS/IPLD.\n */\nexport const lexiconCidLinkSchema = l.object({\n type: l.literal('cid-link'),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon CID link definition.\n *\n * Represents the structure of a CID link field in a Lexicon document.\n *\n * @see {@link lexiconCidLinkSchema} for the schema definition\n */\nexport type LexiconCid = l.Infer<typeof lexiconCidLinkSchema>\n\n/**\n * Schema for validating Lexicon blob type definitions.\n *\n * Validates blob field definitions with optional MIME type acceptance list\n * and maximum size constraints. Blobs represent uploaded file references.\n */\nexport const lexiconBlobSchema = l.object({\n type: l.literal('blob'),\n accept: l.optional(l.array(l.string())),\n maxSize: l.optional(l.integer()),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon blob definition.\n *\n * Represents the structure of a blob field in a Lexicon document,\n * including optional accept list and maxSize constraints.\n *\n * @see {@link lexiconBlobSchema} for the schema definition\n */\nexport type LexiconBlob = l.Infer<typeof lexiconBlobSchema>\n\n/**\n * Array of all concrete (primitive) Lexicon type schemas.\n * Includes boolean, integer, string, bytes, cid-link, and blob types.\n */\nconst CONCRETE_TYPES = [\n lexiconBooleanSchema,\n lexiconIntegerSchema,\n lexiconStringSchema,\n // Lexicon (DAG-CBOR)\n lexiconBytesSchema,\n lexiconCidLinkSchema,\n // Lexicon Specific\n lexiconBlobSchema,\n] as const\n\n// Meta types\n\n/**\n * Schema for validating Lexicon unknown type definitions.\n *\n * Validates unknown field definitions which accept any valid data.\n * Used when the schema cannot determine the type ahead of time.\n */\nexport const lexiconUnknownSchema = l.object({\n type: l.literal('unknown'),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon unknown definition.\n *\n * Represents the structure of an unknown field in a Lexicon document.\n *\n * @see {@link lexiconUnknownSchema} for the schema definition\n */\nexport type LexiconUnknown = l.Infer<typeof lexiconUnknownSchema>\n\n/**\n * Schema for validating Lexicon token type definitions.\n *\n * Validates token definitions which represent symbolic constants.\n * Tokens are used to define enumeration-like values that can be\n * referenced across different lexicons.\n */\nexport const lexiconTokenSchema = l.object({\n type: l.literal('token'),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon token definition.\n *\n * Represents the structure of a token in a Lexicon document.\n *\n * @see {@link lexiconTokenSchema} for the schema definition\n */\nexport type LexiconToken = l.Infer<typeof lexiconTokenSchema>\n\n/**\n * Schema for validating Lexicon reference type definitions.\n *\n * Validates reference definitions which point to other type definitions\n * within the same or different Lexicon documents. References use the\n * format \"nsid#defName\" for cross-document refs or \"#defName\" for local refs.\n */\nexport const lexiconRefSchema = l.object({\n type: l.literal('ref'),\n ref: l.string(),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon reference definition.\n *\n * Represents the structure of a reference field in a Lexicon document,\n * including the ref string pointing to another definition.\n *\n * @see {@link lexiconRefSchema} for the schema definition\n */\nexport type LexiconRef = l.Infer<typeof lexiconRefSchema>\n\n/**\n * Schema for validating Lexicon union reference type definitions.\n *\n * Validates union definitions which can reference multiple possible types.\n * The union can be closed (only listed types allowed) or open (allows\n * additional unlisted types).\n */\nexport const lexiconRefUnionSchema = l.object({\n type: l.literal('union'),\n refs: l.array(l.string()),\n closed: l.optional(l.boolean()),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon union reference definition.\n *\n * Represents the structure of a union field in a Lexicon document,\n * including an array of reference strings and optional closed flag.\n *\n * @see {@link lexiconRefUnionSchema} for the schema definition\n */\nexport type LexiconRefUnion = l.Infer<typeof lexiconRefUnionSchema>\n\n// Complex Types\n\nconst ARRAY_ITEMS_SCHEMAS = [\n ...CONCRETE_TYPES,\n // Meta\n lexiconUnknownSchema,\n lexiconRefSchema,\n lexiconRefUnionSchema,\n] as const\n\n/**\n * TypeScript type representing valid item types for Lexicon arrays.\n *\n * Union of all types that can appear as items within a Lexicon array definition.\n */\nexport type LexiconArrayItems = l.Infer<(typeof ARRAY_ITEMS_SCHEMAS)[number]>\n\n/**\n * Schema for validating Lexicon array type definitions.\n *\n * Validates array field definitions with specified item type and\n * optional length constraints.\n */\nexport const lexiconArraySchema = l.object({\n type: l.literal('array'),\n items: l.discriminatedUnion('type', ARRAY_ITEMS_SCHEMAS),\n minLength: l.optional(l.integer()),\n maxLength: l.optional(l.integer()),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon array definition.\n *\n * Represents the structure of an array field in a Lexicon document,\n * including the items schema and optional length constraints.\n *\n * @see {@link lexiconArraySchema} for the schema definition\n */\nexport type LexiconArray = l.Infer<typeof lexiconArraySchema>\n\nconst requirePropertiesRefinement: l.RefinementCheck<{\n required?: string[]\n properties: Record<string, unknown>\n}> = {\n check: (v) => !v.required || v.required.every((k) => k in v.properties),\n message: 'All required parameters must be defined in properties',\n path: 'required',\n}\n\n/**\n * Schema for validating Lexicon object type definitions.\n *\n * Validates object definitions with named properties, required field lists,\n * and nullable field lists. Includes refinement to ensure all required\n * properties are defined in the properties map.\n */\nexport const lexiconObjectSchema = l.refine(\n l.object({\n type: l.literal('object'),\n properties: l.dict(\n l.string(),\n l.discriminatedUnion('type', [\n ...ARRAY_ITEMS_SCHEMAS,\n lexiconArraySchema,\n ]),\n ),\n required: l.optional(l.array(l.string())),\n nullable: l.optional(l.array(l.string())),\n description: l.optional(l.string()),\n }),\n requirePropertiesRefinement,\n)\n\n/**\n * TypeScript type for a Lexicon object definition.\n *\n * Represents the structure of an object type in a Lexicon document,\n * including properties map, required array, and nullable array.\n *\n * @see {@link lexiconObjectSchema} for the schema definition\n */\nexport type LexiconObject = l.Infer<typeof lexiconObjectSchema>\n\n// Records\n\n/**\n * Schema for validating Lexicon record key definitions.\n *\n * Validates record key type specifications. Valid values are:\n * - \"any\": Any valid record key\n * - \"nsid\": Namespaced identifier\n * - \"tid\": Timestamp identifier\n * - \"literal:<string>\": A specific literal string value\n */\nexport const lexiconRecordKeySchema = l.custom(\n l.isLexiconRecordKey,\n 'Invalid record key definition (must be \"any\", \"nsid\", \"tid\", or \"literal:<string>\")',\n)\n\n/**\n * TypeScript type for valid Lexicon record key values.\n *\n * Can be \"any\", \"nsid\", \"tid\", or \"literal:<string>\".\n *\n * @see {@link lexiconRecordKeySchema} for the schema definition\n */\nexport type LexiconRecordKey = l.LexiconRecordKey\n\n/**\n * Schema for validating Lexicon record type definitions.\n *\n * Validates record definitions which define the structure of data\n * stored in AT Protocol repositories. Records have a key type\n * and an object schema defining the record's data structure.\n */\nexport const lexiconRecordSchema = l.object({\n type: l.literal('record'),\n record: lexiconObjectSchema,\n description: l.optional(l.string()),\n key: lexiconRecordKeySchema,\n})\n\n/**\n * TypeScript type for a Lexicon record definition.\n *\n * Represents the structure of a record type in a Lexicon document,\n * including the key type and the object schema for the record data.\n *\n * @see {@link lexiconRecordSchema} for the schema definition\n */\nexport type LexiconRecord = l.Infer<typeof lexiconRecordSchema>\n\n// XRPC Methods\n\n/**\n * Schema for validating Lexicon XRPC method parameters.\n *\n * Validates the parameters definition for query and procedure methods.\n * Parameters can only be primitive types (boolean, integer, string)\n * or arrays of primitives.\n */\nexport const lexiconParameters = l.refine(\n l.object({\n type: l.literal('params'),\n properties: l.dict(\n l.string(),\n l.discriminatedUnion('type', [\n lexiconBooleanSchema,\n lexiconIntegerSchema,\n lexiconStringSchema,\n l.object({\n type: l.literal('array'),\n items: l.discriminatedUnion('type', [\n lexiconBooleanSchema,\n lexiconIntegerSchema,\n lexiconStringSchema,\n ]),\n minLength: l.optional(l.integer()),\n maxLength: l.optional(l.integer()),\n description: l.optional(l.string()),\n }),\n ]),\n ),\n required: l.optional(l.array(l.string())),\n description: l.optional(l.string()),\n }),\n requirePropertiesRefinement,\n)\n\n/**\n * TypeScript type for Lexicon XRPC method parameters.\n *\n * Represents the structure of parameters for query and procedure methods.\n *\n * @see {@link lexiconParameters} for the schema definition\n */\nexport type LexiconParameters = l.Infer<typeof lexiconParameters>\n\n/**\n * Schema for validating Lexicon XRPC method payloads.\n *\n * Validates input/output payload definitions for procedures and queries.\n * Payloads specify the encoding (MIME type) and optional schema for\n * the request or response body.\n */\nexport const lexiconPayload = l.object({\n encoding: l.refine(l.string(), {\n check: (v) => !v.includes(',') && !v.includes(';') && !v.includes(' '),\n message:\n 'Invalid encoding string (must be a single MIME type without parameters)',\n }),\n schema: l.optional(\n l.discriminatedUnion('type', [\n lexiconRefSchema,\n lexiconRefUnionSchema,\n lexiconObjectSchema,\n ]),\n ),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon XRPC payload definition.\n *\n * Represents the structure of an input or output payload,\n * including encoding type and optional schema.\n *\n * @see {@link lexiconPayload} for the schema definition\n */\nexport type LexiconPayload = l.Infer<typeof lexiconPayload>\n\n/**\n * Schema for validating Lexicon XRPC error definitions.\n *\n * Validates error definitions that can be returned by XRPC methods.\n * Each error has a name and optional description.\n */\nexport const lexiconError = l.object({\n name: l.string({ minLength: 1 }),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon XRPC error definition.\n *\n * Represents an error that can be returned by an XRPC method.\n *\n * @see {@link lexiconError} for the schema definition\n */\nexport type LexiconError = l.Infer<typeof lexiconError>\n\n/**\n * Schema for validating Lexicon query (GET) method definitions.\n *\n * Validates query method definitions which represent read-only HTTP GET\n * operations. Queries can have parameters, an output payload, and\n * defined error types.\n */\nexport const lexiconQuerySchema = l.object({\n type: l.literal('query'),\n parameters: l.optional(lexiconParameters),\n output: l.optional(lexiconPayload),\n errors: l.optional(l.array(lexiconError)),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon query method definition.\n *\n * Represents the structure of an XRPC query (GET) method.\n *\n * @see {@link lexiconQuerySchema} for the schema definition\n */\nexport type LexiconQuery = l.Infer<typeof lexiconQuerySchema>\n\n/**\n * Schema for validating Lexicon procedure (POST) method definitions.\n *\n * Validates procedure method definitions which represent HTTP POST\n * operations that may modify state. Procedures can have parameters,\n * input payload, output payload, and defined error types.\n */\nexport const lexiconProcedureSchema = l.object({\n type: l.literal('procedure'),\n parameters: l.optional(lexiconParameters),\n input: l.optional(lexiconPayload),\n output: l.optional(lexiconPayload),\n errors: l.optional(l.array(lexiconError)),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon procedure method definition.\n *\n * Represents the structure of an XRPC procedure (POST) method.\n *\n * @see {@link lexiconProcedureSchema} for the schema definition\n */\nexport type LexiconProcedure = l.Infer<typeof lexiconProcedureSchema>\n\n/**\n * Schema for validating Lexicon subscription (WebSocket) method definitions.\n *\n * Validates subscription method definitions which represent real-time\n * streaming connections over WebSocket. Subscriptions have parameters,\n * a message schema defining the streamed data format, and error types.\n */\nexport const lexiconSubscriptionSchema = l.object({\n type: l.literal('subscription'),\n description: l.optional(l.string()),\n parameters: l.optional(lexiconParameters),\n message: l.object({\n description: l.optional(l.string()),\n schema: lexiconRefUnionSchema,\n }),\n errors: l.optional(l.array(lexiconError)),\n})\n\n/**\n * TypeScript type for a Lexicon subscription method definition.\n *\n * Represents the structure of an XRPC subscription (WebSocket) method.\n *\n * @see {@link lexiconSubscriptionSchema} for the schema definition\n */\nexport type LexiconSubscription = l.Infer<typeof lexiconSubscriptionSchema>\n\n// Permissions\n\n/**\n * Schema for validating language codes in Lexicon permission definitions.\n */\nexport const lexiconLanguageSchema = l.string({ format: 'language' })\n\n/**\n * TypeScript type for a BCP 47 language code string.\n *\n * @see {@link lexiconLanguageSchema} for the schema definition\n */\nexport type LexiconLanguage = l.Infer<typeof lexiconLanguageSchema>\n\n/**\n * Schema for validating language-keyed string dictionaries.\n * Used for localized text in permission definitions.\n */\nexport const lexiconLanguageDict = l.dict(lexiconLanguageSchema, l.string())\n\n/**\n * TypeScript type for a language-keyed dictionary of localized strings.\n *\n * @see {@link lexiconLanguageDict} for the schema definition\n */\nexport type LexiconLanguageDict = l.Infer<typeof lexiconLanguageDict>\n\n/**\n * Schema for validating individual Lexicon permission definitions.\n */\nexport const lexiconPermissionSchema = l.intersection(\n l.object({\n type: l.literal('permission'),\n resource: l.string({ minLength: 1 }),\n }),\n l.dict(l.string(), l.paramSchema),\n)\n\n/**\n * TypeScript type for a Lexicon permission definition.\n *\n * Represents a single permission with a resource identifier\n * and optional additional parameters.\n *\n * @see {@link lexiconPermissionSchema} for the schema definition\n */\nexport type LexiconPermission = l.Infer<typeof lexiconPermissionSchema>\n\n/**\n * Schema for validating Lexicon permission set definitions.\n */\nexport const lexiconPermissionSetSchema = l.object({\n type: l.literal('permission-set'),\n permissions: l.array(lexiconPermissionSchema),\n title: l.optional(l.string()),\n 'title:lang': l.optional(lexiconLanguageDict),\n detail: l.optional(l.string()),\n 'detail:lang': l.optional(lexiconLanguageDict),\n description: l.optional(l.string()),\n})\n\n/**\n * TypeScript type for a Lexicon permission set definition.\n *\n * Represents a collection of permissions with optional\n * localized title and detail text.\n *\n * @see {@link lexiconPermissionSetSchema} for the schema definition\n */\nexport type LexiconPermissionSet = l.Infer<typeof lexiconPermissionSetSchema>\n\nconst NAMED_LEXICON_SCHEMAS = [\n ...CONCRETE_TYPES,\n lexiconArraySchema,\n lexiconObjectSchema,\n lexiconTokenSchema,\n] as const\n\n/**\n * TypeScript type for any named Lexicon definition.\n *\n * Union of all definition types that can appear in the defs section\n * of a Lexicon document (excluding main-only types).\n */\nexport type NamedLexiconDefinition = l.Infer<\n (typeof NAMED_LEXICON_SCHEMAS)[number]\n>\n\nconst MAIN_LEXICON_SCHEMAS = [\n lexiconPermissionSetSchema,\n lexiconProcedureSchema,\n lexiconQuerySchema,\n lexiconRecordSchema,\n lexiconSubscriptionSchema,\n ...NAMED_LEXICON_SCHEMAS,\n] as const\n\n/**\n * TypeScript type for main Lexicon definitions.\n *\n * Union of all definition types that can appear as the \"main\" entry\n * in a Lexicon document's defs section.\n */\nexport type MainLexiconDefinition = l.Infer<\n (typeof MAIN_LEXICON_SCHEMAS)[number]\n>\n\n/**\n * Schema for validating Lexicon document identifiers (NSIDs).\n *\n * Validates that the identifier follows the Namespaced Identifier format\n * (e.g., \"com.atproto.repo.createRecord\").\n */\nexport const lexiconIdentifierSchema = l.string({ format: 'nsid' })\n\n/**\n * TypeScript type for a Lexicon document identifier.\n *\n * A Namespaced Identifier (NSID) string in reverse-domain format.\n *\n * @see {@link lexiconIdentifierSchema} for the schema definition\n */\nexport type LexiconIdentifier = l.Infer<typeof lexiconIdentifierSchema>\n\n/**\n * Schema for validating complete Lexicon document structures.\n *\n * Validates the top-level structure of a Lexicon document, including:\n * - `lexicon`: Must be 1 (the current Lexicon version)\n * - `id`: The document's NSID\n * - `revision`: Optional version number\n * - `description`: Optional document description\n * - `defs`: Map of definition names to their schemas\n *\n * The \"main\" definition (if present) can be any main-only type,\n * while other definitions are limited to named types.\n *\n * @example\n * ```ts\n * const result = lexiconDocumentSchema.parse({\n * lexicon: 1,\n * id: 'com.example.getProfile',\n * defs: {\n * main: {\n * type: 'query',\n * output: {\n * encoding: 'application/json',\n * schema: { type: 'ref', ref: '#profile' }\n * }\n * },\n * profile: {\n * type: 'object',\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * }\n * })\n * ```\n */\nexport const lexiconDocumentSchema = l.object({\n lexicon: l.literal(1),\n id: lexiconIdentifierSchema,\n revision: l.optional(l.integer()),\n description: l.optional(l.string()),\n defs: l.intersection(\n l.object({\n main: l.optional(l.discriminatedUnion('type', MAIN_LEXICON_SCHEMAS)),\n }),\n l.dict(\n l.string({ minLength: 1 }),\n l.discriminatedUnion('type', NAMED_LEXICON_SCHEMAS),\n ),\n ),\n})\n\n/**\n * TypeScript type for a complete Lexicon document.\n *\n * Represents the full structure of a Lexicon JSON document,\n * including the version, identifier, and all type definitions.\n *\n * @see {@link lexiconDocumentSchema} for the schema definition\n */\nexport type LexiconDocument = l.Infer<typeof lexiconDocumentSchema>\n"]}
|
package/dist/lexicon-indexer.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LexiconIterableIndexer = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Lazily indexes Lexicon documents from an iterable source.
|
|
6
3
|
*
|
|
@@ -31,8 +28,7 @@ exports.LexiconIterableIndexer = void 0;
|
|
|
31
28
|
* const schemas = await LexiconSchemaBuilder.buildAll(indexer)
|
|
32
29
|
* ```
|
|
33
30
|
*/
|
|
34
|
-
class LexiconIterableIndexer {
|
|
35
|
-
source;
|
|
31
|
+
export class LexiconIterableIndexer {
|
|
36
32
|
#lexicons = new Map();
|
|
37
33
|
#iterator;
|
|
38
34
|
/**
|
|
@@ -114,5 +110,4 @@ class LexiconIterableIndexer {
|
|
|
114
110
|
await this.#iterator.return?.();
|
|
115
111
|
}
|
|
116
112
|
}
|
|
117
|
-
exports.LexiconIterableIndexer = LexiconIterableIndexer;
|
|
118
113
|
//# sourceMappingURL=lexicon-iterable-indexer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-iterable-indexer.js","sourceRoot":"","sources":["../src/lexicon-iterable-indexer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lexicon-iterable-indexer.js","sourceRoot":"","sources":["../src/lexicon-iterable-indexer.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,sBAAsB;IACxB,SAAS,GAAiC,IAAI,GAAG,EAAE,CAAA;IACnD,SAAS,CAE0B;IAE5C;;;;;;;;;;;;;;OAcG;IACH,YACW,MAAkE;QAAlE,WAAM,GAAN,MAAM,CAA4D;QAE3E,IAAI,CAAC,SAAS;YACZ,MAAM,CAAC,aAAa,IAAI,MAAM;gBAC5B,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE;gBAChC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAA;IACjC,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG,CAAC,EAAU;QAClB,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACrC,IAAI,MAAM;YAAE,OAAO,MAAM,CAAA;QAEzB,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YAC7B,IAAI,GAAG,CAAC,EAAE,KAAK,EAAE;gBAAE,OAAO,GAAG,CAAA;QAC/B,CAAC;QAED,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,WAAW,EAAE,YAAY,CAAC,EAAE;YACxD,IAAI,EAAE,QAAQ;SACf,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC;QAK3B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAA;QAElC,KAAK,MAAM,GA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IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAA;IACjC,CAAC;CACF","sourcesContent":["import { LexiconDocument } from './lexicon-document.js'\nimport { LexiconIndexer } from './lexicon-indexer.js'\n\n/**\n * Lazily indexes Lexicon documents from an iterable source.\n *\n * This class implements `LexiconIndexer` by consuming documents from an\n * iterable (sync or async) and caching them for efficient retrieval.\n * Documents are indexed on-demand as they are requested or iterated over.\n *\n * @example\n * ```ts\n * // From an array of documents\n * const docs = [lexiconDoc1, lexiconDoc2, lexiconDoc3]\n * const indexer = new LexiconIterableIndexer(docs)\n *\n * // Documents are indexed lazily as requested\n * const doc = await indexer.get('com.example.post')\n * ```\n *\n * @example\n * ```ts\n * // From an async generator (e.g., reading from files)\n * async function* loadLexicons() {\n * for (const file of lexiconFiles) {\n * yield JSON.parse(await fs.readFile(file, 'utf8'))\n * }\n * }\n *\n * await using indexer = new LexiconIterableIndexer(loadLexicons())\n * const schemas = await LexiconSchemaBuilder.buildAll(indexer)\n * ```\n */\nexport class LexiconIterableIndexer implements LexiconIndexer, AsyncDisposable {\n readonly #lexicons: Map<string, LexiconDocument> = new Map()\n readonly #iterator:\n | AsyncIterator<LexiconDocument, void, unknown>\n | Iterator<LexiconDocument, void, unknown>\n\n /**\n * Creates a new {@link LexiconIterableIndexer} from an iterable source.\n *\n * @param source - An iterable or async iterable of Lexicon documents.\n * The iterator is consumed lazily as documents are requested.\n *\n * @example\n * ```ts\n * // Sync iterable (array, Set, Map.values(), etc.)\n * const indexer = new LexiconIterableIndexer(lexiconDocuments)\n *\n * // Async iterable (async generator, ReadableStream, etc.)\n * const indexer = new LexiconIterableIndexer(asyncLexiconStream)\n * ```\n */\n constructor(\n readonly source: AsyncIterable<LexiconDocument> | Iterable<LexiconDocument>,\n ) {\n this.#iterator =\n Symbol.asyncIterator in source\n ? source[Symbol.asyncIterator]()\n : source[Symbol.iterator]()\n }\n\n /**\n * Retrieves a Lexicon document by its NSID.\n *\n * If the document has already been indexed, it is returned from cache.\n * Otherwise, the source iterator is consumed until the document is found.\n *\n * @see {@link LexiconIndexer.get}\n */\n async get(id: string): Promise<LexiconDocument> {\n const cached = this.#lexicons.get(id)\n if (cached) return cached\n\n for await (const doc of this) {\n if (doc.id === id) return doc\n }\n\n throw Object.assign(new Error(`Lexicon ${id} not found`), {\n code: 'ENOENT',\n })\n }\n\n async *[Symbol.asyncIterator](): AsyncIterator<\n LexiconDocument,\n void,\n undefined\n > {\n const returned = new Set<string>()\n\n for (const doc of this.#lexicons.values()) {\n returned.add(doc.id)\n yield doc\n }\n\n do {\n const { value, done } = await this.#iterator.next()\n\n if (done) break\n\n if (returned.has(value.id)) {\n const err = new Error(`Duplicate lexicon document id: ${value.id}`)\n await this.#iterator.throw?.(err)\n throw err // In case iterator.throw does not exist or does not throw\n }\n\n this.#lexicons.set(value.id, value)\n returned.add(value.id)\n yield value\n } while (true)\n\n // At this point, the underlying iterator is done. However, there may have\n // been requests (.get()) for documents that caused the iterator to yield\n // those documents during concurrent execution of this loop. If that was the\n // case, new documents may have been added to `#lexicons` that have not yet\n // been yielded. We need to yield those as well. Since we yield control back\n // to the caller, we need to repeat this process until no new documents\n // appear sunce we don't know what happens.\n\n for (const doc of this.#lexicons.values()) {\n if (!returned.has(doc.id)) {\n returned.add(doc.id)\n yield doc\n }\n }\n }\n\n async [Symbol.asyncDispose](): Promise<void> {\n await this.#iterator.return?.()\n }\n}\n"]}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LexiconSchemaBuilder = void 0;
|
|
4
|
-
exports.memoize = memoize;
|
|
5
|
-
const lex_schema_1 = require("@atproto/lex-schema");
|
|
1
|
+
import { l } from '@atproto/lex-schema';
|
|
6
2
|
/**
|
|
7
3
|
* Builds validators for Lexicon documents.
|
|
8
4
|
*
|
|
@@ -38,8 +34,7 @@ const lex_schema_1 = require("@atproto/lex-schema");
|
|
|
38
34
|
* }
|
|
39
35
|
* ```
|
|
40
36
|
*/
|
|
41
|
-
class LexiconSchemaBuilder {
|
|
42
|
-
indexer;
|
|
37
|
+
export class LexiconSchemaBuilder {
|
|
43
38
|
/**
|
|
44
39
|
* Builds a validator for a single Lexicon definition reference.
|
|
45
40
|
*
|
|
@@ -62,7 +57,7 @@ class LexiconSchemaBuilder {
|
|
|
62
57
|
const ctx = new LexiconSchemaBuilder(indexer);
|
|
63
58
|
try {
|
|
64
59
|
const result = await ctx.buildFullRef(fullRef);
|
|
65
|
-
if (!(result instanceof
|
|
60
|
+
if (!(result instanceof l.Schema)) {
|
|
66
61
|
throw new Error(`Ref ${fullRef} is not a schema type`);
|
|
67
62
|
}
|
|
68
63
|
return result;
|
|
@@ -116,7 +111,7 @@ class LexiconSchemaBuilder {
|
|
|
116
111
|
await builder.done();
|
|
117
112
|
}
|
|
118
113
|
}
|
|
119
|
-
#asyncTasks
|
|
114
|
+
#asyncTasks;
|
|
120
115
|
/**
|
|
121
116
|
* Creates a new LexiconSchemaBuilder instance.
|
|
122
117
|
*
|
|
@@ -127,6 +122,21 @@ class LexiconSchemaBuilder {
|
|
|
127
122
|
*/
|
|
128
123
|
constructor(indexer) {
|
|
129
124
|
this.indexer = indexer;
|
|
125
|
+
this.#asyncTasks = new AsyncTasks();
|
|
126
|
+
/**
|
|
127
|
+
* Builds a validator for a full reference (memoized).
|
|
128
|
+
*
|
|
129
|
+
* Results are cached, so calling with the same reference returns
|
|
130
|
+
* the same promise/result.
|
|
131
|
+
*
|
|
132
|
+
* @param fullRef - The full reference in format "nsid#defName"
|
|
133
|
+
* @returns A promise resolving to the built schema or method definition
|
|
134
|
+
*/
|
|
135
|
+
this.buildFullRef = memoize(async (fullRef) => {
|
|
136
|
+
const { nsid, hash } = parseRef(fullRef);
|
|
137
|
+
const doc = await this.indexer.get(nsid);
|
|
138
|
+
return this.compileDef(doc, hash);
|
|
139
|
+
});
|
|
130
140
|
}
|
|
131
141
|
/**
|
|
132
142
|
* Waits for all pending reference resolution tasks to complete.
|
|
@@ -144,24 +154,10 @@ class LexiconSchemaBuilder {
|
|
|
144
154
|
async [Symbol.asyncDispose]() {
|
|
145
155
|
await this.done();
|
|
146
156
|
}
|
|
147
|
-
/**
|
|
148
|
-
* Builds a validator for a full reference (memoized).
|
|
149
|
-
*
|
|
150
|
-
* Results are cached, so calling with the same reference returns
|
|
151
|
-
* the same promise/result.
|
|
152
|
-
*
|
|
153
|
-
* @param fullRef - The full reference in format "nsid#defName"
|
|
154
|
-
* @returns A promise resolving to the built schema or method definition
|
|
155
|
-
*/
|
|
156
|
-
buildFullRef = memoize(async (fullRef) => {
|
|
157
|
-
const { nsid, hash } = parseRef(fullRef);
|
|
158
|
-
const doc = await this.indexer.get(nsid);
|
|
159
|
-
return this.compileDef(doc, hash);
|
|
160
|
-
});
|
|
161
157
|
buildRefGetter(fullRef) {
|
|
162
158
|
let schema;
|
|
163
159
|
this.#asyncTasks.add(this.buildFullRef(fullRef).then((v) => {
|
|
164
|
-
if (!(v instanceof
|
|
160
|
+
if (!(v instanceof l.Schema)) {
|
|
165
161
|
throw new Error(`Only refs to schema types are allowed`);
|
|
166
162
|
}
|
|
167
163
|
schema = v;
|
|
@@ -175,7 +171,7 @@ class LexiconSchemaBuilder {
|
|
|
175
171
|
buildTypedRefGetter(fullRef) {
|
|
176
172
|
let validator;
|
|
177
173
|
this.#asyncTasks.add(this.buildFullRef(fullRef).then((v) => {
|
|
178
|
-
if (v instanceof
|
|
174
|
+
if (v instanceof l.TypedObjectSchema || v instanceof l.RecordSchema) {
|
|
179
175
|
validator = v;
|
|
180
176
|
}
|
|
181
177
|
else {
|
|
@@ -195,19 +191,19 @@ class LexiconSchemaBuilder {
|
|
|
195
191
|
}
|
|
196
192
|
switch (def.type) {
|
|
197
193
|
case 'permission-set':
|
|
198
|
-
return
|
|
194
|
+
return l.permissionSet(doc.id, def.permissions.map(({ resource, type, ...p }) => l.permission(resource, p)), def);
|
|
199
195
|
case 'procedure':
|
|
200
|
-
return
|
|
196
|
+
return l.procedure(doc.id, this.compileParams(doc, def.parameters), this.compilePayload(doc, def.input), this.compilePayload(doc, def.output), this.compileErrors(doc, def.errors));
|
|
201
197
|
case 'query':
|
|
202
|
-
return
|
|
198
|
+
return l.query(doc.id, this.compileParams(doc, def.parameters), this.compilePayload(doc, def.output), this.compileErrors(doc, def.errors));
|
|
203
199
|
case 'subscription':
|
|
204
|
-
return
|
|
200
|
+
return l.subscription(doc.id, this.compileParams(doc, def.parameters), this.compilePayloadSchema(doc, def.message.schema), this.compileErrors(doc, def.errors));
|
|
205
201
|
case 'token':
|
|
206
|
-
return
|
|
202
|
+
return l.token(doc.id, hash);
|
|
207
203
|
case 'record':
|
|
208
|
-
return
|
|
204
|
+
return l.record(def.key, doc.id, this.compileObject(doc, def.record));
|
|
209
205
|
case 'object':
|
|
210
|
-
return
|
|
206
|
+
return l.typedObject(doc.id, hash, this.compileObject(doc, def));
|
|
211
207
|
default:
|
|
212
208
|
return this.compileLeaf(doc, def);
|
|
213
209
|
}
|
|
@@ -218,11 +214,11 @@ class LexiconSchemaBuilder {
|
|
|
218
214
|
def.enum != null &&
|
|
219
215
|
def.const !== undefined &&
|
|
220
216
|
!def.enum.includes(def.const)) {
|
|
221
|
-
return
|
|
217
|
+
return l.never();
|
|
222
218
|
}
|
|
223
219
|
switch (def.type) {
|
|
224
220
|
case 'string': {
|
|
225
|
-
const schema =
|
|
221
|
+
const schema = l.string(def);
|
|
226
222
|
if (def.default != null)
|
|
227
223
|
schema.check(def.default);
|
|
228
224
|
if (def.const != null)
|
|
@@ -231,14 +227,14 @@ class LexiconSchemaBuilder {
|
|
|
231
227
|
for (const v of def.enum)
|
|
232
228
|
schema.check(v);
|
|
233
229
|
const result = def.const != null
|
|
234
|
-
?
|
|
230
|
+
? l.literal(def.const)
|
|
235
231
|
: def.enum != null
|
|
236
|
-
?
|
|
232
|
+
? l.enum(def.enum)
|
|
237
233
|
: schema;
|
|
238
|
-
return def.default != null ?
|
|
234
|
+
return def.default != null ? l.withDefault(result, def.default) : result;
|
|
239
235
|
}
|
|
240
236
|
case 'integer': {
|
|
241
|
-
const schema =
|
|
237
|
+
const schema = l.integer(def);
|
|
242
238
|
if (def.default != null)
|
|
243
239
|
schema.check(def.default);
|
|
244
240
|
if (def.const != null)
|
|
@@ -247,26 +243,26 @@ class LexiconSchemaBuilder {
|
|
|
247
243
|
for (const v of def.enum)
|
|
248
244
|
schema.check(v);
|
|
249
245
|
const result = def.const != null
|
|
250
|
-
?
|
|
246
|
+
? l.literal(def.const)
|
|
251
247
|
: def.enum != null
|
|
252
|
-
?
|
|
248
|
+
? l.enum(def.enum)
|
|
253
249
|
: schema;
|
|
254
|
-
return def.default != null ?
|
|
250
|
+
return def.default != null ? l.withDefault(result, def.default) : result;
|
|
255
251
|
}
|
|
256
252
|
case 'boolean': {
|
|
257
|
-
const result = def.const != null ?
|
|
258
|
-
return def.default != null ?
|
|
253
|
+
const result = def.const != null ? l.literal(def.const) : l.boolean();
|
|
254
|
+
return def.default != null ? l.withDefault(result, def.default) : result;
|
|
259
255
|
}
|
|
260
256
|
case 'blob':
|
|
261
|
-
return
|
|
257
|
+
return l.blob(def);
|
|
262
258
|
case 'cid-link':
|
|
263
|
-
return
|
|
259
|
+
return l.cid();
|
|
264
260
|
case 'bytes':
|
|
265
|
-
return
|
|
261
|
+
return l.bytes(def);
|
|
266
262
|
case 'unknown':
|
|
267
|
-
return
|
|
263
|
+
return l.lexMap();
|
|
268
264
|
case 'array':
|
|
269
|
-
return
|
|
265
|
+
return l.array(this.compileLeaf(doc, def.items), def);
|
|
270
266
|
default:
|
|
271
267
|
return this.compileRef(doc, def);
|
|
272
268
|
}
|
|
@@ -274,9 +270,9 @@ class LexiconSchemaBuilder {
|
|
|
274
270
|
compileRef(doc, def) {
|
|
275
271
|
switch (def.type) {
|
|
276
272
|
case 'ref':
|
|
277
|
-
return
|
|
273
|
+
return l.ref(this.buildRefGetter(buildFullRef(doc, def.ref)));
|
|
278
274
|
case 'union':
|
|
279
|
-
return
|
|
275
|
+
return l.typedUnion(def.refs.map((r) => l.typedRef(this.buildTypedRefGetter(buildFullRef(doc, r)))), def.closed ?? false);
|
|
280
276
|
default:
|
|
281
277
|
// @ts-expect-error
|
|
282
278
|
throw new Error(`Unknown lexicon type: ${def.type}`);
|
|
@@ -291,17 +287,17 @@ class LexiconSchemaBuilder {
|
|
|
291
287
|
const isRequired = def.required?.includes(key);
|
|
292
288
|
let schema = this.compileLeaf(doc, propDef);
|
|
293
289
|
if (isNullable) {
|
|
294
|
-
schema =
|
|
290
|
+
schema = l.nullable(schema);
|
|
295
291
|
}
|
|
296
292
|
if (!isRequired) {
|
|
297
|
-
schema =
|
|
293
|
+
schema = l.optional(schema);
|
|
298
294
|
}
|
|
299
295
|
props[key] = schema;
|
|
300
296
|
}
|
|
301
|
-
return
|
|
297
|
+
return l.object(props);
|
|
302
298
|
}
|
|
303
299
|
compilePayload(doc, def) {
|
|
304
|
-
return
|
|
300
|
+
return l.payload(def?.encoding, def?.schema ? this.compilePayloadSchema(doc, def.schema) : undefined);
|
|
305
301
|
}
|
|
306
302
|
compileErrors(_doc, errors) {
|
|
307
303
|
return errors?.map((e) => e.name);
|
|
@@ -316,19 +312,18 @@ class LexiconSchemaBuilder {
|
|
|
316
312
|
}
|
|
317
313
|
compileParams(doc, def) {
|
|
318
314
|
if (!def)
|
|
319
|
-
return
|
|
315
|
+
return l.params();
|
|
320
316
|
const shape = {};
|
|
321
317
|
for (const [paramName, paramDef] of Object.entries(def.properties)) {
|
|
322
318
|
if (paramDef === undefined)
|
|
323
319
|
continue;
|
|
324
320
|
const isRequired = def.required?.includes(paramName);
|
|
325
321
|
const propSchema = this.compileLeaf(doc, paramDef);
|
|
326
|
-
shape[paramName] = isRequired ? propSchema :
|
|
322
|
+
shape[paramName] = isRequired ? propSchema : l.optional(propSchema);
|
|
327
323
|
}
|
|
328
|
-
return
|
|
324
|
+
return l.params(shape);
|
|
329
325
|
}
|
|
330
326
|
}
|
|
331
|
-
exports.LexiconSchemaBuilder = LexiconSchemaBuilder;
|
|
332
327
|
class AsyncTasks {
|
|
333
328
|
/**
|
|
334
329
|
* A set that, eventually, contains only rejected promises.
|
|
@@ -369,7 +364,7 @@ function buildFullRef(from, ref) {
|
|
|
369
364
|
return `${from.id}${ref}`;
|
|
370
365
|
return ref;
|
|
371
366
|
}
|
|
372
|
-
function memoize(fn) {
|
|
367
|
+
export function memoize(fn) {
|
|
373
368
|
const cache = new Map();
|
|
374
369
|
return ((arg) => {
|
|
375
370
|
if (cache.has(arg))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-schema-builder.js","sourceRoot":"","sources":["../src/lexicon-schema-builder.ts"],"names":[],"mappings":";;;AAieA,0BAQC;AAxeD,oDAAuC;AAcvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAa,oBAAoB;IAiGT;IAhGtB;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK,CAChB,OAAuB,EACvB,OAAe;QAEf,MAAM,GAAG,GAAG,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAA;QAC7C,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;YAC9C,IAAI,CAAC,CAAC,MAAM,YAAY,cAAC,CAAC,MAAM,CAAC,EAAE,CAAC;gBAClC,MAAM,IAAI,KAAK,CAAC,OAAO,OAAO,uBAAuB,CAAC,CAAA;YACxD,CAAC;YACD,OAAO,MAAM,CAAA;QACf,CAAC;gBAAS,CAAC;YACT,MAAM,GAAG,CAAC,IAAI,EAAE,CAAA;QAClB,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAuB;QAC3C,MAAM,OAAO,GAAG,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAA;QACjD,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,\n LexiconDocument,\n LexiconError,\n LexiconObject,\n LexiconParameters,\n LexiconPayload,\n LexiconRef,\n LexiconRefUnion,\n} from './lexicon-document.js'\nimport { LexiconIndexer } from './lexicon-indexer.js'\n\n/**\n * Builds validators for Lexicon documents.\n *\n * This class converts Lexicon type definitions into runtime validators\n * that can validate data against the schema. It handles reference resolution,\n * supporting both local (`#defName`) and cross-document (`nsid#defName`) refs.\n *\n * @example\n * ```ts\n * import { LexiconSchemaBuilder, LexiconIterableIndexer } from '@atproto/lex-document'\n *\n * // Build a single validator\n * const indexer = new LexiconIterableIndexer(lexiconDocs)\n * const validator = await LexiconSchemaBuilder.build(indexer, 'com.example.post#main')\n *\n * // Validate data\n * const result = validator.safeParse(myPostData)\n * if (result.success) {\n * console.log('Valid:', result.value)\n * } else {\n * console.log('Invalid:', result.error)\n * }\n * ```\n *\n * @example\n * ```ts\n * // Build all validators from an iterable indexer\n * const indexer = new LexiconIterableIndexer(lexiconDocs)\n * const allSchemas = await LexiconSchemaBuilder.buildAll(indexer)\n *\n * for (const [ref, schema] of allSchemas) {\n * console.log(`Built validator for ${ref}`)\n * }\n * ```\n */\nexport class LexiconSchemaBuilder implements AsyncDisposable {\n /**\n * Builds a validator for a single Lexicon definition reference.\n *\n * @param indexer - The Lexicon indexer to resolve documents from\n * @param fullRef - The full reference to build, in format \"nsid#defName\"\n * @returns A promise resolving to a validator for the referenced definition\n * @throws Error if the reference does not point to a schema type\n *\n * @example\n * ```ts\n * const validator = await LexiconSchemaBuilder.build(\n * indexer,\n * 'app.bsky.feed.post#main'\n * )\n *\n * validator.parse(postRecord) // Throws if invalid\n * ```\n */\n static async build(\n indexer: LexiconIndexer,\n fullRef: string,\n ): Promise<l.Schema<LexValue>> {\n const ctx = new LexiconSchemaBuilder(indexer)\n try {\n const result = await ctx.buildFullRef(fullRef)\n if (!(result instanceof l.Schema)) {\n throw new Error(`Ref ${fullRef} is not a schema type`)\n }\n return result\n } finally {\n await ctx.done()\n }\n }\n\n /**\n * Builds validators for all definitions in all documents from an iterable indexer.\n *\n * This method iterates over all Lexicon documents available in the indexer\n * and builds validators for every definition in each document.\n *\n * @param indexer - An iterable Lexicon indexer (must implement `Symbol.asyncIterator`)\n * @returns A promise resolving to a Map of full references to their validators.\n * The map values can be validators, Query, Subscription, Procedure, or PermissionSet.\n * @throws Error if the indexer does not support iteration\n *\n * @example\n * ```ts\n * const indexer = new LexiconIterableIndexer(allLexiconDocs)\n * const schemas = await LexiconSchemaBuilder.buildAll(indexer)\n *\n * // Access a specific schema\n * const postSchema = schemas.get('app.bsky.feed.post#main')\n *\n * // Iterate all schemas\n * for (const [ref, schema] of schemas) {\n * console.log(ref, schema)\n * }\n * ```\n */\n static async buildAll(indexer: LexiconIndexer) {\n const builder = new LexiconSchemaBuilder(indexer)\n const schemas = new Map<\n string,\n | l.Schema<LexValue>\n | l.Query\n | l.Subscription\n | l.Procedure\n | l.PermissionSet\n >()\n if (!isAsyncIterableObject(indexer)) {\n throw new Error('An iterable indexer is required to build all schemas')\n }\n try {\n for await (const doc of indexer) {\n for (const hash of Object.keys(doc.defs)) {\n const fullRef = `${doc.id}#${hash}`\n const schema = await builder.buildFullRef(fullRef)\n schemas.set(fullRef, schema)\n }\n }\n return schemas\n } finally {\n await builder.done()\n }\n }\n\n #asyncTasks = new AsyncTasks()\n\n /**\n * Creates a new LexiconSchemaBuilder instance.\n *\n * Note: For most use cases, prefer using the static `build()` or `buildAll()`\n * methods instead of instantiating directly.\n *\n * @param indexer - The Lexicon indexer to resolve documents from\n */\n constructor(protected indexer: LexiconIndexer) {}\n\n /**\n * Waits for all pending reference resolution tasks to complete.\n *\n * When building schemas with cross-references, the builder schedules\n * async tasks to resolve those references. This method must be called\n * to ensure all references are fully resolved before using the validators.\n *\n * @returns A promise that resolves when all pending tasks are complete\n * @throws Rethrows any errors from failed reference resolution\n */\n async done(): Promise<void> {\n await this.#asyncTasks.done()\n }\n\n async [Symbol.asyncDispose]() {\n await this.done()\n }\n\n /**\n * Builds a validator for a full reference (memoized).\n *\n * Results are cached, so calling with the same reference returns\n * the same promise/result.\n *\n * @param fullRef - The full reference in format \"nsid#defName\"\n * @returns A promise resolving to the built schema or method definition\n */\n buildFullRef = memoize(async (fullRef: string) => {\n const { nsid, hash } = parseRef(fullRef)\n\n const doc = await this.indexer.get(nsid)\n\n return this.compileDef(doc, hash)\n })\n\n protected buildRefGetter(fullRef: string): () => l.Schema<LexValue> {\n let schema: l.Schema<LexValue>\n\n this.#asyncTasks.add(\n this.buildFullRef(fullRef).then((v) => {\n if (!(v instanceof l.Schema)) {\n throw new Error(`Only refs to schema types are allowed`)\n }\n schema = v\n }),\n )\n\n return () => {\n if (schema) return schema\n throw new Error('Validator not yet built. Did you await done()?')\n }\n }\n\n protected buildTypedRefGetter(\n fullRef: string,\n ): () => l.TypedObjectSchema | l.RecordSchema {\n let validator: l.TypedObjectSchema | l.RecordSchema\n\n this.#asyncTasks.add(\n this.buildFullRef(fullRef).then((v) => {\n if (v instanceof l.TypedObjectSchema || v instanceof l.RecordSchema) {\n validator = v\n } else {\n throw new Error(\n 'Only refs to records and object definitions are allowed',\n )\n }\n }),\n )\n\n return () => {\n if (validator) return validator\n throw new Error('Validator not yet built. Did you await done()?')\n }\n }\n\n protected compileDef(doc: LexiconDocument, hash: string) {\n const def = Object.hasOwn(doc.defs, hash) ? doc.defs[hash] : null\n if (!def) {\n throw new Error(\n `No definition found for hash \"${JSON.stringify(hash)}\" in ${doc.id}`,\n )\n }\n switch (def.type) {\n case 'permission-set':\n return l.permissionSet(\n doc.id,\n def.permissions.map(({ resource, type, ...p }) =>\n l.permission(resource, p),\n ),\n def,\n )\n case 'procedure':\n return l.procedure(\n doc.id,\n this.compileParams(doc, def.parameters),\n this.compilePayload(doc, def.input),\n this.compilePayload(doc, def.output),\n this.compileErrors(doc, def.errors),\n )\n case 'query':\n return l.query(\n doc.id,\n this.compileParams(doc, def.parameters),\n this.compilePayload(doc, def.output),\n this.compileErrors(doc, def.errors),\n )\n case 'subscription':\n return l.subscription(\n doc.id,\n this.compileParams(doc, def.parameters),\n this.compilePayloadSchema(doc, def.message.schema),\n this.compileErrors(doc, def.errors),\n )\n case 'token':\n return l.token(doc.id, hash)\n case 'record':\n return l.record(def.key, doc.id, this.compileObject(doc, def.record))\n case 'object':\n return l.typedObject(doc.id, hash, this.compileObject(doc, def))\n default:\n return this.compileLeaf(doc, def)\n }\n }\n\n protected compileLeaf(\n doc: LexiconDocument,\n def: LexiconArray | LexiconArrayItems,\n ): l.Schema<LexValue> {\n if (\n 'const' in def &&\n 'enum' in def &&\n def.enum != null &&\n def.const !== undefined &&\n !(def.enum as readonly unknown[]).includes(def.const)\n ) {\n return l.never()\n }\n\n switch (def.type) {\n case 'string': {\n const schema = l.string(def)\n if (def.default != null) schema.check(def.default)\n if (def.const != null) schema.check(def.const)\n if (def.enum != null) for (const v of def.enum) schema.check(v)\n\n const result =\n def.const != null\n ? l.literal(def.const)\n : def.enum != null\n ? l.enum(def.enum)\n : schema\n\n return def.default != null ? l.withDefault(result, def.default) : result\n }\n case 'integer': {\n const schema = l.integer(def)\n if (def.default != null) schema.check(def.default)\n if (def.const != null) schema.check(def.const)\n if (def.enum != null) for (const v of def.enum) schema.check(v)\n\n const result =\n def.const != null\n ? l.literal(def.const)\n : def.enum != null\n ? l.enum(def.enum)\n : schema\n\n return def.default != null ? l.withDefault(result, def.default) : result\n }\n case 'boolean': {\n const result = def.const != null ? l.literal(def.const) : l.boolean()\n\n return def.default != null ? l.withDefault(result, def.default) : result\n }\n case 'blob':\n return l.blob(def)\n case 'cid-link':\n return l.cid()\n case 'bytes':\n return l.bytes(def)\n case 'unknown':\n return l.lexMap()\n case 'array':\n return l.array(this.compileLeaf(doc, def.items), def)\n default:\n return this.compileRef(doc, def)\n }\n }\n\n protected compileRef(\n doc: LexiconDocument,\n def: LexiconRef | LexiconRefUnion,\n ): l.Schema<LexValue> {\n switch (def.type) {\n case 'ref':\n return l.ref(this.buildRefGetter(buildFullRef(doc, def.ref)))\n case 'union':\n return l.typedUnion(\n def.refs.map((r) =>\n l.typedRef(this.buildTypedRefGetter(buildFullRef(doc, r))),\n ),\n def.closed ?? false,\n )\n default:\n // @ts-expect-error\n throw new Error(`Unknown lexicon type: ${def.type}`)\n }\n }\n\n protected compileObject(doc: LexiconDocument, def: LexiconObject) {\n const props: Record<string, l.Schema<undefined | LexValue>> = {}\n for (const [key, propDef] of Object.entries(def.properties)) {\n if (propDef === undefined) continue\n\n const isNullable = def.nullable?.includes(key)\n const isRequired = def.required?.includes(key)\n\n let schema: l.Schema<undefined | LexValue> = this.compileLeaf(\n doc,\n propDef,\n )\n\n if (isNullable) {\n schema = l.nullable(schema)\n }\n\n if (!isRequired) {\n schema = l.optional(schema)\n }\n\n props[key] = schema\n }\n return l.object(props)\n }\n\n protected compilePayload(\n doc: LexiconDocument,\n def: LexiconPayload | undefined,\n ) {\n return l.payload(\n def?.encoding,\n def?.schema ? this.compilePayloadSchema(doc, def.schema) : undefined,\n )\n }\n\n protected compileErrors(\n _doc: LexiconDocument,\n errors?: readonly LexiconError[],\n ): undefined | string[] {\n return errors?.map((e) => e.name)\n }\n\n protected compilePayloadSchema(\n doc: LexiconDocument,\n def: LexiconObject | LexiconRef | LexiconRefUnion,\n ): l.Schema<LexValue, LexValue> {\n switch (def.type) {\n case 'object':\n return this.compileObject(doc, def)\n default:\n return this.compileRef(doc, def)\n }\n }\n\n protected compileParams(doc: LexiconDocument, def?: LexiconParameters) {\n if (!def) return l.params()\n\n const shape: l.ParamsShape = {}\n for (const [paramName, paramDef] of Object.entries(def.properties)) {\n if (paramDef === undefined) continue\n\n const isRequired = def.required?.includes(paramName)\n\n const propSchema = this.compileLeaf(doc, paramDef) as\n | l.StringSchema\n | l.BooleanSchema\n | l.IntegerSchema\n | l.ArraySchema<l.StringSchema>\n | l.ArraySchema<l.BooleanSchema>\n | l.ArraySchema<l.IntegerSchema>\n\n shape[paramName] = isRequired ? propSchema : l.optional(propSchema)\n }\n\n return l.params(shape)\n }\n}\n\nclass AsyncTasks {\n /**\n * A set that, eventually, contains only rejected promises.\n */\n #promises = new Set<Promise<void>>()\n\n async done(): Promise<void> {\n do {\n // @NOTE this is going to throw on the first rejected promise (which is\n // what we want)\n for (const p of this.#promises) await p\n // At this point, all settled promises should have been removed. If\n // this.#promises is not empty, it means new promises were added during\n // the awaiting process, so we loop again.\n } while (this.#promises.size > 0)\n }\n\n add(p: Promise<void>) {\n const promise = Promise.resolve(p).then(() => {\n // No need to keep the promise any longer\n this.#promises.delete(promise)\n })\n\n void promise.catch((_err) => {\n // ignore errors here, they should be caught though done()\n })\n\n this.#promises.add(promise)\n }\n}\n\nfunction parseRef(fullRef: string) {\n const { length, 0: nsid, 1: hash } = fullRef.split('#')\n if (length !== 2) throw new Error('Uri can only have one hash segment')\n if (!nsid || !hash) throw new Error('Invalid ref, missing hash')\n return { nsid, hash }\n}\n\nfunction buildFullRef(from: LexiconDocument, ref: string) {\n if (ref.startsWith('#')) return `${from.id}${ref}`\n return ref\n}\n\nexport function memoize<Fn extends (arg: string) => unknown>(fn: Fn): Fn {\n const cache = new Map<string, ReturnType<Fn>>()\n return ((arg: string) => {\n if (cache.has(arg)) return cache.get(arg)!\n const result = fn(arg) as ReturnType<Fn>\n cache.set(arg, result)\n return result\n }) as Fn\n}\n\nfunction isAsyncIterableObject<T>(\n obj: T,\n): obj is T & object & AsyncIterable<unknown> {\n return (\n obj != null &&\n typeof obj === 'object' &&\n Symbol.asyncIterator in obj &&\n typeof obj[Symbol.asyncIterator] === 'function'\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"lexicon-schema-builder.js","sourceRoot":"","sources":["../src/lexicon-schema-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AAcvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,OAAO,oBAAoB;IAC/B;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,KAAK,C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;IAC/C,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;QACtB,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAE,CAAA;QAC1C,MAAM,MAAM,GAAG,EAAE,CAAC,GAAG,CAAmB,CAAA;QACxC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACtB,OAAO,MAAM,CAAA;IACf,CAAC,CAAO,CAAA;AACV,CAAC;AAED,SAAS,qBAAqB,CAC5B,GAAM;IAEN,OAAO,CACL,GAAG,IAAI,IAAI;QACX,OAAO,GAAG,KAAK,QAAQ;QACvB,MAAM,CAAC,aAAa,IAAI,GAAG;QAC3B,OAAO,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,UAAU,CAChD,CAAA;AACH,CAAC","sourcesContent":["import { LexValue } from '@atproto/lex-data'\nimport { l } from '@atproto/lex-schema'\nimport {\n LexiconArray,\n LexiconArrayItems,\n LexiconDocument,\n LexiconError,\n LexiconObject,\n LexiconParameters,\n LexiconPayload,\n LexiconRef,\n LexiconRefUnion,\n} from './lexicon-document.js'\nimport { LexiconIndexer } from './lexicon-indexer.js'\n\n/**\n * Builds validators for Lexicon documents.\n *\n * This class converts Lexicon type definitions into runtime validators\n * that can validate data against the schema. It handles reference resolution,\n * supporting both local (`#defName`) and cross-document (`nsid#defName`) refs.\n *\n * @example\n * ```ts\n * import { LexiconSchemaBuilder, LexiconIterableIndexer } from '@atproto/lex-document'\n *\n * // Build a single validator\n * const indexer = new LexiconIterableIndexer(lexiconDocs)\n * const validator = await LexiconSchemaBuilder.build(indexer, 'com.example.post#main')\n *\n * // Validate data\n * const result = validator.safeParse(myPostData)\n * if (result.success) {\n * console.log('Valid:', result.value)\n * } else {\n * console.log('Invalid:', result.error)\n * }\n * ```\n *\n * @example\n * ```ts\n * // Build all validators from an iterable indexer\n * const indexer = new LexiconIterableIndexer(lexiconDocs)\n * const allSchemas = await LexiconSchemaBuilder.buildAll(indexer)\n *\n * for (const [ref, schema] of allSchemas) {\n * console.log(`Built validator for ${ref}`)\n * }\n * ```\n */\nexport class LexiconSchemaBuilder implements AsyncDisposable {\n /**\n * Builds a validator for a single Lexicon definition reference.\n *\n * @param indexer - The Lexicon indexer to resolve documents from\n * @param fullRef - The full reference to build, in format \"nsid#defName\"\n * @returns A promise resolving to a validator for the referenced definition\n * @throws Error if the reference does not point to a schema type\n *\n * @example\n * ```ts\n * const validator = await LexiconSchemaBuilder.build(\n * indexer,\n * 'app.bsky.feed.post#main'\n * )\n *\n * validator.parse(postRecord) // Throws if invalid\n * ```\n */\n static async build(\n indexer: LexiconIndexer,\n fullRef: string,\n ): Promise<l.Schema<LexValue>> {\n const ctx = new LexiconSchemaBuilder(indexer)\n try {\n const result = await ctx.buildFullRef(fullRef)\n if (!(result instanceof l.Schema)) {\n throw new Error(`Ref ${fullRef} is not a schema type`)\n }\n return result\n } finally {\n await ctx.done()\n }\n }\n\n /**\n * Builds validators for all definitions in all documents from an iterable indexer.\n *\n * This method iterates over all Lexicon documents available in the indexer\n * and builds validators for every definition in each document.\n *\n * @param indexer - An iterable Lexicon indexer (must implement `Symbol.asyncIterator`)\n * @returns A promise resolving to a Map of full references to their validators.\n * The map values can be validators, Query, Subscription, Procedure, or PermissionSet.\n * @throws Error if the indexer does not support iteration\n *\n * @example\n * ```ts\n * const indexer = new LexiconIterableIndexer(allLexiconDocs)\n * const schemas = await LexiconSchemaBuilder.buildAll(indexer)\n *\n * // Access a specific schema\n * const postSchema = schemas.get('app.bsky.feed.post#main')\n *\n * // Iterate all schemas\n * for (const [ref, schema] of schemas) {\n * console.log(ref, schema)\n * }\n * ```\n */\n static async buildAll(indexer: LexiconIndexer) {\n const builder = new LexiconSchemaBuilder(indexer)\n const schemas = new Map<\n string,\n | l.Schema<LexValue>\n | l.Query\n | l.Subscription\n | l.Procedure\n | l.PermissionSet\n >()\n if (!isAsyncIterableObject(indexer)) {\n throw new Error('An iterable indexer is required to build all schemas')\n }\n try {\n for await (const doc of indexer) {\n for (const hash of Object.keys(doc.defs)) {\n const fullRef = `${doc.id}#${hash}`\n const schema = await builder.buildFullRef(fullRef)\n schemas.set(fullRef, schema)\n }\n }\n return schemas\n } finally {\n await builder.done()\n }\n }\n\n #asyncTasks = new AsyncTasks()\n\n /**\n * Creates a new LexiconSchemaBuilder instance.\n *\n * Note: For most use cases, prefer using the static `build()` or `buildAll()`\n * methods instead of instantiating directly.\n *\n * @param indexer - The Lexicon indexer to resolve documents from\n */\n constructor(protected indexer: LexiconIndexer) {}\n\n /**\n * Waits for all pending reference resolution tasks to complete.\n *\n * When building schemas with cross-references, the builder schedules\n * async tasks to resolve those references. This method must be called\n * to ensure all references are fully resolved before using the validators.\n *\n * @returns A promise that resolves when all pending tasks are complete\n * @throws Rethrows any errors from failed reference resolution\n */\n async done(): Promise<void> {\n await this.#asyncTasks.done()\n }\n\n async [Symbol.asyncDispose]() {\n await this.done()\n }\n\n /**\n * Builds a validator for a full reference (memoized).\n *\n * Results are cached, so calling with the same reference returns\n * the same promise/result.\n *\n * @param fullRef - The full reference in format \"nsid#defName\"\n * @returns A promise resolving to the built schema or method definition\n */\n buildFullRef = memoize(async (fullRef: string) => {\n const { nsid, hash } = parseRef(fullRef)\n\n const doc = await this.indexer.get(nsid)\n\n return this.compileDef(doc, hash)\n })\n\n protected buildRefGetter(fullRef: string): () => l.Schema<LexValue> {\n let schema: l.Schema<LexValue>\n\n this.#asyncTasks.add(\n this.buildFullRef(fullRef).then((v) => {\n if (!(v instanceof l.Schema)) {\n throw new Error(`Only refs to schema types are allowed`)\n }\n schema = v\n }),\n )\n\n return () => {\n if (schema) return schema\n throw new Error('Validator not yet built. Did you await done()?')\n }\n }\n\n protected buildTypedRefGetter(\n fullRef: string,\n ): () => l.TypedObjectSchema | l.RecordSchema {\n let validator: l.TypedObjectSchema | l.RecordSchema\n\n this.#asyncTasks.add(\n this.buildFullRef(fullRef).then((v) => {\n if (v instanceof l.TypedObjectSchema || v instanceof l.RecordSchema) {\n validator = v\n } else {\n throw new Error(\n 'Only refs to records and object definitions are allowed',\n )\n }\n }),\n )\n\n return () => {\n if (validator) return validator\n throw new Error('Validator not yet built. Did you await done()?')\n }\n }\n\n protected compileDef(doc: LexiconDocument, hash: string) {\n const def = Object.hasOwn(doc.defs, hash) ? doc.defs[hash] : null\n if (!def) {\n throw new Error(\n `No definition found for hash \"${JSON.stringify(hash)}\" in ${doc.id}`,\n )\n }\n switch (def.type) {\n case 'permission-set':\n return l.permissionSet(\n doc.id,\n def.permissions.map(({ resource, type, ...p }) =>\n l.permission(resource, p),\n ),\n def,\n )\n case 'procedure':\n return l.procedure(\n doc.id,\n this.compileParams(doc, def.parameters),\n this.compilePayload(doc, def.input),\n this.compilePayload(doc, def.output),\n this.compileErrors(doc, def.errors),\n )\n case 'query':\n return l.query(\n doc.id,\n this.compileParams(doc, def.parameters),\n this.compilePayload(doc, def.output),\n this.compileErrors(doc, def.errors),\n )\n case 'subscription':\n return l.subscription(\n doc.id,\n this.compileParams(doc, def.parameters),\n this.compilePayloadSchema(doc, def.message.schema),\n this.compileErrors(doc, def.errors),\n )\n case 'token':\n return l.token(doc.id, hash)\n case 'record':\n return l.record(def.key, doc.id, this.compileObject(doc, def.record))\n case 'object':\n return l.typedObject(doc.id, hash, this.compileObject(doc, def))\n default:\n return this.compileLeaf(doc, def)\n }\n }\n\n protected compileLeaf(\n doc: LexiconDocument,\n def: LexiconArray | LexiconArrayItems,\n ): l.Schema<LexValue> {\n if (\n 'const' in def &&\n 'enum' in def &&\n def.enum != null &&\n def.const !== undefined &&\n !(def.enum as readonly unknown[]).includes(def.const)\n ) {\n return l.never()\n }\n\n switch (def.type) {\n case 'string': {\n const schema = l.string(def)\n if (def.default != null) schema.check(def.default)\n if (def.const != null) schema.check(def.const)\n if (def.enum != null) for (const v of def.enum) schema.check(v)\n\n const result =\n def.const != null\n ? l.literal(def.const)\n : def.enum != null\n ? l.enum(def.enum)\n : schema\n\n return def.default != null ? l.withDefault(result, def.default) : result\n }\n case 'integer': {\n const schema = l.integer(def)\n if (def.default != null) schema.check(def.default)\n if (def.const != null) schema.check(def.const)\n if (def.enum != null) for (const v of def.enum) schema.check(v)\n\n const result =\n def.const != null\n ? l.literal(def.const)\n : def.enum != null\n ? l.enum(def.enum)\n : schema\n\n return def.default != null ? l.withDefault(result, def.default) : result\n }\n case 'boolean': {\n const result = def.const != null ? l.literal(def.const) : l.boolean()\n\n return def.default != null ? l.withDefault(result, def.default) : result\n }\n case 'blob':\n return l.blob(def)\n case 'cid-link':\n return l.cid()\n case 'bytes':\n return l.bytes(def)\n case 'unknown':\n return l.lexMap()\n case 'array':\n return l.array(this.compileLeaf(doc, def.items), def)\n default:\n return this.compileRef(doc, def)\n }\n }\n\n protected compileRef(\n doc: LexiconDocument,\n def: LexiconRef | LexiconRefUnion,\n ): l.Schema<LexValue> {\n switch (def.type) {\n case 'ref':\n return l.ref(this.buildRefGetter(buildFullRef(doc, def.ref)))\n case 'union':\n return l.typedUnion(\n def.refs.map((r) =>\n l.typedRef(this.buildTypedRefGetter(buildFullRef(doc, r))),\n ),\n def.closed ?? false,\n )\n default:\n // @ts-expect-error\n throw new Error(`Unknown lexicon type: ${def.type}`)\n }\n }\n\n protected compileObject(doc: LexiconDocument, def: LexiconObject) {\n const props: Record<string, l.Schema<undefined | LexValue>> = {}\n for (const [key, propDef] of Object.entries(def.properties)) {\n if (propDef === undefined) continue\n\n const isNullable = def.nullable?.includes(key)\n const isRequired = def.required?.includes(key)\n\n let schema: l.Schema<undefined | LexValue> = this.compileLeaf(\n doc,\n propDef,\n )\n\n if (isNullable) {\n schema = l.nullable(schema)\n }\n\n if (!isRequired) {\n schema = l.optional(schema)\n }\n\n props[key] = schema\n }\n return l.object(props)\n }\n\n protected compilePayload(\n doc: LexiconDocument,\n def: LexiconPayload | undefined,\n ) {\n return l.payload(\n def?.encoding,\n def?.schema ? this.compilePayloadSchema(doc, def.schema) : undefined,\n )\n }\n\n protected compileErrors(\n _doc: LexiconDocument,\n errors?: readonly LexiconError[],\n ): undefined | string[] {\n return errors?.map((e) => e.name)\n }\n\n protected compilePayloadSchema(\n doc: LexiconDocument,\n def: LexiconObject | LexiconRef | LexiconRefUnion,\n ): l.Schema<LexValue, LexValue> {\n switch (def.type) {\n case 'object':\n return this.compileObject(doc, def)\n default:\n return this.compileRef(doc, def)\n }\n }\n\n protected compileParams(doc: LexiconDocument, def?: LexiconParameters) {\n if (!def) return l.params()\n\n const shape: l.ParamsShape = {}\n for (const [paramName, paramDef] of Object.entries(def.properties)) {\n if (paramDef === undefined) continue\n\n const isRequired = def.required?.includes(paramName)\n\n const propSchema = this.compileLeaf(doc, paramDef) as\n | l.StringSchema\n | l.BooleanSchema\n | l.IntegerSchema\n | l.ArraySchema<l.StringSchema>\n | l.ArraySchema<l.BooleanSchema>\n | l.ArraySchema<l.IntegerSchema>\n\n shape[paramName] = isRequired ? propSchema : l.optional(propSchema)\n }\n\n return l.params(shape)\n }\n}\n\nclass AsyncTasks {\n /**\n * A set that, eventually, contains only rejected promises.\n */\n #promises = new Set<Promise<void>>()\n\n async done(): Promise<void> {\n do {\n // @NOTE this is going to throw on the first rejected promise (which is\n // what we want)\n for (const p of this.#promises) await p\n // At this point, all settled promises should have been removed. If\n // this.#promises is not empty, it means new promises were added during\n // the awaiting process, so we loop again.\n } while (this.#promises.size > 0)\n }\n\n add(p: Promise<void>) {\n const promise = Promise.resolve(p).then(() => {\n // No need to keep the promise any longer\n this.#promises.delete(promise)\n })\n\n void promise.catch((_err) => {\n // ignore errors here, they should be caught though done()\n })\n\n this.#promises.add(promise)\n }\n}\n\nfunction parseRef(fullRef: string) {\n const { length, 0: nsid, 1: hash } = fullRef.split('#')\n if (length !== 2) throw new Error('Uri can only have one hash segment')\n if (!nsid || !hash) throw new Error('Invalid ref, missing hash')\n return { nsid, hash }\n}\n\nfunction buildFullRef(from: LexiconDocument, ref: string) {\n if (ref.startsWith('#')) return `${from.id}${ref}`\n return ref\n}\n\nexport function memoize<Fn extends (arg: string) => unknown>(fn: Fn): Fn {\n const cache = new Map<string, ReturnType<Fn>>()\n return ((arg: string) => {\n if (cache.has(arg)) return cache.get(arg)!\n const result = fn(arg) as ReturnType<Fn>\n cache.set(arg, result)\n return result\n }) as Fn\n}\n\nfunction isAsyncIterableObject<T>(\n obj: T,\n): obj is T & object & AsyncIterable<unknown> {\n return (\n obj != null &&\n typeof obj === 'object' &&\n Symbol.asyncIterator in obj &&\n typeof obj[Symbol.asyncIterator] === 'function'\n )\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/lex-document",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=22"
|
|
6
|
+
},
|
|
4
7
|
"license": "MIT",
|
|
5
8
|
"description": "Lexicon document validation tools for AT",
|
|
6
9
|
"keywords": [
|
|
@@ -24,25 +27,21 @@
|
|
|
24
27
|
"./CHANGELOG.md"
|
|
25
28
|
],
|
|
26
29
|
"sideEffects": false,
|
|
27
|
-
"type": "
|
|
28
|
-
"main": "./dist/index.js",
|
|
29
|
-
"types": "./dist/index.d.ts",
|
|
30
|
+
"type": "module",
|
|
30
31
|
"exports": {
|
|
31
32
|
".": {
|
|
32
33
|
"types": "./dist/index.d.ts",
|
|
33
|
-
"browser": "./dist/index.js",
|
|
34
|
-
"import": "./dist/index.js",
|
|
35
34
|
"default": "./dist/index.js"
|
|
36
35
|
}
|
|
37
36
|
},
|
|
38
37
|
"dependencies": {
|
|
39
38
|
"core-js": "^3",
|
|
40
39
|
"tslib": "^2.8.1",
|
|
41
|
-
"@atproto/lex-schema": "^0.0
|
|
40
|
+
"@atproto/lex-schema": "^0.1.0"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
44
43
|
"vitest": "^4.0.16",
|
|
45
|
-
"@atproto/lex-data": "^0.0
|
|
44
|
+
"@atproto/lex-data": "^0.1.0"
|
|
46
45
|
},
|
|
47
46
|
"scripts": {
|
|
48
47
|
"build": "tsc --build tsconfig.build.json",
|
package/src/core-js.d.ts
ADDED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import 'core-js/
|
|
2
|
-
import 'core-js/
|
|
1
|
+
import 'core-js/es/symbol/async-dispose.js'
|
|
2
|
+
import 'core-js/es/symbol/dispose.js'
|
|
3
3
|
|
|
4
4
|
export * from './lexicon-document.js'
|
|
5
5
|
export * from './lexicon-indexer.js'
|
package/tsconfig.tests.json
CHANGED