@atcute/lex-cli 1.1.2 → 2.0.1
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 +557 -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/package.json +11 -6
- package/src/cli.ts +101 -0
- package/src/codegen.ts +738 -0
- package/src/index.ts +9 -150
- package/dist/generator.d.ts +0 -7
- package/dist/generator.js +0 -579
- package/dist/generator.js.map +0 -1
- package/dist/schema.d.ts +0 -3689
- package/dist/schema.js +0 -174
- package/dist/schema.js.map +0 -1
- package/src/generator.ts +0 -664
- package/src/schema.ts +0 -290
package/src/schema.ts
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import * as v from '@badrap/valita';
|
|
2
|
-
|
|
3
|
-
const integerType = v
|
|
4
|
-
.number()
|
|
5
|
-
.assert((v) => Number.isInteger(v) && v >= 0, 'Number is expected to be a positive integer');
|
|
6
|
-
|
|
7
|
-
export const booleanSchema = v.object({
|
|
8
|
-
type: v.literal('boolean'),
|
|
9
|
-
description: v.string().optional(),
|
|
10
|
-
default: v.boolean().optional(),
|
|
11
|
-
const: v.boolean().optional(),
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
export type BooleanSchema = v.Infer<typeof booleanSchema>;
|
|
15
|
-
|
|
16
|
-
export const integerSchema = v.object({
|
|
17
|
-
type: v.literal('integer'),
|
|
18
|
-
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(),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export type IntegerSchema = v.Infer<typeof integerSchema>;
|
|
27
|
-
|
|
28
|
-
export const stringSchema = v.object({
|
|
29
|
-
type: v.literal('string'),
|
|
30
|
-
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
|
-
default: v.string().optional(),
|
|
47
|
-
const: v.string().optional(),
|
|
48
|
-
enum: v.array(v.string()).optional(),
|
|
49
|
-
knownValues: v.array(v.string()).optional(),
|
|
50
|
-
maxLength: integerType.optional(),
|
|
51
|
-
minLength: integerType.optional(),
|
|
52
|
-
maxGraphemes: integerType.optional(),
|
|
53
|
-
minGraphemes: integerType.optional(),
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
export type StringSchema = v.Infer<typeof stringSchema>;
|
|
57
|
-
|
|
58
|
-
export const unknownSchema = v.object({
|
|
59
|
-
type: v.literal('unknown'),
|
|
60
|
-
description: v.string().optional(),
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
export type UnknownSchema = v.Infer<typeof unknownSchema>;
|
|
64
|
-
|
|
65
|
-
export const primitiveSchema = v.union(booleanSchema, integerSchema, stringSchema, unknownSchema);
|
|
66
|
-
|
|
67
|
-
export type PrimitiveSchema = v.Infer<typeof primitiveSchema>;
|
|
68
|
-
|
|
69
|
-
export const bytesSchema = v.object({
|
|
70
|
-
type: v.literal('bytes'),
|
|
71
|
-
description: v.string().optional(),
|
|
72
|
-
maxLength: integerType.optional(),
|
|
73
|
-
minLength: integerType.optional(),
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
export type BytesSchema = v.Infer<typeof bytesSchema>;
|
|
77
|
-
|
|
78
|
-
export const cidLinkSchema = v.object({
|
|
79
|
-
type: v.literal('cid-link'),
|
|
80
|
-
description: v.string().optional(),
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
export type CidLinkSchema = v.Infer<typeof cidLinkSchema>;
|
|
84
|
-
|
|
85
|
-
export const ipldTypeSchema = v.union(bytesSchema, cidLinkSchema);
|
|
86
|
-
|
|
87
|
-
export type IpldTypeSchema = v.Infer<typeof ipldTypeSchema>;
|
|
88
|
-
|
|
89
|
-
export const refSchema = v.object({
|
|
90
|
-
type: v.literal('ref'),
|
|
91
|
-
description: v.string().optional(),
|
|
92
|
-
ref: v.string(),
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
export type RefSchema = v.Infer<typeof refSchema>;
|
|
96
|
-
|
|
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`);
|
|
105
|
-
|
|
106
|
-
export type RefUnionSchema = v.Infer<typeof refUnionSchema>;
|
|
107
|
-
|
|
108
|
-
export const refVariantSchema = v.union(refSchema, refUnionSchema);
|
|
109
|
-
|
|
110
|
-
export type RefVariantSchema = v.Infer<typeof refVariantSchema>;
|
|
111
|
-
|
|
112
|
-
export const blobSchema = v.object({
|
|
113
|
-
type: v.literal('blob'),
|
|
114
|
-
description: v.string().optional(),
|
|
115
|
-
accept: v.array(v.string()).optional(),
|
|
116
|
-
maxSize: integerType.optional(),
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
export type BlobSchema = v.Infer<typeof blobSchema>;
|
|
120
|
-
|
|
121
|
-
export const arraySchema = v.object({
|
|
122
|
-
type: v.literal('array'),
|
|
123
|
-
description: v.string().optional(),
|
|
124
|
-
items: v.union(primitiveSchema, ipldTypeSchema, blobSchema, refVariantSchema),
|
|
125
|
-
maxLength: integerType.optional(),
|
|
126
|
-
minLength: integerType.optional(),
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
export type ArraySchema = v.Infer<typeof arraySchema>;
|
|
130
|
-
|
|
131
|
-
export const primitiveArraySchema = arraySchema.extend({
|
|
132
|
-
items: primitiveSchema,
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
export type PrimitiveArraySchema = v.Infer<typeof primitiveArraySchema>;
|
|
136
|
-
|
|
137
|
-
export const tokenSchema = v.object({
|
|
138
|
-
type: v.literal('token'),
|
|
139
|
-
description: v.string().optional(),
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
export type TokenSchema = v.Infer<typeof tokenSchema>;
|
|
143
|
-
|
|
144
|
-
const refineRequiredProperties = <T extends { required: string[]; properties: Record<string, unknown> }>(
|
|
145
|
-
obj: T,
|
|
146
|
-
): 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`);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return v.ok(obj);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
export const objectSchema = v
|
|
157
|
-
.object({
|
|
158
|
-
type: v.literal('object'),
|
|
159
|
-
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)),
|
|
163
|
-
})
|
|
164
|
-
.chain(refineRequiredProperties);
|
|
165
|
-
|
|
166
|
-
export type ObjectSchema = v.Infer<typeof objectSchema>;
|
|
167
|
-
|
|
168
|
-
export const xrpcParametersSchema = v
|
|
169
|
-
.object({
|
|
170
|
-
type: v.literal('params'),
|
|
171
|
-
description: v.string().optional(),
|
|
172
|
-
required: v.array(v.string()).optional(() => []),
|
|
173
|
-
properties: v.record(v.union(primitiveSchema, primitiveArraySchema)),
|
|
174
|
-
})
|
|
175
|
-
.chain(refineRequiredProperties);
|
|
176
|
-
|
|
177
|
-
export type XrpcParametersSchema = v.Infer<typeof xrpcParametersSchema>;
|
|
178
|
-
|
|
179
|
-
export const xrpcBodySchema = v.object({
|
|
180
|
-
description: v.string().optional(),
|
|
181
|
-
encoding: v.string(),
|
|
182
|
-
schema: v.union(refVariantSchema, objectSchema).optional(),
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
export type XrpcBodySchema = v.Infer<typeof xrpcBodySchema>;
|
|
186
|
-
|
|
187
|
-
export const xrpcSubscriptionMessageSchema = v.object({
|
|
188
|
-
description: v.string().optional(),
|
|
189
|
-
schema: v.union(refVariantSchema, objectSchema).optional(),
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
export type XrpcSubscriptionMessageSchema = v.Infer<typeof xrpcSubscriptionMessageSchema>;
|
|
193
|
-
|
|
194
|
-
export const xrpcErrorSchema = v.object({
|
|
195
|
-
name: v.string(),
|
|
196
|
-
description: v.string().optional(),
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
export type XrpcErrorSchema = v.Infer<typeof xrpcErrorSchema>;
|
|
200
|
-
|
|
201
|
-
export const xrpcQuerySchema = v.object({
|
|
202
|
-
type: v.literal('query'),
|
|
203
|
-
description: v.string().optional(),
|
|
204
|
-
parameters: xrpcParametersSchema.optional(),
|
|
205
|
-
output: xrpcBodySchema.optional(),
|
|
206
|
-
errors: v.array(xrpcErrorSchema).optional(),
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
export type XrpcQuerySchema = v.Infer<typeof xrpcQuerySchema>;
|
|
210
|
-
|
|
211
|
-
export const xrpcProcedureSchema = v.object({
|
|
212
|
-
type: v.literal('procedure'),
|
|
213
|
-
description: v.string().optional(),
|
|
214
|
-
parameters: xrpcParametersSchema.optional(),
|
|
215
|
-
input: xrpcBodySchema.optional(),
|
|
216
|
-
output: xrpcBodySchema.optional(),
|
|
217
|
-
errors: v.array(xrpcErrorSchema).optional(),
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
export type XrpcProcedureSchema = v.Infer<typeof xrpcProcedureSchema>;
|
|
221
|
-
|
|
222
|
-
export const xrpcSubscriptionSchema = v.object({
|
|
223
|
-
type: v.literal('subscription'),
|
|
224
|
-
description: v.string().optional(),
|
|
225
|
-
parameters: xrpcParametersSchema.optional(),
|
|
226
|
-
message: xrpcSubscriptionMessageSchema.optional(),
|
|
227
|
-
errors: v.array(xrpcErrorSchema).optional(),
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
export type XrpcSubscriptionSchema = v.Infer<typeof xrpcSubscriptionSchema>;
|
|
231
|
-
|
|
232
|
-
export const recordSchema = v.object({
|
|
233
|
-
type: v.literal('record'),
|
|
234
|
-
description: v.string().optional(),
|
|
235
|
-
key: v.string().optional(),
|
|
236
|
-
record: objectSchema,
|
|
237
|
-
});
|
|
238
|
-
|
|
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,
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
export type UserTypeSchema = v.Infer<typeof userTypeSchema>;
|
|
259
|
-
|
|
260
|
-
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`);
|
|
263
|
-
|
|
264
|
-
export const documentSchema = v
|
|
265
|
-
.object({
|
|
266
|
-
lexicon: v.literal(1),
|
|
267
|
-
id: nsidType,
|
|
268
|
-
revision: v.number().optional(),
|
|
269
|
-
description: v.string().optional(),
|
|
270
|
-
defs: v.record(userTypeSchema),
|
|
271
|
-
})
|
|
272
|
-
.chain((doc) => {
|
|
273
|
-
const defs = doc.defs;
|
|
274
|
-
|
|
275
|
-
for (const id in defs) {
|
|
276
|
-
const def = defs[id];
|
|
277
|
-
const type = def.type;
|
|
278
|
-
|
|
279
|
-
if (
|
|
280
|
-
id !== 'main' &&
|
|
281
|
-
(type === 'record' || type === 'query' || type === 'procedure' || type === 'subscription')
|
|
282
|
-
) {
|
|
283
|
-
return v.err({ message: `${type} must be the \`main\` definition`, path: ['defs', id] });
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return v.ok(doc);
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
export type DocumentSchema = v.Infer<typeof documentSchema>;
|