@hatchet-dev/typescript-sdk 1.15.2 → 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 (202) hide show
  1. package/README.md +14 -2
  2. package/clients/admin/admin-client.d.ts +2 -2
  3. package/clients/admin/admin-client.js +8 -9
  4. package/clients/dispatcher/action-listener.d.ts +3 -6
  5. package/clients/dispatcher/action-listener.js +54 -23
  6. package/clients/dispatcher/dispatcher-client.js +5 -8
  7. package/clients/dispatcher/heartbeat/heartbeat-worker.js +7 -4
  8. package/clients/event/event-client.d.ts +2 -2
  9. package/clients/event/event-client.js +5 -11
  10. package/clients/hatchet-client/hatchet-logger.js +8 -17
  11. package/clients/listeners/durable-listener/durable-listener-client.d.ts +115 -15
  12. package/clients/listeners/durable-listener/durable-listener-client.js +769 -19
  13. package/clients/listeners/durable-listener/pooled-durable-listener-client.js +11 -22
  14. package/clients/listeners/run-listener/child-listener-client.d.ts +1 -1
  15. package/clients/listeners/run-listener/child-listener-client.js +34 -30
  16. package/clients/listeners/run-listener/pooled-child-listener-client.js +9 -19
  17. package/clients/rest/generated/Api.d.ts +25 -1
  18. package/clients/rest/generated/Api.js +20 -0
  19. package/clients/rest/generated/data-contracts.d.ts +60 -1
  20. package/clients/rest/generated/data-contracts.js +9 -1
  21. package/legacy/examples/affinity-workers.js +2 -3
  22. package/legacy/examples/byo-logger.js +0 -2
  23. package/legacy/examples/concurrency/cancel-in-progress/concurrency-worker.js +4 -2
  24. package/legacy/examples/concurrency/group-round-robin/concurrency-event.js +0 -1
  25. package/legacy/examples/concurrency/group-round-robin/concurrency-worker-expression.js +4 -2
  26. package/legacy/examples/concurrency/group-round-robin/concurrency-worker-key-fn.js +4 -2
  27. package/legacy/examples/example-event.js +0 -3
  28. package/legacy/examples/logger.js +0 -1
  29. package/legacy/examples/sticky-worker-with-check.js +0 -1
  30. package/legacy/examples/sticky-worker.js +0 -1
  31. package/legacy/legacy-client.js +2 -2
  32. package/legacy/legacy-transformer.js +2 -4
  33. package/legacy/step.d.ts +16 -16
  34. package/legacy/step.js +8 -17
  35. package/legacy/workflow.d.ts +81 -81
  36. package/package.json +20 -29
  37. package/protoc/dispatcher/dispatcher.d.ts +20 -0
  38. package/protoc/dispatcher/dispatcher.js +136 -2
  39. package/protoc/v1/dispatcher.d.ts +168 -0
  40. package/protoc/v1/dispatcher.js +1920 -1
  41. package/protoc/v1/shared/trigger.d.ts +89 -0
  42. package/protoc/v1/shared/trigger.js +493 -0
  43. package/protoc/v1/workflows.d.ts +34 -34
  44. package/protoc/v1/workflows.js +252 -200
  45. package/protoc/workflows/workflows.d.ts +2 -75
  46. package/protoc/workflows/workflows.js +16 -491
  47. package/util/abort-error.d.ts +15 -1
  48. package/util/abort-error.js +30 -5
  49. package/util/config-loader/config-loader.js +4 -3
  50. package/util/config-loader/token.js +9 -2
  51. package/util/errors/eviction-not-supported-error.d.ts +5 -0
  52. package/util/errors/eviction-not-supported-error.js +18 -0
  53. package/util/errors/hatchet-error.d.ts +9 -1
  54. package/util/errors/hatchet-error.js +23 -2
  55. package/util/errors/non-determinism-error.d.ts +7 -0
  56. package/util/errors/non-determinism-error.js +21 -0
  57. package/util/errors/task-run-terminated-error.d.ts +6 -0
  58. package/util/errors/task-run-terminated-error.js +15 -0
  59. package/util/grpc-error.d.ts +9 -0
  60. package/util/grpc-error.js +25 -0
  61. package/util/hatchet-promise/hatchet-promise.d.ts +6 -1
  62. package/util/hatchet-promise/hatchet-promise.js +16 -2
  63. package/util/logger/logger.js +0 -1
  64. package/util/parse.d.ts +1 -1
  65. package/util/parse.js +4 -2
  66. package/util/retrier.js +2 -3
  67. package/util/sleep.d.ts +3 -2
  68. package/util/sleep.js +6 -4
  69. package/util/workflow-run-ref.js +5 -3
  70. package/v1/client/admin.d.ts +2 -2
  71. package/v1/client/admin.js +2 -6
  72. package/v1/client/client.d.ts +7 -11
  73. package/v1/client/client.interface.d.ts +5 -8
  74. package/v1/client/client.js +34 -40
  75. package/v1/client/duration.d.ts +11 -1
  76. package/v1/client/duration.js +44 -0
  77. package/v1/client/features/cel.js +1 -1
  78. package/v1/client/features/crons.js +2 -2
  79. package/v1/client/features/index.d.ts +5 -0
  80. package/v1/client/features/index.js +5 -0
  81. package/v1/client/features/logs.d.ts +37 -0
  82. package/v1/client/features/logs.js +46 -0
  83. package/v1/client/features/runs.d.ts +16 -3
  84. package/v1/client/features/runs.js +38 -4
  85. package/v1/client/features/schedules.js +4 -4
  86. package/v1/client/features/webhooks.js +4 -2
  87. package/v1/client/features/workflows.js +1 -1
  88. package/v1/client/worker/context.d.ts +101 -6
  89. package/v1/client/worker/context.js +257 -44
  90. package/v1/client/worker/deprecated/deprecation.js +8 -4
  91. package/v1/client/worker/deprecated/index.d.ts +1 -1
  92. package/v1/client/worker/deprecated/index.js +2 -1
  93. package/v1/client/worker/deprecated/legacy-worker.d.ts +5 -0
  94. package/v1/client/worker/deprecated/legacy-worker.js +33 -24
  95. package/v1/client/worker/deprecated/pre-eviction.d.ts +12 -0
  96. package/v1/client/worker/deprecated/pre-eviction.js +37 -0
  97. package/v1/client/worker/engine-version.d.ts +5 -0
  98. package/v1/client/worker/engine-version.js +14 -0
  99. package/v1/client/worker/eviction/eviction-cache.d.ts +33 -0
  100. package/v1/client/worker/eviction/eviction-cache.js +139 -0
  101. package/v1/client/worker/eviction/eviction-manager.d.ts +42 -0
  102. package/v1/client/worker/eviction/eviction-manager.js +132 -0
  103. package/v1/client/worker/eviction/eviction-policy.d.ts +19 -0
  104. package/v1/client/worker/eviction/eviction-policy.js +8 -0
  105. package/v1/client/worker/eviction/index.d.ts +3 -0
  106. package/v1/client/worker/eviction/index.js +11 -0
  107. package/v1/client/worker/health-server.js +3 -3
  108. package/v1/client/worker/slot-utils.js +0 -3
  109. package/v1/client/worker/worker-internal.d.ts +23 -4
  110. package/v1/client/worker/worker-internal.js +216 -148
  111. package/v1/client/worker/worker.d.ts +1 -0
  112. package/v1/client/worker/worker.js +34 -0
  113. package/v1/conditions/base.js +0 -1
  114. package/v1/conditions/index.js +2 -4
  115. package/v1/conditions/sleep-condition.js +2 -1
  116. package/v1/conditions/transformer.js +2 -1
  117. package/v1/declaration.d.ts +6 -4
  118. package/v1/declaration.js +20 -7
  119. package/v1/examples/__e2e__/harness.d.ts +5 -0
  120. package/v1/examples/__e2e__/harness.js +17 -3
  121. package/v1/examples/affinity/affinity-workers.js +0 -1
  122. package/v1/examples/bulk_operations/workflow.js +0 -1
  123. package/v1/examples/cancellation/run.js +0 -1
  124. package/v1/examples/cancellations/run.js +0 -1
  125. package/v1/examples/child_workflows/run.js +0 -2
  126. package/v1/examples/child_workflows/workflow.js +0 -1
  127. package/v1/examples/concurrency-rr/load.js +0 -1
  128. package/v1/examples/concurrency-rr/run.js +0 -3
  129. package/v1/examples/concurrency_limit_rr/load.js +0 -1
  130. package/v1/examples/concurrency_limit_rr/run.js +0 -3
  131. package/v1/examples/concurrency_workflow_level/workflow.d.ts +1 -1
  132. package/v1/examples/concurrency_workflow_level/workflow.js +1 -1
  133. package/v1/examples/conditions/event.js +0 -1
  134. package/v1/examples/conditions/run.js +0 -1
  135. package/v1/examples/dag/run.js +0 -1
  136. package/v1/examples/dag_match_condition/event.js +0 -1
  137. package/v1/examples/dag_match_condition/run.js +0 -1
  138. package/v1/examples/deep/run.js +0 -2
  139. package/v1/examples/durable/workflow.d.ts +57 -0
  140. package/v1/examples/durable/workflow.js +164 -10
  141. package/v1/examples/durable-event/event.js +0 -1
  142. package/v1/examples/durable-event/run.js +0 -2
  143. package/v1/examples/durable-event/workflow.js +2 -7
  144. package/v1/examples/durable-sleep/event.js +0 -1
  145. package/v1/examples/durable-sleep/run.js +0 -2
  146. package/v1/examples/durable_event/event.js +0 -1
  147. package/v1/examples/durable_event/run.js +0 -2
  148. package/v1/examples/durable_event/workflow.d.ts +1 -0
  149. package/v1/examples/durable_event/workflow.js +4 -9
  150. package/v1/examples/durable_eviction/capacity-worker.d.ts +1 -0
  151. package/v1/examples/durable_eviction/capacity-worker.js +31 -0
  152. package/v1/examples/durable_eviction/worker.d.ts +1 -0
  153. package/v1/examples/durable_eviction/worker.js +34 -0
  154. package/v1/examples/durable_eviction/workflow.d.ts +44 -0
  155. package/v1/examples/durable_eviction/workflow.js +129 -0
  156. package/v1/examples/durable_sleep/event.js +0 -1
  157. package/v1/examples/durable_sleep/run.js +0 -2
  158. package/v1/examples/e2e-worker.js +42 -19
  159. package/v1/examples/events/event.js +0 -1
  160. package/v1/examples/high-memory/run.js +0 -1
  161. package/v1/examples/inferred-typing/run.js +0 -1
  162. package/v1/examples/landing_page/durable-excution.js +0 -1
  163. package/v1/examples/landing_page/queues.js +0 -1
  164. package/v1/examples/legacy/run.js +0 -1
  165. package/v1/examples/logger/byo-logger.js +0 -2
  166. package/v1/examples/logger/logger.js +0 -1
  167. package/v1/examples/logging/byo-logger.js +0 -2
  168. package/v1/examples/logging/logger.js +0 -1
  169. package/v1/examples/middleware/recipes.js +3 -1
  170. package/v1/examples/migration-guides/mergent.js +2 -1
  171. package/v1/examples/multiple_wf_concurrency/run.js +0 -3
  172. package/v1/examples/non_retryable/run.js +0 -1
  173. package/v1/examples/on_event/event.js +0 -1
  174. package/v1/examples/on_failure/run.js +0 -1
  175. package/v1/examples/on_failure/workflow.js +0 -1
  176. package/v1/examples/on_success/run.js +0 -1
  177. package/v1/examples/on_success/workflow.js +0 -1
  178. package/v1/examples/priority/run.js +0 -1
  179. package/v1/examples/priority/workflow.js +0 -1
  180. package/v1/examples/retries/run.js +0 -1
  181. package/v1/examples/retries/workflow.js +0 -1
  182. package/v1/examples/simple/bulk.js +0 -1
  183. package/v1/examples/simple/cron.js +0 -2
  184. package/v1/examples/simple/delay.js +0 -1
  185. package/v1/examples/simple/enqueue.js +0 -2
  186. package/v1/examples/simple/run.js +0 -1
  187. package/v1/examples/simple/schedule.js +0 -1
  188. package/v1/examples/simple/workflow-with-child.js +10 -4
  189. package/v1/examples/sticky/run.js +0 -1
  190. package/v1/examples/sticky/workflow.js +0 -1
  191. package/v1/examples/streaming/nextjs-proxy.js +0 -1
  192. package/v1/examples/streaming/run.js +0 -1
  193. package/v1/examples/timeout/run.js +0 -1
  194. package/v1/examples/timeouts/run.js +0 -1
  195. package/v1/index.d.ts +5 -0
  196. package/v1/index.js +10 -0
  197. package/v1/parent-run-context-vars.d.ts +6 -0
  198. package/v1/slot-types.js +0 -1
  199. package/v1/task.d.ts +10 -2
  200. package/v1/task.js +2 -1
  201. package/version.d.ts +1 -1
  202. 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';
