@hatchet-dev/typescript-sdk 1.16.0 → 1.17.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.
Files changed (94) hide show
  1. package/README.md +14 -2
  2. package/clients/admin/admin-client.d.ts +2 -2
  3. package/clients/dispatcher/action-listener.d.ts +3 -6
  4. package/clients/dispatcher/action-listener.js +12 -17
  5. package/clients/listeners/durable-listener/durable-listener-client.d.ts +115 -15
  6. package/clients/listeners/durable-listener/durable-listener-client.js +769 -19
  7. package/clients/listeners/durable-listener/pooled-durable-listener-client.js +1 -14
  8. package/clients/listeners/run-listener/pooled-child-listener-client.js +1 -14
  9. package/clients/rest/generated/Api.d.ts +5 -1
  10. package/clients/rest/generated/data-contracts.d.ts +16 -2
  11. package/clients/rest/generated/data-contracts.js +7 -3
  12. package/legacy/examples/affinity-workers.js +2 -2
  13. package/legacy/legacy-client.js +1 -1
  14. package/legacy/step.d.ts +2 -2
  15. package/legacy/step.js +3 -2
  16. package/legacy/workflow.d.ts +25 -25
  17. package/package.json +1 -1
  18. package/protoc/dispatcher/dispatcher.d.ts +20 -0
  19. package/protoc/dispatcher/dispatcher.js +136 -2
  20. package/protoc/v1/dispatcher.d.ts +168 -0
  21. package/protoc/v1/dispatcher.js +1920 -1
  22. package/protoc/v1/shared/trigger.d.ts +89 -0
  23. package/protoc/v1/shared/trigger.js +493 -0
  24. package/protoc/v1/workflows.d.ts +34 -34
  25. package/protoc/v1/workflows.js +252 -200
  26. package/protoc/workflows/workflows.d.ts +2 -75
  27. package/protoc/workflows/workflows.js +16 -491
  28. package/util/abort-error.d.ts +10 -0
  29. package/util/abort-error.js +15 -0
  30. package/util/errors/eviction-not-supported-error.d.ts +5 -0
  31. package/util/errors/eviction-not-supported-error.js +18 -0
  32. package/util/errors/non-determinism-error.d.ts +7 -0
  33. package/util/errors/non-determinism-error.js +21 -0
  34. package/util/errors/task-run-terminated-error.d.ts +6 -0
  35. package/util/errors/task-run-terminated-error.js +15 -0
  36. package/util/hatchet-promise/hatchet-promise.d.ts +2 -1
  37. package/util/hatchet-promise/hatchet-promise.js +10 -1
  38. package/util/sleep.d.ts +3 -2
  39. package/util/sleep.js +6 -4
  40. package/v1/client/admin.d.ts +2 -2
  41. package/v1/client/client.js +1 -1
  42. package/v1/client/duration.d.ts +11 -1
  43. package/v1/client/duration.js +44 -0
  44. package/v1/client/features/runs.d.ts +16 -3
  45. package/v1/client/features/runs.js +38 -3
  46. package/v1/client/worker/context.d.ts +101 -6
  47. package/v1/client/worker/context.js +247 -21
  48. package/v1/client/worker/deprecated/index.d.ts +1 -1
  49. package/v1/client/worker/deprecated/index.js +2 -1
  50. package/v1/client/worker/deprecated/legacy-worker.d.ts +5 -0
  51. package/v1/client/worker/deprecated/legacy-worker.js +32 -23
  52. package/v1/client/worker/deprecated/pre-eviction.d.ts +12 -0
  53. package/v1/client/worker/deprecated/pre-eviction.js +37 -0
  54. package/v1/client/worker/engine-version.d.ts +5 -0
  55. package/v1/client/worker/engine-version.js +14 -0
  56. package/v1/client/worker/eviction/eviction-cache.d.ts +33 -0
  57. package/v1/client/worker/eviction/eviction-cache.js +139 -0
  58. package/v1/client/worker/eviction/eviction-manager.d.ts +42 -0
  59. package/v1/client/worker/eviction/eviction-manager.js +132 -0
  60. package/v1/client/worker/eviction/eviction-policy.d.ts +19 -0
  61. package/v1/client/worker/eviction/eviction-policy.js +8 -0
  62. package/v1/client/worker/eviction/index.d.ts +3 -0
  63. package/v1/client/worker/eviction/index.js +11 -0
  64. package/v1/client/worker/worker-internal.d.ts +23 -4
  65. package/v1/client/worker/worker-internal.js +177 -138
  66. package/v1/client/worker/worker.d.ts +1 -0
  67. package/v1/client/worker/worker.js +34 -1
  68. package/v1/conditions/sleep-condition.js +2 -1
  69. package/v1/conditions/transformer.js +2 -1
  70. package/v1/declaration.d.ts +5 -3
  71. package/v1/declaration.js +8 -0
  72. package/v1/examples/__e2e__/harness.d.ts +5 -0
  73. package/v1/examples/__e2e__/harness.js +13 -0
  74. package/v1/examples/concurrency_workflow_level/workflow.d.ts +1 -1
  75. package/v1/examples/concurrency_workflow_level/workflow.js +1 -1
  76. package/v1/examples/durable/workflow.d.ts +57 -0
  77. package/v1/examples/durable/workflow.js +162 -7
  78. package/v1/examples/durable-event/workflow.js +2 -7
  79. package/v1/examples/durable_event/workflow.d.ts +1 -0
  80. package/v1/examples/durable_event/workflow.js +4 -9
  81. package/v1/examples/durable_eviction/capacity-worker.d.ts +1 -0
  82. package/v1/examples/durable_eviction/capacity-worker.js +31 -0
  83. package/v1/examples/durable_eviction/worker.d.ts +1 -0
  84. package/v1/examples/durable_eviction/worker.js +34 -0
  85. package/v1/examples/durable_eviction/workflow.d.ts +44 -0
  86. package/v1/examples/durable_eviction/workflow.js +129 -0
  87. package/v1/examples/e2e-worker.js +42 -19
  88. package/v1/index.d.ts +5 -0
  89. package/v1/index.js +10 -0
  90. package/v1/parent-run-context-vars.d.ts +6 -0
  91. package/v1/task.d.ts +10 -2
  92. package/v1/task.js +2 -1
  93. package/version.d.ts +1 -1
  94. package/version.js +1 -1
