@kizunajs/cli 2.0.0-beta.0

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/LICENSE.MD ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sondre Ørland
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # @kizunajs/cli
2
+
3
+ The `kizuna` command, which writes the `Config` your `kizuna.config.ts` implies and every client it declares. The package also exports the config loader the Swift and Kotlin generators share.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ pnpm add -D @kizunajs/cli
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```sh
14
+ kizuna generate
15
+ ```
16
+
17
+ Writes `kizuna.types.ts` beside your config, and every target under `clients`. A file that already matches is left alone.
18
+
19
+ ```sh
20
+ kizuna generate --check
21
+ ```
22
+
23
+ The same work without writing. Names whatever has fallen behind and exits `1`, for a pipeline to fail on.
24
+
25
+ ## Documentation
26
+
27
+ [Configuration](https://kizunajs.com/docs/configuration)
package/dist/cli.cjs ADDED
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env node
2
+ const require_route_map = require("./route-map-DW2UUkD_.cjs");
3
+ let node_fs = require("node:fs");
4
+ let node_path = require("node:path");
5
+ let node_util = require("node:util");
6
+ //#region src/cli.ts
7
+ const usage = `Usage: kizuna <command> [options]
8
+
9
+ Commands:
10
+ generate Write kizuna.types.ts and every client the config declares.
11
+ routes Print every route the config serves.
12
+ diff Compare the config against the same config at a git ref.
13
+
14
+ Options:
15
+ --config <path> Path to the config. Default: kizuna.config.ts
16
+ --json Print machine-readable output. routes, diff.
17
+
18
+ generate:
19
+ --check Report what would be rewritten and write nothing. Exits 1
20
+ when anything is behind, for a pipeline to fail on.
21
+ --types <path> Where the Config is written, overriding the config's
22
+ typescript.outputFile.
23
+
24
+ diff:
25
+ --against <ref> The git ref to compare against. Default: main
26
+ Exits 1 when a change breaks callers.
27
+ `;
28
+ const COMMANDS = [
29
+ "generate",
30
+ "routes",
31
+ "diff"
32
+ ];
33
+ /**
34
+ * A path as the person reading the terminal knows it: relative to where they
35
+ * ran the command, unless that climbs out of the directory.
36
+ */
37
+ const displayPath = (file) => {
38
+ const shown = (0, node_path.relative)(process.cwd(), file);
39
+ return shown.startsWith("..") ? file : shown;
40
+ };
41
+ const die = (message, code = 1) => {
42
+ process.stderr.write(`${message}\n`);
43
+ process.exit(code);
44
+ };
45
+ /**
46
+ * Resolves the config the command runs against, dying with the same message
47
+ * whichever command asked.
48
+ */
49
+ const configPathFrom = (given) => {
50
+ const configPath = (0, node_path.resolve)(process.cwd(), given ?? "kizuna.config.ts");
51
+ if (!(0, node_fs.existsSync)(configPath)) die(`No config at ${displayPath(configPath)}. Pass --config to point at one.`);
52
+ return configPath;
53
+ };
54
+ const loadOrDie = async (configPath) => {
55
+ const [config] = await require_route_map.loadConfig(configPath);
56
+ if (!config) die(`No config found at ${displayPath(configPath)}. A kizuna config default-exports its \`defineConfig(...)\` call.`);
57
+ return config;
58
+ };
59
+ const runGenerate = async (values) => {
60
+ const configPath = configPathFrom(values.config);
61
+ let types;
62
+ try {
63
+ types = require_route_map.generateConfigTypes((0, node_fs.readFileSync)(configPath, "utf8"), configPath);
64
+ } catch (error) {
65
+ if (error instanceof require_route_map.ConfigSyntaxError) die(`${displayPath(configPath)}: ${error.message}`);
66
+ throw error;
67
+ }
68
+ const config = await loadOrDie(configPath);
69
+ const typesOutput = values.types ?? config.typesOutput;
70
+ if (typesOutput === void 0) die(`${displayPath(configPath)} declares no \`typescript.outputFile\`, which is where the \`Config\` is written. Add one, or pass --types.`);
71
+ const typesPath = (0, node_path.resolve)((0, node_path.dirname)(configPath), typesOutput);
72
+ const typesCurrent = (0, node_fs.existsSync)(typesPath) ? (0, node_fs.readFileSync)(typesPath, "utf8") : void 0;
73
+ const typesBehind = typesCurrent !== types;
74
+ if (values.check) {
75
+ const stale = require_route_map.checkClients(config.api, config.clients);
76
+ if (!typesBehind && stale.length === 0) {
77
+ process.stdout.write("Everything kizuna generates is up to date.\n");
78
+ return;
79
+ }
80
+ if (typesBehind) process.stdout.write(` ${displayPath(typesPath)} is ${typesCurrent === void 0 ? "missing" : "behind the config"}\n`);
81
+ if (stale.length > 0) process.stdout.write(`${require_route_map.formatStale(stale)}\n`);
82
+ process.exit(1);
83
+ }
84
+ if (typesBehind) (0, node_fs.writeFileSync)(typesPath, types);
85
+ const written = require_route_map.writeClients(config.api, config.clients);
86
+ const changed = [...typesBehind ? [displayPath(typesPath)] : [], ...written.filter((client) => client.changed).map((client) => displayPath(client.output))];
87
+ process.stdout.write(changed.length > 0 ? `Wrote:\n${changed.map((file) => ` ${file}`).join("\n")}\n` : "Everything was already up to date.\n");
88
+ };
89
+ const runRoutes = async (values) => {
90
+ const entries = require_route_map.routeMap((await loadOrDie(configPathFrom(values.config))).api, {});
91
+ process.stdout.write(values.json ? `${JSON.stringify(entries, null, 2)}\n` : `${require_route_map.formatRoutes(entries)}\n`);
92
+ };
93
+ const runDiff = async (values) => {
94
+ const configPath = configPathFrom(values.config);
95
+ const changes = await require_route_map.diffAgainst(values.against ?? "main", configPath);
96
+ if (values.json) process.stdout.write(`${JSON.stringify(changes, null, 2)}\n`);
97
+ else if (changes.length === 0) process.stdout.write("Nothing callers depend on has moved.\n");
98
+ else process.stdout.write(`${changes.map((change) => require_route_map.formatChange(change)).join("\n\n")}\n`);
99
+ if (require_route_map.hasBreakingChange(changes)) process.exit(1);
100
+ };
101
+ const main = async () => {
102
+ const argv = process.argv.slice(2);
103
+ const command = argv[0];
104
+ if (command === void 0 || !COMMANDS.includes(command)) die(usage, command === void 0 || command === "--help" || command === "-h" ? 0 : 1);
105
+ const { values } = (0, node_util.parseArgs)({
106
+ args: argv.slice(1),
107
+ options: {
108
+ check: { type: "boolean" },
109
+ config: { type: "string" },
110
+ types: { type: "string" },
111
+ json: { type: "boolean" },
112
+ against: { type: "string" }
113
+ },
114
+ strict: true
115
+ });
116
+ if (command === "routes") return runRoutes(values);
117
+ if (command === "diff") return runDiff(values);
118
+ return runGenerate(values);
119
+ };
120
+ main().catch((error) => {
121
+ die(`Error: ${error instanceof Error ? error.message : String(error)}`);
122
+ });
123
+ //#endregion
package/dist/cli.d.cts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/cli.mjs ADDED
@@ -0,0 +1,124 @@
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-D7cBgYmT.mjs";
3
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
4
+ import { dirname, relative, resolve } from "node:path";
5
+ import { parseArgs } from "node:util";
6
+ //#region src/cli.ts
7
+ const usage = `Usage: kizuna <command> [options]
8
+
9
+ Commands:
10
+ generate Write kizuna.types.ts and every client the config declares.
11
+ routes Print every route the config serves.
12
+ diff Compare the config against the same config at a git ref.
13
+
14
+ Options:
15
+ --config <path> Path to the config. Default: kizuna.config.ts
16
+ --json Print machine-readable output. routes, diff.
17
+
18
+ generate:
19
+ --check Report what would be rewritten and write nothing. Exits 1
20
+ when anything is behind, for a pipeline to fail on.
21
+ --types <path> Where the Config is written, overriding the config's
22
+ typescript.outputFile.
23
+
24
+ diff:
25
+ --against <ref> The git ref to compare against. Default: main
26
+ Exits 1 when a change breaks callers.
27
+ `;
28
+ const COMMANDS = [
29
+ "generate",
30
+ "routes",
31
+ "diff"
32
+ ];
33
+ /**
34
+ * A path as the person reading the terminal knows it: relative to where they
35
+ * ran the command, unless that climbs out of the directory.
36
+ */
37
+ const displayPath = (file) => {
38
+ const shown = relative(process.cwd(), file);
39
+ return shown.startsWith("..") ? file : shown;
40
+ };
41
+ const die = (message, code = 1) => {
42
+ process.stderr.write(`${message}\n`);
43
+ process.exit(code);
44
+ };
45
+ /**
46
+ * Resolves the config the command runs against, dying with the same message
47
+ * whichever command asked.
48
+ */
49
+ const configPathFrom = (given) => {
50
+ const configPath = resolve(process.cwd(), given ?? "kizuna.config.ts");
51
+ if (!existsSync(configPath)) die(`No config at ${displayPath(configPath)}. Pass --config to point at one.`);
52
+ return configPath;
53
+ };
54
+ const loadOrDie = async (configPath) => {
55
+ const [config] = await loadConfig(configPath);
56
+ if (!config) die(`No config found at ${displayPath(configPath)}. A kizuna config default-exports its \`defineConfig(...)\` call.`);
57
+ return config;
58
+ };
59
+ const runGenerate = async (values) => {
60
+ const configPath = configPathFrom(values.config);
61
+ let types;
62
+ try {
63
+ types = generateConfigTypes(readFileSync(configPath, "utf8"), configPath);
64
+ } catch (error) {
65
+ if (error instanceof ConfigSyntaxError) die(`${displayPath(configPath)}: ${error.message}`);
66
+ throw error;
67
+ }
68
+ const config = await loadOrDie(configPath);
69
+ const typesOutput = values.types ?? config.typesOutput;
70
+ if (typesOutput === void 0) die(`${displayPath(configPath)} declares no \`typescript.outputFile\`, which is where the \`Config\` is written. Add one, or pass --types.`);
71
+ const typesPath = resolve(dirname(configPath), typesOutput);
72
+ const typesCurrent = existsSync(typesPath) ? readFileSync(typesPath, "utf8") : void 0;
73
+ const typesBehind = typesCurrent !== types;
74
+ if (values.check) {
75
+ const stale = checkClients(config.api, config.clients);
76
+ if (!typesBehind && stale.length === 0) {
77
+ process.stdout.write("Everything kizuna generates is up to date.\n");
78
+ return;
79
+ }
80
+ if (typesBehind) process.stdout.write(` ${displayPath(typesPath)} is ${typesCurrent === void 0 ? "missing" : "behind the config"}\n`);
81
+ if (stale.length > 0) process.stdout.write(`${formatStale(stale)}\n`);
82
+ process.exit(1);
83
+ }
84
+ if (typesBehind) writeFileSync(typesPath, types);
85
+ const written = writeClients(config.api, config.clients);
86
+ const changed = [...typesBehind ? [displayPath(typesPath)] : [], ...written.filter((client) => client.changed).map((client) => displayPath(client.output))];
87
+ process.stdout.write(changed.length > 0 ? `Wrote:\n${changed.map((file) => ` ${file}`).join("\n")}\n` : "Everything was already up to date.\n");
88
+ };
89
+ const runRoutes = async (values) => {
90
+ const entries = routeMap((await loadOrDie(configPathFrom(values.config))).api, {});
91
+ process.stdout.write(values.json ? `${JSON.stringify(entries, null, 2)}\n` : `${formatRoutes(entries)}\n`);
92
+ };
93
+ const runDiff = async (values) => {
94
+ const configPath = configPathFrom(values.config);
95
+ const changes = await diffAgainst(values.against ?? "main", configPath);
96
+ if (values.json) process.stdout.write(`${JSON.stringify(changes, null, 2)}\n`);
97
+ else if (changes.length === 0) process.stdout.write("Nothing callers depend on has moved.\n");
98
+ else process.stdout.write(`${changes.map((change) => formatChange(change)).join("\n\n")}\n`);
99
+ if (hasBreakingChange(changes)) process.exit(1);
100
+ };
101
+ const main = async () => {
102
+ const argv = process.argv.slice(2);
103
+ const command = argv[0];
104
+ if (command === void 0 || !COMMANDS.includes(command)) die(usage, command === void 0 || command === "--help" || command === "-h" ? 0 : 1);
105
+ const { values } = parseArgs({
106
+ args: argv.slice(1),
107
+ options: {
108
+ check: { type: "boolean" },
109
+ config: { type: "string" },
110
+ types: { type: "string" },
111
+ json: { type: "boolean" },
112
+ against: { type: "string" }
113
+ },
114
+ strict: true
115
+ });
116
+ if (command === "routes") return runRoutes(values);
117
+ if (command === "diff") return runDiff(values);
118
+ return runGenerate(values);
119
+ };
120
+ main().catch((error) => {
121
+ die(`Error: ${error instanceof Error ? error.message : String(error)}`);
122
+ });
123
+ //#endregion
124
+ export {};
package/dist/index.cjs ADDED
@@ -0,0 +1,79 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_route_map = require("./route-map-DW2UUkD_.cjs");
3
+ let kizunajs_generator = require("kizunajs/generator");
4
+ //#region src/api-notices.ts
5
+ const readSunset = (route) => {
6
+ const declared = route.sunset;
7
+ if (declared === void 0) return void 0;
8
+ return typeof declared === "string" ? declared : declared.date;
9
+ };
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) => {
19
+ const now = options.now ?? /* @__PURE__ */ new Date();
20
+ const notices = [];
21
+ return {
22
+ processRoute({ routeKey, route, deprecated, deprecationMessage }) {
23
+ const sunset = readSunset(route);
24
+ if (!deprecated && sunset === void 0) return;
25
+ const sunsetDate = sunset === void 0 ? void 0 : new Date(sunset);
26
+ const dated = sunsetDate !== void 0 && !Number.isNaN(sunsetDate.getTime());
27
+ notices.push({
28
+ routeKey,
29
+ method: route.method,
30
+ path: route.path,
31
+ deprecated,
32
+ ...deprecationMessage === void 0 ? {} : { message: deprecationMessage },
33
+ ...sunset === void 0 ? {} : { sunset },
34
+ ...dated ? { daysUntilSunset: daysBetween(now, sunsetDate) } : {}
35
+ });
36
+ },
37
+ finalize() {
38
+ return notices.sort((left, right) => {
39
+ if (left.daysUntilSunset === void 0) return right.daysUntilSunset === void 0 ? 0 : 1;
40
+ if (right.daysUntilSunset === void 0) return -1;
41
+ return left.daysUntilSunset - right.daysUntilSunset;
42
+ });
43
+ }
44
+ };
45
+ });
46
+ /**
47
+ * One line per notice, for a watcher to print.
48
+ *
49
+ * @example
50
+ * DELETE /users/:id users.deleteUser deprecated, sunset in 14 days
51
+ */
52
+ const formatNotice = (notice) => {
53
+ const parts = [];
54
+ if (notice.deprecated) parts.push("deprecated");
55
+ if (notice.daysUntilSunset !== void 0) {
56
+ const days = notice.daysUntilSunset;
57
+ if (days < 0) parts.push(`sunset ${Math.abs(days)} days ago`);
58
+ else if (days === 0) parts.push("sunset today");
59
+ else parts.push(`sunset in ${days} days`);
60
+ } else if (notice.sunset !== void 0) parts.push(`sunset ${notice.sunset}`);
61
+ const suffix = notice.message === void 0 ? "" : `. ${notice.message}`;
62
+ return `${notice.method} ${notice.path} ${notice.routeKey} ${parts.join(", ")}${suffix}`;
63
+ };
64
+ //#endregion
65
+ exports.ConfigSyntaxError = require_route_map.ConfigSyntaxError;
66
+ exports.apiNotices = apiNotices;
67
+ exports.checkClients = require_route_map.checkClients;
68
+ exports.diffAgainst = require_route_map.diffAgainst;
69
+ exports.diffApis = require_route_map.diffApis;
70
+ exports.diffSchemas = require_route_map.diffSchemas;
71
+ exports.formatChange = require_route_map.formatChange;
72
+ exports.formatNotice = formatNotice;
73
+ exports.formatRoutes = require_route_map.formatRoutes;
74
+ exports.formatStale = require_route_map.formatStale;
75
+ exports.generateConfigTypes = require_route_map.generateConfigTypes;
76
+ exports.hasBreakingChange = require_route_map.hasBreakingChange;
77
+ exports.loadConfig = require_route_map.loadConfig;
78
+ exports.routeMap = require_route_map.routeMap;
79
+ exports.writeClients = require_route_map.writeClients;
@@ -0,0 +1,223 @@
1
+ import * as _$kizunajs from "kizunajs";
2
+ import { ApiDefinition, ClientTarget } from "kizunajs";
3
+ import { z } from "zod";
4
+
5
+ //#region src/load-config.d.ts
6
+ /**
7
+ * One api a config declares, with everything generated from it. A config that
8
+ * declares a single api reports it under `default`.
9
+ */
10
+ interface LoadedApi {
11
+ name: string;
12
+ api: ApiDefinition;
13
+ clients: readonly ClientTarget[];
14
+ /**
15
+ * Where `kizuna generate` writes the `Config`, when the config says.
16
+ */
17
+ typesOutput: string | undefined;
18
+ }
19
+ /**
20
+ * Imports a config module with jiti, so a `.ts` config works without a build
21
+ * step, and returns every api it declares along with the clients and the types
22
+ * output each one asks for.
23
+ *
24
+ * Returns an empty list when the module default-exports nothing that looks like
25
+ * a config.
26
+ */
27
+ declare const loadConfig: (configPath: string) => Promise<LoadedApi[]>;
28
+ //#endregion
29
+ //#region src/api-notices.d.ts
30
+ /**
31
+ * A route that announces its own retirement.
32
+ */
33
+ interface Notice {
34
+ /**
35
+ * `users.getUser`.
36
+ */
37
+ routeKey: string;
38
+ method: string;
39
+ path: string;
40
+ deprecated: boolean;
41
+ /**
42
+ * What the route's `deprecated` says to use instead.
43
+ */
44
+ message?: string;
45
+ /**
46
+ * When it will be removed, ISO 8601, from the route's `sunset`.
47
+ */
48
+ sunset?: string;
49
+ /**
50
+ * Whole days until `sunset`, negative once it has passed.
51
+ */
52
+ daysUntilSunset?: number;
53
+ }
54
+ /**
55
+ * Every route that is deprecated or has a sunset date, soonest first, with
56
+ * undated deprecations last.
57
+ *
58
+ * Reads the same `deprecated` field the generated clients carry in an
59
+ * editor, so a watcher and a hover agree.
60
+ */
61
+ declare const apiNotices: (contract: _$kizunajs.ApiDefinition, options: {
62
+ now?: Date;
63
+ }) => Notice[];
64
+ /**
65
+ * One line per notice, for a watcher to print.
66
+ *
67
+ * @example
68
+ * DELETE /users/:id users.deleteUser deprecated, sunset in 14 days
69
+ */
70
+ declare const formatNotice: (notice: Notice) => string;
71
+ //#endregion
72
+ //#region src/diff-apis.d.ts
73
+ /**
74
+ * How much a change asks of the people already calling an API.
75
+ */
76
+ type ChangeLevel = 'breaking' | 'changed' | 'added';
77
+ interface Change {
78
+ level: ChangeLevel;
79
+ /**
80
+ * `users.getUser`, or the job or tool key the change is about.
81
+ */
82
+ key: string;
83
+ summary: string;
84
+ /**
85
+ * What it costs whoever is already calling it.
86
+ */
87
+ detail?: string;
88
+ }
89
+ /**
90
+ * What changed between two apis, worst first.
91
+ *
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.
94
+ */
95
+ declare const diffApis: (before: ApiDefinition, after: ApiDefinition) => Change[];
96
+ /**
97
+ * One block per change, ready to print: the level, the summary, and the
98
+ * detail indented beneath it.
99
+ */
100
+ declare const formatChange: (change: Change) => string;
101
+ /**
102
+ * Whether a diff should fail a pipeline.
103
+ */
104
+ declare const hasBreakingChange: (changes: Change[]) => boolean;
105
+ //#endregion
106
+ //#region src/generate-clients.d.ts
107
+ /**
108
+ * A client that was written, and whether it had to be.
109
+ */
110
+ interface WrittenClient {
111
+ kind: string;
112
+ output: string;
113
+ changed: boolean;
114
+ }
115
+ /**
116
+ * A generated client that does not match its api.
117
+ */
118
+ interface StaleClient {
119
+ kind: string;
120
+ output: string;
121
+ /**
122
+ * `missing` when nothing is there, `outdated` when what is there is old.
123
+ */
124
+ reason: 'missing' | 'outdated';
125
+ }
126
+ /**
127
+ * Writes every client an api declares, leaving a file alone when it already
128
+ * matches so watchers and build tools see no change.
129
+ */
130
+ declare const writeClients: (contract: ApiDefinition, clients: readonly ClientTarget[]) => WrittenClient[];
131
+ /**
132
+ * Every client that no longer matches its api, without writing anything.
133
+ *
134
+ * This is what a pipeline runs: a generated client that has fallen behind is a
135
+ * compile error waiting to happen in whatever imports it.
136
+ */
137
+ declare const checkClients: (contract: ApiDefinition, clients: readonly ClientTarget[]) => StaleClient[];
138
+ /**
139
+ * What a pipeline prints when a check fails, naming the command that fixes it
140
+ * rather than printing a diff nobody reads.
141
+ */
142
+ declare const formatStale: (stale: readonly StaleClient[], command?: string) => string;
143
+ //#endregion
144
+ //#region src/generate-types.d.ts
145
+ declare class ConfigSyntaxError extends Error {}
146
+ /**
147
+ * Write the `Config` a `kizuna.config.ts` implies, which is what
148
+ * `new Kizuna<Config>()` is typed by.
149
+ *
150
+ * Read from the config's syntax rather than by running it: the generated file
151
+ * imports the same names the config did, and a config that loads is not a
152
+ * prerequisite for typing the routes it serves.
153
+ */
154
+ declare const generateConfigTypes: (configSource: string, fileName?: string) => string;
155
+ //#endregion
156
+ //#region src/diff-schemas.d.ts
157
+ /**
158
+ * Which way a schema travels, which decides what a change costs.
159
+ *
160
+ * A caller sends requests and reads responses, so tightening an input and
161
+ * dropping an output are the two that break them.
162
+ */
163
+ type Direction = 'request' | 'response';
164
+ interface SchemaChange {
165
+ breaking: boolean;
166
+ /**
167
+ * `body.organisationId`, relative to the schema being compared.
168
+ */
169
+ path: string;
170
+ summary: string;
171
+ }
172
+ /**
173
+ * What changed between two versions of one schema, and whether it breaks the
174
+ * people already calling the route.
175
+ */
176
+ declare const diffSchemas: (before: z.core.$ZodType | undefined, after: z.core.$ZodType | undefined, direction: Direction, path?: string) => SchemaChange[];
177
+ //#endregion
178
+ //#region src/diff-against.d.ts
179
+ interface DiffAgainstOptions {
180
+ /**
181
+ * Repository the ref lives in.
182
+ *
183
+ * @default process.cwd()
184
+ */
185
+ cwd?: string;
186
+ }
187
+ /**
188
+ * Compares the config on disk against the same config at a git ref.
189
+ *
190
+ * The ref is checked out into a worktree inside the repository, which costs a
191
+ * few files rather than a clone. Nothing is installed there: module resolution
192
+ * walks up to the repository's own `node_modules`, so the base tree needs only
193
+ * its source.
194
+ *
195
+ * @example
196
+ * const changes = await diffAgainst('main', './src/contract.ts');
197
+ */
198
+ declare const diffAgainst: (ref: string, configPath: string, options?: DiffAgainstOptions) => Promise<Change[]>;
199
+ //#endregion
200
+ //#region src/route-map.d.ts
201
+ /**
202
+ * One route, flattened to what someone reading a terminal wants to know.
203
+ */
204
+ interface RouteEntry {
205
+ key: string;
206
+ method: string;
207
+ path: string;
208
+ auth: string;
209
+ tags: string[];
210
+ tool?: string;
211
+ deprecated?: string;
212
+ sunset?: string;
213
+ }
214
+ /**
215
+ * Every route an api serves, in the order it declares them.
216
+ */
217
+ declare const routeMap: (contract: ApiDefinition, options: Record<string, never>) => RouteEntry[];
218
+ /**
219
+ * The route map as aligned columns, one route per line.
220
+ */
221
+ declare const formatRoutes: (entries: readonly RouteEntry[]) => string;
222
+ //#endregion
223
+ 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 };