@hatchet-dev/typescript-sdk 0.1.28 → 0.1.29
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.js +4 -2
- package/clients/hatchet-client/client-config.d.ts +3 -0
- package/clients/hatchet-client/client-config.js +1 -0
- package/clients/worker/worker.d.ts +1 -1
- package/clients/worker/worker.js +4 -3
- package/package.json +2 -1
- package/util/config-loader/config-loader.js +5 -3
|
@@ -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;
|
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hatchet-dev/typescript-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"exec": "npx dotenv -- ts-node -r tsconfig-paths/register --project tsconfig.json",
|
|
35
35
|
"example:event": "npm run exec -- ./examples/example-event.ts",
|
|
36
36
|
"example:event-listen": "npm run exec -- ./examples/example-event-with-results.ts",
|
|
37
|
+
"worker:namespaced": "npm run exec -- ./examples/namespaced-worker.ts",
|
|
37
38
|
"worker:simple": "npm run exec -- ./examples/simple-worker.ts",
|
|
38
39
|
"manual:trigger": "npm run exec -- ./examples/manual-trigger.ts",
|
|
39
40
|
"worker:dag": "npm run exec -- ./examples/dag-worker.ts",
|
|
@@ -34,7 +34,7 @@ const token_1 = require("./token");
|
|
|
34
34
|
const DEFAULT_CONFIG_FILE = '.hatchet.yaml';
|
|
35
35
|
class ConfigLoader {
|
|
36
36
|
static loadClientConfig(override, config) {
|
|
37
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
|
|
37
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
|
|
38
38
|
const yaml = this.loadYamlConfig(config === null || config === void 0 ? void 0 : config.path);
|
|
39
39
|
const tlsConfig = (_a = override === null || override === void 0 ? void 0 : override.tls_config) !== null && _a !== void 0 ? _a : {
|
|
40
40
|
tls_strategy: (_d = (_c = (_b = yaml === null || yaml === void 0 ? void 0 : yaml.tls_config) === null || _b === void 0 ? void 0 : _b.tls_strategy) !== null && _c !== void 0 ? _c : this.env('HATCHET_CLIENT_TLS_STRATEGY')) !== null && _d !== void 0 ? _d : 'tls',
|
|
@@ -64,13 +64,15 @@ class ConfigLoader {
|
|
|
64
64
|
grpcBroadcastAddress = (_v = yaml === null || yaml === void 0 ? void 0 : yaml.host_port) !== null && _v !== void 0 ? _v : this.env('HATCHET_CLIENT_HOST_PORT');
|
|
65
65
|
apiUrl = (_x = (_w = override === null || override === void 0 ? void 0 : override.api_url) !== null && _w !== void 0 ? _w : yaml === null || yaml === void 0 ? void 0 : yaml.api_url) !== null && _x !== void 0 ? _x : this.env('HATCHET_CLIENT_API_URL');
|
|
66
66
|
}
|
|
67
|
+
const namespace = (_z = (_y = override === null || override === void 0 ? void 0 : override.namespace) !== null && _y !== void 0 ? _y : yaml === null || yaml === void 0 ? void 0 : yaml.namespace) !== null && _z !== void 0 ? _z : this.env('HATCHET_CLIENT_NAMESPACE');
|
|
67
68
|
return {
|
|
68
|
-
token: (
|
|
69
|
+
token: (_1 = (_0 = override === null || override === void 0 ? void 0 : override.token) !== null && _0 !== void 0 ? _0 : yaml === null || yaml === void 0 ? void 0 : yaml.token) !== null && _1 !== void 0 ? _1 : this.env('HATCHET_CLIENT_TOKEN'),
|
|
69
70
|
host_port: grpcBroadcastAddress,
|
|
70
71
|
api_url: apiUrl,
|
|
71
72
|
tls_config: tlsConfig,
|
|
72
|
-
log_level: (
|
|
73
|
+
log_level: (_4 = (_3 = (_2 = override === null || override === void 0 ? void 0 : override.log_level) !== null && _2 !== void 0 ? _2 : yaml === null || yaml === void 0 ? void 0 : yaml.log_level) !== null && _3 !== void 0 ? _3 : this.env('HATCHET_CLIENT_LOG_LEVEL')) !== null && _4 !== void 0 ? _4 : 'INFO',
|
|
73
74
|
tenant_id: tenantId,
|
|
75
|
+
namespace: namespace ? `${namespace}_` : '',
|
|
74
76
|
};
|
|
75
77
|
}
|
|
76
78
|
static get default_yaml_config_path() {
|