import { Emitter } from "./nanoevents.js"; import { Prettify, Assign, KeysOrCb, ContextGetter, UnpackFunction, MyRecord, FullyUnpackObject, UnPromisify, UnpackFunctionReturn } from "./_utils.js"; import type { Intersection } from "utility-types"; declare abstract class AbstractContainer { abstract get(token: T): UnpackFunction; abstract getTokens(): { [M in T]: T; }; } type Events = { containerUpdated: (payload: { key: keyof Context; newContainer: Context[keyof Context]; newItem: Context[keyof Context]; }) => void; containerUpserted: (payload: { key: keyof Context; newContainer: Context[keyof Context] | null; newItem: Context[keyof Context] | null; }) => void; containerDeleted: (payload: { key: keyof Context; }) => void; containerDisposed: (payload: { key: keyof Context; }) => void; itemUpdated: (payload: { key: keyof Context; newItem: Context[keyof Context] | null; }) => void; itemUpserted: (payload: { key: keyof Context; newItem: Context[keyof Context] | null; }) => void; itemDeleted: (payload: { key: keyof Context; }) => void; itemDisposed: (payload: { key: keyof Context; }) => void; }; declare class InternalContainer extends AbstractContainer { /** * When we create a new class instance or function, we cache the output */ private _cache; private _cacheSync; /** * Holds key:value factories in a form token:factory */ _context: Context; /** * Here we hold references to "disposers". * A disposer is a function assigned to a token that will be called when * `dispose` call is made. */ _disposeCtx: { [K in keyof DisposeContext]?: any; }; /** * EventEmitter Logic */ protected ee: Emitter>; on>(event: E, callback: Events[E]): import("./nanoevents.js").Unsubscribe; constructor(); protected _storeInSyncCache(token: keyof Context, v: any): void; protected _storeInCache(token: keyof Context, v: any): void; get(token: SearchToken): UnpackFunction; getSync(token: SearchToken): UnpackFunction; delete(token: SearchToken): Container, DisposeContext>; dispose(token: DisposeToken): Promise; /** * Will naively dispose all the containers in the dispose context. * * It will only dispose values we've touched / created. * * Always async, because disposing is 95% async anyway */ disposeAll(): Promise; protected _updateContext(updatedContext: Context): void; subscribeToItem(token: T, cb: (err: any, container: UnpackFunction) => void): () => void; /** * @deprecated Use `subscribeToItem` instead. This method will be removed in a future version. */ subscribeToContainer: (token: T, cb: (err: any, container: UnpackFunction) => void) => () => void; getTokens(): { [T in keyof Context]: T; }; } export declare class Container extends InternalContainer { constructor(); upsert(newContext: NewContext | ((containers: ContextGetter, self: Container) => NewContext)): Container>, DisposeContext>; add, NewContext>>(newContextOrCb: NewContext | ((items: ContextGetter, self: Container) => NewContext)): Container>, DisposeContext>; addDisposer>) => any; }>(newContextOrCb: NewDisposerContext | ((items: ContextGetter, self: Container) => NewDisposerContext)): Container>; _extractTokens(tokensOrCb: KeysOrCb): T[]; subscribeToItems(tokensOrCb: T | ((t: { [K in keyof Context]: K; }) => T), cb: (err: any, container: { [K in T[number]]: FullyUnpackObject[K]; }) => void): () => void; getItemsSync(tokensOrCb: KeysOrCb): Promise<{ [K in T]: FullyUnpackObject[K]; }> | { [K in T]: FullyUnpackObject[K]; }; /** * Gets multiple items from the container by their tokens. * Handles both synchronous and asynchronous values properly. */ getItems(tokensOrCb: T | ((t: { [K in keyof Context]: K; }) => T)): Promise<{ [K in T[number]]: FullyUnpackObject[K]; }>; get items(): ContextGetter; /** * This is used to get a container from the context. * It should always return a promise? * But it seems that it is not possible to do that with the current implementation. * @deprecated */ get containers(): ContextGetter; /** * @deprecated Use `getItems` instead. This method will be removed in a future version. */ getContainerSet: (tokensOrCb: T | ((t: { [K in keyof Context]: K; }) => T)) => Promise<{ [K in T[number]]: FullyUnpackObject[K]; }>; /** * @deprecated Use `subscribeToItems` instead. This method will be removed in a future version. */ subscribeToContainerSet: (tokensOrCb: T | ((t: { [K in keyof Context]: K; }) => T), cb: (err: any, container: { [K in T[number]]: FullyUnpackObject[K]; }) => void) => () => void; } export declare function createContainer(): Container<{}, {}>; export {};