@hatchet-dev/typescript-sdk 1.0.0-alpha1 → 1.0.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 (194) hide show
  1. package/clients/admin/admin-client.d.ts +15 -20
  2. package/clients/admin/admin-client.js +21 -17
  3. package/clients/hatchet-client/hatchet-client.d.ts +5 -4
  4. package/clients/hatchet-client/hatchet-client.js +6 -4
  5. package/clients/listeners/durable-listener/durable-listener-client.d.ts +25 -0
  6. package/clients/listeners/durable-listener/durable-listener-client.js +30 -0
  7. package/clients/listeners/durable-listener/pooled-durable-listener-client.d.ts +43 -0
  8. package/clients/listeners/durable-listener/pooled-durable-listener-client.js +241 -0
  9. package/clients/{listener/listener-client.d.ts → listeners/run-listener/child-listener-client.d.ts} +8 -8
  10. package/clients/{listener/listener-client.js → listeners/run-listener/child-listener-client.js} +8 -19
  11. package/clients/{listener/child-listener-client.d.ts → listeners/run-listener/pooled-child-listener-client.d.ts} +5 -5
  12. package/clients/{listener/child-listener-client.js → listeners/run-listener/pooled-child-listener-client.js} +5 -5
  13. package/clients/rest/generated/Api.d.ts +49 -2
  14. package/clients/rest/generated/Api.js +30 -0
  15. package/clients/rest/generated/data-contracts.d.ts +88 -82
  16. package/clients/rest/generated/data-contracts.js +8 -1
  17. package/clients/worker/worker.d.ts +5 -1
  18. package/clients/worker/worker.js +173 -2
  19. package/examples/affinity-workers.js +5 -1
  20. package/examples/api.js +1 -1
  21. package/examples/bulk-fanout-worker.js +1 -1
  22. package/examples/byo-logger.js +4 -0
  23. package/examples/concurrency/cancel-in-progress/concurrency-event.js +2 -2
  24. package/examples/concurrency/group-round-robin/concurrency-event.js +1 -1
  25. package/examples/crons/programatic-crons.js +4 -4
  26. package/examples/dag-worker.js +0 -1
  27. package/examples/example-event.js +2 -2
  28. package/examples/logger.js +2 -0
  29. package/examples/on-failure.js +1 -1
  30. package/examples/rate-limit/events.js +3 -3
  31. package/examples/scheduled-runs/programatic-schedules.js +4 -4
  32. package/examples/sticky-worker-with-check.js +2 -2
  33. package/examples/sticky-worker.js +5 -0
  34. package/index.d.ts +1 -3
  35. package/index.js +1 -3
  36. package/package.json +2 -2
  37. package/protoc/dispatcher/dispatcher.d.ts +2 -0
  38. package/protoc/dispatcher/dispatcher.js +1 -1
  39. package/protoc/events/events.js +1 -1
  40. package/protoc/google/protobuf/timestamp.js +1 -1
  41. package/protoc/v1/dispatcher.d.ts +77 -0
  42. package/protoc/v1/dispatcher.js +341 -0
  43. package/protoc/v1/shared/condition.d.ts +59 -0
  44. package/protoc/v1/shared/condition.js +549 -0
  45. package/protoc/v1/workflows.d.ts +263 -0
  46. package/protoc/v1/workflows.js +1823 -0
  47. package/protoc/workflows/workflows.js +1 -1
  48. package/step.d.ts +173 -47
  49. package/step.js +208 -64
  50. package/util/sleep.d.ts +7 -0
  51. package/util/sleep.js +7 -0
  52. package/util/workflow-run-ref.d.ts +8 -2
  53. package/util/workflow-run-ref.js +13 -0
  54. package/v1/client/client.d.ts +125 -7
  55. package/v1/client/client.interface.d.ts +9 -1
  56. package/v1/client/client.js +148 -17
  57. package/v1/client/duration.d.ts +7 -0
  58. package/v1/client/duration.js +2 -0
  59. package/v1/client/features/index.d.ts +5 -0
  60. package/v1/client/features/index.js +21 -0
  61. package/v1/client/features/metrics.d.ts +14 -0
  62. package/v1/client/features/metrics.js +45 -0
  63. package/v1/client/features/ratelimits.d.ts +20 -0
  64. package/v1/client/features/ratelimits.js +40 -0
  65. package/v1/client/features/runs.d.ts +15 -0
  66. package/v1/client/features/runs.js +60 -0
  67. package/v1/client/features/workers.d.ts +14 -0
  68. package/v1/client/features/workers.js +56 -0
  69. package/v1/client/features/workflows.d.ts +17 -0
  70. package/v1/client/features/workflows.js +93 -0
  71. package/v1/client/worker.d.ts +25 -15
  72. package/v1/client/worker.js +76 -47
  73. package/v1/conditions/base.d.ts +18 -0
  74. package/v1/conditions/base.js +18 -0
  75. package/v1/conditions/index.d.ts +31 -0
  76. package/v1/conditions/index.js +91 -0
  77. package/v1/conditions/parent-condition.d.ts +40 -0
  78. package/v1/conditions/parent-condition.js +36 -0
  79. package/v1/conditions/sleep-condition.d.ts +47 -0
  80. package/v1/conditions/sleep-condition.js +38 -0
  81. package/v1/conditions/transformer.d.ts +5 -0
  82. package/v1/conditions/transformer.js +52 -0
  83. package/v1/conditions/user-event-condition.d.ts +50 -0
  84. package/v1/conditions/user-event-condition.js +39 -0
  85. package/v1/declaration.d.ts +309 -0
  86. package/v1/declaration.js +296 -0
  87. package/v1/examples/child_workflows/worker.js +2 -2
  88. package/v1/examples/child_workflows/workflow.d.ts +2 -2
  89. package/v1/examples/child_workflows/workflow.js +5 -3
  90. package/v1/examples/concurrency-rr/load.js +2 -2
  91. package/v1/examples/concurrency-rr/worker.js +2 -2
  92. package/v1/examples/concurrency-rr/workflow.d.ts +1 -1
  93. package/v1/examples/concurrency-rr/workflow.js +2 -3
  94. package/v1/examples/dag/worker.js +2 -2
  95. package/v1/examples/dag/workflow.d.ts +1 -1
  96. package/v1/examples/dag/workflow.js +3 -3
  97. package/v1/examples/dag_match_condition/event.js +28 -0
  98. package/v1/examples/dag_match_condition/run.d.ts +1 -0
  99. package/v1/examples/dag_match_condition/run.js +25 -0
  100. package/v1/examples/dag_match_condition/worker.d.ts +1 -0
  101. package/{examples/playground.js → v1/examples/dag_match_condition/worker.js} +7 -22
  102. package/v1/examples/dag_match_condition/workflow.d.ts +11 -0
  103. package/v1/examples/dag_match_condition/workflow.js +41 -0
  104. package/v1/examples/deep/worker.js +2 -2
  105. package/v1/examples/deep/workflow.d.ts +6 -6
  106. package/v1/examples/deep/workflow.js +7 -7
  107. package/v1/examples/durable-sleep/event.d.ts +1 -0
  108. package/v1/examples/durable-sleep/event.js +28 -0
  109. package/v1/examples/durable-sleep/run.d.ts +1 -0
  110. package/v1/examples/durable-sleep/run.js +30 -0
  111. package/v1/examples/durable-sleep/worker.d.ts +1 -0
  112. package/v1/examples/durable-sleep/worker.js +24 -0
  113. package/v1/examples/durable-sleep/workflow.d.ts +1 -0
  114. package/v1/examples/durable-sleep/workflow.js +37 -0
  115. package/v1/examples/inferred-typing/run.d.ts +1 -0
  116. package/v1/examples/inferred-typing/run.js +41 -0
  117. package/v1/examples/inferred-typing/worker.d.ts +1 -0
  118. package/v1/examples/inferred-typing/worker.js +24 -0
  119. package/v1/examples/inferred-typing/workflow.d.ts +15 -0
  120. package/v1/examples/inferred-typing/workflow.js +44 -0
  121. package/v1/examples/landing_page/durable-excution.d.ts +3 -0
  122. package/v1/examples/landing_page/durable-excution.js +40 -0
  123. package/v1/examples/landing_page/event-signaling.d.ts +6 -0
  124. package/v1/examples/landing_page/event-signaling.js +16 -0
  125. package/v1/examples/landing_page/flow-control.d.ts +6 -0
  126. package/v1/examples/landing_page/flow-control.js +26 -0
  127. package/v1/examples/landing_page/queues.d.ts +3 -0
  128. package/v1/examples/landing_page/queues.js +33 -0
  129. package/v1/examples/landing_page/scheduling.d.ts +1 -0
  130. package/v1/examples/landing_page/scheduling.js +12 -0
  131. package/v1/examples/landing_page/task-routing.d.ts +6 -0
  132. package/v1/examples/landing_page/task-routing.js +25 -0
  133. package/v1/examples/legacy/run.js +2 -2
  134. package/v1/examples/legacy/worker.js +2 -2
  135. package/v1/examples/on_cron/worker.d.ts +1 -0
  136. package/v1/examples/on_cron/worker.js +24 -0
  137. package/v1/examples/on_cron/workflow.d.ts +10 -0
  138. package/v1/examples/on_cron/workflow.js +21 -0
  139. package/v1/examples/on_event/event.js +3 -2
  140. package/v1/examples/on_event/worker.js +2 -2
  141. package/v1/examples/on_event/workflow.d.ts +4 -4
  142. package/v1/examples/on_event/workflow.js +6 -3
  143. package/v1/examples/on_event copy/event.d.ts +1 -0
  144. package/v1/examples/on_event copy/event.js +26 -0
  145. package/v1/examples/on_event copy/worker.d.ts +1 -0
  146. package/v1/examples/on_event copy/worker.js +24 -0
  147. package/v1/examples/on_event copy/workflow.d.ts +16 -0
  148. package/v1/examples/on_event copy/workflow.js +35 -0
  149. package/v1/examples/on_failure/worker.js +2 -2
  150. package/v1/examples/on_failure/workflow.d.ts +1 -1
  151. package/v1/examples/on_failure/workflow.js +18 -8
  152. package/v1/examples/on_success/run.d.ts +1 -0
  153. package/v1/examples/on_success/run.js +31 -0
  154. package/v1/examples/on_success/worker.d.ts +1 -0
  155. package/v1/examples/on_success/worker.js +24 -0
  156. package/v1/examples/on_success/workflow.d.ts +4 -0
  157. package/v1/examples/on_success/workflow.js +59 -0
  158. package/v1/examples/retries/run.d.ts +1 -0
  159. package/v1/examples/retries/run.js +29 -0
  160. package/v1/examples/retries/worker.d.ts +1 -0
  161. package/v1/examples/retries/worker.js +24 -0
  162. package/v1/examples/retries/workflow.d.ts +5 -0
  163. package/v1/examples/retries/workflow.js +53 -0
  164. package/v1/examples/simple/client-run.d.ts +1 -0
  165. package/v1/examples/simple/client-run.js +16 -0
  166. package/v1/examples/simple/cron.js +6 -2
  167. package/v1/examples/simple/delay.js +2 -2
  168. package/v1/examples/simple/enqueue.d.ts +1 -0
  169. package/v1/examples/simple/enqueue.js +43 -0
  170. package/v1/examples/simple/run.js +8 -3
  171. package/v1/examples/simple/schedule.js +11 -5
  172. package/v1/examples/simple/stub-workflow.d.ts +9 -0
  173. package/v1/examples/simple/stub-workflow.js +17 -0
  174. package/v1/examples/simple/worker.js +7 -2
  175. package/v1/examples/simple/workflow.d.ts +4 -3
  176. package/v1/examples/simple/workflow.js +5 -5
  177. package/v1/examples/sticky/run.d.ts +1 -0
  178. package/v1/examples/sticky/run.js +29 -0
  179. package/v1/examples/sticky/worker.d.ts +1 -0
  180. package/v1/examples/sticky/worker.js +24 -0
  181. package/v1/examples/sticky/workflow.d.ts +7 -0
  182. package/v1/examples/sticky/workflow.js +32 -0
  183. package/v1/examples/with_timeouts/workflow.d.ts +9 -0
  184. package/v1/examples/with_timeouts/workflow.js +62 -0
  185. package/v1/index.d.ts +5 -0
  186. package/v1/index.js +20 -0
  187. package/v1/task.d.ts +144 -14
  188. package/version.d.ts +1 -1
  189. package/version.js +1 -1
  190. package/v1/workflow.d.ts +0 -158
  191. package/v1/workflow.js +0 -145
  192. /package/{examples/playground.d.ts → v1/examples/dag_match_condition/event.d.ts} +0 -0
  193. /package/v1/examples/{client.d.ts → hatchet-client.d.ts} +0 -0
  194. /package/v1/examples/{client.js → hatchet-client.js} +0 -0
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RunsClient = void 0;
13
+ /**
14
+ * RunsClient is used to list and manage runs
15
+ */
16
+ class RunsClient {
17
+ constructor(client) {
18
+ this.api = client.api;
19
+ this.tenantId = client.tenantId;
20
+ }
21
+ // TODO expose streaming methods?
22
+ get(run) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const runId = typeof run === 'string' ? run : yield run.getWorkflowRunId();
25
+ const { data } = yield this.api.workflowRunGet(this.tenantId, runId);
26
+ return data;
27
+ });
28
+ }
29
+ getDetails(run) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const runId = typeof run === 'string' ? run : yield run.getWorkflowRunId();
32
+ const { data } = yield this.api.workflowRunGetShape(this.tenantId, runId);
33
+ return data;
34
+ });
35
+ }
36
+ list(opts) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ // TODO workflow id on opts is a uuid
39
+ const { data } = yield this.api.workflowRunList(this.tenantId, opts);
40
+ return data;
41
+ });
42
+ }
43
+ replay(opts) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ // TODO is v1 check
46
+ // TODO workflowIds?: string[]; on opts.filters
47
+ const { data } = yield this.api.v1TaskReplay(this.tenantId, opts);
48
+ return data;
49
+ });
50
+ }
51
+ cancel(opts) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ // TODO is v1 check
54
+ // TODO workflowIds?: string[]; on opts.filters
55
+ const { data } = yield this.api.v1TaskCancel(this.tenantId, opts);
56
+ return data;
57
+ });
58
+ }
59
+ }
60
+ exports.RunsClient = RunsClient;
@@ -0,0 +1,14 @@
1
+ import { HatchetClient } from '../client';
2
+ /**
3
+ * WorkersClient is used to list and manage workers
4
+ */
5
+ export declare class WorkersClient {
6
+ api: HatchetClient['api'];
7
+ tenantId: string;
8
+ constructor(client: HatchetClient);
9
+ get(workerId: string): Promise<import("../../../clients/rest/generated/data-contracts").Worker>;
10
+ list(): Promise<import("../../../clients/rest/generated/data-contracts").WorkerList>;
11
+ isPaused(workerId: string): Promise<boolean>;
12
+ pause(workerId: string): Promise<import("../../../clients/rest/generated/data-contracts").Worker>;
13
+ unpause(workerId: string): Promise<import("../../../clients/rest/generated/data-contracts").Worker>;
14
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.WorkersClient = void 0;
13
+ /**
14
+ * WorkersClient is used to list and manage workers
15
+ */
16
+ class WorkersClient {
17
+ constructor(client) {
18
+ this.api = client.api;
19
+ this.tenantId = client.tenantId;
20
+ }
21
+ get(workerId) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const { data } = yield this.api.workerGet(workerId);
24
+ return data;
25
+ });
26
+ }
27
+ list() {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const { data } = yield this.api.workerList(this.tenantId);
30
+ return data;
31
+ });
32
+ }
33
+ isPaused(workerId) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const wf = yield this.get(workerId);
36
+ return wf.status === 'PAUSED';
37
+ });
38
+ }
39
+ pause(workerId) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const { data } = yield this.api.workerUpdate(workerId, {
42
+ isPaused: true,
43
+ });
44
+ return data;
45
+ });
46
+ }
47
+ unpause(workerId) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const { data } = yield this.api.workerUpdate(workerId, {
50
+ isPaused: false,
51
+ });
52
+ return data;
53
+ });
54
+ }
55
+ }
56
+ exports.WorkersClient = WorkersClient;
@@ -0,0 +1,17 @@
1
+ import { Workflow } from '../../../workflow';
2
+ import { BaseWorkflowDeclaration } from '../..';
3
+ import { HatchetClient } from '../client';
4
+ export declare const workflowNameString: (workflow: string | Workflow | BaseWorkflowDeclaration<any, any>) => string;
5
+ /**
6
+ * WorkflowsClient is used to list and manage workflows
7
+ */
8
+ export declare class WorkflowsClient {
9
+ api: HatchetClient['api'];
10
+ tenantId: string;
11
+ private workflowCache;
12
+ private cacheTTL;
13
+ constructor(client: HatchetClient, cacheTTL?: number);
14
+ get(workflow: string | BaseWorkflowDeclaration<any, any> | Workflow): Promise<any>;
15
+ list(opts?: Parameters<typeof this.api.workflowList>[1]): Promise<import("../../../clients/rest/generated/data-contracts").WorkflowList>;
16
+ delete(workflow: string | BaseWorkflowDeclaration<any, any> | Workflow): Promise<void>;
17
+ }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.WorkflowsClient = exports.workflowNameString = void 0;
13
+ const workflowNameString = (workflow) => (typeof workflow === 'string' ? workflow : workflow.id);
14
+ exports.workflowNameString = workflowNameString;
15
+ /**
16
+ * WorkflowsClient is used to list and manage workflows
17
+ */
18
+ class WorkflowsClient {
19
+ constructor(client, cacheTTL) {
20
+ // Add a cache for workflows
21
+ this.workflowCache = new Map();
22
+ // Default cache TTL: 5 minutes (in ms)
23
+ this.cacheTTL = 5 * 60 * 1000;
24
+ this.api = client.api;
25
+ this.tenantId = client.tenantId;
26
+ // Allow custom cache TTL if provided
27
+ if (cacheTTL !== undefined) {
28
+ this.cacheTTL = cacheTTL;
29
+ }
30
+ }
31
+ get(workflow) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ // Get workflow name string
34
+ const name = (0, exports.workflowNameString)(workflow);
35
+ // Check cache first
36
+ const cached = this.workflowCache.get(name);
37
+ if (cached && cached.expiry > Date.now()) {
38
+ return cached.workflow;
39
+ }
40
+ // If not in cache or expired, fetch from API
41
+ try {
42
+ // Since the API only supports listing with a name filter,
43
+ // we'll use the list endpoint with a name filter
44
+ const { data } = yield this.api.workflowList(this.tenantId, {
45
+ name,
46
+ });
47
+ if (data && data.rows && data.rows.length > 0) {
48
+ const wf = data.rows[0];
49
+ // Cache the result
50
+ this.workflowCache.set(name, {
51
+ workflow: wf,
52
+ expiry: Date.now() + this.cacheTTL,
53
+ });
54
+ return workflow;
55
+ }
56
+ throw new Error(`Workflow with name ${name} not found`);
57
+ }
58
+ catch (error) {
59
+ // Clear cache on error
60
+ this.workflowCache.delete(name);
61
+ throw error;
62
+ }
63
+ });
64
+ }
65
+ list(opts) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const { data } = yield this.api.workflowList(this.tenantId, opts);
68
+ return data;
69
+ });
70
+ }
71
+ delete(workflow) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ const name = (0, exports.workflowNameString)(workflow);
74
+ try {
75
+ // Get the workflow first to find its ID
76
+ const workflowObj = yield this.get(name);
77
+ if (!workflowObj || !workflowObj.metadata || !workflowObj.metadata.id) {
78
+ throw new Error(`Could not find workflow with name ${name}`);
79
+ }
80
+ const { data } = yield this.api.workflowDelete(workflowObj.metadata.id);
81
+ // Remove from cache after deletion
82
+ this.workflowCache.delete(name);
83
+ return data;
84
+ }
85
+ catch (error) {
86
+ // Clear cache on error
87
+ this.workflowCache.delete(name);
88
+ throw error;
89
+ }
90
+ });
91
+ }
92
+ }
93
+ exports.WorkflowsClient = WorkflowsClient;
@@ -3,64 +3,72 @@ import { InternalHatchetClient } from '../../clients/hatchet-client';
3
3
  import { V0Worker } from '../../clients/worker';
