@bobbykim/manguito-cms-api 0.1.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/dist/codegen/index.d.mts +7 -0
- package/dist/codegen/index.d.ts +7 -0
- package/dist/codegen/index.js +701 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/index.mjs +672 -0
- package/dist/codegen/index.mjs.map +1 -0
- package/dist/index.d.mts +41 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +3228 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3189 -0
- package/dist/index.mjs.map +1 -0
- package/dist/runtime/index.d.mts +29 -0
- package/dist/runtime/index.d.ts +29 -0
- package/dist/runtime/index.js +118 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/index.mjs +86 -0
- package/dist/runtime/index.mjs.map +1 -0
- package/dist/storage/index.d.mts +25 -0
- package/dist/storage/index.d.ts +25 -0
- package/dist/storage/index.js +287 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/index.mjs +253 -0
- package/dist/storage/index.mjs.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
// src/codegen/routes.ts
|
|
2
|
+
function getSegment(machineName) {
|
|
3
|
+
const idx = machineName.indexOf("--");
|
|
4
|
+
return idx !== -1 ? machineName.slice(idx + 2) : machineName;
|
|
5
|
+
}
|
|
6
|
+
function toPascalCase(snakeOrKebab) {
|
|
7
|
+
return snakeOrKebab.split(/[_-]/).filter(Boolean).map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join("");
|
|
8
|
+
}
|
|
9
|
+
function schemaVar(machineName) {
|
|
10
|
+
return toPascalCase(getSegment(machineName)) + "Schema";
|
|
11
|
+
}
|
|
12
|
+
function routeVar(prefix, machineName, suffix) {
|
|
13
|
+
return `${prefix}${toPascalCase(getSegment(machineName))}${suffix}Route`;
|
|
14
|
+
}
|
|
15
|
+
function openApiPath(honoPath) {
|
|
16
|
+
return honoPath.replace(/:([^/]+)/g, "{$1}");
|
|
17
|
+
}
|
|
18
|
+
function fieldToZodSchema(field, registry) {
|
|
19
|
+
const { field_type, validation } = field;
|
|
20
|
+
switch (field_type) {
|
|
21
|
+
case "text/plain": {
|
|
22
|
+
let s = "z.string()";
|
|
23
|
+
if (validation.limit !== void 0) s += `.max(${validation.limit})`;
|
|
24
|
+
if (validation.pattern !== void 0) s += `.regex(new RegExp(${JSON.stringify(validation.pattern)}))`;
|
|
25
|
+
return s;
|
|
26
|
+
}
|
|
27
|
+
case "text/rich":
|
|
28
|
+
return "z.string()";
|
|
29
|
+
case "integer": {
|
|
30
|
+
let s = "z.number().int()";
|
|
31
|
+
if (validation.min !== void 0) s += `.min(${validation.min})`;
|
|
32
|
+
if (validation.max !== void 0) s += `.max(${validation.max})`;
|
|
33
|
+
return s;
|
|
34
|
+
}
|
|
35
|
+
case "float": {
|
|
36
|
+
let s = "z.number()";
|
|
37
|
+
if (validation.min !== void 0) s += `.min(${validation.min})`;
|
|
38
|
+
if (validation.max !== void 0) s += `.max(${validation.max})`;
|
|
39
|
+
return s;
|
|
40
|
+
}
|
|
41
|
+
case "boolean":
|
|
42
|
+
return "z.boolean()";
|
|
43
|
+
case "date":
|
|
44
|
+
return "z.string().datetime()";
|
|
45
|
+
case "image": {
|
|
46
|
+
const fields = [
|
|
47
|
+
"id: z.string().uuid()",
|
|
48
|
+
"url: z.string().url()",
|
|
49
|
+
"mime_type: z.string()",
|
|
50
|
+
"alt: z.string().optional()",
|
|
51
|
+
"file_size: z.number().int()",
|
|
52
|
+
"width: z.number().int().optional()",
|
|
53
|
+
"height: z.number().int().optional()"
|
|
54
|
+
];
|
|
55
|
+
return `z.object({ ${fields.join(", ")} })`;
|
|
56
|
+
}
|
|
57
|
+
case "video": {
|
|
58
|
+
const fields = [
|
|
59
|
+
"id: z.string().uuid()",
|
|
60
|
+
"url: z.string().url()",
|
|
61
|
+
"mime_type: z.string()",
|
|
62
|
+
"alt: z.string().optional()",
|
|
63
|
+
"file_size: z.number().int()",
|
|
64
|
+
"width: z.number().int().optional()",
|
|
65
|
+
"height: z.number().int().optional()",
|
|
66
|
+
"duration: z.number().optional()"
|
|
67
|
+
];
|
|
68
|
+
return `z.object({ ${fields.join(", ")} })`;
|
|
69
|
+
}
|
|
70
|
+
case "file": {
|
|
71
|
+
const fields = [
|
|
72
|
+
"id: z.string().uuid()",
|
|
73
|
+
"url: z.string().url()",
|
|
74
|
+
"mime_type: z.string()",
|
|
75
|
+
"alt: z.string().optional()",
|
|
76
|
+
"file_size: z.number().int()"
|
|
77
|
+
];
|
|
78
|
+
return `z.object({ ${fields.join(", ")} })`;
|
|
79
|
+
}
|
|
80
|
+
case "enum": {
|
|
81
|
+
const values = validation.allowed_values ?? [];
|
|
82
|
+
if (values.length === 0) return "z.string()";
|
|
83
|
+
const quoted = values.map((v) => JSON.stringify(v)).join(", ");
|
|
84
|
+
return `z.enum([${quoted}])`;
|
|
85
|
+
}
|
|
86
|
+
case "paragraph": {
|
|
87
|
+
const ui = field.ui_component;
|
|
88
|
+
if (ui.component !== "paragraph-embed") return "z.unknown()";
|
|
89
|
+
const paragraphType = registry?.paragraph_types[ui.ref];
|
|
90
|
+
if (!paragraphType) return "z.unknown()";
|
|
91
|
+
const inner = generateParagraphObjectSchema(paragraphType, registry);
|
|
92
|
+
return ui.rel === "one-to-many" ? `z.array(${inner})` : inner;
|
|
93
|
+
}
|
|
94
|
+
case "reference": {
|
|
95
|
+
const ui = field.ui_component;
|
|
96
|
+
if (ui.component !== "typeahead-select") return "z.string().uuid()";
|
|
97
|
+
return ui.rel === "one-to-many" ? "z.array(z.string().uuid())" : "z.string().uuid()";
|
|
98
|
+
}
|
|
99
|
+
default:
|
|
100
|
+
return "z.unknown()";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function generateParagraphObjectSchema(paragraph, registry) {
|
|
104
|
+
const entries = paragraph.fields.map((f) => {
|
|
105
|
+
const zodType = fieldToZodSchema(f, registry);
|
|
106
|
+
return `${f.name}: ${f.required ? zodType : `${zodType}.optional()`}`;
|
|
107
|
+
});
|
|
108
|
+
if (entries.length === 0) return "z.object({})";
|
|
109
|
+
return `z.object({ ${entries.join(", ")} })`;
|
|
110
|
+
}
|
|
111
|
+
function systemFieldEntries(schema) {
|
|
112
|
+
const entries = ["id: z.string().uuid()"];
|
|
113
|
+
if (schema.schema_type === "content-type" && !schema.only_one) {
|
|
114
|
+
entries.push("slug: z.string()");
|
|
115
|
+
}
|
|
116
|
+
entries.push("published: z.boolean()");
|
|
117
|
+
entries.push("created_at: z.string().datetime()");
|
|
118
|
+
entries.push("updated_at: z.string().datetime()");
|
|
119
|
+
return entries;
|
|
120
|
+
}
|
|
121
|
+
function schemaFieldEntries(fields, registry) {
|
|
122
|
+
return fields.map((f) => {
|
|
123
|
+
const zodType = fieldToZodSchema(f, registry);
|
|
124
|
+
return ` ${f.name}: ${f.required ? zodType : `${zodType}.optional()`}`;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function generateContentSchema(schema, registry) {
|
|
128
|
+
const name = schemaVar(schema.name);
|
|
129
|
+
const sysEntries = systemFieldEntries(schema).map((e) => ` ${e}`);
|
|
130
|
+
const fieldEntries = schemaFieldEntries(schema.fields, registry);
|
|
131
|
+
const allEntries = [...sysEntries, ...fieldEntries];
|
|
132
|
+
return `const ${name} = z.object({
|
|
133
|
+
${allEntries.join(",\n")},
|
|
134
|
+
})`;
|
|
135
|
+
}
|
|
136
|
+
function generateParagraphSchemaDecl(paragraph, registry) {
|
|
137
|
+
const name = schemaVar(paragraph.name);
|
|
138
|
+
const inner = generateParagraphObjectSchema(paragraph, registry);
|
|
139
|
+
return `const ${name} = ${inner}`;
|
|
140
|
+
}
|
|
141
|
+
var SHARED_SCHEMAS_BLOCK = `const ErrorResponseSchema = z.object({
|
|
142
|
+
ok: z.literal(false),
|
|
143
|
+
error: z.object({
|
|
144
|
+
code: z.string(),
|
|
145
|
+
message: z.string(),
|
|
146
|
+
details: z.unknown().optional(),
|
|
147
|
+
}),
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
function listResponseSchema<T extends z.ZodTypeAny>(dataSchema: T) {
|
|
151
|
+
return z.object({
|
|
152
|
+
ok: z.literal(true),
|
|
153
|
+
data: z.array(dataSchema),
|
|
154
|
+
meta: z.object({
|
|
155
|
+
total: z.number().int(),
|
|
156
|
+
page: z.number().int(),
|
|
157
|
+
per_page: z.number().int(),
|
|
158
|
+
total_pages: z.number().int(),
|
|
159
|
+
has_next: z.boolean(),
|
|
160
|
+
has_prev: z.boolean(),
|
|
161
|
+
}),
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function itemResponseSchema<T extends z.ZodTypeAny>(dataSchema: T) {
|
|
166
|
+
return z.object({
|
|
167
|
+
ok: z.literal(true),
|
|
168
|
+
data: dataSchema,
|
|
169
|
+
})
|
|
170
|
+
}`;
|
|
171
|
+
var PUBLIC_LIST_QUERY = `z.object({
|
|
172
|
+
page: z.coerce.number().int().min(1).default(1),
|
|
173
|
+
per_page: z.coerce.number().int().min(1).max(100).default(10),
|
|
174
|
+
include: z.string().optional().describe('Comma-separated relation field names to expand'),
|
|
175
|
+
sort_by: z.enum(['title', 'created_at', 'updated_at']).optional().default('created_at'),
|
|
176
|
+
sort_order: z.enum(['asc', 'desc']).optional().default('asc'),
|
|
177
|
+
})`;
|
|
178
|
+
var ADMIN_LIST_QUERY = `z.object({
|
|
179
|
+
page: z.coerce.number().int().min(1).default(1),
|
|
180
|
+
per_page: z.coerce.number().int().min(1).max(100).default(10),
|
|
181
|
+
include: z.string().optional().describe('Comma-separated relation field names to expand'),
|
|
182
|
+
sort_by: z.enum(['title', 'created_at', 'updated_at']).optional().default('created_at'),
|
|
183
|
+
sort_order: z.enum(['asc', 'desc']).optional().default('asc'),
|
|
184
|
+
published: z.enum(['true', 'false']).optional().describe('Filter by published state'),
|
|
185
|
+
})`;
|
|
186
|
+
var SLUG_PARAMS = `z.object({ slug: z.string() })`;
|
|
187
|
+
var ID_PARAMS = `z.object({ id: z.string().uuid() })`;
|
|
188
|
+
var INCLUDE_QUERY = `z.object({ include: z.string().optional().describe('Comma-separated relation field names to expand') })`;
|
|
189
|
+
function generateContentRoutes(contentType) {
|
|
190
|
+
const sVar = schemaVar(contentType.name);
|
|
191
|
+
const label = contentType.label;
|
|
192
|
+
const tag = label;
|
|
193
|
+
const lines = [];
|
|
194
|
+
if (!contentType.only_one) {
|
|
195
|
+
const collPath = contentType.api.collection_path;
|
|
196
|
+
const itemPath = contentType.api.item_path;
|
|
197
|
+
lines.push(
|
|
198
|
+
`export const ${routeVar("get", contentType.name, "List")} = createRoute({
|
|
199
|
+
method: 'get',
|
|
200
|
+
path: '${collPath}',
|
|
201
|
+
tags: [${JSON.stringify(tag)}],
|
|
202
|
+
request: {
|
|
203
|
+
query: ${PUBLIC_LIST_QUERY},
|
|
204
|
+
},
|
|
205
|
+
responses: {
|
|
206
|
+
200: {
|
|
207
|
+
content: { 'application/json': { schema: listResponseSchema(${sVar}) } },
|
|
208
|
+
description: 'List of ${label}',
|
|
209
|
+
},
|
|
210
|
+
400: {
|
|
211
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
212
|
+
description: 'Invalid query parameters',
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
})`
|
|
216
|
+
);
|
|
217
|
+
lines.push(
|
|
218
|
+
`export const ${routeVar("get", contentType.name, "")} = createRoute({
|
|
219
|
+
method: 'get',
|
|
220
|
+
path: '${openApiPath(itemPath)}',
|
|
221
|
+
tags: [${JSON.stringify(tag)}],
|
|
222
|
+
request: {
|
|
223
|
+
params: ${SLUG_PARAMS},
|
|
224
|
+
query: ${INCLUDE_QUERY},
|
|
225
|
+
},
|
|
226
|
+
responses: {
|
|
227
|
+
200: {
|
|
228
|
+
content: { 'application/json': { schema: itemResponseSchema(${sVar}) } },
|
|
229
|
+
description: '${label}',
|
|
230
|
+
},
|
|
231
|
+
404: {
|
|
232
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
233
|
+
description: '${label} not found',
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
})`
|
|
237
|
+
);
|
|
238
|
+
const adminCollPath = "/admin" + collPath;
|
|
239
|
+
const adminItemPath = adminCollPath + "/{id}";
|
|
240
|
+
lines.push(
|
|
241
|
+
`export const ${routeVar("adminGet", contentType.name, "List")} = createRoute({
|
|
242
|
+
method: 'get',
|
|
243
|
+
path: '${adminCollPath}',
|
|
244
|
+
tags: [${JSON.stringify(tag)}],
|
|
245
|
+
request: {
|
|
246
|
+
query: ${ADMIN_LIST_QUERY},
|
|
247
|
+
},
|
|
248
|
+
responses: {
|
|
249
|
+
200: {
|
|
250
|
+
content: { 'application/json': { schema: listResponseSchema(${sVar}) } },
|
|
251
|
+
description: 'List of ${label}',
|
|
252
|
+
},
|
|
253
|
+
400: {
|
|
254
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
255
|
+
description: 'Invalid query parameters',
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
})`
|
|
259
|
+
);
|
|
260
|
+
lines.push(
|
|
261
|
+
`export const ${routeVar("adminGet", contentType.name, "")} = createRoute({
|
|
262
|
+
method: 'get',
|
|
263
|
+
path: '${adminItemPath}',
|
|
264
|
+
tags: [${JSON.stringify(tag)}],
|
|
265
|
+
request: {
|
|
266
|
+
params: ${ID_PARAMS},
|
|
267
|
+
query: ${INCLUDE_QUERY},
|
|
268
|
+
},
|
|
269
|
+
responses: {
|
|
270
|
+
200: {
|
|
271
|
+
content: { 'application/json': { schema: itemResponseSchema(${sVar}) } },
|
|
272
|
+
description: '${label}',
|
|
273
|
+
},
|
|
274
|
+
404: {
|
|
275
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
276
|
+
description: '${label} not found',
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
})`
|
|
280
|
+
);
|
|
281
|
+
lines.push(
|
|
282
|
+
`export const ${routeVar("adminCreate", contentType.name, "")} = createRoute({
|
|
283
|
+
method: 'post',
|
|
284
|
+
path: '${adminCollPath}',
|
|
285
|
+
tags: [${JSON.stringify(tag)}],
|
|
286
|
+
request: {
|
|
287
|
+
body: {
|
|
288
|
+
content: { 'application/json': { schema: ${sVar} } },
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
responses: {
|
|
292
|
+
201: {
|
|
293
|
+
content: { 'application/json': { schema: itemResponseSchema(${sVar}) } },
|
|
294
|
+
description: '${label} created',
|
|
295
|
+
},
|
|
296
|
+
422: {
|
|
297
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
298
|
+
description: 'Validation error',
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
})`
|
|
302
|
+
);
|
|
303
|
+
lines.push(
|
|
304
|
+
`export const ${routeVar("adminUpdate", contentType.name, "")} = createRoute({
|
|
305
|
+
method: 'patch',
|
|
306
|
+
path: '${adminItemPath}',
|
|
307
|
+
tags: [${JSON.stringify(tag)}],
|
|
308
|
+
request: {
|
|
309
|
+
params: ${ID_PARAMS},
|
|
310
|
+
body: {
|
|
311
|
+
content: { 'application/json': { schema: ${sVar}.partial().extend({ published: z.boolean().optional() }) } },
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
responses: {
|
|
315
|
+
200: {
|
|
316
|
+
content: { 'application/json': { schema: itemResponseSchema(${sVar}) } },
|
|
317
|
+
description: '${label} updated',
|
|
318
|
+
},
|
|
319
|
+
404: {
|
|
320
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
321
|
+
description: '${label} not found',
|
|
322
|
+
},
|
|
323
|
+
422: {
|
|
324
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
325
|
+
description: 'Validation error',
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
})`
|
|
329
|
+
);
|
|
330
|
+
lines.push(
|
|
331
|
+
`export const ${routeVar("adminDelete", contentType.name, "")} = createRoute({
|
|
332
|
+
method: 'delete',
|
|
333
|
+
path: '${adminItemPath}',
|
|
334
|
+
tags: [${JSON.stringify(tag)}],
|
|
335
|
+
request: {
|
|
336
|
+
params: ${ID_PARAMS},
|
|
337
|
+
},
|
|
338
|
+
responses: {
|
|
339
|
+
200: {
|
|
340
|
+
content: { 'application/json': { schema: z.object({ ok: z.literal(true) }) } },
|
|
341
|
+
description: '${label} deleted',
|
|
342
|
+
},
|
|
343
|
+
404: {
|
|
344
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
345
|
+
description: '${label} not found',
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
})`
|
|
349
|
+
);
|
|
350
|
+
} else {
|
|
351
|
+
const itemPath = contentType.api.item_path;
|
|
352
|
+
const adminItemBase = "/admin" + itemPath;
|
|
353
|
+
const adminPatchPath = "/admin/api/" + contentType.default_base_path + "/{id}";
|
|
354
|
+
lines.push(
|
|
355
|
+
`export const ${routeVar("get", contentType.name, "")} = createRoute({
|
|
356
|
+
method: 'get',
|
|
357
|
+
path: '${itemPath}',
|
|
358
|
+
tags: [${JSON.stringify(tag)}],
|
|
359
|
+
request: {
|
|
360
|
+
query: ${INCLUDE_QUERY},
|
|
361
|
+
},
|
|
362
|
+
responses: {
|
|
363
|
+
200: {
|
|
364
|
+
content: { 'application/json': { schema: itemResponseSchema(${sVar}) } },
|
|
365
|
+
description: '${label}',
|
|
366
|
+
},
|
|
367
|
+
404: {
|
|
368
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
369
|
+
description: '${label} not found',
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
})`
|
|
373
|
+
);
|
|
374
|
+
lines.push(
|
|
375
|
+
`export const ${routeVar("adminGet", contentType.name, "")} = createRoute({
|
|
376
|
+
method: 'get',
|
|
377
|
+
path: '${adminItemBase}',
|
|
378
|
+
tags: [${JSON.stringify(tag)}],
|
|
379
|
+
request: {
|
|
380
|
+
query: ${INCLUDE_QUERY},
|
|
381
|
+
},
|
|
382
|
+
responses: {
|
|
383
|
+
200: {
|
|
384
|
+
content: { 'application/json': { schema: itemResponseSchema(${sVar}) } },
|
|
385
|
+
description: '${label}',
|
|
386
|
+
},
|
|
387
|
+
404: {
|
|
388
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
389
|
+
description: '${label} not found',
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
})`
|
|
393
|
+
);
|
|
394
|
+
const adminPostPath = "/admin/api/" + contentType.default_base_path;
|
|
395
|
+
lines.push(
|
|
396
|
+
`export const ${routeVar("adminCreate", contentType.name, "")} = createRoute({
|
|
397
|
+
method: 'post',
|
|
398
|
+
path: '${adminPostPath}',
|
|
399
|
+
tags: [${JSON.stringify(tag)}],
|
|
400
|
+
request: {
|
|
401
|
+
body: {
|
|
402
|
+
content: { 'application/json': { schema: ${sVar} } },
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
responses: {
|
|
406
|
+
201: {
|
|
407
|
+
content: { 'application/json': { schema: itemResponseSchema(${sVar}) } },
|
|
408
|
+
description: '${label} created',
|
|
409
|
+
},
|
|
410
|
+
409: {
|
|
411
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
412
|
+
description: 'Singleton already exists',
|
|
413
|
+
},
|
|
414
|
+
422: {
|
|
415
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
416
|
+
description: 'Validation error',
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
})`
|
|
420
|
+
);
|
|
421
|
+
lines.push(
|
|
422
|
+
`export const ${routeVar("adminUpdate", contentType.name, "")} = createRoute({
|
|
423
|
+
method: 'patch',
|
|
424
|
+
path: '${adminPatchPath}',
|
|
425
|
+
tags: [${JSON.stringify(tag)}],
|
|
426
|
+
request: {
|
|
427
|
+
params: ${ID_PARAMS},
|
|
428
|
+
body: {
|
|
429
|
+
content: { 'application/json': { schema: ${sVar}.partial().extend({ published: z.boolean().optional() }) } },
|
|
430
|
+
},
|
|
431
|
+
},
|
|
432
|
+
responses: {
|
|
433
|
+
200: {
|
|
434
|
+
content: { 'application/json': { schema: itemResponseSchema(${sVar}) } },
|
|
435
|
+
description: '${label} updated',
|
|
436
|
+
},
|
|
437
|
+
404: {
|
|
438
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
439
|
+
description: '${label} not found',
|
|
440
|
+
},
|
|
441
|
+
422: {
|
|
442
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
443
|
+
description: 'Validation error',
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
})`
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
return lines.join("\n\n");
|
|
450
|
+
}
|
|
451
|
+
function generateTaxonomyRoutes(taxonomyType) {
|
|
452
|
+
const sVar = schemaVar(taxonomyType.name);
|
|
453
|
+
const label = taxonomyType.label;
|
|
454
|
+
const tag = label;
|
|
455
|
+
const collPath = taxonomyType.api.collection_path;
|
|
456
|
+
const itemPath = taxonomyType.api.item_path;
|
|
457
|
+
const adminCollPath = "/admin" + collPath;
|
|
458
|
+
const adminItemPath = "/admin" + openApiPath(itemPath);
|
|
459
|
+
const lines = [];
|
|
460
|
+
lines.push(
|
|
461
|
+
`export const ${routeVar("get", taxonomyType.name, "List")} = createRoute({
|
|
462
|
+
method: 'get',
|
|
463
|
+
path: '${collPath}',
|
|
464
|
+
tags: [${JSON.stringify(tag)}],
|
|
465
|
+
request: {
|
|
466
|
+
query: ${PUBLIC_LIST_QUERY},
|
|
467
|
+
},
|
|
468
|
+
responses: {
|
|
469
|
+
200: {
|
|
470
|
+
content: { 'application/json': { schema: listResponseSchema(${sVar}) } },
|
|
471
|
+
description: 'List of ${label}',
|
|
472
|
+
},
|
|
473
|
+
400: {
|
|
474
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
475
|
+
description: 'Invalid query parameters',
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
})`
|
|
479
|
+
);
|
|
480
|
+
lines.push(
|
|
481
|
+
`export const ${routeVar("get", taxonomyType.name, "")} = createRoute({
|
|
482
|
+
method: 'get',
|
|
483
|
+
path: '${openApiPath(itemPath)}',
|
|
484
|
+
tags: [${JSON.stringify(tag)}],
|
|
485
|
+
request: {
|
|
486
|
+
params: ${ID_PARAMS},
|
|
487
|
+
query: ${INCLUDE_QUERY},
|
|
488
|
+
},
|
|
489
|
+
responses: {
|
|
490
|
+
200: {
|
|
491
|
+
content: { 'application/json': { schema: itemResponseSchema(${sVar}) } },
|
|
492
|
+
description: '${label}',
|
|
493
|
+
},
|
|
494
|
+
404: {
|
|
495
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
496
|
+
description: '${label} not found',
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
})`
|
|
500
|
+
);
|
|
501
|
+
lines.push(
|
|
502
|
+
`export const ${routeVar("adminGet", taxonomyType.name, "List")} = createRoute({
|
|
503
|
+
method: 'get',
|
|
504
|
+
path: '${adminCollPath}',
|
|
505
|
+
tags: [${JSON.stringify(tag)}],
|
|
506
|
+
request: {
|
|
507
|
+
query: ${ADMIN_LIST_QUERY},
|
|
508
|
+
},
|
|
509
|
+
responses: {
|
|
510
|
+
200: {
|
|
511
|
+
content: { 'application/json': { schema: listResponseSchema(${sVar}) } },
|
|
512
|
+
description: 'List of ${label}',
|
|
513
|
+
},
|
|
514
|
+
400: {
|
|
515
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
516
|
+
description: 'Invalid query parameters',
|
|
517
|
+
},
|
|
518
|
+
},
|
|
519
|
+
})`
|
|
520
|
+
);
|
|
521
|
+
lines.push(
|
|
522
|
+
`export const ${routeVar("adminGet", taxonomyType.name, "")} = createRoute({
|
|
523
|
+
method: 'get',
|
|
524
|
+
path: '${adminItemPath}',
|
|
525
|
+
tags: [${JSON.stringify(tag)}],
|
|
526
|
+
request: {
|
|
527
|
+
params: ${ID_PARAMS},
|
|
528
|
+
query: ${INCLUDE_QUERY},
|
|
529
|
+
},
|
|
530
|
+
responses: {
|
|
531
|
+
200: {
|
|
532
|
+
content: { 'application/json': { schema: itemResponseSchema(${sVar}) } },
|
|
533
|
+
description: '${label}',
|
|
534
|
+
},
|
|
535
|
+
404: {
|
|
536
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
537
|
+
description: '${label} not found',
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
})`
|
|
541
|
+
);
|
|
542
|
+
lines.push(
|
|
543
|
+
`export const ${routeVar("adminCreate", taxonomyType.name, "")} = createRoute({
|
|
544
|
+
method: 'post',
|
|
545
|
+
path: '${adminCollPath}',
|
|
546
|
+
tags: [${JSON.stringify(tag)}],
|
|
547
|
+
request: {
|
|
548
|
+
body: {
|
|
549
|
+
content: { 'application/json': { schema: ${sVar} } },
|
|
550
|
+
},
|
|
551
|
+
},
|
|
552
|
+
responses: {
|
|
553
|
+
201: {
|
|
554
|
+
content: { 'application/json': { schema: itemResponseSchema(${sVar}) } },
|
|
555
|
+
description: '${label} created',
|
|
556
|
+
},
|
|
557
|
+
422: {
|
|
558
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
559
|
+
description: 'Validation error',
|
|
560
|
+
},
|
|
561
|
+
},
|
|
562
|
+
})`
|
|
563
|
+
);
|
|
564
|
+
lines.push(
|
|
565
|
+
`export const ${routeVar("adminUpdate", taxonomyType.name, "")} = createRoute({
|
|
566
|
+
method: 'patch',
|
|
567
|
+
path: '${adminItemPath}',
|
|
568
|
+
tags: [${JSON.stringify(tag)}],
|
|
569
|
+
request: {
|
|
570
|
+
params: ${ID_PARAMS},
|
|
571
|
+
body: {
|
|
572
|
+
content: { 'application/json': { schema: ${sVar}.partial().extend({ published: z.boolean().optional() }) } },
|
|
573
|
+
},
|
|
574
|
+
},
|
|
575
|
+
responses: {
|
|
576
|
+
200: {
|
|
577
|
+
content: { 'application/json': { schema: itemResponseSchema(${sVar}) } },
|
|
578
|
+
description: '${label} updated',
|
|
579
|
+
},
|
|
580
|
+
404: {
|
|
581
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
582
|
+
description: '${label} not found',
|
|
583
|
+
},
|
|
584
|
+
422: {
|
|
585
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
586
|
+
description: 'Validation error',
|
|
587
|
+
},
|
|
588
|
+
},
|
|
589
|
+
})`
|
|
590
|
+
);
|
|
591
|
+
lines.push(
|
|
592
|
+
`export const ${routeVar("adminDelete", taxonomyType.name, "")} = createRoute({
|
|
593
|
+
method: 'delete',
|
|
594
|
+
path: '${adminItemPath}',
|
|
595
|
+
tags: [${JSON.stringify(tag)}],
|
|
596
|
+
request: {
|
|
597
|
+
params: ${ID_PARAMS},
|
|
598
|
+
},
|
|
599
|
+
responses: {
|
|
600
|
+
200: {
|
|
601
|
+
content: { 'application/json': { schema: z.object({ ok: z.literal(true) }) } },
|
|
602
|
+
description: '${label} deleted',
|
|
603
|
+
},
|
|
604
|
+
404: {
|
|
605
|
+
content: { 'application/json': { schema: ErrorResponseSchema } },
|
|
606
|
+
description: '${label} not found',
|
|
607
|
+
},
|
|
608
|
+
},
|
|
609
|
+
})`
|
|
610
|
+
);
|
|
611
|
+
return lines.join("\n\n");
|
|
612
|
+
}
|
|
613
|
+
function generateRoutes(registry) {
|
|
614
|
+
const parts = [];
|
|
615
|
+
parts.push("// Auto-generated by generateRoutes() \u2014 do not hand-edit");
|
|
616
|
+
parts.push("import { createRoute, z } from '@hono/zod-openapi'");
|
|
617
|
+
parts.push("");
|
|
618
|
+
parts.push("// \u2500\u2500\u2500 Shared schemas \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
619
|
+
parts.push("");
|
|
620
|
+
parts.push(SHARED_SCHEMAS_BLOCK);
|
|
621
|
+
parts.push("");
|
|
622
|
+
const paragraphEntries = Object.entries(registry.paragraph_types);
|
|
623
|
+
if (paragraphEntries.length > 0) {
|
|
624
|
+
parts.push("// \u2500\u2500\u2500 Paragraph schemas \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
625
|
+
parts.push("");
|
|
626
|
+
for (const [, paragraphType] of paragraphEntries) {
|
|
627
|
+
parts.push(generateParagraphSchemaDecl(paragraphType, registry));
|
|
628
|
+
}
|
|
629
|
+
parts.push("");
|
|
630
|
+
}
|
|
631
|
+
const contentEntries = Object.entries(registry.content_types);
|
|
632
|
+
if (contentEntries.length > 0) {
|
|
633
|
+
parts.push("// \u2500\u2500\u2500 Content type schemas \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
634
|
+
parts.push("");
|
|
635
|
+
for (const [, contentType] of contentEntries) {
|
|
636
|
+
parts.push(generateContentSchema(contentType, registry));
|
|
637
|
+
parts.push("");
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
const taxonomyEntries = Object.entries(registry.taxonomy_types);
|
|
641
|
+
if (taxonomyEntries.length > 0) {
|
|
642
|
+
parts.push("// \u2500\u2500\u2500 Taxonomy type schemas \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
643
|
+
parts.push("");
|
|
644
|
+
for (const [, taxonomyType] of taxonomyEntries) {
|
|
645
|
+
parts.push(generateContentSchema(taxonomyType, registry));
|
|
646
|
+
parts.push("");
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
if (contentEntries.length > 0) {
|
|
650
|
+
parts.push("// \u2500\u2500\u2500 Content routes \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
651
|
+
parts.push("");
|
|
652
|
+
for (const [, contentType] of contentEntries) {
|
|
653
|
+
parts.push(generateContentRoutes(contentType));
|
|
654
|
+
parts.push("");
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
if (taxonomyEntries.length > 0) {
|
|
658
|
+
parts.push("// \u2500\u2500\u2500 Taxonomy routes \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
659
|
+
parts.push("");
|
|
660
|
+
for (const [, taxonomyType] of taxonomyEntries) {
|
|
661
|
+
parts.push(generateTaxonomyRoutes(taxonomyType));
|
|
662
|
+
parts.push("");
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
return parts.join("\n");
|
|
666
|
+
}
|
|
667
|
+
export {
|
|
668
|
+
fieldToZodSchema,
|
|
669
|
+
generateContentSchema,
|
|
670
|
+
generateRoutes
|
|
671
|
+
};
|
|
672
|
+
//# sourceMappingURL=index.mjs.map
|