@keq-request/cli 5.0.0-alpha.27 → 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.
Files changed (46) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cli.cjs +132 -86
  3. package/dist/cli.cjs.map +1 -1
  4. package/dist/cli.js +132 -86
  5. package/dist/cli.js.map +1 -1
  6. package/dist/compiler/compiler.d.ts.map +1 -1
  7. package/dist/compiler/tasks/setup/index.d.ts.map +1 -1
  8. package/dist/compiler/tasks/setup/utils/index.d.ts +0 -1
  9. package/dist/compiler/tasks/setup/utils/index.d.ts.map +1 -1
  10. package/dist/compiler/tasks/setup/utils/parse-runtime-config.d.ts +3 -0
  11. package/dist/compiler/tasks/setup/utils/parse-runtime-config.d.ts.map +1 -0
  12. package/dist/compiler/types/compiler-context.d.ts +1 -1
  13. package/dist/compiler/types/compiler-context.d.ts.map +1 -1
  14. package/dist/compiler/types/compiler-hooks.d.ts +2 -1
  15. package/dist/compiler/types/compiler-hooks.d.ts.map +1 -1
  16. package/dist/define-config.d.ts +3 -0
  17. package/dist/define-config.d.ts.map +1 -0
  18. package/dist/index.cjs +137 -93
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +2 -2
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +136 -91
  23. package/dist/index.js.map +1 -1
  24. package/dist/models/module-definition.d.ts +3 -2
  25. package/dist/models/module-definition.d.ts.map +1 -1
  26. package/dist/plugins/download-http-file/download-http-file.plugin.d.ts +2 -2
  27. package/dist/plugins/download-http-file/download-http-file.plugin.d.ts.map +1 -1
  28. package/dist/plugins/download-local-file/download-local-file.plugin.d.ts.map +1 -1
  29. package/dist/plugins/shaking/shaking.plugin.d.ts.map +1 -1
  30. package/dist/plugins.cjs +25 -12
  31. package/dist/plugins.cjs.map +1 -1
  32. package/dist/plugins.js +25 -12
  33. package/dist/plugins.js.map +1 -1
  34. package/dist/types/address.d.ts +8 -0
  35. package/dist/types/address.d.ts.map +1 -0
  36. package/dist/types/index.d.ts +2 -1
  37. package/dist/types/index.d.ts.map +1 -1
  38. package/dist/types/runtime-config.d.ts +16 -7
  39. package/dist/types/runtime-config.d.ts.map +1 -1
  40. package/dist/utils/is-valid-url.d.ts +16 -0
  41. package/dist/utils/is-valid-url.d.ts.map +1 -0
  42. package/package.json +3 -3
  43. package/dist/compiler/tasks/setup/utils/validate-modules.d.ts +0 -2
  44. package/dist/compiler/tasks/setup/utils/validate-modules.d.ts.map +0 -1
  45. package/dist/define-keq-config.d.ts +0 -3
  46. package/dist/define-keq-config.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../src/compiler/compiler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAIjE,OAAO,EAKL,gBAAgB,EAEjB,MAAM,kBAAkB,CAAA;AAKzB,OAAO,EAEL,2BAA2B,EAC5B,MAAM,oBAAoB,CAAA;AAG3B,UAAU,OAAQ,SAAQ,gBAAgB;IACxC,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,KAAK,EAAE,OAAO,CAAA;IACd,WAAW,CAAC,EAAE,OAAO,GAAG,2BAA2B,CAAA;CACpD;AAGD,qBAAa,QAAQ;IAuBV,OAAO,EAAE,OAAO;IAtBzB,OAAO,EAAE,eAAe,CAAK;IAE7B,KAAK,EAAE,aAAa,CAiBnB;gBAGQ,OAAO,EAAE,OAAO;IAgBnB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAyB3B"}