package/README.md CHANGED
@@ -63,9 +63,21 @@ pnpm install
63
63
  pnpm build
64
64
  ```
65
65
 
66
- 3. Run tests:
66
+ 3. Run unit tests:
67
67
  ```bash
68
- pnpm test
68
+ pnpm test:unit
69
+ ```
70
+
71
+ 4. Run e2e tests (requires a running Hatchet engine):
72
+ ```bash
73
+ # Run all e2e tests
74
+ pnpm test:e2e
75
+
76
+ # Run a specific e2e test file
77
+ pnpm test:e2e durable.e2e.ts
78
+
79
+ # Run a specific test by name
80
+ pnpm test:e2e durable.e2e.ts -t "durable replay reset"
69
81
  ```
70
82
 
71
83
  ## Contributing
@@ -1,10 +1,10 @@
1
1
  import { Channel, ClientFactory } from 'nice-grpc';
2
- import { CreateWorkflowVersionOpts, RateLimitDuration, WorkerLabelComparator, WorkflowServiceClient } from '../../protoc/workflows';
2
+ import { CreateWorkflowVersionOpts, RateLimitDuration, WorkflowServiceClient } from '../../protoc/workflows';
3
3
  import { ClientConfig } from '../hatchet-client/client-config';
4
4
  import { Logger } from '../../util/logger';
5
5
  import WorkflowRunRef from '../../util/workflow-run-ref';
6
6
  import { AdminServiceClient, CreateWorkflowVersionRequest } from '../../protoc/v1/workflows';
7
- import { Priority, RunsClient } from '../../v1';
7
+ import { Priority, RunsClient, WorkerLabelComparator } from '../../v1';
8
8
  import { Api } from '../rest';
9
9
  import { WebhookWorkerCreateRequest, WorkflowRunStatus, WorkflowRunStatusList } from '../rest/generated/data-contracts';
10
10
  import { RunListenerClient } from '../listeners/run-listener/child-listener-client';
@@ -7,14 +7,11 @@ declare enum ListenStrategy {
7
7
  LISTEN_STRATEGY_V1 = 1,
8
8
  LISTEN_STRATEGY_V2 = 2
9
9
  }
10
+ export type ActionKey = `${string}/${number}`;
10
11
  export type Action = AssignedAction & {
11
- /** @deprecated use taskRunId */
12
- stepRunId?: string;
13
- /** @deprecated use taskId */
14
- stepId?: string;
12
+ readonly key: ActionKey;
15
13
  };
16
- export type ActionKey = string;
17
- export declare function createActionKey(action: Action): ActionKey;
14
+ export declare function createAction(assignedAction: AssignedAction): Action;
18
15
  export declare class ActionListener {
19
16
  config: ClientConfig;
20
17
  client: PbDispatcherClient;
@@ -66,8 +66,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
66
66
  };
67
67
  Object.defineProperty(exports, "__esModule", { value: true });
68
68
  exports.ActionListener = void 0;
69
- exports.createActionKey = createActionKey;
70
- const dispatcher_1 = require("../../protoc/dispatcher");
69
+ exports.createAction = createAction;
71
70
  const nice_grpc_1 = require("nice-grpc");
72
71
  const grpc_error_1 = require("../../util/grpc-error");
73
72
  const abort_controller_x_1 = require("abort-controller-x");
@@ -81,19 +80,16 @@ var ListenStrategy;
81
80
  ListenStrategy[ListenStrategy["LISTEN_STRATEGY_V1"] = 1] = "LISTEN_STRATEGY_V1";
82
81
  ListenStrategy[ListenStrategy["LISTEN_STRATEGY_V2"] = 2] = "LISTEN_STRATEGY_V2";
83
82
  })(ListenStrategy || (ListenStrategy = {}));
84
- function createActionKey(action) {
85
- switch (action.actionType) {
86
- case dispatcher_1.ActionType.START_GET_GROUP_KEY:
87
- return `${action.getGroupKeyRunId}/${action.retryCount}`;
88
- case dispatcher_1.ActionType.CANCEL_STEP_RUN:
89
- case dispatcher_1.ActionType.START_STEP_RUN:
90
- case dispatcher_1.ActionType.UNRECOGNIZED:
91
- return `${action.taskRunExternalId}/${action.retryCount}`;
92
- default:
93
- // eslint-disable-next-line no-case-declarations
94
- const exhaustivenessCheck = action.actionType;
95
- throw new Error(`Unhandled action type: ${exhaustivenessCheck}`);
96
- }
83
+ function createAction(assignedAction) {
84
+ const action = assignedAction;
85
+ Object.defineProperty(action, 'key', {
86
+ get() {
87
+ return `${this.taskRunExternalId}/${this.retryCount}`;
88
+ },
89
+ enumerable: true,
90
+ configurable: true,
91
+ });
92
+ return action;
97
93
  }
98
94
  class ActionListener {
99
95
  constructor(client, workerId, retryInterval = DEFAULT_ACTION_LISTENER_RETRY_INTERVAL, retryCount = DEFAULT_ACTION_LISTENER_RETRY_COUNT) {
@@ -117,8 +113,7 @@ class ActionListener {
117
113
  _c = listenClient_1_1.value;
118
114
  _d = false;
119
115
  const assignedAction = _c;
120
- const action = Object.assign(Object.assign({}, assignedAction), { stepRunId: assignedAction.taskRunExternalId, stepId: assignedAction.taskId });
121
- yield yield __await(action);
116
+ yield yield __await(createAction(assignedAction));
122
117
  }
123
118
  }
124
119
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -1,31 +1,131 @@
1
+ import { EventEmitter } from 'events';
1
2
  import { Channel, ClientFactory } from 'nice-grpc';
2
3
  import { ClientConfig } from '../../hatchet-client/client-config';
3
4
  import { Logger } from '../../../util/logger';
4
- import { V1DispatcherClient } from '../../../protoc/v1/dispatcher';
5
- import { SleepMatchCondition, UserEventMatchCondition } from '../../../protoc/v1/shared/condition';
6
- import { Api } from '../../rest';
7
- import { DurableEventGrpcPooledListener } from './pooled-durable-listener-client';
5
+ import { V1DispatcherClient, DurableEvent, RegisterDurableEventResponse } from '../../../protoc/v1/dispatcher';
6
+ import { DurableEventListenerConditions, SleepMatchCondition, UserEventMatchCondition } from '../../../protoc/v1/shared/condition';
7
+ import { TriggerWorkflowRequest } from '../../../protoc/v1/shared/trigger';
8
+ export interface DurableTaskRunAckEntryResult {
9
+ nodeId: number;
10
+ branchId: number;
11
+ }
12
+ export interface DurableTaskEventRunAck {
13
+ ackType: 'run';
14
+ invocationCount: number;
15
+ durableTaskExternalId: string;
16
+ runEntries: DurableTaskRunAckEntryResult[];
17
+ }
18
+ export interface DurableTaskEventMemoAck {
19
+ ackType: 'memo';
20
+ invocationCount: number;
21
+ durableTaskExternalId: string;
22
+ branchId: number;
23
+ nodeId: number;
24
+ memoAlreadyExisted: boolean;
25
+ memoResultPayload?: Uint8Array;
26
+ }
27
+ export interface DurableTaskEventWaitForAck {
28
+ ackType: 'waitFor';
29
+ invocationCount: number;
30
+ durableTaskExternalId: string;
31
+ branchId: number;
32
+ nodeId: number;
33
+ }
34
+ export type DurableTaskEventAck = DurableTaskEventRunAck | DurableTaskEventMemoAck | DurableTaskEventWaitForAck;
35
+ export interface DurableTaskEventLogEntryResult {
36
+ durableTaskExternalId: string;
37
+ nodeId: number;
38
+ payload: Record<string, unknown> | undefined;
39
+ }
40
+ export interface WaitForEvent {
41
+ kind: 'waitFor';
42
+ waitForConditions: DurableEventListenerConditions;
43
+ }
44
+ export interface RunChildrenEvent {
45
+ kind: 'runChildren';
46
+ triggerOpts: TriggerWorkflowRequest[];
47
+ }
48
+ export interface MemoEvent {
49
+ kind: 'memo';
50
+ memoKey: Uint8Array;
51
+ payload?: Uint8Array;
52
+ }
53
+ export type DurableTaskSendEvent = WaitForEvent | RunChildrenEvent | MemoEvent;
8
54
  export declare class DurableListenerClient {
9
55
  config: ClientConfig;
10
56
  client: V1DispatcherClient;
11
57
  logger: Logger;
12
- api: Api;
13
- pooledListener: DurableEventGrpcPooledListener | undefined;
14
- constructor(config: ClientConfig, channel: Channel, factory: ClientFactory, api: Api);
58
+ private _workerId;
59
+ private _running;
60
+ private _requestQueue;
61
+ private _requestNotify;
62
+ private _pendingEventAcks;
63
+ private _pendingCallbacks;
64
+ private _bufferedCompletions;
65
+ private _pendingEvictionAcks;
66
+ private _receiveAbort;
67
+ private _statusInterval;
68
+ private _startLock;
69
+ onServerEvict: ((durableTaskExternalId: string, invocationCount: number) => void) | undefined;
70
+ constructor(config: ClientConfig, channel: Channel, factory: ClientFactory);
71
+ get workerId(): string | undefined;
72
+ start(workerId: string): Promise<void>;
73
+ private _doStart;
74
+ ensureStarted(workerId: string): Promise<void>;
75
+ stop(): Promise<void>;
76
+ private _connect;
77
+ private _streamLoop;
78
+ private _requestIterator;
79
+ private _enqueueRequest;
80
+ private _startStatusPolling;
81
+ private _pollWorkerStatus;
82
+ private _failPendingAcks;
83
+ private _failAllPending;
84
+ private _handleResponse;
85
+ sendEvent(durableTaskExternalId: string, invocationCount: number, event: RunChildrenEvent): Promise<DurableTaskEventRunAck>;
86
+ sendEvent(durableTaskExternalId: string, invocationCount: number, event: WaitForEvent): Promise<DurableTaskEventWaitForAck>;
87
+ sendEvent(durableTaskExternalId: string, invocationCount: number, event: MemoEvent): Promise<DurableTaskEventMemoAck>;
88
+ waitForCallback(durableTaskExternalId: string, invocationCount: number, branchId: number, nodeId: number, opts?: {
89
+ signal?: AbortSignal;
90
+ }): Promise<DurableTaskEventLogEntryResult>;
91
+ cleanupTaskState(durableTaskExternalId: string, invocationCount: number): void;
92
+ sendEvictInvocation(durableTaskExternalId: string, invocationCount: number, reason?: string): Promise<void>;
93
+ sendMemoCompletedNotification(durableTaskExternalId: string, nodeId: number, branchId: number, invocationCount: number, memoKey: Uint8Array, memoResultPayload?: Uint8Array): Promise<void>;
94
+ /**
95
+ * @deprecated Legacy backward-compat: uses the old unary RegisterDurableEvent RPC.
96
+ */
97
+ registerDurableEvent(request: {
98
+ taskId: string;
99
+ signalKey: string;
100
+ sleepConditions: Array<SleepMatchCondition>;
101
+ userEventConditions: Array<UserEventMatchCondition>;
102
+ }): Promise<RegisterDurableEventResponse>;
103
+ /**
104
+ * @deprecated Legacy backward-compat: uses the old streaming ListenForDurableEvent RPC.
105
+ */
15
106
  subscribe(request: {
16
107
  taskId: string;
17
108
  signalKey: string;
18
- }): import("./pooled-durable-listener-client").DurableEventStreamable;
109
+ }): LegacyDurableEventStreamable;
110
+ /**
111
+ * @deprecated Legacy backward-compat: subscribes and waits for a single result.
112
+ */
19
113
  result(request: {
20
114
  taskId: string;
21
115
  signalKey: string;
22
116
  }, opts?: {
23
117
  signal?: AbortSignal;
24
- }): Promise<import("../../../protoc/v1/dispatcher").DurableEvent>;
25
- registerDurableEvent(request: {
26
- taskId: string;
27
- signalKey: string;
28
- sleepConditions: Array<SleepMatchCondition>;
29
- userEventConditions: Array<UserEventMatchCondition>;
30
- }): Promise<import("../../../protoc/v1/dispatcher").RegisterDurableEventResponse>;
118
+ }): Promise<DurableEvent>;
119
+ private _legacyPooledListener;
120
+ }
121
+ /**
122
+ * @deprecated Legacy support for the old streaming ListenForDurableEvent RPC.
123
+ */
124
+ export declare class LegacyDurableEventStreamable {
125
+ responseEmitter: EventEmitter<[never]>;
126
+ private _onCleanup;
127
+ constructor(onCleanup: () => void);
128
+ get(opts?: {
129
+ signal?: AbortSignal;
130
+ }): Promise<DurableEvent>;
31
131
  }