import { BlueBase } from '../BlueBase'; /** * Source of this item. Contains information about who registered this it. */ export interface ItemSource { type: 'plugin' | 'boot' | 'system' | 'custom'; key?: string; } /** * BlueBase Registry Item */ export interface RegistryItem { /** Additional Item Data */ [key: string]: any; /** Item Key */ key: string; /** * Registry Item Value. */ value: ValueType; /** The source of this item */ source: ItemSource; } /** * BlueBase Registry Item */ export interface RegistryInputItem { /** Additional Item Data */ [key: string]: any; /** * Registry Item Value. */ value: ValueType; } /** * A collection of input items. Used by `registerCollection` function. */ export type ItemCollection = Array | { [key: string]: T | T['value']; }; /** * Callback function called when a subscription update is published. */ export type RegistrySubscriptionFn = (value: ItemType['value'], item: ItemType) => void; /** * A Base Registry */ export declare class Registry { protected BB: BlueBase; /** Internal data */ protected data: Map; /** List of subscriptions */ protected subscriptions: Map>>; constructor(BB: BlueBase); /** * The get() method returns a specified registry item. * @param key */ get(...keys: string[]): ItemType | undefined; /** * The set() method adds or updates an element with a specified * key and item to the registry. * @param key * @param value */ set(key: string, item: ItemType | ItemInputType): this; /** * The getValue() method returns a specified value from a Registry object. * @param key */ getValue(...keys: string[]): ItemType['value'] | undefined; /** * The setValue() method adds or updates the value a registry item with the specified key. * @param key * @param value */ setValue(key: string, value: ItemType['value'] | ItemInputType['value']): this; /** * The setMeta() method sets extra props of a registry item * @param key * @param props */ setMeta(key: string, meta: { [key: string]: any; }): void; setMeta(key: string, metaKey: string, metaValue: any): void; /** * The setMeta() method gets extra props of a registry item * @param key * @param props */ getMeta(key: string, metaKey: string, defaultValue?: any): any; /** * Adds an Item or an Item value to the registry. * * @param item */ register(item: ItemType | ItemType['value'] | ItemInputType | ItemInputType['value']): Promise; register(key: string, item: ItemType | ItemType['value'] | ItemInputType | ItemInputType['value']): Promise; /** * Register a collection of items. * @param collection */ registerCollection(collection?: ItemCollection, meta?: { [key: string]: any; source?: ItemSource; }): Promise; /** * The has() method returns a boolean indicating whether an element * with the specified key exists or not. * @param key */ has(key: string): boolean; /** * The delete() method removes the specified element from a Registry object. * @param key */ delete(key: string): boolean; /** * The clear() method removes all elements from a Registry object. */ clear(): void; /** * The entries() method returns a new Iterator object that * contains the [key, value] pairs for each element in the Registry * object in insertion order. */ entries(): IterableIterator<[string, ItemType]>; /** * The keys() method returns a new Iterator object that contains * the keys for each element in the Registry object in insertion order. */ keys(): IterableIterator; /** * The values() method returns a new Iterator object that contains * the values for each element in the Registry object in insertion order. */ values(): IterableIterator; /** * Returns the number of items in the Registry. */ size(): number; /** * The forEach() method executes a provided function once per * each key/value pair in the Registry object, in insertion order. * @param callbackfn * @param thisArg */ forEach(callbackfn: (value: ItemType, key: string, map: Map) => void, thisArg?: any): void; /** * Filter registry items by a predicate function. * @param predicate */ filter(predicate: (value: ItemType['value'], key: string, item: ItemType) => boolean): { [key: string]: ItemType; }; /** * Filter registry items by a predicate function. * @param predicate */ filterValues(predicate: (value: ItemType['value'], key: string, item: ItemType) => boolean): { [key: string]: ItemType; }; /** * Subscribe to a config value update * @param key Config key * @param callback Callback function * @returns Subscription ID */ subscribe(key: string, callback: RegistrySubscriptionFn): string; /** * Unsubscribe from a config value update * @param key Config key * @param subscriptionId Subscription ID */ unsubscribe(key: string, subscriptionId: string): void; /** * Convert any input value to an item. This is where you transform inputs and add defualts * @param key * @param partial */ protected createItem(key: string, partial: ItemType | ItemInputType): ItemType; /** * Typeguard to check a given object is a registry value * @param value */ protected isValue(value: any): value is ItemType['value']; /** * Typeguard to check a given object is an input value * @param value */ protected isInputValue(value: any): value is ItemInputType['value']; /** * Typeguard to check a given object is a registry item * @param item */ protected isItem(item: any): item is ItemType; /** * Typeguard to check a given object is a input item * @param item */ protected isInputItem(item: any): item is ItemInputType; /** * Publishes updates of a config value change to all the subscribers * @param key * @param item */ protected publish(key: string, item: ItemType): void; /** * Find one item in a given sequence. Returns the first item found. * @param keys */ protected findOne(...keys: any[]): ItemType | undefined; /** * Used internally by the register method. Since this function as many overloads, * resolves final key and value params. * @param item */ protected getKeyAnyItem(item: ItemType | ItemType['value'] | ItemInputType | ItemInputType['value']): { key: string; item: ItemType | ItemType['value'] | ItemInputType | ItemInputType['value']; }; protected getKeyAnyItem(key: string, item: ItemType | ItemType['value'] | ItemInputType | ItemInputType['value']): { key: string; item: ItemType | ItemType['value'] | ItemInputType | ItemInputType['value']; }; /** * This function is used to auto generate an item key * @param item */ protected generateKey(_item: ItemType | ItemType['value'] | ItemInputType | ItemInputType['value']): string | undefined; }