@dudousxd/nestjs-durable 0.27.0 → 0.29.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.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { StepError, WorkflowRef, SingletonConfig, StateStore, Transport, NamedTransport, ControlPlane, ScheduledWorkflow, RetentionPolicy, QueueConfig, AdmissionBackend, WorkflowClass, WorkflowInputOf, StartOptions, RunResult, RunGateway, WorkflowEngine, EntityHandler, RunDetail, RunQuery, WorkflowRun, EngineEvent, RunRequest, RunReply, StepInvocation, TenantEvent } from '@dudousxd/nestjs-durable-core';
1
+ import { StepError, WorkflowRef, SingletonConfig, StateStore, Transport, NamedTransport, ControlPlane, ScheduledWorkflow, RetentionPolicy, QueueConfig, AdmissionBackend, WorkflowClass, WorkflowInputOf, StartOptions, RunResult, RunGateway, WorkflowEngine, EntityHandler, RunDetail, RunQuery, WorkflowRun, GroupHealth, EngineEvent, RunRequest, RunReply, StepInvocation, TenantEvent } from '@dudousxd/nestjs-durable-core';
2
2
  import { z } from 'zod';
3
3
  import { ConcurrencyOption, StartRunDeps, RunRedisWorkerOptions, RunningWorker, DurableWorkerRuntime } from '@dudousxd/durable-worker';
4
4
  import { DynamicModule, InjectionToken, OnModuleInit, OnApplicationBootstrap, OnApplicationShutdown, Provider } from '@nestjs/common';
@@ -106,7 +106,7 @@ interface WorkflowOptions {
106
106
  * Start a fresh run of this workflow whenever any of these events is published via
107
107
  * `publishEvent(name, payload)` — the payload becomes the run's input. e.g.
108
108
  * `onEvent: ['user.registered', 'user.invited']`. The same subscription can also be declared with
109
- * the `@OnEvent(...)` class decorator; the two are merged.
109
+ * the `@OnDurableEvent(...)` class decorator; the two are merged.
110
110
  */
111
111
  onEvent?: string[];
112
112
  /**
@@ -234,11 +234,16 @@ declare const ON_EVENT_METADATA: unique symbol;
234
234
  /**
235
235
  * Subscribe a `@Workflow` class to one or more events: when any of them is published via
236
236
  * `publishEvent(name, payload)`, a fresh run of the workflow starts with the payload as input.
237
- * Equivalent to `@Workflow({ onEvent })` — use whichever reads better; multiple `@OnEvent(...)`
238
- * decorators and the option are all merged.
237
+ * Equivalent to `@Workflow({ onEvent })` — use whichever reads better; multiple
238
+ * `@OnDurableEvent(...)` decorators and the option are all merged.
239
+ *
240
+ * Named "durable" on purpose: `@nestjs/event-emitter` exports an `@OnEvent` decorator, and in an
241
+ * app using both libs an auto-import picking the wrong one fails silently in either direction.
239
242
  */
240
- declare function OnEvent(...events: string[]): ClassDecorator;
241
- /** All events a workflow class subscribes to — the union of `@Workflow({ onEvent })` and `@OnEvent`. */
243
+ declare function OnDurableEvent(...events: string[]): ClassDecorator;
244
+ /** @deprecated Renamed to `OnDurableEvent` — this alias clashes with `@nestjs/event-emitter`'s `@OnEvent` and will be removed in the next minor. */
245
+ declare const OnEvent: typeof OnDurableEvent;
246
+ /** All events a workflow class subscribes to — the union of `@Workflow({ onEvent })` and `@OnDurableEvent`. */
242
247
  declare function getOnEvents(meta: WorkflowMeta, target: object): string[];
243
248
 
244
249
  /**
@@ -712,6 +717,8 @@ declare class ProxyRunGateway implements RunGateway {
712
717
  private request;
713
718
  getRunDetail(runId: string): Promise<RunDetail | null>;
714
719
  listRuns(query: RunQuery): Promise<WorkflowRun[]>;
720
+ /** Round-trips to the operator, which scopes the result to this tenant's own `@<tenant>` groups. */
721
+ workerHealth(): Promise<GroupHealth[]>;
715
722
  cancel(runId: string, opts?: {
716
723
  compensate?: boolean;
717
724
  }): Promise<RunResult | null>;
@@ -796,6 +803,9 @@ declare class StoreRunGateway implements RunGateway {
796
803
  constructor(store: StateStore, engine: WorkflowEngine);
797
804
  getRunDetail(runId: string): Promise<RunDetail | null>;
798
805
  listRuns(query: RunQuery): Promise<WorkflowRun[]>;
806
+ /** Every group the engine knows about — unscoped. A tenant proxy's request is scoped by the
807
+ * `RunRequestResponder` (to the requester's `@<tenant>` groups); the operator's own UI sees all. */
808
+ workerHealth(): Promise<GroupHealth[]>;
799
809
  cancel(runId: string, opts?: {
800
810
  compensate?: boolean;
801
811
  }): Promise<RunResult | null>;
@@ -901,7 +911,7 @@ declare class WorkflowService {
901
911
  }>;
902
912
  /**
903
913
  * Publish a named event. Resumes runs waiting on it via `ctx.waitForEvent(name, { match })` and
904
- * starts a fresh run of every workflow subscribed via `@Workflow({ onEvent })` / `@OnEvent` (the
914
+ * starts a fresh run of every workflow subscribed via `@Workflow({ onEvent })` / `@OnDurableEvent` (the
905
915
  * payload becomes its input). Pass `opts.id` to dedupe redeliveries. Returns how many runs it
906
916
  * touched (resumed + started).
907
917
  */
@@ -910,4 +920,4 @@ declare class WorkflowService {
910
920
  }): Promise<number>;
911
921
  }
