hono-takibi 0.9.994 → 0.9.995
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/config/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ declare const ConfigSchema: z.ZodReadonly<z.ZodPipe<z.ZodObject<{
|
|
|
15
15
|
pathAlias: z.ZodExactOptional<z.ZodString>;
|
|
16
16
|
framework: z.ZodExactOptional<z.ZodDefault<z.ZodEnum<{
|
|
17
17
|
vitest: "vitest";
|
|
18
|
+
"vite-plus": "vite-plus";
|
|
18
19
|
bun: "bun";
|
|
19
20
|
}>>>;
|
|
20
21
|
}, z.core.$strip>>;
|
|
@@ -145,6 +146,7 @@ declare const ConfigSchema: z.ZodReadonly<z.ZodPipe<z.ZodObject<{
|
|
|
145
146
|
import: z.ZodString;
|
|
146
147
|
framework: z.ZodExactOptional<z.ZodDefault<z.ZodEnum<{
|
|
147
148
|
vitest: "vitest";
|
|
149
|
+
"vite-plus": "vite-plus";
|
|
148
150
|
bun: "bun";
|
|
149
151
|
}>>>;
|
|
150
152
|
}, z.core.$strip>>;
|
|
@@ -165,7 +167,7 @@ declare const ConfigSchema: z.ZodReadonly<z.ZodPipe<z.ZodObject<{
|
|
|
165
167
|
test: boolean;
|
|
166
168
|
routeHandler: boolean;
|
|
167
169
|
pathAlias?: string;
|
|
168
|
-
framework?: "vitest" | "bun";
|
|
170
|
+
framework?: "vitest" | "vite-plus" | "bun";
|
|
169
171
|
};
|
|
170
172
|
exportSchemas?: boolean;
|
|
171
173
|
exportSchemasTypes?: boolean;
|
|
@@ -295,7 +297,7 @@ declare const ConfigSchema: z.ZodReadonly<z.ZodPipe<z.ZodObject<{
|
|
|
295
297
|
test?: {
|
|
296
298
|
output: string;
|
|
297
299
|
import: string;
|
|
298
|
-
framework?: "vitest" | "bun";
|
|
300
|
+
framework?: "vitest" | "vite-plus" | "bun";
|
|
299
301
|
};
|
|
300
302
|
mock?: {
|
|
301
303
|
output: string;
|
|
@@ -317,7 +319,7 @@ declare const ConfigSchema: z.ZodReadonly<z.ZodPipe<z.ZodObject<{
|
|
|
317
319
|
test: boolean;
|
|
318
320
|
routeHandler: boolean;
|
|
319
321
|
pathAlias?: string;
|
|
320
|
-
framework?: "vitest" | "bun";
|
|
322
|
+
framework?: "vitest" | "vite-plus" | "bun";
|
|
321
323
|
};
|
|
322
324
|
exportSchemas?: boolean;
|
|
323
325
|
exportSchemasTypes?: boolean;
|
|
@@ -444,7 +446,7 @@ declare const ConfigSchema: z.ZodReadonly<z.ZodPipe<z.ZodObject<{
|
|
|
444
446
|
test?: {
|
|
445
447
|
output: string;
|
|
446
448
|
import: string;
|
|
447
|
-
framework?: "vitest" | "bun";
|
|
449
|
+
framework?: "vitest" | "vite-plus" | "bun";
|
|
448
450
|
};
|
|
449
451
|
mock?: {
|
|
450
452
|
output: string;
|
|
@@ -492,7 +494,7 @@ declare function defineConfig(config: ConfigInput): Readonly<{
|
|
|
492
494
|
test?: boolean | undefined;
|
|
493
495
|
routeHandler?: boolean | undefined;
|
|
494
496
|
pathAlias?: string;
|
|
495
|
-
framework?: "vitest" | "bun" | undefined;
|
|
497
|
+
framework?: "vitest" | "vite-plus" | "bun" | undefined;
|
|
496
498
|
};
|
|
497
499
|
exportSchemas?: boolean;
|
|
498
500
|
exportSchemasTypes?: boolean;
|
|
@@ -619,7 +621,7 @@ declare function defineConfig(config: ConfigInput): Readonly<{
|
|
|
619
621
|
test?: {
|
|
620
622
|
output: string;
|
|
621
623
|
import: string;
|
|
622
|
-
framework?: "vitest" | "bun" | undefined;
|
|
624
|
+
framework?: "vitest" | "vite-plus" | "bun" | undefined;
|
|
623
625
|
};
|
|
624
626
|
mock?: {
|
|
625
627
|
output: string;
|
package/dist/config/index.js
CHANGED
|
@@ -16,7 +16,11 @@ const ConfigSchema = z.object({
|
|
|
16
16
|
test: z.boolean().default(false),
|
|
17
17
|
routeHandler: z.boolean().default(false),
|
|
18
18
|
pathAlias: z.string().exactOptional(),
|
|
19
|
-
framework: z.enum([
|
|
19
|
+
framework: z.enum([
|
|
20
|
+
"vitest",
|
|
21
|
+
"vite-plus",
|
|
22
|
+
"bun"
|
|
23
|
+
]).default("vitest").exactOptional()
|
|
20
24
|
}).exactOptional(),
|
|
21
25
|
exportSchemas: z.boolean().exactOptional(),
|
|
22
26
|
exportSchemasTypes: z.boolean().exactOptional(),
|
|
@@ -143,7 +147,11 @@ const ConfigSchema = z.object({
|
|
|
143
147
|
test: z.object({
|
|
144
148
|
output: z.string(),
|
|
145
149
|
import: z.string(),
|
|
146
|
-
framework: z.enum([
|
|
150
|
+
framework: z.enum([
|
|
151
|
+
"vitest",
|
|
152
|
+
"vite-plus",
|
|
153
|
+
"bun"
|
|
154
|
+
]).default("vitest").exactOptional()
|
|
147
155
|
}).exactOptional(),
|
|
148
156
|
mock: z.object({ output: z.string() }).exactOptional(),
|
|
149
157
|
docs: z.object({
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readConfig } from "./config/index.js";
|
|
3
3
|
import { r as setFormatOptions } from "./core-BlUaJE2n.js";
|
|
4
|
-
import { _ as examples, a as takibi, c as securitySchemes, d as requestBodies, f as pathItems, g as headers, h as links, i as template, l as schemas, m as mediaTypes, n as webhooks, o as route, p as parameters, r as test, s as mock, t as parseOpenAPI, u as responses, v as callbacks } from "./openapi-
|
|
4
|
+
import { _ as examples, a as takibi, c as securitySchemes, d as requestBodies, f as pathItems, g as headers, h as links, i as template, l as schemas, m as mediaTypes, n as webhooks, o as route, p as parameters, r as test, s as mock, t as parseOpenAPI, u as responses, v as callbacks } from "./openapi-D2QO8Njt.js";
|
|
5
5
|
import { t as docs } from "./docs-Da_MOdAe.js";
|
|
6
6
|
import { rpc } from "./core/rpc/index.js";
|
|
7
7
|
import { svelteQuery } from "./core/svelte-query/index.js";
|
|
@@ -799,6 +799,13 @@ async function securitySchemes(securitySchemes, output, split, readonly) {
|
|
|
799
799
|
//#endregion
|
|
800
800
|
//#region src/generator/test/faker-mapping.ts
|
|
801
801
|
/**
|
|
802
|
+
* Sanitize a schema name for use as a JavaScript identifier in mock function names.
|
|
803
|
+
* Removes dots from namespace-qualified names (e.g., "Auth.SignupRequest" → "AuthSignupRequest")
|
|
804
|
+
*/
|
|
805
|
+
function sanitizeMockName(name) {
|
|
806
|
+
return name.replace(/\./g, "");
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
802
809
|
* OpenAPI format to faker method mapping
|
|
803
810
|
*/
|
|
804
811
|
const FORMAT_TO_FAKER = {
|
|
@@ -888,7 +895,7 @@ function schemaToFaker(schema, propertyName, options = {}) {
|
|
|
888
895
|
if (options.useExamples && schema.example !== void 0) return JSON.stringify(schema.example);
|
|
889
896
|
if (schema.const !== void 0) return `${JSON.stringify(schema.const)} as const`;
|
|
890
897
|
if (schema.enum && schema.enum.length > 0) return `faker.helpers.arrayElement([${schema.enum.map((v) => JSON.stringify(v)).join(", ")}] as const)`;
|
|
891
|
-
if (schema.$ref) return `mock${schema.$ref.split("/").pop() || "unknown"}()`;
|
|
898
|
+
if (schema.$ref) return `mock${sanitizeMockName(schema.$ref.split("/").pop() || "unknown")}()`;
|
|
892
899
|
if (schema.type === "array" && schema.items) {
|
|
893
900
|
const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
|
|
894
901
|
if (!itemSchema) return "[]";
|
|
@@ -1018,7 +1025,8 @@ function detectCircularSchemas$1(schemas) {
|
|
|
1018
1025
|
*/
|
|
1019
1026
|
function generateMockFunction(name, schema, schemas, isCircular) {
|
|
1020
1027
|
const mockBody = schemaToFaker(schema, void 0, { schemas });
|
|
1021
|
-
|
|
1028
|
+
const returnType = isCircular ? ": any" : "";
|
|
1029
|
+
return `function mock${sanitizeMockName(name)}()${returnType} {\n return ${mockBody}\n}`;
|
|
1022
1030
|
}
|
|
1023
1031
|
function extractSecurityInfo(opSecurity, globalSecurity, securitySchemes) {
|
|
1024
1032
|
return (opSecurity ?? globalSecurity ?? []).flatMap((secDef) => Object.keys(secDef).flatMap((schemeName) => {
|
|
@@ -1410,10 +1418,16 @@ function extractTestCases(spec) {
|
|
|
1410
1418
|
};
|
|
1411
1419
|
})();
|
|
1412
1420
|
const usedSchemaRefs = (() => {
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1421
|
+
const refs = [];
|
|
1422
|
+
if (op.requestBody && isContentBody(op.requestBody)) {
|
|
1423
|
+
const jsonContent = op.requestBody.content?.["application/json"];
|
|
1424
|
+
if (jsonContent?.schema) refs.push(...collectSchemaRefs(jsonContent.schema, spec.components?.schemas));
|
|
1425
|
+
}
|
|
1426
|
+
for (const rawParam of op.parameters || []) {
|
|
1427
|
+
const param = rawParam.$ref ? spec.components?.parameters?.[rawParam.$ref.replace("#/components/parameters/", "")] ?? rawParam : rawParam;
|
|
1428
|
+
if (param?.schema) refs.push(...collectSchemaRefs(param.schema, spec.components?.schemas));
|
|
1429
|
+
}
|
|
1430
|
+
return [...new Set(refs)];
|
|
1417
1431
|
})();
|
|
1418
1432
|
const responseKeys = Object.keys(op.responses || {});
|
|
1419
1433
|
const successStatus = responseKeys.filter((s) => s.startsWith("2")).map((s) => Number.parseInt(s, 10)).sort((a, b) => a - b)[0] ?? 200;
|
|
@@ -1510,17 +1524,19 @@ function makeMockFunctions(spec, usedSchemaNames) {
|
|
|
1510
1524
|
};
|
|
1511
1525
|
for (const name of usedSchemaNames) visit(name);
|
|
1512
1526
|
return sorted.map((name) => {
|
|
1513
|
-
|
|
1527
|
+
const returnType = circular.has(name) ? ": any" : "";
|
|
1528
|
+
return `function mock${sanitizeMockName(name)}()${returnType} {\n return ${schemaToFaker(schemas[name])}\n}`;
|
|
1514
1529
|
}).join("\n\n");
|
|
1515
1530
|
}
|
|
1516
1531
|
/**
|
|
1517
1532
|
* Generate a non-existent value for 404 testing based on the schema type
|
|
1518
1533
|
* Returns raw value without quotes (for URL path insertion)
|
|
1519
1534
|
*/
|
|
1520
|
-
function getNonExistentValue(schema) {
|
|
1535
|
+
function getNonExistentValue(schema, schemas) {
|
|
1521
1536
|
if (!schema) return "__non_existent__";
|
|
1522
|
-
|
|
1523
|
-
if (
|
|
1537
|
+
const resolved = schema.$ref && schemas ? schemas[schema.$ref.replace("#/components/schemas/", "")] ?? schema : schema;
|
|
1538
|
+
if (resolved.type === "integer" || resolved.type === "number") return "-1";
|
|
1539
|
+
if (resolved.format === "uuid") return "00000000-0000-0000-0000-000000000000";
|
|
1524
1540
|
return "__non_existent__";
|
|
1525
1541
|
}
|
|
1526
1542
|
function makeAuthHeader(sec) {
|
|
@@ -1534,7 +1550,7 @@ function makeAuthHeader(sec) {
|
|
|
1534
1550
|
default: return "";
|
|
1535
1551
|
}
|
|
1536
1552
|
}
|
|
1537
|
-
function makeTestCase(tc, basePath = "/") {
|
|
1553
|
+
function makeTestCase(tc, basePath = "/", schemas) {
|
|
1538
1554
|
const basePathPrefix = basePath !== "/" ? basePath : "";
|
|
1539
1555
|
const fullPath = tc.path === "/" && basePathPrefix ? basePathPrefix : `${basePathPrefix}${tc.path}`;
|
|
1540
1556
|
const testPath = tc.pathParams.reduce((path, param) => path.replace(`{${param.name}}`, `\${${param.name}}`), fullPath);
|
|
@@ -1568,7 +1584,7 @@ function makeTestCase(tc, basePath = "/") {
|
|
|
1568
1584
|
bodySetup
|
|
1569
1585
|
].filter(Boolean).join("\n");
|
|
1570
1586
|
return `${`describe('${tc.method} ${fullPath}',()=>{it('${itDescription}',async()=>{${setupCode}\nconst res=await app.request(\`${testPath}${queryString}\`,{method:'${tc.method}'${headersOption}${bodyOption}})\nexpect(res.status).toBe(${tc.successStatus})})`}${tc.security.length > 0 ? `\nit('should return 401 without auth',async()=>{${setupCode}\nconst res=await app.request(\`${testPath}${queryString}\`,{method:'${tc.method}'${headersWithoutAuth}${bodyOption}})\nexpect(res.status).toBe(401)})` : ""}${tc.pathParams.length > 0 && tc.errorStatuses.includes(404) ? (() => {
|
|
1571
|
-
const notFoundPath = tc.pathParams.reduce((path, param) => path.replace(`{${param.name}}`, getNonExistentValue(param.schema)), fullPath);
|
|
1587
|
+
const notFoundPath = tc.pathParams.reduce((path, param) => path.replace(`{${param.name}}`, getNonExistentValue(param.schema, schemas)), fullPath);
|
|
1572
1588
|
return `\nit('should return 404 for non-existent resource',async()=>{${[
|
|
1573
1589
|
...tc.queryParams.map((param) => `const ${param.name}=${param.fakerCode}`),
|
|
1574
1590
|
...headerSetup,
|
|
@@ -1579,6 +1595,11 @@ function makeTestCase(tc, basePath = "/") {
|
|
|
1579
1595
|
function escapeString(s) {
|
|
1580
1596
|
return s.replace(/'/g, "\\'").replace(/\n/g, " ");
|
|
1581
1597
|
}
|
|
1598
|
+
const TEST_IMPORT_SOURCE = {
|
|
1599
|
+
vitest: "vitest",
|
|
1600
|
+
"vite-plus": "vite-plus/test",
|
|
1601
|
+
bun: "bun:test"
|
|
1602
|
+
};
|
|
1582
1603
|
function makeTestFile(spec, appImportPath = "./app", basePath = "/", framework = "vitest") {
|
|
1583
1604
|
const testCases = extractTestCases(spec);
|
|
1584
1605
|
const apiTitle = spec.info?.title || "API";
|
|
@@ -1590,12 +1611,12 @@ function makeTestFile(spec, appImportPath = "./app", basePath = "/", framework =
|
|
|
1590
1611
|
const mockFunctions = makeMockFunctions(spec, usedSchemaNames);
|
|
1591
1612
|
const tagDescribes = Array.from(byTag.entries()).map(([tag, cases]) => {
|
|
1592
1613
|
const tagDescription = (spec.tags?.find((t) => t.name === tag))?.description || tag;
|
|
1593
|
-
const testCasesCode = cases.map((tc) => makeTestCase(tc, basePath)).join("");
|
|
1614
|
+
const testCasesCode = cases.map((tc) => makeTestCase(tc, basePath, spec.components?.schemas)).join("");
|
|
1594
1615
|
return `describe('${escapeString(tagDescription)}',()=>{${testCasesCode}})\n`;
|
|
1595
1616
|
}).join("");
|
|
1596
1617
|
const body = `${mockFunctions ? `${mockFunctions}\n\n` : ""}describe('${escapeString(apiTitle)}',()=>{${tagDescribes}})\n`;
|
|
1597
1618
|
const fakerImport = body.includes("faker.") ? `\nimport{faker}from'@faker-js/faker'` : "";
|
|
1598
|
-
return `${`import{describe,it,expect}from'${framework
|
|
1619
|
+
return `${`import{describe,it,expect}from'${TEST_IMPORT_SOURCE[framework]}'${fakerImport}\nimport app from'${appImportPath}'\n`}\n${body}`;
|
|
1599
1620
|
}
|
|
1600
1621
|
/**
|
|
1601
1622
|
* Extract the first path segment from an API path.
|
|
@@ -1612,10 +1633,10 @@ function makeHandlerTestCode(spec, handlerPath, _routeNames, importFrom, basePat
|
|
|
1612
1633
|
});
|
|
1613
1634
|
if (relevantCases.length === 0) return "";
|
|
1614
1635
|
const mockFunctions = makeMockFunctions(spec, new Set(relevantCases.flatMap((tc) => tc.usedSchemaRefs)));
|
|
1615
|
-
const testCasesCode = relevantCases.map((tc) => makeTestCase(tc, basePath)).join("");
|
|
1636
|
+
const testCasesCode = relevantCases.map((tc) => makeTestCase(tc, basePath, spec.components?.schemas)).join("");
|
|
1616
1637
|
const body = `${mockFunctions ? `${mockFunctions}\n\n` : ""}describe('${handlerFileName.charAt(0).toUpperCase() + handlerFileName.slice(1)}',()=>{${testCasesCode}})\n`;
|
|
1617
1638
|
const fakerImport = body.includes("faker.") ? `\nimport{faker}from'@faker-js/faker'` : "";
|
|
1618
|
-
return `${`import{describe,it,expect}from'${framework
|
|
1639
|
+
return `${`import{describe,it,expect}from'${TEST_IMPORT_SOURCE[framework]}'${fakerImport}\nimport app from'${importFrom}'\n`}\n${body}`;
|
|
1619
1640
|
}
|
|
1620
1641
|
//#endregion
|
|
1621
1642
|
//#region src/merge/index.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseConfig } from "../config/index.js";
|
|
2
2
|
import { f as isRecord } from "../guard-BabA4f3q.js";
|
|
3
3
|
import { r as setFormatOptions } from "../core-BlUaJE2n.js";
|
|
4
|
-
import { _ as examples, a as takibi, c as securitySchemes, d as requestBodies, f as pathItems, g as headers, h as links, i as template, l as schemas, m as mediaTypes, n as webhooks, o as route, p as parameters, r as test, s as mock, t as parseOpenAPI, u as responses, v as callbacks } from "../openapi-
|
|
4
|
+
import { _ as examples, a as takibi, c as securitySchemes, d as requestBodies, f as pathItems, g as headers, h as links, i as template, l as schemas, m as mediaTypes, n as webhooks, o as route, p as parameters, r as test, s as mock, t as parseOpenAPI, u as responses, v as callbacks } from "../openapi-D2QO8Njt.js";
|
|
5
5
|
import { t as docs } from "../docs-Da_MOdAe.js";
|
|
6
6
|
import { rpc } from "../core/rpc/index.js";
|
|
7
7
|
import { svelteQuery } from "../core/svelte-query/index.js";
|