@dudousxd/nestjs-durable 0.32.0 → 0.34.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,10 +1,76 @@
1
- import { StepError, WorkflowRef, SingletonConfig, SearchAttributesSchema, StateStore, Transport, NamedTransport, ControlPlane, ScheduledWorkflow, RetentionPolicy, QueueConfig, AdmissionBackend, WorkflowClass, WorkflowInputOf, StartOptions, RunResult, RunGateway, WorkflowEngine, EntityHandler, DurableTopology, RunDetail, RunQuery, RunListItem, GroupHealth, RunWaiting, EngineEvent, RunRequest, RunReply, StepInvocation, TenantEvent } from '@dudousxd/nestjs-durable-core';
2
- export { AttributeFilter, EngineEvent, RunDetail, RunGateway, RunListItem, RunQuery, RunStatus, RunWaiting, SearchAttributes, StepCheckpoint, StepLogger, WorkflowCtx, WorkflowEngine, WorkflowRun } from '@dudousxd/nestjs-durable-core';
1
+ import { WorkflowCtx, SearchAttributes, WorkflowClass, StepError, WorkflowRef, SingletonConfig, SearchAttributesSchema, StateStore, Transport, NamedTransport, ControlPlane, ScheduledWorkflow, RetentionPolicy, QueueConfig, AdmissionBackend, WorkflowInputOf, StartOptions, RunResult, RunGateway, WorkflowEngine, EntityHandler, DurableTopology, RunDetail, RunQuery, RunListItem, GroupHealth, RunWaiting, EngineEvent, RunRequest, RunReply, StepInvocation, TenantEvent } from '@dudousxd/nestjs-durable-core';
2
+ export { AttributeFilter, EngineEvent, InferSearchAttributes, RunDetail, RunGateway, RunListItem, RunQuery, RunStatus, RunWaiting, SearchAttributes, SearchAttributesSchema, StepCheckpoint, StepEvent, StepLogger, WorkflowCtx, WorkflowEngine, WorkflowHandler, WorkflowRun, readSearchAttributes } from '@dudousxd/nestjs-durable-core';
3
3
  import { z } from 'zod';
4
4
  import { ConcurrencyOption, StartRunDeps, RunRedisWorkerOptions, RunningWorker, DurableWorkerRuntime } from '@dudousxd/durable-worker';
5
5
  import { DynamicModule, InjectionToken, OnModuleInit, OnApplicationBootstrap, OnApplicationShutdown, Provider } from '@nestjs/common';
6
6
  import { DiscoveryService, MetadataScanner } from '@nestjs/core';
7
7
 
