@hatchet-dev/typescript-sdk 1.19.2-alpha.2 → 1.19.2-alpha.3
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
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const childIndexChild: import("../..").TaskWorkflowDeclaration<{
|
|
2
|
+
tag: string;
|
|
3
|
+
}, {
|
|
4
|
+
tag: string;
|
|
5
|
+
}, {}, {}, {}, {}>;
|
|
6
|
+
export declare const childIndexParent: import("../..").WorkflowDeclaration<{
|
|
7
|
+
n: number;
|
|
8
|
+
}, {}, {}>;
|
|
9
|
+
export declare const scenarioTask: import("../..").TaskWorkflowDeclaration<{
|
|
10
|
+
scenarioId: string;
|
|
11
|
+
}, {
|
|
12
|
+
scenarioId: string;
|
|
13
|
+
status: string;
|
|
14
|
+
}, {}, {}, {}, {}>;
|
|
15
|
+
export declare const orchestratorTask: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
|
|
16
|
+
total: number;
|
|
17
|
+
expected: number;
|
|
18
|
+
uniqueRunIds: number;
|
|
19
|
+
hasDuplicates: boolean;
|
|
20
|
+
scenarios: string[];
|
|
21
|
+
}, {}, {}, {}, {}>;
|
|
@@ -0,0 +1,155 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.orchestratorTask = exports.scenarioTask = exports.childIndexParent = exports.childIndexChild = void 0;
|
|
16
|
+
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
17
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
18
|
+
exports.childIndexChild = hatchet_client_1.hatchet.task({
|
|
19
|
+
name: 'child-index-child',
|
|
20
|
+
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
return { tag: input.tag };
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
exports.childIndexParent = hatchet_client_1.hatchet.workflow({
|
|
25
|
+
name: 'child-index-parent',
|
|
26
|
+
});
|
|
27
|
+
exports.childIndexParent.task({
|
|
28
|
+
name: 'mixed-spawn',
|
|
29
|
+
executionTimeout: '3m',
|
|
30
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
const { n } = input;
|
|
32
|
+
const ctxResults = [];
|
|
33
|
+
for (let i = 0; i < n; i++) {
|
|
34
|
+
const result = yield ctx.runChild(exports.childIndexChild, { tag: `ctx-${i}` });
|
|
35
|
+
ctxResults.push(result.tag);
|
|
36
|
+
}
|
|
37
|
+
const refs = yield Promise.all(Array.from({ length: n }, (_, i) => exports.childIndexChild.runNoWait({ tag: `rnw-${i}` })));
|
|
38
|
+
const runIds = yield Promise.all(refs.map((r) => r.runId));
|
|
39
|
+
const outputs = yield Promise.all(refs.map((r) => r.output));
|
|
40
|
+
const rnwResults = outputs.map((o) => o.tag);
|
|
41
|
+
return {
|
|
42
|
+
ctxResults,
|
|
43
|
+
rnwResults,
|
|
44
|
+
runIds,
|
|
45
|
+
};
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
48
|
+
function buildTree() {
|
|
49
|
+
// Root → Fund → Portfolio → Portfolio → Project structure
|
|
50
|
+
// ~30 total nodes to keep the test manageable
|
|
51
|
+
return {
|
|
52
|
+
id: 'fund-root',
|
|
53
|
+
children: [
|
|
54
|
+
{
|
|
55
|
+
id: 'fund-a',
|
|
56
|
+
children: [
|
|
57
|
+
{
|
|
58
|
+
id: 'portfolio-a1',
|
|
59
|
+
children: [
|
|
60
|
+
{ id: 'project-a1a', children: [] },
|
|
61
|
+
{ id: 'project-a1b', children: [] },
|
|
62
|
+
{ id: 'project-a1c', children: [] },
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: 'portfolio-a2',
|
|
67
|
+
children: [
|
|
68
|
+
{ id: 'project-a2a', children: [] },
|
|
69
|
+
{ id: 'project-a2b', children: [] },
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
id: 'fund-b',
|
|
76
|
+
children: [
|
|
77
|
+
{
|
|
78
|
+
id: 'portfolio-b1',
|
|
79
|
+
children: [
|
|
80
|
+
{ id: 'project-b1a', children: [] },
|
|
81
|
+
{ id: 'project-b1b', children: [] },
|
|
82
|
+
{ id: 'project-b1c', children: [] },
|
|
83
|
+
{ id: 'project-b1d', children: [] },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: 'portfolio-b2',
|
|
88
|
+
children: [
|
|
89
|
+
{ id: 'project-b2a', children: [] },
|
|
90
|
+
{ id: 'project-b2b', children: [] },
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: 'fund-c',
|
|
97
|
+
children: [
|
|
98
|
+
{
|
|
99
|
+
id: 'portfolio-c1',
|
|
100
|
+
children: [
|
|
101
|
+
{ id: 'project-c1a', children: [] },
|
|
102
|
+
{ id: 'project-c1b', children: [] },
|
|
103
|
+
{ id: 'project-c1c', children: [] },
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function countNodes(node) {
|
|
112
|
+
return 1 + node.children.reduce((sum, c) => sum + countNodes(c), 0);
|
|
113
|
+
}
|
|
114
|
+
exports.scenarioTask = hatchet_client_1.hatchet.task({
|
|
115
|
+
name: 'child-index-scenario',
|
|
116
|
+
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
yield (0, sleep_1.default)(100);
|
|
118
|
+
return { scenarioId: input.scenarioId, status: 'completed' };
|
|
119
|
+
}),
|
|
120
|
+
});
|
|
121
|
+
exports.orchestratorTask = hatchet_client_1.hatchet.task({
|
|
122
|
+
name: 'child-index-orchestrator',
|
|
123
|
+
executionTimeout: '5m',
|
|
124
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
const tree = buildTree();
|
|
126
|
+
const totalExpected = countNodes(tree);
|
|
127
|
+
const collectedRunIds = [];
|
|
128
|
+
const collectedScenarios = [];
|
|
129
|
+
// Recursive bottom-up traversal — mirrors Evan's runChildScenarioFn pattern.
|
|
130
|
+
// Process children first, wait for completion, then process this node.
|
|
131
|
+
function processNode(node) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
for (const child of node.children) {
|
|
134
|
+
yield processNode(child);
|
|
135
|
+
}
|
|
136
|
+
const runRef = yield exports.scenarioTask.runNoWait({
|
|
137
|
+
scenarioId: node.id,
|
|
138
|
+
});
|
|
139
|
+
const runId = yield runRef.runId;
|
|
140
|
+
collectedRunIds.push(runId);
|
|
141
|
+
collectedScenarios.push(node.id);
|
|
142
|
+
yield runRef.output;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
yield processNode(tree);
|
|
146
|
+
const uniqueRunIds = new Set(collectedRunIds);
|
|
147
|
+
return {
|
|
148
|
+
total: collectedRunIds.length,
|
|
149
|
+
expected: totalExpected,
|
|
150
|
+
uniqueRunIds: uniqueRunIds.size,
|
|
151
|
+
hasDuplicates: uniqueRunIds.size !== collectedRunIds.length,
|
|
152
|
+
scenarios: collectedScenarios,
|
|
153
|
+
};
|
|
154
|
+
}),
|
|
155
|
+
});
|
|
@@ -39,6 +39,7 @@ const e2e_workflows_1 = require("./simple/e2e-workflows");
|
|
|
39
39
|
const workflow_18 = require("./streaming/workflow");
|
|
40
40
|
const workflow_19 = require("./timeout/workflow");
|
|
41
41
|
const workflow_20 = require("./webhooks/workflow");
|
|
42
|
+
const workflow_21 = require("./child_index/workflow");
|
|
42
43
|
const workflows = [
|
|
43
44
|
workflow_1.bulkChild,
|
|
44
45
|
workflow_1.bulkParentWorkflow,
|
|
@@ -86,6 +87,10 @@ const workflows = [
|
|
|
86
87
|
workflow_19.timeoutTask,
|
|
87
88
|
workflow_19.refreshTimeoutTask,
|
|
88
89
|
workflow_20.webhookWorkflow,
|
|
90
|
+
workflow_21.childIndexChild,
|
|
91
|
+
workflow_21.childIndexParent,
|
|
92
|
+
workflow_21.scenarioTask,
|
|
93
|
+
workflow_21.orchestratorTask,
|
|
89
94
|
];
|
|
90
95
|
function main() {
|
|
91
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -26,7 +26,12 @@ class ParentRunContextManager {
|
|
|
26
26
|
var _a;
|
|
27
27
|
const parentRunContext = this.getContext();
|
|
28
28
|
if (parentRunContext) {
|
|
29
|
-
|
|
29
|
+
// Mutate in place — do NOT use enterWith/setContext here.
|
|
30
|
+
// storage.run() gives every async descendant the same object reference,
|
|
31
|
+
// so direct mutation is visible across all await boundaries within the
|
|
32
|
+
// same task execution. enterWith would create a new object whose
|
|
33
|
+
// updates are invisible to parent async contexts after an await.
|
|
34
|
+
parentRunContext.childIndex = ((_a = parentRunContext.childIndex) !== null && _a !== void 0 ? _a : 0) + n;
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
getContext() {
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.19.2-alpha.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.19.2-alpha.3";
|
package/version.js
CHANGED