@atcute/lex-cli 1.1.2 → 2.0.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/cli.mjs +1 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +77 -0
- package/dist/cli.js.map +1 -0
- package/dist/codegen.d.ts +23 -0
- package/dist/codegen.js +552 -0
- package/dist/codegen.js.map +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +3 -125
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +816 -1944
- package/dist/schema.js +152 -93
- package/dist/schema.js.map +1 -1
- package/package.json +9 -5
- package/src/cli.ts +100 -0
- package/src/codegen.ts +726 -0
- package/src/index.ts +9 -150
- package/src/schema.ts +391 -150
- package/dist/generator.d.ts +0 -7
- package/dist/generator.js +0 -579
- package/dist/generator.js.map +0 -1
- package/src/generator.ts +0 -664
package/src/schema.ts
CHANGED
|
@@ -1,290 +1,531 @@
|
|
|
1
1
|
import * as v from '@badrap/valita';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// tsc dislikes this schema with the amount of type expansion that happens here.
|
|
4
|
+
// the interface declaration allows tsc to just reference it instead of
|
|
5
|
+
// expanding on every type reference.
|
|
6
|
+
|
|
7
|
+
const _integer = v
|
|
4
8
|
.number()
|
|
5
|
-
.assert((
|
|
9
|
+
.assert((input) => input >= 0 && Number.isSafeInteger(input), `expected non-negative integer`);
|
|
10
|
+
|
|
11
|
+
const integer = _integer as integer.$schema;
|
|
12
|
+
declare namespace integer {
|
|
13
|
+
export {};
|
|
6
14
|
|
|
7
|
-
|
|
15
|
+
type $schematype = typeof _integer;
|
|
16
|
+
export interface $schema extends $schematype {}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const _lexBoolean = v.object({
|
|
8
20
|
type: v.literal('boolean'),
|
|
9
21
|
description: v.string().optional(),
|
|
10
22
|
default: v.boolean().optional(),
|
|
11
23
|
const: v.boolean().optional(),
|
|
12
24
|
});
|
|
13
25
|
|
|
14
|
-
export
|
|
26
|
+
export const lexBoolean = _lexBoolean as lexBoolean.$schema;
|
|
27
|
+
export interface LexBoolean extends v.Infer<typeof lexBoolean> {}
|
|
28
|
+
export declare namespace lexBoolean {
|
|
29
|
+
export {};
|
|
30
|
+
|
|
31
|
+
type $schematype = typeof _lexBoolean;
|
|
32
|
+
export interface $schema extends $schematype {}
|
|
33
|
+
}
|
|
15
34
|
|
|
16
|
-
|
|
35
|
+
const _lexInteger = v.object({
|
|
17
36
|
type: v.literal('integer'),
|
|
18
37
|
description: v.string().optional(),
|
|
19
|
-
default:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
default: integer.optional(),
|
|
39
|
+
minimum: integer.optional(),
|
|
40
|
+
maximum: integer.optional(),
|
|
41
|
+
enum: v.array(integer).optional(),
|
|
42
|
+
const: integer.optional(),
|
|
24
43
|
});
|
|
25
44
|
|
|
26
|
-
export
|
|
45
|
+
export const lexInteger = _lexInteger as lexInteger.$schema;
|
|
46
|
+
export interface LexInteger extends v.Infer<typeof lexInteger> {}
|
|
47
|
+
export declare namespace lexInteger {
|
|
48
|
+
export {};
|
|
49
|
+
|
|
50
|
+
type $schematype = typeof _lexInteger;
|
|
51
|
+
export interface $schema extends $schematype {}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const _lexStringFormat = v.union(
|
|
55
|
+
v.literal('datetime'),
|
|
56
|
+
v.literal('uri'),
|
|
57
|
+
v.literal('at-uri'),
|
|
58
|
+
v.literal('did'),
|
|
59
|
+
v.literal('handle'),
|
|
60
|
+
v.literal('at-identifier'),
|
|
61
|
+
v.literal('nsid'),
|
|
62
|
+
v.literal('cid'),
|
|
63
|
+
v.literal('language'),
|
|
64
|
+
v.literal('tid'),
|
|
65
|
+
v.literal('record-key'),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
export const lexStringFormat = _lexStringFormat as lexStringFormat.$schema;
|
|
69
|
+
export type LexStringFormat = v.Infer<typeof lexStringFormat>;
|
|
70
|
+
export declare namespace lexStringFormat {
|
|
71
|
+
export {};
|
|
72
|
+
|
|
73
|
+
type $schematype = typeof _lexStringFormat;
|
|
74
|
+
export interface $schema extends $schematype {}
|
|
75
|
+
}
|
|
27
76
|
|
|
28
|
-
|
|
77
|
+
const _lexString = v.object({
|
|
29
78
|
type: v.literal('string'),
|
|
79
|
+
format: lexStringFormat.optional(),
|
|
30
80
|
description: v.string().optional(),
|
|
31
|
-
format: v
|
|
32
|
-
.union(
|
|
33
|
-
v.literal('at-identifier'),
|
|
34
|
-
v.literal('at-uri'),
|
|
35
|
-
v.literal('cid'),
|
|
36
|
-
v.literal('datetime'),
|
|
37
|
-
v.literal('did'),
|
|
38
|
-
v.literal('handle'),
|
|
39
|
-
v.literal('language'),
|
|
40
|
-
v.literal('nsid'),
|
|
41
|
-
v.literal('record-key'),
|
|
42
|
-
v.literal('tid'),
|
|
43
|
-
v.literal('uri'),
|
|
44
|
-
)
|
|
45
|
-
.optional(),
|
|
46
81
|
default: v.string().optional(),
|
|
47
|
-
|
|
82
|
+
minLength: integer.optional(),
|
|
83
|
+
maxLength: integer.optional(),
|
|
84
|
+
minGraphemes: integer.optional(),
|
|
85
|
+
maxGraphemes: integer.optional(),
|
|
48
86
|
enum: v.array(v.string()).optional(),
|
|
87
|
+
const: v.string().optional(),
|
|
49
88
|
knownValues: v.array(v.string()).optional(),
|
|
50
|
-
maxLength: integerType.optional(),
|
|
51
|
-
minLength: integerType.optional(),
|
|
52
|
-
maxGraphemes: integerType.optional(),
|
|
53
|
-
minGraphemes: integerType.optional(),
|
|
54
89
|
});
|
|
55
90
|
|
|
56
|
-
export
|
|
91
|
+
export const lexString = _lexString as lexString.$schema;
|
|
92
|
+
export interface LexString extends v.Infer<typeof lexString> {}
|
|
93
|
+
export declare namespace lexString {
|
|
94
|
+
export {};
|
|
95
|
+
|
|
96
|
+
type $schematype = typeof _lexString;
|
|
97
|
+
export interface $schema extends $schematype {}
|
|
98
|
+
}
|
|
57
99
|
|
|
58
|
-
|
|
100
|
+
const _lexUnknown = v.object({
|
|
59
101
|
type: v.literal('unknown'),
|
|
60
102
|
description: v.string().optional(),
|
|
61
103
|
});
|
|
62
104
|
|
|
63
|
-
export
|
|
105
|
+
export const lexUnknown = _lexUnknown as lexUnknown.$schema;
|
|
106
|
+
export interface LexUnknown extends v.Infer<typeof lexUnknown> {}
|
|
107
|
+
export declare namespace lexUnknown {
|
|
108
|
+
export {};
|
|
64
109
|
|
|
65
|
-
|
|
110
|
+
type $schematype = typeof _lexUnknown;
|
|
111
|
+
export interface $schema extends $schematype {}
|
|
112
|
+
}
|
|
66
113
|
|
|
67
|
-
|
|
114
|
+
const _lexPrimitive = v.union(lexBoolean, lexInteger, lexString, lexUnknown);
|
|
68
115
|
|
|
69
|
-
export const
|
|
116
|
+
export const lexPrimitive = _lexPrimitive as lexPrimitive.$schema;
|
|
117
|
+
export type LexPrimitive = v.Infer<typeof lexPrimitive>;
|
|
118
|
+
export declare namespace lexPrimitive {
|
|
119
|
+
export {};
|
|
120
|
+
|
|
121
|
+
type $schematype = typeof _lexPrimitive;
|
|
122
|
+
export interface $schema extends $schematype {}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const _lexBytes = v.object({
|
|
70
126
|
type: v.literal('bytes'),
|
|
71
127
|
description: v.string().optional(),
|
|
72
|
-
|
|
73
|
-
|
|
128
|
+
minLength: integer.optional(),
|
|
129
|
+
maxLength: integer.optional(),
|
|
74
130
|
});
|
|
75
131
|
|
|
76
|
-
export
|
|
132
|
+
export const lexBytes = _lexBytes as lexBytes.$schema;
|
|
133
|
+
export interface LexBytes extends v.Infer<typeof lexBytes> {}
|
|
134
|
+
export declare namespace lexBytes {
|
|
135
|
+
export {};
|
|
77
136
|
|
|
78
|
-
|
|
137
|
+
type $schematype = typeof _lexBytes;
|
|
138
|
+
export interface $schema extends $schematype {}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const _lexCidLink = v.object({
|
|
79
142
|
type: v.literal('cid-link'),
|
|
80
143
|
description: v.string().optional(),
|
|
81
144
|
});
|
|
82
145
|
|
|
83
|
-
export
|
|
146
|
+
export const lexCidLink = _lexCidLink as lexCidLink.$schema;
|
|
147
|
+
export interface LexCidLink extends v.Infer<typeof lexCidLink> {}
|
|
148
|
+
export declare namespace lexCidLink {
|
|
149
|
+
export {};
|
|
150
|
+
|
|
151
|
+
type $schematype = typeof _lexCidLink;
|
|
152
|
+
export interface $schema extends $schematype {}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const _lexIpldType = v.union(lexBytes, lexCidLink);
|
|
156
|
+
|
|
157
|
+
export const lexIpldType = _lexIpldType as lexIpldType.$schema;
|
|
158
|
+
export type LexIpldType = v.Infer<typeof lexIpldType>;
|
|
159
|
+
export declare namespace lexIpldType {
|
|
160
|
+
export {};
|
|
161
|
+
|
|
162
|
+
type $schematype = typeof _lexIpldType;
|
|
163
|
+
export interface $schema extends $schematype {}
|
|
164
|
+
}
|
|
84
165
|
|
|
85
|
-
|
|
166
|
+
const REF_RE =
|
|
167
|
+
/^(?=.)(?:[a-zA-Z](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+\.[a-zA-Z][a-zA-Z0-9]{0,62}?)?(?:#[a-zA-Z][a-zA-Z0-9_]{0,62}?)?$/;
|
|
86
168
|
|
|
87
|
-
|
|
169
|
+
const refString = v.string().assert((input) => REF_RE.test(input));
|
|
88
170
|
|
|
89
|
-
|
|
171
|
+
const _lexRef = v.object({
|
|
90
172
|
type: v.literal('ref'),
|
|
91
173
|
description: v.string().optional(),
|
|
92
|
-
ref:
|
|
174
|
+
ref: refString,
|
|
93
175
|
});
|
|
94
176
|
|
|
95
|
-
export
|
|
177
|
+
export const lexRef = _lexRef as lexRef.$schema;
|
|
178
|
+
export interface LexRef extends v.Infer<typeof lexRef> {}
|
|
179
|
+
export declare namespace lexRef {
|
|
180
|
+
export {};
|
|
96
181
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
.
|
|
182
|
+
type $schematype = typeof _lexRef;
|
|
183
|
+
export interface $schema extends $schematype {}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const _lexRefUnion = v.object({
|
|
187
|
+
type: v.literal('union'),
|
|
188
|
+
description: v.string().optional(),
|
|
189
|
+
refs: v.array(refString),
|
|
190
|
+
closed: v.boolean().optional(() => false),
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
export const lexRefUnion = _lexRefUnion as lexRefUnion.$schema;
|
|
194
|
+
export interface LexRefUnion extends v.Infer<typeof lexRefUnion> {}
|
|
195
|
+
export declare namespace lexRefUnion {
|
|
196
|
+
export {};
|
|
105
197
|
|
|
106
|
-
|
|
198
|
+
type $schematype = typeof _lexRefUnion;
|
|
199
|
+
export interface $schema extends $schematype {}
|
|
200
|
+
}
|
|
107
201
|
|
|
108
|
-
|
|
202
|
+
const _lexRefVariant = v.union(lexRef, lexRefUnion);
|
|
109
203
|
|
|
110
|
-
export
|
|
204
|
+
export const lexRefVariant = _lexRefVariant as lexRefVariant.$schema;
|
|
205
|
+
export type LexRefVariant = v.Infer<typeof lexRefVariant>;
|
|
206
|
+
export declare namespace lexRefVariant {
|
|
207
|
+
export {};
|
|
111
208
|
|
|
112
|
-
|
|
209
|
+
type $schematype = typeof _lexRefVariant;
|
|
210
|
+
export interface $schema extends $schematype {}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const _lexBlob = v.object({
|
|
113
214
|
type: v.literal('blob'),
|
|
114
215
|
description: v.string().optional(),
|
|
115
216
|
accept: v.array(v.string()).optional(),
|
|
116
|
-
maxSize:
|
|
217
|
+
maxSize: integer.optional(),
|
|
117
218
|
});
|
|
118
219
|
|
|
119
|
-
export
|
|
220
|
+
export const lexBlob = _lexBlob as lexBlob.$schema;
|
|
221
|
+
export interface LexBlob extends v.Infer<typeof lexBlob> {}
|
|
222
|
+
export declare namespace lexBlob {
|
|
223
|
+
export {};
|
|
224
|
+
|
|
225
|
+
type $schematype = typeof _lexBlob;
|
|
226
|
+
export interface $schema extends $schematype {}
|
|
227
|
+
}
|
|
120
228
|
|
|
121
|
-
|
|
229
|
+
const _lexArray = v.object({
|
|
122
230
|
type: v.literal('array'),
|
|
123
231
|
description: v.string().optional(),
|
|
124
|
-
items: v.union(
|
|
125
|
-
|
|
126
|
-
|
|
232
|
+
items: v.union(lexPrimitive, lexIpldType, lexRefVariant, lexBlob),
|
|
233
|
+
minLength: integer.optional(),
|
|
234
|
+
maxLength: integer.optional(),
|
|
127
235
|
});
|
|
128
236
|
|
|
129
|
-
export
|
|
237
|
+
export const lexArray = _lexArray as lexArray.$schema;
|
|
238
|
+
export interface LexArray extends v.Infer<typeof lexArray> {}
|
|
239
|
+
export declare namespace lexArray {
|
|
240
|
+
export {};
|
|
130
241
|
|
|
131
|
-
|
|
132
|
-
|
|
242
|
+
type $schematype = typeof _lexArray;
|
|
243
|
+
export interface $schema extends $schematype {}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const _lexPrimitiveArray = lexArray.extend({
|
|
247
|
+
items: lexPrimitive,
|
|
133
248
|
});
|
|
134
249
|
|
|
135
|
-
export
|
|
250
|
+
export const lexPrimitiveArray = _lexPrimitiveArray as lexPrimitiveArray.$schema;
|
|
251
|
+
export interface LexPrimitiveArray extends v.Infer<typeof lexPrimitiveArray> {}
|
|
252
|
+
export declare namespace lexPrimitiveArray {
|
|
253
|
+
export {};
|
|
254
|
+
|
|
255
|
+
type $schematype = typeof _lexPrimitiveArray;
|
|
256
|
+
export interface $schema extends $schematype {}
|
|
257
|
+
}
|
|
136
258
|
|
|
137
|
-
|
|
259
|
+
const _lexToken = v.object({
|
|
138
260
|
type: v.literal('token'),
|
|
139
261
|
description: v.string().optional(),
|
|
140
262
|
});
|
|
141
263
|
|
|
142
|
-
export
|
|
264
|
+
export const lexToken = _lexToken as lexToken.$schema;
|
|
265
|
+
export interface LexToken extends v.Infer<typeof lexToken> {}
|
|
266
|
+
export declare namespace lexToken {
|
|
267
|
+
export {};
|
|
143
268
|
|
|
144
|
-
|
|
145
|
-
|
|
269
|
+
type $schematype = typeof _lexToken;
|
|
270
|
+
export interface $schema extends $schematype {}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const KEY_RE = /^[a-zA-Z][a-zA-Z0-9_]{0,62}?$/;
|
|
274
|
+
|
|
275
|
+
const refineObjectProperties = <T extends { required?: string[]; properties?: Record<string, unknown> }>(
|
|
276
|
+
input: T,
|
|
146
277
|
): v.ValitaResult<T> => {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
278
|
+
const { required = [], properties } = input;
|
|
279
|
+
|
|
280
|
+
for (const key in properties) {
|
|
281
|
+
if (!KEY_RE.test(key)) {
|
|
282
|
+
return v.err({
|
|
283
|
+
message: `invalid property key`,
|
|
284
|
+
path: ['properties', key],
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (required.length > 0) {
|
|
290
|
+
if (properties === undefined) {
|
|
291
|
+
return v.err({
|
|
292
|
+
message: `required fields specified but no properties defined`,
|
|
293
|
+
path: ['properties'],
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
for (const key of required) {
|
|
298
|
+
if (properties[key] === undefined) {
|
|
299
|
+
return v.err({
|
|
300
|
+
message: `required fields not defined`,
|
|
301
|
+
path: ['properties', key],
|
|
302
|
+
});
|
|
303
|
+
}
|
|
150
304
|
}
|
|
151
305
|
}
|
|
152
306
|
|
|
153
|
-
return v.ok(
|
|
307
|
+
return v.ok(input);
|
|
154
308
|
};
|
|
155
309
|
|
|
156
|
-
|
|
310
|
+
const _lexObject = v
|
|
157
311
|
.object({
|
|
158
312
|
type: v.literal('object'),
|
|
159
313
|
description: v.string().optional(),
|
|
160
|
-
required: v.array(v.string()).optional(
|
|
161
|
-
nullable: v.array(v.string()).optional(
|
|
162
|
-
properties: v.record(v.union(
|
|
314
|
+
required: v.array(v.string()).optional(),
|
|
315
|
+
nullable: v.array(v.string()).optional(),
|
|
316
|
+
properties: v.record(v.union(lexArray, lexPrimitive, lexIpldType, lexRefVariant, lexBlob)).optional(),
|
|
163
317
|
})
|
|
164
|
-
.chain(
|
|
318
|
+
.chain(refineObjectProperties);
|
|
319
|
+
|
|
320
|
+
export const lexObject = _lexObject as lexObject.$schema;
|
|
321
|
+
export interface LexObject extends v.Infer<typeof lexObject> {}
|
|
322
|
+
export declare namespace lexObject {
|
|
323
|
+
export {};
|
|
165
324
|
|
|
166
|
-
|
|
325
|
+
type $schematype = typeof _lexObject;
|
|
326
|
+
export interface $schema extends $schematype {}
|
|
327
|
+
}
|
|
167
328
|
|
|
168
|
-
|
|
329
|
+
const _lexXrpcParameters = v
|
|
169
330
|
.object({
|
|
170
331
|
type: v.literal('params'),
|
|
171
332
|
description: v.string().optional(),
|
|
172
|
-
required: v.array(v.string()).optional(
|
|
173
|
-
properties: v.record(v.union(
|
|
333
|
+
required: v.array(v.string()).optional(),
|
|
334
|
+
properties: v.record(v.union(lexPrimitive, lexPrimitiveArray)).optional(),
|
|
174
335
|
})
|
|
175
|
-
.chain(
|
|
336
|
+
.chain(refineObjectProperties);
|
|
337
|
+
|
|
338
|
+
export const lexXrpcParameters = _lexXrpcParameters as lexXrpcParameters.$schema;
|
|
339
|
+
export interface LexXrpcParameters extends v.Infer<typeof lexXrpcParameters> {}
|
|
340
|
+
export declare namespace lexXrpcParameters {
|
|
341
|
+
export {};
|
|
176
342
|
|
|
177
|
-
|
|
343
|
+
type $schematype = typeof _lexXrpcParameters;
|
|
344
|
+
export interface $schema extends $schematype {}
|
|
345
|
+
}
|
|
178
346
|
|
|
179
|
-
|
|
347
|
+
const _lexXrpcBody = v.object({
|
|
180
348
|
description: v.string().optional(),
|
|
181
349
|
encoding: v.string(),
|
|
182
|
-
schema: v.union(
|
|
350
|
+
schema: v.union(lexRefVariant, lexObject).optional(),
|
|
183
351
|
});
|
|
184
352
|
|
|
185
|
-
export
|
|
353
|
+
export const lexXrpcBody = _lexXrpcBody as lexXrpcBody.$schema;
|
|
354
|
+
export interface LexXrpcBody extends v.Infer<typeof lexXrpcBody> {}
|
|
355
|
+
export declare namespace lexXrpcBody {
|
|
356
|
+
export {};
|
|
186
357
|
|
|
187
|
-
|
|
358
|
+
type $schematype = typeof _lexXrpcBody;
|
|
359
|
+
export interface $schema extends $schematype {}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const _lexXrpcSubscriptionMessage = v.object({
|
|
188
363
|
description: v.string().optional(),
|
|
189
|
-
schema: v.union(
|
|
364
|
+
schema: v.union(lexRefVariant, lexObject).optional(),
|
|
190
365
|
});
|
|
191
366
|
|
|
192
|
-
export
|
|
367
|
+
export const lexXrpcSubscriptionMessage = _lexXrpcSubscriptionMessage as lexXrpcSubscriptionMessage.$schema;
|
|
368
|
+
export interface LexXrpcSubscriptionMessage extends v.Infer<typeof lexXrpcSubscriptionMessage> {}
|
|
369
|
+
export declare namespace lexXrpcSubscriptionMessage {
|
|
370
|
+
export {};
|
|
371
|
+
|
|
372
|
+
type $schematype = typeof _lexXrpcSubscriptionMessage;
|
|
373
|
+
export interface $schema extends $schematype {}
|
|
374
|
+
}
|
|
193
375
|
|
|
194
|
-
|
|
376
|
+
const _lexXrpcError = v.object({
|
|
195
377
|
name: v.string(),
|
|
196
378
|
description: v.string().optional(),
|
|
197
379
|
});
|
|
198
380
|
|
|
199
|
-
export
|
|
381
|
+
export const lexXrpcError = _lexXrpcError as lexXrpcError.$schema;
|
|
382
|
+
export interface LexXrpcError extends v.Infer<typeof lexXrpcError> {}
|
|
383
|
+
export declare namespace lexXrpcError {
|
|
384
|
+
export {};
|
|
200
385
|
|
|
201
|
-
|
|
386
|
+
type $schematype = typeof _lexXrpcError;
|
|
387
|
+
export interface $schema extends $schematype {}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const _lexXrpcQuery = v.object({
|
|
202
391
|
type: v.literal('query'),
|
|
203
392
|
description: v.string().optional(),
|
|
204
|
-
parameters:
|
|
205
|
-
output:
|
|
206
|
-
errors: v.array(
|
|
393
|
+
parameters: lexXrpcParameters.optional(),
|
|
394
|
+
output: lexXrpcBody.optional(),
|
|
395
|
+
errors: v.array(lexXrpcError).optional(),
|
|
207
396
|
});
|
|
208
397
|
|
|
209
|
-
export
|
|
398
|
+
export const lexXrpcQuery = _lexXrpcQuery as lexXrpcQuery.$schema;
|
|
399
|
+
export interface LexXrpcQuery extends v.Infer<typeof lexXrpcQuery> {}
|
|
400
|
+
export declare namespace lexXrpcQuery {
|
|
401
|
+
export {};
|
|
402
|
+
|
|
403
|
+
type $schematype = typeof _lexXrpcQuery;
|
|
404
|
+
export interface $schema extends $schematype {}
|
|
405
|
+
}
|
|
210
406
|
|
|
211
|
-
|
|
407
|
+
const _lexXrpcProcedure = v.object({
|
|
212
408
|
type: v.literal('procedure'),
|
|
213
409
|
description: v.string().optional(),
|
|
214
|
-
parameters:
|
|
215
|
-
input:
|
|
216
|
-
output:
|
|
217
|
-
errors: v.array(
|
|
410
|
+
parameters: lexXrpcParameters.optional(),
|
|
411
|
+
input: lexXrpcBody.optional(),
|
|
412
|
+
output: lexXrpcBody.optional(),
|
|
413
|
+
errors: v.array(lexXrpcError).optional(),
|
|
218
414
|
});
|
|
219
415
|
|
|
220
|
-
export
|
|
416
|
+
export const lexXrpcProcedure = _lexXrpcProcedure as lexXrpcProcedure.$schema;
|
|
417
|
+
export interface LexXrpcProcedure extends v.Infer<typeof lexXrpcProcedure> {}
|
|
418
|
+
export declare namespace lexXrpcProcedure {
|
|
419
|
+
export {};
|
|
221
420
|
|
|
222
|
-
|
|
421
|
+
type $schematype = typeof _lexXrpcProcedure;
|
|
422
|
+
export interface $schema extends $schematype {}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const _lexXrpcSubscription = v.object({
|
|
223
426
|
type: v.literal('subscription'),
|
|
224
427
|
description: v.string().optional(),
|
|
225
|
-
parameters:
|
|
226
|
-
message:
|
|
227
|
-
errors: v.array(
|
|
428
|
+
parameters: lexXrpcParameters.optional(),
|
|
429
|
+
message: lexXrpcSubscriptionMessage.optional(),
|
|
430
|
+
errors: v.array(lexXrpcError).optional(),
|
|
228
431
|
});
|
|
229
432
|
|
|
230
|
-
export
|
|
433
|
+
export const lexXrpcSubscription = _lexXrpcSubscription as lexXrpcSubscription.$schema;
|
|
434
|
+
export interface LexXrpcSubscription extends v.Infer<typeof lexXrpcSubscription> {}
|
|
435
|
+
export declare namespace lexXrpcSubscription {
|
|
436
|
+
export {};
|
|
437
|
+
|
|
438
|
+
type $schematype = typeof _lexXrpcSubscription;
|
|
439
|
+
export interface $schema extends $schematype {}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
const LITERAL_KEY_RE = /^literal:(.+)$/;
|
|
231
443
|
|
|
232
|
-
|
|
444
|
+
const _lexRecord = v.object({
|
|
233
445
|
type: v.literal('record'),
|
|
234
446
|
description: v.string().optional(),
|
|
235
|
-
key: v
|
|
236
|
-
|
|
447
|
+
key: v
|
|
448
|
+
.union(
|
|
449
|
+
v.literal('tid'),
|
|
450
|
+
v.literal('nsid'),
|
|
451
|
+
v.literal('any'),
|
|
452
|
+
v.string().assert<`literal:${string}`>((input) => LITERAL_KEY_RE.test(input)),
|
|
453
|
+
)
|
|
454
|
+
.optional(() => 'any'),
|
|
455
|
+
record: lexObject,
|
|
237
456
|
});
|
|
238
457
|
|
|
239
|
-
export
|
|
240
|
-
|
|
241
|
-
export
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
458
|
+
export const lexRecord = _lexRecord as lexRecord.$schema;
|
|
459
|
+
export interface LexRecord extends v.Infer<typeof lexRecord> {}
|
|
460
|
+
export declare namespace lexRecord {
|
|
461
|
+
export {};
|
|
462
|
+
|
|
463
|
+
type $schematype = typeof _lexRecord;
|
|
464
|
+
export interface $schema extends $schematype {}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const _lexUserType = v.union(
|
|
468
|
+
lexRecord,
|
|
469
|
+
lexXrpcQuery,
|
|
470
|
+
lexXrpcProcedure,
|
|
471
|
+
lexXrpcSubscription,
|
|
472
|
+
lexObject,
|
|
473
|
+
lexArray,
|
|
474
|
+
lexToken,
|
|
475
|
+
lexIpldType,
|
|
476
|
+
lexBlob,
|
|
477
|
+
lexPrimitive,
|
|
256
478
|
);
|
|
257
479
|
|
|
258
|
-
export
|
|
480
|
+
export const lexUserType = _lexUserType as lexUserType.$schema;
|
|
481
|
+
export type LexUserType = v.Infer<typeof lexUserType>;
|
|
482
|
+
export declare namespace lexUserType {
|
|
483
|
+
export {};
|
|
484
|
+
|
|
485
|
+
type $schematype = typeof _lexUserType;
|
|
486
|
+
export interface $schema extends $schematype {}
|
|
487
|
+
}
|
|
259
488
|
|
|
260
489
|
const NSID_RE =
|
|
261
|
-
/^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(
|
|
262
|
-
const nsidType = v.string().assert((v) => NSID_RE.test(v), `string doesn't match nsid format`);
|
|
490
|
+
/^[a-zA-Z](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?:\.[a-zA-Z](?:[a-zA-Z0-9]{0,62})?)$/;
|
|
263
491
|
|
|
264
|
-
|
|
492
|
+
const _lexiconDoc = v
|
|
265
493
|
.object({
|
|
266
494
|
lexicon: v.literal(1),
|
|
267
|
-
id:
|
|
268
|
-
revision:
|
|
495
|
+
id: v.string().assert((input) => NSID_RE.test(input), `must be valid nsid`),
|
|
496
|
+
revision: integer.optional(),
|
|
269
497
|
description: v.string().optional(),
|
|
270
|
-
defs: v.record(
|
|
498
|
+
// defs: v.record(v.pipe(v.string(), v.regex(/^[a-zA-Z][a-zA-Z0-9_]{0,62}?$/)), lexUserType),
|
|
499
|
+
defs: v.record(lexUserType),
|
|
271
500
|
})
|
|
272
|
-
.chain((
|
|
273
|
-
const defs =
|
|
501
|
+
.chain((input) => {
|
|
502
|
+
const { defs } = input;
|
|
274
503
|
|
|
275
|
-
for (const
|
|
276
|
-
const def = defs[
|
|
277
|
-
const type = def.type;
|
|
504
|
+
for (const key in defs) {
|
|
505
|
+
const def = defs[key];
|
|
278
506
|
|
|
279
507
|
if (
|
|
280
|
-
|
|
281
|
-
(type === 'record' ||
|
|
508
|
+
key !== 'main' &&
|
|
509
|
+
(def.type === 'record' ||
|
|
510
|
+
def.type === 'procedure' ||
|
|
511
|
+
def.type === 'query' ||
|
|
512
|
+
def.type === 'subscription')
|
|
282
513
|
) {
|
|
283
|
-
return v.err({
|
|
514
|
+
return v.err({
|
|
515
|
+
message: `records, procedures, queries and subscriptions must be the main definition`,
|
|
516
|
+
path: ['defs', key],
|
|
517
|
+
});
|
|
284
518
|
}
|
|
285
519
|
}
|
|
286
520
|
|
|
287
|
-
return v.ok(
|
|
521
|
+
return v.ok(input);
|
|
288
522
|
});
|
|
289
523
|
|
|
290
|
-
export
|
|
524
|
+
export const lexiconDoc = _lexiconDoc as lexiconDoc.$schema;
|
|
525
|
+
export interface LexiconDoc extends v.Infer<typeof lexiconDoc> {}
|
|
526
|
+
export declare namespace lexiconDoc {
|
|
527
|
+
export {};
|
|
528
|
+
|
|
529
|
+
type $schematype = typeof _lexiconDoc;
|
|
530
|
+
export interface $schema extends $schematype {}
|
|
531
|
+
}
|