@hatchet-dev/typescript-sdk 1.15.2 → 1.17.0
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/README.md +14 -2
- package/clients/admin/admin-client.d.ts +2 -2
- package/clients/admin/admin-client.js +8 -9
- package/clients/dispatcher/action-listener.d.ts +3 -6
- package/clients/dispatcher/action-listener.js +54 -23
- package/clients/dispatcher/dispatcher-client.js +5 -8
- package/clients/dispatcher/heartbeat/heartbeat-worker.js +7 -4
- package/clients/event/event-client.d.ts +2 -2
- package/clients/event/event-client.js +5 -11
- package/clients/hatchet-client/hatchet-logger.js +8 -17
- package/clients/listeners/durable-listener/durable-listener-client.d.ts +115 -15
- package/clients/listeners/durable-listener/durable-listener-client.js +769 -19
- package/clients/listeners/durable-listener/pooled-durable-listener-client.js +11 -22
- package/clients/listeners/run-listener/child-listener-client.d.ts +1 -1
- package/clients/listeners/run-listener/child-listener-client.js +34 -30
- package/clients/listeners/run-listener/pooled-child-listener-client.js +9 -19
- package/clients/rest/generated/Api.d.ts +25 -1
- package/clients/rest/generated/Api.js +20 -0
- package/clients/rest/generated/data-contracts.d.ts +60 -1
- package/clients/rest/generated/data-contracts.js +9 -1
- package/legacy/examples/affinity-workers.js +2 -3
- package/legacy/examples/byo-logger.js +0 -2
- package/legacy/examples/concurrency/cancel-in-progress/concurrency-worker.js +4 -2
- package/legacy/examples/concurrency/group-round-robin/concurrency-event.js +0 -1
- package/legacy/examples/concurrency/group-round-robin/concurrency-worker-expression.js +4 -2
- package/legacy/examples/concurrency/group-round-robin/concurrency-worker-key-fn.js +4 -2
- package/legacy/examples/example-event.js +0 -3
- package/legacy/examples/logger.js +0 -1
- package/legacy/examples/sticky-worker-with-check.js +0 -1
- package/legacy/examples/sticky-worker.js +0 -1
- package/legacy/legacy-client.js +2 -2
- package/legacy/legacy-transformer.js +2 -4
- package/legacy/step.d.ts +16 -16
- package/legacy/step.js +8 -17
- package/legacy/workflow.d.ts +81 -81
- package/package.json +20 -29
- package/protoc/dispatcher/dispatcher.d.ts +20 -0
- package/protoc/dispatcher/dispatcher.js +136 -2
- package/protoc/v1/dispatcher.d.ts +168 -0
- package/protoc/v1/dispatcher.js +1920 -1
- package/protoc/v1/shared/trigger.d.ts +89 -0
- package/protoc/v1/shared/trigger.js +493 -0
- package/protoc/v1/workflows.d.ts +34 -34
- package/protoc/v1/workflows.js +252 -200
- package/protoc/workflows/workflows.d.ts +2 -75
- package/protoc/workflows/workflows.js +16 -491
- package/util/abort-error.d.ts +15 -1
- package/util/abort-error.js +30 -5
- package/util/config-loader/config-loader.js +4 -3
- package/util/config-loader/token.js +9 -2
- package/util/errors/eviction-not-supported-error.d.ts +5 -0
- package/util/errors/eviction-not-supported-error.js +18 -0
- package/util/errors/hatchet-error.d.ts +9 -1
- package/util/errors/hatchet-error.js +23 -2
- package/util/errors/non-determinism-error.d.ts +7 -0
- package/util/errors/non-determinism-error.js +21 -0
- package/util/errors/task-run-terminated-error.d.ts +6 -0
- package/util/errors/task-run-terminated-error.js +15 -0
- package/util/grpc-error.d.ts +9 -0
- package/util/grpc-error.js +25 -0
- package/util/hatchet-promise/hatchet-promise.d.ts +6 -1
- package/util/hatchet-promise/hatchet-promise.js +16 -2
- package/util/logger/logger.js +0 -1
- package/util/parse.d.ts +1 -1
- package/util/parse.js +4 -2
- package/util/retrier.js +2 -3
- package/util/sleep.d.ts +3 -2
- package/util/sleep.js +6 -4
- package/util/workflow-run-ref.js +5 -3
- package/v1/client/admin.d.ts +2 -2
- package/v1/client/admin.js +2 -6
- package/v1/client/client.d.ts +7 -11
- package/v1/client/client.interface.d.ts +5 -8
- package/v1/client/client.js +34 -40
- package/v1/client/duration.d.ts +11 -1
- package/v1/client/duration.js +44 -0
- package/v1/client/features/cel.js +1 -1
- package/v1/client/features/crons.js +2 -2
- package/v1/client/features/index.d.ts +5 -0
- package/v1/client/features/index.js +5 -0
- package/v1/client/features/logs.d.ts +37 -0
- package/v1/client/features/logs.js +46 -0
- package/v1/client/features/runs.d.ts +16 -3
- package/v1/client/features/runs.js +38 -4
- package/v1/client/features/schedules.js +4 -4
- package/v1/client/features/webhooks.js +4 -2
- package/v1/client/features/workflows.js +1 -1
- package/v1/client/worker/context.d.ts +101 -6
- package/v1/client/worker/context.js +257 -44
- package/v1/client/worker/deprecated/deprecation.js +8 -4
- package/v1/client/worker/deprecated/index.d.ts +1 -1
- package/v1/client/worker/deprecated/index.js +2 -1
- package/v1/client/worker/deprecated/legacy-worker.d.ts +5 -0
- package/v1/client/worker/deprecated/legacy-worker.js +33 -24
- package/v1/client/worker/deprecated/pre-eviction.d.ts +12 -0
- package/v1/client/worker/deprecated/pre-eviction.js +37 -0
- package/v1/client/worker/engine-version.d.ts +5 -0
- package/v1/client/worker/engine-version.js +14 -0
- package/v1/client/worker/eviction/eviction-cache.d.ts +33 -0
- package/v1/client/worker/eviction/eviction-cache.js +139 -0
- package/v1/client/worker/eviction/eviction-manager.d.ts +42 -0
- package/v1/client/worker/eviction/eviction-manager.js +132 -0
- package/v1/client/worker/eviction/eviction-policy.d.ts +19 -0
- package/v1/client/worker/eviction/eviction-policy.js +8 -0
- package/v1/client/worker/eviction/index.d.ts +3 -0
- package/v1/client/worker/eviction/index.js +11 -0
- package/v1/client/worker/health-server.js +3 -3
- package/v1/client/worker/slot-utils.js +0 -3
- package/v1/client/worker/worker-internal.d.ts +23 -4
- package/v1/client/worker/worker-internal.js +216 -148
- package/v1/client/worker/worker.d.ts +1 -0
- package/v1/client/worker/worker.js +34 -0
- package/v1/conditions/base.js +0 -1
- package/v1/conditions/index.js +2 -4
- package/v1/conditions/sleep-condition.js +2 -1
- package/v1/conditions/transformer.js +2 -1
- package/v1/declaration.d.ts +6 -4
- package/v1/declaration.js +20 -7
- package/v1/examples/__e2e__/harness.d.ts +5 -0
- package/v1/examples/__e2e__/harness.js +17 -3
- package/v1/examples/affinity/affinity-workers.js +0 -1
- package/v1/examples/bulk_operations/workflow.js +0 -1
- package/v1/examples/cancellation/run.js +0 -1
- package/v1/examples/cancellations/run.js +0 -1
- package/v1/examples/child_workflows/run.js +0 -2
- package/v1/examples/child_workflows/workflow.js +0 -1
- package/v1/examples/concurrency-rr/load.js +0 -1
- package/v1/examples/concurrency-rr/run.js +0 -3
- package/v1/examples/concurrency_limit_rr/load.js +0 -1
- package/v1/examples/concurrency_limit_rr/run.js +0 -3
- package/v1/examples/concurrency_workflow_level/workflow.d.ts +1 -1
- package/v1/examples/concurrency_workflow_level/workflow.js +1 -1
- package/v1/examples/conditions/event.js +0 -1
- package/v1/examples/conditions/run.js +0 -1
- package/v1/examples/dag/run.js +0 -1
- package/v1/examples/dag_match_condition/event.js +0 -1
- package/v1/examples/dag_match_condition/run.js +0 -1
- package/v1/examples/deep/run.js +0 -2
- package/v1/examples/durable/workflow.d.ts +57 -0
- package/v1/examples/durable/workflow.js +164 -10
- package/v1/examples/durable-event/event.js +0 -1
- package/v1/examples/durable-event/run.js +0 -2
- package/v1/examples/durable-event/workflow.js +2 -7
- package/v1/examples/durable-sleep/event.js +0 -1
- package/v1/examples/durable-sleep/run.js +0 -2
- package/v1/examples/durable_event/event.js +0 -1
- package/v1/examples/durable_event/run.js +0 -2
- package/v1/examples/durable_event/workflow.d.ts +1 -0
- package/v1/examples/durable_event/workflow.js +4 -9
- package/v1/examples/durable_eviction/capacity-worker.d.ts +1 -0
- package/v1/examples/durable_eviction/capacity-worker.js +31 -0
- package/v1/examples/durable_eviction/worker.d.ts +1 -0
- package/v1/examples/durable_eviction/worker.js +34 -0
- package/v1/examples/durable_eviction/workflow.d.ts +44 -0
- package/v1/examples/durable_eviction/workflow.js +129 -0
- package/v1/examples/durable_sleep/event.js +0 -1
- package/v1/examples/durable_sleep/run.js +0 -2
- package/v1/examples/e2e-worker.js +42 -19
- package/v1/examples/events/event.js +0 -1
- package/v1/examples/high-memory/run.js +0 -1
- package/v1/examples/inferred-typing/run.js +0 -1
- package/v1/examples/landing_page/durable-excution.js +0 -1
- package/v1/examples/landing_page/queues.js +0 -1
- package/v1/examples/legacy/run.js +0 -1
- package/v1/examples/logger/byo-logger.js +0 -2
- package/v1/examples/logger/logger.js +0 -1
- package/v1/examples/logging/byo-logger.js +0 -2
- package/v1/examples/logging/logger.js +0 -1
- package/v1/examples/middleware/recipes.js +3 -1
- package/v1/examples/migration-guides/mergent.js +2 -1
- package/v1/examples/multiple_wf_concurrency/run.js +0 -3
- package/v1/examples/non_retryable/run.js +0 -1
- package/v1/examples/on_event/event.js +0 -1
- package/v1/examples/on_failure/run.js +0 -1
- package/v1/examples/on_failure/workflow.js +0 -1
- package/v1/examples/on_success/run.js +0 -1
- package/v1/examples/on_success/workflow.js +0 -1
- package/v1/examples/priority/run.js +0 -1
- package/v1/examples/priority/workflow.js +0 -1
- package/v1/examples/retries/run.js +0 -1
- package/v1/examples/retries/workflow.js +0 -1
- package/v1/examples/simple/bulk.js +0 -1
- package/v1/examples/simple/cron.js +0 -2
- package/v1/examples/simple/delay.js +0 -1
- package/v1/examples/simple/enqueue.js +0 -2
- package/v1/examples/simple/run.js +0 -1
- package/v1/examples/simple/schedule.js +0 -1
- package/v1/examples/simple/workflow-with-child.js +10 -4
- package/v1/examples/sticky/run.js +0 -1
- package/v1/examples/sticky/workflow.js +0 -1
- package/v1/examples/streaming/nextjs-proxy.js +0 -1
- package/v1/examples/streaming/run.js +0 -1
- package/v1/examples/timeout/run.js +0 -1
- package/v1/examples/timeouts/run.js +0 -1
- package/v1/index.d.ts +5 -0
- package/v1/index.js +10 -0
- package/v1/parent-run-context-vars.d.ts +6 -0
- package/v1/slot-types.js +0 -1
- package/v1/task.d.ts +10 -2
- package/v1/task.js +2 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/v1/client/client.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This is the TypeScript SDK reference, documenting methods available for interacting with Hatchet resources.
|
|
4
|
+
* Check out the [user guide](https://docs.hatchet.run/home/) for an introduction to getting your first tasks running.
|
|
5
|
+
*
|
|
6
|
+
* @module Hatchet TypeScript SDK Reference
|
|
7
|
+
*/
|
|
2
8
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
9
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
10
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -13,14 +19,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
19
|
};
|
|
14
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
21
|
exports.HatchetClient = void 0;
|
|
16
|
-
/**
|
|
17
|
-
* This is the TypeScript SDK reference, documenting methods available for interacting with Hatchet resources.
|
|
18
|
-
* Check out the [user guide](https://docs.hatchet.run/home/) for an introduction to getting your first tasks running.
|
|
19
|
-
*
|
|
20
|
-
* @module Hatchet TypeScript SDK Reference
|
|
21
|
-
*/
|
|
22
|
-
/* eslint-disable no-dupe-class-members */
|
|
23
|
-
/* eslint-disable no-underscore-dangle */
|
|
24
22
|
const hatchet_client_1 = require("../../clients/hatchet-client");
|
|
25
23
|
const rest_1 = __importDefault(require("../../clients/rest"));
|
|
26
24
|
const config_loader_1 = require("../../util/config-loader");
|
|
@@ -35,18 +33,8 @@ const nice_grpc_1 = require("nice-grpc");
|
|
|
35
33
|
const declaration_1 = require("../declaration");
|
|
36
34
|
const legacy_transformer_1 = require("../../legacy/legacy-transformer");
|
|
37
35
|
const worker_1 = require("./worker/worker");
|
|
38
|
-
const metrics_1 = require("./features/metrics");
|
|
39
|
-
const workers_1 = require("./features/workers");
|
|
40
|
-
const workflows_1 = require("./features/workflows");
|
|
41
|
-
const runs_1 = require("./features/runs");
|
|
42
36
|
const features_1 = require("./features");
|
|
43
37
|
const admin_1 = require("./admin");
|
|
44
|
-
const filters_1 = require("./features/filters");
|
|
45
|
-
const schedules_1 = require("./features/schedules");
|
|
46
|
-
const crons_1 = require("./features/crons");
|
|
47
|
-
const cel_1 = require("./features/cel");
|
|
48
|
-
const tenant_1 = require("./features/tenant");
|
|
49
|
-
const webhooks_1 = require("./features/webhooks");
|
|
50
38
|
/**
|
|
51
39
|
* HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
|
|
52
40
|
* It provides methods for creating and executing workflows, as well as managing workers.
|
|
@@ -102,7 +90,7 @@ class HatchetClient {
|
|
|
102
90
|
}
|
|
103
91
|
catch (e) {
|
|
104
92
|
if (e instanceof zod_1.z.ZodError) {
|
|
105
|
-
throw new Error(`Invalid client config: ${e.message}
|
|
93
|
+
throw new Error(`Invalid client config: ${e.message}`, { cause: e });
|
|
106
94
|
}
|
|
107
95
|
throw e;
|
|
108
96
|
}
|
|
@@ -120,7 +108,7 @@ class HatchetClient {
|
|
|
120
108
|
// Do nothing here
|
|
121
109
|
});
|
|
122
110
|
}
|
|
123
|
-
catch (
|
|
111
|
+
catch (_b) {
|
|
124
112
|
// Do nothing here
|
|
125
113
|
}
|
|
126
114
|
}
|
|
@@ -148,10 +136,12 @@ class HatchetClient {
|
|
|
148
136
|
withMiddleware(middleware) {
|
|
149
137
|
const existing = this._config.middleware || {};
|
|
150
138
|
const toArray = (v) => {
|
|
151
|
-
if (v == null)
|
|
139
|
+
if (v == null) {
|
|
152
140
|
return [];
|
|
153
|
-
|
|
141
|
+
}
|
|
142
|
+
if (Array.isArray(v)) {
|
|
154
143
|
return [...v];
|
|
144
|
+
}
|
|
155
145
|
return [v];
|
|
156
146
|
};
|
|
157
147
|
this._config.middleware = {
|
|
@@ -238,7 +228,7 @@ class HatchetClient {
|
|
|
238
228
|
*/
|
|
239
229
|
get cel() {
|
|
240
230
|
if (!this._cel) {
|
|
241
|
-
this._cel = new
|
|
231
|
+
this._cel = new features_1.CELClient(this);
|
|
242
232
|
}
|
|
243
233
|
return this._cel;
|
|
244
234
|
}
|
|
@@ -248,7 +238,7 @@ class HatchetClient {
|
|
|
248
238
|
*/
|
|
249
239
|
get crons() {
|
|
250
240
|
if (!this._crons) {
|
|
251
|
-
this._crons = new
|
|
241
|
+
this._crons = new features_1.CronClient(this);
|
|
252
242
|
}
|
|
253
243
|
return this._crons;
|
|
254
244
|
}
|
|
@@ -267,7 +257,7 @@ class HatchetClient {
|
|
|
267
257
|
*/
|
|
268
258
|
get scheduled() {
|
|
269
259
|
if (!this._scheduled) {
|
|
270
|
-
this._scheduled = new
|
|
260
|
+
this._scheduled = new features_1.ScheduleClient(this);
|
|
271
261
|
}
|
|
272
262
|
return this._scheduled;
|
|
273
263
|
}
|
|
@@ -314,7 +304,7 @@ class HatchetClient {
|
|
|
314
304
|
*/
|
|
315
305
|
get durableListener() {
|
|
316
306
|
if (!this._durableListener) {
|
|
317
|
-
this._durableListener = new durable_listener_client_1.DurableListenerClient(this._config, (0, grpc_helpers_1.channelFactory)(this._config, this._credentials), this._clientFactory
|
|
307
|
+
this._durableListener = new durable_listener_client_1.DurableListenerClient(this._config, (0, grpc_helpers_1.channelFactory)(this._config, this._credentials), this._clientFactory);
|
|
318
308
|
}
|
|
319
309
|
return this._durableListener;
|
|
320
310
|
}
|
|
@@ -339,7 +329,7 @@ class HatchetClient {
|
|
|
339
329
|
*/
|
|
340
330
|
get metrics() {
|
|
341
331
|
if (!this._metrics) {
|
|
342
|
-
this._metrics = new
|
|
332
|
+
this._metrics = new features_1.MetricsClient(this);
|
|
343
333
|
}
|
|
344
334
|
return this._metrics;
|
|
345
335
|
}
|
|
@@ -349,7 +339,7 @@ class HatchetClient {
|
|
|
349
339
|
*/
|
|
350
340
|
get filters() {
|
|
351
341
|
if (!this._filters) {
|
|
352
|
-
this._filters = new
|
|
342
|
+
this._filters = new features_1.FiltersClient(this);
|
|
353
343
|
}
|
|
354
344
|
return this._filters;
|
|
355
345
|
}
|
|
@@ -359,7 +349,7 @@ class HatchetClient {
|
|
|
359
349
|
*/
|
|
360
350
|
get tenant() {
|
|
361
351
|
if (!this._tenant) {
|
|
362
|
-
this._tenant = new
|
|
352
|
+
this._tenant = new features_1.TenantClient(this);
|
|
363
353
|
}
|
|
364
354
|
return this._tenant;
|
|
365
355
|
}
|
|
@@ -369,10 +359,20 @@ class HatchetClient {
|
|
|
369
359
|
*/
|
|
370
360
|
get webhooks() {
|
|
371
361
|
if (!this._webhooks) {
|
|
372
|
-
this._webhooks = new
|
|
362
|
+
this._webhooks = new features_1.WebhooksClient(this);
|
|
373
363
|
}
|
|
374
364
|
return this._webhooks;
|
|
375
365
|
}
|
|
366
|
+
/**
|
|
367
|
+
* Get the logs client for creating and managing logs
|
|
368
|
+
* @returns A logs client instance
|
|
369
|
+
*/
|
|
370
|
+
get logs() {
|
|
371
|
+
if (!this._logs) {
|
|
372
|
+
this._logs = new features_1.LogsClient(this);
|
|
373
|
+
}
|
|
374
|
+
return this._logs;
|
|
375
|
+
}
|
|
376
376
|
/**
|
|
377
377
|
* Get the rate limits client for creating and managing rate limits
|
|
378
378
|
* @returns A rate limits client instance
|
|
@@ -389,7 +389,7 @@ class HatchetClient {
|
|
|
389
389
|
*/
|
|
390
390
|
get runs() {
|
|
391
391
|
if (!this._runs) {
|
|
392
|
-
this._runs = new
|
|
392
|
+
this._runs = new features_1.RunsClient(this);
|
|
393
393
|
}
|
|
394
394
|
return this._runs;
|
|
395
395
|
}
|
|
@@ -399,7 +399,7 @@ class HatchetClient {
|
|
|
399
399
|
*/
|
|
400
400
|
get workflows() {
|
|
401
401
|
if (!this._workflows) {
|
|
402
|
-
this._workflows = new
|
|
402
|
+
this._workflows = new features_1.WorkflowsClient(this);
|
|
403
403
|
}
|
|
404
404
|
return this._workflows;
|
|
405
405
|
}
|
|
@@ -416,7 +416,7 @@ class HatchetClient {
|
|
|
416
416
|
*/
|
|
417
417
|
get workers() {
|
|
418
418
|
if (!this._workers) {
|
|
419
|
-
this._workers = new
|
|
419
|
+
this._workers = new features_1.WorkersClient(this);
|
|
420
420
|
}
|
|
421
421
|
return this._workers;
|
|
422
422
|
}
|
|
@@ -445,13 +445,7 @@ class HatchetClient {
|
|
|
445
445
|
* @returns A promise that resolves with a new HatchetWorker instance
|
|
446
446
|
*/
|
|
447
447
|
worker(name, options) {
|
|
448
|
-
|
|
449
|
-
if (typeof options === 'number') {
|
|
450
|
-
opts = { slots: options };
|
|
451
|
-
}
|
|
452
|
-
else {
|
|
453
|
-
opts = options || {};
|
|
454
|
-
}
|
|
448
|
+
const opts = typeof options === 'number' ? { slots: options } : (options !== null && options !== void 0 ? options : {});
|
|
455
449
|
return worker_1.Worker.create(this, name, opts);
|
|
456
450
|
}
|
|
457
451
|
runRef(id) {
|
package/v1/client/duration.d.ts
CHANGED
|
@@ -3,5 +3,15 @@ type MinutesDuration = `${number}m`;
|
|
|
3
3
|
type HoursDuration = `${number}h`;
|
|
4
4
|
type TwoUnitDurations = `${number}h${number}m` | `${number}h${number}s` | `${number}m${number}s`;
|
|
5
5
|
type ThreeUnitDurations = `${number}h${number}m${number}s`;
|
|
6
|
-
|
|
6
|
+
type DurationString = SecondsDuration | MinutesDuration | HoursDuration | TwoUnitDurations | ThreeUnitDurations;
|
|
7
|
+
export interface DurationObject {
|
|
8
|
+
hours?: number;
|
|
9
|
+
minutes?: number;
|
|
10
|
+
seconds?: number;
|
|
11
|
+
}
|
|
12
|
+
/** A number is treated as milliseconds. */
|
|
13
|
+
export type Duration = DurationString | DurationObject | number;
|
|
14
|
+
/** Normalizes a Duration to Go-style string format (e.g. "1h30m5s"). */
|
|
15
|
+
export declare function durationToString(d: Duration): string;
|
|
16
|
+
export declare function durationToMs(d: Duration): number;
|
|
7
17
|
export {};
|
package/v1/client/duration.js
CHANGED
|
@@ -1,2 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.durationToString = durationToString;
|
|
4
|
+
exports.durationToMs = durationToMs;
|
|
5
|
+
const DURATION_RE = /^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/;
|
|
6
|
+
/** Normalizes a Duration to Go-style string format (e.g. "1h30m5s"). */
|
|
7
|
+
function durationToString(d) {
|
|
8
|
+
if (typeof d === 'string')
|
|
9
|
+
return d;
|
|
10
|
+
if (typeof d === 'number') {
|
|
11
|
+
const totalSeconds = Math.floor(d / 1000);
|
|
12
|
+
const h = Math.floor(totalSeconds / 3600);
|
|
13
|
+
const m = Math.floor((totalSeconds % 3600) / 60);
|
|
14
|
+
const s = totalSeconds % 60;
|
|
15
|
+
let out = '';
|
|
16
|
+
if (h)
|
|
17
|
+
out += `${h}h`;
|
|
18
|
+
if (m)
|
|
19
|
+
out += `${m}m`;
|
|
20
|
+
if (s || !out)
|
|
21
|
+
out += `${s}s`;
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
let s = '';
|
|
25
|
+
if (d.hours)
|
|
26
|
+
s += `${d.hours}h`;
|
|
27
|
+
if (d.minutes)
|
|
28
|
+
s += `${d.minutes}m`;
|
|
29
|
+
if (d.seconds)
|
|
30
|
+
s += `${d.seconds}s`;
|
|
31
|
+
return s || '0s';
|
|
32
|
+
}
|
|
33
|
+
function durationToMs(d) {
|
|
34
|
+
var _a, _b, _c;
|
|
35
|
+
if (typeof d === 'number')
|
|
36
|
+
return d;
|
|
37
|
+
if (typeof d === 'object') {
|
|
38
|
+
return (((_a = d.hours) !== null && _a !== void 0 ? _a : 0) * 3600 + ((_b = d.minutes) !== null && _b !== void 0 ? _b : 0) * 60 + ((_c = d.seconds) !== null && _c !== void 0 ? _c : 0)) * 1000;
|
|
39
|
+
}
|
|
40
|
+
const match = d.match(DURATION_RE);
|
|
41
|
+
if (!match) {
|
|
42
|
+
throw new Error(`Invalid duration string: "${d}". Expected format like "1h30m5s", "10m", "30s".`);
|
|
43
|
+
}
|
|
44
|
+
const [, h, m, s] = match;
|
|
45
|
+
return ((parseInt(h !== null && h !== void 0 ? h : '0', 10) * 3600 + parseInt(m !== null && m !== void 0 ? m : '0', 10) * 60 + parseInt(s !== null && s !== void 0 ? s : '0', 10)) * 1000);
|
|
46
|
+
}
|
|
@@ -51,7 +51,7 @@ class CELClient {
|
|
|
51
51
|
}
|
|
52
52
|
catch (err) {
|
|
53
53
|
if (err instanceof axios_1.AxiosError) {
|
|
54
|
-
throw new Error(JSON.stringify((_a = err.response) === null || _a === void 0 ? void 0 : _a.data.errors));
|
|
54
|
+
throw new Error(JSON.stringify((_a = err.response) === null || _a === void 0 ? void 0 : _a.data.errors), { cause: err });
|
|
55
55
|
}
|
|
56
56
|
throw err;
|
|
57
57
|
}
|
|
@@ -84,10 +84,10 @@ class CronClient {
|
|
|
84
84
|
}
|
|
85
85
|
catch (err) {
|
|
86
86
|
if (err instanceof zod_1.z.ZodError) {
|
|
87
|
-
throw new Error(`Invalid cron input: ${err.message}
|
|
87
|
+
throw new Error(`Invalid cron input: ${err.message}`, { cause: err });
|
|
88
88
|
}
|
|
89
89
|
if (err instanceof axios_1.AxiosError) {
|
|
90
|
-
throw new Error(JSON.stringify((_c = err.response) === null || _c === void 0 ? void 0 : _c.data.errors));
|
|
90
|
+
throw new Error(JSON.stringify((_c = err.response) === null || _c === void 0 ? void 0 : _c.data.errors), { cause: err });
|
|
91
91
|
}
|
|
92
92
|
throw err;
|
|
93
93
|
}
|
|
@@ -21,3 +21,8 @@ __exportStar(require("./runs"), exports);
|
|
|
21
21
|
__exportStar(require("./workers"), exports);
|
|
22
22
|
__exportStar(require("./workflows"), exports);
|
|
23
23
|
__exportStar(require("./schedules"), exports);
|
|
24
|
+
__exportStar(require("./logs"), exports);
|
|
25
|
+
__exportStar(require("./filters"), exports);
|
|
26
|
+
__exportStar(require("./tenant"), exports);
|
|
27
|
+
__exportStar(require("./webhooks"), exports);
|
|
28
|
+
__exportStar(require("./cel"), exports);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { V1LogLineLevel, V1LogLineOrderByDirection } from '../../../clients/rest/generated/data-contracts';
|
|
2
|
+
import { HatchetClient } from '../client';
|
|
3
|
+
/**
|
|
4
|
+
* The options for the list logs operation.
|
|
5
|
+
*/
|
|
6
|
+
export type ListLogsOpts = {
|
|
7
|
+
/** The maximum number of log lines to return. */
|
|
8
|
+
limit?: number;
|
|
9
|
+
/** Return only logs after this date. */
|
|
10
|
+
since?: Date;
|
|
11
|
+
/** Return only logs before this date. */
|
|
12
|
+
until?: Date;
|
|
13
|
+
/** Filter logs by a search string. */
|
|
14
|
+
search?: string;
|
|
15
|
+
/** Filter logs by log level. */
|
|
16
|
+
levels?: V1LogLineLevel[];
|
|
17
|
+
/** The direction to order the logs by. */
|
|
18
|
+
orderByDirection?: V1LogLineOrderByDirection;
|
|
19
|
+
/** Filter logs by attempt number. */
|
|
20
|
+
attempt?: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The logs client is a client for interacting with Hatchet's logs API.
|
|
24
|
+
*/
|
|
25
|
+
export declare class LogsClient {
|
|
26
|
+
tenantId: string;
|
|
27
|
+
api: HatchetClient['api'];
|
|
28
|
+
constructor(client: HatchetClient);
|
|
29
|
+
/**
|
|
30
|
+
* Lists the logs for a given task run.
|
|
31
|
+
* @param taskRunId - The ID of the task run to list logs for.
|
|
32
|
+
* @param opts - The options filter for the list operation.
|
|
33
|
+
* @returns A promise that resolves to the list of logs.
|
|
34
|
+
*/
|
|
35
|
+
list(taskRunId: string, opts?: ListLogsOpts): Promise<import("../../../clients/rest/generated/data-contracts").V1LogLineList>;
|
|
36
|
+
}
|
|
37
|
+
export { V1LogLineLevel, V1LogLineOrderByDirection };
|
|
@@ -0,0 +1,46 @@
|
|
|
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.V1LogLineOrderByDirection = exports.V1LogLineLevel = exports.LogsClient = void 0;
|
|
13
|
+
const data_contracts_1 = require("../../../clients/rest/generated/data-contracts");
|
|
14
|
+
Object.defineProperty(exports, "V1LogLineLevel", { enumerable: true, get: function () { return data_contracts_1.V1LogLineLevel; } });
|
|
15
|
+
Object.defineProperty(exports, "V1LogLineOrderByDirection", { enumerable: true, get: function () { return data_contracts_1.V1LogLineOrderByDirection; } });
|
|
16
|
+
/**
|
|
17
|
+
* The logs client is a client for interacting with Hatchet's logs API.
|
|
18
|
+
*/
|
|
19
|
+
class LogsClient {
|
|
20
|
+
constructor(client) {
|
|
21
|
+
this.api = client.api;
|
|
22
|
+
this.tenantId = client.tenantId;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Lists the logs for a given task run.
|
|
26
|
+
* @param taskRunId - The ID of the task run to list logs for.
|
|
27
|
+
* @param opts - The options filter for the list operation.
|
|
28
|
+
* @returns A promise that resolves to the list of logs.
|
|
29
|
+
*/
|
|
30
|
+
list(taskRunId, opts) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
const { data } = yield this.api.v1LogLineList(taskRunId, {
|
|
34
|
+
limit: opts === null || opts === void 0 ? void 0 : opts.limit,
|
|
35
|
+
since: (_a = opts === null || opts === void 0 ? void 0 : opts.since) === null || _a === void 0 ? void 0 : _a.toISOString(),
|
|
36
|
+
until: (_b = opts === null || opts === void 0 ? void 0 : opts.until) === null || _b === void 0 ? void 0 : _b.toISOString(),
|
|
37
|
+
search: opts === null || opts === void 0 ? void 0 : opts.search,
|
|
38
|
+
levels: opts === null || opts === void 0 ? void 0 : opts.levels,
|
|
39
|
+
order_by_direction: opts === null || opts === void 0 ? void 0 : opts.orderByDirection,
|
|
40
|
+
attempt: opts === null || opts === void 0 ? void 0 : opts.attempt,
|
|
41
|
+
});
|
|
42
|
+
return data;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.LogsClient = LogsClient;
|
|
@@ -106,10 +106,23 @@ export declare class RunsClient {
|
|
|
106
106
|
private prepareFilter;
|
|
107
107
|
private prepareListFilter;
|
|
108
108
|
/**
|
|
109
|
-
*
|
|
110
|
-
* @param
|
|
111
|
-
* @returns A promise that resolves to the run reference.
|
|
109
|
+
* Restore an evicted durable task so it can resume execution.
|
|
110
|
+
* @param taskExternalId - The external ID of the evicted task.
|
|
112
111
|
*/
|
|
112
|
+
restoreTask(taskExternalId: string): Promise<import("axios").AxiosResponse<import("../../../clients/rest/generated/data-contracts").V1RestoreTaskResponse, any, {}>>;
|
|
113
|
+
/**
|
|
114
|
+
* Fork (reset) a durable task from a specific node, triggering re-execution from that point.
|
|
115
|
+
* @param taskExternalId - The external ID of the durable task to reset.
|
|
116
|
+
* @param nodeId - The node ID to replay from.
|
|
117
|
+
*/
|
|
118
|
+
branchDurableTask(taskExternalId: string, nodeId: number, branchId?: number): Promise<import("axios").AxiosResponse<import("../../../clients/rest/generated/data-contracts").V1BranchDurableTaskResponse, any, {}>>;
|
|
119
|
+
/**
|
|
120
|
+
* Resolve the task external ID for a workflow run. For runs with multiple tasks,
|
|
121
|
+
* returns the first task's external ID.
|
|
122
|
+
* @param workflowRunId - The workflow run ID to look up.
|
|
123
|
+
* @returns The task external ID.
|
|
124
|
+
*/
|
|
125
|
+
getTaskExternalId(workflowRunId: string): Promise<string>;
|
|
113
126
|
runRef<T extends Record<string, any> = any>(id: string): WorkflowRunRef<T>;
|
|
114
127
|
/**
|
|
115
128
|
* Subscribes to a stream of events for a task or workflow run by its ID.
|
|
@@ -43,7 +43,6 @@ class RunsClient {
|
|
|
43
43
|
this.api = client.api;
|
|
44
44
|
this.tenantId = client.tenantId;
|
|
45
45
|
this.workflows = client.workflows;
|
|
46
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
47
46
|
this.listener = client._listener;
|
|
48
47
|
}
|
|
49
48
|
/**
|
|
@@ -148,10 +147,45 @@ class RunsClient {
|
|
|
148
147
|
});
|
|
149
148
|
}
|
|
150
149
|
/**
|
|
151
|
-
*
|
|
152
|
-
* @param
|
|
153
|
-
* @returns A promise that resolves to the run reference.
|
|
150
|
+
* Restore an evicted durable task so it can resume execution.
|
|
151
|
+
* @param taskExternalId - The external ID of the evicted task.
|
|
154
152
|
*/
|
|
153
|
+
restoreTask(taskExternalId) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
return this.api.v1TaskRestore(taskExternalId);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Fork (reset) a durable task from a specific node, triggering re-execution from that point.
|
|
160
|
+
* @param taskExternalId - The external ID of the durable task to reset.
|
|
161
|
+
* @param nodeId - The node ID to replay from.
|
|
162
|
+
*/
|
|
163
|
+
branchDurableTask(taskExternalId_1, nodeId_1) {
|
|
164
|
+
return __awaiter(this, arguments, void 0, function* (taskExternalId, nodeId, branchId = 0) {
|
|
165
|
+
return this.api.v1DurableTaskBranch(this.tenantId, {
|
|
166
|
+
taskExternalId,
|
|
167
|
+
nodeId,
|
|
168
|
+
branchId,
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Resolve the task external ID for a workflow run. For runs with multiple tasks,
|
|
174
|
+
* returns the first task's external ID.
|
|
175
|
+
* @param workflowRunId - The workflow run ID to look up.
|
|
176
|
+
* @returns The task external ID.
|
|
177
|
+
*/
|
|
178
|
+
getTaskExternalId(workflowRunId) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
var _a;
|
|
181
|
+
const run = yield this.get(workflowRunId);
|
|
182
|
+
const tasks = run === null || run === void 0 ? void 0 : run.tasks;
|
|
183
|
+
if (Array.isArray(tasks) && tasks.length > 0 && ((_a = tasks[0]) === null || _a === void 0 ? void 0 : _a.taskExternalId)) {
|
|
184
|
+
return tasks[0].taskExternalId;
|
|
185
|
+
}
|
|
186
|
+
throw new Error(`Could not find task external ID for workflow run ${workflowRunId}`);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
155
189
|
runRef(id) {
|
|
156
190
|
return new workflow_run_ref_1.default(id, this.listener, this);
|
|
157
191
|
}
|
|
@@ -89,10 +89,10 @@ class ScheduleClient {
|
|
|
89
89
|
}
|
|
90
90
|
catch (err) {
|
|
91
91
|
if (err instanceof zod_1.z.ZodError) {
|
|
92
|
-
throw new Error(`Invalid cron input: ${err.message}
|
|
92
|
+
throw new Error(`Invalid cron input: ${err.message}`, { cause: err });
|
|
93
93
|
}
|
|
94
94
|
if (err instanceof axios_1.AxiosError) {
|
|
95
|
-
throw new Error(JSON.stringify((_c = err.response) === null || _c === void 0 ? void 0 : _c.data.errors));
|
|
95
|
+
throw new Error(JSON.stringify((_c = err.response) === null || _c === void 0 ? void 0 : _c.data.errors), { cause: err });
|
|
96
96
|
}
|
|
97
97
|
throw err;
|
|
98
98
|
}
|
|
@@ -117,10 +117,10 @@ class ScheduleClient {
|
|
|
117
117
|
}
|
|
118
118
|
catch (err) {
|
|
119
119
|
if (err instanceof zod_1.z.ZodError) {
|
|
120
|
-
throw new Error(`Invalid update input: ${err.message}
|
|
120
|
+
throw new Error(`Invalid update input: ${err.message}`, { cause: err });
|
|
121
121
|
}
|
|
122
122
|
if (err instanceof axios_1.AxiosError) {
|
|
123
|
-
throw new Error(JSON.stringify((_a = err.response) === null || _a === void 0 ? void 0 : _a.data.errors));
|
|
123
|
+
throw new Error(JSON.stringify((_a = err.response) === null || _a === void 0 ? void 0 : _a.data.errors), { cause: err });
|
|
124
124
|
}
|
|
125
125
|
throw err;
|
|
126
126
|
}
|
|
@@ -23,10 +23,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
23
23
|
exports.WebhooksClient = void 0;
|
|
24
24
|
const data_contracts_1 = require("../../../clients/rest/generated/data-contracts");
|
|
25
25
|
function getAuthType(auth) {
|
|
26
|
-
if ('username' in auth && 'password' in auth)
|
|
26
|
+
if ('username' in auth && 'password' in auth) {
|
|
27
27
|
return data_contracts_1.V1WebhookAuthType.BASIC;
|
|
28
|
-
|
|
28
|
+
}
|
|
29
|
+
if ('headerName' in auth && 'apiKey' in auth) {
|
|
29
30
|
return data_contracts_1.V1WebhookAuthType.API_KEY;
|
|
31
|
+
}
|
|
30
32
|
if ('signingSecret' in auth &&
|
|
31
33
|
'signatureHeaderName' in auth &&
|
|
32
34
|
'algorithm' in auth &&
|