1 | import type { Make, Hooks, Swaps, Bindings, BindingKey, Constructor, ErrorCreator, BindingValues, ExtractFunctions, ContainerOptions, ContextualBindings, AbstractConstructor } from './types.js';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export declare class ContainerResolver<KnownBindings extends Record<any, any>> {
|
16 | #private;
|
17 | constructor(container: {
|
18 | bindings: Bindings;
|
19 | bindingValues: BindingValues;
|
20 | swaps: Swaps;
|
21 | hooks: Hooks;
|
22 | aliases: Map<Partial<keyof KnownBindings>, keyof KnownBindings | AbstractConstructor<any>>;
|
23 | contextualBindings: Map<Constructor<any>, ContextualBindings>;
|
24 | }, options: ContainerOptions);
|
25 | /**
|
26 | * Find if the resolver has a binding registered using the
|
27 | * "bind", the "singleton", or the "bindValue" methods.
|
28 | */
|
29 | hasBinding<Binding extends keyof KnownBindings>(binding: Binding): boolean;
|
30 | hasBinding(binding: BindingKey): boolean;
|
31 | /**
|
32 | * Find if the resolver has all the bindings registered using the
|
33 | * "bind", the "singleton", or the "bindValue" methods.
|
34 | */
|
35 | hasAllBindings<Binding extends keyof KnownBindings>(bindings: Binding[]): boolean;
|
36 | hasAllBindings(bindings: BindingKey[]): boolean;
|
37 | /**
|
38 | * Resolves binding in context of a parent. The method is same as
|
39 | * the "make" method, but instead takes a parent class
|
40 | * constructor.
|
41 | */
|
42 | resolveFor<Binding>(parent: unknown, binding: Binding, runtimeValues?: any[], createError?: ErrorCreator): Promise<Make<Binding>>;
|
43 | /**
|
44 | * Resolves the binding or constructor a class instance as follows.
|
45 | *
|
46 | * - Resolve the binding from the values (if registered)
|
47 | * - Resolve the binding from the bindings (if registered)
|
48 | * - If binding is a class, then create a instance of it. The constructor
|
49 | * dependencies are further resolved as well.
|
50 | * - All other values are returned as it is.
|
51 | *
|
52 | * ```ts
|
53 | * await resolver.make('route')
|
54 | * await resolver.make(Database)
|
55 | * ```
|
56 | */
|
57 | make<Binding extends keyof KnownBindings>(binding: Binding, runtimeValues?: any[], createError?: ErrorCreator): Promise<Binding extends string | symbol ? KnownBindings[Binding] : Make<Binding>>;
|
58 | make<Binding>(binding: Binding, runtimeValues?: any[], createError?: ErrorCreator): Promise<Make<Binding>>;
|
59 | /**
|
60 | * Call a method on an object by injecting its dependencies. The method
|
61 | * dependencies are resolved in the same manner as a class constructor
|
62 | * dependencies.
|
63 | *
|
64 | * ```ts
|
65 | * await resolver.call(await resolver.make(UsersController), 'index')
|
66 | * ```
|
67 | */
|
68 | call<Value extends Record<any, any>, Method extends ExtractFunctions<Value>>(value: Value, method: Method, runtimeValues?: any[], createError?: ErrorCreator): Promise<ReturnType<Value[Method]>>;
|
69 | /**
|
70 | * Register a binding as a value
|
71 | *
|
72 | * ```ts
|
73 | * container.bindValue(Route, new Route())
|
74 | * ```
|
75 | */
|
76 | bindValue<Binding extends keyof KnownBindings>(
|
77 | |
78 |
|
79 |
|
80 | binding: Binding extends string | symbol ? Binding : never, value: KnownBindings[Binding]): void;
|
81 | bindValue<Binding extends AbstractConstructor<any>>(binding: Binding, value: InstanceType<Binding>): void;
|
82 | }
|