@atcute/lex-cli 1.1.1 → 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 +817 -1945
- package/dist/schema.js +152 -113
- 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 +396 -176
- 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,311 +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
|
+
);
|
|
27
67
|
|
|
28
|
-
export const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
format: v
|
|
33
|
-
.union(
|
|
34
|
-
v.literal('at-identifier'),
|
|
35
|
-
v.literal('at-uri'),
|
|
36
|
-
v.literal('cid'),
|
|
37
|
-
v.literal('datetime'),
|
|
38
|
-
v.literal('did'),
|
|
39
|
-
v.literal('handle'),
|
|
40
|
-
v.literal('language'),
|
|
41
|
-
v.literal('nsid'),
|
|
42
|
-
v.literal('record-key'),
|
|
43
|
-
v.literal('tid'),
|
|
44
|
-
v.literal('uri'),
|
|
45
|
-
)
|
|
46
|
-
.optional(),
|
|
47
|
-
default: v.string().optional(),
|
|
48
|
-
const: v.string().optional(),
|
|
49
|
-
enum: v.array(v.string()).optional(),
|
|
50
|
-
knownValues: v.array(v.string()).optional(),
|
|
51
|
-
maxLength: integerType.optional(),
|
|
52
|
-
minLength: integerType.optional(),
|
|
53
|
-
maxGraphemes: integerType.optional(),
|
|
54
|
-
minGraphemes: integerType.optional(),
|
|
55
|
-
})
|
|
56
|
-
.chain((obj) => {
|
|
57
|
-
const format = obj.format;
|
|
58
|
-
if (format !== undefined && format !== 'uri') {
|
|
59
|
-
// `com.atproto.repo.applyWrites#create` has `maxLength` for compatibility reasons
|
|
60
|
-
// if (obj.maxLength !== undefined) {
|
|
61
|
-
// return v.err(`${format} format can't be used with maxLength`);
|
|
62
|
-
// }
|
|
63
|
-
if (obj.minLength !== undefined) {
|
|
64
|
-
return v.err(`${format} format can't be used with minLength`);
|
|
65
|
-
}
|
|
66
|
-
if (obj.maxGraphemes !== undefined) {
|
|
67
|
-
return v.err(`${format} format can't be used with maxGraphemes`);
|
|
68
|
-
}
|
|
69
|
-
if (obj.minGraphemes !== undefined) {
|
|
70
|
-
return v.err(`${format} format can't be used with minGraphemes`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
68
|
+
export const lexStringFormat = _lexStringFormat as lexStringFormat.$schema;
|
|
69
|
+
export type LexStringFormat = v.Infer<typeof lexStringFormat>;
|
|
70
|
+
export declare namespace lexStringFormat {
|
|
71
|
+
export {};
|
|
73
72
|
|
|
74
|
-
|
|
75
|
-
}
|
|
73
|
+
type $schematype = typeof _lexStringFormat;
|
|
74
|
+
export interface $schema extends $schematype {}
|
|
75
|
+
}
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
const _lexString = v.object({
|
|
78
|
+
type: v.literal('string'),
|
|
79
|
+
format: lexStringFormat.optional(),
|
|
80
|
+
description: v.string().optional(),
|
|
81
|
+
default: v.string().optional(),
|
|
82
|
+
minLength: integer.optional(),
|
|
83
|
+
maxLength: integer.optional(),
|
|
84
|
+
minGraphemes: integer.optional(),
|
|
85
|
+
maxGraphemes: integer.optional(),
|
|
86
|
+
enum: v.array(v.string()).optional(),
|
|
87
|
+
const: v.string().optional(),
|
|
88
|
+
knownValues: v.array(v.string()).optional(),
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
export const lexString = _lexString as lexString.$schema;
|
|
92
|
+
export interface LexString extends v.Infer<typeof lexString> {}
|
|
93
|
+
export declare namespace lexString {
|
|
94
|
+
export {};
|
|
78
95
|
|
|
79
|
-
|
|
96
|
+
type $schematype = typeof _lexString;
|
|
97
|
+
export interface $schema extends $schematype {}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const _lexUnknown = v.object({
|
|
80
101
|
type: v.literal('unknown'),
|
|
81
102
|
description: v.string().optional(),
|
|
82
103
|
});
|
|
83
104
|
|
|
84
|
-
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 {};
|
|
109
|
+
|
|
110
|
+
type $schematype = typeof _lexUnknown;
|
|
111
|
+
export interface $schema extends $schematype {}
|
|
112
|
+
}
|
|
85
113
|
|
|
86
|
-
|
|
114
|
+
const _lexPrimitive = v.union(lexBoolean, lexInteger, lexString, lexUnknown);
|
|
87
115
|
|
|
88
|
-
export
|
|
116
|
+
export const lexPrimitive = _lexPrimitive as lexPrimitive.$schema;
|
|
117
|
+
export type LexPrimitive = v.Infer<typeof lexPrimitive>;
|
|
118
|
+
export declare namespace lexPrimitive {
|
|
119
|
+
export {};
|
|
89
120
|
|
|
90
|
-
|
|
121
|
+
type $schematype = typeof _lexPrimitive;
|
|
122
|
+
export interface $schema extends $schematype {}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const _lexBytes = v.object({
|
|
91
126
|
type: v.literal('bytes'),
|
|
92
127
|
description: v.string().optional(),
|
|
93
|
-
|
|
94
|
-
|
|
128
|
+
minLength: integer.optional(),
|
|
129
|
+
maxLength: integer.optional(),
|
|
95
130
|
});
|
|
96
131
|
|
|
97
|
-
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 {};
|
|
136
|
+
|
|
137
|
+
type $schematype = typeof _lexBytes;
|
|
138
|
+
export interface $schema extends $schematype {}
|
|
139
|
+
}
|
|
98
140
|
|
|
99
|
-
|
|
141
|
+
const _lexCidLink = v.object({
|
|
100
142
|
type: v.literal('cid-link'),
|
|
101
143
|
description: v.string().optional(),
|
|
102
144
|
});
|
|
103
145
|
|
|
104
|
-
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
|
+
}
|
|
105
154
|
|
|
106
|
-
|
|
155
|
+
const _lexIpldType = v.union(lexBytes, lexCidLink);
|
|
107
156
|
|
|
108
|
-
export
|
|
157
|
+
export const lexIpldType = _lexIpldType as lexIpldType.$schema;
|
|
158
|
+
export type LexIpldType = v.Infer<typeof lexIpldType>;
|
|
159
|
+
export declare namespace lexIpldType {
|
|
160
|
+
export {};
|
|
109
161
|
|
|
110
|
-
|
|
162
|
+
type $schematype = typeof _lexIpldType;
|
|
163
|
+
export interface $schema extends $schematype {}
|
|
164
|
+
}
|
|
165
|
+
|
|
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}?)?$/;
|
|
168
|
+
|
|
169
|
+
const refString = v.string().assert((input) => REF_RE.test(input));
|
|
170
|
+
|
|
171
|
+
const _lexRef = v.object({
|
|
111
172
|
type: v.literal('ref'),
|
|
112
173
|
description: v.string().optional(),
|
|
113
|
-
ref:
|
|
174
|
+
ref: refString,
|
|
114
175
|
});
|
|
115
176
|
|
|
116
|
-
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 {};
|
|
117
181
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
description: v.string().optional(),
|
|
122
|
-
refs: v.array(v.string()),
|
|
123
|
-
closed: v.boolean().optional(() => false),
|
|
124
|
-
})
|
|
125
|
-
.assert((v) => !v.closed || v.refs.length > 0, `A closed union can't have empty refs list`);
|
|
182
|
+
type $schematype = typeof _lexRef;
|
|
183
|
+
export interface $schema extends $schematype {}
|
|
184
|
+
}
|
|
126
185
|
|
|
127
|
-
|
|
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 {};
|
|
197
|
+
|
|
198
|
+
type $schematype = typeof _lexRefUnion;
|
|
199
|
+
export interface $schema extends $schematype {}
|
|
200
|
+
}
|
|
128
201
|
|
|
129
|
-
|
|
202
|
+
const _lexRefVariant = v.union(lexRef, lexRefUnion);
|
|
130
203
|
|
|
131
|
-
export
|
|
204
|
+
export const lexRefVariant = _lexRefVariant as lexRefVariant.$schema;
|
|
205
|
+
export type LexRefVariant = v.Infer<typeof lexRefVariant>;
|
|
206
|
+
export declare namespace lexRefVariant {
|
|
207
|
+
export {};
|
|
132
208
|
|
|
133
|
-
|
|
209
|
+
type $schematype = typeof _lexRefVariant;
|
|
210
|
+
export interface $schema extends $schematype {}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const _lexBlob = v.object({
|
|
134
214
|
type: v.literal('blob'),
|
|
135
215
|
description: v.string().optional(),
|
|
136
216
|
accept: v.array(v.string()).optional(),
|
|
137
|
-
maxSize:
|
|
217
|
+
maxSize: integer.optional(),
|
|
138
218
|
});
|
|
139
219
|
|
|
140
|
-
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
|
+
}
|
|
141
228
|
|
|
142
|
-
|
|
229
|
+
const _lexArray = v.object({
|
|
143
230
|
type: v.literal('array'),
|
|
144
231
|
description: v.string().optional(),
|
|
145
|
-
items: v.union(
|
|
146
|
-
|
|
147
|
-
|
|
232
|
+
items: v.union(lexPrimitive, lexIpldType, lexRefVariant, lexBlob),
|
|
233
|
+
minLength: integer.optional(),
|
|
234
|
+
maxLength: integer.optional(),
|
|
148
235
|
});
|
|
149
236
|
|
|
150
|
-
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 {};
|
|
241
|
+
|
|
242
|
+
type $schematype = typeof _lexArray;
|
|
243
|
+
export interface $schema extends $schematype {}
|
|
244
|
+
}
|
|
151
245
|
|
|
152
|
-
|
|
153
|
-
items:
|
|
246
|
+
const _lexPrimitiveArray = lexArray.extend({
|
|
247
|
+
items: lexPrimitive,
|
|
154
248
|
});
|
|
155
249
|
|
|
156
|
-
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 {};
|
|
157
254
|
|
|
158
|
-
|
|
255
|
+
type $schematype = typeof _lexPrimitiveArray;
|
|
256
|
+
export interface $schema extends $schematype {}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const _lexToken = v.object({
|
|
159
260
|
type: v.literal('token'),
|
|
160
261
|
description: v.string().optional(),
|
|
161
262
|
});
|
|
162
263
|
|
|
163
|
-
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 {};
|
|
268
|
+
|
|
269
|
+
type $schematype = typeof _lexToken;
|
|
270
|
+
export interface $schema extends $schematype {}
|
|
271
|
+
}
|
|
164
272
|
|
|
165
|
-
const
|
|
166
|
-
|
|
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,
|
|
167
277
|
): v.ValitaResult<T> => {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
+
});
|
|
171
286
|
}
|
|
172
287
|
}
|
|
173
288
|
|
|
174
|
-
|
|
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
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return v.ok(input);
|
|
175
308
|
};
|
|
176
309
|
|
|
177
|
-
|
|
310
|
+
const _lexObject = v
|
|
178
311
|
.object({
|
|
179
312
|
type: v.literal('object'),
|
|
180
313
|
description: v.string().optional(),
|
|
181
|
-
required: v.array(v.string()).optional(
|
|
182
|
-
nullable: v.array(v.string()).optional(
|
|
183
|
-
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(),
|
|
184
317
|
})
|
|
185
|
-
.chain(
|
|
318
|
+
.chain(refineObjectProperties);
|
|
186
319
|
|
|
187
|
-
export
|
|
320
|
+
export const lexObject = _lexObject as lexObject.$schema;
|
|
321
|
+
export interface LexObject extends v.Infer<typeof lexObject> {}
|
|
322
|
+
export declare namespace lexObject {
|
|
323
|
+
export {};
|
|
188
324
|
|
|
189
|
-
|
|
325
|
+
type $schematype = typeof _lexObject;
|
|
326
|
+
export interface $schema extends $schematype {}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const _lexXrpcParameters = v
|
|
190
330
|
.object({
|
|
191
331
|
type: v.literal('params'),
|
|
192
332
|
description: v.string().optional(),
|
|
193
|
-
required: v.array(v.string()).optional(
|
|
194
|
-
properties: v.record(v.union(
|
|
333
|
+
required: v.array(v.string()).optional(),
|
|
334
|
+
properties: v.record(v.union(lexPrimitive, lexPrimitiveArray)).optional(),
|
|
195
335
|
})
|
|
196
|
-
.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 {};
|
|
197
342
|
|
|
198
|
-
|
|
343
|
+
type $schematype = typeof _lexXrpcParameters;
|
|
344
|
+
export interface $schema extends $schematype {}
|
|
345
|
+
}
|
|
199
346
|
|
|
200
|
-
|
|
347
|
+
const _lexXrpcBody = v.object({
|
|
201
348
|
description: v.string().optional(),
|
|
202
349
|
encoding: v.string(),
|
|
203
|
-
schema: v.union(
|
|
350
|
+
schema: v.union(lexRefVariant, lexObject).optional(),
|
|
204
351
|
});
|
|
205
352
|
|
|
206
|
-
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 {};
|
|
207
357
|
|
|
208
|
-
|
|
358
|
+
type $schematype = typeof _lexXrpcBody;
|
|
359
|
+
export interface $schema extends $schematype {}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const _lexXrpcSubscriptionMessage = v.object({
|
|
209
363
|
description: v.string().optional(),
|
|
210
|
-
schema: v.union(
|
|
364
|
+
schema: v.union(lexRefVariant, lexObject).optional(),
|
|
211
365
|
});
|
|
212
366
|
|
|
213
|
-
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
|
+
}
|
|
214
375
|
|
|
215
|
-
|
|
376
|
+
const _lexXrpcError = v.object({
|
|
216
377
|
name: v.string(),
|
|
217
378
|
description: v.string().optional(),
|
|
218
379
|
});
|
|
219
380
|
|
|
220
|
-
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 {};
|
|
385
|
+
|
|
386
|
+
type $schematype = typeof _lexXrpcError;
|
|
387
|
+
export interface $schema extends $schematype {}
|
|
388
|
+
}
|
|
221
389
|
|
|
222
|
-
|
|
390
|
+
const _lexXrpcQuery = v.object({
|
|
223
391
|
type: v.literal('query'),
|
|
224
392
|
description: v.string().optional(),
|
|
225
|
-
parameters:
|
|
226
|
-
output:
|
|
227
|
-
errors: v.array(
|
|
393
|
+
parameters: lexXrpcParameters.optional(),
|
|
394
|
+
output: lexXrpcBody.optional(),
|
|
395
|
+
errors: v.array(lexXrpcError).optional(),
|
|
228
396
|
});
|
|
229
397
|
|
|
230
|
-
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 {};
|
|
231
402
|
|
|
232
|
-
|
|
403
|
+
type $schematype = typeof _lexXrpcQuery;
|
|
404
|
+
export interface $schema extends $schematype {}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const _lexXrpcProcedure = v.object({
|
|
233
408
|
type: v.literal('procedure'),
|
|
234
409
|
description: v.string().optional(),
|
|
235
|
-
parameters:
|
|
236
|
-
input:
|
|
237
|
-
output:
|
|
238
|
-
errors: v.array(
|
|
410
|
+
parameters: lexXrpcParameters.optional(),
|
|
411
|
+
input: lexXrpcBody.optional(),
|
|
412
|
+
output: lexXrpcBody.optional(),
|
|
413
|
+
errors: v.array(lexXrpcError).optional(),
|
|
239
414
|
});
|
|
240
415
|
|
|
241
|
-
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 {};
|
|
420
|
+
|
|
421
|
+
type $schematype = typeof _lexXrpcProcedure;
|
|
422
|
+
export interface $schema extends $schematype {}
|
|
423
|
+
}
|
|
242
424
|
|
|
243
|
-
|
|
425
|
+
const _lexXrpcSubscription = v.object({
|
|
244
426
|
type: v.literal('subscription'),
|
|
245
427
|
description: v.string().optional(),
|
|
246
|
-
parameters:
|
|
247
|
-
message:
|
|
248
|
-
errors: v.array(
|
|
428
|
+
parameters: lexXrpcParameters.optional(),
|
|
429
|
+
message: lexXrpcSubscriptionMessage.optional(),
|
|
430
|
+
errors: v.array(lexXrpcError).optional(),
|
|
249
431
|
});
|
|
250
432
|
|
|
251
|
-
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
|
+
}
|
|
252
441
|
|
|
253
|
-
|
|
442
|
+
const LITERAL_KEY_RE = /^literal:(.+)$/;
|
|
443
|
+
|
|
444
|
+
const _lexRecord = v.object({
|
|
254
445
|
type: v.literal('record'),
|
|
255
446
|
description: v.string().optional(),
|
|
256
|
-
key: v
|
|
257
|
-
|
|
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,
|
|
258
456
|
});
|
|
259
457
|
|
|
260
|
-
export
|
|
261
|
-
|
|
262
|
-
export
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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,
|
|
277
478
|
);
|
|
278
479
|
|
|
279
|
-
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
|
+
}
|
|
280
488
|
|
|
281
489
|
const NSID_RE =
|
|
282
|
-
/^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(
|
|
283
|
-
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})?)$/;
|
|
284
491
|
|
|
285
|
-
|
|
492
|
+
const _lexiconDoc = v
|
|
286
493
|
.object({
|
|
287
494
|
lexicon: v.literal(1),
|
|
288
|
-
id:
|
|
289
|
-
revision:
|
|
495
|
+
id: v.string().assert((input) => NSID_RE.test(input), `must be valid nsid`),
|
|
496
|
+
revision: integer.optional(),
|
|
290
497
|
description: v.string().optional(),
|
|
291
|
-
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),
|
|
292
500
|
})
|
|
293
|
-
.chain((
|
|
294
|
-
const defs =
|
|
501
|
+
.chain((input) => {
|
|
502
|
+
const { defs } = input;
|
|
295
503
|
|
|
296
|
-
for (const
|
|
297
|
-
const def = defs[
|
|
298
|
-
const type = def.type;
|
|
504
|
+
for (const key in defs) {
|
|
505
|
+
const def = defs[key];
|
|
299
506
|
|
|
300
507
|
if (
|
|
301
|
-
|
|
302
|
-
(type === 'record' ||
|
|
508
|
+
key !== 'main' &&
|
|
509
|
+
(def.type === 'record' ||
|
|
510
|
+
def.type === 'procedure' ||
|
|
511
|
+
def.type === 'query' ||
|
|
512
|
+
def.type === 'subscription')
|
|
303
513
|
) {
|
|
304
|
-
return v.err({
|
|
514
|
+
return v.err({
|
|
515
|
+
message: `records, procedures, queries and subscriptions must be the main definition`,
|
|
516
|
+
path: ['defs', key],
|
|
517
|
+
});
|
|
305
518
|
}
|
|
306
519
|
}
|
|
307
520
|
|
|
308
|
-
return v.ok(
|
|
521
|
+
return v.ok(input);
|
|
309
522
|
});
|
|
310
523
|
|
|
311
|
-
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
|
+
}
|