@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.
- package/LICENSE +23 -0
- package/README.md +50 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +8 -0
- package/dist/core/codecs/aes-gcm-payload.codec.d.ts +42 -0
- package/dist/core/codecs/aes-gcm-payload.codec.js +119 -0
- package/dist/core/codecs/index.d.ts +2 -0
- package/dist/core/codecs/index.js +2 -0
- package/dist/core/codecs/payload-codecs.d.ts +59 -0
- package/dist/core/codecs/payload-codecs.js +130 -0
- package/dist/core/index.d.ts +16 -0
- package/dist/core/index.js +21 -0
- package/dist/core/interfaces/clock.interface.d.ts +18 -0
- package/dist/core/interfaces/clock.interface.js +1 -0
- package/dist/core/interfaces/index.d.ts +9 -0
- package/dist/core/interfaces/index.js +9 -0
- package/dist/core/interfaces/leased-worker-options.interface.d.ts +94 -0
- package/dist/core/interfaces/leased-worker-options.interface.js +1 -0
- package/dist/core/interfaces/limits.interface.d.ts +92 -0
- package/dist/core/interfaces/limits.interface.js +1 -0
- package/dist/core/interfaces/payload-codec.interface.d.ts +64 -0
- package/dist/core/interfaces/payload-codec.interface.js +1 -0
- package/dist/core/interfaces/result-waiter-options.interface.d.ts +52 -0
- package/dist/core/interfaces/result-waiter-options.interface.js +1 -0
- package/dist/core/interfaces/retry-settings.interface.d.ts +71 -0
- package/dist/core/interfaces/retry-settings.interface.js +1 -0
- package/dist/core/interfaces/schedule-store.interface.d.ts +143 -0
- package/dist/core/interfaces/schedule-store.interface.js +1 -0
- package/dist/core/interfaces/schedule.interface.d.ts +106 -0
- package/dist/core/interfaces/schedule.interface.js +1 -0
- package/dist/core/interfaces/scheduler-options.interface.d.ts +152 -0
- package/dist/core/interfaces/scheduler-options.interface.js +1 -0
- package/dist/core/limits/index.d.ts +1 -0
- package/dist/core/limits/index.js +1 -0
- package/dist/core/limits/limits.d.ts +61 -0
- package/dist/core/limits/limits.js +130 -0
- package/dist/core/results/index.d.ts +1 -0
- package/dist/core/results/index.js +1 -0
- package/dist/core/results/result-waiter.d.ts +54 -0
- package/dist/core/results/result-waiter.js +140 -0
- package/dist/core/retries/index.d.ts +1 -0
- package/dist/core/retries/index.js +1 -0
- package/dist/core/retries/retry.d.ts +60 -0
- package/dist/core/retries/retry.js +107 -0
- package/dist/core/scheduling/cron.util.d.ts +52 -0
- package/dist/core/scheduling/cron.util.js +262 -0
- package/dist/core/scheduling/encoded-schedule.store.d.ts +26 -0
- package/dist/core/scheduling/encoded-schedule.store.js +54 -0
- package/dist/core/scheduling/in-memory-schedule.store.d.ts +20 -0
- package/dist/core/scheduling/in-memory-schedule.store.js +90 -0
- package/dist/core/scheduling/index.d.ts +3 -0
- package/dist/core/scheduling/index.js +3 -0
- package/dist/core/scheduling/rrule.util.d.ts +55 -0
- package/dist/core/scheduling/rrule.util.js +371 -0
- package/dist/core/scheduling/schedule-spec.d.ts +57 -0
- package/dist/core/scheduling/schedule-spec.js +233 -0
- package/dist/core/scheduling/scheduler.d.ts +134 -0
- package/dist/core/scheduling/scheduler.js +450 -0
- package/dist/core/scheduling/time-zone.util.d.ts +18 -0
- package/dist/core/scheduling/time-zone.util.js +88 -0
- package/dist/core/time/clock.d.ts +28 -0
- package/dist/core/time/clock.js +35 -0
- package/dist/core/time/duration.d.ts +21 -0
- package/dist/core/time/duration.js +30 -0
- package/dist/core/time/index.d.ts +2 -0
- package/dist/core/time/index.js +2 -0
- package/dist/core/utils/canonical.util.d.ts +2 -0
- package/dist/core/utils/canonical.util.js +4 -0
- package/dist/core/utils/maybe.util.d.ts +8 -0
- package/dist/core/utils/maybe.util.js +14 -0
- package/dist/core/utils/payload-place.util.d.ts +10 -0
- package/dist/core/utils/payload-place.util.js +32 -0
- package/dist/core/workers/index.d.ts +1 -0
- package/dist/core/workers/index.js +1 -0
- package/dist/core/workers/leased-worker.d.ts +86 -0
- package/dist/core/workers/leased-worker.js +280 -0
- package/dist/cqrs/decorators/index.d.ts +2 -0
- package/dist/cqrs/decorators/index.js +2 -0
- package/dist/cqrs/decorators/signal-on.decorator.d.ts +18 -0
- package/dist/cqrs/decorators/signal-on.decorator.js +34 -0
- package/dist/cqrs/decorators/start-on.decorator.d.ts +18 -0
- package/dist/cqrs/decorators/start-on.decorator.js +49 -0
- package/dist/cqrs/index.d.ts +3 -0
- package/dist/cqrs/index.js +5 -0
- package/dist/cqrs/interfaces/index.d.ts +4 -0
- package/dist/cqrs/interfaces/index.js +4 -0
- package/dist/cqrs/interfaces/signal-on-options.interface.d.ts +22 -0
- package/dist/cqrs/interfaces/signal-on-options.interface.js +1 -0
- package/dist/cqrs/interfaces/start-on-options.interface.d.ts +23 -0
- package/dist/cqrs/interfaces/start-on-options.interface.js +1 -0
- package/dist/cqrs/interfaces/workflow-dispatcher-context.interface.d.ts +10 -0
- package/dist/cqrs/interfaces/workflow-dispatcher-context.interface.js +1 -0
- package/dist/cqrs/interfaces/workflow-event-route.interface.d.ts +20 -0
- package/dist/cqrs/interfaces/workflow-event-route.interface.js +1 -0
- package/dist/cqrs/utils/event-routes.util.d.ts +7 -0
- package/dist/cqrs/utils/event-routes.util.js +22 -0
- package/dist/cqrs/workflow-event.publisher.d.ts +52 -0
- package/dist/cqrs/workflow-event.publisher.js +257 -0
- package/dist/cqrs/workflow-events.explorer.d.ts +27 -0
- package/dist/cqrs/workflow-events.explorer.js +92 -0
- package/dist/cqrs/workflows-cqrs.module.d.ts +10 -0
- package/dist/cqrs/workflows-cqrs.module.js +27 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +1 -0
- package/dist/decorators/workflow.decorator.d.ts +7 -0
- package/dist/decorators/workflow.decorator.js +52 -0
- package/dist/errors/child-workflow-failed.error.d.ts +13 -0
- package/dist/errors/child-workflow-failed.error.js +14 -0
- package/dist/errors/index.d.ts +13 -0
- package/dist/errors/index.js +13 -0
- package/dist/errors/non-retryable-step.error.d.ts +4 -0
- package/dist/errors/non-retryable-step.error.js +7 -0
- package/dist/errors/step-failed.error.d.ts +15 -0
- package/dist/errors/step-failed.error.js +16 -0
- package/dist/errors/step-timeout.error.d.ts +5 -0
- package/dist/errors/step-timeout.error.js +8 -0
- package/dist/errors/workflow-definition.error.d.ts +10 -0
- package/dist/errors/workflow-definition.error.js +13 -0
- package/dist/errors/workflow-failed.error.d.ts +20 -0
- package/dist/errors/workflow-failed.error.js +17 -0
- package/dist/errors/workflow-id-conflict.error.d.ts +6 -0
- package/dist/errors/workflow-id-conflict.error.js +9 -0
- package/dist/errors/workflow-interrupt.error.d.ts +32 -0
- package/dist/errors/workflow-interrupt.error.js +19 -0
- package/dist/errors/workflow-non-determinism.error.d.ts +4 -0
- package/dist/errors/workflow-non-determinism.error.js +7 -0
- package/dist/errors/workflow-not-found.error.d.ts +10 -0
- package/dist/errors/workflow-not-found.error.js +13 -0
- package/dist/errors/workflow-result-timeout.error.d.ts +11 -0
- package/dist/errors/workflow-result-timeout.error.js +13 -0
- package/dist/errors/workflow-state.error.d.ts +11 -0
- package/dist/errors/workflow-state.error.js +14 -0
- package/dist/errors/workflow.error.d.ts +7 -0
- package/dist/errors/workflow.error.js +7 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.js +3 -0
- package/dist/events/workflow-events.interface.d.ts +145 -0
- package/dist/events/workflow-events.interface.js +1 -0
- package/dist/events/workflow-events.service.d.ts +17 -0
- package/dist/events/workflow-events.service.js +38 -0
- package/dist/events/workflows.channels.d.ts +3 -0
- package/dist/events/workflows.channels.js +9 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +23 -0
- package/dist/interfaces/index.d.ts +13 -0
- package/dist/interfaces/index.js +13 -0
- package/dist/interfaces/serialized-workflow-error.interface.d.ts +6 -0
- package/dist/interfaces/serialized-workflow-error.interface.js +1 -0
- package/dist/interfaces/workflow-client.interface.d.ts +156 -0
- package/dist/interfaces/workflow-client.interface.js +1 -0
- package/dist/interfaces/workflow-clock.interface.d.ts +7 -0
- package/dist/interfaces/workflow-clock.interface.js +1 -0
- package/dist/interfaces/workflow-context.interface.d.ts +241 -0
- package/dist/interfaces/workflow-context.interface.js +1 -0
- package/dist/interfaces/workflow-decorator-options.interface.d.ts +101 -0
- package/dist/interfaces/workflow-decorator-options.interface.js +1 -0
- package/dist/interfaces/workflow-instance.interface.d.ts +83 -0
- package/dist/interfaces/workflow-instance.interface.js +1 -0
- package/dist/interfaces/workflow-payload-codec.interface.d.ts +32 -0
- package/dist/interfaces/workflow-payload-codec.interface.js +1 -0
- package/dist/interfaces/workflow-retry-options.interface.d.ts +9 -0
- package/dist/interfaces/workflow-retry-options.interface.js +1 -0
- package/dist/interfaces/workflow-runner.interface.d.ts +11 -0
- package/dist/interfaces/workflow-runner.interface.js +1 -0
- package/dist/interfaces/workflow-schedule.interface.d.ts +104 -0
- package/dist/interfaces/workflow-schedule.interface.js +1 -0
- package/dist/interfaces/workflow-storage.interface.d.ts +4 -0
- package/dist/interfaces/workflow-storage.interface.js +1 -0
- package/dist/interfaces/workflow-store.interface.d.ts +488 -0
- package/dist/interfaces/workflow-store.interface.js +1 -0
- package/dist/interfaces/workflows-module-options.interface.d.ts +80 -0
- package/dist/interfaces/workflows-module-options.interface.js +1 -0
- package/dist/mysql/index.d.ts +5 -0
- package/dist/mysql/index.js +8 -0
- package/dist/mysql/interfaces/index.d.ts +1 -0
- package/dist/mysql/interfaces/index.js +1 -0
- package/dist/mysql/interfaces/mysql-workflow-store-options.interface.d.ts +25 -0
- package/dist/mysql/interfaces/mysql-workflow-store-options.interface.js +1 -0
- package/dist/mysql/key-limits.d.ts +30 -0
- package/dist/mysql/key-limits.js +41 -0
- package/dist/mysql/migrations/index.d.ts +7 -0
- package/dist/mysql/migrations/index.js +16 -0
- package/dist/mysql/migrations/initial.migration.d.ts +9 -0
- package/dist/mysql/migrations/initial.migration.js +104 -0
- package/dist/mysql/mysql-workflow.store.d.ts +197 -0
- package/dist/mysql/mysql-workflow.store.js +828 -0
- package/dist/postgres/errors/index.d.ts +1 -0
- package/dist/postgres/errors/index.js +2 -0
- package/dist/postgres/index.d.ts +5 -0
- package/dist/postgres/index.js +8 -0
- package/dist/postgres/interfaces/index.d.ts +1 -0
- package/dist/postgres/interfaces/index.js +1 -0
- package/dist/postgres/interfaces/postgres-workflow-store-options.interface.d.ts +22 -0
- package/dist/postgres/interfaces/postgres-workflow-store-options.interface.js +1 -0
- package/dist/postgres/migrations/index.d.ts +6 -0
- package/dist/postgres/migrations/index.js +15 -0
- package/dist/postgres/migrations/initial.migration.d.ts +6 -0
- package/dist/postgres/migrations/initial.migration.js +106 -0
- package/dist/postgres/postgres-workflow.store.d.ts +132 -0
- package/dist/postgres/postgres-workflow.store.js +586 -0
- package/dist/services/index.d.ts +6 -0
- package/dist/services/index.js +6 -0
- package/dist/services/workflow-client.service.d.ts +146 -0
- package/dist/services/workflow-client.service.js +436 -0
- package/dist/services/workflow-execution.service.d.ts +267 -0
- package/dist/services/workflow-execution.service.js +1076 -0
- package/dist/services/workflow-registry.service.d.ts +56 -0
- package/dist/services/workflow-registry.service.js +172 -0
- package/dist/services/workflow-scheduler.service.d.ts +54 -0
- package/dist/services/workflow-scheduler.service.js +173 -0
- package/dist/services/workflow-schedules.service.d.ts +60 -0
- package/dist/services/workflow-schedules.service.js +193 -0
- package/dist/services/workflow-worker.service.d.ts +92 -0
- package/dist/services/workflow-worker.service.js +468 -0
- package/dist/signals/index.d.ts +1 -0
- package/dist/signals/index.js +1 -0
- package/dist/signals/workflow.signal.d.ts +17 -0
- package/dist/signals/workflow.signal.js +28 -0
- package/dist/sql/rate-windows.d.ts +41 -0
- package/dist/sql/rate-windows.js +53 -0
- package/dist/sql/workflow-rows.d.ts +16 -0
- package/dist/sql/workflow-rows.js +102 -0
- package/dist/sql/workflow-schema.error.d.ts +21 -0
- package/dist/sql/workflow-schema.error.js +15 -0
- package/dist/storage/encoded-workflow.store.d.ts +71 -0
- package/dist/storage/encoded-workflow.store.js +201 -0
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +1 -0
- package/dist/storage/workflow.storage.d.ts +55 -0
- package/dist/storage/workflow.storage.js +159 -0
- package/dist/stores/in-memory-workflow.store.d.ts +75 -0
- package/dist/stores/in-memory-workflow.store.js +380 -0
- package/dist/stores/index.d.ts +1 -0
- package/dist/stores/index.js +1 -0
- package/dist/testing/assertions.d.ts +10 -0
- package/dist/testing/assertions.js +72 -0
- package/dist/testing/index.d.ts +38 -0
- package/dist/testing/index.js +1089 -0
- package/dist/testing/schedule-store.contract.d.ts +33 -0
- package/dist/testing/schedule-store.contract.js +161 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/journal-limits.util.d.ts +6 -0
- package/dist/utils/journal-limits.util.js +25 -0
- package/dist/utils/new-instance.util.d.ts +26 -0
- package/dist/utils/new-instance.util.js +87 -0
- package/dist/utils/normalize.util.d.ts +5 -0
- package/dist/utils/normalize.util.js +11 -0
- package/dist/utils/run-timeout.util.d.ts +3 -0
- package/dist/utils/run-timeout.util.js +15 -0
- package/dist/utils/schedule-spec.util.d.ts +16 -0
- package/dist/utils/schedule-spec.util.js +9 -0
- package/dist/utils/schedule-store.util.d.ts +15 -0
- package/dist/utils/schedule-store.util.js +44 -0
- package/dist/utils/serialize-error.util.d.ts +7 -0
- package/dist/utils/serialize-error.util.js +22 -0
- package/dist/utils/step-scope.util.d.ts +16 -0
- package/dist/utils/step-scope.util.js +38 -0
- package/dist/workflows.constants.d.ts +10 -0
- package/dist/workflows.constants.js +10 -0
- package/dist/workflows.module-definition.d.ts +4 -0
- package/dist/workflows.module-definition.js +6 -0
- package/dist/workflows.module.d.ts +24 -0
- package/dist/workflows.module.js +68 -0
- package/package.json +123 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { ConcurrencyLimit, RateLimit, RateWindow, ResolvedConcurrency, ResolvedRateLimit } from '../core/interfaces/limits.interface.js';
|
|
2
|
+
import type { Duration } from '../core/time/duration.js';
|
|
3
|
+
import type { WorkflowScheduleSpec } from '../utils/schedule-spec.util.js';
|
|
4
|
+
import type { WorkflowScheduleDeclaration } from './workflow-schedule.interface.js';
|
|
5
|
+
export interface WorkflowMetadata {
|
|
6
|
+
name: string;
|
|
7
|
+
version: number;
|
|
8
|
+
/** In milliseconds. */
|
|
9
|
+
timeout?: number;
|
|
10
|
+
/** `null`: no limit. `undefined`: not known here (a workflow started by name that this process doesn't register). */
|
|
11
|
+
concurrency?: WorkflowConcurrencyMetadata | null;
|
|
12
|
+
/** `null`: no limit. `undefined`: not known here, as for `concurrency`. */
|
|
13
|
+
rateLimit?: WorkflowRateLimitMetadata | null;
|
|
14
|
+
/** `@Workflow(name, { schedules })`, validated. */
|
|
15
|
+
schedules?: WorkflowDeclaredSchedule[];
|
|
16
|
+
}
|
|
17
|
+
/** One of `@Workflow(name, { schedules })`, validated: its spec (as the store keeps it) and its input. */
|
|
18
|
+
export interface WorkflowDeclaredSchedule {
|
|
19
|
+
id: string;
|
|
20
|
+
spec: WorkflowScheduleSpec;
|
|
21
|
+
/** A JSON value (normalized), or a function of the occurrence. */
|
|
22
|
+
input: unknown;
|
|
23
|
+
}
|
|
24
|
+
/** `@Workflow(name, { concurrency })`, validated. */
|
|
25
|
+
export type WorkflowConcurrencyMetadata = ResolvedConcurrency;
|
|
26
|
+
/** `@Workflow(name, { rateLimit })`, validated. */
|
|
27
|
+
export type WorkflowRateLimitMetadata = ResolvedRateLimit;
|
|
28
|
+
/** At most `max` executions start per window of `duration` milliseconds. */
|
|
29
|
+
export type WorkflowRateWindow = RateWindow;
|
|
30
|
+
/** One limit of `@Workflow(name, { concurrency })`. */
|
|
31
|
+
export interface WorkflowConcurrency extends ConcurrencyLimit {
|
|
32
|
+
/** A positive integer: how many instances may run at once, of the workflow, or with `key`, per key. */
|
|
33
|
+
limit: number;
|
|
34
|
+
/**
|
|
35
|
+
* Makes `limit` a limit per key: the key of an instance, computed from its (JSON) input when
|
|
36
|
+
* it starts, such as `(order) => order.customerId`. `null` or `undefined` leaves the instance
|
|
37
|
+
* out of every key. `start()`'s `concurrencyKey` option overrides it.
|
|
38
|
+
*/
|
|
39
|
+
key?: (input: any) => string | null | undefined;
|
|
40
|
+
}
|
|
41
|
+
/** One limit of `@Workflow(name, { rateLimit })`. */
|
|
42
|
+
export interface WorkflowRateLimit extends RateLimit {
|
|
43
|
+
/** A positive integer: how many executions may start per `duration`, of the workflow, or with `key`, per key. */
|
|
44
|
+
max: number;
|
|
45
|
+
/** The window, such as `'1m'`. */
|
|
46
|
+
duration: Duration;
|
|
47
|
+
/**
|
|
48
|
+
* Makes the limit a limit per key: the key of an instance, computed from its (JSON) input when it starts, such
|
|
49
|
+
* as `(order) => order.customerId`. `null` or `undefined` leaves the instance out of every key. `start()`'s
|
|
50
|
+
* `rateLimitKey` option overrides it.
|
|
51
|
+
*/
|
|
52
|
+
key?: (input: any) => string | null | undefined;
|
|
53
|
+
}
|
|
54
|
+
export interface WorkflowDecoratorOptions {
|
|
55
|
+
/**
|
|
56
|
+
* Bump when a change would not replay against journals written by the
|
|
57
|
+
* previous code (renamed, removed, reordered or inserted steps). Keep the old
|
|
58
|
+
* class registered until its instances finish. Default 1.
|
|
59
|
+
*/
|
|
60
|
+
version?: number;
|
|
61
|
+
/**
|
|
62
|
+
* How long an instance may run, from its start to its end, sleeps and waits included. Once it
|
|
63
|
+
* passes, the instance stops at its next `ctx` call (a step that is running finishes first), runs
|
|
64
|
+
* its compensations and ends as `failed` with a `WorkflowTimeoutError`. The deadline is stored
|
|
65
|
+
* with the instance, so it holds across restarts, and a parked instance wakes for it. `start()`'s
|
|
66
|
+
* `timeout` option overrides it. Default: none.
|
|
67
|
+
*/
|
|
68
|
+
timeout?: Duration;
|
|
69
|
+
/**
|
|
70
|
+
* How many instances may run at once, across every worker: `{ limit }` for the workflow,
|
|
71
|
+
* `{ limit, key }` per key (at most one instance per customer: `{ limit: 1, key: (order) =>
|
|
72
|
+
* order.customerId }`), or one of each in an array. An instance holds a slot while an
|
|
73
|
+
* execution runs it (compensations included), not while it sleeps or waits for a signal: a
|
|
74
|
+
* limit protects what the steps call, and an instance parked for days doesn't hold up the
|
|
75
|
+
* others. Instances past a limit stay due and queue, most overdue first; one busy key never
|
|
76
|
+
* holds back the others. Applies to every version of the workflow, with the highest
|
|
77
|
+
* registered version's limits. Default: none.
|
|
78
|
+
*/
|
|
79
|
+
concurrency?: WorkflowConcurrency | WorkflowConcurrency[];
|
|
80
|
+
/**
|
|
81
|
+
* How many executions may start per window, across every worker: `{ max, duration }` for the workflow,
|
|
82
|
+
* `{ max, duration, key }` per key (at most 5 a minute per customer: `{ max: 5, duration: '1m', key: (order) =>
|
|
83
|
+
* order.customerId }`), or one of each in an array. Every execution counts: an instance's first run and each
|
|
84
|
+
* resumption (after a sleep, a signal, a retry's backoff, a cancel), because each can call what the limit
|
|
85
|
+
* protects. A window starts with the first execution after the previous window ended. Instances past a limit stay
|
|
86
|
+
* due and wait, in priority order; one busy key never holds back the others. Applies to every version of the
|
|
87
|
+
* workflow, with the highest registered version's limits. Default: none.
|
|
88
|
+
*/
|
|
89
|
+
rateLimit?: WorkflowRateLimit | WorkflowRateLimit[];
|
|
90
|
+
/**
|
|
91
|
+
* Starts instances on a schedule: a `cron` expression, an interval (`every`) or an RFC 5545 `rrule`, in a
|
|
92
|
+
* time zone (`tz`), with an `id` unique across the application. Kept in step with the code, also in a rolling
|
|
93
|
+
* deploy: a process saves and confirms the schedules its highest registered version of the workflow declares, at
|
|
94
|
+
* startup and every minute, and removes one its code doesn't declare, of any workflow, once no process whose code
|
|
95
|
+
* declares it has confirmed it for five minutes (a process whose code declares it saves it again as it starts);
|
|
96
|
+
* it leaves a newer version's declaration as it is while a process of that code runs. Each occurrence starts one
|
|
97
|
+
* instance, whose id is `<schedule id>@<ISO time of the occurrence>`, however many workers there are;
|
|
98
|
+
* `WorkflowSchedules` pauses, resumes, triggers and lists them. Default: none.
|
|
99
|
+
*/
|
|
100
|
+
schedules?: WorkflowScheduleDeclaration[];
|
|
101
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { SerializedWorkflowError } from './serialized-workflow-error.interface.js';
|
|
2
|
+
export type WorkflowStatus = 'pending' | 'running' | 'suspended' | 'compensating' | 'completed' | 'failed' | 'cancelled' | 'compensation_failed';
|
|
3
|
+
/** What happens to a child instance that is still running when its parent ends (`ctx.startChild()`'s `parentClose`). */
|
|
4
|
+
export type WorkflowParentClose = 'cancel' | 'terminate' | 'abandon';
|
|
5
|
+
export interface WorkflowInstance {
|
|
6
|
+
id: string;
|
|
7
|
+
workflow: string;
|
|
8
|
+
version: number;
|
|
9
|
+
/** The instance that started this one with `ctx.startChild()`, or `null`. */
|
|
10
|
+
parentId: string | null;
|
|
11
|
+
/** For a child: what happens to it if it is still running when its parent ends. */
|
|
12
|
+
parentClose: WorkflowParentClose | null;
|
|
13
|
+
/** The key its workflow's per-key concurrency limit counts it under, or `null`. */
|
|
14
|
+
concurrencyKey: string | null;
|
|
15
|
+
/** The key its workflow's per-key rate limit counts it under, or `null`. */
|
|
16
|
+
rateLimitKey: string | null;
|
|
17
|
+
/** Lower is claimed first; `0` (none given) before every other. */
|
|
18
|
+
priority: number;
|
|
19
|
+
/** The schedule that started it (`WorkflowSchedules`, `@Workflow(name, { schedules })`), or `null`. */
|
|
20
|
+
scheduleId: string | null;
|
|
21
|
+
/** For an instance a schedule started: when its occurrence was due (or triggered), or `null`. */
|
|
22
|
+
scheduledAt: number | null;
|
|
23
|
+
status: WorkflowStatus;
|
|
24
|
+
input: unknown;
|
|
25
|
+
output?: unknown;
|
|
26
|
+
error?: SerializedWorkflowError | null;
|
|
27
|
+
/** When the instance is next runnable. `null` = only a signal or cancel can wake it. */
|
|
28
|
+
wakeAt: number | null;
|
|
29
|
+
leaseOwner: string | null;
|
|
30
|
+
leaseUntil: number | null;
|
|
31
|
+
cancelRequested: boolean;
|
|
32
|
+
/** Set with `cancelRequested` by `WorkflowClient.terminate()`: stop without compensating. */
|
|
33
|
+
terminateRequested: boolean;
|
|
34
|
+
cancelReason: string | null;
|
|
35
|
+
/**
|
|
36
|
+
* When the run timeout passes (`@Workflow(name, { timeout })` or `start()`'s `timeout`), or
|
|
37
|
+
* `null` for none.
|
|
38
|
+
*/
|
|
39
|
+
deadline: number | null;
|
|
40
|
+
/**
|
|
41
|
+
* What the workflow last set with `ctx.setStatus()` (JSON), or `null`. Written with the lease
|
|
42
|
+
* holder's writes, so it lags `setStatus()` until the instance's next journal write or
|
|
43
|
+
* suspension.
|
|
44
|
+
*/
|
|
45
|
+
customStatus: unknown;
|
|
46
|
+
/** Signals with an id above this one can match the instance's waits. */
|
|
47
|
+
signalCursor: number;
|
|
48
|
+
/** Number of executions (claims) so far. */
|
|
49
|
+
runs: number;
|
|
50
|
+
createdAt: number;
|
|
51
|
+
updatedAt: number;
|
|
52
|
+
}
|
|
53
|
+
export interface WorkflowJournalEntry {
|
|
54
|
+
name: string;
|
|
55
|
+
/** `retry`: an operator's `WorkflowClient.retry()`, recorded under `$retry:<n>` with what it retried in `data`. */
|
|
56
|
+
kind: 'step' | 'sleep' | 'signal' | 'any' | 'child' | 'commit' | 'now' | 'random' | 'uuid' | 'compensation' | 'retry';
|
|
57
|
+
/**
|
|
58
|
+
* `cancelled`: still pending (a sleep, a wait, a retry backoff) when the
|
|
59
|
+
* instance ended as `cancelled`, `failed` or `compensation_failed`.
|
|
60
|
+
*/
|
|
61
|
+
status: 'pending' | 'completed' | 'failed' | 'cancelled';
|
|
62
|
+
/**
|
|
63
|
+
* JSON-safe step result, signal `{ signalId, payload }`, `waitForAny()` winner
|
|
64
|
+
* `{ key, signalId, payload }` (`signalId: null` for a timer), started child
|
|
65
|
+
* `{ id, workflow, version }`, or helper value.
|
|
66
|
+
*/
|
|
67
|
+
result?: unknown;
|
|
68
|
+
error?: SerializedWorkflowError;
|
|
69
|
+
/** Attempts started (steps and compensations). */
|
|
70
|
+
attempts: number;
|
|
71
|
+
/** Sleep deadline, wait timeout, or retry time. `null` while an attempt runs. */
|
|
72
|
+
wakeAt?: number | null;
|
|
73
|
+
/** Last `heartbeat(progress)` checkpoint. */
|
|
74
|
+
progress?: unknown;
|
|
75
|
+
/** Wait spec (`{ signal, key }`), or a `waitForAny()`'s conditions (`{ waits, timers }`). */
|
|
76
|
+
data?: unknown;
|
|
77
|
+
updatedAt?: number;
|
|
78
|
+
}
|
|
79
|
+
/** A signal an instance is waiting for. */
|
|
80
|
+
export interface WorkflowWait {
|
|
81
|
+
signal: string;
|
|
82
|
+
key: string | null;
|
|
83
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { PayloadCodec, PayloadContext } from '../core/interfaces/payload-codec.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* Where a payload is stored, which the codec receives with it, the same to encode and to decode: a codec that
|
|
4
|
+
* authenticates it (`AesGcmPayloadCodec` does) refuses a payload moved to another instance, entry or field.
|
|
5
|
+
*/
|
|
6
|
+
export interface WorkflowPayloadContext extends PayloadContext {
|
|
7
|
+
/**
|
|
8
|
+
* The field that holds it: of an instance (`input`, `output`, `error`, `customStatus`, `cancelReason`), of one of
|
|
9
|
+
* its journal entries (`result`, `progress`, `error`, `data`), of a signal (`payload`), or of a schedule (`input`).
|
|
10
|
+
*/
|
|
11
|
+
field: 'input' | 'output' | 'error' | 'customStatus' | 'cancelReason' | 'result' | 'progress' | 'data' | 'payload';
|
|
12
|
+
/** The instance, for an instance's or a journal entry's payload. */
|
|
13
|
+
instanceId?: string;
|
|
14
|
+
/** The journal entry's name, for an entry's payload. */
|
|
15
|
+
entry?: string;
|
|
16
|
+
/** The signal's name, for a signal's payload. */
|
|
17
|
+
signal?: string;
|
|
18
|
+
/** The schedule's id, for a schedule's input. */
|
|
19
|
+
schedule?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Encodes what workflows store for you before the store sees it, and decodes it on the way back: to encrypt it, or
|
|
23
|
+
* compress it. The module applies it to inputs, outputs, step results, checkpoints, journal entries' data, signal
|
|
24
|
+
* payloads, custom statuses, cancel reasons, schedule inputs, and errors' messages and stacks. Ids, names, keys,
|
|
25
|
+
* statuses and times stay as they are: the store matches on them. `WorkflowsModule.forRoot({ codec })` takes one
|
|
26
|
+
* (an instance, or a class Nest creates with its dependencies), or several: the first encodes, and each payload is
|
|
27
|
+
* decoded by the codec whose `id` it was stored with, so a codec you replace keeps decoding what it encoded.
|
|
28
|
+
* Payloads stored before any codec was set are read as they are. A `PayloadCodec` of `@nestjs/workflows/core` whose
|
|
29
|
+
* methods take any context (`AesGcmPayloadCodec`) is one.
|
|
30
|
+
*/
|
|
31
|
+
export interface WorkflowPayloadCodec extends PayloadCodec<WorkflowPayloadContext> {
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RetrySettings } from '../core/interfaces/retry-settings.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* How a step (or compensation) retries. `retry: 5` means `{ attempts: 5 }`;
|
|
4
|
+
* `retry: false` means a single attempt. Workflows default to 3 attempts, a
|
|
5
|
+
* 1s first delay doubling up to 5m, no jitter. Every retry parks the instance
|
|
6
|
+
* durably: the wait survives restarts. A `NonRetryableStepError` never retries.
|
|
7
|
+
*/
|
|
8
|
+
export interface WorkflowRetryOptions extends RetrySettings {
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { WorkflowContext } from './workflow-context.interface.js';
|
|
2
|
+
/** Implemented by `@Workflow()` classes: `WorkflowRunner<Input, Output>`. */
|
|
3
|
+
export interface WorkflowRunner<I = unknown, O = unknown> {
|
|
4
|
+
run(ctx: WorkflowContext, input: I): Promise<O>;
|
|
5
|
+
}
|
|
6
|
+
export type WorkflowInput<W> = W extends {
|
|
7
|
+
run(ctx: any, input: infer I): any;
|
|
8
|
+
} ? I : unknown;
|
|
9
|
+
export type WorkflowOutput<W> = W extends {
|
|
10
|
+
run(ctx: any, input: any): infer R;
|
|
11
|
+
} ? Awaited<R> : unknown;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { Type } from '@nestjs/common';
|
|
2
|
+
import type { ScheduleMissed, ScheduleOccurrence, ScheduleOptions, ScheduleOverlap, ScheduleTiming } from '../core/interfaces/schedule.interface.js';
|
|
3
|
+
import type { WorkflowInput } from './workflow-runner.interface.js';
|
|
4
|
+
/**
|
|
5
|
+
* When a schedule's occurrences are: exactly one of `cron`, `every` or `rrule`, with its time zone and
|
|
6
|
+
* bounds. Times are wall-clock times in `tz`: on the day clocks go forward, a time that doesn't exist runs
|
|
7
|
+
* that much later (02:30 runs at 03:30); on the day they go back, a time that happens twice runs once, the
|
|
8
|
+
* first time. For a fixed interval whatever the clocks do, use `every` (or `tz: 'UTC'`).
|
|
9
|
+
*/
|
|
10
|
+
export type WorkflowScheduleTiming = ScheduleTiming;
|
|
11
|
+
/**
|
|
12
|
+
* What a schedule does with occurrences no worker was up to start (a deploy, an outage): `'skip'` them (only an
|
|
13
|
+
* occurrence found within a minute of its time starts), start the latest of them `'once'`, or start `'all'` of
|
|
14
|
+
* them at once (the latest 100 at most; it needs `overlap: 'allow'`).
|
|
15
|
+
*/
|
|
16
|
+
export type WorkflowScheduleMissed = ScheduleMissed;
|
|
17
|
+
/**
|
|
18
|
+
* What an occurrence does while an instance the schedule started is still running: `'skip'` it, `'allow'` it
|
|
19
|
+
* (both run), `'cancel-previous'` (the running one is cancelled, and compensates, while the new one starts), or
|
|
20
|
+
* `'buffer-one'` (it starts once the running one ends; one occurrence waits at most, later ones are skipped).
|
|
21
|
+
*/
|
|
22
|
+
export type WorkflowScheduleOverlap = ScheduleOverlap;
|
|
23
|
+
/** What `@Workflow(name, { schedules })` and `WorkflowSchedules.upsert()` share. */
|
|
24
|
+
export interface WorkflowScheduleOptions extends ScheduleOptions {
|
|
25
|
+
/** The priority of the instances it starts, as `WorkflowClient.start()`'s. Default: none. */
|
|
26
|
+
priority?: number;
|
|
27
|
+
}
|
|
28
|
+
/** An occurrence of a schedule: what a declared schedule's `input` function receives, and `ctx.schedule`. */
|
|
29
|
+
export type WorkflowScheduleOccurrence = ScheduleOccurrence;
|
|
30
|
+
/** One entry of `@Workflow(name, { schedules })`. */
|
|
31
|
+
export interface WorkflowScheduleDeclaration<I = any> extends WorkflowScheduleOptions {
|
|
32
|
+
/** Unique across the application's schedules: letters, digits, `.`, `:`, `_` and `-`. */
|
|
33
|
+
id: string;
|
|
34
|
+
/**
|
|
35
|
+
* The input of the instances it starts: a JSON value, or a function of the occurrence, called by the worker
|
|
36
|
+
* that starts it (`input: ({ at }) => ({ week: isoWeek(at) })`). Default: none.
|
|
37
|
+
*/
|
|
38
|
+
input?: ((occurrence: WorkflowScheduleOccurrence) => I) | ScheduleInputValue<I>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A declared schedule's input as a value. Without a type for it, any JSON value: not `I` itself, since `any` or
|
|
42
|
+
* `unknown` in the union would swallow the function beside it, and with it the occurrence's type for its parameter.
|
|
43
|
+
*/
|
|
44
|
+
type ScheduleInputValue<I> = unknown extends I ? string | number | boolean | object | null : I;
|
|
45
|
+
/** What `WorkflowSchedules.upsert()` takes. */
|
|
46
|
+
export interface UpsertWorkflowScheduleOptions<W = unknown> extends WorkflowScheduleOptions {
|
|
47
|
+
/** The workflow it starts: the class, or its name. */
|
|
48
|
+
workflow: Type<W> | string;
|
|
49
|
+
/** Pin a version. Default: the highest the worker that starts an occurrence registers. */
|
|
50
|
+
version?: number;
|
|
51
|
+
/** The input of the instances it starts: a JSON value, stored with the schedule. Default: none. */
|
|
52
|
+
input?: WorkflowInput<W>;
|
|
53
|
+
}
|
|
54
|
+
/** What `WorkflowSchedules.preview()` takes, with the spec of a schedule that isn't stored. */
|
|
55
|
+
export type WorkflowSchedulePreviewSpec = WorkflowScheduleTiming & Pick<WorkflowScheduleOptions, 'limit'>;
|
|
56
|
+
/** A schedule, as `WorkflowSchedules.get()` and `list()` return it. */
|
|
57
|
+
export interface WorkflowSchedule {
|
|
58
|
+
id: string;
|
|
59
|
+
/** The workflow it starts. */
|
|
60
|
+
workflow: string;
|
|
61
|
+
/** The version it starts, or `null`: the highest the worker that starts an occurrence registers. */
|
|
62
|
+
version: number | null;
|
|
63
|
+
/** Declared with `@Workflow(name, { schedules })`: kept in step with the code at startup. */
|
|
64
|
+
declared: boolean;
|
|
65
|
+
cron?: string;
|
|
66
|
+
/** In milliseconds. */
|
|
67
|
+
every?: number;
|
|
68
|
+
rrule?: string;
|
|
69
|
+
tz: string;
|
|
70
|
+
startAt: number | null;
|
|
71
|
+
endAt: number | null;
|
|
72
|
+
limit: number | null;
|
|
73
|
+
missed: WorkflowScheduleMissed;
|
|
74
|
+
overlap: WorkflowScheduleOverlap;
|
|
75
|
+
/** `0`: none. */
|
|
76
|
+
priority: number;
|
|
77
|
+
/** The stored input; `undefined` for a declared schedule whose input is a function. */
|
|
78
|
+
input?: unknown;
|
|
79
|
+
paused: boolean;
|
|
80
|
+
/** When its next occurrence is due (epoch milliseconds), or `null`: paused, or ended (`endAt`, `limit`, COUNT, UNTIL). */
|
|
81
|
+
nextAt: number | null;
|
|
82
|
+
/** Occurrences it started (or buffered) so far: what `limit` counts. */
|
|
83
|
+
runs: number;
|
|
84
|
+
/** An occurrence waiting for the running instance to end (`overlap: 'buffer-one'`), or `null`. */
|
|
85
|
+
bufferedAt: number | null;
|
|
86
|
+
createdAt: number;
|
|
87
|
+
updatedAt: number;
|
|
88
|
+
}
|
|
89
|
+
/** What `WorkflowSchedules.list()` takes. */
|
|
90
|
+
export interface WorkflowScheduleListFilter {
|
|
91
|
+
/** Only the schedules of this workflow. */
|
|
92
|
+
workflow?: string;
|
|
93
|
+
/** Default 100. */
|
|
94
|
+
limit?: number;
|
|
95
|
+
offset?: number;
|
|
96
|
+
}
|
|
97
|
+
/** What `WorkflowSchedules.preview()` takes. */
|
|
98
|
+
export interface WorkflowSchedulePreviewOptions {
|
|
99
|
+
/** Occurrences after this time. Default: now. */
|
|
100
|
+
from?: Date | number;
|
|
101
|
+
/** How many. Default 10, at most 1,000. */
|
|
102
|
+
count?: number;
|
|
103
|
+
}
|
|
104
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|