@kubb/core 5.0.0-beta.95 → 5.0.0-beta.97

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/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_usingCtx = require("./usingCtx-eyNeehd2.cjs");
2
+ const require_usingCtx = require("./usingCtx-BLzqdXPG.cjs");
3
3
  let node_async_hooks = require("node:async_hooks");
4
4
  let node_util = require("node:util");
5
5
  let node_crypto = require("node:crypto");
@@ -191,7 +191,7 @@ function memoize(store, factory) {
191
191
  }
192
192
  //#endregion
193
193
  //#region package.json
194
- var version = "5.0.0-beta.95";
194
+ var version = "5.0.0-beta.97";
195
195
  //#endregion
196
196
  //#region src/constants.ts
197
197
  /**
@@ -269,6 +269,11 @@ const diagnosticCode = {
269
269
  */
270
270
  pathTraversal: "KUBB_PATH_TRAVERSAL",
271
271
  /**
272
+ * `output.clean` is enabled but `output.path` resolves to the project root or a parent of it,
273
+ * so cleaning would delete kubb.config and every source file.
274
+ */
275
+ cleanRoot: "KUBB_CLEAN_ROOT",
276
+ /**
272
277
  * A plugin's options are invalid, for example `output.mode: 'file'` paired with a `group` option.
273
278
  */
274
279
  invalidPluginOptions: "KUBB_INVALID_PLUGIN_OPTIONS",
@@ -416,6 +421,11 @@ const diagnosticCatalog = {
416
421
  cause: "A resolved output path escaped the output directory, which can stem from a path traversal in the spec or a misconfigured `group.name`.",
417
422
  fix: "Keep generated paths within the output directory. Review the `group.name` function and the names coming from the spec."
418
423
  },
424
+ [diagnosticCode.cleanRoot]: {
425
+ title: "Clean targets the project root",
426
+ cause: "`output.clean` is enabled and `output.path` resolves to the project root or a parent of it, so cleaning would delete `kubb.config` and every source file.",
427
+ fix: "Point `output.path` at a subdirectory such as `./src/gen` so clean only removes generated code, or disable `output.clean`."
428
+ },
419
429
  [diagnosticCode.invalidPluginOptions]: {
420
430
  title: "Invalid plugin options",
421
431
  cause: "A plugin was configured with options that cannot be honored, for example `output.mode: 'file'` paired with a `group` option.",
@@ -901,23 +911,32 @@ var Resolver = class Resolver {
901
911
  } });
902
912
  }
903
913
  /**
904
- * Merges `override` over `base` and returns a new resolver with helpers re-bound. Top-level
905
- * keys replace, and a namespace (or `file`) merges per method, so overriding `query.name`
906
- * keeps the base `query.keyName`. Used when applying `setResolver` partial overrides. Reads a
907
- * resolver's options through the shared brand rather than `instanceof`, so a `file` override
908
- * survives even when `base` and `override` come from different `@kubb/core` copies.
909
- */
910
- static merge(base, override) {
911
- const patch = resolverOptions in override ? override[resolverOptions] : override;
912
- const merged = { ...base[resolverOptions] };
913
- for (const [key, value] of Object.entries(patch)) {
914
- if (value === void 0) continue;
915
- const current = merged[key];
916
- merged[key] = isNamespace(value) && isNamespace(current) ? {
917
- ...current,
918
- ...value
919
- } : value;
920
- }
914
+ * Folds each `override` over `base`, left to right, and returns a new resolver with helpers
915
+ * re-bound. Top-level keys replace, and a namespace (or `file`) merges per method, so overriding
916
+ * `query.name` keeps the base `query.keyName`. The last override wins per key. Used when applying
917
+ * `setResolver` partial overrides, and to compose shared resolver fragments without spreading each
918
+ * namespace by hand. Reads a resolver's options through the shared brand rather than `instanceof`,
919
+ * so a `file` override survives even when `base` and `override` come from different `@kubb/core`
920
+ * copies.
921
+ *
922
+ * @example Fold several partial overrides onto a resolver
923
+ * ```ts
924
+ * const resolver = Resolver.merge(defaultResolver, sharedNamingPatch, { name: (name) => name.toUpperCase() })
925
+ * ```
926
+ */
927
+ static merge(base, ...overrides) {
928
+ const merged = overrides.reduce((acc, override) => {
929
+ const patch = resolverOptions in override ? override[resolverOptions] : override;
930
+ for (const [key, value] of Object.entries(patch)) {
931
+ if (value === void 0) continue;
932
+ const current = acc[key];
933
+ acc[key] = isNamespace(value) && isNamespace(current) ? {
934
+ ...current,
935
+ ...value
936
+ } : value;
937
+ }
938
+ return acc;
939
+ }, { ...base[resolverOptions] });
921
940
  return new Resolver(merged);
922
941
  }
923
942
  /**
@@ -2085,7 +2104,17 @@ var Kubb = class {
2085
2104
  const config = this.config;
2086
2105
  const driver = new KubbDriver(config, { hooks: this.hooks });
2087
2106
  this.hooks.setMaxListeners(Math.max(10, config.plugins.length * 4));
2088
- if (config.output.clean) await config.storage.clear((0, node_path.resolve)(config.root, config.output.path));
2107
+ if (config.output.clean) {
2108
+ const cleanPath = (0, node_path.resolve)(config.root, config.output.path);
2109
+ if (require_usingCtx.isPathInside(config.root, cleanPath)) throw new Diagnostics.Error({
2110
+ code: Diagnostics.code.cleanRoot,
2111
+ severity: "error",
2112
+ message: `output.clean cannot delete "${cleanPath}" because it is the project root or a parent of it.`,
2113
+ help: "Point `output.path` at a subdirectory such as `./src/gen` so clean only removes generated code.",
2114
+ location: { kind: "config" }
2115
+ });
2116
+ await config.storage.clear(cleanPath);
2117
+ }
2089
2118
  await driver.setup();
2090
2119
  this.#driver = driver;
2091
2120
  this.#storage = config.storage;