@kizunajs/cli 2.0.0-beta.31 → 2.0.0-beta.33
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 +2 -2
- package/dist/cli.mjs +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +9 -3
- package/dist/index.d.mts +9 -3
- package/dist/index.mjs +1 -1
- package/dist/{route-map-BHe__KDP.cjs → route-map-CGZ5VfE9.cjs} +32 -2
- package/dist/{route-map-C0K0orUw.mjs → route-map-pLtv53AW.mjs} +32 -2
- package/package.json +3 -3
package/dist/cli.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_route_map = require("./route-map-
|
|
2
|
+
const require_route_map = require("./route-map-CGZ5VfE9.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");
|
|
@@ -115,7 +115,7 @@ const runGenerate = async (values) => {
|
|
|
115
115
|
const typesPath = (0, node_path.resolve)((0, node_path.dirname)(configPath), typesOutput);
|
|
116
116
|
let types;
|
|
117
117
|
try {
|
|
118
|
-
types = require_route_map.generateConfigTypes((0, node_fs.readFileSync)(configPath, "utf8"), configPath, typesPath);
|
|
118
|
+
types = require_route_map.generateConfigTypes((0, node_fs.readFileSync)(configPath, "utf8"), configPath, typesPath, config.typesExtensions);
|
|
119
119
|
} catch (error) {
|
|
120
120
|
if (error instanceof require_route_map.ConfigSyntaxError) die(`${displayPath(configPath)}: ${error.message}`);
|
|
121
121
|
throw error;
|
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-
|
|
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";
|
|
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";
|
|
@@ -115,7 +115,7 @@ const runGenerate = async (values) => {
|
|
|
115
115
|
const typesPath = resolve(dirname(configPath), typesOutput);
|
|
116
116
|
let types;
|
|
117
117
|
try {
|
|
118
|
-
types = generateConfigTypes(readFileSync(configPath, "utf8"), configPath, typesPath);
|
|
118
|
+
types = generateConfigTypes(readFileSync(configPath, "utf8"), configPath, typesPath, config.typesExtensions);
|
|
119
119
|
} catch (error) {
|
|
120
120
|
if (error instanceof ConfigSyntaxError) die(`${displayPath(configPath)}: ${error.message}`);
|
|
121
121
|
throw error;
|
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-
|
|
2
|
+
const require_route_map = require("./route-map-CGZ5VfE9.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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiDefinition, DiffSettings, GeneratedFile } from "kizunajs";
|
|
1
|
+
import { ApiDefinition, ConfigExtension, DiffSettings, GeneratedFile } from "kizunajs";
|
|
2
2
|
//#region src/load-config.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* One api a config declares, with everything generated from it. A config that
|
|
@@ -16,6 +16,10 @@ interface LoadedApi {
|
|
|
16
16
|
* Where `kizuna generate` writes the `Config`, when the config says.
|
|
17
17
|
*/
|
|
18
18
|
typesOutput: string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* What `typescript.extend` adds to the `Config`.
|
|
21
|
+
*/
|
|
22
|
+
typesExtensions: readonly ConfigExtension[];
|
|
19
23
|
/**
|
|
20
24
|
* What else `kizuna diff` treats as breaking.
|
|
21
25
|
*/
|
|
@@ -208,12 +212,14 @@ declare class ConfigSyntaxError extends Error {}
|
|
|
208
212
|
*
|
|
209
213
|
* Read from the config's syntax rather than by running it: the generated file
|
|
210
214
|
* imports the same names the config did, and a config that loads is not a
|
|
211
|
-
* prerequisite for typing the routes it serves.
|
|
215
|
+
* prerequisite for typing the routes it serves. What
|
|
216
|
+
* `typescript.extend` adds exists only once the config has run, so the caller passes
|
|
217
|
+
* it in.
|
|
212
218
|
*
|
|
213
219
|
* `outputPath` is what the imports are written relative to. Left out, they stay
|
|
214
220
|
* relative to the config.
|
|
215
221
|
*/
|
|
216
|
-
declare const generateConfigTypes: (configSource: string, fileName?: string, outputPath?: string) => string;
|
|
222
|
+
declare const generateConfigTypes: (configSource: string, fileName?: string, outputPath?: string, extensions?: readonly ConfigExtension[]) => string;
|
|
217
223
|
//#endregion
|
|
218
224
|
//#region src/diff-schemas.d.ts
|
|
219
225
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiDefinition, DiffSettings, GeneratedFile } from "kizunajs";
|
|
1
|
+
import { ApiDefinition, ConfigExtension, DiffSettings, GeneratedFile } from "kizunajs";
|
|
2
2
|
//#region src/load-config.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* One api a config declares, with everything generated from it. A config that
|
|
@@ -16,6 +16,10 @@ interface LoadedApi {
|
|
|
16
16
|
* Where `kizuna generate` writes the `Config`, when the config says.
|
|
17
17
|
*/
|
|
18
18
|
typesOutput: string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* What `typescript.extend` adds to the `Config`.
|
|
21
|
+
*/
|
|
22
|
+
typesExtensions: readonly ConfigExtension[];
|
|
19
23
|
/**
|
|
20
24
|
* What else `kizuna diff` treats as breaking.
|
|
21
25
|
*/
|
|
@@ -208,12 +212,14 @@ declare class ConfigSyntaxError extends Error {}
|
|
|
208
212
|
*
|
|
209
213
|
* Read from the config's syntax rather than by running it: the generated file
|
|
210
214
|
* imports the same names the config did, and a config that loads is not a
|
|
211
|
-
* prerequisite for typing the routes it serves.
|
|
215
|
+
* prerequisite for typing the routes it serves. What
|
|
216
|
+
* `typescript.extend` adds exists only once the config has run, so the caller passes
|
|
217
|
+
* it in.
|
|
212
218
|
*
|
|
213
219
|
* `outputPath` is what the imports are written relative to. Left out, they stay
|
|
214
220
|
* relative to the config.
|
|
215
221
|
*/
|
|
216
|
-
declare const generateConfigTypes: (configSource: string, fileName?: string, outputPath?: string) => string;
|
|
222
|
+
declare const generateConfigTypes: (configSource: string, fileName?: string, outputPath?: string, extensions?: readonly ConfigExtension[]) => string;
|
|
217
223
|
//#endregion
|
|
218
224
|
//#region src/diff-schemas.d.ts
|
|
219
225
|
/**
|
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-
|
|
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";
|
|
2
2
|
import { walkApi } from "kizunajs/generator";
|
|
3
3
|
//#region src/api-notices.ts
|
|
4
4
|
const readSunset = (route) => {
|
|
@@ -50,6 +50,7 @@ const loadConfig = async (configPath) => {
|
|
|
50
50
|
clients: entry.clients ?? [],
|
|
51
51
|
generators: entry.generators ?? [],
|
|
52
52
|
typesOutput: entry.typescript?.outputFile,
|
|
53
|
+
typesExtensions: entry.typescript?.extend ?? [],
|
|
53
54
|
diff: entry.diff ?? {}
|
|
54
55
|
}));
|
|
55
56
|
};
|
|
@@ -702,6 +703,32 @@ const authLines = (expression, used) => {
|
|
|
702
703
|
}
|
|
703
704
|
return lines;
|
|
704
705
|
};
|
|
706
|
+
/**
|
|
707
|
+
* A string as Prettier writes it: single quotes, unless the string holds more
|
|
708
|
+
* of them than double quotes.
|
|
709
|
+
*/
|
|
710
|
+
const stringLiteral = (value) => {
|
|
711
|
+
const quote = value.split("'").length > value.split("\"").length ? "\"" : "'";
|
|
712
|
+
return `${quote}${value.replaceAll("\\", "\\\\").replaceAll(quote, `\\${quote}`)}${quote}`;
|
|
713
|
+
};
|
|
714
|
+
const propertyName = (name) => /^[A-Za-z_$][\w$]*$/.test(name) ? name : stringLiteral(name);
|
|
715
|
+
/**
|
|
716
|
+
* One entry under `typescript.extend`. A list of strings becomes a
|
|
717
|
+
* union, wrapped one member per line when it would run past
|
|
718
|
+
* {@link PRINT_WIDTH}, the way Prettier does.
|
|
719
|
+
*/
|
|
720
|
+
const typeOfExtension = (values, indent) => {
|
|
721
|
+
const lines = Object.entries(values).map(([key, value]) => {
|
|
722
|
+
const prefix = `${indent} ${propertyName(key)}:`;
|
|
723
|
+
if (!Array.isArray(value)) return `${prefix} ${typeOfExtension(value, `${indent} `)};`;
|
|
724
|
+
const members = [...new Set(value)].map(stringLiteral);
|
|
725
|
+
if (members.length === 0) return `${prefix} never;`;
|
|
726
|
+
const inline = `${prefix} ${members.join(" | ")};`;
|
|
727
|
+
if (members.length === 1 || inline.length <= PRINT_WIDTH) return inline;
|
|
728
|
+
return `${prefix}\n${members.map((member) => `${indent} | ${member}`).join("\n")};`;
|
|
729
|
+
});
|
|
730
|
+
return lines.length === 0 ? "{}" : `{\n${lines.join("\n")}\n${indent}}`;
|
|
731
|
+
};
|
|
705
732
|
const HEADER = `/**
|
|
706
733
|
* This file was automatically generated by kizuna.
|
|
707
734
|
* DO NOT MODIFY IT BY HAND. Instead, modify your source kizuna config,
|
|
@@ -744,12 +771,14 @@ const renderImports = (imports, used, rebase) => {
|
|
|
744
771
|
*
|
|
745
772
|
* Read from the config's syntax rather than by running it: the generated file
|
|
746
773
|
* imports the same names the config did, and a config that loads is not a
|
|
747
|
-
* prerequisite for typing the routes it serves.
|
|
774
|
+
* prerequisite for typing the routes it serves. What
|
|
775
|
+
* `typescript.extend` adds exists only once the config has run, so the caller passes
|
|
776
|
+
* it in.
|
|
748
777
|
*
|
|
749
778
|
* `outputPath` is what the imports are written relative to. Left out, they stay
|
|
750
779
|
* relative to the config.
|
|
751
780
|
*/
|
|
752
|
-
const generateConfigTypes = (configSource, fileName = "kizuna.config.ts", outputPath) => {
|
|
781
|
+
const generateConfigTypes = (configSource, fileName = "kizuna.config.ts", outputPath, extensions = []) => {
|
|
753
782
|
const source = typescript.default.createSourceFile(fileName, configSource, typescript.default.ScriptTarget.Latest, true);
|
|
754
783
|
const imports = collectImports(source);
|
|
755
784
|
const configObject = findConfigObject(source);
|
|
@@ -776,6 +805,7 @@ const generateConfigTypes = (configSource, fileName = "kizuna.config.ts", output
|
|
|
776
805
|
} else if (key === "plugins") lines.push(` ${key}: ${typeOfPluginList(value, used, ` ${key}: `)};`);
|
|
777
806
|
else lines.push(` ${key}: ${typeOfValue(value, used, key)};`);
|
|
778
807
|
}
|
|
808
|
+
for (const extension of extensions) for (const [name, values] of Object.entries(extension)) lines.push(` ${propertyName(name)}: ${typeOfExtension(values, " ")};`);
|
|
779
809
|
const configDir = (0, node_path.dirname)((0, node_path.resolve)(fileName));
|
|
780
810
|
const outputDir = outputPath === void 0 ? configDir : (0, node_path.dirname)((0, node_path.resolve)(outputPath));
|
|
781
811
|
const importBlock = renderImports(imports, used, (specifier) => outputDir === configDir ? specifier : rebaseSpecifier(specifier, configDir, outputDir));
|
|
@@ -27,6 +27,7 @@ const loadConfig = async (configPath) => {
|
|
|
27
27
|
clients: entry.clients ?? [],
|
|
28
28
|
generators: entry.generators ?? [],
|
|
29
29
|
typesOutput: entry.typescript?.outputFile,
|
|
30
|
+
typesExtensions: entry.typescript?.extend ?? [],
|
|
30
31
|
diff: entry.diff ?? {}
|
|
31
32
|
}));
|
|
32
33
|
};
|
|
@@ -679,6 +680,32 @@ const authLines = (expression, used) => {
|
|
|
679
680
|
}
|
|
680
681
|
return lines;
|
|
681
682
|
};
|
|
683
|
+
/**
|
|
684
|
+
* A string as Prettier writes it: single quotes, unless the string holds more
|
|
685
|
+
* of them than double quotes.
|
|
686
|
+
*/
|
|
687
|
+
const stringLiteral = (value) => {
|
|
688
|
+
const quote = value.split("'").length > value.split("\"").length ? "\"" : "'";
|
|
689
|
+
return `${quote}${value.replaceAll("\\", "\\\\").replaceAll(quote, `\\${quote}`)}${quote}`;
|
|
690
|
+
};
|
|
691
|
+
const propertyName = (name) => /^[A-Za-z_$][\w$]*$/.test(name) ? name : stringLiteral(name);
|
|
692
|
+
/**
|
|
693
|
+
* One entry under `typescript.extend`. A list of strings becomes a
|
|
694
|
+
* union, wrapped one member per line when it would run past
|
|
695
|
+
* {@link PRINT_WIDTH}, the way Prettier does.
|
|
696
|
+
*/
|
|
697
|
+
const typeOfExtension = (values, indent) => {
|
|
698
|
+
const lines = Object.entries(values).map(([key, value]) => {
|
|
699
|
+
const prefix = `${indent} ${propertyName(key)}:`;
|
|
700
|
+
if (!Array.isArray(value)) return `${prefix} ${typeOfExtension(value, `${indent} `)};`;
|
|
701
|
+
const members = [...new Set(value)].map(stringLiteral);
|
|
702
|
+
if (members.length === 0) return `${prefix} never;`;
|
|
703
|
+
const inline = `${prefix} ${members.join(" | ")};`;
|
|
704
|
+
if (members.length === 1 || inline.length <= PRINT_WIDTH) return inline;
|
|
705
|
+
return `${prefix}\n${members.map((member) => `${indent} | ${member}`).join("\n")};`;
|
|
706
|
+
});
|
|
707
|
+
return lines.length === 0 ? "{}" : `{\n${lines.join("\n")}\n${indent}}`;
|
|
708
|
+
};
|
|
682
709
|
const HEADER = `/**
|
|
683
710
|
* This file was automatically generated by kizuna.
|
|
684
711
|
* DO NOT MODIFY IT BY HAND. Instead, modify your source kizuna config,
|
|
@@ -721,12 +748,14 @@ const renderImports = (imports, used, rebase) => {
|
|
|
721
748
|
*
|
|
722
749
|
* Read from the config's syntax rather than by running it: the generated file
|
|
723
750
|
* imports the same names the config did, and a config that loads is not a
|
|
724
|
-
* prerequisite for typing the routes it serves.
|
|
751
|
+
* prerequisite for typing the routes it serves. What
|
|
752
|
+
* `typescript.extend` adds exists only once the config has run, so the caller passes
|
|
753
|
+
* it in.
|
|
725
754
|
*
|
|
726
755
|
* `outputPath` is what the imports are written relative to. Left out, they stay
|
|
727
756
|
* relative to the config.
|
|
728
757
|
*/
|
|
729
|
-
const generateConfigTypes = (configSource, fileName = "kizuna.config.ts", outputPath) => {
|
|
758
|
+
const generateConfigTypes = (configSource, fileName = "kizuna.config.ts", outputPath, extensions = []) => {
|
|
730
759
|
const source = ts.createSourceFile(fileName, configSource, ts.ScriptTarget.Latest, true);
|
|
731
760
|
const imports = collectImports(source);
|
|
732
761
|
const configObject = findConfigObject(source);
|
|
@@ -753,6 +782,7 @@ const generateConfigTypes = (configSource, fileName = "kizuna.config.ts", output
|
|
|
753
782
|
} else if (key === "plugins") lines.push(` ${key}: ${typeOfPluginList(value, used, ` ${key}: `)};`);
|
|
754
783
|
else lines.push(` ${key}: ${typeOfValue(value, used, key)};`);
|
|
755
784
|
}
|
|
785
|
+
for (const extension of extensions) for (const [name, values] of Object.entries(extension)) lines.push(` ${propertyName(name)}: ${typeOfExtension(values, " ")};`);
|
|
756
786
|
const configDir = dirname(resolve(fileName));
|
|
757
787
|
const outputDir = outputPath === void 0 ? configDir : dirname(resolve(outputPath));
|
|
758
788
|
const importBlock = renderImports(imports, used, (specifier) => outputDir === configDir ? specifier : rebaseSpecifier(specifier, configDir, outputDir));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kizunajs/cli",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.33",
|
|
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.
|
|
64
|
+
"kizunajs": "2.0.0-beta.33",
|
|
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.
|
|
70
|
+
"kizunajs": "2.0.0-beta.33",
|
|
71
71
|
"tsdown": "^0.21.10",
|
|
72
72
|
"zod": "^4.6.7"
|
|
73
73
|
},
|