import type { Return } from '@kraftr/errors'; import EventEmitter from 'node:events'; import { BindingAddress } from '../bindings'; import { ContextNotFound, SourceNotDefined } from '../errors'; import { BindingSource, BindingType } from './types'; export declare class Binding extends EventEmitter { key: BindingAddress; scope: string; tagMap?: Map; private _cache; private _source; private _initialized; isLocked: boolean; constructor(key: BindingAddress); get type(): BindingType; /** * @throws LockError * @param value - to bind to the key * @returns this */ with(value: BindingSource['value']): Return; /** * Cache the result even with transient, recompute the value when dependencies changes (inner binds) * @param value */ memoize(value?: boolean): this; /** * Mark this bind as locked so any change to the source is not allowed * @returns this */ lock(): this; /** * Mark this binding as constant, this way always the source is returned as is * @returns this */ constant(): this; /** * Mark this binding as dynamic, so if the source * is a function this will be called every time value() is called * @returns this */ dynamic(): this; /** * Mark this binding as the source is newable object, so every call to * value() would return a new instance * @returns this */ class(): this; tag(key: string, value?: unknown): this; apply(template: (bind: this) => Bind): Bind; /** * * @param bindingScope context scope where attach this binding * @returns this */ in(bindingScope: string): this; /** * @throws SourceNotDefined | ContextNotFound * @returns bound value */ value(): Return; /** * Locate and check for the resolution context * @throws ContextNotFound */ private getResolutionContext; on(eventName: 'tag', listener: (key: string, value: unknown) => void): this; on(eventName: 'source' | 'value', listener: (value: BindingSource['value']) => void): this; on(eventName: 'scope', listener: (newScope: string) => void): this; emit(eventName: 'tag', key: string, value: unknown): boolean; emit(eventName: 'source' | 'value', value: BindingSource['value']): boolean; emit(eventName: 'scope', scope: string): boolean; }