@kizunajs/cli 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/cli.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const require_route_map = require("./route-map-I400Eb9_.cjs");
2
+ const require_route_map = require("./route-map-Sk1Wybox.cjs");
3
3
  let node_path = require("node:path");
4
4
  let node_fs = require("node:fs");
5
5
  let node_util = require("node:util");
@@ -59,13 +59,13 @@ const loadOrDie = async (configPath) => {
59
59
  return config;
60
60
  };
61
61
  /**
62
- * A client writes where its config says, not where the command was run from,
63
- * so `kizuna generate --config apps/api/kizuna.config.ts` lands the same files
62
+ * A file writes where its config says, not where the command was run from, so
63
+ * `kizuna generate --config apps/api/kizuna.config.ts` lands the same files
64
64
  * wherever it is invoked.
65
65
  */
66
- const besideConfig = (configPath, clients) => clients.map((client) => ({
67
- ...client,
68
- output: (0, node_path.resolve)((0, node_path.dirname)(configPath), client.output)
66
+ const besideConfig = (configPath, files) => files.map((file) => ({
67
+ ...file,
68
+ output: (0, node_path.resolve)((0, node_path.dirname)(configPath), file.output)
69
69
  }));
70
70
  const runGenerate = async (values) => {
71
71
  const configPath = configPathFrom(values.config);
@@ -83,7 +83,7 @@ const runGenerate = async (values) => {
83
83
  const typesCurrent = (0, node_fs.existsSync)(typesPath) ? (0, node_fs.readFileSync)(typesPath, "utf8") : void 0;
84
84
  const typesBehind = typesCurrent !== types;
85
85
  if (values.check) {
86
- const stale = require_route_map.checkClients(config.api, [...besideConfig(configPath, config.clients), require_route_map.snapshotTarget(configPath)]);
86
+ const stale = require_route_map.checkFiles(config.api, [...besideConfig(configPath, [...config.clients, ...config.generators]), require_route_map.snapshotTarget(configPath)]);
87
87
  if (!typesBehind && stale.length === 0) {
88
88
  process.stdout.write("Everything kizuna generates is up to date.\n");
89
89
  return;
@@ -93,8 +93,8 @@ const runGenerate = async (values) => {
93
93
  process.exit(1);
94
94
  }
95
95
  if (typesBehind) (0, node_fs.writeFileSync)(typesPath, types);
96
- const written = require_route_map.writeClients(config.api, [...besideConfig(configPath, config.clients), require_route_map.snapshotTarget(configPath)]);
97
- const changed = [...typesBehind ? [displayPath(typesPath)] : [], ...written.filter((client) => client.changed).map((client) => displayPath(client.output))];
96
+ const written = require_route_map.writeFiles(config.api, [...besideConfig(configPath, [...config.clients, ...config.generators]), require_route_map.snapshotTarget(configPath)]);
97
+ const changed = [...typesBehind ? [displayPath(typesPath)] : [], ...written.filter((file) => file.changed).map((file) => displayPath(file.output))];
98
98
  process.stdout.write(changed.length > 0 ? `Wrote:\n${changed.map((file) => ` ${file}`).join("\n")}\n` : "Everything was already up to date.\n");
99
99
  };
100
100
  const runRoutes = async (values) => {
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { _ as loadConfig, a as ConfigSyntaxError, c as formatStale, d as diffSnapshots, f as formatChange, h as snapshotTarget, i as readSnapshot, l as writeClients, m as snapshotPathFor, n as routeMap, o as generateConfigTypes, p as hasBreakingChange, r as diffAgainst, s as checkClients, t as formatRoutes } from "./route-map-C484dhbj.mjs";
2
+ import { _ as loadConfig, a as ConfigSyntaxError, c as formatStale, d as diffSnapshots, f as formatChange, h as snapshotTarget, i as readSnapshot, l as writeFiles, m as snapshotPathFor, n as routeMap, o as generateConfigTypes, p as hasBreakingChange, r as diffAgainst, s as checkFiles, t as formatRoutes } from "./route-map-B2vDHecG.mjs";
3
3
  import { dirname, relative, resolve } from "node:path";
4
4
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
5
5
  import { parseArgs } from "node:util";
@@ -59,13 +59,13 @@ const loadOrDie = async (configPath) => {
59
59
  return config;
60
60
  };
61
61
  /**
62
- * A client writes where its config says, not where the command was run from,
63
- * so `kizuna generate --config apps/api/kizuna.config.ts` lands the same files
62
+ * A file writes where its config says, not where the command was run from, so
63
+ * `kizuna generate --config apps/api/kizuna.config.ts` lands the same files
64
64
  * wherever it is invoked.
65
65
  */
66
- const besideConfig = (configPath, clients) => clients.map((client) => ({
67
- ...client,
68
- output: resolve(dirname(configPath), client.output)
66
+ const besideConfig = (configPath, files) => files.map((file) => ({
67
+ ...file,
68
+ output: resolve(dirname(configPath), file.output)
69
69
  }));
70
70
  const runGenerate = async (values) => {
71
71
  const configPath = configPathFrom(values.config);
@@ -83,7 +83,7 @@ const runGenerate = async (values) => {
83
83
  const typesCurrent = existsSync(typesPath) ? readFileSync(typesPath, "utf8") : void 0;
84
84
  const typesBehind = typesCurrent !== types;
85
85
  if (values.check) {
86
- const stale = checkClients(config.api, [...besideConfig(configPath, config.clients), snapshotTarget(configPath)]);
86
+ const stale = checkFiles(config.api, [...besideConfig(configPath, [...config.clients, ...config.generators]), snapshotTarget(configPath)]);
87
87
  if (!typesBehind && stale.length === 0) {
88
88
  process.stdout.write("Everything kizuna generates is up to date.\n");
89
89
  return;
@@ -93,8 +93,8 @@ const runGenerate = async (values) => {
93
93
  process.exit(1);
94
94
  }
95
95
  if (typesBehind) writeFileSync(typesPath, types);
96
- const written = writeClients(config.api, [...besideConfig(configPath, config.clients), snapshotTarget(configPath)]);
97
- const changed = [...typesBehind ? [displayPath(typesPath)] : [], ...written.filter((client) => client.changed).map((client) => displayPath(client.output))];
96
+ const written = writeFiles(config.api, [...besideConfig(configPath, [...config.clients, ...config.generators]), snapshotTarget(configPath)]);
97
+ const changed = [...typesBehind ? [displayPath(typesPath)] : [], ...written.filter((file) => file.changed).map((file) => displayPath(file.output))];
98
98
  process.stdout.write(changed.length > 0 ? `Wrote:\n${changed.map((file) => ` ${file}`).join("\n")}\n` : "Everything was already up to date.\n");
99
99
  };
100
100
  const runRoutes = async (values) => {
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_route_map = require("./route-map-I400Eb9_.cjs");
2
+ const require_route_map = require("./route-map-Sk1Wybox.cjs");
3
3
  let kizunajs_generator = require("kizunajs/generator");
4
4
  //#region src/api-notices.ts
5
5
  const readSunset = (route) => {
@@ -8,14 +8,7 @@ const readSunset = (route) => {
8
8
  return typeof declared === "string" ? declared : declared.date;
9
9
  };
10
10
  const daysBetween = (from, to) => Math.ceil((to.getTime() - from.getTime()) / 864e5);
11
- /**
12
- * Every route that is deprecated or has a sunset date, soonest first, with
13
- * undated deprecations last.
14
- *
15
- * Reads the same `deprecated` field the generated clients carry in an
16
- * editor, so a watcher and a hover agree.
17
- */
18
- const apiNotices = (0, kizunajs_generator.createGenerator)((options) => {
11
+ const noticesWalk = (options) => {
19
12
  const now = options.now ?? /* @__PURE__ */ new Date();
20
13
  const notices = [];
21
14
  return {
@@ -42,7 +35,15 @@ const apiNotices = (0, kizunajs_generator.createGenerator)((options) => {
42
35
  });
43
36
  }
44
37
  };
45
- });
38
+ };
39
+ /**
40
+ * Every route that is deprecated or has a sunset date, soonest first, with
41
+ * undated deprecations last.
42
+ *
43
+ * Reads the same `deprecated` field the generated clients carry in an
44
+ * editor, so a watcher and a hover agree.
45
+ */
46
+ const apiNotices = (api, options = {}) => (0, kizunajs_generator.walkApi)(api, noticesWalk(options));
46
47
  /**
47
48
  * One line per notice, for a watcher to print.
48
49
  *
@@ -64,7 +65,7 @@ const formatNotice = (notice) => {
64
65
  //#endregion
65
66
  exports.ConfigSyntaxError = require_route_map.ConfigSyntaxError;
66
67
  exports.apiNotices = apiNotices;
67
- exports.checkClients = require_route_map.checkClients;
68
+ exports.checkFiles = require_route_map.checkFiles;
68
69
  exports.diffAgainst = require_route_map.diffAgainst;
69
70
  exports.diffApis = require_route_map.diffApis;
70
71
  exports.diffSchemas = require_route_map.diffSchemas;
@@ -76,4 +77,4 @@ exports.generateConfigTypes = require_route_map.generateConfigTypes;
76
77
  exports.hasBreakingChange = require_route_map.hasBreakingChange;
77
78
  exports.loadConfig = require_route_map.loadConfig;
78
79
  exports.routeMap = require_route_map.routeMap;
79
- exports.writeClients = require_route_map.writeClients;
80
+ exports.writeFiles = require_route_map.writeFiles;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,4 @@
1
- import * as _$kizunajs from "kizunajs";
2
- import { ApiDefinition, ClientTarget, DiffSettings } from "kizunajs";
1
+ import { ApiDefinition, DiffSettings, GeneratedFile } from "kizunajs";
3
2
  //#region src/load-config.d.ts
4
3
  /**
5
4
  * One api a config declares, with everything generated from it. A config that
@@ -8,7 +7,11 @@ import { ApiDefinition, ClientTarget, DiffSettings } from "kizunajs";
8
7
  interface LoadedApi {
9
8
  name: string;
10
9
  api: ApiDefinition;
11
- clients: readonly ClientTarget[];
10
+ clients: readonly GeneratedFile[];
11
+ /**
12
+ * The files the config's plugins generate.
13
+ */
14
+ generators: readonly GeneratedFile[];
12
15
  /**
13
16
  * Where `kizuna generate` writes the `Config`, when the config says.
14
17
  */
@@ -60,7 +63,7 @@ interface Notice {
60
63
  * Reads the same `deprecated` field the generated clients carry in an
61
64
  * editor, so a watcher and a hover agree.
62
65
  */
63
- declare const apiNotices: (contract: _$kizunajs.ApiDefinition, options: {
66
+ declare const apiNotices: (api: ApiDefinition, options?: {
64
67
  now?: Date;
65
68
  }) => Notice[];
66
69
  /**
@@ -157,18 +160,16 @@ declare const hasBreakingChange: (changes: Change[]) => boolean;
157
160
  //#endregion
158
161
  //#region src/generate-clients.d.ts
159
162
  /**
160
- * A client that was written, and whether it had to be.
163
+ * A file that was written, and whether it had to be.
161
164
  */
162
- interface WrittenClient {
163
- kind: string;
165
+ interface WrittenFile {
164
166
  output: string;
165
167
  changed: boolean;
166
168
  }
167
169
  /**
168
- * A generated client that does not match its api.
170
+ * A generated file that does not match its api.
169
171
  */
170
- interface StaleClient {
171
- kind: string;
172
+ interface StaleFile {
172
173
  output: string;
173
174
  /**
174
175
  * `missing` when nothing is there, `outdated` when what is there is old.
@@ -176,22 +177,24 @@ interface StaleClient {
176
177
  reason: 'missing' | 'outdated';
177
178
  }
178
179
  /**
179
- * Writes every client an api declares, leaving a file alone when it already
180
- * matches so watchers and build tools see no change.
180
+ * Writes every generated file, the clients and what plugins generate, leaving
181
+ * a file alone when it already matches so watchers and build tools see no
182
+ * change.
181
183
  */
182
- declare const writeClients: (contract: ApiDefinition, clients: readonly ClientTarget[]) => WrittenClient[];
184
+ declare const writeFiles: (contract: ApiDefinition, files: readonly GeneratedFile[]) => WrittenFile[];
183
185
  /**
184
- * Every client that no longer matches its api, without writing anything.
186
+ * Every generated file that no longer matches its api, without writing
187
+ * anything.
185
188
  *
186
189
  * This is what a pipeline runs: a generated client that has fallen behind is a
187
190
  * compile error waiting to happen in whatever imports it.
188
191
  */
189
- declare const checkClients: (contract: ApiDefinition, clients: readonly ClientTarget[]) => StaleClient[];
192
+ declare const checkFiles: (contract: ApiDefinition, files: readonly GeneratedFile[]) => StaleFile[];
190
193
  /**
191
194
  * What a pipeline prints when a check fails, naming the command that fixes it
192
195
  * rather than printing a diff nobody reads.
193
196
  */
194
- declare const formatStale: (stale: readonly StaleClient[], command?: string) => string;
197
+ declare const formatStale: (stale: readonly StaleFile[], command?: string) => string;
195
198
  //#endregion
196
199
  //#region src/generate-types.d.ts
197
200
  declare class ConfigSyntaxError extends Error {}
@@ -261,14 +264,18 @@ interface RouteEntry {
261
264
  tool?: string;
262
265
  deprecated?: string;
263
266
  sunset?: string;
267
+ /**
268
+ * `true` when the route is `hidden`: served, but in no generated client.
269
+ */
270
+ hidden?: true;
264
271
  }
265
272
  /**
266
273
  * Every route an api serves, in the order it declares them.
267
274
  */
268
- declare const routeMap: (contract: ApiDefinition, options: Record<string, never>) => RouteEntry[];
275
+ declare const routeMap: (api: ApiDefinition, _options?: Record<string, never>) => RouteEntry[];
269
276
  /**
270
277
  * The route map as aligned columns, one route per line.
271
278
  */
272
279
  declare const formatRoutes: (entries: readonly RouteEntry[]) => string;
273
280
  //#endregion
274
- export { type Change, type ChangeLevel, ConfigSyntaxError, type DiffAgainstOptions, type Direction, type LoadedApi, type Notice, type RouteEntry, type SchemaChange, type StaleClient, type WrittenClient, apiNotices, checkClients, diffAgainst, diffApis, diffSchemas, formatChange, formatNotice, formatRoutes, formatStale, generateConfigTypes, hasBreakingChange, loadConfig, routeMap, writeClients };
281
+ export { type Change, type ChangeLevel, ConfigSyntaxError, type DiffAgainstOptions, type Direction, type LoadedApi, type Notice, type RouteEntry, type SchemaChange, type StaleFile, type WrittenFile, apiNotices, checkFiles, diffAgainst, diffApis, diffSchemas, formatChange, formatNotice, formatRoutes, formatStale, generateConfigTypes, hasBreakingChange, loadConfig, routeMap, writeFiles };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
- import * as _$kizunajs from "kizunajs";
2
- import { ApiDefinition, ClientTarget, DiffSettings } from "kizunajs";
1
+ import { ApiDefinition, DiffSettings, GeneratedFile } from "kizunajs";
3
2
  //#region src/load-config.d.ts
4
3
  /**
5
4
  * One api a config declares, with everything generated from it. A config that
@@ -8,7 +7,11 @@ import { ApiDefinition, ClientTarget, DiffSettings } from "kizunajs";
8
7
  interface LoadedApi {
9
8
  name: string;
10
9
  api: ApiDefinition;
11
- clients: readonly ClientTarget[];
10
+ clients: readonly GeneratedFile[];
11
+ /**
12
+ * The files the config's plugins generate.
13
+ */
14
+ generators: readonly GeneratedFile[];
12
15
  /**
13
16
  * Where `kizuna generate` writes the `Config`, when the config says.
14
17
  */
@@ -60,7 +63,7 @@ interface Notice {
60
63
  * Reads the same `deprecated` field the generated clients carry in an
61
64
  * editor, so a watcher and a hover agree.
62
65
  */
63
- declare const apiNotices: (contract: _$kizunajs.ApiDefinition, options: {
66
+ declare const apiNotices: (api: ApiDefinition, options?: {
64
67
  now?: Date;
65
68
  }) => Notice[];
66
69
  /**
@@ -157,18 +160,16 @@ declare const hasBreakingChange: (changes: Change[]) => boolean;
157
160
  //#endregion
158
161
  //#region src/generate-clients.d.ts
159
162
  /**
160
- * A client that was written, and whether it had to be.
163
+ * A file that was written, and whether it had to be.
161
164
  */
162
- interface WrittenClient {
163
- kind: string;
165
+ interface WrittenFile {
164
166
  output: string;
165
167
  changed: boolean;
166
168
  }
167
169
  /**
168
- * A generated client that does not match its api.
170
+ * A generated file that does not match its api.
169
171
  */
170
- interface StaleClient {
171
- kind: string;
172
+ interface StaleFile {
172
173
  output: string;
173
174
  /**
174
175
  * `missing` when nothing is there, `outdated` when what is there is old.
@@ -176,22 +177,24 @@ interface StaleClient {
176
177
  reason: 'missing' | 'outdated';
177
178
  }
178
179
  /**
179
- * Writes every client an api declares, leaving a file alone when it already
180
- * matches so watchers and build tools see no change.
180
+ * Writes every generated file, the clients and what plugins generate, leaving
181
+ * a file alone when it already matches so watchers and build tools see no
182
+ * change.
181
183
  */
182
- declare const writeClients: (contract: ApiDefinition, clients: readonly ClientTarget[]) => WrittenClient[];
184
+ declare const writeFiles: (contract: ApiDefinition, files: readonly GeneratedFile[]) => WrittenFile[];
183
185
  /**
184
- * Every client that no longer matches its api, without writing anything.
186
+ * Every generated file that no longer matches its api, without writing
187
+ * anything.
185
188
  *
186
189
  * This is what a pipeline runs: a generated client that has fallen behind is a
187
190
  * compile error waiting to happen in whatever imports it.
188
191
  */
189
- declare const checkClients: (contract: ApiDefinition, clients: readonly ClientTarget[]) => StaleClient[];
192
+ declare const checkFiles: (contract: ApiDefinition, files: readonly GeneratedFile[]) => StaleFile[];
190
193
  /**
191
194
  * What a pipeline prints when a check fails, naming the command that fixes it
192
195
  * rather than printing a diff nobody reads.
193
196
  */
194
- declare const formatStale: (stale: readonly StaleClient[], command?: string) => string;
197
+ declare const formatStale: (stale: readonly StaleFile[], command?: string) => string;
195
198
  //#endregion
196
199
  //#region src/generate-types.d.ts
197
200
  declare class ConfigSyntaxError extends Error {}
@@ -261,14 +264,18 @@ interface RouteEntry {
261
264
  tool?: string;
262
265
  deprecated?: string;
263
266
  sunset?: string;
267
+ /**
268
+ * `true` when the route is `hidden`: served, but in no generated client.
269
+ */
270
+ hidden?: true;
264
271
  }
265
272
  /**
266
273
  * Every route an api serves, in the order it declares them.
267
274
  */
268
- declare const routeMap: (contract: ApiDefinition, options: Record<string, never>) => RouteEntry[];
275
+ declare const routeMap: (api: ApiDefinition, _options?: Record<string, never>) => RouteEntry[];
269
276
  /**
270
277
  * The route map as aligned columns, one route per line.
271
278
  */
272
279
  declare const formatRoutes: (entries: readonly RouteEntry[]) => string;
273
280
  //#endregion
274
- export { type Change, type ChangeLevel, ConfigSyntaxError, type DiffAgainstOptions, type Direction, type LoadedApi, type Notice, type RouteEntry, type SchemaChange, type StaleClient, type WrittenClient, apiNotices, checkClients, diffAgainst, diffApis, diffSchemas, formatChange, formatNotice, formatRoutes, formatStale, generateConfigTypes, hasBreakingChange, loadConfig, routeMap, writeClients };
281
+ export { type Change, type ChangeLevel, ConfigSyntaxError, type DiffAgainstOptions, type Direction, type LoadedApi, type Notice, type RouteEntry, type SchemaChange, type StaleFile, type WrittenFile, apiNotices, checkFiles, diffAgainst, diffApis, diffSchemas, formatChange, formatNotice, formatRoutes, formatStale, generateConfigTypes, hasBreakingChange, loadConfig, routeMap, writeFiles };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { _ as loadConfig, a as ConfigSyntaxError, c as formatStale, f as formatChange, g as diffSchemas, l as writeClients, n as routeMap, o as generateConfigTypes, p as hasBreakingChange, r as diffAgainst, s as checkClients, t as formatRoutes, u as diffApis } from "./route-map-C484dhbj.mjs";
2
- import { createGenerator } from "kizunajs/generator";
1
+ import { _ as loadConfig, a as ConfigSyntaxError, c as formatStale, f as formatChange, g as diffSchemas, l as writeFiles, n as routeMap, o as generateConfigTypes, p as hasBreakingChange, r as diffAgainst, s as checkFiles, t as formatRoutes, u as diffApis } from "./route-map-B2vDHecG.mjs";
2
+ import { walkApi } from "kizunajs/generator";
3
3
  //#region src/api-notices.ts
4
4
  const readSunset = (route) => {
5
5
  const declared = route.sunset;
@@ -7,14 +7,7 @@ const readSunset = (route) => {
7
7
  return typeof declared === "string" ? declared : declared.date;
8
8
  };
9
9
  const daysBetween = (from, to) => Math.ceil((to.getTime() - from.getTime()) / 864e5);
10
- /**
11
- * Every route that is deprecated or has a sunset date, soonest first, with
12
- * undated deprecations last.
13
- *
14
- * Reads the same `deprecated` field the generated clients carry in an
15
- * editor, so a watcher and a hover agree.
16
- */
17
- const apiNotices = createGenerator((options) => {
10
+ const noticesWalk = (options) => {
18
11
  const now = options.now ?? /* @__PURE__ */ new Date();
19
12
  const notices = [];
20
13
  return {
@@ -41,7 +34,15 @@ const apiNotices = createGenerator((options) => {
41
34
  });
42
35
  }
43
36
  };
44
- });
37
+ };
38
+ /**
39
+ * Every route that is deprecated or has a sunset date, soonest first, with
40
+ * undated deprecations last.
41
+ *
42
+ * Reads the same `deprecated` field the generated clients carry in an
43
+ * editor, so a watcher and a hover agree.
44
+ */
45
+ const apiNotices = (api, options = {}) => walkApi(api, noticesWalk(options));
45
46
  /**
46
47
  * One line per notice, for a watcher to print.
47
48
  *
@@ -61,4 +62,4 @@ const formatNotice = (notice) => {
61
62
  return `${notice.method} ${notice.path} ${notice.routeKey} ${parts.join(", ")}${suffix}`;
62
63
  };
63
64
  //#endregion
64
- export { ConfigSyntaxError, apiNotices, checkClients, diffAgainst, diffApis, diffSchemas, formatChange, formatNotice, formatRoutes, formatStale, generateConfigTypes, hasBreakingChange, loadConfig, routeMap, writeClients };
65
+ export { ConfigSyntaxError, apiNotices, checkFiles, diffAgainst, diffApis, diffSchemas, formatChange, formatNotice, formatRoutes, formatStale, generateConfigTypes, hasBreakingChange, loadConfig, routeMap, writeFiles };
@@ -1,6 +1,6 @@
1
1
  import { createJiti } from "jiti";
2
2
  import { apiEntries } from "kizunajs";
3
- import { createGenerator, deriveToolNames, flattenJobs, readDef, readObjectShape, resolveResponseBody, toToolName, unwrapOptionalWrappers } from "kizunajs/generator";
3
+ import { deriveToolNames, flattenJobs, readDef, readObjectShape, resolveResponseBody, toToolName, unwrapOptionalWrappers, walkApi } from "kizunajs/generator";
4
4
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
5
5
  import { parse, stringify } from "yaml";
6
6
  import { flattenRoutes } from "kizunajs/adapter";
@@ -25,6 +25,7 @@ const loadConfig = async (configPath) => {
25
25
  name,
26
26
  api: entry.api,
27
27
  clients: entry.clients ?? [],
28
+ generators: entry.generators ?? [],
28
29
  typesOutput: entry.typescript?.outputFile,
29
30
  diff: entry.diff ?? {}
30
31
  }));
@@ -183,10 +184,10 @@ const sunsetOf = (route) => {
183
184
  if (declared === void 0) return void 0;
184
185
  return typeof declared === "string" ? declared : declared.date;
185
186
  };
186
- const routeSnapshots = createGenerator(() => {
187
+ const routeSnapshots = (api) => {
187
188
  const routes = {};
188
- return {
189
- processRoute({ routeKey, route, deprecated }) {
189
+ return walkApi(api, {
190
+ processRoute({ routeKey, route, deprecated, hidden }) {
190
191
  const sunset = sunsetOf(route);
191
192
  const responses = {};
192
193
  for (const [status, response] of Object.entries(route.responses)) {
@@ -198,6 +199,7 @@ const routeSnapshots = createGenerator(() => {
198
199
  path: route.path,
199
200
  statuses: Object.keys(route.responses).map(Number).sort((a, b) => a - b),
200
201
  deprecated,
202
+ ...hidden ? { hidden: true } : {},
201
203
  ...sunset === void 0 ? {} : { sunset },
202
204
  ...route.body ? { body: toSchemaNode(route.body) } : {},
203
205
  ...route.query ? { query: toSchemaNode(route.query) } : {},
@@ -206,8 +208,8 @@ const routeSnapshots = createGenerator(() => {
206
208
  };
207
209
  },
208
210
  finalize: () => routes
209
- };
210
- });
211
+ });
212
+ };
211
213
  /**
212
214
  * Everything `kizuna diff` compares, as plain data.
213
215
  *
@@ -219,7 +221,7 @@ const toSnapshot = (api) => {
219
221
  const jobs = declared ? flattenJobs(declared).map((job) => job.jobKey).sort() : [];
220
222
  const tools = Object.fromEntries(flattenRoutes(api.routes).filter(({ route }) => route.tool !== void 0 && route.tool !== false).map(({ routeKey }) => [routeKey, toToolName(routeKey)]));
221
223
  return {
222
- routes: routeSnapshots(api, {}),
224
+ routes: routeSnapshots(api),
223
225
  jobs,
224
226
  tools
225
227
  };
@@ -244,9 +246,8 @@ const snapshotPathFor = (configPath) => {
244
246
  * `kizuna generate --check` refuses to let it go stale.
245
247
  */
246
248
  const snapshotTarget = (configPath) => ({
247
- kind: "snapshot",
248
249
  output: snapshotPathFor(configPath),
249
- generate: renderSnapshot
250
+ render: renderSnapshot
250
251
  });
251
252
  //#endregion
252
253
  //#region src/diff-apis.ts
@@ -355,6 +356,17 @@ const diffSnapshots = (before, after, options = {}) => {
355
356
  summary: `${httpLabel(arrived, key)} ${change.summary}`
356
357
  });
357
358
  }
359
+ if (gone.hidden !== true && arrived.hidden === true) changes.push({
360
+ level: "breaking",
361
+ key,
362
+ summary: `${httpLabel(arrived, key)} is now hidden`,
363
+ detail: "the server still serves it, but it is no longer in the generated clients or the OpenAPI document"
364
+ });
365
+ if (gone.hidden === true && arrived.hidden !== true) changes.push({
366
+ level: "added",
367
+ key,
368
+ summary: `${httpLabel(arrived, key)} is no longer hidden`
369
+ });
358
370
  if (!gone.deprecated && arrived.deprecated) changes.push({
359
371
  level: "changed",
360
372
  key,
@@ -430,38 +442,37 @@ const currentContents = (output) => {
430
442
  }
431
443
  };
432
444
  /**
433
- * Writes every client an api declares, leaving a file alone when it already
434
- * matches so watchers and build tools see no change.
445
+ * Writes every generated file, the clients and what plugins generate, leaving
446
+ * a file alone when it already matches so watchers and build tools see no
447
+ * change.
435
448
  */
436
- const writeClients = (contract, clients) => clients.map((client) => {
437
- const rendered = client.generate(contract);
438
- const changed = currentContents(client.output) !== rendered;
449
+ const writeFiles = (contract, files) => files.map((file) => {
450
+ const rendered = file.render(contract);
451
+ const changed = currentContents(file.output) !== rendered;
439
452
  if (changed) {
440
- mkdirSync(dirname(client.output), { recursive: true });
441
- writeFileSync(client.output, rendered);
453
+ mkdirSync(dirname(file.output), { recursive: true });
454
+ writeFileSync(file.output, rendered);
442
455
  }
443
456
  return {
444
- kind: client.kind,
445
- output: client.output,
457
+ output: file.output,
446
458
  changed
447
459
  };
448
460
  });
449
461
  /**
450
- * Every client that no longer matches its api, without writing anything.
462
+ * Every generated file that no longer matches its api, without writing
463
+ * anything.
451
464
  *
452
465
  * This is what a pipeline runs: a generated client that has fallen behind is a
453
466
  * compile error waiting to happen in whatever imports it.
454
467
  */
455
- const checkClients = (contract, clients) => clients.flatMap((client) => {
456
- const current = currentContents(client.output);
468
+ const checkFiles = (contract, files) => files.flatMap((file) => {
469
+ const current = currentContents(file.output);
457
470
  if (current === void 0) return [{
458
- kind: client.kind,
459
- output: client.output,
471
+ output: file.output,
460
472
  reason: "missing"
461
473
  }];
462
- if (current !== client.generate(contract)) return [{
463
- kind: client.kind,
464
- output: client.output,
474
+ if (current !== file.render(contract)) return [{
475
+ output: file.output,
465
476
  reason: "outdated"
466
477
  }];
467
478
  return [];
@@ -471,9 +482,9 @@ const checkClients = (contract, clients) => clients.flatMap((client) => {
471
482
  * rather than printing a diff nobody reads.
472
483
  */
473
484
  const formatStale = (stale, command = "kizuna generate") => {
474
- const lines = stale.map((client) => {
475
- const where = relative(process.cwd(), client.output);
476
- return client.reason === "missing" ? ` ${where} has not been generated` : ` ${where} is behind the config`;
485
+ const lines = stale.map((file) => {
486
+ const where = relative(process.cwd(), file.output);
487
+ return file.reason === "missing" ? ` ${where} has not been generated` : ` ${where} is behind the config`;
477
488
  });
478
489
  return [
479
490
  stale.length === 1 ? "A generated file is out of date:" : `${stale.length} generated files are out of date:`,
@@ -798,11 +809,11 @@ const describeSunset = (sunset) => {
798
809
  /**
799
810
  * Every route an api serves, in the order it declares them.
800
811
  */
801
- const routeMap = createGenerator((_options, _api) => {
812
+ const routeMap = (api, _options = {}) => {
802
813
  const entries = [];
803
814
  const toolKeys = [];
804
- return {
805
- processRoute({ routeKey, route, routeTags, deprecated, deprecationMessage }) {
815
+ return walkApi(api, {
816
+ processRoute({ routeKey, route, routeTags, deprecated, deprecationMessage, hidden }) {
806
817
  if (route.tool) toolKeys.push({
807
818
  key: routeKey,
808
819
  origin: "route"
@@ -814,7 +825,8 @@ const routeMap = createGenerator((_options, _api) => {
814
825
  auth: describeAuth(route.auth),
815
826
  tags: routeTags,
816
827
  deprecated: deprecated ? deprecationMessage ?? "" : void 0,
817
- sunset: describeSunset(route.sunset)
828
+ sunset: describeSunset(route.sunset),
829
+ ...hidden ? { hidden: true } : {}
818
830
  });
819
831
  },
820
832
  finalize() {
@@ -824,8 +836,8 @@ const routeMap = createGenerator((_options, _api) => {
824
836
  tool: names.get(entry.key) ?? (toolKeys.some((tool) => tool.key === entry.key) ? toToolName(entry.key) : void 0)
825
837
  }));
826
838
  }
827
- };
828
- });
839
+ });
840
+ };
829
841
  const pad = (text, width) => text + " ".repeat(Math.max(0, width - text.length));
830
842
  /**
831
843
  * The route map as aligned columns, one route per line.
@@ -840,10 +852,11 @@ const formatRoutes = (entries) => {
840
852
  `auth: ${entry.auth}`,
841
853
  entry.tool && `tool: ${entry.tool}`,
842
854
  entry.deprecated !== void 0 && `deprecated${entry.deprecated ? `, ${entry.deprecated}` : ""}`,
843
- entry.sunset && `sunset ${entry.sunset}`
855
+ entry.sunset && `sunset ${entry.sunset}`,
856
+ entry.hidden && "hidden"
844
857
  ].filter(Boolean);
845
858
  return `${pad(entry.method, methodWidth)} ${pad(entry.path, pathWidth)} ${pad(entry.key, keyWidth)} ${notes.join(" ")}`.trimEnd();
846
859
  }).join("\n");
847
860
  };
848
861
  //#endregion
849
- export { loadConfig as _, ConfigSyntaxError as a, formatStale as c, diffSnapshots as d, formatChange as f, diffSchemas as g, snapshotTarget as h, readSnapshot as i, writeClients as l, snapshotPathFor as m, routeMap as n, generateConfigTypes as o, hasBreakingChange as p, diffAgainst as r, checkClients as s, formatRoutes as t, diffApis as u };
862
+ export { loadConfig as _, ConfigSyntaxError as a, formatStale as c, diffSnapshots as d, formatChange as f, diffSchemas as g, snapshotTarget as h, readSnapshot as i, writeFiles as l, snapshotPathFor as m, routeMap as n, generateConfigTypes as o, hasBreakingChange as p, diffAgainst as r, checkFiles as s, formatRoutes as t, diffApis as u };
@@ -48,6 +48,7 @@ const loadConfig = async (configPath) => {
48
48
  name,
49
49
  api: entry.api,
50
50
  clients: entry.clients ?? [],
51
+ generators: entry.generators ?? [],
51
52
  typesOutput: entry.typescript?.outputFile,
52
53
  diff: entry.diff ?? {}
53
54
  }));
@@ -206,10 +207,10 @@ const sunsetOf = (route) => {
206
207
  if (declared === void 0) return void 0;
207
208
  return typeof declared === "string" ? declared : declared.date;
208
209
  };
209
- const routeSnapshots = (0, kizunajs_generator.createGenerator)(() => {
210
+ const routeSnapshots = (api) => {
210
211
  const routes = {};
211
- return {
212
- processRoute({ routeKey, route, deprecated }) {
212
+ return (0, kizunajs_generator.walkApi)(api, {
213
+ processRoute({ routeKey, route, deprecated, hidden }) {
213
214
  const sunset = sunsetOf(route);
214
215
  const responses = {};
215
216
  for (const [status, response] of Object.entries(route.responses)) {
@@ -221,6 +222,7 @@ const routeSnapshots = (0, kizunajs_generator.createGenerator)(() => {
221
222
  path: route.path,
222
223
  statuses: Object.keys(route.responses).map(Number).sort((a, b) => a - b),
223
224
  deprecated,
225
+ ...hidden ? { hidden: true } : {},
224
226
  ...sunset === void 0 ? {} : { sunset },
225
227
  ...route.body ? { body: toSchemaNode(route.body) } : {},
226
228
  ...route.query ? { query: toSchemaNode(route.query) } : {},
@@ -229,8 +231,8 @@ const routeSnapshots = (0, kizunajs_generator.createGenerator)(() => {
229
231
  };
230
232
  },
231
233
  finalize: () => routes
232
- };
233
- });
234
+ });
235
+ };
234
236
  /**
235
237
  * Everything `kizuna diff` compares, as plain data.
236
238
  *
@@ -242,7 +244,7 @@ const toSnapshot = (api) => {
242
244
  const jobs = declared ? (0, kizunajs_generator.flattenJobs)(declared).map((job) => job.jobKey).sort() : [];
243
245
  const tools = Object.fromEntries((0, kizunajs_adapter.flattenRoutes)(api.routes).filter(({ route }) => route.tool !== void 0 && route.tool !== false).map(({ routeKey }) => [routeKey, (0, kizunajs_generator.toToolName)(routeKey)]));
244
246
  return {
245
- routes: routeSnapshots(api, {}),
247
+ routes: routeSnapshots(api),
246
248
  jobs,
247
249
  tools
248
250
  };
@@ -267,9 +269,8 @@ const snapshotPathFor = (configPath) => {
267
269
  * `kizuna generate --check` refuses to let it go stale.
268
270
  */
269
271
  const snapshotTarget = (configPath) => ({
270
- kind: "snapshot",
271
272
  output: snapshotPathFor(configPath),
272
- generate: renderSnapshot
273
+ render: renderSnapshot
273
274
  });
274
275
  //#endregion
275
276
  //#region src/diff-apis.ts
@@ -378,6 +379,17 @@ const diffSnapshots = (before, after, options = {}) => {
378
379
  summary: `${httpLabel(arrived, key)} ${change.summary}`
379
380
  });
380
381
  }
382
+ if (gone.hidden !== true && arrived.hidden === true) changes.push({
383
+ level: "breaking",
384
+ key,
385
+ summary: `${httpLabel(arrived, key)} is now hidden`,
386
+ detail: "the server still serves it, but it is no longer in the generated clients or the OpenAPI document"
387
+ });
388
+ if (gone.hidden === true && arrived.hidden !== true) changes.push({
389
+ level: "added",
390
+ key,
391
+ summary: `${httpLabel(arrived, key)} is no longer hidden`
392
+ });
381
393
  if (!gone.deprecated && arrived.deprecated) changes.push({
382
394
  level: "changed",
383
395
  key,
@@ -453,38 +465,37 @@ const currentContents = (output) => {
453
465
  }
454
466
  };
455
467
  /**
456
- * Writes every client an api declares, leaving a file alone when it already
457
- * matches so watchers and build tools see no change.
468
+ * Writes every generated file, the clients and what plugins generate, leaving
469
+ * a file alone when it already matches so watchers and build tools see no
470
+ * change.
458
471
  */
459
- const writeClients = (contract, clients) => clients.map((client) => {
460
- const rendered = client.generate(contract);
461
- const changed = currentContents(client.output) !== rendered;
472
+ const writeFiles = (contract, files) => files.map((file) => {
473
+ const rendered = file.render(contract);
474
+ const changed = currentContents(file.output) !== rendered;
462
475
  if (changed) {
463
- (0, node_fs.mkdirSync)((0, node_path.dirname)(client.output), { recursive: true });
464
- (0, node_fs.writeFileSync)(client.output, rendered);
476
+ (0, node_fs.mkdirSync)((0, node_path.dirname)(file.output), { recursive: true });
477
+ (0, node_fs.writeFileSync)(file.output, rendered);
465
478
  }
466
479
  return {
467
- kind: client.kind,
468
- output: client.output,
480
+ output: file.output,
469
481
  changed
470
482
  };
471
483
  });
472
484
  /**
473
- * Every client that no longer matches its api, without writing anything.
485
+ * Every generated file that no longer matches its api, without writing
486
+ * anything.
474
487
  *
475
488
  * This is what a pipeline runs: a generated client that has fallen behind is a
476
489
  * compile error waiting to happen in whatever imports it.
477
490
  */
478
- const checkClients = (contract, clients) => clients.flatMap((client) => {
479
- const current = currentContents(client.output);
491
+ const checkFiles = (contract, files) => files.flatMap((file) => {
492
+ const current = currentContents(file.output);
480
493
  if (current === void 0) return [{
481
- kind: client.kind,
482
- output: client.output,
494
+ output: file.output,
483
495
  reason: "missing"
484
496
  }];
485
- if (current !== client.generate(contract)) return [{
486
- kind: client.kind,
487
- output: client.output,
497
+ if (current !== file.render(contract)) return [{
498
+ output: file.output,
488
499
  reason: "outdated"
489
500
  }];
490
501
  return [];
@@ -494,9 +505,9 @@ const checkClients = (contract, clients) => clients.flatMap((client) => {
494
505
  * rather than printing a diff nobody reads.
495
506
  */
496
507
  const formatStale = (stale, command = "kizuna generate") => {
497
- const lines = stale.map((client) => {
498
- const where = (0, node_path.relative)(process.cwd(), client.output);
499
- return client.reason === "missing" ? ` ${where} has not been generated` : ` ${where} is behind the config`;
508
+ const lines = stale.map((file) => {
509
+ const where = (0, node_path.relative)(process.cwd(), file.output);
510
+ return file.reason === "missing" ? ` ${where} has not been generated` : ` ${where} is behind the config`;
500
511
  });
501
512
  return [
502
513
  stale.length === 1 ? "A generated file is out of date:" : `${stale.length} generated files are out of date:`,
@@ -821,11 +832,11 @@ const describeSunset = (sunset) => {
821
832
  /**
822
833
  * Every route an api serves, in the order it declares them.
823
834
  */
824
- const routeMap = (0, kizunajs_generator.createGenerator)((_options, _api) => {
835
+ const routeMap = (api, _options = {}) => {
825
836
  const entries = [];
826
837
  const toolKeys = [];
827
- return {
828
- processRoute({ routeKey, route, routeTags, deprecated, deprecationMessage }) {
838
+ return (0, kizunajs_generator.walkApi)(api, {
839
+ processRoute({ routeKey, route, routeTags, deprecated, deprecationMessage, hidden }) {
829
840
  if (route.tool) toolKeys.push({
830
841
  key: routeKey,
831
842
  origin: "route"
@@ -837,7 +848,8 @@ const routeMap = (0, kizunajs_generator.createGenerator)((_options, _api) => {
837
848
  auth: describeAuth(route.auth),
838
849
  tags: routeTags,
839
850
  deprecated: deprecated ? deprecationMessage ?? "" : void 0,
840
- sunset: describeSunset(route.sunset)
851
+ sunset: describeSunset(route.sunset),
852
+ ...hidden ? { hidden: true } : {}
841
853
  });
842
854
  },
843
855
  finalize() {
@@ -847,8 +859,8 @@ const routeMap = (0, kizunajs_generator.createGenerator)((_options, _api) => {
847
859
  tool: names.get(entry.key) ?? (toolKeys.some((tool) => tool.key === entry.key) ? (0, kizunajs_generator.toToolName)(entry.key) : void 0)
848
860
  }));
849
861
  }
850
- };
851
- });
862
+ });
863
+ };
852
864
  const pad = (text, width) => text + " ".repeat(Math.max(0, width - text.length));
853
865
  /**
854
866
  * The route map as aligned columns, one route per line.
@@ -863,7 +875,8 @@ const formatRoutes = (entries) => {
863
875
  `auth: ${entry.auth}`,
864
876
  entry.tool && `tool: ${entry.tool}`,
865
877
  entry.deprecated !== void 0 && `deprecated${entry.deprecated ? `, ${entry.deprecated}` : ""}`,
866
- entry.sunset && `sunset ${entry.sunset}`
878
+ entry.sunset && `sunset ${entry.sunset}`,
879
+ entry.hidden && "hidden"
867
880
  ].filter(Boolean);
868
881
  return `${pad(entry.method, methodWidth)} ${pad(entry.path, pathWidth)} ${pad(entry.key, keyWidth)} ${notes.join(" ")}`.trimEnd();
869
882
  }).join("\n");
@@ -881,10 +894,10 @@ Object.defineProperty(exports, "__toESM", {
881
894
  return __toESM;
882
895
  }
883
896
  });
884
- Object.defineProperty(exports, "checkClients", {
897
+ Object.defineProperty(exports, "checkFiles", {
885
898
  enumerable: true,
886
899
  get: function() {
887
- return checkClients;
900
+ return checkFiles;
888
901
  }
889
902
  });
890
903
  Object.defineProperty(exports, "diffAgainst", {
@@ -971,9 +984,9 @@ Object.defineProperty(exports, "snapshotTarget", {
971
984
  return snapshotTarget;
972
985
  }
973
986
  });
974
- Object.defineProperty(exports, "writeClients", {
987
+ Object.defineProperty(exports, "writeFiles", {
975
988
  enumerable: true,
976
989
  get: function() {
977
- return writeClients;
990
+ return writeFiles;
978
991
  }
979
992
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizunajs/cli",
3
- "version": "2.0.0-beta.10",
3
+ "version": "2.0.0-beta.11",
4
4
  "description": "Command line tooling for Kizuna.js",
5
5
  "keywords": [
6
6
  "kizunajs",
@@ -62,14 +62,14 @@
62
62
  },
63
63
  "peerDependencies": {
64
64
  "zod": "^4.0.0",
65
- "kizunajs": "2.0.0-beta.10"
65
+ "kizunajs": "2.0.0-beta.11"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/node": "^24",
69
69
  "@types/react": "^19.2.18",
70
70
  "tsdown": "^0.21.0",
71
71
  "zod": "^4.0.0",
72
- "kizunajs": "2.0.0-beta.10"
72
+ "kizunajs": "2.0.0-beta.11"
73
73
  },
74
74
  "scripts": {
75
75
  "build": "tsdown src/index.ts src/cli.ts --format esm,cjs --dts --clean --external kizunajs --external zod --external jiti --external typescript",