##// END OF EJS Templates
working on typings
working on typings

File last commit:

r8:80cb5668e4a7 default
r8:80cb5668e4a7 default
Show More
interfaces.ts
183 lines | 7.9 KiB | video/mp2t | TypeScriptLexer
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 import { key } from "./traits";
cin
working on fluent configuration
r1
cin
initial commit
r0 export interface IDestroyable {
destroy(): void;
}
cin
working on fluent configuration
r1 /**
* @template S Карта доступных зависимостей
*/
cin
working on typings
r8 export interface Resolver<S> {
cin
working on fluent configuration
r1 /**
* Функция для разрешения зависимостей, поддерживает создание фабричных методов,
* отложенную активацию и значение по-умолчанию для сервисов
* @template K Ключ сервиса из {@link S}
* @template O Тип параметра {@link opts} используется для выведения типа
* возвращаемого значения.
* @param name Ключ сервиса, который будет разрешен.
* @param {boolean=} opts.lazy Признак того, что требуется отложенная активация,
* будет возвращен фабричный метод для получения зависимости. Если не указан,
* то считается `false`.
* @param {any=} opts.default Значение по умолчанию, если в контейнере указанный
* сервис не зарегистрирован
* @returns Либо фабричный метод для получения зависимости, либо значение зависимости
* @throws Error Если зависимость не найдена и не предоставлено значение по-умолчанию
*/
<K extends keyof S, O extends { lazy: true; default?: unknown }>(name: K, opts?: O): () => (O extends { default: infer T } ? T : never) | NonNullable<S[K]>;
<K extends keyof S, O extends { lazy?: false; default?: unknown }>(name: K, opts?: O): (O extends { default: infer T } ? T : never) | NonNullable<S[K]>;
cin
initial commit
r0 }
cin
working on typings
r8 export type DepsMap<S> = {
[k in key]: Refs<S> | keyof S;
cin
improved typings
r7 };
cin
working on typings
r8 export type Refs<S> = {
cin
improved typings
r7 [k in keyof S]: Ref<k, boolean, S[k]>;
cin
working on typings
r8 }[keyof S];
cin
improved typings
r7
export type Ref<K extends key, L extends boolean, D> = { name: K, lazy?: L, default?: D | null };
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4
cin
improved typings
r7 export type Lazy<T, L extends boolean> = L extends true ? () => T : T;
export type InferDefault<T> = T extends { default: infer D } ? D : never;
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4
cin
working on typings
r8 export type Resolve<S, R> =
cin
improved typings
r7 R extends keyof S ? NonNullable<S[R]> :
cin
working on typings
r8 R extends Ref<infer K, infer L, unknown> ?
K extends keyof S ? Lazy<NonNullable<S[K]> | InferDefault<R>, L> :
never :
cin
improved typings
r7 never;
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4
cin
working on typings
r8 /**
* Интерфейс для конфигурирования сервиса в контейнере
*/
export interface IDescriptorBuilder<S, T, R, O extends keyof S> {
cin
working on fluent configuration
r1
cin
working on typings
r8 /** Указывает фабрика для создания экземпляра сервиса, фабрика передается
* в виде параметра. При вызове фабрике будет передан объект с зависимостями,
* которые были предварительно указаны вызовами метода `wants(...)`
cin
working on fluent configuration
r1 *
cin
working on typings
r8 * Вызов данного метода завершает конфигурирование сервиса.
*
* @param f Фабрика для создания экземпляра сервиса
cin
working on fluent configuration
r1 */
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 factory(f: (refs: R) => T): void;
cin
working on typings
r8 /**
* Используется для указания зависимостей, которые потребуются фабричному
* методу при создании нового экземпляра сервиса. Данный метод может быть
* вызван несколько раз подряд, при этом вызовы этого метода имеют
* кумулятивный эффект.
*
* @template X Тип объекта с зависимостями, которые требуется получить при
* создании экземпляра фабрики при помощи фабричного метода.
* @param refs Объект с описанием зависимостей
* @returns Возвращает дескриптор сервиса, в котором указаны необходимые
* зависимости
*/
cin
improved typings
r7 wants<X extends DepsMap<S> & Record<keyof R & keyof X, never>>(refs: X):
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 IDescriptorBuilder<S, T, R & {
cin
improved typings
r7 [k in keyof X]: Resolve<S, X[k]>;
cin
Corrected method signatures
r6 }, O>
cin
initial commit
r0
cin
Corrected method signatures
r6 override<K extends O>(name: K, builder: RegistrationBuilder<S, NonNullable<S[K]>>): this;
override<K extends O>(services: { [name in K]: RegistrationBuilder<S, NonNullable<S[K]>> }): this;
cin
initial commit
r0
cin
working on fluent configuration
r1 lifetime(lifetime: "singleton", typeId: string | number | object): this;
lifetime(lifetime: ILifetime<T> | Exclude<ActivationType, "singleton">): this;
cin
initial commit
r0
cin
working on typings
r8 /** Указывает функцию для освобождения экземпляра сервиса для случаев, когда
* время жизни привязано к контейнеру.
*/
cin
initial commit
r0 cleanup(cb: (item: T) => void): this;
cin
working on typings
r8 /**
* Регистрирует в контейнере постоянное значение в качестве реализации сервиса.
*
* @param v Экземпляр реализации сервиса.
*/
cin
initial commit
r0 value(v: T): void;
}
cin
working on typings
r8 export type RegistrationBuilder<S, T> = (d: IDescriptorBuilder<S, T, object, ConfigurableKeys<S>>) => void;
cin
initial commit
r0
cin
Corrected method signatures
r6 export type RegistrationBuildersMap<S extends Configurable<S>, K extends keyof S = keyof S> = {
cin
Working on container builder
r5 [k in K]-?: RegistrationBuilder<ContainerServices<S>, NonNullable<S[k]>>
cin
working on fluent configuration
r1 };
cin
initial commit
r0
cin
working on typings
r8 export interface Descriptor<S, T> {
cin
Working on container builder
r5 activate(context: IActivationContext<S>): T;
cin
initial commit
r0 }
cin
working on typings
r8 export interface IActivationContext<S> extends ServiceLocator<S> {
cin
Working on container builder
r5 createLifetime<T>(): ILifetime<T>;
createContainerLifetime<T>(): ILifetime<T>;
}
cin
working on typings
r8 export type RegistrationMap<S, K extends keyof S = keyof S> = {
cin
working on fluent configuration
r1 [k in K]-?: Descriptor<S, S[k]>;
cin
initial commit
r0 };
cin
working on typings
r8 export interface ContainerProvided<S> {
cin
working on fluent configuration
r1 container: ServiceLocator<ContainerServices<S>>;
cin
Working on container builder
r5 childContainer: IContainerBuilder<S>;
cin
working on fluent configuration
r1 }
cin
working on typings
r8 export type Configurable<S> = { [k in keyof S]: k extends ProvidedKeys ? never : S[k]; };
cin
working on fluent configuration
r1
cin
Working on container builder
r5 export type ProvidedKeys = keyof ContainerProvided<never>;
cin
working on fluent configuration
r1
cin
working on typings
r8 export type ContainerServices<S> =
{ [k in keyof S as k extends ProvidedKeys ? never: k]: S[k] } &
ContainerProvided<S>;
cin
working on fluent configuration
r1
cin
working on typings
r8 export type ConfigurableKeys<S> = Exclude<keyof S, ProvidedKeys>;
cin
working on fluent configuration
r1
cin
working on typings
r8 export type ConfigurableServices<S> = Pick<S, ConfigurableKeys<S>>;
cin
initial commit
r0
cin
working on typings
r8 export type ContainerKeys<S> = keyof S | ProvidedKeys;
cin
Working on container builder
r5
cin
working on typings
r8 export interface ServiceLocator<S> {
cin
working on fluent configuration
r1 resolve<K extends keyof S>(name: K): NonNullable<S[K]>;
resolve<K extends keyof S, T>(name: K, def: T): NonNullable<S[K]> | T;
cin
initial commit
r0 }
cin
working on fluent configuration
r1 export interface LifetimeContainer {
createLifetime<T>(): ILifetime<T>;
}
cin
working on typings
r8 export interface ServiceContainer<S> extends
cin
Working on container builder
r5 ServiceLocator<ContainerServices<S>>,
IDestroyable {
cin
working on fluent configuration
r1
cin
Working on container builder
r5 createChildContainer(): IContainerBuilder<S>;
}
cin
initial commit
r0
cin
working on typings
r8 export interface IContainerBuilder<S> {
cin
Corrected method signatures
r6 createServiceBuilder<K extends keyof S>(name: K): IDescriptorBuilder<S, NonNullable<S[K]>, object, keyof S>;
cin
Working on container builder
r5
build(): ServiceContainer<S>;
cin
initial commit
r0 }
export type ActivationType = "singleton" | "container" | "hierarchy" | "context" | "call";
/**
* Интерфейс для управления жизнью экземпляра объекта. Каждая регистрация имеет
* свой собственный объект `ILifetime`, который создается при первой активации
*/
cin
working on fluent configuration
r1 export interface ILifetime<T> {
cin
initial commit
r0 /** Проверяет, что уже создан экземпляр объекта */
has(): boolean;
cin
working on fluent configuration
r1 get(): T;
cin
Working on container builder
r5 initialize(context: IActivationContext<object>): void;
cin
initial commit
r0
cin
working on fluent configuration
r1 store(item: T, cleanup?: (item: T) => void): void;
}
cin
initial commit
r0
cin
code comments
r2 export type ExtractRequired<T, K extends keyof T = keyof T> = { [p in K as (undefined extends T[p] ? never : p)]-?: T[p] };
cin
working on fluent configuration
r1