@kizunajs/cli 2.0.0-beta.3 → 2.0.0-beta.4

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,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- const require_route_map = require("./route-map-BUq6Iw3_.cjs");
3
- let node_fs = require("node:fs");
2
+ const require_route_map = require("./route-map-yRIISgnC.cjs");
4
3
  let node_path = require("node:path");
4
+ let node_fs = require("node:fs");
5
5
  let node_util = require("node:util");
6
6
  //#region src/cli.ts
7
7
  const usage = `Usage: kizuna <command> [options]
@@ -24,6 +24,8 @@ generate:
24
24
  diff:
25
25
  --against <ref> The git ref to compare against. Default: main
26
26
  Exits 1 when a change breaks callers.
27
+ --from <path> Compare two snapshots directly, with no git and no
28
+ --to <path> config. Pass both.
27
29
  `;
28
30
  const COMMANDS = [
29
31
  "generate",
@@ -56,6 +58,15 @@ const loadOrDie = async (configPath) => {
56
58
  if (!config) die(`No config found at ${displayPath(configPath)}. A kizuna config default-exports its \`defineConfig(...)\` call.`);
57
59
  return config;
58
60
  };
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
64
+ * wherever it is invoked.
65
+ */
66
+ const besideConfig = (configPath, clients) => clients.map((client) => ({
67
+ ...client,
68
+ output: (0, node_path.resolve)((0, node_path.dirname)(configPath), client.output)
69
+ }));
59
70
  const runGenerate = async (values) => {
60
71
  const configPath = configPathFrom(values.config);
61
72
  const config = await loadOrDie(configPath);
@@ -72,7 +83,7 @@ const runGenerate = async (values) => {
72
83
  const typesCurrent = (0, node_fs.existsSync)(typesPath) ? (0, node_fs.readFileSync)(typesPath, "utf8") : void 0;
73
84
  const typesBehind = typesCurrent !== types;
74
85
  if (values.check) {
75
- const stale = require_route_map.checkClients(config.api, config.clients);
86
+ const stale = require_route_map.checkClients(config.api, [...besideConfig(configPath, config.clients), require_route_map.snapshotTarget(configPath)]);
76
87
  if (!typesBehind && stale.length === 0) {
77
88
  process.stdout.write("Everything kizuna generates is up to date.\n");
78
89
  return;
@@ -82,7 +93,7 @@ const runGenerate = async (values) => {
82
93
  process.exit(1);
83
94
  }
84
95
  if (typesBehind) (0, node_fs.writeFileSync)(typesPath, types);
85
- const written = require_route_map.writeClients(config.api, config.clients);
96
+ const written = require_route_map.writeClients(config.api, [...besideConfig(configPath, config.clients), require_route_map.snapshotTarget(configPath)]);
86
97
  const changed = [...typesBehind ? [displayPath(typesPath)] : [], ...written.filter((client) => client.changed).map((client) => displayPath(client.output))];
87
98
  process.stdout.write(changed.length > 0 ? `Wrote:\n${changed.map((file) => ` ${file}`).join("\n")}\n` : "Everything was already up to date.\n");
88
99
  };
@@ -91,8 +102,15 @@ const runRoutes = async (values) => {
91
102
  process.stdout.write(values.json ? `${JSON.stringify(entries, null, 2)}\n` : `${require_route_map.formatRoutes(entries)}\n`);
92
103
  };
93
104
  const runDiff = async (values) => {
94
- const configPath = configPathFrom(values.config);
95
- const changes = await require_route_map.diffAgainst(values.against ?? "main", configPath);
105
+ let changes;
106
+ if (values.from !== void 0 || values.to !== void 0) {
107
+ if (values.from === void 0 || values.to === void 0) die("Pass --from and --to together, or neither.");
108
+ changes = require_route_map.diffSnapshots(require_route_map.readSnapshot(values.from), require_route_map.readSnapshot(values.to));
109
+ } else {
110
+ const configPath = configPathFrom(values.config);
111
+ const config = await loadOrDie(configPath);
112
+ changes = require_route_map.diffAgainst(values.against ?? "main", require_route_map.snapshotPathFor(configPath), config.diff);
113
+ }
96
114
  if (values.json) process.stdout.write(`${JSON.stringify(changes, null, 2)}\n`);
97
115
  else if (changes.length === 0) process.stdout.write("Nothing callers depend on has moved.\n");
98
116
  else process.stdout.write(`${changes.map((change) => require_route_map.formatChange(change)).join("\n\n")}\n`);
@@ -109,7 +127,9 @@ const main = async () => {
109
127
  config: { type: "string" },
110
128
  types: { type: "string" },
111
129
  json: { type: "boolean" },
112
- against: { type: "string" }
130
+ against: { type: "string" },
131
+ from: { type: "string" },
132
+ to: { type: "string" }
113
133
  },
114
134
  strict: true
115
135
  });
package/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { a as generateConfigTypes, c as writeClients, d as hasBreakingChange, i as ConfigSyntaxError, n as routeMap, o as checkClients, p as loadConfig, r as diffAgainst, s as formatStale, t as formatRoutes, u as formatChange } from "./route-map-BZVDVH7m.mjs";
3
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
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-CRWVBQGf.mjs";
4
3
  import { dirname, relative, resolve } from "node:path";
4
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
5
5
  import { parseArgs } from "node:util";
6
6
  //#region src/cli.ts
7
7
  const usage = `Usage: kizuna <command> [options]
@@ -24,6 +24,8 @@ generate:
24
24
  diff:
25
25
  --against <ref> The git ref to compare against. Default: main
26
26
  Exits 1 when a change breaks callers.
27
+ --from <path> Compare two snapshots directly, with no git and no
28
+ --to <path> config. Pass both.
27
29
  `;
28
30
  const COMMANDS = [
29
31
  "generate",
@@ -56,6 +58,15 @@ const loadOrDie = async (configPath) => {
56
58
  if (!config) die(`No config found at ${displayPath(configPath)}. A kizuna config default-exports its \`defineConfig(...)\` call.`);
57
59
  return config;
58
60
  };
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
64
+ * wherever it is invoked.
65
+ */
66
+ const besideConfig = (configPath, clients) => clients.map((client) => ({
67
+ ...client,
68
+ output: resolve(dirname(configPath), client.output)
69
+ }));
59
70
  const runGenerate = async (values) => {
60
71
  const configPath = configPathFrom(values.config);
61
72
  const config = await loadOrDie(configPath);
@@ -72,7 +83,7 @@ const runGenerate = async (values) => {
72
83
  const typesCurrent = existsSync(typesPath) ? readFileSync(typesPath, "utf8") : void 0;
73
84
  const typesBehind = typesCurrent !== types;
74
85
  if (values.check) {
75
- const stale = checkClients(config.api, config.clients);
86
+ const stale = checkClients(config.api, [...besideConfig(configPath, config.clients), snapshotTarget(configPath)]);
76
87
  if (!typesBehind && stale.length === 0) {
77
88
  process.stdout.write("Everything kizuna generates is up to date.\n");
78
89
  return;
@@ -82,7 +93,7 @@ const runGenerate = async (values) => {
82
93
  process.exit(1);
83
94
  }
84
95
  if (typesBehind) writeFileSync(typesPath, types);
85
- const written = writeClients(config.api, config.clients);
96
+ const written = writeClients(config.api, [...besideConfig(configPath, config.clients), snapshotTarget(configPath)]);
86
97
  const changed = [...typesBehind ? [displayPath(typesPath)] : [], ...written.filter((client) => client.changed).map((client) => displayPath(client.output))];
87
98
  process.stdout.write(changed.length > 0 ? `Wrote:\n${changed.map((file) => ` ${file}`).join("\n")}\n` : "Everything was already up to date.\n");
88
99
  };
@@ -91,8 +102,15 @@ const runRoutes = async (values) => {
91
102
  process.stdout.write(values.json ? `${JSON.stringify(entries, null, 2)}\n` : `${formatRoutes(entries)}\n`);
92
103
  };
93
104
  const runDiff = async (values) => {
94
- const configPath = configPathFrom(values.config);
95
- const changes = await diffAgainst(values.against ?? "main", configPath);
105
+ let changes;
106
+ if (values.from !== void 0 || values.to !== void 0) {
107
+ if (values.from === void 0 || values.to === void 0) die("Pass --from and --to together, or neither.");
108
+ changes = diffSnapshots(readSnapshot(values.from), readSnapshot(values.to));
109
+ } else {
110
+ const configPath = configPathFrom(values.config);
111
+ const config = await loadOrDie(configPath);
112
+ changes = diffAgainst(values.against ?? "main", snapshotPathFor(configPath), config.diff);
113
+ }
96
114
  if (values.json) process.stdout.write(`${JSON.stringify(changes, null, 2)}\n`);
97
115
  else if (changes.length === 0) process.stdout.write("Nothing callers depend on has moved.\n");
98
116
  else process.stdout.write(`${changes.map((change) => formatChange(change)).join("\n\n")}\n`);
@@ -109,7 +127,9 @@ const main = async () => {
109
127
  config: { type: "string" },
110
128
  types: { type: "string" },
111
129
  json: { type: "boolean" },
112
- against: { type: "string" }
130
+ against: { type: "string" },
131
+ from: { type: "string" },
132
+ to: { type: "string" }
113
133
  },
114
134
  strict: true
115
135
  });
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-BUq6Iw3_.cjs");
2
+ const require_route_map = require("./route-map-yRIISgnC.cjs");
3
3
  let kizunajs_generator = require("kizunajs/generator");
4
4
  //#region src/api-notices.ts
5
5
  const readSunset = (route) => {
package/dist/index.d.cts CHANGED
@@ -1,7 +1,5 @@
1
1
  import * as _$kizunajs from "kizunajs";
2
- import { ApiDefinition, ClientTarget } from "kizunajs";
3
- import { z } from "zod";
4
-
2
+ import { ApiDefinition, ClientTarget, DiffSettings } from "kizunajs";
5
3
  //#region src/load-config.d.ts
6
4
  /**
7
5
  * One api a config declares, with everything generated from it. A config that
@@ -15,6 +13,10 @@ interface LoadedApi {
15
13
  * Where `kizuna generate` writes the `Config`, when the config says.
16
14
  */
17
15
  typesOutput: string | undefined;
16
+ /**
17
+ * What else `kizuna diff` treats as breaking.
18
+ */
19
+ diff: DiffSettings;
18
20
  }
19
21
  /**
20
22
  * Imports a config module with jiti, so a `.ts` config works without a build
@@ -69,6 +71,31 @@ declare const apiNotices: (contract: _$kizunajs.ApiDefinition, options: {
69
71
  */
70
72
  declare const formatNotice: (notice: Notice) => string;
71
73
  //#endregion
74
+ //#region src/snapshot.d.ts
75
+ /**
76
+ * A schema reduced to what a comparison needs: its kind, its fields, and the
77
+ * values it accepts when it is closed.
78
+ */
79
+ type SchemaNode = {
80
+ kind: 'object';
81
+ fields: Record<string, {
82
+ optional: boolean;
83
+ schema: SchemaNode;
84
+ }>;
85
+ refinements?: number;
86
+ } | {
87
+ kind: 'array';
88
+ element: SchemaNode;
89
+ refinements?: number;
90
+ } | {
91
+ kind: 'enum';
92
+ values: string[];
93
+ refinements?: number;
94
+ } | {
95
+ kind: string;
96
+ refinements?: number;
97
+ };
98
+ //#endregion
72
99
  //#region src/diff-apis.d.ts
73
100
  /**
74
101
  * How much a change asks of the people already calling an API.
@@ -86,13 +113,38 @@ interface Change {
86
113
  */
87
114
  detail?: string;
88
115
  }
116
+ interface DiffOptions {
117
+ /**
118
+ * Report a job key that is gone. A job answers `POST /jobs/run` by its
119
+ * dotted key, so this matters once something outside your own code
120
+ * dispatches them.
121
+ *
122
+ * @default false
123
+ */
124
+ jobs?: boolean;
125
+ /**
126
+ * Report an MCP tool a model can no longer call.
127
+ *
128
+ * @default false
129
+ */
130
+ tools?: boolean;
131
+ /**
132
+ * Treat a renamed dotted key, such as `users.getUser` becoming
133
+ * `users.fetchUser`, as breaking. The key names the method on a generated
134
+ * client, so a rename breaks anyone building an SDK on one and leaves the
135
+ * HTTP surface untouched.
136
+ *
137
+ * @default false
138
+ */
139
+ dottedKeys?: boolean;
140
+ }
89
141
  /**
90
- * What changed between two apis, worst first.
142
+ * What changed between two apis, for a caller holding both in memory.
91
143
  *
92
- * Compares the declarations rather than an OpenAPI document, so it sees route
93
- * keys, MCP tool names and job keys, none of which a document carries.
144
+ * `kizuna diff` reads snapshots instead, so it never has to load the other
145
+ * side's code.
94
146
  */
95
- declare const diffApis: (before: ApiDefinition, after: ApiDefinition) => Change[];
147
+ declare const diffApis: (before: ApiDefinition, after: ApiDefinition, options?: DiffOptions) => Change[];
96
148
  /**
97
149
  * One block per change, ready to print: the level, the summary, and the
98
150
  * detail indented beneath it.
@@ -176,29 +228,25 @@ interface SchemaChange {
176
228
  * What changed between two versions of one schema, and whether it breaks the
177
229
  * people already calling the route.
178
230
  */
179
- declare const diffSchemas: (before: z.core.$ZodType | undefined, after: z.core.$ZodType | undefined, direction: Direction, path?: string) => SchemaChange[];
231
+ declare const diffSchemas: (before: SchemaNode | undefined, after: SchemaNode | undefined, direction: Direction, path?: string) => SchemaChange[];
180
232
  //#endregion
181
233
  //#region src/diff-against.d.ts
182
- interface DiffAgainstOptions {
234
+ interface DiffAgainstOptions extends DiffOptions {
183
235
  /**
184
- * Repository the ref lives in.
236
+ * Where a relative path is resolved from.
185
237
  *
186
238
  * @default process.cwd()
187
239
  */
188
240
  cwd?: string;
189
241
  }
190
242
  /**
191
- * Compares the config on disk against the same config at a git ref.
243
+ * Compares a snapshot against the same file at a git ref.
192
244
  *
193
- * The ref is checked out into a worktree inside the repository, which costs a
194
- * few files rather than a clone. Nothing is installed there: module resolution
195
- * walks up to the repository's own `node_modules`, so the base tree needs only
196
- * its source.
197
- *
198
- * @example
199
- * const changes = await diffAgainst('main', './src/contract.ts');
245
+ * The ref is read with `git show`, so nothing is checked out, installed or
246
+ * executed for the other side. A snapshot written a year ago compares fine
247
+ * against one written today.
200
248
  */
201
- declare const diffAgainst: (ref: string, configPath: string, options?: DiffAgainstOptions) => Promise<Change[]>;
249
+ declare const diffAgainst: (ref: string, snapshotPath: string, options?: DiffAgainstOptions) => Change[];
202
250
  //#endregion
203
251
  //#region src/route-map.d.ts
204
252
  /**
package/dist/index.d.mts CHANGED
@@ -1,7 +1,5 @@
1
1
  import * as _$kizunajs from "kizunajs";
2
- import { ApiDefinition, ClientTarget } from "kizunajs";
3
- import { z } from "zod";
4
-
2
+ import { ApiDefinition, ClientTarget, DiffSettings } from "kizunajs";
5
3
  //#region src/load-config.d.ts
6
4
  /**
7
5
  * One api a config declares, with everything generated from it. A config that
@@ -15,6 +13,10 @@ interface LoadedApi {
15
13
  * Where `kizuna generate` writes the `Config`, when the config says.
16
14
  */
17
15
  typesOutput: string | undefined;
16
+ /**
17
+ * What else `kizuna diff` treats as breaking.
18
+ */
19
+ diff: DiffSettings;
18
20
  }
19
21
  /**
20
22
  * Imports a config module with jiti, so a `.ts` config works without a build
@@ -69,6 +71,31 @@ declare const apiNotices: (contract: _$kizunajs.ApiDefinition, options: {
69
71
  */
70
72
  declare const formatNotice: (notice: Notice) => string;
71
73
  //#endregion
74
+ //#region src/snapshot.d.ts
75
+ /**
76
+ * A schema reduced to what a comparison needs: its kind, its fields, and the
77
+ * values it accepts when it is closed.
78
+ */
79
+ type SchemaNode = {
80
+ kind: 'object';
81
+ fields: Record<string, {
82
+ optional: boolean;
83
+ schema: SchemaNode;
84
+ }>;
85
+ refinements?: number;
86
+ } | {
87
+ kind: 'array';
88
+ element: SchemaNode;
89
+ refinements?: number;
90
+ } | {
91
+ kind: 'enum';
92
+ values: string[];
93
+ refinements?: number;
94
+ } | {
95
+ kind: string;
96
+ refinements?: number;
97
+ };
98
+ //#endregion
72
99
  //#region src/diff-apis.d.ts
73
100
  /**
74
101
  * How much a change asks of the people already calling an API.
@@ -86,13 +113,38 @@ interface Change {
86
113
  */
87
114
  detail?: string;
88
115
  }
116
+ interface DiffOptions {
117
+ /**
118
+ * Report a job key that is gone. A job answers `POST /jobs/run` by its
119
+ * dotted key, so this matters once something outside your own code
120
+ * dispatches them.
121
+ *
122
+ * @default false
123
+ */
124
+ jobs?: boolean;
125
+ /**
126
+ * Report an MCP tool a model can no longer call.
127
+ *
128
+ * @default false
129
+ */
130
+ tools?: boolean;
131
+ /**
132
+ * Treat a renamed dotted key, such as `users.getUser` becoming
133
+ * `users.fetchUser`, as breaking. The key names the method on a generated
134
+ * client, so a rename breaks anyone building an SDK on one and leaves the
135
+ * HTTP surface untouched.
136
+ *
137
+ * @default false
138
+ */
139
+ dottedKeys?: boolean;
140
+ }
89
141
  /**
90
- * What changed between two apis, worst first.
142
+ * What changed between two apis, for a caller holding both in memory.
91
143
  *
92
- * Compares the declarations rather than an OpenAPI document, so it sees route
93
- * keys, MCP tool names and job keys, none of which a document carries.
144
+ * `kizuna diff` reads snapshots instead, so it never has to load the other
145
+ * side's code.
94
146
  */
95
- declare const diffApis: (before: ApiDefinition, after: ApiDefinition) => Change[];
147
+ declare const diffApis: (before: ApiDefinition, after: ApiDefinition, options?: DiffOptions) => Change[];
96
148
  /**
97
149
  * One block per change, ready to print: the level, the summary, and the
98
150
  * detail indented beneath it.
@@ -176,29 +228,25 @@ interface SchemaChange {
176
228
  * What changed between two versions of one schema, and whether it breaks the
177
229
  * people already calling the route.
178
230
  */
179
- declare const diffSchemas: (before: z.core.$ZodType | undefined, after: z.core.$ZodType | undefined, direction: Direction, path?: string) => SchemaChange[];
231
+ declare const diffSchemas: (before: SchemaNode | undefined, after: SchemaNode | undefined, direction: Direction, path?: string) => SchemaChange[];
180
232
  //#endregion
181
233
  //#region src/diff-against.d.ts
182
- interface DiffAgainstOptions {
234
+ interface DiffAgainstOptions extends DiffOptions {
183
235
  /**
184
- * Repository the ref lives in.
236
+ * Where a relative path is resolved from.
185
237
  *
186
238
  * @default process.cwd()
187
239
  */
188
240
  cwd?: string;
189
241
  }
190
242
  /**
191
- * Compares the config on disk against the same config at a git ref.
243
+ * Compares a snapshot against the same file at a git ref.
192
244
  *
193
- * The ref is checked out into a worktree inside the repository, which costs a
194
- * few files rather than a clone. Nothing is installed there: module resolution
195
- * walks up to the repository's own `node_modules`, so the base tree needs only
196
- * its source.
197
- *
198
- * @example
199
- * const changes = await diffAgainst('main', './src/contract.ts');
245
+ * The ref is read with `git show`, so nothing is checked out, installed or
246
+ * executed for the other side. A snapshot written a year ago compares fine
247
+ * against one written today.
200
248
  */
201
- declare const diffAgainst: (ref: string, configPath: string, options?: DiffAgainstOptions) => Promise<Change[]>;
249
+ declare const diffAgainst: (ref: string, snapshotPath: string, options?: DiffAgainstOptions) => Change[];
202
250
  //#endregion
203
251
  //#region src/route-map.d.ts
204
252
  /**
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as generateConfigTypes, c as writeClients, d as hasBreakingChange, f as diffSchemas, i as ConfigSyntaxError, l as diffApis, n as routeMap, o as checkClients, p as loadConfig, r as diffAgainst, s as formatStale, t as formatRoutes, u as formatChange } from "./route-map-BZVDVH7m.mjs";
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-CRWVBQGf.mjs";
2
2
  import { createGenerator } from "kizunajs/generator";
3
3
  //#region src/api-notices.ts
4
4
  const readSunset = (route) => {