@hatchet-dev/typescript-sdk 0.8.0-alpha.3 → 0.9.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/clients/admin/admin-client.d.ts +13 -8
- package/clients/admin/admin-client.js +23 -23
- package/clients/dispatcher/action-listener.d.ts +3 -60
- package/clients/dispatcher/action-listener.js +1 -18
- package/clients/dispatcher/heartbeat/heartbeat-controller.d.ts +0 -1
- package/clients/hatchet-client/hatchet-client.d.ts +0 -1
- package/clients/hatchet-client/hatchet-client.js +1 -7
- package/clients/listener/child-listener-client.d.ts +0 -1
- package/clients/listener/listener-client.d.ts +6 -14
- package/clients/listener/listener-client.js +16 -85
- package/clients/rest/generated/Api.d.ts +2 -19
- package/clients/rest/generated/Api.js +0 -17
- package/clients/rest/generated/data-contracts.d.ts +0 -25
- package/clients/rest/generated/http-client.js +2 -2
- package/clients/worker/worker.d.ts +3 -10
- package/clients/worker/worker.js +153 -205
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +4 -4
- package/protoc/dispatcher/dispatcher.js +13 -13
- package/protoc/workflows/workflows.js +5 -5
- package/step.d.ts +11 -13
- package/step.js +13 -70
- package/util/config-loader/token.js +2 -3
- package/util/parse.js +1 -7
- package/util/retrier.js +1 -2
- package/util/thread-helper.d.ts +0 -1
- package/util/thread-helper.js +1 -2
- package/util/workflow-run-ref.d.ts +17 -0
- package/util/workflow-run-ref.js +94 -0
- package/clients/worker/handler.d.ts +0 -58
- package/clients/worker/handler.js +0 -191
|
@@ -28,7 +28,19 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
28
28
|
return result;
|
|
29
29
|
};
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.DispatcherDefinition = exports.ReleaseSlotResponse = exports.ReleaseSlotRequest = exports.RefreshTimeoutResponse = exports.RefreshTimeoutRequest = exports.HeartbeatResponse = exports.HeartbeatRequest = exports.OverridesDataResponse = exports.OverridesData = exports.StepRunResult = exports.WorkflowRunEvent = exports.WorkflowEvent = exports.SubscribeToWorkflowRunsRequest = exports.SubscribeToWorkflowEventsRequest = exports.ActionEventResponse = exports.StepActionEvent = exports.GroupKeyActionEvent = exports.WorkerUnsubscribeResponse = exports.WorkerUnsubscribeRequest = exports.WorkerListenRequest = exports.AssignedAction = exports.WorkerRegisterResponse = exports.WorkerRegisterRequest = exports.
|
|
31
|
+
exports.DispatcherDefinition = exports.ReleaseSlotResponse = exports.ReleaseSlotRequest = exports.RefreshTimeoutResponse = exports.RefreshTimeoutRequest = exports.HeartbeatResponse = exports.HeartbeatRequest = exports.OverridesDataResponse = exports.OverridesData = exports.StepRunResult = exports.WorkflowRunEvent = exports.WorkflowEvent = exports.SubscribeToWorkflowRunsRequest = exports.SubscribeToWorkflowEventsRequest = exports.ActionEventResponse = exports.StepActionEvent = exports.GroupKeyActionEvent = exports.WorkerUnsubscribeResponse = exports.WorkerUnsubscribeRequest = exports.WorkerListenRequest = exports.AssignedAction = exports.WorkerRegisterResponse = exports.WorkerRegisterRequest = exports.WorkflowRunEventType = exports.ResourceEventType = exports.ResourceType = exports.StepActionEventType = exports.GroupKeyActionEventType = exports.ActionType = exports.protobufPackage = void 0;
|
|
32
|
+
exports.actionTypeFromJSON = actionTypeFromJSON;
|
|
33
|
+
exports.actionTypeToJSON = actionTypeToJSON;
|
|
34
|
+
exports.groupKeyActionEventTypeFromJSON = groupKeyActionEventTypeFromJSON;
|
|
35
|
+
exports.groupKeyActionEventTypeToJSON = groupKeyActionEventTypeToJSON;
|
|
36
|
+
exports.stepActionEventTypeFromJSON = stepActionEventTypeFromJSON;
|
|
37
|
+
exports.stepActionEventTypeToJSON = stepActionEventTypeToJSON;
|
|
38
|
+
exports.resourceTypeFromJSON = resourceTypeFromJSON;
|
|
39
|
+
exports.resourceTypeToJSON = resourceTypeToJSON;
|
|
40
|
+
exports.resourceEventTypeFromJSON = resourceEventTypeFromJSON;
|
|
41
|
+
exports.resourceEventTypeToJSON = resourceEventTypeToJSON;
|
|
42
|
+
exports.workflowRunEventTypeFromJSON = workflowRunEventTypeFromJSON;
|
|
43
|
+
exports.workflowRunEventTypeToJSON = workflowRunEventTypeToJSON;
|
|
32
44
|
const _m0 = __importStar(require("protobufjs/minimal"));
|
|
33
45
|
const timestamp_1 = require("../google/protobuf/timestamp");
|
|
34
46
|
exports.protobufPackage = '';
|
|
@@ -56,7 +68,6 @@ function actionTypeFromJSON(object) {
|
|
|
56
68
|
return ActionType.UNRECOGNIZED;
|
|
57
69
|
}
|
|
58
70
|
}
|
|
59
|
-
exports.actionTypeFromJSON = actionTypeFromJSON;
|
|
60
71
|
function actionTypeToJSON(object) {
|
|
61
72
|
switch (object) {
|
|
62
73
|
case ActionType.START_STEP_RUN:
|
|
@@ -70,7 +81,6 @@ function actionTypeToJSON(object) {
|
|
|
70
81
|
return 'UNRECOGNIZED';
|
|
71
82
|
}
|
|
72
83
|
}
|
|
73
|
-
exports.actionTypeToJSON = actionTypeToJSON;
|
|
74
84
|
var GroupKeyActionEventType;
|
|
75
85
|
(function (GroupKeyActionEventType) {
|
|
76
86
|
GroupKeyActionEventType[GroupKeyActionEventType["GROUP_KEY_EVENT_TYPE_UNKNOWN"] = 0] = "GROUP_KEY_EVENT_TYPE_UNKNOWN";
|
|
@@ -99,7 +109,6 @@ function groupKeyActionEventTypeFromJSON(object) {
|
|
|
99
109
|
return GroupKeyActionEventType.UNRECOGNIZED;
|
|
100
110
|
}
|
|
101
111
|
}
|
|
102
|
-
exports.groupKeyActionEventTypeFromJSON = groupKeyActionEventTypeFromJSON;
|
|
103
112
|
function groupKeyActionEventTypeToJSON(object) {
|
|
104
113
|
switch (object) {
|
|
105
114
|
case GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_UNKNOWN:
|
|
@@ -115,7 +124,6 @@ function groupKeyActionEventTypeToJSON(object) {
|
|
|
115
124
|
return 'UNRECOGNIZED';
|
|
116
125
|
}
|
|
117
126
|
}
|
|
118
|
-
exports.groupKeyActionEventTypeToJSON = groupKeyActionEventTypeToJSON;
|
|
119
127
|
var StepActionEventType;
|
|
120
128
|
(function (StepActionEventType) {
|
|
121
129
|
StepActionEventType[StepActionEventType["STEP_EVENT_TYPE_UNKNOWN"] = 0] = "STEP_EVENT_TYPE_UNKNOWN";
|
|
@@ -144,7 +152,6 @@ function stepActionEventTypeFromJSON(object) {
|
|
|
144
152
|
return StepActionEventType.UNRECOGNIZED;
|
|
145
153
|
}
|
|
146
154
|
}
|
|
147
|
-
exports.stepActionEventTypeFromJSON = stepActionEventTypeFromJSON;
|
|
148
155
|
function stepActionEventTypeToJSON(object) {
|
|
149
156
|
switch (object) {
|
|
150
157
|
case StepActionEventType.STEP_EVENT_TYPE_UNKNOWN:
|
|
@@ -160,7 +167,6 @@ function stepActionEventTypeToJSON(object) {
|
|
|
160
167
|
return 'UNRECOGNIZED';
|
|
161
168
|
}
|
|
162
169
|
}
|
|
163
|
-
exports.stepActionEventTypeToJSON = stepActionEventTypeToJSON;
|
|
164
170
|
var ResourceType;
|
|
165
171
|
(function (ResourceType) {
|
|
166
172
|
ResourceType[ResourceType["RESOURCE_TYPE_UNKNOWN"] = 0] = "RESOURCE_TYPE_UNKNOWN";
|
|
@@ -185,7 +191,6 @@ function resourceTypeFromJSON(object) {
|
|
|
185
191
|
return ResourceType.UNRECOGNIZED;
|
|
186
192
|
}
|
|
187
193
|
}
|
|
188
|
-
exports.resourceTypeFromJSON = resourceTypeFromJSON;
|
|
189
194
|
function resourceTypeToJSON(object) {
|
|
190
195
|
switch (object) {
|
|
191
196
|
case ResourceType.RESOURCE_TYPE_UNKNOWN:
|
|
@@ -199,7 +204,6 @@ function resourceTypeToJSON(object) {
|
|
|
199
204
|
return 'UNRECOGNIZED';
|
|
200
205
|
}
|
|
201
206
|
}
|
|
202
|
-
exports.resourceTypeToJSON = resourceTypeToJSON;
|
|
203
207
|
var ResourceEventType;
|
|
204
208
|
(function (ResourceEventType) {
|
|
205
209
|
ResourceEventType[ResourceEventType["RESOURCE_EVENT_TYPE_UNKNOWN"] = 0] = "RESOURCE_EVENT_TYPE_UNKNOWN";
|
|
@@ -240,7 +244,6 @@ function resourceEventTypeFromJSON(object) {
|
|
|
240
244
|
return ResourceEventType.UNRECOGNIZED;
|
|
241
245
|
}
|
|
242
246
|
}
|
|
243
|
-
exports.resourceEventTypeFromJSON = resourceEventTypeFromJSON;
|
|
244
247
|
function resourceEventTypeToJSON(object) {
|
|
245
248
|
switch (object) {
|
|
246
249
|
case ResourceEventType.RESOURCE_EVENT_TYPE_UNKNOWN:
|
|
@@ -262,7 +265,6 @@ function resourceEventTypeToJSON(object) {
|
|
|
262
265
|
return 'UNRECOGNIZED';
|
|
263
266
|
}
|
|
264
267
|
}
|
|
265
|
-
exports.resourceEventTypeToJSON = resourceEventTypeToJSON;
|
|
266
268
|
var WorkflowRunEventType;
|
|
267
269
|
(function (WorkflowRunEventType) {
|
|
268
270
|
WorkflowRunEventType[WorkflowRunEventType["WORKFLOW_RUN_EVENT_TYPE_FINISHED"] = 0] = "WORKFLOW_RUN_EVENT_TYPE_FINISHED";
|
|
@@ -279,7 +281,6 @@ function workflowRunEventTypeFromJSON(object) {
|
|
|
279
281
|
return WorkflowRunEventType.UNRECOGNIZED;
|
|
280
282
|
}
|
|
281
283
|
}
|
|
282
|
-
exports.workflowRunEventTypeFromJSON = workflowRunEventTypeFromJSON;
|
|
283
284
|
function workflowRunEventTypeToJSON(object) {
|
|
284
285
|
switch (object) {
|
|
285
286
|
case WorkflowRunEventType.WORKFLOW_RUN_EVENT_TYPE_FINISHED:
|
|
@@ -289,7 +290,6 @@ function workflowRunEventTypeToJSON(object) {
|
|
|
289
290
|
return 'UNRECOGNIZED';
|
|
290
291
|
}
|
|
291
292
|
}
|
|
292
|
-
exports.workflowRunEventTypeToJSON = workflowRunEventTypeToJSON;
|
|
293
293
|
function createBaseWorkerRegisterRequest() {
|
|
294
294
|
return { workerName: '', actions: [], services: [], maxRuns: undefined };
|
|
295
295
|
}
|
|
@@ -28,7 +28,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
28
28
|
return result;
|
|
29
29
|
};
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.WorkflowServiceDefinition = exports.PutRateLimitResponse = exports.PutRateLimitRequest = exports.TriggerWorkflowResponse = exports.TriggerWorkflowRequest = exports.WorkflowTriggerCronRef = exports.WorkflowTriggerEventRef = exports.WorkflowVersion = exports.ScheduleWorkflowRequest = exports.ListWorkflowsRequest = exports.CreateStepRateLimit = exports.CreateWorkflowStepOpts = exports.CreateWorkflowJobOpts = exports.WorkflowConcurrencyOpts = exports.CreateWorkflowVersionOpts = exports.PutWorkflowRequest = exports.
|
|
31
|
+
exports.WorkflowServiceDefinition = exports.PutRateLimitResponse = exports.PutRateLimitRequest = exports.TriggerWorkflowResponse = exports.TriggerWorkflowRequest = exports.WorkflowTriggerCronRef = exports.WorkflowTriggerEventRef = exports.WorkflowVersion = exports.ScheduleWorkflowRequest = exports.ListWorkflowsRequest = exports.CreateStepRateLimit = exports.CreateWorkflowStepOpts = exports.CreateWorkflowJobOpts = exports.WorkflowConcurrencyOpts = exports.CreateWorkflowVersionOpts = exports.PutWorkflowRequest = exports.RateLimitDuration = exports.ConcurrencyLimitStrategy = exports.protobufPackage = void 0;
|
|
32
|
+
exports.concurrencyLimitStrategyFromJSON = concurrencyLimitStrategyFromJSON;
|
|
33
|
+
exports.concurrencyLimitStrategyToJSON = concurrencyLimitStrategyToJSON;
|
|
34
|
+
exports.rateLimitDurationFromJSON = rateLimitDurationFromJSON;
|
|
35
|
+
exports.rateLimitDurationToJSON = rateLimitDurationToJSON;
|
|
32
36
|
const _m0 = __importStar(require("protobufjs/minimal"));
|
|
33
37
|
const timestamp_1 = require("../google/protobuf/timestamp");
|
|
34
38
|
exports.protobufPackage = '';
|
|
@@ -60,7 +64,6 @@ function concurrencyLimitStrategyFromJSON(object) {
|
|
|
60
64
|
return ConcurrencyLimitStrategy.UNRECOGNIZED;
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
|
-
exports.concurrencyLimitStrategyFromJSON = concurrencyLimitStrategyFromJSON;
|
|
64
67
|
function concurrencyLimitStrategyToJSON(object) {
|
|
65
68
|
switch (object) {
|
|
66
69
|
case ConcurrencyLimitStrategy.CANCEL_IN_PROGRESS:
|
|
@@ -76,7 +79,6 @@ function concurrencyLimitStrategyToJSON(object) {
|
|
|
76
79
|
return 'UNRECOGNIZED';
|
|
77
80
|
}
|
|
78
81
|
}
|
|
79
|
-
exports.concurrencyLimitStrategyToJSON = concurrencyLimitStrategyToJSON;
|
|
80
82
|
var RateLimitDuration;
|
|
81
83
|
(function (RateLimitDuration) {
|
|
82
84
|
RateLimitDuration[RateLimitDuration["SECOND"] = 0] = "SECOND";
|
|
@@ -117,7 +119,6 @@ function rateLimitDurationFromJSON(object) {
|
|
|
117
119
|
return RateLimitDuration.UNRECOGNIZED;
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
|
-
exports.rateLimitDurationFromJSON = rateLimitDurationFromJSON;
|
|
121
122
|
function rateLimitDurationToJSON(object) {
|
|
122
123
|
switch (object) {
|
|
123
124
|
case RateLimitDuration.SECOND:
|
|
@@ -139,7 +140,6 @@ function rateLimitDurationToJSON(object) {
|
|
|
139
140
|
return 'UNRECOGNIZED';
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
|
-
exports.rateLimitDurationToJSON = rateLimitDurationToJSON;
|
|
143
143
|
function createBasePutWorkflowRequest() {
|
|
144
144
|
return { opts: undefined };
|
|
145
145
|
}
|
package/step.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Action } from './clients/dispatcher/action-listener';
|
|
|
3
3
|
import { LogLevel } from './clients/event/event-client';
|
|
4
4
|
import { Logger } from './util/logger';
|
|
5
5
|
import { HatchetClient } from './clients/hatchet-client';
|
|
6
|
-
import
|
|
6
|
+
import WorkflowRunRef from './util/workflow-run-ref';
|
|
7
7
|
export declare const CreateRateLimitSchema: z.ZodObject<{
|
|
8
8
|
key: z.ZodString;
|
|
9
9
|
units: z.ZodNumber;
|
|
@@ -48,9 +48,16 @@ export declare const CreateStepSchema: z.ZodObject<{
|
|
|
48
48
|
units: number;
|
|
49
49
|
}[] | undefined;
|
|
50
50
|
}>;
|
|
51
|
-
type
|
|
51
|
+
export type JsonObject = {
|
|
52
|
+
[Key in string]: JsonValue;
|
|
53
|
+
} & {
|
|
54
|
+
[Key in string]?: JsonValue | undefined;
|
|
55
|
+
};
|
|
56
|
+
export type JsonArray = JsonValue[] | readonly JsonValue[];
|
|
57
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
58
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
52
59
|
export type NextStep = {
|
|
53
|
-
[key: string]:
|
|
60
|
+
[key: string]: JsonValue;
|
|
54
61
|
};
|
|
55
62
|
interface ContextData<T, K> {
|
|
56
63
|
input: T;
|
|
@@ -58,15 +65,6 @@ interface ContextData<T, K> {
|
|
|
58
65
|
triggered_by: string;
|
|
59
66
|
user_data: K;
|
|
60
67
|
}
|
|
61
|
-
declare class ChildWorkflowRef<T> {
|
|
62
|
-
workflowRunId: Promise<string>;
|
|
63
|
-
parentWorkflowRunId: string;
|
|
64
|
-
client: HatchetClient;
|
|
65
|
-
constructor(workflowRunId: Promise<string>, parentWorkflowRunId: string, client: HatchetClient);
|
|
66
|
-
stream(): Promise<AsyncGenerator<WorkflowRunEvent, void, unknown>>;
|
|
67
|
-
result(): Promise<T>;
|
|
68
|
-
toJSON(): Promise<string>;
|
|
69
|
-
}
|
|
70
68
|
export declare class Context<T, K = {}> {
|
|
71
69
|
data: ContextData<T, K>;
|
|
72
70
|
input: T;
|
|
@@ -96,7 +94,7 @@ export declare class Context<T, K = {}> {
|
|
|
96
94
|
refreshTimeout(incrementBy: string): Promise<void>;
|
|
97
95
|
releaseSlot(): Promise<void>;
|
|
98
96
|
putStream(data: string | Uint8Array): Promise<void>;
|
|
99
|
-
spawnWorkflow<
|
|
97
|
+
spawnWorkflow<Q = JsonValue, P = JsonValue>(workflowName: string, input: Q, key?: string): WorkflowRunRef<P>;
|
|
100
98
|
}
|
|
101
99
|
export type StepRunFunction<T, K> = (ctx: Context<T, K>) => Promise<NextStep | void> | NextStep | void;
|
|
102
100
|
export interface CreateStep<T, K> extends z.infer<typeof CreateStepSchema> {
|
package/step.js
CHANGED
|
@@ -31,13 +31,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
35
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
36
|
-
var m = o[Symbol.asyncIterator], i;
|
|
37
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
38
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
39
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
40
|
-
};
|
|
41
34
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
36
|
};
|
|
@@ -49,7 +42,6 @@ const z = __importStar(require("zod"));
|
|
|
49
42
|
const workflow_1 = require("./workflow");
|
|
50
43
|
const logger_1 = require("./util/logger");
|
|
51
44
|
const parse_1 = require("./util/parse");
|
|
52
|
-
const dispatcher_1 = require("./protoc/dispatcher");
|
|
53
45
|
exports.CreateRateLimitSchema = z.object({
|
|
54
46
|
key: z.string(),
|
|
55
47
|
units: z.number().min(1),
|
|
@@ -61,60 +53,6 @@ exports.CreateStepSchema = z.object({
|
|
|
61
53
|
retries: z.number().optional(),
|
|
62
54
|
rate_limits: z.array(exports.CreateRateLimitSchema).optional(),
|
|
63
55
|
});
|
|
64
|
-
class ChildWorkflowRef {
|
|
65
|
-
constructor(workflowRunId, parentWorkflowRunId, client) {
|
|
66
|
-
this.workflowRunId = workflowRunId;
|
|
67
|
-
this.parentWorkflowRunId = parentWorkflowRunId;
|
|
68
|
-
this.client = client;
|
|
69
|
-
}
|
|
70
|
-
stream() {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
const workflowRunId = yield this.workflowRunId;
|
|
73
|
-
const listener = yield this.client.listener.getChildListener(workflowRunId, this.parentWorkflowRunId);
|
|
74
|
-
return listener.stream();
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
result() {
|
|
78
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
const listener = yield this.stream();
|
|
80
|
-
return new Promise((resolve, reject) => {
|
|
81
|
-
(() => __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
var _a, e_1, _b, _c;
|
|
83
|
-
try {
|
|
84
|
-
for (var _d = true, _e = __asyncValues(yield listener), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
85
|
-
_c = _f.value;
|
|
86
|
-
_d = false;
|
|
87
|
-
const event = _c;
|
|
88
|
-
if (event.eventType === dispatcher_1.WorkflowRunEventType.WORKFLOW_RUN_EVENT_TYPE_FINISHED) {
|
|
89
|
-
if (event.results.some((r) => !!r.error)) {
|
|
90
|
-
reject(event.results);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const result = event.results.reduce((acc, r) => (Object.assign(Object.assign({}, acc), { [r.stepReadableId]: JSON.parse(r.output || '{}') })), {});
|
|
94
|
-
resolve(result);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
100
|
-
finally {
|
|
101
|
-
try {
|
|
102
|
-
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
103
|
-
}
|
|
104
|
-
finally { if (e_1) throw e_1.error; }
|
|
105
|
-
}
|
|
106
|
-
}))();
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
toJSON() {
|
|
111
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
return JSON.stringify({
|
|
113
|
-
workflowRunId: yield this.workflowRunId,
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
56
|
class Context {
|
|
119
57
|
constructor(action, client) {
|
|
120
58
|
this.controller = new AbortController();
|
|
@@ -229,14 +167,19 @@ class Context {
|
|
|
229
167
|
spawnWorkflow(workflowName, input, key) {
|
|
230
168
|
const { workflowRunId, stepRunId } = this.action;
|
|
231
169
|
const name = this.client.config.namespace + workflowName;
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
170
|
+
try {
|
|
171
|
+
const resp = this.client.admin.runWorkflow(name, input, {
|
|
172
|
+
parentId: workflowRunId,
|
|
173
|
+
parentStepRunId: stepRunId,
|
|
174
|
+
childKey: key,
|
|
175
|
+
childIndex: this.spawnIndex,
|
|
176
|
+
});
|
|
177
|
+
this.spawnIndex += 1;
|
|
178
|
+
return resp;
|
|
179
|
+
}
|
|
180
|
+
catch (e) {
|
|
181
|
+
throw new hatchet_error_1.default(e.message);
|
|
182
|
+
}
|
|
240
183
|
}
|
|
241
184
|
}
|
|
242
185
|
exports.Context = Context;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getTenantIdFromJWT = getTenantIdFromJWT;
|
|
4
|
+
exports.getAddressesFromJWT = getAddressesFromJWT;
|
|
4
5
|
function getTenantIdFromJWT(token) {
|
|
5
6
|
const claims = extractClaimsFromJWT(token);
|
|
6
7
|
return claims.sub;
|
|
7
8
|
}
|
|
8
|
-
exports.getTenantIdFromJWT = getTenantIdFromJWT;
|
|
9
9
|
function getAddressesFromJWT(token) {
|
|
10
10
|
const claims = extractClaimsFromJWT(token);
|
|
11
11
|
return {
|
|
@@ -13,7 +13,6 @@ function getAddressesFromJWT(token) {
|
|
|
13
13
|
grpcBroadcastAddress: claims.grpc_broadcast_address,
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
exports.getAddressesFromJWT = getAddressesFromJWT;
|
|
17
16
|
function extractClaimsFromJWT(token) {
|
|
18
17
|
const parts = token.split('.');
|
|
19
18
|
if (parts.length !== 3) {
|
package/util/parse.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseJSON =
|
|
3
|
+
exports.parseJSON = parseJSON;
|
|
4
4
|
function parseJSON(json) {
|
|
5
|
-
// TODO why is this needed?
|
|
6
|
-
if (json.startsWith('ey')) {
|
|
7
|
-
const decoded = Buffer.from(json, 'base64').toString('utf8');
|
|
8
|
-
return JSON.parse(decoded);
|
|
9
|
-
}
|
|
10
5
|
try {
|
|
11
6
|
const firstParse = JSON.parse(json);
|
|
12
7
|
// Hatchet engine versions <=0.14.0 return JSON as a quoted string which needs to be parsed again.
|
|
@@ -22,4 +17,3 @@ function parseJSON(json) {
|
|
|
22
17
|
throw new Error(`Could not parse JSON: ${e.message}`);
|
|
23
18
|
}
|
|
24
19
|
}
|
|
25
|
-
exports.parseJSON = parseJSON;
|
package/util/retrier.js
CHANGED
|
@@ -12,7 +12,7 @@ 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.retrier =
|
|
15
|
+
exports.retrier = retrier;
|
|
16
16
|
const sleep_1 = __importDefault(require("./sleep"));
|
|
17
17
|
const DEFAULT_RETRY_INTERVAL = 5; // seconds
|
|
18
18
|
const DEFAULT_RETRY_COUNT = 5;
|
|
@@ -33,4 +33,3 @@ function retrier(fn_1, logger_1) {
|
|
|
33
33
|
throw lastError;
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
exports.retrier = retrier;
|
package/util/thread-helper.d.ts
CHANGED
package/util/thread-helper.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.runThreaded =
|
|
6
|
+
exports.runThreaded = runThreaded;
|
|
7
7
|
const worker_threads_1 = require("worker_threads");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
function runThreaded(scriptPath, options) {
|
|
@@ -32,5 +32,4 @@ function runThreaded(scriptPath, options) {
|
|
|
32
32
|
: resolvedPath;
|
|
33
33
|
return new worker_threads_1.Worker(ex, Object.assign(Object.assign({}, options), { eval: isTs ? true : undefined }));
|
|
34
34
|
}
|
|
35
|
-
exports.runThreaded = runThreaded;
|
|
36
35
|
// execArgv: ? ['--require', 'ts-node/register'] : undefined,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ListenerClient, StepRunEvent } from '../clients/listener/listener-client';
|
|
2
|
+
type EventualWorkflowRunId = string | Promise<string> | Promise<{
|
|
3
|
+
workflowRunId: string;
|
|
4
|
+
}>;
|
|
5
|
+
export default class WorkflowRunRef<T> {
|
|
6
|
+
workflowRunId: EventualWorkflowRunId;
|
|
7
|
+
parentWorkflowRunId?: string;
|
|
8
|
+
private client;
|
|
9
|
+
constructor(workflowRunId: string | Promise<string> | Promise<{
|
|
10
|
+
workflowRunId: string;
|
|
11
|
+
}>, client: ListenerClient, parentWorkflowRunId?: string);
|
|
12
|
+
getWorkflowRunId(): Promise<string>;
|
|
13
|
+
stream(): Promise<AsyncGenerator<StepRunEvent, void, unknown>>;
|
|
14
|
+
result(): Promise<T>;
|
|
15
|
+
toJSON(): Promise<string>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
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 __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
12
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
+
var m = o[Symbol.asyncIterator], i;
|
|
14
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
15
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
16
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
const dispatcher_1 = require("../protoc/dispatcher");
|
|
20
|
+
function getWorkflowRunId(workflowRunId) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
if (typeof workflowRunId === 'string') {
|
|
23
|
+
return workflowRunId;
|
|
24
|
+
}
|
|
25
|
+
if (workflowRunId instanceof Promise) {
|
|
26
|
+
const resolved = yield workflowRunId;
|
|
27
|
+
if (typeof resolved === 'string') {
|
|
28
|
+
return resolved;
|
|
29
|
+
}
|
|
30
|
+
return resolved.workflowRunId;
|
|
31
|
+
}
|
|
32
|
+
throw new Error('Invalid workflowRunId');
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
class WorkflowRunRef {
|
|
36
|
+
constructor(workflowRunId, client, parentWorkflowRunId) {
|
|
37
|
+
this.workflowRunId = workflowRunId;
|
|
38
|
+
this.parentWorkflowRunId = parentWorkflowRunId;
|
|
39
|
+
this.client = client;
|
|
40
|
+
}
|
|
41
|
+
getWorkflowRunId() {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
return getWorkflowRunId(this.workflowRunId);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
stream() {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const workflowRunId = yield getWorkflowRunId(this.workflowRunId);
|
|
49
|
+
return this.client.stream(workflowRunId);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
result() {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const workflowRunId = yield getWorkflowRunId(this.workflowRunId);
|
|
55
|
+
const streamable = yield this.client.get(workflowRunId);
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
var _a, e_1, _b, _c;
|
|
59
|
+
try {
|
|
60
|
+
for (var _d = true, _e = __asyncValues(streamable.stream()), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
61
|
+
_c = _f.value;
|
|
62
|
+
_d = false;
|
|
63
|
+
const event = _c;
|
|
64
|
+
if (event.eventType === dispatcher_1.WorkflowRunEventType.WORKFLOW_RUN_EVENT_TYPE_FINISHED) {
|
|
65
|
+
if (event.results.some((r) => !!r.error)) {
|
|
66
|
+
reject(event.results);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const result = event.results.reduce((acc, r) => (Object.assign(Object.assign({}, acc), { [r.stepReadableId]: JSON.parse(r.output || '{}') })), {});
|
|
70
|
+
resolve(result);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
76
|
+
finally {
|
|
77
|
+
try {
|
|
78
|
+
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
79
|
+
}
|
|
80
|
+
finally { if (e_1) throw e_1.error; }
|
|
81
|
+
}
|
|
82
|
+
}))();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
toJSON() {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
return JSON.stringify({
|
|
89
|
+
workflowRunId: yield this.workflowRunId,
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.default = WorkflowRunRef;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
-
import { Workflow } from '../../workflow';
|
|
4
|
-
import { Worker } from './worker';
|
|
5
|
-
export interface HandlerOpts {
|
|
6
|
-
secret: string;
|
|
7
|
-
}
|
|
8
|
-
export declare class WebhookHandler {
|
|
9
|
-
private worker;
|
|
10
|
-
private workflows;
|
|
11
|
-
constructor(worker: Worker, workflows: Workflow[]);
|
|
12
|
-
/**
|
|
13
|
-
* Handles a request with a provided body, secret, and signature.
|
|
14
|
-
*
|
|
15
|
-
* @param {string | undefined} body - The body of the request.
|
|
16
|
-
* @param {string | undefined} secret - The secret used for signature verification.
|
|
17
|
-
* @param {string | string[] | undefined | null} signature - The signature of the request.
|
|
18
|
-
*
|
|
19
|
-
* @throws {HatchetError} - If no signature is provided or the signature is not a string.
|
|
20
|
-
* @throws {HatchetError} - If no secret is provided.
|
|
21
|
-
* @throws {HatchetError} - If no body is provided.
|
|
22
|
-
*/
|
|
23
|
-
handle(body: string | undefined, secret: string | undefined, signature: string | string[] | undefined | null): Promise<void>;
|
|
24
|
-
private getHealthcheckResponse;
|
|
25
|
-
/**
|
|
26
|
-
* Express Handler
|
|
27
|
-
*
|
|
28
|
-
* This method is an asynchronous function that returns an Express middleware handler.
|
|
29
|
-
* The handler function is responsible for handling incoming requests and invoking the
|
|
30
|
-
* corresponding logic based on the provided secret.
|
|
31
|
-
*
|
|
32
|
-
* @param {string} secret - The secret key used to authenticate and authorize the incoming requests.
|
|
33
|
-
*
|
|
34
|
-
* @return {Function} - An Express middleware handler function that receives the request and response objects.
|
|
35
|
-
*/
|
|
36
|
-
expressHandler({ secret }: HandlerOpts): (req: any, res: any) => void;
|
|
37
|
-
/**
|
|
38
|
-
* A method that returns an HTTP request handler.
|
|
39
|
-
*
|
|
40
|
-
* @param {string} secret - The secret key used for verification.
|
|
41
|
-
*
|
|
42
|
-
* @returns {function} - An HTTP request handler function.
|
|
43
|
-
*/
|
|
44
|
-
httpHandler({ secret }: HandlerOpts): (req: IncomingMessage, res: ServerResponse) => void;
|
|
45
|
-
/**
|
|
46
|
-
* A method that returns a Next.js request handler.
|
|
47
|
-
*
|
|
48
|
-
* @param {any} req - The request object received from Next.js.
|
|
49
|
-
* @param {string} secret - The secret key used to verify the request.
|
|
50
|
-
* @return {Promise<Response>} - A Promise that resolves with a Response object.
|
|
51
|
-
*/
|
|
52
|
-
nextJSHandler({ secret }: HandlerOpts): {
|
|
53
|
-
GET: () => Promise<Response>;
|
|
54
|
-
POST: (req: Request) => Promise<Response>;
|
|
55
|
-
PUT: (req: Request) => Promise<Response>;
|
|
56
|
-
};
|
|
57
|
-
private getBody;
|
|
58
|
-
}
|