@kizunajs/cli 2.0.0-beta.15 → 2.0.0-beta.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -1,14 +1,54 @@
1
1
  #!/usr/bin/env node
2
- const require_route_map = require("./route-map-CTy0nJPu.cjs");
2
+ const require_route_map = require("./route-map-C0CF82bw.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 entries = require_route_map.routeMap((await loadOrDie(configPathFrom(values.config))).api, {});
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-Bt94ERSi.mjs";
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-BPi-Oj1o.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 entries = routeMap((await loadOrDie(configPathFrom(values.config))).api, {});
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-CTy0nJPu.cjs");
2
+ const require_route_map = require("./route-map-C0CF82bw.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
@@ -260,7 +260,10 @@ interface RouteEntry {
260
260
  method: string;
261
261
  path: string;
262
262
  auth: string;
263
- tags: string[];
263
+ /**
264
+ * The route's groups, as dotted paths.
265
+ */
266
+ groups: string[];
264
267
  tool?: string;
265
268
  deprecated?: string;
266
269
  sunset?: string;
package/dist/index.d.mts CHANGED
@@ -260,7 +260,10 @@ interface RouteEntry {
260
260
  method: string;
261
261
  path: string;
262
262
  auth: string;
263
- tags: string[];
263
+ /**
264
+ * The route's groups, as dotted paths.
265
+ */
266
+ groups: string[];
264
267
  tool?: string;
265
268
  deprecated?: string;
266
269
  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-Bt94ERSi.mjs";
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-BPi-Oj1o.mjs";
2
2
  import { walkApi } from "kizunajs/generator";
3
3
  //#region src/api-notices.ts
4
4
  const readSunset = (route) => {
@@ -502,7 +502,7 @@ const formatStale = (stale, command = "kizuna generate") => {
502
502
  */
503
503
  const CONFIG_KEYS = [
504
504
  "adapter",
505
- "tags",
505
+ "groups",
506
506
  "auth",
507
507
  "requestContext",
508
508
  "validation",
@@ -823,7 +823,7 @@ const routeMap = (api, _options = {}) => {
823
823
  const entries = [];
824
824
  const toolKeys = [];
825
825
  return walkApi(api, {
826
- processRoute({ routeKey, route, routeTags, deprecated, deprecationMessage, hidden }) {
826
+ processRoute({ routeKey, route, routeGroups, deprecated, deprecationMessage, hidden }) {
827
827
  if (route.tool) toolKeys.push({
828
828
  key: routeKey,
829
829
  origin: "route"
@@ -833,7 +833,7 @@ const routeMap = (api, _options = {}) => {
833
833
  method: route.method,
834
834
  path: route.path,
835
835
  auth: describeAuth(route.auth),
836
- tags: routeTags,
836
+ groups: routeGroups,
837
837
  deprecated: deprecated ? deprecationMessage ?? "" : void 0,
838
838
  sunset: describeSunset(route.sunset),
839
839
  ...hidden ? { hidden: true } : {}
@@ -860,6 +860,7 @@ const formatRoutes = (entries) => {
860
860
  return entries.map((entry) => {
861
861
  const notes = [
862
862
  `auth: ${entry.auth}`,
863
+ entry.groups.length > 0 && `group: ${entry.groups.join(", ")}`,
863
864
  entry.tool && `tool: ${entry.tool}`,
864
865
  entry.deprecated !== void 0 && `deprecated${entry.deprecated ? `, ${entry.deprecated}` : ""}`,
865
866
  entry.sunset && `sunset ${entry.sunset}`,
@@ -525,7 +525,7 @@ const formatStale = (stale, command = "kizuna generate") => {
525
525
  */
526
526
  const CONFIG_KEYS = [
527
527
  "adapter",
528
- "tags",
528
+ "groups",
529
529
  "auth",
530
530
  "requestContext",
531
531
  "validation",
@@ -846,7 +846,7 @@ const routeMap = (api, _options = {}) => {
846
846
  const entries = [];
847
847
  const toolKeys = [];
848
848
  return (0, kizunajs_generator.walkApi)(api, {
849
- processRoute({ routeKey, route, routeTags, deprecated, deprecationMessage, hidden }) {
849
+ processRoute({ routeKey, route, routeGroups, deprecated, deprecationMessage, hidden }) {
850
850
  if (route.tool) toolKeys.push({
851
851
  key: routeKey,
852
852
  origin: "route"
@@ -856,7 +856,7 @@ const routeMap = (api, _options = {}) => {
856
856
  method: route.method,
857
857
  path: route.path,
858
858
  auth: describeAuth(route.auth),
859
- tags: routeTags,
859
+ groups: routeGroups,
860
860
  deprecated: deprecated ? deprecationMessage ?? "" : void 0,
861
861
  sunset: describeSunset(route.sunset),
862
862
  ...hidden ? { hidden: true } : {}
@@ -883,6 +883,7 @@ const formatRoutes = (entries) => {
883
883
  return entries.map((entry) => {
884
884
  const notes = [
885
885
  `auth: ${entry.auth}`,
886
+ entry.groups.length > 0 && `group: ${entry.groups.join(", ")}`,
886
887
  entry.tool && `tool: ${entry.tool}`,
887
888
  entry.deprecated !== void 0 && `deprecated${entry.deprecated ? `, ${entry.deprecated}` : ""}`,
888
889
  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.15",
3
+ "version": "2.0.0-beta.17",
4
4
  "description": "Command line tooling for Kizuna.js",
5
5
  "keywords": [
6
6
  "kizunajs",
@@ -61,15 +61,15 @@
61
61
  "yaml": "^2.8.4"
62
62
  },
63
63
  "peerDependencies": {
64
- "zod": "^4.0.0",
65
- "kizunajs": "2.0.0-beta.15"
64
+ "kizunajs": "2.0.0-beta.17",
65
+ "zod": "^4.0.0"
66
66
  },
67
67
  "devDependencies": {
68
+ "kizunajs": "2.0.0-beta.17",
68
69
  "@types/node": "^24",
69
70
  "@types/react": "^19.2.18",
70
71
  "tsdown": "^0.21.0",
71
- "zod": "^4.0.0",
72
- "kizunajs": "2.0.0-beta.15"
72
+ "zod": "^4.0.0"
73
73
  },
74
74
  "scripts": {
75
75
  "build": "tsdown src/index.ts src/cli.ts --format esm,cjs --dts --clean --external kizunajs --external zod --external jiti --external typescript",