@hatchet-dev/typescript-sdk 1.28.2 → 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/clients/rest/generated/Api.d.ts +65 -1
- package/clients/rest/generated/Api.js +53 -0
- package/clients/rest/generated/data-contracts.d.ts +99 -3
- package/clients/rest/generated/data-contracts.js +7 -1
- package/package.json +1 -1
- package/v1/client/client.d.ts +1 -1
- package/v1/client/client.js +1 -1
- package/v1/client/features/tenant.d.ts +0 -3
- package/v1/client/worker/context.d.ts +1 -1
- package/v1/client/worker/context.js +2 -2
- package/v1/declaration.js +1 -1
- package/v1/embedded.d.ts +71 -0
- package/v1/embedded.js +344 -0
- package/v1/examples/embedded/worker.d.ts +2 -0
- package/v1/examples/embedded/worker.js +76 -0
- package/v1/examples/migration-guides/temporal.d.ts +76 -0
- package/v1/examples/migration-guides/temporal.js +280 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/v1/embedded.js
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
45
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
46
|
+
var m = o[Symbol.asyncIterator], i;
|
|
47
|
+
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);
|
|
48
|
+
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); }); }; }
|
|
49
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
50
|
+
};
|
|
51
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
+
exports.HatchetEmbeddedClient = void 0;
|
|
53
|
+
exports.stopEmbeddedSidecar = stopEmbeddedSidecar;
|
|
54
|
+
exports.startEmbeddedSidecar = startEmbeddedSidecar;
|
|
55
|
+
const child_process_1 = require("child_process");
|
|
56
|
+
const client_1 = require("./client/client");
|
|
57
|
+
const crypto_1 = require("crypto");
|
|
58
|
+
const fs_1 = require("fs");
|
|
59
|
+
const fs = __importStar(require("fs/promises"));
|
|
60
|
+
const os = __importStar(require("os"));
|
|
61
|
+
const path = __importStar(require("path"));
|
|
62
|
+
const stream_1 = require("stream");
|
|
63
|
+
const net_1 = require("net");
|
|
64
|
+
const promises_1 = require("stream/promises");
|
|
65
|
+
const REPO_URL = 'https://github.com/hatchet-dev/hatchet-embedded';
|
|
66
|
+
const DEFAULT_READY_TIMEOUT_MS = 300000;
|
|
67
|
+
function sidecarAssetName() {
|
|
68
|
+
const platform = { darwin: 'darwin', linux: 'linux' }[process.platform];
|
|
69
|
+
const arch = { x64: 'amd64', arm64: 'arm64' }[process.arch];
|
|
70
|
+
if (!platform || !arch) {
|
|
71
|
+
throw new Error(`hatchet embedded is not supported on ${process.platform}/${process.arch}`);
|
|
72
|
+
}
|
|
73
|
+
return `hatchet-embedded-sidecar_${platform}_${arch}`;
|
|
74
|
+
}
|
|
75
|
+
function resolveVersion(version) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
var _a;
|
|
78
|
+
const requested = (_a = version !== null && version !== void 0 ? version : process.env.HATCHET_CLIENT_EMBEDDED_VERSION) !== null && _a !== void 0 ? _a : 'latest';
|
|
79
|
+
if (requested !== 'latest') {
|
|
80
|
+
return requested;
|
|
81
|
+
}
|
|
82
|
+
const res = yield fetch(`${REPO_URL}/releases/latest`, { redirect: 'manual' });
|
|
83
|
+
const location = res.headers.get('location');
|
|
84
|
+
const tag = location === null || location === void 0 ? void 0 : location.split('/').pop();
|
|
85
|
+
if (!tag || !tag.startsWith('v')) {
|
|
86
|
+
throw new Error(`could not resolve the latest hatchet-embedded release from ${REPO_URL}`);
|
|
87
|
+
}
|
|
88
|
+
return tag;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function expectedChecksum(tag, asset) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const url = `${REPO_URL}/releases/download/${tag}/checksums.txt`;
|
|
94
|
+
const res = yield fetch(url, { signal: AbortSignal.timeout(10000) });
|
|
95
|
+
if (!res.ok) {
|
|
96
|
+
throw new Error(`could not download ${url}: ${res.status}`);
|
|
97
|
+
}
|
|
98
|
+
for (const line of (yield res.text()).split('\n')) {
|
|
99
|
+
const parts = line.split(/\s+/).filter(Boolean);
|
|
100
|
+
if (parts.length === 2 && parts[1] === asset) {
|
|
101
|
+
return parts[0];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
throw new Error(`no checksum for ${asset} in ${url}`);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function sha256File(filePath) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
var _a, e_1, _b, _c;
|
|
110
|
+
const digest = (0, crypto_1.createHash)('sha256');
|
|
111
|
+
try {
|
|
112
|
+
for (var _d = true, _e = __asyncValues((0, fs_1.createReadStream)(filePath)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
113
|
+
_c = _f.value;
|
|
114
|
+
_d = false;
|
|
115
|
+
const chunk = _c;
|
|
116
|
+
digest.update(chunk);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
120
|
+
finally {
|
|
121
|
+
try {
|
|
122
|
+
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
123
|
+
}
|
|
124
|
+
finally { if (e_1) throw e_1.error; }
|
|
125
|
+
}
|
|
126
|
+
return digest.digest('hex');
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function resolveExpectedChecksum(tag, asset, binPath) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
const checksumPath = path.join(path.dirname(binPath), `${asset}.sha256`);
|
|
132
|
+
// fall back to the checksum cached at download time so a pinned, already
|
|
133
|
+
// verified binary still starts when GitHub is unreachable
|
|
134
|
+
let expected;
|
|
135
|
+
try {
|
|
136
|
+
expected = yield expectedChecksum(tag, asset);
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
const cachedDigest = yield fs.readFile(checksumPath, 'utf8').then((s) => s.trim(), () => undefined);
|
|
140
|
+
const hasBinary = yield fs.access(binPath).then(() => true, () => false);
|
|
141
|
+
if (cachedDigest && hasBinary) {
|
|
142
|
+
return cachedDigest;
|
|
143
|
+
}
|
|
144
|
+
throw err;
|
|
145
|
+
}
|
|
146
|
+
yield fs.writeFile(checksumPath, `${expected}\n`);
|
|
147
|
+
return expected;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function ensureSidecarBinary(version, checksum) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
const tag = yield resolveVersion(version);
|
|
153
|
+
const asset = sidecarAssetName();
|
|
154
|
+
const binPath = path.join(os.homedir(), '.hatchet', 'embedded', tag, asset);
|
|
155
|
+
yield fs.mkdir(path.dirname(binPath), { recursive: true });
|
|
156
|
+
// verified on every start, not just at download; a cached binary that no
|
|
157
|
+
// longer matches the expected checksum is re-downloaded
|
|
158
|
+
const expected = checksum !== null && checksum !== void 0 ? checksum : (yield resolveExpectedChecksum(tag, asset, binPath));
|
|
159
|
+
const cached = yield fs.access(binPath).then(() => true, () => false);
|
|
160
|
+
if (cached && (yield sha256File(binPath)) === expected) {
|
|
161
|
+
return binPath;
|
|
162
|
+
}
|
|
163
|
+
const url = `${REPO_URL}/releases/download/${tag}/${asset}`;
|
|
164
|
+
const res = yield fetch(url);
|
|
165
|
+
if (!res.ok || !res.body) {
|
|
166
|
+
throw new Error(`could not download the hatchet embedded sidecar from ${url}: ${res.status}`);
|
|
167
|
+
}
|
|
168
|
+
// unique temp name per call (not per process) so concurrent downloads of
|
|
169
|
+
// the same version never clobber each other, even within one process; the
|
|
170
|
+
// final rename is atomic and last-writer-wins
|
|
171
|
+
const tmpPath = `${binPath}.${(0, crypto_1.randomUUID)()}.download`;
|
|
172
|
+
try {
|
|
173
|
+
yield (0, promises_1.pipeline)(stream_1.Readable.fromWeb(res.body), (0, fs_1.createWriteStream)(tmpPath, { mode: 0o755 }));
|
|
174
|
+
const actual = yield sha256File(tmpPath);
|
|
175
|
+
if (actual !== expected) {
|
|
176
|
+
throw new Error(`checksum mismatch for ${url}: expected ${expected}, got ${actual}`);
|
|
177
|
+
}
|
|
178
|
+
yield fs.rename(tmpPath, binPath);
|
|
179
|
+
}
|
|
180
|
+
finally {
|
|
181
|
+
yield fs.rm(tmpPath, { force: true });
|
|
182
|
+
}
|
|
183
|
+
return binPath;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
function waitForHandshake(child, handshakePath, timeoutMs) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
const deadline = Date.now() + timeoutMs;
|
|
189
|
+
let exited;
|
|
190
|
+
child.once('exit', (code) => {
|
|
191
|
+
exited = new Error(`hatchet embedded sidecar exited with code ${code} before becoming ready`);
|
|
192
|
+
});
|
|
193
|
+
while (Date.now() < deadline) {
|
|
194
|
+
if (exited) {
|
|
195
|
+
throw exited;
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
const handshake = JSON.parse(yield fs.readFile(handshakePath, 'utf8'));
|
|
199
|
+
if (handshake.token) {
|
|
200
|
+
return handshake;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
catch (_a) {
|
|
204
|
+
// not ready yet
|
|
205
|
+
}
|
|
206
|
+
yield new Promise((resolve) => {
|
|
207
|
+
setTimeout(resolve, 200);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
child.kill();
|
|
211
|
+
throw new Error(`hatchet embedded sidecar did not become ready within ${timeoutMs}ms`);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Downloads (and caches) the hatchet-embedded sidecar binary, spawns it, and
|
|
216
|
+
* waits until the embedded engine is ready. The sidecar shuts down when this
|
|
217
|
+
* process exits. Use `HatchetEmbedded()` unless you need the raw
|
|
218
|
+
* connection details.
|
|
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
|
+
}
|
|
235
|
+
function startEmbeddedSidecar() {
|
|
236
|
+
return __awaiter(this, arguments, void 0, function* (opts = {}) {
|
|
237
|
+
var _a, _b;
|
|
238
|
+
const suppliedPath = (_a = opts.binaryPath) !== null && _a !== void 0 ? _a : process.env.HATCHET_CLIENT_EMBEDDED_BINARY_PATH;
|
|
239
|
+
let binPath;
|
|
240
|
+
if (suppliedPath) {
|
|
241
|
+
if (opts.checksum) {
|
|
242
|
+
const actual = yield sha256File(suppliedPath);
|
|
243
|
+
if (actual !== opts.checksum) {
|
|
244
|
+
throw new Error(`checksum mismatch for ${suppliedPath}: expected ${opts.checksum}, got ${actual}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
binPath = suppliedPath;
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
binPath = yield ensureSidecarBinary(opts.version, opts.checksum);
|
|
251
|
+
}
|
|
252
|
+
const handshakePath = path.join(yield fs.mkdtemp(path.join(os.tmpdir(), 'hatchet-embedded-')), 'handshake.json');
|
|
253
|
+
const args = ['-handshake-file', handshakePath];
|
|
254
|
+
if (opts.databaseUrl) {
|
|
255
|
+
args.push('-database-url', opts.databaseUrl);
|
|
256
|
+
}
|
|
257
|
+
if (opts.rabbitmqUrl) {
|
|
258
|
+
args.push('-rabbitmq-url', opts.rabbitmqUrl);
|
|
259
|
+
}
|
|
260
|
+
if (opts.postgresDataDir) {
|
|
261
|
+
args.push('-postgres-data-dir', opts.postgresDataDir);
|
|
262
|
+
}
|
|
263
|
+
if (opts.grpcPort) {
|
|
264
|
+
args.push('-grpc-port', String(opts.grpcPort));
|
|
265
|
+
}
|
|
266
|
+
if (opts.apiPort) {
|
|
267
|
+
args.push('-api-port', String(opts.apiPort));
|
|
268
|
+
}
|
|
269
|
+
if (opts.startApi === false) {
|
|
270
|
+
args.push('-no-api');
|
|
271
|
+
}
|
|
272
|
+
if (opts.runMigrations === false) {
|
|
273
|
+
args.push('-no-migrations');
|
|
274
|
+
}
|
|
275
|
+
if (opts.logLevel) {
|
|
276
|
+
args.push('-log-level', opts.logLevel);
|
|
277
|
+
}
|
|
278
|
+
// the sidecar shuts down when its stdin closes, so it never outlives this
|
|
279
|
+
// process, no matter how this process dies
|
|
280
|
+
const child = (0, child_process_1.spawn)(binPath, args, { stdio: ['pipe', 'ignore', 'inherit'] });
|
|
281
|
+
const killChild = () => child.kill();
|
|
282
|
+
process.once('exit', killChild);
|
|
283
|
+
let handshake;
|
|
284
|
+
try {
|
|
285
|
+
handshake = yield waitForHandshake(child, handshakePath, (_b = opts.readyTimeoutMs) !== null && _b !== void 0 ? _b : DEFAULT_READY_TIMEOUT_MS);
|
|
286
|
+
}
|
|
287
|
+
finally {
|
|
288
|
+
yield fs.rm(path.dirname(handshakePath), { recursive: true, force: true }).catch(() => { });
|
|
289
|
+
}
|
|
290
|
+
child.unref();
|
|
291
|
+
if (child.stdin instanceof net_1.Socket) {
|
|
292
|
+
child.stdin.unref();
|
|
293
|
+
}
|
|
294
|
+
let stopping;
|
|
295
|
+
const sidecar = {
|
|
296
|
+
token: handshake.token,
|
|
297
|
+
tenantId: handshake.tenant_id,
|
|
298
|
+
grpcAddress: handshake.grpc_address,
|
|
299
|
+
apiUrl: handshake.api_url,
|
|
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
|
+
},
|
|
319
|
+
};
|
|
320
|
+
activeSidecars.add(sidecar);
|
|
321
|
+
return sidecar;
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
class HatchetEmbeddedClient {
|
|
325
|
+
/**
|
|
326
|
+
* Runs a full Hatchet engine locally via the hatchet-embedded sidecar (downloaded
|
|
327
|
+
* on first use) and returns a client wired to it. By default the sidecar starts a
|
|
328
|
+
* bundled Postgres; pass `databaseUrl` to point it at your own instead.
|
|
329
|
+
* @param embeddedOpts - Options for the embedded engine (version, ports, database, ...).
|
|
330
|
+
* @param config - Optional configuration overrides for the client.
|
|
331
|
+
* @param options - Optional client options.
|
|
332
|
+
* @param axiosConfig - Optional Axios configuration for HTTP requests.
|
|
333
|
+
* @returns A new Hatchet client instance connected to the embedded engine.
|
|
334
|
+
*/
|
|
335
|
+
static init(embeddedOpts, config, options, axiosConfig) {
|
|
336
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
337
|
+
const sidecar = yield startEmbeddedSidecar(embeddedOpts);
|
|
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;
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
exports.HatchetEmbeddedClient = HatchetEmbeddedClient;
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { HatchetClient } from '../..';
|
|
2
|
+
export declare const hatchet: HatchetClient<{}, {}, {}, {}>;
|
|
3
|
+
export type OrderInput = {
|
|
4
|
+
orderId: string;
|
|
5
|
+
correlationId: string;
|
|
6
|
+
};
|
|
7
|
+
export type ValidateOutput = {
|
|
8
|
+
valid: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type FulfillOutput = {
|
|
11
|
+
fulfilled: boolean;
|
|
12
|
+
shipmentId: string;
|
|
13
|
+
};
|
|
14
|
+
export type SignupInput = {
|
|
15
|
+
userId: string;
|
|
16
|
+
email: string;
|
|
17
|
+
};
|
|
18
|
+
export type EmailOutput = {
|
|
19
|
+
sent: boolean;
|
|
20
|
+
};
|
|
21
|
+
export declare const validateOrder: import("../..").TaskWorkflowDeclaration<OrderInput, ValidateOutput, {}, {}, {}, {}>;
|
|
22
|
+
export type ChargeOutput = {
|
|
23
|
+
charged: boolean;
|
|
24
|
+
amountCents: number;
|
|
25
|
+
};
|
|
26
|
+
export declare const chargeOrder: import("../..").TaskWorkflowDeclaration<OrderInput, ChargeOutput, {}, {}, {}, {}>;
|
|
27
|
+
export declare const fulfillOrder: import("../..").TaskWorkflowDeclaration<OrderInput, FulfillOutput, {}, {}, {}, {}>;
|
|
28
|
+
export declare const processOrder: import("../..").TaskWorkflowDeclaration<OrderInput, FulfillOutput, {}, {}, {}, {}>;
|
|
29
|
+
export declare const sendWelcomeEmail: import("../..").TaskWorkflowDeclaration<SignupInput, EmailOutput, {}, {}, {}, {}>;
|
|
30
|
+
export declare const sendFollowupEmail: import("../..").TaskWorkflowDeclaration<SignupInput, EmailOutput, {}, {}, {}, {}>;
|
|
31
|
+
export declare const onboardingFlow: import("../..").TaskWorkflowDeclaration<SignupInput, EmailOutput, {}, {}, {}, {}>;
|
|
32
|
+
export declare const chargeOrderWithRetries: import("../..").TaskWorkflowDeclaration<OrderInput, ChargeOutput, {}, {}, {}, {}>;
|
|
33
|
+
export declare const orderFollowUp: import("../..").TaskWorkflowDeclaration<OrderInput, EmailOutput, {}, {}, {}, {}>;
|
|
34
|
+
export declare const approvalFlow: import("../..").TaskWorkflowDeclaration<OrderInput, FulfillOutput, {}, {}, {}, {}>;
|
|
35
|
+
export type ItemInput = {
|
|
36
|
+
item: string;
|
|
37
|
+
};
|
|
38
|
+
export type ItemOutput = {
|
|
39
|
+
packed: boolean;
|
|
40
|
+
};
|
|
41
|
+
export declare const processItem: import("../..").TaskWorkflowDeclaration<ItemInput, ItemOutput, {}, {}, {}, {}>;
|
|
42
|
+
export declare const packOrder: import("../..").TaskWorkflowDeclaration<{
|
|
43
|
+
items: string[];
|
|
44
|
+
}, {
|
|
45
|
+
packed: number;
|
|
46
|
+
}, {}, {}, {}, {}>;
|
|
47
|
+
export type ReportInput = {
|
|
48
|
+
kind: string;
|
|
49
|
+
};
|
|
50
|
+
export type ReportOutput = {
|
|
51
|
+
generate: {
|
|
52
|
+
rows: number;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export declare const weeklyReport: import("../..").WorkflowDeclaration<ReportInput, ReportOutput, {}>;
|
|
56
|
+
export type SyncInput = {
|
|
57
|
+
customerId: string;
|
|
58
|
+
};
|
|
59
|
+
export type SyncOutput = {
|
|
60
|
+
sync: {
|
|
61
|
+
synced: number;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export type PromptInput = {
|
|
65
|
+
prompt: string;
|
|
66
|
+
};
|
|
67
|
+
export declare const syncCustomer: import("../..").WorkflowDeclaration<SyncInput, SyncOutput, {}>;
|
|
68
|
+
export declare const callModel: import("../..").TaskWorkflowDeclaration<PromptInput, {
|
|
69
|
+
completion: string;
|
|
70
|
+
}, {}, {}, {}, {}>;
|
|
71
|
+
export type OrderDagOutput = {
|
|
72
|
+
validate: ValidateOutput;
|
|
73
|
+
charge: ChargeOutput;
|
|
74
|
+
fulfill: FulfillOutput;
|
|
75
|
+
};
|
|
76
|
+
export declare const orderWorkflow: import("../..").WorkflowDeclaration<OrderInput, OrderDagOutput, {}>;
|