@hatchet-dev/typescript-sdk 0.8.1 → 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 +12 -6
- package/clients/admin/admin-client.js +23 -18
- package/clients/dispatcher/heartbeat/heartbeat-controller.d.ts +0 -1
- package/clients/hatchet-client/hatchet-client.js +1 -1
- 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 +1 -1
- package/clients/rest/generated/http-client.js +2 -2
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +2 -2
- 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 -2
- 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
|
@@ -2,8 +2,10 @@ import { Channel, ClientFactory } from 'nice-grpc';
|
|
|
2
2
|
import { CreateWorkflowVersionOpts, RateLimitDuration, WorkflowServiceClient } from '../../protoc/workflows';
|
|
3
3
|
import { ClientConfig } from '../hatchet-client/client-config';
|
|
4
4
|
import { Logger } from '../../util/logger';
|
|
5
|
+
import WorkflowRunRef from '../../util/workflow-run-ref';
|
|
5
6
|
import { Api } from '../rest';
|
|
6
7
|
import { WorkflowRunStatus, WorkflowRunStatusList } from '../rest/generated/data-contracts';
|
|
8
|
+
import { ListenerClient } from '../listener/listener-client';
|
|
7
9
|
type WorkflowMetricsQuery = {
|
|
8
10
|
workflowId?: string;
|
|
9
11
|
workflowName?: string;
|
|
@@ -32,7 +34,8 @@ export declare class AdminClient {
|
|
|
32
34
|
api: Api;
|
|
33
35
|
tenantId: string;
|
|
34
36
|
logger: Logger;
|
|
35
|
-
|
|
37
|
+
listenerClient: ListenerClient;
|
|
38
|
+
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory, api: Api, tenantId: string, listenerClient: ListenerClient);
|
|
36
39
|
/**
|
|
37
40
|
* @deprecated use putWorkflow instead
|
|
38
41
|
*/
|
|
@@ -57,7 +60,7 @@ export declare class AdminClient {
|
|
|
57
60
|
childIndex?: number | undefined;
|
|
58
61
|
childKey?: string | undefined;
|
|
59
62
|
additionalMetadata?: Record<string, string> | undefined;
|
|
60
|
-
}): Promise<
|
|
63
|
+
}): Promise<WorkflowRunRef<object>>;
|
|
61
64
|
/**
|
|
62
65
|
* Run a new instance of a workflow with the given input. This will create a new workflow run and return the ID of the
|
|
63
66
|
* new run.
|
|
@@ -66,13 +69,13 @@ export declare class AdminClient {
|
|
|
66
69
|
* @param options an object containing the options to run the workflow
|
|
67
70
|
* @returns the ID of the new workflow run
|
|
68
71
|
*/
|
|
69
|
-
runWorkflow<
|
|
72
|
+
runWorkflow<Q = object, P = object>(workflowName: string, input: Q, options?: {
|
|
70
73
|
parentId?: string | undefined;
|
|
71
74
|
parentStepRunId?: string | undefined;
|
|
72
75
|
childIndex?: number | undefined;
|
|
73
76
|
childKey?: string | undefined;
|
|
74
77
|
additionalMetadata?: Record<string, string> | undefined;
|
|
75
|
-
}):
|
|
78
|
+
}): WorkflowRunRef<P>;
|
|
76
79
|
/**
|
|
77
80
|
* @deprecated use listWorkflows instead
|
|
78
81
|
*/
|
|
@@ -106,13 +109,13 @@ export declare class AdminClient {
|
|
|
106
109
|
/**
|
|
107
110
|
* @deprecated use getWorkflowRun instead
|
|
108
111
|
*/
|
|
109
|
-
get_workflow_run(workflowRunId: string): Promise<
|
|
112
|
+
get_workflow_run(workflowRunId: string): Promise<WorkflowRunRef<unknown>>;
|
|
110
113
|
/**
|
|
111
114
|
* Get a workflow run.
|
|
112
115
|
* @param workflowRunId the id of the workflow run to get
|
|
113
116
|
* @returns the workflow run
|
|
114
117
|
*/
|
|
115
|
-
getWorkflowRun(workflowRunId: string): Promise<
|
|
118
|
+
getWorkflowRun(workflowRunId: string): Promise<WorkflowRunRef<unknown>>;
|
|
116
119
|
/**
|
|
117
120
|
* @deprecated use listWorkflowRuns instead
|
|
118
121
|
*/
|
|
@@ -146,14 +149,17 @@ export declare class AdminClient {
|
|
|
146
149
|
*/
|
|
147
150
|
schedule_workflow(name: string, options?: {
|
|
148
151
|
schedules?: Date[];
|
|
152
|
+
input?: object;
|
|
149
153
|
}): Promise<void>;
|
|
150
154
|
/**
|
|
151
155
|
* Schedule a workflow to run at a specific time or times.
|
|
152
156
|
* @param name the name of the workflow to schedule
|
|
153
157
|
* @param options an object containing the schedules to set
|
|
158
|
+
* @param input an object containing the input to the workflow
|
|
154
159
|
*/
|
|
155
160
|
scheduleWorkflow(name: string, options?: {
|
|
156
161
|
schedules?: Date[];
|
|
162
|
+
input?: object;
|
|
157
163
|
}): void;
|
|
158
164
|
/**
|
|
159
165
|
* @deprecated use getWorkflowMetrics instead
|
|
@@ -17,6 +17,7 @@ const workflows_1 = require("../../protoc/workflows");
|
|
|
17
17
|
const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
|
|
18
18
|
const logger_1 = require("../../util/logger");
|
|
19
19
|
const retrier_1 = require("../../util/retrier");
|
|
20
|
+
const workflow_run_ref_1 = __importDefault(require("../../util/workflow-run-ref"));
|
|
20
21
|
/**
|
|
21
22
|
* AdminClient is a client for interacting with the Hatchet Admin API. This allows you to configure, trigger,
|
|
22
23
|
* and monitor workflows.
|
|
@@ -34,12 +35,13 @@ const retrier_1 = require("../../util/retrier");
|
|
|
34
35
|
* ```
|
|
35
36
|
*/
|
|
36
37
|
class AdminClient {
|
|
37
|
-
constructor(config, channel, factory, api, tenantId) {
|
|
38
|
+
constructor(config, channel, factory, api, tenantId, listenerClient) {
|
|
38
39
|
this.config = config;
|
|
39
40
|
this.client = factory.create(workflows_1.WorkflowServiceDefinition, channel);
|
|
40
41
|
this.api = api;
|
|
41
42
|
this.tenantId = tenantId;
|
|
42
43
|
this.logger = new logger_1.Logger(`Admin`, config.log_level);
|
|
44
|
+
this.listenerClient = listenerClient;
|
|
43
45
|
}
|
|
44
46
|
/**
|
|
45
47
|
* @deprecated use putWorkflow instead
|
|
@@ -105,22 +107,20 @@ class AdminClient {
|
|
|
105
107
|
* @returns the ID of the new workflow run
|
|
106
108
|
*/
|
|
107
109
|
runWorkflow(workflowName, input, options) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
computedName = this.config.namespace + workflowName;
|
|
113
|
-
}
|
|
114
|
-
const inputStr = JSON.stringify(input);
|
|
115
|
-
const resp = yield this.client.triggerWorkflow(Object.assign(Object.assign({ name: computedName, input: inputStr }, options), { additionalMetadata: (options === null || options === void 0 ? void 0 : options.additionalMetadata)
|
|
116
|
-
? JSON.stringify(options === null || options === void 0 ? void 0 : options.additionalMetadata)
|
|
117
|
-
: undefined }));
|
|
118
|
-
return resp.workflowRunId;
|
|
119
|
-
}
|
|
120
|
-
catch (e) {
|
|
121
|
-
throw new hatchet_error_1.default(e.message);
|
|
110
|
+
let computedName = workflowName;
|
|
111
|
+
try {
|
|
112
|
+
if (this.config.namespace && !workflowName.startsWith(this.config.namespace)) {
|
|
113
|
+
computedName = this.config.namespace + workflowName;
|
|
122
114
|
}
|
|
123
|
-
|
|
115
|
+
const inputStr = JSON.stringify(input);
|
|
116
|
+
const resp = this.client.triggerWorkflow(Object.assign(Object.assign({ name: computedName, input: inputStr }, options), { additionalMetadata: (options === null || options === void 0 ? void 0 : options.additionalMetadata)
|
|
117
|
+
? JSON.stringify(options === null || options === void 0 ? void 0 : options.additionalMetadata)
|
|
118
|
+
: undefined }));
|
|
119
|
+
return new workflow_run_ref_1.default(resp, this.listenerClient, options === null || options === void 0 ? void 0 : options.parentId);
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
throw new hatchet_error_1.default(e.message);
|
|
123
|
+
}
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
126
|
* @deprecated use listWorkflows instead
|
|
@@ -196,8 +196,7 @@ class AdminClient {
|
|
|
196
196
|
*/
|
|
197
197
|
getWorkflowRun(workflowRunId) {
|
|
198
198
|
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
-
|
|
200
|
-
return res.data;
|
|
199
|
+
return new workflow_run_ref_1.default(workflowRunId, this.listenerClient);
|
|
201
200
|
});
|
|
202
201
|
}
|
|
203
202
|
/**
|
|
@@ -231,12 +230,18 @@ class AdminClient {
|
|
|
231
230
|
* Schedule a workflow to run at a specific time or times.
|
|
232
231
|
* @param name the name of the workflow to schedule
|
|
233
232
|
* @param options an object containing the schedules to set
|
|
233
|
+
* @param input an object containing the input to the workflow
|
|
234
234
|
*/
|
|
235
235
|
scheduleWorkflow(name, options) {
|
|
236
236
|
try {
|
|
237
|
+
let input;
|
|
238
|
+
if (options === null || options === void 0 ? void 0 : options.input) {
|
|
239
|
+
input = JSON.stringify(options.input);
|
|
240
|
+
}
|
|
237
241
|
this.client.scheduleWorkflow({
|
|
238
242
|
name,
|
|
239
243
|
schedules: options === null || options === void 0 ? void 0 : options.schedules,
|
|
244
|
+
input,
|
|
240
245
|
});
|
|
241
246
|
}
|
|
242
247
|
catch (e) {
|
|
@@ -111,8 +111,8 @@ class HatchetClient {
|
|
|
111
111
|
this.api = (0, rest_1.default)(this.config.api_url, this.config.token, axiosOpts);
|
|
112
112
|
this.event = new event_client_1.EventClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory);
|
|
113
113
|
this.dispatcher = new dispatcher_client_1.DispatcherClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory);
|
|
114
|
-
this.admin = new admin_client_1.AdminClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory, this.api, this.tenantId);
|
|
115
114
|
this.listener = new listener_client_1.ListenerClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory, this.api);
|
|
115
|
+
this.admin = new admin_client_1.AdminClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory, this.api, this.tenantId, this.listener);
|
|
116
116
|
this.logger = new logger_1.default('HatchetClient', this.config.log_level);
|
|
117
117
|
this.logger.info(`Initialized HatchetClient`);
|
|
118
118
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { Channel, ClientFactory } from 'nice-grpc';
|
|
3
2
|
import { EventEmitter } from 'events';
|
|
4
|
-
import { DispatcherClient as PbDispatcherClient } from '../../protoc/dispatcher';
|
|
3
|
+
import { DispatcherClient as PbDispatcherClient, DispatcherClient } from '../../protoc/dispatcher';
|
|
5
4
|
import { ClientConfig } from '../hatchet-client/client-config';
|
|
6
5
|
import { Logger } from '../../util/logger';
|
|
7
6
|
import { Api } from '../rest';
|
|
@@ -23,21 +22,15 @@ export interface StepRunEvent {
|
|
|
23
22
|
type: RunEventType;
|
|
24
23
|
payload: string;
|
|
25
24
|
}
|
|
26
|
-
export declare class
|
|
27
|
-
client:
|
|
25
|
+
export declare class RunEventListener {
|
|
26
|
+
client: DispatcherClient;
|
|
28
27
|
q: Array<StepRunEvent>;
|
|
29
28
|
eventEmitter: EventEmitter<[never]>;
|
|
30
29
|
pollInterval: any;
|
|
31
|
-
constructor(workflowRunid: string, client:
|
|
30
|
+
constructor(workflowRunid: string, client: DispatcherClient);
|
|
32
31
|
emit(event: StepRunEvent): void;
|
|
33
32
|
listen(workflowRunId: string): Promise<void>;
|
|
34
33
|
retrySubscribe(workflowRunId: string): Promise<AsyncIterable<import("../../protoc/dispatcher").WorkflowEvent>>;
|
|
35
|
-
getWorkflowRun(workflowRunId: string): Promise<{
|
|
36
|
-
type: RunEventType;
|
|
37
|
-
payload: string;
|
|
38
|
-
} | undefined>;
|
|
39
|
-
polling(workflowRunId: string): Promise<void>;
|
|
40
|
-
close(): void;
|
|
41
34
|
stream(): AsyncGenerator<StepRunEvent, void, unknown>;
|
|
42
35
|
}
|
|
43
36
|
export declare class ListenerClient {
|
|
@@ -45,9 +38,8 @@ export declare class ListenerClient {
|
|
|
45
38
|
client: PbDispatcherClient;
|
|
46
39
|
logger: Logger;
|
|
47
40
|
api: Api;
|
|
48
|
-
|
|
41
|
+
pooledListener: GrpcPooledListener | undefined;
|
|
49
42
|
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory, api: Api);
|
|
50
|
-
|
|
51
|
-
get(workflowRunId: string): PollingAsyncListener;
|
|
43
|
+
get(workflowRunId: string): import("./child-listener-client").Streamable;
|
|
52
44
|
stream(workflowRunId: string): Promise<AsyncGenerator<StepRunEvent, void, unknown>>;
|
|
53
45
|
}
|
|
@@ -32,7 +32,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
32
32
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.ListenerClient = exports.
|
|
35
|
+
exports.ListenerClient = exports.RunEventListener = exports.RunEventType = void 0;
|
|
36
36
|
// eslint-disable-next-line max-classes-per-file
|
|
37
37
|
const nice_grpc_1 = require("nice-grpc");
|
|
38
38
|
const events_1 = require("events");
|
|
@@ -94,13 +94,12 @@ const workflowStatusMap = {
|
|
|
94
94
|
[data_contracts_1.WorkflowRunStatus.RUNNING]: undefined,
|
|
95
95
|
[data_contracts_1.WorkflowRunStatus.QUEUED]: undefined,
|
|
96
96
|
};
|
|
97
|
-
class
|
|
97
|
+
class RunEventListener {
|
|
98
98
|
constructor(workflowRunid, client) {
|
|
99
99
|
this.q = [];
|
|
100
100
|
this.eventEmitter = new events_1.EventEmitter();
|
|
101
101
|
this.client = client;
|
|
102
102
|
this.listen(workflowRunid);
|
|
103
|
-
this.polling(workflowRunid);
|
|
104
103
|
}
|
|
105
104
|
emit(event) {
|
|
106
105
|
this.q.push(event);
|
|
@@ -110,14 +109,9 @@ class PollingAsyncListener {
|
|
|
110
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
110
|
var _a, e_1, _b, _c;
|
|
112
111
|
var _d;
|
|
113
|
-
let listener = this.client.
|
|
112
|
+
let listener = this.client.subscribeToWorkflowEvents({
|
|
114
113
|
workflowRunId,
|
|
115
114
|
});
|
|
116
|
-
const res = yield this.getWorkflowRun(workflowRunId);
|
|
117
|
-
if (res) {
|
|
118
|
-
this.emit(res);
|
|
119
|
-
this.close();
|
|
120
|
-
}
|
|
121
115
|
try {
|
|
122
116
|
try {
|
|
123
117
|
for (var _e = true, listener_1 = __asyncValues(listener), listener_1_1; listener_1_1 = yield listener_1.next(), _a = listener_1_1.done, !_a; _e = true) {
|
|
@@ -126,19 +120,10 @@ class PollingAsyncListener {
|
|
|
126
120
|
const workflowEvent = _c;
|
|
127
121
|
const eventType = (_d = resourceTypeMap[workflowEvent.resourceType]) === null || _d === void 0 ? void 0 : _d[workflowEvent.eventType];
|
|
128
122
|
if (eventType) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this.emit(data);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
this.emit({
|
|
138
|
-
type: eventType,
|
|
139
|
-
payload: workflowEvent.eventPayload,
|
|
140
|
-
});
|
|
141
|
-
}
|
|
123
|
+
this.emit({
|
|
124
|
+
type: eventType,
|
|
125
|
+
payload: workflowEvent.eventPayload,
|
|
126
|
+
});
|
|
142
127
|
}
|
|
143
128
|
}
|
|
144
129
|
}
|
|
@@ -158,7 +143,6 @@ class PollingAsyncListener {
|
|
|
158
143
|
listener = yield this.retrySubscribe(workflowRunId);
|
|
159
144
|
}
|
|
160
145
|
}
|
|
161
|
-
setTimeout(() => this.close(), DEFAULT_EVENT_LISTENER_POLL_INTERVAL * 5);
|
|
162
146
|
});
|
|
163
147
|
}
|
|
164
148
|
retrySubscribe(workflowRunId) {
|
|
@@ -167,7 +151,7 @@ class PollingAsyncListener {
|
|
|
167
151
|
while (retries < DEFAULT_EVENT_LISTENER_RETRY_COUNT) {
|
|
168
152
|
try {
|
|
169
153
|
yield (0, sleep_1.default)(DEFAULT_EVENT_LISTENER_RETRY_INTERVAL);
|
|
170
|
-
const listener = this.client.
|
|
154
|
+
const listener = this.client.subscribeToWorkflowEvents({
|
|
171
155
|
workflowRunId,
|
|
172
156
|
});
|
|
173
157
|
return listener;
|
|
@@ -179,54 +163,6 @@ class PollingAsyncListener {
|
|
|
179
163
|
throw new hatchet_error_1.default(`Could not subscribe to the worker after ${DEFAULT_EVENT_LISTENER_RETRY_COUNT} retries`);
|
|
180
164
|
});
|
|
181
165
|
}
|
|
182
|
-
getWorkflowRun(workflowRunId) {
|
|
183
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
-
var _a, _b, _c;
|
|
185
|
-
try {
|
|
186
|
-
const res = yield this.client.api.workflowRunGet(this.client.config.tenant_id, workflowRunId);
|
|
187
|
-
const stepRuns = (_c = (_b = (_a = res.data.jobRuns) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.stepRuns) !== null && _c !== void 0 ? _c : [];
|
|
188
|
-
const stepRunOutput = stepRuns.reduce((acc, stepRun) => {
|
|
189
|
-
var _a;
|
|
190
|
-
acc[((_a = stepRun.step) === null || _a === void 0 ? void 0 : _a.readableId) || ''] = JSON.parse(stepRun.output || '{}');
|
|
191
|
-
return acc;
|
|
192
|
-
}, {});
|
|
193
|
-
if (Object.keys(workflowStatusMap).includes(res.data.status)) {
|
|
194
|
-
const type = workflowStatusMap[res.data.status];
|
|
195
|
-
if (!type)
|
|
196
|
-
return undefined;
|
|
197
|
-
return {
|
|
198
|
-
type,
|
|
199
|
-
payload: JSON.stringify(stepRunOutput),
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
return undefined;
|
|
203
|
-
}
|
|
204
|
-
catch (e) {
|
|
205
|
-
throw new hatchet_error_1.default(e.message);
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
polling(workflowRunId) {
|
|
210
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
211
|
-
this.pollInterval = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
212
|
-
try {
|
|
213
|
-
const result = yield this.getWorkflowRun(workflowRunId);
|
|
214
|
-
if (result) {
|
|
215
|
-
this.emit(result);
|
|
216
|
-
this.close();
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
catch (e) {
|
|
220
|
-
// TODO error handling
|
|
221
|
-
}
|
|
222
|
-
}), DEFAULT_EVENT_LISTENER_POLL_INTERVAL);
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
close() {
|
|
226
|
-
if (this.pollInterval) {
|
|
227
|
-
clearInterval(this.pollInterval);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
166
|
stream() {
|
|
231
167
|
return __asyncGenerator(this, arguments, function* stream_1() {
|
|
232
168
|
var _a, e_2, _b, _c;
|
|
@@ -253,33 +189,28 @@ class PollingAsyncListener {
|
|
|
253
189
|
});
|
|
254
190
|
}
|
|
255
191
|
}
|
|
256
|
-
exports.
|
|
192
|
+
exports.RunEventListener = RunEventListener;
|
|
257
193
|
class ListenerClient {
|
|
258
194
|
constructor(config, channel, factory, api) {
|
|
259
|
-
this.childListeners = {};
|
|
260
195
|
this.config = config;
|
|
261
196
|
this.client = factory.create(dispatcher_1.DispatcherDefinition, channel);
|
|
262
197
|
this.logger = new logger_1.Logger(`Listener`, config.log_level);
|
|
263
198
|
this.api = api;
|
|
264
199
|
}
|
|
265
|
-
|
|
266
|
-
if (!this.
|
|
267
|
-
this.
|
|
268
|
-
|
|
269
|
-
delete this.childListeners[parentWorkflowRunId];
|
|
200
|
+
get(workflowRunId) {
|
|
201
|
+
if (!this.pooledListener) {
|
|
202
|
+
this.pooledListener = new child_listener_client_1.GrpcPooledListener(this, () => {
|
|
203
|
+
this.pooledListener = undefined;
|
|
270
204
|
});
|
|
271
205
|
}
|
|
272
|
-
return this.
|
|
206
|
+
return this.pooledListener.subscribe({
|
|
273
207
|
workflowRunId,
|
|
274
208
|
});
|
|
275
209
|
}
|
|
276
|
-
get(workflowRunId) {
|
|
277
|
-
const listener = new PollingAsyncListener(workflowRunId, this);
|
|
278
|
-
return listener;
|
|
279
|
-
}
|
|
280
210
|
stream(workflowRunId) {
|
|
281
211
|
return __awaiter(this, void 0, void 0, function* () {
|
|
282
|
-
|
|
212
|
+
const listener = new RunEventListener(workflowRunId, this.client);
|
|
213
|
+
return listener.stream();
|
|
283
214
|
});
|
|
284
215
|
}
|
|
285
216
|
}
|
|
@@ -535,7 +535,7 @@ export declare class Api<SecurityDataType = unknown> extends HttpClient<Security
|
|
|
535
535
|
* @secure
|
|
536
536
|
*/
|
|
537
537
|
workflowRunCancel: (tenant: string, data: WorkflowRunsCancelRequest, params?: RequestParams) => Promise<import("axios").AxiosResponse<{
|
|
538
|
-
workflowRunIds?: string[]
|
|
538
|
+
workflowRunIds?: string[];
|
|
539
539
|
}, any>>;
|
|
540
540
|
/**
|
|
541
541
|
* @description Get a workflow for a tenant
|
|
@@ -49,8 +49,8 @@ class HttpClient {
|
|
|
49
49
|
this.setSecurityData = (data) => {
|
|
50
50
|
this.securityData = data;
|
|
51
51
|
};
|
|
52
|
-
this.request = (
|
|
53
|
-
var { secure, path, type, query, format, body } =
|
|
52
|
+
this.request = (_a) => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
var { secure, path, type, query, format, body } = _a, params = __rest(_a, ["secure", "path", "type", "query", "format", "body"]);
|
|
54
54
|
const secureParams = ((typeof secure === 'boolean' ? secure : this.secure) &&
|
|
55
55
|
this.securityWorker &&
|
|
56
56
|
(yield this.securityWorker(this.securityData))) ||
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -20,4 +20,5 @@ __exportStar(require("./step"), exports);
|
|
|
20
20
|
__exportStar(require("./clients/worker"), exports);
|
|
21
21
|
__exportStar(require("./clients/rest"), exports);
|
|
22
22
|
__exportStar(require("./clients/admin"), exports);
|
|
23
|
+
__exportStar(require("./util/workflow-run-ref"), exports);
|
|
23
24
|
exports.default = hatchet_client_1.HatchetClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hatchet-dev/typescript-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"ts-jest": "^29.1.1",
|
|
85
85
|
"ts-node": "^10.9.2",
|
|
86
86
|
"ts-proto": "^1.167.0",
|
|
87
|
-
"typedoc": "^0.
|
|
87
|
+
"typedoc": "^0.26.2",
|
|
88
88
|
"typedoc-plugin-markdown": "^4.0.2",
|
|
89
89
|
"typescript": "^5.3.3"
|
|
90
90
|
},
|
|
@@ -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,6 +1,6 @@
|
|
|
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
5
|
try {
|
|
6
6
|
const firstParse = JSON.parse(json);
|
|
@@ -17,4 +17,3 @@ function parseJSON(json) {
|
|
|
17
17
|
throw new Error(`Could not parse JSON: ${e.message}`);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
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;
|