@kizunajs/fetch 2.0.0-beta.10 → 2.0.0-beta.11

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let kizunajs_schemas = require("kizunajs/schemas");
3
3
  let kizunajs_generator = require("kizunajs/generator");
4
+ let zod = require("zod");
4
5
  //#region src/zod-to-typescript.ts
5
6
  /**
6
7
  * Collects the named types a walk produces, so a model shared by many routes is
@@ -390,7 +391,7 @@ const emitRequestContext = (contract, collector) => {
390
391
  const generateFetchClient = (contract, options = {}) => {
391
392
  const { namespace: namespaceName = "API", runtimeModule = "@kizunajs/fetch", regenerateCommand = "kizuna generate", source } = options;
392
393
  const collector = new TypeCollector();
393
- const tree = emitTree(contract.routes, "", collector, namespaceName);
394
+ const tree = emitTree((0, kizunajs_generator.listedRoutes)(contract), "", collector, namespaceName);
394
395
  const api = [...collector.all().map((model) => {
395
396
  return `${model.description ? `/**\n * ${model.description}\n */\n` : ""}export type ${model.name} = ${model.body};`;
396
397
  }), ...tree.declarations].join("\n\n");
@@ -433,16 +434,45 @@ export const createClient = (config: ClientConfig & { requestContext?: RequestCo
433
434
  };
434
435
  //#endregion
435
436
  //#region src/client-target.ts
437
+ const FetchClientOptionsSchema = zod.z.object({
438
+ /**
439
+ * Name of the generated namespace holding every model and every route's
440
+ * `Params`, `Query`, `Body`, `Headers` and `Result`.
441
+ *
442
+ * @default 'API'
443
+ */
444
+ namespace: zod.z.string().optional(),
445
+ /**
446
+ * Module the generated file imports its runtime from.
447
+ *
448
+ * @default '@kizunajs/fetch'
449
+ */
450
+ runtimeModule: zod.z.string().optional(),
451
+ /**
452
+ * Command the file's header tells a reader to run.
453
+ *
454
+ * @default 'kizuna generate'
455
+ */
456
+ regenerateCommand: zod.z.string().optional(),
457
+ /**
458
+ * Path to the api this was generated from, relative to the generated
459
+ * file. Named in the header so tooling can tell when the client has fallen
460
+ * behind, and so a reader knows where the API is declared.
461
+ */
462
+ source: zod.z.string().optional()
463
+ });
436
464
  /**
437
- * A TypeScript client target for `kizuna.config.ts`.
465
+ * A TypeScript client for `kizuna.config.ts`.
438
466
  *
439
467
  * @example
440
- * fetchClient({ output: './packages/api-client/src/generated.ts' });
468
+ * fetchClient({
469
+ * output: './packages/api-client/src/generated.ts',
470
+ * });
441
471
  */
442
- const fetchClient = ({ output, ...options }) => ({
443
- kind: "fetch",
444
- output,
445
- generate: (contract) => generateFetchClient(contract, options)
472
+ const fetchClient = (0, kizunajs_generator.defineClient)({
473
+ target: "fetch",
474
+ options: FetchClientOptionsSchema,
475
+ generate: ({ options, api }) => ({ finalize: () => generateFetchClient(api, options) })
446
476
  });
447
477
  //#endregion
448
478
  exports.fetchClient = fetchClient;
package/dist/server.d.cts CHANGED
@@ -1,4 +1,7 @@
1
- import { ApiDefinition, ClientTarget } from "kizunajs";
1
+ import { z } from "zod";
2
+ import * as _$kizunajs from "kizunajs";
3
+ import { ApiDefinition } from "kizunajs";
4
+ import { GeneratedFileOptions } from "kizunajs/generator";
2
5
 
3
6
  //#region src/generator.d.ts
4
7
  /**
@@ -34,24 +37,29 @@ interface FetchClientOptions {
34
37
  declare const generateFetchClient: (contract: ApiDefinition, options?: FetchClientOptions) => string;
35
38
  //#endregion
36
39
  //#region src/client-target.d.ts
40
+ declare const FetchClientOptionsSchema: z.ZodObject<{
41
+ namespace: z.ZodOptional<z.ZodString>;
42
+ runtimeModule: z.ZodOptional<z.ZodString>;
43
+ regenerateCommand: z.ZodOptional<z.ZodString>;
44
+ source: z.ZodOptional<z.ZodString>;
45
+ }, z.core.$strip>;
37
46
  /**
38
47
  * Where a generated TypeScript client is written.
39
48
  */
40
- interface FetchClientTargetOptions extends FetchClientOptions {
41
- /**
42
- * Path the generated file is written to.
43
- */
44
- output: string;
45
- }
49
+ type FetchClientTargetOptions = z.input<typeof FetchClientOptionsSchema> & GeneratedFileOptions;
46
50
  /**
47
- * A TypeScript client target for `kizuna.config.ts`.
51
+ * A TypeScript client for `kizuna.config.ts`.
48
52
  *
49
53
  * @example
50
- * fetchClient({ output: './packages/api-client/src/generated.ts' });
54
+ * fetchClient({
55
+ * output: './packages/api-client/src/generated.ts',
56
+ * });
51
57
  */
52
- declare const fetchClient: ({
53
- output,
54
- ...options
55
- }: FetchClientTargetOptions) => ClientTarget;
58
+ declare const fetchClient: (options: {
59
+ namespace?: string | undefined;
60
+ runtimeModule?: string | undefined;
61
+ regenerateCommand?: string | undefined;
62
+ source?: string | undefined;
63
+ } & GeneratedFileOptions) => _$kizunajs.GeneratedFile;
56
64
  //#endregion
57
65
  export { type FetchClientOptions, type FetchClientTargetOptions, fetchClient, generateFetchClient };
package/dist/server.d.mts CHANGED
@@ -1,4 +1,7 @@
1
- import { ApiDefinition, ClientTarget } from "kizunajs";
1
+ import * as _$kizunajs from "kizunajs";
2
+ import { ApiDefinition } from "kizunajs";
3
+ import { GeneratedFileOptions } from "kizunajs/generator";
4
+ import { z } from "zod";
2
5
 
3
6
  //#region src/generator.d.ts
4
7
  /**
@@ -34,24 +37,29 @@ interface FetchClientOptions {
34
37
  declare const generateFetchClient: (contract: ApiDefinition, options?: FetchClientOptions) => string;
35
38
  //#endregion
36
39
  //#region src/client-target.d.ts
40
+ declare const FetchClientOptionsSchema: z.ZodObject<{
41
+ namespace: z.ZodOptional<z.ZodString>;
42
+ runtimeModule: z.ZodOptional<z.ZodString>;
43
+ regenerateCommand: z.ZodOptional<z.ZodString>;
44
+ source: z.ZodOptional<z.ZodString>;
45
+ }, z.core.$strip>;
37
46
  /**
38
47
  * Where a generated TypeScript client is written.
39
48
  */
40
- interface FetchClientTargetOptions extends FetchClientOptions {
41
- /**
42
- * Path the generated file is written to.
43
- */
44
- output: string;
45
- }
49
+ type FetchClientTargetOptions = z.input<typeof FetchClientOptionsSchema> & GeneratedFileOptions;
46
50
  /**
47
- * A TypeScript client target for `kizuna.config.ts`.
51
+ * A TypeScript client for `kizuna.config.ts`.
48
52
  *
49
53
  * @example
50
- * fetchClient({ output: './packages/api-client/src/generated.ts' });
54
+ * fetchClient({
55
+ * output: './packages/api-client/src/generated.ts',
56
+ * });
51
57
  */
52
- declare const fetchClient: ({
53
- output,
54
- ...options
55
- }: FetchClientTargetOptions) => ClientTarget;
58
+ declare const fetchClient: (options: {
59
+ namespace?: string | undefined;
60
+ runtimeModule?: string | undefined;
61
+ regenerateCommand?: string | undefined;
62
+ source?: string | undefined;
63
+ } & GeneratedFileOptions) => _$kizunajs.GeneratedFile;
56
64
  //#endregion
57
65
  export { type FetchClientOptions, type FetchClientTargetOptions, fetchClient, generateFetchClient };
package/dist/server.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ValidationErrorSchema } from "kizunajs/schemas";
2
- import { isBinarySchema, isFileSchema, isStreamResponse, isVoidSchema, readDef, readDeprecation, readDiscriminatedUnion, readMetaDescription, readMetaExamples, readMetaId, readObjectShape, resolveResponseBody, resolveResponseHeaders, streamContentType, toPascalCase, unwrapOptionalWrappers } from "kizunajs/generator";
2
+ import { defineClient, isBinarySchema, isFileSchema, isStreamResponse, isVoidSchema, listedRoutes, readDef, readDeprecation, readDiscriminatedUnion, readMetaDescription, readMetaExamples, readMetaId, readObjectShape, resolveResponseBody, resolveResponseHeaders, streamContentType, toPascalCase, unwrapOptionalWrappers } from "kizunajs/generator";
3
+ import { z } from "zod";
3
4
  //#region src/zod-to-typescript.ts
4
5
  /**
5
6
  * Collects the named types a walk produces, so a model shared by many routes is
@@ -389,7 +390,7 @@ const emitRequestContext = (contract, collector) => {
389
390
  const generateFetchClient = (contract, options = {}) => {
390
391
  const { namespace: namespaceName = "API", runtimeModule = "@kizunajs/fetch", regenerateCommand = "kizuna generate", source } = options;
391
392
  const collector = new TypeCollector();
392
- const tree = emitTree(contract.routes, "", collector, namespaceName);
393
+ const tree = emitTree(listedRoutes(contract), "", collector, namespaceName);
393
394
  const api = [...collector.all().map((model) => {
394
395
  return `${model.description ? `/**\n * ${model.description}\n */\n` : ""}export type ${model.name} = ${model.body};`;
395
396
  }), ...tree.declarations].join("\n\n");
