@kizunajs/cli 2.0.0-beta.2 → 2.0.0-beta.20
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 +80 -15
- package/dist/cli.mjs +80 -15
- package/dist/index.cjs +13 -12
- package/dist/index.d.cts +103 -38
- package/dist/index.d.mts +103 -38
- package/dist/index.mjs +13 -12
- package/dist/{route-map-DW2UUkD_.cjs → route-map-BHe__KDP.cjs} +355 -178
- package/dist/{route-map-D7cBgYmT.mjs → route-map-C0K0orUw.mjs} +330 -177
- package/package.json +8 -6
package/dist/cli.cjs
CHANGED
|
@@ -1,14 +1,54 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_route_map = require("./route-map-
|
|
3
|
-
let
|
|
2
|
+
const require_route_map = require("./route-map-BHe__KDP.cjs");
|
|
3
|
+
let kizunajs_generator = require("kizunajs/generator");
|
|
4
4
|
let node_path = require("node:path");
|
|
5
|
+
let node_fs = require("node:fs");
|
|
5
6
|
let node_util = require("node:util");
|
|
7
|
+
//#region src/group-check.ts
|
|
8
|
+
const within = (path, group) => path === group || path.startsWith(`${group}.`);
|
|
9
|
+
/**
|
|
10
|
+
* Every group problem in an api. Hidden and plugin routes are skipped.
|
|
11
|
+
*/
|
|
12
|
+
const checkGroups = (api) => {
|
|
13
|
+
const declared = api.groups?.groups;
|
|
14
|
+
if (declared === void 0 || declared.size === 0) return [];
|
|
15
|
+
const problems = [];
|
|
16
|
+
const filed = [];
|
|
17
|
+
(0, kizunajs_generator.walkApi)(api, {
|
|
18
|
+
processRoute({ routeKey, routeGroups, hidden, plugin }) {
|
|
19
|
+
if (plugin !== void 0 || hidden) return;
|
|
20
|
+
if (routeGroups[0] === void 0) {
|
|
21
|
+
problems.push({
|
|
22
|
+
kind: "ungrouped",
|
|
23
|
+
message: `${routeKey} is in no group. Declare it with k.routes.<group>(...).`
|
|
24
|
+
});
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
filed.push(...routeGroups);
|
|
28
|
+
},
|
|
29
|
+
finalize: () => void 0
|
|
30
|
+
});
|
|
31
|
+
for (const group of declared.values()) {
|
|
32
|
+
if (filed.some((path) => within(path, group.path))) continue;
|
|
33
|
+
problems.push({
|
|
34
|
+
kind: "empty",
|
|
35
|
+
message: `The group ${group.path} holds no routes. Remove it, or file a route in it.`
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return problems;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The problems, for the terminal.
|
|
42
|
+
*/
|
|
43
|
+
const formatGroupProblems = (problems) => [`${problems.length} group ${problems.length === 1 ? "problem" : "problems"}:`, ...problems.map((problem) => ` ${problem.message}`)].join("\n");
|
|
44
|
+
//#endregion
|
|
6
45
|
//#region src/cli.ts
|
|
7
46
|
const usage = `Usage: kizuna <command> [options]
|
|
8
47
|
|
|
9
48
|
Commands:
|
|
10
49
|
generate Write kizuna.types.ts and every client the config declares.
|
|
11
|
-
routes Print every route the config serves.
|
|
50
|
+
routes Print every route the config serves. Exits 1 when a route is in
|
|
51
|
+
no group while others are, or a group holds no routes.
|
|
12
52
|
diff Compare the config against the same config at a git ref.
|
|
13
53
|
|
|
14
54
|
Options:
|
|
@@ -24,6 +64,8 @@ generate:
|
|
|
24
64
|
diff:
|
|
25
65
|
--against <ref> The git ref to compare against. Default: main
|
|
26
66
|
Exits 1 when a change breaks callers.
|
|
67
|
+
--from <path> Compare two snapshots directly, with no git and no
|
|
68
|
+
--to <path> config. Pass both.
|
|
27
69
|
`;
|
|
28
70
|
const COMMANDS = [
|
|
29
71
|
"generate",
|
|
@@ -56,23 +98,32 @@ const loadOrDie = async (configPath) => {
|
|
|
56
98
|
if (!config) die(`No config found at ${displayPath(configPath)}. A kizuna config default-exports its \`defineConfig(...)\` call.`);
|
|
57
99
|
return config;
|
|
58
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* A file writes where its config says, not where the command was run from, so
|
|
103
|
+
* `kizuna generate --config apps/api/kizuna.config.ts` lands the same files
|
|
104
|
+
* wherever it is invoked.
|
|
105
|
+
*/
|
|
106
|
+
const besideConfig = (configPath, files) => files.map((file) => ({
|
|
107
|
+
...file,
|
|
108
|
+
output: (0, node_path.resolve)((0, node_path.dirname)(configPath), file.output)
|
|
109
|
+
}));
|
|
59
110
|
const runGenerate = async (values) => {
|
|
60
111
|
const configPath = configPathFrom(values.config);
|
|
112
|
+
const config = await loadOrDie(configPath);
|
|
113
|
+
const typesOutput = values.types ?? config.typesOutput;
|
|
114
|
+
if (typesOutput === void 0) die(`${displayPath(configPath)} declares no \`typescript.outputFile\`, which is where the \`Config\` is written. Add one, or pass --types.`);
|
|
115
|
+
const typesPath = (0, node_path.resolve)((0, node_path.dirname)(configPath), typesOutput);
|
|
61
116
|
let types;
|
|
62
117
|
try {
|
|
63
|
-
types = require_route_map.generateConfigTypes((0, node_fs.readFileSync)(configPath, "utf8"), configPath);
|
|
118
|
+
types = require_route_map.generateConfigTypes((0, node_fs.readFileSync)(configPath, "utf8"), configPath, typesPath);
|
|
64
119
|
} catch (error) {
|
|
65
120
|
if (error instanceof require_route_map.ConfigSyntaxError) die(`${displayPath(configPath)}: ${error.message}`);
|
|
66
121
|
throw error;
|
|
67
122
|
}
|
|
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
123
|
const typesCurrent = (0, node_fs.existsSync)(typesPath) ? (0, node_fs.readFileSync)(typesPath, "utf8") : void 0;
|
|
73
124
|
const typesBehind = typesCurrent !== types;
|
|
74
125
|
if (values.check) {
|
|
75
|
-
const stale = require_route_map.
|
|
126
|
+
const stale = require_route_map.checkFiles(config.api, [...besideConfig(configPath, [...config.clients, ...config.generators]), require_route_map.snapshotTarget(configPath)]);
|
|
76
127
|
if (!typesBehind && stale.length === 0) {
|
|
77
128
|
process.stdout.write("Everything kizuna generates is up to date.\n");
|
|
78
129
|
return;
|
|
@@ -82,17 +133,29 @@ const runGenerate = async (values) => {
|
|
|
82
133
|
process.exit(1);
|
|
83
134
|
}
|
|
84
135
|
if (typesBehind) (0, node_fs.writeFileSync)(typesPath, types);
|
|
85
|
-
const written = require_route_map.
|
|
86
|
-
const changed = [...typesBehind ? [displayPath(typesPath)] : [], ...written.filter((
|
|
136
|
+
const written = require_route_map.writeFiles(config.api, [...besideConfig(configPath, [...config.clients, ...config.generators]), require_route_map.snapshotTarget(configPath)]);
|
|
137
|
+
const changed = [...typesBehind ? [displayPath(typesPath)] : [], ...written.filter((file) => file.changed).map((file) => displayPath(file.output))];
|
|
87
138
|
process.stdout.write(changed.length > 0 ? `Wrote:\n${changed.map((file) => ` ${file}`).join("\n")}\n` : "Everything was already up to date.\n");
|
|
88
139
|
};
|
|
89
140
|
const runRoutes = async (values) => {
|
|
90
|
-
const
|
|
141
|
+
const config = await loadOrDie(configPathFrom(values.config));
|
|
142
|
+
const entries = require_route_map.routeMap(config.api, {});
|
|
143
|
+
const problems = checkGroups(config.api);
|
|
91
144
|
process.stdout.write(values.json ? `${JSON.stringify(entries, null, 2)}\n` : `${require_route_map.formatRoutes(entries)}\n`);
|
|
145
|
+
if (problems.length === 0) return;
|
|
146
|
+
process.stderr.write(`\n${formatGroupProblems(problems)}\n`);
|
|
147
|
+
process.exit(1);
|
|
92
148
|
};
|
|
93
149
|
const runDiff = async (values) => {
|
|
94
|
-
|
|
95
|
-
|
|
150
|
+
let changes;
|
|
151
|
+
if (values.from !== void 0 || values.to !== void 0) {
|
|
152
|
+
if (values.from === void 0 || values.to === void 0) die("Pass --from and --to together, or neither.");
|
|
153
|
+
changes = require_route_map.diffSnapshots(require_route_map.readSnapshot(values.from), require_route_map.readSnapshot(values.to));
|
|
154
|
+
} else {
|
|
155
|
+
const configPath = configPathFrom(values.config);
|
|
156
|
+
const config = await loadOrDie(configPath);
|
|
157
|
+
changes = require_route_map.diffAgainst(values.against ?? "main", require_route_map.snapshotPathFor(configPath), config.diff);
|
|
158
|
+
}
|
|
96
159
|
if (values.json) process.stdout.write(`${JSON.stringify(changes, null, 2)}\n`);
|
|
97
160
|
else if (changes.length === 0) process.stdout.write("Nothing callers depend on has moved.\n");
|
|
98
161
|
else process.stdout.write(`${changes.map((change) => require_route_map.formatChange(change)).join("\n\n")}\n`);
|
|
@@ -109,7 +172,9 @@ const main = async () => {
|
|
|
109
172
|
config: { type: "string" },
|
|
110
173
|
types: { type: "string" },
|
|
111
174
|
json: { type: "boolean" },
|
|
112
|
-
against: { type: "string" }
|
|
175
|
+
against: { type: "string" },
|
|
176
|
+
from: { type: "string" },
|
|
177
|
+
to: { type: "string" }
|
|
113
178
|
},
|
|
114
179
|
strict: true
|
|
115
180
|
});
|
package/dist/cli.mjs
CHANGED
|
@@ -1,14 +1,54 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as
|
|
3
|
-
import {
|
|
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-C0K0orUw.mjs";
|
|
3
|
+
import { walkApi } from "kizunajs/generator";
|
|
4
4
|
import { dirname, relative, resolve } from "node:path";
|
|
5
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
6
|
import { parseArgs } from "node:util";
|
|
7
|
+
//#region src/group-check.ts
|
|
8
|
+
const within = (path, group) => path === group || path.startsWith(`${group}.`);
|
|
9
|
+
/**
|
|
10
|
+
* Every group problem in an api. Hidden and plugin routes are skipped.
|
|
11
|
+
*/
|
|
12
|
+
const checkGroups = (api) => {
|
|
13
|
+
const declared = api.groups?.groups;
|
|
14
|
+
if (declared === void 0 || declared.size === 0) return [];
|
|
15
|
+
const problems = [];
|
|
16
|
+
const filed = [];
|
|
17
|
+
walkApi(api, {
|
|
18
|
+
processRoute({ routeKey, routeGroups, hidden, plugin }) {
|
|
19
|
+
if (plugin !== void 0 || hidden) return;
|
|
20
|
+
if (routeGroups[0] === void 0) {
|
|
21
|
+
problems.push({
|
|
22
|
+
kind: "ungrouped",
|
|
23
|
+
message: `${routeKey} is in no group. Declare it with k.routes.<group>(...).`
|
|
24
|
+
});
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
filed.push(...routeGroups);
|
|
28
|
+
},
|
|
29
|
+
finalize: () => void 0
|
|
30
|
+
});
|
|
31
|
+
for (const group of declared.values()) {
|
|
32
|
+
if (filed.some((path) => within(path, group.path))) continue;
|
|
33
|
+
problems.push({
|
|
34
|
+
kind: "empty",
|
|
35
|
+
message: `The group ${group.path} holds no routes. Remove it, or file a route in it.`
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return problems;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The problems, for the terminal.
|
|
42
|
+
*/
|
|
43
|
+
const formatGroupProblems = (problems) => [`${problems.length} group ${problems.length === 1 ? "problem" : "problems"}:`, ...problems.map((problem) => ` ${problem.message}`)].join("\n");
|
|
44
|
+
//#endregion
|
|
6
45
|
//#region src/cli.ts
|
|
7
46
|
const usage = `Usage: kizuna <command> [options]
|
|
8
47
|
|
|
9
48
|
Commands:
|
|
10
49
|
generate Write kizuna.types.ts and every client the config declares.
|
|
11
|
-
routes Print every route the config serves.
|
|
50
|
+
routes Print every route the config serves. Exits 1 when a route is in
|
|
51
|
+
no group while others are, or a group holds no routes.
|
|
12
52
|
diff Compare the config against the same config at a git ref.
|
|
13
53
|
|
|
14
54
|
Options:
|
|
@@ -24,6 +64,8 @@ generate:
|
|
|
24
64
|
diff:
|
|
25
65
|
--against <ref> The git ref to compare against. Default: main
|
|
26
66
|
Exits 1 when a change breaks callers.
|
|
67
|
+
--from <path> Compare two snapshots directly, with no git and no
|
|
68
|
+
--to <path> config. Pass both.
|
|
27
69
|
`;
|
|
28
70
|
const COMMANDS = [
|
|
29
71
|
"generate",
|
|
@@ -56,23 +98,32 @@ const loadOrDie = async (configPath) => {
|
|
|
56
98
|
if (!config) die(`No config found at ${displayPath(configPath)}. A kizuna config default-exports its \`defineConfig(...)\` call.`);
|
|
57
99
|
return config;
|
|
58
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* A file writes where its config says, not where the command was run from, so
|
|
103
|
+
* `kizuna generate --config apps/api/kizuna.config.ts` lands the same files
|
|
104
|
+
* wherever it is invoked.
|
|
105
|
+
*/
|
|
106
|
+
const besideConfig = (configPath, files) => files.map((file) => ({
|
|
107
|
+
...file,
|
|
108
|
+
output: resolve(dirname(configPath), file.output)
|
|
109
|
+
}));
|
|
59
110
|
const runGenerate = async (values) => {
|
|
60
111
|
const configPath = configPathFrom(values.config);
|
|
112
|
+
const config = await loadOrDie(configPath);
|
|
113
|
+
const typesOutput = values.types ?? config.typesOutput;
|
|
114
|
+
if (typesOutput === void 0) die(`${displayPath(configPath)} declares no \`typescript.outputFile\`, which is where the \`Config\` is written. Add one, or pass --types.`);
|
|
115
|
+
const typesPath = resolve(dirname(configPath), typesOutput);
|
|
61
116
|
let types;
|
|
62
117
|
try {
|
|
63
|
-
types = generateConfigTypes(readFileSync(configPath, "utf8"), configPath);
|
|
118
|
+
types = generateConfigTypes(readFileSync(configPath, "utf8"), configPath, typesPath);
|
|
64
119
|
} catch (error) {
|
|
65
120
|
if (error instanceof ConfigSyntaxError) die(`${displayPath(configPath)}: ${error.message}`);
|
|
66
121
|
throw error;
|
|
67
122
|
}
|
|
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
123
|
const typesCurrent = existsSync(typesPath) ? readFileSync(typesPath, "utf8") : void 0;
|
|
73
124
|
const typesBehind = typesCurrent !== types;
|
|
74
125
|
if (values.check) {
|
|
75
|
-
const stale =
|
|
126
|
+
const stale = checkFiles(config.api, [...besideConfig(configPath, [...config.clients, ...config.generators]), snapshotTarget(configPath)]);
|
|
76
127
|
if (!typesBehind && stale.length === 0) {
|
|
77
128
|
process.stdout.write("Everything kizuna generates is up to date.\n");
|
|
78
129
|
return;
|
|
@@ -82,17 +133,29 @@ const runGenerate = async (values) => {
|
|
|
82
133
|
process.exit(1);
|
|
83
134
|
}
|
|
84
135
|
if (typesBehind) writeFileSync(typesPath, types);
|
|
85
|
-
const written =
|
|
86
|
-
const changed = [...typesBehind ? [displayPath(typesPath)] : [], ...written.filter((
|
|
136
|
+
const written = writeFiles(config.api, [...besideConfig(configPath, [...config.clients, ...config.generators]), snapshotTarget(configPath)]);
|
|
137
|
+
const changed = [...typesBehind ? [displayPath(typesPath)] : [], ...written.filter((file) => file.changed).map((file) => displayPath(file.output))];
|
|
87
138
|
process.stdout.write(changed.length > 0 ? `Wrote:\n${changed.map((file) => ` ${file}`).join("\n")}\n` : "Everything was already up to date.\n");
|
|
88
139
|
};
|
|
89
140
|
const runRoutes = async (values) => {
|
|
90
|
-
const
|
|
141
|
+
const config = await loadOrDie(configPathFrom(values.config));
|
|
142
|
+
const entries = routeMap(config.api, {});
|
|
143
|
+
const problems = checkGroups(config.api);
|
|
91
144
|
process.stdout.write(values.json ? `${JSON.stringify(entries, null, 2)}\n` : `${formatRoutes(entries)}\n`);
|
|
145
|
+
if (problems.length === 0) return;
|
|
146
|
+
process.stderr.write(`\n${formatGroupProblems(problems)}\n`);
|
|
147
|
+
process.exit(1);
|
|
92
148
|
};
|
|
93
149
|
const runDiff = async (values) => {
|
|
94
|
-
|
|
95
|
-
|
|
150
|
+
let changes;
|
|
151
|
+
if (values.from !== void 0 || values.to !== void 0) {
|
|
152
|
+
if (values.from === void 0 || values.to === void 0) die("Pass --from and --to together, or neither.");
|
|
153
|
+
changes = diffSnapshots(readSnapshot(values.from), readSnapshot(values.to));
|
|
154
|
+
} else {
|
|
155
|
+
const configPath = configPathFrom(values.config);
|
|
156
|
+
const config = await loadOrDie(configPath);
|
|
157
|
+
changes = diffAgainst(values.against ?? "main", snapshotPathFor(configPath), config.diff);
|
|
158
|
+
}
|
|
96
159
|
if (values.json) process.stdout.write(`${JSON.stringify(changes, null, 2)}\n`);
|
|
97
160
|
else if (changes.length === 0) process.stdout.write("Nothing callers depend on has moved.\n");
|
|
98
161
|
else process.stdout.write(`${changes.map((change) => formatChange(change)).join("\n\n")}\n`);
|
|
@@ -109,7 +172,9 @@ const main = async () => {
|
|
|
109
172
|
config: { type: "string" },
|
|
110
173
|
types: { type: "string" },
|
|
111
174
|
json: { type: "boolean" },
|
|
112
|
-
against: { type: "string" }
|
|
175
|
+
against: { type: "string" },
|
|
176
|
+
from: { type: "string" },
|
|
177
|
+
to: { type: "string" }
|
|
113
178
|
},
|
|
114
179
|
strict: true
|
|
115
180
|
});
|
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-
|
|
2
|
+
const require_route_map = require("./route-map-BHe__KDP.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.
|
|
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.
|
|
80
|
+
exports.writeFiles = require_route_map.writeFiles;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ApiDefinition, ClientTarget } from "kizunajs";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
|
|
1
|
+
import { ApiDefinition, DiffSettings, GeneratedFile } from "kizunajs";
|
|
5
2
|
//#region src/load-config.d.ts
|
|
6
3
|
/**
|
|
7
4
|
* One api a config declares, with everything generated from it. A config that
|
|
@@ -10,11 +7,19 @@ import { z } from "zod";
|
|
|
10
7
|
interface LoadedApi {
|
|
11
8
|
name: string;
|
|
12
9
|
api: ApiDefinition;
|
|
13
|
-
clients: readonly
|
|
10
|
+
clients: readonly GeneratedFile[];
|
|
11
|
+
/**
|
|
12
|
+
* The files the config's plugins generate.
|
|
13
|
+
*/
|
|
14
|
+
generators: readonly GeneratedFile[];
|
|
14
15
|
/**
|
|
15
16
|
* Where `kizuna generate` writes the `Config`, when the config says.
|
|
16
17
|
*/
|
|
17
18
|
typesOutput: string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* What else `kizuna diff` treats as breaking.
|
|
21
|
+
*/
|
|
22
|
+
diff: DiffSettings;
|
|
18
23
|
}
|
|
19
24
|
/**
|
|
20
25
|
* Imports a config module with jiti, so a `.ts` config works without a build
|
|
@@ -58,7 +63,7 @@ interface Notice {
|
|
|
58
63
|
* Reads the same `deprecated` field the generated clients carry in an
|
|
59
64
|
* editor, so a watcher and a hover agree.
|
|
60
65
|
*/
|
|
61
|
-
declare const apiNotices: (
|
|
66
|
+
declare const apiNotices: (api: ApiDefinition, options?: {
|
|
62
67
|
now?: Date;
|
|
63
68
|
}) => Notice[];
|
|
64
69
|
/**
|
|
@@ -69,6 +74,35 @@ declare const apiNotices: (contract: _$kizunajs.ApiDefinition, options: {
|
|
|
69
74
|
*/
|
|
70
75
|
declare const formatNotice: (notice: Notice) => string;
|
|
71
76
|
//#endregion
|
|
77
|
+
//#region src/snapshot.d.ts
|
|
78
|
+
/**
|
|
79
|
+
* A schema reduced to what a comparison needs: its kind, whether it accepts
|
|
80
|
+
* `null`, its fields, and the values it accepts when it is closed.
|
|
81
|
+
*/
|
|
82
|
+
type SchemaNode = {
|
|
83
|
+
kind: 'object';
|
|
84
|
+
nullable?: true;
|
|
85
|
+
fields: Record<string, {
|
|
86
|
+
optional: boolean;
|
|
87
|
+
schema: SchemaNode;
|
|
88
|
+
}>;
|
|
89
|
+
refinements?: number;
|
|
90
|
+
} | {
|
|
91
|
+
kind: 'array';
|
|
92
|
+
nullable?: true;
|
|
93
|
+
element: SchemaNode;
|
|
94
|
+
refinements?: number;
|
|
95
|
+
} | {
|
|
96
|
+
kind: 'enum';
|
|
97
|
+
nullable?: true;
|
|
98
|
+
values: string[];
|
|
99
|
+
refinements?: number;
|
|
100
|
+
} | {
|
|
101
|
+
kind: string;
|
|
102
|
+
nullable?: true;
|
|
103
|
+
refinements?: number;
|
|
104
|
+
};
|
|
105
|
+
//#endregion
|
|
72
106
|
//#region src/diff-apis.d.ts
|
|
73
107
|
/**
|
|
74
108
|
* How much a change asks of the people already calling an API.
|
|
@@ -86,13 +120,38 @@ interface Change {
|
|
|
86
120
|
*/
|
|
87
121
|
detail?: string;
|
|
88
122
|
}
|
|
123
|
+
interface DiffOptions {
|
|
124
|
+
/**
|
|
125
|
+
* Report a job key that is gone. A job answers `POST /jobs/run` by its
|
|
126
|
+
* dotted key, so this matters once something outside your own code
|
|
127
|
+
* dispatches them.
|
|
128
|
+
*
|
|
129
|
+
* @default false
|
|
130
|
+
*/
|
|
131
|
+
jobs?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Report an MCP tool a model can no longer call.
|
|
134
|
+
*
|
|
135
|
+
* @default false
|
|
136
|
+
*/
|
|
137
|
+
tools?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Treat a renamed dotted key, such as `users.getUser` becoming
|
|
140
|
+
* `users.fetchUser`, as breaking. The key names the method on a generated
|
|
141
|
+
* client, so a rename breaks anyone building an SDK on one and leaves the
|
|
142
|
+
* HTTP surface untouched.
|
|
143
|
+
*
|
|
144
|
+
* @default false
|
|
145
|
+
*/
|
|
146
|
+
dottedKeys?: boolean;
|
|
147
|
+
}
|
|
89
148
|
/**
|
|
90
|
-
* What changed between two apis,
|
|
149
|
+
* What changed between two apis, for a caller holding both in memory.
|
|
91
150
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
151
|
+
* `kizuna diff` reads snapshots instead, so it never has to load the other
|
|
152
|
+
* side's code.
|
|
94
153
|
*/
|
|
95
|
-
declare const diffApis: (before: ApiDefinition, after: ApiDefinition) => Change[];
|
|
154
|
+
declare const diffApis: (before: ApiDefinition, after: ApiDefinition, options?: DiffOptions) => Change[];
|
|
96
155
|
/**
|
|
97
156
|
* One block per change, ready to print: the level, the summary, and the
|
|
98
157
|
* detail indented beneath it.
|
|
@@ -105,18 +164,16 @@ declare const hasBreakingChange: (changes: Change[]) => boolean;
|
|
|
105
164
|
//#endregion
|
|
106
165
|
//#region src/generate-clients.d.ts
|
|
107
166
|
/**
|
|
108
|
-
* A
|
|
167
|
+
* A file that was written, and whether it had to be.
|
|
109
168
|
*/
|
|
110
|
-
interface
|
|
111
|
-
kind: string;
|
|
169
|
+
interface WrittenFile {
|
|
112
170
|
output: string;
|
|
113
171
|
changed: boolean;
|
|
114
172
|
}
|
|
115
173
|
/**
|
|
116
|
-
* A generated
|
|
174
|
+
* A generated file that does not match its api.
|
|
117
175
|
*/
|
|
118
|
-
interface
|
|
119
|
-
kind: string;
|
|
176
|
+
interface StaleFile {
|
|
120
177
|
output: string;
|
|
121
178
|
/**
|
|
122
179
|
* `missing` when nothing is there, `outdated` when what is there is old.
|
|
@@ -124,22 +181,24 @@ interface StaleClient {
|
|
|
124
181
|
reason: 'missing' | 'outdated';
|
|
125
182
|
}
|
|
126
183
|
/**
|
|
127
|
-
* Writes every
|
|
128
|
-
* matches so watchers and build tools see no
|
|
184
|
+
* Writes every generated file, the clients and what plugins generate, leaving
|
|
185
|
+
* a file alone when it already matches so watchers and build tools see no
|
|
186
|
+
* change.
|
|
129
187
|
*/
|
|
130
|
-
declare const
|
|
188
|
+
declare const writeFiles: (contract: ApiDefinition, files: readonly GeneratedFile[]) => WrittenFile[];
|
|
131
189
|
/**
|
|
132
|
-
* Every
|
|
190
|
+
* Every generated file that no longer matches its api, without writing
|
|
191
|
+
* anything.
|
|
133
192
|
*
|
|
134
193
|
* This is what a pipeline runs: a generated client that has fallen behind is a
|
|
135
194
|
* compile error waiting to happen in whatever imports it.
|
|
136
195
|
*/
|
|
137
|
-
declare const
|
|
196
|
+
declare const checkFiles: (contract: ApiDefinition, files: readonly GeneratedFile[]) => StaleFile[];
|
|
138
197
|
/**
|
|
139
198
|
* What a pipeline prints when a check fails, naming the command that fixes it
|
|
140
199
|
* rather than printing a diff nobody reads.
|
|
141
200
|
*/
|
|
142
|
-
declare const formatStale: (stale: readonly
|
|
201
|
+
declare const formatStale: (stale: readonly StaleFile[], command?: string) => string;
|
|
143
202
|
//#endregion
|
|
144
203
|
//#region src/generate-types.d.ts
|
|
145
204
|
declare class ConfigSyntaxError extends Error {}
|
|
@@ -150,8 +209,11 @@ declare class ConfigSyntaxError extends Error {}
|
|
|
150
209
|
* Read from the config's syntax rather than by running it: the generated file
|
|
151
210
|
* imports the same names the config did, and a config that loads is not a
|
|
152
211
|
* prerequisite for typing the routes it serves.
|
|
212
|
+
*
|
|
213
|
+
* `outputPath` is what the imports are written relative to. Left out, they stay
|
|
214
|
+
* relative to the config.
|
|
153
215
|
*/
|
|
154
|
-
declare const generateConfigTypes: (configSource: string, fileName?: string) => string;
|
|
216
|
+
declare const generateConfigTypes: (configSource: string, fileName?: string, outputPath?: string) => string;
|
|
155
217
|
//#endregion
|
|
156
218
|
//#region src/diff-schemas.d.ts
|
|
157
219
|
/**
|
|
@@ -173,29 +235,25 @@ interface SchemaChange {
|
|
|
173
235
|
* What changed between two versions of one schema, and whether it breaks the
|
|
174
236
|
* people already calling the route.
|
|
175
237
|
*/
|
|
176
|
-
declare const diffSchemas: (before:
|
|
238
|
+
declare const diffSchemas: (before: SchemaNode | undefined, after: SchemaNode | undefined, direction: Direction, path?: string) => SchemaChange[];
|
|
177
239
|
//#endregion
|
|
178
240
|
//#region src/diff-against.d.ts
|
|
179
|
-
interface DiffAgainstOptions {
|
|
241
|
+
interface DiffAgainstOptions extends DiffOptions {
|
|
180
242
|
/**
|
|
181
|
-
*
|
|
243
|
+
* Where a relative path is resolved from.
|
|
182
244
|
*
|
|
183
245
|
* @default process.cwd()
|
|
184
246
|
*/
|
|
185
247
|
cwd?: string;
|
|
186
248
|
}
|
|
187
249
|
/**
|
|
188
|
-
* Compares
|
|
250
|
+
* Compares a snapshot against the same file at a git ref.
|
|
189
251
|
*
|
|
190
|
-
* The ref is
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
* its source.
|
|
194
|
-
*
|
|
195
|
-
* @example
|
|
196
|
-
* const changes = await diffAgainst('main', './src/contract.ts');
|
|
252
|
+
* The ref is read with `git show`, so nothing is checked out, installed or
|
|
253
|
+
* executed for the other side. A snapshot written a year ago compares fine
|
|
254
|
+
* against one written today.
|
|
197
255
|
*/
|
|
198
|
-
declare const diffAgainst: (ref: string,
|
|
256
|
+
declare const diffAgainst: (ref: string, snapshotPath: string, options?: DiffAgainstOptions) => Change[];
|
|
199
257
|
//#endregion
|
|
200
258
|
//#region src/route-map.d.ts
|
|
201
259
|
/**
|
|
@@ -206,18 +264,25 @@ interface RouteEntry {
|
|
|
206
264
|
method: string;
|
|
207
265
|
path: string;
|
|
208
266
|
auth: string;
|
|
209
|
-
|
|
267
|
+
/**
|
|
268
|
+
* The route's groups, as dotted paths.
|
|
269
|
+
*/
|
|
270
|
+
groups: string[];
|
|
210
271
|
tool?: string;
|
|
211
272
|
deprecated?: string;
|
|
212
273
|
sunset?: string;
|
|
274
|
+
/**
|
|
275
|
+
* `true` when the route is `hidden`: served, but in no generated client.
|
|
276
|
+
*/
|
|
277
|
+
hidden?: true;
|
|
213
278
|
}
|
|
214
279
|
/**
|
|
215
280
|
* Every route an api serves, in the order it declares them.
|
|
216
281
|
*/
|
|
217
|
-
declare const routeMap: (
|
|
282
|
+
declare const routeMap: (api: ApiDefinition, _options?: Record<string, never>) => RouteEntry[];
|
|
218
283
|
/**
|
|
219
284
|
* The route map as aligned columns, one route per line.
|
|
220
285
|
*/
|
|
221
286
|
declare const formatRoutes: (entries: readonly RouteEntry[]) => string;
|
|
222
287
|
//#endregion
|
|
223
|
-
export { type Change, type ChangeLevel, ConfigSyntaxError, type DiffAgainstOptions, type Direction, type LoadedApi, type Notice, type RouteEntry, type SchemaChange, type
|
|
288
|
+
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 };
|