import { AnyVoid, RequiredAll } from './internals/types.js'; import { Serializable } from './internals/serializable.js'; /** * Copyright 2025 IBM Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ type MatcherFn = (event: EventMeta) => boolean; type Matcher = "*" | "*.*" | RegExp | MatcherFn; type InferCallbackValue = NonNullable extends Callback ? P : never; type Callback = (value: T, event: EventMeta) => AnyVoid; type CleanupFn = () => void; type StringKey = Extract; interface EmitterOptions { isBlocking?: boolean; once?: boolean; persistent?: boolean; matchNested?: boolean; } interface EventTrace { id: string; runId: string; parentRunId?: string; } interface EventMeta { id: string; groupId?: string; name: string; path: string; createdAt: Date; source: Emitter; creator: object; context: C; trace?: EventTrace; } /** * Copyright 2025 IBM Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ interface EmitterInput { groupId?: string; namespace?: string[]; creator?: object; context?: E & object; trace?: EventTrace; } interface EmitterChildInput { groupId?: string; namespace?: string[]; creator?: object; context?: E & object; trace?: EventTrace; } interface Listener { readonly match: MatcherFn; readonly raw: Matcher; readonly callback: Callback; readonly options?: EmitterOptions; } declare class Emitter>> extends Serializable { protected listeners: Set>; protected readonly groupId?: string; readonly namespace: string[]; readonly creator?: object; readonly context: object; readonly trace?: EventTrace; protected readonly cleanups: CleanupFn[]; constructor(input?: EmitterInput); static get root(): Emitter>>; child(input?: EmitterChildInput): Emitter; pipe(target: Emitter): CleanupFn; destroy(): void; reset(): void; registerCallbacks>>(callbacks: Partial extends Callback ? Callback : never>>, options?: Partial>): CleanupFn; on>>(event: K, callback: NonNullable extends Callback ? T[K] : never, options?: EmitterOptions): CleanupFn; match(matcher: Matcher, callback: Callback, options?: EmitterOptions): CleanupFn; emit>>(name: K, value: NonNullable extends Callback ? X : unknown): Promise; protected invoke(data: unknown, event: EventMeta): Promise; protected createEvent(name: string): EventMeta; createSnapshot(): { groupId: string | undefined; namespace: string[]; creator: object | undefined; context: object; trace: EventTrace | undefined; listeners: { readonly options?: EmitterOptions | undefined; readonly raw: Matcher; readonly callback: Callback; }[]; cleanups: CleanupFn[]; }; loadSnapshot({ listeners, ...snapshot }: ReturnType): void; } export { type Callback as C, Emitter as E, type InferCallbackValue as I, type MatcherFn as M, type StringKey as S, type Matcher as a, type CleanupFn as b, type EmitterOptions as c, type EventTrace as d, type EventMeta as e, type EmitterInput as f, type EmitterChildInput as g };