1
+ {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../src/compiler/compiler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAIjE,OAAO,EAKL,gBAAgB,EAEjB,MAAM,kBAAkB,CAAA;AAKzB,OAAO,EAEL,2BAA2B,EAC5B,MAAM,oBAAoB,CAAA;AAI3B,UAAU,OAAQ,SAAQ,gBAAgB;IACxC,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,KAAK,EAAE,OAAO,CAAA;IACd,WAAW,CAAC,EAAE,OAAO,GAAG,2BAA2B,CAAA;CACpD;AAGD,qBAAa,QAAQ;IAuBV,OAAO,EAAE,OAAO;IAtBzB,OAAO,EAAE,eAAe,CAAK;IAE7B,KAAK,EAAE,aAAa,CAiBnB;gBAGQ,OAAO,EAAE,OAAO;IAgBnB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAyB3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/compiler/tasks/setup/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,EAAiB,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAG5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAGtD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB,MAAM,CAAC,EAAE,KAAK,GAAG;QACf,KAAK,EAAE,iBAAiB,EAAE,CAAA;KAC3B,CAAA;CACF;AAqED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,GAAG,eAAe,GAAG,SAAS,CAAC,eAAe,CAAC,CAkB3H"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/compiler/tasks/setup/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,EAAiB,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAE5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAItD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB,MAAM,CAAC,EAAE,KAAK,GAAG;QACf,KAAK,EAAE,iBAAiB,EAAE,CAAA;KAC3B,CAAA;CACF;AA8DD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,GAAG,eAAe,GAAG,SAAS,CAAC,eAAe,CAAC,CAkB3H"}
@@ -1,4 +1,3 @@
1
- export * from './validate-modules.js';
2
1
  export * from './find-nearest-package-json.js';
3
2
  export * from './get-project-module-system.js';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/compiler/tasks/setup/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,gCAAgC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/compiler/tasks/setup/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAA;AAC9C,cAAc,gCAAgC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { RuntimeConfig } from '../../../../types/index.js';
2
+ export declare function parseRuntimeConfig(data: unknown): RuntimeConfig;
3
+ //# sourceMappingURL=parse-runtime-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-runtime-config.d.ts","sourceRoot":"","sources":["../../../../../src/compiler/tasks/setup/utils/parse-runtime-config.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,aAAa,EAAU,MAAM,kBAAkB,CAAA;AAGnE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,GAAG,aAAa,CAqB/D"}
@@ -1,5 +1,5 @@
1
1
  import { ApiDocumentV3_1, Artifact, Asset } from '../../models/index.js';
2
- import { RuntimeConfig } from '../../types/runtime-config.js';
2
+ import { RuntimeConfig } from '../../types/index.js';
3
3
  import { IgnoreMatcher } from '../../utils/ignore-matcher.js';
