@kubb/core 5.0.0-alpha.20 → 5.0.0-alpha.21
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/{PluginDriver-BkSenc-R.d.ts → PluginDriver-CEQPafXV.d.ts} +271 -104
- package/dist/hooks.cjs +7 -94
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +6 -79
- package/dist/hooks.js +6 -91
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +313 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +260 -24
- package/dist/index.js +308 -33
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/defineBuilder.ts +26 -0
- package/src/defineGenerator.ts +3 -0
- package/src/definePreset.ts +9 -5
- package/src/defineResolver.ts +333 -16
- package/src/hooks/index.ts +1 -2
- package/src/hooks/{usePluginDriver.ts → useDriver.ts} +1 -4
- package/src/hooks/useMode.ts +1 -1
- package/src/hooks/usePlugin.ts +1 -1
- package/src/index.ts +10 -1
- package/src/renderNode.tsx +10 -13
- package/src/types.ts +204 -16
- package/src/utils/getBarrelFiles.ts +1 -1
- package/src/utils/getPreset.ts +17 -6
- package/src/hooks/useKubb.ts +0 -160
package/dist/index.cjs
CHANGED
|
@@ -1469,7 +1469,7 @@ const fsStorage = createStorage(() => ({
|
|
|
1469
1469
|
}));
|
|
1470
1470
|
//#endregion
|
|
1471
1471
|
//#region package.json
|
|
1472
|
-
var version = "5.0.0-alpha.
|
|
1472
|
+
var version = "5.0.0-alpha.21";
|
|
1473
1473
|
//#endregion
|
|
1474
1474
|
//#region src/utils/diagnostics.ts
|
|
1475
1475
|
/**
|
|
@@ -1857,6 +1857,26 @@ function createPlugin(build) {
|
|
|
1857
1857
|
return (options) => build(options ?? {});
|
|
1858
1858
|
}
|
|
1859
1859
|
//#endregion
|
|
1860
|
+
//#region src/defineBuilder.ts
|
|
1861
|
+
/**
|
|
1862
|
+
* Defines a builder for a plugin — a named collection of schema-building helpers that
|
|
1863
|
+
* can be exported alongside the plugin and imported by other plugins or generators.
|
|
1864
|
+
*
|
|
1865
|
+
* @example
|
|
1866
|
+
* export const builder = defineBuilder<PluginTs>(() => ({
|
|
1867
|
+
* name: 'default',
|
|
1868
|
+
* buildParamsSchema({ params, node, resolver }) {
|
|
1869
|
+
* return createSchema({ type: 'object', properties: [] })
|
|
1870
|
+
* },
|
|
1871
|
+
* buildDataSchemaNode({ node, resolver }) {
|
|
1872
|
+
* return createSchema({ type: 'object', properties: [] })
|
|
1873
|
+
* },
|
|
1874
|
+
* }))
|
|
1875
|
+
*/
|
|
1876
|
+
function defineBuilder(build) {
|
|
1877
|
+
return build();
|
|
1878
|
+
}
|
|
1879
|
+
//#endregion
|
|
1860
1880
|
//#region src/defineGenerator.ts
|
|
1861
1881
|
function defineGenerator(generator) {
|
|
1862
1882
|
if (generator.type === "react") return {
|
|
@@ -1906,8 +1926,8 @@ function defineLogger(logger) {
|
|
|
1906
1926
|
//#endregion
|
|
1907
1927
|
//#region src/definePreset.ts
|
|
1908
1928
|
/**
|
|
1909
|
-
* Creates a typed preset object that bundles a name, resolvers,
|
|
1910
|
-
* transformers — the building block for composable plugin presets.
|
|
1929
|
+
* Creates a typed preset object that bundles a name, resolvers, optional
|
|
1930
|
+
* transformers, and optional generators — the building block for composable plugin presets.
|
|
1911
1931
|
*
|
|
1912
1932
|
* @example
|
|
1913
1933
|
* import { definePreset } from '@kubb/core'
|
|
@@ -1918,12 +1938,17 @@ function defineLogger(logger) {
|
|
|
1918
1938
|
* @example
|
|
1919
1939
|
* // With custom transformers
|
|
1920
1940
|
* export const myPreset = definePreset('myPreset', { resolvers: [resolverTsLegacy], transformers: [myTransformer] })
|
|
1941
|
+
*
|
|
1942
|
+
* @example
|
|
1943
|
+
* // With generators
|
|
1944
|
+
* export const myPreset = definePreset('myPreset', { resolvers: [resolverTsLegacy], generators: [typeGeneratorLegacy] })
|
|
1921
1945
|
*/
|
|
1922
|
-
function definePreset(name, { resolvers, transformers }) {
|
|
1946
|
+
function definePreset(name, { resolvers, transformers, generators }) {
|
|
1923
1947
|
return {
|
|
1924
1948
|
name,
|
|
1925
1949
|
resolvers,
|
|
1926
|
-
transformers
|
|
1950
|
+
transformers,
|
|
1951
|
+
generators
|
|
1927
1952
|
};
|
|
1928
1953
|
}
|
|
1929
1954
|
//#endregion
|
|
@@ -1958,6 +1983,7 @@ function matchesOperationPattern(node, type, pattern) {
|
|
|
1958
1983
|
}
|
|
1959
1984
|
/**
|
|
1960
1985
|
* Checks if a schema matches a pattern for a given filter type (`schemaName`).
|
|
1986
|
+
*
|
|
1961
1987
|
* Returns `null` when the filter type doesn't apply to schemas.
|
|
1962
1988
|
*/
|
|
1963
1989
|
function matchesSchemaPattern(node, type, pattern) {
|
|
@@ -1967,7 +1993,11 @@ function matchesSchemaPattern(node, type, pattern) {
|
|
|
1967
1993
|
}
|
|
1968
1994
|
}
|
|
1969
1995
|
/**
|
|
1970
|
-
* Default name resolver
|
|
1996
|
+
* Default name resolver used by `defineResolver`.
|
|
1997
|
+
*
|
|
1998
|
+
* - `camelCase` for `function` and `file` types.
|
|
1999
|
+
* - `PascalCase` for `type`.
|
|
2000
|
+
* - `camelCase` for everything else.
|
|
1971
2001
|
*/
|
|
1972
2002
|
function defaultResolver(name, type) {
|
|
1973
2003
|
let resolvedName = camelCase(name);
|
|
@@ -1976,8 +2006,27 @@ function defaultResolver(name, type) {
|
|
|
1976
2006
|
return resolvedName;
|
|
1977
2007
|
}
|
|
1978
2008
|
/**
|
|
1979
|
-
* Default option resolver — applies include/exclude filters and merges
|
|
1980
|
-
*
|
|
2009
|
+
* Default option resolver — applies include/exclude filters and merges matching override options.
|
|
2010
|
+
*
|
|
2011
|
+
* Returns `null` when the node is filtered out by an `exclude` rule or not matched by any `include` rule.
|
|
2012
|
+
*
|
|
2013
|
+
* @example Include/exclude filtering
|
|
2014
|
+
* ```ts
|
|
2015
|
+
* const options = defaultResolveOptions(operationNode, {
|
|
2016
|
+
* options: { output: 'types' },
|
|
2017
|
+
* exclude: [{ type: 'tag', pattern: 'internal' }],
|
|
2018
|
+
* })
|
|
2019
|
+
* // → null when node has tag 'internal'
|
|
2020
|
+
* ```
|
|
2021
|
+
*
|
|
2022
|
+
* @example Override merging
|
|
2023
|
+
* ```ts
|
|
2024
|
+
* const options = defaultResolveOptions(operationNode, {
|
|
2025
|
+
* options: { enumType: 'asConst' },
|
|
2026
|
+
* override: [{ type: 'operationId', pattern: 'listPets', options: { enumType: 'enum' } }],
|
|
2027
|
+
* })
|
|
2028
|
+
* // → { enumType: 'enum' } when operationId matches
|
|
2029
|
+
* ```
|
|
1981
2030
|
*/
|
|
1982
2031
|
function defaultResolveOptions(node, { options, exclude = [], include, override = [] }) {
|
|
1983
2032
|
if ((0, _kubb_ast.isOperationNode)(node)) {
|
|
@@ -2004,27 +2053,245 @@ function defaultResolveOptions(node, { options, exclude = [], include, override
|
|
|
2004
2053
|
return options;
|
|
2005
2054
|
}
|
|
2006
2055
|
/**
|
|
2007
|
-
*
|
|
2008
|
-
* Override `default` or `resolveOptions` in the builder to customize the behavior.
|
|
2056
|
+
* Default path resolver used by `defineResolver`.
|
|
2009
2057
|
*
|
|
2010
|
-
*
|
|
2058
|
+
* - Returns the output directory in `single` mode.
|
|
2059
|
+
* - Resolves into a tag- or path-based subdirectory when `group` and a `tag`/`path` value are provided.
|
|
2060
|
+
* - Falls back to a flat `output/baseName` path otherwise.
|
|
2061
|
+
*
|
|
2062
|
+
* A custom `group.name` function overrides the default subdirectory naming.
|
|
2063
|
+
* For `tag` groups the default is `${camelCase(tag)}Controller`.
|
|
2064
|
+
* For `path` groups the default is the first path segment after `/`.
|
|
2065
|
+
*
|
|
2066
|
+
* @example Flat output
|
|
2067
|
+
* ```ts
|
|
2068
|
+
* defaultResolvePath({ baseName: 'petTypes.ts' }, { root: '/src', output: { path: 'types' } })
|
|
2069
|
+
* // → '/src/types/petTypes.ts'
|
|
2070
|
+
* ```
|
|
2071
|
+
*
|
|
2072
|
+
* @example Tag-based grouping
|
|
2073
|
+
* ```ts
|
|
2074
|
+
* defaultResolvePath(
|
|
2075
|
+
* { baseName: 'petTypes.ts', tag: 'pets' },
|
|
2076
|
+
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
2077
|
+
* )
|
|
2078
|
+
* // → '/src/types/petsController/petTypes.ts'
|
|
2079
|
+
* ```
|
|
2080
|
+
*
|
|
2081
|
+
* @example Path-based grouping
|
|
2082
|
+
* ```ts
|
|
2083
|
+
* defaultResolvePath(
|
|
2084
|
+
* { baseName: 'petTypes.ts', path: '/pets/list' },
|
|
2085
|
+
* { root: '/src', output: { path: 'types' }, group: { type: 'path' } },
|
|
2086
|
+
* )
|
|
2087
|
+
* // → '/src/types/pets/petTypes.ts'
|
|
2088
|
+
* ```
|
|
2089
|
+
*
|
|
2090
|
+
* @example Single-file mode
|
|
2091
|
+
* ```ts
|
|
2092
|
+
* defaultResolvePath(
|
|
2093
|
+
* { baseName: 'petTypes.ts', pathMode: 'single' },
|
|
2094
|
+
* { root: '/src', output: { path: 'types' } },
|
|
2095
|
+
* )
|
|
2096
|
+
* // → '/src/types'
|
|
2097
|
+
* ```
|
|
2098
|
+
*/
|
|
2099
|
+
function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }, { root, output, group }) {
|
|
2100
|
+
if ((pathMode ?? getMode(node_path.default.resolve(root, output.path))) === "single") return node_path.default.resolve(root, output.path);
|
|
2101
|
+
if (group && (groupPath || tag)) {
|
|
2102
|
+
const groupName = group.name ? group.name : (ctx) => {
|
|
2103
|
+
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
2104
|
+
return `${camelCase(ctx.group)}Controller`;
|
|
2105
|
+
};
|
|
2106
|
+
return node_path.default.resolve(root, output.path, groupName({ group: group.type === "path" ? groupPath : tag }), baseName);
|
|
2107
|
+
}
|
|
2108
|
+
return node_path.default.resolve(root, output.path, baseName);
|
|
2109
|
+
}
|
|
2110
|
+
/**
|
|
2111
|
+
* Default file resolver used by `defineResolver`.
|
|
2112
|
+
*
|
|
2113
|
+
* Resolves a `KubbFile.File` by combining name resolution (`resolver.default`) with
|
|
2114
|
+
* path resolution (`resolver.resolvePath`). The resolved file always has empty
|
|
2115
|
+
* `sources`, `imports`, and `exports` arrays — consumers populate those separately.
|
|
2116
|
+
*
|
|
2117
|
+
* In `single` mode the name is omitted and the file sits directly in the output directory.
|
|
2118
|
+
*
|
|
2119
|
+
* @example Resolve a schema file
|
|
2120
|
+
* ```ts
|
|
2121
|
+
* const file = defaultResolveFile.call(resolver,
|
|
2122
|
+
* { name: 'pet', extname: '.ts' },
|
|
2123
|
+
* { root: '/src', output: { path: 'types' } },
|
|
2124
|
+
* )
|
|
2125
|
+
* // → { baseName: 'pet.ts', path: '/src/types/pet.ts', sources: [], ... }
|
|
2126
|
+
* ```
|
|
2127
|
+
*
|
|
2128
|
+
* @example Resolve an operation file with tag grouping
|
|
2129
|
+
* ```ts
|
|
2130
|
+
* const file = defaultResolveFile.call(resolver,
|
|
2131
|
+
* { name: 'listPets', extname: '.ts', tag: 'pets' },
|
|
2132
|
+
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
2133
|
+
* )
|
|
2134
|
+
* // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
|
|
2135
|
+
* ```
|
|
2136
|
+
*/
|
|
2137
|
+
function defaultResolveFile({ name, extname, tag, path: groupPath }, context) {
|
|
2138
|
+
const pathMode = getMode(node_path.default.resolve(context.root, context.output.path));
|
|
2139
|
+
const baseName = `${pathMode === "single" ? "" : this.default(name, "file")}${extname}`;
|
|
2140
|
+
const filePath = this.resolvePath({
|
|
2141
|
+
baseName,
|
|
2142
|
+
pathMode,
|
|
2143
|
+
tag,
|
|
2144
|
+
path: groupPath
|
|
2145
|
+
}, context);
|
|
2146
|
+
return {
|
|
2147
|
+
path: filePath,
|
|
2148
|
+
baseName: node_path.default.basename(filePath),
|
|
2149
|
+
meta: { pluginName: this.pluginName },
|
|
2150
|
+
sources: [],
|
|
2151
|
+
imports: [],
|
|
2152
|
+
exports: []
|
|
2153
|
+
};
|
|
2154
|
+
}
|
|
2155
|
+
/**
|
|
2156
|
+
* Generates the default "Generated by Kubb" banner from config and optional node metadata.
|
|
2157
|
+
*/
|
|
2158
|
+
function buildDefaultBanner({ title, description, version, config }) {
|
|
2159
|
+
try {
|
|
2160
|
+
let source = "";
|
|
2161
|
+
if (Array.isArray(config.input)) {
|
|
2162
|
+
const first = config.input[0];
|
|
2163
|
+
if (first && "path" in first) source = node_path.default.basename(first.path);
|
|
2164
|
+
} else if ("path" in config.input) source = node_path.default.basename(config.input.path);
|
|
2165
|
+
else if ("data" in config.input) source = "text content";
|
|
2166
|
+
let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
|
|
2167
|
+
if (config.output.defaultBanner === "simple") {
|
|
2168
|
+
banner += "*/\n";
|
|
2169
|
+
return banner;
|
|
2170
|
+
}
|
|
2171
|
+
if (source) banner += `* Source: ${source}\n`;
|
|
2172
|
+
if (title) banner += `* Title: ${title}\n`;
|
|
2173
|
+
if (description) {
|
|
2174
|
+
const formattedDescription = description.replace(/\n/gm, "\n* ");
|
|
2175
|
+
banner += `* Description: ${formattedDescription}\n`;
|
|
2176
|
+
}
|
|
2177
|
+
if (version) banner += `* OpenAPI spec version: ${version}\n`;
|
|
2178
|
+
banner += "*/\n";
|
|
2179
|
+
return banner;
|
|
2180
|
+
} catch (_error) {
|
|
2181
|
+
return "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/";
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
/**
|
|
2185
|
+
* Default banner resolver — returns the banner string for a generated file.
|
|
2186
|
+
*
|
|
2187
|
+
* - When `output.banner` is a function and `node` is provided, calls it with the node.
|
|
2188
|
+
* - When `output.banner` is a function and `node` is absent, falls back to the default Kubb banner.
|
|
2189
|
+
* - When `output.banner` is a string, returns it directly.
|
|
2190
|
+
* - When `config.output.defaultBanner` is `false`, returns `undefined`.
|
|
2191
|
+
* - Otherwise returns the default "Generated by Kubb" banner.
|
|
2192
|
+
*
|
|
2193
|
+
* @example String banner
|
|
2194
|
+
* ```ts
|
|
2195
|
+
* defaultResolveBanner(undefined, { output: { banner: '// my banner' }, config })
|
|
2196
|
+
* // → '// my banner'
|
|
2197
|
+
* ```
|
|
2198
|
+
*
|
|
2199
|
+
* @example Function banner with node
|
|
2200
|
+
* ```ts
|
|
2201
|
+
* defaultResolveBanner(rootNode, { output: { banner: (node) => `// v${node.version}` }, config })
|
|
2202
|
+
* // → '// v3.0.0'
|
|
2203
|
+
* ```
|
|
2204
|
+
*
|
|
2205
|
+
* @example Disabled banner
|
|
2206
|
+
* ```ts
|
|
2207
|
+
* defaultResolveBanner(undefined, { config: { output: { defaultBanner: false }, ...config } })
|
|
2208
|
+
* // → undefined
|
|
2209
|
+
* ```
|
|
2210
|
+
*/
|
|
2211
|
+
function defaultResolveBanner(node, { output, config }) {
|
|
2212
|
+
if (typeof output?.banner === "function") return node ? output.banner(node) : buildDefaultBanner({ config });
|
|
2213
|
+
if (typeof output?.banner === "string") return output.banner;
|
|
2214
|
+
if (config.output.defaultBanner === false) return;
|
|
2215
|
+
return buildDefaultBanner({ config });
|
|
2216
|
+
}
|
|
2217
|
+
/**
|
|
2218
|
+
* Default footer resolver — returns the footer string for a generated file.
|
|
2219
|
+
*
|
|
2220
|
+
* - When `output.footer` is a function and `node` is provided, calls it with the node.
|
|
2221
|
+
* - When `output.footer` is a function and `node` is absent, returns `undefined`.
|
|
2222
|
+
* - When `output.footer` is a string, returns it directly.
|
|
2223
|
+
* - Otherwise returns `undefined`.
|
|
2224
|
+
*
|
|
2225
|
+
* @example String footer
|
|
2226
|
+
* ```ts
|
|
2227
|
+
* defaultResolveFooter(undefined, { output: { footer: '// end of file' }, config })
|
|
2228
|
+
* // → '// end of file'
|
|
2229
|
+
* ```
|
|
2230
|
+
*
|
|
2231
|
+
* @example Function footer with node
|
|
2232
|
+
* ```ts
|
|
2233
|
+
* defaultResolveFooter(rootNode, { output: { footer: (node) => `// ${node.title}` }, config })
|
|
2234
|
+
* // → '// Pet Store'
|
|
2235
|
+
* ```
|
|
2236
|
+
*/
|
|
2237
|
+
function defaultResolveFooter(node, { output }) {
|
|
2238
|
+
if (typeof output?.footer === "function") return node ? output.footer(node) : void 0;
|
|
2239
|
+
if (typeof output?.footer === "string") return output.footer;
|
|
2240
|
+
}
|
|
2241
|
+
/**
|
|
2242
|
+
* Defines a resolver for a plugin, injecting built-in defaults for name casing,
|
|
2243
|
+
* include/exclude/override filtering, path resolution, and file construction.
|
|
2244
|
+
*
|
|
2245
|
+
* All four defaults can be overridden by providing them in the builder function:
|
|
2246
|
+
* - `default` — name casing strategy (camelCase / PascalCase)
|
|
2247
|
+
* - `resolveOptions` — include/exclude/override filtering
|
|
2248
|
+
* - `resolvePath` — output path computation
|
|
2249
|
+
* - `resolveFile` — full `KubbFile.File` construction
|
|
2250
|
+
*
|
|
2251
|
+
* Methods in the builder have access to `this` (the full resolver object), so they
|
|
2252
|
+
* can call other resolver methods without circular imports.
|
|
2253
|
+
*
|
|
2254
|
+
* @example Basic resolver with naming helpers
|
|
2255
|
+
* ```ts
|
|
2011
2256
|
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
2012
2257
|
* name: 'default',
|
|
2013
|
-
* resolveName(
|
|
2014
|
-
* return this.default(name, 'function')
|
|
2258
|
+
* resolveName(node) {
|
|
2259
|
+
* return this.default(node.name, 'function')
|
|
2260
|
+
* },
|
|
2261
|
+
* resolveTypedName(node) {
|
|
2262
|
+
* return this.default(node.name, 'type')
|
|
2015
2263
|
* },
|
|
2016
|
-
*
|
|
2017
|
-
*
|
|
2264
|
+
* }))
|
|
2265
|
+
* ```
|
|
2266
|
+
*
|
|
2267
|
+
* @example Override resolvePath for a custom output structure
|
|
2268
|
+
* ```ts
|
|
2269
|
+
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
2270
|
+
* name: 'custom',
|
|
2271
|
+
* resolvePath({ baseName }, { root, output }) {
|
|
2272
|
+
* return path.resolve(root, output.path, 'generated', baseName)
|
|
2018
2273
|
* },
|
|
2274
|
+
* }))
|
|
2275
|
+
* ```
|
|
2276
|
+
*
|
|
2277
|
+
* @example Use this.default inside a helper
|
|
2278
|
+
* ```ts
|
|
2279
|
+
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
2280
|
+
* name: 'default',
|
|
2019
2281
|
* resolveParamName(node, param) {
|
|
2020
|
-
* return this.
|
|
2282
|
+
* return this.default(`${node.operationId} ${param.in} ${param.name}`, 'type')
|
|
2021
2283
|
* },
|
|
2022
2284
|
* }))
|
|
2285
|
+
* ```
|
|
2023
2286
|
*/
|
|
2024
2287
|
function defineResolver(build) {
|
|
2025
2288
|
return {
|
|
2026
2289
|
default: defaultResolver,
|
|
2027
2290
|
resolveOptions: defaultResolveOptions,
|
|
2291
|
+
resolvePath: defaultResolvePath,
|
|
2292
|
+
resolveFile: defaultResolveFile,
|
|
2293
|
+
resolveBanner: defaultResolveBanner,
|
|
2294
|
+
resolveFooter: defaultResolveFooter,
|
|
2028
2295
|
...build()
|
|
2029
2296
|
};
|
|
2030
2297
|
}
|
|
@@ -2034,13 +2301,17 @@ function defineResolver(build) {
|
|
|
2034
2301
|
* Renders a React component for a list of operation nodes (V2 generators).
|
|
2035
2302
|
*/
|
|
2036
2303
|
async function renderOperations(nodes, options) {
|
|
2037
|
-
const { config, fabric, plugin, Component, adapter } = options;
|
|
2304
|
+
const { config, fabric, plugin, Component, driver, adapter } = options;
|
|
2038
2305
|
if (!Component) return;
|
|
2039
2306
|
const fabricChild = (0, _kubb_react_fabric.createReactFabric)();
|
|
2040
2307
|
await fabricChild.render(/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Fabric, {
|
|
2041
|
-
meta: {
|
|
2308
|
+
meta: {
|
|
2309
|
+
plugin,
|
|
2310
|
+
driver
|
|
2311
|
+
},
|
|
2042
2312
|
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Component, {
|
|
2043
2313
|
config,
|
|
2314
|
+
plugin,
|
|
2044
2315
|
adapter,
|
|
2045
2316
|
nodes,
|
|
2046
2317
|
options: options.options
|
|
@@ -2053,17 +2324,17 @@ async function renderOperations(nodes, options) {
|
|
|
2053
2324
|
* Renders a React component for a single operation node (V2 generators).
|
|
2054
2325
|
*/
|
|
2055
2326
|
async function renderOperation(node, options) {
|
|
2056
|
-
const { config, fabric, plugin, Component, adapter, driver
|
|
2327
|
+
const { config, fabric, plugin, Component, adapter, driver } = options;
|
|
2057
2328
|
if (!Component) return;
|
|
2058
2329
|
const fabricChild = (0, _kubb_react_fabric.createReactFabric)();
|
|
2059
2330
|
await fabricChild.render(/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Fabric, {
|
|
2060
2331
|
meta: {
|
|
2061
2332
|
plugin,
|
|
2062
|
-
driver
|
|
2063
|
-
mode
|
|
2333
|
+
driver
|
|
2064
2334
|
},
|
|
2065
2335
|
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Component, {
|
|
2066
2336
|
config,
|
|
2337
|
+
plugin,
|
|
2067
2338
|
adapter,
|
|
2068
2339
|
node,
|
|
2069
2340
|
options: options.options
|
|
@@ -2076,17 +2347,17 @@ async function renderOperation(node, options) {
|
|
|
2076
2347
|
* Renders a React component for a single schema node (V2 generators).
|
|
2077
2348
|
*/
|
|
2078
2349
|
async function renderSchema(node, options) {
|
|
2079
|
-
const { config, fabric, plugin, Component, adapter, driver
|
|
2350
|
+
const { config, fabric, plugin, Component, adapter, driver } = options;
|
|
2080
2351
|
if (!Component) return;
|
|
2081
2352
|
const fabricChild = (0, _kubb_react_fabric.createReactFabric)();
|
|
2082
2353
|
await fabricChild.render(/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Fabric, {
|
|
2083
2354
|
meta: {
|
|
2084
2355
|
plugin,
|
|
2085
|
-
driver
|
|
2086
|
-
mode
|
|
2356
|
+
driver
|
|
2087
2357
|
},
|
|
2088
2358
|
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Component, {
|
|
2089
2359
|
config,
|
|
2360
|
+
plugin,
|
|
2090
2361
|
adapter,
|
|
2091
2362
|
node,
|
|
2092
2363
|
options: options.options
|
|
@@ -2407,7 +2678,7 @@ function buildDirectoryTree(files, rootFolder = "") {
|
|
|
2407
2678
|
function getBarrelFilesByRoot(root, files) {
|
|
2408
2679
|
const cachedFiles = /* @__PURE__ */ new Map();
|
|
2409
2680
|
TreeNode.build(files, root)?.forEach((treeNode) => {
|
|
2410
|
-
if (!treeNode
|
|
2681
|
+
if (!treeNode?.children || !treeNode.parent?.data.path) return;
|
|
2411
2682
|
const barrelFile = {
|
|
2412
2683
|
path: (0, node_path.join)(treeNode.parent?.data.path, "index.ts"),
|
|
2413
2684
|
baseName: "index.ts",
|
|
@@ -2505,21 +2776,25 @@ function mergeResolvers(...resolvers) {
|
|
|
2505
2776
|
//#endregion
|
|
2506
2777
|
//#region src/utils/getPreset.ts
|
|
2507
2778
|
/**
|
|
2508
|
-
* Resolves a named preset into merged resolvers and
|
|
2779
|
+
* Resolves a named preset into merged resolvers, transformers, and generators.
|
|
2509
2780
|
*
|
|
2510
|
-
* - Merges the preset's resolvers on top of the first (default)
|
|
2781
|
+
* - Merges the preset's resolvers on top of the first (default)
|
|
2511
2782
|
* - Merges any additional user-supplied resolvers on top of that to produce the final `resolver`.
|
|
2512
2783
|
* - Concatenates preset transformers before user-supplied transformers.
|
|
2784
|
+
* - Combines preset generators with user-supplied generators; falls back to the `default` preset's generators when neither provides any.
|
|
2513
2785
|
*/
|
|
2514
2786
|
function getPreset(params) {
|
|
2515
|
-
const { preset: presetName, presets, resolvers, transformers: userTransformers } = params;
|
|
2787
|
+
const { preset: presetName, presets, resolvers, transformers: userTransformers, generators: userGenerators } = params;
|
|
2516
2788
|
const [defaultResolver, ...userResolvers] = resolvers;
|
|
2517
2789
|
const preset = presets[presetName];
|
|
2518
|
-
const
|
|
2790
|
+
const resolver = mergeResolvers(mergeResolvers(defaultResolver, ...preset?.resolvers ?? []), ...userResolvers ?? []);
|
|
2791
|
+
const transformers = [...preset?.transformers ?? [], ...userTransformers ?? []];
|
|
2792
|
+
const presetGenerators = preset?.generators ?? [];
|
|
2793
|
+
const defaultPresetGenerators = presets["default"]?.generators ?? [];
|
|
2519
2794
|
return {
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2795
|
+
resolver,
|
|
2796
|
+
transformers,
|
|
2797
|
+
generators: presetGenerators.length > 0 || userGenerators.length ? [...presetGenerators, ...userGenerators] : defaultPresetGenerators,
|
|
2523
2798
|
preset
|
|
2524
2799
|
};
|
|
2525
2800
|
}
|
|
@@ -2611,11 +2886,17 @@ exports.FunctionParams = FunctionParams;
|
|
|
2611
2886
|
exports.PluginDriver = PluginDriver;
|
|
2612
2887
|
exports.URLPath = URLPath;
|
|
2613
2888
|
exports.build = build;
|
|
2889
|
+
exports.buildDefaultBanner = buildDefaultBanner;
|
|
2614
2890
|
exports.createAdapter = createAdapter;
|
|
2615
2891
|
exports.createPlugin = createPlugin;
|
|
2616
2892
|
exports.createStorage = createStorage;
|
|
2617
2893
|
exports.default = build;
|
|
2894
|
+
exports.defaultResolveBanner = defaultResolveBanner;
|
|
2895
|
+
exports.defaultResolveFile = defaultResolveFile;
|
|
2896
|
+
exports.defaultResolveFooter = defaultResolveFooter;
|
|
2618
2897
|
exports.defaultResolveOptions = defaultResolveOptions;
|
|
2898
|
+
exports.defaultResolvePath = defaultResolvePath;
|
|
2899
|
+
exports.defineBuilder = defineBuilder;
|
|
2619
2900
|
exports.defineConfig = defineConfig;
|
|
2620
2901
|
exports.defineGenerator = defineGenerator;
|
|
2621
2902
|
exports.defineLogger = defineLogger;
|