@kizunajs/fetch 2.0.0-beta.4 → 2.0.0-beta.5
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/server.cjs +12 -12
- package/dist/server.d.cts +7 -0
- package/dist/server.d.mts +7 -0
- package/dist/server.mjs +12 -12
- package/package.json +4 -4
package/dist/server.cjs
CHANGED
|
@@ -291,7 +291,7 @@ const routeDoc = (routeKey, route) => {
|
|
|
291
291
|
lines.push("@example", exampleCall(routeKey, route));
|
|
292
292
|
return docComment(lines);
|
|
293
293
|
};
|
|
294
|
-
const emitRoute = (routeKey, key, route, collector) => {
|
|
294
|
+
const emitRoute = (routeKey, key, route, collector, namespaceName) => {
|
|
295
295
|
const namespace = routeKey.split(".").map(kizunajs_generator.toPascalCase).join("");
|
|
296
296
|
const members = [];
|
|
297
297
|
const args = [];
|
|
@@ -299,19 +299,19 @@ const emitRoute = (routeKey, key, route, collector) => {
|
|
|
299
299
|
if (params.length > 0) {
|
|
300
300
|
const body = route.pathParams ? typeOf(route.pathParams, collector, `${namespace}Params`) : `{\n${indent(params.map((name) => `${name}: string;`).join("\n"))}\n}`;
|
|
301
301
|
members.push(`export type Params = ${body};`);
|
|
302
|
-
args.push(`params:
|
|
302
|
+
args.push(`params: ${namespaceName}.${namespace}.Params`);
|
|
303
303
|
}
|
|
304
304
|
if (route.query) {
|
|
305
305
|
members.push(`export type Query = ${typeOf(route.query, collector, `${namespace}Query`)};`);
|
|
306
|
-
args.push(`query?:
|
|
306
|
+
args.push(`query?: ${namespaceName}.${namespace}.Query`);
|
|
307
307
|
}
|
|
308
308
|
if (route.body && !(0, kizunajs_generator.isVoidSchema)(route.body)) {
|
|
309
309
|
members.push(`export type Body = ${typeOf(route.body, collector, `${namespace}Body`)};`);
|
|
310
|
-
args.push(`body:
|
|
310
|
+
args.push(`body: ${namespaceName}.${namespace}.Body`);
|
|
311
311
|
}
|
|
312
312
|
if (route.headers) {
|
|
313
313
|
members.push(`export type Headers = ${typeOf(route.headers, collector, `${namespace}Headers`)};`);
|
|
314
|
-
args.push(`headers?:
|
|
314
|
+
args.push(`headers?: ${namespaceName}.${namespace}.Headers`);
|
|
315
315
|
} else args.push("headers?: Record<string, string>");
|
|
316
316
|
args.push("fetchOptions?: RequestInit");
|
|
317
317
|
const validates = route.body !== void 0 || route.query !== void 0;
|
|
@@ -335,13 +335,13 @@ const emitRoute = (routeKey, key, route, collector) => {
|
|
|
335
335
|
const streams = Object.values(route.responses).some((response) => (0, kizunajs_generator.isStreamResponse)(response));
|
|
336
336
|
return {
|
|
337
337
|
namespace,
|
|
338
|
-
signature: `${routeDoc(routeKey, route)}${key}: ClientMethod<'${route.method}', ${streams}, ${argsType},
|
|
338
|
+
signature: `${routeDoc(routeKey, route)}${key}: ClientMethod<'${route.method}', ${streams}, ${argsType}, ${namespaceName}.${namespace}.Result>;`,
|
|
339
339
|
declaration: `export namespace ${namespace} {\n${indent(members.join("\n\n"))}\n}`,
|
|
340
340
|
table: `${key}: {\n${indent(tableEntries.map((entry) => `${entry},`).join("\n"))}\n},`
|
|
341
341
|
};
|
|
342
342
|
};
|
|
343
343
|
const isRoute = (value) => !!value && typeof value === "object" && typeof value.method === "string";
|
|
344
|
-
const emitTree = (routes, prefix, collector) => {
|
|
344
|
+
const emitTree = (routes, prefix, collector, namespaceName) => {
|
|
345
345
|
const signatures = [];
|
|
346
346
|
const tables = [];
|
|
347
347
|
const declarations = [];
|
|
@@ -349,14 +349,14 @@ const emitTree = (routes, prefix, collector) => {
|
|
|
349
349
|
const node = routes[key];
|
|
350
350
|
const routeKey = prefix ? `${prefix}.${key}` : key;
|
|
351
351
|
if (isRoute(node)) {
|
|
352
|
-
const emitted = emitRoute(routeKey, key, node, collector);
|
|
352
|
+
const emitted = emitRoute(routeKey, key, node, collector, namespaceName);
|
|
353
353
|
signatures.push(emitted.signature);
|
|
354
354
|
tables.push(emitted.table);
|
|
355
355
|
declarations.push(emitted.declaration);
|
|
356
356
|
continue;
|
|
357
357
|
}
|
|
358
358
|
if (node && typeof node === "object") {
|
|
359
|
-
const group = emitTree(node, routeKey, collector);
|
|
359
|
+
const group = emitTree(node, routeKey, collector, namespaceName);
|
|
360
360
|
signatures.push(`${key}: {\n${indent(group.signatures)}\n};`);
|
|
361
361
|
tables.push(`${key}: {\n${indent(group.table)}\n},`);
|
|
362
362
|
declarations.push(...group.declarations);
|
|
@@ -388,9 +388,9 @@ const emitRequestContext = (contract, collector) => {
|
|
|
388
388
|
return fields.length > 0 ? `export interface RequestContext {\n${indent(fields.join("\n"))}\n}` : void 0;
|
|
389
389
|
};
|
|
390
390
|
const generateFetchClient = (contract, options = {}) => {
|
|
391
|
-
const { runtimeModule = "@kizunajs/fetch", regenerateCommand = "kizuna generate", source } = options;
|
|
391
|
+
const { namespace: namespaceName = "API", runtimeModule = "@kizunajs/fetch", regenerateCommand = "kizuna generate", source } = options;
|
|
392
392
|
const collector = new TypeCollector();
|
|
393
|
-
const tree = emitTree(contract.routes, "", collector);
|
|
393
|
+
const tree = emitTree(contract.routes, "", collector, namespaceName);
|
|
394
394
|
const api = [...collector.all().map((model) => {
|
|
395
395
|
return `${model.description ? `/**\n * ${model.description}\n */\n` : ""}export type ${model.name} = ${model.body};`;
|
|
396
396
|
}), ...tree.declarations].join("\n\n");
|
|
@@ -406,7 +406,7 @@ ${[
|
|
|
406
406
|
*/
|
|
407
407
|
import { createGeneratedClient, type ClientConfig, type ClientMethod, type GeneratedRoutes } from '${runtimeModule}';
|
|
408
408
|
|
|
409
|
-
export namespace
|
|
409
|
+
export namespace ${namespaceName} {
|
|
410
410
|
${indent(api)}
|
|
411
411
|
}
|
|
412
412
|
|
package/dist/server.d.cts
CHANGED
|
@@ -5,6 +5,13 @@ import { ApiDefinition, ClientTarget } from "kizunajs";
|
|
|
5
5
|
* What a generated client is called and where its runtime comes from.
|
|
6
6
|
*/
|
|
7
7
|
interface FetchClientOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Name of the generated namespace holding every model and every route's
|
|
10
|
+
* `Params`, `Query`, `Body`, `Headers` and `Result`.
|
|
11
|
+
*
|
|
12
|
+
* @default 'API'
|
|
13
|
+
*/
|
|
14
|
+
namespace?: string;
|
|
8
15
|
/**
|
|
9
16
|
* Module the generated file imports its runtime from.
|
|
10
17
|
*
|
package/dist/server.d.mts
CHANGED
|
@@ -5,6 +5,13 @@ import { ApiDefinition, ClientTarget } from "kizunajs";
|
|
|
5
5
|
* What a generated client is called and where its runtime comes from.
|
|
6
6
|
*/
|
|
7
7
|
interface FetchClientOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Name of the generated namespace holding every model and every route's
|
|
10
|
+
* `Params`, `Query`, `Body`, `Headers` and `Result`.
|
|
11
|
+
*
|
|
12
|
+
* @default 'API'
|
|
13
|
+
*/
|
|
14
|
+
namespace?: string;
|
|
8
15
|
/**
|
|
9
16
|
* Module the generated file imports its runtime from.
|
|
10
17
|
*
|
package/dist/server.mjs
CHANGED
|
@@ -290,7 +290,7 @@ const routeDoc = (routeKey, route) => {
|
|
|
290
290
|
lines.push("@example", exampleCall(routeKey, route));
|
|
291
291
|
return docComment(lines);
|
|
292
292
|
};
|
|
293
|
-
const emitRoute = (routeKey, key, route, collector) => {
|
|
293
|
+
const emitRoute = (routeKey, key, route, collector, namespaceName) => {
|
|
294
294
|
const namespace = routeKey.split(".").map(toPascalCase).join("");
|
|
295
295
|
const members = [];
|
|
296
296
|
const args = [];
|
|
@@ -298,19 +298,19 @@ const emitRoute = (routeKey, key, route, collector) => {
|
|
|
298
298
|
if (params.length > 0) {
|
|
299
299
|
const body = route.pathParams ? typeOf(route.pathParams, collector, `${namespace}Params`) : `{\n${indent(params.map((name) => `${name}: string;`).join("\n"))}\n}`;
|
|
300
300
|
members.push(`export type Params = ${body};`);
|
|
301
|
-
args.push(`params:
|
|
301
|
+
args.push(`params: ${namespaceName}.${namespace}.Params`);
|
|
302
302
|
}
|
|
303
303
|
if (route.query) {
|
|
304
304
|
members.push(`export type Query = ${typeOf(route.query, collector, `${namespace}Query`)};`);
|
|
305
|
-
args.push(`query?:
|
|
305
|
+
args.push(`query?: ${namespaceName}.${namespace}.Query`);
|
|
306
306
|
}
|
|
307
307
|
if (route.body && !isVoidSchema(route.body)) {
|
|
308
308
|
members.push(`export type Body = ${typeOf(route.body, collector, `${namespace}Body`)};`);
|
|
309
|
-
args.push(`body:
|
|
309
|
+
args.push(`body: ${namespaceName}.${namespace}.Body`);
|
|
310
310
|
}
|
|
311
311
|
if (route.headers) {
|
|
312
312
|
members.push(`export type Headers = ${typeOf(route.headers, collector, `${namespace}Headers`)};`);
|
|
313
|
-
args.push(`headers?:
|
|
313
|
+
args.push(`headers?: ${namespaceName}.${namespace}.Headers`);
|
|
314
314
|
} else args.push("headers?: Record<string, string>");
|
|
315
315
|
args.push("fetchOptions?: RequestInit");
|
|
316
316
|
const validates = route.body !== void 0 || route.query !== void 0;
|
|
@@ -334,13 +334,13 @@ const emitRoute = (routeKey, key, route, collector) => {
|
|
|
334
334
|
const streams = Object.values(route.responses).some((response) => isStreamResponse(response));
|
|
335
335
|
return {
|
|
336
336
|
namespace,
|
|
337
|
-
signature: `${routeDoc(routeKey, route)}${key}: ClientMethod<'${route.method}', ${streams}, ${argsType},
|
|
337
|
+
signature: `${routeDoc(routeKey, route)}${key}: ClientMethod<'${route.method}', ${streams}, ${argsType}, ${namespaceName}.${namespace}.Result>;`,
|
|
338
338
|
declaration: `export namespace ${namespace} {\n${indent(members.join("\n\n"))}\n}`,
|
|
339
339
|
table: `${key}: {\n${indent(tableEntries.map((entry) => `${entry},`).join("\n"))}\n},`
|
|
340
340
|
};
|
|
341
341
|
};
|
|
342
342
|
const isRoute = (value) => !!value && typeof value === "object" && typeof value.method === "string";
|
|
343
|
-
const emitTree = (routes, prefix, collector) => {
|
|
343
|
+
const emitTree = (routes, prefix, collector, namespaceName) => {
|
|
344
344
|
const signatures = [];
|
|
345
345
|
const tables = [];
|
|
346
346
|
const declarations = [];
|
|
@@ -348,14 +348,14 @@ const emitTree = (routes, prefix, collector) => {
|
|
|
348
348
|
const node = routes[key];
|
|
349
349
|
const routeKey = prefix ? `${prefix}.${key}` : key;
|
|
350
350
|
if (isRoute(node)) {
|
|
351
|
-
const emitted = emitRoute(routeKey, key, node, collector);
|
|
351
|
+
const emitted = emitRoute(routeKey, key, node, collector, namespaceName);
|
|
352
352
|
signatures.push(emitted.signature);
|
|
353
353
|
tables.push(emitted.table);
|
|
354
354
|
declarations.push(emitted.declaration);
|
|
355
355
|
continue;
|
|
356
356
|
}
|
|
357
357
|
if (node && typeof node === "object") {
|
|
358
|
-
const group = emitTree(node, routeKey, collector);
|
|
358
|
+
const group = emitTree(node, routeKey, collector, namespaceName);
|
|
359
359
|
signatures.push(`${key}: {\n${indent(group.signatures)}\n};`);
|
|
360
360
|
tables.push(`${key}: {\n${indent(group.table)}\n},`);
|
|
361
361
|
declarations.push(...group.declarations);
|
|
@@ -387,9 +387,9 @@ const emitRequestContext = (contract, collector) => {
|
|
|
387
387
|
return fields.length > 0 ? `export interface RequestContext {\n${indent(fields.join("\n"))}\n}` : void 0;
|
|
388
388
|
};
|
|
389
389
|
const generateFetchClient = (contract, options = {}) => {
|
|
390
|
-
const { runtimeModule = "@kizunajs/fetch", regenerateCommand = "kizuna generate", source } = options;
|
|
390
|
+
const { namespace: namespaceName = "API", runtimeModule = "@kizunajs/fetch", regenerateCommand = "kizuna generate", source } = options;
|
|
391
391
|
const collector = new TypeCollector();
|
|
392
|
-
const tree = emitTree(contract.routes, "", collector);
|
|
392
|
+
const tree = emitTree(contract.routes, "", collector, namespaceName);
|
|
393
393
|
const api = [...collector.all().map((model) => {
|
|
394
394
|
return `${model.description ? `/**\n * ${model.description}\n */\n` : ""}export type ${model.name} = ${model.body};`;
|
|
395
395
|
}), ...tree.declarations].join("\n\n");
|
|
@@ -405,7 +405,7 @@ ${[
|
|
|
405
405
|
*/
|
|
406
406
|
import { createGeneratedClient, type ClientConfig, type ClientMethod, type GeneratedRoutes } from '${runtimeModule}';
|
|
407
407
|
|
|
408
|
-
export namespace
|
|
408
|
+
export namespace ${namespaceName} {
|
|
409
409
|
${indent(api)}
|
|
410
410
|
}
|
|
411
411
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kizunajs/fetch",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.5",
|
|
4
4
|
"description": "Typed fetch client for Kizuna.js APIs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kizunajs",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"zod": "^4.0.0",
|
|
71
|
-
"kizunajs": "2.0.0-beta.
|
|
71
|
+
"kizunajs": "2.0.0-beta.5"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@types/express": "^5.0.0",
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
"tsdown": "^0.21.0",
|
|
77
77
|
"typescript": "^6.0.3",
|
|
78
78
|
"zod": "^4.0.0",
|
|
79
|
-
"kizunajs": "2.0.0-beta.
|
|
80
|
-
"@kizunajs/express": "2.0.0-beta.
|
|
79
|
+
"kizunajs": "2.0.0-beta.5",
|
|
80
|
+
"@kizunajs/express": "2.0.0-beta.5"
|
|
81
81
|
},
|
|
82
82
|
"scripts": {
|
|
83
83
|
"build": "tsdown src/index.ts src/server.ts --format esm,cjs --dts --clean --external kizunajs --external zod",
|