@hatchet-dev/typescript-sdk 1.0.5 → 1.0.7
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.js +1 -0
- package/clients/rest/generated/data-contracts.d.ts +2 -0
- package/clients/rest/generated/data-contracts.js +3 -0
- package/clients/rest/generated/http-client.js +1 -0
- package/package.json +37 -36
- package/protoc/dispatcher/dispatcher.d.ts +0 -2
- package/protoc/dispatcher/dispatcher.js +1 -1
- package/protoc/events/events.js +1 -1
- package/protoc/google/protobuf/timestamp.js +1 -1
- package/protoc/v1/dispatcher.js +1 -1
- package/protoc/v1/shared/condition.js +1 -1
- package/protoc/v1/workflows.js +1 -1
- package/protoc/workflows/workflows.js +1 -1
- package/step.js +59 -57
- package/util/workflow-run-ref.d.ts +1 -0
- package/util/workflow-run-ref.js +10 -2
- package/v1/client/client.d.ts +2 -2
- package/v1/declaration.d.ts +13 -5
- package/v1/declaration.js +28 -12
- package/v1/examples/dag/interface-workflow.d.ts +12 -0
- package/v1/examples/dag/interface-workflow.js +40 -0
- package/v1/examples/simple/worker.js +2 -1
- package/v1/examples/simple/workflow-with-child.d.ts +12 -0
- package/v1/examples/simple/workflow-with-child.js +35 -0
- package/v1/types.d.ts +6 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -212,8 +212,10 @@ export declare enum TenantMemberRole {
|
|
|
212
212
|
}
|
|
213
213
|
export declare enum TenantResource {
|
|
214
214
|
WORKER = "WORKER",
|
|
215
|
+
WORKER_SLOT = "WORKER_SLOT",
|
|
215
216
|
EVENT = "EVENT",
|
|
216
217
|
WORKFLOW_RUN = "WORKFLOW_RUN",
|
|
218
|
+
TASK_RUN = "TASK_RUN",
|
|
217
219
|
CRON = "CRON",
|
|
218
220
|
SCHEDULE = "SCHEDULE"
|
|
219
221
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
/* tslint:disable */
|
|
4
|
+
// @ts-nocheck
|
|
4
5
|
/*
|
|
5
6
|
* ---------------------------------------------------------------
|
|
6
7
|
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
|
|
@@ -20,8 +21,10 @@ var TenantMemberRole;
|
|
|
20
21
|
var TenantResource;
|
|
21
22
|
(function (TenantResource) {
|
|
22
23
|
TenantResource["WORKER"] = "WORKER";
|
|
24
|
+
TenantResource["WORKER_SLOT"] = "WORKER_SLOT";
|
|
23
25
|
TenantResource["EVENT"] = "EVENT";
|
|
24
26
|
TenantResource["WORKFLOW_RUN"] = "WORKFLOW_RUN";
|
|
27
|
+
TenantResource["TASK_RUN"] = "TASK_RUN";
|
|
25
28
|
TenantResource["CRON"] = "CRON";
|
|
26
29
|
TenantResource["SCHEDULE"] = "SCHEDULE";
|
|
27
30
|
})(TenantResource || (exports.TenantResource = TenantResource = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hatchet-dev/typescript-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
|
-
"url": "https://github.com/hatchet-dev/hatchet
|
|
15
|
+
"url": "https://github.com/hatchet-dev/hatchet.git"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "echo 'build hatchet sdk with `npm run tsc:build` to ensure it is not build during the publish step' && exit 0",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test:e2e": "jest --testMatch='**/*.e2e.ts'",
|
|
24
24
|
"test:unit:watch": "jest --testMatch='**/*.test.ts' --watch",
|
|
25
25
|
"generate": "pnpm run '/generate-.*/'",
|
|
26
|
-
"generate-api": "npx --yes swagger-cli bundle ../../api-contracts/openapi/openapi.yaml --outfile openapi.yaml --type yaml && npx swagger-typescript-api -p openapi.yaml -o src/clients/rest/generated -n hatchet.ts --modular --axios",
|
|
26
|
+
"generate-api": "npx --yes swagger-cli bundle ../../api-contracts/openapi/openapi.yaml --outfile openapi.yaml --type yaml && npx swagger-typescript-api generate -p openapi.yaml -o src/clients/rest/generated -n hatchet.ts --modular --axios",
|
|
27
27
|
"generate-protoc": "./generate-protoc.sh",
|
|
28
28
|
"lint:check": "npm run eslint:check && npm run prettier:check",
|
|
29
29
|
"lint:fix": "npm run eslint:fix && npm run prettier:fix",
|
|
@@ -71,49 +71,50 @@
|
|
|
71
71
|
"license": "MIT",
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@tsd/typescript": "^5.8.2",
|
|
74
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
75
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
74
76
|
"@types/jest": "^29.5.14",
|
|
75
|
-
"@types/node": "^22.
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"dotenv-cli": "^7.3.0",
|
|
77
|
+
"@types/node": "^22.13.14",
|
|
78
|
+
"autoprefixer": "^10.4.21",
|
|
79
|
+
"dotenv-cli": "^7.4.4",
|
|
79
80
|
"eslint": "^8.56.0",
|
|
80
|
-
"eslint-config-airbnb-typescript": "^
|
|
81
|
+
"eslint-config-airbnb-typescript": "^17.1.0",
|
|
81
82
|
"eslint-config-prettier": "^9.1.0",
|
|
82
|
-
"eslint-config-standard
|
|
83
|
-
"eslint-import-resolver-typescript": "^3.
|
|
84
|
-
"eslint-plugin-import": "^2.
|
|
85
|
-
"eslint-plugin-jest": "^28.
|
|
86
|
-
"eslint-plugin-n": "^
|
|
87
|
-
"eslint-plugin-prettier": "^5.
|
|
88
|
-
"eslint-plugin-promise": "^6.
|
|
89
|
-
"eslint-plugin-react": "^7.
|
|
90
|
-
"eslint-plugin-react-hooks": "^4.6.
|
|
91
|
-
"eslint-plugin-react-refresh": "^0.4.
|
|
92
|
-
"eslint-plugin-unused-imports": "^4.1.
|
|
93
|
-
"grpc-tools": "^1.
|
|
83
|
+
"eslint-config-standard": "^17.1.0",
|
|
84
|
+
"eslint-import-resolver-typescript": "^3.10.0",
|
|
85
|
+
"eslint-plugin-import": "^2.31.0",
|
|
86
|
+
"eslint-plugin-jest": "^28.11.0",
|
|
87
|
+
"eslint-plugin-n": "^16.6.2",
|
|
88
|
+
"eslint-plugin-prettier": "^5.2.5",
|
|
89
|
+
"eslint-plugin-promise": "^6.6.0",
|
|
90
|
+
"eslint-plugin-react": "^7.37.4",
|
|
91
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
92
|
+
"eslint-plugin-react-refresh": "^0.4.19",
|
|
93
|
+
"eslint-plugin-unused-imports": "^4.1.4",
|
|
94
|
+
"grpc-tools": "^1.13.0",
|
|
94
95
|
"jest": "^29.7.0",
|
|
95
96
|
"jest-tsd": "^0.2.2",
|
|
96
97
|
"pino": "^9.6.0",
|
|
97
|
-
"prettier": "^3.
|
|
98
|
-
"resolve-tspaths": "^0.8.
|
|
99
|
-
"ts-jest": "^29.
|
|
98
|
+
"prettier": "^3.5.3",
|
|
99
|
+
"resolve-tspaths": "^0.8.23",
|
|
100
|
+
"ts-jest": "^29.3.1",
|
|
100
101
|
"ts-node": "^10.9.2",
|
|
101
|
-
"ts-proto": "^2.0
|
|
102
|
-
"typedoc": "^0.
|
|
103
|
-
"typedoc-plugin-markdown": "^4.0
|
|
104
|
-
"typescript": "^5.
|
|
102
|
+
"ts-proto": "^2.7.0",
|
|
103
|
+
"typedoc": "^0.28.0",
|
|
104
|
+
"typedoc-plugin-markdown": "^4.6.0",
|
|
105
|
+
"typescript": "^5.8.2"
|
|
105
106
|
},
|
|
106
107
|
"dependencies": {
|
|
107
|
-
"@bufbuild/protobuf": "^2.
|
|
108
|
-
"@types/qs": "^6.9.
|
|
108
|
+
"@bufbuild/protobuf": "^2.2.5",
|
|
109
|
+
"@types/qs": "^6.9.18",
|
|
109
110
|
"abort-controller-x": "^0.4.3",
|
|
110
|
-
"axios": "^1.
|
|
111
|
-
"long": "^5.
|
|
112
|
-
"nice-grpc": "^2.1.
|
|
111
|
+
"axios": "^1.8.4",
|
|
112
|
+
"long": "^5.3.1",
|
|
113
|
+
"nice-grpc": "^2.1.12",
|
|
113
114
|
"nice-grpc-common": "^2.0.2",
|
|
114
|
-
"protobufjs": "^7.
|
|
115
|
-
"qs": "^6.
|
|
116
|
-
"yaml": "^2.
|
|
117
|
-
"zod": "^3.
|
|
115
|
+
"protobufjs": "^7.4.0",
|
|
116
|
+
"qs": "^6.14.0",
|
|
117
|
+
"yaml": "^2.7.1",
|
|
118
|
+
"zod": "^3.24.2"
|
|
118
119
|
}
|
|
119
120
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.
|
|
4
|
+
// protoc-gen-ts_proto v2.7.0
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: dispatcher/dispatcher.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
package/protoc/events/events.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.
|
|
4
|
+
// protoc-gen-ts_proto v2.7.0
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: events/events.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.
|
|
4
|
+
// protoc-gen-ts_proto v2.7.0
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: google/protobuf/timestamp.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
package/protoc/v1/dispatcher.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.
|
|
4
|
+
// protoc-gen-ts_proto v2.7.0
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: v1/dispatcher.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.
|
|
4
|
+
// protoc-gen-ts_proto v2.7.0
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: v1/shared/condition.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
package/protoc/v1/workflows.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.
|
|
4
|
+
// protoc-gen-ts_proto v2.7.0
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: v1/workflows.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.
|
|
4
|
+
// protoc-gen-ts_proto v2.7.0
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: workflows/workflows.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
package/step.js
CHANGED
|
@@ -47,6 +47,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
48
|
exports.DurableContext = exports.Context = exports.ContextWorker = exports.CreateStepSchema = exports.DesiredWorkerLabelSchema = exports.CreateRateLimitSchema = void 0;
|
|
49
49
|
exports.mapRateLimit = mapRateLimit;
|
|
50
|
+
/* eslint-disable no-underscore-dangle */
|
|
50
51
|
/* eslint-disable max-classes-per-file */
|
|
51
52
|
const hatchet_error_1 = __importDefault(require("./util/errors/hatchet-error"));
|
|
52
53
|
const z = __importStar(require("zod"));
|
|
@@ -351,7 +352,9 @@ class Context {
|
|
|
351
352
|
* @returns A list of workflow run references to the enqueued runs.
|
|
352
353
|
*/
|
|
353
354
|
bulkRunNoWaitChildren(children) {
|
|
354
|
-
return this
|
|
355
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
356
|
+
return this.spawnWorkflows(children);
|
|
357
|
+
});
|
|
355
358
|
}
|
|
356
359
|
/**
|
|
357
360
|
* Runs multiple children workflows in parallel and waits for all results.
|
|
@@ -361,15 +364,7 @@ class Context {
|
|
|
361
364
|
bulkRunChildren(children) {
|
|
362
365
|
return __awaiter(this, void 0, void 0, function* () {
|
|
363
366
|
const runs = yield this.bulkRunNoWaitChildren(children);
|
|
364
|
-
|
|
365
|
-
const wf = children[index].workflow;
|
|
366
|
-
if (wf instanceof declaration_1.TaskWorkflowDeclaration) {
|
|
367
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
368
|
-
return run.output[wf._standalone_task_name];
|
|
369
|
-
}
|
|
370
|
-
return run.output;
|
|
371
|
-
});
|
|
372
|
-
return Promise.all(res);
|
|
367
|
+
return Promise.all(runs.map((run) => run.output));
|
|
373
368
|
});
|
|
374
369
|
}
|
|
375
370
|
/**
|
|
@@ -380,49 +375,60 @@ class Context {
|
|
|
380
375
|
* @deprecated Use bulkRunNoWaitChildren or bulkRunChildren instead.
|
|
381
376
|
*/
|
|
382
377
|
spawnWorkflows(workflows) {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
378
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
379
|
+
const { workflowRunId, stepRunId } = this.action;
|
|
380
|
+
const workflowRuns = workflows.map(({ workflow, input, options }) => {
|
|
381
|
+
let workflowName;
|
|
382
|
+
if (typeof workflow === 'string') {
|
|
383
|
+
workflowName = workflow;
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
workflowName = workflow.id;
|
|
387
|
+
}
|
|
388
|
+
const name = this.client.config.namespace + workflowName;
|
|
389
|
+
let key;
|
|
390
|
+
let sticky = false;
|
|
391
|
+
let metadata;
|
|
392
|
+
if (options) {
|
|
393
|
+
key = options.key;
|
|
394
|
+
sticky = options.sticky;
|
|
395
|
+
metadata = options.additionalMetadata;
|
|
396
|
+
}
|
|
397
|
+
if (sticky && !this.worker.hasWorkflow(name)) {
|
|
398
|
+
throw new hatchet_error_1.default(`Cannot run with sticky: workflow ${name} is not registered on the worker`);
|
|
399
|
+
}
|
|
400
|
+
const resp = {
|
|
401
|
+
workflowName: name,
|
|
402
|
+
input,
|
|
403
|
+
options: {
|
|
404
|
+
parentId: workflowRunId,
|
|
405
|
+
parentStepRunId: stepRunId,
|
|
406
|
+
childKey: key,
|
|
407
|
+
childIndex: this.spawnIndex,
|
|
408
|
+
desiredWorkerId: sticky ? this.worker.id() : undefined,
|
|
409
|
+
additionalMetadata: metadata,
|
|
410
|
+
},
|
|
411
|
+
};
|
|
412
|
+
this.spawnIndex += 1;
|
|
413
|
+
return resp;
|
|
414
|
+
});
|
|
415
|
+
try {
|
|
416
|
+
const resp = yield this.client.admin.runWorkflows(workflowRuns);
|
|
417
|
+
const res = [];
|
|
418
|
+
resp.forEach((ref, index) => {
|
|
419
|
+
const wf = workflows[index].workflow;
|
|
420
|
+
if (wf instanceof declaration_1.TaskWorkflowDeclaration) {
|
|
421
|
+
// eslint-disable-next-line no-param-reassign
|
|
422
|
+
ref._standalone_task_name = wf._standalone_task_name;
|
|
423
|
+
}
|
|
424
|
+
res.push(ref);
|
|
425
|
+
});
|
|
426
|
+
return resp;
|
|
400
427
|
}
|
|
401
|
-
|
|
402
|
-
throw new hatchet_error_1.default(
|
|
428
|
+
catch (e) {
|
|
429
|
+
throw new hatchet_error_1.default(e.message);
|
|
403
430
|
}
|
|
404
|
-
const resp = {
|
|
405
|
-
workflowName: name,
|
|
406
|
-
input,
|
|
407
|
-
options: {
|
|
408
|
-
parentId: workflowRunId,
|
|
409
|
-
parentStepRunId: stepRunId,
|
|
410
|
-
childKey: key,
|
|
411
|
-
childIndex: this.spawnIndex,
|
|
412
|
-
desiredWorkerId: sticky ? this.worker.id() : undefined,
|
|
413
|
-
additionalMetadata: metadata,
|
|
414
|
-
},
|
|
415
|
-
};
|
|
416
|
-
this.spawnIndex += 1;
|
|
417
|
-
return resp;
|
|
418
431
|
});
|
|
419
|
-
try {
|
|
420
|
-
const resp = this.client.admin.runWorkflows(workflowRuns);
|
|
421
|
-
return resp;
|
|
422
|
-
}
|
|
423
|
-
catch (e) {
|
|
424
|
-
throw new hatchet_error_1.default(e.message);
|
|
425
|
-
}
|
|
426
432
|
}
|
|
427
433
|
/**
|
|
428
434
|
* Runs a new workflow and waits for its result.
|
|
@@ -435,13 +441,6 @@ class Context {
|
|
|
435
441
|
runChild(workflow, input, optionsOrKey) {
|
|
436
442
|
return __awaiter(this, void 0, void 0, function* () {
|
|
437
443
|
const run = yield this.spawnWorkflow(workflow, input, optionsOrKey);
|
|
438
|
-
if (workflow instanceof declaration_1.TaskWorkflowDeclaration) {
|
|
439
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
440
|
-
if (workflow._standalone_task_name) {
|
|
441
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
442
|
-
return run.output[workflow._standalone_task_name];
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
444
|
return run.output;
|
|
446
445
|
});
|
|
447
446
|
}
|
|
@@ -500,6 +499,9 @@ class Context {
|
|
|
500
499
|
additionalMetadata: metadata,
|
|
501
500
|
});
|
|
502
501
|
this.spawnIndex += 1;
|
|
502
|
+
if (workflow instanceof declaration_1.TaskWorkflowDeclaration) {
|
|
503
|
+
resp._standalone_task_name = workflow._standalone_task_name;
|
|
504
|
+
}
|
|
503
505
|
return resp;
|
|
504
506
|
}
|
|
505
507
|
catch (e) {
|
|
@@ -11,6 +11,7 @@ export default class WorkflowRunRef<T> {
|
|
|
11
11
|
parentWorkflowRunId?: string;
|
|
12
12
|
private client;
|
|
13
13
|
private runs;
|
|
14
|
+
_standalone_task_name?: string;
|
|
14
15
|
constructor(workflowRunId: string | Promise<string> | Promise<{
|
|
15
16
|
workflowRunId: string;
|
|
16
17
|
}>, client: RunListenerClient, runsClient?: RunsClient, parentWorkflowRunId?: string);
|
package/util/workflow-run-ref.js
CHANGED
|
@@ -118,11 +118,19 @@ class WorkflowRunRef {
|
|
|
118
118
|
outputs[readableStepName] = stepRun.output;
|
|
119
119
|
}
|
|
120
120
|
});
|
|
121
|
-
|
|
121
|
+
if (!this._standalone_task_name) {
|
|
122
|
+
resolve(outputs);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
resolve(outputs[this._standalone_task_name]);
|
|
122
126
|
return;
|
|
123
127
|
}
|
|
124
128
|
const result = event.results.reduce((acc, r) => (Object.assign(Object.assign({}, acc), { [r.stepReadableId]: JSON.parse(r.output || '{}') })), {});
|
|
125
|
-
|
|
129
|
+
if (!this._standalone_task_name) {
|
|
130
|
+
resolve(result);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
resolve(result[this._standalone_task_name]);
|
|
126
134
|
return;
|
|
127
135
|
}
|
|
128
136
|
}
|
package/v1/client/client.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { WorkersClient } from './features/workers';
|
|
|
12
12
|
import { WorkflowsClient } from './features/workflows';
|
|
13
13
|
import { RunsClient } from './features/runs';
|
|
14
14
|
import { CreateStandaloneDurableTaskOpts } from '../task';
|
|
15
|
-
import { InputType, OutputType, UnknownInputType,
|
|
15
|
+
import { InputType, OutputType, UnknownInputType, StrictWorkflowOutputType } from '../types';
|
|
16
16
|
/**
|
|
17
17
|
* HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
|
|
18
18
|
* It provides methods for creating and executing workflows, as well as managing workers.
|
|
@@ -52,7 +52,7 @@ export declare class HatchetClient implements IHatchetClient {
|
|
|
52
52
|
* @returns A new Workflow instance
|
|
53
53
|
* @note It is possible to create an orphaned workflow if no client is available using @hatchet/client CreateWorkflow
|
|
54
54
|
*/
|
|
55
|
-
workflow<I extends InputType = UnknownInputType, O extends
|
|
55
|
+
workflow<I extends InputType = UnknownInputType, O extends StrictWorkflowOutputType = {}>(options: CreateWorkflowOpts): WorkflowDeclaration<I, O>;
|
|
56
56
|
/**
|
|
57
57
|
* Creates a new task workflow.
|
|
58
58
|
* Types can be explicitly specified as generics or inferred from the function signature.
|
package/v1/declaration.d.ts
CHANGED
|
@@ -171,7 +171,7 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
|
|
|
171
171
|
* @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
|
|
172
172
|
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
173
173
|
*/
|
|
174
|
-
runNoWait(input: I, options?: RunOpts): WorkflowRunRef<O>;
|
|
174
|
+
runNoWait(input: I, options?: RunOpts, _standaloneTaskName?: string): WorkflowRunRef<O>;
|
|
175
175
|
/**
|
|
176
176
|
* @alias run
|
|
177
177
|
* Triggers a workflow run and waits for the result.
|
|
@@ -181,8 +181,8 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
|
|
|
181
181
|
* @param options - Configuration options for the workflow run
|
|
182
182
|
* @returns A promise that resolves with the workflow result
|
|
183
183
|
*/
|
|
184
|
-
runAndWait(input: I, options?: RunOpts): Promise<O>;
|
|
185
|
-
runAndWait(input: I[], options?: RunOpts): Promise<O[]>;
|
|
184
|
+
runAndWait(input: I, options?: RunOpts, _standaloneTaskName?: string): Promise<O>;
|
|
185
|
+
runAndWait(input: I[], options?: RunOpts, _standaloneTaskName?: string): Promise<O[]>;
|
|
186
186
|
/**
|
|
187
187
|
* Executes the workflow with the given input and awaits the results.
|
|
188
188
|
* @param input The input data for the workflow.
|
|
@@ -190,8 +190,8 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
|
|
|
190
190
|
* @returns A promise that resolves with the workflow result.
|
|
191
191
|
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
192
192
|
*/
|
|
193
|
-
run(input: I, options?: RunOpts): Promise<O>;
|
|
194
|
-
run(input: I[], options?: RunOpts): Promise<O[]>;
|
|
193
|
+
run(input: I, options?: RunOpts, _standaloneTaskName?: string): Promise<O>;
|
|
194
|
+
run(input: I[], options?: RunOpts, _standaloneTaskName?: string): Promise<O[]>;
|
|
195
195
|
/**
|
|
196
196
|
* Schedules a workflow to run at a specific date and time in the future.
|
|
197
197
|
* @param enqueueAt The date when the workflow should be triggered.
|
|
@@ -302,6 +302,14 @@ export declare class TaskWorkflowDeclaration<I extends InputType = UnknownInputT
|
|
|
302
302
|
constructor(options: CreateTaskWorkflowOpts<I, O>, client?: IHatchetClient);
|
|
303
303
|
run(input: I, options?: RunOpts): Promise<O>;
|
|
304
304
|
run(input: I[], options?: RunOpts): Promise<O[]>;
|
|
305
|
+
/**
|
|
306
|
+
* Triggers a workflow run without waiting for completion.
|
|
307
|
+
* @param input The input data for the workflow.
|
|
308
|
+
* @param options Optional configuration for this workflow run.
|
|
309
|
+
* @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
|
|
310
|
+
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
311
|
+
*/
|
|
312
|
+
runNoWait(input: I, options?: RunOpts): WorkflowRunRef<O>;
|
|
305
313
|
get taskDef(): CreateWorkflowTaskOpts<any, any>;
|
|
306
314
|
}
|
|
307
315
|
/**
|
package/v1/declaration.js
CHANGED
|
@@ -36,33 +36,40 @@ class BaseWorkflowDeclaration {
|
|
|
36
36
|
* @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
|
|
37
37
|
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
38
38
|
*/
|
|
39
|
-
runNoWait(input, options) {
|
|
39
|
+
runNoWait(input, options, _standaloneTaskName) {
|
|
40
40
|
if (!this.client) {
|
|
41
41
|
throw UNBOUND_ERR;
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
const res = this.client._v0.admin.runWorkflow(this.name, input, options);
|
|
44
|
+
if (_standaloneTaskName) {
|
|
45
|
+
res._standalone_task_name = _standaloneTaskName;
|
|
46
|
+
}
|
|
47
|
+
return res;
|
|
44
48
|
}
|
|
45
|
-
runAndWait(input, options) {
|
|
49
|
+
runAndWait(input, options, _standaloneTaskName) {
|
|
46
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
51
|
if (!this.client) {
|
|
48
52
|
throw UNBOUND_ERR;
|
|
49
53
|
}
|
|
50
54
|
if (Array.isArray(input)) {
|
|
51
|
-
return Promise.all(input.map((i) => this.runAndWait(i, options)));
|
|
55
|
+
return Promise.all(input.map((i) => this.runAndWait(i, options, _standaloneTaskName)));
|
|
52
56
|
}
|
|
53
|
-
return this.run(input, options);
|
|
57
|
+
return this.run(input, options, _standaloneTaskName);
|
|
54
58
|
});
|
|
55
59
|
}
|
|
56
|
-
run(input, options) {
|
|
60
|
+
run(input, options, _standaloneTaskName) {
|
|
57
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
62
|
if (!this.client) {
|
|
59
63
|
throw UNBOUND_ERR;
|
|
60
64
|
}
|
|
61
65
|
if (Array.isArray(input)) {
|
|
62
66
|
// FIXME use bulk endpoint?
|
|
63
|
-
return Promise.all(input.map((i) => this.run(i, options)));
|
|
67
|
+
return Promise.all(input.map((i) => this.run(i, options, _standaloneTaskName)));
|
|
64
68
|
}
|
|
65
69
|
const res = this.client._v0.admin.runWorkflow(this.definition.name, input, options);
|
|
70
|
+
if (_standaloneTaskName) {
|
|
71
|
+
res._standalone_task_name = _standaloneTaskName;
|
|
72
|
+
}
|
|
66
73
|
return res.result();
|
|
67
74
|
});
|
|
68
75
|
}
|
|
@@ -288,13 +295,22 @@ class TaskWorkflowDeclaration extends BaseWorkflowDeclaration {
|
|
|
288
295
|
run: { get: () => super.run }
|
|
289
296
|
});
|
|
290
297
|
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
-
|
|
292
|
-
if (Array.isArray(res)) {
|
|
293
|
-
return res.map((r) => r[this._standalone_task_name]);
|
|
294
|
-
}
|
|
295
|
-
return res[this._standalone_task_name];
|
|
298
|
+
return (yield _super.run.call(this, input, options, this._standalone_task_name));
|
|
296
299
|
});
|
|
297
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Triggers a workflow run without waiting for completion.
|
|
303
|
+
* @param input The input data for the workflow.
|
|
304
|
+
* @param options Optional configuration for this workflow run.
|
|
305
|
+
* @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
|
|
306
|
+
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
307
|
+
*/
|
|
308
|
+
runNoWait(input, options) {
|
|
309
|
+
if (!this.client) {
|
|
310
|
+
throw UNBOUND_ERR;
|
|
311
|
+
}
|
|
312
|
+
return super.runNoWait(input, options, this._standalone_task_name);
|
|
313
|
+
}
|
|
298
314
|
get taskDef() {
|
|
299
315
|
return this.definition._tasks[0];
|
|
300
316
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WorkflowInputType, WorkflowOutputType } from '../..';
|
|
2
|
+
interface DagInput extends WorkflowInputType {
|
|
3
|
+
Message: string;
|
|
4
|
+
}
|
|
5
|
+
interface DagOutput extends WorkflowOutputType {
|
|
6
|
+
reverse: {
|
|
7
|
+
Original: string;
|
|
8
|
+
Transformed: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare const dag: import("../..").WorkflowDeclaration<DagInput, DagOutput>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.dag = void 0;
|
|
13
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
14
|
+
// ❓ Declaring a DAG Workflow
|
|
15
|
+
// First, we declare the workflow
|
|
16
|
+
exports.dag = hatchet_client_1.hatchet.workflow({
|
|
17
|
+
name: 'simple',
|
|
18
|
+
});
|
|
19
|
+
const reverse = exports.dag.task({
|
|
20
|
+
name: 'reverse',
|
|
21
|
+
fn: (input) => {
|
|
22
|
+
return {
|
|
23
|
+
Original: input.Message,
|
|
24
|
+
Transformed: input.Message.split('').reverse().join(''),
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
exports.dag.task({
|
|
29
|
+
name: 'to-lower',
|
|
30
|
+
parents: [reverse],
|
|
31
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
const r = yield ctx.parentOutput(reverse);
|
|
33
|
+
return {
|
|
34
|
+
reverse: {
|
|
35
|
+
Original: r.Transformed,
|
|
36
|
+
Transformed: r.Transformed.toLowerCase(),
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
@@ -12,11 +12,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
// ❓ Declaring a Worker
|
|
13
13
|
const hatchet_client_1 = require("../hatchet-client");
|
|
14
14
|
const workflow_1 = require("./workflow");
|
|
15
|
+
const workflow_with_child_1 = require("./workflow-with-child");
|
|
15
16
|
function main() {
|
|
16
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
18
|
const worker = yield hatchet_client_1.hatchet.worker('simple-worker', {
|
|
18
19
|
// 👀 Declare the workflows that the worker can execute
|
|
19
|
-
workflows: [workflow_1.simple],
|
|
20
|
+
workflows: [workflow_1.simple, workflow_with_child_1.parent, workflow_with_child_1.child],
|
|
20
21
|
// 👀 Declare the number of concurrent task runs the worker can accept
|
|
21
22
|
slots: 100,
|
|
22
23
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type ChildInput = {
|
|
2
|
+
Message: string;
|
|
3
|
+
};
|
|
4
|
+
export type ParentInput = {
|
|
5
|
+
Message: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const child: import("../..").TaskWorkflowDeclaration<ChildInput, {
|
|
8
|
+
TransformedMessage: string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const parent: import("../..").TaskWorkflowDeclaration<ParentInput, {
|
|
11
|
+
TransformedMessage: string;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.parent = exports.child = void 0;
|
|
13
|
+
// ❓ Declaring a Task
|
|
14
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
+
exports.child = hatchet_client_1.hatchet.task({
|
|
16
|
+
name: 'child',
|
|
17
|
+
fn: (input) => {
|
|
18
|
+
return {
|
|
19
|
+
TransformedMessage: input.Message.toLowerCase(),
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
exports.parent = hatchet_client_1.hatchet.task({
|
|
24
|
+
name: 'parent',
|
|
25
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
const c = yield ctx.runChild(exports.child, {
|
|
27
|
+
Message: input.Message,
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
TransformedMessage: c.TransformedMessage,
|
|
31
|
+
};
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
// !!
|
|
35
|
+
// see ./worker.ts and ./run.ts for how to run the workflow
|
package/v1/types.d.ts
CHANGED
|
@@ -7,10 +7,15 @@ export type JsonObject = {
|
|
|
7
7
|
[Key in string]?: JsonValue | undefined;
|
|
8
8
|
};
|
|
9
9
|
export type InputType = JsonObject;
|
|
10
|
+
export interface WorkflowInputType extends InputType {
|
|
11
|
+
}
|
|
10
12
|
export type UnknownInputType = {};
|
|
11
13
|
export type OutputType = JsonObject | void;
|
|
14
|
+
export interface WorkflowOutputType {
|
|
15
|
+
[key: string]: JsonObject;
|
|
16
|
+
}
|
|
12
17
|
type IsValidWorkflowOutput<T> = T extends Record<string, JsonObject> ? true : false;
|
|
13
|
-
export type
|
|
18
|
+
export type StrictWorkflowOutputType<T = any> = IsValidWorkflowOutput<T> extends true ? T : (Record<string, JsonObject> | void) & {
|
|
14
19
|
[ERROR_WORKFLOW_OUTPUT]?: 'Workflow output must be shaped as Record<"task-name", JsonObject>. Each property must be an object, not a primitive value.';
|
|
15
20
|
};
|
|
16
21
|
declare const ERROR_WORKFLOW_OUTPUT: unique symbol;
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.0.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.0.7";
|
package/version.js
CHANGED