@@ -430,18 +431,44 @@ export const createClient = (config: ClientConfig & { requestContext?: RequestCo
430
431
  createGeneratedClient(routes, config) as unknown as Client;`}
431
432
  `;
432
433
  };
433
- //#endregion
434
- //#region src/client-target.ts
435
434
  /**
436
- * A TypeScript client target for `kizuna.config.ts`.
435
+ * A TypeScript client for `kizuna.config.ts`.
437
436
  *
438
437
  * @example
439
- * fetchClient({ output: './packages/api-client/src/generated.ts' });
438
+ * fetchClient({
439
+ * output: './packages/api-client/src/generated.ts',
440
+ * });
440
441
  */
441
- const fetchClient = ({ output, ...options }) => ({
442
- kind: "fetch",
443
- output,
444
- generate: (contract) => generateFetchClient(contract, options)
442
+ const fetchClient = defineClient({
443
+ target: "fetch",
444
+ options: z.object({
445
+ /**
446
+ * Name of the generated namespace holding every model and every route's
447
+ * `Params`, `Query`, `Body`, `Headers` and `Result`.
448
+ *
449
+ * @default 'API'
450
+ */
451
+ namespace: z.string().optional(),
452
+ /**
453
+ * Module the generated file imports its runtime from.
454
+ *
455
+ * @default '@kizunajs/fetch'
456
+ */
457
+ runtimeModule: z.string().optional(),
458
+ /**
459
+ * Command the file's header tells a reader to run.
460
+ *
461
+ * @default 'kizuna generate'
462
+ */
463
+ regenerateCommand: z.string().optional(),
464
+ /**
465
+ * Path to the api this was generated from, relative to the generated
466
+ * file. Named in the header so tooling can tell when the client has fallen
467
+ * behind, and so a reader knows where the API is declared.
468
+ */
469
+ source: z.string().optional()
470
+ }),
471
+ generate: ({ options, api }) => ({ finalize: () => generateFetchClient(api, options) })
445
472
  });
446
473
  //#endregion
447
474
  export { fetchClient, generateFetchClient };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizunajs/fetch",
3
- "version": "2.0.0-beta.10",
3
+ "version": "2.0.0-beta.11",
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.10"
71
+ "kizunajs": "2.0.0-beta.11"
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/express": "2.0.0-beta.10",
80
- "kizunajs": "2.0.0-beta.10"
79
+ "kizunajs": "2.0.0-beta.11",
80
+ "@kizunajs/express": "2.0.0-beta.11"
81
81
  },
82
82
  "scripts": {
83
83
  "build": "tsdown src/index.ts src/server.ts --format esm,cjs --dts --clean --external kizunajs --external zod",