@atproto/lex-document 0.0.9 → 0.0.11
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 +14 -0
- package/LICENSE.txt +1 -1
- package/dist/lexicon-document.d.ts +2414 -2395
- package/dist/lexicon-document.d.ts.map +1 -1
- package/dist/lexicon-document.js +59 -67
- package/dist/lexicon-document.js.map +1 -1
- package/dist/lexicon-schema-builder.d.ts +7 -15
- package/dist/lexicon-schema-builder.d.ts.map +1 -1
- package/dist/lexicon-schema-builder.js +16 -25
- package/dist/lexicon-schema-builder.js.map +1 -1
- package/package.json +3 -3
- package/src/lexicon-document.ts +59 -71
- package/src/lexicon-schema-builder.test.ts +2 -2
- package/src/lexicon-schema-builder.ts +17 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-document.d.ts","sourceRoot":"","sources":["../src/lexicon-document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"lexicon-document.d.ts","sourceRoot":"","sources":["../src/lexicon-document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AAMvC,eAAO,MAAM,oBAAoB;;;;;EAK/B,CAAA;AACF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAEjE,eAAO,MAAM,oBAAoB;;;;;;;;EAQ/B,CAAA;AACF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAEjE,eAAO,MAAM,mBAAmB;;;;;;;;;;;;EAY9B,CAAA;AACF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAE/D,eAAO,MAAM,kBAAkB;;;;;EAK7B,CAAA;AACF,MAAM,MAAM,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2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.lexiconDocumentSchema = exports.lexiconIdentifierSchema = 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
4
|
const lex_schema_1 = require("@atproto/lex-schema");
|
|
5
|
-
// Re-usable shortcuts (avoid creating too many schemas)
|
|
6
|
-
const bool = lex_schema_1.l.boolean();
|
|
7
|
-
const int = lex_schema_1.l.integer();
|
|
8
|
-
const str = lex_schema_1.l.string();
|
|
9
|
-
const boopOpt = lex_schema_1.l.optional(bool);
|
|
10
|
-
const intOpt = lex_schema_1.l.optional(int);
|
|
11
|
-
const strOpt = lex_schema_1.l.optional(str);
|
|
12
|
-
const strArrOpt = lex_schema_1.l.optional(lex_schema_1.l.array(str));
|
|
13
5
|
// https://atproto.com/specs/lexicon
|
|
14
6
|
// "Concrete" Types
|
|
15
7
|
exports.lexiconBooleanSchema = lex_schema_1.l.object({
|
|
16
8
|
type: lex_schema_1.l.literal('boolean'),
|
|
17
|
-
default:
|
|
18
|
-
const:
|
|
19
|
-
description:
|
|
9
|
+
default: lex_schema_1.l.optional(lex_schema_1.l.boolean()),
|
|
10
|
+
const: lex_schema_1.l.optional(lex_schema_1.l.boolean()),
|
|
11
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
20
12
|
});
|
|
21
13
|
exports.lexiconIntegerSchema = lex_schema_1.l.object({
|
|
22
14
|
type: lex_schema_1.l.literal('integer'),
|
|
23
|
-
default:
|
|
24
|
-
minimum:
|
|
25
|
-
maximum:
|
|
15
|
+
default: lex_schema_1.l.optional(lex_schema_1.l.integer()),
|
|
16
|
+
minimum: lex_schema_1.l.optional(lex_schema_1.l.integer()),
|
|
17
|
+
maximum: lex_schema_1.l.optional(lex_schema_1.l.integer()),
|
|
26
18
|
enum: lex_schema_1.l.optional(lex_schema_1.l.array(lex_schema_1.l.integer())),
|
|
27
|
-
const:
|
|
28
|
-
description:
|
|
19
|
+
const: lex_schema_1.l.optional(lex_schema_1.l.integer()),
|
|
20
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
29
21
|
});
|
|
30
22
|
exports.lexiconStringSchema = lex_schema_1.l.object({
|
|
31
23
|
type: lex_schema_1.l.literal('string'),
|
|
32
24
|
format: lex_schema_1.l.optional(lex_schema_1.l.enum(lex_schema_1.l.STRING_FORMATS)),
|
|
33
|
-
default:
|
|
34
|
-
minLength:
|
|
35
|
-
maxLength:
|
|
36
|
-
minGraphemes:
|
|
37
|
-
maxGraphemes:
|
|
38
|
-
enum:
|
|
39
|
-
const:
|
|
40
|
-
knownValues:
|
|
41
|
-
description:
|
|
25
|
+
default: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
26
|
+
minLength: lex_schema_1.l.optional(lex_schema_1.l.integer()),
|
|
27
|
+
maxLength: lex_schema_1.l.optional(lex_schema_1.l.integer()),
|
|
28
|
+
minGraphemes: lex_schema_1.l.optional(lex_schema_1.l.integer()),
|
|
29
|
+
maxGraphemes: lex_schema_1.l.optional(lex_schema_1.l.integer()),
|
|
30
|
+
enum: lex_schema_1.l.optional(lex_schema_1.l.array(lex_schema_1.l.string())),
|
|
31
|
+
const: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
32
|
+
knownValues: lex_schema_1.l.optional(lex_schema_1.l.array(lex_schema_1.l.string())),
|
|
33
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
42
34
|
});
|
|
43
35
|
exports.lexiconBytesSchema = lex_schema_1.l.object({
|
|
44
36
|
type: lex_schema_1.l.literal('bytes'),
|
|
45
|
-
maxLength:
|
|
46
|
-
minLength:
|
|
47
|
-
description:
|
|
37
|
+
maxLength: lex_schema_1.l.optional(lex_schema_1.l.integer()),
|
|
38
|
+
minLength: lex_schema_1.l.optional(lex_schema_1.l.integer()),
|
|
39
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
48
40
|
});
|
|
49
41
|
exports.lexiconCidLinkSchema = lex_schema_1.l.object({
|
|
50
42
|
type: lex_schema_1.l.literal('cid-link'),
|
|
51
|
-
description:
|
|
43
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
52
44
|
});
|
|
53
45
|
exports.lexiconBlobSchema = lex_schema_1.l.object({
|
|
54
46
|
type: lex_schema_1.l.literal('blob'),
|
|
55
|
-
accept:
|
|
56
|
-
maxSize:
|
|
57
|
-
description:
|
|
47
|
+
accept: lex_schema_1.l.optional(lex_schema_1.l.array(lex_schema_1.l.string())),
|
|
48
|
+
maxSize: lex_schema_1.l.optional(lex_schema_1.l.integer()),
|
|
49
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
58
50
|
});
|
|
59
51
|
const CONCRETE_TYPES = [
|
|
60
52
|
exports.lexiconBooleanSchema,
|
|
@@ -69,22 +61,22 @@ const CONCRETE_TYPES = [
|
|
|
69
61
|
// Meta types
|
|
70
62
|
exports.lexiconUnknownSchema = lex_schema_1.l.object({
|
|
71
63
|
type: lex_schema_1.l.literal('unknown'),
|
|
72
|
-
description:
|
|
64
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
73
65
|
});
|
|
74
66
|
exports.lexiconTokenSchema = lex_schema_1.l.object({
|
|
75
67
|
type: lex_schema_1.l.literal('token'),
|
|
76
|
-
description:
|
|
68
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
77
69
|
});
|
|
78
70
|
exports.lexiconRefSchema = lex_schema_1.l.object({
|
|
79
71
|
type: lex_schema_1.l.literal('ref'),
|
|
80
|
-
ref:
|
|
81
|
-
description:
|
|
72
|
+
ref: lex_schema_1.l.string(),
|
|
73
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
82
74
|
});
|
|
83
75
|
exports.lexiconRefUnionSchema = lex_schema_1.l.object({
|
|
84
76
|
type: lex_schema_1.l.literal('union'),
|
|
85
|
-
refs: lex_schema_1.l.array(
|
|
86
|
-
closed:
|
|
87
|
-
description:
|
|
77
|
+
refs: lex_schema_1.l.array(lex_schema_1.l.string()),
|
|
78
|
+
closed: lex_schema_1.l.optional(lex_schema_1.l.boolean()),
|
|
79
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
88
80
|
});
|
|
89
81
|
// Complex Types
|
|
90
82
|
const ARRAY_ITEMS_SCHEMAS = [
|
|
@@ -97,9 +89,9 @@ const ARRAY_ITEMS_SCHEMAS = [
|
|
|
97
89
|
exports.lexiconArraySchema = lex_schema_1.l.object({
|
|
98
90
|
type: lex_schema_1.l.literal('array'),
|
|
99
91
|
items: lex_schema_1.l.discriminatedUnion('type', ARRAY_ITEMS_SCHEMAS),
|
|
100
|
-
minLength:
|
|
101
|
-
maxLength:
|
|
102
|
-
description:
|
|
92
|
+
minLength: lex_schema_1.l.optional(lex_schema_1.l.integer()),
|
|
93
|
+
maxLength: lex_schema_1.l.optional(lex_schema_1.l.integer()),
|
|
94
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
103
95
|
});
|
|
104
96
|
const requirePropertiesRefinement = {
|
|
105
97
|
check: (v) => !v.required || v.required.every((k) => k in v.properties),
|
|
@@ -108,26 +100,26 @@ const requirePropertiesRefinement = {
|
|
|
108
100
|
};
|
|
109
101
|
exports.lexiconObjectSchema = lex_schema_1.l.refine(lex_schema_1.l.object({
|
|
110
102
|
type: lex_schema_1.l.literal('object'),
|
|
111
|
-
properties: lex_schema_1.l.dict(
|
|
103
|
+
properties: lex_schema_1.l.dict(lex_schema_1.l.string(), lex_schema_1.l.discriminatedUnion('type', [
|
|
112
104
|
...ARRAY_ITEMS_SCHEMAS,
|
|
113
105
|
exports.lexiconArraySchema,
|
|
114
106
|
])),
|
|
115
|
-
required:
|
|
116
|
-
nullable:
|
|
117
|
-
description:
|
|
107
|
+
required: lex_schema_1.l.optional(lex_schema_1.l.array(lex_schema_1.l.string())),
|
|
108
|
+
nullable: lex_schema_1.l.optional(lex_schema_1.l.array(lex_schema_1.l.string())),
|
|
109
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
118
110
|
}), requirePropertiesRefinement);
|
|
119
111
|
// Records
|
|
120
112
|
exports.lexiconRecordKeySchema = lex_schema_1.l.custom(lex_schema_1.l.isLexiconRecordKey, 'Invalid record key definition (must be "any", "nsid", "tid", or "literal:<string>")');
|
|
121
113
|
exports.lexiconRecordSchema = lex_schema_1.l.object({
|
|
122
114
|
type: lex_schema_1.l.literal('record'),
|
|
123
115
|
record: exports.lexiconObjectSchema,
|
|
124
|
-
description:
|
|
116
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
125
117
|
key: exports.lexiconRecordKeySchema,
|
|
126
118
|
});
|
|
127
119
|
// XRPC Methods
|
|
128
120
|
exports.lexiconParameters = lex_schema_1.l.refine(lex_schema_1.l.object({
|
|
129
121
|
type: lex_schema_1.l.literal('params'),
|
|
130
|
-
properties: lex_schema_1.l.dict(
|
|
122
|
+
properties: lex_schema_1.l.dict(lex_schema_1.l.string(), lex_schema_1.l.discriminatedUnion('type', [
|
|
131
123
|
exports.lexiconBooleanSchema,
|
|
132
124
|
exports.lexiconIntegerSchema,
|
|
133
125
|
exports.lexiconStringSchema,
|
|
@@ -138,33 +130,33 @@ exports.lexiconParameters = lex_schema_1.l.refine(lex_schema_1.l.object({
|
|
|
138
130
|
exports.lexiconIntegerSchema,
|
|
139
131
|
exports.lexiconStringSchema,
|
|
140
132
|
]),
|
|
141
|
-
minLength:
|
|
142
|
-
maxLength:
|
|
143
|
-
description:
|
|
133
|
+
minLength: lex_schema_1.l.optional(lex_schema_1.l.integer()),
|
|
134
|
+
maxLength: lex_schema_1.l.optional(lex_schema_1.l.integer()),
|
|
135
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
144
136
|
}),
|
|
145
137
|
])),
|
|
146
|
-
required:
|
|
147
|
-
description:
|
|
138
|
+
required: lex_schema_1.l.optional(lex_schema_1.l.array(lex_schema_1.l.string())),
|
|
139
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
148
140
|
}), requirePropertiesRefinement);
|
|
149
141
|
exports.lexiconPayload = lex_schema_1.l.object({
|
|
150
|
-
encoding:
|
|
142
|
+
encoding: lex_schema_1.l.string(),
|
|
151
143
|
schema: lex_schema_1.l.optional(lex_schema_1.l.discriminatedUnion('type', [
|
|
152
144
|
exports.lexiconRefSchema,
|
|
153
145
|
exports.lexiconRefUnionSchema,
|
|
154
146
|
exports.lexiconObjectSchema,
|
|
155
147
|
])),
|
|
156
|
-
description:
|
|
148
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
157
149
|
});
|
|
158
150
|
exports.lexiconError = lex_schema_1.l.object({
|
|
159
151
|
name: lex_schema_1.l.string({ minLength: 1 }),
|
|
160
|
-
description:
|
|
152
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
161
153
|
});
|
|
162
154
|
exports.lexiconQuerySchema = lex_schema_1.l.object({
|
|
163
155
|
type: lex_schema_1.l.literal('query'),
|
|
164
156
|
parameters: lex_schema_1.l.optional(exports.lexiconParameters),
|
|
165
157
|
output: lex_schema_1.l.optional(exports.lexiconPayload),
|
|
166
158
|
errors: lex_schema_1.l.optional(lex_schema_1.l.array(exports.lexiconError)),
|
|
167
|
-
description:
|
|
159
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
168
160
|
});
|
|
169
161
|
exports.lexiconProcedureSchema = lex_schema_1.l.object({
|
|
170
162
|
type: lex_schema_1.l.literal('procedure'),
|
|
@@ -172,33 +164,33 @@ exports.lexiconProcedureSchema = lex_schema_1.l.object({
|
|
|
172
164
|
input: lex_schema_1.l.optional(exports.lexiconPayload),
|
|
173
165
|
output: lex_schema_1.l.optional(exports.lexiconPayload),
|
|
174
166
|
errors: lex_schema_1.l.optional(lex_schema_1.l.array(exports.lexiconError)),
|
|
175
|
-
description:
|
|
167
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
176
168
|
});
|
|
177
169
|
exports.lexiconSubscriptionSchema = lex_schema_1.l.object({
|
|
178
170
|
type: lex_schema_1.l.literal('subscription'),
|
|
179
|
-
description:
|
|
171
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
180
172
|
parameters: lex_schema_1.l.optional(exports.lexiconParameters),
|
|
181
173
|
message: lex_schema_1.l.object({
|
|
182
|
-
description:
|
|
174
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
183
175
|
schema: exports.lexiconRefUnionSchema,
|
|
184
176
|
}),
|
|
185
177
|
errors: lex_schema_1.l.optional(lex_schema_1.l.array(exports.lexiconError)),
|
|
186
178
|
});
|
|
187
179
|
// Permissions
|
|
188
180
|
const lexiconLanguageSchema = lex_schema_1.l.string({ format: 'language' });
|
|
189
|
-
const lexiconLanguageDict = lex_schema_1.l.dict(lexiconLanguageSchema,
|
|
181
|
+
const lexiconLanguageDict = lex_schema_1.l.dict(lexiconLanguageSchema, lex_schema_1.l.string());
|
|
190
182
|
const lexiconPermissionSchema = lex_schema_1.l.intersection(lex_schema_1.l.object({
|
|
191
183
|
type: lex_schema_1.l.literal('permission'),
|
|
192
184
|
resource: lex_schema_1.l.string({ minLength: 1 }),
|
|
193
|
-
}), lex_schema_1.l.
|
|
185
|
+
}), lex_schema_1.l.dict(lex_schema_1.l.string(), lex_schema_1.l.paramSchema));
|
|
194
186
|
const lexiconPermissionSetSchema = lex_schema_1.l.object({
|
|
195
187
|
type: lex_schema_1.l.literal('permission-set'),
|
|
196
188
|
permissions: lex_schema_1.l.array(lexiconPermissionSchema),
|
|
197
|
-
title:
|
|
189
|
+
title: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
198
190
|
'title:lang': lex_schema_1.l.optional(lexiconLanguageDict),
|
|
199
|
-
detail:
|
|
191
|
+
detail: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
200
192
|
'detail:lang': lex_schema_1.l.optional(lexiconLanguageDict),
|
|
201
|
-
description:
|
|
193
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
202
194
|
});
|
|
203
195
|
// Schemas that can appear anywhere in the defs
|
|
204
196
|
const NAMED_LEXICON_SCHEMAS = [
|
|
@@ -220,8 +212,8 @@ exports.lexiconIdentifierSchema = lex_schema_1.l.string({ format: 'nsid' });
|
|
|
220
212
|
exports.lexiconDocumentSchema = lex_schema_1.l.object({
|
|
221
213
|
lexicon: lex_schema_1.l.literal(1),
|
|
222
214
|
id: exports.lexiconIdentifierSchema,
|
|
223
|
-
revision:
|
|
224
|
-
description:
|
|
215
|
+
revision: lex_schema_1.l.optional(lex_schema_1.l.integer()),
|
|
216
|
+
description: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
225
217
|
defs: lex_schema_1.l.intersection(lex_schema_1.l.object({
|
|
226
218
|
main: lex_schema_1.l.optional(lex_schema_1.l.discriminatedUnion('type', MAIN_LEXICON_SCHEMAS)),
|
|
227
219
|
}), lex_schema_1.l.dict(lex_schema_1.l.string({ minLength: 1 }), lex_schema_1.l.discriminatedUnion('type', NAMED_LEXICON_SCHEMAS))),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-document.js","sourceRoot":"","sources":["../src/lexicon-document.ts"],"names":[],"mappings":";;;AAAA,oDAAuC;AAEvC,wDAAwD;AAExD,MAAM,IAAI,GAAG,cAAC,CAAC,OAAO,EAAE,CAAA;AACxB,MAAM,GAAG,GAAG,cAAC,CAAC,OAAO,EAAE,CAAA;AACvB,MAAM,GAAG,GAAG,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AG,qBAAqB;CAChB,CAAA;AAMG,QAAA,uBAAuB,GAAG,cAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AAGtD,QAAA,qBAAqB,GAAG,cAAC,CAAC,MAAM,CAAC;IAC5C,OAAO,EAAE,cAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACrB,EAAE,EAAE,+BAAuB;IAC3B,QAAQ,EAAE,MAAM;IAChB,WAAW,EAAE,MAAM;IACnB,IAAI,EAAE,cAAC,CAAC,YAAY,CAClB,cAAC,CAAC,MAAM,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// Re-usable shortcuts (avoid creating too many schemas)\n\nconst bool = l.boolean()\nconst int = l.integer()\nconst str = l.string()\n\nconst boopOpt = l.optional(bool)\nconst intOpt = l.optional(int)\nconst strOpt = l.optional(str)\n\nconst strArrOpt = l.optional(l.array(str))\n\n// https://atproto.com/specs/lexicon\n\n// \"Concrete\" Types\n\nexport const lexiconBooleanSchema = l.object({\n type: l.literal('boolean'),\n default: boopOpt,\n const: boopOpt,\n description: strOpt,\n})\nexport type LexiconBoolean = l.Infer<typeof lexiconBooleanSchema>\n\nexport const lexiconIntegerSchema = l.object({\n type: l.literal('integer'),\n default: intOpt,\n minimum: intOpt,\n maximum: intOpt,\n enum: l.optional(l.array(l.integer())),\n const: intOpt,\n description: strOpt,\n})\nexport type LexiconInteger = l.Infer<typeof lexiconIntegerSchema>\n\nexport const lexiconStringSchema = l.object({\n type: l.literal('string'),\n format: l.optional(l.enum<l.StringFormat>(l.STRING_FORMATS)),\n default: strOpt,\n minLength: intOpt,\n maxLength: intOpt,\n minGraphemes: intOpt,\n maxGraphemes: intOpt,\n enum: strArrOpt,\n const: strOpt,\n knownValues: strArrOpt,\n description: strOpt,\n})\nexport type LexiconString = l.Infer<typeof lexiconStringSchema>\n\nexport const lexiconBytesSchema = l.object({\n type: l.literal('bytes'),\n maxLength: intOpt,\n minLength: intOpt,\n description: strOpt,\n})\nexport type LexiconBytes = l.Infer<typeof lexiconBytesSchema>\n\nexport const lexiconCidLinkSchema = l.object({\n type: l.literal('cid-link'),\n description: strOpt,\n})\nexport type LexiconCid = l.Infer<typeof lexiconCidLinkSchema>\n\nexport const lexiconBlobSchema = l.object({\n type: l.literal('blob'),\n accept: strArrOpt,\n maxSize: intOpt,\n description: strOpt,\n})\nexport type LexiconBlob = l.Infer<typeof lexiconBlobSchema>\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\nexport const lexiconUnknownSchema = l.object({\n type: l.literal('unknown'),\n description: strOpt,\n})\nexport type LexiconUnknown = l.Infer<typeof lexiconUnknownSchema>\n\nexport const lexiconTokenSchema = l.object({\n type: l.literal('token'),\n description: strOpt,\n})\nexport type LexiconToken = l.Infer<typeof lexiconTokenSchema>\n\nexport const lexiconRefSchema = l.object({\n type: l.literal('ref'),\n ref: str,\n description: strOpt,\n})\nexport type LexiconRef = l.Infer<typeof lexiconRefSchema>\n\nexport const lexiconRefUnionSchema = l.object({\n type: l.literal('union'),\n refs: l.array(str),\n closed: boopOpt,\n description: strOpt,\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\nexport type LexiconArrayItems = l.Infer<(typeof ARRAY_ITEMS_SCHEMAS)[number]>\n\nexport const lexiconArraySchema = l.object({\n type: l.literal('array'),\n items: l.discriminatedUnion('type', ARRAY_ITEMS_SCHEMAS),\n minLength: intOpt,\n maxLength: intOpt,\n description: strOpt,\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\nexport const lexiconObjectSchema = l.refine(\n l.object({\n type: l.literal('object'),\n properties: l.dict(\n str,\n l.discriminatedUnion('type', [\n ...ARRAY_ITEMS_SCHEMAS,\n lexiconArraySchema,\n ]),\n ),\n required: strArrOpt,\n nullable: strArrOpt,\n description: strOpt,\n }),\n requirePropertiesRefinement,\n)\nexport type LexiconObject = l.Infer<typeof lexiconObjectSchema>\n\n// Records\n\nexport const lexiconRecordKeySchema = l.custom(\n l.isLexiconRecordKey,\n 'Invalid record key definition (must be \"any\", \"nsid\", \"tid\", or \"literal:<string>\")',\n)\n\nexport type LexiconRecordKey = l.LexiconRecordKey\n\nexport const lexiconRecordSchema = l.object({\n type: l.literal('record'),\n record: lexiconObjectSchema,\n description: strOpt,\n key: lexiconRecordKeySchema,\n})\nexport type LexiconRecord = l.Infer<typeof lexiconRecordSchema>\n\n// XRPC Methods\n\nexport const lexiconParameters = l.refine(\n l.object({\n type: l.literal('params'),\n properties: l.dict(\n str,\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: intOpt,\n maxLength: intOpt,\n description: strOpt,\n }),\n ]),\n ),\n required: strArrOpt,\n description: strOpt,\n }),\n requirePropertiesRefinement,\n)\nexport type LexiconParameters = l.Infer<typeof lexiconParameters>\n\nexport const lexiconPayload = l.object({\n encoding: str,\n schema: l.optional(\n l.discriminatedUnion('type', [\n lexiconRefSchema,\n lexiconRefUnionSchema,\n lexiconObjectSchema,\n ]),\n ),\n description: strOpt,\n})\nexport type LexiconPayload = l.Infer<typeof lexiconPayload>\n\nexport const lexiconError = l.object({\n name: l.string({ minLength: 1 }),\n description: strOpt,\n})\nexport type LexiconError = l.Infer<typeof lexiconError>\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: strOpt,\n})\nexport type LexiconQuery = l.Infer<typeof lexiconQuerySchema>\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: strOpt,\n})\nexport type LexiconProcedure = l.Infer<typeof lexiconProcedureSchema>\n\nexport const lexiconSubscriptionSchema = l.object({\n type: l.literal('subscription'),\n description: strOpt,\n parameters: l.optional(lexiconParameters),\n message: l.object({\n description: strOpt,\n schema: lexiconRefUnionSchema,\n }),\n errors: l.optional(l.array(lexiconError)),\n})\n\nexport type LexiconSubscription = l.Infer<typeof lexiconSubscriptionSchema>\n\n// Permissions\n\nconst lexiconLanguageSchema = l.string({ format: 'language' })\n\nexport type LexiconLanguage = l.Infer<typeof lexiconLanguageSchema>\n\nconst lexiconLanguageDict = l.dict(lexiconLanguageSchema, str)\n\nexport type LexiconLanguageDict = l.Infer<typeof lexiconLanguageDict>\n\nconst lexiconPermissionSchema = l.intersection(\n l.object({\n type: l.literal('permission'),\n resource: l.string({ minLength: 1 }),\n }),\n l.paramsSchema,\n)\n\nexport type LexiconPermission = l.Infer<typeof lexiconPermissionSchema>\n\nconst lexiconPermissionSetSchema = l.object({\n type: l.literal('permission-set'),\n permissions: l.array(lexiconPermissionSchema),\n title: strOpt,\n 'title:lang': l.optional(lexiconLanguageDict),\n detail: strOpt,\n 'detail:lang': l.optional(lexiconLanguageDict),\n description: strOpt,\n})\n\nexport type LexiconPermissionSet = l.Infer<typeof lexiconPermissionSetSchema>\n\n// Schemas that can appear anywhere in the defs\nconst NAMED_LEXICON_SCHEMAS = [\n ...CONCRETE_TYPES,\n lexiconArraySchema,\n lexiconObjectSchema,\n lexiconTokenSchema,\n] as const\n\nexport type NamedLexiconDefinition = l.Infer<\n (typeof NAMED_LEXICON_SCHEMAS)[number]\n>\n\n// Schemas that can only appear as \"main\" def\nconst MAIN_LEXICON_SCHEMAS = [\n lexiconPermissionSetSchema,\n lexiconProcedureSchema,\n lexiconQuerySchema,\n lexiconRecordSchema,\n lexiconSubscriptionSchema,\n ...NAMED_LEXICON_SCHEMAS,\n] as const\n\nexport type MainLexiconDefinition = l.Infer<\n (typeof MAIN_LEXICON_SCHEMAS)[number]\n>\n\nexport const lexiconIdentifierSchema = l.string({ format: 'nsid' })\nexport type LexiconIdentifier = l.Infer<typeof lexiconIdentifierSchema>\n\nexport const lexiconDocumentSchema = l.object({\n lexicon: l.literal(1),\n id: lexiconIdentifierSchema,\n revision: intOpt,\n description: strOpt,\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})\nexport type LexiconDocument = l.Infer<typeof lexiconDocumentSchema>\n"]}
|
|
1
|
+
{"version":3,"file":"lexicon-document.js","sourceRoot":"","sources":["../src/lexicon-document.ts"],"names":[],"mappings":";;;AAAA,oDAAuC;AAEvC,oCAAoC;AAEpC,mBAAmB;AAEN,QAAA,oBAAoB,GAAG,cAAC,CAAC,MAAM,CAAC;IAC3C,IAAI,EAAE,cA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AC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AAGtD,QAAA,qBAAqB,GAAG,cAAC,CAAC,MAAM,CAAC;IAC5C,OAAO,EAAE,cAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACrB,EAAE,EAAE,+BAAuB;IAC3B,QAAQ,EAAE,cAAC,CAAC,QAAQ,CAAC,cAAC,CAAC,OAAO,EAAE,CAAC;IACjC,WAAW,EAAE,cAAC,CAAC,QAAQ,CAAC,cAAC,CAAC,MAAM,EAAE,CAAC;IACnC,IAAI,EAAE,cAAC,CAAC,YAAY,CAClB,cAAC,CAAC,MAAM,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\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})\nexport type LexiconBoolean = l.Infer<typeof lexiconBooleanSchema>\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})\nexport type LexiconInteger = l.Infer<typeof lexiconIntegerSchema>\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})\nexport type LexiconString = l.Infer<typeof lexiconStringSchema>\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})\nexport type LexiconBytes = l.Infer<typeof lexiconBytesSchema>\n\nexport const lexiconCidLinkSchema = l.object({\n type: l.literal('cid-link'),\n description: l.optional(l.string()),\n})\nexport type LexiconCid = l.Infer<typeof lexiconCidLinkSchema>\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})\nexport type LexiconBlob = l.Infer<typeof lexiconBlobSchema>\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\nexport const lexiconUnknownSchema = l.object({\n type: l.literal('unknown'),\n description: l.optional(l.string()),\n})\nexport type LexiconUnknown = l.Infer<typeof lexiconUnknownSchema>\n\nexport const lexiconTokenSchema = l.object({\n type: l.literal('token'),\n description: l.optional(l.string()),\n})\nexport type LexiconToken = l.Infer<typeof lexiconTokenSchema>\n\nexport const lexiconRefSchema = l.object({\n type: l.literal('ref'),\n ref: l.string(),\n description: l.optional(l.string()),\n})\nexport type LexiconRef = l.Infer<typeof lexiconRefSchema>\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})\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\nexport type LexiconArrayItems = l.Infer<(typeof ARRAY_ITEMS_SCHEMAS)[number]>\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})\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\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)\nexport type LexiconObject = l.Infer<typeof lexiconObjectSchema>\n\n// Records\n\nexport const lexiconRecordKeySchema = l.custom(\n l.isLexiconRecordKey,\n 'Invalid record key definition (must be \"any\", \"nsid\", \"tid\", or \"literal:<string>\")',\n)\n\nexport type LexiconRecordKey = l.LexiconRecordKey\n\nexport const lexiconRecordSchema = l.object({\n type: l.literal('record'),\n record: lexiconObjectSchema,\n description: l.optional(l.string()),\n key: lexiconRecordKeySchema,\n})\nexport type LexiconRecord = l.Infer<typeof lexiconRecordSchema>\n\n// XRPC Methods\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)\nexport type LexiconParameters = l.Infer<typeof lexiconParameters>\n\nexport const lexiconPayload = l.object({\n encoding: l.string(),\n schema: l.optional(\n l.discriminatedUnion('type', [\n lexiconRefSchema,\n lexiconRefUnionSchema,\n lexiconObjectSchema,\n ]),\n ),\n description: l.optional(l.string()),\n})\nexport type LexiconPayload = l.Infer<typeof lexiconPayload>\n\nexport const lexiconError = l.object({\n name: l.string({ minLength: 1 }),\n description: l.optional(l.string()),\n})\nexport type LexiconError = l.Infer<typeof lexiconError>\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})\nexport type LexiconQuery = l.Infer<typeof lexiconQuerySchema>\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})\nexport type LexiconProcedure = l.Infer<typeof lexiconProcedureSchema>\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\nexport type LexiconSubscription = l.Infer<typeof lexiconSubscriptionSchema>\n\n// Permissions\n\nconst lexiconLanguageSchema = l.string({ format: 'language' })\n\nexport type LexiconLanguage = l.Infer<typeof lexiconLanguageSchema>\n\nconst lexiconLanguageDict = l.dict(lexiconLanguageSchema, l.string())\n\nexport type LexiconLanguageDict = l.Infer<typeof lexiconLanguageDict>\n\nconst 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\nexport type LexiconPermission = l.Infer<typeof lexiconPermissionSchema>\n\nconst 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\nexport type LexiconPermissionSet = l.Infer<typeof lexiconPermissionSetSchema>\n\n// Schemas that can appear anywhere in the defs\nconst NAMED_LEXICON_SCHEMAS = [\n ...CONCRETE_TYPES,\n lexiconArraySchema,\n lexiconObjectSchema,\n lexiconTokenSchema,\n] as const\n\nexport type NamedLexiconDefinition = l.Infer<\n (typeof NAMED_LEXICON_SCHEMAS)[number]\n>\n\n// Schemas that can only appear as \"main\" def\nconst MAIN_LEXICON_SCHEMAS = [\n lexiconPermissionSetSchema,\n lexiconProcedureSchema,\n lexiconQuerySchema,\n lexiconRecordSchema,\n lexiconSubscriptionSchema,\n ...NAMED_LEXICON_SCHEMAS,\n] as const\n\nexport type MainLexiconDefinition = l.Infer<\n (typeof MAIN_LEXICON_SCHEMAS)[number]\n>\n\nexport const lexiconIdentifierSchema = l.string({ format: 'nsid' })\nexport type LexiconIdentifier = l.Infer<typeof lexiconIdentifierSchema>\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})\nexport type LexiconDocument = l.Infer<typeof lexiconDocumentSchema>\n"]}
|
|
@@ -18,31 +18,23 @@ export declare class LexiconSchemaBuilder {
|
|
|
18
18
|
#private;
|
|
19
19
|
protected indexer: LexiconIndexer;
|
|
20
20
|
static build(indexer: LexiconIndexer, fullRef: string): Promise<l.Validator<unknown>>;
|
|
21
|
-
static buildAll(indexer: LexiconIndexer): Promise<Map<string, l.Validator<unknown> | l.Query<`${string}.${string}.${string}`, l.ParamsSchema<l.ParamsSchemaShape>, l.Payload<string | undefined, l.Schema<
|
|
21
|
+
static buildAll(indexer: LexiconIndexer): Promise<Map<string, l.Validator<unknown, unknown> | l.Query<`${string}.${string}.${string}`, l.ParamsSchema<l.ParamsSchemaShape>, l.Payload<string | undefined, l.Schema<unknown, unknown, l.SchemaInternals<unknown, unknown>> | undefined>, readonly string[] | undefined> | l.Subscription<`${string}.${string}.${string}`, l.ParamsSchema<l.ParamsSchemaShape>, l.Schema<unknown, unknown, l.SchemaInternals<unknown, unknown>>, readonly string[] | undefined> | l.Procedure<`${string}.${string}.${string}`, l.ParamsSchema<l.ParamsSchemaShape>, l.Payload<string | undefined, l.Schema<unknown, unknown, l.SchemaInternals<unknown, unknown>> | undefined>, l.Payload<string | undefined, l.Schema<unknown, unknown, l.SchemaInternals<unknown, unknown>> | undefined>, readonly string[] | undefined> | l.PermissionSet<any, any>>>;
|
|
22
22
|
constructor(indexer: LexiconIndexer);
|
|
23
23
|
done(): Promise<void>;
|
|
24
|
-
buildFullRef: (fullRef: string) => Promise<l.Validator<unknown> | l.PermissionSet<`${string}.${string}.${string}`, l.Permission<string, {
|
|
24
|
+
buildFullRef: (fullRef: string) => Promise<l.Validator<unknown, unknown> | l.PermissionSet<`${string}.${string}.${string}`, l.Permission<string, {
|
|
25
25
|
[x: string]: string | number | boolean | (string | number | boolean)[];
|
|
26
|
-
}>[]> | l.Procedure<`${string}.${string}.${string}`, l.ParamsSchema<{}>, l.Payload<string | undefined, l.Schema<
|
|
27
|
-
[x: string]: any;
|
|
28
|
-
}>[], boolean>, string[]>>;
|
|
26
|
+
}>[]> | l.Procedure<`${string}.${string}.${string}`, l.ParamsSchema<{}>, l.Payload<string | undefined, l.Schema<unknown, unknown, l.SchemaInternals<unknown, unknown>> | undefined>, l.Payload<string | undefined, l.Schema<unknown, unknown, l.SchemaInternals<unknown, unknown>> | undefined>, string[]> | l.Query<`${string}.${string}.${string}`, l.ParamsSchema<{}>, l.Payload<string | undefined, l.Schema<unknown, unknown, l.SchemaInternals<unknown, unknown>> | undefined>, string[]> | l.Subscription<`${string}.${string}.${string}`, l.ParamsSchema<{}>, l.ObjectSchema<any> | l.RefSchema<l.Validator<unknown, unknown>> | l.TypedUnionSchema<l.TypedRefSchema<l.TypedObjectSchema<`${string}.${string}.${string}` | `${string}.${string}.${string}#${string}`, any> | l.RecordSchema<any, any, any>>[], boolean>, string[]>>;
|
|
29
27
|
protected buildRefGetter(fullRef: string): () => l.Validator<unknown>;
|
|
30
28
|
protected buildTypedRefGetter(fullRef: string): () => l.TypedObjectSchema | l.RecordSchema;
|
|
31
|
-
protected compileDef(doc: LexiconDocument, hash: string): l.Validator<unknown> | l.PermissionSet<`${string}.${string}.${string}`, l.Permission<string, {
|
|
29
|
+
protected compileDef(doc: LexiconDocument, hash: string): l.Validator<unknown, unknown> | l.PermissionSet<`${string}.${string}.${string}`, l.Permission<string, {
|
|
32
30
|
[x: string]: string | number | boolean | (string | number | boolean)[];
|
|
33
|
-
}>[]> | l.Procedure<`${string}.${string}.${string}`, l.ParamsSchema<{}>, l.Payload<string | undefined, l.Schema<
|
|
34
|
-
[x: string]: any;
|
|
35
|
-
}>[], boolean>, string[]>;
|
|
31
|
+
}>[]> | l.Procedure<`${string}.${string}.${string}`, l.ParamsSchema<{}>, l.Payload<string | undefined, l.Schema<unknown, unknown, l.SchemaInternals<unknown, unknown>> | undefined>, l.Payload<string | undefined, l.Schema<unknown, unknown, l.SchemaInternals<unknown, unknown>> | undefined>, string[]> | l.Query<`${string}.${string}.${string}`, l.ParamsSchema<{}>, l.Payload<string | undefined, l.Schema<unknown, unknown, l.SchemaInternals<unknown, unknown>> | undefined>, string[]> | l.Subscription<`${string}.${string}.${string}`, l.ParamsSchema<{}>, l.ObjectSchema<any> | l.RefSchema<l.Validator<unknown, unknown>> | l.TypedUnionSchema<l.TypedRefSchema<l.TypedObjectSchema<`${string}.${string}.${string}` | `${string}.${string}.${string}#${string}`, any> | l.RecordSchema<any, any, any>>[], boolean>, string[]>;
|
|
36
32
|
protected compileLeaf(doc: LexiconDocument, def: LexiconArray | LexiconArrayItems): l.Validator<unknown>;
|
|
37
|
-
protected compileRef(doc: LexiconDocument, def: LexiconRef | LexiconRefUnion): l.RefSchema<unknown
|
|
38
|
-
[x: string]: any;
|
|
39
|
-
}>[], boolean>;
|
|
33
|
+
protected compileRef(doc: LexiconDocument, def: LexiconRef | LexiconRefUnion): l.RefSchema<l.Validator<unknown, unknown>> | l.TypedUnionSchema<l.TypedRefSchema<l.TypedObjectSchema<`${string}.${string}.${string}` | `${string}.${string}.${string}#${string}`, any> | l.RecordSchema<any, any, any>>[], boolean>;
|
|
40
34
|
protected compileObject(doc: LexiconDocument, def: LexiconObject): l.ObjectSchema;
|
|
41
35
|
protected compilePayload(doc: LexiconDocument, def: LexiconPayload | undefined): l.Payload;
|
|
42
36
|
protected compileErrors(_doc: LexiconDocument, errors?: readonly LexiconError[]): undefined | string[];
|
|
43
|
-
protected compilePayloadSchema(doc: LexiconDocument, def: LexiconObject | LexiconRef | LexiconRefUnion): l.ObjectSchema<any> | l.RefSchema<unknown
|
|
44
|
-
[x: string]: any;
|
|
45
|
-
}>[], boolean>;
|
|
37
|
+
protected compilePayloadSchema(doc: LexiconDocument, def: LexiconObject | LexiconRef | LexiconRefUnion): l.ObjectSchema<any> | l.RefSchema<l.Validator<unknown, unknown>> | l.TypedUnionSchema<l.TypedRefSchema<l.TypedObjectSchema<`${string}.${string}.${string}` | `${string}.${string}.${string}#${string}`, any> | l.RecordSchema<any, any, any>>[], boolean>;
|
|
46
38
|
protected compileParams(doc: LexiconDocument, def?: LexiconParameters): l.ParamsSchema<{}>;
|
|
47
39
|
}
|
|
48
40
|
export declare function memoize<Fn extends (arg: string) => unknown>(fn: Fn): Fn;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-schema-builder.d.ts","sourceRoot":"","sources":["../src/lexicon-schema-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AACvC,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,eAAe,EAChB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAErD;;;;;;;;;;;;GAYG;AACH,qBAAa,oBAAoB;;IA8CnB,SAAS,CAAC,OAAO,EAAE,cAAc;WA7ChC,KAAK,CAChB,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;WAanB,QAAQ,CAAC,OAAO,EAAE,cAAc;gBA6BvB,OAAO,EAAE,cAAc;IAEvC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,YAAY,YAA2B,MAAM
|
|
1
|
+
{"version":3,"file":"lexicon-schema-builder.d.ts","sourceRoot":"","sources":["../src/lexicon-schema-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AACvC,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,eAAe,EAChB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAErD;;;;;;;;;;;;GAYG;A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AAa,GAAG,UAAU,GAAG,eAAe;IAUnD,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,CAAC,EAAE,iBAAiB;CAgBtE;AA6CD,wBAAgB,OAAO,CAAC,EAAE,SAAS,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,CAQvE"}
|
|
@@ -136,13 +136,11 @@ class LexiconSchemaBuilder {
|
|
|
136
136
|
for (const v of def.enum)
|
|
137
137
|
schema.check(v);
|
|
138
138
|
const result = def.const != null
|
|
139
|
-
? lex_schema_1.l.literal(def.const
|
|
139
|
+
? lex_schema_1.l.literal(def.const)
|
|
140
140
|
: def.enum != null
|
|
141
|
-
? lex_schema_1.l.enum(def.enum
|
|
141
|
+
? lex_schema_1.l.enum(def.enum)
|
|
142
142
|
: schema;
|
|
143
|
-
|
|
144
|
-
result.check(def.default);
|
|
145
|
-
return result;
|
|
143
|
+
return def.default != null ? lex_schema_1.l.withDefault(result, def.default) : result;
|
|
146
144
|
}
|
|
147
145
|
case 'integer': {
|
|
148
146
|
const schema = lex_schema_1.l.integer(def);
|
|
@@ -154,24 +152,20 @@ class LexiconSchemaBuilder {
|
|
|
154
152
|
for (const v of def.enum)
|
|
155
153
|
schema.check(v);
|
|
156
154
|
const result = def.const != null
|
|
157
|
-
? lex_schema_1.l.literal(def.const
|
|
155
|
+
? lex_schema_1.l.literal(def.const)
|
|
158
156
|
: def.enum != null
|
|
159
|
-
? lex_schema_1.l.enum(def.enum
|
|
157
|
+
? lex_schema_1.l.enum(def.enum)
|
|
160
158
|
: schema;
|
|
161
|
-
|
|
162
|
-
result.check(def.default);
|
|
163
|
-
return result;
|
|
159
|
+
return def.default != null ? lex_schema_1.l.withDefault(result, def.default) : result;
|
|
164
160
|
}
|
|
165
161
|
case 'boolean': {
|
|
166
|
-
const result = def.const != null ? lex_schema_1.l.literal(def.const
|
|
167
|
-
|
|
168
|
-
result.check(def.default);
|
|
169
|
-
return result;
|
|
162
|
+
const result = def.const != null ? lex_schema_1.l.literal(def.const) : lex_schema_1.l.boolean();
|
|
163
|
+
return def.default != null ? lex_schema_1.l.withDefault(result, def.default) : result;
|
|
170
164
|
}
|
|
171
165
|
case 'blob':
|
|
172
166
|
return lex_schema_1.l.blob(def);
|
|
173
167
|
case 'cid-link':
|
|
174
|
-
return lex_schema_1.l.
|
|
168
|
+
return lex_schema_1.l.cid();
|
|
175
169
|
case 'bytes':
|
|
176
170
|
return lex_schema_1.l.bytes(def);
|
|
177
171
|
case 'unknown':
|
|
@@ -228,18 +222,15 @@ class LexiconSchemaBuilder {
|
|
|
228
222
|
compileParams(doc, def) {
|
|
229
223
|
if (!def)
|
|
230
224
|
return lex_schema_1.l.params();
|
|
231
|
-
const
|
|
232
|
-
for (const [
|
|
233
|
-
if (
|
|
225
|
+
const shape = {};
|
|
226
|
+
for (const [paramName, paramDef] of Object.entries(def.properties)) {
|
|
227
|
+
if (paramDef === undefined)
|
|
234
228
|
continue;
|
|
235
|
-
const isRequired = def.required?.includes(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
schema = lex_schema_1.l.optional(schema);
|
|
239
|
-
}
|
|
240
|
-
props[key] = schema;
|
|
229
|
+
const isRequired = def.required?.includes(paramName);
|
|
230
|
+
const propSchema = this.compileLeaf(doc, paramDef);
|
|
231
|
+
shape[paramName] = isRequired ? propSchema : lex_schema_1.l.optional(propSchema);
|
|
241
232
|
}
|
|
242
|
-
return lex_schema_1.l.params(
|
|
233
|
+
return lex_schema_1.l.params(shape);
|
|
243
234
|
}
|
|
244
235
|
}
|
|
245
236
|
exports.LexiconSchemaBuilder = LexiconSchemaBuilder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-schema-builder.js","sourceRoot":"","sources":["../src/lexicon-schema-builder.ts"],"names":[],"mappings":";;;AAiYA,0BAQC;AAzYD,oDAAuC;AAcvC;;;;;;;;;;;;GAYG;AACH,MAAa,oBAAoB;IA8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C1C,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 { 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 a validator for a given lexicon \"ref\" from a lexicon indexer.\n *\n * @example\n *\n * ```ts\n * import { LexiconSchemaBuilder } from '@atproto/lex/doc'\n * import { LexiconStreamIndexer } from '@atproto/lex/doc'\n *\n * const indexer = new LexiconStreamIndexer(lexiconDocs)\n * const validator = await LexiconSchemaBuilder.build(indexer, 'com.example.foo#bar')\n * ```\n */\nexport class LexiconSchemaBuilder {\n static async build(\n indexer: LexiconIndexer,\n fullRef: string,\n ): Promise<l.Validator<unknown>> {\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 static async buildAll(indexer: LexiconIndexer) {\n const builder = new LexiconSchemaBuilder(indexer)\n const schemas = new Map<\n string,\n | l.Validator<unknown>\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 constructor(protected indexer: LexiconIndexer) {}\n\n async done(): Promise<void> {\n await this.#asyncTasks.done()\n }\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.Validator<unknown> {\n let validator: l.Validator<unknown>\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 validator = v\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 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.Validator<unknown> {\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, def)\n : def.enum != null\n ? l.enum(def.enum, def)\n : schema\n\n if (def.default != null) result.check(def.default)\n return 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, def)\n : def.enum != null\n ? l.enum(def.enum, def)\n : schema\n\n if (def.default != null) result.check(def.default)\n return result\n }\n case 'boolean': {\n const result =\n def.const != null ? l.literal(def.const, def) : l.boolean(def)\n\n if (def.default != null) result.check(def.default)\n return result\n }\n case 'blob':\n return l.blob(def)\n case 'cid-link':\n return l.cidLink()\n case 'bytes':\n return l.bytes(def)\n case 'unknown':\n return l.unknown()\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 ) {\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(\n doc: LexiconDocument,\n def: LexiconObject,\n ): l.ObjectSchema {\n const props: Record<string, l.Validator> = {}\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 = this.compileLeaf(doc, propDef)\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 ): l.Payload {\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 ) {\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 props: Record<string, l.Validator> = {}\n for (const [key, propDef] of Object.entries(def.properties)) {\n if (propDef === undefined) continue\n\n const isRequired = def.required?.includes(key)\n\n let schema = this.compileLeaf(doc, propDef)\n\n if (!isRequired) {\n schema = l.optional(schema)\n }\n\n props[key] = schema\n }\n return l.params(props)\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":";;;AA0XA,0BAQC;AAlYD,oDAAuC;AAcvC;;;;;;;;;;;;GAYG;AACH,MAAa,oBAAoB;IA8CT;IA7CtB,MAAM,CAAC,KAAK,CAAC,KAAK,CAChB,OAAuB,EACvB,OAAe;QAEf,MAAM,GAAG,GAAG,IAAI,oBAAoB,CAAC,OA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AC,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 { 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 a validator for a given lexicon \"ref\" from a lexicon indexer.\n *\n * @example\n *\n * ```ts\n * import { LexiconSchemaBuilder } from '@atproto/lex/doc'\n * import { LexiconStreamIndexer } from '@atproto/lex/doc'\n *\n * const indexer = new LexiconStreamIndexer(lexiconDocs)\n * const validator = await LexiconSchemaBuilder.build(indexer, 'com.example.foo#bar')\n * ```\n */\nexport class LexiconSchemaBuilder {\n static async build(\n indexer: LexiconIndexer,\n fullRef: string,\n ): Promise<l.Validator<unknown>> {\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 static async buildAll(indexer: LexiconIndexer) {\n const builder = new LexiconSchemaBuilder(indexer)\n const schemas = new Map<\n string,\n | l.Validator<unknown>\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 constructor(protected indexer: LexiconIndexer) {}\n\n async done(): Promise<void> {\n await this.#asyncTasks.done()\n }\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.Validator<unknown> {\n let validator: l.Validator<unknown>\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 validator = v\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 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.Validator<unknown> {\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.unknown()\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 ) {\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(\n doc: LexiconDocument,\n def: LexiconObject,\n ): l.ObjectSchema {\n const props: Record<string, l.Validator> = {}\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 = this.compileLeaf(doc, propDef)\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 ): l.Payload {\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 ) {\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.ParamsSchemaShape = {}\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 l.Validator<l.Param>\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"]}
|