@kizunajs/cli 2.0.0-beta.4 → 2.0.0-beta.40
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 +57 -12
- package/dist/cli.mjs +57 -12
- package/dist/index.cjs +13 -12
- package/dist/index.d.cts +56 -23
- package/dist/index.d.mts +56 -23
- package/dist/index.mjs +13 -12
- package/dist/{route-map-yRIISgnC.cjs → route-map-BMcSul55.cjs} +202 -68
- package/dist/{route-map-CRWVBQGf.mjs → route-map-C-GvgV1C.mjs} +200 -66
- package/package.json +9 -9
package/dist/cli.cjs
CHANGED
|
@@ -1,14 +1,54 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_route_map = require("./route-map-
|
|
2
|
+
const require_route_map = require("./route-map-BMcSul55.cjs");
|
|
3
|
+
let kizunajs_generator = require("kizunajs/generator");
|
|
3
4
|
let node_path = require("node:path");
|
|
4
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:
|
|
@@ -59,13 +99,13 @@ const loadOrDie = async (configPath) => {
|
|
|
59
99
|
return config;
|
|
60
100
|
};
|
|
61
101
|
/**
|
|
62
|
-
* A
|
|
63
|
-
*
|
|
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
|
|
64
104
|
* wherever it is invoked.
|
|
65
105
|
*/
|
|
66
|
-
const besideConfig = (configPath,
|
|
67
|
-
...
|
|
68
|
-
output: (0, node_path.resolve)((0, node_path.dirname)(configPath),
|
|
106
|
+
const besideConfig = (configPath, files) => files.map((file) => ({
|
|
107
|
+
...file,
|
|
108
|
+
output: (0, node_path.resolve)((0, node_path.dirname)(configPath), file.output)
|
|
69
109
|
}));
|
|
70
110
|
const runGenerate = async (values) => {
|
|
71
111
|
const configPath = configPathFrom(values.config);
|
|
@@ -75,7 +115,7 @@ const runGenerate = async (values) => {
|
|
|
75
115
|
const typesPath = (0, node_path.resolve)((0, node_path.dirname)(configPath), typesOutput);
|
|
76
116
|
let types;
|
|
77
117
|
try {
|
|
78
|
-
types = require_route_map.generateConfigTypes((0, node_fs.readFileSync)(configPath, "utf8"), configPath, typesPath);
|
|
118
|
+
types = require_route_map.generateConfigTypes((0, node_fs.readFileSync)(configPath, "utf8"), configPath, typesPath, config.typesExtensions);
|
|
79
119
|
} catch (error) {
|
|
80
120
|
if (error instanceof require_route_map.ConfigSyntaxError) die(`${displayPath(configPath)}: ${error.message}`);
|
|
81
121
|
throw error;
|
|
@@ -83,7 +123,7 @@ const runGenerate = async (values) => {
|
|
|
83
123
|
const typesCurrent = (0, node_fs.existsSync)(typesPath) ? (0, node_fs.readFileSync)(typesPath, "utf8") : void 0;
|
|
84
124
|
const typesBehind = typesCurrent !== types;
|
|
85
125
|
if (values.check) {
|
|
86
|
-
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)]);
|
|
87
127
|
if (!typesBehind && stale.length === 0) {
|
|
88
128
|
process.stdout.write("Everything kizuna generates is up to date.\n");
|
|
89
129
|
return;
|
|
@@ -93,13 +133,18 @@ const runGenerate = async (values) => {
|
|
|
93
133
|
process.exit(1);
|
|
94
134
|
}
|
|
95
135
|
if (typesBehind) (0, node_fs.writeFileSync)(typesPath, types);
|
|
96
|
-
const written = require_route_map.
|
|
97
|
-
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))];
|
|
98
138
|
process.stdout.write(changed.length > 0 ? `Wrote:\n${changed.map((file) => ` ${file}`).join("\n")}\n` : "Everything was already up to date.\n");
|
|
99
139
|
};
|
|
100
140
|
const runRoutes = async (values) => {
|
|
101
|
-
const
|
|
141
|
+
const config = await loadOrDie(configPathFrom(values.config));
|
|
142
|
+
const entries = require_route_map.routeMap(config.api, {});
|
|
143
|
+
const problems = checkGroups(config.api);
|
|
102
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);
|
|
103
148
|
};
|
|
104
149
|
const runDiff = async (values) => {
|
|
105
150
|
let changes;
|
package/dist/cli.mjs
CHANGED
|
@@ -1,14 +1,54 @@
|
|
|
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
|
|
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-C-GvgV1C.mjs";
|
|
3
|
+
import { walkApi } from "kizunajs/generator";
|
|
3
4
|
import { dirname, relative, resolve } from "node:path";
|
|
4
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:
|
|
@@ -59,13 +99,13 @@ const loadOrDie = async (configPath) => {
|
|
|
59
99
|
return config;
|
|
60
100
|
};
|
|
61
101
|
/**
|
|
62
|
-
* A
|
|
63
|
-
*
|
|
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
|
|
64
104
|
* wherever it is invoked.
|
|
65
105
|
*/
|
|
66
|
-
const besideConfig = (configPath,
|
|
67
|
-
...
|
|
68
|
-
output: resolve(dirname(configPath),
|
|
106
|
+
const besideConfig = (configPath, files) => files.map((file) => ({
|
|
107
|
+
...file,
|
|
108
|
+
output: resolve(dirname(configPath), file.output)
|
|
69
109
|
}));
|
|
70
110
|
const runGenerate = async (values) => {
|
|
71
111
|
const configPath = configPathFrom(values.config);
|
|
@@ -75,7 +115,7 @@ const runGenerate = async (values) => {
|
|
|
75
115
|
const typesPath = resolve(dirname(configPath), typesOutput);
|
|
76
116
|
let types;
|
|
77
117
|
try {
|
|
78
|
-
types = generateConfigTypes(readFileSync(configPath, "utf8"), configPath, typesPath);
|
|
118
|
+
types = generateConfigTypes(readFileSync(configPath, "utf8"), configPath, typesPath, config.typesExtensions);
|
|
79
119
|
} catch (error) {
|
|
80
120
|
if (error instanceof ConfigSyntaxError) die(`${displayPath(configPath)}: ${error.message}`);
|
|
81
121
|
throw error;
|
|
@@ -83,7 +123,7 @@ const runGenerate = async (values) => {
|
|
|
83
123
|
const typesCurrent = existsSync(typesPath) ? readFileSync(typesPath, "utf8") : void 0;
|
|
84
124
|
const typesBehind = typesCurrent !== types;
|
|
85
125
|
if (values.check) {
|
|
86
|
-
const stale =
|
|
126
|
+
const stale = checkFiles(config.api, [...besideConfig(configPath, [...config.clients, ...config.generators]), snapshotTarget(configPath)]);
|
|
87
127
|
if (!typesBehind && stale.length === 0) {
|
|
88
128
|
process.stdout.write("Everything kizuna generates is up to date.\n");
|
|
89
129
|
return;
|
|
@@ -93,13 +133,18 @@ const runGenerate = async (values) => {
|
|
|
93
133
|
process.exit(1);
|
|
94
134
|
}
|
|
95
135
|
if (typesBehind) writeFileSync(typesPath, types);
|
|
96
|
-
const written =
|
|
97
|
-
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))];
|
|
98
138
|
process.stdout.write(changed.length > 0 ? `Wrote:\n${changed.map((file) => ` ${file}`).join("\n")}\n` : "Everything was already up to date.\n");
|
|
99
139
|
};
|
|
100
140
|
const runRoutes = async (values) => {
|
|
101
|
-
const
|
|
141
|
+
const config = await loadOrDie(configPathFrom(values.config));
|
|
142
|
+
const entries = routeMap(config.api, {});
|
|
143
|
+
const problems = checkGroups(config.api);
|
|
102
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);
|
|
103
148
|
};
|
|
104
149
|
const runDiff = async (values) => {
|
|
105
150
|
let changes;
|
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-BMcSul55.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,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ApiDefinition, ClientTarget, DiffSettings } from "kizunajs";
|
|
1
|
+
import { ApiDefinition, ConfigExtension, 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,11 +7,19 @@ import { ApiDefinition, ClientTarget, DiffSettings } from "kizunajs";
|
|
|
8
7
|
interface LoadedApi {
|
|
9
8
|
name: string;
|
|
10
9
|
api: ApiDefinition;
|
|
11
|
-
clients: readonly
|
|
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
|
*/
|
|
15
18
|
typesOutput: string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* What `typescript.extend` adds to the `Config`.
|
|
21
|
+
*/
|
|
22
|
+
typesExtensions: readonly ConfigExtension[];
|
|
16
23
|
/**
|
|
17
24
|
* What else `kizuna diff` treats as breaking.
|
|
18
25
|
*/
|
|
@@ -60,7 +67,7 @@ interface Notice {
|
|
|
60
67
|
* Reads the same `deprecated` field the generated clients carry in an
|
|
61
68
|
* editor, so a watcher and a hover agree.
|
|
62
69
|
*/
|
|
63
|
-
declare const apiNotices: (
|
|
70
|
+
declare const apiNotices: (api: ApiDefinition, options?: {
|
|
64
71
|
now?: Date;
|
|
65
72
|
}) => Notice[];
|
|
66
73
|
/**
|
|
@@ -73,11 +80,12 @@ declare const formatNotice: (notice: Notice) => string;
|
|
|
73
80
|
//#endregion
|
|
74
81
|
//#region src/snapshot.d.ts
|
|
75
82
|
/**
|
|
76
|
-
* A schema reduced to what a comparison needs: its kind,
|
|
77
|
-
* values it accepts when it is closed.
|
|
83
|
+
* A schema reduced to what a comparison needs: its kind, whether it accepts
|
|
84
|
+
* `null`, its fields, and the values it accepts when it is closed.
|
|
78
85
|
*/
|
|
79
86
|
type SchemaNode = {
|
|
80
87
|
kind: 'object';
|
|
88
|
+
nullable?: true;
|
|
81
89
|
fields: Record<string, {
|
|
82
90
|
optional: boolean;
|
|
83
91
|
schema: SchemaNode;
|
|
@@ -85,14 +93,29 @@ type SchemaNode = {
|
|
|
85
93
|
refinements?: number;
|
|
86
94
|
} | {
|
|
87
95
|
kind: 'array';
|
|
96
|
+
nullable?: true;
|
|
88
97
|
element: SchemaNode;
|
|
89
98
|
refinements?: number;
|
|
90
99
|
} | {
|
|
91
100
|
kind: 'enum';
|
|
101
|
+
nullable?: true;
|
|
92
102
|
values: string[];
|
|
103
|
+
extensible?: true;
|
|
104
|
+
refinements?: number;
|
|
105
|
+
} | {
|
|
106
|
+
kind: 'model';
|
|
107
|
+
nullable?: true;
|
|
108
|
+
model: string;
|
|
109
|
+
refinements?: number;
|
|
110
|
+
} | {
|
|
111
|
+
kind: 'union';
|
|
112
|
+
nullable?: true;
|
|
113
|
+
options: SchemaNode[];
|
|
114
|
+
extensible?: true;
|
|
93
115
|
refinements?: number;
|
|
94
116
|
} | {
|
|
95
117
|
kind: string;
|
|
118
|
+
nullable?: true;
|
|
96
119
|
refinements?: number;
|
|
97
120
|
};
|
|
98
121
|
//#endregion
|
|
@@ -157,18 +180,16 @@ declare const hasBreakingChange: (changes: Change[]) => boolean;
|
|
|
157
180
|
//#endregion
|
|
158
181
|
//#region src/generate-clients.d.ts
|
|
159
182
|
/**
|
|
160
|
-
* A
|
|
183
|
+
* A file that was written, and whether it had to be.
|
|
161
184
|
*/
|
|
162
|
-
interface
|
|
163
|
-
kind: string;
|
|
185
|
+
interface WrittenFile {
|
|
164
186
|
output: string;
|
|
165
187
|
changed: boolean;
|
|
166
188
|
}
|
|
167
189
|
/**
|
|
168
|
-
* A generated
|
|
190
|
+
* A generated file that does not match its api.
|
|
169
191
|
*/
|
|
170
|
-
interface
|
|
171
|
-
kind: string;
|
|
192
|
+
interface StaleFile {
|
|
172
193
|
output: string;
|
|
173
194
|
/**
|
|
174
195
|
* `missing` when nothing is there, `outdated` when what is there is old.
|
|
@@ -176,22 +197,24 @@ interface StaleClient {
|
|
|
176
197
|
reason: 'missing' | 'outdated';
|
|
177
198
|
}
|
|
178
199
|
/**
|
|
179
|
-
* Writes every
|
|
180
|
-
* matches so watchers and build tools see no
|
|
200
|
+
* Writes every generated file, the clients and what plugins generate, leaving
|
|
201
|
+
* a file alone when it already matches so watchers and build tools see no
|
|
202
|
+
* change.
|
|
181
203
|
*/
|
|
182
|
-
declare const
|
|
204
|
+
declare const writeFiles: (contract: ApiDefinition, files: readonly GeneratedFile[]) => WrittenFile[];
|
|
183
205
|
/**
|
|
184
|
-
* Every
|
|
206
|
+
* Every generated file that no longer matches its api, without writing
|
|
207
|
+
* anything.
|
|
185
208
|
*
|
|
186
209
|
* This is what a pipeline runs: a generated client that has fallen behind is a
|
|
187
210
|
* compile error waiting to happen in whatever imports it.
|
|
188
211
|
*/
|
|
189
|
-
declare const
|
|
212
|
+
declare const checkFiles: (contract: ApiDefinition, files: readonly GeneratedFile[]) => StaleFile[];
|
|
190
213
|
/**
|
|
191
214
|
* What a pipeline prints when a check fails, naming the command that fixes it
|
|
192
215
|
* rather than printing a diff nobody reads.
|
|
193
216
|
*/
|
|
194
|
-
declare const formatStale: (stale: readonly
|
|
217
|
+
declare const formatStale: (stale: readonly StaleFile[], command?: string) => string;
|
|
195
218
|
//#endregion
|
|
196
219
|
//#region src/generate-types.d.ts
|
|
197
220
|
declare class ConfigSyntaxError extends Error {}
|
|
@@ -201,12 +224,14 @@ declare class ConfigSyntaxError extends Error {}
|
|
|
201
224
|
*
|
|
202
225
|
* Read from the config's syntax rather than by running it: the generated file
|
|
203
226
|
* imports the same names the config did, and a config that loads is not a
|
|
204
|
-
* prerequisite for typing the routes it serves.
|
|
227
|
+
* prerequisite for typing the routes it serves. What
|
|
228
|
+
* `typescript.extend` adds exists only once the config has run, so the caller passes
|
|
229
|
+
* it in.
|
|
205
230
|
*
|
|
206
231
|
* `outputPath` is what the imports are written relative to. Left out, they stay
|
|
207
232
|
* relative to the config.
|
|
208
233
|
*/
|
|
209
|
-
declare const generateConfigTypes: (configSource: string, fileName?: string, outputPath?: string) => string;
|
|
234
|
+
declare const generateConfigTypes: (configSource: string, fileName?: string, outputPath?: string, extensions?: readonly ConfigExtension[]) => string;
|
|
210
235
|
//#endregion
|
|
211
236
|
//#region src/diff-schemas.d.ts
|
|
212
237
|
/**
|
|
@@ -223,6 +248,7 @@ interface SchemaChange {
|
|
|
223
248
|
*/
|
|
224
249
|
path: string;
|
|
225
250
|
summary: string;
|
|
251
|
+
detail?: string;
|
|
226
252
|
}
|
|
227
253
|
/**
|
|
228
254
|
* What changed between two versions of one schema, and whether it breaks the
|
|
@@ -257,18 +283,25 @@ interface RouteEntry {
|
|
|
257
283
|
method: string;
|
|
258
284
|
path: string;
|
|
259
285
|
auth: string;
|
|
260
|
-
|
|
286
|
+
/**
|
|
287
|
+
* The route's groups, as dotted paths.
|
|
288
|
+
*/
|
|
289
|
+
groups: string[];
|
|
261
290
|
tool?: string;
|
|
262
291
|
deprecated?: string;
|
|
263
292
|
sunset?: string;
|
|
293
|
+
/**
|
|
294
|
+
* `true` when the route is `hidden`: served, but in no generated client.
|
|
295
|
+
*/
|
|
296
|
+
hidden?: true;
|
|
264
297
|
}
|
|
265
298
|
/**
|
|
266
299
|
* Every route an api serves, in the order it declares them.
|
|
267
300
|
*/
|
|
268
|
-
declare const routeMap: (
|
|
301
|
+
declare const routeMap: (api: ApiDefinition, _options?: Record<string, never>) => RouteEntry[];
|
|
269
302
|
/**
|
|
270
303
|
* The route map as aligned columns, one route per line.
|
|
271
304
|
*/
|
|
272
305
|
declare const formatRoutes: (entries: readonly RouteEntry[]) => string;
|
|
273
306
|
//#endregion
|
|
274
|
-
export { type Change, type ChangeLevel, ConfigSyntaxError, type DiffAgainstOptions, type Direction, type LoadedApi, type Notice, type RouteEntry, type SchemaChange, type
|
|
307
|
+
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
|
|
2
|
-
import { ApiDefinition, ClientTarget, DiffSettings } from "kizunajs";
|
|
1
|
+
import { ApiDefinition, ConfigExtension, 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,11 +7,19 @@ import { ApiDefinition, ClientTarget, DiffSettings } from "kizunajs";
|
|
|
8
7
|
interface LoadedApi {
|
|
9
8
|
name: string;
|
|
10
9
|
api: ApiDefinition;
|
|
11
|
-
clients: readonly
|
|
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
|
*/
|
|
15
18
|
typesOutput: string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* What `typescript.extend` adds to the `Config`.
|
|
21
|
+
*/
|
|
22
|
+
typesExtensions: readonly ConfigExtension[];
|
|
16
23
|
/**
|
|
17
24
|
* What else `kizuna diff` treats as breaking.
|
|
18
25
|
*/
|
|
@@ -60,7 +67,7 @@ interface Notice {
|
|
|
60
67
|
* Reads the same `deprecated` field the generated clients carry in an
|
|
61
68
|
* editor, so a watcher and a hover agree.
|
|
62
69
|
*/
|
|
63
|
-
declare const apiNotices: (
|
|
70
|
+
declare const apiNotices: (api: ApiDefinition, options?: {
|
|
64
71
|
now?: Date;
|
|
65
72
|
}) => Notice[];
|
|
66
73
|
/**
|
|
@@ -73,11 +80,12 @@ declare const formatNotice: (notice: Notice) => string;
|
|
|
73
80
|
//#endregion
|
|
74
81
|
//#region src/snapshot.d.ts
|
|
75
82
|
/**
|
|
76
|
-
* A schema reduced to what a comparison needs: its kind,
|
|
77
|
-
* values it accepts when it is closed.
|
|
83
|
+
* A schema reduced to what a comparison needs: its kind, whether it accepts
|
|
84
|
+
* `null`, its fields, and the values it accepts when it is closed.
|
|
78
85
|
*/
|
|
79
86
|
type SchemaNode = {
|
|
80
87
|
kind: 'object';
|
|
88
|
+
nullable?: true;
|
|
81
89
|
fields: Record<string, {
|
|
82
90
|
optional: boolean;
|
|
83
91
|
schema: SchemaNode;
|
|
@@ -85,14 +93,29 @@ type SchemaNode = {
|
|
|
85
93
|
refinements?: number;
|
|
86
94
|
} | {
|
|
87
95
|
kind: 'array';
|
|
96
|
+
nullable?: true;
|
|
88
97
|
element: SchemaNode;
|
|
89
98
|
refinements?: number;
|
|
90
99
|
} | {
|
|
91
100
|
kind: 'enum';
|
|
101
|
+
nullable?: true;
|
|
92
102
|
values: string[];
|
|
103
|
+
extensible?: true;
|
|
104
|
+
refinements?: number;
|
|
105
|
+
} | {
|
|
106
|
+
kind: 'model';
|
|
107
|
+
nullable?: true;
|
|
108
|
+
model: string;
|
|
109
|
+
refinements?: number;
|
|
110
|
+
} | {
|
|
111
|
+
kind: 'union';
|
|
112
|
+
nullable?: true;
|
|
113
|
+
options: SchemaNode[];
|
|
114
|
+
extensible?: true;
|
|
93
115
|
refinements?: number;
|
|
94
116
|
} | {
|
|
95
117
|
kind: string;
|
|
118
|
+
nullable?: true;
|
|
96
119
|
refinements?: number;
|
|
97
120
|
};
|
|
98
121
|
//#endregion
|
|
@@ -157,18 +180,16 @@ declare const hasBreakingChange: (changes: Change[]) => boolean;
|
|
|
157
180
|
//#endregion
|
|
158
181
|
//#region src/generate-clients.d.ts
|
|
159
182
|
/**
|
|
160
|
-
* A
|
|
183
|
+
* A file that was written, and whether it had to be.
|
|
161
184
|
*/
|
|
162
|
-
interface
|
|
163
|
-
kind: string;
|
|
185
|
+
interface WrittenFile {
|
|
164
186
|
output: string;
|
|
165
187
|
changed: boolean;
|
|
166
188
|
}
|
|
167
189
|
/**
|
|
168
|
-
* A generated
|
|
190
|
+
* A generated file that does not match its api.
|
|
169
191
|
*/
|
|
170
|
-
interface
|
|
171
|
-
kind: string;
|
|
192
|
+
interface StaleFile {
|
|
172
193
|
output: string;
|
|
173
194
|
/**
|
|
174
195
|
* `missing` when nothing is there, `outdated` when what is there is old.
|
|
@@ -176,22 +197,24 @@ interface StaleClient {
|
|
|
176
197
|
reason: 'missing' | 'outdated';
|
|
177
198
|
}
|
|
178
199
|
/**
|
|
179
|
-
* Writes every
|
|
180
|
-
* matches so watchers and build tools see no
|
|
200
|
+
* Writes every generated file, the clients and what plugins generate, leaving
|
|
201
|
+
* a file alone when it already matches so watchers and build tools see no
|
|
202
|
+
* change.
|
|
181
203
|
*/
|
|
182
|
-
declare const
|
|
204
|
+
declare const writeFiles: (contract: ApiDefinition, files: readonly GeneratedFile[]) => WrittenFile[];
|
|
183
205
|
/**
|
|
184
|
-
* Every
|
|
206
|
+
* Every generated file that no longer matches its api, without writing
|
|
207
|
+
* anything.
|
|
185
208
|
*
|
|
186
209
|
* This is what a pipeline runs: a generated client that has fallen behind is a
|
|
187
210
|
* compile error waiting to happen in whatever imports it.
|
|
188
211
|
*/
|
|
189
|
-
declare const
|
|
212
|
+
declare const checkFiles: (contract: ApiDefinition, files: readonly GeneratedFile[]) => StaleFile[];
|
|
190
213
|
/**
|
|
191
214
|
* What a pipeline prints when a check fails, naming the command that fixes it
|
|
192
215
|
* rather than printing a diff nobody reads.
|
|
193
216
|
*/
|
|
194
|
-
declare const formatStale: (stale: readonly
|
|
217
|
+
declare const formatStale: (stale: readonly StaleFile[], command?: string) => string;
|
|
195
218
|
//#endregion
|
|
196
219
|
//#region src/generate-types.d.ts
|
|
197
220
|
declare class ConfigSyntaxError extends Error {}
|
|
@@ -201,12 +224,14 @@ declare class ConfigSyntaxError extends Error {}
|
|
|
201
224
|
*
|
|
202
225
|
* Read from the config's syntax rather than by running it: the generated file
|
|
203
226
|
* imports the same names the config did, and a config that loads is not a
|
|
204
|
-
* prerequisite for typing the routes it serves.
|
|
227
|
+
* prerequisite for typing the routes it serves. What
|
|
228
|
+
* `typescript.extend` adds exists only once the config has run, so the caller passes
|
|
229
|
+
* it in.
|
|
205
230
|
*
|
|
206
231
|
* `outputPath` is what the imports are written relative to. Left out, they stay
|
|
207
232
|
* relative to the config.
|
|
208
233
|
*/
|
|
209
|
-
declare const generateConfigTypes: (configSource: string, fileName?: string, outputPath?: string) => string;
|
|
234
|
+
declare const generateConfigTypes: (configSource: string, fileName?: string, outputPath?: string, extensions?: readonly ConfigExtension[]) => string;
|
|
210
235
|
//#endregion
|
|
211
236
|
//#region src/diff-schemas.d.ts
|
|
212
237
|
/**
|
|
@@ -223,6 +248,7 @@ interface SchemaChange {
|
|
|
223
248
|
*/
|
|
224
249
|
path: string;
|
|
225
250
|
summary: string;
|
|
251
|
+
detail?: string;
|
|
226
252
|
}
|
|
227
253
|
/**
|
|
228
254
|
* What changed between two versions of one schema, and whether it breaks the
|
|
@@ -257,18 +283,25 @@ interface RouteEntry {
|
|
|
257
283
|
method: string;
|
|
258
284
|
path: string;
|
|
259
285
|
auth: string;
|
|
260
|
-
|
|
286
|
+
/**
|
|
287
|
+
* The route's groups, as dotted paths.
|
|
288
|
+
*/
|
|
289
|
+
groups: string[];
|
|
261
290
|
tool?: string;
|
|
262
291
|
deprecated?: string;
|
|
263
292
|
sunset?: string;
|
|
293
|
+
/**
|
|
294
|
+
* `true` when the route is `hidden`: served, but in no generated client.
|
|
295
|
+
*/
|
|
296
|
+
hidden?: true;
|
|
264
297
|
}
|
|
265
298
|
/**
|
|
266
299
|
* Every route an api serves, in the order it declares them.
|
|
267
300
|
*/
|
|
268
|
-
declare const routeMap: (
|
|
301
|
+
declare const routeMap: (api: ApiDefinition, _options?: Record<string, never>) => RouteEntry[];
|
|
269
302
|
/**
|
|
270
303
|
* The route map as aligned columns, one route per line.
|
|
271
304
|
*/
|
|
272
305
|
declare const formatRoutes: (entries: readonly RouteEntry[]) => string;
|
|
273
306
|
//#endregion
|
|
274
|
-
export { type Change, type ChangeLevel, ConfigSyntaxError, type DiffAgainstOptions, type Direction, type LoadedApi, type Notice, type RouteEntry, type SchemaChange, type
|
|
307
|
+
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 };
|