@kizunajs/cli 2.0.0-beta.0
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/LICENSE.MD +9 -0
- package/README.md +27 -0
- package/dist/cli.cjs +123 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +124 -0
- package/dist/index.cjs +79 -0
- package/dist/index.d.cts +223 -0
- package/dist/index.d.mts +223 -0
- package/dist/index.mjs +64 -0
- package/dist/route-map-D7cBgYmT.mjs +747 -0
- package/dist/route-map-DW2UUkD_.cjs +853 -0
- package/package.json +76 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import * as _$kizunajs from "kizunajs";
|
|
2
|
+
import { ApiDefinition, ClientTarget } from "kizunajs";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/load-config.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* One api a config declares, with everything generated from it. A config that
|
|
8
|
+
* declares a single api reports it under `default`.
|
|
9
|
+
*/
|
|
10
|
+
interface LoadedApi {
|
|
11
|
+
name: string;
|
|
12
|
+
api: ApiDefinition;
|
|
13
|
+
clients: readonly ClientTarget[];
|
|
14
|
+
/**
|
|
15
|
+
* Where `kizuna generate` writes the `Config`, when the config says.
|
|
16
|
+
*/
|
|
17
|
+
typesOutput: string | undefined;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Imports a config module with jiti, so a `.ts` config works without a build
|
|
21
|
+
* step, and returns every api it declares along with the clients and the types
|
|
22
|
+
* output each one asks for.
|
|
23
|
+
*
|
|
24
|
+
* Returns an empty list when the module default-exports nothing that looks like
|
|
25
|
+
* a config.
|
|
26
|
+
*/
|
|
27
|
+
declare const loadConfig: (configPath: string) => Promise<LoadedApi[]>;
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/api-notices.d.ts
|
|
30
|
+
/**
|
|
31
|
+
* A route that announces its own retirement.
|
|
32
|
+
*/
|
|
33
|
+
interface Notice {
|
|
34
|
+
/**
|
|
35
|
+
* `users.getUser`.
|
|
36
|
+
*/
|
|
37
|
+
routeKey: string;
|
|
38
|
+
method: string;
|
|
39
|
+
path: string;
|
|
40
|
+
deprecated: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* What the route's `deprecated` says to use instead.
|
|
43
|
+
*/
|
|
44
|
+
message?: string;
|
|
45
|
+
/**
|
|
46
|
+
* When it will be removed, ISO 8601, from the route's `sunset`.
|
|
47
|
+
*/
|
|
48
|
+
sunset?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Whole days until `sunset`, negative once it has passed.
|
|
51
|
+
*/
|
|
52
|
+
daysUntilSunset?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Every route that is deprecated or has a sunset date, soonest first, with
|
|
56
|
+
* undated deprecations last.
|
|
57
|
+
*
|
|
58
|
+
* Reads the same `deprecated` field the generated clients carry in an
|
|
59
|
+
* editor, so a watcher and a hover agree.
|
|
60
|
+
*/
|
|
61
|
+
declare const apiNotices: (contract: _$kizunajs.ApiDefinition, options: {
|
|
62
|
+
now?: Date;
|
|
63
|
+
}) => Notice[];
|
|
64
|
+
/**
|
|
65
|
+
* One line per notice, for a watcher to print.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* DELETE /users/:id users.deleteUser deprecated, sunset in 14 days
|
|
69
|
+
*/
|
|
70
|
+
declare const formatNotice: (notice: Notice) => string;
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/diff-apis.d.ts
|
|
73
|
+
/**
|
|
74
|
+
* How much a change asks of the people already calling an API.
|
|
75
|
+
*/
|
|
76
|
+
type ChangeLevel = 'breaking' | 'changed' | 'added';
|
|
77
|
+
interface Change {
|
|
78
|
+
level: ChangeLevel;
|
|
79
|
+
/**
|
|
80
|
+
* `users.getUser`, or the job or tool key the change is about.
|
|
81
|
+
*/
|
|
82
|
+
key: string;
|
|
83
|
+
summary: string;
|
|
84
|
+
/**
|
|
85
|
+
* What it costs whoever is already calling it.
|
|
86
|
+
*/
|
|
87
|
+
detail?: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* What changed between two apis, worst first.
|
|
91
|
+
*
|
|
92
|
+
* Compares the declarations rather than an OpenAPI document, so it sees route
|
|
93
|
+
* keys, MCP tool names and job keys, none of which a document carries.
|
|
94
|
+
*/
|
|
95
|
+
declare const diffApis: (before: ApiDefinition, after: ApiDefinition) => Change[];
|
|
96
|
+
/**
|
|
97
|
+
* One block per change, ready to print: the level, the summary, and the
|
|
98
|
+
* detail indented beneath it.
|
|
99
|
+
*/
|
|
100
|
+
declare const formatChange: (change: Change) => string;
|
|
101
|
+
/**
|
|
102
|
+
* Whether a diff should fail a pipeline.
|
|
103
|
+
*/
|
|
104
|
+
declare const hasBreakingChange: (changes: Change[]) => boolean;
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/generate-clients.d.ts
|
|
107
|
+
/**
|
|
108
|
+
* A client that was written, and whether it had to be.
|
|
109
|
+
*/
|
|
110
|
+
interface WrittenClient {
|
|
111
|
+
kind: string;
|
|
112
|
+
output: string;
|
|
113
|
+
changed: boolean;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* A generated client that does not match its api.
|
|
117
|
+
*/
|
|
118
|
+
interface StaleClient {
|
|
119
|
+
kind: string;
|
|
120
|
+
output: string;
|
|
121
|
+
/**
|
|
122
|
+
* `missing` when nothing is there, `outdated` when what is there is old.
|
|
123
|
+
*/
|
|
124
|
+
reason: 'missing' | 'outdated';
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Writes every client an api declares, leaving a file alone when it already
|
|
128
|
+
* matches so watchers and build tools see no change.
|
|
129
|
+
*/
|
|
130
|
+
declare const writeClients: (contract: ApiDefinition, clients: readonly ClientTarget[]) => WrittenClient[];
|
|
131
|
+
/**
|
|
132
|
+
* Every client that no longer matches its api, without writing anything.
|
|
133
|
+
*
|
|
134
|
+
* This is what a pipeline runs: a generated client that has fallen behind is a
|
|
135
|
+
* compile error waiting to happen in whatever imports it.
|
|
136
|
+
*/
|
|
137
|
+
declare const checkClients: (contract: ApiDefinition, clients: readonly ClientTarget[]) => StaleClient[];
|
|
138
|
+
/**
|
|
139
|
+
* What a pipeline prints when a check fails, naming the command that fixes it
|
|
140
|
+
* rather than printing a diff nobody reads.
|
|
141
|
+
*/
|
|
142
|
+
declare const formatStale: (stale: readonly StaleClient[], command?: string) => string;
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/generate-types.d.ts
|
|
145
|
+
declare class ConfigSyntaxError extends Error {}
|
|
146
|
+
/**
|
|
147
|
+
* Write the `Config` a `kizuna.config.ts` implies, which is what
|
|
148
|
+
* `new Kizuna<Config>()` is typed by.
|
|
149
|
+
*
|
|
150
|
+
* Read from the config's syntax rather than by running it: the generated file
|
|
151
|
+
* imports the same names the config did, and a config that loads is not a
|
|
152
|
+
* prerequisite for typing the routes it serves.
|
|
153
|
+
*/
|
|
154
|
+
declare const generateConfigTypes: (configSource: string, fileName?: string) => string;
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/diff-schemas.d.ts
|
|
157
|
+
/**
|
|
158
|
+
* Which way a schema travels, which decides what a change costs.
|
|
159
|
+
*
|
|
160
|
+
* A caller sends requests and reads responses, so tightening an input and
|
|
161
|
+
* dropping an output are the two that break them.
|
|
162
|
+
*/
|
|
163
|
+
type Direction = 'request' | 'response';
|
|
164
|
+
interface SchemaChange {
|
|
165
|
+
breaking: boolean;
|
|
166
|
+
/**
|
|
167
|
+
* `body.organisationId`, relative to the schema being compared.
|
|
168
|
+
*/
|
|
169
|
+
path: string;
|
|
170
|
+
summary: string;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* What changed between two versions of one schema, and whether it breaks the
|
|
174
|
+
* people already calling the route.
|
|
175
|
+
*/
|
|
176
|
+
declare const diffSchemas: (before: z.core.$ZodType | undefined, after: z.core.$ZodType | undefined, direction: Direction, path?: string) => SchemaChange[];
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/diff-against.d.ts
|
|
179
|
+
interface DiffAgainstOptions {
|
|
180
|
+
/**
|
|
181
|
+
* Repository the ref lives in.
|
|
182
|
+
*
|
|
183
|
+
* @default process.cwd()
|
|
184
|
+
*/
|
|
185
|
+
cwd?: string;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Compares the config on disk against the same config at a git ref.
|
|
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.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* const changes = await diffAgainst('main', './src/contract.ts');
|
|
197
|
+
*/
|
|
198
|
+
declare const diffAgainst: (ref: string, configPath: string, options?: DiffAgainstOptions) => Promise<Change[]>;
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/route-map.d.ts
|
|
201
|
+
/**
|
|
202
|
+
* One route, flattened to what someone reading a terminal wants to know.
|
|
203
|
+
*/
|
|
204
|
+
interface RouteEntry {
|
|
205
|
+
key: string;
|
|
206
|
+
method: string;
|
|
207
|
+
path: string;
|
|
208
|
+
auth: string;
|
|
209
|
+
tags: string[];
|
|
210
|
+
tool?: string;
|
|
211
|
+
deprecated?: string;
|
|
212
|
+
sunset?: string;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Every route an api serves, in the order it declares them.
|
|
216
|
+
*/
|
|
217
|
+
declare const routeMap: (contract: ApiDefinition, options: Record<string, never>) => RouteEntry[];
|
|
218
|
+
/**
|
|
219
|
+
* The route map as aligned columns, one route per line.
|
|
220
|
+
*/
|
|
221
|
+
declare const formatRoutes: (entries: readonly RouteEntry[]) => string;
|
|
222
|
+
//#endregion
|
|
223
|
+
export { type Change, type ChangeLevel, ConfigSyntaxError, type DiffAgainstOptions, type Direction, type LoadedApi, type Notice, type RouteEntry, type SchemaChange, type StaleClient, type WrittenClient, apiNotices, checkClients, diffAgainst, diffApis, diffSchemas, formatChange, formatNotice, formatRoutes, formatStale, generateConfigTypes, hasBreakingChange, loadConfig, routeMap, writeClients };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { a as generateConfigTypes, c as writeClients, d as hasBreakingChange, f as diffSchemas, i as ConfigSyntaxError, l as diffApis, n as routeMap, o as checkClients, p as loadConfig, r as diffAgainst, s as formatStale, t as formatRoutes, u as formatChange } from "./route-map-D7cBgYmT.mjs";
|
|
2
|
+
import { createGenerator } from "kizunajs/generator";
|
|
3
|
+
//#region src/api-notices.ts
|
|
4
|
+
const readSunset = (route) => {
|
|
5
|
+
const declared = route.sunset;
|
|
6
|
+
if (declared === void 0) return void 0;
|
|
7
|
+
return typeof declared === "string" ? declared : declared.date;
|
|
8
|
+
};
|
|
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) => {
|
|
18
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
19
|
+
const notices = [];
|
|
20
|
+
return {
|
|
21
|
+
processRoute({ routeKey, route, deprecated, deprecationMessage }) {
|
|
22
|
+
const sunset = readSunset(route);
|
|
23
|
+
if (!deprecated && sunset === void 0) return;
|
|
24
|
+
const sunsetDate = sunset === void 0 ? void 0 : new Date(sunset);
|
|
25
|
+
const dated = sunsetDate !== void 0 && !Number.isNaN(sunsetDate.getTime());
|
|
26
|
+
notices.push({
|
|
27
|
+
routeKey,
|
|
28
|
+
method: route.method,
|
|
29
|
+
path: route.path,
|
|
30
|
+
deprecated,
|
|
31
|
+
...deprecationMessage === void 0 ? {} : { message: deprecationMessage },
|
|
32
|
+
...sunset === void 0 ? {} : { sunset },
|
|
33
|
+
...dated ? { daysUntilSunset: daysBetween(now, sunsetDate) } : {}
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
finalize() {
|
|
37
|
+
return notices.sort((left, right) => {
|
|
38
|
+
if (left.daysUntilSunset === void 0) return right.daysUntilSunset === void 0 ? 0 : 1;
|
|
39
|
+
if (right.daysUntilSunset === void 0) return -1;
|
|
40
|
+
return left.daysUntilSunset - right.daysUntilSunset;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* One line per notice, for a watcher to print.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* DELETE /users/:id users.deleteUser deprecated, sunset in 14 days
|
|
50
|
+
*/
|
|
51
|
+
const formatNotice = (notice) => {
|
|
52
|
+
const parts = [];
|
|
53
|
+
if (notice.deprecated) parts.push("deprecated");
|
|
54
|
+
if (notice.daysUntilSunset !== void 0) {
|
|
55
|
+
const days = notice.daysUntilSunset;
|
|
56
|
+
if (days < 0) parts.push(`sunset ${Math.abs(days)} days ago`);
|
|
57
|
+
else if (days === 0) parts.push("sunset today");
|
|
58
|
+
else parts.push(`sunset in ${days} days`);
|
|
59
|
+
} else if (notice.sunset !== void 0) parts.push(`sunset ${notice.sunset}`);
|
|
60
|
+
const suffix = notice.message === void 0 ? "" : `. ${notice.message}`;
|
|
61
|
+
return `${notice.method} ${notice.path} ${notice.routeKey} ${parts.join(", ")}${suffix}`;
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { ConfigSyntaxError, apiNotices, checkClients, diffAgainst, diffApis, diffSchemas, formatChange, formatNotice, formatRoutes, formatStale, generateConfigTypes, hasBreakingChange, loadConfig, routeMap, writeClients };
|