nestjs-temporal-core 3.2.3 → 3.2.7

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.
Files changed (37) hide show
  1. package/README.md +303 -4
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +4 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/interfaces.d.ts +39 -104
  6. package/dist/interfaces.js +2 -1
  7. package/dist/interfaces.js.map +1 -1
  8. package/dist/services/temporal-client.service.d.ts +6 -5
  9. package/dist/services/temporal-client.service.js +44 -2
  10. package/dist/services/temporal-client.service.js.map +1 -1
  11. package/dist/services/temporal-schedule.service.d.ts +4 -6
  12. package/dist/services/temporal-schedule.service.js +47 -22
  13. package/dist/services/temporal-schedule.service.js.map +1 -1
  14. package/dist/services/temporal-worker.service.js +7 -9
  15. package/dist/services/temporal-worker.service.js.map +1 -1
  16. package/dist/services/temporal.service.d.ts +1 -0
  17. package/dist/services/temporal.service.js +16 -0
  18. package/dist/services/temporal.service.js.map +1 -1
  19. package/dist/temporal.module.js +15 -2
  20. package/dist/temporal.module.js.map +1 -1
  21. package/dist/tsconfig.tsbuildinfo +1 -1
  22. package/dist/utils/index.d.ts +1 -0
  23. package/dist/utils/index.js +4 -1
  24. package/dist/utils/index.js.map +1 -1
  25. package/dist/utils/workflow-token.d.ts +5 -0
  26. package/dist/utils/workflow-token.js +16 -0
  27. package/dist/utils/workflow-token.js.map +1 -0
  28. package/dist/workflow-proxy/index.d.ts +2 -0
  29. package/dist/workflow-proxy/index.js +8 -0
  30. package/dist/workflow-proxy/index.js.map +1 -0
  31. package/dist/workflow-proxy/workflow-proxy.d.ts +26 -0
  32. package/dist/workflow-proxy/workflow-proxy.factory.d.ts +9 -0
  33. package/dist/workflow-proxy/workflow-proxy.factory.js +29 -0
  34. package/dist/workflow-proxy/workflow-proxy.factory.js.map +1 -0
  35. package/dist/workflow-proxy/workflow-proxy.js +41 -0
  36. package/dist/workflow-proxy/workflow-proxy.js.map +1 -0
  37. package/package.json +24 -23
package/README.md CHANGED
@@ -4,10 +4,11 @@
4
4
 
5
5
  A comprehensive NestJS integration framework for Temporal.io that provides enterprise-ready workflow orchestration with automatic discovery, declarative decorators, and robust monitoring capabilities.
6
6
 
