@hatchet-dev/typescript-sdk 1.19.2-alpha.3 → 1.20.1
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/clients/rest/generated/Api.d.ts +115 -30
- package/clients/rest/generated/Api.js +40 -10
- package/clients/rest/generated/data-contracts.d.ts +95 -30
- package/clients/rest/generated/data-contracts.js +36 -17
- package/package.json +1 -1
- package/protoc/dispatcher/dispatcher.d.ts +30 -30
- package/protoc/dispatcher/dispatcher.js +1 -1
- package/protoc/events/events.d.ts +10 -10
- package/protoc/events/events.js +1 -1
- package/protoc/google/protobuf/timestamp.js +1 -1
- package/protoc/v1/dispatcher.d.ts +6 -6
- package/protoc/v1/dispatcher.js +1 -1
- package/protoc/v1/shared/condition.d.ts +3 -0
- package/protoc/v1/shared/condition.js +68 -3
- package/protoc/v1/shared/trigger.js +1 -1
- package/protoc/v1/workflows.d.ts +12 -12
- package/protoc/v1/workflows.js +1 -1
- package/protoc/workflows/workflows.d.ts +10 -10
- package/protoc/workflows/workflows.js +1 -1
- package/v1/client/worker/context.d.ts +2 -2
- package/v1/client/worker/context.js +11 -2
- package/v1/conditions/index.js +1 -1
- package/v1/conditions/transformer.js +4 -0
- package/v1/conditions/user-event-condition.d.ts +11 -1
- package/v1/conditions/user-event-condition.js +3 -1
- package/v1/examples/durable/workflow.d.ts +19 -0
- package/v1/examples/durable/workflow.js +42 -1
- package/v1/examples/e2e-worker.js +3 -0
- package/v1/parent-run-context-vars.d.ts +0 -2
- package/v1/parent-run-context-vars.js +3 -16
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -20,6 +20,14 @@ export interface UserEvent {
|
|
|
20
20
|
* If not specified, the eventKey will be used as the default identifier.
|
|
21
21
|
*/
|
|
22
22
|
readableDataKey?: string;
|
|
23
|
+
/**
|
|
24
|
+
An optional scope to filter events. If provided, only events with a matching scope will be considered when looking for matches. This is required if `lookback_window` is provided (if you wish to consider events that were pushed before the wait was established as valid).
|
|
25
|
+
*/
|
|
26
|
+
scope?: string;
|
|
27
|
+
/**
|
|
28
|
+
An optional ISO-formatted date string indicating how far back to look for matching events when the condition is first evaluated.
|
|
29
|
+
*/
|
|
30
|
+
considerEventsSince?: string;
|
|
23
31
|
}
|
|
24
32
|
/**
|
|
25
33
|
* Represents a condition that is triggered based on a specific user event.
|
|
@@ -46,5 +54,7 @@ export interface UserEvent {
|
|
|
46
54
|
export declare class UserEventCondition extends Condition {
|
|
47
55
|
eventKey: string;
|
|
48
56
|
expression: string;
|
|
49
|
-
|
|
57
|
+
scope?: string;
|
|
58
|
+
considerEventsSince?: string;
|
|
59
|
+
constructor(eventKey: string, expression: string, readableDataKey?: string, action?: Action, scope?: string, considerEventsSince?: string);
|
|
50
60
|
}
|
|
@@ -25,7 +25,7 @@ const base_1 = require("./base");
|
|
|
25
25
|
* );
|
|
26
26
|
*/
|
|
27
27
|
class UserEventCondition extends base_1.Condition {
|
|
28
|
-
constructor(eventKey, expression, readableDataKey, action) {
|
|
28
|
+
constructor(eventKey, expression, readableDataKey, action, scope, considerEventsSince) {
|
|
29
29
|
super({
|
|
30
30
|
readableDataKey: readableDataKey || eventKey,
|
|
31
31
|
action,
|
|
@@ -34,6 +34,8 @@ class UserEventCondition extends base_1.Condition {
|
|
|
34
34
|
});
|
|
35
35
|
this.eventKey = eventKey;
|
|
36
36
|
this.expression = expression;
|
|
37
|
+
this.scope = scope;
|
|
38
|
+
this.considerEventsSince = considerEventsSince;
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
exports.UserEventCondition = UserEventCondition;
|
|
@@ -52,6 +52,25 @@ export declare const durableReplayReset: import("../..").TaskWorkflowDeclaration
|
|
|
52
52
|
sleep_2_duration: number;
|
|
53
53
|
sleep_3_duration: number;
|
|
54
54
|
}, {}, {}, {}, {}>;
|
|
55
|
+
export declare const LOOKBACK_WINDOW: "1m";
|
|
56
|
+
export declare const waitForEventLookback: import("../..").TaskWorkflowDeclaration<{
|
|
57
|
+
scope: string;
|
|
58
|
+
}, {
|
|
59
|
+
elapsed: number;
|
|
60
|
+
event: any;
|
|
61
|
+
}, {}, {}, {}, {}>;
|
|
62
|
+
export declare const waitForOrEventLookback: import("../..").TaskWorkflowDeclaration<{
|
|
63
|
+
scope: string;
|
|
64
|
+
}, {
|
|
65
|
+
elapsed: number;
|
|
66
|
+
}, {}, {}, {}, {}>;
|
|
67
|
+
export declare const waitForTwoEventsSecondPushedFirst: import("../..").TaskWorkflowDeclaration<{
|
|
68
|
+
scope: string;
|
|
69
|
+
}, {
|
|
70
|
+
elapsed: number;
|
|
71
|
+
event1: any;
|
|
72
|
+
event2: any;
|
|
73
|
+
}, {}, {}, {}, {}>;
|
|
55
74
|
export declare const memoNowCaching: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
|
|
56
75
|
start_time: string;
|
|
57
76
|
}, {}, {}, {}, {}>;
|
|
@@ -12,10 +12,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.durableSpawnDag = exports.dagChildWorkflow = exports.memoNowCaching = exports.durableReplayReset = exports.REPLAY_RESET_MEMOIZED_MAX_SECONDS = exports.REPLAY_RESET_SLEEP_SECONDS = exports.durableNonDeterminism = exports.durableWithExplicitSpawn = exports.durableSleepEventSpawn = exports.durableWithBulkSpawn = exports.durableWithSpawn = exports.spawnChildTask = exports.waitForSleepTwice = exports.durableWorkflow = exports.SLEEP_TIME = exports.SLEEP_TIME_SECONDS = exports.EVENT_KEY = void 0;
|
|
15
|
+
exports.durableSpawnDag = exports.dagChildWorkflow = exports.memoNowCaching = exports.waitForTwoEventsSecondPushedFirst = exports.waitForOrEventLookback = exports.waitForEventLookback = exports.LOOKBACK_WINDOW = exports.durableReplayReset = exports.REPLAY_RESET_MEMOIZED_MAX_SECONDS = exports.REPLAY_RESET_SLEEP_SECONDS = exports.durableNonDeterminism = exports.durableWithExplicitSpawn = exports.durableSleepEventSpawn = exports.durableWithBulkSpawn = exports.durableWithSpawn = exports.spawnChildTask = exports.waitForSleepTwice = exports.durableWorkflow = exports.SLEEP_TIME = exports.SLEEP_TIME_SECONDS = exports.EVENT_KEY = void 0;
|
|
16
16
|
const conditions_1 = require("../../conditions");
|
|
17
17
|
const non_determinism_error_1 = require("../../../util/errors/non-determinism-error");
|
|
18
18
|
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
19
|
+
const duration_1 = require("../../client/duration");
|
|
19
20
|
const hatchet_client_1 = require("../hatchet-client");
|
|
20
21
|
exports.EVENT_KEY = 'durable-example:event';
|
|
21
22
|
exports.SLEEP_TIME_SECONDS = 2;
|
|
@@ -223,6 +224,46 @@ exports.durableReplayReset = hatchet_client_1.hatchet.durableTask({
|
|
|
223
224
|
};
|
|
224
225
|
}),
|
|
225
226
|
});
|
|
227
|
+
exports.LOOKBACK_WINDOW = '1m';
|
|
228
|
+
exports.waitForEventLookback = hatchet_client_1.hatchet.durableTask({
|
|
229
|
+
name: 'wait-for-event-lookback',
|
|
230
|
+
executionTimeout: '10m',
|
|
231
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
232
|
+
const start = Date.now();
|
|
233
|
+
const event = yield ctx.waitForEvent(exports.EVENT_KEY, undefined, undefined, input.scope, exports.LOOKBACK_WINDOW);
|
|
234
|
+
return {
|
|
235
|
+
elapsed: (Date.now() - start) / 1000,
|
|
236
|
+
event,
|
|
237
|
+
};
|
|
238
|
+
}),
|
|
239
|
+
});
|
|
240
|
+
exports.waitForOrEventLookback = hatchet_client_1.hatchet.durableTask({
|
|
241
|
+
name: 'wait-for-or-event-lookback',
|
|
242
|
+
executionTimeout: '10m',
|
|
243
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
244
|
+
const start = Date.now();
|
|
245
|
+
const now = yield ctx.now();
|
|
246
|
+
const considerEventsSince = new Date(now.getTime() - (0, duration_1.durationToMs)(exports.LOOKBACK_WINDOW)).toISOString();
|
|
247
|
+
yield ctx.waitFor((0, conditions_1.Or)(new conditions_1.SleepCondition(exports.SLEEP_TIME), new conditions_1.UserEventCondition(exports.EVENT_KEY, '', undefined, undefined, input.scope, considerEventsSince)));
|
|
248
|
+
return {
|
|
249
|
+
elapsed: (Date.now() - start) / 1000,
|
|
250
|
+
};
|
|
251
|
+
}),
|
|
252
|
+
});
|
|
253
|
+
exports.waitForTwoEventsSecondPushedFirst = hatchet_client_1.hatchet.durableTask({
|
|
254
|
+
name: 'wait-for-two-events-second-pushed-first',
|
|
255
|
+
executionTimeout: '10m',
|
|
256
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
257
|
+
const start = Date.now();
|
|
258
|
+
const event1 = yield ctx.waitForEvent('key1', undefined, undefined, input.scope, exports.LOOKBACK_WINDOW);
|
|
259
|
+
const event2 = yield ctx.waitForEvent('key2', undefined, undefined, input.scope, exports.LOOKBACK_WINDOW);
|
|
260
|
+
return {
|
|
261
|
+
elapsed: (Date.now() - start) / 1000,
|
|
262
|
+
event1,
|
|
263
|
+
event2,
|
|
264
|
+
};
|
|
265
|
+
}),
|
|
266
|
+
});
|
|
226
267
|
exports.memoNowCaching = hatchet_client_1.hatchet.durableTask({
|
|
227
268
|
name: 'memo-now-caching',
|
|
228
269
|
executionTimeout: '10m',
|
|
@@ -64,6 +64,9 @@ const workflows = [
|
|
|
64
64
|
workflow_8.durableReplayReset,
|
|
65
65
|
workflow_8.dagChildWorkflow,
|
|
66
66
|
workflow_8.durableSpawnDag,
|
|
67
|
+
workflow_8.waitForEventLookback,
|
|
68
|
+
workflow_8.waitForOrEventLookback,
|
|
69
|
+
workflow_8.waitForTwoEventsSecondPushedFirst,
|
|
67
70
|
workflow_9.durableEvent,
|
|
68
71
|
workflow_9.durableEventWithFilter,
|
|
69
72
|
workflow_11.durableSleep,
|
|
@@ -22,8 +22,6 @@ export declare class ParentRunContextManager {
|
|
|
22
22
|
private storage;
|
|
23
23
|
constructor();
|
|
24
24
|
runWithContext<T>(opts: ParentRunContext, fn: () => T): T;
|
|
25
|
-
setContext(opts: ParentRunContext): void;
|
|
26
|
-
setParentRunIdAndIncrementChildIndex(opts: ParentRunContext): void;
|
|
27
25
|
incrementChildIndex(n: number): void;
|
|
28
26
|
getContext(): ParentRunContext | undefined;
|
|
29
27
|
}
|
|
@@ -9,28 +9,15 @@ class ParentRunContextManager {
|
|
|
9
9
|
runWithContext(opts, fn) {
|
|
10
10
|
return this.storage.run(Object.assign({}, opts), fn);
|
|
11
11
|
}
|
|
12
|
-
setContext(opts) {
|
|
13
|
-
this.storage.enterWith(Object.assign({}, opts));
|
|
14
|
-
}
|
|
15
|
-
setParentRunIdAndIncrementChildIndex(opts) {
|
|
16
|
-
var _a;
|
|
17
|
-
const parentRunContext = this.getContext();
|
|
18
|
-
if (parentRunContext) {
|
|
19
|
-
parentRunContext.parentId = opts.parentId;
|
|
20
|
-
parentRunContext.parentTaskRunExternalId = opts.parentTaskRunExternalId;
|
|
21
|
-
parentRunContext.childIndex = ((_a = parentRunContext.childIndex) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
22
|
-
this.setContext(parentRunContext);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
12
|
incrementChildIndex(n) {
|
|
26
13
|
var _a;
|
|
27
14
|
const parentRunContext = this.getContext();
|
|
28
15
|
if (parentRunContext) {
|
|
29
|
-
// Mutate in place — do NOT use enterWith
|
|
16
|
+
// Mutate in place — do NOT use enterWith here.
|
|
30
17
|
// storage.run() gives every async descendant the same object reference,
|
|
31
18
|
// so direct mutation is visible across all await boundaries within the
|
|
32
|
-
// same task execution. enterWith would
|
|
33
|
-
// updates
|
|
19
|
+
// same task execution. enterWith would replace the object, and the new
|
|
20
|
+
// object's updates would be invisible to parent async contexts after an await.
|
|
34
21
|
parentRunContext.childIndex = ((_a = parentRunContext.childIndex) !== null && _a !== void 0 ? _a : 0) + n;
|
|
35
22
|
}
|
|
36
23
|
}
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.20.1";
|
package/version.js
CHANGED