@kizunajs/cli 2.0.0-beta.3 → 2.0.0-beta.30
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 +75 -10
- package/dist/cli.mjs +75 -10
- package/dist/index.cjs +13 -12
- package/dist/index.d.cts +99 -37
- package/dist/index.d.mts +99 -37
- package/dist/index.mjs +13 -12
- package/dist/{route-map-BUq6Iw3_.cjs → route-map-BHe__KDP.cjs} +329 -171
- package/dist/{route-map-BZVDVH7m.mjs → route-map-C0K0orUw.mjs} +304 -170
- package/package.json +10 -9
package/dist/index.d.mts
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 {}
|
|
@@ -176,29 +235,25 @@ interface SchemaChange {
|
|
|
176
235
|
* What changed between two versions of one schema, and whether it breaks the
|
|
177
236
|
* people already calling the route.
|
|
178
237
|
*/
|
|
179
|
-
declare const diffSchemas: (before:
|
|
238
|
+
declare const diffSchemas: (before: SchemaNode | undefined, after: SchemaNode | undefined, direction: Direction, path?: string) => SchemaChange[];
|
|
180
239
|
//#endregion
|
|
181
240
|
//#region src/diff-against.d.ts
|
|
182
|
-
interface DiffAgainstOptions {
|
|
241
|
+
interface DiffAgainstOptions extends DiffOptions {
|
|
183
242
|
/**
|
|
184
|
-
*
|
|
243
|
+
* Where a relative path is resolved from.
|
|
185
244
|
*
|
|
186
245
|
* @default process.cwd()
|
|
187
246
|
*/
|
|
188
247
|
cwd?: string;
|
|
189
248
|
}
|
|
190
249
|
/**
|
|
191
|
-
* Compares
|
|
250
|
+
* Compares a snapshot against the same file at a git ref.
|
|
192
251
|
*
|
|
193
|
-
* The ref is
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* its source.
|
|
197
|
-
*
|
|
198
|
-
* @example
|
|
199
|
-
* 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.
|
|
200
255
|
*/
|
|
201
|
-
declare const diffAgainst: (ref: string,
|
|
256
|
+
declare const diffAgainst: (ref: string, snapshotPath: string, options?: DiffAgainstOptions) => Change[];
|
|
202
257
|
//#endregion
|
|
203
258
|
//#region src/route-map.d.ts
|
|
204
259
|
/**
|
|
@@ -209,18 +264,25 @@ interface RouteEntry {
|
|
|
209
264
|
method: string;
|
|
210
265
|
path: string;
|
|
211
266
|
auth: string;
|
|
212
|
-
|
|
267
|
+
/**
|
|
268
|
+
* The route's groups, as dotted paths.
|
|
269
|
+
*/
|
|
270
|
+
groups: string[];
|
|
213
271
|
tool?: string;
|
|
214
272
|
deprecated?: string;
|
|
215
273
|
sunset?: string;
|
|
274
|
+
/**
|
|
275
|
+
* `true` when the route is `hidden`: served, but in no generated client.
|
|
276
|
+
*/
|
|
277
|
+
hidden?: true;
|
|
216
278
|
}
|
|
217
279
|
/**
|
|
218
280
|
* Every route an api serves, in the order it declares them.
|
|
219
281
|
*/
|
|
220
|
-
declare const routeMap: (
|
|
282
|
+
declare const routeMap: (api: ApiDefinition, _options?: Record<string, never>) => RouteEntry[];
|
|
221
283
|
/**
|
|
222
284
|
* The route map as aligned columns, one route per line.
|
|
223
285
|
*/
|
|
224
286
|
declare const formatRoutes: (entries: readonly RouteEntry[]) => string;
|
|
225
287
|
//#endregion
|
|
226
|
-
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
+
import { walkApi } from "kizunajs/generator";
|
|
3
3
|
//#region src/api-notices.ts
|
|
4
4
|
const readSunset = (route) => {
|
|
5
5
|
const declared = route.sunset;
|
|
@@ -7,14 +7,7 @@ const readSunset = (route) => {
|
|
|
7
7
|
return typeof declared === "string" ? declared : declared.date;
|
|
8
8
|
};
|
|
9
9
|
const daysBetween = (from, to) => Math.ceil((to.getTime() - from.getTime()) / 864e5);
|
|
10
|
-
|
|
11
|
-
* Every route that is deprecated or has a sunset date, soonest first, with
|
|
12
|
-
* undated deprecations last.
|
|
13
|
-
*
|
|
14
|
-
* Reads the same `deprecated` field the generated clients carry in an
|
|
15
|
-
* editor, so a watcher and a hover agree.
|
|
16
|
-
*/
|
|
17
|
-
const apiNotices = createGenerator((options) => {
|
|
10
|
+
const noticesWalk = (options) => {
|
|
18
11
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
19
12
|
const notices = [];
|
|
20
13
|
return {
|
|
@@ -41,7 +34,15 @@ const apiNotices = createGenerator((options) => {
|
|
|
41
34
|
});
|
|
42
35
|
}
|
|
43
36
|
};
|
|
44
|
-
}
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Every route that is deprecated or has a sunset date, soonest first, with
|
|
40
|
+
* undated deprecations last.
|
|
41
|
+
*
|
|
42
|
+
* Reads the same `deprecated` field the generated clients carry in an
|
|
43
|
+
* editor, so a watcher and a hover agree.
|
|
44
|
+
*/
|
|
45
|
+
const apiNotices = (api, options = {}) => walkApi(api, noticesWalk(options));
|
|
45
46
|
/**
|
|
46
47
|
* One line per notice, for a watcher to print.
|
|
47
48
|
*
|
|
@@ -61,4 +62,4 @@ const formatNotice = (notice) => {
|
|
|
61
62
|
return `${notice.method} ${notice.path} ${notice.routeKey} ${parts.join(", ")}${suffix}`;
|
|
62
63
|
};
|
|
63
64
|
//#endregion
|
|
64
|
-
export { ConfigSyntaxError, apiNotices,
|
|
65
|
+
export { ConfigSyntaxError, apiNotices, checkFiles, diffAgainst, diffApis, diffSchemas, formatChange, formatNotice, formatRoutes, formatStale, generateConfigTypes, hasBreakingChange, loadConfig, routeMap, writeFiles };
|