7
- ![Statements](https://img.shields.io/badge/statements-98.72%25-brightgreen.svg?style=flat)
8
- ![Branches](https://img.shields.io/badge/branches-91.71%25-brightgreen.svg?style=flat)
9
- ![Functions](https://img.shields.io/badge/functions-99.69%25-brightgreen.svg?style=flat)
10
- ![Lines](https://img.shields.io/badge/lines-98.78%25-brightgreen.svg?style=flat)
7
+ ![Statements](https://img.shields.io/badge/statements-99.81%25-brightgreen.svg?style=flat)
8
+ ![Branches](https://img.shields.io/badge/branches-94.6%25-brightgreen.svg?style=flat)
9
+ ![Functions](https://img.shields.io/badge/functions-98.29%25-brightgreen.svg?style=flat)
10
+ ![Lines](https://img.shields.io/badge/lines-99.95%25-brightgreen.svg?style=flat)
11
+ [![codecov](https://codecov.io/gh/harsh-simform/nestjs-temporal-core/branch/main/graph/badge.svg?token=BYSE45L6DI)](https://codecov.io/gh/harsh-simform/nestjs-temporal-core)
11
12
 
12
13
  [Documentation](https://harsh-simform.github.io/nestjs-temporal-core/) • [NPM](https://www.npmjs.com/package/nestjs-temporal-core) • [GitHub](https://github.com/harsh-simform/nestjs-temporal-core) • [Example Project](https://github.com/harsh-simform/nestjs-temporal-core-example)
13
14
 
@@ -31,6 +32,8 @@ A comprehensive NestJS integration framework for Temporal.io that provides enter
31
32
  - [Activities](#activities)
32
33
  - [Workflows](#workflows)
33
34
  - [Signals and Queries](#signals-and-queries)
35
+ - [Typed Workflow Proxy](#typed-workflow-proxy)
36
+ - [Signal-with-Start](#signal-with-start)
34
37
  - [API Reference](#api-reference)
35
38
  - [Examples](#examples)
36
39
  - [Advanced Usage](#advanced-usage)
@@ -65,6 +68,8 @@ NestJS Temporal Core bridges NestJS's powerful dependency injection system with
65
68
  - **Automatic Discovery** - Runtime discovery and registration of activities with zero configuration
66
69
  - **Schedule Management** - Programmatic schedule creation, updates, and monitoring
67
70
  - **Health Monitoring** - Built-in health checks and comprehensive status reporting
71
+ - **Typed Workflow Proxy** - Generic `IWorkflowProxy<T>` that infers start args, signal args, and query return types from your workflow function signature
72
+ - **Signal-with-Start** - Atomic "ensure running + signal" on both the low-level client service and the high-level `TemporalService`
68
73
 
69
74
  ### Enterprise Features
70
75
 
@@ -841,6 +846,234 @@ export class OrderService {
841
846
 
842
847
  [🔝 Back to top](#table-of-contents)
843
848
 
849
+ ### Typed Workflow Proxy
850
+
851
+ The typed workflow proxy gives you end-to-end type safety when interacting with a specific workflow. Instead of passing workflow names and args as strings/`unknown[]`, you get a generic `IWorkflowProxy<T>` where `T` is your workflow function type — all method signatures are inferred from `T`.
852
+
853
+ **What it solves:**
854
+
855
+ ```typescript
856
+ // Before: string names, unknown args, manual casts on query results
857
+ const handle = await this.temporal.startWorkflow('orderWorkflow', [orderId, customerId]);
858
+ const status = await this.temporal.queryWorkflow<OrderStatus>(workflowId, 'getStatus');
859
+ ```
860
+
861
+ ```typescript
862
+ // After: fully typed against the workflow signature
863
+ const handle = await this.orderProxy.start([orderId, customerId]); // args typed as Parameters<typeof orderWorkflow>
864
+ const status = await this.orderProxy.query(workflowId, statusQuery); // return type inferred from QueryDefinition
865
+ ```
866
+
867
+ If you rename a workflow parameter or change its return type, every call site becomes a compile error until fixed.
868
+
869
+ #### 1. Define signal/query definitions in your workflow file
870
+
871
+ ```typescript
872
+ // workflows/order.workflow.ts
873
+ import { defineSignal, defineQuery, setHandler, condition } from '@temporalio/workflow';
874
+
875
+ export interface OrderStatus {
876
+ orderId: string;
877
+ state: 'pending' | 'approved' | 'shipped' | 'cancelled';
878
+ }
879
+
880
+ export const approveSignal = defineSignal<[string]>('approve'); // signal takes one string arg
881
+ export const cancelSignal = defineSignal<[string]>('cancel');
882
+ export const statusQuery = defineQuery<OrderStatus>('getStatus'); // query returns OrderStatus
883
+
884
+ export async function orderWorkflow(orderId: string, customerId: number): Promise<OrderStatus> {
885
+ let status: OrderStatus = { orderId, state: 'pending' };
886
+
887
+ setHandler(approveSignal, (approver) => {
888
+ status = { ...status, state: 'approved' };
889
+ });
890
+ setHandler(cancelSignal, (reason) => {
891
+ status = { ...status, state: 'cancelled' };
892
+ });
893
+ setHandler(statusQuery, () => status);
894
+
895
+ await condition(() => status.state !== 'pending');
896
+ return status;
897
+ }
898
+ ```
899
+
900
+ #### 2. Register a typed proxy as a NestJS provider
901
+
902
+ ```typescript
903
+ // order.module.ts
904
+ import { Module } from '@nestjs/common';
905
+ import { createWorkflowToken, createWorkflowProvider } from 'nestjs-temporal-core';
906
+ import { orderWorkflow } from './workflows/order.workflow';
907
+ import { OrderService } from './order.service';
908
+
909
+ export const ORDER_WORKFLOW = createWorkflowToken('orderWorkflow');
910
+
911
+ @Module({
912
+ providers: [
913
+ OrderService,
914
+ createWorkflowProvider<typeof orderWorkflow>(ORDER_WORKFLOW, {
915
+ workflowType: 'orderWorkflow',
916
+ taskQueue: 'orders',
917
+ }),
918
+ ],
919
+ exports: [ORDER_WORKFLOW],
920
+ })
921
+ export class OrderModule {}
922
+ ```
923
+
924
+ #### 3. Inject and use — fully typed
925
+
926
+ ```typescript
927
+ // order.service.ts
928
+ import { Injectable, Inject } from '@nestjs/common';
929
+ import { IWorkflowProxy } from 'nestjs-temporal-core';
930
+ import {
931
+ orderWorkflow,
932
+ approveSignal,
933
+ cancelSignal,
934
+ statusQuery,
935
+ OrderStatus,
936
+ } from './workflows/order.workflow';
937
+ import { ORDER_WORKFLOW } from './order.module';
938
+
939
+ @Injectable()
940
+ export class OrderService {
941
+ constructor(
942
+ @Inject(ORDER_WORKFLOW)
943
+ private readonly orderProxy: IWorkflowProxy<typeof orderWorkflow>,
944
+ ) {}
945
+
946
+ async createOrder(orderId: string, customerId: number) {
947
+ // start() args are typed as Parameters<typeof orderWorkflow> = [string, number]
948
+ const handle = await this.orderProxy.start([orderId, customerId], {
949
+ workflowId: `order-${orderId}`,
950
+ });
951
+ return { workflowId: handle.workflowId };
952
+ }
953
+
954
+ async approve(workflowId: string, approver: string) {
955
+ // signal() infers TArgs from approveSignal — passing a number here is a compile error
956
+ await this.orderProxy.signal(workflowId, approveSignal, approver);
957
+ }
958
+
959
+ async getStatus(workflowId: string): Promise<OrderStatus> {
960
+ // query() return type is inferred from statusQuery
961
+ return this.orderProxy.query(workflowId, statusQuery);
962
+ }
963
+
964
+ async waitForCompletion(workflowId: string): Promise<OrderStatus> {
965
+ const handle = await this.orderProxy.getHandle(workflowId);
966
+ // handle.result() is Promise<OrderStatus>, not Promise<unknown>
967
+ return handle.result();
968
+ }
969
+
970
+ async cancelOrder(orderId: string, reason: string) {
971
+ // signalWithStart: atomically starts the workflow and signals it
972
+ await this.orderProxy.signalWithStart(
973
+ cancelSignal,
974
+ [reason], // signal args — typed
975
+ [orderId, 0], // workflow args — typed as Parameters<typeof orderWorkflow>
976
+ { workflowId: `order-${orderId}` },
977
+ );
978
+ }
979
+ }
980
+ ```
981
+
982
+ #### Alternative: use `WorkflowProxyFactory` directly
983
+
984
+ If you don't want a token-bound provider, inject the factory and create proxies on demand:
985
+
986
+ ```typescript
987
+ import { Injectable } from '@nestjs/common';
988
+ import { WorkflowProxyFactory, IWorkflowProxy } from 'nestjs-temporal-core';
989
+ import { orderWorkflow } from './workflows/order.workflow';
990
+
991
+ @Injectable()
992
+ export class OrderService {
993
+ private readonly orderProxy: IWorkflowProxy<typeof orderWorkflow>;
994
+
995
+ constructor(factory: WorkflowProxyFactory) {
996
+ this.orderProxy = factory.createProxy<typeof orderWorkflow>({
997
+ workflowType: 'orderWorkflow',
998
+ taskQueue: 'orders',
999
+ });
1000
+ }
1001
+ }
1002
+ ```
1003
+
1004
+ `WorkflowProxyFactory` is registered globally by `TemporalModule`, so no imports are needed in feature modules.
1005
+
1006
+ #### Proxy method reference
1007
+
1008
+ | Method | Purpose | Typing |
1009
+ |---|---|---|
1010
+ | `start(args, options?)` | Start a new workflow execution | `args` typed as `Parameters<T>`; returns `WorkflowHandleWithMetadata<T>` |
1011
+ | `getHandle(workflowId, runId?)` | Get a handle to an existing execution | Returns `WorkflowHandle<T>`; `result()` returns `Promise<WorkflowResultType<T>>` |
1012
+ | `signal(workflowId, signalDef, ...args)` | Send a typed signal | `args` typed from `SignalDefinition<TArgs>` |
1013
+ | `signalByName(workflowId, signalName, args?)` | Send a signal by string name | Fallback when no `SignalDefinition` is available |
1014
+ | `query(workflowId, queryDef, ...args)` | Query with a typed definition | Return type inferred from `QueryDefinition<TResult, TArgs>` |
1015
+ | `queryByName<TResult>(workflowId, queryName, args?)` | Query by string name | Caller specifies `TResult` |
1016
+ | `signalWithStart(signalDef, signalArgs, workflowArgs, options?)` | Atomic start + signal | Both arg lists fully typed |
1017
+
1018
+ [🔝 Back to top](#table-of-contents)
1019
+
1020
+ ### Signal-with-Start
1021
+
1022
+ `signalWithStart` atomically starts a workflow and sends it a signal in one operation. If the workflow is already running, only the signal is delivered — no duplicate start, no race condition.
1023
+
1024
+ Use it for **idempotent "ensure running + signal"** patterns, e.g. a cart that should be started on the first item-add and signaled on every subsequent one.
1025
+
1026
+ #### Via the typed proxy (recommended)
1027
+
1028
+ ```typescript
1029
+ // in workflows/cart.workflow.ts:
1030
+ // export const addItemSignal = defineSignal<[CartItem]>('addItem');
1031
+ // export async function cartWorkflow(userId: string) { ... }
1032
+
1033
+ await this.cartProxy.signalWithStart(
1034
+ addItemSignal,
1035
+ [{ sku: 'SKU-123', qty: 2 }], // signal args — typed from SignalDefinition
1036
+ [userId], // workflow args — typed as Parameters<typeof cartWorkflow>
1037
+ { workflowId: `cart-${userId}`, taskQueue: 'carts' },
1038
+ );
1039
+ ```
1040
+
1041
+ #### Via `TemporalService` (structured result)
1042
+
1043
+ ```typescript
1044
+ const result = await this.temporal.signalWithStart(
1045
+ 'cartWorkflow',
1046
+ 'addItem',
1047
+ [{ sku: 'SKU-123', qty: 2 }],
1048
+ [userId],
1049
+ { workflowId: `cart-${userId}`, taskQueue: 'carts' },
1050
+ );
1051
+
1052
+ if (result.success) {
1053
+ this.logger.log(`Signal '${result.signalName}' delivered to ${result.workflowId}`);
1054
+ }
1055
+ ```
1056
+
1057
+ #### Via `TemporalClientService` (raw handle)
1058
+
1059
+ ```typescript
1060
+ const handle = await this.clientService.signalWithStart(
1061
+ 'orderWorkflow',
1062
+ 'approve',
1063
+ ['manager-approval'],
1064
+ [orderId, customerId],
1065
+ {
1066
+ workflowId: `order-${orderId}`,
1067
+ taskQueue: 'orders',
1068
+ workflowIdReusePolicy: 'ALLOW_DUPLICATE',
1069
+ workflowExecutionTimeout: '1h',
1070
+ memo: { source: 'api' },
1071
+ },
1072
+ );
1073
+ ```
1074
+
1075
+ [🔝 Back to top](#table-of-contents)
1076
+
844
1077
  ## API Reference
845
1078
 
846
1079
  For detailed API documentation, visit the [Full API Documentation](https://harsh-simform.github.io/nestjs-temporal-core/).
@@ -852,6 +1085,7 @@ The main unified service providing access to all Temporal functionality. See the
852
1085
  Key methods:
853
1086
  - `startWorkflow()` - Start a workflow execution
854
1087
  - `signalWorkflow()` - Send a signal to a running workflow
1088
+ - `signalWithStart()` - Atomically start a workflow and send it a signal (see [Signal-with-Start](#signal-with-start))
855
1089
  - `queryWorkflow()` - Query a running workflow
856
1090
  - `getWorkflowHandle()` - Get a workflow handle to interact with it
857
1091
  - `terminateWorkflow()` - Terminate a workflow execution
@@ -861,6 +1095,17 @@ Key methods:
861
1095
  - `listSchedules()` - List all schedules
862
1096
  - `deleteSchedule()` - Delete a schedule
863
1097
 
1098
+ ### WorkflowProxyFactory
1099
+
1100
+ Creates typed `IWorkflowProxy<T>` instances. Registered globally by `TemporalModule`. See [Typed Workflow Proxy](#typed-workflow-proxy) for the full pattern.
1101
+
1102
+ - `createProxy<T>(config)` - Create a typed proxy for a workflow function type `T`
1103
+
1104
+ ### Proxy provider helpers
1105
+
1106
+ - `createWorkflowToken(workflowType)` - Generate a unique NestJS injection token for a workflow proxy
1107
+ - `createWorkflowProvider<T>(token, config)` - Build a `FactoryProvider` that resolves to `IWorkflowProxy<T>`
1108
+
864
1109
  [🔝 Back to top](#table-of-contents)
865
1110
 
866
1111
  ## Examples
@@ -1312,6 +1557,60 @@ const result = await temporal.registerWorker({
1312
1557
  });
1313
1558
  ```
1314
1559
 
1560
+ ### Migrating to v3.3.0 (Typed Workflow Proxy + Schedule fixes)
1561
+
1562
+ This release is **backward-compatible** — existing code continues to compile and run. The headline additions are a typed workflow proxy, `signalWithStart` on both service layers, and correctness fixes for a few schedule fields that were previously silently ignored.
1563
+
1564
+ #### No changes required
1565
+
1566
+ Every type that was previously exported is still exported with the same name. Old field shapes continue to compile:
1567
+
1568
+ - `spec.timezones?: string[]` on `ScheduleSpec` (deprecated — prefer SDK `timezone` singular, automatically normalized at runtime)
1569
+ - `action.retryPolicy?` on schedule actions (deprecated — prefer SDK `retry`, automatically forwarded)
1570
+ - `searchAttributes?: Record<string, unknown>` on `ScheduleCreationOptions`
1571
+ - `enableSDKTracing?` / `enableOpenTelemetry?` on `WorkerCreateOptions` (deprecated no-ops — had no effect in prior versions either)
1572
+
1573
+ #### Runtime behavior fixes
1574
+
1575
+ Three schedule fields were previously declared in the API but silently dropped by the SDK because of wrong field names or wrong shapes. They now work as the field name promises:
1576
+
1577
+ | Field | Before v3.3.0 | After v3.3.0 |
1578
+ |---|---|---|
1579
+ | `spec.timezone` on a schedule | Written to `spec.timeZone` (wrong casing) — SDK ignored it, schedules always ran in UTC | Routed to SDK's `timezone` — schedule honors the zone |
1580
+ | `description` on `createSchedule()` | Passed as a top-level field SDK ignored | Flows to `state.note` |
1581
+ | `searchAttributes` on `createSchedule()` | Cast to `typedSearchAttributes` with the wrong shape | Routed to the correct `searchAttributes` SDK field |
1582
+
1583
+ **Action**: if you had set `timezone` on a `@Scheduled` or `createSchedule()` call and configured your schedule times assuming UTC (because the timezone was being ignored), double-check your schedule timing after upgrade — the timezone will now actually apply.
1584
+
1585
+ `limitedActions` on `createSchedule()` remains a no-op for backward compatibility; set `state.remainingActions` directly via the SDK if you need that behavior.
1586
+
1587
+ #### New APIs in v3.3.0
1588
+
1589
+ ```typescript
1590
+ import {
1591
+ IWorkflowProxy,
1592
+ WorkflowProxyFactory,
1593
+ createWorkflowToken,
1594
+ createWorkflowProvider,
1595
+ } from 'nestjs-temporal-core';
1596
+
1597
+ // Typed proxy — see "Typed Workflow Proxy" section for the full pattern
1598
+ const ORDER_WORKFLOW = createWorkflowToken('orderWorkflow');
1599
+ const provider = createWorkflowProvider<typeof orderWorkflow>(ORDER_WORKFLOW, {
1600
+ workflowType: 'orderWorkflow',
1601
+ taskQueue: 'orders',
1602
+ });
1603
+
1604
+ // Atomic start + signal — see "Signal-with-Start" section
1605
+ await temporal.signalWithStart(
1606
+ 'cartWorkflow',
1607
+ 'addItem',
1608
+ [{ sku: 'SKU-123', qty: 2 }],
1609
+ [userId],
1610
+ { workflowId: `cart-${userId}`, taskQueue: 'carts' },
1611
+ );
1612
+ ```
1613
+
1315
1614
  [🔝 Back to top](#table-of-contents)
1316
1615
 
1317
1616
  ## Requirements
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export { TemporalWorkerManagerService } from './services/temporal-worker.service
9
9
  export { TemporalDiscoveryService } from './services/temporal-discovery.service';
10
10
  export { TemporalMetadataAccessor } from './services/temporal-metadata.service';
11
11
  export { TemporalScheduleService } from './services/temporal-schedule.service';
12
+ export { WorkflowProxyFactory, IWorkflowProxy, WorkflowProxy } from './workflow-proxy';
12
13
  export * from './utils';
13
14
  export * from './interfaces';
14
15
  export { DEFAULT_NAMESPACE, DEFAULT_TASK_QUEUE, DEFAULT_CONNECTION_TIMEOUT_MS, TEMPORAL_ACTIVITY, TEMPORAL_ACTIVITY_METHOD, TEMPORAL_SIGNAL_METHOD, TEMPORAL_QUERY_METHOD, WORKFLOW_PARAMS_METADATA, TEMPORAL_CLIENT, TEMPORAL_MODULE_OPTIONS, TEMPORAL_CONNECTION, TIMEOUTS, RETRY_POLICIES, } from './constants';
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.RETRY_POLICIES = exports.TIMEOUTS = exports.TEMPORAL_CONNECTION = exports.TEMPORAL_MODULE_OPTIONS = exports.TEMPORAL_CLIENT = exports.WORKFLOW_PARAMS_METADATA = exports.TEMPORAL_QUERY_METHOD = exports.TEMPORAL_SIGNAL_METHOD = exports.TEMPORAL_ACTIVITY_METHOD = exports.TEMPORAL_ACTIVITY = exports.DEFAULT_CONNECTION_TIMEOUT_MS = exports.DEFAULT_TASK_QUEUE = exports.DEFAULT_NAMESPACE = exports.TemporalScheduleService = exports.TemporalMetadataAccessor = exports.TemporalDiscoveryService = exports.TemporalWorkerManagerService = exports.TemporalClientService = exports.TemporalService = exports.TemporalHealthController = exports.TemporalHealthModule = exports.TemporalModule = void 0;
17
+ exports.RETRY_POLICIES = exports.TIMEOUTS = exports.TEMPORAL_CONNECTION = exports.TEMPORAL_MODULE_OPTIONS = exports.TEMPORAL_CLIENT = exports.WORKFLOW_PARAMS_METADATA = exports.TEMPORAL_QUERY_METHOD = exports.TEMPORAL_SIGNAL_METHOD = exports.TEMPORAL_ACTIVITY_METHOD = exports.TEMPORAL_ACTIVITY = exports.DEFAULT_CONNECTION_TIMEOUT_MS = exports.DEFAULT_TASK_QUEUE = exports.DEFAULT_NAMESPACE = exports.WorkflowProxy = exports.WorkflowProxyFactory = exports.TemporalScheduleService = exports.TemporalMetadataAccessor = exports.TemporalDiscoveryService = exports.TemporalWorkerManagerService = exports.TemporalClientService = exports.TemporalService = exports.TemporalHealthController = exports.TemporalHealthModule = exports.TemporalModule = void 0;
18
18
  require("reflect-metadata");
19
19
  __exportStar(require("./decorators"), exports);
20
20
  var temporal_module_1 = require("./temporal.module");
@@ -35,6 +35,9 @@ var temporal_metadata_service_1 = require("./services/temporal-metadata.service"
35
35
  Object.defineProperty(exports, "TemporalMetadataAccessor", { enumerable: true, get: function () { return temporal_metadata_service_1.TemporalMetadataAccessor; } });
36
36
  var temporal_schedule_service_1 = require("./services/temporal-schedule.service");
37
37
  Object.defineProperty(exports, "TemporalScheduleService", { enumerable: true, get: function () { return temporal_schedule_service_1.TemporalScheduleService; } });
38
+ var workflow_proxy_1 = require("./workflow-proxy");
39
+ Object.defineProperty(exports, "WorkflowProxyFactory", { enumerable: true, get: function () { return workflow_proxy_1.WorkflowProxyFactory; } });
40
+ Object.defineProperty(exports, "WorkflowProxy", { enumerable: true, get: function () { return workflow_proxy_1.WorkflowProxy; } });
38
41
  __exportStar(require("./utils"), exports);
39
42
  __exportStar(require("./interfaces"), exports);
40
43
  var constants_1 = require("./constants");
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4BAA0B;AAE1B,+CAA6B;AAG7B,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AAGvB,0EAAuE;AAA9D,8HAAA,oBAAoB,OAAA;AAC7B,kFAA+E;AAAtE,sIAAA,wBAAwB,OAAA;AAGjC,gEAA8D;AAArD,mHAAA,eAAe,OAAA;AAGxB,8EAA2E;AAAlE,gIAAA,qBAAqB,OAAA;AAG9B,8EAAkF;AAAzE,uIAAA,4BAA4B,OAAA;AAGrC,oFAAiF;AAAxE,sIAAA,wBAAwB,OAAA;AAGjC,kFAAgF;AAAvE,qIAAA,wBAAwB,OAAA;AAGjC,kFAA+E;AAAtE,oIAAA,uBAAuB,OAAA;AAGhC,0CAAwB;AAGxB,+CAA6B;AAG7B,yCAcqB;AAbjB,8GAAA,iBAAiB,OAAA;AACjB,+GAAA,kBAAkB,OAAA;AAClB,0HAAA,6BAA6B,OAAA;AAC7B,8GAAA,iBAAiB,OAAA;AACjB,qHAAA,wBAAwB,OAAA;AACxB,mHAAA,sBAAsB,OAAA;AACtB,kHAAA,qBAAqB,OAAA;AACrB,qHAAA,wBAAwB,OAAA;AACxB,4GAAA,eAAe,OAAA;AACf,oHAAA,uBAAuB,OAAA;AACvB,gHAAA,mBAAmB,OAAA;AACnB,qGAAA,QAAQ,OAAA;AACR,2GAAA,cAAc,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4BAA0B;AAE1B,+CAA6B;AAG7B,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AAGvB,0EAAuE;AAA9D,8HAAA,oBAAoB,OAAA;AAC7B,kFAA+E;AAAtE,sIAAA,wBAAwB,OAAA;AAGjC,gEAA8D;AAArD,mHAAA,eAAe,OAAA;AAGxB,8EAA2E;AAAlE,gIAAA,qBAAqB,OAAA;AAG9B,8EAAkF;AAAzE,uIAAA,4BAA4B,OAAA;AAGrC,oFAAiF;AAAxE,sIAAA,wBAAwB,OAAA;AAGjC,kFAAgF;AAAvE,qIAAA,wBAAwB,OAAA;AAGjC,kFAA+E;AAAtE,oIAAA,uBAAuB,OAAA;AAGhC,mDAAuF;AAA9E,sHAAA,oBAAoB,OAAA;AAAkB,+GAAA,aAAa,OAAA;AAG5D,0CAAwB;AAGxB,+CAA6B;AAG7B,yCAcqB;AAbjB,8GAAA,iBAAiB,OAAA;AACjB,+GAAA,kBAAkB,OAAA;AAClB,0HAAA,6BAA6B,OAAA;AAC7B,8GAAA,iBAAiB,OAAA;AACjB,qHAAA,wBAAwB,OAAA;AACxB,mHAAA,sBAAsB,OAAA;AACtB,kHAAA,qBAAqB,OAAA;AACrB,qHAAA,wBAAwB,OAAA;AACxB,4GAAA,eAAe,OAAA;AACf,oHAAA,uBAAuB,OAAA;AACvB,gHAAA,mBAAmB,OAAA;AACnB,qGAAA,QAAQ,OAAA;AACR,2GAAA,cAAc,OAAA"}
@@ -1,11 +1,17 @@
1
1
  export { RetryPolicy, Duration, SearchAttributes } from '@temporalio/common';
2
- export { WorkflowHandle, Client, ConnectionOptions as TemporalConnectionOptions, } from '@temporalio/client';
2
+ export { WorkflowHandle, Client, ConnectionOptions as TemporalConnectionOptions, WorkflowIdReusePolicy, } from '@temporalio/client';
3
3
  export { Worker } from '@temporalio/worker';
4
+ export type { Workflow, WorkflowResultType } from '@temporalio/workflow';
4
5
  import { Type } from '@nestjs/common';
5
- import { ScheduleClient, ScheduleHandle } from '@temporalio/client';
6
- import { NativeConnection, Worker } from '@temporalio/worker';
7
- import { Duration, TypedSearchAttributes } from '@temporalio/common';
6
+ import { ScheduleClient, ScheduleHandle, WorkflowHandle, WorkflowIdReusePolicy, ScheduleOptions as SdkScheduleOptions, ScheduleSpec as SdkScheduleSpec, ScheduleOptionsAction, ScheduleOptionsStartWorkflowAction, ScheduleDescription as SdkScheduleDescription } from '@temporalio/client';
7
+ import { NativeConnection, Worker, WorkerOptions, WorkflowBundleOption } from '@temporalio/worker';
8
+ import { Duration, RetryPolicy, TypedSearchAttributes } from '@temporalio/common';
8
9
  import { TLSConfig } from '@temporalio/common/lib/internal-non-workflow';
10
+ import type { Workflow } from '@temporalio/workflow';
11
+ export interface WorkflowProxyConfig {
12
+ workflowType: string;
13
+ taskQueue?: string;
14
+ }
9
15
  export interface ClientConnectionOptions {
10
16
  address: string;
11
17
  tls?: boolean | TLSConfig;
@@ -23,7 +29,7 @@ export interface RetryPolicyConfig {
23
29
  export interface WorkerDefinition {
24
30
  taskQueue: string;
25
31
  workflowsPath?: string;
26
- workflowBundle?: Record<string, unknown>;
32
+ workflowBundle?: WorkflowBundleOption | Record<string, unknown>;
27
33
  activityClasses?: Array<Type<object>>;
28
34
  autoStart?: boolean;
29
35
  autoRestart?: boolean;
@@ -41,7 +47,7 @@ export interface TemporalOptions extends LoggerConfig {
41
47
  taskQueue?: string;
42
48
  worker?: {
43
49
  workflowsPath?: string;
44
- workflowBundle?: Record<string, unknown>;
50
+ workflowBundle?: WorkflowBundleOption | Record<string, unknown>;
45
51
  activityClasses?: Array<Type<object>>;
46
52
  autoStart?: boolean;
47
53
  autoRestart?: boolean;
@@ -56,43 +62,10 @@ export interface TemporalOptions extends LoggerConfig {
56
62
  enableShutdownHooks?: boolean;
57
63
  shutdownTimeout?: number;
58
64
  }
59
- export interface WorkerCreateOptions {
60
- identity?: string;
61
- buildId?: string;
62
- useVersioning?: boolean;
63
- workerDeploymentOptions?: Record<string, unknown>;
64
- shutdownGraceTime?: string | number;
65
- shutdownForceTime?: string | number;
66
- dataConverter?: Record<string, unknown>;
67
- tuner?: Record<string, unknown>;
68
- maxConcurrentActivityTaskExecutions?: number;
69
- maxConcurrentLocalActivityExecutions?: number;
70
- maxConcurrentActivityTaskPolls?: number;
71
- enableNonLocalActivities?: boolean;
72
- maxActivitiesPerSecond?: number;
73
- maxTaskQueueActivitiesPerSecond?: number;
74
- maxConcurrentWorkflowTaskExecutions?: number;
75
- maxConcurrentWorkflowTaskPolls?: number;
76
- nonStickyToStickyPollRatio?: number;
77
- maxCachedWorkflows?: number;
78
- stickyQueueScheduleToStartTimeout?: string | number;
79
- workflowThreadPoolSize?: number;
80
- reuseV8Context?: boolean;
81
- maxHeartbeatThrottleInterval?: string | number;
82
- defaultHeartbeatThrottleInterval?: string | number;
83
- debugMode?: boolean;
84
- enableLoggingInReplay?: boolean;
85
- showStackTraceSources?: boolean;
86
- interceptors?: {
87
- activityInbound?: unknown[];
88
- activity?: unknown[];
89
- workflowModules?: string[];
90
- };
91
- sinks?: Record<string, unknown>;
92
- bundlerOptions?: Record<string, unknown>;
65
+ export type WorkerCreateOptions = Omit<WorkerOptions, 'connection' | 'taskQueue' | 'activities' | 'workflowsPath' | 'workflowBundle' | 'namespace'> & {
93
66
  enableSDKTracing?: boolean;
94
67
  enableOpenTelemetry?: boolean;
95
- }
68
+ };
96
69
  export interface WorkerModuleOptions {
97
70
  connection?: {
98
71
  address?: string;
@@ -303,35 +276,27 @@ export interface ActivityContext {
303
276
  executionId?: string;
304
277
  timestamp?: Date;
305
278
  }
306
- export interface ScheduleSpec {
279
+ export type ScheduleSpec = Omit<SdkScheduleSpec, 'intervals' | 'jitter'> & {
307
280
  intervals?: Array<{
308
- every: string | number;
281
+ every: Duration | string | number;
282
+ offset?: Duration | string | number;
309
283
  }>;
310
- cronExpressions?: string[];
284
+ jitter?: Duration | string | number;
311
285
  timezones?: string[];
312
- startAt?: Date;
313
- endAt?: Date;
314
- jitter?: string | number;
315
- }
316
- export interface ScheduleAction {
317
- type: 'startWorkflow';
318
- workflowType: string;
319
- args?: unknown[];
320
- taskQueue: string;
321
- workflowId?: string;
322
- workflowExecutionTimeout?: Duration;
323
- workflowRunTimeout?: Duration;
324
- workflowTaskTimeout?: Duration;
325
- }
286
+ };
287
+ export type ScheduleAction = ScheduleOptionsAction & {
288
+ retryPolicy?: RetryPolicy | Record<string, unknown>;
289
+ };
326
290
  export interface WorkflowStartOptions {
327
291
  workflowId?: string;
328
292
  taskQueue?: string;
329
293
  searchAttributes?: TypedSearchAttributes;
330
- memo?: Record<string, string | number | boolean | object>;
331
- workflowIdReusePolicy?: 'ALLOW_DUPLICATE' | 'ALLOW_DUPLICATE_FAILED_ONLY' | 'REJECT_DUPLICATE';
294
+ memo?: Record<string, unknown>;
295
+ workflowIdReusePolicy?: WorkflowIdReusePolicy;
332
296
  workflowExecutionTimeout?: Duration;
333
297
  workflowRunTimeout?: Duration;
334
298
  workflowTaskTimeout?: Duration;
299
+ retryPolicy?: RetryPolicy;
335
300
  }
336
301
  export type HealthStatus = 'healthy' | 'unhealthy' | 'degraded';
337
302
  export interface ServiceHealth {
@@ -377,8 +342,8 @@ export interface WorkflowSignalConfig {
377
342
  name: string;
378
343
  args?: unknown[];
379
344
  }
380
- export type WorkflowHandleWithMetadata = import('@temporalio/client').WorkflowHandle & {
381
- handle: import('@temporalio/client').WorkflowHandle;
345
+ export type WorkflowHandleWithMetadata<T extends Workflow = Workflow> = WorkflowHandle<T> & {
346
+ handle: WorkflowHandle<T>;
382
347
  };
383
348
  export interface ClientServiceStatus {
384
349
  available: boolean;
@@ -396,20 +361,7 @@ export interface GenericClient {
396
361
  getHandle: (id: string, runId?: string) => import('@temporalio/client').WorkflowHandle;
397
362
  };
398
363
  }
399
- export interface ScheduleDescription {
400
- spec: ScheduleSpec;
401
- action: ScheduleAction;
402
- policies: {
403
- overlap: TemporalOverlapPolicy;
404
- catchupWindow: number;
405
- pauseOnFailure: boolean;
406
- };
407
- state: {
408
- paused: boolean;
409
- note?: string;
410
- remainingActions?: number;
411
- };
412
- }
364
+ export type ScheduleDescription = SdkScheduleDescription;
413
365
  export interface DiscoveryServiceStats {
414
366
  methods: number;
415
367
  activities: number;
@@ -626,17 +578,19 @@ export interface ScheduleWorkflowOptions {
626
578
  workflowExecutionTimeout?: Duration;
627
579
  workflowRunTimeout?: Duration;
628
580
  workflowTaskTimeout?: Duration;
629
- retryPolicy?: Record<string, unknown>;
581
+ retryPolicy?: RetryPolicy | Record<string, unknown>;
630
582
  args?: unknown[];
631
583
  }
632
584
  export interface ScheduleSpecBuilderResult {
633
585
  success: boolean;
634
- spec?: Record<string, unknown>;
586
+ spec?: Partial<ScheduleSpec>;
635
587
  error?: Error;
636
588
  }
637
589
  export interface ScheduleIntervalParseResult {
638
590
  success: boolean;
639
- interval?: Record<string, unknown>;
591
+ interval?: {
592
+ every: Duration;
593
+ };
640
594
  error?: Error;
641
595
  }
642
596
  export interface TemporalConnection {
@@ -645,24 +599,10 @@ export interface TemporalConnection {
645
599
  tls?: boolean | object;
646
600
  metadata?: Record<string, string>;
647
601
  }
648
- export interface ScheduleWorkflowAction {
649
- type: 'startWorkflow';
650
- workflowType: string;
651
- taskQueue: string;
652
- args?: unknown[];
653
- workflowId?: string;
654
- workflowExecutionTimeout?: Duration;
655
- workflowRunTimeout?: Duration;
656
- workflowTaskTimeout?: Duration;
657
- retryPolicy?: Record<string, unknown>;
658
- }
659
- export interface ScheduleOptions {
660
- scheduleId: string;
661
- spec: Record<string, unknown>;
662
- action: ScheduleWorkflowAction;
663
- memo?: Record<string, unknown>;
664
- searchAttributes?: Record<string, unknown>;
665
- }
602
+ export type ScheduleWorkflowAction = ScheduleOptionsStartWorkflowAction<Workflow> & {
603
+ retryPolicy?: RetryPolicy | Record<string, unknown>;
604
+ };
605
+ export type ScheduleOptions = SdkScheduleOptions;
666
606
  export interface WorkerConnectionOptions {
667
607
  address: string;
668
608
  tls?: boolean | object;
@@ -670,16 +610,11 @@ export interface WorkerConnectionOptions {
670
610
  apiKey?: string;
671
611
  namespace?: string;
672
612
  }
673
- export interface WorkerConfig {
674
- taskQueue: string;
613
+ export type WorkerConfig = WorkerOptions & {
675
614
  namespace: string;
676
615
  connection: NativeConnection;
677
616
  activities: Record<string, Function>;
678
- workflowsPath?: string;
679
- workflowBundle?: unknown;
680
- workerOptions?: Record<string, unknown>;
681
- [key: string]: unknown;
682
- }
617
+ };
683
618
  export interface WorkerInitResult {
684
619
  success: boolean;
685
620
  worker?: Worker;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Worker = exports.Client = void 0;
3
+ exports.Worker = exports.WorkflowIdReusePolicy = exports.Client = void 0;
4
4
  var client_1 = require("@temporalio/client");
5
5
  Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
6
+ Object.defineProperty(exports, "WorkflowIdReusePolicy", { enumerable: true, get: function () { return client_1.WorkflowIdReusePolicy; } });
6
7
  var worker_1 = require("@temporalio/worker");
7
8
  Object.defineProperty(exports, "Worker", { enumerable: true, get: function () { return worker_1.Worker; } });
8
9
  //# sourceMappingURL=interfaces.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;;AACA,6CAI4B;AAFxB,gGAAA,MAAM,OAAA;AAGV,6CAA4C;AAAnC,gGAAA,MAAM,OAAA"}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;;AACA,6CAK4B;AAHxB,gGAAA,MAAM,OAAA;AAEN,+GAAA,qBAAqB,OAAA;AAEzB,6CAA4C;AAAnC,gGAAA,MAAM,OAAA"}
@@ -11,14 +11,15 @@ export declare class TemporalClientService implements OnModuleInit {
11
11
  private healthCheckInterval;
12
12
  constructor(temporalClient: Client | null, options: TemporalOptions);
13
13
  onModuleInit(): Promise<void>;
14
- startWorkflow(workflowType: string, args?: unknown[], options?: WorkflowStartOptions): Promise<WorkflowHandleWithMetadata>;
14
+ startWorkflow(workflowType: string, args?: readonly unknown[], options?: WorkflowStartOptions): Promise<WorkflowHandleWithMetadata>;
15
15
  getWorkflowHandle(workflowId: string, runId?: string): Promise<WorkflowHandle>;
16
16
  terminateWorkflow(workflowId: string, reason?: string, runId?: string): Promise<void>;
17
17
  cancelWorkflow(workflowId: string, runId?: string): Promise<void>;
18
- signalWorkflow(workflowId: string, signalName: string, args?: unknown[], runId?: string): Promise<void>;
19
- signalWorkflowHandle(handle: WorkflowHandle, signalName: string, args?: unknown[]): Promise<void>;
20
- queryWorkflow<T = unknown>(workflowId: string, queryName: string, args?: unknown[], runId?: string): Promise<T>;
21
- queryWorkflowHandle<T = unknown>(handle: WorkflowHandle, queryName: string, args?: unknown[]): Promise<T>;
18
+ signalWorkflow(workflowId: string, signalName: string, args?: readonly unknown[], runId?: string): Promise<void>;
19
+ signalWorkflowHandle(handle: WorkflowHandle, signalName: string, args?: readonly unknown[]): Promise<void>;
20
+ signalWithStart(workflowType: string, signalName: string, signalArgs: readonly unknown[], workflowArgs: readonly unknown[], options?: WorkflowStartOptions): Promise<WorkflowHandleWithMetadata>;
21
+ queryWorkflow<T = unknown>(workflowId: string, queryName: string, args?: readonly unknown[], runId?: string): Promise<T>;
22
+ queryWorkflowHandle<T = unknown>(handle: WorkflowHandle, queryName: string, args?: readonly unknown[]): Promise<T>;
22
23
  getWorkflowResult<T = unknown>(workflowId: string, runId?: string): Promise<T>;
23
24
  isHealthy(): boolean;
24
25
  getHealth(): ClientHealthStatus;