@@ -25,7 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.AdminClient = void 0;
27
27
  const workflows_1 = require("../../protoc/workflows");
28
- const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
28
+ const hatchet_error_1 = require("../../util/errors/hatchet-error");
29
29
  const retrier_1 = require("../../util/retrier");
30
30
  const workflow_run_ref_1 = __importDefault(require("../../util/workflow-run-ref"));
31
31
  const workflows_2 = require("../../protoc/v1/workflows");
@@ -72,7 +72,7 @@ class AdminClient {
72
72
  return yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.client.putWorkflow({ opts: workflow }); }), this.logger);
73
73
  }
74
74
  catch (e) {
75
- throw new hatchet_error_1.default(e.message);
75
+ throw (0, hatchet_error_1.toHatchetError)(e);
76
76
  }
77
77
  });
78
78
  }
@@ -87,7 +87,7 @@ class AdminClient {
87
87
  return yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.v1Client.putWorkflow(workflow); }), this.logger);
88
88
  }
89
89
  catch (e) {
90
- throw new hatchet_error_1.default(e.message);
90
+ throw (0, hatchet_error_1.toHatchetError)(e);
91
91
  }
92
92
  });
93
93
  }
@@ -114,7 +114,7 @@ class AdminClient {
114
114
  }), this.logger);
