@kubb/kit 5.7.0 → 5.8.0
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/README.md +13 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/options.cjs +140 -0
- package/dist/options.cjs.map +1 -0
- package/dist/options.d.ts +253 -0
- package/dist/options.js +127 -0
- package/dist/options.js.map +1 -0
- package/dist/rolldown-runtime-qbf5tadS.cjs +38 -0
- package/package.json +18 -4
package/README.md
CHANGED
|
@@ -77,6 +77,19 @@ Rounding out the package are the option and hook types every plugin, generator,
|
|
|
77
77
|
import { createMockedPlugin, renderGeneratorSchema } from 'kubb/kit/testing'
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
+
## Options schemas
|
|
81
|
+
|
|
82
|
+
`@kubb/kit/options` holds Zod schemas for the options most plugins share (`outputOptionsSchema`, `includeSchema`, `excludeSchema`, `overrideSchema`, `resolverSchema`, `macrosSchema`), plus `suggest()` for an open string with suggested values and `when()` for an option that only applies when another option matches. Install `zod` 4 to use it. The main `@kubb/kit` import never pulls in Zod.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { excludeSchema, outputOptionsSchema, suggest } from '@kubb/kit/options'
|
|
86
|
+
|
|
87
|
+
const optionsSchema = outputOptionsSchema.extend({
|
|
88
|
+
exclude: excludeSchema.optional(),
|
|
89
|
+
importPath: suggest(['zod', 'zod/mini']).optional(),
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
80
93
|
## Why a separate package from `@kubb/core`
|
|
81
94
|
|
|
82
95
|
`@kubb/core` also runs the build engine: the plugin driver, the file manager, and the CLI reporters. None of that is part of authoring a plugin. `@kubb/kit` keeps the two apart, the same way the surrounding `kubb/ast` and `kubb/jsx` subpaths separate the AST layer and the JSX renderer from the engine that drives them.
|
package/dist/index.cjs
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
2
|
import { SchemaNode, ast, ast as ast$1 } from "@kubb/ast";
|
|
3
|
-
import { Adapter, AdapterFactoryOptions, AdapterSource, BannerMeta, Config, Diagnostic, Diagnostics, Exclude, ExtensionDependencies, ExtensionDependency, ExtensionDependencyRecord, ExtensionFactory, ExtensionKind, ExtensionMeta, Generator as Generator$1, GeneratorContext, Group, Hookable, Include, KubbHooks, KubbPluginEndContext, KubbPluginSetupContext, KubbPluginStartContext, NodeCache, NormalizedPlugin, Output, OutputOptions, Override, Parser, ParserDefinition, ParserFactory, Plugin, PluginDefinition, PluginFactory, PluginFactoryOptions, PluginType, Renderer, RendererFactory, ResolveFileOptions, ResolveImportsOptions, ResolvePathOptions, Resolver, ResolverFile, ResolverFileParams, ResolverFilePathParams, ResolverPatch, Storage, addGenerator, addMacro, assertPluginOption, createAdapter, createRenderer, createResolver, createStorage, defineGenerator, defineParser, definePlugin, fsStorage, injectFile, kubbContext, memoryStorage, requirePlugin, setMacros, setOptions, setResolver, tryUseKubb, useConfig, useKubb, useOptions } from "@kubb/core";
|
|
3
|
+
import { Adapter, AdapterFactoryOptions, AdapterSource, BannerMeta, Config, Diagnostic, Diagnostics, Exclude, ExtensionDependencies, ExtensionDependency, ExtensionDependencyRecord, ExtensionFactory, ExtensionKind, ExtensionMeta, Generator as Generator$1, GeneratorContext, Group, Hookable, Include, KubbHooks, KubbPluginEndContext, KubbPluginSetupContext, KubbPluginStartContext, NodeCache, NormalizedPlugin, Output, OutputOptions, Override, Parser, ParserDefinition, ParserFactory, Plugin, PluginDefinition, PluginFactory, PluginFactoryOptions, PluginOptions, PluginType, Renderer, RendererFactory, ResolveFileOptions, ResolveImportsOptions, ResolvePathOptions, Resolver, ResolverFile, ResolverFileParams, ResolverFilePathParams, ResolverPatch, StandardSchemaV1, Storage, addGenerator, addMacro, assertPluginOption, createAdapter, createRenderer, createResolver, createStorage, defineGenerator, defineParser, definePlugin, fsStorage, injectFile, kubbContext, memoryStorage, requirePlugin, setMacros, setOptions, setResolver, tryUseKubb, useConfig, useKubb, useOptions } from "@kubb/core";
|
|
4
4
|
//#region src/Url.d.ts
|
|
5
5
|
type URLObject = {
|
|
6
6
|
/**
|
|
@@ -232,5 +232,5 @@ export declare function containsCircularRef(node: SchemaNode | undefined, { circ
|
|
|
232
232
|
excludeName?: string;
|
|
233
233
|
}): boolean;
|
|
234
234
|
//#endregion
|
|
235
|
-
export { type Adapter, type AdapterFactoryOptions, type AdapterSource, type BannerMeta, type Config, type Diagnostic, Diagnostics, type Exclude, type ExtensionDependencies, type ExtensionDependency, type ExtensionDependencyRecord, type ExtensionFactory, type ExtensionKind, type ExtensionMeta, type Generator$1 as Generator, type GeneratorContext, type Group, Hookable, type Include, type KubbHooks, type KubbPluginEndContext, type KubbPluginSetupContext, type KubbPluginStartContext, type NodeCache, type NormalizedPlugin, type Output, type OutputOptions, type Override, type Parser, type ParserDefinition, type ParserFactory, type Plugin, type PluginDefinition, type PluginFactory, type PluginFactoryOptions, type PluginType, type Renderer, type RendererFactory, type ResolveFileOptions, type ResolveImportsOptions, type ResolvePathOptions, Resolver, type ResolverFile, type ResolverFileParams, type ResolverFilePathParams, type ResolverPatch, type Storage, addGenerator, addMacro, assertPluginOption, ast, createAdapter, createRenderer, createResolver, createStorage, defineGenerator, defineParser, definePlugin, fsStorage, injectFile, kubbContext, memoryStorage, requirePlugin, setMacros, setOptions, setResolver, tryUseKubb, useConfig, useKubb, useOptions };
|
|
235
|
+
export { type Adapter, type AdapterFactoryOptions, type AdapterSource, type BannerMeta, type Config, type Diagnostic, Diagnostics, type Exclude, type ExtensionDependencies, type ExtensionDependency, type ExtensionDependencyRecord, type ExtensionFactory, type ExtensionKind, type ExtensionMeta, type Generator$1 as Generator, type GeneratorContext, type Group, Hookable, type Include, type KubbHooks, type KubbPluginEndContext, type KubbPluginSetupContext, type KubbPluginStartContext, type NodeCache, type NormalizedPlugin, type Output, type OutputOptions, type Override, type Parser, type ParserDefinition, type ParserFactory, type Plugin, type PluginDefinition, type PluginFactory, type PluginFactoryOptions, type PluginOptions, type PluginType, type Renderer, type RendererFactory, type ResolveFileOptions, type ResolveImportsOptions, type ResolvePathOptions, Resolver, type ResolverFile, type ResolverFileParams, type ResolverFilePathParams, type ResolverPatch, type StandardSchemaV1, type Storage, addGenerator, addMacro, assertPluginOption, ast, createAdapter, createRenderer, createResolver, createStorage, defineGenerator, defineParser, definePlugin, fsStorage, injectFile, kubbContext, memoryStorage, requirePlugin, setMacros, setOptions, setResolver, tryUseKubb, useConfig, useKubb, useOptions };
|
|
236
236
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/options.cjs
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-qbf5tadS.cjs");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
5
|
+
let zod = require("zod");
|
|
6
|
+
zod = require_rolldown_runtime.__toESM(zod, 1);
|
|
7
|
+
//#region src/options.ts
|
|
8
|
+
/**
|
|
9
|
+
* Builds `x-kubb-when` metadata for `.meta()`, such as `.meta({ description, ...when({ 'enum.type': 'asConst' }) })`.
|
|
10
|
+
*/
|
|
11
|
+
function when(condition) {
|
|
12
|
+
return { "x-kubb-when": condition };
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Accepts any string while its type autocompletes `values`. JSON Schema lists them as `x-kubb-values`.
|
|
16
|
+
*/
|
|
17
|
+
function suggest(values) {
|
|
18
|
+
return zod.string().meta({ "x-kubb-values": values });
|
|
19
|
+
}
|
|
20
|
+
function functionSchema() {
|
|
21
|
+
return zod.custom((value) => typeof value === "function", { message: "Expected a function" });
|
|
22
|
+
}
|
|
23
|
+
function isObject(value) {
|
|
24
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25
|
+
}
|
|
26
|
+
function isMacro(value) {
|
|
27
|
+
if (!isObject(value) || typeof value.name !== "string") return false;
|
|
28
|
+
return Object.entries(value).every(([key, member]) => key === "name" || key === "enforce" || member === void 0 || typeof member === "function");
|
|
29
|
+
}
|
|
30
|
+
const bannerSchema = zod.union([zod.string(), functionSchema()]);
|
|
31
|
+
/**
|
|
32
|
+
* Mirrors core's `Output`, including `barrel`. The `group` check lives in {@link outputOptionsSchema}.
|
|
33
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#output
|
|
34
|
+
*/
|
|
35
|
+
const outputSchema = zod.object({
|
|
36
|
+
path: zod.string().meta({ description: "Directory where the plugin writes its generated code, resolved against the global `output.path` set on `defineConfig`. With `mode: 'file'`, this is the full output file path and must include the extension (e.g. `'types.ts'`, `'models.py'`)." }),
|
|
37
|
+
mode: zod.enum(["directory", "file"]).meta({ description: "How generated code is consolidated into files. `'file'` writes everything into a single file, `'directory'` writes one file per operation or schema under `path`. Defaults to `'file'` when `path` carries an extension and `'directory'` when it does not." }).optional(),
|
|
38
|
+
banner: bannerSchema.meta({ description: "Text prepended to every generated file. Useful for license headers, lint disables, or `@ts-nocheck` directives. Pass a function to compute the banner from the file's `BannerMeta`." }).optional(),
|
|
39
|
+
footer: bannerSchema.meta({ description: "Text appended at the end of every generated file. Pass a function to compute the footer from the file's `BannerMeta`." }).optional(),
|
|
40
|
+
barrel: zod.union([zod.object({
|
|
41
|
+
type: zod.enum(["all", "named"]).meta({ description: "Export strategy for the plugin's barrel files. `'all'` uses wildcard exports, `'named'` uses explicit exports." }),
|
|
42
|
+
nested: zod.boolean().meta({ description: "Generate an `index.ts` in every sub-directory, each re-exporting only what's directly inside it." }).optional()
|
|
43
|
+
}), zod.literal(false)]).meta({ description: "Barrel configuration for this plugin's output. Set to `{ type: 'named' | 'all' }` to opt into a barrel, or `false` to disable it. Falls back to `config.output.barrel` when omitted." }).optional()
|
|
44
|
+
}).meta({ description: "Output configuration shared by every plugin." });
|
|
45
|
+
/**
|
|
46
|
+
* Mirrors core's `Group`.
|
|
47
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#group
|
|
48
|
+
*/
|
|
49
|
+
const groupSchema = zod.object({
|
|
50
|
+
type: zod.enum(["tag", "path"]).meta({ description: "Property used to assign each operation to a group. `'tag'` uses the first tag, `'path'` uses the first segment of the operation's URL." }),
|
|
51
|
+
name: functionSchema().meta({ description: "Returns the subdirectory name from the group key. Defaults to the camelCased tag for `tag` groups, or the first path segment as written in the spec for `path` groups." }).optional()
|
|
52
|
+
}).meta({ description: "Groups generated files into subdirectories based on an OpenAPI tag or path segment." });
|
|
53
|
+
function refineGroup(options, ctx) {
|
|
54
|
+
if (!options.output || !options.group) return;
|
|
55
|
+
if ((options.output.mode ?? (node_path.default.extname(options.output.path) ? "file" : "directory")) === "file") ctx.addIssue({
|
|
56
|
+
code: "custom",
|
|
57
|
+
path: ["group"],
|
|
58
|
+
message: "A single-file output has nothing to group. Remove the `group` option, give `output.path` an extensionless directory name, or set `output.mode: 'directory'` explicitly."
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* `output` and `group` together. Rejects `group` when `output.mode` resolves to `'file'`. `.extend()` keeps the check.
|
|
63
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#output
|
|
64
|
+
*/
|
|
65
|
+
const outputOptionsSchema = zod.object({
|
|
66
|
+
output: outputSchema.optional(),
|
|
67
|
+
group: groupSchema.optional()
|
|
68
|
+
}).superRefine(refineGroup);
|
|
69
|
+
const patternSchema = zod.union([zod.string(), zod.instanceof(RegExp)]);
|
|
70
|
+
function byPattern(type, typeDescription, patternDescription) {
|
|
71
|
+
return zod.object({
|
|
72
|
+
type: zod.literal(type).meta({ description: typeDescription }),
|
|
73
|
+
pattern: patternSchema.meta({ description: patternDescription })
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Mirrors core's `Filter`: one include, exclude, or override rule.
|
|
78
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#include
|
|
79
|
+
*/
|
|
80
|
+
const filterSchema = zod.discriminatedUnion("type", [
|
|
81
|
+
byPattern("tag", "Filter by OpenAPI `tags` field. Matches one or more tags assigned to operations.", "Tag name to match (case-sensitive). Can be a literal string or regex pattern."),
|
|
82
|
+
byPattern("operationId", "Filter by OpenAPI `operationId` field. Each operation (GET, POST, etc.) has a unique identifier.", "Operation ID to match (case-sensitive). Can be a literal string or regex pattern."),
|
|
83
|
+
byPattern("path", "Filter by OpenAPI `path` (URL endpoint). Useful to group or filter by service segments like `/pets`, `/users`, etc.", "URL path to match (case-sensitive). Can be a literal string or regex pattern. Matches against the full path."),
|
|
84
|
+
zod.object({
|
|
85
|
+
type: zod.literal("method").meta({ description: "Filter by HTTP method." }),
|
|
86
|
+
pattern: zod.union([zod.enum([
|
|
87
|
+
"GET",
|
|
88
|
+
"POST",
|
|
89
|
+
"PUT",
|
|
90
|
+
"PATCH",
|
|
91
|
+
"DELETE",
|
|
92
|
+
"HEAD",
|
|
93
|
+
"OPTIONS",
|
|
94
|
+
"TRACE"
|
|
95
|
+
]), zod.instanceof(RegExp)]).meta({ description: "HTTP method to match, as one of the `HttpMethod` values or a regex." })
|
|
96
|
+
}),
|
|
97
|
+
byPattern("contentType", "Filter by response or request content type: `'application/json'`, `'application/xml'`, etc.", "Content type to match (case-sensitive). Can be a literal string or regex pattern."),
|
|
98
|
+
byPattern("schemaName", "Filter by schema component name (TypeScript or JSON schema). Matches schemas in `#/components/schemas`.", "Schema name to match (case-sensitive). Can be a literal string or regex pattern.")
|
|
99
|
+
]).meta({ description: "Pattern filter that matches operations or schemas by tag, operationId, path, method, content type, or schema name." });
|
|
100
|
+
/**
|
|
101
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#include
|
|
102
|
+
*/
|
|
103
|
+
const includeSchema = zod.array(filterSchema).meta({ description: "Restricts generation to operations or schemas matching at least one entry." });
|
|
104
|
+
/**
|
|
105
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#exclude
|
|
106
|
+
*/
|
|
107
|
+
const excludeSchema = zod.array(filterSchema).meta({ description: "Skips matching operations or schemas during generation." });
|
|
108
|
+
/**
|
|
109
|
+
* Builds the `override` option from a plugin's options schema, with partial `options` and no `override` key.
|
|
110
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#override
|
|
111
|
+
*/
|
|
112
|
+
function overrideSchema(options) {
|
|
113
|
+
const { override: _override, ...shape } = options.shape;
|
|
114
|
+
return zod.array(zod.intersection(filterSchema, zod.object({ options: zod.object(shape).partial().superRefine((options, ctx) => refineGroup(options, ctx)).meta({ description: "Options merged on top of the plugin options when the filter matches." }) }))).meta({ description: "Filters paired with partial options. The first matching entry wins." });
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Mirrors core's `ResolverPatch<T>`.
|
|
118
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#resolver
|
|
119
|
+
*/
|
|
120
|
+
function resolverSchema() {
|
|
121
|
+
return zod.custom((value) => isObject(value) && Object.values(value).every((member) => member === void 0 || typeof member === "function" || isObject(member)), { message: "Expected a resolver object of methods and method namespaces" }).meta({ description: "Partial resolver whose methods replace the plugin's naming and path defaults." });
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#macros
|
|
125
|
+
*/
|
|
126
|
+
const macrosSchema = zod.array(zod.custom(isMacro, { message: "Expected a macro object with a name and function hooks" })).meta({ description: "Named AST transforms that run before the generators." });
|
|
127
|
+
//#endregion
|
|
128
|
+
exports.excludeSchema = excludeSchema;
|
|
129
|
+
exports.filterSchema = filterSchema;
|
|
130
|
+
exports.groupSchema = groupSchema;
|
|
131
|
+
exports.includeSchema = includeSchema;
|
|
132
|
+
exports.macrosSchema = macrosSchema;
|
|
133
|
+
exports.outputOptionsSchema = outputOptionsSchema;
|
|
134
|
+
exports.outputSchema = outputSchema;
|
|
135
|
+
exports.overrideSchema = overrideSchema;
|
|
136
|
+
exports.resolverSchema = resolverSchema;
|
|
137
|
+
exports.suggest = suggest;
|
|
138
|
+
exports.when = when;
|
|
139
|
+
|
|
140
|
+
//# sourceMappingURL=options.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.cjs","names":["z","path"],"sources":["../src/options.ts"],"sourcesContent":["import path from 'node:path'\nimport type { LiteralUnion } from '@internals/utils'\nimport type { HttpMethod, Macro } from '@kubb/ast'\nimport type { BannerMeta, Resolver, ResolverPatch } from '@kubb/core'\nimport * as z from 'zod'\n\n/**\n * A value an option is compared against in a `when` condition.\n */\nexport type WhenValue = string | number | boolean | null\n\n/**\n * Shows an option only when every entry matches. Keys are dotted option paths, such as `'enum.type'`.\n */\nexport type WhenCondition = Record<string, WhenValue | ReadonlyArray<WhenValue>>\n\ndeclare module 'zod' {\n interface GlobalMeta {\n 'x-kubb-when'?: WhenCondition\n 'x-kubb-values'?: ReadonlyArray<string>\n }\n}\n\n/**\n * Builds `x-kubb-when` metadata for `.meta()`, such as `.meta({ description, ...when({ 'enum.type': 'asConst' }) })`.\n */\nexport function when(condition: WhenCondition): { 'x-kubb-when': WhenCondition } {\n return { 'x-kubb-when': condition }\n}\n\n/**\n * Accepts any string while its type autocompletes `values`. JSON Schema lists them as `x-kubb-values`.\n */\nexport function suggest<const TValues extends ReadonlyArray<string>>(values: TValues): z.ZodType<LiteralUnion<TValues[number]>, LiteralUnion<TValues[number]>> {\n return z.string().meta({ 'x-kubb-values': values })\n}\n\n// `z.function()` would wrap user callbacks, so accept any function as written.\nfunction functionSchema<T>() {\n return z.custom<T>((value) => typeof value === 'function', { message: 'Expected a function' })\n}\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction isMacro(value: unknown): boolean {\n if (!isObject(value) || typeof value.name !== 'string') return false\n return Object.entries(value).every(([key, member]) => key === 'name' || key === 'enforce' || member === undefined || typeof member === 'function')\n}\n\nconst bannerSchema = z.union([z.string(), functionSchema<(meta: BannerMeta) => string>()])\n\n/**\n * Mirrors core's `Output`, including `barrel`. The `group` check lives in {@link outputOptionsSchema}.\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#output\n */\nexport const outputSchema = z\n .object({\n path: z.string().meta({\n description:\n \"Directory where the plugin writes its generated code, resolved against the global `output.path` set on `defineConfig`. With `mode: 'file'`, this is the full output file path and must include the extension (e.g. `'types.ts'`, `'models.py'`).\",\n }),\n mode: z\n .enum(['directory', 'file'])\n .meta({\n description:\n \"How generated code is consolidated into files. `'file'` writes everything into a single file, `'directory'` writes one file per operation or schema under `path`. Defaults to `'file'` when `path` carries an extension and `'directory'` when it does not.\",\n })\n .optional(),\n banner: bannerSchema\n .meta({\n description:\n \"Text prepended to every generated file. Useful for license headers, lint disables, or `@ts-nocheck` directives. Pass a function to compute the banner from the file's `BannerMeta`.\",\n })\n .optional(),\n footer: bannerSchema\n .meta({ description: \"Text appended at the end of every generated file. Pass a function to compute the footer from the file's `BannerMeta`.\" })\n .optional(),\n barrel: z\n .union([\n z.object({\n type: z.enum(['all', 'named']).meta({\n description: \"Export strategy for the plugin's barrel files. `'all'` uses wildcard exports, `'named'` uses explicit exports.\",\n }),\n nested: z\n .boolean()\n .meta({ description: \"Generate an `index.ts` in every sub-directory, each re-exporting only what's directly inside it.\" })\n .optional(),\n }),\n z.literal(false),\n ])\n .meta({\n description:\n \"Barrel configuration for this plugin's output. Set to `{ type: 'named' | 'all' }` to opt into a barrel, or `false` to disable it. Falls back to `config.output.barrel` when omitted.\",\n })\n .optional(),\n })\n .meta({ description: 'Output configuration shared by every plugin.' })\n\n/**\n * Mirrors core's `Group`.\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#group\n */\nexport const groupSchema = z\n .object({\n type: z.enum(['tag', 'path']).meta({\n description: \"Property used to assign each operation to a group. `'tag'` uses the first tag, `'path'` uses the first segment of the operation's URL.\",\n }),\n name: functionSchema<(context: { group: string }) => string>()\n .meta({\n description:\n 'Returns the subdirectory name from the group key. Defaults to the camelCased tag for `tag` groups, or the first path segment as written in the spec for `path` groups.',\n })\n .optional(),\n })\n .meta({ description: 'Groups generated files into subdirectories based on an OpenAPI tag or path segment.' })\n\ntype GroupedOptions = { output?: { path: string; mode?: 'directory' | 'file' }; group?: object }\n\nfunction refineGroup(options: GroupedOptions, ctx: z.RefinementCtx): void {\n if (!options.output || !options.group) return\n\n const mode = options.output.mode ?? (path.extname(options.output.path) ? 'file' : 'directory')\n if (mode === 'file') {\n ctx.addIssue({\n code: 'custom',\n path: ['group'],\n message:\n \"A single-file output has nothing to group. Remove the `group` option, give `output.path` an extensionless directory name, or set `output.mode: 'directory'` explicitly.\",\n })\n }\n}\n\n/**\n * `output` and `group` together. Rejects `group` when `output.mode` resolves to `'file'`. `.extend()` keeps the check.\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#output\n */\nexport const outputOptionsSchema = z\n .object({\n output: outputSchema.optional(),\n group: groupSchema.optional(),\n })\n .superRefine(refineGroup)\n\nconst patternSchema = z.union([z.string(), z.instanceof(RegExp)])\n\nfunction byPattern<const TType extends string>(type: TType, typeDescription: string, patternDescription: string) {\n return z.object({\n type: z.literal(type).meta({ description: typeDescription }),\n pattern: patternSchema.meta({ description: patternDescription }),\n })\n}\n\nconst httpMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS', 'TRACE'] as const satisfies ReadonlyArray<HttpMethod>\n\n/**\n * Mirrors core's `Filter`: one include, exclude, or override rule.\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#include\n */\nexport const filterSchema = z\n .discriminatedUnion('type', [\n byPattern(\n 'tag',\n 'Filter by OpenAPI `tags` field. Matches one or more tags assigned to operations.',\n 'Tag name to match (case-sensitive). Can be a literal string or regex pattern.',\n ),\n byPattern(\n 'operationId',\n 'Filter by OpenAPI `operationId` field. Each operation (GET, POST, etc.) has a unique identifier.',\n 'Operation ID to match (case-sensitive). Can be a literal string or regex pattern.',\n ),\n byPattern(\n 'path',\n 'Filter by OpenAPI `path` (URL endpoint). Useful to group or filter by service segments like `/pets`, `/users`, etc.',\n 'URL path to match (case-sensitive). Can be a literal string or regex pattern. Matches against the full path.',\n ),\n z.object({\n type: z.literal('method').meta({ description: 'Filter by HTTP method.' }),\n pattern: z\n .union([z.enum(httpMethods), z.instanceof(RegExp)])\n .meta({ description: 'HTTP method to match, as one of the `HttpMethod` values or a regex.' }),\n }),\n byPattern(\n 'contentType',\n \"Filter by response or request content type: `'application/json'`, `'application/xml'`, etc.\",\n 'Content type to match (case-sensitive). Can be a literal string or regex pattern.',\n ),\n byPattern(\n 'schemaName',\n 'Filter by schema component name (TypeScript or JSON schema). Matches schemas in `#/components/schemas`.',\n 'Schema name to match (case-sensitive). Can be a literal string or regex pattern.',\n ),\n ])\n .meta({ description: 'Pattern filter that matches operations or schemas by tag, operationId, path, method, content type, or schema name.' })\n\n/**\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#include\n */\nexport const includeSchema = z.array(filterSchema).meta({ description: 'Restricts generation to operations or schemas matching at least one entry.' })\n\n/**\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#exclude\n */\nexport const excludeSchema = z.array(filterSchema).meta({ description: 'Skips matching operations or schemas during generation.' })\n\n/**\n * Builds the `override` option from a plugin's options schema, with partial `options` and no `override` key.\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#override\n */\nexport function overrideSchema<TShape extends z.ZodRawShape>(options: z.ZodObject<TShape, z.core.$ZodObjectConfig>) {\n const { override: _override, ...shape } = options.shape\n\n return z\n .array(\n z.intersection(\n filterSchema,\n z.object({\n options: z\n .object(shape)\n .partial()\n .superRefine((options, ctx) => refineGroup(options as GroupedOptions, ctx))\n .meta({ description: 'Options merged on top of the plugin options when the filter matches.' }),\n }),\n ),\n )\n .meta({ description: 'Filters paired with partial options. The first matching entry wins.' })\n}\n\n/**\n * Mirrors core's `ResolverPatch<T>`.\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#resolver\n */\nexport function resolverSchema<T extends Resolver = Resolver>() {\n return z\n .custom<ResolverPatch<T>>(\n (value) => isObject(value) && Object.values(value).every((member) => member === undefined || typeof member === 'function' || isObject(member)),\n { message: 'Expected a resolver object of methods and method namespaces' },\n )\n .meta({ description: \"Partial resolver whose methods replace the plugin's naming and path defaults.\" })\n}\n\n/**\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#macros\n */\nexport const macrosSchema = z\n .array(z.custom<Macro>(isMacro, { message: 'Expected a macro object with a name and function hooks' }))\n .meta({ description: 'Named AST transforms that run before the generators.' })\n"],"mappings":";;;;;;;;;;AA0BA,SAAgB,KAAK,WAA4D;CAC/E,OAAO,EAAE,eAAe,UAAU;AACpC;;;;AAKA,SAAgB,QAAqD,QAA0F;CAC7J,OAAOA,IAAE,OAAO,CAAC,CAAC,KAAK,EAAE,iBAAiB,OAAO,CAAC;AACpD;AAGA,SAAS,iBAAoB;CAC3B,OAAOA,IAAE,QAAW,UAAU,OAAO,UAAU,YAAY,EAAE,SAAS,sBAAsB,CAAC;AAC/F;AAEA,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,QAAQ,OAAyB;CACxC,IAAI,CAAC,SAAS,KAAK,KAAK,OAAO,MAAM,SAAS,UAAU,OAAO;CAC/D,OAAO,OAAO,QAAQ,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,YAAY,QAAQ,UAAU,QAAQ,aAAa,WAAW,KAAA,KAAa,OAAO,WAAW,UAAU;AACnJ;AAEA,MAAM,eAAeA,IAAE,MAAM,CAACA,IAAE,OAAO,GAAG,eAA6C,CAAC,CAAC;;;;;AAMzF,MAAa,eAAeA,IACzB,OAAO;CACN,MAAMA,IAAE,OAAO,CAAC,CAAC,KAAK,EACpB,aACE,mPACJ,CAAC;CACD,MAAMA,IACH,KAAK,CAAC,aAAa,MAAM,CAAC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AAC,CAC1E,KAAK,EAAE,aAAa,uEAAuE,CAAC,EACjG,CAAC,CACH,CACF,CAAC,CACA,KAAK,EAAE,aAAa,sEAAsE,CAAC;AAChG;;;;;AAMA,SAAgB,iBAAgD;CAC9D,OAAOA,IACJ,QACE,UAAU,SAAS,KAAK,KAAK,OAAO,OAAO,KAAK,CAAC,CAAC,OAAO,WAAW,WAAW,KAAA,KAAa,OAAO,WAAW,cAAc,SAAS,MAAM,CAAC,GAC7I,EAAE,SAAS,8DAA8D,CAC3E,CAAC,CACA,KAAK,EAAE,aAAa,gFAAgF,CAAC;AAC1G;;;;AAKA,MAAa,eAAeA,IACzB,MAAMA,IAAE,OAAc,SAAS,EAAE,SAAS,yDAAyD,CAAC,CAAC,CAAC,CACtG,KAAK,EAAE,aAAa,uDAAuD,CAAC"}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
+
import { Macro } from "@kubb/ast";
|
|
3
|
+
import { BannerMeta, Resolver, ResolverPatch } from "@kubb/core";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
//#region ../../internals/utils/src/types.d.ts
|
|
6
|
+
/** A union of known literals that still accepts any other value of `Base`, without collapsing
|
|
7
|
+
* the literals away. Editors keep autocompleting the known members while arbitrary strings stay
|
|
8
|
+
* assignable.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* type PluginName = LiteralUnion<'plugin-ts' | 'plugin-zod'>
|
|
13
|
+
* const a: PluginName = 'plugin-ts' // autocompletes
|
|
14
|
+
* const b: PluginName = 'anything' // still allowed
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
type LiteralUnion<T extends Base, Base = string> = T | (Base & {});
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/options.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* A value an option is compared against in a `when` condition.
|
|
22
|
+
*/
|
|
23
|
+
export type WhenValue = string | number | boolean | null;
|
|
24
|
+
/**
|
|
25
|
+
* Shows an option only when every entry matches. Keys are dotted option paths, such as `'enum.type'`.
|
|
26
|
+
*/
|
|
27
|
+
export type WhenCondition = Record<string, WhenValue | ReadonlyArray<WhenValue>>;
|
|
28
|
+
declare module 'zod' {
|
|
29
|
+
interface GlobalMeta {
|
|
30
|
+
'x-kubb-when'?: WhenCondition;
|
|
31
|
+
'x-kubb-values'?: ReadonlyArray<string>;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Builds `x-kubb-when` metadata for `.meta()`, such as `.meta({ description, ...when({ 'enum.type': 'asConst' }) })`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function when(condition: WhenCondition): {
|
|
38
|
+
'x-kubb-when': WhenCondition;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Accepts any string while its type autocompletes `values`. JSON Schema lists them as `x-kubb-values`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function suggest<const TValues extends ReadonlyArray<string>>(values: TValues): z.ZodType<LiteralUnion<TValues[number]>, LiteralUnion<TValues[number]>>;
|
|
44
|
+
/**
|
|
45
|
+
* Mirrors core's `Output`, including `barrel`. The `group` check lives in {@link outputOptionsSchema}.
|
|
46
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#output
|
|
47
|
+
*/
|
|
48
|
+
export declare const outputSchema: z.ZodObject<{
|
|
49
|
+
path: z.ZodString;
|
|
50
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
51
|
+
directory: "directory";
|
|
52
|
+
file: "file";
|
|
53
|
+
}>>;
|
|
54
|
+
banner: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<(meta: BannerMeta) => string, (meta: BannerMeta) => string>]>>;
|
|
55
|
+
footer: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<(meta: BannerMeta) => string, (meta: BannerMeta) => string>]>>;
|
|
56
|
+
barrel: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
57
|
+
type: z.ZodEnum<{
|
|
58
|
+
all: "all";
|
|
59
|
+
named: "named";
|
|
60
|
+
}>;
|
|
61
|
+
nested: z.ZodOptional<z.ZodBoolean>;
|
|
62
|
+
}, z.core.$strip>, z.ZodLiteral<false>]>>;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
/**
|
|
65
|
+
* Mirrors core's `Group`.
|
|
66
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#group
|
|
67
|
+
*/
|
|
68
|
+
export declare const groupSchema: z.ZodObject<{
|
|
69
|
+
type: z.ZodEnum<{
|
|
70
|
+
path: "path";
|
|
71
|
+
tag: "tag";
|
|
72
|
+
}>;
|
|
73
|
+
name: z.ZodOptional<z.ZodCustom<(context: {
|
|
74
|
+
group: string;
|
|
75
|
+
}) => string, (context: {
|
|
76
|
+
group: string;
|
|
77
|
+
}) => string>>;
|
|
78
|
+
}, z.core.$strip>;
|
|
79
|
+
/**
|
|
80
|
+
* `output` and `group` together. Rejects `group` when `output.mode` resolves to `'file'`. `.extend()` keeps the check.
|
|
81
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#output
|
|
82
|
+
*/
|
|
83
|
+
export declare const outputOptionsSchema: z.ZodObject<{
|
|
84
|
+
output: z.ZodOptional<z.ZodObject<{
|
|
85
|
+
path: z.ZodString;
|
|
86
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
87
|
+
directory: "directory";
|
|
88
|
+
file: "file";
|
|
89
|
+
}>>;
|
|
90
|
+
banner: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<(meta: BannerMeta) => string, (meta: BannerMeta) => string>]>>;
|
|
91
|
+
footer: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<(meta: BannerMeta) => string, (meta: BannerMeta) => string>]>>;
|
|
92
|
+
barrel: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
93
|
+
type: z.ZodEnum<{
|
|
94
|
+
all: "all";
|
|
95
|
+
named: "named";
|
|
96
|
+
}>;
|
|
97
|
+
nested: z.ZodOptional<z.ZodBoolean>;
|
|
98
|
+
}, z.core.$strip>, z.ZodLiteral<false>]>>;
|
|
99
|
+
}, z.core.$strip>>;
|
|
100
|
+
group: z.ZodOptional<z.ZodObject<{
|
|
101
|
+
type: z.ZodEnum<{
|
|
102
|
+
path: "path";
|
|
103
|
+
tag: "tag";
|
|
104
|
+
}>;
|
|
105
|
+
name: z.ZodOptional<z.ZodCustom<(context: {
|
|
106
|
+
group: string;
|
|
107
|
+
}) => string, (context: {
|
|
108
|
+
group: string;
|
|
109
|
+
}) => string>>;
|
|
110
|
+
}, z.core.$strip>>;
|
|
111
|
+
}, z.core.$strip>;
|
|
112
|
+
/**
|
|
113
|
+
* Mirrors core's `Filter`: one include, exclude, or override rule.
|
|
114
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#include
|
|
115
|
+
*/
|
|
116
|
+
export declare const filterSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
117
|
+
type: z.ZodLiteral<"tag">;
|
|
118
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
119
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
120
|
+
type: z.ZodLiteral<"operationId">;
|
|
121
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
122
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
123
|
+
type: z.ZodLiteral<"path">;
|
|
124
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
125
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
126
|
+
type: z.ZodLiteral<"method">;
|
|
127
|
+
pattern: z.ZodUnion<readonly [z.ZodEnum<{
|
|
128
|
+
GET: "GET";
|
|
129
|
+
POST: "POST";
|
|
130
|
+
PUT: "PUT";
|
|
131
|
+
PATCH: "PATCH";
|
|
132
|
+
DELETE: "DELETE";
|
|
133
|
+
HEAD: "HEAD";
|
|
134
|
+
OPTIONS: "OPTIONS";
|
|
135
|
+
TRACE: "TRACE";
|
|
136
|
+
}>, z.ZodInstanceOf<RegExp>]>;
|
|
137
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
138
|
+
type: z.ZodLiteral<"contentType">;
|
|
139
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
140
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
141
|
+
type: z.ZodLiteral<"schemaName">;
|
|
142
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
143
|
+
}, z.core.$strip>], "type">;
|
|
144
|
+
/**
|
|
145
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#include
|
|
146
|
+
*/
|
|
147
|
+
export declare const includeSchema: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
148
|
+
type: z.ZodLiteral<"tag">;
|
|
149
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
150
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
151
|
+
type: z.ZodLiteral<"operationId">;
|
|
152
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
153
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
154
|
+
type: z.ZodLiteral<"path">;
|
|
155
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
156
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
157
|
+
type: z.ZodLiteral<"method">;
|
|
158
|
+
pattern: z.ZodUnion<readonly [z.ZodEnum<{
|
|
159
|
+
GET: "GET";
|
|
160
|
+
POST: "POST";
|
|
161
|
+
PUT: "PUT";
|
|
162
|
+
PATCH: "PATCH";
|
|
163
|
+
DELETE: "DELETE";
|
|
164
|
+
HEAD: "HEAD";
|
|
165
|
+
OPTIONS: "OPTIONS";
|
|
166
|
+
TRACE: "TRACE";
|
|
167
|
+
}>, z.ZodInstanceOf<RegExp>]>;
|
|
168
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
169
|
+
type: z.ZodLiteral<"contentType">;
|
|
170
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
171
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
172
|
+
type: z.ZodLiteral<"schemaName">;
|
|
173
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
174
|
+
}, z.core.$strip>], "type">>;
|
|
175
|
+
/**
|
|
176
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#exclude
|
|
177
|
+
*/
|
|
178
|
+
export declare const excludeSchema: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
179
|
+
type: z.ZodLiteral<"tag">;
|
|
180
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
181
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
182
|
+
type: z.ZodLiteral<"operationId">;
|
|
183
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
184
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
185
|
+
type: z.ZodLiteral<"path">;
|
|
186
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
187
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
188
|
+
type: z.ZodLiteral<"method">;
|
|
189
|
+
pattern: z.ZodUnion<readonly [z.ZodEnum<{
|
|
190
|
+
GET: "GET";
|
|
191
|
+
POST: "POST";
|
|
192
|
+
PUT: "PUT";
|
|
193
|
+
PATCH: "PATCH";
|
|
194
|
+
DELETE: "DELETE";
|
|
195
|
+
HEAD: "HEAD";
|
|
196
|
+
OPTIONS: "OPTIONS";
|
|
197
|
+
TRACE: "TRACE";
|
|
198
|
+
}>, z.ZodInstanceOf<RegExp>]>;
|
|
199
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
200
|
+
type: z.ZodLiteral<"contentType">;
|
|
201
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
202
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
203
|
+
type: z.ZodLiteral<"schemaName">;
|
|
204
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
205
|
+
}, z.core.$strip>], "type">>;
|
|
206
|
+
/**
|
|
207
|
+
* Builds the `override` option from a plugin's options schema, with partial `options` and no `override` key.
|
|
208
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#override
|
|
209
|
+
*/
|
|
210
|
+
export declare function overrideSchema<TShape extends z.ZodRawShape>(options: z.ZodObject<TShape, z.core.$ZodObjectConfig>): z.ZodArray<z.ZodIntersection<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
211
|
+
type: z.ZodLiteral<"tag">;
|
|
212
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
213
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
214
|
+
type: z.ZodLiteral<"operationId">;
|
|
215
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
216
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
217
|
+
type: z.ZodLiteral<"path">;
|
|
218
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
219
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
220
|
+
type: z.ZodLiteral<"method">;
|
|
221
|
+
pattern: z.ZodUnion<readonly [z.ZodEnum<{
|
|
222
|
+
GET: "GET";
|
|
223
|
+
POST: "POST";
|
|
224
|
+
PUT: "PUT";
|
|
225
|
+
PATCH: "PATCH";
|
|
226
|
+
DELETE: "DELETE";
|
|
227
|
+
HEAD: "HEAD";
|
|
228
|
+
OPTIONS: "OPTIONS";
|
|
229
|
+
TRACE: "TRACE";
|
|
230
|
+
}>, z.ZodInstanceOf<RegExp>]>;
|
|
231
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
232
|
+
type: z.ZodLiteral<"contentType">;
|
|
233
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
234
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
235
|
+
type: z.ZodLiteral<"schemaName">;
|
|
236
|
+
pattern: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<RegExp>]>;
|
|
237
|
+
}, z.core.$strip>], "type">, z.ZodObject<{
|
|
238
|
+
options: z.ZodObject<(Omit<TShape, "override"> extends (infer T_1) ? { -readonly [P in keyof T_1]: T_1[P]; } : never) extends (infer T extends Readonly<{
|
|
239
|
+
[k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
240
|
+
}>) ? { -readonly [k in keyof T]: z.ZodOptional<T[k]>; } : never, z.core.$strip>;
|
|
241
|
+
}, z.core.$strip>>>;
|
|
242
|
+
/**
|
|
243
|
+
* Mirrors core's `ResolverPatch<T>`.
|
|
244
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#resolver
|
|
245
|
+
*/
|
|
246
|
+
export declare function resolverSchema<T extends Resolver = Resolver>(): z.ZodCustom<ResolverPatch<T>, ResolverPatch<T>>;
|
|
247
|
+
/**
|
|
248
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#macros
|
|
249
|
+
*/
|
|
250
|
+
export declare const macrosSchema: z.ZodArray<z.ZodCustom<Macro, Macro>>;
|
|
251
|
+
//#endregion
|
|
252
|
+
export {};
|
|
253
|
+
//# sourceMappingURL=options.d.ts.map
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
//#region src/options.ts
|
|
5
|
+
/**
|
|
6
|
+
* Builds `x-kubb-when` metadata for `.meta()`, such as `.meta({ description, ...when({ 'enum.type': 'asConst' }) })`.
|
|
7
|
+
*/
|
|
8
|
+
function when(condition) {
|
|
9
|
+
return { "x-kubb-when": condition };
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Accepts any string while its type autocompletes `values`. JSON Schema lists them as `x-kubb-values`.
|
|
13
|
+
*/
|
|
14
|
+
function suggest(values) {
|
|
15
|
+
return z.string().meta({ "x-kubb-values": values });
|
|
16
|
+
}
|
|
17
|
+
function functionSchema() {
|
|
18
|
+
return z.custom((value) => typeof value === "function", { message: "Expected a function" });
|
|
19
|
+
}
|
|
20
|
+
function isObject(value) {
|
|
21
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22
|
+
}
|
|
23
|
+
function isMacro(value) {
|
|
24
|
+
if (!isObject(value) || typeof value.name !== "string") return false;
|
|
25
|
+
return Object.entries(value).every(([key, member]) => key === "name" || key === "enforce" || member === void 0 || typeof member === "function");
|
|
26
|
+
}
|
|
27
|
+
const bannerSchema = z.union([z.string(), functionSchema()]);
|
|
28
|
+
/**
|
|
29
|
+
* Mirrors core's `Output`, including `barrel`. The `group` check lives in {@link outputOptionsSchema}.
|
|
30
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#output
|
|
31
|
+
*/
|
|
32
|
+
const outputSchema = z.object({
|
|
33
|
+
path: z.string().meta({ description: "Directory where the plugin writes its generated code, resolved against the global `output.path` set on `defineConfig`. With `mode: 'file'`, this is the full output file path and must include the extension (e.g. `'types.ts'`, `'models.py'`)." }),
|
|
34
|
+
mode: z.enum(["directory", "file"]).meta({ description: "How generated code is consolidated into files. `'file'` writes everything into a single file, `'directory'` writes one file per operation or schema under `path`. Defaults to `'file'` when `path` carries an extension and `'directory'` when it does not." }).optional(),
|
|
35
|
+
banner: bannerSchema.meta({ description: "Text prepended to every generated file. Useful for license headers, lint disables, or `@ts-nocheck` directives. Pass a function to compute the banner from the file's `BannerMeta`." }).optional(),
|
|
36
|
+
footer: bannerSchema.meta({ description: "Text appended at the end of every generated file. Pass a function to compute the footer from the file's `BannerMeta`." }).optional(),
|
|
37
|
+
barrel: z.union([z.object({
|
|
38
|
+
type: z.enum(["all", "named"]).meta({ description: "Export strategy for the plugin's barrel files. `'all'` uses wildcard exports, `'named'` uses explicit exports." }),
|
|
39
|
+
nested: z.boolean().meta({ description: "Generate an `index.ts` in every sub-directory, each re-exporting only what's directly inside it." }).optional()
|
|
40
|
+
}), z.literal(false)]).meta({ description: "Barrel configuration for this plugin's output. Set to `{ type: 'named' | 'all' }` to opt into a barrel, or `false` to disable it. Falls back to `config.output.barrel` when omitted." }).optional()
|
|
41
|
+
}).meta({ description: "Output configuration shared by every plugin." });
|
|
42
|
+
/**
|
|
43
|
+
* Mirrors core's `Group`.
|
|
44
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#group
|
|
45
|
+
*/
|
|
46
|
+
const groupSchema = z.object({
|
|
47
|
+
type: z.enum(["tag", "path"]).meta({ description: "Property used to assign each operation to a group. `'tag'` uses the first tag, `'path'` uses the first segment of the operation's URL." }),
|
|
48
|
+
name: functionSchema().meta({ description: "Returns the subdirectory name from the group key. Defaults to the camelCased tag for `tag` groups, or the first path segment as written in the spec for `path` groups." }).optional()
|
|
49
|
+
}).meta({ description: "Groups generated files into subdirectories based on an OpenAPI tag or path segment." });
|
|
50
|
+
function refineGroup(options, ctx) {
|
|
51
|
+
if (!options.output || !options.group) return;
|
|
52
|
+
if ((options.output.mode ?? (path.extname(options.output.path) ? "file" : "directory")) === "file") ctx.addIssue({
|
|
53
|
+
code: "custom",
|
|
54
|
+
path: ["group"],
|
|
55
|
+
message: "A single-file output has nothing to group. Remove the `group` option, give `output.path` an extensionless directory name, or set `output.mode: 'directory'` explicitly."
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* `output` and `group` together. Rejects `group` when `output.mode` resolves to `'file'`. `.extend()` keeps the check.
|
|
60
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#output
|
|
61
|
+
*/
|
|
62
|
+
const outputOptionsSchema = z.object({
|
|
63
|
+
output: outputSchema.optional(),
|
|
64
|
+
group: groupSchema.optional()
|
|
65
|
+
}).superRefine(refineGroup);
|
|
66
|
+
const patternSchema = z.union([z.string(), z.instanceof(RegExp)]);
|
|
67
|
+
function byPattern(type, typeDescription, patternDescription) {
|
|
68
|
+
return z.object({
|
|
69
|
+
type: z.literal(type).meta({ description: typeDescription }),
|
|
70
|
+
pattern: patternSchema.meta({ description: patternDescription })
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Mirrors core's `Filter`: one include, exclude, or override rule.
|
|
75
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#include
|
|
76
|
+
*/
|
|
77
|
+
const filterSchema = z.discriminatedUnion("type", [
|
|
78
|
+
byPattern("tag", "Filter by OpenAPI `tags` field. Matches one or more tags assigned to operations.", "Tag name to match (case-sensitive). Can be a literal string or regex pattern."),
|
|
79
|
+
byPattern("operationId", "Filter by OpenAPI `operationId` field. Each operation (GET, POST, etc.) has a unique identifier.", "Operation ID to match (case-sensitive). Can be a literal string or regex pattern."),
|
|
80
|
+
byPattern("path", "Filter by OpenAPI `path` (URL endpoint). Useful to group or filter by service segments like `/pets`, `/users`, etc.", "URL path to match (case-sensitive). Can be a literal string or regex pattern. Matches against the full path."),
|
|
81
|
+
z.object({
|
|
82
|
+
type: z.literal("method").meta({ description: "Filter by HTTP method." }),
|
|
83
|
+
pattern: z.union([z.enum([
|
|
84
|
+
"GET",
|
|
85
|
+
"POST",
|
|
86
|
+
"PUT",
|
|
87
|
+
"PATCH",
|
|
88
|
+
"DELETE",
|
|
89
|
+
"HEAD",
|
|
90
|
+
"OPTIONS",
|
|
91
|
+
"TRACE"
|
|
92
|
+
]), z.instanceof(RegExp)]).meta({ description: "HTTP method to match, as one of the `HttpMethod` values or a regex." })
|
|
93
|
+
}),
|
|
94
|
+
byPattern("contentType", "Filter by response or request content type: `'application/json'`, `'application/xml'`, etc.", "Content type to match (case-sensitive). Can be a literal string or regex pattern."),
|
|
95
|
+
byPattern("schemaName", "Filter by schema component name (TypeScript or JSON schema). Matches schemas in `#/components/schemas`.", "Schema name to match (case-sensitive). Can be a literal string or regex pattern.")
|
|
96
|
+
]).meta({ description: "Pattern filter that matches operations or schemas by tag, operationId, path, method, content type, or schema name." });
|
|
97
|
+
/**
|
|
98
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#include
|
|
99
|
+
*/
|
|
100
|
+
const includeSchema = z.array(filterSchema).meta({ description: "Restricts generation to operations or schemas matching at least one entry." });
|
|
101
|
+
/**
|
|
102
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#exclude
|
|
103
|
+
*/
|
|
104
|
+
const excludeSchema = z.array(filterSchema).meta({ description: "Skips matching operations or schemas during generation." });
|
|
105
|
+
/**
|
|
106
|
+
* Builds the `override` option from a plugin's options schema, with partial `options` and no `override` key.
|
|
107
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#override
|
|
108
|
+
*/
|
|
109
|
+
function overrideSchema(options) {
|
|
110
|
+
const { override: _override, ...shape } = options.shape;
|
|
111
|
+
return z.array(z.intersection(filterSchema, z.object({ options: z.object(shape).partial().superRefine((options, ctx) => refineGroup(options, ctx)).meta({ description: "Options merged on top of the plugin options when the filter matches." }) }))).meta({ description: "Filters paired with partial options. The first matching entry wins." });
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Mirrors core's `ResolverPatch<T>`.
|
|
115
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#resolver
|
|
116
|
+
*/
|
|
117
|
+
function resolverSchema() {
|
|
118
|
+
return z.custom((value) => isObject(value) && Object.values(value).every((member) => member === void 0 || typeof member === "function" || isObject(member)), { message: "Expected a resolver object of methods and method namespaces" }).meta({ description: "Partial resolver whose methods replace the plugin's naming and path defaults." });
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* @see https://kubb.dev/docs/5.x/reference/plugin-options#macros
|
|
122
|
+
*/
|
|
123
|
+
const macrosSchema = z.array(z.custom(isMacro, { message: "Expected a macro object with a name and function hooks" })).meta({ description: "Named AST transforms that run before the generators." });
|
|
124
|
+
//#endregion
|
|
125
|
+
export { excludeSchema, filterSchema, groupSchema, includeSchema, macrosSchema, outputOptionsSchema, outputSchema, overrideSchema, resolverSchema, suggest, when };
|
|
126
|
+
|
|
127
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","names":[],"sources":["../src/options.ts"],"sourcesContent":["import path from 'node:path'\nimport type { LiteralUnion } from '@internals/utils'\nimport type { HttpMethod, Macro } from '@kubb/ast'\nimport type { BannerMeta, Resolver, ResolverPatch } from '@kubb/core'\nimport * as z from 'zod'\n\n/**\n * A value an option is compared against in a `when` condition.\n */\nexport type WhenValue = string | number | boolean | null\n\n/**\n * Shows an option only when every entry matches. Keys are dotted option paths, such as `'enum.type'`.\n */\nexport type WhenCondition = Record<string, WhenValue | ReadonlyArray<WhenValue>>\n\ndeclare module 'zod' {\n interface GlobalMeta {\n 'x-kubb-when'?: WhenCondition\n 'x-kubb-values'?: ReadonlyArray<string>\n }\n}\n\n/**\n * Builds `x-kubb-when` metadata for `.meta()`, such as `.meta({ description, ...when({ 'enum.type': 'asConst' }) })`.\n */\nexport function when(condition: WhenCondition): { 'x-kubb-when': WhenCondition } {\n return { 'x-kubb-when': condition }\n}\n\n/**\n * Accepts any string while its type autocompletes `values`. JSON Schema lists them as `x-kubb-values`.\n */\nexport function suggest<const TValues extends ReadonlyArray<string>>(values: TValues): z.ZodType<LiteralUnion<TValues[number]>, LiteralUnion<TValues[number]>> {\n return z.string().meta({ 'x-kubb-values': values })\n}\n\n// `z.function()` would wrap user callbacks, so accept any function as written.\nfunction functionSchema<T>() {\n return z.custom<T>((value) => typeof value === 'function', { message: 'Expected a function' })\n}\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction isMacro(value: unknown): boolean {\n if (!isObject(value) || typeof value.name !== 'string') return false\n return Object.entries(value).every(([key, member]) => key === 'name' || key === 'enforce' || member === undefined || typeof member === 'function')\n}\n\nconst bannerSchema = z.union([z.string(), functionSchema<(meta: BannerMeta) => string>()])\n\n/**\n * Mirrors core's `Output`, including `barrel`. The `group` check lives in {@link outputOptionsSchema}.\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#output\n */\nexport const outputSchema = z\n .object({\n path: z.string().meta({\n description:\n \"Directory where the plugin writes its generated code, resolved against the global `output.path` set on `defineConfig`. With `mode: 'file'`, this is the full output file path and must include the extension (e.g. `'types.ts'`, `'models.py'`).\",\n }),\n mode: z\n .enum(['directory', 'file'])\n .meta({\n description:\n \"How generated code is consolidated into files. `'file'` writes everything into a single file, `'directory'` writes one file per operation or schema under `path`. Defaults to `'file'` when `path` carries an extension and `'directory'` when it does not.\",\n })\n .optional(),\n banner: bannerSchema\n .meta({\n description:\n \"Text prepended to every generated file. Useful for license headers, lint disables, or `@ts-nocheck` directives. Pass a function to compute the banner from the file's `BannerMeta`.\",\n })\n .optional(),\n footer: bannerSchema\n .meta({ description: \"Text appended at the end of every generated file. Pass a function to compute the footer from the file's `BannerMeta`.\" })\n .optional(),\n barrel: z\n .union([\n z.object({\n type: z.enum(['all', 'named']).meta({\n description: \"Export strategy for the plugin's barrel files. `'all'` uses wildcard exports, `'named'` uses explicit exports.\",\n }),\n nested: z\n .boolean()\n .meta({ description: \"Generate an `index.ts` in every sub-directory, each re-exporting only what's directly inside it.\" })\n .optional(),\n }),\n z.literal(false),\n ])\n .meta({\n description:\n \"Barrel configuration for this plugin's output. Set to `{ type: 'named' | 'all' }` to opt into a barrel, or `false` to disable it. Falls back to `config.output.barrel` when omitted.\",\n })\n .optional(),\n })\n .meta({ description: 'Output configuration shared by every plugin.' })\n\n/**\n * Mirrors core's `Group`.\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#group\n */\nexport const groupSchema = z\n .object({\n type: z.enum(['tag', 'path']).meta({\n description: \"Property used to assign each operation to a group. `'tag'` uses the first tag, `'path'` uses the first segment of the operation's URL.\",\n }),\n name: functionSchema<(context: { group: string }) => string>()\n .meta({\n description:\n 'Returns the subdirectory name from the group key. Defaults to the camelCased tag for `tag` groups, or the first path segment as written in the spec for `path` groups.',\n })\n .optional(),\n })\n .meta({ description: 'Groups generated files into subdirectories based on an OpenAPI tag or path segment.' })\n\ntype GroupedOptions = { output?: { path: string; mode?: 'directory' | 'file' }; group?: object }\n\nfunction refineGroup(options: GroupedOptions, ctx: z.RefinementCtx): void {\n if (!options.output || !options.group) return\n\n const mode = options.output.mode ?? (path.extname(options.output.path) ? 'file' : 'directory')\n if (mode === 'file') {\n ctx.addIssue({\n code: 'custom',\n path: ['group'],\n message:\n \"A single-file output has nothing to group. Remove the `group` option, give `output.path` an extensionless directory name, or set `output.mode: 'directory'` explicitly.\",\n })\n }\n}\n\n/**\n * `output` and `group` together. Rejects `group` when `output.mode` resolves to `'file'`. `.extend()` keeps the check.\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#output\n */\nexport const outputOptionsSchema = z\n .object({\n output: outputSchema.optional(),\n group: groupSchema.optional(),\n })\n .superRefine(refineGroup)\n\nconst patternSchema = z.union([z.string(), z.instanceof(RegExp)])\n\nfunction byPattern<const TType extends string>(type: TType, typeDescription: string, patternDescription: string) {\n return z.object({\n type: z.literal(type).meta({ description: typeDescription }),\n pattern: patternSchema.meta({ description: patternDescription }),\n })\n}\n\nconst httpMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS', 'TRACE'] as const satisfies ReadonlyArray<HttpMethod>\n\n/**\n * Mirrors core's `Filter`: one include, exclude, or override rule.\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#include\n */\nexport const filterSchema = z\n .discriminatedUnion('type', [\n byPattern(\n 'tag',\n 'Filter by OpenAPI `tags` field. Matches one or more tags assigned to operations.',\n 'Tag name to match (case-sensitive). Can be a literal string or regex pattern.',\n ),\n byPattern(\n 'operationId',\n 'Filter by OpenAPI `operationId` field. Each operation (GET, POST, etc.) has a unique identifier.',\n 'Operation ID to match (case-sensitive). Can be a literal string or regex pattern.',\n ),\n byPattern(\n 'path',\n 'Filter by OpenAPI `path` (URL endpoint). Useful to group or filter by service segments like `/pets`, `/users`, etc.',\n 'URL path to match (case-sensitive). Can be a literal string or regex pattern. Matches against the full path.',\n ),\n z.object({\n type: z.literal('method').meta({ description: 'Filter by HTTP method.' }),\n pattern: z\n .union([z.enum(httpMethods), z.instanceof(RegExp)])\n .meta({ description: 'HTTP method to match, as one of the `HttpMethod` values or a regex.' }),\n }),\n byPattern(\n 'contentType',\n \"Filter by response or request content type: `'application/json'`, `'application/xml'`, etc.\",\n 'Content type to match (case-sensitive). Can be a literal string or regex pattern.',\n ),\n byPattern(\n 'schemaName',\n 'Filter by schema component name (TypeScript or JSON schema). Matches schemas in `#/components/schemas`.',\n 'Schema name to match (case-sensitive). Can be a literal string or regex pattern.',\n ),\n ])\n .meta({ description: 'Pattern filter that matches operations or schemas by tag, operationId, path, method, content type, or schema name.' })\n\n/**\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#include\n */\nexport const includeSchema = z.array(filterSchema).meta({ description: 'Restricts generation to operations or schemas matching at least one entry.' })\n\n/**\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#exclude\n */\nexport const excludeSchema = z.array(filterSchema).meta({ description: 'Skips matching operations or schemas during generation.' })\n\n/**\n * Builds the `override` option from a plugin's options schema, with partial `options` and no `override` key.\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#override\n */\nexport function overrideSchema<TShape extends z.ZodRawShape>(options: z.ZodObject<TShape, z.core.$ZodObjectConfig>) {\n const { override: _override, ...shape } = options.shape\n\n return z\n .array(\n z.intersection(\n filterSchema,\n z.object({\n options: z\n .object(shape)\n .partial()\n .superRefine((options, ctx) => refineGroup(options as GroupedOptions, ctx))\n .meta({ description: 'Options merged on top of the plugin options when the filter matches.' }),\n }),\n ),\n )\n .meta({ description: 'Filters paired with partial options. The first matching entry wins.' })\n}\n\n/**\n * Mirrors core's `ResolverPatch<T>`.\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#resolver\n */\nexport function resolverSchema<T extends Resolver = Resolver>() {\n return z\n .custom<ResolverPatch<T>>(\n (value) => isObject(value) && Object.values(value).every((member) => member === undefined || typeof member === 'function' || isObject(member)),\n { message: 'Expected a resolver object of methods and method namespaces' },\n )\n .meta({ description: \"Partial resolver whose methods replace the plugin's naming and path defaults.\" })\n}\n\n/**\n * @see https://kubb.dev/docs/5.x/reference/plugin-options#macros\n */\nexport const macrosSchema = z\n .array(z.custom<Macro>(isMacro, { message: 'Expected a macro object with a name and function hooks' }))\n .meta({ description: 'Named AST transforms that run before the generators.' })\n"],"mappings":";;;;;;;AA0BA,SAAgB,KAAK,WAA4D;CAC/E,OAAO,EAAE,eAAe,UAAU;AACpC;;;;AAKA,SAAgB,QAAqD,QAA0F;CAC7J,OAAO,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,iBAAiB,OAAO,CAAC;AACpD;AAGA,SAAS,iBAAoB;CAC3B,OAAO,EAAE,QAAW,UAAU,OAAO,UAAU,YAAY,EAAE,SAAS,sBAAsB,CAAC;AAC/F;AAEA,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,QAAQ,OAAyB;CACxC,IAAI,CAAC,SAAS,KAAK,KAAK,OAAO,MAAM,SAAS,UAAU,OAAO;CAC/D,OAAO,OAAO,QAAQ,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,YAAY,QAAQ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Aa,0DAA0D,CAAC;;;;;AAMlI,SAAgB,eAA6C,SAAuD;CAClH,MAAM,EAAE,UAAU,WAAW,GAAG,UAAU,QAAQ;CAElD,OAAO,EACJ,MACC,EAAE,aACA,cACA,EAAE,OAAO,EACP,SAAS,EACN,OAAO,KAAK,CAAC,CACb,QAAQ,CAAC,CACT,aAAa,SAAS,QAAQ,YAAY,SAA2B,GAAG,CAAC,CAAC,CAC1E,KAAK,EAAE,aAAa,uEAAuE,CAAC,EACjG,CAAC,CACH,CACF,CAAC,CACA,KAAK,EAAE,aAAa,sEAAsE,CAAC;AAChG;;;;;AAMA,SAAgB,iBAAgD;CAC9D,OAAO,EACJ,QACE,UAAU,SAAS,KAAK,KAAK,OAAO,OAAO,KAAK,CAAC,CAAC,OAAO,WAAW,WAAW,KAAA,KAAa,OAAO,WAAW,cAAc,SAAS,MAAM,CAAC,GAC7I,EAAE,SAAS,8DAA8D,CAC3E,CAAC,CACA,KAAK,EAAE,aAAa,gFAAgF,CAAC;AAC1G;;;;AAKA,MAAa,eAAe,EACzB,MAAM,EAAE,OAAc,SAAS,EAAE,SAAS,yDAAyD,CAAC,CAAC,CAAC,CACtG,KAAK,EAAE,aAAa,uDAAuD,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
5
|
+
value,
|
|
6
|
+
configurable: true
|
|
7
|
+
});
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
|
+
key = keys[i];
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: ((k) => from[k]).bind(null, key),
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
//#endregion
|
|
27
|
+
Object.defineProperty(exports, "__name", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function() {
|
|
30
|
+
return __name;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(exports, "__toESM", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function() {
|
|
36
|
+
return __toESM;
|
|
37
|
+
}
|
|
38
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/kit",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.8.0",
|
|
4
4
|
"description": "Authoring toolkit for Kubb plugins, generators, adapters, resolvers, and renderers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codegen",
|
|
@@ -56,6 +56,11 @@
|
|
|
56
56
|
"import": "./dist/testing.js",
|
|
57
57
|
"require": "./dist/testing.cjs"
|
|
58
58
|
},
|
|
59
|
+
"./options": {
|
|
60
|
+
"types": "./dist/options.d.ts",
|
|
61
|
+
"import": "./dist/options.js",
|
|
62
|
+
"require": "./dist/options.cjs"
|
|
63
|
+
},
|
|
59
64
|
"./package.json": "./package.json"
|
|
60
65
|
},
|
|
61
66
|
"publishConfig": {
|
|
@@ -63,11 +68,20 @@
|
|
|
63
68
|
"registry": "https://registry.npmjs.org/"
|
|
64
69
|
},
|
|
65
70
|
"dependencies": {
|
|
66
|
-
"@kubb/ast": "5.
|
|
67
|
-
"@kubb/core": "5.
|
|
71
|
+
"@kubb/ast": "5.8.0",
|
|
72
|
+
"@kubb/core": "5.8.0"
|
|
68
73
|
},
|
|
69
74
|
"devDependencies": {
|
|
70
|
-
"@internals/utils": "0.0.1"
|
|
75
|
+
"@internals/utils": "0.0.1",
|
|
76
|
+
"zod": "^4.6.5"
|
|
77
|
+
},
|
|
78
|
+
"peerDependencies": {
|
|
79
|
+
"zod": "^4.0.0"
|
|
80
|
+
},
|
|
81
|
+
"peerDependenciesMeta": {
|
|
82
|
+
"zod": {
|
|
83
|
+
"optional": true
|
|
84
|
+
}
|
|
71
85
|
},
|
|
72
86
|
"engines": {
|
|
73
87
|
"node": ">=22"
|