UNPKG

arvo-event-handler

Version:

Type-safe event handler system with versioning, telemetry, and contract validation for distributed Arvo event-driven architectures, featuring routing and multi-handler support.

65 lines (64 loc) 2.92 kB
import { type SpanOptions } from '@opentelemetry/api'; import type { ArvoEvent } from 'arvo-core'; import type { ArvoEventHandlerOpenTelemetryOptions } from '../types'; export declare function isError(e: unknown): e is Error; /** * Checks if the item is null or undefined. * * @param item - The value to check. * @returns True if the item is null or undefined, false otherwise. */ export declare function isNullOrUndefined(item: unknown): item is null | undefined; /** * Returns the provided value if it's not null or undefined; otherwise, returns the default value. * * @template T - The type of the value and default value. * @param value - The value to check. * @param defaultValue - The default value to return if the provided value is null or undefined. * @returns The provided value if it's not null or undefined; otherwise, the default value. */ export declare function getValueOrDefault<T>(value: T | null | undefined, defaultValue: NonNullable<T>): NonNullable<T>; /** * Returns the first non-null and non-undefined value from the provided arguments. * If all arguments are null or undefined, returns undefined. * * @template T - The type of the values. * @param values - The values to coalesce. * @returns The first non-null and non-undefined value, or undefined if all are null or undefined. */ export declare function coalesce<T>(...values: (T | null | undefined)[]): T | undefined; /** * Returns the first non-null and non-undefined value from the provided array of values. * If all values in the array are null or undefined, returns the specified default value. * * @template T - The type of the values and the default value. * @param values - An array of values to coalesce. * @param _default - The default value to return if all values in the array are null or undefined. * @returns The first non-null and non-undefined value from the array, or the default value if all are null or undefined. * * @example * const result = coalesceOrDefault([null, undefined, 'hello', 'world'], 'default'); * console.log(result); // Output: 'hello' * * @example * const result = coalesceOrDefault([null, undefined], 'default'); * console.log(result); // Output: 'default' */ export declare function coalesceOrDefault<T>(values: (T | null | undefined)[], _default: NonNullable<T>): NonNullable<T>; export declare const createEventHandlerTelemetryConfig: (name: string, options: SpanOptions, contextConfig: ArvoEventHandlerOpenTelemetryOptions, event: ArvoEvent) => { name: string; disableSpanManagement: boolean; spanOptions: SpanOptions; context: { inheritFrom: "TRACE_HEADERS"; traceHeaders: { traceparent: string | null; tracestate: string | null; }; context?: undefined; } | { inheritFrom: "CONTEXT"; context: import("@opentelemetry/api").Context; traceHeaders?: undefined; }; };