115
115
  }
116
116
  catch (e) {
117
- throw new hatchet_error_1.default(e.message);
117
+ throw (0, hatchet_error_1.toHatchetError)(e);
118
118
  }
119
119
  });
120
120
  }
@@ -153,7 +153,7 @@ class AdminClient {
153
153
  return new workflow_run_ref_1.default(resp, this.listenerClient, this.workflows, options === null || options === void 0 ? void 0 : options.parentId);
154
154
  }
155
155
  catch (e) {
156
- throw new hatchet_error_1.default(e.message);
156
+ throw (0, hatchet_error_1.toHatchetError)(e);
157
157
  }
158
158
  }
159
159
  /**
@@ -186,7 +186,7 @@ class AdminClient {
186
186
  });
187
187
  }
188
188
  catch (e) {
189
- throw new hatchet_error_1.default(e.message);
189
+ throw (0, hatchet_error_1.toHatchetError)(e);
190
190
  }
191
191
  }
192
192
  /**
@@ -301,9 +301,8 @@ class AdminClient {
301
301
  * @deprecated use hatchet.schedules.create instead
302
302
  */
303
303
  scheduleWorkflow(name, options) {
304
- let computedName = name;
305
304
  try {
306
- computedName = (0, apply_namespace_1.applyNamespace)(name, this.config.namespace);
305
+ const computedName = (0, apply_namespace_1.applyNamespace)(name, this.config.namespace);
307
306
  let input;
308
307
  if (options === null || options === void 0 ? void 0 : options.input) {
309
308
  input = JSON.stringify(options.input);
@@ -315,7 +314,7 @@ class AdminClient {
315
314
  });
316
315
  }
317
316
  catch (e) {
318
- throw new hatchet_error_1.default(e.message);
317
+ throw (0, hatchet_error_1.toHatchetError)(e);
319
318
  }
320
319
  }
