@nestjs/workflows 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +50 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +8 -0
  5. package/dist/core/codecs/aes-gcm-payload.codec.d.ts +42 -0
  6. package/dist/core/codecs/aes-gcm-payload.codec.js +119 -0
  7. package/dist/core/codecs/index.d.ts +2 -0
  8. package/dist/core/codecs/index.js +2 -0
  9. package/dist/core/codecs/payload-codecs.d.ts +59 -0
  10. package/dist/core/codecs/payload-codecs.js +130 -0
  11. package/dist/core/index.d.ts +16 -0
  12. package/dist/core/index.js +21 -0
  13. package/dist/core/interfaces/clock.interface.d.ts +18 -0
  14. package/dist/core/interfaces/clock.interface.js +1 -0
  15. package/dist/core/interfaces/index.d.ts +9 -0
  16. package/dist/core/interfaces/index.js +9 -0
  17. package/dist/core/interfaces/leased-worker-options.interface.d.ts +94 -0
  18. package/dist/core/interfaces/leased-worker-options.interface.js +1 -0
  19. package/dist/core/interfaces/limits.interface.d.ts +92 -0
  20. package/dist/core/interfaces/limits.interface.js +1 -0
  21. package/dist/core/interfaces/payload-codec.interface.d.ts +64 -0
  22. package/dist/core/interfaces/payload-codec.interface.js +1 -0
  23. package/dist/core/interfaces/result-waiter-options.interface.d.ts +52 -0
  24. package/dist/core/interfaces/result-waiter-options.interface.js +1 -0
  25. package/dist/core/interfaces/retry-settings.interface.d.ts +71 -0
  26. package/dist/core/interfaces/retry-settings.interface.js +1 -0
  27. package/dist/core/interfaces/schedule-store.interface.d.ts +143 -0
  28. package/dist/core/interfaces/schedule-store.interface.js +1 -0
  29. package/dist/core/interfaces/schedule.interface.d.ts +106 -0
  30. package/dist/core/interfaces/schedule.interface.js +1 -0
  31. package/dist/core/interfaces/scheduler-options.interface.d.ts +152 -0
  32. package/dist/core/interfaces/scheduler-options.interface.js +1 -0
  33. package/dist/core/limits/index.d.ts +1 -0
  34. package/dist/core/limits/index.js +1 -0
  35. package/dist/core/limits/limits.d.ts +61 -0
  36. package/dist/core/limits/limits.js +130 -0
  37. package/dist/core/results/index.d.ts +1 -0
  38. package/dist/core/results/index.js +1 -0
  39. package/dist/core/results/result-waiter.d.ts +54 -0
  40. package/dist/core/results/result-waiter.js +140 -0
  41. package/dist/core/retries/index.d.ts +1 -0
  42. package/dist/core/retries/index.js +1 -0
  43. package/dist/core/retries/retry.d.ts +60 -0
  44. package/dist/core/retries/retry.js +107 -0
  45. package/dist/core/scheduling/cron.util.d.ts +52 -0
  46. package/dist/core/scheduling/cron.util.js +262 -0
  47. package/dist/core/scheduling/encoded-schedule.store.d.ts +26 -0
  48. package/dist/core/scheduling/encoded-schedule.store.js +54 -0
  49. package/dist/core/scheduling/in-memory-schedule.store.d.ts +20 -0
  50. package/dist/core/scheduling/in-memory-schedule.store.js +90 -0
  51. package/dist/core/scheduling/index.d.ts +3 -0
  52. package/dist/core/scheduling/index.js +3 -0
  53. package/dist/core/scheduling/rrule.util.d.ts +55 -0
  54. package/dist/core/scheduling/rrule.util.js +371 -0
  55. package/dist/core/scheduling/schedule-spec.d.ts +57 -0
  56. package/dist/core/scheduling/schedule-spec.js +233 -0
  57. package/dist/core/scheduling/scheduler.d.ts +134 -0
  58. package/dist/core/scheduling/scheduler.js +450 -0
  59. package/dist/core/scheduling/time-zone.util.d.ts +18 -0
  60. package/dist/core/scheduling/time-zone.util.js +88 -0
  61. package/dist/core/time/clock.d.ts +28 -0
  62. package/dist/core/time/clock.js +35 -0
  63. package/dist/core/time/duration.d.ts +21 -0
  64. package/dist/core/time/duration.js +30 -0
  65. package/dist/core/time/index.d.ts +2 -0
  66. package/dist/core/time/index.js +2 -0
  67. package/dist/core/utils/canonical.util.d.ts +2 -0
  68. package/dist/core/utils/canonical.util.js +4 -0
  69. package/dist/core/utils/maybe.util.d.ts +8 -0
  70. package/dist/core/utils/maybe.util.js +14 -0
  71. package/dist/core/utils/payload-place.util.d.ts +10 -0
  72. package/dist/core/utils/payload-place.util.js +32 -0
  73. package/dist/core/workers/index.d.ts +1 -0
  74. package/dist/core/workers/index.js +1 -0
  75. package/dist/core/workers/leased-worker.d.ts +86 -0
  76. package/dist/core/workers/leased-worker.js +280 -0
  77. package/dist/cqrs/decorators/index.d.ts +2 -0
  78. package/dist/cqrs/decorators/index.js +2 -0
  79. package/dist/cqrs/decorators/signal-on.decorator.d.ts +18 -0
  80. package/dist/cqrs/decorators/signal-on.decorator.js +34 -0
  81. package/dist/cqrs/decorators/start-on.decorator.d.ts +18 -0
  82. package/dist/cqrs/decorators/start-on.decorator.js +49 -0
  83. package/dist/cqrs/index.d.ts +3 -0
  84. package/dist/cqrs/index.js +5 -0
  85. package/dist/cqrs/interfaces/index.d.ts +4 -0
  86. package/dist/cqrs/interfaces/index.js +4 -0
  87. package/dist/cqrs/interfaces/signal-on-options.interface.d.ts +22 -0
  88. package/dist/cqrs/interfaces/signal-on-options.interface.js +1 -0
  89. package/dist/cqrs/interfaces/start-on-options.interface.d.ts +23 -0
  90. package/dist/cqrs/interfaces/start-on-options.interface.js +1 -0
  91. package/dist/cqrs/interfaces/workflow-dispatcher-context.interface.d.ts +10 -0
  92. package/dist/cqrs/interfaces/workflow-dispatcher-context.interface.js +1 -0
  93. package/dist/cqrs/interfaces/workflow-event-route.interface.d.ts +20 -0
  94. package/dist/cqrs/interfaces/workflow-event-route.interface.js +1 -0
  95. package/dist/cqrs/utils/event-routes.util.d.ts +7 -0
  96. package/dist/cqrs/utils/event-routes.util.js +22 -0
  97. package/dist/cqrs/workflow-event.publisher.d.ts +52 -0
  98. package/dist/cqrs/workflow-event.publisher.js +257 -0
  99. package/dist/cqrs/workflow-events.explorer.d.ts +27 -0
  100. package/dist/cqrs/workflow-events.explorer.js +92 -0
  101. package/dist/cqrs/workflows-cqrs.module.d.ts +10 -0
  102. package/dist/cqrs/workflows-cqrs.module.js +27 -0
  103. package/dist/decorators/index.d.ts +1 -0
  104. package/dist/decorators/index.js +1 -0
  105. package/dist/decorators/workflow.decorator.d.ts +7 -0
  106. package/dist/decorators/workflow.decorator.js +52 -0
  107. package/dist/errors/child-workflow-failed.error.d.ts +13 -0
  108. package/dist/errors/child-workflow-failed.error.js +14 -0
  109. package/dist/errors/index.d.ts +13 -0
  110. package/dist/errors/index.js +13 -0
  111. package/dist/errors/non-retryable-step.error.d.ts +4 -0
  112. package/dist/errors/non-retryable-step.error.js +7 -0
  113. package/dist/errors/step-failed.error.d.ts +15 -0
  114. package/dist/errors/step-failed.error.js +16 -0
  115. package/dist/errors/step-timeout.error.d.ts +5 -0
  116. package/dist/errors/step-timeout.error.js +8 -0
  117. package/dist/errors/workflow-definition.error.d.ts +10 -0
  118. package/dist/errors/workflow-definition.error.js +13 -0
  119. package/dist/errors/workflow-failed.error.d.ts +20 -0
  120. package/dist/errors/workflow-failed.error.js +17 -0
  121. package/dist/errors/workflow-id-conflict.error.d.ts +6 -0
  122. package/dist/errors/workflow-id-conflict.error.js +9 -0
  123. package/dist/errors/workflow-interrupt.error.d.ts +32 -0
  124. package/dist/errors/workflow-interrupt.error.js +19 -0
  125. package/dist/errors/workflow-non-determinism.error.d.ts +4 -0
  126. package/dist/errors/workflow-non-determinism.error.js +7 -0
  127. package/dist/errors/workflow-not-found.error.d.ts +10 -0
  128. package/dist/errors/workflow-not-found.error.js +13 -0
  129. package/dist/errors/workflow-result-timeout.error.d.ts +11 -0
  130. package/dist/errors/workflow-result-timeout.error.js +13 -0
  131. package/dist/errors/workflow-state.error.d.ts +11 -0
  132. package/dist/errors/workflow-state.error.js +14 -0
  133. package/dist/errors/workflow.error.d.ts +7 -0
  134. package/dist/errors/workflow.error.js +7 -0
  135. package/dist/events/index.d.ts +3 -0
  136. package/dist/events/index.js +3 -0
  137. package/dist/events/workflow-events.interface.d.ts +145 -0
  138. package/dist/events/workflow-events.interface.js +1 -0
  139. package/dist/events/workflow-events.service.d.ts +17 -0
  140. package/dist/events/workflow-events.service.js +38 -0
  141. package/dist/events/workflows.channels.d.ts +3 -0
  142. package/dist/events/workflows.channels.js +9 -0
  143. package/dist/index.d.ts +20 -0
  144. package/dist/index.js +23 -0
  145. package/dist/interfaces/index.d.ts +13 -0
  146. package/dist/interfaces/index.js +13 -0
  147. package/dist/interfaces/serialized-workflow-error.interface.d.ts +6 -0
  148. package/dist/interfaces/serialized-workflow-error.interface.js +1 -0
  149. package/dist/interfaces/workflow-client.interface.d.ts +156 -0
  150. package/dist/interfaces/workflow-client.interface.js +1 -0
  151. package/dist/interfaces/workflow-clock.interface.d.ts +7 -0
  152. package/dist/interfaces/workflow-clock.interface.js +1 -0
  153. package/dist/interfaces/workflow-context.interface.d.ts +241 -0
  154. package/dist/interfaces/workflow-context.interface.js +1 -0
  155. package/dist/interfaces/workflow-decorator-options.interface.d.ts +101 -0
  156. package/dist/interfaces/workflow-decorator-options.interface.js +1 -0
  157. package/dist/interfaces/workflow-instance.interface.d.ts +83 -0
  158. package/dist/interfaces/workflow-instance.interface.js +1 -0
  159. package/dist/interfaces/workflow-payload-codec.interface.d.ts +32 -0
  160. package/dist/interfaces/workflow-payload-codec.interface.js +1 -0
  161. package/dist/interfaces/workflow-retry-options.interface.d.ts +9 -0
  162. package/dist/interfaces/workflow-retry-options.interface.js +1 -0
  163. package/dist/interfaces/workflow-runner.interface.d.ts +11 -0
  164. package/dist/interfaces/workflow-runner.interface.js +1 -0
  165. package/dist/interfaces/workflow-schedule.interface.d.ts +104 -0
  166. package/dist/interfaces/workflow-schedule.interface.js +1 -0
  167. package/dist/interfaces/workflow-storage.interface.d.ts +4 -0
  168. package/dist/interfaces/workflow-storage.interface.js +1 -0
  169. package/dist/interfaces/workflow-store.interface.d.ts +488 -0
  170. package/dist/interfaces/workflow-store.interface.js +1 -0
  171. package/dist/interfaces/workflows-module-options.interface.d.ts +80 -0
  172. package/dist/interfaces/workflows-module-options.interface.js +1 -0
  173. package/dist/mysql/index.d.ts +5 -0
  174. package/dist/mysql/index.js +8 -0
  175. package/dist/mysql/interfaces/index.d.ts +1 -0
  176. package/dist/mysql/interfaces/index.js +1 -0
  177. package/dist/mysql/interfaces/mysql-workflow-store-options.interface.d.ts +25 -0
  178. package/dist/mysql/interfaces/mysql-workflow-store-options.interface.js +1 -0
  179. package/dist/mysql/key-limits.d.ts +30 -0
  180. package/dist/mysql/key-limits.js +41 -0
  181. package/dist/mysql/migrations/index.d.ts +7 -0
  182. package/dist/mysql/migrations/index.js +16 -0
  183. package/dist/mysql/migrations/initial.migration.d.ts +9 -0
  184. package/dist/mysql/migrations/initial.migration.js +104 -0
  185. package/dist/mysql/mysql-workflow.store.d.ts +197 -0
  186. package/dist/mysql/mysql-workflow.store.js +828 -0
  187. package/dist/postgres/errors/index.d.ts +1 -0
  188. package/dist/postgres/errors/index.js +2 -0
  189. package/dist/postgres/index.d.ts +5 -0
  190. package/dist/postgres/index.js +8 -0
  191. package/dist/postgres/interfaces/index.d.ts +1 -0
  192. package/dist/postgres/interfaces/index.js +1 -0
  193. package/dist/postgres/interfaces/postgres-workflow-store-options.interface.d.ts +22 -0
  194. package/dist/postgres/interfaces/postgres-workflow-store-options.interface.js +1 -0
  195. package/dist/postgres/migrations/index.d.ts +6 -0
  196. package/dist/postgres/migrations/index.js +15 -0
  197. package/dist/postgres/migrations/initial.migration.d.ts +6 -0
  198. package/dist/postgres/migrations/initial.migration.js +106 -0
  199. package/dist/postgres/postgres-workflow.store.d.ts +132 -0
  200. package/dist/postgres/postgres-workflow.store.js +586 -0
  201. package/dist/services/index.d.ts +6 -0
  202. package/dist/services/index.js +6 -0
  203. package/dist/services/workflow-client.service.d.ts +146 -0
  204. package/dist/services/workflow-client.service.js +436 -0
  205. package/dist/services/workflow-execution.service.d.ts +267 -0
  206. package/dist/services/workflow-execution.service.js +1076 -0
  207. package/dist/services/workflow-registry.service.d.ts +56 -0
  208. package/dist/services/workflow-registry.service.js +172 -0
  209. package/dist/services/workflow-scheduler.service.d.ts +54 -0
  210. package/dist/services/workflow-scheduler.service.js +173 -0
  211. package/dist/services/workflow-schedules.service.d.ts +60 -0
  212. package/dist/services/workflow-schedules.service.js +193 -0
  213. package/dist/services/workflow-worker.service.d.ts +92 -0
  214. package/dist/services/workflow-worker.service.js +468 -0
  215. package/dist/signals/index.d.ts +1 -0
  216. package/dist/signals/index.js +1 -0
  217. package/dist/signals/workflow.signal.d.ts +17 -0
  218. package/dist/signals/workflow.signal.js +28 -0
  219. package/dist/sql/rate-windows.d.ts +41 -0
  220. package/dist/sql/rate-windows.js +53 -0
  221. package/dist/sql/workflow-rows.d.ts +16 -0
  222. package/dist/sql/workflow-rows.js +102 -0
  223. package/dist/sql/workflow-schema.error.d.ts +21 -0
  224. package/dist/sql/workflow-schema.error.js +15 -0
  225. package/dist/storage/encoded-workflow.store.d.ts +71 -0
  226. package/dist/storage/encoded-workflow.store.js +201 -0
  227. package/dist/storage/index.d.ts +1 -0
  228. package/dist/storage/index.js +1 -0
  229. package/dist/storage/workflow.storage.d.ts +55 -0
  230. package/dist/storage/workflow.storage.js +159 -0
  231. package/dist/stores/in-memory-workflow.store.d.ts +75 -0
  232. package/dist/stores/in-memory-workflow.store.js +380 -0
  233. package/dist/stores/index.d.ts +1 -0
  234. package/dist/stores/index.js +1 -0
  235. package/dist/testing/assertions.d.ts +10 -0
  236. package/dist/testing/assertions.js +72 -0
  237. package/dist/testing/index.d.ts +38 -0
  238. package/dist/testing/index.js +1089 -0
  239. package/dist/testing/schedule-store.contract.d.ts +33 -0
  240. package/dist/testing/schedule-store.contract.js +161 -0
  241. package/dist/utils/index.d.ts +7 -0
  242. package/dist/utils/index.js +7 -0
  243. package/dist/utils/journal-limits.util.d.ts +6 -0
  244. package/dist/utils/journal-limits.util.js +25 -0
  245. package/dist/utils/new-instance.util.d.ts +26 -0
  246. package/dist/utils/new-instance.util.js +87 -0
  247. package/dist/utils/normalize.util.d.ts +5 -0
  248. package/dist/utils/normalize.util.js +11 -0
  249. package/dist/utils/run-timeout.util.d.ts +3 -0
  250. package/dist/utils/run-timeout.util.js +15 -0
  251. package/dist/utils/schedule-spec.util.d.ts +16 -0
  252. package/dist/utils/schedule-spec.util.js +9 -0
  253. package/dist/utils/schedule-store.util.d.ts +15 -0
  254. package/dist/utils/schedule-store.util.js +44 -0
  255. package/dist/utils/serialize-error.util.d.ts +7 -0
  256. package/dist/utils/serialize-error.util.js +22 -0
  257. package/dist/utils/step-scope.util.d.ts +16 -0
  258. package/dist/utils/step-scope.util.js +38 -0
  259. package/dist/workflows.constants.d.ts +10 -0
  260. package/dist/workflows.constants.js +10 -0
  261. package/dist/workflows.module-definition.d.ts +4 -0
  262. package/dist/workflows.module-definition.js +6 -0
  263. package/dist/workflows.module.d.ts +24 -0
  264. package/dist/workflows.module.js +68 -0
  265. package/package.json +123 -0
