@dudousxd/nestjs-durable 0.56.0 → 0.58.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
@@ -83,7 +83,8 @@ declare function attributesOf<C extends WorkflowClass>(workflow: C, run: {
83
83
  * Kept byte-aligned with nestjs-context's `ContextAccessor` (and the identical
84
84
  * mirror in `@dudousxd/nestjs-authz`): `traceId()` / `tenantId()` are REQUIRED
85
85
  * (the real accessor always provides them) and `get()` is included, so the
86
- * structural match stays exact when DurableModule auto-feeds the carrier.
86
+ * structural match stays exact when DurableModule auto-feeds the carrier. The tenancy
87
+ * members (`tenant`/`tenancy`/`tenantFilter`, nestjs-context ≥ 1.2) are optional.
87
88
  */
88
89
  interface UserRef {
89
90
  type: string;
@@ -100,7 +101,40 @@ interface ContextAccessor {
100
101
  userRef(): UserRef | undefined;
101
102
  /** The raw context store for the current request, or `undefined`. */
102
103
  get(): ContextStore | undefined;
104
+ /**
105
+ * The active tenant (the customer the request's data belongs to). Optional: an older context, or
106
+ * an app's own accessor, may not have it; durable then treats tenancy as off.
107
+ */
108
+ tenant?(): TenantRef | undefined;
109
+ /** The context's `tenancy` switch: `{ enabled, kinds? }`. Optional, as above. */
110
+ tenancy?(): {
111
+ enabled: boolean;
112
+ kinds?: string[];
113
+ };
114
+ /** How a lib must scope data right now. Optional, as above. */
115
+ tenantFilter?(options?: {
116
+ kinds?: string[];
117
+ }): TenantFilter;
103
118
  }
119
+ /** A tenant as the context reports it. Structural mirror of nestjs-context's `TenantRef`. */
120
+ interface TenantRef {
121
+ id: string;
122
+ kind: string;
123
+ source: string;
124
+ slug?: string;
125
+ role?: string;
126
+ }
127
+ /** How a lib must scope data right now. Structural mirror of nestjs-context's `TenantFilter`. */
128
+ type TenantFilter = {
129
+ mode: 'system';
130
+ } | {
131
+ mode: 'all';
132
+ } | {
133
+ mode: 'tenantless';
134
+ } | {
135
+ mode: 'tenant';
136
+ tenant: TenantRef;
137
+ };
104
138
 
105
139
  /** A class-validator DTO class — validated with the same `plainToInstance` + `validate` NestJS's
106
140
  * `ValidationPipe` runs. */
@@ -132,8 +166,8 @@ interface WorkflowMeta {
132
166
  concurrency?: ConcurrencyConfig | undefined;
133
167
  /** Max wall-clock lifetime before a run is cancelled (e.g. `'2h'`). See `WorkflowOptions`. */
134
168
  executionTimeout?: string | number | undefined;
135
- /** Input schema (Standard Schema or DTO class), parsed at start and before every turn. Holds
136
- * `input` or its `inputSchema` alias. See `WorkflowOptions`. */
169
+ /** Input schema (Standard Schema or DTO class), parsed at start and before every turn. See
170
+ * `WorkflowOptions`. */
137
171
  input?: IoSchema | undefined;
138
172
  /** Output schema, parsed before the run completes. See `WorkflowOptions`. */
139
173
  output?: IoSchema | undefined;
@@ -235,11 +269,6 @@ interface WorkflowOptions {
235
269
  * run with `code: 'invalid_output'`. The same option `@Step({ output })` takes.
236
270
  */
237
271
  output?: IoSchema;
238
- /**
239
- * Alias of {@link input}, kept for workflows declared before `input` existed. Setting both is an
240
- * error.
241
- */
242
- inputSchema?: IoSchema;
243
272
  /**
244
273
  * A custom check at `start` (throw to reject) for a rule a schema can't express — a cross-field
245
274
  * invariant, an async lookup. It runs after `input` parses and receives the parsed value (the input
@@ -380,11 +409,6 @@ interface StepOptions {
380
409
  * from the method signature are the only check, and the step dispatches with no retry/timeout.
381
410
  */
382
411
  declare function Step(nameOrOptions?: string | StepOptions): MethodDecorator;
383
- /**
384
- * @deprecated Use `@Step` instead. `@DurableStep` is a back-compat alias of {@link Step} and
385
- * writes the same `DURABLE_STEP_METADATA`, so discovery/registrars treat them identically.
386
- */
387
- declare const DurableStep: typeof Step;
388
412
  declare function getDurableStepMeta(method: Function): DurableStepMeta | undefined;
389
413
  declare const DEAD_LETTER_METADATA: unique symbol;
390
414
  /**
@@ -567,14 +591,28 @@ declare const ON_EVENT_BATCH_METADATA: unique symbol;
567
591
  * workflow never silently coalesces one way while its decorator says another.
568
592
  */
569
593
  declare function eventBatchOf(meta: WorkflowMeta, target: object): EventBatchConfig | undefined;
570
- /** @deprecated Renamed to `OnDurableEvent` — this alias clashes with `@nestjs/event-emitter`'s `@OnEvent` and will be removed in the next minor. */
571
- declare const OnEvent: typeof OnDurableEvent;
572
594
  /**
573
595
  * All events a workflow class subscribes to: `@Workflow({ onEvent })`, `@OnDurableEvent`,
574
596
  * `@OnWorkflowCompleted` and `@OnWorkflowFailed`. Repeated bare names collapse to one.
575
597
  */
576
598
  declare function getOnEvents(meta: WorkflowMeta, target: object): OnEventEntry[];
577
599
 
600
+ /**
601
+ * Tenancy for durable: the CUSTOMER a run belongs to (`@dudousxd/nestjs-context`'s tenant), not the
602
+ * worker-pool `namespace`. A local, structural reader of the context contract — durable never imports
603
+ * nestjs-context, so it works with any context version or none at all: with the accessor (or its
604
+ * tenancy methods) missing, tenancy reads as off and durable behaves exactly as without it.
605
+ */
606
+ /** The `tenancy` option of `DurableModule`. Same shape in every Aviary lib. */
607
+ type DurableTenancyOption = 'inherit' | false | {
608
+ /** `'inherit'` (default) follows `ContextModule`'s `tenancy.enabled`. */
609
+ enabled?: 'inherit' | boolean;
610
+ /** Tenant kinds durable honours, instead of the context's own `kinds`. */
611
+ kinds?: string[];
612
+ /** Whether a tenant request also sees runs with no tenant. Default `'tenantless'` (it does not). */
613
+ nullRows?: 'tenantless' | 'shared';
614
+ };
615
+
578
616
  /** What a tenant verifier receives for each request a tenant process sends. */
579
617
  interface TenantVerifierInput {
580
618
  /** The token presented on the request (the wire `tenant` field). */
@@ -666,7 +704,7 @@ interface DurableRetentionOptions {
666
704
  * timer/retention/registrars, executing registered bodies INLINE. Driven by {@link drive} (default
667
705
  * `true`).
668
706
  * - `{ connection }` (no `store`): **thin worker**, `WorkflowEngine` resolves to a store-less
669
- * `DurableStartClient`; `RUN_GATEWAY` is a `ProxyRunGateway` when `transport` is also given, else
707
+ * `DurableStartClient`; `RunGateway` is a `ProxyRunGateway` when `transport` is also given, else
670
708
  * every method rejects with a clear error. No store/timer/retention/entity, just discovered
671
709
  * `@Workflow`/`@Step` handlers served over ONE `runRedisWorker` consumer.
672
710
  * - `{ store, transport, connection }`: an **operator that also runs a co-located worker**: every
@@ -927,6 +965,17 @@ interface DurableModuleSharedOptions {
927
965
  * authorization boundary. Operator only.
928
966
  */
929
967
  context?: () => Record<string, unknown> | undefined;
968
+ /**
969
+ * Tenancy: scope runs by the CUSTOMER they belong to (`@dudousxd/nestjs-context`'s tenant), not by
970
+ * the worker-pool {@link namespace}. With it on, `start` stamps the request's tenant on the run
971
+ * (an explicit `StartOptions.tenantId` wins), children, `continueAsNew` and schedules inherit it,
972
+ * every turn runs with it restored as the context tenant, and app-facing reads and control calls
973
+ * (`getRun`, `signal`, `cancel`, retry, the dashboard) only see the caller's tenant's runs.
974
+ *
975
+ * `'inherit'` (default) follows `ContextModule.forRoot({ tenancy: { enabled } })`, which is off by
976
+ * default; `false` keeps durable out of tenancy. Without nestjs-context ≥ 1.2, tenancy is off.
977
+ */
978
+ tenancy?: DurableTenancyOption;
930
979
  /** Attempts for each saga compensation when a run fails. Default 1 (no retry). Idempotent undos.
931
980
  * Operator only. */
932
981
  compensationRetries?: number;
@@ -1201,7 +1250,7 @@ declare class ThinWorkerBootstrap implements OnApplicationBootstrap, OnApplicati
1201
1250
  */
1202
1251
  declare function thinWorkerProviders(): Provider[];
1203
1252
  /**
1204
- * The no-transport fallback bound to `RUN_GATEWAY` for a thin worker (`connection` set, `store`
1253
+ * The no-transport fallback bound to `RunGateway` for a thin worker (`connection` set, `store`
1205
1254
  * unset) that didn't also pass a `transport` — mirrors `DurableStartClient`'s tenant-error idiom
1206
1255
  * (`tenantUnsupported`): every method rejects with a clear, named error instead of a cryptic
1207
1256
  * `this.gateway.X is not a function`. `subscribe` is synchronous on the `RunGateway` port, so it
@@ -1385,7 +1434,7 @@ declare class RunGatewayError extends Error {
1385
1434
  /**
1386
1435
  * Tenant-side `RunGateway` — round-trips every verb as a `RunRequest`/`RunReply` pair over the
1387
1436
  * transport, correlated by a minted `requestId`, and bridges `subscribe` onto the transport's
1388
- * per-tenant event stream. Bound under `RUN_GATEWAY` by `DurableModule`'s thin-worker role
1437
+ * per-tenant event stream. Bound under `RunGateway` by `DurableModule`'s thin-worker role
1389
1438
  * (`connection` set, no `store`) when the app supplies a `transport` (see `unavailableRunGateway`
1390
1439
  * for the no-transport fallback). The counterpart to the operator-side `StoreRunGateway`: a tenant
1391
1440
  * worker never touches a store/driver directly, only this proxy.
@@ -1510,7 +1559,7 @@ declare function StepInterceptor(): ClassDecorator;
1510
1559
  declare function isStepInterceptor(target: Function): boolean;
1511
1560
 
1512
1561
  /**
1513
- * Store-backed `RunGateway` — the operator-side implementation, bound to {@link RUN_GATEWAY} on
1562
+ * Store-backed `RunGateway` — the operator-side implementation, bound to {@link RunGateway} on
1514
1563
  * worker/drive instances. Reuses `DashboardService`'s six read/control method bodies verbatim
1515
1564
  * (`dashboard.service.ts:76-172`), so a consumer that only needs the bounded `RunGateway` surface
1516
1565
  * (the `RunRequestResponder`, a thin controller) doesn't have to depend on the dashboard package.
@@ -1520,6 +1569,13 @@ declare class StoreRunGateway implements RunGateway {
1520
1569
  private readonly engine;
1521
1570
  constructor(store: StateStore, engine: WorkflowEngine);
1522
1571
  topology(): DurableTopology;
1572
+ /**
1573
+ * Narrow `query` to the caller's tenant (the tenancy matching rule; see `DurableModule`'s
1574
+ * `tenancy`). A no-op with tenancy off, or for a caller outside any request (`system`).
1575
+ */
1576
+ private scoped;
1577
+ /** The run, or null when it is missing OR belongs to a tenant the caller may not see (404). */
1578
+ private visibleRun;
1523
1579
  getRunDetail(runId: string, options?: RunDetailOptions): Promise<RunDetail | null>;
1524
1580
  /**
1525
1581
  * What a run detail reads beyond the run row and its checkpoints: what this run's settling
@@ -1578,6 +1634,10 @@ declare class StoreRunGateway implements RunGateway {
1578
1634
  redispatched: number;
1579
1635
  }) | null>;
1580
1636
  republishLifecycle(target: RepublishLifecycleTarget): Promise<RepublishLifecycleResult>;
1637
+ /**
1638
+ * Stream `runId`'s events. With tenancy, a run the caller may not see streams nothing; events of a
1639
+ * run that does not exist yet are held until its row shows whose it is.
1640
+ */
1581
1641
  subscribe(runId: string, onEvent: (event: EngineEvent) => void): () => void;
1582
1642
  }
1583
1643
 
@@ -1621,14 +1681,10 @@ declare class TenantEventRepublisher {
1621
1681
  */
1622
1682
  declare const CONTEXT_ACCESSOR: unique symbol;
1623
1683
  /**
1624
- * @deprecated Inject the `RunGateway` abstract class directly (it is its own DI token now):
1625
- * `constructor(private readonly gateway: RunGateway)`, provider `{ provide: RunGateway, useClass }`.
1626
- * This symbol is kept as a back-compat alias — it points at the `RunGateway` class, so existing
1627
- * `@Inject(RUN_GATEWAY)` sites resolve the very same token — and will be removed in a future major.
1628
- *
1629
- * `RunGateway` is owned by `@dudousxd/nestjs-durable-core` (a required peer dep of both this package
1630
- * and the dashboard), so the abstract class is a single shared token across packages without the
1631
- * previous `Symbol.for` value-sharing hack.
1684
+ * @deprecated Inject the `RunGateway` class, which is its own DI token:
1685
+ * `constructor(private readonly gateway: RunGateway)`. Kept because published
1686
+ * `@dudousxd/nestjs-agent` and `@dudousxd/nestjs-agent-opencode` releases import it; it is the
1687
+ * `RunGateway` class itself, so `@Inject(RUN_GATEWAY)` resolves the same provider.
1632
1688
  */
1633
1689
  declare const RUN_GATEWAY: typeof RunGateway;
1634
1690
 
@@ -1710,4 +1766,4 @@ declare class WorkflowService {
1710
1766
  republishLifecycle(target: RepublishLifecycleTarget): Promise<RepublishLifecycleResult>;
1711
1767
  }
1712
1768
 
1713
- 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, DurableStep, type DurableStepInterceptor, type DurableStepMeta, type DurableTopologyName, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, type ErrorClassWithCode, 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, OnEvent, 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 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, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, onErrorCodesOf, thinWorkerProviders, unavailableRunGateway };
1769
+ 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, 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 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, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, onErrorCodesOf, thinWorkerProviders, unavailableRunGateway };
package/dist/index.d.ts CHANGED
@@ -83,7 +83,8 @@ declare function attributesOf<C extends WorkflowClass>(workflow: C, run: {
83
83
  * Kept byte-aligned with nestjs-context's `ContextAccessor` (and the identical
84
84
  * mirror in `@dudousxd/nestjs-authz`): `traceId()` / `tenantId()` are REQUIRED
85
85
  * (the real accessor always provides them) and `get()` is included, so the
86
- * structural match stays exact when DurableModule auto-feeds the carrier.
86
+ * structural match stays exact when DurableModule auto-feeds the carrier. The tenancy
87
+ * members (`tenant`/`tenancy`/`tenantFilter`, nestjs-context ≥ 1.2) are optional.
87
88
  */
88
89
  interface UserRef {
89
90
  type: string;
@@ -100,7 +101,40 @@ interface ContextAccessor {
100
101
  userRef(): UserRef | undefined;
101
102
  /** The raw context store for the current request, or `undefined`. */
102
103
  get(): ContextStore | undefined;
104
+ /**
105
+ * The active tenant (the customer the request's data belongs to). Optional: an older context, or
106
+ * an app's own accessor, may not have it; durable then treats tenancy as off.
107
+ */
108
+ tenant?(): TenantRef | undefined;
109
+ /** The context's `tenancy` switch: `{ enabled, kinds? }`. Optional, as above. */
110
+ tenancy?(): {
111
+ enabled: boolean;
112
+ kinds?: string[];
113
+ };
114
+ /** How a lib must scope data right now. Optional, as above. */
115
+ tenantFilter?(options?: {
116
+ kinds?: string[];
117
+ }): TenantFilter;
103
118
  }
119
+ /** A tenant as the context reports it. Structural mirror of nestjs-context's `TenantRef`. */
120
+ interface TenantRef {
121
+ id: string;
122
+ kind: string;
123
+ source: string;
124
+ slug?: string;
125
+ role?: string;
126
+ }
127
+ /** How a lib must scope data right now. Structural mirror of nestjs-context's `TenantFilter`. */
128
+ type TenantFilter = {
129
+ mode: 'system';
130
+ } | {
131
+ mode: 'all';
132
+ } | {
133
+ mode: 'tenantless';
134
+ } | {
135
+ mode: 'tenant';
136
+ tenant: TenantRef;
137
+ };
104
138
 
105
139
  /** A class-validator DTO class — validated with the same `plainToInstance` + `validate` NestJS's
106
140
  * `ValidationPipe` runs. */
@@ -132,8 +166,8 @@ interface WorkflowMeta {
132
166
  concurrency?: ConcurrencyConfig | undefined;
133
167
  /** Max wall-clock lifetime before a run is cancelled (e.g. `'2h'`). See `WorkflowOptions`. */
134
168
  executionTimeout?: string | number | undefined;
135
- /** Input schema (Standard Schema or DTO class), parsed at start and before every turn. Holds
136
- * `input` or its `inputSchema` alias. See `WorkflowOptions`. */
169
+ /** Input schema (Standard Schema or DTO class), parsed at start and before every turn. See
170
+ * `WorkflowOptions`. */
137
171
  input?: IoSchema | undefined;
138
172
  /** Output schema, parsed before the run completes. See `WorkflowOptions`. */
139
173
  output?: IoSchema | undefined;
@@ -235,11 +269,6 @@ interface WorkflowOptions {
235
269
  * run with `code: 'invalid_output'`. The same option `@Step({ output })` takes.
236
270
  */
237
271
  output?: IoSchema;
238
- /**
239
- * Alias of {@link input}, kept for workflows declared before `input` existed. Setting both is an
240
- * error.
241
- */
242
- inputSchema?: IoSchema;
243
272
  /**
244
273
  * A custom check at `start` (throw to reject) for a rule a schema can't express — a cross-field
245
274
  * invariant, an async lookup. It runs after `input` parses and receives the parsed value (the input
@@ -380,11 +409,6 @@ interface StepOptions {
380
409
  * from the method signature are the only check, and the step dispatches with no retry/timeout.
381
410
  */
382
411
  declare function Step(nameOrOptions?: string | StepOptions): MethodDecorator;
383
- /**
384
- * @deprecated Use `@Step` instead. `@DurableStep` is a back-compat alias of {@link Step} and
385
- * writes the same `DURABLE_STEP_METADATA`, so discovery/registrars treat them identically.
386
- */
387
- declare const DurableStep: typeof Step;
388
412
  declare function getDurableStepMeta(method: Function): DurableStepMeta | undefined;
389
413
  declare const DEAD_LETTER_METADATA: unique symbol;
390
414
  /**
@@ -567,14 +591,28 @@ declare const ON_EVENT_BATCH_METADATA: unique symbol;
567
591
  * workflow never silently coalesces one way while its decorator says another.
568
592
  */
569
593
  declare function eventBatchOf(meta: WorkflowMeta, target: object): EventBatchConfig | undefined;
570
- /** @deprecated Renamed to `OnDurableEvent` — this alias clashes with `@nestjs/event-emitter`'s `@OnEvent` and will be removed in the next minor. */
571
- declare const OnEvent: typeof OnDurableEvent;
572
594
  /**
573
595
  * All events a workflow class subscribes to: `@Workflow({ onEvent })`, `@OnDurableEvent`,
574
596
  * `@OnWorkflowCompleted` and `@OnWorkflowFailed`. Repeated bare names collapse to one.
575
597
  */
576
598
  declare function getOnEvents(meta: WorkflowMeta, target: object): OnEventEntry[];
577
599
 
600
+ /**
601
+ * Tenancy for durable: the CUSTOMER a run belongs to (`@dudousxd/nestjs-context`'s tenant), not the
602
+ * worker-pool `namespace`. A local, structural reader of the context contract — durable never imports
603
+ * nestjs-context, so it works with any context version or none at all: with the accessor (or its
604
+ * tenancy methods) missing, tenancy reads as off and durable behaves exactly as without it.
605
+ */
606
+ /** The `tenancy` option of `DurableModule`. Same shape in every Aviary lib. */
607
+ type DurableTenancyOption = 'inherit' | false | {
608
+ /** `'inherit'` (default) follows `ContextModule`'s `tenancy.enabled`. */
609
+ enabled?: 'inherit' | boolean;
610
+ /** Tenant kinds durable honours, instead of the context's own `kinds`. */
611
+ kinds?: string[];
612
+ /** Whether a tenant request also sees runs with no tenant. Default `'tenantless'` (it does not). */
613
+ nullRows?: 'tenantless' | 'shared';
614
+ };
615
+
578
616
  /** What a tenant verifier receives for each request a tenant process sends. */
579
617
  interface TenantVerifierInput {
580
618
  /** The token presented on the request (the wire `tenant` field). */
@@ -666,7 +704,7 @@ interface DurableRetentionOptions {
666
704
  * timer/retention/registrars, executing registered bodies INLINE. Driven by {@link drive} (default
667
705
  * `true`).
668
706
  * - `{ connection }` (no `store`): **thin worker**, `WorkflowEngine` resolves to a store-less
669
- * `DurableStartClient`; `RUN_GATEWAY` is a `ProxyRunGateway` when `transport` is also given, else
707
+ * `DurableStartClient`; `RunGateway` is a `ProxyRunGateway` when `transport` is also given, else
670
708
  * every method rejects with a clear error. No store/timer/retention/entity, just discovered
671
709
  * `@Workflow`/`@Step` handlers served over ONE `runRedisWorker` consumer.
672
710
  * - `{ store, transport, connection }`: an **operator that also runs a co-located worker**: every
@@ -927,6 +965,17 @@ interface DurableModuleSharedOptions {
927
965
  * authorization boundary. Operator only.
928
966
  */
929
967
  context?: () => Record<string, unknown> | undefined;
968
+ /**
969
+ * Tenancy: scope runs by the CUSTOMER they belong to (`@dudousxd/nestjs-context`'s tenant), not by
970
+ * the worker-pool {@link namespace}. With it on, `start` stamps the request's tenant on the run
971
+ * (an explicit `StartOptions.tenantId` wins), children, `continueAsNew` and schedules inherit it,
972
+ * every turn runs with it restored as the context tenant, and app-facing reads and control calls
973
+ * (`getRun`, `signal`, `cancel`, retry, the dashboard) only see the caller's tenant's runs.
974
+ *
975
+ * `'inherit'` (default) follows `ContextModule.forRoot({ tenancy: { enabled } })`, which is off by
976
+ * default; `false` keeps durable out of tenancy. Without nestjs-context ≥ 1.2, tenancy is off.
977
+ */
978
+ tenancy?: DurableTenancyOption;
930
979
  /** Attempts for each saga compensation when a run fails. Default 1 (no retry). Idempotent undos.
931
980
  * Operator only. */
932
981
  compensationRetries?: number;
@@ -1201,7 +1250,7 @@ declare class ThinWorkerBootstrap implements OnApplicationBootstrap, OnApplicati
1201
1250
  */
1202
1251
  declare function thinWorkerProviders(): Provider[];
1203
1252
  /**
1204
- * The no-transport fallback bound to `RUN_GATEWAY` for a thin worker (`connection` set, `store`
1253
+ * The no-transport fallback bound to `RunGateway` for a thin worker (`connection` set, `store`
1205
1254
  * unset) that didn't also pass a `transport` — mirrors `DurableStartClient`'s tenant-error idiom
1206
1255
  * (`tenantUnsupported`): every method rejects with a clear, named error instead of a cryptic
1207
1256
  * `this.gateway.X is not a function`. `subscribe` is synchronous on the `RunGateway` port, so it
@@ -1385,7 +1434,7 @@ declare class RunGatewayError extends Error {
1385
1434
  /**
1386
1435
  * Tenant-side `RunGateway` — round-trips every verb as a `RunRequest`/`RunReply` pair over the
1387
1436
  * transport, correlated by a minted `requestId`, and bridges `subscribe` onto the transport's
1388
- * per-tenant event stream. Bound under `RUN_GATEWAY` by `DurableModule`'s thin-worker role
1437
+ * per-tenant event stream. Bound under `RunGateway` by `DurableModule`'s thin-worker role
1389
1438
  * (`connection` set, no `store`) when the app supplies a `transport` (see `unavailableRunGateway`
1390
1439
  * for the no-transport fallback). The counterpart to the operator-side `StoreRunGateway`: a tenant
1391
1440
  * worker never touches a store/driver directly, only this proxy.
@@ -1510,7 +1559,7 @@ declare function StepInterceptor(): ClassDecorator;
1510
1559
  declare function isStepInterceptor(target: Function): boolean;
1511
1560
 
1512
1561
  /**
1513
- * Store-backed `RunGateway` — the operator-side implementation, bound to {@link RUN_GATEWAY} on
1562
+ * Store-backed `RunGateway` — the operator-side implementation, bound to {@link RunGateway} on
1514
1563
  * worker/drive instances. Reuses `DashboardService`'s six read/control method bodies verbatim
1515
1564
  * (`dashboard.service.ts:76-172`), so a consumer that only needs the bounded `RunGateway` surface
1516
1565
  * (the `RunRequestResponder`, a thin controller) doesn't have to depend on the dashboard package.
@@ -1520,6 +1569,13 @@ declare class StoreRunGateway implements RunGateway {
1520
1569
  private readonly engine;
1521
1570
  constructor(store: StateStore, engine: WorkflowEngine);
1522
1571
  topology(): DurableTopology;
1572
+ /**
1573
+ * Narrow `query` to the caller's tenant (the tenancy matching rule; see `DurableModule`'s
1574
+ * `tenancy`). A no-op with tenancy off, or for a caller outside any request (`system`).
1575
+ */
1576
+ private scoped;
1577
+ /** The run, or null when it is missing OR belongs to a tenant the caller may not see (404). */
1578
+ private visibleRun;
1523
1579
  getRunDetail(runId: string, options?: RunDetailOptions): Promise<RunDetail | null>;
1524
1580
  /**
1525
1581
  * What a run detail reads beyond the run row and its checkpoints: what this run's settling
@@ -1578,6 +1634,10 @@ declare class StoreRunGateway implements RunGateway {
1578
1634
  redispatched: number;
1579
1635
  }) | null>;
1580
1636
  republishLifecycle(target: RepublishLifecycleTarget): Promise<RepublishLifecycleResult>;
1637
+ /**
1638
+ * Stream `runId`'s events. With tenancy, a run the caller may not see streams nothing; events of a
1639
+ * run that does not exist yet are held until its row shows whose it is.
1640
+ */
1581
1641
  subscribe(runId: string, onEvent: (event: EngineEvent) => void): () => void;
1582
1642
  }
1583
1643
 
@@ -1621,14 +1681,10 @@ declare class TenantEventRepublisher {
1621
1681
  */
1622
1682
  declare const CONTEXT_ACCESSOR: unique symbol;
1623
1683
  /**
1624
- * @deprecated Inject the `RunGateway` abstract class directly (it is its own DI token now):
1625
- * `constructor(private readonly gateway: RunGateway)`, provider `{ provide: RunGateway, useClass }`.
1626
- * This symbol is kept as a back-compat alias — it points at the `RunGateway` class, so existing
1627
- * `@Inject(RUN_GATEWAY)` sites resolve the very same token — and will be removed in a future major.
1628
- *
1629
- * `RunGateway` is owned by `@dudousxd/nestjs-durable-core` (a required peer dep of both this package
1630
- * and the dashboard), so the abstract class is a single shared token across packages without the
1631
- * previous `Symbol.for` value-sharing hack.
1684
+ * @deprecated Inject the `RunGateway` class, which is its own DI token:
1685
+ * `constructor(private readonly gateway: RunGateway)`. Kept because published
1686
+ * `@dudousxd/nestjs-agent` and `@dudousxd/nestjs-agent-opencode` releases import it; it is the
1687
+ * `RunGateway` class itself, so `@Inject(RUN_GATEWAY)` resolves the same provider.
1632
1688
  */
1633
1689
  declare const RUN_GATEWAY: typeof RunGateway;
1634
1690
 
@@ -1710,4 +1766,4 @@ declare class WorkflowService {
1710
1766
  republishLifecycle(target: RepublishLifecycleTarget): Promise<RepublishLifecycleResult>;
1711
1767
  }
1712
1768
 
1713
- 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, DurableStep, type DurableStepInterceptor, type DurableStepMeta, type DurableTopologyName, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, type ErrorClassWithCode, 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, OnEvent, 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 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, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, onErrorCodesOf, thinWorkerProviders, unavailableRunGateway };
1769
+ 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, 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 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, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, onErrorCodesOf, thinWorkerProviders, unavailableRunGateway };