@kubb/core 5.0.0-alpha.3 → 5.0.0-alpha.4
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/hooks.d.ts +1 -1
- package/dist/index.cjs +88 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +38 -2
- package/dist/index.js +88 -3
- package/dist/index.js.map +1 -1
- package/dist/{types-CiPWLv-5.d.ts → types-Bbh1o0yW.d.ts} +59 -3
- package/package.json +2 -2
- package/src/defineGenerator.ts +106 -0
- package/src/index.ts +2 -0
- package/src/types.ts +1 -0
- package/src/utils/resolveOptions.ts +93 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { A as UserPluginWithLifeCycle, B as
|
|
2
|
+
import { A as UserPluginWithLifeCycle, B as formatters, C as PrinterFactoryOptions, D as UserConfig, E as UnknownUserPlugin, F as KubbEvents, H as logLevel, I as PluginManager, L as getMode, M as Generator, N as ReactGeneratorV2, O as UserLogger, P as defineGenerator, R as DefineStorage, S as Printer, T as ResolvePathParams, U as AsyncEventEmitter, V as linters, W as URLPath, _ as PluginFactoryOptions, a as Config, b as PluginParameter, c as Group, d as Logger, f as LoggerContext, g as PluginContext, h as Plugin, i as BarrelType, j as CoreGeneratorV2, k as UserPlugin, l as InputData, m as Output, n as AdapterFactoryOptions, o as DevtoolsOptions, p as LoggerOptions, r as AdapterSource, s as GetPluginFactoryOptions, t as Adapter, u as InputPath, v as PluginLifecycle, w as ResolveNameParams, x as PluginWithLifeCycle, y as PluginLifecycleHooks, z as defineStorage } from "./types-Bbh1o0yW.js";
|
|
3
3
|
import { definePrinter } from "@kubb/ast";
|
|
4
4
|
import { Fabric } from "@kubb/react-fabric";
|
|
5
|
+
import { Node } from "@kubb/ast/types";
|
|
5
6
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
6
7
|
|
|
7
8
|
//#region src/build.d.ts
|
|
@@ -311,5 +312,40 @@ declare function getConfigs(config: ConfigInput | UserConfig, args: CLIOptions):
|
|
|
311
312
|
type Linter = keyof typeof linters;
|
|
312
313
|
declare function detectLinter(): Promise<Linter | undefined>;
|
|
313
314
|
//#endregion
|
|
314
|
-
|
|
315
|
+
//#region src/utils/resolveOptions.d.ts
|
|
316
|
+
type FilterItem = {
|
|
317
|
+
type: string;
|
|
318
|
+
pattern: string | RegExp;
|
|
319
|
+
};
|
|
320
|
+
type OverrideItem<TOptions> = FilterItem & {
|
|
321
|
+
options: Partial<TOptions>;
|
|
322
|
+
};
|
|
323
|
+
type ResolveOptionsContext<TOptions> = {
|
|
324
|
+
options: TOptions;
|
|
325
|
+
exclude?: Array<FilterItem>;
|
|
326
|
+
include?: Array<FilterItem>;
|
|
327
|
+
override?: Array<OverrideItem<TOptions>>;
|
|
328
|
+
};
|
|
329
|
+
/**
|
|
330
|
+
* Resolves the effective plugin options for a given AST node by applying
|
|
331
|
+
* `exclude`, `include`, and `override` rules from the plugin configuration.
|
|
332
|
+
*
|
|
333
|
+
* Returns `null` when the node is excluded or not matched by `include`.
|
|
334
|
+
* Returns the merged options (base options merged with any matching `override`) otherwise.
|
|
335
|
+
*
|
|
336
|
+
* Supported filter types for `OperationNode`: `tag`, `operationId`, `path`, `method`.
|
|
337
|
+
* Supported filter types for `SchemaNode`: `schemaName`.
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* const resolved = resolveOptions(operationNode, { options, exclude, include, override })
|
|
341
|
+
* if (!resolved) return // excluded
|
|
342
|
+
*/
|
|
343
|
+
declare function resolveOptions<TOptions>(node: Node, {
|
|
344
|
+
options,
|
|
345
|
+
exclude,
|
|
346
|
+
include,
|
|
347
|
+
override
|
|
348
|
+
}: ResolveOptionsContext<TOptions>): TOptions | null;
|
|
349
|
+
//#endregion
|
|
350
|
+
export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BarrelType, type CLIOptions, Config, type ConfigInput, CoreGeneratorV2, DefineStorage, DevtoolsOptions, type FileMetaBase, FunctionParams, type FunctionParamsAST, Generator, GetPluginFactoryOptions, Group, InputData, InputPath, KubbEvents, Logger, LoggerContext, LoggerOptions, Output, PackageManager, Plugin, PluginContext, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginParameter, PluginWithLifeCycle, Printer, PrinterFactoryOptions, PromiseManager, ReactGeneratorV2, ResolveNameParams, ResolvePathParams, URLPath, UnknownUserPlugin, UserConfig, UserLogger, UserPlugin, UserPluginWithLifeCycle, build, build as default, defineAdapter, defineConfig, defineGenerator, defineLogger, definePlugin, definePrinter, defineStorage, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, isInputPath, linters, logLevel, memoryStorage, resolveOptions, safeBuild, setup };
|
|
315
351
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { parseArgs, styleText } from "node:util";
|
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
6
|
import { access, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
7
7
|
import path, { basename, dirname, extname, join, posix, relative, resolve } from "node:path";
|
|
8
|
-
import { definePrinter } from "@kubb/ast";
|
|
8
|
+
import { definePrinter, isOperationNode, isSchemaNode } from "@kubb/ast";
|
|
9
9
|
import { createFabric } from "@kubb/react-fabric";
|
|
10
10
|
import { typescriptParser } from "@kubb/react-fabric/parsers";
|
|
11
11
|
import { fsPlugin } from "@kubb/react-fabric/plugins";
|
|
@@ -1456,7 +1456,7 @@ const fsStorage = defineStorage(() => ({
|
|
|
1456
1456
|
}));
|
|
1457
1457
|
//#endregion
|
|
1458
1458
|
//#region package.json
|
|
1459
|
-
var version$1 = "5.0.0-alpha.
|
|
1459
|
+
var version$1 = "5.0.0-alpha.4";
|
|
1460
1460
|
//#endregion
|
|
1461
1461
|
//#region src/utils/diagnostics.ts
|
|
1462
1462
|
/**
|
|
@@ -1789,6 +1789,36 @@ function defineAdapter(build) {
|
|
|
1789
1789
|
return (options) => build(options ?? {});
|
|
1790
1790
|
}
|
|
1791
1791
|
//#endregion
|
|
1792
|
+
//#region src/defineGenerator.ts
|
|
1793
|
+
function defineGenerator(generator) {
|
|
1794
|
+
if (generator.type === "react") return {
|
|
1795
|
+
version: "2",
|
|
1796
|
+
Operations() {
|
|
1797
|
+
return null;
|
|
1798
|
+
},
|
|
1799
|
+
Operation() {
|
|
1800
|
+
return null;
|
|
1801
|
+
},
|
|
1802
|
+
Schema() {
|
|
1803
|
+
return null;
|
|
1804
|
+
},
|
|
1805
|
+
...generator
|
|
1806
|
+
};
|
|
1807
|
+
return {
|
|
1808
|
+
version: "2",
|
|
1809
|
+
async operations() {
|
|
1810
|
+
return [];
|
|
1811
|
+
},
|
|
1812
|
+
async operation() {
|
|
1813
|
+
return [];
|
|
1814
|
+
},
|
|
1815
|
+
async schema() {
|
|
1816
|
+
return [];
|
|
1817
|
+
},
|
|
1818
|
+
...generator
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
//#endregion
|
|
1792
1822
|
//#region src/defineLogger.ts
|
|
1793
1823
|
function defineLogger(logger) {
|
|
1794
1824
|
return { ...logger };
|
|
@@ -2302,6 +2332,61 @@ async function detectLinter() {
|
|
|
2302
2332
|
]) if (await isLinterAvailable(linter)) return linter;
|
|
2303
2333
|
}
|
|
2304
2334
|
//#endregion
|
|
2305
|
-
|
|
2335
|
+
//#region src/utils/resolveOptions.ts
|
|
2336
|
+
function matchesOperationPattern(node, type, pattern) {
|
|
2337
|
+
switch (type) {
|
|
2338
|
+
case "tag": return node.tags.some((tag) => !!tag.match(pattern));
|
|
2339
|
+
case "operationId": return !!node.operationId.match(pattern);
|
|
2340
|
+
case "path": return !!node.path.match(pattern);
|
|
2341
|
+
case "method": return !!node.method.toLowerCase().match(pattern);
|
|
2342
|
+
default: return false;
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
function matchesSchemaPattern(node, type, pattern) {
|
|
2346
|
+
switch (type) {
|
|
2347
|
+
case "schemaName": return node.name ? !!node.name.match(pattern) : false;
|
|
2348
|
+
default: return null;
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
/**
|
|
2352
|
+
* Resolves the effective plugin options for a given AST node by applying
|
|
2353
|
+
* `exclude`, `include`, and `override` rules from the plugin configuration.
|
|
2354
|
+
*
|
|
2355
|
+
* Returns `null` when the node is excluded or not matched by `include`.
|
|
2356
|
+
* Returns the merged options (base options merged with any matching `override`) otherwise.
|
|
2357
|
+
*
|
|
2358
|
+
* Supported filter types for `OperationNode`: `tag`, `operationId`, `path`, `method`.
|
|
2359
|
+
* Supported filter types for `SchemaNode`: `schemaName`.
|
|
2360
|
+
*
|
|
2361
|
+
* @example
|
|
2362
|
+
* const resolved = resolveOptions(operationNode, { options, exclude, include, override })
|
|
2363
|
+
* if (!resolved) return // excluded
|
|
2364
|
+
*/
|
|
2365
|
+
function resolveOptions(node, { options, exclude = [], include, override = [] }) {
|
|
2366
|
+
if (isOperationNode(node)) {
|
|
2367
|
+
if (exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
|
|
2368
|
+
if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
|
|
2369
|
+
const overrideOptions = override.find(({ type, pattern }) => matchesOperationPattern(node, type, pattern))?.options;
|
|
2370
|
+
return {
|
|
2371
|
+
...options,
|
|
2372
|
+
...overrideOptions
|
|
2373
|
+
};
|
|
2374
|
+
}
|
|
2375
|
+
if (isSchemaNode(node)) {
|
|
2376
|
+
if (exclude.some(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)) return null;
|
|
2377
|
+
if (include) {
|
|
2378
|
+
const applicable = include.map(({ type, pattern }) => matchesSchemaPattern(node, type, pattern)).filter((r) => r !== null);
|
|
2379
|
+
if (applicable.length > 0 && !applicable.includes(true)) return null;
|
|
2380
|
+
}
|
|
2381
|
+
const overrideOptions = override.find(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)?.options;
|
|
2382
|
+
return {
|
|
2383
|
+
...options,
|
|
2384
|
+
...overrideOptions
|
|
2385
|
+
};
|
|
2386
|
+
}
|
|
2387
|
+
return options;
|
|
2388
|
+
}
|
|
2389
|
+
//#endregion
|
|
2390
|
+
export { AsyncEventEmitter, FunctionParams, PackageManager, PluginManager, PromiseManager, URLPath, build, build as default, defineAdapter, defineConfig, defineGenerator, defineLogger, definePlugin, definePrinter, defineStorage, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, isInputPath, linters, logLevel, memoryStorage, resolveOptions, safeBuild, setup };
|
|
2306
2391
|
|
|
2307
2392
|
//# sourceMappingURL=index.js.map
|