import { type Encodable, type SensitivityMask } from "@automate.ax/codec"; import { type AutomationErrorValue } from "@automate.ax/api-contract/errors"; import type { SignalDerivation } from "@automate.ax/api-contract/runtime"; import type ms from "ms"; import type { AutomationRunState, RuntimeValueContext } from "./runtime.js"; import type { SignalCoreMethods, SignalMethods, SignalRegisteredMethods, SignalReservedMethods } from "./signal-methods.js"; export declare const signalDependencyCollector: unique symbol; export declare const signalDependencyBinder: unique symbol; declare const SIGNAL_DERIVATION_DEFINITION: unique symbol; export declare const signalContextDependencyCollector: unique symbol; export declare const signalContextOrigins: unique symbol; export declare const signalAncestorOrigins: unique symbol; export declare const signalGlobal: unique symbol; export declare const signalIndex: unique symbol; export declare const signalOrigins: unique symbol; export declare const signalResolver: unique symbol; export declare const signalValueType: unique symbol; /** Author-safe normalized error exposed by signal lifecycle APIs. */ export type AutomationError = AutomationErrorValue; /** A signal's mutually exclusive terminal outcome. */ export type SignalOutcome = { status: "closed"; } | { failure: AutomationError; status: "failed"; } | { sensitivity?: SensitivityMask; status: "succeeded"; value: T; }; export type SignalDependencyResolution = { outcomeSeq: number; status: "closed"; } | { failure: AutomationError; outcomeSeq: number; status: "failed"; } | { status: "pending"; } | { outcomeSeq: number; status: "succeeded"; }; export interface SignalDependencySets { actionDependencyIds: Set; eventDependencyIds: Set; signalDependencyIds: Set; } /** Compact duration literal accepted by the platform duration parser. */ export type DurationString = ms.StringValue; /** Rejects callbacks whose inferred result is asynchronous. */ export type Synchronous unknown> = [ ReturnType ] extends [never] ? unknown : ReturnType extends PromiseLike ? never : unknown; interface SignalBehavior { ancestorOrigins?: readonly string[]; collect(this: void, state: AutomationRunState, dependencies: SignalDependencySets): SignalDependencyResolution; collectContext?: SignalBehavior["collect"]; contextOrigins?: readonly string[]; derivation?: SignalDerivationDefinition; origins: readonly string[]; resolve(this: void, context: RuntimeValueContext): SignalOutcome; } type SignalDerivationDefinition = { inputs: readonly Signal[]; property: string; type: "property"; } | { inputs: readonly Signal[]; type: "transform" | "transparent"; }; export interface SignalIndexDefinition { getKey(value: T, context: RuntimeValueContext): Encodable; getPosition?(value: T, context: RuntimeValueContext): number; } /** Maps a payload's properties to child signals. */ type SignalProperties = { readonly [TKey in keyof NonNullable as TKey extends keyof SignalProtocol | keyof SignalCoreMethods | keyof SignalReservedMethods ? never : TKey extends string | number ? TKey : never]-?: NonNullable[TKey] extends (...arguments_: never[]) => unknown ? never : Signal[TKey]>; }; type SignalProtocol = { readonly [signalAncestorOrigins]: readonly string[]; readonly [signalContextDependencyCollector]: SignalBehavior["collect"]; readonly [signalContextOrigins]: readonly string[]; readonly [signalDependencyBinder]: (dependency: Signal) => Signal; readonly [signalDependencyCollector]: SignalBehavior["collect"]; readonly [SIGNAL_DERIVATION_DEFINITION]?: SignalDerivationDefinition; readonly [signalGlobal]?: true; readonly [signalIndex]?: SignalIndexDefinition; readonly [signalOrigins]: readonly string[]; readonly [signalResolver]: SignalBehavior["resolve"]; readonly [signalValueType]: () => T; }; /** * A durable symbolic reference to a value that will be materialized during * automation execution. * * Signals compose synchronously while their values are unavailable. Accessing a * property creates a derived signal, so `request.path` is equivalent to * `request.transform((value) => value.path)`. Property access can be chained * across objects and primitives; for example, `request.path.length` is a * `Signal`. Resolving a property derived from a `null` or `undefined` * value throws a `TypeError`. * * Function-valued properties are reserved for signal methods rather than * projected as callable values. Use `transform` to invoke a method on the * materialized value. * * @template T - Value represented by the signal. */ export type Signal = SignalProtocol & SignalCoreMethods & SignalMethods & SignalProperties & object; /** A signal carrying a durable cross-context key definition. */ export type KeyedSignal = Signal & { readonly [signalIndex]: SignalIndexDefinition; }; /** A signal explicitly using one shared partition per cross-context operator. */ export type GlobalSignal = Signal & { readonly [signalGlobal]: true; }; /** Preserves a source's explicit keyed or global coordination mode. */ export type InheritSignalCoordination = TSignal extends KeyedSignal ? KeyedSignal : TSignal extends GlobalSignal ? GlobalSignal : Signal; export type InferSignal = TSignal extends TSignal ? ReturnType : never; /** Internal control-flow marker for a signal that closed without emitting. */ export declare class ClosedSignalError extends Error { name: string; } /** Internal control-flow marker carrying a failed signal's details. */ export declare class FailedSignalError extends Error { readonly failure: AutomationError; name: string; /** @param failure - Failure propagated from the resolved signal. */ constructor(failure: AutomationError); } /** Raised when merged parent histories expose multiple values at one slot. */ export declare class AmbiguousSignalError extends Error { name: string; } /** * Determines whether a value implements the internal signal protocol. * * @param value - Value to inspect. */ export declare function isSignal(value: unknown): value is Signal; /** * Installs the public fluent adapters used by every signal proxy. * * @param implementations - Source-first functions keyed by fluent method name. */ export declare function registerSignalMethodImplementations(implementations: Readonly>): void; /** * Combines dependencies that must all succeed. * * @param outcomes - Dependency states to combine. */ export declare function combineSignalDependencyOutcomes(outcomes: SignalDependencyResolution[]): SignalDependencyResolution; /** * Materializes the explanatory source, property, and transform graph consumed * by one durable declaration. * * @param signals - Signal roots consumed by the declaration. * @param state - Current runtime occurrence used to resolve durable sources. * @param selectedDependencies - Exact durable sources selected by dependency * traversal. */ export declare function buildSignalDerivation(signals: readonly Signal[], state: AutomationRunState, ...selectedDependencies: [SignalDependencySets, ...SignalDependencySets[]]): SignalDerivation | null; /** * Creates a derived signal from explicit signal inputs and a pure transformer. * * Dependency collection traverses the inputs without invoking the transformer. * The transformer runs only after the runtime materializes every input. * * @param inputs - Signals consumed by the transformer. * @param transformer - Pure function that computes the derived value. */ export declare function transform unknown>(inputs: { readonly [TIndex in keyof TValues]: Signal; }, transformer: Synchronous extends never ? never : TTransformer): Signal>; /** @inheritdoc */ export declare function transform unknown>(input: Signal, transformer: Synchronous extends never ? never : TTransformer): Signal>; /** * Normalizes an unknown thrown value for public automation lifecycle handling. * * @param error - Thrown value to normalize. * @param fallbackCode - Classification used when the error has no stable code. */ export declare function normalizeAutomationError(error: unknown, fallbackCode?: string): AutomationError; /** * Copies an explicit keyed or global coordination mode to a value-preserving * signal result. * * @param source - Signal whose coordination mode is retained. * @param result - Value-preserving result signal. */ export declare function inheritSignalCoordination(source: TSignal, result: Signal): InheritSignalCoordination; /** * Exposes static properties on a transparent wrapper around a signal. * * @param signal - Signal whose value and dependency behavior are retained. * @param staticProperties - Properties exposed directly on the returned proxy. */ export declare function withSignalStaticProperties(signal: Signal, staticProperties: TStatic): SignalProtocol & SignalCoreMethods & SignalMethods & SignalProperties & object & Readonly; /** * Creates a proxy implementing behavior shared by every signal. * * @param behavior - Dependency, origin, and resolution behavior. * @param staticProperties - Values exposed directly instead of as projections. */ export declare function createSignal(behavior: SignalBehavior, staticProperties?: TStatic): Signal & Readonly; export {}; //# sourceMappingURL=signal-protocol.d.ts.map