912
922
 
913
- export { CONTEXT_ACCESSOR, type ContextAccessor, type ContextStore, DEAD_LETTER_METADATA, DURABLE_STEP_METADATA, DURABLE_WORKER_RUNNERS, DeadLetter, DurableModule, type DurableModuleAsyncOptions, type DurableModuleOptions, type DurableRetentionOptions, DurableStartClient, DurableStep, type DurableStepInterceptor, type DurableStepMeta, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, IN_APP_RUN_REDIS_WORKER, IN_APP_WORKER_BINDING, IN_APP_WORKER_RUNNERS, IN_APP_WORKER_RUNTIME, type InAppWorkerBinding, InAppWorkerBootstrap, ON_EVENT_METADATA, On, OnEvent, ProxyRunGateway, RUN_GATEWAY, RUN_REDIS_WORKER, type RunLookupStore, type RunRedisWorkerFn, RunRequestResponder, type RunRequestTransport, STEP_INTERCEPTOR_METADATA, Step, StepInterceptor, type StepOptions, StoreRunGateway, TenantEventRepublisher, ThinStepRegistrar, ThinWorkerBootstrap, ThinWorkflowRegistrar, type UserRef, WORKFLOW_METADATA, Workflow, type WorkflowMeta, type WorkflowOptions, WorkflowService, entityConfigFor, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, thinWorkerProviders, unavailableRunGateway };
923
+ export { CONTEXT_ACCESSOR, type ContextAccessor, type ContextStore, DEAD_LETTER_METADATA, DURABLE_STEP_METADATA, DURABLE_WORKER_RUNNERS, DeadLetter, DurableModule, type DurableModuleAsyncOptions, type DurableModuleOptions, type DurableRetentionOptions, DurableStartClient, DurableStep, type DurableStepInterceptor, type DurableStepMeta, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, IN_APP_RUN_REDIS_WORKER, IN_APP_WORKER_BINDING, IN_APP_WORKER_RUNNERS, IN_APP_WORKER_RUNTIME, type InAppWorkerBinding, InAppWorkerBootstrap, ON_EVENT_METADATA, On, OnDurableEvent, OnEvent, ProxyRunGateway, RUN_GATEWAY, RUN_REDIS_WORKER, type RunLookupStore, type RunRedisWorkerFn, RunRequestResponder, type RunRequestTransport, STEP_INTERCEPTOR_METADATA, Step, StepInterceptor, type StepOptions, StoreRunGateway, TenantEventRepublisher, ThinStepRegistrar, ThinWorkerBootstrap, ThinWorkflowRegistrar, type UserRef, WORKFLOW_METADATA, Workflow, type WorkflowMeta, type WorkflowOptions, WorkflowService, entityConfigFor, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, thinWorkerProviders, unavailableRunGateway };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { StepError, WorkflowRef, SingletonConfig, StateStore, Transport, NamedTransport, ControlPlane, ScheduledWorkflow, RetentionPolicy, QueueConfig, AdmissionBackend, WorkflowClass, WorkflowInputOf, StartOptions, RunResult, RunGateway, WorkflowEngine, EntityHandler, RunDetail, RunQuery, WorkflowRun, EngineEvent, RunRequest, RunReply, StepInvocation, TenantEvent } from '@dudousxd/nestjs-durable-core';
1
+ import { StepError, WorkflowRef, SingletonConfig, StateStore, Transport, NamedTransport, ControlPlane, ScheduledWorkflow, RetentionPolicy, QueueConfig, AdmissionBackend, WorkflowClass, WorkflowInputOf, StartOptions, RunResult, RunGateway, WorkflowEngine, EntityHandler, RunDetail, RunQuery, WorkflowRun, GroupHealth, EngineEvent, RunRequest, RunReply, StepInvocation, TenantEvent } from '@dudousxd/nestjs-durable-core';
2
2
  import { z } from 'zod';
