hono-takibi 0.9.51 → 0.9.52
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/cli/index.js +5 -10
- package/dist/config/index.js +1 -2
- package/dist/core/route.js +1 -2
- package/dist/core/rpc.js +21 -16
- package/dist/core/schema.js +13 -23
- package/dist/core/takibi.js +14 -40
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -72,9 +72,8 @@ export async function honoTakibi() {
|
|
|
72
72
|
return { ok: false, error: cliResult.error };
|
|
73
73
|
const cli = cliResult.value;
|
|
74
74
|
const takibiResult = await takibi(cli.input, cli.output, cli.exportSchema ?? false, cli.exportType ?? false, cli.template ?? false, cli.test ?? false, cli.basePath);
|
|
75
|
-
if (!takibiResult.ok)
|
|
75
|
+
if (!takibiResult.ok)
|
|
76
76
|
return { ok: false, error: takibiResult.error };
|
|
77
|
-
}
|
|
78
77
|
return {
|
|
79
78
|
ok: true,
|
|
80
79
|
value: takibiResult.value,
|
|
@@ -91,30 +90,26 @@ export async function honoTakibi() {
|
|
|
91
90
|
? await takibi(c.input, c['zod-openapi']?.output, c['zod-openapi']?.exportSchema ?? false, c['zod-openapi']?.exportType ?? false, false, // template
|
|
92
91
|
false)
|
|
93
92
|
: undefined;
|
|
94
|
-
if (takibiResult && !takibiResult.ok)
|
|
93
|
+
if (takibiResult && !takibiResult.ok)
|
|
95
94
|
return { ok: false, error: takibiResult.error };
|
|
96
|
-
}
|
|
97
95
|
/** schema */
|
|
98
96
|
const schemaResult = c['zod-openapi']?.schema
|
|
99
97
|
? await schema(c.input, c['zod-openapi'].schema.output, c['zod-openapi'].schema.exportType ?? false, c['zod-openapi']?.schema.split ?? false)
|
|
100
98
|
: undefined;
|
|
101
|
-
if (schemaResult && !schemaResult.ok)
|
|
99
|
+
if (schemaResult && !schemaResult.ok)
|
|
102
100
|
return { ok: false, error: schemaResult.error };
|
|
103
|
-
}
|
|
104
101
|
/** route */
|
|
105
102
|
const routeResult = c['zod-openapi']?.route
|
|
106
103
|
? await route(c.input, c['zod-openapi'].route.output, c['zod-openapi'].route.import, c['zod-openapi'].route.split ?? false)
|
|
107
104
|
: undefined;
|
|
108
|
-
if (routeResult && !routeResult.ok)
|
|
105
|
+
if (routeResult && !routeResult.ok)
|
|
109
106
|
return { ok: false, error: routeResult.error };
|
|
110
|
-
}
|
|
111
107
|
/** rpc */
|
|
112
108
|
const rpcResult = c.rpc
|
|
113
109
|
? await rpc(c.input, c.rpc.output, c.rpc.import, c.rpc.split ?? false)
|
|
114
110
|
: undefined;
|
|
115
|
-
if (rpcResult && !rpcResult.ok)
|
|
111
|
+
if (rpcResult && !rpcResult.ok)
|
|
116
112
|
return { ok: false, error: rpcResult.error };
|
|
117
|
-
}
|
|
118
113
|
const results = [takibiResult?.value, rpcResult?.value].filter((v) => Boolean(v));
|
|
119
114
|
return {
|
|
120
115
|
ok: true,
|
package/dist/config/index.js
CHANGED
|
@@ -11,9 +11,8 @@ export async function config() {
|
|
|
11
11
|
register();
|
|
12
12
|
const url = pathToFileURL(abs).href;
|
|
13
13
|
const mod = await import(/* @vite-ignore */ url);
|
|
14
|
-
if (!('default' in mod) || mod.default === undefined)
|
|
14
|
+
if (!('default' in mod) || mod.default === undefined)
|
|
15
15
|
return { ok: false, error: 'Config must export default object' };
|
|
16
|
-
}
|
|
17
16
|
const result = parseConfig(mod.default);
|
|
18
17
|
if (!result.ok)
|
|
19
18
|
return { ok: false, error: result.error };
|
package/dist/core/route.js
CHANGED
|
@@ -24,9 +24,8 @@ const extractRouteBlocks = (src) => {
|
|
|
24
24
|
const lowerFirst = (s) => (s ? s.charAt(0).toLowerCase() + s.slice(1) : s);
|
|
25
25
|
export async function route(input, output, importPath, split) {
|
|
26
26
|
const openAPIResult = await parseOpenAPI(input);
|
|
27
|
-
if (!openAPIResult.ok)
|
|
27
|
+
if (!openAPIResult.ok)
|
|
28
28
|
return { ok: false, error: openAPIResult.error };
|
|
29
|
-
}
|
|
30
29
|
const openAPI = openAPIResult.value;
|
|
31
30
|
const routesSrc = routeCode(openAPI.paths);
|
|
32
31
|
if (!split) {
|
package/dist/core/rpc.js
CHANGED
|
@@ -236,9 +236,15 @@ const generateOperationCode = (pathStr, method, item, deps) => {
|
|
|
236
236
|
: `${deps.client}${clientAccess}.$${method}()`;
|
|
237
237
|
const summary = typeof op.summary === 'string' ? op.summary : '';
|
|
238
238
|
const description = typeof op.description === 'string' ? op.description : '';
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
239
|
+
const docs = [
|
|
240
|
+
'/**',
|
|
241
|
+
` * ${method.toUpperCase()} ${pathStr}`,
|
|
242
|
+
...(summary ? [' *', ` * ${summary.trimEnd()}`] : []),
|
|
243
|
+
...(description ? [' *', ` * ${description.trimEnd()}`] : []),
|
|
244
|
+
' */',
|
|
245
|
+
].join('\n');
|
|
246
|
+
const func = `export async function ${funcName}(${argSig}){return await ${call}}`;
|
|
247
|
+
return `${docs}\n${func}`;
|
|
242
248
|
};
|
|
243
249
|
/* ─────────────────────────────── Split ─────────────────────────────── */
|
|
244
250
|
const resolveSplitOutDir = (output) => {
|
|
@@ -256,9 +262,8 @@ const resolveSplitOutDir = (output) => {
|
|
|
256
262
|
*/
|
|
257
263
|
export async function rpc(input, output, importPath, split) {
|
|
258
264
|
const openAPIResult = await parseOpenAPI(input);
|
|
259
|
-
if (!openAPIResult.ok)
|
|
265
|
+
if (!openAPIResult.ok)
|
|
260
266
|
return { ok: false, error: openAPIResult.error };
|
|
261
|
-
}
|
|
262
267
|
const openAPI = openAPIResult.value;
|
|
263
268
|
const client = 'client';
|
|
264
269
|
const s = `import { client } from '${importPath}'`;
|
|
@@ -309,12 +314,12 @@ export async function rpc(input, output, importPath, split) {
|
|
|
309
314
|
return { ok: false, error: fmtResult.error };
|
|
310
315
|
const { outDir } = resolveSplitOutDir(output);
|
|
311
316
|
const filePath = path.join(outDir, `${funcName}.ts`);
|
|
312
|
-
const
|
|
313
|
-
if (!
|
|
314
|
-
return { ok: false, error:
|
|
315
|
-
const
|
|
316
|
-
if (!
|
|
317
|
-
return { ok: false, error:
|
|
317
|
+
const mkdirResult = await mkdir(path.dirname(filePath));
|
|
318
|
+
if (!mkdirResult.ok)
|
|
319
|
+
return { ok: false, error: mkdirResult.error };
|
|
320
|
+
const writeResult = await writeFile(filePath, fmtResult.value);
|
|
321
|
+
if (!writeResult.ok)
|
|
322
|
+
return { ok: false, error: writeResult.error };
|
|
318
323
|
splitExports.add(`export * from './${funcName}'`);
|
|
319
324
|
}
|
|
320
325
|
else {
|
|
@@ -324,9 +329,9 @@ export async function rpc(input, output, importPath, split) {
|
|
|
324
329
|
}
|
|
325
330
|
// Non-split: write single file
|
|
326
331
|
if (!split) {
|
|
327
|
-
const
|
|
328
|
-
if (!
|
|
329
|
-
return { ok: false, error:
|
|
332
|
+
const mkdirResult = await mkdir(path.dirname(output));
|
|
333
|
+
if (!mkdirResult.ok)
|
|
334
|
+
return { ok: false, error: mkdirResult.error };
|
|
330
335
|
const code = `${header}${combinedOut.join('\n\n')}${combinedOut.length ? '\n' : ''}`;
|
|
331
336
|
const fmtResult = await fmt(code);
|
|
332
337
|
if (!fmtResult.ok)
|
|
@@ -338,8 +343,8 @@ export async function rpc(input, output, importPath, split) {
|
|
|
338
343
|
}
|
|
339
344
|
// Split: write index.ts (barrel)
|
|
340
345
|
const { outDir, indexPath } = resolveSplitOutDir(output);
|
|
341
|
-
const
|
|
342
|
-
const fmtResult = await fmt(
|
|
346
|
+
const index = `${Array.from(splitExports).sort().join('\n')}\n`;
|
|
347
|
+
const fmtResult = await fmt(index);
|
|
343
348
|
if (!fmtResult.ok)
|
|
344
349
|
return { ok: false, error: fmtResult.error };
|
|
345
350
|
const mkdirResult = await mkdir(path.dirname(indexPath));
|
package/dist/core/schema.js
CHANGED
|
@@ -43,9 +43,8 @@ export async function schema(input, output, exportType, split) {
|
|
|
43
43
|
}
|
|
44
44
|
const openAPI = openAPIResult.value;
|
|
45
45
|
const { schemas } = openAPI.components ? openAPI.components : {};
|
|
46
|
-
if (!schemas)
|
|
46
|
+
if (!schemas)
|
|
47
47
|
return { ok: false, error: 'No schemas found' };
|
|
48
|
-
}
|
|
49
48
|
// split
|
|
50
49
|
if (split) {
|
|
51
50
|
const outDir = output.replace(/\.ts$/, '');
|
|
@@ -60,37 +59,31 @@ export async function schema(input, output, exportType, split) {
|
|
|
60
59
|
? deps.map((d) => `import { ${d}Schema } from './${lowerFirst(d)}'`).join('\n')
|
|
61
60
|
: '';
|
|
62
61
|
const fileCode = [importZ, depImports, '\n', zs].filter(Boolean).join('\n');
|
|
62
|
+
const filePath = `${outDir}/${lowerFirst(schemaName)}.ts`;
|
|
63
63
|
const fmtResult = await fmt(fileCode);
|
|
64
|
-
if (!fmtResult.ok)
|
|
64
|
+
if (!fmtResult.ok)
|
|
65
65
|
return { ok: false, error: fmtResult.error };
|
|
66
|
-
}
|
|
67
|
-
const filePath = `${outDir}/${lowerFirst(schemaName)}.ts`;
|
|
68
66
|
const mkdirResult = await mkdir(path.dirname(filePath));
|
|
69
|
-
if (!mkdirResult.ok)
|
|
67
|
+
if (!mkdirResult.ok)
|
|
70
68
|
return { ok: false, error: mkdirResult.error };
|
|
71
|
-
}
|
|
72
69
|
const writeResult = await writeFile(filePath, fmtResult.value);
|
|
73
|
-
if (!writeResult.ok)
|
|
70
|
+
if (!writeResult.ok)
|
|
74
71
|
return { ok: false, error: writeResult.error };
|
|
75
|
-
}
|
|
76
72
|
}
|
|
77
73
|
// index.ts
|
|
78
|
-
const
|
|
74
|
+
const index = `${Object.keys(schemas)
|
|
79
75
|
.sort()
|
|
80
76
|
.map((n) => `export * from './${lowerFirst(n)}'`)
|
|
81
77
|
.join('\n')}\n`;
|
|
82
|
-
const fmtResult = await fmt(
|
|
83
|
-
if (!fmtResult.ok)
|
|
78
|
+
const fmtResult = await fmt(index);
|
|
79
|
+
if (!fmtResult.ok)
|
|
84
80
|
return { ok: false, error: fmtResult.error };
|
|
85
|
-
}
|
|
86
81
|
const mkdirResult = await mkdir(path.dirname(`${outDir}/index.ts`));
|
|
87
|
-
if (!mkdirResult.ok)
|
|
82
|
+
if (!mkdirResult.ok)
|
|
88
83
|
return { ok: false, error: mkdirResult.error };
|
|
89
|
-
}
|
|
90
84
|
const writeResult = await writeFile(`${outDir}/index.ts`, fmtResult.value);
|
|
91
|
-
if (!writeResult.ok)
|
|
85
|
+
if (!writeResult.ok)
|
|
92
86
|
return { ok: false, error: writeResult.error };
|
|
93
|
-
}
|
|
94
87
|
return {
|
|
95
88
|
ok: true,
|
|
96
89
|
value: `Generated schema code written to ${outDir}/*.ts (index.ts included)`,
|
|
@@ -110,16 +103,13 @@ export async function schema(input, output, exportType, split) {
|
|
|
110
103
|
const importCode = `import { z } from '@hono/zod-openapi'`;
|
|
111
104
|
const schemaDefinitionsCode = `${importCode}\n\n${schemaDefinitions}`;
|
|
112
105
|
const fmtResult = await fmt(schemaDefinitionsCode);
|
|
113
|
-
if (!fmtResult.ok)
|
|
106
|
+
if (!fmtResult.ok)
|
|
114
107
|
return { ok: false, error: fmtResult.error };
|
|
115
|
-
}
|
|
116
108
|
const mkdirResult = await mkdir(path.dirname(output));
|
|
117
|
-
if (!mkdirResult.ok)
|
|
109
|
+
if (!mkdirResult.ok)
|
|
118
110
|
return { ok: false, error: mkdirResult.error };
|
|
119
|
-
}
|
|
120
111
|
const writeResult = await writeFile(output, fmtResult.value);
|
|
121
|
-
if (!writeResult.ok)
|
|
112
|
+
if (!writeResult.ok)
|
|
122
113
|
return { ok: false, error: writeResult.error };
|
|
123
|
-
}
|
|
124
114
|
return { ok: true, value: `Generated schema code written to ${output}` };
|
|
125
115
|
}
|
package/dist/core/takibi.js
CHANGED
|
@@ -54,42 +54,34 @@ import { isHttpMethod, methodPath } from '../utils/index.js';
|
|
|
54
54
|
*/
|
|
55
55
|
export async function takibi(input, output, exportSchema, exportType, template, test, basePath) {
|
|
56
56
|
const openAPIResult = await parseOpenAPI(input);
|
|
57
|
-
if (!openAPIResult.ok)
|
|
57
|
+
if (!openAPIResult.ok)
|
|
58
58
|
return { ok: false, error: openAPIResult.error };
|
|
59
|
-
}
|
|
60
59
|
const openAPI = openAPIResult.value;
|
|
61
60
|
const honoResult = await fmt(zodOpenAPIHono(openAPI, exportSchema, exportType));
|
|
62
|
-
if (!honoResult.ok)
|
|
61
|
+
if (!honoResult.ok)
|
|
63
62
|
return { ok: false, error: honoResult.error };
|
|
64
|
-
}
|
|
65
63
|
const mkdirResult = await mkdir(path.dirname(output));
|
|
66
|
-
if (!mkdirResult.ok)
|
|
64
|
+
if (!mkdirResult.ok)
|
|
67
65
|
return { ok: false, error: mkdirResult.error };
|
|
68
|
-
}
|
|
69
66
|
const writeResult = await writeFile(output, honoResult.value);
|
|
70
|
-
if (!writeResult.ok)
|
|
67
|
+
if (!writeResult.ok)
|
|
71
68
|
return { ok: false, error: writeResult.error };
|
|
72
|
-
}
|
|
73
69
|
/** template */
|
|
74
70
|
if (template && output.includes('/')) {
|
|
75
71
|
const appResult = await fmt(app(openAPI, output, basePath));
|
|
76
|
-
if (!appResult.ok)
|
|
72
|
+
if (!appResult.ok)
|
|
77
73
|
return { ok: false, error: appResult.error };
|
|
78
|
-
}
|
|
79
74
|
const dir = path.dirname(output);
|
|
80
75
|
const readdirResult = await readdir(dir);
|
|
81
|
-
if (!readdirResult.ok)
|
|
76
|
+
if (!readdirResult.ok)
|
|
82
77
|
return { ok: false, error: readdirResult.error };
|
|
83
|
-
}
|
|
84
78
|
const target = path.join(dir, 'index.ts');
|
|
85
79
|
const writeResult = await writeFile(target, appResult.value);
|
|
86
|
-
if (!writeResult.ok)
|
|
80
|
+
if (!writeResult.ok)
|
|
87
81
|
return { ok: false, error: writeResult.error };
|
|
88
|
-
}
|
|
89
82
|
const zodOpenapiHonoHandlerResult = await zodOpenapiHonoHandler(openAPI, output, test);
|
|
90
|
-
if (!zodOpenapiHonoHandlerResult.ok)
|
|
83
|
+
if (!zodOpenapiHonoHandlerResult.ok)
|
|
91
84
|
return { ok: false, error: zodOpenapiHonoHandlerResult.error };
|
|
92
|
-
}
|
|
93
85
|
return { ok: true, value: 'Generated code and template files written' };
|
|
94
86
|
}
|
|
95
87
|
return {
|
|
@@ -156,10 +148,7 @@ async function zodOpenapiHonoHandler(openapi, output, test) {
|
|
|
156
148
|
const importFrom = `../${routeEntryBasename.replace(/\.ts$/, '')}`;
|
|
157
149
|
const mkdirResult = await mkdir(handlerPath);
|
|
158
150
|
if (!mkdirResult.ok)
|
|
159
|
-
return {
|
|
160
|
-
ok: false,
|
|
161
|
-
error: mkdirResult.error,
|
|
162
|
-
};
|
|
151
|
+
return { ok: false, error: mkdirResult.error };
|
|
163
152
|
for (const handler of mergedHandlers) {
|
|
164
153
|
const routeTypes = Array.from(new Set(handler.routeNames)).join(', ');
|
|
165
154
|
const importRouteTypes = routeTypes ? `import type { ${routeTypes} } from '${importFrom}';` : '';
|
|
@@ -167,38 +156,23 @@ async function zodOpenapiHonoHandler(openapi, output, test) {
|
|
|
167
156
|
const fileContent = `${importStatements}\n\n${handler.routeHandlerContents.join('\n\n')}`;
|
|
168
157
|
const fmtResult = await fmt(fileContent);
|
|
169
158
|
if (!fmtResult.ok)
|
|
170
|
-
return {
|
|
171
|
-
ok: false,
|
|
172
|
-
error: fmtResult.error,
|
|
173
|
-
};
|
|
159
|
+
return { ok: false, error: fmtResult.error };
|
|
174
160
|
const writeResult = await writeFile(`${handlerPath}/${handler.fileName}`, fmtResult.value);
|
|
175
161
|
if (!writeResult.ok)
|
|
176
|
-
return {
|
|
177
|
-
ok: false,
|
|
178
|
-
error: writeResult.error,
|
|
179
|
-
};
|
|
162
|
+
return { ok: false, error: writeResult.error };
|
|
180
163
|
if (test) {
|
|
181
164
|
const writeResult = await writeFile(`${handlerPath}/${handler.testFileName}`, '');
|
|
182
165
|
if (!writeResult.ok)
|
|
183
|
-
return {
|
|
184
|
-
ok: false,
|
|
185
|
-
error: writeResult.error,
|
|
186
|
-
};
|
|
166
|
+
return { ok: false, error: writeResult.error };
|
|
187
167
|
}
|
|
188
168
|
}
|
|
189
169
|
const sorted = mergedHandlers.map((h) => h.fileName).sort();
|
|
190
170
|
const exports = sorted.map((h) => `export * from './${h}'`).join('\n');
|
|
191
171
|
const fmtResult = await fmt(exports);
|
|
192
172
|
if (!fmtResult.ok)
|
|
193
|
-
return {
|
|
194
|
-
ok: false,
|
|
195
|
-
error: fmtResult.error,
|
|
196
|
-
};
|
|
173
|
+
return { ok: false, error: fmtResult.error };
|
|
197
174
|
const writeResult = await writeFile(`${handlerPath}/index.ts`, fmtResult.value);
|
|
198
175
|
if (!writeResult.ok)
|
|
199
|
-
return {
|
|
200
|
-
ok: false,
|
|
201
|
-
error: writeResult.error,
|
|
202
|
-
};
|
|
176
|
+
return { ok: false, error: writeResult.error };
|
|
203
177
|
return { ok: true, value: undefined };
|
|
204
178
|
}
|