@hatchet-dev/typescript-sdk 1.34.1 → 1.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.34.1",
3
+ "version": "1.35.0",
4
4
  "engines": {
5
5
  "node": ">=20"
6
6
  },
@@ -1,6 +1,17 @@
1
1
  import { BaseWorkflowDeclaration, WorkflowDefinition } from '../..';
2
2
  import type { LegacyWorkflow } from '../../../legacy/legacy-transformer';
3
+ import { WorkflowPauseScheduledCronRunQueueBehavior } from '../../../clients/rest/generated/data-contracts';
3
4
  import { HatchetClient } from '../client';
5
+ import { Duration } from '../duration';
6
+ export { WorkflowPauseScheduledCronRunQueueBehavior };
7
+ export type PauseWorkflowOpts = {
8
+ /** How long runs stay queued while the workflow is paused before they are dropped. */
9
+ queueTTL: Duration;
10
+ /** The behavior of cron runs triggered while the workflow is paused. Defaults to QUEUE. */
11
+ pausedWorkflowCronRunQueueBehavior?: WorkflowPauseScheduledCronRunQueueBehavior;
12
+ /** The behavior of scheduled runs triggered while the workflow is paused. Defaults to QUEUE. */
13
+ pausedWorkflowScheduledRunQueueBehavior?: WorkflowPauseScheduledCronRunQueueBehavior;
14
+ };
4
15
  export declare const workflowNameString: (workflow: string | WorkflowDefinition | BaseWorkflowDeclaration<any, any> | LegacyWorkflow) => string;
5
16
  /**
6
17
  * The workflows client is a client for managing workflows programmatically within Hatchet.
@@ -39,4 +50,18 @@ export declare class WorkflowsClient {
39
50
  * @returns A promise that resolves to the deleted workflow.
40
51
  */
41
52
  delete(workflow: string | BaseWorkflowDeclaration<any, any> | LegacyWorkflow): Promise<void>;
53
+ /**
54
+ * Pause a workflow. While paused, new runs of the workflow are queued but not started.
55
+ * @param workflow - The workflow name, ID, or object.
56
+ * @param opts - The options for the pause operation.
57
+ * @returns A promise that resolves to the updated workflow.
58
+ */
59
+ pause(workflow: string | BaseWorkflowDeclaration<any, any> | LegacyWorkflow, opts: PauseWorkflowOpts): Promise<import("../../../clients/rest/generated/data-contracts").Workflow>;
60
+ /**
61
+ * Unpause a workflow.
62
+ * @param workflow - The workflow name, ID, or object.
63
+ * @returns A promise that resolves to the updated workflow.
64
+ */
65
+ unpause(workflow: string | BaseWorkflowDeclaration<any, any> | LegacyWorkflow): Promise<import("../../../clients/rest/generated/data-contracts").Workflow>;
66
+ private update;
42
67
  }
@@ -9,9 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.WorkflowsClient = exports.workflowNameString = void 0;
12
+ exports.WorkflowsClient = exports.workflowNameString = exports.WorkflowPauseScheduledCronRunQueueBehavior = void 0;
13
13
  const legacy_transformer_1 = require("../../../legacy/legacy-transformer");
14
14
  const uuid_1 = require("../../../util/uuid");
15
+ const data_contracts_1 = require("../../../clients/rest/generated/data-contracts");
16
+ Object.defineProperty(exports, "WorkflowPauseScheduledCronRunQueueBehavior", { enumerable: true, get: function () { return data_contracts_1.WorkflowPauseScheduledCronRunQueueBehavior; } });
17
+ const duration_1 = require("../duration");
15
18
  const workflowNameString = (workflow) => {
16
19
  if (typeof workflow === 'string') {
17
20
  return workflow;
@@ -148,5 +151,50 @@ class WorkflowsClient {
148
151
  }
149
152
  });
150
153
  }
154
+ /**
155
+ * Pause a workflow. While paused, new runs of the workflow are queued but not started.
156
+ * @param workflow - The workflow name, ID, or object.
157
+ * @param opts - The options for the pause operation.
158
+ * @returns A promise that resolves to the updated workflow.
159
+ */
160
+ pause(workflow, opts) {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ var _a, _b;
163
+ return this.update(workflow, {
164
+ pause: {
165
+ action: 'pause',
166
+ pausedWorkflowQueueTTL: (0, duration_1.durationToString)(opts.queueTTL),
167
+ pausedWorkflowCronRunQueueBehavior: (_a = opts.pausedWorkflowCronRunQueueBehavior) !== null && _a !== void 0 ? _a : data_contracts_1.WorkflowPauseScheduledCronRunQueueBehavior.QUEUE,
168
+ pausedWorkflowScheduledRunQueueBehavior: (_b = opts.pausedWorkflowScheduledRunQueueBehavior) !== null && _b !== void 0 ? _b : data_contracts_1.WorkflowPauseScheduledCronRunQueueBehavior.QUEUE,
169
+ },
170
+ });
171
+ });
172
+ }
173
+ /**
174
+ * Unpause a workflow.
175
+ * @param workflow - The workflow name, ID, or object.
176
+ * @returns A promise that resolves to the updated workflow.
177
+ */
178
+ unpause(workflow) {
179
+ return __awaiter(this, void 0, void 0, function* () {
180
+ return this.update(workflow, { pause: { action: 'unpause' } });
181
+ });
182
+ }
183
+ update(workflow, request) {
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ const name = (0, exports.workflowNameString)(workflow);
186
+ const workflowId = yield this.getWorkflowIdFromName(name);
187
+ try {
188
+ const { data } = yield this.api.workflowUpdate(workflowId, request);
189
+ this.workflowCache.delete(name);
190
+ this.workflowCache.delete(data.name);
191
+ return data;
192
+ }
193
+ catch (error) {
194
+ this.workflowCache.delete(name);
195
+ throw error;
196
+ }
197
+ });
198
+ }
151
199
  }