321
320
  /**
@@ -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;
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -33,34 +66,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
66
  };
34
67
  Object.defineProperty(exports, "__esModule", { value: true });
35
68
  exports.ActionListener = void 0;
36
- exports.createActionKey = createActionKey;
37
- const dispatcher_1 = require("../../protoc/dispatcher");
69
+ exports.createAction = createAction;
38
70
  const nice_grpc_1 = require("nice-grpc");
71
+ const grpc_error_1 = require("../../util/grpc-error");
39
72
  const abort_controller_x_1 = require("abort-controller-x");
40
73
  const sleep_1 = __importDefault(require("../../util/sleep"));
41
- const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
74
+ const hatchet_error_1 = __importStar(require("../../util/errors/hatchet-error"));
42
75
  const heartbeat_controller_1 = require("./heartbeat/heartbeat-controller");
43
76
  const DEFAULT_ACTION_LISTENER_RETRY_INTERVAL = 5000; // milliseconds
44
77
  const DEFAULT_ACTION_LISTENER_RETRY_COUNT = 20;
45
- // eslint-disable-next-line no-shadow
46
78
  var ListenStrategy;
47
79
  (function (ListenStrategy) {
48
80
  ListenStrategy[ListenStrategy["LISTEN_STRATEGY_V1"] = 1] = "LISTEN_STRATEGY_V1";
49
81
  ListenStrategy[ListenStrategy["LISTEN_STRATEGY_V2"] = 2] = "LISTEN_STRATEGY_V2";
50
82
  })(ListenStrategy || (ListenStrategy = {}));
51
- function createActionKey(action) {
52
- switch (action.actionType) {
53
- case dispatcher_1.ActionType.START_GET_GROUP_KEY:
54
- return `${action.getGroupKeyRunId}/${action.retryCount}`;
55
- case dispatcher_1.ActionType.CANCEL_STEP_RUN:
56
- case dispatcher_1.ActionType.START_STEP_RUN:
57
- case dispatcher_1.ActionType.UNRECOGNIZED:
58
- return `${action.taskRunExternalId}/${action.retryCount}`;
59
- default:
60
- // eslint-disable-next-line no-case-declarations
61
- const exhaustivenessCheck = action.actionType;
62
- throw new Error(`Unhandled action type: ${exhaustivenessCheck}`);
63
- }
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;
64
93
  }
65
94
  class ActionListener {
66
95
  constructor(client, workerId, retryInterval = DEFAULT_ACTION_LISTENER_RETRY_INTERVAL, retryCount = DEFAULT_ACTION_LISTENER_RETRY_COUNT) {
@@ -84,8 +113,7 @@ class ActionListener {
84
113
  _c = listenClient_1_1.value;
85
114
  _d = false;
86
115
  const assignedAction = _c;
87
- const action = Object.assign(Object.assign({}, assignedAction), { stepRunId: assignedAction.taskRunExternalId, stepId: assignedAction.taskId });
88
- yield yield __await(action);
116
+ yield yield __await(createAction(assignedAction));
89
117
  }
90
118
  }
91
119
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -108,11 +136,11 @@ class ActionListener {
108
136
  throw e;
109
137
  }
110
138
  if ((yield __await(client.getListenStrategy())) === ListenStrategy.LISTEN_STRATEGY_V2 &&
111
- e.code === nice_grpc_1.Status.UNIMPLEMENTED) {
139
+ (0, grpc_error_1.getGrpcErrorCode)(e) === nice_grpc_1.Status.UNIMPLEMENTED) {
112
140
  client.setListenStrategy(ListenStrategy.LISTEN_STRATEGY_V1);
113
141
  }
114
142
  client.incrementRetries();
115
- client.logger.error(`Listener encountered an error: ${e.message}`);
143
+ client.logger.error(`Listener encountered an error: ${(0, hatchet_error_1.getErrorMessage)(e)}`);
116
144
  if (client.retries > 1) {
117
145
  client.logger.info(`Retrying in ${client.retryInterval}ms...`);
118
146
  yield __await((0, sleep_1.default)(client.retryInterval));
@@ -186,7 +214,7 @@ class ActionListener {
186
214
  catch (e) {
187
215
  this.retries += 1;
188
216
  this.logger.error(`Attempt ${this.retries}: Failed to connect, retrying...`);
189
- if (e.code === nice_grpc_1.Status.UNAVAILABLE) {
217
+ if ((0, grpc_error_1.getGrpcErrorCode)(e) === nice_grpc_1.Status.UNAVAILABLE) {
190
218
  // Connection lost, reset heartbeat interval and retry connection
191
219
  this.heartbeat.stop();
192
220
  return this.getListenClient();
@@ -209,7 +237,10 @@ class ActionListener {
209
237
  });
210
238
  }
211
239
  catch (e) {
212
- throw new hatchet_error_1.default(`Failed to unsubscribe: ${e.message}`);
240
+ throw (0, hatchet_error_1.toHatchetError)(e, {
241
+ defaultMessage: 'Failed to unsubscribe',
242
+ prefix: 'Failed to unsubscribe: ',
243
+ });
213
244
  }
214
245
  });
215
246
  }
@@ -19,14 +19,11 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  }
20
20
  return t;
21
21
  };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
22
  Object.defineProperty(exports, "__esModule", { value: true });
26
23
  exports.DispatcherClient = void 0;
27
24
  exports.mapLabels = mapLabels;
28
25
  const dispatcher_1 = require("../../protoc/dispatcher");
29
- const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
26
+ const hatchet_error_1 = require("../../util/errors/hatchet-error");
30
27
  const retrier_1 = require("../../util/retrier");
31
28
  const version_1 = require("../../version");
32
29
  const slot_types_1 = require("../../v1/slot-types");
@@ -82,7 +79,7 @@ class DispatcherClient {
82
79
  return yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.client.sendStepActionEvent(event); }), this.logger);
83
80
  }
84
81
  catch (e) {
85
- throw new hatchet_error_1.default(e.message);
82
+ throw (0, hatchet_error_1.toHatchetError)(e);
86
83
  }
87
84
  });
88
85
  }
@@ -92,7 +89,7 @@ class DispatcherClient {
92
89
  return yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.client.sendGroupKeyActionEvent(in_); }), this.logger);
93
90
  }
94
91
  catch (e) {
95
- throw new hatchet_error_1.default(e.message);
92
+ throw (0, hatchet_error_1.toHatchetError)(e);
96
93
  }
97
94
  });
98
95
  }
@@ -112,7 +109,7 @@ class DispatcherClient {
112
109
  });
113
110
  }
114
111
  catch (e) {
115
- throw new hatchet_error_1.default(e.message);
112
+ throw (0, hatchet_error_1.toHatchetError)(e);
116
113
  }
117
114
  });
118
115
  }
@@ -125,7 +122,7 @@ class DispatcherClient {
125
122
  });
126
123
  }
127
124
  catch (e) {
128
- throw new hatchet_error_1.default(e.message);
125
+ throw (0, hatchet_error_1.toHatchetError)(e);
129
126
  }
130
127
  });
131
128
  }
@@ -13,6 +13,8 @@ const worker_threads_1 = require("worker_threads");
13
13
  const hatchet_client_1 = require("../../hatchet-client");
14
14
  const config_loader_1 = require("../../../util/config-loader");
15
15
  const nice_grpc_1 = require("nice-grpc");
16
+ const hatchet_error_1 = require("../../../util/errors/hatchet-error");
17
+ const grpc_error_1 = require("../../../util/grpc-error");
16
18
  const grpc_helpers_1 = require("../../../util/grpc-helpers");
17
19
  const dispatcher_client_1 = require("../dispatcher-client");
18
20
  const heartbeat_controller_1 = require("./heartbeat-controller");
@@ -69,7 +71,7 @@ class HeartbeatWorker {
69
71
  this.timeLastHeartbeat = now;
70
72
  }
71
73
  catch (e) {
72
- if (e.code === nice_grpc_1.Status.UNIMPLEMENTED) {
74
+ if ((0, grpc_error_1.getGrpcErrorCode)(e) === nice_grpc_1.Status.UNIMPLEMENTED) {
73
75
  // break out of interval
74
76
  const message = 'Heartbeat not implemented, closing heartbeat';
75
77
  this.logger.debug(message);
@@ -80,7 +82,7 @@ class HeartbeatWorker {
80
82
  this.stop();
81
83
  return;
82
84
  }
83
- const message = `Failed to send heartbeat: ${e.message}`;
85
+ const message = `Failed to send heartbeat: ${(0, hatchet_error_1.getErrorMessage)(e)}`;
84
86
  this.logger.debug(message);
85
87
  postMessage({
86
88
  type: 'error',
@@ -96,13 +98,14 @@ class HeartbeatWorker {
96
98
  stop() {
97
99
  if (this.heartbeatInterval) {
98
100
  clearInterval(this.heartbeatInterval);
99
- this.heartbeatInterval = null;
101
+ this.heartbeatInterval = undefined;
100
102
  }
101
103
  }
102
104
  }
103
105
  const heartbeat = new HeartbeatWorker(worker_threads_1.workerData.config, worker_threads_1.workerData.workerId);
104
106
  heartbeat.start();
105
107
  worker_threads_1.parentPort === null || worker_threads_1.parentPort === void 0 ? void 0 : worker_threads_1.parentPort.on('message', (msg) => {
106
- if (msg === heartbeat_controller_1.STOP_HEARTBEAT)
108
+ if (msg === heartbeat_controller_1.STOP_HEARTBEAT) {
107
109
  heartbeat.stop();
110
+ }
108
111
  });
@@ -17,7 +17,7 @@ export interface PushEventOptions {
17
17
  }
18
18
  export interface EventWithMetadata<T> {
19
19
  payload: T;
20
- additionalMetadata?: Record<string, any>;
20
+ additionalMetadata?: Record<string, unknown>;
21
21
  priority?: number;
22
22
  scope?: string;
23
23
  }
@@ -31,7 +31,7 @@ export declare class EventClient {
31
31
  constructor(config: ClientConfig, channel: Channel, factory: ClientFactory, api: HatchetClient['api']);
32
32
  push<T>(type: string, input: T, options?: PushEventOptions): Promise<import("../../protoc/events/events").Event>;
33
33
  bulkPush<T>(type: string, inputs: EventWithMetadata<T>[], options?: PushEventOptions): Promise<import("../../protoc/events/events").Events>;
34
- putLog(taskRunExternalId: string, log: string, level?: LogLevel, taskRetryCount?: number, metadata?: Record<string, any>): Promise<void>;
34
+ putLog(taskRunExternalId: string, log: string, level?: LogLevel, taskRetryCount?: number, metadata?: Record<string, unknown>): Promise<void>;
35
35
  putStream(taskRunExternalId: string, data: string | Uint8Array, index: number | undefined): Promise<void>;
36
36
  list(opts?: Parameters<typeof this.api.v1EventList>[1]): Promise<import("../rest/generated/data-contracts").V1EventList>;
37
37
  }
@@ -8,16 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  exports.EventClient = exports.LogLevel = void 0;
16
13
  const events_1 = require("../../protoc/events/events");
17
- const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
14
+ const hatchet_error_1 = require("../../util/errors/hatchet-error");
18
15
  const retrier_1 = require("../../util/retrier");
19
16
  const apply_namespace_1 = require("../../util/apply-namespace");
20
- // eslint-disable-next-line no-shadow
21
17
  var LogLevel;
22
18
  (function (LogLevel) {
23
19
  LogLevel["INFO"] = "INFO";
@@ -52,7 +48,7 @@ class EventClient {
52
48
  return e;
53
49
  }
54
50
  catch (e) {
55
- throw new hatchet_error_1.default(e.message);
51
+ throw (0, hatchet_error_1.toHatchetError)(e);
56
52
  }
57
53
  }
58
54
  bulkPush(type, inputs, options = {}) {
@@ -84,7 +80,7 @@ class EventClient {
84
80
  return res;
85
81
  }
86
82
  catch (e) {
87
- throw new hatchet_error_1.default(e.message);
83
+ throw (0, hatchet_error_1.toHatchetError)(e);
88
84
  }
89
85
  }
90
86
  putLog(taskRunExternalId, log, level, taskRetryCount, metadata) {
@@ -105,8 +101,7 @@ class EventClient {
105
101
  metadata: metadata ? JSON.stringify(metadata) : undefined,
106
102
  })
107
103
  .catch((e) => {
108
- // log a warning, but this is not a fatal error
109
- this.logger.warn(`Could not put log: ${e.message}`);
104
+ this.logger.warn(`Could not put log: ${(0, hatchet_error_1.getErrorMessage)(e)}`);
110
105
  });
111
106
  });
112
107
  }
@@ -131,8 +126,7 @@ class EventClient {
131
126
  eventIndex: index,
132
127
  });
133
128
  }), this.logger).catch((e) => {
134
- // log a warning, but this is not a fatal error
135
- this.logger.warn(`Could not put log: ${e.message}`);
129
+ this.logger.warn(`Could not put log: ${(0, hatchet_error_1.getErrorMessage)(e)}`);
136
130
  });
137
131
  });
138
132
  }
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.HatchetLogger = exports.DEFAULT_LOGGER = void 0;
13
- /* eslint-disable no-console */
14
13
  const logger_1 = require("../../util/logger");
