@dudousxd/nestjs-durable 0.63.0 → 0.64.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 { 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, RunResult, WorkflowStartClient, 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, SignalOptions } from '@dudousxd/nestjs-durable-core';
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, RunResult, 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, SignalOptions } 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';
@@ -970,6 +970,21 @@ interface DurableModuleSharedOptions {
970
970
  * deterministic and advancing a schedule is a compare-and-set. Operator only.
971
971
  */
972
972
  persistedSchedules?: boolean;
973
+ /**
974
+ * Adopt the `schedules` that TENANT apps declare and fire them here (a tenant has no store to fire
975
+ * them from). Each tenant worker announces its app's schedules on its descriptor; every `syncMs`
976
+ * (default 15 s) a driving instance turns them into persisted schedules (id
977
+ * `app:<partition>:<key>`, tagged `schedule:announced`), applies a changed definition, and pauses
978
+ * one that no live worker of its app has announced for `graceMs` (default 10 minutes). It then
979
+ * fires them on every tick, through the tenant start path: with no live worker of the app, a run
980
+ * waits `blocked` (`no_live_worker`) for one. On by default for a driving instance with a store
981
+ * that persists schedules and a transport that reads worker descriptors (BullMQ); `false` turns it
982
+ * off. Operator only.
983
+ */
984
+ announcedSchedules?: boolean | {
985
+ syncMs?: number;
986
+ graceMs?: number;
987
+ };
973
988
  /**
974
989
  * Hard-prune terminal run history on an interval so `durable_workflow_runs` (and its child tables)
975
990
  * stays bounded — without it, completed/failed/cancelled runs accumulate forever and the timer
@@ -1184,6 +1199,11 @@ interface DurableModuleAsyncOptions {
1184
1199
  useFactory: (...args: never[]) => DurableModuleOptions | Promise<DurableModuleOptions>;
1185
1200
  inject?: InjectionToken[];
1186
1201
  }
1202
+ /** The `verifyTenant` / `tenantToken` options, resolved to the plain functions the wire layer calls. */
1203
+ interface ResolvedTenantAuth {
1204
+ verifyTenant: TenantVerifier | undefined;
1205
+ tenantToken: TenantTokenSource | undefined;
1206
+ }
1187
1207
  /**
1188
1208
  * `forRoot` / `forRootAsync` first refuse to boot when two different installs of
1189
1209
  * `@dudousxd/nestjs-durable-core` are loaded in this process (a pnpm peer-variant split): each copy
@@ -1306,11 +1326,21 @@ declare class ThinWorkerBootstrap implements OnApplicationBootstrap, OnApplicati
1306
1326
  private readonly options;
1307
1327
  private readonly runRedisWorker;
1308
1328
  private readonly runnersSink;
1329
+ private readonly auth;
1309
1330
  private readonly runners;
1310
- constructor(runtime: DurableWorkerRuntime | null, options: DurableModuleOptions, runRedisWorker: RunRedisWorkerFn, runnersSink: RunningWorker[]);
1331
+ constructor(runtime: DurableWorkerRuntime | null, options: DurableModuleOptions, runRedisWorker: RunRedisWorkerFn, runnersSink: RunningWorker[], auth: ResolvedTenantAuth);
1311
1332
  onApplicationBootstrap(): Promise<void>;
1312
1333
  onApplicationShutdown(): Promise<void>;
1313
1334
  }
1335
+ /**
1336
+ * The tenant's `schedules`, as its worker announces them: under the wire tenant its starts carry (the
1337
+ * signed token when the app has one, else the partition), one {@link AnnouncedSchedule} per schedule.
1338
+ * A schedule's `namespace` is dropped (a tenant's runs always belong to its own namespace), and
1339
+ * `backfill` becomes the control plane's `catchup: 'latest'` (at most one late window).
1340
+ */
1341
+ declare function tenantScheduleAnnouncement(options: DurableModuleOptions, tenantToken: TenantTokenSource | undefined): Promise<{
1342
+ schedules?: ScheduleAnnouncement;
1343
+ }>;
1314
1344
  /**
1315
1345
  * The thin-worker slice of {@link import('./durable.module').DurableModule}'s unified provider set —
1316
1346
  * active for the pure thin-worker role (`connection` set, `store` unset): registers discovered
@@ -1900,6 +1930,11 @@ declare class TenantEventRepublisher {
1900
1930
  * byte-identical with nestjs-context's export.
1901
1931
  */
1902
1932
  declare const CONTEXT_ACCESSOR: unique symbol;
1933
+ /**
1934
+ * Internal: the module's resolved tenant auth (`verifyTenant` and `tenantToken`, resolved through
1935
+ * DI). Shared by the module and the thin-worker providers, which announce under the tenant token.
1936
+ */
1937
+ declare const TENANT_AUTH: unique symbol;
1903
1938
  /**
1904
1939
  * @deprecated Inject the `RunGateway` class, which is its own DI token:
1905
1940
  * `constructor(private readonly gateway: RunGateway)`. Kept because published
@@ -1986,4 +2021,4 @@ declare class WorkflowService {
1986
2021
  republishLifecycle(target: RepublishLifecycleTarget): Promise<RepublishLifecycleResult>;
1987
2022
  }
1988
2023
 
1989
- export { BAD_RUN_REQUEST, CONTEXT_ACCESSOR, type ContextAccessor, type ContextStore, type ContractClass, type ControlPlaneDurableOptions, DEAD_LETTER_METADATA, DURABLE_STEP_METADATA, DURABLE_WORKER_RUNNERS, DURABLE_WORKER_RUNTIME, DeadLetter, type DtoClass, DurableModule, type DurableModuleAsyncOptions, type DurableModuleOptions, type DurableModuleSharedOptions, type DurableRetentionOptions, DurableStartClient, type DurableStepInterceptor, type DurableStepMeta, type DurableTopologyName, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, type ErrorClassWithCode, FederatedAppGateway, type FederatedAppGatewayOptions, IN_APP_RUN_REDIS_WORKER, IN_APP_WORKER_BINDING, IN_APP_WORKER_RUNNERS, IN_APP_WORKER_RUNTIME, type InAppWorkerBinding, InAppWorkerBootstrap, type IoSchema, type LazyContract, ON_ERROR_METADATA, ON_EVENT_BATCH_METADATA, ON_EVENT_METADATA, On, OnDurableEvent, OnError, type OnErrorMethod, OnWorkflowCompleted, OnWorkflowFailed, type OnWorkflowFailedOptions, type OnWorkflowSettledOptions, ProxyRunGateway, RUN_GATEWAY, RUN_REDIS_WORKER, RunGatewayError, type RunGatewayErrorCode, type RunLookupStore, type RunRedisWorkerFn, RunRequestResponder, type RunRequestResponderOptions, type RunRequestTransport, STEP_INTERCEPTOR_METADATA, type StandaloneDurableOptions, Step, StepInterceptor, type StepOptions, StoreRunGateway, type SubscriberBatch, type SubscriberDebounce, type SubscriberDecorator, TENANT_REPUBLISH_MAX_LIMIT, type TenantCredentialsContract, type TenantDurableOptions, TenantEventRepublisher, type TenantFilter, type TenantLevel, type TenantRef, type TenantTokenOption, type TenantVerifierContract, type TenantVerifierInput, type TenantVerifierOption, ThinStepRegistrar, ThinWorkerBootstrap, ThinWorkflowRegistrar, UNSUPPORTED_RUN_REQUEST, type UserRef, WORKFLOW_METADATA, Workflow, type WorkflowAttributesOf, type WorkflowMeta, type WorkflowOptions, WorkflowService, attributesOf, entityConfigFor, eventBatchOf, federatedAppGateway, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, onErrorCodesOf, thinWorkerProviders, unavailableRunGateway };
2024
+ export { BAD_RUN_REQUEST, CONTEXT_ACCESSOR, type ContextAccessor, type ContextStore, type ContractClass, type ControlPlaneDurableOptions, DEAD_LETTER_METADATA, DURABLE_STEP_METADATA, DURABLE_WORKER_RUNNERS, DURABLE_WORKER_RUNTIME, DeadLetter, type DtoClass, DurableModule, type DurableModuleAsyncOptions, type DurableModuleOptions, type DurableModuleSharedOptions, type DurableRetentionOptions, DurableStartClient, type DurableStepInterceptor, type DurableStepMeta, type DurableTopologyName, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, type ErrorClassWithCode, FederatedAppGateway, type FederatedAppGatewayOptions, IN_APP_RUN_REDIS_WORKER, IN_APP_WORKER_BINDING, IN_APP_WORKER_RUNNERS, IN_APP_WORKER_RUNTIME, type InAppWorkerBinding, InAppWorkerBootstrap, type IoSchema, type LazyContract, ON_ERROR_METADATA, ON_EVENT_BATCH_METADATA, ON_EVENT_METADATA, On, OnDurableEvent, OnError, type OnErrorMethod, OnWorkflowCompleted, OnWorkflowFailed, type OnWorkflowFailedOptions, type OnWorkflowSettledOptions, ProxyRunGateway, RUN_GATEWAY, RUN_REDIS_WORKER, type ResolvedTenantAuth, RunGatewayError, type RunGatewayErrorCode, type RunLookupStore, type RunRedisWorkerFn, RunRequestResponder, type RunRequestResponderOptions, type RunRequestTransport, STEP_INTERCEPTOR_METADATA, type StandaloneDurableOptions, Step, StepInterceptor, type StepOptions, StoreRunGateway, type SubscriberBatch, type SubscriberDebounce, type SubscriberDecorator, TENANT_AUTH, TENANT_REPUBLISH_MAX_LIMIT, type TenantCredentialsContract, type TenantDurableOptions, TenantEventRepublisher, type TenantFilter, type TenantLevel, type TenantRef, type TenantTokenOption, type TenantVerifierContract, type TenantVerifierInput, type TenantVerifierOption, ThinStepRegistrar, ThinWorkerBootstrap, ThinWorkflowRegistrar, UNSUPPORTED_RUN_REQUEST, type UserRef, WORKFLOW_METADATA, Workflow, type WorkflowAttributesOf, type WorkflowMeta, type WorkflowOptions, WorkflowService, attributesOf, entityConfigFor, eventBatchOf, federatedAppGateway, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, onErrorCodesOf, tenantScheduleAnnouncement, thinWorkerProviders, unavailableRunGateway };
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, RunResult, WorkflowStartClient, 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, SignalOptions } from '@dudousxd/nestjs-durable-core';
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, RunResult, 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, SignalOptions } 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';
@@ -970,6 +970,21 @@ interface DurableModuleSharedOptions {
970
970
  * deterministic and advancing a schedule is a compare-and-set. Operator only.
971
971
  */
972
972
  persistedSchedules?: boolean;
973
+ /**
974
+ * Adopt the `schedules` that TENANT apps declare and fire them here (a tenant has no store to fire
975
+ * them from). Each tenant worker announces its app's schedules on its descriptor; every `syncMs`
976
+ * (default 15 s) a driving instance turns them into persisted schedules (id
977
+ * `app:<partition>:<key>`, tagged `schedule:announced`), applies a changed definition, and pauses
978
+ * one that no live worker of its app has announced for `graceMs` (default 10 minutes). It then
979
+ * fires them on every tick, through the tenant start path: with no live worker of the app, a run
980
+ * waits `blocked` (`no_live_worker`) for one. On by default for a driving instance with a store
981
+ * that persists schedules and a transport that reads worker descriptors (BullMQ); `false` turns it
982
+ * off. Operator only.
983
+ */
984
+ announcedSchedules?: boolean | {
985
+ syncMs?: number;
986
+ graceMs?: number;
987
+ };
973
988
  /**
974
989
  * Hard-prune terminal run history on an interval so `durable_workflow_runs` (and its child tables)
975
990
  * stays bounded — without it, completed/failed/cancelled runs accumulate forever and the timer
@@ -1184,6 +1199,11 @@ interface DurableModuleAsyncOptions {
1184
1199
  useFactory: (...args: never[]) => DurableModuleOptions | Promise<DurableModuleOptions>;
1185
1200
  inject?: InjectionToken[];
1186
1201
  }
1202
+ /** The `verifyTenant` / `tenantToken` options, resolved to the plain functions the wire layer calls. */
1203
+ interface ResolvedTenantAuth {
1204
+ verifyTenant: TenantVerifier | undefined;
1205
+ tenantToken: TenantTokenSource | undefined;
1206
+ }
1187
1207
  /**
1188
1208
  * `forRoot` / `forRootAsync` first refuse to boot when two different installs of
1189
1209
  * `@dudousxd/nestjs-durable-core` are loaded in this process (a pnpm peer-variant split): each copy
@@ -1306,11 +1326,21 @@ declare class ThinWorkerBootstrap implements OnApplicationBootstrap, OnApplicati
1306
1326
  private readonly options;
1307
1327
  private readonly runRedisWorker;
1308
1328
  private readonly runnersSink;
1329
+ private readonly auth;
1309
1330
  private readonly runners;
1310
- constructor(runtime: DurableWorkerRuntime | null, options: DurableModuleOptions, runRedisWorker: RunRedisWorkerFn, runnersSink: RunningWorker[]);
1331
+ constructor(runtime: DurableWorkerRuntime | null, options: DurableModuleOptions, runRedisWorker: RunRedisWorkerFn, runnersSink: RunningWorker[], auth: ResolvedTenantAuth);
1311
1332
  onApplicationBootstrap(): Promise<void>;
1312
1333
  onApplicationShutdown(): Promise<void>;
1313
1334
  }
1335
+ /**
1336
+ * The tenant's `schedules`, as its worker announces them: under the wire tenant its starts carry (the
1337
+ * signed token when the app has one, else the partition), one {@link AnnouncedSchedule} per schedule.
1338
+ * A schedule's `namespace` is dropped (a tenant's runs always belong to its own namespace), and
1339
+ * `backfill` becomes the control plane's `catchup: 'latest'` (at most one late window).
1340
+ */
1341
+ declare function tenantScheduleAnnouncement(options: DurableModuleOptions, tenantToken: TenantTokenSource | undefined): Promise<{
1342
+ schedules?: ScheduleAnnouncement;
1343
+ }>;
1314
1344
  /**
1315
1345
  * The thin-worker slice of {@link import('./durable.module').DurableModule}'s unified provider set —
1316
1346
  * active for the pure thin-worker role (`connection` set, `store` unset): registers discovered
@@ -1900,6 +1930,11 @@ declare class TenantEventRepublisher {
1900
1930
  * byte-identical with nestjs-context's export.
1901
1931
  */
1902
1932
  declare const CONTEXT_ACCESSOR: unique symbol;
1933
+ /**
1934
+ * Internal: the module's resolved tenant auth (`verifyTenant` and `tenantToken`, resolved through
1935
+ * DI). Shared by the module and the thin-worker providers, which announce under the tenant token.
1936
+ */
1937
+ declare const TENANT_AUTH: unique symbol;
1903
1938
  /**
1904
1939
  * @deprecated Inject the `RunGateway` class, which is its own DI token:
1905
1940
  * `constructor(private readonly gateway: RunGateway)`. Kept because published
@@ -1986,4 +2021,4 @@ declare class WorkflowService {
1986
2021
  republishLifecycle(target: RepublishLifecycleTarget): Promise<RepublishLifecycleResult>;
1987
2022
  }
1988
2023
 
1989
- export { BAD_RUN_REQUEST, CONTEXT_ACCESSOR, type ContextAccessor, type ContextStore, type ContractClass, type ControlPlaneDurableOptions, DEAD_LETTER_METADATA, DURABLE_STEP_METADATA, DURABLE_WORKER_RUNNERS, DURABLE_WORKER_RUNTIME, DeadLetter, type DtoClass, DurableModule, type DurableModuleAsyncOptions, type DurableModuleOptions, type DurableModuleSharedOptions, type DurableRetentionOptions, DurableStartClient, type DurableStepInterceptor, type DurableStepMeta, type DurableTopologyName, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, type ErrorClassWithCode, FederatedAppGateway, type FederatedAppGatewayOptions, IN_APP_RUN_REDIS_WORKER, IN_APP_WORKER_BINDING, IN_APP_WORKER_RUNNERS, IN_APP_WORKER_RUNTIME, type InAppWorkerBinding, InAppWorkerBootstrap, type IoSchema, type LazyContract, ON_ERROR_METADATA, ON_EVENT_BATCH_METADATA, ON_EVENT_METADATA, On, OnDurableEvent, OnError, type OnErrorMethod, OnWorkflowCompleted, OnWorkflowFailed, type OnWorkflowFailedOptions, type OnWorkflowSettledOptions, ProxyRunGateway, RUN_GATEWAY, RUN_REDIS_WORKER, RunGatewayError, type RunGatewayErrorCode, type RunLookupStore, type RunRedisWorkerFn, RunRequestResponder, type RunRequestResponderOptions, type RunRequestTransport, STEP_INTERCEPTOR_METADATA, type StandaloneDurableOptions, Step, StepInterceptor, type StepOptions, StoreRunGateway, type SubscriberBatch, type SubscriberDebounce, type SubscriberDecorator, TENANT_REPUBLISH_MAX_LIMIT, type TenantCredentialsContract, type TenantDurableOptions, TenantEventRepublisher, type TenantFilter, type TenantLevel, type TenantRef, type TenantTokenOption, type TenantVerifierContract, type TenantVerifierInput, type TenantVerifierOption, ThinStepRegistrar, ThinWorkerBootstrap, ThinWorkflowRegistrar, UNSUPPORTED_RUN_REQUEST, type UserRef, WORKFLOW_METADATA, Workflow, type WorkflowAttributesOf, type WorkflowMeta, type WorkflowOptions, WorkflowService, attributesOf, entityConfigFor, eventBatchOf, federatedAppGateway, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, onErrorCodesOf, thinWorkerProviders, unavailableRunGateway };
2024
+ export { BAD_RUN_REQUEST, CONTEXT_ACCESSOR, type ContextAccessor, type ContextStore, type ContractClass, type ControlPlaneDurableOptions, DEAD_LETTER_METADATA, DURABLE_STEP_METADATA, DURABLE_WORKER_RUNNERS, DURABLE_WORKER_RUNTIME, DeadLetter, type DtoClass, DurableModule, type DurableModuleAsyncOptions, type DurableModuleOptions, type DurableModuleSharedOptions, type DurableRetentionOptions, DurableStartClient, type DurableStepInterceptor, type DurableStepMeta, type DurableTopologyName, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, type ErrorClassWithCode, FederatedAppGateway, type FederatedAppGatewayOptions, IN_APP_RUN_REDIS_WORKER, IN_APP_WORKER_BINDING, IN_APP_WORKER_RUNNERS, IN_APP_WORKER_RUNTIME, type InAppWorkerBinding, InAppWorkerBootstrap, type IoSchema, type LazyContract, ON_ERROR_METADATA, ON_EVENT_BATCH_METADATA, ON_EVENT_METADATA, On, OnDurableEvent, OnError, type OnErrorMethod, OnWorkflowCompleted, OnWorkflowFailed, type OnWorkflowFailedOptions, type OnWorkflowSettledOptions, ProxyRunGateway, RUN_GATEWAY, RUN_REDIS_WORKER, type ResolvedTenantAuth, RunGatewayError, type RunGatewayErrorCode, type RunLookupStore, type RunRedisWorkerFn, RunRequestResponder, type RunRequestResponderOptions, type RunRequestTransport, STEP_INTERCEPTOR_METADATA, type StandaloneDurableOptions, Step, StepInterceptor, type StepOptions, StoreRunGateway, type SubscriberBatch, type SubscriberDebounce, type SubscriberDecorator, TENANT_AUTH, TENANT_REPUBLISH_MAX_LIMIT, type TenantCredentialsContract, type TenantDurableOptions, TenantEventRepublisher, type TenantFilter, type TenantLevel, type TenantRef, type TenantTokenOption, type TenantVerifierContract, type TenantVerifierInput, type TenantVerifierOption, ThinStepRegistrar, ThinWorkerBootstrap, ThinWorkflowRegistrar, UNSUPPORTED_RUN_REQUEST, type UserRef, WORKFLOW_METADATA, Workflow, type WorkflowAttributesOf, type WorkflowMeta, type WorkflowOptions, WorkflowService, attributesOf, entityConfigFor, eventBatchOf, federatedAppGateway, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, onErrorCodesOf, tenantScheduleAnnouncement, thinWorkerProviders, unavailableRunGateway };
package/dist/index.js CHANGED
@@ -804,7 +804,7 @@ function tenantUnsupported(method) {
804
804
  __name(tenantUnsupported, "tenantUnsupported");
805
805
 
806
806
  // src/durable-worker.module.ts
807
- import { DURABLE_OPTIONS_CANONICAL, WorkflowEngine, bindWorkflowClass } from "@dudousxd/nestjs-durable-core";
807
+ import { DURABLE_OPTIONS_CANONICAL, WorkflowEngine, bindWorkflowClass, resolveTenantToken as resolveTenantToken2, workflowName as workflowName3 } from "@dudousxd/nestjs-durable-core";
808
808
  import { Inject, Injectable as Injectable2 } from "@nestjs/common";
809
809
  import { DiscoveryService, MetadataScanner } from "@nestjs/core";
810
810
 
@@ -1001,6 +1001,12 @@ function registerOnRuntime(runtime, scanner, meta, instance, origin) {
1001
1001
  }
1002
1002
  __name(registerOnRuntime, "registerOnRuntime");
1003
1003
 
1004
+ // src/tokens.ts
1005
+ import { RunGateway } from "@dudousxd/nestjs-durable-core";
1006
+ var CONTEXT_ACCESSOR = Symbol.for("@dudousxd/nestjs-context:accessor");
1007
+ var TENANT_AUTH = Symbol("nestjs-durable:tenant-auth");
1008
+ var RUN_GATEWAY = RunGateway;
1009
+
1004
1010
  // src/durable-worker.module.ts
1005
1011
  function _ts_decorate2(decorators, target, key, desc) {
1006
1012
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -1117,18 +1123,25 @@ var ThinWorkerBootstrap = class {
1117
1123
  options;
1118
1124
  runRedisWorker;
1119
1125
  runnersSink;
1126
+ auth;
1120
1127
  runners = [];
1121
- constructor(runtime, options, runRedisWorker2, runnersSink) {
1128
+ constructor(runtime, options, runRedisWorker2, runnersSink, auth) {
1122
1129
  this.runtime = runtime;
1123
1130
  this.options = options;
1124
1131
  this.runRedisWorker = runRedisWorker2;
1125
1132
  this.runnersSink = runnersSink;
1133
+ this.auth = auth;
1126
1134
  }
1127
1135
  async onApplicationBootstrap() {
1128
1136
  const options = this.options;
1129
1137
  const runtime = this.runtime;
1130
1138
  if (runtime === null || !isPureThinWorker(options) || options.connection === void 0) return;
1131
- if (options.consumers === false) return;
1139
+ if (options.consumers === false) {
1140
+ if ((options.schedules?.length ?? 0) > 0) {
1141
+ console.warn("[nestjs-durable] `schedules` on a tenant with `consumers: false` are not announced: a tenant announces its schedules on its worker descriptor, so declare them on the processes that run its workers.");
1142
+ }
1143
+ return;
1144
+ }
1132
1145
  const handle = await this.runRedisWorker({
1133
1146
  runtime,
1134
1147
  connection: options.connection,
@@ -1143,7 +1156,10 @@ var ThinWorkerBootstrap = class {
1143
1156
  } : {},
1144
1157
  ...options.concurrency !== void 0 ? {
1145
1158
  concurrency: options.concurrency
1146
- } : {}
1159
+ } : {},
1160
+ // Announce the app's schedules (an empty list too) so the control plane adopts, updates and
1161
+ // withdraws them: a tenant has no store to fire them from.
1162
+ ...await tenantScheduleAnnouncement(options, this.auth.tenantToken)
1147
1163
  });
1148
1164
  this.runners.push(handle);
1149
1165
  this.runnersSink.push(handle);
@@ -1158,14 +1174,47 @@ ThinWorkerBootstrap = _ts_decorate2([
1158
1174
  _ts_param(1, Inject(DURABLE_OPTIONS_CANONICAL)),
1159
1175
  _ts_param(2, Inject(RUN_REDIS_WORKER)),
1160
1176
  _ts_param(3, Inject(DURABLE_WORKER_RUNNERS)),
1177
+ _ts_param(4, Inject(TENANT_AUTH)),
1161
1178
  _ts_metadata2("design:type", Function),
1162
1179
  _ts_metadata2("design:paramtypes", [
1163
1180
  Object,
1164
1181
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
1165
1182
  typeof RunRedisWorkerFn === "undefined" ? Object : RunRedisWorkerFn,
1166
- Array
1183
+ Array,
1184
+ typeof ResolvedTenantAuth === "undefined" ? Object : ResolvedTenantAuth
1167
1185
  ])
1168
1186
  ], ThinWorkerBootstrap);
1187
+ async function tenantScheduleAnnouncement(options, tenantToken) {
1188
+ let tenant;
1189
+ try {
1190
+ tenant = tenantToken !== void 0 ? await resolveTenantToken2(tenantToken) : options.partition ?? "default";
1191
+ } catch (error) {
1192
+ console.warn(`[nestjs-durable] this worker announces no schedules: its tenantToken failed (${error instanceof Error ? error.message : String(error)})`);
1193
+ return {};
1194
+ }
1195
+ return {
1196
+ schedules: {
1197
+ tenant,
1198
+ items: (options.schedules ?? []).map(announcedSchedule)
1199
+ }
1200
+ };
1201
+ }
1202
+ __name(tenantScheduleAnnouncement, "tenantScheduleAnnouncement");
1203
+ function announcedSchedule(s) {
1204
+ const item = {
1205
+ key: s.key,
1206
+ workflow: workflowName3(s.workflow)
1207
+ };
1208
+ if (s.input !== void 0) item.input = s.input;
1209
+ if (s.everyMs !== void 0) item.everyMs = s.everyMs;
1210
+ if (s.cron !== void 0) item.cron = s.cron;
1211
+ if (s.timezone !== void 0) item.timezone = s.timezone;
1212
+ if (s.paused === true) item.paused = true;
1213
+ if (s.overlap !== void 0) item.overlap = s.overlap;
1214
+ if (s.jitter !== void 0 && s.jitter > 0) item.jitterMs = s.jitter;
1215
+ return item;
1216
+ }
1217
+ __name(announcedSchedule, "announcedSchedule");
1169
1218
  function thinWorkerProviders() {
1170
1219
  return [
1171
1220
  {
@@ -1591,7 +1640,7 @@ function inAppWorkerProviders() {
1591
1640
  __name(inAppWorkerProviders, "inAppWorkerProviders");
1592
1641
 
1593
1642
  // src/proxy-run-gateway.ts
1594
- import { SUMMARY_CHILD_LIMIT, childIdsOf, pageFan, resolveTenantToken as resolveTenantToken2, scopeTenantQuery, summarizeTimeline, tenantVisible } from "@dudousxd/nestjs-durable-core";
1643
+ import { SUMMARY_CHILD_LIMIT, childIdsOf, pageFan, resolveTenantToken as resolveTenantToken3, scopeTenantQuery, summarizeTimeline, tenantVisible } from "@dudousxd/nestjs-durable-core";
1595
1644
  import { Injectable as Injectable6 } from "@nestjs/common";
1596
1645
 
1597
1646
  // src/run-request-responder.ts
@@ -2204,7 +2253,7 @@ var ProxyRunGateway = class {
2204
2253
  request(body) {
2205
2254
  const source = this.tenantToken;
2206
2255
  if (typeof source !== "function") return this.send(source ?? this.tenant, body);
2207
- return resolveTenantToken2(source).then((tenant) => this.send(tenant, body));
2256
+ return resolveTenantToken3(source).then((tenant) => this.send(tenant, body));
2208
2257
  }
2209
2258
  send(tenant, body) {
2210
2259
  return new Promise((resolve, reject) => {
@@ -3218,7 +3267,7 @@ var TenantEventRepublisher = class {
3218
3267
 
3219
3268
  // src/timer-poller.ts
3220
3269
  import * as durableCore from "@dudousxd/nestjs-durable-core";
3221
- import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL6, WorkflowEngine as WorkflowEngine4, runSchedules, workflowName as workflowName3 } from "@dudousxd/nestjs-durable-core";
3270
+ import { ANNOUNCED_SCHEDULE_TAG, DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL6, WorkflowEngine as WorkflowEngine4, runSchedules, workflowName as workflowName4 } from "@dudousxd/nestjs-durable-core";
3222
3271
  import { Inject as Inject7, Injectable as Injectable10, Optional as Optional3 } from "@nestjs/common";
3223
3272
  function _ts_decorate10(decorators, target, key, desc) {
3224
3273
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -3269,13 +3318,15 @@ var TimerPoller = class {
3269
3318
  endWait;
3270
3319
  /** When the owed-lifecycle listing last succeeded (see {@link owedSweepDue}). */
3271
3320
  owedSweptAt;
3321
+ /** When the tenant schedule announcements were last reconciled (see {@link announcedSchedules}). */
3322
+ announcedSyncedAt;
3272
3323
  constructor(engine, options, leases = new SweepLeases()) {
3273
3324
  this.engine = engine;
3274
3325
  this.options = options;
3275
3326
  this.leases = leases;
3276
3327
  }
3277
3328
  async onApplicationBootstrap() {
3278
- for (const s of this.options.schedules ?? []) workflowName3(s.workflow);
3329
+ for (const s of this.options.schedules ?? []) workflowName4(s.workflow);
3279
3330
  if (!isDrivingOperator(this.options)) return;
3280
3331
  this.engine.consumeRuns?.();
3281
3332
  this.unsubscribeEnqueued = this.engine.onEnqueued((runId) => {
@@ -3358,7 +3409,8 @@ var TimerPoller = class {
3358
3409
  try {
3359
3410
  const now = Date.now();
3360
3411
  const stored = await this.engine.nextDueAt(now + wait, {
3361
- persistedSchedules: this.options.persistedSchedules === true
3412
+ persistedSchedules: this.options.persistedSchedules === true,
3413
+ announcedSchedules: this.announcedSchedules() !== void 0
3362
3414
  });
3363
3415
  const schedules = this.options.schedules;
3364
3416
  const scheduled = schedules && schedules.length > 0 && nextScheduleFireAt2 ? nextScheduleFireAt2(this.engine, schedules, now) : void 0;
@@ -3375,6 +3427,22 @@ var TimerPoller = class {
3375
3427
  }
3376
3428
  }
3377
3429
  /**
3430
+ * The tenant schedule adoption settings when it is on (see
3431
+ * {@link DurableModuleOptions.announcedSchedules}), else undefined: off by option, on a core
3432
+ * without it, or on a store that does not persist schedules.
3433
+ */
3434
+ announcedSchedules() {
3435
+ const option = this.options.announcedSchedules;
3436
+ if (option === false) return void 0;
3437
+ if (typeof this.engine.syncAnnouncedSchedules !== "function") return void 0;
3438
+ if (this.engine.schedules?.supported !== true) return void 0;
3439
+ const settings = typeof option === "object" ? option : {};
3440
+ return {
3441
+ syncMs: settings.syncMs ?? 15e3,
3442
+ graceMs: settings.graceMs
3443
+ };
3444
+ }
3445
+ /**
3378
3446
  * Whether this poll lists the owed lifecycle runs: until a sweep that listed them succeeded, then
3379
3447
  * once per `owedLifecycleSweepMs` (a clock that went back lists them again).
3380
3448
  */
@@ -3457,8 +3525,27 @@ var TimerPoller = class {
3457
3525
  if (schedules && schedules.length > 0) {
3458
3526
  note(await this.sweep("schedules", () => runSchedules(this.engine, schedules, Date.now())));
3459
3527
  }
3528
+ const announced = this.announcedSchedules();
3529
+ if (announced) {
3530
+ const at = Date.now();
3531
+ const last = this.announcedSyncedAt;
3532
+ if (last === void 0 || at < last || at - last >= announced.syncMs) {
3533
+ await this.sweep("announcedSchedules", () => this.leases.run("announced-schedules", async () => {
3534
+ await this.engine.syncAnnouncedSchedules({
3535
+ ...announced.graceMs !== void 0 ? {
3536
+ graceMs: announced.graceMs
3537
+ } : {}
3538
+ });
3539
+ this.announcedSyncedAt = at;
3540
+ }));
3541
+ }
3542
+ }
3460
3543
  if (this.options.persistedSchedules) {
3461
3544
  note(await this.sweep("persistedSchedules", () => this.engine.schedules.tick()));
3545
+ } else if (announced) {
3546
+ note(await this.sweep("announcedScheduleFires", () => this.engine.schedules.tick(Date.now(), {
3547
+ tag: ANNOUNCED_SCHEDULE_TAG
3548
+ })));
3462
3549
  }
3463
3550
  return worked;
3464
3551
  }
@@ -3484,13 +3571,8 @@ TimerPoller = _ts_decorate10([
3484
3571
  ])
3485
3572
  ], TimerPoller);
3486
3573
 
3487
- // src/tokens.ts
3488
- import { RunGateway } from "@dudousxd/nestjs-durable-core";
3489
- var CONTEXT_ACCESSOR = Symbol.for("@dudousxd/nestjs-context:accessor");
3490
- var RUN_GATEWAY = RunGateway;
3491
-
3492
3574
  // src/workflow.registrar.ts
3493
- import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL7, RemoteWorkflowExecutor, STATE_STORE_CANONICAL as STATE_STORE_CANONICAL3, WorkflowEngine as WorkflowEngine5, bindWorkflowClass as bindWorkflowClass2, sanitizeQueueToken, tenantGroup, workflowName as workflowName4 } from "@dudousxd/nestjs-durable-core";
3575
+ import { DURABLE_OPTIONS_CANONICAL as DURABLE_OPTIONS_CANONICAL7, RemoteWorkflowExecutor, STATE_STORE_CANONICAL as STATE_STORE_CANONICAL3, WorkflowEngine as WorkflowEngine5, bindWorkflowClass as bindWorkflowClass2, sanitizeQueueToken, tenantGroup, workflowName as workflowName5 } from "@dudousxd/nestjs-durable-core";
3494
3576
  import { Inject as Inject8, Injectable as Injectable11 } from "@nestjs/common";
3495
3577
  import { DiscoveryService as DiscoveryService4, MetadataScanner as MetadataScanner4 } from "@nestjs/core";
3496
3578
 
@@ -3650,7 +3732,7 @@ var WorkflowRegistrar = class {
3650
3732
  });
3651
3733
  deadLetterByWorkflow.set(meta.name, dlqName);
3652
3734
  } else if (meta.deadLetterWorkflow) {
3653
- deadLetterByWorkflow.set(meta.name, workflowName4(meta.deadLetterWorkflow));
3735
+ deadLetterByWorkflow.set(meta.name, workflowName5(meta.deadLetterWorkflow));
3654
3736
  }