3
3
  import { ConcurrencyOption, StartRunDeps, RunRedisWorkerOptions, RunningWorker, DurableWorkerRuntime } from '@dudousxd/durable-worker';
4
4
  import { DynamicModule, InjectionToken, OnModuleInit, OnApplicationBootstrap, OnApplicationShutdown, Provider } from '@nestjs/common';
@@ -106,7 +106,7 @@ interface WorkflowOptions {
106
106
  * Start a fresh run of this workflow whenever any of these events is published via
107
107
  * `publishEvent(name, payload)` — the payload becomes the run's input. e.g.
108
108
  * `onEvent: ['user.registered', 'user.invited']`. The same subscription can also be declared with
109
- * the `@OnEvent(...)` class decorator; the two are merged.
109
+ * the `@OnDurableEvent(...)` class decorator; the two are merged.
110
110
  */
111
111
  onEvent?: string[];
112
112
  /**
@@ -234,11 +234,16 @@ declare const ON_EVENT_METADATA: unique symbol;
234
234
  /**
235
235
  * Subscribe a `@Workflow` class to one or more events: when any of them is published via
236
236
  * `publishEvent(name, payload)`, a fresh run of the workflow starts with the payload as input.
237
- * Equivalent to `@Workflow({ onEvent })` — use whichever reads better; multiple `@OnEvent(...)`
238
- * decorators and the option are all merged.
237
+ * Equivalent to `@Workflow({ onEvent })` — use whichever reads better; multiple
238
+ * `@OnDurableEvent(...)` decorators and the option are all merged.
239
+ *
240
+ * Named "durable" on purpose: `@nestjs/event-emitter` exports an `@OnEvent` decorator, and in an
241
+ * app using both libs an auto-import picking the wrong one fails silently in either direction.
239
242
  */
240
- declare function OnEvent(...events: string[]): ClassDecorator;
241
- /** All events a workflow class subscribes to — the union of `@Workflow({ onEvent })` and `@OnEvent`. */
243
+ declare function OnDurableEvent(...events: string[]): ClassDecorator;
244
+ /** @deprecated Renamed to `OnDurableEvent` — this alias clashes with `@nestjs/event-emitter`'s `@OnEvent` and will be removed in the next minor. */
245
+ declare const OnEvent: typeof OnDurableEvent;
246
+ /** All events a workflow class subscribes to — the union of `@Workflow({ onEvent })` and `@OnDurableEvent`. */
242
247
  declare function getOnEvents(meta: WorkflowMeta, target: object): string[];
243
248
 
244
249
  /**
@@ -712,6 +717,8 @@ declare class ProxyRunGateway implements RunGateway {
712
717
  private request;
713
718
  getRunDetail(runId: string): Promise<RunDetail | null>;
714
719
  listRuns(query: RunQuery): Promise<WorkflowRun[]>;
720
+ /** Round-trips to the operator, which scopes the result to this tenant's own `@<tenant>` groups. */
721
+ workerHealth(): Promise<GroupHealth[]>;
715
722
  cancel(runId: string, opts?: {
716
723
  compensate?: boolean;
717
724
  }): Promise<RunResult | null>;
@@ -796,6 +803,9 @@ declare class StoreRunGateway implements RunGateway {
796
803
  constructor(store: StateStore, engine: WorkflowEngine);
797
804
  getRunDetail(runId: string): Promise<RunDetail | null>;
798
805
  listRuns(query: RunQuery): Promise<WorkflowRun[]>;
806
+ /** Every group the engine knows about — unscoped. A tenant proxy's request is scoped by the
807
+ * `RunRequestResponder` (to the requester's `@<tenant>` groups); the operator's own UI sees all. */
808
+ workerHealth(): Promise<GroupHealth[]>;
799
809
  cancel(runId: string, opts?: {
800
810
  compensate?: boolean;
801
811
  }): Promise<RunResult | null>;
@@ -901,7 +911,7 @@ declare class WorkflowService {
901
911
  }>;
902
912
  /**
903
913
  * Publish a named event. Resumes runs waiting on it via `ctx.waitForEvent(name, { match })` and
904
- * starts a fresh run of every workflow subscribed via `@Workflow({ onEvent })` / `@OnEvent` (the
914
+ * starts a fresh run of every workflow subscribed via `@Workflow({ onEvent })` / `@OnDurableEvent` (the
905
915
  * payload becomes its input). Pass `opts.id` to dedupe redeliveries. Returns how many runs it
906
916
  * touched (resumed + started).
907
917
  */
@@ -910,4 +920,4 @@ declare class WorkflowService {
910
920
  }): Promise<number>;
911
921
  }
