import { Context } from './context'; import { Constructor } from './resolver'; import { Provider } from './provider'; export declare type BoundValue = any; export declare type ValueOrPromise = T | Promise; export declare class Binding { isLocked: boolean; static PROPERTY_SEPARATOR: string; /** * Validate the binding key format. Please note that `#` is reserved. * @param key Binding key, such as `a, a.b, a:b, a/b */ static validateKey(key: string): string; /** * Remove the segament that denotes a property path * @param key Binding key, such as `a, a.b, a:b, a/b, a.b#x, a:b#x.y, a/b#x.y` */ static normalizeKey(key: string): string; /** * Get the property path separated by `#` * @param key Binding key */ static getKeyPath(key: string): string | undefined; private readonly _key; private _tags; valueConstructor: Constructor; constructor(_key: string, isLocked?: boolean); readonly key: string; readonly tags: Set; /** * This is an internal function optimized for performance. * Users should use `@inject(key)` or `ctx.get(key)` instead. * * Get the value bound to this key. Depending on `isSync`, this * function returns either: * - the bound value * - a promise of the bound value * * Consumers wishing to consume sync values directly should use `isPromise` * to check the type of the returned value to decide how to handle it. * * ``` * const result = binding.getValue(ctx); * if (isPromise(result)) { * result.then(doSomething) * } else { * doSomething(result); * } * ``` */ getValue(ctx: Context): BoundValue | Promise; lock(): this; tag(tagName: string | string[]): this; /** * Bind the key to a constant value. * * @param value The bound value. * * @example * * ```ts * ctx.bind('appName').to('CodeHub'); * ``` */ to(value: BoundValue): this; /** * Bind the key to a computed (dynamic) value. * * @param factoryFn The factory function creating the value. * Both sync and async functions are supported. * * @example * * ```ts * // synchronous * ctx.bind('now').toDynamicValue(() => Date.now()); * * // asynchronous * ctx.bind('something').toDynamicValue( * async () => Promise.delay(10).then(doSomething) * ); * ``` */ toDynamicValue(factoryFn: () => BoundValue | Promise): this; /** * Bind the key to a BindingProvider */ toProvider(providerClass: Constructor>): this; /** * Bind the key to an instance of the given class. * * @param ctor The class constructor to call. Any constructor * arguments must be annotated with `@inject` so that * we can resolve them from the context. */ toClass(ctor: Constructor): this; unlock(): this; }