@hatchet-dev/typescript-sdk 1.2.0-alpha.1 → 1.3.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 +3 -1
- package/clients/admin/admin-client.js +1 -1
- package/clients/hatchet-client/features/cron-client.d.ts +3 -0
- package/clients/hatchet-client/features/cron-client.js +2 -0
- package/clients/hatchet-client/features/schedule-client.d.ts +3 -0
- package/clients/hatchet-client/features/schedule-client.js +2 -0
- package/clients/rest/generated/data-contracts.d.ts +193 -167
- package/clients/rest/generated/data-contracts.js +168 -168
- package/clients/worker/worker.js +5 -1
- package/package.json +2 -3
- package/protoc/dispatcher/dispatcher.d.ts +1 -0
- package/protoc/dispatcher/dispatcher.js +17 -1
- package/protoc/v1/workflows.d.ts +6 -1
- package/protoc/v1/workflows.js +60 -4
- package/protoc/workflows/workflows.d.ts +2 -0
- package/protoc/workflows/workflows.js +17 -1
- package/step.d.ts +15 -34
- package/step.js +25 -42
- package/v1/client/client.d.ts +3 -11
- package/v1/client/client.interface.d.ts +0 -2
- package/v1/client/client.js +14 -35
- package/v1/client/worker.js +2 -4
- package/v1/declaration.d.ts +32 -6
- package/v1/declaration.js +55 -64
- package/v1/examples/cancellations/run.js +4 -4
- package/v1/examples/multiple_wf_concurrency/run.js +39 -0
- package/v1/examples/{middleware → multiple_wf_concurrency}/worker.js +3 -8
- package/v1/examples/multiple_wf_concurrency/workflow.d.ts +11 -0
- package/v1/examples/multiple_wf_concurrency/workflow.js +43 -0
- package/v1/examples/priority/run.d.ts +1 -0
- package/v1/examples/priority/run.js +41 -0
- package/v1/examples/priority/worker.d.ts +1 -0
- package/v1/examples/{middleware/run.js → priority/worker.js} +5 -15
- package/v1/examples/priority/workflow.d.ts +8 -0
- package/v1/examples/priority/workflow.js +50 -0
- package/v1/index.d.ts +1 -0
- package/v1/index.js +1 -0
- package/v1/task.d.ts +6 -7
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/v1/examples/middleware/hatchet-client.d.ts +0 -2
- package/v1/examples/middleware/hatchet-client.js +0 -32
- package/v1/examples/middleware/workflow.d.ts +0 -9
- package/v1/examples/middleware/workflow.js +0 -37
- package/v1/next/index.d.ts +0 -1
- package/v1/next/index.js +0 -17
- package/v1/next/middleware/middleware.d.ts +0 -27
- package/v1/next/middleware/middleware.js +0 -121
- /package/v1/examples/{middleware → multiple_wf_concurrency}/run.d.ts +0 -0
- /package/v1/examples/{middleware → multiple_wf_concurrency}/worker.d.ts +0 -0
package/protoc/v1/workflows.js
CHANGED
|
@@ -609,7 +609,12 @@ exports.ReplayTasksResponse = {
|
|
|
609
609
|
},
|
|
610
610
|
};
|
|
611
611
|
function createBaseTriggerWorkflowRunRequest() {
|
|
612
|
-
return {
|
|
612
|
+
return {
|
|
613
|
+
workflowName: '',
|
|
614
|
+
input: new Uint8Array(0),
|
|
615
|
+
additionalMetadata: new Uint8Array(0),
|
|
616
|
+
priority: undefined,
|
|
617
|
+
};
|
|
613
618
|
}
|
|
614
619
|
exports.TriggerWorkflowRunRequest = {
|
|
615
620
|
encode(message, writer = new wire_1.BinaryWriter()) {
|
|
@@ -622,6 +627,9 @@ exports.TriggerWorkflowRunRequest = {
|
|
|
622
627
|
if (message.additionalMetadata.length !== 0) {
|
|
623
628
|
writer.uint32(26).bytes(message.additionalMetadata);
|
|
624
629
|
}
|
|
630
|
+
if (message.priority !== undefined) {
|
|
631
|
+
writer.uint32(32).int32(message.priority);
|
|
632
|
+
}
|
|
625
633
|
return writer;
|
|
626
634
|
},
|
|
627
635
|
decode(input, length) {
|
|
@@ -652,6 +660,13 @@ exports.TriggerWorkflowRunRequest = {
|
|
|
652
660
|
message.additionalMetadata = reader.bytes();
|
|
653
661
|
continue;
|
|
654
662
|
}
|
|
663
|
+
case 4: {
|
|
664
|
+
if (tag !== 32) {
|
|
665
|
+
break;
|
|
666
|
+
}
|
|
667
|
+
message.priority = reader.int32();
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
655
670
|
}
|
|
656
671
|
if ((tag & 7) === 4 || tag === 0) {
|
|
657
672
|
break;
|
|
@@ -667,6 +682,7 @@ exports.TriggerWorkflowRunRequest = {
|
|
|
667
682
|
additionalMetadata: isSet(object.additionalMetadata)
|
|
668
683
|
? bytesFromBase64(object.additionalMetadata)
|
|
669
684
|
: new Uint8Array(0),
|
|
685
|
+
priority: isSet(object.priority) ? globalThis.Number(object.priority) : undefined,
|
|
670
686
|
};
|
|
671
687
|
},
|
|
672
688
|
toJSON(message) {
|
|
@@ -680,17 +696,21 @@ exports.TriggerWorkflowRunRequest = {
|
|
|
680
696
|
if (message.additionalMetadata.length !== 0) {
|
|
681
697
|
obj.additionalMetadata = base64FromBytes(message.additionalMetadata);
|
|
682
698
|
}
|
|
699
|
+
if (message.priority !== undefined) {
|
|
700
|
+
obj.priority = Math.round(message.priority);
|
|
701
|
+
}
|
|
683
702
|
return obj;
|
|
684
703
|
},
|
|
685
704
|
create(base) {
|
|
686
705
|
return exports.TriggerWorkflowRunRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
687
706
|
},
|
|
688
707
|
fromPartial(object) {
|
|
689
|
-
var _a, _b, _c;
|
|
708
|
+
var _a, _b, _c, _d;
|
|
690
709
|
const message = createBaseTriggerWorkflowRunRequest();
|
|
691
710
|
message.workflowName = (_a = object.workflowName) !== null && _a !== void 0 ? _a : '';
|
|
692
711
|
message.input = (_b = object.input) !== null && _b !== void 0 ? _b : new Uint8Array(0);
|
|
693
712
|
message.additionalMetadata = (_c = object.additionalMetadata) !== null && _c !== void 0 ? _c : new Uint8Array(0);
|
|
713
|
+
message.priority = (_d = object.priority) !== null && _d !== void 0 ? _d : undefined;
|
|
694
714
|
return message;
|
|
695
715
|
},
|
|
696
716
|
};
|
|
@@ -758,6 +778,8 @@ function createBaseCreateWorkflowVersionRequest() {
|
|
|
758
778
|
cronInput: undefined,
|
|
759
779
|
onFailureTask: undefined,
|
|
760
780
|
sticky: undefined,
|
|
781
|
+
defaultPriority: undefined,
|
|
782
|
+
concurrencyArr: [],
|
|
761
783
|
};
|
|
762
784
|
}
|
|
763
785
|
exports.CreateWorkflowVersionRequest = {
|
|
@@ -792,6 +814,12 @@ exports.CreateWorkflowVersionRequest = {
|
|
|
792
814
|
if (message.sticky !== undefined) {
|
|
793
815
|
writer.uint32(80).int32(message.sticky);
|
|
794
816
|
}
|
|
817
|
+
if (message.defaultPriority !== undefined) {
|
|
818
|
+
writer.uint32(88).int32(message.defaultPriority);
|
|
819
|
+
}
|
|
820
|
+
for (const v of message.concurrencyArr) {
|
|
821
|
+
exports.Concurrency.encode(v, writer.uint32(98).fork()).join();
|
|
822
|
+
}
|
|
795
823
|
return writer;
|
|
796
824
|
},
|
|
797
825
|
decode(input, length) {
|
|
@@ -871,6 +899,20 @@ exports.CreateWorkflowVersionRequest = {
|
|
|
871
899
|
message.sticky = reader.int32();
|
|
872
900
|
continue;
|
|
873
901
|
}
|
|
902
|
+
case 11: {
|
|
903
|
+
if (tag !== 88) {
|
|
904
|
+
break;
|
|
905
|
+
}
|
|
906
|
+
message.defaultPriority = reader.int32();
|
|
907
|
+
continue;
|
|
908
|
+
}
|
|
909
|
+
case 12: {
|
|
910
|
+
if (tag !== 98) {
|
|
911
|
+
break;
|
|
912
|
+
}
|
|
913
|
+
message.concurrencyArr.push(exports.Concurrency.decode(reader, reader.uint32()));
|
|
914
|
+
continue;
|
|
915
|
+
}
|
|
874
916
|
}
|
|
875
917
|
if ((tag & 7) === 4 || tag === 0) {
|
|
876
918
|
break;
|
|
@@ -899,10 +941,16 @@ exports.CreateWorkflowVersionRequest = {
|
|
|
899
941
|
? exports.CreateTaskOpts.fromJSON(object.onFailureTask)
|
|
900
942
|
: undefined,
|
|
901
943
|
sticky: isSet(object.sticky) ? stickyStrategyFromJSON(object.sticky) : undefined,
|
|
944
|
+
defaultPriority: isSet(object.defaultPriority)
|
|
945
|
+
? globalThis.Number(object.defaultPriority)
|
|
946
|
+
: undefined,
|
|
947
|
+
concurrencyArr: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.concurrencyArr)
|
|
948
|
+
? object.concurrencyArr.map((e) => exports.Concurrency.fromJSON(e))
|
|
949
|
+
: [],
|
|
902
950
|
};
|
|
903
951
|
},
|
|
904
952
|
toJSON(message) {
|
|
905
|
-
var _a, _b, _c;
|
|
953
|
+
var _a, _b, _c, _d;
|
|
906
954
|
const obj = {};
|
|
907
955
|
if (message.name !== '') {
|
|
908
956
|
obj.name = message.name;
|
|
@@ -934,13 +982,19 @@ exports.CreateWorkflowVersionRequest = {
|
|
|
934
982
|
if (message.sticky !== undefined) {
|
|
935
983
|
obj.sticky = stickyStrategyToJSON(message.sticky);
|
|
936
984
|
}
|
|
985
|
+
if (message.defaultPriority !== undefined) {
|
|
986
|
+
obj.defaultPriority = Math.round(message.defaultPriority);
|
|
987
|
+
}
|
|
988
|
+
if ((_d = message.concurrencyArr) === null || _d === void 0 ? void 0 : _d.length) {
|
|
989
|
+
obj.concurrencyArr = message.concurrencyArr.map((e) => exports.Concurrency.toJSON(e));
|
|
990
|
+
}
|
|
937
991
|
return obj;
|
|
938
992
|
},
|
|
939
993
|
create(base) {
|
|
940
994
|
return exports.CreateWorkflowVersionRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
941
995
|
},
|
|
942
996
|
fromPartial(object) {
|
|
943
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
997
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
944
998
|
const message = createBaseCreateWorkflowVersionRequest();
|
|
945
999
|
message.name = (_a = object.name) !== null && _a !== void 0 ? _a : '';
|
|
946
1000
|
message.description = (_b = object.description) !== null && _b !== void 0 ? _b : '';
|
|
@@ -958,6 +1012,8 @@ exports.CreateWorkflowVersionRequest = {
|
|
|
958
1012
|
? exports.CreateTaskOpts.fromPartial(object.onFailureTask)
|
|
959
1013
|
: undefined;
|
|
960
1014
|
message.sticky = (_h = object.sticky) !== null && _h !== void 0 ? _h : undefined;
|
|
1015
|
+
message.defaultPriority = (_j = object.defaultPriority) !== null && _j !== void 0 ? _j : undefined;
|
|
1016
|
+
message.concurrencyArr = ((_k = object.concurrencyArr) === null || _k === void 0 ? void 0 : _k.map((e) => exports.Concurrency.fromPartial(e))) || [];
|
|
961
1017
|
return message;
|
|
962
1018
|
},
|
|
963
1019
|
};
|
|
@@ -195,6 +195,8 @@ export interface ScheduleWorkflowRequest {
|
|
|
195
195
|
childKey?: string | undefined;
|
|
196
196
|
/** (optional) the additional metadata for the workflow */
|
|
197
197
|
additionalMetadata?: string | undefined;
|
|
198
|
+
/** (optional) the priority of the workflow */
|
|
199
|
+
priority: number;
|
|
198
200
|
}
|
|
199
201
|
/** ScheduledWorkflow represents a scheduled workflow. */
|
|
200
202
|
export interface ScheduledWorkflow {
|
|
@@ -1409,6 +1409,7 @@ function createBaseScheduleWorkflowRequest() {
|
|
|
1409
1409
|
childIndex: undefined,
|
|
1410
1410
|
childKey: undefined,
|
|
1411
1411
|
additionalMetadata: undefined,
|
|
1412
|
+
priority: 0,
|
|
1412
1413
|
};
|
|
1413
1414
|
}
|
|
1414
1415
|
exports.ScheduleWorkflowRequest = {
|
|
@@ -1437,6 +1438,9 @@ exports.ScheduleWorkflowRequest = {
|
|
|
1437
1438
|
if (message.additionalMetadata !== undefined) {
|
|
1438
1439
|
writer.uint32(66).string(message.additionalMetadata);
|
|
1439
1440
|
}
|
|
1441
|
+
if (message.priority !== 0) {
|
|
1442
|
+
writer.uint32(72).int32(message.priority);
|
|
1443
|
+
}
|
|
1440
1444
|
return writer;
|
|
1441
1445
|
},
|
|
1442
1446
|
decode(input, length) {
|
|
@@ -1502,6 +1506,13 @@ exports.ScheduleWorkflowRequest = {
|
|
|
1502
1506
|
message.additionalMetadata = reader.string();
|
|
1503
1507
|
continue;
|
|
1504
1508
|
}
|
|
1509
|
+
case 9: {
|
|
1510
|
+
if (tag !== 72) {
|
|
1511
|
+
break;
|
|
1512
|
+
}
|
|
1513
|
+
message.priority = reader.int32();
|
|
1514
|
+
continue;
|
|
1515
|
+
}
|
|
1505
1516
|
}
|
|
1506
1517
|
if ((tag & 7) === 4 || tag === 0) {
|
|
1507
1518
|
break;
|
|
@@ -1526,6 +1537,7 @@ exports.ScheduleWorkflowRequest = {
|
|
|
1526
1537
|
additionalMetadata: isSet(object.additionalMetadata)
|
|
1527
1538
|
? globalThis.String(object.additionalMetadata)
|
|
1528
1539
|
: undefined,
|
|
1540
|
+
priority: isSet(object.priority) ? globalThis.Number(object.priority) : 0,
|
|
1529
1541
|
};
|
|
1530
1542
|
},
|
|
1531
1543
|
toJSON(message) {
|
|
@@ -1555,13 +1567,16 @@ exports.ScheduleWorkflowRequest = {
|
|
|
1555
1567
|
if (message.additionalMetadata !== undefined) {
|
|
1556
1568
|
obj.additionalMetadata = message.additionalMetadata;
|
|
1557
1569
|
}
|
|
1570
|
+
if (message.priority !== 0) {
|
|
1571
|
+
obj.priority = Math.round(message.priority);
|
|
1572
|
+
}
|
|
1558
1573
|
return obj;
|
|
1559
1574
|
},
|
|
1560
1575
|
create(base) {
|
|
1561
1576
|
return exports.ScheduleWorkflowRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
1562
1577
|
},
|
|
1563
1578
|
fromPartial(object) {
|
|
1564
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1579
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
1565
1580
|
const message = createBaseScheduleWorkflowRequest();
|
|
1566
1581
|
message.name = (_a = object.name) !== null && _a !== void 0 ? _a : '';
|
|
1567
1582
|
message.schedules = ((_b = object.schedules) === null || _b === void 0 ? void 0 : _b.map((e) => e)) || [];
|
|
@@ -1571,6 +1586,7 @@ exports.ScheduleWorkflowRequest = {
|
|
|
1571
1586
|
message.childIndex = (_f = object.childIndex) !== null && _f !== void 0 ? _f : undefined;
|
|
1572
1587
|
message.childKey = (_g = object.childKey) !== null && _g !== void 0 ? _g : undefined;
|
|
1573
1588
|
message.additionalMetadata = (_h = object.additionalMetadata) !== null && _h !== void 0 ? _h : undefined;
|
|
1589
|
+
message.priority = (_j = object.priority) !== null && _j !== void 0 ? _j : 0;
|
|
1574
1590
|
return message;
|
|
1575
1591
|
},
|
|
1576
1592
|
};
|
package/step.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ import WorkflowRunRef from './util/workflow-run-ref';
|
|
|
8
8
|
import { V0Worker } from './clients/worker';
|
|
9
9
|
import { WorkerLabels } from './clients/dispatcher/dispatcher-client';
|
|
10
10
|
import { CreateStepRateLimit, RateLimitDuration, WorkerLabelComparator } from './protoc/workflows';
|
|
11
|
-
import { CreateWorkflowTaskOpts } from './v1
|
|
12
|
-
import { TaskWorkflowDeclaration, BaseWorkflowDeclaration as WorkflowV1 } from './v1/declaration';
|
|
11
|
+
import { CreateWorkflowTaskOpts, Priority } from './v1';
|
|
12
|
+
import { RunOpts, TaskWorkflowDeclaration, BaseWorkflowDeclaration as WorkflowV1 } from './v1/declaration';
|
|
13
13
|
import { Conditions } from './v1/conditions';
|
|
14
14
|
import { Duration } from './v1/client/duration';
|
|
15
15
|
import { JsonObject, JsonValue, OutputType } from './v1/types';
|
|
@@ -155,6 +155,10 @@ export type NextStep = {
|
|
|
155
155
|
[key: string]: JsonValue;
|
|
156
156
|
};
|
|
157
157
|
type TriggerData = Record<string, Record<string, any>>;
|
|
158
|
+
type ChildRunOpts = RunOpts & {
|
|
159
|
+
key?: string;
|
|
160
|
+
sticky?: boolean;
|
|
161
|
+
};
|
|
158
162
|
interface ContextData<T, K> {
|
|
159
163
|
input: T;
|
|
160
164
|
triggers: TriggerData;
|
|
@@ -314,11 +318,7 @@ export declare class Context<T, K = {}> {
|
|
|
314
318
|
bulkRunNoWaitChildren<Q extends JsonObject = any, P extends JsonObject = any>(children: Array<{
|
|
315
319
|
workflow: string | Workflow | WorkflowV1<Q, P>;
|
|
316
320
|
input: Q;
|
|
317
|
-
options?:
|
|
318
|
-
key?: string;
|
|
319
|
-
sticky?: boolean;
|
|
320
|
-
additionalMetadata?: Record<string, string>;
|
|
321
|
-
};
|
|
321
|
+
options?: ChildRunOpts;
|
|
322
322
|
}>): Promise<WorkflowRunRef<P>[]>;
|
|
323
323
|
/**
|
|
324
324
|
* Runs multiple children workflows in parallel and waits for all results.
|
|
@@ -328,11 +328,7 @@ export declare class Context<T, K = {}> {
|
|
|
328
328
|
bulkRunChildren<Q extends JsonObject = any, P extends JsonObject = any>(children: Array<{
|
|
329
329
|
workflow: string | Workflow | WorkflowV1<Q, P>;
|
|
330
330
|
input: Q;
|
|
331
|
-
options?:
|
|
332
|
-
key?: string;
|
|
333
|
-
sticky?: boolean;
|
|
334
|
-
additionalMetadata?: Record<string, string>;
|
|
335
|
-
};
|
|
331
|
+
options?: ChildRunOpts;
|
|
336
332
|
}>): Promise<P[]>;
|
|
337
333
|
/**
|
|
338
334
|
* Spawns multiple workflows.
|
|
@@ -344,38 +340,26 @@ export declare class Context<T, K = {}> {
|
|
|
344
340
|
spawnWorkflows<Q extends JsonObject = any, P extends JsonObject = any>(workflows: Array<{
|
|
345
341
|
workflow: string | Workflow | WorkflowV1<Q, P>;
|
|
346
342
|
input: Q;
|
|
347
|
-
options?:
|
|
348
|
-
key?: string;
|
|
349
|
-
sticky?: boolean;
|
|
350
|
-
additionalMetadata?: Record<string, string>;
|
|
351
|
-
};
|
|
343
|
+
options?: ChildRunOpts;
|
|
352
344
|
}>): Promise<WorkflowRunRef<P>[]>;
|
|
353
345
|
/**
|
|
354
346
|
* Runs a new workflow and waits for its result.
|
|
355
347
|
*
|
|
356
348
|
* @param workflow - The workflow to run (name, Workflow instance, or WorkflowV1 instance).
|
|
357
349
|
* @param input - The input data for the workflow.
|
|
358
|
-
* @param
|
|
350
|
+
* @param options - An options object containing key, sticky, priority, and additionalMetadata.
|
|
359
351
|
* @returns The result of the workflow.
|
|
360
352
|
*/
|
|
361
|
-
runChild<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P> | TaskWorkflowDeclaration<Q, P>, input: Q,
|
|
362
|
-
key?: string;
|
|
363
|
-
sticky?: boolean;
|
|
364
|
-
additionalMetadata?: Record<string, string>;
|
|
365
|
-
}): Promise<P>;
|
|
353
|
+
runChild<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P> | TaskWorkflowDeclaration<Q, P>, input: Q, options?: ChildRunOpts): Promise<P>;
|
|
366
354
|
/**
|
|
367
355
|
* Enqueues a new workflow without waiting for its result.
|
|
368
356
|
*
|
|
369
357
|
* @param workflow - The workflow to enqueue (name, Workflow instance, or WorkflowV1 instance).
|
|
370
358
|
* @param input - The input data for the workflow.
|
|
371
|
-
* @param
|
|
359
|
+
* @param options - An options object containing key, sticky, priority, and additionalMetadata.
|
|
372
360
|
* @returns A reference to the spawned workflow run.
|
|
373
361
|
*/
|
|
374
|
-
runNoWaitChild<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q,
|
|
375
|
-
key?: string;
|
|
376
|
-
sticky?: boolean;
|
|
377
|
-
additionalMetadata?: Record<string, string>;
|
|
378
|
-
}): WorkflowRunRef<P>;
|
|
362
|
+
runNoWaitChild<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q, options?: ChildRunOpts): WorkflowRunRef<P>;
|
|
379
363
|
/**
|
|
380
364
|
* Spawns a new workflow.
|
|
381
365
|
*
|
|
@@ -385,11 +369,7 @@ export declare class Context<T, K = {}> {
|
|
|
385
369
|
* @returns A reference to the spawned workflow run.
|
|
386
370
|
* @deprecated Use runChild or runNoWaitChild instead.
|
|
387
371
|
*/
|
|
388
|
-
spawnWorkflow<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P> | TaskWorkflowDeclaration<Q, P>, input: Q, options?:
|
|
389
|
-
key?: string;
|
|
390
|
-
sticky?: boolean;
|
|
391
|
-
additionalMetadata?: Record<string, string>;
|
|
392
|
-
}): WorkflowRunRef<P>;
|
|
372
|
+
spawnWorkflow<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P> | TaskWorkflowDeclaration<Q, P>, input: Q, options?: ChildRunOpts): WorkflowRunRef<P>;
|
|
393
373
|
/**
|
|
394
374
|
* Retrieves additional metadata associated with the current workflow run.
|
|
395
375
|
* @returns A record of metadata key-value pairs.
|
|
@@ -410,6 +390,7 @@ export declare class Context<T, K = {}> {
|
|
|
410
390
|
* @returns The parent workflow run ID, or undefined if not a child workflow.
|
|
411
391
|
*/
|
|
412
392
|
parentWorkflowRunId(): string | undefined;
|
|
393
|
+
priority(): Priority | undefined;
|
|
413
394
|
}
|
|
414
395
|
export declare class DurableContext<T, K = {}> extends Context<T, K> {
|
|
415
396
|
waitKey: number;
|
package/step.js
CHANGED
|
@@ -53,6 +53,7 @@ const hatchet_error_1 = __importDefault(require("./util/errors/hatchet-error"));
|
|
|
53
53
|
const z = __importStar(require("zod"));
|
|
54
54
|
const parse_1 = require("./util/parse");
|
|
55
55
|
const workflows_1 = require("./protoc/workflows");
|
|
56
|
+
const v1_1 = require("./v1");
|
|
56
57
|
const declaration_1 = require("./v1/declaration");
|
|
57
58
|
const conditions_1 = require("./v1/conditions");
|
|
58
59
|
const condition_1 = require("./protoc/v1/shared/condition");
|
|
@@ -386,28 +387,15 @@ class Context {
|
|
|
386
387
|
workflowName = workflow.id;
|
|
387
388
|
}
|
|
388
389
|
const name = this.client.config.namespace + workflowName;
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
let metadata;
|
|
392
|
-
if (options) {
|
|
393
|
-
key = options.key;
|
|
394
|
-
sticky = options.sticky;
|
|
395
|
-
metadata = options.additionalMetadata;
|
|
396
|
-
}
|
|
390
|
+
const opts = options || {};
|
|
391
|
+
const { sticky } = opts;
|
|
397
392
|
if (sticky && !this.worker.hasWorkflow(name)) {
|
|
398
393
|
throw new hatchet_error_1.default(`Cannot run with sticky: workflow ${name} is not registered on the worker`);
|
|
399
394
|
}
|
|
400
395
|
const resp = {
|
|
401
396
|
workflowName: name,
|
|
402
397
|
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
|
-
},
|
|
398
|
+
options: Object.assign(Object.assign({}, opts), { parentId: workflowRunId, parentStepRunId: stepRunId, childIndex: this.spawnIndex, desiredWorkerId: sticky ? this.worker.id() : undefined }),
|
|
411
399
|
};
|
|
412
400
|
this.spawnIndex += 1;
|
|
413
401
|
return resp;
|
|
@@ -441,12 +429,12 @@ class Context {
|
|
|
441
429
|
*
|
|
442
430
|
* @param workflow - The workflow to run (name, Workflow instance, or WorkflowV1 instance).
|
|
443
431
|
* @param input - The input data for the workflow.
|
|
444
|
-
* @param
|
|
432
|
+
* @param options - An options object containing key, sticky, priority, and additionalMetadata.
|
|
445
433
|
* @returns The result of the workflow.
|
|
446
434
|
*/
|
|
447
|
-
runChild(workflow, input,
|
|
435
|
+
runChild(workflow, input, options) {
|
|
448
436
|
return __awaiter(this, void 0, void 0, function* () {
|
|
449
|
-
const run = yield this.spawnWorkflow(workflow, input,
|
|
437
|
+
const run = yield this.spawnWorkflow(workflow, input, options);
|
|
450
438
|
return run.output;
|
|
451
439
|
});
|
|
452
440
|
}
|
|
@@ -455,11 +443,11 @@ class Context {
|
|
|
455
443
|
*
|
|
456
444
|
* @param workflow - The workflow to enqueue (name, Workflow instance, or WorkflowV1 instance).
|
|
457
445
|
* @param input - The input data for the workflow.
|
|
458
|
-
* @param
|
|
446
|
+
* @param options - An options object containing key, sticky, priority, and additionalMetadata.
|
|
459
447
|
* @returns A reference to the spawned workflow run.
|
|
460
448
|
*/
|
|
461
|
-
runNoWaitChild(workflow, input,
|
|
462
|
-
return this.spawnWorkflow(workflow, input,
|
|
449
|
+
runNoWaitChild(workflow, input, options) {
|
|
450
|
+
return this.spawnWorkflow(workflow, input, options);
|
|
463
451
|
}
|
|
464
452
|
/**
|
|
465
453
|
* Spawns a new workflow.
|
|
@@ -480,30 +468,13 @@ class Context {
|
|
|
480
468
|
workflowName = workflow.id;
|
|
481
469
|
}
|
|
482
470
|
const name = this.client.config.namespace + workflowName;
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
let metadata;
|
|
486
|
-
if (typeof options === 'string') {
|
|
487
|
-
this.logger.warn('Using key param is deprecated and will be removed in a future release. Use options.key instead.');
|
|
488
|
-
key = options;
|
|
489
|
-
}
|
|
490
|
-
else {
|
|
491
|
-
key = options === null || options === void 0 ? void 0 : options.key;
|
|
492
|
-
sticky = options === null || options === void 0 ? void 0 : options.sticky;
|
|
493
|
-
metadata = options === null || options === void 0 ? void 0 : options.additionalMetadata;
|
|
494
|
-
}
|
|
471
|
+
const opts = options || {};
|
|
472
|
+
const { sticky } = opts;
|
|
495
473
|
if (sticky && !this.worker.hasWorkflow(name)) {
|
|
496
474
|
throw new hatchet_error_1.default(`cannot run with sticky: workflow ${name} is not registered on the worker`);
|
|
497
475
|
}
|
|
498
476
|
try {
|
|
499
|
-
const resp = this.client.admin.runWorkflow(name, input, {
|
|
500
|
-
parentId: workflowRunId,
|
|
501
|
-
parentStepRunId: stepRunId,
|
|
502
|
-
childKey: key,
|
|
503
|
-
childIndex: this.spawnIndex,
|
|
504
|
-
desiredWorkerId: sticky ? this.worker.id() : undefined,
|
|
505
|
-
additionalMetadata: metadata,
|
|
506
|
-
});
|
|
477
|
+
const resp = this.client.admin.runWorkflow(name, input, Object.assign({ parentId: workflowRunId, parentStepRunId: stepRunId, childIndex: this.spawnIndex, desiredWorkerId: sticky ? this.worker.id() : undefined }, opts));
|
|
507
478
|
this.spawnIndex += 1;
|
|
508
479
|
if (workflow instanceof declaration_1.TaskWorkflowDeclaration) {
|
|
509
480
|
resp._standalone_task_name = workflow._standalone_task_name;
|
|
@@ -547,6 +518,18 @@ class Context {
|
|
|
547
518
|
parentWorkflowRunId() {
|
|
548
519
|
return this.action.parentWorkflowRunId;
|
|
549
520
|
}
|
|
521
|
+
priority() {
|
|
522
|
+
switch (this.action.priority) {
|
|
523
|
+
case 1:
|
|
524
|
+
return v1_1.Priority.LOW;
|
|
525
|
+
case 2:
|
|
526
|
+
return v1_1.Priority.MEDIUM;
|
|
527
|
+
case 3:
|
|
528
|
+
return v1_1.Priority.HIGH;
|
|
529
|
+
default:
|
|
530
|
+
return undefined;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
550
533
|
}
|
|
551
534
|
exports.Context = Context;
|
|
552
535
|
class DurableContext extends Context {
|
package/v1/client/client.d.ts
CHANGED
|
@@ -13,11 +13,6 @@ import { WorkflowsClient } from './features/workflows';
|
|
|
13
13
|
import { RunsClient } from './features/runs';
|
|
14
14
|
import { InputType, OutputType, UnknownInputType, StrictWorkflowOutputType } from '../types';
|
|
15
15
|
import { RatelimitsClient } from './features';
|
|
16
|
-
import { Middleware } from '../next/middleware/middleware';
|
|
17
|
-
export interface RuntimeOpts {
|
|
18
|
-
middleware?: Middleware[];
|
|
19
|
-
}
|
|
20
|
-
type Config = Partial<ClientConfig> & RuntimeOpts;
|
|
21
16
|
/**
|
|
22
17
|
* HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
|
|
23
18
|
* It provides methods for creating and executing workflows, as well as managing workers.
|
|
@@ -26,8 +21,6 @@ export declare class HatchetClient implements IHatchetClient {
|
|
|
26
21
|
/** The underlying v0 client instance */
|
|
27
22
|
_v0: InternalHatchetClient;
|
|
28
23
|
_api: Api;
|
|
29
|
-
private _middleware?;
|
|
30
|
-
get middleware(): Middleware[] | undefined;
|
|
31
24
|
/**
|
|
32
25
|
* @deprecated v0 client will be removed in a future release, please upgrade to v1
|
|
33
26
|
*/
|
|
@@ -42,7 +35,7 @@ export declare class HatchetClient implements IHatchetClient {
|
|
|
42
35
|
* @param options - Optional client options
|
|
43
36
|
* @param axiosConfig - Optional Axios configuration for HTTP requests
|
|
44
37
|
*/
|
|
45
|
-
constructor(config?:
|
|
38
|
+
constructor(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig);
|
|
46
39
|
/**
|
|
47
40
|
* Static factory method to create a new Hatchet client instance.
|
|
48
41
|
* @param config - Optional configuration for the client
|
|
@@ -50,7 +43,7 @@ export declare class HatchetClient implements IHatchetClient {
|
|
|
50
43
|
* @param axiosConfig - Optional Axios configuration for HTTP requests
|
|
51
44
|
* @returns A new Hatchet client instance
|
|
52
45
|
*/
|
|
53
|
-
static init(config?:
|
|
46
|
+
static init(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): HatchetClient;
|
|
54
47
|
/**
|
|
55
48
|
* Creates a new workflow definition.
|
|
56
49
|
* @template I - The input type for the workflow
|
|
@@ -105,7 +98,7 @@ export declare class HatchetClient implements IHatchetClient {
|
|
|
105
98
|
* @param options - Configuration options for the workflow run
|
|
106
99
|
* @returns A WorkflowRunRef containing the run ID and methods to interact with the run
|
|
107
100
|
*/
|
|
108
|
-
runNoWait<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> | string | V0Workflow, input: I, options
|
|
101
|
+
runNoWait<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> | string | V0Workflow, input: I, options: RunOpts): WorkflowRunRef<O>;
|
|
109
102
|
/**
|
|
110
103
|
* @alias run
|
|
111
104
|
* Triggers a workflow run and waits for the result.
|
|
@@ -219,4 +212,3 @@ export declare class HatchetClient implements IHatchetClient {
|
|
|
219
212
|
webhooks(workflows: V0Workflow[]): import("../../clients/worker/handler").WebhookHandler;
|
|
220
213
|
runRef<T extends Record<string, any> = any>(id: string): WorkflowRunRef<T>;
|
|
221
214
|
}
|
|
222
|
-
export {};
|
|
@@ -3,12 +3,10 @@ import { MetricsClient } from './features/metrics';
|
|
|
3
3
|
import { RunsClient } from './features/runs';
|
|
4
4
|
import { WorkersClient } from './features/workers';
|
|
5
5
|
import { WorkflowsClient } from './features/workflows';
|
|
6
|
-
import { Middleware } from '../next/middleware/middleware';
|
|
7
6
|
export interface IHatchetClient {
|
|
8
7
|
_v0: InternalHatchetClient;
|
|
9
8
|
metrics: MetricsClient;
|
|
10
9
|
runs: RunsClient;
|
|
11
10
|
workflows: WorkflowsClient;
|
|
12
11
|
workers: WorkersClient;
|
|
13
|
-
middleware?: Middleware[];
|
|
14
12
|
}
|
package/v1/client/client.js
CHANGED
|
@@ -28,15 +28,11 @@ const workers_1 = require("./features/workers");
|
|
|
28
28
|
const workflows_1 = require("./features/workflows");
|
|
29
29
|
const runs_1 = require("./features/runs");
|
|
30
30
|
const features_1 = require("./features");
|
|
31
|
-
const middleware_1 = require("../next/middleware/middleware");
|
|
32
31
|
/**
|
|
33
32
|
* HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
|
|
34
33
|
* It provides methods for creating and executing workflows, as well as managing workers.
|
|
35
34
|
*/
|
|
36
35
|
class HatchetClient {
|
|
37
|
-
get middleware() {
|
|
38
|
-
return this._middleware;
|
|
39
|
-
}
|
|
40
36
|
/**
|
|
41
37
|
* @deprecated v0 client will be removed in a future release, please upgrade to v1
|
|
42
38
|
*/
|
|
@@ -67,9 +63,6 @@ class HatchetClient {
|
|
|
67
63
|
this.tenantId = clientConfig.tenant_id;
|
|
68
64
|
this._api = (0, rest_1.default)(clientConfig.api_url, clientConfig.token, axiosConfig);
|
|
69
65
|
this._v0 = new hatchet_client_1.InternalHatchetClient(clientConfig, options, axiosConfig, this.runs);
|
|
70
|
-
if (config === null || config === void 0 ? void 0 : config.middleware) {
|
|
71
|
-
this._middleware = config.middleware;
|
|
72
|
-
}
|
|
73
66
|
}
|
|
74
67
|
catch (e) {
|
|
75
68
|
if (e instanceof zod_1.z.ZodError) {
|
|
@@ -120,29 +113,18 @@ class HatchetClient {
|
|
|
120
113
|
* @param options - Configuration options for the workflow run
|
|
121
114
|
* @returns A WorkflowRunRef containing the run ID and methods to interact with the run
|
|
122
115
|
*/
|
|
123
|
-
runNoWait(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const serializedInput = yield (0, middleware_1.serializeInput)(input, this.middleware);
|
|
136
|
-
const runRef = this._v0.admin.runWorkflow(name, serializedInput, options);
|
|
137
|
-
// Wrap the runRef to apply output deserialization
|
|
138
|
-
const originalResult = runRef.result;
|
|
139
|
-
runRef.result = () => __awaiter(this, void 0, void 0, function* () {
|
|
140
|
-
const output = yield originalResult.call(runRef);
|
|
141
|
-
const deserializedOutput = yield (0, middleware_1.deserializeOutput)(output, this.middleware);
|
|
142
|
-
return deserializedOutput;
|
|
143
|
-
});
|
|
144
|
-
return runRef;
|
|
145
|
-
});
|
|
116
|
+
runNoWait(workflow, input, options) {
|
|
117
|
+
let name;
|
|
118
|
+
if (typeof workflow === 'string') {
|
|
119
|
+
name = workflow;
|
|
120
|
+
}
|
|
121
|
+
else if ('id' in workflow) {
|
|
122
|
+
name = workflow.id;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
throw new Error('unable to identify workflow');
|
|
126
|
+
}
|
|
127
|
+
return this._v0.admin.runWorkflow(name, input, options);
|
|
146
128
|
}
|
|
147
129
|
/**
|
|
148
130
|
* @alias run
|
|
@@ -170,11 +152,8 @@ class HatchetClient {
|
|
|
170
152
|
*/
|
|
171
153
|
run(workflow_1, input_1) {
|
|
172
154
|
return __awaiter(this, arguments, void 0, function* (workflow, input, options = {}) {
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
const output = yield runRef.result();
|
|
176
|
-
const deserializedOutput = yield (0, middleware_1.deserializeOutput)(output, this.middleware);
|
|
177
|
-
return deserializedOutput;
|
|
155
|
+
const run = this.runNoWait(workflow, input, options);
|
|
156
|
+
return run.output;
|
|
178
157
|
});
|
|
179
158
|
}
|
|
180
159
|
/**
|
package/v1/client/worker.js
CHANGED
|
@@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Worker = void 0;
|
|
13
13
|
const declaration_1 = require("../declaration");
|
|
14
|
-
const middleware_1 = require("../next/middleware/middleware");
|
|
15
14
|
const DEFAULT_DURABLE_SLOTS = 1000;
|
|
16
15
|
/**
|
|
17
16
|
* HatchetWorker class for workflow execution runtime
|
|
@@ -51,14 +50,13 @@ class Worker {
|
|
|
51
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
51
|
return Promise.all((workflows === null || workflows === void 0 ? void 0 : workflows.map((wf) => __awaiter(this, void 0, void 0, function* () {
|
|
53
52
|
if (wf instanceof declaration_1.BaseWorkflowDeclaration) {
|
|
54
|
-
const withMiddleware = yield (0, middleware_1.bindMiddleware)(wf, this._v1);
|
|
55
53
|
// TODO check if tenant is V1
|
|
56
|
-
const register = this.nonDurable.registerWorkflowV1(
|
|
54
|
+
const register = this.nonDurable.registerWorkflowV1(wf);
|
|
57
55
|
if (wf.definition._durableTasks.length > 0) {
|
|
58
56
|
if (!this.durable) {
|
|
59
57
|
this.durable = yield this._v0.worker(`${this.name}-durable`, Object.assign(Object.assign({}, this.config), { maxRuns: this.config.durableSlots || DEFAULT_DURABLE_SLOTS }));
|
|
60
58
|
}
|
|
61
|
-
this.durable.registerDurableActionsV1(
|
|
59
|
+
this.durable.registerDurableActionsV1(wf.definition);
|
|
62
60
|
}
|
|
63
61
|
return register;
|
|
64
62
|
}
|