@kizunajs/cli 2.0.0-beta.1 → 2.0.0-beta.11
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 +33 -13
- package/dist/cli.mjs +33 -13
- package/dist/index.cjs +13 -12
- package/dist/index.d.cts +95 -37
- package/dist/index.d.mts +95 -37
- package/dist/index.mjs +13 -12
- package/dist/{route-map-D7cBgYmT.mjs → route-map-B2vDHecG.mjs} +285 -170
- package/dist/{route-map-DW2UUkD_.cjs → route-map-Sk1Wybox.cjs} +310 -171
- package/package.json +6 -4
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,31 @@ 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, its fields, and the
|
|
80
|
+
* values it accepts when it is closed.
|
|
81
|
+
*/
|
|
82
|
+
type SchemaNode = {
|
|
83
|
+
kind: 'object';
|
|
84
|
+
fields: Record<string, {
|
|
85
|
+
optional: boolean;
|
|
86
|
+
schema: SchemaNode;
|
|
87
|
+
}>;
|
|
88
|
+
refinements?: number;
|
|
89
|
+
} | {
|
|
90
|
+
kind: 'array';
|
|
91
|
+
element: SchemaNode;
|
|
92
|
+
refinements?: number;
|
|
93
|
+
} | {
|
|
94
|
+
kind: 'enum';
|
|
95
|
+
values: string[];
|
|
96
|
+
refinements?: number;
|
|
97
|
+
} | {
|
|
98
|
+
kind: string;
|
|
99
|
+
refinements?: number;
|
|
100
|
+
};
|
|
101
|
+
//#endregion
|
|
72
102
|
//#region src/diff-apis.d.ts
|
|
73
103
|
/**
|
|
74
104
|
* How much a change asks of the people already calling an API.
|
|
@@ -86,13 +116,38 @@ interface Change {
|
|
|
86
116
|
*/
|
|
87
117
|
detail?: string;
|
|
88
118
|
}
|
|
119
|
+
interface DiffOptions {
|
|
120
|
+
/**
|
|
121
|
+
* Report a job key that is gone. A job answers `POST /jobs/run` by its
|
|
122
|
+
* dotted key, so this matters once something outside your own code
|
|
123
|
+
* dispatches them.
|
|
124
|
+
*
|
|
125
|
+
* @default false
|
|
126
|
+
*/
|
|
127
|
+
jobs?: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Report an MCP tool a model can no longer call.
|
|
130
|
+
*
|
|
131
|
+
* @default false
|
|
132
|
+
*/
|
|
133
|
+
tools?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Treat a renamed dotted key, such as `users.getUser` becoming
|
|
136
|
+
* `users.fetchUser`, as breaking. The key names the method on a generated
|
|
137
|
+
* client, so a rename breaks anyone building an SDK on one and leaves the
|
|
138
|
+
* HTTP surface untouched.
|
|
139
|
+
*
|
|
140
|
+
* @default false
|
|
141
|
+
*/
|
|
142
|
+
dottedKeys?: boolean;
|
|
143
|
+
}
|
|
89
144
|
/**
|
|
90
|
-
* What changed between two apis,
|
|
145
|
+
* What changed between two apis, for a caller holding both in memory.
|
|
91
146
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
147
|
+
* `kizuna diff` reads snapshots instead, so it never has to load the other
|
|
148
|
+
* side's code.
|
|
94
149
|
*/
|
|
95
|
-
declare const diffApis: (before: ApiDefinition, after: ApiDefinition) => Change[];
|
|
150
|
+
declare const diffApis: (before: ApiDefinition, after: ApiDefinition, options?: DiffOptions) => Change[];
|
|
96
151
|
/**
|
|
97
152
|
* One block per change, ready to print: the level, the summary, and the
|
|
98
153
|
* detail indented beneath it.
|
|
@@ -105,18 +160,16 @@ declare const hasBreakingChange: (changes: Change[]) => boolean;
|
|
|
105
160
|
//#endregion
|
|
106
161
|
//#region src/generate-clients.d.ts
|
|
107
162
|
/**
|
|
108
|
-
* A
|
|
163
|
+
* A file that was written, and whether it had to be.
|
|
109
164
|
*/
|
|
110
|
-
interface
|
|
111
|
-
kind: string;
|
|
165
|
+
interface WrittenFile {
|
|
112
166
|
output: string;
|
|
113
167
|
changed: boolean;
|
|
114
168
|
}
|
|
115
169
|
/**
|
|
116
|
-
* A generated
|
|
170
|
+
* A generated file that does not match its api.
|
|
117
171
|
*/
|
|
118
|
-
interface
|
|
119
|
-
kind: string;
|
|
172
|
+
interface StaleFile {
|
|
120
173
|
output: string;
|
|
121
174
|
/**
|
|
122
175
|
* `missing` when nothing is there, `outdated` when what is there is old.
|
|
@@ -124,22 +177,24 @@ interface StaleClient {
|
|
|
124
177
|
reason: 'missing' | 'outdated';
|
|
125
178
|
}
|
|
126
179
|
/**
|
|
127
|
-
* Writes every
|
|
128
|
-
* matches so watchers and build tools see no
|
|
180
|
+
* Writes every generated file, the clients and what plugins generate, leaving
|
|
181
|
+
* a file alone when it already matches so watchers and build tools see no
|
|
182
|
+
* change.
|
|
129
183
|
*/
|
|
130
|
-
declare const
|
|
184
|
+
declare const writeFiles: (contract: ApiDefinition, files: readonly GeneratedFile[]) => WrittenFile[];
|
|
131
185
|
/**
|
|
132
|
-
* Every
|
|
186
|
+
* Every generated file that no longer matches its api, without writing
|
|
187
|
+
* anything.
|
|
133
188
|
*
|
|
134
189
|
* This is what a pipeline runs: a generated client that has fallen behind is a
|
|
135
190
|
* compile error waiting to happen in whatever imports it.
|
|
136
191
|
*/
|
|
137
|
-
declare const
|
|
192
|
+
declare const checkFiles: (contract: ApiDefinition, files: readonly GeneratedFile[]) => StaleFile[];
|
|
138
193
|
/**
|
|
139
194
|
* What a pipeline prints when a check fails, naming the command that fixes it
|
|
140
195
|
* rather than printing a diff nobody reads.
|
|
141
196
|
*/
|
|
142
|
-
declare const formatStale: (stale: readonly
|
|
197
|
+
declare const formatStale: (stale: readonly StaleFile[], command?: string) => string;
|
|
143
198
|
//#endregion
|
|
144
199
|
//#region src/generate-types.d.ts
|
|
145
200
|
declare class ConfigSyntaxError extends Error {}
|
|
@@ -150,8 +205,11 @@ declare class ConfigSyntaxError extends Error {}
|
|
|
150
205
|
* Read from the config's syntax rather than by running it: the generated file
|
|
151
206
|
* imports the same names the config did, and a config that loads is not a
|
|
152
207
|
* prerequisite for typing the routes it serves.
|
|
208
|
+
*
|
|
209
|
+
* `outputPath` is what the imports are written relative to. Left out, they stay
|
|
210
|
+
* relative to the config.
|
|
153
211
|
*/
|
|
154
|
-
declare const generateConfigTypes: (configSource: string, fileName?: string) => string;
|
|
212
|
+
declare const generateConfigTypes: (configSource: string, fileName?: string, outputPath?: string) => string;
|
|
155
213
|
//#endregion
|
|
156
214
|
//#region src/diff-schemas.d.ts
|
|
157
215
|
/**
|
|
@@ -173,29 +231,25 @@ interface SchemaChange {
|
|
|
173
231
|
* What changed between two versions of one schema, and whether it breaks the
|
|
174
232
|
* people already calling the route.
|
|
175
233
|
*/
|
|
176
|
-
declare const diffSchemas: (before:
|
|
234
|
+
declare const diffSchemas: (before: SchemaNode | undefined, after: SchemaNode | undefined, direction: Direction, path?: string) => SchemaChange[];
|
|
177
235
|
//#endregion
|
|
178
236
|
//#region src/diff-against.d.ts
|
|
179
|
-
interface DiffAgainstOptions {
|
|
237
|
+
interface DiffAgainstOptions extends DiffOptions {
|
|
180
238
|
/**
|
|
181
|
-
*
|
|
239
|
+
* Where a relative path is resolved from.
|
|
182
240
|
*
|
|
183
241
|
* @default process.cwd()
|
|
184
242
|
*/
|
|
185
243
|
cwd?: string;
|
|
186
244
|
}
|
|
187
245
|
/**
|
|
188
|
-
* Compares
|
|
189
|
-
*
|
|
190
|
-
* The ref is checked out into a worktree inside the repository, which costs a
|
|
191
|
-
* few files rather than a clone. Nothing is installed there: module resolution
|
|
192
|
-
* walks up to the repository's own `node_modules`, so the base tree needs only
|
|
193
|
-
* its source.
|
|
246
|
+
* Compares a snapshot against the same file at a git ref.
|
|
194
247
|
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
248
|
+
* The ref is read with `git show`, so nothing is checked out, installed or
|
|
249
|
+
* executed for the other side. A snapshot written a year ago compares fine
|
|
250
|
+
* against one written today.
|
|
197
251
|
*/
|
|
198
|
-
declare const diffAgainst: (ref: string,
|
|
252
|
+
declare const diffAgainst: (ref: string, snapshotPath: string, options?: DiffAgainstOptions) => Change[];
|
|
199
253
|
//#endregion
|
|
200
254
|
//#region src/route-map.d.ts
|
|
201
255
|
/**
|
|
@@ -210,14 +264,18 @@ interface RouteEntry {
|
|
|
210
264
|
tool?: string;
|
|
211
265
|
deprecated?: string;
|
|
212
266
|
sunset?: string;
|
|
267
|
+
/**
|
|
268
|
+
* `true` when the route is `hidden`: served, but in no generated client.
|
|
269
|
+
*/
|
|
270
|
+
hidden?: true;
|
|
213
271
|
}
|
|
214
272
|
/**
|
|
215
273
|
* Every route an api serves, in the order it declares them.
|
|
216
274
|
*/
|
|
217
|
-
declare const routeMap: (
|
|
275
|
+
declare const routeMap: (api: ApiDefinition, _options?: Record<string, never>) => RouteEntry[];
|
|
218
276
|
/**
|
|
219
277
|
* The route map as aligned columns, one route per line.
|
|
220
278
|
*/
|
|
221
279
|
declare const formatRoutes: (entries: readonly RouteEntry[]) => string;
|
|
222
280
|
//#endregion
|
|
223
|
-
export { type Change, type ChangeLevel, ConfigSyntaxError, type DiffAgainstOptions, type Direction, type LoadedApi, type Notice, type RouteEntry, type SchemaChange, type
|
|
281
|
+
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-B2vDHecG.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 };
|