3655
3737
  });
3656
3738
  this.reportUnattributed(unattributed);
@@ -3698,7 +3780,7 @@ var WorkflowRegistrar = class {
3698
3780
  * a `dlq:<runId>` id, so re-recovery never double-dispatches.
3699
3781
  */
3700
3782
  installDeadLetterRouting(byWorkflow) {
3701
- const fallback = this.options.deadLetterWorkflow ? workflowName4(this.options.deadLetterWorkflow) : void 0;
3783
+ const fallback = this.options.deadLetterWorkflow ? workflowName5(this.options.deadLetterWorkflow) : void 0;
3702
3784
  if (byWorkflow.size === 0 && !fallback) return;
3703
3785
  this.engine.onDead((run) => {
3704
3786
  const target = byWorkflow.get(run.workflow) ?? fallback;
@@ -4007,7 +4089,6 @@ function resolveTopologyPreset(options) {
4007
4089
  };
4008
4090
  }
4009
4091
  __name(resolveTopologyPreset, "resolveTopologyPreset");
4010
- var TENANT_AUTH = Symbol("nestjs-durable:tenant-auth");
4011
4092
  var RunGatewayBootstrap = class RunGatewayBootstrap2 {
4012
4093
  static {
4013
4094
  __name(this, "RunGatewayBootstrap");
@@ -4630,6 +4711,7 @@ export {
4630
4711
  Step,
4631
4712
  StepInterceptor,
4632
4713
  StoreRunGateway,
4714
+ TENANT_AUTH,
4633
4715
  TENANT_REPUBLISH_MAX_LIMIT,
4634
4716
  TenantEventRepublisher,
4635
4717
  ThinStepRegistrar,
@@ -4665,6 +4747,7 @@ export {
4665
4747
  scheduleRunIdAt,
4666
4748
  scheduledRunId,
4667
4749
  signTenantToken,
4750
+ tenantScheduleAnnouncement,
4668
4751
  thinWorkerProviders,
4669
4752
  triggeredRunsOf,
4670
4753
  unavailableRunGateway