152
200
  exports.WorkflowsClient = WorkflowsClient;
@@ -12,6 +12,7 @@ import { IHatchetClient } from './client/client.interface';
12
12
  import { CreateWorkflowTaskOpts, CreateOnFailureTaskOpts, TaskFn, CreateWorkflowDurableTaskOpts, CreateBaseTaskOpts, CreateOnSuccessTaskOpts, Concurrency, DurableTaskFn, WorkerLabelComparator, IdempotencyConfig, BatchTaskConfig, BatchTaskFn } from './task';
13
13
  import { Duration } from './client/duration';
14
14
  import { MetricsClient } from './client/features/metrics';
15
+ import type { PauseWorkflowOpts } from './client/features/workflows';
15
16
  import { InputType, OutputType, UnknownInputType, JsonObject, Resolved } from './types';
16
17
  import { Context, DurableContext } from './client/worker/context';
17
18
  import { EvictionPolicy } from './client/worker/eviction/eviction-policy';
@@ -374,6 +375,19 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
374
375
  * @throws Error if the workflow is not bound to a Hatchet client.
375
376
  */
376
377
  get(): Promise<import("../clients/rest/generated/data-contracts").Workflow>;
378
+ /**
379
+ * Pause the workflow. While paused, new runs of the workflow are queued but not started.
380
+ * @param opts - The options for the pause operation.
381
+ * @returns A promise that resolves to the updated workflow.
382
+ * @throws Error if the workflow is not bound to a Hatchet client.
383
+ */
384
+ pause(opts: PauseWorkflowOpts): Promise<import("../clients/rest/generated/data-contracts").Workflow>;
385
+ /**
386
+ * Unpause the workflow.
387
+ * @returns A promise that resolves to the updated workflow.
388
+ * @throws Error if the workflow is not bound to a Hatchet client.
389
+ */
390
+ unpause(): Promise<import("../clients/rest/generated/data-contracts").Workflow>;
377
391
  /**
378
392
  * @deprecated use definition.name instead
379
393
  * @hidden
package/v1/declaration.js CHANGED
@@ -379,27 +379,29 @@ class BaseWorkflowDeclaration {
379
379
  }
380
380
  return this.client.workflows.get(this);
381
381
  }
382
- // // gets the pause state of the workflow
383
- // isPaused() {
384
- // if (!this.client) {
385
- // throw UNBOUND_ERR;
386
- // }
387
- // return this.client.workflows.isPaused(this);
388
- // }
389
- // // pause assignment of workflow
390
- // pause() {
391
- // if (!this.client) {
392
- // throw UNBOUND_ERR;
393
- // }
394
- // return this.client.workflows.pause(this);
395
- // }
396
- // // unpause assignment of workflow
397
- // unpause() {
398
- // if (!this.client) {
399
- // throw UNBOUND_ERR;
400
- // }
401
- // return this.client.workflows.unpause(this);
402
- // }
382
+ /**
383
+ * Pause the workflow. While paused, new runs of the workflow are queued but not started.
384
+ * @param opts - The options for the pause operation.
385
+ * @returns A promise that resolves to the updated workflow.
386
+ * @throws Error if the workflow is not bound to a Hatchet client.
387
+ */
388
+ pause(opts) {
389
+ if (!this.client) {
390
+ throw UNBOUND_ERR;
391
+ }
392
+ return this.client.workflows.pause(this, opts);
393
+ }
394
+ /**
395
+ * Unpause the workflow.
396
+ * @returns A promise that resolves to the updated workflow.
397
+ * @throws Error if the workflow is not bound to a Hatchet client.
398
+ */
399
+ unpause() {
400
+ if (!this.client) {
401
+ throw UNBOUND_ERR;
402
+ }
403
+ return this.client.workflows.unpause(this);
404
+ }
403
405
  /**
404
406
  * @deprecated use definition.name instead
405
407
  * @hidden
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
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
+ const v1_1 = require("../..");
13
+ const hatchet_client_1 = require("../hatchet-client");
14
+ const pausableWorkflow = hatchet_client_1.hatchet.workflow({
15
+ name: 'pausable-workflow',
16
+ });
17
+ function main() {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ // > Pause a workflow
20
+ yield pausableWorkflow.pause({
21
+ queueTTL: '24h',
22
+ pausedWorkflowCronRunQueueBehavior: v1_1.WorkflowPauseScheduledCronRunQueueBehavior.DROP,
23
+ pausedWorkflowScheduledRunQueueBehavior: v1_1.WorkflowPauseScheduledCronRunQueueBehavior.QUEUE,
24
+ });
25
+ // !!
26
+ // > Unpause a workflow
27
+ yield pausableWorkflow.unpause();
28
+ // !!
29
+ });
30
+ }
31
+ if (require.main === module) {
32
+ main()
33
+ .catch(console.error)
34
+ .finally(() => process.exit(0));
35
+ }
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.34.1";
1
+ export declare const HATCHET_VERSION = "1.35.0";
package/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HATCHET_VERSION = void 0;
4
- exports.HATCHET_VERSION = '1.34.1';
4
+ exports.HATCHET_VERSION = '1.35.0';