15
14
  const DEFAULT_LOGGER = (context, logLevel) => new HatchetLogger(context, logLevel);
16
15
  exports.DEFAULT_LOGGER = DEFAULT_LOGGER;
@@ -20,6 +19,7 @@ class HatchetLogger {
20
19
  this.context = context;
21
20
  }
22
21
  log(level, message, color = '37') {
22
+ var _a;
23
23
  if (logger_1.LogLevelEnum[level] >= logger_1.LogLevelEnum[this.logLevel]) {
24
24
  const time = new Date().toLocaleString('en-US', {
25
25
  month: '2-digit',
@@ -29,22 +29,13 @@ class HatchetLogger {
29
29
  minute: '2-digit',
30
30
  second: '2-digit',
31
31
  });
32
- // eslint-disable-next-line prefer-destructuring
33
- let print = console.log;
34
- if (level === 'ERROR') {
35
- print = console.error;
36
- }
37
- if (level === 'WARN') {
38
- print = console.warn;
39
- }
40
- if (level === 'INFO') {
41
- print = console.info;
42
- }
43
- if (level === 'DEBUG') {
44
- print = console.debug;
45
- }
46
- // eslint-disable-next-line no-console
47
- print(`🪓 ${process.pid} | ${time} ${color && `\x1b[${color || ''}m`} [${level}/${this.context}] ${message}\x1b[0m`);
32
+ const logFn = {
33
+ ERROR: console.error,
34
+ WARN: console.warn,
35
+ INFO: console.info,
36
+ DEBUG: console.debug,
37
+ };
38
+ ((_a = logFn[level]) !== null && _a !== void 0 ? _a : console.log)(`🪓 ${process.pid} | ${time} ${color && `\x1b[${color || ''}m`} [${level}/${this.context}] ${message}\x1b[0m`);
48
39
  }
49
40
  }
50
41
  debug(message) {
@@ -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
  }