8
+ /**
9
+ * The search-attributes shape a `@Workflow` class declares — extracted from its `run` method's
10
+ * `ctx: WorkflowCtx<A>` annotation, mirroring the `WorkflowInputOf`/`WorkflowOutputOf` structural-
11
+ * typing idiom in core's `workflow-ref.ts` (which extract `run`'s `input`/return type the same way).
12
+ * A class whose `run` leaves `ctx` untyped (or types it as the bare `WorkflowCtx`) resolves to the
13
+ * untyped `SearchAttributes` default — matching `WorkflowCtx` itself.
14
+ */
15
+ type WorkflowAttributesOf<C> = C extends abstract new (...args: never[]) => {
16
+ run(ctx: WorkflowCtx<infer A>, input: never): unknown;
17
+ } ? A : SearchAttributes;
18
+ /**
19
+ * Read a run's search attributes **by workflow class**, with the schema resolved from that class's
20
+ * `@Workflow({ searchAttributes })` decorator metadata — the same single-source-of-truth idiom as
21
+ * triggering a workflow by class (`ctx.child(ShippingWorkflow, input)`, `engine.start(CheckoutWorkflow,
22
+ * input)`): the decorator is the one place the schema lives, and every reader references the
23
+ * WORKFLOW, never re-imports or re-declares the schema itself. The return type is inferred
24
+ * structurally from the class's `run(ctx: WorkflowCtx<A>, …)` annotation (see
25
+ * {@link WorkflowAttributesOf}), so a valid read is typed to `A` with no explicit type argument.
26
+ *
27
+ * Delegates to core's `readSearchAttributes(schema, run)` for the actual read, so the same lenient
28
+ * safe-parse semantics apply: a run whose stored `searchAttributes` predate the schema, or fail it,
29
+ * reads back as `{}` rather than throwing (see `readSearchAttributes`'s doc comment).
30
+ *
31
+ * @throws if `workflow` isn't a `@Workflow`-decorated class (no metadata at all — nothing to resolve
32
+ * the schema from).
33
+ * @throws if `workflow` is a `@Workflow` class that never declared a `searchAttributes` schema —
34
+ * reading attributes by class needs one to resolve against.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { z } from 'zod';
39
+ * import { Injectable } from '@nestjs/common';
40
+ * import {
41
+ * attributesOf,
42
+ * InferSearchAttributes,
43
+ * Workflow,
44
+ * WorkflowCtx,
45
+ * WorkflowHandler,
46
+ * } from '@dudousxd/nestjs-durable';
47
+ *
48
+ * const orderAttrs = z.object({ tier: z.enum(['free', 'pro']), amount: z.number() });
49
+ * type OrderAttrs = InferSearchAttributes<typeof orderAttrs>;
50
+ *
51
+ * @Workflow({ name: 'checkout', searchAttributes: orderAttrs })
52
+ * class CheckoutWorkflow implements WorkflowHandler<{ orderId: string }, void, OrderAttrs> {
53
+ * async run(ctx: WorkflowCtx<OrderAttrs>, input: { orderId: string }): Promise<void> {
54
+ * await ctx.upsertSearchAttributes({ tier: 'pro', amount: 100 });
55
+ * }
56
+ * }
57
+ *
58
+ * @Injectable()
59
+ * class CheckoutDashboardService {
60
+ * constructor(private readonly store: StateStore) {}
61
+ *
62
+ * async tierOf(runId: string) {
63
+ * const run = await this.store.getRun(runId);
64
+ * const attrs = attributesOf(CheckoutWorkflow, run ?? {}); // OrderAttrs
65
+ * return attrs.tier;
66
+ * }
67
+ * }
68
+ * ```
69
+ */
70
+ declare function attributesOf<C extends WorkflowClass>(workflow: C, run: {
71
+ searchAttributes?: SearchAttributes | null | undefined;
72
+ }): WorkflowAttributesOf<C>;
73
+
8
74
  /**
9
75
  * Local, structural mirror of `@dudousxd/nestjs-context`'s public accessor
10
76
  * (`packages/core/src/accessor.ts`).
@@ -1035,4 +1101,4 @@ declare class WorkflowService {
1035
1101
  }): Promise<number>;
1036
1102
  }
1037
1103
 
1038
- 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 };
1104
+ 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 WorkflowAttributesOf, type WorkflowMeta, type WorkflowOptions, WorkflowService, attributesOf, entityConfigFor, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, thinWorkerProviders, unavailableRunGateway };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,76 @@
1
- import { StepError, WorkflowRef, SingletonConfig, SearchAttributesSchema, StateStore, Transport, NamedTransport, ControlPlane, ScheduledWorkflow, RetentionPolicy, QueueConfig, AdmissionBackend, WorkflowClass, WorkflowInputOf, StartOptions, RunResult, RunGateway, WorkflowEngine, EntityHandler, DurableTopology, RunDetail, RunQuery, RunListItem, GroupHealth, RunWaiting, EngineEvent, RunRequest, RunReply, StepInvocation, TenantEvent } from '@dudousxd/nestjs-durable-core';
2
- export { AttributeFilter, EngineEvent, RunDetail, RunGateway, RunListItem, RunQuery, RunStatus, RunWaiting, SearchAttributes, StepCheckpoint, StepLogger, WorkflowCtx, WorkflowEngine, WorkflowRun } from '@dudousxd/nestjs-durable-core';
1
+ import { WorkflowCtx, SearchAttributes, WorkflowClass, StepError, WorkflowRef, SingletonConfig, SearchAttributesSchema, StateStore, Transport, NamedTransport, ControlPlane, ScheduledWorkflow, RetentionPolicy, QueueConfig, AdmissionBackend, WorkflowInputOf, StartOptions, RunResult, RunGateway, WorkflowEngine, EntityHandler, DurableTopology, RunDetail, RunQuery, RunListItem, GroupHealth, RunWaiting, EngineEvent, RunRequest, RunReply, StepInvocation, TenantEvent } from '@dudousxd/nestjs-durable-core';
2
+ export { AttributeFilter, EngineEvent, InferSearchAttributes, RunDetail, RunGateway, RunListItem, RunQuery, RunStatus, RunWaiting, SearchAttributes, SearchAttributesSchema, StepCheckpoint, StepEvent, StepLogger, WorkflowCtx, WorkflowEngine, WorkflowHandler, WorkflowRun, readSearchAttributes } from '@dudousxd/nestjs-durable-core';
3
3
  import { z } from 'zod';
4
4
  import { ConcurrencyOption, StartRunDeps, RunRedisWorkerOptions, RunningWorker, DurableWorkerRuntime } from '@dudousxd/durable-worker';
5
5
  import { DynamicModule, InjectionToken, OnModuleInit, OnApplicationBootstrap, OnApplicationShutdown, Provider } from '@nestjs/common';
6
6
  import { DiscoveryService, MetadataScanner } from '@nestjs/core';
7
7
 
8
+ /**
9
+ * The search-attributes shape a `@Workflow` class declares — extracted from its `run` method's
10
+ * `ctx: WorkflowCtx<A>` annotation, mirroring the `WorkflowInputOf`/`WorkflowOutputOf` structural-
11
+ * typing idiom in core's `workflow-ref.ts` (which extract `run`'s `input`/return type the same way).
12
+ * A class whose `run` leaves `ctx` untyped (or types it as the bare `WorkflowCtx`) resolves to the
13
+ * untyped `SearchAttributes` default — matching `WorkflowCtx` itself.
14
+ */
15
+ type WorkflowAttributesOf<C> = C extends abstract new (...args: never[]) => {
16
+ run(ctx: WorkflowCtx<infer A>, input: never): unknown;
17
+ } ? A : SearchAttributes;
18
+ /**
19
+ * Read a run's search attributes **by workflow class**, with the schema resolved from that class's
20
+ * `@Workflow({ searchAttributes })` decorator metadata — the same single-source-of-truth idiom as
21
+ * triggering a workflow by class (`ctx.child(ShippingWorkflow, input)`, `engine.start(CheckoutWorkflow,
22
+ * input)`): the decorator is the one place the schema lives, and every reader references the
23
+ * WORKFLOW, never re-imports or re-declares the schema itself. The return type is inferred
24
+ * structurally from the class's `run(ctx: WorkflowCtx<A>, …)` annotation (see
25
+ * {@link WorkflowAttributesOf}), so a valid read is typed to `A` with no explicit type argument.
26
+ *
27
+ * Delegates to core's `readSearchAttributes(schema, run)` for the actual read, so the same lenient
28
+ * safe-parse semantics apply: a run whose stored `searchAttributes` predate the schema, or fail it,
29
+ * reads back as `{}` rather than throwing (see `readSearchAttributes`'s doc comment).
30
+ *
31
+ * @throws if `workflow` isn't a `@Workflow`-decorated class (no metadata at all — nothing to resolve
32
+ * the schema from).
33
+ * @throws if `workflow` is a `@Workflow` class that never declared a `searchAttributes` schema —
34
+ * reading attributes by class needs one to resolve against.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { z } from 'zod';
39
+ * import { Injectable } from '@nestjs/common';
40
+ * import {
41
+ * attributesOf,
42
+ * InferSearchAttributes,
43
+ * Workflow,
44
+ * WorkflowCtx,
45
+ * WorkflowHandler,
46
+ * } from '@dudousxd/nestjs-durable';
47
+ *
48
+ * const orderAttrs = z.object({ tier: z.enum(['free', 'pro']), amount: z.number() });
49
+ * type OrderAttrs = InferSearchAttributes<typeof orderAttrs>;
50
+ *
51
+ * @Workflow({ name: 'checkout', searchAttributes: orderAttrs })
52
+ * class CheckoutWorkflow implements WorkflowHandler<{ orderId: string }, void, OrderAttrs> {
53
+ * async run(ctx: WorkflowCtx<OrderAttrs>, input: { orderId: string }): Promise<void> {
54
+ * await ctx.upsertSearchAttributes({ tier: 'pro', amount: 100 });
55
+ * }
56
+ * }
57
+ *
58
+ * @Injectable()
59
+ * class CheckoutDashboardService {
60
+ * constructor(private readonly store: StateStore) {}
61
+ *
62
+ * async tierOf(runId: string) {
63
+ * const run = await this.store.getRun(runId);
64
+ * const attrs = attributesOf(CheckoutWorkflow, run ?? {}); // OrderAttrs
65
+ * return attrs.tier;
66
+ * }
67
+ * }
68
+ * ```
69
+ */
70
+ declare function attributesOf<C extends WorkflowClass>(workflow: C, run: {
71
+ searchAttributes?: SearchAttributes | null | undefined;
72
+ }): WorkflowAttributesOf<C>;
73
+
8
74
  /**
9
75
  * Local, structural mirror of `@dudousxd/nestjs-context`'s public accessor
10
76
  * (`packages/core/src/accessor.ts`).
@@ -1035,4 +1101,4 @@ declare class WorkflowService {
1035
1101
  }): Promise<number>;
1036
1102
  }
1037
1103
 
1038
- 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 };
1104
+ 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 WorkflowAttributesOf, type WorkflowMeta, type WorkflowOptions, WorkflowService, attributesOf, entityConfigFor, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, thinWorkerProviders, unavailableRunGateway };
package/dist/index.js CHANGED
@@ -7,6 +7,9 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
7
7
  throw Error('Dynamic require of "' + x + '" is not supported');
8
8
  });
9
9
 
10
+ // src/attributes-of.ts
11
+ import { readSearchAttributes } from "@dudousxd/nestjs-durable-core";
12
+
10
13
  // src/decorators.ts
11
14
  import { DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, WORKFLOW_NAME_KEY } from "@dudousxd/nestjs-durable-core";
12
15
  import "reflect-metadata";
@@ -114,6 +117,19 @@ function getOnEvents(meta, target) {
114
117
  }
115
118
  __name(getOnEvents, "getOnEvents");
116
119
 
120
+ // src/attributes-of.ts
121
+ function attributesOf(workflow, run) {
122
+ const meta = getWorkflowMeta(workflow);
123
+ if (!meta) {
124
+ throw new Error(`attributesOf: ${workflow.name} is not a @Workflow class \u2014 is it decorated with @Workflow({ name, searchAttributes })?`);
125
+ }
126
+ if (!meta.searchAttributes) {
127
+ throw new Error(`attributesOf: workflow '${meta.name}' declares no searchAttributes schema \u2014 reading attributes by class requires the workflow to declare its schema: @Workflow({ name: '${meta.name}', searchAttributes: mySchema }).`);
128
+ }
129
+ return readSearchAttributes(meta.searchAttributes, run);
130
+ }
131
+ __name(attributesOf, "attributesOf");
132
+
117
133
  // src/durable-start-client.ts
118
134
  import { startRun } from "@dudousxd/durable-worker";
119
135
  import { workflowName } from "@dudousxd/nestjs-durable-core";
@@ -2054,7 +2070,7 @@ DurableModule = _ts_decorate12([
2054
2070
  ], DurableModule);
2055
2071
 
2056
2072
  // src/index.ts
2057
- import { WorkflowEngine as WorkflowEngine7 } from "@dudousxd/nestjs-durable-core";
2073
+ import { readSearchAttributes as readSearchAttributes2, WorkflowEngine as WorkflowEngine7 } from "@dudousxd/nestjs-durable-core";
2058
2074
  export {
2059
2075
  CONTEXT_ACCESSOR,
2060
2076
  DEAD_LETTER_METADATA,
@@ -2093,6 +2109,7 @@ export {
2093
2109
  Workflow,
2094
2110
  WorkflowEngine7 as WorkflowEngine,
2095
2111
  WorkflowService,
2112
+ attributesOf,
2096
2113
  entityConfigFor,
2097
2114
  getDurableStepMeta,
2098
2115
  getEntityMeta,
@@ -2103,6 +2120,7 @@ export {
2103
2120
  isDrivingOperator,
2104
2121
  isOperatorRole,
2105
2122
  isStepInterceptor,
2123
+ readSearchAttributes2 as readSearchAttributes,
2106
2124
  thinWorkerProviders,
2107
2125
  unavailableRunGateway
2108
2126
  };