import { t as __name } from "./chunk--u3MIqq1.js"; import { C as ResolvePathOptions, S as Refs, _ as OperationSchemas, a as ReactGenerator, b as PluginOas, c as SchemaGenerator, d as SchemaMethodResult, f as OperationGenerator, g as OperationSchema, h as Include, i as Version, l as SchemaGeneratorBuildOptions, m as Exclude, n as createGenerator$1, o as createReactGenerator$1, p as OperationMethodResult, r as Generator$1, s as GetSchemaGeneratorOptions, u as SchemaGeneratorOptions, v as Options, w as Resolver, x as Ref, y as Override } from "./createGenerator-BZA5dzMY.js"; import { a as SchemaMapper, c as schemaKeywords, i as SchemaKeywordMapper, n as SchemaKeyword, o as SchemaTree, r as SchemaKeywordBase, s as isKeyword, t as Schema } from "./SchemaMapper-SneuY1wg.js"; import { Operation, SchemaObject } from "@kubb/oas"; import * as _kubb_core0 from "@kubb/core"; import { Config, Plugin, PluginFactoryOptions } from "@kubb/core"; import { OperationNode, SchemaNode } from "@kubb/ast/types"; import { Fabric } from "@kubb/react-fabric/types"; //#region src/createParser.d.ts /** * Helper type to create a SchemaTree with a specific current schema type */ type SchemaTreeWithKeyword = Omit & { current: SchemaKeywordMapper[K]; }; /** * Handler context with parse method available via `this` */ type HandlerContext = { parse: (tree: SchemaTree, options: TOptions) => TOutput | null | undefined; }; /** * Handler function type for custom keyword processing * Handlers can access the parse function via `this.parse` * The tree.current is typed based on the keyword K */ type KeywordHandler = (this: HandlerContext, tree: SchemaTreeWithKeyword, options: TOptions) => TOutput | null | undefined; /** * Configuration for createParser */ type CreateParserConfig = { /** * The keyword mapper that maps schema keywords to output generators */ mapper: SchemaMapper; /** * Custom handlers for specific schema keywords * These provide the implementation for complex types that need special processing * * Use function syntax (not arrow functions) to enable use of `this` keyword: * ```typescript * handlers: { * enum(tree, options, parse) { * // Implementation * } * } * ``` * * Common keywords that typically need handlers: * - union: Combine multiple schemas into a union * - and: Combine multiple schemas into an intersection * - array: Handle array types with items * - object: Handle object types with properties * - enum: Handle enum types * - tuple: Handle tuple types * - const: Handle literal/const types * - ref: Handle references to other schemas * - string/number/integer: Handle primitives with constraints (min/max) * - matches: Handle regex patterns * - default/describe/optional/nullable: Handle modifiers */ handlers: Partial<{ [K in keyof SchemaKeywordMapper]: KeywordHandler }>; }; /** * Creates a parser function that converts schema trees to output using the provided mapper and handlers * * This function provides a framework for building parsers by: * 1. Checking for custom handlers for each keyword * 2. Falling back to the mapper for simple keywords * 3. Providing utilities for common operations (finding siblings, etc.) * * The generated parser is recursive and can handle nested schemas. * * **Type Safety**: Each handler receives a `tree` parameter where `tree.current` is automatically * typed as the specific schema keyword type (e.g., `SchemaKeywordMapper['ref']` for the `ref` handler). * This means you can access `tree.current.args` with full type safety without needing `isKeyword` checks, * though such checks can still be used as runtime guards if desired. * * @template TOutput - The output type (e.g., string for Zod/Faker, ts.TypeNode for TypeScript) * @template TOptions - The parser options type * @param config - Configuration object containing mapper and handlers * @returns A parse function that converts SchemaTree to TOutput * * @example * ```ts * // Create a simple string-based parser * const parse = createParser({ * mapper: zodKeywordMapper, * handlers: { * // tree.current is typed as SchemaKeywordMapper['union'] * union(tree, options) { * const items = tree.current.args // args is correctly typed as Schema[] * .map(it => this.parse({ ...tree, current: it }, options)) * .filter(Boolean) * return `z.union([${items.join(', ')}])` * }, * // tree.current is typed as SchemaKeywordMapper['string'] * string(tree, options) { * const minSchema = findSchemaKeyword(tree.siblings, 'min') * const maxSchema = findSchemaKeyword(tree.siblings, 'max') * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args) * }, * // tree.current is typed as SchemaKeywordMapper['ref'] * ref(tree, options) { * // No need for isKeyword check - tree.current.args is already properly typed * return `Ref: ${tree.current.args.name}` * } * } * }) * ``` */ declare function createParser>(config: CreateParserConfig): (tree: SchemaTree, options: TOptions) => TOutput | null | undefined; /** * Helper to find a schema keyword in siblings * Useful in handlers when you need to find related schemas (e.g., min/max for string) * * @example * ```ts * const minSchema = findSchemaKeyword(tree.siblings, 'min') * const maxSchema = findSchemaKeyword(tree.siblings, 'max') * return zodKeywordMapper.string(false, minSchema?.args, maxSchema?.args) * ``` */ declare function findSchemaKeyword(siblings: Schema[], keyword: K): SchemaKeywordMapper[K] | undefined; //#endregion //#region src/plugin.d.ts declare const pluginOasName = "plugin-oas"; declare const pluginOas: (options?: Options | undefined) => _kubb_core0.UserPluginWithLifeCycle; //#endregion //#region src/utils.d.ts type BuildOperationsBaseOptions = { config: Config; fabric: Fabric; plugin: Plugin; }; type BuildOperationsV1Options = BuildOperationsBaseOptions & { version?: '1'; Component: ReactGenerator['Operations']; generator: Omit, 'build'>; }; type BuildOperationsV2Options = BuildOperationsBaseOptions & { version: '2'; Component: ReactGenerator['Operations']; }; declare function buildOperations(operations: Array, options: BuildOperationsV1Options): Promise; declare function buildOperations(nodes: Array, options: BuildOperationsV2Options): Promise; type BuildOperationBaseOptions = { config: Config; fabric: Fabric; plugin: Plugin; }; type BuildOperationV1Options = BuildOperationBaseOptions & { version?: '1'; Component: ReactGenerator['Operation']; generator: Omit, 'build'>; }; type BuildOperationV2Options = BuildOperationBaseOptions & { version: '2'; Component: ReactGenerator['Operation']; }; declare function buildOperation(operation: Operation, options: BuildOperationV1Options): Promise; declare function buildOperation(node: OperationNode, options: BuildOperationV2Options): Promise; type BuildSchemaBaseOptions = { config: Config; fabric: Fabric; plugin: Plugin; }; type BuildSchemaV1Options = BuildSchemaBaseOptions & { version?: '1'; Component: ReactGenerator['Schema']; generator: Omit, 'build'>; }; type BuildSchemaV2Options = BuildSchemaBaseOptions & { version: '2'; Component: ReactGenerator['Schema']; }; declare function buildSchema(schema: { name: string; tree: Array; value: SchemaObject; }, options: BuildSchemaV1Options): Promise; declare function buildSchema(schema: SchemaNode, options: BuildSchemaV2Options): Promise; //#endregion //#region src/index.d.ts /** * @deprecated use `import { createGenerator } from '@kubb/plugin-oas/generators'` */ declare const createGenerator: typeof createGenerator$1; /** * @deprecated use `import { createReactGenerator } from '@kubb/plugin-oas/generators'` */ declare const createReactGenerator: typeof createReactGenerator$1; /** * @deprecated use `import { Generator } from '@kubb/plugin-oas/generators'` */ type Generator = Generator$1; //#endregion export { type CreateParserConfig, Exclude, Generator, type GetSchemaGeneratorOptions, Include, type KeywordHandler, OperationGenerator, type OperationMethodResult, OperationSchema, OperationSchemas, Options, Override, PluginOas, Ref, Refs, ResolvePathOptions, Resolver, type Schema, SchemaGenerator, type SchemaGeneratorBuildOptions, type SchemaGeneratorOptions, type SchemaKeyword, type SchemaKeywordBase, type SchemaKeywordMapper, type SchemaMapper, type SchemaMethodResult, type SchemaTree, buildOperation, buildOperations, buildSchema, createGenerator, createParser, createReactGenerator, findSchemaKeyword, isKeyword, pluginOas, pluginOasName, schemaKeywords }; //# sourceMappingURL=index.d.ts.map