import type { GenerateContext } from '../../context/GenerateContext.js'; import type { RefName } from '../../types/RefName.js'; import type { ContentSettings } from '../ContentSettings.js'; import type { Identifier } from '../Identifier.js'; import * as v from 'valibot'; import type { ModelInsertable } from './types.js'; /** * Arguments for creating a model insertable instance. * * @template EnrichmentType - Type of enrichments to apply to the model */ export type ModelInsertableArgs = { /** The generation context providing access to OAS objects and utilities */ context: GenerateContext; /** Content settings for customizing model generation behavior */ settings: ContentSettings; /** Reference name identifying the model schema */ refName: RefName; }; type ToEnrichmentsArgs = { refName: RefName; context: GenerateContext; }; /** * Configuration for creating a base model class. * * Defines the structure and behavior for model generators, including * identifier generation, export path resolution, and enrichment schemas. * * @template EnrichmentType - Type of enrichments to apply to generated models */ export type BaseModelConfig = { /** Unique identifier for the model generator */ id: string; /** Function to generate identifiers from reference names */ toIdentifier: (refName: RefName) => Identifier; /** Function to generate export paths from reference names */ toExportPath: (refName: RefName) => string; /** Optional function to provide enrichment validation schema */ toEnrichmentSchema?: () => v.BaseSchema>; }; /** * Creates a base model class constructor for generating type-safe model artifacts. * * This factory function creates a specialized ModelBase class that implements * the provided configuration for identifier generation, export paths, and * enrichment handling. The resulting class can be instantiated to generate * model artifacts from OpenAPI schemas. * * @template EnrichmentType - Type of enrichments to apply to generated models * @param config - Configuration defining the model generation behavior * @returns Constructor function for creating model instances * * @example Creating a TypeScript interface generator * ```typescript * import { toModelBase } from '@skmtc/core'; * * const TypeScriptModelBase = toModelBase({ * id: 'typescript-interfaces', * toIdentifier: (refName) => new Identifier(pascalCase(refName)), * toExportPath: (refName) => `./models/${kebabCase(refName)}.ts`, * toEnrichmentSchema: () => v.object({ * includeValidation: v.optional(v.boolean()), * readonly: v.optional(v.boolean()) * }) * }); * * class TypeScriptModelGenerator extends TypeScriptModelBase { * generate() { * const enrichments = this.enrichments; * const interface = generateInterface(this.schema, { * readonly: enrichments?.readonly ?? false * }); * this.register({ file: this.createFile(interface) }); * } * } * ``` * * @example Creating a validation schema generator * ```typescript * const ValidationModelBase = toModelBase({ * id: 'zod-schemas', * toIdentifier: (refName) => new Identifier(`${pascalCase(refName)}Schema`), * toExportPath: (refName) => `./schemas/${kebabCase(refName)}.schema.ts` * }); * ``` */ export declare const toModelBase: (config: BaseModelConfig) => { new (args: ModelInsertableArgs): { settings: ContentSettings; refName: RefName; generatorKey: import("../../mod.js").GeneratorKey; insertModel(insertable: ModelInsertable, refName: RefName, options?: Pick, "noExport">): import("../Inserted.js").Inserted; insertNormalizedModel | import("../../mod.js").OasVoid, EnrichmentType_2 = undefined>(insertable: ModelInsertable, { schema, fallbackName }: Omit, "destinationPath">, options?: Pick, "noExport">): import("../../mod.js").InsertNormalisedModelReturn; register(args: import("../../mod.js").BaseRegisterArgs): void; context: GenerateContext; skipped: boolean; }; id: string; type: "model"; toIdentifier: (refName: RefName) => Identifier; toExportPath: (refName: RefName) => string; toEnrichments: ({ refName, context }: ToEnrichmentsArgs) => EnrichmentType; isSupported: () => boolean; }; export {}; //# sourceMappingURL=toModelBase.d.ts.map