@notjustcoders/ioc-arise
Version:
Arise type-safe IoC containers from your code. Zero overhead, zero coupling.
253 lines • 10.6 kB
TypeScript
import { ClassInfo, ConstructorParameter } from '../../types';
import { ImportGenerator } from '../import-generator';
/**
* Shared utility class for instantiation-related functionality used by both
* flat and modular container generators.
*/
export declare class InstantiationUtils {
/**
* Converts a string to camelCase (first letter lowercase).
*/
static toCamelCase(str: string): string;
/**
* Generates a factory function name from a class name.
*/
static generateFactoryName(className: string): string;
/**
* Generates a getter function name from a class name.
*/
static generateGetterName(className: string): string;
/**
* Generates an instance variable name from a class name.
*/
static generateInstanceName(className: string): string;
/**
* Gets the interface name, abstract class name, or falls back to class name.
*/
static getInterfaceOrClassName(classInfo: ClassInfo): string;
/**
* Creates a map of interface names to their implementing class names.
*/
static createInterfaceToClassMap(classes: ClassInfo[], importGenerator?: any): Map<string, string>;
/**
* Gets default value for a type when no implementation is found.
*/
static getDefaultValueForType(type: string, isOptional: boolean): string;
/**
* Generates constructor arguments for unmanaged dependencies.
*/
static generateConstructorArgs(params: ConstructorParameter[]): string;
/**
* Creates an instance of an unmanaged dependency.
*/
static createUnmanagedDependencyInstance(className: string, classInfo?: ClassInfo): string;
/**
* Finds a class by its interface name in a collection of classes.
*/
static findClassByInterface(interfaceName: string, classes: ClassInfo[]): ClassInfo | undefined;
/**
* Creates a dependency call for managed dependencies based on scope.
*/
static createDependencyCall(className: string, scope: string): string;
/**
* Applies indentation to a string, handling multi-line content.
*/
static applyIndentation(content: string, indentation: string): string;
/**
* Generates a constructor instantiation expression.
*/
static generateConstructorCall(className: string, constructorArgs?: string): string;
/**
* Generates a constructor instantiation expression with alias support.
*/
static generateConstructorCallWithAlias(classInfo: any, constructorArgs?: string, importGenerator?: any): string;
/**
* Generates a function call expression with optional arguments.
*/
static generateFunctionCall(functionName: string, args?: string[]): string;
/**
* Generates a getter property with return statement.
*/
static generateGetterProperty(propertyName: string, returnType: string, returnExpression: string, indentation?: string): string;
/**
* Helper method to generate object exports with consistent formatting.
*/
private static generateObjectExport;
/**
* Helper method to generate a container property with consistent formatting.
*/
private static generateContainerProperty;
/**
* Generic helper for generating code sections with consistent indentation handling.
*/
private static generateCodeSection;
/**
* Filters classes to get only singletons.
*/
static getSingletonClasses(classes: ClassInfo[]): ClassInfo[];
/**
* Filters classes to get only transients.
*/
static getTransientClasses(classes: ClassInfo[]): ClassInfo[];
/**
* Checks if a class is transient.
*/
static isTransient(classInfo: ClassInfo): boolean;
/**
* Checks if a class is singleton.
*/
static isSingleton(classInfo: ClassInfo): boolean;
/**
* Generates factory functions for transient classes.
*/
static generateTransientFactory(classInfo: ClassInfo, constructorArgs?: string, importGenerator?: any): string;
/**
* Generates a singleton variable declaration.
*/
static generateSingletonVariable(classInfo: ClassInfo, importGenerator?: any): string;
/**
* Generates a singleton getter function.
*/
static generateSingletonGetter(classInfo: ClassInfo, constructorArgs?: string, importGenerator?: any): string;
/**
* Filters classes by scope.
*/
static filterClassesByScope(classes: ClassInfo[]): {
singletonClasses: ClassInfo[];
transientClasses: ClassInfo[];
};
/**
* Creates a managed dependency call based on class scope.
*/
static createManagedDependencyCall(classInfo: ClassInfo, implementingClass: string, importGenerator?: any): string;
/**
* Creates a function signature with parameters.
*/
static createFunctionSignature(functionName: string, params: string[]): string;
/**
* Creates a module export getter.
*/
static createModuleExportGetter(classInfo: ClassInfo, importGenerator?: any): string;
/**
* Sorts classes by their dependencies using topological sorting.
*/
static sortClassesByDependencies(classes: ClassInfo[], allModuleClasses: ClassInfo[]): ClassInfo[];
/**
* Resolves a basic dependency by finding the implementing class and creating the appropriate call.
* This is the common pattern used by both flat and modular generators.
*/
static resolveBasicDependency(dependency: string, availableClasses: ClassInfo[], interfaceToClassMap?: Map<string, string>, importGenerator?: ImportGenerator, requestingClass?: ClassInfo): string | null;
/**
* Generates constructor arguments string from an array of argument strings.
* Common pattern used by both generators.
*/
static joinConstructorArguments(args: string[]): string;
/**
* Generates a section of transient factory functions with optional indentation.
* Used by both flat and modular generators.
*/
static generateTransientFactoriesSection(classes: ClassInfo[], constructorArgsResolver: (classInfo: ClassInfo) => string, indentation?: string, importGenerator?: any): string[];
/**
* Generates a section of singleton variable declarations with optional indentation.
* Used by both flat and modular generators.
*/
static generateSingletonVariablesSection(classes: ClassInfo[], indentation?: string, importGenerator?: any): string[];
/**
* Generates a section of singleton getter functions with optional indentation.
* Used by both flat and modular generators.
*/
static generateSingletonGettersSection(classes: ClassInfo[], constructorArgsResolver: (classInfo: ClassInfo) => string, indentation?: string, importGenerator?: any): string[];
/**
* Generates a section of module exports with optional indentation.
* Used by modular generators.
*/
static generateModuleExportsSection(classes: ClassInfo[], indentation?: string, importGenerator?: any): string[];
/**
* Generates a container property getter for singleton classes.
* Used by flat container generators.
*/
static generateSingletonContainerProperty(classInfo: ClassInfo): string;
/**
* Generates a container property getter for transient classes.
* Used by flat container generators.
*/
static generateTransientContainerProperty(classInfo: ClassInfo): string;
/**
* Generates the complete container object with all properties.
* Used by flat container generators.
*/
static generateContainerObject(classes: ClassInfo[]): string;
/**
* Generates the container type export.
* Used by flat container generators.
*/
static generateContainerTypeExport(): string;
/**
* Generates the container type export with path injection utilities.
* Used by flat container generators.
* @param outputPath Path to the container file to check for existing onInit content
*/
static generateContainerTypeExportWithPathUtils(outputPath?: string): string;
/**
* Generates a module function parameter with proper typing.
* Used by modular generators for creating function parameters.
*/
static generateModuleFunctionParameter(moduleName: string): string;
/**
* Generates function parameters for module dependencies.
* Used by modular generators.
*/
static generateModuleFunctionParameters(moduleDeps: Set<string>): string[];
/**
* Generates a module container variable name.
* Used by modular generators.
*/
static generateModuleContainerVariableName(moduleName: string): string;
/**
* Generates a module container function name.
* Used by modular generators.
*/
static generateModuleContainerFunctionName(moduleName: string): string;
/**
* Generates function arguments for module dependencies.
* Used by modular generators.
*/
static generateModuleFunctionArguments(moduleDeps: Set<string>): string[];
/**
* Generates module instantiation code.
* Used by modular generators.
*/
static generateModuleInstantiation(moduleName: string, moduleDependencies: Map<string, Set<string>>): string;
/**
* Generates a module export entry for the aggregated container.
* Used by container aggregators.
*/
static generateModuleExportEntry(moduleName: string): string;
/**
* Generates the aggregated container code for modular architecture.
* Used by container aggregators.
*/
static generateAggregatedContainer(sortedModules: string[]): string;
/**
* Generates the modular container type export.
* Used by container aggregators.
*/
static generateModularContainerTypeExport(): string;
/**
* Generates the modular container type export with path injection utilities.
* Used by container aggregators.
* @param outputPath Path to the container file to check for existing onInit content
*/
static generateModularContainerTypeExportWithPathUtils(outputPath?: string): string;
/**
* Generates a module function return object.
* Used by module function body generators.
*/
static generateModuleFunctionReturnObject(moduleExports: string[]): string;
/**
* Generates the complete module function body.
* Used by module function body generators.
*/
static generateModuleFunctionBody(moduleClasses: ClassInfo[], constructorArgsResolver: (classInfo: ClassInfo) => string, importGenerator?: any): string;
}
//# sourceMappingURL=instantiation-utils.d.ts.map