912
922
 
913
- export { CONTEXT_ACCESSOR, type ContextAccessor, type ContextStore, DEAD_LETTER_METADATA, DURABLE_STEP_METADATA, DURABLE_WORKER_RUNNERS, DeadLetter, DurableModule, type DurableModuleAsyncOptions, type DurableModuleOptions, type DurableRetentionOptions, DurableStartClient, DurableStep, type DurableStepInterceptor, type DurableStepMeta, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, IN_APP_RUN_REDIS_WORKER, IN_APP_WORKER_BINDING, IN_APP_WORKER_RUNNERS, IN_APP_WORKER_RUNTIME, type InAppWorkerBinding, InAppWorkerBootstrap, ON_EVENT_METADATA, On, OnEvent, ProxyRunGateway, RUN_GATEWAY, RUN_REDIS_WORKER, type RunLookupStore, type RunRedisWorkerFn, RunRequestResponder, type RunRequestTransport, STEP_INTERCEPTOR_METADATA, Step, StepInterceptor, type StepOptions, StoreRunGateway, TenantEventRepublisher, ThinStepRegistrar, ThinWorkerBootstrap, ThinWorkflowRegistrar, type UserRef, WORKFLOW_METADATA, Workflow, type WorkflowMeta, type WorkflowOptions, WorkflowService, entityConfigFor, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, thinWorkerProviders, unavailableRunGateway };
923
+ export { CONTEXT_ACCESSOR, type ContextAccessor, type ContextStore, DEAD_LETTER_METADATA, DURABLE_STEP_METADATA, DURABLE_WORKER_RUNNERS, DeadLetter, DurableModule, type DurableModuleAsyncOptions, type DurableModuleOptions, type DurableRetentionOptions, DurableStartClient, DurableStep, type DurableStepInterceptor, type DurableStepMeta, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, IN_APP_RUN_REDIS_WORKER, IN_APP_WORKER_BINDING, IN_APP_WORKER_RUNNERS, IN_APP_WORKER_RUNTIME, type InAppWorkerBinding, InAppWorkerBootstrap, ON_EVENT_METADATA, On, OnDurableEvent, OnEvent, ProxyRunGateway, RUN_GATEWAY, RUN_REDIS_WORKER, type RunLookupStore, type RunRedisWorkerFn, RunRequestResponder, type RunRequestTransport, STEP_INTERCEPTOR_METADATA, Step, StepInterceptor, type StepOptions, StoreRunGateway, TenantEventRepublisher, ThinStepRegistrar, ThinWorkerBootstrap, ThinWorkflowRegistrar, type UserRef, WORKFLOW_METADATA, Workflow, type WorkflowMeta, type WorkflowOptions, WorkflowService, entityConfigFor, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, thinWorkerProviders, unavailableRunGateway };
package/dist/index.js CHANGED
@@ -91,7 +91,7 @@ function isDeadLetterHandler(method) {
91
91
  }
