@dudousxd/nestjs-durable 0.64.0 → 0.65.0
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/dist/index.cjs +730 -352
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +176 -12
- package/dist/index.d.ts +176 -12
- package/dist/index.js +583 -205
- package/dist/index.js.map +1 -1
- package/dist/migrate-from-nestjs-workflows.cjs +8 -2
- package/dist/migrate-from-nestjs-workflows.cjs.map +1 -1
- package/dist/migrate-from-nestjs-workflows.js +8 -2
- package/dist/migrate-from-nestjs-workflows.js.map +1 -1
- package/package.json +3 -3
- package/skills/durable-setup/SKILL.md +5 -1
- package/skills/durable-signals-and-timers/SKILL.md +12 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WorkflowCtx, SearchAttributes, WorkflowClass, StandardSchemaV1, StepError, OnEventEntry, OnErrorInput, LifecycleEventOf, WorkflowLifecycleEvent, WorkflowRef, SingletonConfig, ConcurrencyConfig, SearchAttributesSchema, EventBatchConfig, TenantVerifier, VerifiedTenant, TenantTokenSource, StateStore, Transport, NamedTransport, ControlPlane, StalledRunInfo, ScheduledWorkflow, RetentionPolicy, QueueConfig, AdmissionBackend, WorkflowInputOf, StartOptions,
|
|
1
|
+
import { WorkflowCtx, SearchAttributes, WorkflowClass, StandardSchemaV1, StepError, OnEventEntry, OnErrorInput, LifecycleEventOf, WorkflowLifecycleEvent, WorkflowRef, SingletonConfig, ConcurrencyConfig, SearchAttributesSchema, EventBatchConfig, TenantVerifier, VerifiedTenant, TenantTokenSource, StateStore, Transport, NamedTransport, ControlPlane, StalledRunInfo, ScheduledWorkflow, RetentionPolicy, QueueConfig, AdmissionBackend, SignalOptions, RunResult, StartRunMessage, WorkflowInputOf, StartOptions, WorkflowStartClient, ScheduleAnnouncement, RunGateway, WorkflowEngine, EntityHandler, DurableTopology, RunDetailOptions, RunDetail, FanPageQuery, FanPage, WorkflowRun, RunQuery, RunListItem, RunFacetQuery, RunFacetRow, RunValueAxis, RunValueFacetOptions, RunValueFacetRow, RunWaiting, WorkflowLifecycleLinks, LifecycleKind, GroupHealth, ScheduleListQuery, ScheduleDescription, RepublishLifecycleTarget, RepublishLifecycleResult, ScheduleAction, EngineEvent, RunRequest, RunReply, TenantFilter as TenantFilter$1, StepInvocation, TenantEvent } from '@dudousxd/nestjs-durable-core';
|
|
2
2
|
export { AttributeFilter, DuplicateDurableCopyError, DynamicWorkflowCtx, EngineEvent, EventSubscription, InferSearchAttributes, LIFECYCLE_PENDING_TAG, LifecycleEventOf, LifecycleKind, OnErrorInput, OnEventEntry, RunDetail, RunGateway, RunListItem, RunQuery, RunSchedulesOptions, RunStatus, RunWaiting, ScheduledWorkflow, SearchAttributes, SearchAttributesSchema, StepCheckpoint, StepEvent, StepLogger, TenantTokenSource, TenantVerifier, VerifiedTenant, WorkflowCtx, WorkflowEngine, WorkflowHandler, WorkflowLifecycleEvent, WorkflowRun, hmacTenantVerifier, lifecycleRunId, lifecycleSourceOf, prevCronFireMs, readSearchAttributes, runCompletedEvent, runFailedEvent, runSchedules, scheduleRunIdAt, scheduledRunId, signTenantToken, triggeredRunsOf } from '@dudousxd/nestjs-durable-core';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { ConcurrencyOption, StartRunDeps, RunRedisWorkerOptions, RunningWorker, DurableWorkerRuntime } from '@dudousxd/durable-worker';
|
|
@@ -1219,6 +1219,42 @@ declare class DurableModule {
|
|
|
1219
1219
|
private static build;
|
|
1220
1220
|
}
|
|
1221
1221
|
|
|
1222
|
+
/**
|
|
1223
|
+
* The `@Workflow` options a tenant's start applies itself, before it publishes the start-run: the
|
|
1224
|
+
* ones that are functions of the input, which the control plane (knowing the workflow by name
|
|
1225
|
+
* alone) cannot evaluate. Declared by `ThinWorkflowRegistrar` for every `@Workflow` it discovers.
|
|
1226
|
+
*/
|
|
1227
|
+
interface TenantWorkflowStartPolicy {
|
|
1228
|
+
/** `@Workflow({ input, validateInput })`: rejects the start (throws) before anything is published. */
|
|
1229
|
+
validateInput?: ((input: unknown) => void | Promise<void>) | undefined;
|
|
1230
|
+
/** `@Workflow({ singleton })`: its key is evaluated here and carried on the start-run. */
|
|
1231
|
+
singleton?: SingletonConfig | undefined;
|
|
1232
|
+
/** `@Workflow({ concurrency })`: the default quota, evaluated here unless the start passes one. */
|
|
1233
|
+
concurrency?: ConcurrencyConfig | undefined;
|
|
1234
|
+
/** `@Workflow({ onEvent })` / `@OnDurableEvent`: started by this app's own `publishEvent`. */
|
|
1235
|
+
onEvent?: OnEventEntry[] | undefined;
|
|
1236
|
+
/** The workflow coalesces its event triggers (`debounce`/`batch`), which a tenant cannot apply. */
|
|
1237
|
+
coalesces?: boolean | undefined;
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* Where a tenant's `signal`/`signalWithStart`/`publishEvent` go: run requests to the control plane
|
|
1241
|
+
* (the module's `ProxyRunGateway` over `transport`).
|
|
1242
|
+
*/
|
|
1243
|
+
interface TenantRunRequests {
|
|
1244
|
+
signal(token: string, payload: unknown, opts?: SignalOptions): Promise<RunResult | null>;
|
|
1245
|
+
signalWithStart(start: Omit<StartRunMessage, 'tenant'> & {
|
|
1246
|
+
runId: string;
|
|
1247
|
+
}, signal: {
|
|
1248
|
+
token: string;
|
|
1249
|
+
payload?: unknown;
|
|
1250
|
+
}): Promise<{
|
|
1251
|
+
runId: string;
|
|
1252
|
+
signalled: boolean;
|
|
1253
|
+
}>;
|
|
1254
|
+
publishEvent(name: string, payload: unknown, opts?: {
|
|
1255
|
+
id?: string;
|
|
1256
|
+
}): Promise<number>;
|
|
1257
|
+
}
|
|
1222
1258
|
/**
|
|
1223
1259
|
* The **store-less `engine.start` facade** for a tenant worker. Provided under the `WorkflowEngine`
|
|
1224
1260
|
* DI token by {@link import('./durable.module').DurableModule} (`forRoot({ connection })`, no
|
|
@@ -1236,13 +1272,91 @@ declare class DurableStartClient {
|
|
|
1236
1272
|
private readonly deps?;
|
|
1237
1273
|
/** The context accessor, for the customer tenant a start claims (else the global slot). */
|
|
1238
1274
|
private readonly accessor?;
|
|
1275
|
+
/**
|
|
1276
|
+
* Sends `signal`/`signalWithStart`/`publishEvent` to the control plane as run requests (the
|
|
1277
|
+
* module's `ProxyRunGateway` over `transport`). Absent (no `transport`): they reject, naming it.
|
|
1278
|
+
*/
|
|
1279
|
+
private readonly requests?;
|
|
1239
1280
|
private readonly tenant;
|
|
1240
1281
|
private readonly tenantToken;
|
|
1282
|
+
private readonly policies;
|
|
1283
|
+
private readonly warnedCoalescing;
|
|
1241
1284
|
constructor(options: DurableModuleOptions, deps?: StartRunDeps | undefined,
|
|
1242
1285
|
/** The context accessor, for the customer tenant a start claims (else the global slot). */
|
|
1243
|
-
accessor?: ContextAccessor | undefined
|
|
1286
|
+
accessor?: ContextAccessor | undefined,
|
|
1287
|
+
/**
|
|
1288
|
+
* Sends `signal`/`signalWithStart`/`publishEvent` to the control plane as run requests (the
|
|
1289
|
+
* module's `ProxyRunGateway` over `transport`). Absent (no `transport`): they reject, naming it.
|
|
1290
|
+
*/
|
|
1291
|
+
requests?: (() => TenantRunRequests | undefined) | undefined);
|
|
1292
|
+
/**
|
|
1293
|
+
* Apply `policy` to every start of `workflow` from this process (see
|
|
1294
|
+
* {@link TenantWorkflowStartPolicy}). Called by `ThinWorkflowRegistrar` at boot.
|
|
1295
|
+
*/
|
|
1296
|
+
declareWorkflow(workflow: string, policy: TenantWorkflowStartPolicy): void;
|
|
1297
|
+
/**
|
|
1298
|
+
* The start-run fields a declared policy adds for `input`: it validates the input (throwing), and
|
|
1299
|
+
* evaluates the singleton key and the default quota. A per-start `concurrency` wins over the
|
|
1300
|
+
* workflow's.
|
|
1301
|
+
*/
|
|
1302
|
+
private applyPolicy;
|
|
1303
|
+
/** The wire `tenant`: the signed token when configured, else the partition. */
|
|
1304
|
+
private wireTenant;
|
|
1305
|
+
/**
|
|
1306
|
+
* The customer tenant a start claims: an explicit `tenantId` (`null` = none), else the request's
|
|
1307
|
+
* tenant when tenancy is on.
|
|
1308
|
+
*/
|
|
1309
|
+
private claimedTenant;
|
|
1244
1310
|
start<C extends WorkflowClass>(workflow: C, input: WorkflowInputOf<C>, runId?: string, opts?: StartOptions): Promise<RunResult>;
|
|
1245
1311
|
start(workflow: string, input: unknown, runId?: string, opts?: StartOptions): Promise<RunResult>;
|
|
1312
|
+
/**
|
|
1313
|
+
* The start-run a start of `name` sends (everything but the wire `tenant`): the start options the
|
|
1314
|
+
* control plane applies (version pin, priority, delayed start, quota), the singleton key and the
|
|
1315
|
+
* customer tenant this run claims. Applies the workflow's declared policy first, so a rejected
|
|
1316
|
+
* input throws before anything is published, as `engine.start` does.
|
|
1317
|
+
*/
|
|
1318
|
+
private startMessage;
|
|
1319
|
+
/** The control plane's run requests, or a clear error naming what is missing. */
|
|
1320
|
+
private runRequests;
|
|
1321
|
+
/**
|
|
1322
|
+
* Signal the run of this tenant's partition waiting on `token`, through the control plane.
|
|
1323
|
+
* Resolves the resumed run, or null when no run of this partition waits on it: unlike
|
|
1324
|
+
* `engine.signal` on a control plane, a tenant's signal is NOT buffered for a wait opened later
|
|
1325
|
+
* (another partition's run could open it). Use `signalWithStart` to signal a run that may not wait
|
|
1326
|
+
* yet. `opts.id` deduplicates like `engine.signal`.
|
|
1327
|
+
*/
|
|
1328
|
+
signal(token: string, payload: unknown, opts?: SignalOptions): Promise<RunResult | null>;
|
|
1329
|
+
/**
|
|
1330
|
+
* Ensure the run `runId` of `workflow` exists in this tenant's partition (started like
|
|
1331
|
+
* {@link start}, with the same options and policy), then signal it. The control plane buffers the
|
|
1332
|
+
* signal until the run waits on `signal.token` only when the token contains `runId` (a run-scoped
|
|
1333
|
+
* token, the pattern `signalWithStart` is for): a token that does not is delivered only to a run
|
|
1334
|
+
* of this partition already waiting on it, and refused otherwise.
|
|
1335
|
+
*/
|
|
1336
|
+
signalWithStart<C extends WorkflowClass>(workflow: C, input: WorkflowInputOf<C>, runId: string, signal: {
|
|
1337
|
+
token: string;
|
|
1338
|
+
payload?: unknown;
|
|
1339
|
+
}, opts?: StartOptions): Promise<{
|
|
1340
|
+
runId: string;
|
|
1341
|
+
}>;
|
|
1342
|
+
signalWithStart(workflow: string, input: unknown, runId: string, signal: {
|
|
1343
|
+
token: string;
|
|
1344
|
+
payload?: unknown;
|
|
1345
|
+
}, opts?: StartOptions): Promise<{
|
|
1346
|
+
runId: string;
|
|
1347
|
+
}>;
|
|
1348
|
+
/**
|
|
1349
|
+
* Publish event `name` from this tenant. Starts this app's own `onEvent` subscribers (each one
|
|
1350
|
+
* whose `where` accepts the payload, with its `input` mapping) as runs of this partition, by the
|
|
1351
|
+
* start path ({@link start}, run id `evt:<id>:<workflow>`), and has the control plane resume the
|
|
1352
|
+
* runs of this partition waiting on it (`ctx.waitForEvent`). Resolves how many runs it started or
|
|
1353
|
+
* resumed; a subscriber that throws is warned about and skipped. Unlike a control plane's
|
|
1354
|
+
* `publishEvent`, an event nobody received is not buffered (there is no `buffer` option), and
|
|
1355
|
+
* a subscriber's `debounce`/`batch` is not applied (it starts once per event, with a warning).
|
|
1356
|
+
*/
|
|
1357
|
+
publishEvent(name: string, payload: unknown, opts?: {
|
|
1358
|
+
id?: string;
|
|
1359
|
+
}): Promise<number>;
|
|
1246
1360
|
cancel(_runId: string): Promise<void>;
|
|
1247
1361
|
deleteRun(_runId: string): Promise<void>;
|
|
1248
1362
|
resume(_runId: string): Promise<void>;
|
|
@@ -1250,15 +1364,6 @@ declare class DurableStartClient {
|
|
|
1250
1364
|
timeoutMs?: number;
|
|
1251
1365
|
until?: 'settled' | 'terminal';
|
|
1252
1366
|
}): Promise<void>;
|
|
1253
|
-
signal(_token: string, _payload: unknown): Promise<void>;
|
|
1254
|
-
signalWithStart(_workflow: string, _input: unknown, _runId: string, _signal: {
|
|
1255
|
-
token: string;
|
|
1256
|
-
payload?: unknown;
|
|
1257
|
-
}, _opts?: StartOptions): Promise<void>;
|
|
1258
|
-
publishEvent(_name: string, _payload: unknown, _opts?: {
|
|
1259
|
-
id?: string;
|
|
1260
|
-
buffer?: boolean;
|
|
1261
|
-
}): Promise<void>;
|
|
1262
1367
|
}
|
|
1263
1368
|
|
|
1264
1369
|
/**
|
|
@@ -1296,6 +1401,19 @@ declare class ThinWorkflowRegistrar implements OnModuleInit {
|
|
|
1296
1401
|
/** In this role the store-less `DurableStartClient` facade the module binds under this token. */
|
|
1297
1402
|
starter: WorkflowStartClient);
|
|
1298
1403
|
onModuleInit(): void;
|
|
1404
|
+
/**
|
|
1405
|
+
* `@Entity` providers are refused on a tenant, at boot: an entity's state is a run on the store
|
|
1406
|
+
* and its `@On` handlers run inside the engine that owns that store (`EntityService` and
|
|
1407
|
+
* `ctx.callEntity`/`signalEntity` read and serialize it there). A tenant has no store and no
|
|
1408
|
+
* engine, so an entity declared here would never run. Declare it on the control plane.
|
|
1409
|
+
*/
|
|
1410
|
+
private assertNoEntities;
|
|
1411
|
+
/**
|
|
1412
|
+
* `@StepInterceptor()` providers wrap every step this tenant runs (each `ctx.step` its workers
|
|
1413
|
+
* execute), as `engine.use` does on an engine. A `@durable-worker` too old to take interceptors
|
|
1414
|
+
* says so instead of dropping them silently.
|
|
1415
|
+
*/
|
|
1416
|
+
private useInterceptors;
|
|
1299
1417
|
}
|
|
1300
1418
|
/**
|
|
1301
1419
|
* Discovers every `@Step` method and registers it as a step handler on the thin
|
|
@@ -1610,6 +1728,13 @@ declare class RunRequestResponder {
|
|
|
1610
1728
|
* failure never throws back into the transport (errors are captured into an error reply). */
|
|
1611
1729
|
start(): void;
|
|
1612
1730
|
private handle;
|
|
1731
|
+
/**
|
|
1732
|
+
* A tenant's `signalWithStart`: the run it names must be the requester's when it exists, and so
|
|
1733
|
+
* must a run already waiting on the token; anything else is refused `cross-tenant` before the
|
|
1734
|
+
* gateway is called. The run is started in the requester's namespace (a customer tenant it claims
|
|
1735
|
+
* is kept only when its verified token grants it, as for a start-run).
|
|
1736
|
+
*/
|
|
1737
|
+
private signalWithStart;
|
|
1613
1738
|
/** The run alone (`getRun`, else from its detail), or null when it does not exist. */
|
|
1614
1739
|
private runOf;
|
|
1615
1740
|
/** `call`'s result as an `ok` reply, or its rejection as an error reply. */
|
|
@@ -1766,6 +1891,35 @@ declare class ProxyRunGateway implements RunGateway {
|
|
|
1766
1891
|
* {@link RunGatewayError} with code {@link UNSUPPORTED_RUN_REQUEST}.
|
|
1767
1892
|
*/
|
|
1768
1893
|
private requestNewVerb;
|
|
1894
|
+
/**
|
|
1895
|
+
* Signal the run of this tenant's namespace waiting on `token` (`engine.signal`). Resolves null
|
|
1896
|
+
* when no run of this namespace waits on it: the control plane does NOT buffer a tenant's signal
|
|
1897
|
+
* for a wait opened later (another namespace's run could open it). A control plane that predates
|
|
1898
|
+
* the verb fails it with an {@link UNSUPPORTED_RUN_REQUEST} error.
|
|
1899
|
+
*/
|
|
1900
|
+
signal(token: string, payload: unknown, opts?: SignalOptions): Promise<RunResult | null>;
|
|
1901
|
+
/**
|
|
1902
|
+
* `engine.signalWithStart` for this tenant: the control plane starts `start` in this tenant's
|
|
1903
|
+
* namespace unless its run exists, then signals it (buffered until the run waits, when the token
|
|
1904
|
+
* names the run id). See the responder for the authorization rule.
|
|
1905
|
+
*/
|
|
1906
|
+
signalWithStart(start: Omit<StartRunMessage, 'tenant'> & {
|
|
1907
|
+
runId: string;
|
|
1908
|
+
}, signal: {
|
|
1909
|
+
token: string;
|
|
1910
|
+
payload?: unknown;
|
|
1911
|
+
}): Promise<{
|
|
1912
|
+
runId: string;
|
|
1913
|
+
signalled: boolean;
|
|
1914
|
+
}>;
|
|
1915
|
+
/**
|
|
1916
|
+
* Resume the runs of this tenant's namespace waiting on event `name` (`ctx.waitForEvent`).
|
|
1917
|
+
* Resolves how many it resumed. The tenant's own `onEvent` subscribers are started by the caller
|
|
1918
|
+
* (`DurableStartClient.publishEvent`), not here.
|
|
1919
|
+
*/
|
|
1920
|
+
publishEvent(name: string, payload: unknown, opts?: {
|
|
1921
|
+
id?: string;
|
|
1922
|
+
}): Promise<number>;
|
|
1769
1923
|
subscribe(runId: string, onEvent: (event: EngineEvent) => void): () => void;
|
|
1770
1924
|
}
|
|
1771
1925
|
|
|
@@ -1882,7 +2036,17 @@ declare class StoreRunGateway implements RunGateway {
|
|
|
1882
2036
|
listSchedules(query: ScheduleListQuery): Promise<ScheduleDescription[]>;
|
|
1883
2037
|
getSchedule(id: string): Promise<ScheduleDescription | null>;
|
|
1884
2038
|
scheduleAction(id: string, action: ScheduleAction): Promise<ScheduleDescription | RunResult>;
|
|
1885
|
-
signal(token: string, payload: unknown): Promise<RunResult | null>;
|
|
2039
|
+
signal(token: string, payload: unknown, opts?: SignalOptions): Promise<RunResult | null>;
|
|
2040
|
+
signalWithStartForTenant(start: StartRunMessage & {
|
|
2041
|
+
runId: string;
|
|
2042
|
+
}, namespace: string, clientTenant: Pick<StartOptions, 'tenantId' | 'tenantKind'>, signal: {
|
|
2043
|
+
token: string;
|
|
2044
|
+
payload?: unknown;
|
|
2045
|
+
}): Promise<{
|
|
2046
|
+
runId: string;
|
|
2047
|
+
signalled: boolean;
|
|
2048
|
+
}>;
|
|
2049
|
+
publishEventForTenant(name: string, payload: unknown, namespace: string): Promise<number>;
|
|
1886
2050
|
signalWaiter(token: string): Promise<string | null>;
|
|
1887
2051
|
/**
|
|
1888
2052
|
* Stream `runId`'s events. With tenancy, a run the caller may not see streams nothing; events of a
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WorkflowCtx, SearchAttributes, WorkflowClass, StandardSchemaV1, StepError, OnEventEntry, OnErrorInput, LifecycleEventOf, WorkflowLifecycleEvent, WorkflowRef, SingletonConfig, ConcurrencyConfig, SearchAttributesSchema, EventBatchConfig, TenantVerifier, VerifiedTenant, TenantTokenSource, StateStore, Transport, NamedTransport, ControlPlane, StalledRunInfo, ScheduledWorkflow, RetentionPolicy, QueueConfig, AdmissionBackend, WorkflowInputOf, StartOptions,
|
|
1
|
+
import { WorkflowCtx, SearchAttributes, WorkflowClass, StandardSchemaV1, StepError, OnEventEntry, OnErrorInput, LifecycleEventOf, WorkflowLifecycleEvent, WorkflowRef, SingletonConfig, ConcurrencyConfig, SearchAttributesSchema, EventBatchConfig, TenantVerifier, VerifiedTenant, TenantTokenSource, StateStore, Transport, NamedTransport, ControlPlane, StalledRunInfo, ScheduledWorkflow, RetentionPolicy, QueueConfig, AdmissionBackend, SignalOptions, RunResult, StartRunMessage, WorkflowInputOf, StartOptions, WorkflowStartClient, ScheduleAnnouncement, RunGateway, WorkflowEngine, EntityHandler, DurableTopology, RunDetailOptions, RunDetail, FanPageQuery, FanPage, WorkflowRun, RunQuery, RunListItem, RunFacetQuery, RunFacetRow, RunValueAxis, RunValueFacetOptions, RunValueFacetRow, RunWaiting, WorkflowLifecycleLinks, LifecycleKind, GroupHealth, ScheduleListQuery, ScheduleDescription, RepublishLifecycleTarget, RepublishLifecycleResult, ScheduleAction, EngineEvent, RunRequest, RunReply, TenantFilter as TenantFilter$1, StepInvocation, TenantEvent } from '@dudousxd/nestjs-durable-core';
|
|
2
2
|
export { AttributeFilter, DuplicateDurableCopyError, DynamicWorkflowCtx, EngineEvent, EventSubscription, InferSearchAttributes, LIFECYCLE_PENDING_TAG, LifecycleEventOf, LifecycleKind, OnErrorInput, OnEventEntry, RunDetail, RunGateway, RunListItem, RunQuery, RunSchedulesOptions, RunStatus, RunWaiting, ScheduledWorkflow, SearchAttributes, SearchAttributesSchema, StepCheckpoint, StepEvent, StepLogger, TenantTokenSource, TenantVerifier, VerifiedTenant, WorkflowCtx, WorkflowEngine, WorkflowHandler, WorkflowLifecycleEvent, WorkflowRun, hmacTenantVerifier, lifecycleRunId, lifecycleSourceOf, prevCronFireMs, readSearchAttributes, runCompletedEvent, runFailedEvent, runSchedules, scheduleRunIdAt, scheduledRunId, signTenantToken, triggeredRunsOf } from '@dudousxd/nestjs-durable-core';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { ConcurrencyOption, StartRunDeps, RunRedisWorkerOptions, RunningWorker, DurableWorkerRuntime } from '@dudousxd/durable-worker';
|
|
@@ -1219,6 +1219,42 @@ declare class DurableModule {
|
|
|
1219
1219
|
private static build;
|
|
1220
1220
|
}
|
|
1221
1221
|
|
|
1222
|
+
/**
|
|
1223
|
+
* The `@Workflow` options a tenant's start applies itself, before it publishes the start-run: the
|
|
1224
|
+
* ones that are functions of the input, which the control plane (knowing the workflow by name
|
|
1225
|
+
* alone) cannot evaluate. Declared by `ThinWorkflowRegistrar` for every `@Workflow` it discovers.
|
|
1226
|
+
*/
|
|
1227
|
+
interface TenantWorkflowStartPolicy {
|
|
1228
|
+
/** `@Workflow({ input, validateInput })`: rejects the start (throws) before anything is published. */
|
|
1229
|
+
validateInput?: ((input: unknown) => void | Promise<void>) | undefined;
|
|
1230
|
+
/** `@Workflow({ singleton })`: its key is evaluated here and carried on the start-run. */
|
|
1231
|
+
singleton?: SingletonConfig | undefined;
|
|
1232
|
+
/** `@Workflow({ concurrency })`: the default quota, evaluated here unless the start passes one. */
|
|
1233
|
+
concurrency?: ConcurrencyConfig | undefined;
|
|
1234
|
+
/** `@Workflow({ onEvent })` / `@OnDurableEvent`: started by this app's own `publishEvent`. */
|
|
1235
|
+
onEvent?: OnEventEntry[] | undefined;
|
|
1236
|
+
/** The workflow coalesces its event triggers (`debounce`/`batch`), which a tenant cannot apply. */
|
|
1237
|
+
coalesces?: boolean | undefined;
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* Where a tenant's `signal`/`signalWithStart`/`publishEvent` go: run requests to the control plane
|
|
1241
|
+
* (the module's `ProxyRunGateway` over `transport`).
|
|
1242
|
+
*/
|
|
1243
|
+
interface TenantRunRequests {
|
|
1244
|
+
signal(token: string, payload: unknown, opts?: SignalOptions): Promise<RunResult | null>;
|
|
1245
|
+
signalWithStart(start: Omit<StartRunMessage, 'tenant'> & {
|
|
1246
|
+
runId: string;
|
|
1247
|
+
}, signal: {
|
|
1248
|
+
token: string;
|
|
1249
|
+
payload?: unknown;
|
|
1250
|
+
}): Promise<{
|
|
1251
|
+
runId: string;
|
|
1252
|
+
signalled: boolean;
|
|
1253
|
+
}>;
|
|
1254
|
+
publishEvent(name: string, payload: unknown, opts?: {
|
|
1255
|
+
id?: string;
|
|
1256
|
+
}): Promise<number>;
|
|
1257
|
+
}
|
|
1222
1258
|
/**
|
|
1223
1259
|
* The **store-less `engine.start` facade** for a tenant worker. Provided under the `WorkflowEngine`
|
|
1224
1260
|
* DI token by {@link import('./durable.module').DurableModule} (`forRoot({ connection })`, no
|
|
@@ -1236,13 +1272,91 @@ declare class DurableStartClient {
|
|
|
1236
1272
|
private readonly deps?;
|
|
1237
1273
|
/** The context accessor, for the customer tenant a start claims (else the global slot). */
|
|
1238
1274
|
private readonly accessor?;
|
|
1275
|
+
/**
|
|
1276
|
+
* Sends `signal`/`signalWithStart`/`publishEvent` to the control plane as run requests (the
|
|
1277
|
+
* module's `ProxyRunGateway` over `transport`). Absent (no `transport`): they reject, naming it.
|
|
1278
|
+
*/
|
|
1279
|
+
private readonly requests?;
|
|
1239
1280
|
private readonly tenant;
|
|
1240
1281
|
private readonly tenantToken;
|
|
1282
|
+
private readonly policies;
|
|
1283
|
+
private readonly warnedCoalescing;
|
|
1241
1284
|
constructor(options: DurableModuleOptions, deps?: StartRunDeps | undefined,
|
|
1242
1285
|
/** The context accessor, for the customer tenant a start claims (else the global slot). */
|
|
1243
|
-
accessor?: ContextAccessor | undefined
|
|
1286
|
+
accessor?: ContextAccessor | undefined,
|
|
1287
|
+
/**
|
|
1288
|
+
* Sends `signal`/`signalWithStart`/`publishEvent` to the control plane as run requests (the
|
|
1289
|
+
* module's `ProxyRunGateway` over `transport`). Absent (no `transport`): they reject, naming it.
|
|
1290
|
+
*/
|
|
1291
|
+
requests?: (() => TenantRunRequests | undefined) | undefined);
|
|
1292
|
+
/**
|
|
1293
|
+
* Apply `policy` to every start of `workflow` from this process (see
|
|
1294
|
+
* {@link TenantWorkflowStartPolicy}). Called by `ThinWorkflowRegistrar` at boot.
|
|
1295
|
+
*/
|
|
1296
|
+
declareWorkflow(workflow: string, policy: TenantWorkflowStartPolicy): void;
|
|
1297
|
+
/**
|
|
1298
|
+
* The start-run fields a declared policy adds for `input`: it validates the input (throwing), and
|
|
1299
|
+
* evaluates the singleton key and the default quota. A per-start `concurrency` wins over the
|
|
1300
|
+
* workflow's.
|
|
1301
|
+
*/
|
|
1302
|
+
private applyPolicy;
|
|
1303
|
+
/** The wire `tenant`: the signed token when configured, else the partition. */
|
|
1304
|
+
private wireTenant;
|
|
1305
|
+
/**
|
|
1306
|
+
* The customer tenant a start claims: an explicit `tenantId` (`null` = none), else the request's
|
|
1307
|
+
* tenant when tenancy is on.
|
|
1308
|
+
*/
|
|
1309
|
+
private claimedTenant;
|
|
1244
1310
|
start<C extends WorkflowClass>(workflow: C, input: WorkflowInputOf<C>, runId?: string, opts?: StartOptions): Promise<RunResult>;
|
|
1245
1311
|
start(workflow: string, input: unknown, runId?: string, opts?: StartOptions): Promise<RunResult>;
|
|
1312
|
+
/**
|
|
1313
|
+
* The start-run a start of `name` sends (everything but the wire `tenant`): the start options the
|
|
1314
|
+
* control plane applies (version pin, priority, delayed start, quota), the singleton key and the
|
|
1315
|
+
* customer tenant this run claims. Applies the workflow's declared policy first, so a rejected
|
|
1316
|
+
* input throws before anything is published, as `engine.start` does.
|
|
1317
|
+
*/
|
|
1318
|
+
private startMessage;
|
|
1319
|
+
/** The control plane's run requests, or a clear error naming what is missing. */
|
|
1320
|
+
private runRequests;
|
|
1321
|
+
/**
|
|
1322
|
+
* Signal the run of this tenant's partition waiting on `token`, through the control plane.
|
|
1323
|
+
* Resolves the resumed run, or null when no run of this partition waits on it: unlike
|
|
1324
|
+
* `engine.signal` on a control plane, a tenant's signal is NOT buffered for a wait opened later
|
|
1325
|
+
* (another partition's run could open it). Use `signalWithStart` to signal a run that may not wait
|
|
1326
|
+
* yet. `opts.id` deduplicates like `engine.signal`.
|
|
1327
|
+
*/
|
|
1328
|
+
signal(token: string, payload: unknown, opts?: SignalOptions): Promise<RunResult | null>;
|
|
1329
|
+
/**
|
|
1330
|
+
* Ensure the run `runId` of `workflow` exists in this tenant's partition (started like
|
|
1331
|
+
* {@link start}, with the same options and policy), then signal it. The control plane buffers the
|
|
1332
|
+
* signal until the run waits on `signal.token` only when the token contains `runId` (a run-scoped
|
|
1333
|
+
* token, the pattern `signalWithStart` is for): a token that does not is delivered only to a run
|
|
1334
|
+
* of this partition already waiting on it, and refused otherwise.
|
|
1335
|
+
*/
|
|
1336
|
+
signalWithStart<C extends WorkflowClass>(workflow: C, input: WorkflowInputOf<C>, runId: string, signal: {
|
|
1337
|
+
token: string;
|
|
1338
|
+
payload?: unknown;
|
|
1339
|
+
}, opts?: StartOptions): Promise<{
|
|
1340
|
+
runId: string;
|
|
1341
|
+
}>;
|
|
1342
|
+
signalWithStart(workflow: string, input: unknown, runId: string, signal: {
|
|
1343
|
+
token: string;
|
|
1344
|
+
payload?: unknown;
|
|
1345
|
+
}, opts?: StartOptions): Promise<{
|
|
1346
|
+
runId: string;
|
|
1347
|
+
}>;
|
|
1348
|
+
/**
|
|
1349
|
+
* Publish event `name` from this tenant. Starts this app's own `onEvent` subscribers (each one
|
|
1350
|
+
* whose `where` accepts the payload, with its `input` mapping) as runs of this partition, by the
|
|
1351
|
+
* start path ({@link start}, run id `evt:<id>:<workflow>`), and has the control plane resume the
|
|
1352
|
+
* runs of this partition waiting on it (`ctx.waitForEvent`). Resolves how many runs it started or
|
|
1353
|
+
* resumed; a subscriber that throws is warned about and skipped. Unlike a control plane's
|
|
1354
|
+
* `publishEvent`, an event nobody received is not buffered (there is no `buffer` option), and
|
|
1355
|
+
* a subscriber's `debounce`/`batch` is not applied (it starts once per event, with a warning).
|
|
1356
|
+
*/
|
|
1357
|
+
publishEvent(name: string, payload: unknown, opts?: {
|
|
1358
|
+
id?: string;
|
|
1359
|
+
}): Promise<number>;
|
|
1246
1360
|
cancel(_runId: string): Promise<void>;
|
|
1247
1361
|
deleteRun(_runId: string): Promise<void>;
|
|
1248
1362
|
resume(_runId: string): Promise<void>;
|
|
@@ -1250,15 +1364,6 @@ declare class DurableStartClient {
|
|
|
1250
1364
|
timeoutMs?: number;
|
|
1251
1365
|
until?: 'settled' | 'terminal';
|
|
1252
1366
|
}): Promise<void>;
|
|
1253
|
-
signal(_token: string, _payload: unknown): Promise<void>;
|
|
1254
|
-
signalWithStart(_workflow: string, _input: unknown, _runId: string, _signal: {
|
|
1255
|
-
token: string;
|
|
1256
|
-
payload?: unknown;
|
|
1257
|
-
}, _opts?: StartOptions): Promise<void>;
|
|
1258
|
-
publishEvent(_name: string, _payload: unknown, _opts?: {
|
|
1259
|
-
id?: string;
|
|
1260
|
-
buffer?: boolean;
|
|
1261
|
-
}): Promise<void>;
|
|
1262
1367
|
}
|
|
1263
1368
|
|
|
1264
1369
|
/**
|
|
@@ -1296,6 +1401,19 @@ declare class ThinWorkflowRegistrar implements OnModuleInit {
|
|
|
1296
1401
|
/** In this role the store-less `DurableStartClient` facade the module binds under this token. */
|
|
1297
1402
|
starter: WorkflowStartClient);
|
|
1298
1403
|
onModuleInit(): void;
|
|
1404
|
+
/**
|
|
1405
|
+
* `@Entity` providers are refused on a tenant, at boot: an entity's state is a run on the store
|
|
1406
|
+
* and its `@On` handlers run inside the engine that owns that store (`EntityService` and
|
|
1407
|
+
* `ctx.callEntity`/`signalEntity` read and serialize it there). A tenant has no store and no
|
|
1408
|
+
* engine, so an entity declared here would never run. Declare it on the control plane.
|
|
1409
|
+
*/
|
|
1410
|
+
private assertNoEntities;
|
|
1411
|
+
/**
|
|
1412
|
+
* `@StepInterceptor()` providers wrap every step this tenant runs (each `ctx.step` its workers
|
|
1413
|
+
* execute), as `engine.use` does on an engine. A `@durable-worker` too old to take interceptors
|
|
1414
|
+
* says so instead of dropping them silently.
|
|
1415
|
+
*/
|
|
1416
|
+
private useInterceptors;
|
|
1299
1417
|
}
|
|
1300
1418
|
/**
|
|
1301
1419
|
* Discovers every `@Step` method and registers it as a step handler on the thin
|
|
@@ -1610,6 +1728,13 @@ declare class RunRequestResponder {
|
|
|
1610
1728
|
* failure never throws back into the transport (errors are captured into an error reply). */
|
|
1611
1729
|
start(): void;
|
|
1612
1730
|
private handle;
|
|
1731
|
+
/**
|
|
1732
|
+
* A tenant's `signalWithStart`: the run it names must be the requester's when it exists, and so
|
|
1733
|
+
* must a run already waiting on the token; anything else is refused `cross-tenant` before the
|
|
1734
|
+
* gateway is called. The run is started in the requester's namespace (a customer tenant it claims
|
|
1735
|
+
* is kept only when its verified token grants it, as for a start-run).
|
|
1736
|
+
*/
|
|
1737
|
+
private signalWithStart;
|
|
1613
1738
|
/** The run alone (`getRun`, else from its detail), or null when it does not exist. */
|
|
1614
1739
|
private runOf;
|
|
1615
1740
|
/** `call`'s result as an `ok` reply, or its rejection as an error reply. */
|
|
@@ -1766,6 +1891,35 @@ declare class ProxyRunGateway implements RunGateway {
|
|
|
1766
1891
|
* {@link RunGatewayError} with code {@link UNSUPPORTED_RUN_REQUEST}.
|
|
1767
1892
|
*/
|
|
1768
1893
|
private requestNewVerb;
|
|
1894
|
+
/**
|
|
1895
|
+
* Signal the run of this tenant's namespace waiting on `token` (`engine.signal`). Resolves null
|
|
1896
|
+
* when no run of this namespace waits on it: the control plane does NOT buffer a tenant's signal
|
|
1897
|
+
* for a wait opened later (another namespace's run could open it). A control plane that predates
|
|
1898
|
+
* the verb fails it with an {@link UNSUPPORTED_RUN_REQUEST} error.
|
|
1899
|
+
*/
|
|
1900
|
+
signal(token: string, payload: unknown, opts?: SignalOptions): Promise<RunResult | null>;
|
|
1901
|
+
/**
|
|
1902
|
+
* `engine.signalWithStart` for this tenant: the control plane starts `start` in this tenant's
|
|
1903
|
+
* namespace unless its run exists, then signals it (buffered until the run waits, when the token
|
|
1904
|
+
* names the run id). See the responder for the authorization rule.
|
|
1905
|
+
*/
|
|
1906
|
+
signalWithStart(start: Omit<StartRunMessage, 'tenant'> & {
|
|
1907
|
+
runId: string;
|
|
1908
|
+
}, signal: {
|
|
1909
|
+
token: string;
|
|
1910
|
+
payload?: unknown;
|
|
1911
|
+
}): Promise<{
|
|
1912
|
+
runId: string;
|
|
1913
|
+
signalled: boolean;
|
|
1914
|
+
}>;
|
|
1915
|
+
/**
|
|
1916
|
+
* Resume the runs of this tenant's namespace waiting on event `name` (`ctx.waitForEvent`).
|
|
1917
|
+
* Resolves how many it resumed. The tenant's own `onEvent` subscribers are started by the caller
|
|
1918
|
+
* (`DurableStartClient.publishEvent`), not here.
|
|
1919
|
+
*/
|
|
1920
|
+
publishEvent(name: string, payload: unknown, opts?: {
|
|
1921
|
+
id?: string;
|
|
1922
|
+
}): Promise<number>;
|
|
1769
1923
|
subscribe(runId: string, onEvent: (event: EngineEvent) => void): () => void;
|
|
1770
1924
|
}
|
|
1771
1925
|
|
|
@@ -1882,7 +2036,17 @@ declare class StoreRunGateway implements RunGateway {
|
|
|
1882
2036
|
listSchedules(query: ScheduleListQuery): Promise<ScheduleDescription[]>;
|
|
1883
2037
|
getSchedule(id: string): Promise<ScheduleDescription | null>;
|
|
1884
2038
|
scheduleAction(id: string, action: ScheduleAction): Promise<ScheduleDescription | RunResult>;
|
|
1885
|
-
signal(token: string, payload: unknown): Promise<RunResult | null>;
|
|
2039
|
+
signal(token: string, payload: unknown, opts?: SignalOptions): Promise<RunResult | null>;
|
|
2040
|
+
signalWithStartForTenant(start: StartRunMessage & {
|
|
2041
|
+
runId: string;
|
|
2042
|
+
}, namespace: string, clientTenant: Pick<StartOptions, 'tenantId' | 'tenantKind'>, signal: {
|
|
2043
|
+
token: string;
|
|
2044
|
+
payload?: unknown;
|
|
2045
|
+
}): Promise<{
|
|
2046
|
+
runId: string;
|
|
2047
|
+
signalled: boolean;
|
|
2048
|
+
}>;
|
|
2049
|
+
publishEventForTenant(name: string, payload: unknown, namespace: string): Promise<number>;
|
|
1886
2050
|
signalWaiter(token: string): Promise<string | null>;
|
|
1887
2051
|
/**
|
|
1888
2052
|
* Stream `runId`'s events. With tenancy, a run the caller may not see streams nothing; events of a
|