4
4
  import { Workflow as V0Workflow } from '../../workflow';
5
5
  import { WebhookWorkerCreateRequest } from '../../clients/rest/generated/data-contracts';
6
- import { WorkflowDeclaration } from '../workflow';
6
+ import { BaseWorkflowDeclaration } from '../declaration';
7
+ import { HatchetClient } from '..';
7
8
  /**
8
9
  * Options for creating a new hatchet worker
9
10
  * @interface CreateWorkerOpts
10
11
  */
11
12
  export interface CreateWorkerOpts {
12
- /** Maximum number of concurrent runs on this worker */
13
+ /** (optional) Maximum number of concurrent runs on this worker, defaults to 100 */
13
14
  slots?: number;
14
- /** Array of workflows to register */
15
- workflows?: WorkflowDeclaration<any, any>[] | V0Workflow[];
16
- /** Worker labels for affinity-based assignment */
15
+ /** (optional) Array of workflows to register */
16
+ workflows?: BaseWorkflowDeclaration<any, any>[] | V0Workflow[];
17
+ /** (optional) Worker labels for affinity-based assignment */
17
18
  labels?: WorkerLabels;
18
- /** Whether to handle kill signals */
19
+ /** (optional) Whether to handle kill signals */
19
20
  handleKill?: boolean;
20
21
  /** @deprecated Use slots instead */
21
22
  maxRuns?: number;
23
+ /** (optional) Maximum number of concurrent runs on the durable worker, defaults to 1,000 */
24
+ durableSlots?: number;
22
25
  }