92
92
  __name(isDeadLetterHandler, "isDeadLetterHandler");
93
93
  var ON_EVENT_METADATA = Symbol("nestjs-durable:on-event");
94
- function OnEvent(...events) {
94
+ function OnDurableEvent(...events) {
95
95
  return (target) => {
96
96
  const existing = Reflect.getMetadata(ON_EVENT_METADATA, target) ?? [];
97
97
  Reflect.defineMetadata(ON_EVENT_METADATA, [
@@ -100,7 +100,8 @@ function OnEvent(...events) {
100
100
  ], target);
101
101
  };
102
102
  }
103
- __name(OnEvent, "OnEvent");
103
+ __name(OnDurableEvent, "OnDurableEvent");
104
+ var OnEvent = OnDurableEvent;
104
105
  function getOnEvents(meta, target) {
105
106
  const fromDecorator = Reflect.getMetadata(ON_EVENT_METADATA, target) ?? [];
106
107
  return [
@@ -429,6 +430,9 @@ function unavailableRunGateway() {
429
430
  listRuns(_query) {
430
431
  return tenantGatewayUnavailable("listRuns");
431
432
  },
433
+ workerHealth() {
434
+ return tenantGatewayUnavailable("workerHealth");
435
+ },
432
436
  cancel(_runId) {
433
437
  return tenantGatewayUnavailable("cancel");
434
438
  },
@@ -826,6 +830,12 @@ var ProxyRunGateway = class {
826
830
  query
827
831
  });
828
832
  }
833
+ /** Round-trips to the operator, which scopes the result to this tenant's own `@<tenant>` groups. */
834
+ workerHealth() {
835
+ return this.request({
836
+ kind: "workerHealth"
837
+ });
838
+ }
829
839
  cancel(runId, opts) {
830
840
  return this.request(opts === void 0 ? {
831
841
  kind: "cancel",
@@ -1022,6 +1032,17 @@ var RunRequestResponder = class {
1022
1032
  }
1023
1033
  };
1024
1034
  }
1035
+ if (body.kind === "workerHealth") {
1036
+ const all = await this.gateway.workerHealth();
1037
+ const data = all.filter((h) => h.group.endsWith(`@${msg.tenant}`));
1038
+ return {
1039
+ requestId: msg.requestId,
1040
+ result: {
1041
+ ok: true,
1042
+ data
1043
+ }
1044
+ };
1045
+ }
1025
1046
  const detail = await this.gateway.getRunDetail(body.runId);
1026
1047
  if (detail && detail.run.namespace !== msg.tenant) {
1027
1048
  return {
@@ -1125,6 +1146,11 @@ var StoreRunGateway = class {
1125
1146
  listRuns(query) {
1126
1147
  return this.store.listRuns(query);
1127
1148
  }
1149
+ /** Every group the engine knows about — unscoped. A tenant proxy's request is scoped by the
1150
+ * `RunRequestResponder` (to the requester's `@<tenant>` groups); the operator's own UI sees all. */
1151
+ workerHealth() {
1152
+ return this.engine.workerHealth();
1153
+ }
1128
1154
  cancel(runId, opts) {
1129
1155
  return this.engine.cancel(runId, opts);
1130
1156
  }
@@ -1274,7 +1300,7 @@ var CONTEXT_ACCESSOR = Symbol.for("@dudousxd/nestjs-context:accessor");
1274
1300
  var RUN_GATEWAY = Symbol.for("nestjs-durable:run-gateway");
1275
1301
 
1276
1302
  // src/workflow.registrar.ts
1277
- import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL6, RemoteWorkflowExecutor, STATE_STORE_CANONICAL as STATE_STORE_CANONICAL3, WorkflowEngine as WorkflowEngine4, parseDuration as parseDuration2, sanitizeQueueToken, tenantGroup, workflowName as workflowName2 } from "@dudousxd/nestjs-durable-core";
1303
+ import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL6, RemoteWorkflowExecutor, STATE_STORE_CANONICAL as STATE_STORE_CANONICAL3, WorkflowEngine as WorkflowEngine4, bindWorkflowClass, parseDuration as parseDuration2, sanitizeQueueToken, tenantGroup, workflowName as workflowName2 } from "@dudousxd/nestjs-durable-core";
1278
1304
  import { Inject as Inject7, Injectable as Injectable10 } from "@nestjs/common";
1279
1305
  import { DiscoveryService as DiscoveryService4, MetadataScanner as MetadataScanner4 } from "@nestjs/core";
1280
1306
 
@@ -1424,6 +1450,10 @@ var WorkflowRegistrar = class {
1424
1450
  executor: new RemoteWorkflowExecutor(this.inAppWorker.transport, meta.name, this.inAppWorker.partition)
1425
1451
  } : {}
1426
1452
  });
1453
+ bindWorkflowClass(workflowCtor, {
1454
+ start: /* @__PURE__ */ __name((name, input, runId, opts) => this.engine.start(name, input, runId, opts), "start"),
1455
+ waitForRun: /* @__PURE__ */ __name((runId, opts) => this.engine.waitForRun(runId, opts), "waitForRun")
1456
+ });
1427
1457
  const inline = this.findDeadLetterHandler(workflow);
1428
1458
  if (inline && meta.deadLetterWorkflow) {
1429
1459
  throw new Error(`@Workflow ${meta.name} declares both an inline @DeadLetter() method and a deadLetterWorkflow option. Use one: the inline handler, or the reference.`);
@@ -1540,7 +1570,7 @@ var WorkflowService = class {
1540
1570
  }
1541
1571
  /**
1542
1572
  * Publish a named event. Resumes runs waiting on it via `ctx.waitForEvent(name, { match })` and
1543
- * starts a fresh run of every workflow subscribed via `@Workflow({ onEvent })` / `@OnEvent` (the
1573
+ * starts a fresh run of every workflow subscribed via `@Workflow({ onEvent })` / `@OnDurableEvent` (the
1544
1574
  * payload becomes its input). Pass `opts.id` to dedupe redeliveries. Returns how many runs it
1545
1575
  * touched (resumed + started).
1546
1576
  */
@@ -1874,6 +1904,7 @@ export {
1874
1904
  InAppWorkerBootstrap,
1875
1905
  ON_EVENT_METADATA,
1876
1906
  On,
1907
+ OnDurableEvent,
1877
1908
  OnEvent,
1878
1909
  ProxyRunGateway,
1879
1910
  RUN_GATEWAY,