4
4
  export interface CompilerContext {
5
5
  rc?: RuntimeConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"compiler-context.d.ts","sourceRoot":"","sources":["../../../src/compiler/types/compiler-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAGzD,MAAM,WAAW,eAAe;IAC9B,EAAE,CAAC,EAAE,aAAa,CAAA;IAClB,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,SAAS,CAAC,EAAE,eAAe,EAAE,CAAA;IAC7B,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAA;IACtB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAA;CACjB"}
1
+ {"version":3,"file":"compiler-context.d.ts","sourceRoot":"","sources":["../../../src/compiler/types/compiler-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAGzD,MAAM,WAAW,eAAe;IAC9B,EAAE,CAAC,EAAE,aAAa,CAAA;IAClB,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,SAAS,CAAC,EAAE,eAAe,EAAE,CAAA;IAC7B,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAA;IACtB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAA;CACjB"}
@@ -1,11 +1,12 @@
1
1
  import { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook, SyncHook } from 'tapable';
2
2
  import { TaskWrapper } from '../tasks/index.js';
3
3
  import { ModuleDefinition } from '../../models/index.js';
4
+ import { Address } from '../../types/index.js';
4
5
  export interface CompilerHooks {
5
6
  setup: AsyncParallelHook<[TaskWrapper]>;
6
7
  afterSetup: AsyncSeriesHook<[TaskWrapper]>;
7
8
  beforeDownload: AsyncSeriesHook<[TaskWrapper]>;
8
- download: AsyncSeriesBailHook<[string, ModuleDefinition, TaskWrapper], string | undefined>;
9
+ download: AsyncSeriesBailHook<[Address, ModuleDefinition, TaskWrapper], string | undefined>;
9
10
  afterDownload: AsyncSeriesHook<[TaskWrapper]>;
10
11
  beforeCompile: AsyncSeriesHook<[TaskWrapper]>;
11
12
  compile: AsyncParallelHook<[TaskWrapper]>;
@@ -1 +1 @@
1
- {"version":3,"file":"compiler-hooks.d.ts","sourceRoot":"","sources":["../../../src/compiler/types/compiler-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC3F,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAGpD,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,iBAAiB,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IACvC,UAAU,EAAE,eAAe,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IAE1C,cAAc,EAAE,eAAe,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IAC9C,QAAQ,EAAE,mBAAmB,CAAC,CAAC,MAAM,EAAE,gBAAgB,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;IAC1F,aAAa,EAAE,eAAe,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IAE7C,aAAa,EAAE,eAAe,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IAC7C,OAAO,EAAE,iBAAiB,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IACzC,YAAY,EAAE,eAAe,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IAE5C,aAAa,EAAE,eAAe,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IAC7C,OAAO,EAAE,iBAAiB,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IACzC,YAAY,EAAE,eAAe,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IAE5C,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAA;CACnB"}
1
+ {"version":3,"file":"compiler-hooks.d.ts","sourceRoot":"","sources":["../../../src/compiler/types/compiler-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC3F,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAG1C,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,iBAAiB,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IACvC,UAAU,EAAE,eAAe,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IAE1C,cAAc,EAAE,eAAe,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IAC9C,QAAQ,EAAE,mBAAmB,CAAC,CAAC,OAAO,EAAE,gBAAgB,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;IAC3F,aAAa,EAAE,eAAe,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IAE7C,aAAa,EAAE,eAAe,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IAC7C,OAAO,EAAE,iBAAiB,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IACzC,YAAY,EAAE,eAAe,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IAE5C,aAAa,EAAE,eAAe,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IAC7C,OAAO,EAAE,iBAAiB,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IACzC,YAAY,EAAE,eAAe,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IAE5C,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAA;CACnB"}
@@ -0,0 +1,3 @@
1
+ import { RawConfig } from './types/runtime-config.js';
2
+ export declare function defineConfig(config: RawConfig): RawConfig;
3
+ //# sourceMappingURL=define-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-config.d.ts","sourceRoot":"","sources":["../src/define-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAGrD,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,CAEzD"}
package/dist/index.cjs CHANGED
@@ -38,20 +38,16 @@ __export(src_exports, {
38
38
  ModuleDefinition: () => ModuleDefinition,
39
39
  OperationDefinition: () => OperationDefinition,
40
40
  QsArrayFormat: () => QsArrayFormat,
41
- RuntimeConfig: () => RuntimeConfig,
42
41
  SchemaDefinition: () => SchemaDefinition,
43
- defineKeqConfig: () => defineKeqConfig
42
+ defineConfig: () => defineConfig
44
43
  });
45
44
  module.exports = __toCommonJS(src_exports);
46
45
 
47
- // src/define-keq-config.ts
48
- function defineKeqConfig(config) {
46
+ // src/define-config.ts
47
+ function defineConfig(config) {
49
48
  return config;
50
49
  }
51
50
 
52
- // src/types/runtime-config.ts
53
- var import_typebox = require("@sinclair/typebox");
54
-
55
51
  // src/constants/file-naming-style.ts
56
52
  var FileNamingStyle = /* @__PURE__ */ ((FileNamingStyle2) => {
57
53
  FileNamingStyle2["camelCase"] = "camelCase";
@@ -68,39 +64,6 @@ var FileNamingStyle = /* @__PURE__ */ ((FileNamingStyle2) => {
68
64
  return FileNamingStyle2;
69
65
  })(FileNamingStyle || {});
70
66
 
71
- // src/types/runtime-config.ts
72
- var RuntimeConfig = import_typebox.Type.Object({
73
- mode: import_typebox.Type.Optional(
74
- import_typebox.Type.Union([
75
- import_typebox.Type.Literal("micro-function"),
76
- import_typebox.Type.Literal("nestjs-module"),
77
- import_typebox.Type.Literal("none")
78
- ], { default: "micro-function" })
79
- ),
80
- /**
81
- * Whether to generate ES Module code
82
- *
83
- * If not specified, the module system will be inferred from the nearest package.json "type" field
84
- * or defaults to "cjs" if no package.json is found.
85
- */
86
- esm: import_typebox.Type.Optional(import_typebox.Type.Boolean({ default: false })),
87
- /**
88
- * Output directory for generated files
89
- */
90
- outdir: import_typebox.Type.String({ default: `${process.cwd()}/api` }),
91
- /**
92
- * File naming style for generated files
93
- */
94
- fileNamingStyle: import_typebox.Type.Enum(FileNamingStyle, { default: "snakeCase" /* snakeCase */ }),
95
- modules: import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.String()),
96
- debug: import_typebox.Type.Optional(import_typebox.Type.Boolean({ default: false })),
97
- /**
98
- * Whether to tolerate wrong openapi/swagger structure
99
- */
100
- tolerant: import_typebox.Type.Optional(import_typebox.Type.Boolean({ default: false })),
101
- plugins: import_typebox.Type.Optional(import_typebox.Type.Array(import_typebox.Type.Any(), { default: [] }))
102
- });
103
-
104
67
  // src/constants/qs-array-format.ts
105
68
  var QsArrayFormat = /* @__PURE__ */ ((QsArrayFormat2) => {
106
69
  QsArrayFormat2["brackets"] = "brackets";
@@ -130,7 +93,6 @@ var import_tapable4 = require("tapable");
130
93
  // src/compiler/tasks/setup/index.ts
131
94
  var import_fs_extra2 = __toESM(require("fs-extra"), 1);
132
95
  var import_path = __toESM(require("path"), 1);
133
- var import_value = require("@sinclair/typebox/value");
134
96
  var import_cosmiconfig = require("cosmiconfig");
135
97
 
136
98
  // src/utils/ignore-matcher.ts
@@ -224,35 +186,6 @@ var IgnoreMatcher = class _IgnoreMatcher {
224
186
  }
225
187
  };
226
188
 
227
- // src/compiler/tasks/setup/utils/validate-modules.ts
228
- var R2 = __toESM(require("ramda"), 1);
229
- var import_validator = __toESM(require("validator"), 1);
230
- function validateModules(modules) {
231
- const keys2 = Object.keys(modules);
232
- for (const key of keys2) {
233
- if (!/^[A-Za-z_][A-Za-z0-9_$]*$/.test(key)) {
234
- 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.`);
235
- }
236
- }
237
- const keysGroupByLowerCase = R2.groupBy(R2.toLower, keys2);
238
- for (const groupKey in keysGroupByLowerCase) {
239
- const keys3 = keysGroupByLowerCase[groupKey] || [];
240
- if (keys3.length > 1) {
241
- throw new Error(`Module names ${keys3.map((name) => `"${name}"`).join(", ")} are case-insensitively duplicated.`);
242
- }
243
- }
244
- for (const key in modules) {
245
- const address = modules[key];
246
- if (import_validator.default.isURL(address, { require_host: true, require_protocol: true, protocols: ["http", "https"] })) {
247
- continue;
248
- }
249
- if (/^(\/|\.\/|\.\.\/)/.test(address)) {
250
- continue;
251
- }
252
- throw new Error(`Module address "${address}" of module "${key}" is not valid. It must be a URL or a local path.`);
253
- }
254
- }
255
-
256
189
  // src/compiler/tasks/setup/utils/find-nearest-package-json.ts
257
190
  var import_node_fs = __toESM(require("fs"), 1);
258
191
  var import_node_path = __toESM(require("path"), 1);
@@ -279,6 +212,111 @@ function getProjectModuleSystem(pkgInfo) {
279
212
  return "cjs";
280
213
  }
281
214
 
215
+ // src/compiler/tasks/setup/utils/parse-runtime-config.ts
216
+ var import_value = require("@sinclair/typebox/value");
217
+
218
+ // src/types/address.ts
219
+ var import_typebox = require("@sinclair/typebox");
220
+ var Address = import_typebox.Type.Object({
221
+ url: import_typebox.Type.String(),
222
+ headers: import_typebox.Type.Optional(import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.String(), { default: {} })),
223
+ encoding: import_typebox.Type.Optional(
224
+ import_typebox.Type.Union([
225
+ import_typebox.Type.Literal("utf8"),
226
+ import_typebox.Type.Literal("ascii")
227
+ ], { default: "utf8" })
228
+ )
229
+ });
230
+
231
+ // src/types/runtime-config.ts
232
+ var R2 = __toESM(require("ramda"), 1);
233
+ var import_typebox2 = require("@sinclair/typebox");
234
+
235
+ // src/utils/is-valid-url.ts
236
+ var URL_REGEX = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/(?:[^\s@]+@)?[^\s/:?#]*(?::\d+)?(?:\/[^\s?#]*)?(?:\?[^\s#]*)?(?:#[^\s]*)?$/;
237
+ function isValidURL(url) {
238
+ return URL_REGEX.test(url);
239
+ }
240
+
241
+ // src/types/runtime-config.ts
242
+ var Modules = import_typebox2.Type.Transform(
243
+ import_typebox2.Type.Record(
244
+ import_typebox2.Type.String(),
245
+ import_typebox2.Type.Union([import_typebox2.Type.String(), Address])
246
+ )
247
+ ).Decode((value) => {
248
+ const keys2 = Object.keys(value);
249
+ for (const key of keys2) {
250
+ if (!/^[A-Za-z_][A-Za-z0-9_$]*$/.test(key)) {
251
+ 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.`);
252
+ }
253
+ }
254
+ const keysGroupByLowerCase = R2.groupBy(R2.toLower, keys2);
255
+ for (const groupKey in keysGroupByLowerCase) {
256
+ const keys3 = keysGroupByLowerCase[groupKey] || [];
257
+ if (keys3.length > 1) {
258
+ throw new Error(`Module names ${keys3.map((name) => `"${name}"`).join(", ")} are case-insensitively duplicated.`);
259
+ }
260
+ }
261
+ for (const key in value) {
262
+ const url = typeof value[key] === "string" ? value[key] : value[key].url;
263
+ if (isValidURL(url)) continue;
264
+ throw new Error(`The ${JSON.stringify(url)} of module "${key}" is not a valid URL.`);
265
+ }
266
+ return R2.map(
267
+ (item) => typeof item !== "string" ? item : { url: item, headers: {}, encoding: "utf8" },
268
+ value
269
+ );
270
+ }).Encode((value) => value);
271
+ var RawConfig = import_typebox2.Type.Object({
272
+ mode: import_typebox2.Type.Optional(
273
+ import_typebox2.Type.Union([
274
+ import_typebox2.Type.Literal("micro-function"),
275
+ import_typebox2.Type.Literal("nestjs-module"),
276
+ import_typebox2.Type.Literal("none")
277
+ ], { default: "micro-function" })
278
+ ),
279
+ /**
280
+ * Whether to generate ES Module code
281
+ *
282
+ * If not specified, the module system will be inferred from the nearest package.json "type" field
283
+ * or defaults to "cjs" if no package.json is found.
284
+ */
285
+ esm: import_typebox2.Type.Optional(import_typebox2.Type.Boolean({ default: false })),
286
+ /**
287
+ * Output directory for generated files
288
+ */
289
+ outdir: import_typebox2.Type.String({ default: `${process.cwd()}/api` }),
290
+ /**
291
+ * File naming style for generated files
292
+ */
293
+ fileNamingStyle: import_typebox2.Type.Enum(FileNamingStyle, { default: "snakeCase" /* snakeCase */ }),
294
+ modules: Modules,
295
+ debug: import_typebox2.Type.Optional(import_typebox2.Type.Boolean({ default: false })),
296
+ /**
297
+ * Whether to tolerate wrong openapi/swagger structure
298
+ */
299
+ tolerant: import_typebox2.Type.Optional(import_typebox2.Type.Boolean({ default: false })),
300
+ plugins: import_typebox2.Type.Optional(import_typebox2.Type.Array(import_typebox2.Type.Unsafe(import_typebox2.Type.Any()), { default: [] }))
301
+ });
302
+
303
+ // src/compiler/tasks/setup/utils/parse-runtime-config.ts
304
+ function parseRuntimeConfig(data) {
305
+ try {
306
+ const originalPlugins = typeof data === "object" && data !== null && "plugins" in data ? data.plugins : void 0;
307
+ const parsed = import_value.Value.Parse(RawConfig, data);
308
+ if (originalPlugins !== void 0) {
309
+ parsed.plugins = originalPlugins;
310
+ }
311
+ return parsed;
312
+ } catch (error) {
313
+ if (error instanceof Error) {
314
+ error.message = `Invalid Config: ${error.message}`;
315
+ }
316
+ throw error;
317
+ }
318
+ }
319
+
282
320
  // src/compiler/tasks/setup/index.ts
283
321
  var explore = (0, import_cosmiconfig.cosmiconfig)("keq");
284
322
  function main(compiler, options) {
@@ -288,13 +326,7 @@ function main(compiler, options) {
288
326
  if (!result || "isEmpty" in result && result.isEmpty) {
289
327
  throw new Error("Cannot find config file.");
290
328
  }
291
- if (!import_value.Value.Check(RuntimeConfig, result.config)) {
292
- const errors = [...import_value.Value.Errors(RuntimeConfig, result.config)];
293
- const message = errors.map(({ path: path13, message: message2 }) => `${path13}: ${message2}`).join("\n");
294
- throw new Error(`Invalid Config: ${message}`);
295
- }
296
- const rc = import_value.Value.Default(RuntimeConfig, result.config);
297
- validateModules(rc.modules);
329
+ const rc = parseRuntimeConfig(result.config);
298
330
  if (options?.debug) {
299
331
  await import_fs_extra2.default.ensureDir(".keq");
300
332
  rc.debug = true;
@@ -458,10 +490,14 @@ var ModuleDefinition = class _ModuleDefinition {
458
490
  address;
459
491
  constructor(name, address) {
460
492
  this.name = name;
461
- this.address = address;
493
+ if (typeof address === "string") {
494
+ this.address = { url: address, headers: {}, encoding: "utf8" };
495
+ } else {
496
+ this.address = address;
497
+ }
462
498
  }
463
499
  static unknown() {
464
- return new _ModuleDefinition("", "");
500
+ return new _ModuleDefinition("", { url: "", headers: {}, encoding: "utf8" });
465
501
  }
466
502
  };
467
503
 
@@ -934,10 +970,10 @@ function main2(compiler, options) {
934
970
  task2.skip(`(${moduleDefinition.name}) is ignored`);
935
971
  return;
936
972
  }
937
- task2.output = `Downloaded from ${moduleDefinition.address}`;
973
+ task2.output = `Downloaded from ${moduleDefinition.address.url}`;
938
974
  const content = await compiler.hooks.download.promise(moduleDefinition.address, moduleDefinition, task2);
939
975
  if (!content) {
940
- throw new Exception(moduleDefinition, `Cannot download document from ${moduleDefinition.address}`);
976
+ throw new Exception(moduleDefinition, `Cannot download document from ${moduleDefinition.address.url}`);
941
977
  }
942
978
  const spec = JSON.parse(content);
943
979
  const { valid, errors } = await (0, import_openapi_parser2.validate)(spec);
@@ -2583,24 +2619,25 @@ var GenerateNestjsModulePlugin = class _GenerateNestjsModulePlugin {
2583
2619
  var import_swagger_fix = require("swagger-fix");
2584
2620
 
2585
2621
  // src/plugins/download-http-file/download-http-file.plugin.ts
2586
- var validUrl = __toESM(require("valid-url"), 1);
2587
2622
  var DownloadHttpFilePlugin = class _DownloadHttpFilePlugin {
2588
2623
  apply(compiler) {
2589
2624
  compiler.hooks.download.tapPromise(_DownloadHttpFilePlugin.name, async (address, task) => {
2590
- if (!validUrl.isUri(address)) return void 0;
2625
+ const { url } = address;
2626
+ if (!url.startsWith("http://") && !url.startsWith("https://")) return void 0;
2591
2627
  const content = await this.download(address);
2592
2628
  const spec = this.deserialize(content);
2593
2629
  return JSON.stringify(spec);
2594
2630
  });
2595
2631
  }
2596
2632
  async download(address) {
2633
+ const { url, headers } = address;
2597
2634
  try {
2598
- const res = await fetch(address);
2635
+ const res = await fetch(url, { headers });
2599
2636
  if (res.status >= 400) throw new Error(`failed with status code ${res.status}`);
2600
2637
  return await res.text();
2601
2638
  } catch (e) {
2602
2639
  if (e instanceof Error) {
2603
- e.message = `Unable get the openapi/swagger file from ${address}: ${e.message}`;
2640
+ e.message = `Unable get the openapi/swagger file from ${url}: ${e.message}`;
2604
2641
  }
2605
2642
  throw e;
2606
2643
  }
@@ -2616,17 +2653,21 @@ var DownloadHttpFilePlugin = class _DownloadHttpFilePlugin {
2616
2653
  var path12 = __toESM(require("path"), 1);
2617
2654
  var fs5 = __toESM(require("fs/promises"), 1);
2618
2655
  var yaml = __toESM(require("js-yaml"), 1);
2656
+ var import_url = require("url");
2619
2657
  var DownloadLocalFilePlugin = class _DownloadLocalFilePlugin {
2620
2658
  apply(compiler) {
2621
2659
  compiler.hooks.download.tapPromise(_DownloadLocalFilePlugin.name, async (address, task) => {
2622
- if (!address.startsWith("./") && !address.startsWith("/") && !address.startsWith("../")) return void 0;
2623
- const fileExt = path12.extname(address);
2624
- const content = await fs5.readFile(address, "utf8");
2660
+ const { url, encoding } = address;
2661
+ if (!url.startsWith("file://")) return void 0;
2662
+ const filepath = (0, import_url.fileURLToPath)(url);
2663
+ const fileExt = path12.extname(filepath);
2664
+ const content = await fs5.readFile(filepath, encoding);
2665
+ const str = typeof content === "string" ? content : content.toString(encoding);
2625
2666
  if ([".yml", ".yaml"].includes(fileExt)) {
2626
- const value = yaml.load(content);
2667
+ const value = yaml.load(str);
2627
2668
  return JSON.stringify(OpenapiUtils.to3_1(value));
2628
2669
  } else if (fileExt === ".json") {
2629
- return JSON.stringify(OpenapiUtils.to3_1(JSON.parse(content)));
2670
+ return JSON.stringify(OpenapiUtils.to3_1(JSON.parse(str)));
2630
2671
  }
2631
2672
  });
2632
2673
  }
@@ -2664,7 +2705,11 @@ var ShakingPlugin = class _ShakingPlugin {
2664
2705
  sharkedSwagger,
2665
2706
  new ModuleDefinition(
2666
2707
  document.module.name,
2667
- `file://${document.module.name}.v3_1.sharked.json`
2708
+ {
2709
+ url: `memory://${document.module.name}.v3_1.sharked.json`,
2710
+ headers: {},
2711
+ encoding: "utf8"
2712
+ }
2668
2713
  )
2669
2714
  );
2670
2715
  }
@@ -2848,8 +2893,7 @@ var Compiler = class {
2848
2893
  ModuleDefinition,
2849
2894
  OperationDefinition,
2850
2895
  QsArrayFormat,
2851
- RuntimeConfig,
2852
2896
  SchemaDefinition,
2853
- defineKeqConfig
2897
+ defineConfig
2854
2898
  });
2855
2899
  //# sourceMappingURL=index.cjs.map