@hatchet-dev/typescript-sdk 1.29.0 → 1.29.1
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/package.json +1 -1
- package/v1/embedded.d.ts +16 -5
- package/v1/embedded.js +42 -17
- package/v1/examples/embedded/worker.d.ts +2 -0
- package/v1/examples/embedded/worker.js +76 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/package.json
CHANGED
package/v1/embedded.d.ts
CHANGED
|
@@ -39,11 +39,13 @@ export interface EmbeddedSidecar {
|
|
|
39
39
|
stop: () => Promise<void>;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
42
|
+
* Gracefully stops every sidecar started in this process by
|
|
43
|
+
* `HatchetEmbeddedClient.init()` (or `startEmbeddedSidecar`) and resolves once
|
|
44
|
+
* they have fully exited, including their bundled Postgres. Call this before
|
|
45
|
+
* your process exits so the engine's shutdown output does not print after
|
|
46
|
+
* your program has returned.
|
|
46
47
|
*/
|
|
48
|
+
export declare function stopEmbeddedSidecar(): Promise<void>;
|
|
47
49
|
export declare function startEmbeddedSidecar(opts?: EmbeddedOptions): Promise<EmbeddedSidecar>;
|
|
48
50
|
export declare class HatchetEmbeddedClient {
|
|
49
51
|
/**
|
|
@@ -56,5 +58,14 @@ export declare class HatchetEmbeddedClient {
|
|
|
56
58
|
* @param axiosConfig - Optional Axios configuration for HTTP requests.
|
|
57
59
|
* @returns A new Hatchet client instance connected to the embedded engine.
|
|
58
60
|
*/
|
|
59
|
-
static init<T extends Record<string, any> = {}, U extends Record<string, any> = {}>(embeddedOpts?: EmbeddedOptions, config?: Omit<Partial<ClientConfig>, 'middleware'>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): Promise<
|
|
61
|
+
static init<T extends Record<string, any> = {}, U extends Record<string, any> = {}>(embeddedOpts?: EmbeddedOptions, config?: Omit<Partial<ClientConfig>, 'middleware'>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): Promise<EmbeddedClient<T, U>>;
|
|
60
62
|
}
|
|
63
|
+
export type EmbeddedClient<T extends Record<string, any> = {}, U extends Record<string, any> = {}> = HatchetClient<T, U> & {
|
|
64
|
+
/**
|
|
65
|
+
* Gracefully stops the embedded engine sidecar and resolves once it has
|
|
66
|
+
* fully exited, including its bundled Postgres. Call this before your
|
|
67
|
+
* process exits so the engine's shutdown output does not print after your
|
|
68
|
+
* program has returned.
|
|
69
|
+
*/
|
|
70
|
+
stopEmbedded: () => Promise<void>;
|
|
71
|
+
};
|
package/v1/embedded.js
CHANGED
|
@@ -50,6 +50,7 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
50
50
|
};
|
|
51
51
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
52
|
exports.HatchetEmbeddedClient = void 0;
|
|
53
|
+
exports.stopEmbeddedSidecar = stopEmbeddedSidecar;
|
|
53
54
|
exports.startEmbeddedSidecar = startEmbeddedSidecar;
|
|
54
55
|
const child_process_1 = require("child_process");
|
|
55
56
|
const client_1 = require("./client/client");
|
|
@@ -216,6 +217,21 @@ function waitForHandshake(child, handshakePath, timeoutMs) {
|
|
|
216
217
|
* process exits. Use `HatchetEmbedded()` unless you need the raw
|
|
217
218
|
* connection details.
|
|
218
219
|
*/
|
|
220
|
+
const activeSidecars = new Set();
|
|
221
|
+
/**
|
|
222
|
+
* Gracefully stops every sidecar started in this process by
|
|
223
|
+
* `HatchetEmbeddedClient.init()` (or `startEmbeddedSidecar`) and resolves once
|
|
224
|
+
* they have fully exited, including their bundled Postgres. Call this before
|
|
225
|
+
* your process exits so the engine's shutdown output does not print after
|
|
226
|
+
* your program has returned.
|
|
227
|
+
*/
|
|
228
|
+
function stopEmbeddedSidecar() {
|
|
229
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
230
|
+
for (const sidecar of [...activeSidecars]) {
|
|
231
|
+
yield sidecar.stop();
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
219
235
|
function startEmbeddedSidecar() {
|
|
220
236
|
return __awaiter(this, arguments, void 0, function* (opts = {}) {
|
|
221
237
|
var _a, _b;
|
|
@@ -275,27 +291,34 @@ function startEmbeddedSidecar() {
|
|
|
275
291
|
if (child.stdin instanceof net_1.Socket) {
|
|
276
292
|
child.stdin.unref();
|
|
277
293
|
}
|
|
278
|
-
|
|
294
|
+
let stopping;
|
|
295
|
+
const sidecar = {
|
|
279
296
|
token: handshake.token,
|
|
280
297
|
tenantId: handshake.tenant_id,
|
|
281
298
|
grpcAddress: handshake.grpc_address,
|
|
282
299
|
apiUrl: handshake.api_url,
|
|
283
|
-
stop: () =>
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
300
|
+
stop: () => {
|
|
301
|
+
stopping !== null && stopping !== void 0 ? stopping : (stopping = new Promise((resolve) => {
|
|
302
|
+
var _a;
|
|
303
|
+
activeSidecars.delete(sidecar);
|
|
304
|
+
process.removeListener('exit', killChild);
|
|
305
|
+
if (child.exitCode !== null) {
|
|
306
|
+
resolve();
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const forceKill = setTimeout(() => child.kill('SIGKILL'), 30000);
|
|
310
|
+
(_a = forceKill.unref) === null || _a === void 0 ? void 0 : _a.call(forceKill);
|
|
311
|
+
child.once('exit', () => {
|
|
312
|
+
clearTimeout(forceKill);
|
|
313
|
+
resolve();
|
|
314
|
+
});
|
|
315
|
+
child.kill();
|
|
316
|
+
}));
|
|
317
|
+
return stopping;
|
|
318
|
+
},
|
|
298
319
|
};
|
|
320
|
+
activeSidecars.add(sidecar);
|
|
321
|
+
return sidecar;
|
|
299
322
|
});
|
|
300
323
|
}
|
|
301
324
|
class HatchetEmbeddedClient {
|
|
@@ -312,7 +335,9 @@ class HatchetEmbeddedClient {
|
|
|
312
335
|
static init(embeddedOpts, config, options, axiosConfig) {
|
|
313
336
|
return __awaiter(this, void 0, void 0, function* () {
|
|
314
337
|
const sidecar = yield startEmbeddedSidecar(embeddedOpts);
|
|
315
|
-
|
|
338
|
+
const client = client_1.HatchetClient.init(Object.assign(Object.assign(Object.assign({ token: sidecar.token, tenant_id: sidecar.tenantId, host_port: sidecar.grpcAddress }, (sidecar.apiUrl ? { api_url: sidecar.apiUrl } : {})), { tls_config: { tls_strategy: 'none' } }), config), options, axiosConfig);
|
|
339
|
+
client.stopEmbedded = () => sidecar.stop();
|
|
340
|
+
return client;
|
|
316
341
|
});
|
|
317
342
|
}
|
|
318
343
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
exports.configuredClient = configuredClient;
|
|
13
|
+
exports.fleetClient = fleetClient;
|
|
14
|
+
const embedded_1 = require("../../embedded");
|
|
15
|
+
function configuredClient() {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
// > Configure the embedded engine
|
|
18
|
+
const hatchet = yield embedded_1.HatchetEmbeddedClient.init({
|
|
19
|
+
// use your own Postgres instead of the bundled one
|
|
20
|
+
databaseUrl: 'postgres://...',
|
|
21
|
+
// store the bundled Postgres runtime and data under this directory
|
|
22
|
+
postgresDataDir: '~/my-project/.hatchet-pg',
|
|
23
|
+
// use RabbitMQ instead of the Postgres message queue
|
|
24
|
+
rabbitmqUrl: 'amqp://...',
|
|
25
|
+
// bind the API / gRPC servers to specific ports
|
|
26
|
+
apiPort: 28243,
|
|
27
|
+
grpcPort: 7070,
|
|
28
|
+
// start only the engine + gRPC, no REST API
|
|
29
|
+
startApi: false,
|
|
30
|
+
// skip running migrations on startup
|
|
31
|
+
runMigrations: false,
|
|
32
|
+
// engine log level (default "warn")
|
|
33
|
+
logLevel: 'info',
|
|
34
|
+
// hatchet-embedded release tag to download
|
|
35
|
+
version: 'v0.105.0',
|
|
36
|
+
// use an existing sidecar binary, skips the download
|
|
37
|
+
binaryPath: '/path/to/hatchet-embedded-sidecar',
|
|
38
|
+
// pinned sha256 of the sidecar binary, replaces checksums.txt as the trust anchor
|
|
39
|
+
checksum: '4f2a...',
|
|
40
|
+
});
|
|
41
|
+
// !!
|
|
42
|
+
return hatchet;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function fleetClient() {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
// > Fleet with a shared database
|
|
48
|
+
const hatchet = yield embedded_1.HatchetEmbeddedClient.init({
|
|
49
|
+
databaseUrl: 'postgres://user:pass@db.internal:5432/hatchet',
|
|
50
|
+
});
|
|
51
|
+
// !!
|
|
52
|
+
return hatchet;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function main() {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
// > Create an embedded client
|
|
58
|
+
const hatchet = yield embedded_1.HatchetEmbeddedClient.init();
|
|
59
|
+
// !!
|
|
60
|
+
const greet = hatchet.task({
|
|
61
|
+
name: 'embedded-greet',
|
|
62
|
+
fn: (input) => ({ greeting: `Hello, ${input.name}!` }),
|
|
63
|
+
});
|
|
64
|
+
const worker = yield hatchet.worker('embedded-worker', { workflows: [greet] });
|
|
65
|
+
void worker.start();
|
|
66
|
+
const result = yield greet.run({ name: 'embed' });
|
|
67
|
+
console.log(result.greeting);
|
|
68
|
+
// > Stop the embedded engine
|
|
69
|
+
yield hatchet.stopEmbedded();
|
|
70
|
+
// !!
|
|
71
|
+
process.exit(0);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (require.main === module) {
|
|
75
|
+
main();
|
|
76
|
+
}
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.29.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.29.1";
|
package/version.js
CHANGED