@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/src/schema.ts CHANGED
@@ -1,290 +1,531 @@
1
1
  import * as v from '@badrap/valita';
2
2
 
3
- const integerType = v
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((v) => Number.isInteger(v) && v >= 0, 'Number is expected to be a positive integer');
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
- export const booleanSchema = v.object({
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 type BooleanSchema = v.Infer<typeof booleanSchema>;
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
- export const integerSchema = v.object({
35
+ const _lexInteger = v.object({
17
36
  type: v.literal('integer'),
18
37
  description: v.string().optional(),
19
- default: integerType.optional(),
20
- const: integerType.optional(),
21
- enum: v.array(v.number()).optional(),
22
- maximum: integerType.optional(),
23
- minimum: integerType.optional(),
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 type IntegerSchema = v.Infer<typeof integerSchema>;
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
- export const stringSchema = v.object({
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
- const: v.string().optional(),
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 type StringSchema = v.Infer<typeof stringSchema>;
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
- export const unknownSchema = v.object({
100
+ const _lexUnknown = v.object({
59
101
  type: v.literal('unknown'),
60
102
  description: v.string().optional(),
61
103
  });
62
104
 
63
- export type UnknownSchema = v.Infer<typeof unknownSchema>;
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
- export const primitiveSchema = v.union(booleanSchema, integerSchema, stringSchema, unknownSchema);
110
+ type $schematype = typeof _lexUnknown;
111
+ export interface $schema extends $schematype {}
112
+ }
66
113
 
67
- export type PrimitiveSchema = v.Infer<typeof primitiveSchema>;
114
+ const _lexPrimitive = v.union(lexBoolean, lexInteger, lexString, lexUnknown);
68
115
 
69
- export const bytesSchema = v.object({
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
- maxLength: integerType.optional(),
73
- minLength: integerType.optional(),
128
+ minLength: integer.optional(),
129
+ maxLength: integer.optional(),
74
130
  });
75
131
 
76
- export type BytesSchema = v.Infer<typeof bytesSchema>;
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
- export const cidLinkSchema = v.object({
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 type CidLinkSchema = v.Infer<typeof cidLinkSchema>;
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
- export const ipldTypeSchema = v.union(bytesSchema, cidLinkSchema);
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
- export type IpldTypeSchema = v.Infer<typeof ipldTypeSchema>;
169
+ const refString = v.string().assert((input) => REF_RE.test(input));
88
170
 
89
- export const refSchema = v.object({
171
+ const _lexRef = v.object({
90
172
  type: v.literal('ref'),
91
173
  description: v.string().optional(),
92
- ref: v.string(),
174
+ ref: refString,
93
175
  });
94
176
 
95
- export type RefSchema = v.Infer<typeof refSchema>;
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
- export const refUnionSchema = v
98
- .object({
99
- type: v.literal('union'),
100
- description: v.string().optional(),
101
- refs: v.array(v.string()),
102
- closed: v.boolean().optional(() => false),
103
- })
104
- .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
+ }
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
- export type RefUnionSchema = v.Infer<typeof refUnionSchema>;
198
+ type $schematype = typeof _lexRefUnion;
199
+ export interface $schema extends $schematype {}
200
+ }
107
201
 
108
- export const refVariantSchema = v.union(refSchema, refUnionSchema);
202
+ const _lexRefVariant = v.union(lexRef, lexRefUnion);
109
203
 
110
- export type RefVariantSchema = v.Infer<typeof refVariantSchema>;
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
- export const blobSchema = v.object({
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: integerType.optional(),
217
+ maxSize: integer.optional(),
117
218
  });
118
219
 
119
- export type BlobSchema = v.Infer<typeof blobSchema>;
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
- export const arraySchema = v.object({
229
+ const _lexArray = v.object({
122
230
  type: v.literal('array'),
123
231
  description: v.string().optional(),
124
- items: v.union(primitiveSchema, ipldTypeSchema, blobSchema, refVariantSchema),
125
- maxLength: integerType.optional(),
126
- minLength: integerType.optional(),
232
+ items: v.union(lexPrimitive, lexIpldType, lexRefVariant, lexBlob),
233
+ minLength: integer.optional(),
234
+ maxLength: integer.optional(),
127
235
  });
128
236
 
129
- export type ArraySchema = v.Infer<typeof arraySchema>;
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
- export const primitiveArraySchema = arraySchema.extend({
132
- items: primitiveSchema,
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 type PrimitiveArraySchema = v.Infer<typeof primitiveArraySchema>;
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
- export const tokenSchema = v.object({
259
+ const _lexToken = v.object({
138
260
  type: v.literal('token'),
139
261
  description: v.string().optional(),
140
262
  });
141
263
 
142
- export type TokenSchema = v.Infer<typeof tokenSchema>;
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
- const refineRequiredProperties = <T extends { required: string[]; properties: Record<string, unknown> }>(
145
- obj: T,
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
- for (const field of obj.required) {
148
- if (obj.properties[field] === undefined) {
149
- return v.err(`Required field "${field}" not defined`);
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(obj);
307
+ return v.ok(input);
154
308
  };
155
309
 
156
- export const objectSchema = v
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(refVariantSchema, ipldTypeSchema, arraySchema, blobSchema, primitiveSchema)),
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(refineRequiredProperties);
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
- export type ObjectSchema = v.Infer<typeof objectSchema>;
325
+ type $schematype = typeof _lexObject;
326
+ export interface $schema extends $schematype {}
327
+ }
167
328
 
168
- export const xrpcParametersSchema = v
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(primitiveSchema, primitiveArraySchema)),
333
+ required: v.array(v.string()).optional(),
334
+ properties: v.record(v.union(lexPrimitive, lexPrimitiveArray)).optional(),
174
335
  })
175
- .chain(refineRequiredProperties);
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
- export type XrpcParametersSchema = v.Infer<typeof xrpcParametersSchema>;
343
+ type $schematype = typeof _lexXrpcParameters;
344
+ export interface $schema extends $schematype {}
345
+ }
178
346
 
179
- export const xrpcBodySchema = v.object({
347
+ const _lexXrpcBody = v.object({
180
348
  description: v.string().optional(),
181
349
  encoding: v.string(),
182
- schema: v.union(refVariantSchema, objectSchema).optional(),
350
+ schema: v.union(lexRefVariant, lexObject).optional(),
183
351
  });
184
352
 
185
- export type XrpcBodySchema = v.Infer<typeof xrpcBodySchema>;
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
- export const xrpcSubscriptionMessageSchema = v.object({
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(refVariantSchema, objectSchema).optional(),
364
+ schema: v.union(lexRefVariant, lexObject).optional(),
190
365
  });
191
366
 
192
- export type XrpcSubscriptionMessageSchema = v.Infer<typeof xrpcSubscriptionMessageSchema>;
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
- export const xrpcErrorSchema = v.object({
376
+ const _lexXrpcError = v.object({
195
377
  name: v.string(),
196
378
  description: v.string().optional(),
197
379
  });
198
380
 
199
- export type XrpcErrorSchema = v.Infer<typeof xrpcErrorSchema>;
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
- export const xrpcQuerySchema = v.object({
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: xrpcParametersSchema.optional(),
205
- output: xrpcBodySchema.optional(),
206
- errors: v.array(xrpcErrorSchema).optional(),
393
+ parameters: lexXrpcParameters.optional(),
394
+ output: lexXrpcBody.optional(),
395
+ errors: v.array(lexXrpcError).optional(),
207
396
  });
208
397
 
209
- export type XrpcQuerySchema = v.Infer<typeof xrpcQuerySchema>;
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
- export const xrpcProcedureSchema = v.object({
407
+ const _lexXrpcProcedure = v.object({
212
408
  type: v.literal('procedure'),
213
409
  description: v.string().optional(),
214
- parameters: xrpcParametersSchema.optional(),
215
- input: xrpcBodySchema.optional(),
216
- output: xrpcBodySchema.optional(),
217
- errors: v.array(xrpcErrorSchema).optional(),
410
+ parameters: lexXrpcParameters.optional(),
411
+ input: lexXrpcBody.optional(),
412
+ output: lexXrpcBody.optional(),
413
+ errors: v.array(lexXrpcError).optional(),
218
414
  });
219
415
 
220
- export type XrpcProcedureSchema = v.Infer<typeof xrpcProcedureSchema>;
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
- export const xrpcSubscriptionSchema = v.object({
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: xrpcParametersSchema.optional(),
226
- message: xrpcSubscriptionMessageSchema.optional(),
227
- errors: v.array(xrpcErrorSchema).optional(),
428
+ parameters: lexXrpcParameters.optional(),
429
+ message: lexXrpcSubscriptionMessage.optional(),
430
+ errors: v.array(lexXrpcError).optional(),
228
431
  });
229
432
 
230
- export type XrpcSubscriptionSchema = v.Infer<typeof xrpcSubscriptionSchema>;
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
- export const recordSchema = v.object({
444
+ const _lexRecord = v.object({
233
445
  type: v.literal('record'),
234
446
  description: v.string().optional(),
235
- key: v.string().optional(),
236
- record: objectSchema,
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 type RecordSchema = v.Infer<typeof objectSchema>;
240
-
241
- export const userTypeSchema = v.union(
242
- recordSchema,
243
- xrpcQuerySchema,
244
- xrpcProcedureSchema,
245
- xrpcSubscriptionSchema,
246
- blobSchema,
247
- arraySchema,
248
- tokenSchema,
249
- objectSchema,
250
- booleanSchema,
251
- integerSchema,
252
- stringSchema,
253
- bytesSchema,
254
- cidLinkSchema,
255
- unknownSchema,
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 type UserTypeSchema = v.Infer<typeof userTypeSchema>;
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])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\.[a-zA-Z]([a-zA-Z]{0,61}[a-zA-Z])?)$/;
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
- export const documentSchema = v
492
+ const _lexiconDoc = v
265
493
  .object({
266
494
  lexicon: v.literal(1),
267
- id: nsidType,
268
- revision: v.number().optional(),
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(userTypeSchema),
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((doc) => {
273
- const defs = doc.defs;
501
+ .chain((input) => {
502
+ const { defs } = input;
274
503
 
275
- for (const id in defs) {
276
- const def = defs[id];
277
- const type = def.type;
504
+ for (const key in defs) {
505
+ const def = defs[key];
278
506
 
279
507
  if (
280
- id !== 'main' &&
281
- (type === 'record' || type === 'query' || type === 'procedure' || type === 'subscription')
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({ message: `${type} must be the \`main\` definition`, path: ['defs', id] });
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(doc);
521
+ return v.ok(input);
288
522
  });
289
523
 
290
- export type DocumentSchema = v.Infer<typeof documentSchema>;
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
+ }