@kizunajs/cli 2.0.0-beta.33 → 2.0.0-beta.35

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,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const require_route_map = require("./route-map-CGZ5VfE9.cjs");
2
+ const require_route_map = require("./route-map-CrmTV7B_.cjs");
3
3
  let kizunajs_generator = require("kizunajs/generator");
4
4
  let node_path = require("node:path");
5
5
  let node_fs = require("node:fs");
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
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-pLtv53AW.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-CA8qoJHZ.mjs";
3
3
  import { walkApi } from "kizunajs/generator";
4
4
  import { dirname, relative, resolve } from "node:path";
5
5
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
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-CGZ5VfE9.cjs");
2
+ const require_route_map = require("./route-map-CrmTV7B_.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
@@ -101,6 +101,16 @@ type SchemaNode = {
101
101
  nullable?: true;
102
102
  values: string[];
103
103
  refinements?: number;
104
+ } | {
105
+ kind: 'model';
106
+ nullable?: true;
107
+ model: string;
108
+ refinements?: number;
109
+ } | {
110
+ kind: 'union';
111
+ nullable?: true;
112
+ options: SchemaNode[];
113
+ refinements?: number;
104
114
  } | {
105
115
  kind: string;
106
116
  nullable?: true;
@@ -236,6 +246,7 @@ interface SchemaChange {
236
246
  */
237
247
  path: string;
238
248
  summary: string;
249
+ detail?: string;
239
250
  }
240
251
  /**
241
252
  * What changed between two versions of one schema, and whether it breaks the
package/dist/index.d.mts CHANGED
@@ -101,6 +101,16 @@ type SchemaNode = {
101
101
  nullable?: true;
102
102
  values: string[];
103
103
  refinements?: number;
104
+ } | {
105
+ kind: 'model';
106
+ nullable?: true;
107
+ model: string;
108
+ refinements?: number;
109
+ } | {
110
+ kind: 'union';
111
+ nullable?: true;
112
+ options: SchemaNode[];
113
+ refinements?: number;
104
114
  } | {
105
115
  kind: string;
106
116
  nullable?: true;
@@ -236,6 +246,7 @@ interface SchemaChange {
236
246
  */
237
247
  path: string;
238
248
  summary: string;
249
+ detail?: string;
239
250
  }
240
251
  /**
241
252
  * What changed between two versions of one schema, and whether it breaks the
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-pLtv53AW.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-CA8qoJHZ.mjs";
2
2
  import { walkApi } from "kizunajs/generator";
3
3
  //#region src/api-notices.ts
4
4
  const readSunset = (route) => {
@@ -1,6 +1,6 @@
1
1
  import { createJiti } from "jiti";
2
2
  import { apiEntries } from "kizunajs";
3
- import { deriveToolNames, flattenJobs, readDef, readObjectShape, resolveResponseBody, toToolName, unwrapOptionalWrappers, walkApi } from "kizunajs/generator";
3
+ import { deriveToolNames, flattenJobs, readDef, readMetaId, readModelSchema, readObjectShape, resolveResponseBody, toToolName, unwrapOptionalWrappers, walkApi } from "kizunajs/generator";
4
4
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
5
5
  import { parse, stringify } from "yaml";
6
6
  import { flattenRoutes } from "kizunajs/adapter";
@@ -37,12 +37,30 @@ const joinPath = (parent, key) => parent === "" ? key : `${parent}.${key}`;
37
37
  const fieldsOf = (schema) => schema.kind === "object" ? schema.fields : void 0;
38
38
  const elementOf = (schema) => schema.kind === "array" ? schema.element : void 0;
39
39
  const valuesOf = (schema) => schema.kind === "enum" ? schema.values : void 0;
40
+ const modelOf = (schema) => schema.kind === "model" ? schema.model : void 0;
41
+ const optionsOf = (schema) => schema.kind === "union" ? schema.options : void 0;
40
42
  /**
41
- * What a reader sees when the kinds differ, so `array` reads as `array<string>`.
43
+ * Whether every value `narrow` allows is one `wide` allows too. A union holds
44
+ * whatever one of its options holds.
45
+ */
46
+ const holds = (wide, narrow) => {
47
+ const narrowOptions = optionsOf(narrow);
48
+ if (narrowOptions) return narrowOptions.every((option) => holds(wide, option));
49
+ const wideOptions = optionsOf(wide);
50
+ if (wideOptions && wide.kind !== narrow.kind) return wideOptions.some((option) => holds(option, narrow));
51
+ if (wide.kind !== narrow.kind || modelOf(wide) !== modelOf(narrow)) return false;
52
+ if (narrow.nullable === true && wide.nullable !== true) return false;
53
+ return diffSchemas(narrow, wide, "request").every((change) => !change.breaking);
54
+ };
55
+ /**
56
+ * What a reader sees when the kinds differ, so `array` reads as `array<string>` and a union as `string | number`.
42
57
  */
43
58
  const describeKind = (schema) => {
44
59
  const element = elementOf(schema);
45
- return element ? `array<${describeKind(element)}>` : schema.kind;
60
+ if (element) return `array<${describeKind(element)}>`;
61
+ const options = optionsOf(schema);
62
+ if (options) return options.map(describeKind).join(" | ");
63
+ return modelOf(schema) ?? schema.kind;
46
64
  };
47
65
  /**
48
66
  * What changed between two versions of one schema, and whether it breaks the
@@ -60,11 +78,25 @@ const diffSchemas = (before, after, direction, path = "") => {
60
78
  path,
61
79
  summary: `${path || "the body"} is gone`
62
80
  }];
63
- if (before.kind !== after.kind) return [{
64
- breaking: true,
65
- path,
66
- summary: `${path || "the body"} is ${describeKind(after)} instead of ${describeKind(before)}`
67
- }];
81
+ const kindChanged = before.kind !== after.kind || modelOf(before) !== modelOf(after);
82
+ const bothUnions = optionsOf(before) !== void 0 && optionsOf(after) !== void 0;
83
+ if (kindChanged || bothUnions) {
84
+ const label = path || "the body";
85
+ const widened = holds(after, before);
86
+ const narrowed = holds(before, after);
87
+ if (!kindChanged && widened && narrowed) return [];
88
+ if (direction === "request" ? widened : narrowed) return [{
89
+ breaking: false,
90
+ path,
91
+ summary: `${label} ${direction === "request" ? "widens" : "narrows"} from ${describeKind(before)} to ${describeKind(after)}`,
92
+ detail: "the generated client type changes, the HTTP surface does not"
93
+ }];
94
+ return [{
95
+ breaking: true,
96
+ path,
97
+ summary: `${label} is ${describeKind(after)} instead of ${describeKind(before)}`
98
+ }];
99
+ }
68
100
  const changes = [];
69
101
  const wasNullable = before.nullable === true;
70
102
  const isNullable = after.nullable === true;
@@ -155,26 +187,36 @@ const refinementCount = (schema) => {
155
187
  return custom === 0 ? void 0 : custom;
156
188
  };
157
189
  /**
158
- * A Zod schema reduced to the shape a comparison reads.
190
+ * A Zod schema reduced to the shape a comparison reads. A model that holds
191
+ * itself is written out once, and inside itself as a reference by its title.
192
+ *
193
+ * `inside` is the objects the walk is in, so it can tell when it has gone round.
159
194
  */
160
- const toSchemaNode = (schema) => {
195
+ const toSchemaNode = (schema, inside = []) => {
161
196
  const { inner, nullable } = unwrapOptionalWrappers(schema);
162
197
  const def = readDef(inner);
198
+ const nullability = nullable ? { nullable: true } : {};
199
+ const identity = readModelSchema(inner) ?? inner;
200
+ if (inside.includes(identity)) return {
201
+ kind: "model",
202
+ ...nullability,
203
+ model: readMetaId(inner) ?? ""
204
+ };
163
205
  const options = def.type === "union" ? def.options ?? [] : [];
164
206
  const nonNull = options.filter((option) => readDef(option).type !== "null");
165
207
  if (nonNull.length === 1 && options.length > 1) return {
166
- ...toSchemaNode(nonNull[0]),
208
+ ...toSchemaNode(nonNull[0], inside),
167
209
  nullable: true
168
210
  };
169
- const nullability = nullable ? { nullable: true } : {};
170
211
  const refinements = refinementCount(inner);
171
212
  const carry = refinements === void 0 ? {} : { refinements };
172
213
  const shape = readObjectShape(inner);
173
214
  if (shape) {
174
215
  const fields = {};
216
+ const within = [...inside, identity];
175
217
  for (const [key, field] of Object.entries(shape)) fields[key] = {
176
218
  optional: unwrapOptionalWrappers(field).optional,
177
- schema: toSchemaNode(field)
219
+ schema: toSchemaNode(field, within)
178
220
  };
179
221
  return {
180
222
  kind: "object",
@@ -186,7 +228,7 @@ const toSchemaNode = (schema) => {
186
228
  if (def.type === "array" && def.element) return {
187
229
  kind: "array",
188
230
  ...nullability,
189
- element: toSchemaNode(def.element),
231
+ element: toSchemaNode(def.element, inside),
190
232
  ...carry
191
233
  };
192
234
  if (def.type === "enum") return {
@@ -201,6 +243,12 @@ const toSchemaNode = (schema) => {
201
243
  values: (def.values ?? []).map(String).sort(),
202
244
  ...carry
203
245
  };
246
+ if (def.type === "union") return {
247
+ kind: "union",
248
+ ...nullability,
249
+ options: options.map((option) => toSchemaNode(option, inside)),
250
+ ...carry
251
+ };
204
252
  return {
205
253
  kind: def.type ?? "unknown",
206
254
  ...nullability,
@@ -373,7 +421,8 @@ const diffSnapshots = (before, after, options = {}) => {
373
421
  for (const [direction, label, was, now] of inputs) for (const change of diffSchemas(was, now, direction, label)) changes.push({
374
422
  level: change.breaking ? "breaking" : "changed",
375
423
  key,
376
- summary: `${httpLabel(arrived, key)} ${change.summary}`
424
+ summary: `${httpLabel(arrived, key)} ${change.summary}`,
425
+ ...change.detail === void 0 ? {} : { detail: change.detail }
377
426
  });
378
427
  for (const [status, was] of Object.entries(gone.responses)) {
379
428
  if (!(status in arrived.responses)) continue;
@@ -381,7 +430,8 @@ const diffSnapshots = (before, after, options = {}) => {
381
430
  for (const change of diffSchemas(was ?? void 0, now ?? void 0, "response", status)) changes.push({
382
431
  level: change.breaking ? "breaking" : "changed",
383
432
  key,
384
- summary: `${httpLabel(arrived, key)} ${change.summary}`
433
+ summary: `${httpLabel(arrived, key)} ${change.summary}`,
434
+ ...change.detail === void 0 ? {} : { detail: change.detail }
385
435
  });
386
436
  }
387
437
  if (gone.hidden !== true && arrived.hidden === true) changes.push({
@@ -60,12 +60,30 @@ const joinPath = (parent, key) => parent === "" ? key : `${parent}.${key}`;
60
60
  const fieldsOf = (schema) => schema.kind === "object" ? schema.fields : void 0;
61
61
  const elementOf = (schema) => schema.kind === "array" ? schema.element : void 0;
62
62
  const valuesOf = (schema) => schema.kind === "enum" ? schema.values : void 0;
63
+ const modelOf = (schema) => schema.kind === "model" ? schema.model : void 0;
64
+ const optionsOf = (schema) => schema.kind === "union" ? schema.options : void 0;
63
65
  /**
64
- * What a reader sees when the kinds differ, so `array` reads as `array<string>`.
66
+ * Whether every value `narrow` allows is one `wide` allows too. A union holds
67
+ * whatever one of its options holds.
68
+ */
69
+ const holds = (wide, narrow) => {
70
+ const narrowOptions = optionsOf(narrow);
71
+ if (narrowOptions) return narrowOptions.every((option) => holds(wide, option));
72
+ const wideOptions = optionsOf(wide);
73
+ if (wideOptions && wide.kind !== narrow.kind) return wideOptions.some((option) => holds(option, narrow));
74
+ if (wide.kind !== narrow.kind || modelOf(wide) !== modelOf(narrow)) return false;
75
+ if (narrow.nullable === true && wide.nullable !== true) return false;
76
+ return diffSchemas(narrow, wide, "request").every((change) => !change.breaking);
77
+ };
78
+ /**
79
+ * What a reader sees when the kinds differ, so `array` reads as `array<string>` and a union as `string | number`.
65
80
  */
66
81
  const describeKind = (schema) => {
67
82
  const element = elementOf(schema);
68
- return element ? `array<${describeKind(element)}>` : schema.kind;
83
+ if (element) return `array<${describeKind(element)}>`;
84
+ const options = optionsOf(schema);
85
+ if (options) return options.map(describeKind).join(" | ");
86
+ return modelOf(schema) ?? schema.kind;
69
87
  };
70
88
  /**
71
89
  * What changed between two versions of one schema, and whether it breaks the
@@ -83,11 +101,25 @@ const diffSchemas = (before, after, direction, path = "") => {
83
101
  path,
84
102
  summary: `${path || "the body"} is gone`
85
103
  }];
86
- if (before.kind !== after.kind) return [{
87
- breaking: true,
88
- path,
89
- summary: `${path || "the body"} is ${describeKind(after)} instead of ${describeKind(before)}`
90
- }];
104
+ const kindChanged = before.kind !== after.kind || modelOf(before) !== modelOf(after);
105
+ const bothUnions = optionsOf(before) !== void 0 && optionsOf(after) !== void 0;
106
+ if (kindChanged || bothUnions) {
107
+ const label = path || "the body";
108
+ const widened = holds(after, before);
109
+ const narrowed = holds(before, after);
110
+ if (!kindChanged && widened && narrowed) return [];
111
+ if (direction === "request" ? widened : narrowed) return [{
112
+ breaking: false,
113
+ path,
114
+ summary: `${label} ${direction === "request" ? "widens" : "narrows"} from ${describeKind(before)} to ${describeKind(after)}`,
115
+ detail: "the generated client type changes, the HTTP surface does not"
116
+ }];
117
+ return [{
118
+ breaking: true,
119
+ path,
120
+ summary: `${label} is ${describeKind(after)} instead of ${describeKind(before)}`
121
+ }];
122
+ }
91
123
  const changes = [];
92
124
  const wasNullable = before.nullable === true;
93
125
  const isNullable = after.nullable === true;
@@ -178,26 +210,36 @@ const refinementCount = (schema) => {
178
210
  return custom === 0 ? void 0 : custom;
179
211
  };
180
212
  /**
181
- * A Zod schema reduced to the shape a comparison reads.
213
+ * A Zod schema reduced to the shape a comparison reads. A model that holds
214
+ * itself is written out once, and inside itself as a reference by its title.
215
+ *
216
+ * `inside` is the objects the walk is in, so it can tell when it has gone round.
182
217
  */
183
- const toSchemaNode = (schema) => {
218
+ const toSchemaNode = (schema, inside = []) => {
184
219
  const { inner, nullable } = (0, kizunajs_generator.unwrapOptionalWrappers)(schema);
185
220
  const def = (0, kizunajs_generator.readDef)(inner);
221
+ const nullability = nullable ? { nullable: true } : {};
222
+ const identity = (0, kizunajs_generator.readModelSchema)(inner) ?? inner;
223
+ if (inside.includes(identity)) return {
224
+ kind: "model",
225
+ ...nullability,
226
+ model: (0, kizunajs_generator.readMetaId)(inner) ?? ""
227
+ };
186
228
  const options = def.type === "union" ? def.options ?? [] : [];
187
229
  const nonNull = options.filter((option) => (0, kizunajs_generator.readDef)(option).type !== "null");
188
230
  if (nonNull.length === 1 && options.length > 1) return {
189
- ...toSchemaNode(nonNull[0]),
231
+ ...toSchemaNode(nonNull[0], inside),
190
232
  nullable: true
191
233
  };
192
- const nullability = nullable ? { nullable: true } : {};
193
234
  const refinements = refinementCount(inner);
194
235
  const carry = refinements === void 0 ? {} : { refinements };
195
236
  const shape = (0, kizunajs_generator.readObjectShape)(inner);
196
237
  if (shape) {
197
238
  const fields = {};
239
+ const within = [...inside, identity];
198
240
  for (const [key, field] of Object.entries(shape)) fields[key] = {
199
241
  optional: (0, kizunajs_generator.unwrapOptionalWrappers)(field).optional,
200
- schema: toSchemaNode(field)
242
+ schema: toSchemaNode(field, within)
201
243
  };
202
244
  return {
203
245
  kind: "object",
@@ -209,7 +251,7 @@ const toSchemaNode = (schema) => {
209
251
  if (def.type === "array" && def.element) return {
210
252
  kind: "array",
211
253
  ...nullability,
212
- element: toSchemaNode(def.element),
254
+ element: toSchemaNode(def.element, inside),
213
255
  ...carry
214
256
  };
215
257
  if (def.type === "enum") return {
@@ -224,6 +266,12 @@ const toSchemaNode = (schema) => {
224
266
  values: (def.values ?? []).map(String).sort(),
225
267
  ...carry
226
268
  };
269
+ if (def.type === "union") return {
270
+ kind: "union",
271
+ ...nullability,
272
+ options: options.map((option) => toSchemaNode(option, inside)),
273
+ ...carry
274
+ };
227
275
  return {
228
276
  kind: def.type ?? "unknown",
229
277
  ...nullability,
@@ -396,7 +444,8 @@ const diffSnapshots = (before, after, options = {}) => {
396
444
  for (const [direction, label, was, now] of inputs) for (const change of diffSchemas(was, now, direction, label)) changes.push({
397
445
  level: change.breaking ? "breaking" : "changed",
398
446
  key,
399
- summary: `${httpLabel(arrived, key)} ${change.summary}`
447
+ summary: `${httpLabel(arrived, key)} ${change.summary}`,
448
+ ...change.detail === void 0 ? {} : { detail: change.detail }
400
449
  });
401
450
  for (const [status, was] of Object.entries(gone.responses)) {
402
451
  if (!(status in arrived.responses)) continue;
@@ -404,7 +453,8 @@ const diffSnapshots = (before, after, options = {}) => {
404
453
  for (const change of diffSchemas(was ?? void 0, now ?? void 0, "response", status)) changes.push({
405
454
  level: change.breaking ? "breaking" : "changed",
406
455
  key,
407
- summary: `${httpLabel(arrived, key)} ${change.summary}`
456
+ summary: `${httpLabel(arrived, key)} ${change.summary}`,
457
+ ...change.detail === void 0 ? {} : { detail: change.detail }
408
458
  });
409
459
  }
410
460
  if (gone.hidden !== true && arrived.hidden === true) changes.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizunajs/cli",
3
- "version": "2.0.0-beta.33",
3
+ "version": "2.0.0-beta.35",
4
4
  "description": "Command line tooling for Kizuna.js",
5
5
  "keywords": [
6
6
  "kizunajs",
@@ -61,13 +61,13 @@
61
61
  "yaml": "^2.9.1"
62
62
  },
63
63
  "peerDependencies": {
64
- "kizunajs": "2.0.0-beta.33",
64
+ "kizunajs": "2.0.0-beta.35",
65
65
  "zod": "^4.0.0"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/node": "^24.19.2",
69
69
  "@types/react": "^19.3.0",
70
- "kizunajs": "2.0.0-beta.33",
70
+ "kizunajs": "2.0.0-beta.35",
71
71
  "tsdown": "^0.21.10",
72
72
  "zod": "^4.6.7"
73
73
  },