@hatchet-dev/typescript-sdk 1.26.2 → 1.27.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 +1 -1
- package/protoc/v1/workflows.d.ts +10 -1
- package/protoc/v1/workflows.js +51 -3
- package/v1/client/worker/worker-internal.js +7 -1
- package/v1/examples/idempotency/workflow.d.ts +3 -0
- package/v1/examples/idempotency/workflow.js +14 -1
- package/v1/task.d.ts +13 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/package.json
CHANGED
package/protoc/v1/workflows.d.ts
CHANGED
|
@@ -45,6 +45,13 @@ export declare enum ConcurrencyLimitStrategy {
|
|
|
45
45
|
}
|
|
46
46
|
export declare function concurrencyLimitStrategyFromJSON(object: any): ConcurrencyLimitStrategy;
|
|
47
47
|
export declare function concurrencyLimitStrategyToJSON(object: ConcurrencyLimitStrategy): string;
|
|
48
|
+
export declare enum IdempotencyMethod {
|
|
49
|
+
TTL = 0,
|
|
50
|
+
STATUS = 1,
|
|
51
|
+
UNRECOGNIZED = -1
|
|
52
|
+
}
|
|
53
|
+
export declare function idempotencyMethodFromJSON(object: any): IdempotencyMethod;
|
|
54
|
+
export declare function idempotencyMethodToJSON(object: IdempotencyMethod): string;
|
|
48
55
|
export interface CancelTasksRequest {
|
|
49
56
|
/** a list of external UUIDs */
|
|
50
57
|
externalIds: string[];
|
|
@@ -136,8 +143,10 @@ export interface CreateWorkflowVersionRequest {
|
|
|
136
143
|
export interface IdempotencyConfig {
|
|
137
144
|
/** a CEL expression for determining the idempotency key for workflow runs */
|
|
138
145
|
expression: string;
|
|
139
|
-
/** time-to-live for idempotency keys in milliseconds */
|
|
146
|
+
/** time-to-live for idempotency keys in milliseconds. if the method is `STATUS`, this is a "fallback" - the longest the key can live before it's evicted */
|
|
140
147
|
ttlMs: number;
|
|
148
|
+
/** the method to use for idempotency, defaults to TTL */
|
|
149
|
+
method?: IdempotencyMethod | undefined;
|
|
141
150
|
}
|
|
142
151
|
export interface IdempotencyCollisionError {
|
|
143
152
|
/** the external ID of the existing workflow run that caused the collision */
|
package/protoc/v1/workflows.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: v1/workflows.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.AdminServiceDefinition = exports.GetRunDetailsResponse_TaskRunsEntry = exports.GetRunDetailsResponse = exports.TaskRunDetail = exports.GetRunDetailsRequest = exports.CreateWorkflowVersionResponse = exports.CreateTaskRateLimit = exports.CreateTaskOpts_SlotRequestsEntry = exports.CreateTaskOpts_WorkerLabelsEntry = exports.CreateTaskOpts = exports.Concurrency = exports.DefaultFilter = exports.BulkTriggerIdempotencyCollisionError = exports.IdempotencyCollisionError = exports.IdempotencyConfig = exports.CreateWorkflowVersionRequest = exports.BranchDurableTaskResponse = exports.BranchDurableTaskRequest = exports.TriggerWorkflowRunResponse = exports.TriggerWorkflowRunRequest_DesiredWorkerLabelsEntry = exports.TriggerWorkflowRunRequest = exports.ReplayTasksResponse = exports.CancelTasksResponse = exports.TasksFilter = exports.ReplayTasksRequest = exports.CancelTasksRequest = exports.ConcurrencyLimitStrategy = exports.RunStatus = exports.RateLimitDuration = exports.StickyStrategy = exports.protobufPackage = void 0;
|
|
8
|
+
exports.AdminServiceDefinition = exports.GetRunDetailsResponse_TaskRunsEntry = exports.GetRunDetailsResponse = exports.TaskRunDetail = exports.GetRunDetailsRequest = exports.CreateWorkflowVersionResponse = exports.CreateTaskRateLimit = exports.CreateTaskOpts_SlotRequestsEntry = exports.CreateTaskOpts_WorkerLabelsEntry = exports.CreateTaskOpts = exports.Concurrency = exports.DefaultFilter = exports.BulkTriggerIdempotencyCollisionError = exports.IdempotencyCollisionError = exports.IdempotencyConfig = exports.CreateWorkflowVersionRequest = exports.BranchDurableTaskResponse = exports.BranchDurableTaskRequest = exports.TriggerWorkflowRunResponse = exports.TriggerWorkflowRunRequest_DesiredWorkerLabelsEntry = exports.TriggerWorkflowRunRequest = exports.ReplayTasksResponse = exports.CancelTasksResponse = exports.TasksFilter = exports.ReplayTasksRequest = exports.CancelTasksRequest = exports.IdempotencyMethod = exports.ConcurrencyLimitStrategy = exports.RunStatus = exports.RateLimitDuration = exports.StickyStrategy = exports.protobufPackage = void 0;
|
|
9
9
|
exports.stickyStrategyFromJSON = stickyStrategyFromJSON;
|
|
10
10
|
exports.stickyStrategyToJSON = stickyStrategyToJSON;
|
|
11
11
|
exports.rateLimitDurationFromJSON = rateLimitDurationFromJSON;
|
|
@@ -14,6 +14,8 @@ exports.runStatusFromJSON = runStatusFromJSON;
|
|
|
14
14
|
exports.runStatusToJSON = runStatusToJSON;
|
|
15
15
|
exports.concurrencyLimitStrategyFromJSON = concurrencyLimitStrategyFromJSON;
|
|
16
16
|
exports.concurrencyLimitStrategyToJSON = concurrencyLimitStrategyToJSON;
|
|
17
|
+
exports.idempotencyMethodFromJSON = idempotencyMethodFromJSON;
|
|
18
|
+
exports.idempotencyMethodToJSON = idempotencyMethodToJSON;
|
|
17
19
|
/* eslint-disable */
|
|
18
20
|
const wire_1 = require("@bufbuild/protobuf/wire");
|
|
19
21
|
const timestamp_1 = require("../google/protobuf/timestamp");
|
|
@@ -218,6 +220,37 @@ function concurrencyLimitStrategyToJSON(object) {
|
|
|
218
220
|
return 'UNRECOGNIZED';
|
|
219
221
|
}
|
|
220
222
|
}
|
|
223
|
+
var IdempotencyMethod;
|
|
224
|
+
(function (IdempotencyMethod) {
|
|
225
|
+
IdempotencyMethod[IdempotencyMethod["TTL"] = 0] = "TTL";
|
|
226
|
+
IdempotencyMethod[IdempotencyMethod["STATUS"] = 1] = "STATUS";
|
|
227
|
+
IdempotencyMethod[IdempotencyMethod["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
|
|
228
|
+
})(IdempotencyMethod || (exports.IdempotencyMethod = IdempotencyMethod = {}));
|
|
229
|
+
function idempotencyMethodFromJSON(object) {
|
|
230
|
+
switch (object) {
|
|
231
|
+
case 0:
|
|
232
|
+
case 'TTL':
|
|
233
|
+
return IdempotencyMethod.TTL;
|
|
234
|
+
case 1:
|
|
235
|
+
case 'STATUS':
|
|
236
|
+
return IdempotencyMethod.STATUS;
|
|
237
|
+
case -1:
|
|
238
|
+
case 'UNRECOGNIZED':
|
|
239
|
+
default:
|
|
240
|
+
return IdempotencyMethod.UNRECOGNIZED;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function idempotencyMethodToJSON(object) {
|
|
244
|
+
switch (object) {
|
|
245
|
+
case IdempotencyMethod.TTL:
|
|
246
|
+
return 'TTL';
|
|
247
|
+
case IdempotencyMethod.STATUS:
|
|
248
|
+
return 'STATUS';
|
|
249
|
+
case IdempotencyMethod.UNRECOGNIZED:
|
|
250
|
+
default:
|
|
251
|
+
return 'UNRECOGNIZED';
|
|
252
|
+
}
|
|
253
|
+
}
|
|
221
254
|
function createBaseCancelTasksRequest() {
|
|
222
255
|
return { externalIds: [], filter: undefined };
|
|
223
256
|
}
|
|
@@ -1422,7 +1455,7 @@ exports.CreateWorkflowVersionRequest = {
|
|
|
1422
1455
|
},
|
|
1423
1456
|
};
|
|
1424
1457
|
function createBaseIdempotencyConfig() {
|
|
1425
|
-
return { expression: '', ttlMs: 0 };
|
|
1458
|
+
return { expression: '', ttlMs: 0, method: undefined };
|
|
1426
1459
|
}
|
|
1427
1460
|
exports.IdempotencyConfig = {
|
|
1428
1461
|
encode(message, writer = new wire_1.BinaryWriter()) {
|
|
@@ -1432,6 +1465,9 @@ exports.IdempotencyConfig = {
|
|
|
1432
1465
|
if (message.ttlMs !== 0) {
|
|
1433
1466
|
writer.uint32(16).int64(message.ttlMs);
|
|
1434
1467
|
}
|
|
1468
|
+
if (message.method !== undefined) {
|
|
1469
|
+
writer.uint32(24).int32(message.method);
|
|
1470
|
+
}
|
|
1435
1471
|
return writer;
|
|
1436
1472
|
},
|
|
1437
1473
|
decode(input, length) {
|
|
@@ -1455,6 +1491,13 @@ exports.IdempotencyConfig = {
|
|
|
1455
1491
|
message.ttlMs = longToNumber(reader.int64());
|
|
1456
1492
|
continue;
|
|
1457
1493
|
}
|
|
1494
|
+
case 3: {
|
|
1495
|
+
if (tag !== 24) {
|
|
1496
|
+
break;
|
|
1497
|
+
}
|
|
1498
|
+
message.method = reader.int32();
|
|
1499
|
+
continue;
|
|
1500
|
+
}
|
|
1458
1501
|
}
|
|
1459
1502
|
if ((tag & 7) === 4 || tag === 0) {
|
|
1460
1503
|
break;
|
|
@@ -1471,6 +1514,7 @@ exports.IdempotencyConfig = {
|
|
|
1471
1514
|
: isSet(object.ttl_ms)
|
|
1472
1515
|
? globalThis.Number(object.ttl_ms)
|
|
1473
1516
|
: 0,
|
|
1517
|
+
method: isSet(object.method) ? idempotencyMethodFromJSON(object.method) : undefined,
|
|
1474
1518
|
};
|
|
1475
1519
|
},
|
|
1476
1520
|
toJSON(message) {
|
|
@@ -1481,16 +1525,20 @@ exports.IdempotencyConfig = {
|
|
|
1481
1525
|
if (message.ttlMs !== 0) {
|
|
1482
1526
|
obj.ttlMs = Math.round(message.ttlMs);
|
|
1483
1527
|
}
|
|
1528
|
+
if (message.method !== undefined) {
|
|
1529
|
+
obj.method = idempotencyMethodToJSON(message.method);
|
|
1530
|
+
}
|
|
1484
1531
|
return obj;
|
|
1485
1532
|
},
|
|
1486
1533
|
create(base) {
|
|
1487
1534
|
return exports.IdempotencyConfig.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
1488
1535
|
},
|
|
1489
1536
|
fromPartial(object) {
|
|
1490
|
-
var _a, _b;
|
|
1537
|
+
var _a, _b, _c;
|
|
1491
1538
|
const message = createBaseIdempotencyConfig();
|
|
1492
1539
|
message.expression = (_a = object.expression) !== null && _a !== void 0 ? _a : '';
|
|
1493
1540
|
message.ttlMs = (_b = object.ttlMs) !== null && _b !== void 0 ? _b : 0;
|
|
1541
|
+
message.method = (_c = object.method) !== null && _c !== void 0 ? _c : undefined;
|
|
1494
1542
|
return message;
|
|
1495
1543
|
},
|
|
1496
1544
|
};
|
|
@@ -63,6 +63,7 @@ const dispatcher_1 = require("../../../protoc/dispatcher");
|
|
|
63
63
|
const hatchet_promise_1 = __importStar(require("../../../util/hatchet-promise/hatchet-promise"));
|
|
64
64
|
const workflows_1 = require("../../../protoc/workflows");
|
|
65
65
|
const logger_1 = require("../../../util/logger");
|
|
66
|
+
const workflows_2 = require("../../../protoc/v1/workflows");
|
|
66
67
|
const task_1 = require("../../task");
|
|
67
68
|
const transformer_1 = require("../../conditions/transformer");
|
|
68
69
|
const z = __importStar(require("zod/v4"));
|
|
@@ -338,7 +339,12 @@ class InternalWorker {
|
|
|
338
339
|
idempotency: workflow.idempotency
|
|
339
340
|
? {
|
|
340
341
|
expression: workflow.idempotency.expression,
|
|
341
|
-
ttlMs: workflow.idempotency.
|
|
342
|
+
ttlMs: workflow.idempotency.strategy === 'status'
|
|
343
|
+
? workflow.idempotency.fallbackTtlMs
|
|
344
|
+
: workflow.idempotency.ttlMs,
|
|
345
|
+
method: workflow.idempotency.strategy === 'status'
|
|
346
|
+
? workflows_2.IdempotencyMethod.STATUS
|
|
347
|
+
: workflows_2.IdempotencyMethod.TTL,
|
|
342
348
|
}
|
|
343
349
|
: undefined,
|
|
344
350
|
});
|
|
@@ -8,3 +8,6 @@ export declare const idempotentTask: import("../..").TaskWorkflowDeclaration<Ide
|
|
|
8
8
|
export declare const idempotentTaskShortWindow: import("../..").TaskWorkflowDeclaration<IdempotencyInput, {
|
|
9
9
|
result: string;
|
|
10
10
|
}, {}, {}, {}, {}>;
|
|
11
|
+
export declare const idempotentStatusBasedTask: import("../..").TaskWorkflowDeclaration<IdempotencyInput, {
|
|
12
|
+
result: string;
|
|
13
|
+
}, {}, {}, {}, {}>;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.idempotentTaskShortWindow = exports.idempotentTask = exports.EVENT_KEY = void 0;
|
|
12
|
+
exports.idempotentStatusBasedTask = exports.idempotentTaskShortWindow = exports.idempotentTask = exports.EVENT_KEY = void 0;
|
|
13
13
|
const hatchet_client_1 = require("../hatchet-client");
|
|
14
14
|
exports.EVENT_KEY = 'ts-e2e:idempotency-example';
|
|
15
15
|
// > idempotency
|
|
@@ -37,3 +37,16 @@ exports.idempotentTaskShortWindow = hatchet_client_1.hatchet.task({
|
|
|
37
37
|
return { result: `Hello, world from task ${input.id}` };
|
|
38
38
|
}),
|
|
39
39
|
});
|
|
40
|
+
// > status-based-idempotency
|
|
41
|
+
exports.idempotentStatusBasedTask = hatchet_client_1.hatchet.task({
|
|
42
|
+
name: 'ts-e2e-idempotent-status-based-task',
|
|
43
|
+
idempotency: {
|
|
44
|
+
strategy: 'status',
|
|
45
|
+
expression: 'input.id',
|
|
46
|
+
fallbackTtlMs: 10000,
|
|
47
|
+
},
|
|
48
|
+
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
return { result: `Hello, world from task ${input.id}` };
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
// !!
|
package/v1/task.d.ts
CHANGED
|
@@ -56,10 +56,22 @@ export type TTLBasedIdempotencyConfig = BaseIdempotencyConfig & {
|
|
|
56
56
|
*/
|
|
57
57
|
ttlMs: number;
|
|
58
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* Status-based idempotency: keeps the idempotency key alive until the associated run
|
|
61
|
+
* reaches a terminal status. `fallbackTtlMs` caps how long the key can live before it's evicted.
|
|
62
|
+
*/
|
|
63
|
+
export type StatusBasedIdempotencyConfig = BaseIdempotencyConfig & {
|
|
64
|
+
strategy: 'status';
|
|
65
|
+
/**
|
|
66
|
+
* Fallback time-to-live (in milliseconds): the longest the idempotency key can live
|
|
67
|
+
* before it's evicted, even if the run has not reached a terminal status.
|
|
68
|
+
*/
|
|
69
|
+
fallbackTtlMs: number;
|
|
70
|
+
};
|
|
59
71
|
/**
|
|
60
72
|
* Union of all supported idempotency configurations.
|
|
61
73
|
*/
|
|
62
|
-
export type IdempotencyConfig = TTLBasedIdempotencyConfig;
|
|
74
|
+
export type IdempotencyConfig = TTLBasedIdempotencyConfig | StatusBasedIdempotencyConfig;
|
|
63
75
|
export declare class NonRetryableError extends Error {
|
|
64
76
|
constructor(message?: string);
|
|
65
77
|
}
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.27.0";
|
package/version.js
CHANGED