23
26
  /**
24
27
  * HatchetWorker class for workflow execution runtime
25
28
  */
26
29
  export declare class Worker {
30
+ config: CreateWorkerOpts;
31
+ name: string;
32
+ _v1: HatchetClient;
33
+ _v0: InternalHatchetClient;
27
34
  /** Internal reference to the underlying V0 worker implementation */
28
- v0: V0Worker;
35
+ nonDurable: V0Worker;
36
+ durable?: V0Worker;
29
37
  /**
30
38
  * Creates a new HatchetWorker instance
31
- * @param v0 - The V0 worker implementation
39
+ * @param nonDurable - The V0 worker implementation
32
40
  */
33
- constructor(v0: V0Worker);
41
+ constructor(v1: HatchetClient, v0: InternalHatchetClient, nonDurable: V0Worker, config: CreateWorkerOpts, name: string);
34
42
  /**
35
43
  * Creates and initializes a new HatchetWorker
36
44
  * @param v0 - The HatchetClient instance
37
45
  * @param options - Worker creation options
38
46
  * @returns A new HatchetWorker instance
39
47
  */
40
- static create(v0: InternalHatchetClient, name: string, options: CreateWorkerOpts): Promise<Worker>;
48
+ static create(v1: HatchetClient, v0: InternalHatchetClient, name: string, options: CreateWorkerOpts): Promise<Worker>;
41
49
  /**
42
50
  * Registers workflows with the worker
43
51
  * @param workflows - Array of workflows to register
44
52
  * @returns Array of registered workflow promises
45
53
  */
46
- registerWorkflows(workflows?: Array<WorkflowDeclaration<any, any> | V0Workflow>): Promise<void[]>;
54
+ registerWorkflows(workflows?: Array<BaseWorkflowDeclaration<any, any> | V0Workflow>): Promise<void[]>;
47
55
  /**
48
56
  * Registers a single workflow with the worker
49
57
  * @param workflow - The workflow to register
50
58
  * @returns A promise that resolves when the workflow is registered
51
59
  * @deprecated use registerWorkflows instead
52
60
  */
53
- registerWorkflow(workflow: WorkflowDeclaration<any, any> | V0Workflow): Promise<void[]>;
61
+ registerWorkflow(workflow: BaseWorkflowDeclaration<any, any> | V0Workflow): Promise<void[]>;
54
62
  /**
55
63
  * Starts the worker
56
64
  * @returns Promise that resolves when the worker is stopped or killed
57
65
  */
58
- start(): Promise<void>;
66
+ start(): Promise<void[]>;
59
67
  /**
60
68
  * Stops the worker
61
69
  * @returns Promise that resolves when the worker stops
62
70
  */
63
- stop(): Promise<void>;
71
+ stop(): Promise<void[]>;
64
72
  /**
65
73
  * Updates or inserts worker labels
66
74
  * @param labels - Worker labels to update
@@ -78,5 +86,7 @@ export declare class Worker {
78
86
  * @returns A promise that resolves when the webhook is registered
79
87
  */
80
88
  registerWebhook(webhook: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../../clients/rest/generated/data-contracts").WebhookWorkerCreated, any>>;
89
+ isPaused(): Promise<boolean>;
90
+ pause(): Promise<any[]>;
91
+ unpause(): Promise<any[]>;
81
92
  }
82
- export declare function toV0Workflow(wf: WorkflowDeclaration<any, any> | V0Workflow): V0Workflow;
@@ -10,18 +10,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Worker = void 0;
13
- exports.toV0Workflow = toV0Workflow;
14
- const workflow_1 = require("../workflow");
13
+ const declaration_1 = require("../declaration");
14
+ const DEFAULT_DURABLE_SLOTS = 1000;
15
15
  /**
16
16
  * HatchetWorker class for workflow execution runtime
17
17
  */
18
18
  class Worker {
19
19
  /**
20
20
  * Creates a new HatchetWorker instance
21
- * @param v0 - The V0 worker implementation
21
+ * @param nonDurable - The V0 worker implementation
22
22
  */
23
- constructor(v0) {
24
- this.v0 = v0;
23
+ constructor(v1, v0, nonDurable, config, name) {
24
+ this._v1 = v1;
25
+ this._v0 = v0;
26
+ this.nonDurable = nonDurable;
27
+ this.config = config;
28
+ this.name = name;
25
29
  }
26
30
  /**
27
31
  * Creates and initializes a new HatchetWorker
@@ -29,10 +33,10 @@ class Worker {
29
33
  * @param options - Worker creation options
30
34
  * @returns A new HatchetWorker instance
31
35
  */
32
- static create(v0, name, options) {
36
+ static create(v1, v0, name, options) {
33
37
  return __awaiter(this, void 0, void 0, function* () {
34
38
  const v0worker = yield v0.worker(name, Object.assign(Object.assign({}, options), { maxRuns: options.slots || options.maxRuns }));
35
- const worker = new Worker(v0worker);
39
+ const worker = new Worker(v1, v0, v0worker, options, name);
36
40
  yield worker.registerWorkflows(options.workflows);
37
41
  return worker;
38
42
  });
@@ -44,9 +48,21 @@ class Worker {
44
48
  */
45
49
  registerWorkflows(workflows) {
46
50
  return __awaiter(this, void 0, void 0, function* () {
47
- return Promise.all((workflows === null || workflows === void 0 ? void 0 : workflows.map((wf) => {
48
- return this.v0.registerWorkflow(toV0Workflow(wf));
49
- })) || []);
51
+ return Promise.all((workflows === null || workflows === void 0 ? void 0 : workflows.map((wf) => __awaiter(this, void 0, void 0, function* () {
52
+ if (wf instanceof declaration_1.BaseWorkflowDeclaration) {
53
+ // TODO check if tenant is V1
54
+ const register = this.nonDurable.registerWorkflowV1(wf);
55
+ if (wf.definition._durableTasks.length > 0) {
56
+ if (!this.durable) {
57
+ this.durable = yield this._v0.worker(`${this.name}-durable`, Object.assign(Object.assign({}, this.config), { maxRuns: this.config.durableSlots || DEFAULT_DURABLE_SLOTS }));
58
+ }
59
+ this.durable.registerDurableActionsV1(wf.definition);
60
+ }
61
+ return register;
62
+ }
63
+ // fallback to v0 client for backwards compatibility
64
+ return this.nonDurable.registerWorkflow(wf);
65
+ }))) || []);
50
66
  });
51
67
  }
52
68
  /**
@@ -63,14 +79,22 @@ class Worker {
63
79
  * @returns Promise that resolves when the worker is stopped or killed
64
80
  */
65
81
  start() {
66
- return this.v0.start();
82
+ const workers = [this.nonDurable];
83
+ if (this.durable) {
84
+ workers.push(this.durable);
85
+ }
86
+ return Promise.all(workers.map((w) => w.start()));
67
87
  }
68
88
  /**
69
89
  * Stops the worker
70
90
  * @returns Promise that resolves when the worker stops
71
91
  */
72
92
  stop() {
73
- return this.v0.stop();
93
+ const workers = [this.nonDurable];
94
+ if (this.durable) {
95
+ workers.push(this.durable);
96
+ }
97
+ return Promise.all(workers.map((w) => w.stop()));
74
98
  }
75
99
  /**
76
100
  * Updates or inserts worker labels
@@ -78,14 +102,14 @@ class Worker {
78
102
  * @returns Promise that resolves when labels are updated
79
103
  */
80
104
  upsertLabels(labels) {
81
- return this.v0.upsertLabels(labels);
105
+ return this.nonDurable.upsertLabels(labels);
82
106
  }
83
107
  /**
84
108
  * Get the labels for the worker
85
109
  * @returns The labels for the worker
86
110
  */
87
111
  getLabels() {
88
- return this.v0.labels;
112
+ return this.nonDurable.labels;
89
113
  }
90
114
  /**
91
115
  * Register a webhook with the worker
@@ -93,39 +117,44 @@ class Worker {
93
117
  * @returns A promise that resolves when the webhook is registered
94
118
  */
95
119
  registerWebhook(webhook) {
96
- return this.v0.registerWebhook(webhook);
120
+ return this.nonDurable.registerWebhook(webhook);
97
121
  }
98
- }
99
- exports.Worker = Worker;
100
- function toV0Workflow(wf) {
101
- if (wf instanceof workflow_1.WorkflowDeclaration) {
102
- const { definition } = wf;
103
- return {
104
- id: definition.name,
105
- description: definition.description || '',
106
- version: definition.version || '',
107
- sticky: definition.sticky,
108
- scheduleTimeout: definition.scheduleTimeout,
109
- on: definition.on,
110
- concurrency: definition.concurrency,
111
- onFailure: definition.onFailure && {
112
- name: 'on-failure',
113
- run: (ctx) => definition.onFailure(ctx),
114
- },
115
- steps: definition.tasks.map((task) => {
116
- var _a;
117
- return ({
118
- name: task.name,
119
- parents: (_a = task.parents) === null || _a === void 0 ? void 0 : _a.map((p) => p.name),
120
- run: (ctx) => task.fn(ctx.workflowInput(), ctx),
121
- timeout: task.timeout,
122
- retries: task.retries,
123
- rate_limits: task.rateLimits,
124
- worker_labels: task.workerLabels,
125
- backoff: task.backoff,
126
- });
127
- }),
128
- };
122
+ isPaused() {
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ var _a, _b;
125
+ const promises = [];
126
+ if ((_a = this.nonDurable) === null || _a === void 0 ? void 0 : _a.workerId) {
127
+ promises.push(this._v1.workers.isPaused(this.nonDurable.workerId));
128
+ }
129
+ if ((_b = this.durable) === null || _b === void 0 ? void 0 : _b.workerId) {
130
+ promises.push(this._v1.workers.isPaused(this.durable.workerId));
131
+ }
132
+ const res = yield Promise.all(promises);
133
+ return !res.includes(false);
134
+ });
135
+ }
136
+ // TODO docstrings
137
+ pause() {
138
+ var _a, _b;
139
+ const promises = [];
140
+ if ((_a = this.nonDurable) === null || _a === void 0 ? void 0 : _a.workerId) {
141
+ promises.push(this._v1.workers.pause(this.nonDurable.workerId));
142
+ }
143
+ if ((_b = this.durable) === null || _b === void 0 ? void 0 : _b.workerId) {
144
+ promises.push(this._v1.workers.pause(this.durable.workerId));
145
+ }
146
+ return Promise.all(promises);
147
+ }
148
+ unpause() {
149
+ var _a, _b;
150
+ const promises = [];
151
+ if ((_a = this.nonDurable) === null || _a === void 0 ? void 0 : _a.workerId) {
152
+ promises.push(this._v1.workers.unpause(this.nonDurable.workerId));
153
+ }
154
+ if ((_b = this.durable) === null || _b === void 0 ? void 0 : _b.workerId) {
155
+ promises.push(this._v1.workers.unpause(this.durable.workerId));
156
+ }
157
+ return Promise.all(promises);
129
158
  }
130
- return wf;
131
159
  }
160
+ exports.Worker = Worker;
@@ -0,0 +1,18 @@
1
+ export declare enum Action {
2
+ CREATE = 0,
3
+ QUEUE = 1,
4
+ CANCEL = 2,
5
+ SKIP = 3,
6
+ UNRECOGNIZED = -1
7
+ }
8
+ export interface BaseCondition {
9
+ readableDataKey?: string;
10
+ action?: Action;
11
+ /** a UUID defining the OR group for this condition */
12
+ orGroupId?: string;
13
+ expression?: string;
14
+ }
15
+ export declare abstract class Condition {
16
+ base: BaseCondition;
17
+ constructor(base: BaseCondition);
18
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Condition = exports.Action = void 0;
4
+ /* eslint-disable no-shadow */
5
+ var Action;
6
+ (function (Action) {
7
+ Action[Action["CREATE"] = 0] = "CREATE";
8
+ Action[Action["QUEUE"] = 1] = "QUEUE";
9
+ Action[Action["CANCEL"] = 2] = "CANCEL";
10
+ Action[Action["SKIP"] = 3] = "SKIP";
11
+ Action[Action["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
12
+ })(Action || (exports.Action = Action = {}));
13
+ class Condition {
14
+ constructor(base) {
15
+ this.base = base;
16
+ }
17
+ }
18
+ exports.Condition = Condition;
@@ -0,0 +1,31 @@
1
+ import { Condition, Action } from './base';
2
+ import { Parent } from './parent-condition';
3
+ import { Sleep, SleepCondition } from './sleep-condition';
4
+ import { UserEvent, UserEventCondition } from './user-event-condition';
5
+ export { Sleep, SleepCondition, UserEvent, UserEventCondition };
6
+ export type IConditions = Sleep | UserEvent | Parent;
7
+ export type Conditions = Condition | OrCondition | IConditions;
8
+ export declare class OrCondition {
9
+ conditions: Condition[];
10
+ constructor(conditions: Condition[]);
11
+ }
12
+ /**
13
+ * Creates a condition that waits for all provided conditions to be met (AND logic)
14
+ * use Or() to create a condition that waits for any of the provided conditions to be met (OR logic)
15
+ * @param conditions - Conditions or OrConditions to be rendered
16
+ * @returns A flattened array of Conditions
17
+ *
18
+ * @example
19
+ * const conditions = Render(
20
+ * Or({ sleepFor: 5 }, { eventKey: 'user:update' }),
21
+ * { eventKey: 'user:create' },
22
+ * Or({ eventKey: 'user:update' }, { eventKey: 'user:delete' })
23
+ * );
24
+ */
25
+ export declare function Render(action?: Action, conditions?: Conditions | Conditions[]): Condition[];
26
+ /**
27
+ * Creates a condition group with OR logic
28
+ * Flattens nested Or conditions to ensure proper grouping
29
+ */
30
+ export declare function Or(...conditionsOrObjs: (IConditions | Condition)[]): OrCondition;
31
+ export declare function generateGroupId(): string;