@adonisjs/fold
Version:
Simplest and straightforward implementation of IoC container in JavaScript
59 lines (58 loc) • 1.6 kB
TypeScript
import type { Constructor } from '@poppinss/utils/types';
/**
* Type guard to check if value is a class constructor. Plain old
* functions are not considered as class constructors.
*
* @param value - The value to check
*
* @example
* ```ts
* isClass(Database) // true
* isClass(function foo() {}) // false
* isClass(() => {}) // false
* ```
*/
export declare function isClass<T>(value: unknown): value is Constructor<T>;
/**
* Converts a function to a self-contained queue, where each call to
* the function is queued until the first call resolves or rejects.
*
* After the first call, the value is cached and used forever.
* This is used to implement singleton bindings in the container.
*
* @param callback - The function to enqueue
*
* @example
* ```ts
* const queuedFn = enqueue(async () => {
* return new Database()
* })
*
* // First call executes the function
* const db1 = await queuedFn()
*
* // Second call returns cached value
* const db2 = await queuedFn()
*
* // db1 === db2.value
* ```
*/
export declare function enqueue(callback: Function): (...args: any) => Promise<{
value: any;
cached: boolean;
}>;
/**
* Dynamically import a module and ensure it has a default export
*
* @param importPath - The module path to import
* @param parentURL - The parent URL for resolving the import path
*
* @example
* ```ts
* const UserController = await resolveDefault(
* '#controllers/users_controller',
* import.meta.url
* )
* ```
*/
export declare function resolveDefault(importPath: string, parentURL: URL | string): Promise<any>;