import { Provider } from '../provider.js'; export interface Dictionary { [key: string]: T; } /** * Extract a subset from a larger dictionary * * @param all * @param keyList * @return subset */ export declare function lookup(all: Dictionary, keyList: string[]): Dictionary; export declare function join(kvList: { k: string; v: T; }[]): Dictionary; export declare function split(dict: Dictionary): { k: string; v: T; }[]; /** * Convert a dictionary of promises to a promise * for a dictionary */ export declare function toPromise(dict: Dictionary>): Promise>; export declare type ConfigDb = Dictionary>; /** * An entry in the AppContext configuration db - has * default dictionary and loaded overrides, * can do simple shallow merge with { ...defaults, ...overrides } */ export interface ConfigEntry { defaults: Dictionary; overrides: Dictionary; } export interface AppContextConfig { configHref: string[]; loadConfig: (href: string) => Promise>>; } export declare type ToolBox = Dictionary>; export declare function getTools(tb: ToolBox): Promise>; export declare type ToolFactory = (toolbox: ToolBox) => Provider | Promise>; export interface ProviderInfo { key: string; toolKeys: Dictionary; lambda: ToolFactory; } /** * Core application context database decoupled * from custom element configuration mechanism * * LifeCycle: * singleton - put config accepted * started - lookup config accepted, no new puts */ export declare class AppContext { static build(config: AppContextConfig): Promise; static get(): Promise; private static singletonBarrier; config: AppContextConfig; /** * Trigger context launch - invoke once * from main(). * * @returns a list of tools that * are required by registered providers, but * unbound. */ start: () => Promise; private defaultConfigs; private overrideConfigs; private providerDb; private allToolKeys; private state; private subscriptions; private startBarrier; /** * Constructor takes an immutable configuration */ constructor(config: AppContextConfig); /** * Register a new provider. * A provider's factory specifies the dependencies (toolbox) * it wants injected. A tool dependency must start with * driver/, alias/, or config/ - where config/ translates * into a call to context.getConfig * * @param keyIn automatically prepended with "driver/" if not already * @param toolKeys map from global key (driver/, alias/, or config/) * to the internal key passed to the tool factory * @param lambda */ putProvider(keyIn: string, toolKeys: Dictionary, lambda: ToolFactory): void; /** * Register a lambda to run at startup * * @param toolKeys to inject into lambda - alias to rawKey * @param lambda */ onStart(toolKeys: Dictionary, lambda: (ToolBox: any) => T | Promise): Promise; /** * Register a new provider. * * @param alias automatically prepended with "alias/" if not already * @param driverName automatically prepended with "driver/" if not already */ putAlias(alias: string, driverName: string): void; /** * * @param key must start with driver/, alias/, or config/ */ getProvider(key: string): Promise>; /** * Put a default configuration into the context. * Note that config overrides loaded at runtime * overwrite a default put into the context. * This method is intended for use by modules that * want to register default configuration at * startup time. Multiple calls to putDeafultConfig * with the same key call Object.assign() to augment * the previous value. * * @param contextIn * @param key */ putDefaultConfig(key: string, value: Dictionary): void; getConfig(key: string): Promise; getState(key: string, part: string): Promise; changeState(key: string, handler: (state: any) => Promise): Promise; /** * Load the remote configuration specified * by the constructor injected properties */ private init; private fillToolBox; private putProviderOrAlias; } export default AppContext;