import type { GenerateContext } from '../../context/GenerateContext.js'; import type { OasOperation } from '../../oas/operation/Operation.js'; import type { Identifier } from '../Identifier.js'; import type { OperationInsertable, OperationInsertableArgs } from './types.js'; import * as v from 'valibot'; /** * Configuration for creating a base operation class. * * Defines the structure and behavior for operation generators, including * identifier generation, export path resolution, and enrichment schemas. * * @template EnrichmentType - Type of enrichments to apply to generated operations */ export type BaseOperationConfig = { /** Unique identifier for the operation generator */ id: string; /** Function to generate identifiers from operations */ toIdentifier: (operation: OasOperation) => Identifier; /** Function to generate export paths from operations */ toExportPath: (operation: OasOperation) => string; /** Optional function to provide enrichment validation schema */ toEnrichmentSchema?: () => v.BaseSchema>; }; type ToEnrichmentsArgs = { operation: OasOperation; context: GenerateContext; }; /** * Creates a base operation class constructor for generating type-safe operation artifacts. * * This factory function creates a specialized OperationBase class that implements * the provided configuration for identifier generation, export paths, and * enrichment handling. The resulting class can be instantiated to generate * operation artifacts from OpenAPI operations. * * @template EnrichmentType - Type of enrichments to apply to generated operations * @param config - Configuration defining the operation generation behavior * @returns Constructor function for creating operation instances * * @example Creating a TypeScript function generator * ```typescript * import { toOperationBase } from '@skmtc/core'; * * const TypeScriptOperationBase = toOperationBase({ * id: 'typescript-functions', * toIdentifier: (operation) => new Identifier(camelCase(operation.operationId)), * toExportPath: (operation) => `./operations/${kebabCase(operation.operationId)}.ts`, * toEnrichmentSchema: () => v.object({ * includeValidation: v.optional(v.boolean()), * asyncMode: v.optional(v.boolean()) * }) * }); * * class TypeScriptOperationGenerator extends TypeScriptOperationBase { * generate() { * const enrichments = this.enrichments; * const functionCode = generateFunction(this.operation, { * async: enrichments?.asyncMode ?? true * }); * this.register({ file: this.createFile(functionCode) }); * } * } * ``` * * @example Creating a React hook generator * ```typescript * const ReactHookOperationBase = toOperationBase({ * id: 'react-hooks', * toIdentifier: (operation) => new Identifier(`use${pascalCase(operation.operationId)}`), * toExportPath: (operation) => `./hooks/${kebabCase(operation.operationId)}.hook.ts` * }); * ``` */ export declare const toOperationBase: (config: BaseOperationConfig) => { new (args: OperationInsertableArgs): { settings: import("../ContentSettings.js").ContentSettings; operation: OasOperation; generatorKey: import("../../mod.js").GeneratorKey; insertOperation(insertable: OperationInsertable, operation: OasOperation, options?: Pick, "noExport">): import("../Inserted.js").Inserted; insertModel(insertable: import("../model/types.js").ModelInsertable, refName: import("../../mod.js").RefName, options?: Pick, "noExport">): import("../Inserted.js").Inserted; insertNormalizedModel | import("../../mod.js").OasVoid, EnrichmentType_3 = undefined>(insertable: import("../model/types.js").ModelInsertable, { schema, fallbackName }: Omit, "destinationPath">, options?: Pick, "noExport">): import("../../mod.js").InsertNormalisedModelReturn; defineAndRegister({ identifier, value, noExport }: Omit, "destinationPath">): import("../Definition.js").Definition; register(args: import("../../mod.js").BaseRegisterArgs): void; context: GenerateContext; skipped: boolean; }; id: string; type: "operation"; toIdentifier: (operation: OasOperation) => Identifier; toExportPath: (operation: OasOperation) => string; toEnrichments: ({ operation, context }: ToEnrichmentsArgs) => EnrichmentType; }; export {}; //# sourceMappingURL=toOperationBase.d.ts.map