@@ -0,0 +1,267 @@
1
+ import { type Type } from '@nestjs/common';
2
+ import type { LeasedRun } from '../core/interfaces/leased-worker-options.interface.js';
3
+ import type { WorkflowClock } from '../interfaces/workflow-clock.interface.js';
4
+ import { type Duration } from '../core/time/duration.js';
5
+ import type { SerializedWorkflowError } from '../interfaces/serialized-workflow-error.interface.js';
6
+ import type { WorkflowContext } from '../interfaces/workflow-context.interface.js';
7
+ import type { WorkflowInstance, WorkflowJournalEntry, WorkflowStatus, WorkflowWait } from '../interfaces/workflow-instance.interface.js';
8
+ import type { WorkflowMetadata } from '../interfaces/workflow-decorator-options.interface.js';
9
+ import type { ResolvedRetry } from '../core/interfaces/retry-settings.interface.js';
10
+ import type { WorkflowJournalLimits } from '../interfaces/workflows-module-options.interface.js';
11
+ import type { WorkflowEvents } from '../events/workflow-events.service.js';
12
+ import type { NewWorkflowInstance } from '../interfaces/workflow-store.interface.js';
13
+ import type { WorkflowInstanceStore } from '../storage/encoded-workflow.store.js';
14
+ /** An instance under a worker's lease. */
15
+ export interface ClaimedWorkflowInstance extends WorkflowInstance {
16
+ leaseToken: string;
17
+ }
18
+ /** One entry per name, as the store expects: the last version of each, in the order the names first appear. */
19
+ export declare function uniqueEntries<T extends {
20
+ name: string;
21
+ }>(entries: T[]): T[];
22
+ export interface ExecutionDeps {
23
+ store: WorkflowInstanceStore;
24
+ /** The workflow `ctx.startChild()` starts: its name, version and run timeout (`WorkflowRegistry.resolve()`). */
25
+ resolve(workflow: Type<unknown> | string, version?: number): WorkflowMetadata;
26
+ /**
27
+ * Creates a child, or finds the one an interrupted execution created, and throws
28
+ * `WorkflowIdConflictError` if the id holds another instance.
29
+ */
30
+ createChild(instance: NewWorkflowInstance): Promise<WorkflowInstance>;
31
+ clock: WorkflowClock;
32
+ events: WorkflowEvents;
33
+ defaultRetry: ResolvedRetry;
34
+ journalLimits: Required<WorkflowJournalLimits>;
35
+ }
36
+ export type RunOutcome = {
37
+ ok: true;
38
+ value: unknown;
39
+ } | {
40
+ ok: false;
41
+ error: unknown;
42
+ };
43
+ export type CompensationOutcome = {
44
+ state: 'done';
45
+ count: number;
46
+ } | {
47
+ state: 'suspended';
48
+ wakeAt: number | null;
49
+ } | {
50
+ state: 'failed';
51
+ error: SerializedWorkflowError;
52
+ } | {
53
+ state: 'interrupted';
54
+ } | {
55
+ state: 'terminated';
56
+ };
57
+ /**
58
+ * What `ctx.signalWait()` and `ctx.timer()` make for `ctx.waitForAny()`: a description of what to
59
+ * wait for, and how the winner's journaled payload becomes its value.
60
+ */
61
+ export declare class Condition {
62
+ readonly wait: WorkflowWait | null;
63
+ readonly match: ((payload: any) => boolean) | undefined;
64
+ readonly timer: Duration | {
65
+ until: Date | number;
66
+ } | undefined;
67
+ readonly settle: (payload: unknown) => unknown;
68
+ private constructor();
69
+ static signal(wait: WorkflowWait, match?: (payload: any) => boolean, settle?: (payload: unknown) => unknown): Condition;
70
+ static timer(when: Duration | {
71
+ until: Date | number;
72
+ }): Condition;
73
+ }
74
+ /** What a child sends its parent when it ends (`CHILD_ENDED_SIGNAL`). */
75
+ export interface ChildEnded {
76
+ status: WorkflowStatus;
77
+ output?: unknown;
78
+ error?: SerializedWorkflowError | null;
79
+ }
80
+ /** `ChildWorkflowHandle`: waits for the child's end, once per execution, as `result()` or as a `waitForAny()` condition. */
81
+ export declare class ChildHandle {
82
+ readonly id: string;
83
+ readonly workflow: string;
84
+ readonly version: number;
85
+ private readonly wait;
86
+ readonly condition: Condition;
87
+ private outcome?;
88
+ private waiting?;
89
+ constructor(id: string, workflow: string, version: number, wait: (handle: ChildHandle) => Promise<unknown>);
90
+ result(): Promise<unknown>;
91
+ /** The child's output, from its journaled end, or its failure, thrown. Kept, so a later `result()` returns it. */
92
+ settle(payload: unknown): unknown;
93
+ }
94
+ /**
95
+ * One execution of a workflow instance: runs `run()` from the top against the
96
+ * journal loaded at claim time.
97
+ *
98
+ * - A journaled step returns its stored result (or re-throws its stored
99
+ * failure) without running.
100
+ * - The first step that is not journaled is the frontier. Before it runs, the
101
+ * execution lets the replay settle and checks that every journaled entry was
102
+ * reached. If one was not, the code changed under a running instance and the
103
+ * instance fails instead of re-running a renamed side effect.
104
+ * - A pending sleep, wait or retry backoff records a suspension and throws
105
+ * `WorkflowInterrupt`. After that no new step starts and nothing new is
106
+ * journaled except other sleeps and waits of the same `Promise.all`; the
107
+ * engine parks the instance once in-flight steps settle.
108
+ * - A cancel, shutdown, lost lease or store failure also throws
109
+ * `WorkflowInterrupt`, and decides the outcome whatever `run()` does with it:
110
+ * swallowing or wrapping it can't complete the instance.
111
+ * - In replay-only mode (compensating or cancelling after a restart) nothing
112
+ * new runs: the replay only rebuilds the list of compensations.
113
+ */
114
+ export declare class WorkflowExecution {
115
+ readonly instance: ClaimedWorkflowInstance;
116
+ /** Highest signal id visible to this execution's waits. */
117
+ readonly signalCursor: number;
118
+ private readonly deps;
119
+ /** The worker's run of this instance: its lease, renewed on a heartbeat, and a signal for a lost lease or a shutdown. */
120
+ private readonly lease;
121
+ readonly context: WorkflowContext;
122
+ readonly journal: Map<string, WorkflowJournalEntry>;
123
+ readonly abort: AbortController;
124
+ suspension: {
125
+ wakeAt: number | null;
126
+ waits: WorkflowWait[];
127
+ } | null;
128
+ fatal: Error | null;
129
+ /** Why the journal limit stopped the run, once it did. */
130
+ journalLimitError: SerializedWorkflowError | null;
131
+ leaseLost: boolean;
132
+ storeError: unknown;
133
+ shuttingDown: boolean;
134
+ cancelRequested: boolean;
135
+ /** A terminate was requested: stop compensating too. */
136
+ terminateRequested: boolean;
137
+ /** Attempt counters to restore when a shutdown interrupts an attempt. */
138
+ readonly rollbacks: WorkflowJournalEntry[];
139
+ private mode;
140
+ private userSettled;
141
+ private buffer;
142
+ private frontier?;
143
+ private readonly visited;
144
+ private readonly compensations;
145
+ private readonly inflight;
146
+ private readonly consumed;
147
+ /** The last journal write issued; the next one waits for it (see `write()`). */
148
+ private writes;
149
+ private readonly counters;
150
+ /** Children started so far in this run, per workflow name: the default child ids. */
151
+ private readonly childCounters;
152
+ /** The first interrupt that stops this execution (not a suspension). */
153
+ private stoppedBy;
154
+ /** The step whose function is running, in that function's async context. */
155
+ private readonly insideStep;
156
+ /** Each journal entry's size in bytes, by name, and their sum. */
157
+ private readonly entrySizes;
158
+ private journalBytes;
159
+ /** Whether the journal is past the warning line: it warns once, when it crosses it. */
160
+ private journalLarge;
161
+ /** The last `ctx.setStatus()` value, and the stored one (canonical JSON). */
162
+ private customStatus;
163
+ private storedStatus;
164
+ private static readonly logger;
165
+ constructor(instance: ClaimedWorkflowInstance, journal: WorkflowJournalEntry[],
166
+ /** Highest signal id visible to this execution's waits. */
167
+ signalCursor: number, deps: ExecutionDeps,
168
+ /** The worker's run of this instance: its lease, renewed on a heartbeat, and a signal for a lost lease or a shutdown. */
169
+ lease: LeasedRun, replayOnly: boolean);
170
+ /** Runs the user's `run()` and waits for every step it started. */
171
+ run(fn: () => Promise<unknown>): Promise<RunOutcome>;
172
+ /** Journal entries that this execution never reached (compensations and retry records excluded). */
173
+ unvisited(): string[];
174
+ /** Staged entries (sleeps, helpers) not yet written; the engine commits them. */
175
+ drainBuffer(): WorkflowJournalEntry[];
176
+ requestShutdown(): void;
177
+ /** Past the shutdown timeout, the worker stopped waiting for it: never touch the store again. */
178
+ get detached(): boolean;
179
+ /**
180
+ * Extends the lease, for `WorkflowStepContext.heartbeat()` (the worker renews it on its own heartbeat too). The
181
+ * worker hands the execution the cancel and terminate requests the renewal reads.
182
+ */
183
+ renew(): Promise<void>;
184
+ /** Runs registered compensations in reverse order, each as a journaled, retried step. */
185
+ compensate(reason: SerializedWorkflowError): Promise<CompensationOutcome>;
186
+ private step;
187
+ private sleep;
188
+ /** `waitForSignal()`, and (`internal`) a child handle's `result()`, whose wait is named `$result:<id>`. */
189
+ private receive;
190
+ private startChild;
191
+ private handle;
192
+ /** Whether this instance started children, whose `parentClose` applies when it ends. */
193
+ hasChildren(): boolean;
194
+ private waitForAny;
195
+ /** Signals sent since the instance started, up to this execution's cursor: one that arrived before the wait was reached still counts. */
196
+ private signalsFor;
197
+ /** The first of `candidates` a wait can take: not taken by another wait, sent by `deadline`, and matching. */
198
+ private peek;
199
+ /** `peek()`, and marks the signal taken. Call it with no `await` between the read and the take. */
200
+ private take;
201
+ private commit;
202
+ private setStatus;
203
+ /** `{ customStatus }` when `ctx.setStatus()` changed it since it was last written, else `{}`: spread into a write. */
204
+ statusChange(): {
205
+ customStatus?: unknown;
206
+ };
207
+ /** After a write that carried `change` landed. */
208
+ statusWritten(change: {
209
+ customStatus?: unknown;
210
+ }): void;
211
+ /**
212
+ * Entries still pending when the instance ends without completing: a sleep
213
+ * or wait that will never resolve, a retry that will never run.
214
+ */
215
+ abandoned(): WorkflowJournalEntry[];
216
+ private helper;
217
+ /**
218
+ * Resolves a step's (or compensation's) retry and timeouts. Throws a
219
+ * `TypeError` for invalid options before an attempt is recorded, instead of
220
+ * spending the step's attempts on it.
221
+ */
222
+ private plan;
223
+ private attempt;
224
+ private invoke;
225
+ private giveUp;
226
+ private track;
227
+ /**
228
+ * A step's function runs once; its result is all a replay sees. A `ctx` call
229
+ * made inside it would be journaled on the first run and missing on every
230
+ * replay, so it is a definition error, reported where it happens.
231
+ */
232
+ private assertNotInStep;
233
+ private visit;
234
+ /**
235
+ * Before the first new step runs, let every replayable call happen (replayed
236
+ * results resolve in microtasks, so one macrotask is enough), then require
237
+ * that the whole journal was reached.
238
+ */
239
+ private reachFrontier;
240
+ /** Reserves the step's compensation in call order; `arm()` it with the result once the step completed. */
241
+ private reserveCompensation;
242
+ private assertAlive;
243
+ /** Whether the instance's run timeout has passed. */
244
+ pastDeadline(): boolean;
245
+ /** No new step starts once the execution is suspending or `run()` has settled. */
246
+ private assertCanStart;
247
+ private suspendUntil;
248
+ private stage;
249
+ /** Keeps `entry` as the journal's entry of its name, and tracks the journal's size. */
250
+ private record;
251
+ private measure;
252
+ private pastWarning;
253
+ /**
254
+ * Before a new name is journaled in run mode: a journal at its limit stops the run, which then
255
+ * compensates (compensations may still record their entries) and fails.
256
+ */
257
+ private assertJournalRoom;
258
+ /** Fenced write of staged entries plus `entries`. */
259
+ private write;
260
+ private loseLease;
261
+ private abortInterrupt;
262
+ /** Every interrupt `ctx` throws goes through here; the first one that stops the run is kept. */
263
+ private interrupt;
264
+ private setFatal;
265
+ private describe;
266
+ private emit;
267
+ }