{"version":3,"file":"RunningAction.types-LEgaPrRy.mjs","names":[],"sources":["../src/ActionDefinition/Action/RunningAction.types.ts"],"sourcesContent":["import type { IActionDomain } from \"../Domain/ActionDomain.types\";\nimport type { TInferActionError } from \"../Schema/ActionSchema\";\nimport type { ActionContext } from \"./Context/ActionContext\";\nimport type { TActionProgress } from \"./Payload/ActionPayload.types\";\nimport type { ActionPayload_Progress } from \"./Payload/ActionPayload_Progress\";\nimport type { ActionPayload_Request } from \"./Payload/ActionPayload_Request\";\nimport type { ActionPayload_Result } from \"./Payload/ActionPayload_Result\";\nimport type { RunningAction } from \"./RunningAction\";\n\nexport enum ERunningActionState {\n  running = \"running\",\n  completed = \"completed\",\n}\n\nexport interface IRunningActionState<\n  DOM extends IActionDomain,\n  ID extends keyof DOM[\"actionSchema\"] & string,\n> {\n  request: ActionPayload_Request<DOM, ID>;\n  progress: ActionPayload_Progress<DOM, ID>[];\n  result?: ActionPayload_Result<DOM, ID>;\n}\n\nexport interface IRunningActionState_ConstructorParams<\n  DOM extends IActionDomain,\n  ID extends keyof DOM[\"actionSchema\"] & string,\n> {\n  context: ActionContext<DOM, ID>;\n  request: ActionPayload_Request<DOM, ID>;\n  progress?: ActionPayload_Progress<DOM, ID>[];\n  result?: ActionPayload_Result<DOM, ID>;\n  parentCuid?: string;\n  callSite?: string;\n}\n\n// export interface IActionRunningState_Running<\n//   DOM extends IActionDomain,\n//   ID extends keyof DOM[\"actions\"] & string = keyof DOM[\"actions\"] & string,\n// > {\n//   state: ERunningActionState.running;\n//   request: ActionPayload_Request<DOM, ID>;\n//   lastProgress: ActionPayload_Progress;\n// }\n\n// export interface IActionRunningState_Completed<\n//   DOM extends IActionDomain,\n//   ID extends keyof DOM[\"actions\"] & string = keyof DOM[\"actions\"] & string,\n// > {\n//   state: ERunningActionState.completed;\n//   request: ActionPayload_Request<DOM, ID>;\n//   response: ActionPayload_Result<DOM, ID>;\n// }\n\n// export type TRunningActionState<\n//   DOM extends IActionDomain,\n//   ID extends keyof DOM[\"actions\"] & string = keyof DOM[\"actions\"] & string,\n// > = IActionRunningState_Running<DOM, ID> | IActionRunningState_Completed<DOM, ID>;\n\nexport enum ERunningActionUpdateType {\n  started = \"started\",\n  progress = \"progress\",\n  finished = \"finished\",\n  /**\n   * A reliable action's sender-side delivery facts changed — today: the peer's cumulative ack covered\n   * this frame (`reliability.acked` flipped to `true`). Fires *after* `finished` for a reply-less\n   * reliable action (which settles on send while delivery continues in the background), so observers\n   * (devtools) must not treat `finished` as the last update for those.\n   */\n  reliability = \"reliability\",\n}\n\nexport interface IRunningActionEvent_Base<\n  T extends ERunningActionUpdateType,\n  DOM extends IActionDomain,\n  ID extends keyof DOM[\"actionSchema\"] & string = keyof DOM[\"actionSchema\"] & string,\n> {\n  type: T;\n  runningAction: RunningAction<DOM, ID>;\n  time: number;\n}\n\nexport interface IRunningActionUpdate_Started<\n  DOM extends IActionDomain,\n  ID extends keyof DOM[\"actionSchema\"] & string = keyof DOM[\"actionSchema\"] & string,\n> extends IRunningActionEvent_Base<ERunningActionUpdateType.started, DOM, ID> {}\n\nexport interface IRunningActionUpdate_Progress<\n  DOM extends IActionDomain,\n  ID extends keyof DOM[\"actionSchema\"] & string = keyof DOM[\"actionSchema\"] & string,\n> extends IRunningActionEvent_Base<ERunningActionUpdateType.progress, DOM, ID> {\n  progress: TActionProgress;\n}\n\n/**\n * Sender-side reliable-delivery facts changed (see {@link ERunningActionUpdateType.reliability}). Read\n * the current facts off `runningAction.reliability` — the update carries no payload of its own so the\n * facts have exactly one source of truth.\n */\nexport interface IRunningActionUpdate_Reliability<\n  DOM extends IActionDomain,\n  ID extends keyof DOM[\"actionSchema\"] & string = keyof DOM[\"actionSchema\"] & string,\n> extends IRunningActionEvent_Base<ERunningActionUpdateType.reliability, DOM, ID> {}\n\nexport enum ERunningActionFinishedType {\n  aborted = \"aborted\",\n  failed = \"failed\",\n  success = \"success\",\n}\n\nexport interface IRunningActionUpdate_Finished<\n  FT extends ERunningActionFinishedType,\n  DOM extends IActionDomain,\n  ID extends keyof DOM[\"actionSchema\"] & string = keyof DOM[\"actionSchema\"] & string,\n> extends IRunningActionEvent_Base<ERunningActionUpdateType.finished, DOM, ID> {\n  finishType: FT;\n  reason?: unknown;\n}\n\nexport interface IRunningActionUpdate_Abort<\n  DOM extends IActionDomain,\n  ID extends keyof DOM[\"actionSchema\"] & string = keyof DOM[\"actionSchema\"] & string,\n> extends IRunningActionUpdate_Finished<ERunningActionFinishedType.aborted, DOM, ID> {\n  reason?: unknown;\n}\n\nexport interface IRunningActionUpdate_Failed<\n  DOM extends IActionDomain,\n  ID extends keyof DOM[\"actionSchema\"] & string = keyof DOM[\"actionSchema\"] & string,\n> extends IRunningActionUpdate_Finished<ERunningActionFinishedType.failed, DOM, ID> {\n  error: TInferActionError<DOM[\"actionSchema\"][ID]>;\n}\n\nexport interface IRunningActionUpdate_Success<\n  DOM extends IActionDomain,\n  ID extends keyof DOM[\"actionSchema\"] & string = keyof DOM[\"actionSchema\"] & string,\n> extends IRunningActionUpdate_Finished<ERunningActionFinishedType.success, DOM, ID> {\n  response: ActionPayload_Result<DOM, ID>;\n}\n\nexport type TRunningActionUpdateFinished<\n  DOM extends IActionDomain,\n  ID extends keyof DOM[\"actionSchema\"] & string = keyof DOM[\"actionSchema\"] & string,\n> =\n  | IRunningActionUpdate_Abort<DOM, ID>\n  | IRunningActionUpdate_Failed<DOM, ID>\n  | IRunningActionUpdate_Success<DOM, ID>;\n\nexport type TRunningActionUpdate<\n  DOM extends IActionDomain,\n  ID extends keyof DOM[\"actionSchema\"] & string = keyof DOM[\"actionSchema\"] & string,\n> =\n  | IRunningActionUpdate_Started<DOM, ID>\n  | IRunningActionUpdate_Progress<DOM, ID>\n  | IRunningActionUpdate_Reliability<DOM, ID>\n  | TRunningActionUpdateFinished<DOM, ID>;\n\nexport type TRunningActionUpdateListener<\n  DOM extends IActionDomain,\n  ID extends keyof DOM[\"actionSchema\"] & string = keyof DOM[\"actionSchema\"] & string,\n> = (update: TRunningActionUpdate<DOM, ID>) => void;\n\n/**\n * Distributes a union ID into a proper discriminated union of RunningAction update events,\n * so that narrowing on `update.runningAction.id` also narrows `update.runningAction`'s input/output types.\n */\nexport type TDistributeRunningActionUpdate<\n  DOM extends IActionDomain,\n  ID extends keyof DOM[\"actionSchema\"] & string = keyof DOM[\"actionSchema\"] & string,\n> = ID extends keyof DOM[\"actionSchema\"] & string ? TRunningActionUpdate<DOM, ID> : never;\n\nexport type TDistributeRunningActionUpdateListener<\n  DOM extends IActionDomain,\n  ID extends keyof DOM[\"actionSchema\"] & string = keyof DOM[\"actionSchema\"] & string,\n> = (update: TDistributeRunningActionUpdate<DOM, ID>) => void;\n\nexport interface IRunningActionUserMethods<\n  DOM extends IActionDomain,\n  ID extends keyof DOM[\"actionSchema\"] & string,\n> {\n  waitForResultPayload(): Promise<ActionPayload_Result<DOM, ID>>;\n  /** Await delivery settlement (ack / abandonment) — see {@link RunningAction.waitForAck}. */\n  waitForAck(): Promise<void>;\n  addUpdateListeners(listeners: TRunningActionUpdateListener<DOM, ID>[]): () => void;\n  iterateUpdates(): AsyncIterable<TRunningActionUpdate<DOM, ID>>;\n  abort(reason?: unknown): void;\n}\n"],"mappings":";AASA,IAAY,sBAAL,yBAAA,qBAAA;CACL,oBAAA,aAAA;CACA,oBAAA,eAAA;;AACF,EAAA,CAAA,CAAA;AA8CA,IAAY,2BAAL,yBAAA,0BAAA;CACL,yBAAA,aAAA;CACA,yBAAA,cAAA;CACA,yBAAA,cAAA;;;;;;;CAOA,yBAAA,iBAAA;;AACF,EAAA,CAAA,CAAA;AAkCA,IAAY,6BAAL,yBAAA,4BAAA;CACL,2BAAA,aAAA;CACA,2BAAA,YAAA;CACA,2BAAA,aAAA;;AACF,EAAA,CAAA,CAAA"}