@hatchet-dev/typescript-sdk 1.8.1 → 1.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/event/event-client.d.ts +1 -1
- package/clients/event/event-client.js +2 -1
- package/clients/rest/generated/data-contracts.d.ts +3 -0
- package/package.json +1 -1
- package/protoc/dispatcher/dispatcher.d.ts +1 -0
- package/protoc/dispatcher/dispatcher.js +27 -1
- package/protoc/events/events.d.ts +1 -0
- package/protoc/events/events.js +33 -2
- package/protoc/v1/workflows.d.ts +1 -1
- package/protoc/v1/workflows.js +4 -4
- package/step.js +1 -1
- package/v1/client/features/filters.d.ts +2 -1
- package/v1/client/features/filters.js +2 -10
- package/v1/client/worker/context.d.ts +2 -0
- package/v1/client/worker/context.js +8 -1
- package/v1/client/worker/worker-internal.js +3 -8
- package/v1/client/worker/worker.js +1 -0
- package/v1/examples/streaming/run.d.ts +1 -0
- package/v1/examples/streaming/run.js +54 -0
- package/v1/examples/streaming/worker.d.ts +1 -0
- package/v1/examples/streaming/worker.js +24 -0
- package/v1/examples/streaming/workflow.d.ts +1 -0
- package/v1/examples/streaming/workflow.js +38 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -33,6 +33,6 @@ export declare class EventClient {
|
|
|
33
33
|
push<T>(type: string, input: T, options?: PushEventOptions): Promise<import("../../protoc/events/events").Event>;
|
|
34
34
|
bulkPush<T>(type: string, inputs: EventWithMetadata<T>[], options?: PushEventOptions): Promise<import("../../protoc/events/events").Events>;
|
|
35
35
|
putLog(stepRunId: string, log: string, level?: LogLevel, taskRetryCount?: number, metadata?: Record<string, any>): Promise<void>;
|
|
36
|
-
putStream(stepRunId: string, data: string | Uint8Array): Promise<void>;
|
|
36
|
+
putStream(stepRunId: string, data: string | Uint8Array, index: number | undefined): Promise<void>;
|
|
37
37
|
list(opts?: Parameters<typeof this.api.v1EventList>[1]): Promise<import("../rest/generated/data-contracts").V1EventList>;
|
|
38
38
|
}
|
|
@@ -110,7 +110,7 @@ class EventClient {
|
|
|
110
110
|
});
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
|
-
putStream(stepRunId, data) {
|
|
113
|
+
putStream(stepRunId, data, index) {
|
|
114
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
115
|
const createdAt = new Date();
|
|
116
116
|
let dataBytes;
|
|
@@ -128,6 +128,7 @@ class EventClient {
|
|
|
128
128
|
stepRunId,
|
|
129
129
|
createdAt,
|
|
130
130
|
message: dataBytes,
|
|
131
|
+
eventIndex: index,
|
|
131
132
|
});
|
|
132
133
|
}), this.logger).catch((e) => {
|
|
133
134
|
// log a warning, but this is not a fatal error
|
|
@@ -651,6 +651,7 @@ export interface WorkflowVersion {
|
|
|
651
651
|
triggers?: WorkflowTriggers;
|
|
652
652
|
scheduleTimeout?: string;
|
|
653
653
|
jobs?: Job[];
|
|
654
|
+
workflowConfig?: object;
|
|
654
655
|
}
|
|
655
656
|
export interface WorkflowVersionDefinition {
|
|
656
657
|
/** The raw YAML definition of the workflow. */
|
|
@@ -1482,6 +1483,7 @@ export interface V1TaskSummary {
|
|
|
1482
1483
|
* @format uuid
|
|
1483
1484
|
*/
|
|
1484
1485
|
workflowVersionId?: string;
|
|
1486
|
+
workflowConfig?: object;
|
|
1485
1487
|
}
|
|
1486
1488
|
export interface V1DagChildren {
|
|
1487
1489
|
/** @format uuid */
|
|
@@ -1621,6 +1623,7 @@ export interface V1WorkflowRunDetails {
|
|
|
1621
1623
|
taskName: string;
|
|
1622
1624
|
}[];
|
|
1623
1625
|
tasks: V1TaskSummary[];
|
|
1626
|
+
workflowConfig?: object;
|
|
1624
1627
|
}
|
|
1625
1628
|
export declare enum V1TaskRunStatus {
|
|
1626
1629
|
PENDING = "PENDING",
|
package/package.json
CHANGED
|
@@ -252,6 +252,7 @@ export interface WorkflowEvent {
|
|
|
252
252
|
stepRetries?: number | undefined;
|
|
253
253
|
/** (optional) the retry count of this step */
|
|
254
254
|
retryCount?: number | undefined;
|
|
255
|
+
eventIndex?: number | undefined;
|
|
255
256
|
}
|
|
256
257
|
export interface WorkflowRunEvent {
|
|
257
258
|
/** the id of the workflow run */
|
|
@@ -2219,6 +2219,7 @@ function createBaseWorkflowEvent() {
|
|
|
2219
2219
|
hangup: false,
|
|
2220
2220
|
stepRetries: undefined,
|
|
2221
2221
|
retryCount: undefined,
|
|
2222
|
+
eventIndex: undefined,
|
|
2222
2223
|
};
|
|
2223
2224
|
}
|
|
2224
2225
|
exports.WorkflowEvent = {
|
|
@@ -2250,6 +2251,9 @@ exports.WorkflowEvent = {
|
|
|
2250
2251
|
if (message.retryCount !== undefined) {
|
|
2251
2252
|
writer.uint32(72).int32(message.retryCount);
|
|
2252
2253
|
}
|
|
2254
|
+
if (message.eventIndex !== undefined) {
|
|
2255
|
+
writer.uint32(80).int64(message.eventIndex);
|
|
2256
|
+
}
|
|
2253
2257
|
return writer;
|
|
2254
2258
|
},
|
|
2255
2259
|
decode(input, length) {
|
|
@@ -2322,6 +2326,13 @@ exports.WorkflowEvent = {
|
|
|
2322
2326
|
message.retryCount = reader.int32();
|
|
2323
2327
|
continue;
|
|
2324
2328
|
}
|
|
2329
|
+
case 10: {
|
|
2330
|
+
if (tag !== 80) {
|
|
2331
|
+
break;
|
|
2332
|
+
}
|
|
2333
|
+
message.eventIndex = longToNumber(reader.int64());
|
|
2334
|
+
continue;
|
|
2335
|
+
}
|
|
2325
2336
|
}
|
|
2326
2337
|
if ((tag & 7) === 4 || tag === 0) {
|
|
2327
2338
|
break;
|
|
@@ -2343,6 +2354,7 @@ exports.WorkflowEvent = {
|
|
|
2343
2354
|
hangup: isSet(object.hangup) ? globalThis.Boolean(object.hangup) : false,
|
|
2344
2355
|
stepRetries: isSet(object.stepRetries) ? globalThis.Number(object.stepRetries) : undefined,
|
|
2345
2356
|
retryCount: isSet(object.retryCount) ? globalThis.Number(object.retryCount) : undefined,
|
|
2357
|
+
eventIndex: isSet(object.eventIndex) ? globalThis.Number(object.eventIndex) : undefined,
|
|
2346
2358
|
};
|
|
2347
2359
|
},
|
|
2348
2360
|
toJSON(message) {
|
|
@@ -2374,13 +2386,16 @@ exports.WorkflowEvent = {
|
|
|
2374
2386
|
if (message.retryCount !== undefined) {
|
|
2375
2387
|
obj.retryCount = Math.round(message.retryCount);
|
|
2376
2388
|
}
|
|
2389
|
+
if (message.eventIndex !== undefined) {
|
|
2390
|
+
obj.eventIndex = Math.round(message.eventIndex);
|
|
2391
|
+
}
|
|
2377
2392
|
return obj;
|
|
2378
2393
|
},
|
|
2379
2394
|
create(base) {
|
|
2380
2395
|
return exports.WorkflowEvent.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
2381
2396
|
},
|
|
2382
2397
|
fromPartial(object) {
|
|
2383
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
2398
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2384
2399
|
const message = createBaseWorkflowEvent();
|
|
2385
2400
|
message.workflowRunId = (_a = object.workflowRunId) !== null && _a !== void 0 ? _a : '';
|
|
2386
2401
|
message.resourceType = (_b = object.resourceType) !== null && _b !== void 0 ? _b : 0;
|
|
@@ -2391,6 +2406,7 @@ exports.WorkflowEvent = {
|
|
|
2391
2406
|
message.hangup = (_g = object.hangup) !== null && _g !== void 0 ? _g : false;
|
|
2392
2407
|
message.stepRetries = (_h = object.stepRetries) !== null && _h !== void 0 ? _h : undefined;
|
|
2393
2408
|
message.retryCount = (_j = object.retryCount) !== null && _j !== void 0 ? _j : undefined;
|
|
2409
|
+
message.eventIndex = (_k = object.eventIndex) !== null && _k !== void 0 ? _k : undefined;
|
|
2394
2410
|
return message;
|
|
2395
2411
|
},
|
|
2396
2412
|
};
|
|
@@ -3202,6 +3218,16 @@ function fromJsonTimestamp(o) {
|
|
|
3202
3218
|
return fromTimestamp(timestamp_1.Timestamp.fromJSON(o));
|
|
3203
3219
|
}
|
|
3204
3220
|
}
|
|
3221
|
+
function longToNumber(int64) {
|
|
3222
|
+
const num = globalThis.Number(int64.toString());
|
|
3223
|
+
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
|
|
3224
|
+
throw new globalThis.Error('Value is larger than Number.MAX_SAFE_INTEGER');
|
|
3225
|
+
}
|
|
3226
|
+
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
|
|
3227
|
+
throw new globalThis.Error('Value is smaller than Number.MIN_SAFE_INTEGER');
|
|
3228
|
+
}
|
|
3229
|
+
return num;
|
|
3230
|
+
}
|
|
3205
3231
|
function isObject(value) {
|
|
3206
3232
|
return typeof value === 'object' && value !== null;
|
|
3207
3233
|
}
|
package/protoc/events/events.js
CHANGED
|
@@ -399,7 +399,13 @@ exports.PutLogResponse = {
|
|
|
399
399
|
},
|
|
400
400
|
};
|
|
401
401
|
function createBasePutStreamEventRequest() {
|
|
402
|
-
return {
|
|
402
|
+
return {
|
|
403
|
+
stepRunId: '',
|
|
404
|
+
createdAt: undefined,
|
|
405
|
+
message: new Uint8Array(0),
|
|
406
|
+
metadata: '',
|
|
407
|
+
eventIndex: undefined,
|
|
408
|
+
};
|
|
403
409
|
}
|
|
404
410
|
exports.PutStreamEventRequest = {
|
|
405
411
|
encode(message, writer = new wire_1.BinaryWriter()) {
|
|
@@ -415,6 +421,9 @@ exports.PutStreamEventRequest = {
|
|
|
415
421
|
if (message.metadata !== '') {
|
|
416
422
|
writer.uint32(42).string(message.metadata);
|
|
417
423
|
}
|
|
424
|
+
if (message.eventIndex !== undefined) {
|
|
425
|
+
writer.uint32(48).int64(message.eventIndex);
|
|
426
|
+
}
|
|
418
427
|
return writer;
|
|
419
428
|
},
|
|
420
429
|
decode(input, length) {
|
|
@@ -452,6 +461,13 @@ exports.PutStreamEventRequest = {
|
|
|
452
461
|
message.metadata = reader.string();
|
|
453
462
|
continue;
|
|
454
463
|
}
|
|
464
|
+
case 6: {
|
|
465
|
+
if (tag !== 48) {
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
message.eventIndex = longToNumber(reader.int64());
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
455
471
|
}
|
|
456
472
|
if ((tag & 7) === 4 || tag === 0) {
|
|
457
473
|
break;
|
|
@@ -466,6 +482,7 @@ exports.PutStreamEventRequest = {
|
|
|
466
482
|
createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined,
|
|
467
483
|
message: isSet(object.message) ? bytesFromBase64(object.message) : new Uint8Array(0),
|
|
468
484
|
metadata: isSet(object.metadata) ? globalThis.String(object.metadata) : '',
|
|
485
|
+
eventIndex: isSet(object.eventIndex) ? globalThis.Number(object.eventIndex) : undefined,
|
|
469
486
|
};
|
|
470
487
|
},
|
|
471
488
|
toJSON(message) {
|
|
@@ -482,18 +499,22 @@ exports.PutStreamEventRequest = {
|
|
|
482
499
|
if (message.metadata !== '') {
|
|
483
500
|
obj.metadata = message.metadata;
|
|
484
501
|
}
|
|
502
|
+
if (message.eventIndex !== undefined) {
|
|
503
|
+
obj.eventIndex = Math.round(message.eventIndex);
|
|
504
|
+
}
|
|
485
505
|
return obj;
|
|
486
506
|
},
|
|
487
507
|
create(base) {
|
|
488
508
|
return exports.PutStreamEventRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
489
509
|
},
|
|
490
510
|
fromPartial(object) {
|
|
491
|
-
var _a, _b, _c, _d;
|
|
511
|
+
var _a, _b, _c, _d, _e;
|
|
492
512
|
const message = createBasePutStreamEventRequest();
|
|
493
513
|
message.stepRunId = (_a = object.stepRunId) !== null && _a !== void 0 ? _a : '';
|
|
494
514
|
message.createdAt = (_b = object.createdAt) !== null && _b !== void 0 ? _b : undefined;
|
|
495
515
|
message.message = (_c = object.message) !== null && _c !== void 0 ? _c : new Uint8Array(0);
|
|
496
516
|
message.metadata = (_d = object.metadata) !== null && _d !== void 0 ? _d : '';
|
|
517
|
+
message.eventIndex = (_e = object.eventIndex) !== null && _e !== void 0 ? _e : undefined;
|
|
497
518
|
return message;
|
|
498
519
|
},
|
|
499
520
|
};
|
|
@@ -875,6 +896,16 @@ function fromJsonTimestamp(o) {
|
|
|
875
896
|
return fromTimestamp(timestamp_1.Timestamp.fromJSON(o));
|
|
876
897
|
}
|
|
877
898
|
}
|
|
899
|
+
function longToNumber(int64) {
|
|
900
|
+
const num = globalThis.Number(int64.toString());
|
|
901
|
+
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
|
|
902
|
+
throw new globalThis.Error('Value is larger than Number.MAX_SAFE_INTEGER');
|
|
903
|
+
}
|
|
904
|
+
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
|
|
905
|
+
throw new globalThis.Error('Value is smaller than Number.MIN_SAFE_INTEGER');
|
|
906
|
+
}
|
|
907
|
+
return num;
|
|
908
|
+
}
|
|
878
909
|
function isSet(value) {
|
|
879
910
|
return value !== null && value !== undefined;
|
|
880
911
|
}
|
package/protoc/v1/workflows.d.ts
CHANGED
|
@@ -111,7 +111,7 @@ export interface DefaultFilter {
|
|
|
111
111
|
/** (required) the scope of the filter */
|
|
112
112
|
scope: string;
|
|
113
113
|
/** (optional) the payload for the filter, if any. A JSON object as a string. */
|
|
114
|
-
payload?:
|
|
114
|
+
payload?: Uint8Array | undefined;
|
|
115
115
|
}
|
|
116
116
|
export interface Concurrency {
|
|
117
117
|
/** (required) the expression to use for concurrency */
|
package/protoc/v1/workflows.js
CHANGED
|
@@ -1047,7 +1047,7 @@ exports.DefaultFilter = {
|
|
|
1047
1047
|
writer.uint32(18).string(message.scope);
|
|
1048
1048
|
}
|
|
1049
1049
|
if (message.payload !== undefined) {
|
|
1050
|
-
writer.uint32(26).
|
|
1050
|
+
writer.uint32(26).bytes(message.payload);
|
|
1051
1051
|
}
|
|
1052
1052
|
return writer;
|
|
1053
1053
|
},
|
|
@@ -1076,7 +1076,7 @@ exports.DefaultFilter = {
|
|
|
1076
1076
|
if (tag !== 26) {
|
|
1077
1077
|
break;
|
|
1078
1078
|
}
|
|
1079
|
-
message.payload = reader.
|
|
1079
|
+
message.payload = reader.bytes();
|
|
1080
1080
|
continue;
|
|
1081
1081
|
}
|
|
1082
1082
|
}
|
|
@@ -1091,7 +1091,7 @@ exports.DefaultFilter = {
|
|
|
1091
1091
|
return {
|
|
1092
1092
|
expression: isSet(object.expression) ? globalThis.String(object.expression) : '',
|
|
1093
1093
|
scope: isSet(object.scope) ? globalThis.String(object.scope) : '',
|
|
1094
|
-
payload: isSet(object.payload) ?
|
|
1094
|
+
payload: isSet(object.payload) ? bytesFromBase64(object.payload) : undefined,
|
|
1095
1095
|
};
|
|
1096
1096
|
},
|
|
1097
1097
|
toJSON(message) {
|
|
@@ -1103,7 +1103,7 @@ exports.DefaultFilter = {
|
|
|
1103
1103
|
obj.scope = message.scope;
|
|
1104
1104
|
}
|
|
1105
1105
|
if (message.payload !== undefined) {
|
|
1106
|
-
obj.payload = message.payload;
|
|
1106
|
+
obj.payload = base64FromBytes(message.payload);
|
|
1107
1107
|
}
|
|
1108
1108
|
return obj;
|
|
1109
1109
|
},
|
package/step.js
CHANGED
|
@@ -13,7 +13,8 @@ export declare class FiltersClient {
|
|
|
13
13
|
list(opts?: {
|
|
14
14
|
limit?: number;
|
|
15
15
|
offset?: number;
|
|
16
|
-
|
|
16
|
+
workflowIds?: string[];
|
|
17
|
+
scopes?: string[];
|
|
17
18
|
}): Promise<import("../../../clients/rest/generated/data-contracts").V1FilterList>;
|
|
18
19
|
get(filterId: Parameters<typeof this.api.v1FilterGet>[1]): Promise<import("../../../clients/rest/generated/data-contracts").V1Filter>;
|
|
19
20
|
create(opts: Parameters<typeof this.api.v1FilterCreate>[1]): Promise<import("../../../clients/rest/generated/data-contracts").V1Filter>;
|
|
@@ -20,19 +20,11 @@ class FiltersClient {
|
|
|
20
20
|
}
|
|
21
21
|
list(opts) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
var _a, _b;
|
|
24
|
-
const hasWorkflowIdsAndScopes = (opts === null || opts === void 0 ? void 0 : opts.workflowIdsAndScopes) !== undefined;
|
|
25
|
-
const workflowIds = hasWorkflowIdsAndScopes
|
|
26
|
-
? (_a = opts.workflowIdsAndScopes) === null || _a === void 0 ? void 0 : _a.map((pair) => pair.workflowId)
|
|
27
|
-
: undefined;
|
|
28
|
-
const scopes = hasWorkflowIdsAndScopes
|
|
29
|
-
? (_b = opts.workflowIdsAndScopes) === null || _b === void 0 ? void 0 : _b.map((pair) => pair.scope)
|
|
30
|
-
: undefined;
|
|
31
23
|
const { data } = yield this.api.v1FilterList(this.tenantId, {
|
|
32
24
|
limit: opts === null || opts === void 0 ? void 0 : opts.limit,
|
|
33
25
|
offset: opts === null || opts === void 0 ? void 0 : opts.offset,
|
|
34
|
-
workflowIds,
|
|
35
|
-
scopes,
|
|
26
|
+
workflowIds: opts === null || opts === void 0 ? void 0 : opts.workflowIds,
|
|
27
|
+
scopes: opts === null || opts === void 0 ? void 0 : opts.scopes,
|
|
36
28
|
});
|
|
37
29
|
return data;
|
|
38
30
|
});
|
|
@@ -38,6 +38,7 @@ export declare class Context<T, K = {}> {
|
|
|
38
38
|
overridesData: Record<string, any>;
|
|
39
39
|
_logger: Logger;
|
|
40
40
|
spawnIndex: number;
|
|
41
|
+
streamIndex: number;
|
|
41
42
|
constructor(action: Action, v1: HatchetClient, worker: V1Worker);
|
|
42
43
|
get abortController(): AbortController;
|
|
43
44
|
get cancelled(): boolean;
|
|
@@ -253,6 +254,7 @@ export declare class Context<T, K = {}> {
|
|
|
253
254
|
* @deprecated Use runChild or runNoWaitChild instead.
|
|
254
255
|
*/
|
|
255
256
|
spawnWorkflow<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P> | TaskWorkflowDeclaration<Q, P>, input: Q, options?: ChildRunOpts): Promise<WorkflowRunRef<P>>;
|
|
257
|
+
_incrementStreamIndex(): number;
|
|
256
258
|
}
|
|
257
259
|
export declare class DurableContext<T, K = {}> extends Context<T, K> {
|
|
258
260
|
waitKey: number;
|
|
@@ -29,6 +29,7 @@ class Context {
|
|
|
29
29
|
this.controller = new AbortController();
|
|
30
30
|
this.overridesData = {};
|
|
31
31
|
this.spawnIndex = 0;
|
|
32
|
+
this.streamIndex = 0;
|
|
32
33
|
try {
|
|
33
34
|
const data = (0, parse_1.parseJSON)(action.actionPayload);
|
|
34
35
|
this.data = data;
|
|
@@ -282,7 +283,8 @@ class Context {
|
|
|
282
283
|
this._logger.warn('cannot log from context without stepRunId');
|
|
283
284
|
return;
|
|
284
285
|
}
|
|
285
|
-
|
|
286
|
+
const index = this._incrementStreamIndex();
|
|
287
|
+
yield this.v1._v0.event.putStream(stepRunId, data, index);
|
|
286
288
|
});
|
|
287
289
|
}
|
|
288
290
|
spawnOptions(workflow, options) {
|
|
@@ -535,6 +537,11 @@ class Context {
|
|
|
535
537
|
}
|
|
536
538
|
});
|
|
537
539
|
}
|
|
540
|
+
_incrementStreamIndex() {
|
|
541
|
+
const index = this.streamIndex;
|
|
542
|
+
this.streamIndex += 1;
|
|
543
|
+
return index;
|
|
544
|
+
}
|
|
538
545
|
}
|
|
539
546
|
exports.Context = Context;
|
|
540
547
|
class DurableContext extends Context {
|
|
@@ -93,7 +93,7 @@ class V1Worker {
|
|
|
93
93
|
}
|
|
94
94
|
registerDurableActionsV1(workflow) {
|
|
95
95
|
const newActions = workflow._durableTasks.reduce((acc, task) => {
|
|
96
|
-
acc[`${workflow.name}:${task.name.toLowerCase()}`] = (ctx) => task.fn(ctx.input, ctx);
|
|
96
|
+
acc[`${(0, apply_namespace_1.applyNamespace)(workflow.name, this.client.config.namespace).toLowerCase()}:${task.name.toLowerCase()}`] = (ctx) => task.fn(ctx.input, ctx);
|
|
97
97
|
return acc;
|
|
98
98
|
}, {});
|
|
99
99
|
this.action_registry = Object.assign(Object.assign({}, this.action_registry), newActions);
|
|
@@ -244,7 +244,7 @@ class V1Worker {
|
|
|
244
244
|
defaultFilters: (_x = (_w = workflow.defaultFilters) === null || _w === void 0 ? void 0 : _w.map((f) => ({
|
|
245
245
|
scope: f.scope,
|
|
246
246
|
expression: f.expression,
|
|
247
|
-
payload: f.payload ? JSON.stringify(f.payload) : undefined,
|
|
247
|
+
payload: f.payload ? new TextEncoder().encode(JSON.stringify(f.payload)) : undefined,
|
|
248
248
|
}))) !== null && _x !== void 0 ? _x : [],
|
|
249
249
|
});
|
|
250
250
|
this.registeredWorkflowPromises.push(registeredWorkflow);
|
|
@@ -254,12 +254,7 @@ class V1Worker {
|
|
|
254
254
|
catch (e) {
|
|
255
255
|
throw new hatchet_error_1.default(`Could not register workflow: ${e.message}`);
|
|
256
256
|
}
|
|
257
|
-
|
|
258
|
-
this.registerActionsV1(workflow);
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
this.registerDurableActionsV1(workflow);
|
|
262
|
-
}
|
|
257
|
+
this.registerActionsV1(workflow);
|
|
263
258
|
});
|
|
264
259
|
}
|
|
265
260
|
registerWorkflow(initWorkflow) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
/* eslint-disable no-console */
|
|
20
|
+
const child_listener_client_1 = require("../../../clients/listeners/run-listener/child-listener-client");
|
|
21
|
+
const workflow_1 = require("./workflow");
|
|
22
|
+
function main() {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
var _a, e_1, _b, _c;
|
|
25
|
+
// > Consume
|
|
26
|
+
const ref = yield workflow_1.streamingTask.runNoWait({});
|
|
27
|
+
const stream = yield ref.stream();
|
|
28
|
+
try {
|
|
29
|
+
for (var _d = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _a = stream_1_1.done, !_a; _d = true) {
|
|
30
|
+
_c = stream_1_1.value;
|
|
31
|
+
_d = false;
|
|
32
|
+
const event = _c;
|
|
33
|
+
if (event.type === child_listener_client_1.RunEventType.STEP_RUN_EVENT_TYPE_STREAM) {
|
|
34
|
+
process.stdout.write(event.payload);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
39
|
+
finally {
|
|
40
|
+
try {
|
|
41
|
+
if (!_d && !_a && (_b = stream_1.return)) yield _b.call(stream_1);
|
|
42
|
+
}
|
|
43
|
+
finally { if (e_1) throw e_1.error; }
|
|
44
|
+
}
|
|
45
|
+
// !!
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (require.main === module) {
|
|
49
|
+
main()
|
|
50
|
+
.catch(console.error)
|
|
51
|
+
.finally(() => {
|
|
52
|
+
process.exit(0);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
13
|
+
const workflow_1 = require("./workflow");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const worker = yield hatchet_client_1.hatchet.worker('streaming-worker', {
|
|
17
|
+
workflows: [workflow_1.streamingTask],
|
|
18
|
+
});
|
|
19
|
+
yield worker.start();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const streamingTask: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, void>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.streamingTask = void 0;
|
|
16
|
+
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
17
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
18
|
+
// > Streaming
|
|
19
|
+
const annaKarenina = `
|
|
20
|
+
Happy families are all alike; every unhappy family is unhappy in its own way.
|
|
21
|
+
|
|
22
|
+
Everything was in confusion in the Oblonskys' house. The wife had discovered that the husband was carrying on an intrigue with a French girl, who had been a governess in their family, and she had announced to her husband that she could not go on living in the same house with him.
|
|
23
|
+
`;
|
|
24
|
+
function* createChunks(content, n) {
|
|
25
|
+
for (let i = 0; i < content.length; i += n) {
|
|
26
|
+
yield content.slice(i, i + n);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.streamingTask = hatchet_client_1.hatchet.task({
|
|
30
|
+
name: 'stream-example',
|
|
31
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
for (const chunk of createChunks(annaKarenina, 10)) {
|
|
33
|
+
ctx.putStream(chunk);
|
|
34
|
+
yield (0, sleep_1.default)(200);
|
|
35
|
+
}
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
// !!
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.9.0";
|
package/version.js
CHANGED