@hatchet-dev/typescript-sdk 0.1.1 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/clients/admin/admin-client.d.ts +12 -0
- package/clients/admin/admin-client.js +47 -0
- package/clients/dispatcher/action-listener.d.ts +26 -0
- package/clients/dispatcher/action-listener.js +113 -0
- package/clients/dispatcher/dispatcher-client.d.ts +20 -0
- package/clients/dispatcher/dispatcher-client.js +58 -0
- package/clients/event/event-client.d.ts +11 -0
- package/clients/event/event-client.js +32 -0
- package/clients/hatchet-client/client-config.d.ts +72 -0
- package/clients/hatchet-client/client-config.js +17 -0
- package/clients/hatchet-client/hatchet-client.d.ts +26 -0
- package/clients/hatchet-client/hatchet-client.js +133 -0
- package/clients/hatchet-client/index.d.ts +2 -0
- package/clients/hatchet-client/index.js +18 -0
- package/clients/worker/index.d.ts +1 -0
- package/clients/worker/index.js +17 -0
- package/clients/worker/worker.d.ts +34 -0
- package/clients/worker/worker.js +317 -0
- package/index.d.ts +2 -0
- package/index.js +4 -0
- package/package.json +3 -2
- package/protoc/dispatcher/dispatcher.d.ts +333 -0
- package/protoc/dispatcher/dispatcher.js +1152 -0
- package/protoc/dispatcher/index.d.ts +1 -0
- package/protoc/dispatcher/index.js +17 -0
- package/protoc/events/events.d.ts +165 -0
- package/protoc/events/events.js +443 -0
- package/protoc/events/index.d.ts +1 -0
- package/protoc/events/index.js +17 -0
- package/protoc/google/protobuf/timestamp.d.ts +121 -0
- package/protoc/google/protobuf/timestamp.js +110 -0
- package/protoc/google/protobuf/wrappers.d.ts +160 -0
- package/protoc/google/protobuf/wrappers.js +527 -0
- package/protoc/workflows/index.d.ts +1 -0
- package/protoc/workflows/index.js +17 -0
- package/protoc/workflows/workflows.d.ts +464 -0
- package/protoc/workflows/workflows.js +1951 -0
- package/sdk.d.ts +2 -0
- package/sdk.js +4 -0
- package/step.d.ts +33 -0
- package/step.js +65 -0
- package/util/config-loader/config-loader.d.ts +13 -0
- package/util/config-loader/config-loader.js +85 -0
- package/util/config-loader/index.d.ts +1 -0
- package/util/config-loader/index.js +17 -0
- package/util/errors/hatchet-error.d.ts +4 -0
- package/util/errors/hatchet-error.js +9 -0
- package/util/hatchet-promise/hatchet-promise.d.ts +6 -0
- package/util/hatchet-promise/hatchet-promise.js +12 -0
- package/util/logger/index.d.ts +1 -0
- package/util/logger/index.js +17 -0
- package/util/logger/logger.d.ts +12 -0
- package/util/logger/logger.js +37 -0
- package/util/sleep.d.ts +2 -0
- package/util/sleep.js +6 -0
- package/workflow.d.ts +111 -0
- package/workflow.js +54 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Channel, ClientFactory } from 'nice-grpc';
|
|
2
|
+
import { CreateWorkflowVersionOpts, WorkflowServiceClient } from '../../../../src/protoc/workflows';
|
|
3
|
+
import { ClientConfig } from '../../../../src/clients/hatchet-client/client-config';
|
|
4
|
+
export declare class AdminClient {
|
|
5
|
+
config: ClientConfig;
|
|
6
|
+
client: WorkflowServiceClient;
|
|
7
|
+
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory);
|
|
8
|
+
put_workflow(workflow: CreateWorkflowVersionOpts): Promise<void>;
|
|
9
|
+
schedule_workflow(workflowId: string, options?: {
|
|
10
|
+
schedules?: Date[];
|
|
11
|
+
}): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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.AdminClient = void 0;
|
|
16
|
+
const workflows_1 = require("../../../../src/protoc/workflows");
|
|
17
|
+
const hatchet_error_1 = __importDefault(require("../../../../src/util/errors/hatchet-error"));
|
|
18
|
+
class AdminClient {
|
|
19
|
+
constructor(config, channel, factory) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
this.client = factory.create(workflows_1.WorkflowServiceDefinition, channel);
|
|
22
|
+
}
|
|
23
|
+
put_workflow(workflow) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
try {
|
|
26
|
+
yield this.client.putWorkflow({
|
|
27
|
+
opts: workflow,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
throw new hatchet_error_1.default(e.message);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
schedule_workflow(workflowId, options) {
|
|
36
|
+
try {
|
|
37
|
+
this.client.scheduleWorkflow({
|
|
38
|
+
workflowId,
|
|
39
|
+
schedules: options === null || options === void 0 ? void 0 : options.schedules,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
throw new hatchet_error_1.default(e.message);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.AdminClient = AdminClient;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DispatcherClient as PbDispatcherClient, AssignedAction } from '../../../../src/protoc/dispatcher';
|
|
2
|
+
import { ClientConfig } from '../../../../src/clients/hatchet-client/client-config';
|
|
3
|
+
import { DispatcherClient } from './dispatcher-client';
|
|
4
|
+
export interface Action {
|
|
5
|
+
tenantId: string;
|
|
6
|
+
jobId: string;
|
|
7
|
+
jobName: string;
|
|
8
|
+
jobRunId: string;
|
|
9
|
+
stepId: string;
|
|
10
|
+
stepRunId: string;
|
|
11
|
+
actionId: string;
|
|
12
|
+
actionType: number;
|
|
13
|
+
actionPayload: string;
|
|
14
|
+
workflowRunId: string;
|
|
15
|
+
getGroupKeyRunId: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class ActionListener {
|
|
18
|
+
config: ClientConfig;
|
|
19
|
+
client: PbDispatcherClient;
|
|
20
|
+
listener: AsyncIterable<AssignedAction>;
|
|
21
|
+
workerId: string;
|
|
22
|
+
constructor(client: DispatcherClient, listener: AsyncIterable<AssignedAction>, workerId: string);
|
|
23
|
+
actions: () => AsyncGenerator<Action, void, unknown>;
|
|
24
|
+
retrySubscribe(): Promise<void>;
|
|
25
|
+
unregister(): Promise<import("../../../../src/protoc/dispatcher").WorkerUnsubscribeResponse>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
19
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
20
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
21
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
22
|
+
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
23
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
24
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
25
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
26
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
27
|
+
function fulfill(value) { resume("next", value); }
|
|
28
|
+
function reject(value) { resume("throw", value); }
|
|
29
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
30
|
+
};
|
|
31
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
32
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.ActionListener = void 0;
|
|
36
|
+
const nice_grpc_1 = require("nice-grpc");
|
|
37
|
+
const sleep_1 = __importDefault(require("../../../../src/util/sleep"));
|
|
38
|
+
const hatchet_error_1 = __importDefault(require("../../../../src/util/errors/hatchet-error"));
|
|
39
|
+
const DEFAULT_ACTION_LISTENER_RETRY_INTERVAL = 5; // seconds
|
|
40
|
+
const DEFAULT_ACTION_LISTENER_RETRY_COUNT = 5;
|
|
41
|
+
class ActionListener {
|
|
42
|
+
constructor(client, listener, workerId) {
|
|
43
|
+
this.actions = () => (function gen(client) {
|
|
44
|
+
return __asyncGenerator(this, arguments, function* gen_1() {
|
|
45
|
+
var _a, e_1, _b, _c;
|
|
46
|
+
while (true) {
|
|
47
|
+
try {
|
|
48
|
+
try {
|
|
49
|
+
for (var _d = true, _e = (e_1 = void 0, __asyncValues(client.listener)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
|
|
50
|
+
_c = _f.value;
|
|
51
|
+
_d = false;
|
|
52
|
+
const assignedAction = _c;
|
|
53
|
+
const action = Object.assign({}, assignedAction);
|
|
54
|
+
yield yield __await(action);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
58
|
+
finally {
|
|
59
|
+
try {
|
|
60
|
+
if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
|
|
61
|
+
}
|
|
62
|
+
finally { if (e_1) throw e_1.error; }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
if (e.code === nice_grpc_1.Status.CANCELLED) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
if (e.code === nice_grpc_1.Status.UNAVAILABLE) {
|
|
70
|
+
client.retrySubscribe();
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
})(this);
|
|
77
|
+
this.config = client.config;
|
|
78
|
+
this.client = client.client;
|
|
79
|
+
this.listener = listener;
|
|
80
|
+
this.workerId = workerId;
|
|
81
|
+
}
|
|
82
|
+
retrySubscribe() {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
let retries = 0;
|
|
85
|
+
while (retries < DEFAULT_ACTION_LISTENER_RETRY_COUNT) {
|
|
86
|
+
try {
|
|
87
|
+
yield (0, sleep_1.default)(DEFAULT_ACTION_LISTENER_RETRY_INTERVAL);
|
|
88
|
+
this.listener = this.client.listen({
|
|
89
|
+
workerId: this.workerId,
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
retries += 1;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
throw new hatchet_error_1.default(`Could not subscribe to the worker after ${DEFAULT_ACTION_LISTENER_RETRY_COUNT} retries`);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
unregister() {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
try {
|
|
103
|
+
return this.client.unsubscribe({
|
|
104
|
+
workerId: this.workerId,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
throw new hatchet_error_1.default(`Failed to unsubscribe: ${e.message}`);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.ActionListener = ActionListener;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Channel, ClientFactory } from 'nice-grpc';
|
|
2
|
+
import { DispatcherClient as PbDispatcherClient, StepActionEvent, GroupKeyActionEvent } from '../../../../src/protoc/dispatcher';
|
|
3
|
+
import { ClientConfig } from '../../../../src/clients/hatchet-client/client-config';
|
|
4
|
+
import { Logger } from '../../../../src/util/logger';
|
|
5
|
+
import { ActionListener } from './action-listener';
|
|
6
|
+
interface GetActionListenerOptions {
|
|
7
|
+
workerName: string;
|
|
8
|
+
services: string[];
|
|
9
|
+
actions: string[];
|
|
10
|
+
}
|
|
11
|
+
export declare class DispatcherClient {
|
|
12
|
+
config: ClientConfig;
|
|
13
|
+
client: PbDispatcherClient;
|
|
14
|
+
logger: Logger;
|
|
15
|
+
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory);
|
|
16
|
+
getActionListener(options: GetActionListenerOptions): Promise<ActionListener>;
|
|
17
|
+
sendStepActionEvent(in_: StepActionEvent): Promise<import("../../../../src/protoc/dispatcher").ActionEventResponse>;
|
|
18
|
+
sendGroupKeyActionEvent(in_: GroupKeyActionEvent): Promise<import("../../../../src/protoc/dispatcher").ActionEventResponse>;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
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.DispatcherClient = void 0;
|
|
16
|
+
const dispatcher_1 = require("../../../../src/protoc/dispatcher");
|
|
17
|
+
const hatchet_error_1 = __importDefault(require("../../../../src/util/errors/hatchet-error"));
|
|
18
|
+
const logger_1 = require("../../../../src/util/logger");
|
|
19
|
+
const action_listener_1 = require("./action-listener");
|
|
20
|
+
class DispatcherClient {
|
|
21
|
+
constructor(config, channel, factory) {
|
|
22
|
+
this.config = config;
|
|
23
|
+
this.client = factory.create(dispatcher_1.DispatcherDefinition, channel);
|
|
24
|
+
this.logger = new logger_1.Logger(`Dispatcher`, config.log_level);
|
|
25
|
+
}
|
|
26
|
+
getActionListener(options) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
// Register the worker
|
|
29
|
+
const registration = yield this.client.register(Object.assign({}, options));
|
|
30
|
+
// Subscribe to the worker
|
|
31
|
+
const listener = this.client.listen({
|
|
32
|
+
workerId: registration.workerId,
|
|
33
|
+
});
|
|
34
|
+
return new action_listener_1.ActionListener(this, listener, registration.workerId);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
sendStepActionEvent(in_) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
try {
|
|
40
|
+
return this.client.sendStepActionEvent(in_);
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
throw new hatchet_error_1.default(e.message);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
sendGroupKeyActionEvent(in_) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
try {
|
|
50
|
+
return this.client.sendGroupKeyActionEvent(in_);
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
throw new hatchet_error_1.default(e.message);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.DispatcherClient = DispatcherClient;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Channel, ClientFactory } from 'nice-grpc';
|
|
2
|
+
import { EventsServiceClient } from '../../../../src/protoc/events/events';
|
|
3
|
+
import { ClientConfig } from '../../../../src/clients/hatchet-client/client-config';
|
|
4
|
+
import { Logger } from '../../../../src/util/logger';
|
|
5
|
+
export declare class EventClient {
|
|
6
|
+
config: ClientConfig;
|
|
7
|
+
client: EventsServiceClient;
|
|
8
|
+
logger: Logger;
|
|
9
|
+
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory);
|
|
10
|
+
push<T>(type: string, input: T): Promise<import("../../../../src/protoc/events/events").Event>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.EventClient = void 0;
|
|
7
|
+
const events_1 = require("../../../../src/protoc/events/events");
|
|
8
|
+
const hatchet_error_1 = __importDefault(require("../../../../src/util/errors/hatchet-error"));
|
|
9
|
+
const logger_1 = require("../../../../src/util/logger");
|
|
10
|
+
class EventClient {
|
|
11
|
+
constructor(config, channel, factory) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
this.client = factory.create(events_1.EventsServiceDefinition, channel);
|
|
14
|
+
this.logger = new logger_1.Logger(`Dispatcher`, config.log_level);
|
|
15
|
+
}
|
|
16
|
+
push(type, input) {
|
|
17
|
+
const req = {
|
|
18
|
+
key: type,
|
|
19
|
+
payload: JSON.stringify(input),
|
|
20
|
+
eventTimestamp: new Date(),
|
|
21
|
+
};
|
|
22
|
+
try {
|
|
23
|
+
const e = this.client.push(req);
|
|
24
|
+
this.logger.info(`Event pushed: ${type}`);
|
|
25
|
+
return e;
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
throw new hatchet_error_1.default(e.message);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.EventClient = EventClient;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ChannelCredentials } from 'nice-grpc';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
declare const ClientTLSConfigSchema: z.ZodObject<{
|
|
4
|
+
tls_strategy: z.ZodOptional<z.ZodEnum<["tls", "mtls"]>>;
|
|
5
|
+
cert_file: z.ZodOptional<z.ZodString>;
|
|
6
|
+
ca_file: z.ZodOptional<z.ZodString>;
|
|
7
|
+
key_file: z.ZodOptional<z.ZodString>;
|
|
8
|
+
server_name: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
tls_strategy?: "tls" | "mtls" | undefined;
|
|
11
|
+
cert_file?: string | undefined;
|
|
12
|
+
ca_file?: string | undefined;
|
|
13
|
+
key_file?: string | undefined;
|
|
14
|
+
server_name?: string | undefined;
|
|
15
|
+
}, {
|
|
16
|
+
tls_strategy?: "tls" | "mtls" | undefined;
|
|
17
|
+
cert_file?: string | undefined;
|
|
18
|
+
ca_file?: string | undefined;
|
|
19
|
+
key_file?: string | undefined;
|
|
20
|
+
server_name?: string | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
export declare const ClientConfigSchema: z.ZodObject<{
|
|
23
|
+
token: z.ZodString;
|
|
24
|
+
tls_config: z.ZodObject<{
|
|
25
|
+
tls_strategy: z.ZodOptional<z.ZodEnum<["tls", "mtls"]>>;
|
|
26
|
+
cert_file: z.ZodOptional<z.ZodString>;
|
|
27
|
+
ca_file: z.ZodOptional<z.ZodString>;
|
|
28
|
+
key_file: z.ZodOptional<z.ZodString>;
|
|
29
|
+
server_name: z.ZodOptional<z.ZodString>;
|
|
30
|
+
}, "strip", z.ZodTypeAny, {
|
|
31
|
+
tls_strategy?: "tls" | "mtls" | undefined;
|
|
32
|
+
cert_file?: string | undefined;
|
|
33
|
+
ca_file?: string | undefined;
|
|
34
|
+
key_file?: string | undefined;
|
|
35
|
+
server_name?: string | undefined;
|
|
36
|
+
}, {
|
|
37
|
+
tls_strategy?: "tls" | "mtls" | undefined;
|
|
38
|
+
cert_file?: string | undefined;
|
|
39
|
+
ca_file?: string | undefined;
|
|
40
|
+
key_file?: string | undefined;
|
|
41
|
+
server_name?: string | undefined;
|
|
42
|
+
}>;
|
|
43
|
+
host_port: z.ZodString;
|
|
44
|
+
log_level: z.ZodOptional<z.ZodEnum<["OFF", "DEBUG", "INFO", "WARN", "ERROR"]>>;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
token: string;
|
|
47
|
+
tls_config: {
|
|
48
|
+
tls_strategy?: "tls" | "mtls" | undefined;
|
|
49
|
+
cert_file?: string | undefined;
|
|
50
|
+
ca_file?: string | undefined;
|
|
51
|
+
key_file?: string | undefined;
|
|
52
|
+
server_name?: string | undefined;
|
|
53
|
+
};
|
|
54
|
+
host_port: string;
|
|
55
|
+
log_level?: "OFF" | "DEBUG" | "INFO" | "WARN" | "ERROR" | undefined;
|
|
56
|
+
}, {
|
|
57
|
+
token: string;
|
|
58
|
+
tls_config: {
|
|
59
|
+
tls_strategy?: "tls" | "mtls" | undefined;
|
|
60
|
+
cert_file?: string | undefined;
|
|
61
|
+
ca_file?: string | undefined;
|
|
62
|
+
key_file?: string | undefined;
|
|
63
|
+
server_name?: string | undefined;
|
|
64
|
+
};
|
|
65
|
+
host_port: string;
|
|
66
|
+
log_level?: "OFF" | "DEBUG" | "INFO" | "WARN" | "ERROR" | undefined;
|
|
67
|
+
}>;
|
|
68
|
+
export type ClientConfig = z.infer<typeof ClientConfigSchema> & {
|
|
69
|
+
credentials?: ChannelCredentials;
|
|
70
|
+
};
|
|
71
|
+
export type ClientTLSConfig = z.infer<typeof ClientTLSConfigSchema>;
|
|
72
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientConfigSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const ClientTLSConfigSchema = zod_1.z.object({
|
|
6
|
+
tls_strategy: zod_1.z.enum(['tls', 'mtls']).optional(),
|
|
7
|
+
cert_file: zod_1.z.string().optional(),
|
|
8
|
+
ca_file: zod_1.z.string().optional(),
|
|
9
|
+
key_file: zod_1.z.string().optional(),
|
|
10
|
+
server_name: zod_1.z.string().optional(),
|
|
11
|
+
});
|
|
12
|
+
exports.ClientConfigSchema = zod_1.z.object({
|
|
13
|
+
token: zod_1.z.string(),
|
|
14
|
+
tls_config: ClientTLSConfigSchema,
|
|
15
|
+
host_port: zod_1.z.string(),
|
|
16
|
+
log_level: zod_1.z.enum(['OFF', 'DEBUG', 'INFO', 'WARN', 'ERROR']).optional(),
|
|
17
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EventClient } from '../../../../src/clients/event/event-client';
|
|
2
|
+
import { DispatcherClient } from '../../../../src/clients/dispatcher/dispatcher-client';
|
|
3
|
+
import { AdminClient } from '../../../../src/clients/admin/admin-client';
|
|
4
|
+
import { Channel, ChannelCredentials } from 'nice-grpc';
|
|
5
|
+
import { Workflow } from '../../../../src/workflow';
|
|
6
|
+
import { Worker } from '../../../../src/clients/worker';
|
|
7
|
+
import Logger from '../../../../src/util/logger/logger';
|
|
8
|
+
import { ClientConfig } from './client-config';
|
|
9
|
+
export interface HatchetClientOptions {
|
|
10
|
+
config_path?: string;
|
|
11
|
+
credentials?: ChannelCredentials;
|
|
12
|
+
}
|
|
13
|
+
export declare class HatchetClient {
|
|
14
|
+
config: ClientConfig;
|
|
15
|
+
credentials: ChannelCredentials;
|
|
16
|
+
channel: Channel;
|
|
17
|
+
event: EventClient;
|
|
18
|
+
dispatcher: DispatcherClient;
|
|
19
|
+
admin: AdminClient;
|
|
20
|
+
logger: Logger;
|
|
21
|
+
constructor(config?: Partial<ClientConfig>, options?: HatchetClientOptions);
|
|
22
|
+
static with_host_port(host: string, port: number, config?: Partial<ClientConfig>, options?: HatchetClientOptions): HatchetClient;
|
|
23
|
+
static init(config?: Partial<ClientConfig>, options?: HatchetClientOptions): HatchetClient;
|
|
24
|
+
run(workflow: string | Workflow): Promise<Worker>;
|
|
25
|
+
worker(workflow: string | Workflow): Promise<Worker>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
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
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
19
|
+
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
|
|
20
|
+
var i, p;
|
|
21
|
+
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
22
|
+
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
|
|
23
|
+
};
|
|
24
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
25
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
26
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
27
|
+
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
28
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
29
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
30
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
31
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
32
|
+
function fulfill(value) { resume("next", value); }
|
|
33
|
+
function reject(value) { resume("throw", value); }
|
|
34
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
35
|
+
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.HatchetClient = void 0;
|
|
41
|
+
const zod_1 = require("zod");
|
|
42
|
+
const config_loader_1 = require("../../../../src/util/config-loader");
|
|
43
|
+
const event_client_1 = require("../../../../src/clients/event/event-client");
|
|
44
|
+
const dispatcher_client_1 = require("../../../../src/clients/dispatcher/dispatcher-client");
|
|
45
|
+
const admin_client_1 = require("../../../../src/clients/admin/admin-client");
|
|
46
|
+
const nice_grpc_1 = require("nice-grpc");
|
|
47
|
+
const worker_1 = require("../../../../src/clients/worker");
|
|
48
|
+
const logger_1 = __importDefault(require("../../../../src/util/logger/logger"));
|
|
49
|
+
const client_config_1 = require("./client-config");
|
|
50
|
+
const addTokenMiddleware = (token) => function _(call, options) {
|
|
51
|
+
return __asyncGenerator(this, arguments, function* _1() {
|
|
52
|
+
var _a, e_1, _b, _c;
|
|
53
|
+
const optionsWithAuth = Object.assign(Object.assign({}, options), { metadata: new nice_grpc_1.Metadata({ authorization: `bearer ${token}` }) });
|
|
54
|
+
if (!call.responseStream) {
|
|
55
|
+
const response = yield __await(yield* __asyncDelegator(__asyncValues(call.next(call.request, optionsWithAuth))));
|
|
56
|
+
return yield __await(response);
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
for (var _d = true, _e = __asyncValues(call.next(call.request, optionsWithAuth)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
|
|
60
|
+
_c = _f.value;
|
|
61
|
+
_d = false;
|
|
62
|
+
const response = _c;
|
|
63
|
+
yield yield __await(response);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
67
|
+
finally {
|
|
68
|
+
try {
|
|
69
|
+
if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
|
|
70
|
+
}
|
|
71
|
+
finally { if (e_1) throw e_1.error; }
|
|
72
|
+
}
|
|
73
|
+
return yield __await(undefined);
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
class HatchetClient {
|
|
77
|
+
constructor(config, options) {
|
|
78
|
+
// Initializes a new Client instance.
|
|
79
|
+
// Loads config in the following order: config param > yaml file > env vars
|
|
80
|
+
var _a;
|
|
81
|
+
const loaded = config_loader_1.ConfigLoader.load_client_config({
|
|
82
|
+
path: options === null || options === void 0 ? void 0 : options.config_path,
|
|
83
|
+
});
|
|
84
|
+
try {
|
|
85
|
+
const valid = client_config_1.ClientConfigSchema.parse(Object.assign(Object.assign({}, loaded), Object.assign(Object.assign({}, config), { tls_config: Object.assign(Object.assign({}, loaded.tls_config), config === null || config === void 0 ? void 0 : config.tls_config) })));
|
|
86
|
+
this.config = valid;
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
if (e instanceof zod_1.z.ZodError) {
|
|
90
|
+
throw new Error(`Invalid client config: ${e.message}`);
|
|
91
|
+
}
|
|
92
|
+
throw e;
|
|
93
|
+
}
|
|
94
|
+
this.credentials =
|
|
95
|
+
(_a = options === null || options === void 0 ? void 0 : options.credentials) !== null && _a !== void 0 ? _a : config_loader_1.ConfigLoader.createCredentials(this.config.tls_config);
|
|
96
|
+
this.channel = (0, nice_grpc_1.createChannel)(this.config.host_port, this.credentials, {
|
|
97
|
+
'grpc.ssl_target_name_override': this.config.tls_config.server_name,
|
|
98
|
+
});
|
|
99
|
+
const clientFactory = (0, nice_grpc_1.createClientFactory)().use(addTokenMiddleware(this.config.token));
|
|
100
|
+
this.event = new event_client_1.EventClient(this.config, this.channel, clientFactory);
|
|
101
|
+
this.dispatcher = new dispatcher_client_1.DispatcherClient(this.config, this.channel, clientFactory);
|
|
102
|
+
this.admin = new admin_client_1.AdminClient(this.config, this.channel, clientFactory);
|
|
103
|
+
this.logger = new logger_1.default('HatchetClient', this.config.log_level);
|
|
104
|
+
this.logger.info(`Initialized HatchetClient`);
|
|
105
|
+
}
|
|
106
|
+
static with_host_port(host, port, config, options) {
|
|
107
|
+
return new HatchetClient(Object.assign(Object.assign({}, config), { host_port: `${host}:${port}` }), options);
|
|
108
|
+
}
|
|
109
|
+
static init(config, options) {
|
|
110
|
+
return new HatchetClient(config, options);
|
|
111
|
+
}
|
|
112
|
+
run(workflow) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
const worker = yield this.worker(workflow);
|
|
115
|
+
worker.start();
|
|
116
|
+
return worker;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
worker(workflow) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
const name = typeof workflow === 'string' ? workflow : workflow.id;
|
|
122
|
+
const worker = new worker_1.Worker(this, {
|
|
123
|
+
name,
|
|
124
|
+
});
|
|
125
|
+
if (typeof workflow !== 'string') {
|
|
126
|
+
yield worker.registerWorkflow(workflow);
|
|
127
|
+
return worker;
|
|
128
|
+
}
|
|
129
|
+
return worker;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.HatchetClient = HatchetClient;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./hatchet-client"), exports);
|
|
18
|
+
__exportStar(require("./client-config"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './worker';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./worker"), exports);
|