@kizunajs/cli 2.0.0-beta.16 → 2.0.0-beta.18
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 +48 -3
- package/dist/cli.mjs +48 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +10 -3
- package/dist/index.d.mts +10 -3
- package/dist/index.mjs +1 -1
- package/dist/{route-map-CTy0nJPu.cjs → route-map-BHe__KDP.cjs} +38 -10
- package/dist/{route-map-Bt94ERSi.mjs → route-map-C0K0orUw.mjs} +38 -10
- package/package.json +3 -3
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-BHe__KDP.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:
|
|
@@ -98,8 +138,13 @@ const runGenerate = async (values) => {
|
|
|
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 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-
|
|
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";
|
|
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:
|
|
@@ -98,8 +138,13 @@ const runGenerate = async (values) => {
|
|
|
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-BHe__KDP.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
|
@@ -76,11 +76,12 @@ declare const formatNotice: (notice: Notice) => string;
|
|
|
76
76
|
//#endregion
|
|
77
77
|
//#region src/snapshot.d.ts
|
|
78
78
|
/**
|
|
79
|
-
* A schema reduced to what a comparison needs: its kind,
|
|
80
|
-
* values it accepts when it is closed.
|
|
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
81
|
*/
|
|
82
82
|
type SchemaNode = {
|
|
83
83
|
kind: 'object';
|
|
84
|
+
nullable?: true;
|
|
84
85
|
fields: Record<string, {
|
|
85
86
|
optional: boolean;
|
|
86
87
|
schema: SchemaNode;
|
|
@@ -88,14 +89,17 @@ type SchemaNode = {
|
|
|
88
89
|
refinements?: number;
|
|
89
90
|
} | {
|
|
90
91
|
kind: 'array';
|
|
92
|
+
nullable?: true;
|
|
91
93
|
element: SchemaNode;
|
|
92
94
|
refinements?: number;
|
|
93
95
|
} | {
|
|
94
96
|
kind: 'enum';
|
|
97
|
+
nullable?: true;
|
|
95
98
|
values: string[];
|
|
96
99
|
refinements?: number;
|
|
97
100
|
} | {
|
|
98
101
|
kind: string;
|
|
102
|
+
nullable?: true;
|
|
99
103
|
refinements?: number;
|
|
100
104
|
};
|
|
101
105
|
//#endregion
|
|
@@ -260,7 +264,10 @@ interface RouteEntry {
|
|
|
260
264
|
method: string;
|
|
261
265
|
path: string;
|
|
262
266
|
auth: string;
|
|
263
|
-
|
|
267
|
+
/**
|
|
268
|
+
* The route's groups, as dotted paths.
|
|
269
|
+
*/
|
|
270
|
+
groups: string[];
|
|
264
271
|
tool?: string;
|
|
265
272
|
deprecated?: string;
|
|
266
273
|
sunset?: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -76,11 +76,12 @@ declare const formatNotice: (notice: Notice) => string;
|
|
|
76
76
|
//#endregion
|
|
77
77
|
//#region src/snapshot.d.ts
|
|
78
78
|
/**
|
|
79
|
-
* A schema reduced to what a comparison needs: its kind,
|
|
80
|
-
* values it accepts when it is closed.
|
|
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
81
|
*/
|
|
82
82
|
type SchemaNode = {
|
|
83
83
|
kind: 'object';
|
|
84
|
+
nullable?: true;
|
|
84
85
|
fields: Record<string, {
|
|
85
86
|
optional: boolean;
|
|
86
87
|
schema: SchemaNode;
|
|
@@ -88,14 +89,17 @@ type SchemaNode = {
|
|
|
88
89
|
refinements?: number;
|
|
89
90
|
} | {
|
|
90
91
|
kind: 'array';
|
|
92
|
+
nullable?: true;
|
|
91
93
|
element: SchemaNode;
|
|
92
94
|
refinements?: number;
|
|
93
95
|
} | {
|
|
94
96
|
kind: 'enum';
|
|
97
|
+
nullable?: true;
|
|
95
98
|
values: string[];
|
|
96
99
|
refinements?: number;
|
|
97
100
|
} | {
|
|
98
101
|
kind: string;
|
|
102
|
+
nullable?: true;
|
|
99
103
|
refinements?: number;
|
|
100
104
|
};
|
|
101
105
|
//#endregion
|
|
@@ -260,7 +264,10 @@ interface RouteEntry {
|
|
|
260
264
|
method: string;
|
|
261
265
|
path: string;
|
|
262
266
|
auth: string;
|
|
263
|
-
|
|
267
|
+
/**
|
|
268
|
+
* The route's groups, as dotted paths.
|
|
269
|
+
*/
|
|
270
|
+
groups: string[];
|
|
264
271
|
tool?: string;
|
|
265
272
|
deprecated?: string;
|
|
266
273
|
sunset?: string;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as loadConfig, a as ConfigSyntaxError, c as formatStale, f as formatChange, g as diffSchemas, l as writeFiles, n as routeMap, o as generateConfigTypes, p as hasBreakingChange, r as diffAgainst, s as checkFiles, t as formatRoutes, u as diffApis } from "./route-map-
|
|
1
|
+
import { _ as loadConfig, a as ConfigSyntaxError, c as formatStale, f as formatChange, g as diffSchemas, l as writeFiles, n as routeMap, o as generateConfigTypes, p as hasBreakingChange, r as diffAgainst, s as checkFiles, t as formatRoutes, u as diffApis } from "./route-map-C0K0orUw.mjs";
|
|
2
2
|
import { walkApi } from "kizunajs/generator";
|
|
3
3
|
//#region src/api-notices.ts
|
|
4
4
|
const readSunset = (route) => {
|
|
@@ -82,10 +82,25 @@ const diffSchemas = (before, after, direction, path = "") => {
|
|
|
82
82
|
path,
|
|
83
83
|
summary: `${path || "the body"} is gone`
|
|
84
84
|
}];
|
|
85
|
+
if (before.kind !== after.kind) return [{
|
|
86
|
+
breaking: true,
|
|
87
|
+
path,
|
|
88
|
+
summary: `${path || "the body"} is ${describeKind(after)} instead of ${describeKind(before)}`
|
|
89
|
+
}];
|
|
85
90
|
const changes = [];
|
|
91
|
+
const wasNullable = before.nullable === true;
|
|
92
|
+
const isNullable = after.nullable === true;
|
|
93
|
+
if (wasNullable !== isNullable) changes.push({
|
|
94
|
+
breaking: direction === (isNullable ? "response" : "request"),
|
|
95
|
+
path,
|
|
96
|
+
summary: isNullable ? `${path || "the body"} can now be null` : `${path || "the body"} can no longer be null`
|
|
97
|
+
});
|
|
86
98
|
const beforeElement = elementOf(before);
|
|
87
99
|
const afterElement = elementOf(after);
|
|
88
|
-
if (beforeElement && afterElement)
|
|
100
|
+
if (beforeElement && afterElement) {
|
|
101
|
+
changes.push(...diffSchemas(beforeElement, afterElement, direction, `${path}[]`));
|
|
102
|
+
return changes;
|
|
103
|
+
}
|
|
89
104
|
const beforeFields = fieldsOf(before);
|
|
90
105
|
const afterFields = fieldsOf(after);
|
|
91
106
|
if (beforeFields && afterFields) {
|
|
@@ -105,6 +120,11 @@ const diffSchemas = (before, after, direction, path = "") => {
|
|
|
105
120
|
path: here,
|
|
106
121
|
summary: `${here} is no longer optional`
|
|
107
122
|
});
|
|
123
|
+
if (!existing.optional && field.optional) changes.push({
|
|
124
|
+
breaking: direction === "response",
|
|
125
|
+
path: here,
|
|
126
|
+
summary: direction === "response" ? `${here} may now be left out` : `${here} is now optional`
|
|
127
|
+
});
|
|
108
128
|
changes.push(...diffSchemas(existing.schema, field.schema, direction, here));
|
|
109
129
|
}
|
|
110
130
|
for (const key of Object.keys(beforeFields)) {
|
|
@@ -118,11 +138,6 @@ const diffSchemas = (before, after, direction, path = "") => {
|
|
|
118
138
|
}
|
|
119
139
|
return changes;
|
|
120
140
|
}
|
|
121
|
-
if (before.kind !== after.kind) return [{
|
|
122
|
-
breaking: true,
|
|
123
|
-
path,
|
|
124
|
-
summary: `${path || "the body"} is ${describeKind(after)} instead of ${describeKind(before)}`
|
|
125
|
-
}];
|
|
126
141
|
const was = valuesOf(before);
|
|
127
142
|
const now = valuesOf(after);
|
|
128
143
|
if (was && now) {
|
|
@@ -165,8 +180,15 @@ const refinementCount = (schema) => {
|
|
|
165
180
|
* A Zod schema reduced to the shape a comparison reads.
|
|
166
181
|
*/
|
|
167
182
|
const toSchemaNode = (schema) => {
|
|
168
|
-
const { inner } = (0, kizunajs_generator.unwrapOptionalWrappers)(schema);
|
|
183
|
+
const { inner, nullable } = (0, kizunajs_generator.unwrapOptionalWrappers)(schema);
|
|
169
184
|
const def = (0, kizunajs_generator.readDef)(inner);
|
|
185
|
+
const options = def.type === "union" ? def.options ?? [] : [];
|
|
186
|
+
const nonNull = options.filter((option) => (0, kizunajs_generator.readDef)(option).type !== "null");
|
|
187
|
+
if (nonNull.length === 1 && options.length > 1) return {
|
|
188
|
+
...toSchemaNode(nonNull[0]),
|
|
189
|
+
nullable: true
|
|
190
|
+
};
|
|
191
|
+
const nullability = nullable ? { nullable: true } : {};
|
|
170
192
|
const refinements = refinementCount(inner);
|
|
171
193
|
const carry = refinements === void 0 ? {} : { refinements };
|
|
172
194
|
const shape = (0, kizunajs_generator.readObjectShape)(inner);
|
|
@@ -178,27 +200,32 @@ const toSchemaNode = (schema) => {
|
|
|
178
200
|
};
|
|
179
201
|
return {
|
|
180
202
|
kind: "object",
|
|
203
|
+
...nullability,
|
|
181
204
|
fields,
|
|
182
205
|
...carry
|
|
183
206
|
};
|
|
184
207
|
}
|
|
185
208
|
if (def.type === "array" && def.element) return {
|
|
186
209
|
kind: "array",
|
|
210
|
+
...nullability,
|
|
187
211
|
element: toSchemaNode(def.element),
|
|
188
212
|
...carry
|
|
189
213
|
};
|
|
190
214
|
if (def.type === "enum") return {
|
|
191
215
|
kind: "enum",
|
|
216
|
+
...nullability,
|
|
192
217
|
values: Object.values(def.entries ?? {}).map(String).sort(),
|
|
193
218
|
...carry
|
|
194
219
|
};
|
|
195
220
|
if (def.type === "literal") return {
|
|
196
221
|
kind: "enum",
|
|
222
|
+
...nullability,
|
|
197
223
|
values: (def.values ?? []).map(String).sort(),
|
|
198
224
|
...carry
|
|
199
225
|
};
|
|
200
226
|
return {
|
|
201
227
|
kind: def.type ?? "unknown",
|
|
228
|
+
...nullability,
|
|
202
229
|
...carry
|
|
203
230
|
};
|
|
204
231
|
};
|
|
@@ -525,7 +552,7 @@ const formatStale = (stale, command = "kizuna generate") => {
|
|
|
525
552
|
*/
|
|
526
553
|
const CONFIG_KEYS = [
|
|
527
554
|
"adapter",
|
|
528
|
-
"
|
|
555
|
+
"groups",
|
|
529
556
|
"auth",
|
|
530
557
|
"requestContext",
|
|
531
558
|
"validation",
|
|
@@ -846,7 +873,7 @@ const routeMap = (api, _options = {}) => {
|
|
|
846
873
|
const entries = [];
|
|
847
874
|
const toolKeys = [];
|
|
848
875
|
return (0, kizunajs_generator.walkApi)(api, {
|
|
849
|
-
processRoute({ routeKey, route,
|
|
876
|
+
processRoute({ routeKey, route, routeGroups, deprecated, deprecationMessage, hidden }) {
|
|
850
877
|
if (route.tool) toolKeys.push({
|
|
851
878
|
key: routeKey,
|
|
852
879
|
origin: "route"
|
|
@@ -856,7 +883,7 @@ const routeMap = (api, _options = {}) => {
|
|
|
856
883
|
method: route.method,
|
|
857
884
|
path: route.path,
|
|
858
885
|
auth: describeAuth(route.auth),
|
|
859
|
-
|
|
886
|
+
groups: routeGroups,
|
|
860
887
|
deprecated: deprecated ? deprecationMessage ?? "" : void 0,
|
|
861
888
|
sunset: describeSunset(route.sunset),
|
|
862
889
|
...hidden ? { hidden: true } : {}
|
|
@@ -883,6 +910,7 @@ const formatRoutes = (entries) => {
|
|
|
883
910
|
return entries.map((entry) => {
|
|
884
911
|
const notes = [
|
|
885
912
|
`auth: ${entry.auth}`,
|
|
913
|
+
entry.groups.length > 0 && `group: ${entry.groups.join(", ")}`,
|
|
886
914
|
entry.tool && `tool: ${entry.tool}`,
|
|
887
915
|
entry.deprecated !== void 0 && `deprecated${entry.deprecated ? `, ${entry.deprecated}` : ""}`,
|
|
888
916
|
entry.sunset && `sunset ${entry.sunset}`,
|
|
@@ -59,10 +59,25 @@ const diffSchemas = (before, after, direction, path = "") => {
|
|
|
59
59
|
path,
|
|
60
60
|
summary: `${path || "the body"} is gone`
|
|
61
61
|
}];
|
|
62
|
+
if (before.kind !== after.kind) return [{
|
|
63
|
+
breaking: true,
|
|
64
|
+
path,
|
|
65
|
+
summary: `${path || "the body"} is ${describeKind(after)} instead of ${describeKind(before)}`
|
|
66
|
+
}];
|
|
62
67
|
const changes = [];
|
|
68
|
+
const wasNullable = before.nullable === true;
|
|
69
|
+
const isNullable = after.nullable === true;
|
|
70
|
+
if (wasNullable !== isNullable) changes.push({
|
|
71
|
+
breaking: direction === (isNullable ? "response" : "request"),
|
|
72
|
+
path,
|
|
73
|
+
summary: isNullable ? `${path || "the body"} can now be null` : `${path || "the body"} can no longer be null`
|
|
74
|
+
});
|
|
63
75
|
const beforeElement = elementOf(before);
|
|
64
76
|
const afterElement = elementOf(after);
|
|
65
|
-
if (beforeElement && afterElement)
|
|
77
|
+
if (beforeElement && afterElement) {
|
|
78
|
+
changes.push(...diffSchemas(beforeElement, afterElement, direction, `${path}[]`));
|
|
79
|
+
return changes;
|
|
80
|
+
}
|
|
66
81
|
const beforeFields = fieldsOf(before);
|
|
67
82
|
const afterFields = fieldsOf(after);
|
|
68
83
|
if (beforeFields && afterFields) {
|
|
@@ -82,6 +97,11 @@ const diffSchemas = (before, after, direction, path = "") => {
|
|
|
82
97
|
path: here,
|
|
83
98
|
summary: `${here} is no longer optional`
|
|
84
99
|
});
|
|
100
|
+
if (!existing.optional && field.optional) changes.push({
|
|
101
|
+
breaking: direction === "response",
|
|
102
|
+
path: here,
|
|
103
|
+
summary: direction === "response" ? `${here} may now be left out` : `${here} is now optional`
|
|
104
|
+
});
|
|
85
105
|
changes.push(...diffSchemas(existing.schema, field.schema, direction, here));
|
|
86
106
|
}
|
|
87
107
|
for (const key of Object.keys(beforeFields)) {
|
|
@@ -95,11 +115,6 @@ const diffSchemas = (before, after, direction, path = "") => {
|
|
|
95
115
|
}
|
|
96
116
|
return changes;
|
|
97
117
|
}
|
|
98
|
-
if (before.kind !== after.kind) return [{
|
|
99
|
-
breaking: true,
|
|
100
|
-
path,
|
|
101
|
-
summary: `${path || "the body"} is ${describeKind(after)} instead of ${describeKind(before)}`
|
|
102
|
-
}];
|
|
103
118
|
const was = valuesOf(before);
|
|
104
119
|
const now = valuesOf(after);
|
|
105
120
|
if (was && now) {
|
|
@@ -142,8 +157,15 @@ const refinementCount = (schema) => {
|
|
|
142
157
|
* A Zod schema reduced to the shape a comparison reads.
|
|
143
158
|
*/
|
|
144
159
|
const toSchemaNode = (schema) => {
|
|
145
|
-
const { inner } = unwrapOptionalWrappers(schema);
|
|
160
|
+
const { inner, nullable } = unwrapOptionalWrappers(schema);
|
|
146
161
|
const def = readDef(inner);
|
|
162
|
+
const options = def.type === "union" ? def.options ?? [] : [];
|
|
163
|
+
const nonNull = options.filter((option) => readDef(option).type !== "null");
|
|
164
|
+
if (nonNull.length === 1 && options.length > 1) return {
|
|
165
|
+
...toSchemaNode(nonNull[0]),
|
|
166
|
+
nullable: true
|
|
167
|
+
};
|
|
168
|
+
const nullability = nullable ? { nullable: true } : {};
|
|
147
169
|
const refinements = refinementCount(inner);
|
|
148
170
|
const carry = refinements === void 0 ? {} : { refinements };
|
|
149
171
|
const shape = readObjectShape(inner);
|
|
@@ -155,27 +177,32 @@ const toSchemaNode = (schema) => {
|
|
|
155
177
|
};
|
|
156
178
|
return {
|
|
157
179
|
kind: "object",
|
|
180
|
+
...nullability,
|
|
158
181
|
fields,
|
|
159
182
|
...carry
|
|
160
183
|
};
|
|
161
184
|
}
|
|
162
185
|
if (def.type === "array" && def.element) return {
|
|
163
186
|
kind: "array",
|
|
187
|
+
...nullability,
|
|
164
188
|
element: toSchemaNode(def.element),
|
|
165
189
|
...carry
|
|
166
190
|
};
|
|
167
191
|
if (def.type === "enum") return {
|
|
168
192
|
kind: "enum",
|
|
193
|
+
...nullability,
|
|
169
194
|
values: Object.values(def.entries ?? {}).map(String).sort(),
|
|
170
195
|
...carry
|
|
171
196
|
};
|
|
172
197
|
if (def.type === "literal") return {
|
|
173
198
|
kind: "enum",
|
|
199
|
+
...nullability,
|
|
174
200
|
values: (def.values ?? []).map(String).sort(),
|
|
175
201
|
...carry
|
|
176
202
|
};
|
|
177
203
|
return {
|
|
178
204
|
kind: def.type ?? "unknown",
|
|
205
|
+
...nullability,
|
|
179
206
|
...carry
|
|
180
207
|
};
|
|
181
208
|
};
|
|
@@ -502,7 +529,7 @@ const formatStale = (stale, command = "kizuna generate") => {
|
|
|
502
529
|
*/
|
|
503
530
|
const CONFIG_KEYS = [
|
|
504
531
|
"adapter",
|
|
505
|
-
"
|
|
532
|
+
"groups",
|
|
506
533
|
"auth",
|
|
507
534
|
"requestContext",
|
|
508
535
|
"validation",
|
|
@@ -823,7 +850,7 @@ const routeMap = (api, _options = {}) => {
|
|
|
823
850
|
const entries = [];
|
|
824
851
|
const toolKeys = [];
|
|
825
852
|
return walkApi(api, {
|
|
826
|
-
processRoute({ routeKey, route,
|
|
853
|
+
processRoute({ routeKey, route, routeGroups, deprecated, deprecationMessage, hidden }) {
|
|
827
854
|
if (route.tool) toolKeys.push({
|
|
828
855
|
key: routeKey,
|
|
829
856
|
origin: "route"
|
|
@@ -833,7 +860,7 @@ const routeMap = (api, _options = {}) => {
|
|
|
833
860
|
method: route.method,
|
|
834
861
|
path: route.path,
|
|
835
862
|
auth: describeAuth(route.auth),
|
|
836
|
-
|
|
863
|
+
groups: routeGroups,
|
|
837
864
|
deprecated: deprecated ? deprecationMessage ?? "" : void 0,
|
|
838
865
|
sunset: describeSunset(route.sunset),
|
|
839
866
|
...hidden ? { hidden: true } : {}
|
|
@@ -860,6 +887,7 @@ const formatRoutes = (entries) => {
|
|
|
860
887
|
return entries.map((entry) => {
|
|
861
888
|
const notes = [
|
|
862
889
|
`auth: ${entry.auth}`,
|
|
890
|
+
entry.groups.length > 0 && `group: ${entry.groups.join(", ")}`,
|
|
863
891
|
entry.tool && `tool: ${entry.tool}`,
|
|
864
892
|
entry.deprecated !== void 0 && `deprecated${entry.deprecated ? `, ${entry.deprecated}` : ""}`,
|
|
865
893
|
entry.sunset && `sunset ${entry.sunset}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kizunajs/cli",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.18",
|
|
4
4
|
"description": "Command line tooling for Kizuna.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kizunajs",
|
|
@@ -61,11 +61,11 @@
|
|
|
61
61
|
"yaml": "^2.8.4"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"kizunajs": "2.0.0-beta.
|
|
64
|
+
"kizunajs": "2.0.0-beta.18",
|
|
65
65
|
"zod": "^4.0.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"kizunajs": "2.0.0-beta.
|
|
68
|
+
"kizunajs": "2.0.0-beta.18",
|
|
69
69
|
"@types/node": "^24",
|
|
70
70
|
"@types/react": "^19.2.18",
|
|
71
71
|
"tsdown": "^0.21.0",
|