@hatchet-dev/typescript-sdk 0.1.28 → 0.1.30
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 +2 -2
- package/clients/admin/admin-client.js +3 -3
- package/clients/event/event-client.js +4 -2
- package/clients/hatchet-client/client-config.d.ts +3 -0
- package/clients/hatchet-client/client-config.js +1 -0
- package/clients/hatchet-client/hatchet-client.js +1 -0
- package/clients/worker/worker.d.ts +1 -1
- package/clients/worker/worker.js +4 -3
- package/package.json +3 -3
- package/protoc/events/events.d.ts +0 -50
- package/protoc/events/events.js +1 -128
- package/protoc/workflows/workflows.d.ts +1 -227
- package/protoc/workflows/workflows.js +114 -1061
- package/util/config-loader/config-loader.js +5 -3
|
@@ -77,10 +77,10 @@ export declare class AdminClient {
|
|
|
77
77
|
}): Promise<import("../rest/generated/data-contracts").WorkflowRunList>;
|
|
78
78
|
/**
|
|
79
79
|
* Schedule a workflow to run at a specific time or times.
|
|
80
|
-
* @param
|
|
80
|
+
* @param name the name of the workflow to schedule
|
|
81
81
|
* @param options an object containing the schedules to set
|
|
82
82
|
*/
|
|
83
|
-
schedule_workflow(
|
|
83
|
+
schedule_workflow(name: string, options?: {
|
|
84
84
|
schedules?: Date[];
|
|
85
85
|
}): void;
|
|
86
86
|
}
|
|
@@ -137,13 +137,13 @@ class AdminClient {
|
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
139
|
* Schedule a workflow to run at a specific time or times.
|
|
140
|
-
* @param
|
|
140
|
+
* @param name the name of the workflow to schedule
|
|
141
141
|
* @param options an object containing the schedules to set
|
|
142
142
|
*/
|
|
143
|
-
schedule_workflow(
|
|
143
|
+
schedule_workflow(name, options) {
|
|
144
144
|
try {
|
|
145
145
|
this.client.scheduleWorkflow({
|
|
146
|
-
|
|
146
|
+
name,
|
|
147
147
|
schedules: options === null || options === void 0 ? void 0 : options.schedules,
|
|
148
148
|
});
|
|
149
149
|
}
|
|
@@ -32,14 +32,16 @@ class EventClient {
|
|
|
32
32
|
this.logger = new logger_1.Logger(`Dispatcher`, config.log_level);
|
|
33
33
|
}
|
|
34
34
|
push(type, input) {
|
|
35
|
+
var _a;
|
|
36
|
+
const namespacedType = `${(_a = this.config.namespace) !== null && _a !== void 0 ? _a : ''}${type}`;
|
|
35
37
|
const req = {
|
|
36
|
-
key:
|
|
38
|
+
key: namespacedType,
|
|
37
39
|
payload: JSON.stringify(input),
|
|
38
40
|
eventTimestamp: new Date(),
|
|
39
41
|
};
|
|
40
42
|
try {
|
|
41
43
|
const e = this.client.push(req);
|
|
42
|
-
this.logger.info(`Event pushed: ${
|
|
44
|
+
this.logger.info(`Event pushed: ${namespacedType}`);
|
|
43
45
|
return e;
|
|
44
46
|
}
|
|
45
47
|
catch (e) {
|
|
@@ -44,6 +44,7 @@ export declare const ClientConfigSchema: z.ZodObject<{
|
|
|
44
44
|
api_url: z.ZodString;
|
|
45
45
|
log_level: z.ZodOptional<z.ZodEnum<["OFF", "DEBUG", "INFO", "WARN", "ERROR"]>>;
|
|
46
46
|
tenant_id: z.ZodString;
|
|
47
|
+
namespace: z.ZodOptional<z.ZodString>;
|
|
47
48
|
}, "strip", z.ZodTypeAny, {
|
|
48
49
|
token: string;
|
|
49
50
|
tls_config: {
|
|
@@ -57,6 +58,7 @@ export declare const ClientConfigSchema: z.ZodObject<{
|
|
|
57
58
|
api_url: string;
|
|
58
59
|
tenant_id: string;
|
|
59
60
|
log_level?: "OFF" | "DEBUG" | "INFO" | "WARN" | "ERROR" | undefined;
|
|
61
|
+
namespace?: string | undefined;
|
|
60
62
|
}, {
|
|
61
63
|
token: string;
|
|
62
64
|
tls_config: {
|
|
@@ -70,6 +72,7 @@ export declare const ClientConfigSchema: z.ZodObject<{
|
|
|
70
72
|
api_url: string;
|
|
71
73
|
tenant_id: string;
|
|
72
74
|
log_level?: "OFF" | "DEBUG" | "INFO" | "WARN" | "ERROR" | undefined;
|
|
75
|
+
namespace?: string | undefined;
|
|
73
76
|
}>;
|
|
74
77
|
export type ClientConfig = z.infer<typeof ClientConfigSchema> & {
|
|
75
78
|
credentials?: ChannelCredentials;
|
|
@@ -120,6 +120,7 @@ class HatchetClient {
|
|
|
120
120
|
// @deprecated
|
|
121
121
|
run(workflow) {
|
|
122
122
|
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
this.logger.warn('HatchetClient.run is deprecated and will be removed in a future release. Use HatchetClient.worker and Worker.start instead.');
|
|
123
124
|
const worker = yield this.worker(workflow);
|
|
124
125
|
worker.start();
|
|
125
126
|
return worker;
|
|
@@ -22,7 +22,7 @@ export declare class Worker {
|
|
|
22
22
|
handleKill?: boolean;
|
|
23
23
|
maxRuns?: number;
|
|
24
24
|
});
|
|
25
|
-
registerWorkflow(
|
|
25
|
+
registerWorkflow(initWorkflow: Workflow): Promise<void>;
|
|
26
26
|
registerAction<T, K>(actionId: string, action: StepRunFunction<T, K>): void;
|
|
27
27
|
handleStartStepRun(action: Action): void;
|
|
28
28
|
handleStartGroupKeyRun(action: Action): void;
|
package/clients/worker/worker.js
CHANGED
|
@@ -32,7 +32,7 @@ class Worker {
|
|
|
32
32
|
this.futures = {};
|
|
33
33
|
this.contexts = {};
|
|
34
34
|
this.client = client;
|
|
35
|
-
this.name = options.name;
|
|
35
|
+
this.name = this.client.config.namespace + options.name;
|
|
36
36
|
this.action_registry = {};
|
|
37
37
|
this.maxRuns = options.maxRuns;
|
|
38
38
|
process.on('SIGTERM', () => this.exitGracefully(true));
|
|
@@ -41,9 +41,10 @@ class Worker {
|
|
|
41
41
|
this.handle_kill = options.handleKill === undefined ? true : options.handleKill;
|
|
42
42
|
this.logger = new logger_1.Logger(`Worker/${this.name}`, this.client.config.log_level);
|
|
43
43
|
}
|
|
44
|
-
registerWorkflow(
|
|
44
|
+
registerWorkflow(initWorkflow) {
|
|
45
45
|
var _a, _b;
|
|
46
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const workflow = Object.assign(Object.assign({}, initWorkflow), { id: this.client.config.namespace + initWorkflow.id });
|
|
47
48
|
try {
|
|
48
49
|
const concurrency = ((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.name)
|
|
49
50
|
? {
|
|
@@ -56,7 +57,7 @@ class Worker {
|
|
|
56
57
|
name: workflow.id,
|
|
57
58
|
description: workflow.description,
|
|
58
59
|
version: workflow.version || '',
|
|
59
|
-
eventTriggers: workflow.on.event ? [workflow.on.event] : [],
|
|
60
|
+
eventTriggers: workflow.on.event ? [this.client.config.namespace + workflow.on.event] : [],
|
|
60
61
|
cronTriggers: workflow.on.cron ? [workflow.on.cron] : [],
|
|
61
62
|
scheduledTriggers: [],
|
|
62
63
|
concurrency,
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hatchet-dev/typescript-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.30",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
5
|
"types": "dist/index.d.ts",
|
|
7
6
|
"files": [
|
|
8
7
|
"*",
|
|
@@ -34,6 +33,7 @@
|
|
|
34
33
|
"exec": "npx dotenv -- ts-node -r tsconfig-paths/register --project tsconfig.json",
|
|
35
34
|
"example:event": "npm run exec -- ./examples/example-event.ts",
|
|
36
35
|
"example:event-listen": "npm run exec -- ./examples/example-event-with-results.ts",
|
|
36
|
+
"worker:namespaced": "npm run exec -- ./examples/namespaced-worker.ts",
|
|
37
37
|
"worker:simple": "npm run exec -- ./examples/simple-worker.ts",
|
|
38
38
|
"manual:trigger": "npm run exec -- ./examples/manual-trigger.ts",
|
|
39
39
|
"worker:dag": "npm run exec -- ./examples/dag-worker.ts",
|
|
@@ -92,4 +92,4 @@
|
|
|
92
92
|
"yaml": "^2.3.4",
|
|
93
93
|
"zod": "^3.22.4"
|
|
94
94
|
}
|
|
95
|
-
}
|
|
95
|
+
}
|
|
@@ -35,16 +35,6 @@ export interface PushEventRequest {
|
|
|
35
35
|
/** when the event was generated */
|
|
36
36
|
eventTimestamp: Date | undefined;
|
|
37
37
|
}
|
|
38
|
-
export interface ListEventRequest {
|
|
39
|
-
/** (optional) the number of events to skip */
|
|
40
|
-
offset: number;
|
|
41
|
-
/** (optional) the key for the event */
|
|
42
|
-
key: string;
|
|
43
|
-
}
|
|
44
|
-
export interface ListEventResponse {
|
|
45
|
-
/** the events */
|
|
46
|
-
events: Event[];
|
|
47
|
-
}
|
|
48
38
|
export interface ReplayEventRequest {
|
|
49
39
|
/** the event id to replay */
|
|
50
40
|
eventId: string;
|
|
@@ -81,22 +71,6 @@ export declare const PushEventRequest: {
|
|
|
81
71
|
create(base?: DeepPartial<PushEventRequest>): PushEventRequest;
|
|
82
72
|
fromPartial(object: DeepPartial<PushEventRequest>): PushEventRequest;
|
|
83
73
|
};
|
|
84
|
-
export declare const ListEventRequest: {
|
|
85
|
-
encode(message: ListEventRequest, writer?: _m0.Writer): _m0.Writer;
|
|
86
|
-
decode(input: _m0.Reader | Uint8Array, length?: number): ListEventRequest;
|
|
87
|
-
fromJSON(object: any): ListEventRequest;
|
|
88
|
-
toJSON(message: ListEventRequest): unknown;
|
|
89
|
-
create(base?: DeepPartial<ListEventRequest>): ListEventRequest;
|
|
90
|
-
fromPartial(object: DeepPartial<ListEventRequest>): ListEventRequest;
|
|
91
|
-
};
|
|
92
|
-
export declare const ListEventResponse: {
|
|
93
|
-
encode(message: ListEventResponse, writer?: _m0.Writer): _m0.Writer;
|
|
94
|
-
decode(input: _m0.Reader | Uint8Array, length?: number): ListEventResponse;
|
|
95
|
-
fromJSON(object: any): ListEventResponse;
|
|
96
|
-
toJSON(message: ListEventResponse): unknown;
|
|
97
|
-
create(base?: DeepPartial<ListEventResponse>): ListEventResponse;
|
|
98
|
-
fromPartial(object: DeepPartial<ListEventResponse>): ListEventResponse;
|
|
99
|
-
};
|
|
100
74
|
export declare const ReplayEventRequest: {
|
|
101
75
|
encode(message: ReplayEventRequest, writer?: _m0.Writer): _m0.Writer;
|
|
102
76
|
decode(input: _m0.Reader | Uint8Array, length?: number): ReplayEventRequest;
|
|
@@ -132,28 +106,6 @@ export declare const EventsServiceDefinition: {
|
|
|
132
106
|
readonly responseStream: false;
|
|
133
107
|
readonly options: {};
|
|
134
108
|
};
|
|
135
|
-
readonly list: {
|
|
136
|
-
readonly name: "List";
|
|
137
|
-
readonly requestType: {
|
|
138
|
-
encode(message: ListEventRequest, writer?: _m0.Writer): _m0.Writer;
|
|
139
|
-
decode(input: _m0.Reader | Uint8Array, length?: number): ListEventRequest;
|
|
140
|
-
fromJSON(object: any): ListEventRequest;
|
|
141
|
-
toJSON(message: ListEventRequest): unknown;
|
|
142
|
-
create(base?: DeepPartial<ListEventRequest>): ListEventRequest;
|
|
143
|
-
fromPartial(object: DeepPartial<ListEventRequest>): ListEventRequest;
|
|
144
|
-
};
|
|
145
|
-
readonly requestStream: false;
|
|
146
|
-
readonly responseType: {
|
|
147
|
-
encode(message: ListEventResponse, writer?: _m0.Writer): _m0.Writer;
|
|
148
|
-
decode(input: _m0.Reader | Uint8Array, length?: number): ListEventResponse;
|
|
149
|
-
fromJSON(object: any): ListEventResponse;
|
|
150
|
-
toJSON(message: ListEventResponse): unknown;
|
|
151
|
-
create(base?: DeepPartial<ListEventResponse>): ListEventResponse;
|
|
152
|
-
fromPartial(object: DeepPartial<ListEventResponse>): ListEventResponse;
|
|
153
|
-
};
|
|
154
|
-
readonly responseStream: false;
|
|
155
|
-
readonly options: {};
|
|
156
|
-
};
|
|
157
109
|
readonly replaySingleEvent: {
|
|
158
110
|
readonly name: "ReplaySingleEvent";
|
|
159
111
|
readonly requestType: {
|
|
@@ -202,13 +154,11 @@ export declare const EventsServiceDefinition: {
|
|
|
202
154
|
};
|
|
203
155
|
export interface EventsServiceImplementation<CallContextExt = {}> {
|
|
204
156
|
push(request: PushEventRequest, context: CallContext & CallContextExt): Promise<DeepPartial<Event>>;
|
|
205
|
-
list(request: ListEventRequest, context: CallContext & CallContextExt): Promise<DeepPartial<ListEventResponse>>;
|
|
206
157
|
replaySingleEvent(request: ReplayEventRequest, context: CallContext & CallContextExt): Promise<DeepPartial<Event>>;
|
|
207
158
|
putLog(request: PutLogRequest, context: CallContext & CallContextExt): Promise<DeepPartial<PutLogResponse>>;
|
|
208
159
|
}
|
|
209
160
|
export interface EventsServiceClient<CallOptionsExt = {}> {
|
|
210
161
|
push(request: DeepPartial<PushEventRequest>, options?: CallOptions & CallOptionsExt): Promise<Event>;
|
|
211
|
-
list(request: DeepPartial<ListEventRequest>, options?: CallOptions & CallOptionsExt): Promise<ListEventResponse>;
|
|
212
162
|
replaySingleEvent(request: DeepPartial<ReplayEventRequest>, options?: CallOptions & CallOptionsExt): Promise<Event>;
|
|
213
163
|
putLog(request: DeepPartial<PutLogRequest>, options?: CallOptions & CallOptionsExt): Promise<PutLogResponse>;
|
|
214
164
|
}
|
package/protoc/events/events.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.EventsServiceDefinition = exports.ReplayEventRequest = exports.
|
|
26
|
+
exports.EventsServiceDefinition = exports.ReplayEventRequest = exports.PushEventRequest = exports.PutLogResponse = exports.PutLogRequest = exports.Event = exports.protobufPackage = void 0;
|
|
27
27
|
const _m0 = __importStar(require("protobufjs/minimal"));
|
|
28
28
|
const timestamp_1 = require("../google/protobuf/timestamp");
|
|
29
29
|
exports.protobufPackage = "";
|
|
@@ -363,125 +363,6 @@ exports.PushEventRequest = {
|
|
|
363
363
|
return message;
|
|
364
364
|
},
|
|
365
365
|
};
|
|
366
|
-
function createBaseListEventRequest() {
|
|
367
|
-
return { offset: 0, key: "" };
|
|
368
|
-
}
|
|
369
|
-
exports.ListEventRequest = {
|
|
370
|
-
encode(message, writer = _m0.Writer.create()) {
|
|
371
|
-
if (message.offset !== 0) {
|
|
372
|
-
writer.uint32(8).int32(message.offset);
|
|
373
|
-
}
|
|
374
|
-
if (message.key !== "") {
|
|
375
|
-
writer.uint32(18).string(message.key);
|
|
376
|
-
}
|
|
377
|
-
return writer;
|
|
378
|
-
},
|
|
379
|
-
decode(input, length) {
|
|
380
|
-
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
381
|
-
let end = length === undefined ? reader.len : reader.pos + length;
|
|
382
|
-
const message = createBaseListEventRequest();
|
|
383
|
-
while (reader.pos < end) {
|
|
384
|
-
const tag = reader.uint32();
|
|
385
|
-
switch (tag >>> 3) {
|
|
386
|
-
case 1:
|
|
387
|
-
if (tag !== 8) {
|
|
388
|
-
break;
|
|
389
|
-
}
|
|
390
|
-
message.offset = reader.int32();
|
|
391
|
-
continue;
|
|
392
|
-
case 2:
|
|
393
|
-
if (tag !== 18) {
|
|
394
|
-
break;
|
|
395
|
-
}
|
|
396
|
-
message.key = reader.string();
|
|
397
|
-
continue;
|
|
398
|
-
}
|
|
399
|
-
if ((tag & 7) === 4 || tag === 0) {
|
|
400
|
-
break;
|
|
401
|
-
}
|
|
402
|
-
reader.skipType(tag & 7);
|
|
403
|
-
}
|
|
404
|
-
return message;
|
|
405
|
-
},
|
|
406
|
-
fromJSON(object) {
|
|
407
|
-
return {
|
|
408
|
-
offset: isSet(object.offset) ? globalThis.Number(object.offset) : 0,
|
|
409
|
-
key: isSet(object.key) ? globalThis.String(object.key) : "",
|
|
410
|
-
};
|
|
411
|
-
},
|
|
412
|
-
toJSON(message) {
|
|
413
|
-
const obj = {};
|
|
414
|
-
if (message.offset !== 0) {
|
|
415
|
-
obj.offset = Math.round(message.offset);
|
|
416
|
-
}
|
|
417
|
-
if (message.key !== "") {
|
|
418
|
-
obj.key = message.key;
|
|
419
|
-
}
|
|
420
|
-
return obj;
|
|
421
|
-
},
|
|
422
|
-
create(base) {
|
|
423
|
-
return exports.ListEventRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
424
|
-
},
|
|
425
|
-
fromPartial(object) {
|
|
426
|
-
var _a, _b;
|
|
427
|
-
const message = createBaseListEventRequest();
|
|
428
|
-
message.offset = (_a = object.offset) !== null && _a !== void 0 ? _a : 0;
|
|
429
|
-
message.key = (_b = object.key) !== null && _b !== void 0 ? _b : "";
|
|
430
|
-
return message;
|
|
431
|
-
},
|
|
432
|
-
};
|
|
433
|
-
function createBaseListEventResponse() {
|
|
434
|
-
return { events: [] };
|
|
435
|
-
}
|
|
436
|
-
exports.ListEventResponse = {
|
|
437
|
-
encode(message, writer = _m0.Writer.create()) {
|
|
438
|
-
for (const v of message.events) {
|
|
439
|
-
exports.Event.encode(v, writer.uint32(10).fork()).ldelim();
|
|
440
|
-
}
|
|
441
|
-
return writer;
|
|
442
|
-
},
|
|
443
|
-
decode(input, length) {
|
|
444
|
-
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
445
|
-
let end = length === undefined ? reader.len : reader.pos + length;
|
|
446
|
-
const message = createBaseListEventResponse();
|
|
447
|
-
while (reader.pos < end) {
|
|
448
|
-
const tag = reader.uint32();
|
|
449
|
-
switch (tag >>> 3) {
|
|
450
|
-
case 1:
|
|
451
|
-
if (tag !== 10) {
|
|
452
|
-
break;
|
|
453
|
-
}
|
|
454
|
-
message.events.push(exports.Event.decode(reader, reader.uint32()));
|
|
455
|
-
continue;
|
|
456
|
-
}
|
|
457
|
-
if ((tag & 7) === 4 || tag === 0) {
|
|
458
|
-
break;
|
|
459
|
-
}
|
|
460
|
-
reader.skipType(tag & 7);
|
|
461
|
-
}
|
|
462
|
-
return message;
|
|
463
|
-
},
|
|
464
|
-
fromJSON(object) {
|
|
465
|
-
return { events: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.events) ? object.events.map((e) => exports.Event.fromJSON(e)) : [] };
|
|
466
|
-
},
|
|
467
|
-
toJSON(message) {
|
|
468
|
-
var _a;
|
|
469
|
-
const obj = {};
|
|
470
|
-
if ((_a = message.events) === null || _a === void 0 ? void 0 : _a.length) {
|
|
471
|
-
obj.events = message.events.map((e) => exports.Event.toJSON(e));
|
|
472
|
-
}
|
|
473
|
-
return obj;
|
|
474
|
-
},
|
|
475
|
-
create(base) {
|
|
476
|
-
return exports.ListEventResponse.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
477
|
-
},
|
|
478
|
-
fromPartial(object) {
|
|
479
|
-
var _a;
|
|
480
|
-
const message = createBaseListEventResponse();
|
|
481
|
-
message.events = ((_a = object.events) === null || _a === void 0 ? void 0 : _a.map((e) => exports.Event.fromPartial(e))) || [];
|
|
482
|
-
return message;
|
|
483
|
-
},
|
|
484
|
-
};
|
|
485
366
|
function createBaseReplayEventRequest() {
|
|
486
367
|
return { eventId: "" };
|
|
487
368
|
}
|
|
@@ -545,14 +426,6 @@ exports.EventsServiceDefinition = {
|
|
|
545
426
|
responseStream: false,
|
|
546
427
|
options: {},
|
|
547
428
|
},
|
|
548
|
-
list: {
|
|
549
|
-
name: "List",
|
|
550
|
-
requestType: exports.ListEventRequest,
|
|
551
|
-
requestStream: false,
|
|
552
|
-
responseType: exports.ListEventResponse,
|
|
553
|
-
responseStream: false,
|
|
554
|
-
options: {},
|
|
555
|
-
},
|
|
556
429
|
replaySingleEvent: {
|
|
557
430
|
name: "ReplaySingleEvent",
|
|
558
431
|
requestType: exports.ReplayEventRequest,
|