@keq-request/cli 5.0.0-alpha.26 → 5.0.0-alpha.28
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/CHANGELOG.md +19 -0
- package/dist/cli.cjs +132 -86
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +132 -86
- package/dist/cli.js.map +1 -1
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/compiler/tasks/setup/index.d.ts.map +1 -1
- package/dist/compiler/tasks/setup/utils/index.d.ts +0 -1
- package/dist/compiler/tasks/setup/utils/index.d.ts.map +1 -1
- package/dist/compiler/tasks/setup/utils/parse-runtime-config.d.ts +3 -0
- package/dist/compiler/tasks/setup/utils/parse-runtime-config.d.ts.map +1 -0
- package/dist/compiler/types/compiler-context.d.ts +1 -1
- package/dist/compiler/types/compiler-context.d.ts.map +1 -1
- package/dist/compiler/types/compiler-hooks.d.ts +2 -1
- package/dist/compiler/types/compiler-hooks.d.ts.map +1 -1
- package/dist/define-config.d.ts +3 -0
- package/dist/define-config.d.ts.map +1 -0
- package/dist/index.cjs +137 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +136 -91
- package/dist/index.js.map +1 -1
- package/dist/models/module-definition.d.ts +3 -2
- package/dist/models/module-definition.d.ts.map +1 -1
- package/dist/plugins/download-http-file/download-http-file.plugin.d.ts +2 -2
- package/dist/plugins/download-http-file/download-http-file.plugin.d.ts.map +1 -1
- package/dist/plugins/download-local-file/download-local-file.plugin.d.ts.map +1 -1
- package/dist/plugins/shaking/shaking.plugin.d.ts.map +1 -1
- package/dist/plugins.cjs +25 -12
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.js +25 -12
- package/dist/plugins.js.map +1 -1
- package/dist/types/address.d.ts +8 -0
- package/dist/types/address.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/runtime-config.d.ts +16 -7
- package/dist/types/runtime-config.d.ts.map +1 -1
- package/dist/utils/is-valid-url.d.ts +16 -0
- package/dist/utils/is-valid-url.d.ts.map +1 -0
- package/package.json +3 -3
- package/dist/compiler/tasks/setup/utils/validate-modules.d.ts +0 -2
- package/dist/compiler/tasks/setup/utils/validate-modules.d.ts.map +0 -1
- package/dist/define-keq-config.d.ts +0 -3
- package/dist/define-keq-config.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
## 5.0.0-alpha.6 (2025-09-17)
|
|
2
2
|
|
|
3
|
+
## 5.0.0-alpha.28
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- bbc3403: **BREAKING CHANGE:** drop support relative path and use 'file://' insteaded.
|
|
8
|
+
- bbc3403: **BREAKING CHANGE:** rename defineKeqConfig to defineConfig.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies [d076b76]
|
|
13
|
+
- keq@5.0.0-alpha.28
|
|
14
|
+
|
|
15
|
+
## 5.0.0-alpha.27
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [0c7db81]
|
|
20
|
+
- keq@5.0.0-alpha.27
|
|
21
|
+
|
|
3
22
|
## 5.0.0-alpha.26
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/cli.cjs
CHANGED
|
@@ -53,7 +53,6 @@ var import_tapable4 = require("tapable");
|
|
|
53
53
|
// src/compiler/tasks/setup/index.ts
|
|
54
54
|
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
55
55
|
var import_path = __toESM(require("path"), 1);
|
|
56
|
-
var import_value = require("@sinclair/typebox/value");
|
|
57
56
|
var import_cosmiconfig = require("cosmiconfig");
|
|
58
57
|
|
|
59
58
|
// src/utils/ignore-matcher.ts
|
|
@@ -147,8 +146,51 @@ var IgnoreMatcher = class _IgnoreMatcher {
|
|
|
147
146
|
}
|
|
148
147
|
};
|
|
149
148
|
|
|
150
|
-
// src/
|
|
149
|
+
// src/compiler/tasks/setup/utils/find-nearest-package-json.ts
|
|
150
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
151
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
152
|
+
function findNearestPackageJson(startDir = process.cwd()) {
|
|
153
|
+
let dir = startDir;
|
|
154
|
+
while (true) {
|
|
155
|
+
const pkgPath = import_node_path.default.join(dir, "package.json");
|
|
156
|
+
if (import_node_fs.default.existsSync(pkgPath)) {
|
|
157
|
+
const json = JSON.parse(import_node_fs.default.readFileSync(pkgPath, "utf8"));
|
|
158
|
+
return { json, path: pkgPath };
|
|
159
|
+
}
|
|
160
|
+
const parent = import_node_path.default.dirname(dir);
|
|
161
|
+
if (parent === dir) break;
|
|
162
|
+
dir = parent;
|
|
163
|
+
}
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/compiler/tasks/setup/utils/get-project-module-system.ts
|
|
168
|
+
function getProjectModuleSystem(pkgInfo) {
|
|
169
|
+
if (!pkgInfo?.json) return "cjs";
|
|
170
|
+
const { json } = pkgInfo;
|
|
171
|
+
if (json.type === "module") return "esm";
|
|
172
|
+
return "cjs";
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/compiler/tasks/setup/utils/parse-runtime-config.ts
|
|
176
|
+
var import_value = require("@sinclair/typebox/value");
|
|
177
|
+
|
|
178
|
+
// src/types/address.ts
|
|
151
179
|
var import_typebox = require("@sinclair/typebox");
|
|
180
|
+
var Address = import_typebox.Type.Object({
|
|
181
|
+
url: import_typebox.Type.String(),
|
|
182
|
+
headers: import_typebox.Type.Optional(import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.String(), { default: {} })),
|
|
183
|
+
encoding: import_typebox.Type.Optional(
|
|
184
|
+
import_typebox.Type.Union([
|
|
185
|
+
import_typebox.Type.Literal("utf8"),
|
|
186
|
+
import_typebox.Type.Literal("ascii")
|
|
187
|
+
], { default: "utf8" })
|
|
188
|
+
)
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// src/types/runtime-config.ts
|
|
192
|
+
var R2 = __toESM(require("ramda"), 1);
|
|
193
|
+
var import_typebox2 = require("@sinclair/typebox");
|
|
152
194
|
|
|
153
195
|
// src/constants/file-naming-style.ts
|
|
154
196
|
var FileNamingStyle = /* @__PURE__ */ ((FileNamingStyle2) => {
|
|
@@ -166,13 +208,48 @@ var FileNamingStyle = /* @__PURE__ */ ((FileNamingStyle2) => {
|
|
|
166
208
|
return FileNamingStyle2;
|
|
167
209
|
})(FileNamingStyle || {});
|
|
168
210
|
|
|
211
|
+
// src/utils/is-valid-url.ts
|
|
212
|
+
var URL_REGEX = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/(?:[^\s@]+@)?[^\s/:?#]*(?::\d+)?(?:\/[^\s?#]*)?(?:\?[^\s#]*)?(?:#[^\s]*)?$/;
|
|
213
|
+
function isValidURL(url) {
|
|
214
|
+
return URL_REGEX.test(url);
|
|
215
|
+
}
|
|
216
|
+
|
|
169
217
|
// src/types/runtime-config.ts
|
|
170
|
-
var
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
218
|
+
var Modules = import_typebox2.Type.Transform(
|
|
219
|
+
import_typebox2.Type.Record(
|
|
220
|
+
import_typebox2.Type.String(),
|
|
221
|
+
import_typebox2.Type.Union([import_typebox2.Type.String(), Address])
|
|
222
|
+
)
|
|
223
|
+
).Decode((value) => {
|
|
224
|
+
const keys2 = Object.keys(value);
|
|
225
|
+
for (const key of keys2) {
|
|
226
|
+
if (!/^[A-Za-z_][A-Za-z0-9_$]*$/.test(key)) {
|
|
227
|
+
throw new Error(`Module name "${key}" is not valid. It must start with a letter or underscore, and can only contain letters, numbers, and underscores.`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const keysGroupByLowerCase = R2.groupBy(R2.toLower, keys2);
|
|
231
|
+
for (const groupKey in keysGroupByLowerCase) {
|
|
232
|
+
const keys3 = keysGroupByLowerCase[groupKey] || [];
|
|
233
|
+
if (keys3.length > 1) {
|
|
234
|
+
throw new Error(`Module names ${keys3.map((name) => `"${name}"`).join(", ")} are case-insensitively duplicated.`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
for (const key in value) {
|
|
238
|
+
const url = typeof value[key] === "string" ? value[key] : value[key].url;
|
|
239
|
+
if (isValidURL(url)) continue;
|
|
240
|
+
throw new Error(`The ${JSON.stringify(url)} of module "${key}" is not a valid URL.`);
|
|
241
|
+
}
|
|
242
|
+
return R2.map(
|
|
243
|
+
(item) => typeof item !== "string" ? item : { url: item, headers: {}, encoding: "utf8" },
|
|
244
|
+
value
|
|
245
|
+
);
|
|
246
|
+
}).Encode((value) => value);
|
|
247
|
+
var RawConfig = import_typebox2.Type.Object({
|
|
248
|
+
mode: import_typebox2.Type.Optional(
|
|
249
|
+
import_typebox2.Type.Union([
|
|
250
|
+
import_typebox2.Type.Literal("micro-function"),
|
|
251
|
+
import_typebox2.Type.Literal("nestjs-module"),
|
|
252
|
+
import_typebox2.Type.Literal("none")
|
|
176
253
|
], { default: "micro-function" })
|
|
177
254
|
),
|
|
178
255
|
/**
|
|
@@ -181,77 +258,39 @@ var RuntimeConfig = import_typebox.Type.Object({
|
|
|
181
258
|
* If not specified, the module system will be inferred from the nearest package.json "type" field
|
|
182
259
|
* or defaults to "cjs" if no package.json is found.
|
|
183
260
|
*/
|
|
184
|
-
esm:
|
|
261
|
+
esm: import_typebox2.Type.Optional(import_typebox2.Type.Boolean({ default: false })),
|
|
185
262
|
/**
|
|
186
263
|
* Output directory for generated files
|
|
187
264
|
*/
|
|
188
|
-
outdir:
|
|
265
|
+
outdir: import_typebox2.Type.String({ default: `${process.cwd()}/api` }),
|
|
189
266
|
/**
|
|
190
267
|
* File naming style for generated files
|
|
191
268
|
*/
|
|
192
|
-
fileNamingStyle:
|
|
193
|
-
modules:
|
|
194
|
-
debug:
|
|
269
|
+
fileNamingStyle: import_typebox2.Type.Enum(FileNamingStyle, { default: "snakeCase" /* snakeCase */ }),
|
|
270
|
+
modules: Modules,
|
|
271
|
+
debug: import_typebox2.Type.Optional(import_typebox2.Type.Boolean({ default: false })),
|
|
195
272
|
/**
|
|
196
273
|
* Whether to tolerate wrong openapi/swagger structure
|
|
197
274
|
*/
|
|
198
|
-
tolerant:
|
|
199
|
-
plugins:
|
|
275
|
+
tolerant: import_typebox2.Type.Optional(import_typebox2.Type.Boolean({ default: false })),
|
|
276
|
+
plugins: import_typebox2.Type.Optional(import_typebox2.Type.Array(import_typebox2.Type.Unsafe(import_typebox2.Type.Any()), { default: [] }))
|
|
200
277
|
});
|
|
201
278
|
|
|
202
|
-
// src/compiler/tasks/setup/utils/
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
throw new Error(`Module name "${key}" is not valid. It must start with a letter or underscore, and can only contain letters, numbers, and underscores.`);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
const keysGroupByLowerCase = R2.groupBy(R2.toLower, keys2);
|
|
213
|
-
for (const groupKey in keysGroupByLowerCase) {
|
|
214
|
-
const keys3 = keysGroupByLowerCase[groupKey] || [];
|
|
215
|
-
if (keys3.length > 1) {
|
|
216
|
-
throw new Error(`Module names ${keys3.map((name) => `"${name}"`).join(", ")} are case-insensitively duplicated.`);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
for (const key in modules) {
|
|
220
|
-
const address = modules[key];
|
|
221
|
-
if (import_validator.default.isURL(address, { require_host: true, require_protocol: true, protocols: ["http", "https"] })) {
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
if (/^(\/|\.\/|\.\.\/)/.test(address)) {
|
|
225
|
-
continue;
|
|
279
|
+
// src/compiler/tasks/setup/utils/parse-runtime-config.ts
|
|
280
|
+
function parseRuntimeConfig(data) {
|
|
281
|
+
try {
|
|
282
|
+
const originalPlugins = typeof data === "object" && data !== null && "plugins" in data ? data.plugins : void 0;
|
|
283
|
+
const parsed = import_value.Value.Parse(RawConfig, data);
|
|
284
|
+
if (originalPlugins !== void 0) {
|
|
285
|
+
parsed.plugins = originalPlugins;
|
|
226
286
|
}
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
// src/compiler/tasks/setup/utils/find-nearest-package-json.ts
|
|
232
|
-
var import_node_fs = __toESM(require("fs"), 1);
|
|
233
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
234
|
-
function findNearestPackageJson(startDir = process.cwd()) {
|
|
235
|
-
let dir = startDir;
|
|
236
|
-
while (true) {
|
|
237
|
-
const pkgPath = import_node_path.default.join(dir, "package.json");
|
|
238
|
-
if (import_node_fs.default.existsSync(pkgPath)) {
|
|
239
|
-
const json = JSON.parse(import_node_fs.default.readFileSync(pkgPath, "utf8"));
|
|
240
|
-
return { json, path: pkgPath };
|
|
287
|
+
return parsed;
|
|
288
|
+
} catch (error) {
|
|
289
|
+
if (error instanceof Error) {
|
|
290
|
+
error.message = `Invalid Config: ${error.message}`;
|
|
241
291
|
}
|
|
242
|
-
|
|
243
|
-
if (parent === dir) break;
|
|
244
|
-
dir = parent;
|
|
292
|
+
throw error;
|
|
245
293
|
}
|
|
246
|
-
return null;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// src/compiler/tasks/setup/utils/get-project-module-system.ts
|
|
250
|
-
function getProjectModuleSystem(pkgInfo) {
|
|
251
|
-
if (!pkgInfo?.json) return "cjs";
|
|
252
|
-
const { json } = pkgInfo;
|
|
253
|
-
if (json.type === "module") return "esm";
|
|
254
|
-
return "cjs";
|
|
255
294
|
}
|
|
256
295
|
|
|
257
296
|
// src/compiler/tasks/setup/index.ts
|
|
@@ -263,13 +302,7 @@ function main(compiler, options) {
|
|
|
263
302
|
if (!result || "isEmpty" in result && result.isEmpty) {
|
|
264
303
|
throw new Error("Cannot find config file.");
|
|
265
304
|
}
|
|
266
|
-
|
|
267
|
-
const errors = [...import_value.Value.Errors(RuntimeConfig, result.config)];
|
|
268
|
-
const message = errors.map(({ path: path13, message: message2 }) => `${path13}: ${message2}`).join("\n");
|
|
269
|
-
throw new Error(`Invalid Config: ${message}`);
|
|
270
|
-
}
|
|
271
|
-
const rc = import_value.Value.Default(RuntimeConfig, result.config);
|
|
272
|
-
validateModules(rc.modules);
|
|
305
|
+
const rc = parseRuntimeConfig(result.config);
|
|
273
306
|
if (options?.debug) {
|
|
274
307
|
await import_fs_extra2.default.ensureDir(".keq");
|
|
275
308
|
rc.debug = true;
|
|
@@ -433,10 +466,14 @@ var ModuleDefinition = class _ModuleDefinition {
|
|
|
433
466
|
address;
|
|
434
467
|
constructor(name, address) {
|
|
435
468
|
this.name = name;
|
|
436
|
-
|
|
469
|
+
if (typeof address === "string") {
|
|
470
|
+
this.address = { url: address, headers: {}, encoding: "utf8" };
|
|
471
|
+
} else {
|
|
472
|
+
this.address = address;
|
|
473
|
+
}
|
|
437
474
|
}
|
|
438
475
|
static unknown() {
|
|
439
|
-
return new _ModuleDefinition("", "");
|
|
476
|
+
return new _ModuleDefinition("", { url: "", headers: {}, encoding: "utf8" });
|
|
440
477
|
}
|
|
441
478
|
};
|
|
442
479
|
|
|
@@ -901,10 +938,10 @@ function main2(compiler, options) {
|
|
|
901
938
|
task2.skip(`(${moduleDefinition.name}) is ignored`);
|
|
902
939
|
return;
|
|
903
940
|
}
|
|
904
|
-
task2.output = `Downloaded from ${moduleDefinition.address}`;
|
|
941
|
+
task2.output = `Downloaded from ${moduleDefinition.address.url}`;
|
|
905
942
|
const content = await compiler.hooks.download.promise(moduleDefinition.address, moduleDefinition, task2);
|
|
906
943
|
if (!content) {
|
|
907
|
-
throw new Exception(moduleDefinition, `Cannot download document from ${moduleDefinition.address}`);
|
|
944
|
+
throw new Exception(moduleDefinition, `Cannot download document from ${moduleDefinition.address.url}`);
|
|
908
945
|
}
|
|
909
946
|
const spec = JSON.parse(content);
|
|
910
947
|
const { valid, errors } = await (0, import_openapi_parser2.validate)(spec);
|
|
@@ -2563,24 +2600,25 @@ var GenerateNestjsModulePlugin = class _GenerateNestjsModulePlugin {
|
|
|
2563
2600
|
var import_swagger_fix = require("swagger-fix");
|
|
2564
2601
|
|
|
2565
2602
|
// src/plugins/download-http-file/download-http-file.plugin.ts
|
|
2566
|
-
var validUrl = __toESM(require("valid-url"), 1);
|
|
2567
2603
|
var DownloadHttpFilePlugin = class _DownloadHttpFilePlugin {
|
|
2568
2604
|
apply(compiler) {
|
|
2569
2605
|
compiler.hooks.download.tapPromise(_DownloadHttpFilePlugin.name, async (address, task) => {
|
|
2570
|
-
|
|
2606
|
+
const { url } = address;
|
|
2607
|
+
if (!url.startsWith("http://") && !url.startsWith("https://")) return void 0;
|
|
2571
2608
|
const content = await this.download(address);
|
|
2572
2609
|
const spec = this.deserialize(content);
|
|
2573
2610
|
return JSON.stringify(spec);
|
|
2574
2611
|
});
|
|
2575
2612
|
}
|
|
2576
2613
|
async download(address) {
|
|
2614
|
+
const { url, headers } = address;
|
|
2577
2615
|
try {
|
|
2578
|
-
const res = await fetch(
|
|
2616
|
+
const res = await fetch(url, { headers });
|
|
2579
2617
|
if (res.status >= 400) throw new Error(`failed with status code ${res.status}`);
|
|
2580
2618
|
return await res.text();
|
|
2581
2619
|
} catch (e) {
|
|
2582
2620
|
if (e instanceof Error) {
|
|
2583
|
-
e.message = `Unable get the openapi/swagger file from ${
|
|
2621
|
+
e.message = `Unable get the openapi/swagger file from ${url}: ${e.message}`;
|
|
2584
2622
|
}
|
|
2585
2623
|
throw e;
|
|
2586
2624
|
}
|
|
@@ -2596,17 +2634,21 @@ var DownloadHttpFilePlugin = class _DownloadHttpFilePlugin {
|
|
|
2596
2634
|
var path12 = __toESM(require("path"), 1);
|
|
2597
2635
|
var fs5 = __toESM(require("fs/promises"), 1);
|
|
2598
2636
|
var yaml = __toESM(require("js-yaml"), 1);
|
|
2637
|
+
var import_url = require("url");
|
|
2599
2638
|
var DownloadLocalFilePlugin = class _DownloadLocalFilePlugin {
|
|
2600
2639
|
apply(compiler) {
|
|
2601
2640
|
compiler.hooks.download.tapPromise(_DownloadLocalFilePlugin.name, async (address, task) => {
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
const
|
|
2641
|
+
const { url, encoding } = address;
|
|
2642
|
+
if (!url.startsWith("file://")) return void 0;
|
|
2643
|
+
const filepath = (0, import_url.fileURLToPath)(url);
|
|
2644
|
+
const fileExt = path12.extname(filepath);
|
|
2645
|
+
const content = await fs5.readFile(filepath, encoding);
|
|
2646
|
+
const str = typeof content === "string" ? content : content.toString(encoding);
|
|
2605
2647
|
if ([".yml", ".yaml"].includes(fileExt)) {
|
|
2606
|
-
const value = yaml.load(
|
|
2648
|
+
const value = yaml.load(str);
|
|
2607
2649
|
return JSON.stringify(OpenapiUtils.to3_1(value));
|
|
2608
2650
|
} else if (fileExt === ".json") {
|
|
2609
|
-
return JSON.stringify(OpenapiUtils.to3_1(JSON.parse(
|
|
2651
|
+
return JSON.stringify(OpenapiUtils.to3_1(JSON.parse(str)));
|
|
2610
2652
|
}
|
|
2611
2653
|
});
|
|
2612
2654
|
}
|
|
@@ -2644,7 +2686,11 @@ var ShakingPlugin = class _ShakingPlugin {
|
|
|
2644
2686
|
sharkedSwagger,
|
|
2645
2687
|
new ModuleDefinition(
|
|
2646
2688
|
document.module.name,
|
|
2647
|
-
|
|
2689
|
+
{
|
|
2690
|
+
url: `memory://${document.module.name}.v3_1.sharked.json`,
|
|
2691
|
+
headers: {},
|
|
2692
|
+
encoding: "utf8"
|
|
2693
|
+
}
|
|
2648
2694
|
)
|
|
2649
2695
|
);
|
|
2650
2696
|
}
|