@hatchet-dev/typescript-sdk 1.13.0 → 1.14.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/clients/dispatcher/dispatcher-client.d.ts +1 -1
- package/clients/dispatcher/heartbeat/heartbeat-controller.js +13 -1
- package/clients/dispatcher/heartbeat/heartbeat-worker.js +4 -3
- package/clients/event/event-client.d.ts +1 -2
- package/clients/event/event-client.js +2 -2
- package/clients/hatchet-client/client-config.d.ts +15 -5
- package/clients/hatchet-client/client-config.js +3 -0
- package/clients/hatchet-client/hatchet-logger.js +1 -0
- package/clients/hatchet-client/index.d.ts +1 -1
- package/clients/hatchet-client/index.js +1 -1
- package/clients/listeners/durable-listener/durable-listener-client.d.ts +6 -0
- package/clients/listeners/durable-listener/durable-listener-client.js +8 -0
- package/clients/listeners/durable-listener/pooled-durable-listener-client.d.ts +9 -2
- package/clients/listeners/durable-listener/pooled-durable-listener-client.js +67 -15
- package/clients/listeners/run-listener/child-listener-client.js +1 -0
- package/clients/listeners/run-listener/pooled-child-listener-client.d.ts +10 -2
- package/clients/listeners/run-listener/pooled-child-listener-client.js +63 -7
- package/clients/rest/api.js +10 -2
- package/clients/rest/generated/Api.d.ts +2 -2
- package/clients/rest/generated/data-contracts.d.ts +6 -0
- package/index.d.ts +2 -3
- package/index.js +2 -3
- package/{examples → legacy/examples}/affinity-workers.js +2 -2
- package/{examples → legacy/examples}/bulk-fanout-trigger.js +1 -1
- package/{examples → legacy/examples}/bulk-fanout-worker.js +1 -1
- package/{examples → legacy/examples}/bulk-trigger.js +1 -1
- package/{examples → legacy/examples}/byo-logger.js +1 -1
- package/{examples → legacy/examples}/concurrency/cancel-in-progress/concurrency-event.js +1 -1
- package/{examples → legacy/examples}/concurrency/cancel-in-progress/concurrency-worker.js +1 -1
- package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-event.js +1 -1
- package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-worker-expression.js +2 -2
- package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-worker-key-fn.js +2 -2
- package/{examples → legacy/examples}/crons/cron-worker.d.ts +1 -1
- package/{examples → legacy/examples}/crons/cron-worker.js +1 -1
- package/{examples → legacy/examples}/crons/programatic-crons.js +1 -1
- package/{examples → legacy/examples}/dag-worker.js +1 -1
- package/{examples → legacy/examples}/example-event-with-results.js +2 -2
- package/{examples → legacy/examples}/example-event.js +1 -1
- package/{examples → legacy/examples}/fanout-worker.js +1 -1
- package/{examples → legacy/examples}/logger.js +1 -1
- package/{examples → legacy/examples}/manual-trigger.js +1 -1
- package/{examples → legacy/examples}/multi-workflow.js +1 -1
- package/{examples → legacy/examples}/namespaced-worker.js +1 -1
- package/{examples → legacy/examples}/on-failure.js +1 -1
- package/{examples → legacy/examples}/rate-limit/events.js +1 -1
- package/{examples → legacy/examples}/rate-limit/worker.js +2 -2
- package/{examples → legacy/examples}/retries-with-backoff.js +1 -1
- package/{examples → legacy/examples}/retries-worker.js +1 -1
- package/{examples → legacy/examples}/scheduled-runs/programatic-schedules.js +1 -1
- package/{examples → legacy/examples}/simple-worker.d.ts +1 -1
- package/{examples → legacy/examples}/simple-worker.js +1 -1
- package/{examples → legacy/examples}/sticky-trigger.js +1 -1
- package/{examples → legacy/examples}/sticky-worker-with-check.js +2 -2
- package/{examples → legacy/examples}/sticky-worker.js +2 -2
- package/{examples → legacy/examples}/stream-by-additional-meta.js +2 -2
- package/legacy/legacy-client.d.ts +30 -0
- package/legacy/legacy-client.js +67 -0
- package/legacy/legacy-transformer.d.ts +38 -0
- package/legacy/legacy-transformer.js +181 -0
- package/legacy/step.d.ts +429 -0
- package/legacy/step.js +662 -0
- package/legacy/workflow.d.ts +488 -0
- package/legacy/workflow.js +72 -0
- package/package.json +7 -7
- package/step.d.ts +1 -430
- package/step.js +6 -647
- package/util/abort-error.d.ts +38 -0
- package/util/abort-error.js +58 -0
- package/util/hatchet-promise/hatchet-promise.d.ts +8 -1
- package/util/hatchet-promise/hatchet-promise.js +3 -2
- package/util/logger/index.d.ts +1 -0
- package/util/logger/index.js +1 -0
- package/util/logger/task-run-log.d.ts +3 -0
- package/util/logger/task-run-log.js +20 -0
- package/util/sleep.d.ts +5 -2
- package/util/sleep.js +27 -4
- package/util/workflow-run-ref.d.ts +7 -1
- package/util/workflow-run-ref.js +5 -3
- package/v1/client/admin.d.ts +8 -1
- package/v1/client/admin.js +22 -6
- package/v1/client/client.d.ts +36 -18
- package/v1/client/client.interface.d.ts +9 -2
- package/v1/client/client.js +47 -27
- package/v1/client/features/crons.d.ts +3 -3
- package/v1/client/features/crons.js +2 -2
- package/v1/client/features/schedules.js +2 -2
- package/v1/client/features/workflows.d.ts +5 -5
- package/v1/client/features/workflows.js +7 -8
- package/v1/client/worker/context.d.ts +49 -10
- package/v1/client/worker/context.js +92 -20
- package/v1/client/worker/deprecated/legacy-v1-worker.d.ts +3 -3
- package/v1/client/worker/deprecated/legacy-v1-worker.js +2 -2
- package/v1/client/worker/deprecated/legacy-worker.js +9 -7
- package/v1/client/worker/slot-utils.d.ts +3 -3
- package/v1/client/worker/worker-internal.d.ts +7 -16
- package/v1/client/worker/worker-internal.js +225 -209
- package/v1/client/worker/worker.d.ts +18 -18
- package/v1/client/worker/worker.js +45 -30
- package/v1/declaration.d.ts +28 -7
- package/v1/declaration.js +56 -6
- package/v1/examples/__e2e__/harness.d.ts +19 -0
- package/v1/examples/__e2e__/harness.js +70 -0
- package/v1/examples/affinity/affinity-workers.js +4 -4
- package/v1/examples/bulk_fanout/workflow.d.ts +9 -0
- package/v1/examples/bulk_fanout/workflow.js +34 -0
- package/v1/examples/bulk_operations/workflow.d.ts +3 -0
- package/v1/examples/bulk_operations/workflow.js +44 -0
- package/v1/examples/cancellation/cancellation-workflow.d.ts +2 -0
- package/v1/examples/cancellation/cancellation-workflow.js +69 -0
- package/v1/examples/cancellation/run.js +53 -0
- package/v1/examples/cancellation/worker.d.ts +1 -0
- package/v1/examples/cancellation/worker.js +29 -0
- package/v1/examples/concurrency-types.d.ts +5 -0
- package/v1/examples/concurrency-types.js +2 -0
- package/v1/examples/concurrency_cancel_in_progress/workflow.d.ts +9 -0
- package/v1/examples/concurrency_cancel_in_progress/workflow.js +45 -0
- package/v1/examples/concurrency_cancel_newest/workflow.d.ts +9 -0
- package/v1/examples/concurrency_cancel_newest/workflow.js +45 -0
- package/v1/examples/concurrency_limit_rr/load.d.ts +1 -0
- package/v1/examples/concurrency_limit_rr/load.js +54 -0
- package/v1/examples/concurrency_limit_rr/run.d.ts +1 -0
- package/v1/examples/concurrency_limit_rr/run.js +39 -0
- package/v1/examples/concurrency_limit_rr/worker.d.ts +1 -0
- package/v1/examples/concurrency_limit_rr/worker.js +24 -0
- package/v1/examples/concurrency_limit_rr/workflow.d.ts +12 -0
- package/v1/examples/concurrency_limit_rr/workflow.js +62 -0
- package/v1/examples/concurrency_multiple_keys/workflow.d.ts +12 -0
- package/v1/examples/concurrency_multiple_keys/workflow.js +42 -0
- package/v1/examples/concurrency_workflow_level/workflow.d.ts +13 -0
- package/v1/examples/concurrency_workflow_level/workflow.js +49 -0
- package/v1/examples/conditions/complex-workflow.d.ts +1 -0
- package/v1/examples/conditions/complex-workflow.js +107 -0
- package/v1/examples/conditions/event.d.ts +1 -0
- package/v1/examples/conditions/event.js +28 -0
- package/v1/examples/conditions/run.d.ts +1 -0
- package/v1/examples/conditions/run.js +25 -0
- package/v1/examples/conditions/worker.d.ts +1 -0
- package/v1/examples/conditions/worker.js +24 -0
- package/v1/examples/conditions/workflow.d.ts +11 -0
- package/v1/examples/conditions/workflow.js +41 -0
- package/v1/examples/durable/workflow.d.ts +7 -0
- package/v1/examples/durable/workflow.js +116 -0
- package/v1/examples/durable_event/event.d.ts +1 -0
- package/v1/examples/durable_event/event.js +28 -0
- package/v1/examples/durable_event/run.d.ts +1 -0
- package/v1/examples/durable_event/run.js +30 -0
- package/v1/examples/durable_event/worker.d.ts +1 -0
- package/v1/examples/durable_event/worker.js +24 -0
- package/v1/examples/durable_event/workflow.d.ts +6 -0
- package/v1/examples/durable_event/workflow.js +46 -0
- package/v1/examples/durable_sleep/event.d.ts +1 -0
- package/v1/examples/durable_sleep/event.js +28 -0
- package/v1/examples/durable_sleep/run.d.ts +1 -0
- package/v1/examples/durable_sleep/run.js +30 -0
- package/v1/examples/durable_sleep/worker.d.ts +1 -0
- package/v1/examples/durable_sleep/worker.js +24 -0
- package/v1/examples/durable_sleep/workflow.d.ts +1 -0
- package/v1/examples/durable_sleep/workflow.js +31 -0
- package/v1/examples/e2e-worker.d.ts +1 -0
- package/v1/examples/e2e-worker.js +82 -0
- package/v1/examples/events/event.d.ts +1 -0
- package/v1/examples/events/event.js +53 -0
- package/v1/examples/events/filter.d.ts +1 -0
- package/v1/examples/events/filter.js +32 -0
- package/v1/examples/events/worker.d.ts +1 -0
- package/v1/examples/events/worker.js +24 -0
- package/v1/examples/events/workflow.d.ts +19 -0
- package/v1/examples/events/workflow.js +60 -0
- package/v1/examples/high-memory/workflow-with-child.js +1 -1
- package/v1/examples/logger/byo-logger.d.ts +1 -0
- package/v1/examples/logger/byo-logger.js +73 -0
- package/v1/examples/logger/logger.d.ts +1 -0
- package/v1/examples/logger/logger.js +46 -0
- package/v1/examples/logger/workflow.d.ts +2 -0
- package/v1/examples/logger/workflow.js +38 -0
- package/v1/examples/multiple_wf_concurrency/workflow.js +3 -3
- package/v1/examples/on_failure/workflow.d.ts +1 -0
- package/v1/examples/on_failure/workflow.js +12 -7
- package/v1/examples/priority/workflow.js +1 -1
- package/v1/examples/retries/workflow.js +2 -2
- package/v1/examples/return_exceptions/workflow.d.ts +6 -0
- package/v1/examples/return_exceptions/workflow.js +22 -0
- package/v1/examples/run_details/workflow.d.ts +4 -0
- package/v1/examples/run_details/workflow.js +65 -0
- package/v1/examples/simple/e2e-workflows.d.ts +14 -0
- package/v1/examples/simple/e2e-workflows.js +27 -0
- package/v1/examples/simple/enqueue.js +2 -2
- package/v1/examples/sticky/workflow.js +2 -2
- package/v1/examples/timeout/run.d.ts +1 -0
- package/v1/examples/timeout/run.js +30 -0
- package/v1/examples/timeout/worker.d.ts +1 -0
- package/v1/examples/timeout/worker.js +25 -0
- package/v1/examples/timeout/workflow.d.ts +10 -0
- package/v1/examples/timeout/workflow.js +56 -0
- package/v1/examples/webhooks/workflow.d.ts +5 -0
- package/v1/examples/webhooks/workflow.js +23 -0
- package/v1/index.d.ts +1 -0
- package/v1/index.js +1 -0
- package/v1/parent-run-context-vars.d.ts +6 -0
- package/v1/parent-run-context-vars.js +3 -0
- package/v1/task.d.ts +22 -7
- package/v1/task.js +4 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/workflow.d.ts +3 -491
- package/workflow.js +12 -62
- package/clients/hatchet-client/hatchet-client.d.ts +0 -35
- package/clients/hatchet-client/hatchet-client.js +0 -108
- package/clients/worker/handler.d.ts +0 -50
- package/clients/worker/handler.js +0 -214
- package/clients/worker/index.d.ts +0 -1
- package/clients/worker/index.js +0 -17
- package/clients/worker/worker.d.ts +0 -59
- package/clients/worker/worker.js +0 -568
- package/examples/webhooks.js +0 -45
- /package/{examples → legacy/examples}/affinity-workers.d.ts +0 -0
- /package/{examples → legacy/examples}/bulk-fanout-trigger.d.ts +0 -0
- /package/{examples → legacy/examples}/bulk-fanout-worker.d.ts +0 -0
- /package/{examples → legacy/examples}/bulk-trigger.d.ts +0 -0
- /package/{examples → legacy/examples}/byo-logger.d.ts +0 -0
- /package/{examples → legacy/examples}/concurrency/cancel-in-progress/concurrency-event.d.ts +0 -0
- /package/{examples → legacy/examples}/concurrency/cancel-in-progress/concurrency-worker.d.ts +0 -0
- /package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-event.d.ts +0 -0
- /package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-worker-expression.d.ts +0 -0
- /package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-worker-key-fn.d.ts +0 -0
- /package/{examples → legacy/examples}/crons/programatic-crons.d.ts +0 -0
- /package/{examples → legacy/examples}/dag-worker.d.ts +0 -0
- /package/{examples → legacy/examples}/example-event-with-results.d.ts +0 -0
- /package/{examples → legacy/examples}/example-event.d.ts +0 -0
- /package/{examples → legacy/examples}/fanout-worker.d.ts +0 -0
- /package/{examples → legacy/examples}/logger.d.ts +0 -0
- /package/{examples → legacy/examples}/manual-trigger.d.ts +0 -0
- /package/{examples → legacy/examples}/multi-workflow.d.ts +0 -0
- /package/{examples → legacy/examples}/namespaced-worker.d.ts +0 -0
- /package/{examples → legacy/examples}/on-failure.d.ts +0 -0
- /package/{examples → legacy/examples}/rate-limit/events.d.ts +0 -0
- /package/{examples → legacy/examples}/rate-limit/worker.d.ts +0 -0
- /package/{examples → legacy/examples}/retries-with-backoff.d.ts +0 -0
- /package/{examples → legacy/examples}/retries-worker.d.ts +0 -0
- /package/{examples → legacy/examples}/scheduled-runs/programatic-schedules.d.ts +0 -0
- /package/{examples → legacy/examples}/sticky-trigger.d.ts +0 -0
- /package/{examples → legacy/examples}/sticky-worker-with-check.d.ts +0 -0
- /package/{examples → legacy/examples}/sticky-worker.d.ts +0 -0
- /package/{examples → legacy/examples}/stream-by-additional-meta.d.ts +0 -0
- /package/{examples/webhooks.d.ts → v1/examples/cancellation/run.d.ts} +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAbortError = createAbortError;
|
|
4
|
+
exports.isAbortError = isAbortError;
|
|
5
|
+
exports.rethrowIfAborted = rethrowIfAborted;
|
|
6
|
+
exports.throwIfAborted = throwIfAborted;
|
|
7
|
+
function createAbortError(message = 'Operation aborted') {
|
|
8
|
+
const err = new Error(message);
|
|
9
|
+
err.name = 'AbortError';
|
|
10
|
+
err.code = 'ABORT_ERR';
|
|
11
|
+
return err;
|
|
12
|
+
}
|
|
13
|
+
function isAbortError(err) {
|
|
14
|
+
return err instanceof Error && (err.name === 'AbortError' || err.code === 'ABORT_ERR');
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Helper to be used inside broad `catch` blocks so cancellation isn't accidentally swallowed.
|
|
18
|
+
*
|
|
19
|
+
* Example:
|
|
20
|
+
* ```ts
|
|
21
|
+
* try { ... } catch (e) { rethrowIfAborted(e); ... }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function rethrowIfAborted(err) {
|
|
25
|
+
if (isAbortError(err)) {
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Throws an AbortError if the provided signal is aborted.
|
|
31
|
+
*
|
|
32
|
+
* Notes:
|
|
33
|
+
* - In JS/TS, `catch` can swallow any thrown value, so this is best-effort.
|
|
34
|
+
* - We prefer throwing the signal's `reason` when it is already an Error.
|
|
35
|
+
*/
|
|
36
|
+
function throwIfAborted(signal, optsOrDefaultMessage = 'Operation cancelled by AbortSignal') {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
if (!(signal === null || signal === void 0 ? void 0 : signal.aborted)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const opts = typeof optsOrDefaultMessage === 'string'
|
|
42
|
+
? { defaultMessage: optsOrDefaultMessage }
|
|
43
|
+
: (optsOrDefaultMessage !== null && optsOrDefaultMessage !== void 0 ? optsOrDefaultMessage : {});
|
|
44
|
+
if (opts.isTrigger) {
|
|
45
|
+
const ctx = opts.context ? `${opts.context} ` : '';
|
|
46
|
+
(_a = opts.warn) === null || _a === void 0 ? void 0 : _a.call(opts, `Cancellation: ${ctx}attempted to enqueue/trigger work after cancellation was signaled. ` +
|
|
47
|
+
`This usually means an AbortError was caught and not propagated. ` +
|
|
48
|
+
`See https://docs.hatchet.run/home/cancellation`);
|
|
49
|
+
}
|
|
50
|
+
const { reason } = signal;
|
|
51
|
+
if (reason instanceof Error) {
|
|
52
|
+
throw reason;
|
|
53
|
+
}
|
|
54
|
+
if (typeof reason === 'string' && reason.length > 0) {
|
|
55
|
+
throw createAbortError(reason);
|
|
56
|
+
}
|
|
57
|
+
throw createAbortError((_b = opts.defaultMessage) !== null && _b !== void 0 ? _b : 'Operation cancelled by AbortSignal');
|
|
58
|
+
}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
declare class HatchetPromise<T> {
|
|
2
|
-
cancel:
|
|
2
|
+
cancel: (reason?: any) => void;
|
|
3
3
|
promise: Promise<T>;
|
|
4
|
+
/**
|
|
5
|
+
* The original (non-cancelable) promise passed to the constructor.
|
|
6
|
+
*
|
|
7
|
+
* `promise` is a cancelable wrapper which rejects immediately when `cancel` is called.
|
|
8
|
+
* `inner` continues executing and will settle when the underlying work completes.
|
|
9
|
+
*/
|
|
10
|
+
inner: Promise<T>;
|
|
4
11
|
constructor(promise: Promise<T>);
|
|
5
12
|
}
|
|
6
13
|
export default HatchetPromise;
|
|
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
class HatchetPromise {
|
|
4
4
|
constructor(promise) {
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
-
this.cancel = (
|
|
6
|
+
this.cancel = (_reason) => { };
|
|
7
|
+
this.inner = Promise.resolve(promise);
|
|
7
8
|
this.promise = new Promise((resolve, reject) => {
|
|
8
9
|
this.cancel = reject;
|
|
9
|
-
|
|
10
|
+
this.inner.then(resolve).catch(reject);
|
|
10
11
|
});
|
|
11
12
|
}
|
|
12
13
|
}
|
package/util/logger/index.d.ts
CHANGED
package/util/logger/index.js
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.actionMap = actionMap;
|
|
4
|
+
exports.taskRunLog = taskRunLog;
|
|
5
|
+
const dispatcher_1 = require("../../protoc/dispatcher");
|
|
6
|
+
function actionMap(action) {
|
|
7
|
+
switch (action) {
|
|
8
|
+
case dispatcher_1.ActionType.START_STEP_RUN:
|
|
9
|
+
return 'starting...';
|
|
10
|
+
case dispatcher_1.ActionType.CANCEL_STEP_RUN:
|
|
11
|
+
return 'cancelling...';
|
|
12
|
+
case dispatcher_1.ActionType.START_GET_GROUP_KEY:
|
|
13
|
+
return 'starting to get group key...';
|
|
14
|
+
default:
|
|
15
|
+
return 'unknown';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function taskRunLog(taskName, taskRunExternalId, action) {
|
|
19
|
+
return `Task run ${action} \t ${taskName}/${taskRunExternalId} `;
|
|
20
|
+
}
|
package/util/sleep.d.ts
CHANGED
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* WARNING: This is not a durable sleep. It will not be honored if the worker is
|
|
5
5
|
* restarted or crashes.
|
|
6
|
+
*
|
|
6
7
|
* @param ms - The number of milliseconds to sleep
|
|
7
|
-
* @
|
|
8
|
+
* @param signal - Optional AbortSignal; if aborted, the promise rejects with Error('Cancelled').
|
|
9
|
+
* Use in task handlers so cancellation can interrupt long sleeps.
|
|
10
|
+
* @returns A promise that resolves after the given number of milliseconds (or rejects on abort)
|
|
8
11
|
*/
|
|
9
|
-
declare
|
|
12
|
+
declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
10
13
|
export default sleep;
|
package/util/sleep.js
CHANGED
|
@@ -5,10 +5,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
*
|
|
6
6
|
* WARNING: This is not a durable sleep. It will not be honored if the worker is
|
|
7
7
|
* restarted or crashes.
|
|
8
|
+
*
|
|
8
9
|
* @param ms - The number of milliseconds to sleep
|
|
9
|
-
* @
|
|
10
|
+
* @param signal - Optional AbortSignal; if aborted, the promise rejects with Error('Cancelled').
|
|
11
|
+
* Use in task handlers so cancellation can interrupt long sleeps.
|
|
12
|
+
* @returns A promise that resolves after the given number of milliseconds (or rejects on abort)
|
|
10
13
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
function sleep(ms, signal) {
|
|
15
|
+
if (!signal) {
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
setTimeout(resolve, ms);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const timer = setTimeout(() => {
|
|
22
|
+
signal.removeEventListener('abort', onAbort);
|
|
23
|
+
resolve();
|
|
24
|
+
}, ms);
|
|
25
|
+
const onAbort = () => {
|
|
26
|
+
clearTimeout(timer);
|
|
27
|
+
reject(new Error('Cancelled'));
|
|
28
|
+
};
|
|
29
|
+
if (signal.aborted) {
|
|
30
|
+
clearTimeout(timer);
|
|
31
|
+
reject(new Error('Cancelled'));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
35
|
+
});
|
|
36
|
+
}
|
|
14
37
|
exports.default = sleep;
|
|
@@ -12,9 +12,15 @@ export default class WorkflowRunRef<T> {
|
|
|
12
12
|
private client;
|
|
13
13
|
private runs;
|
|
14
14
|
_standaloneTaskName?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Optional default AbortSignal used for listener-backed waits (e.g. `.result()`).
|
|
17
|
+
* This is primarily set when a run is spawned from within a task so cancellations propagate
|
|
18
|
+
* without manually threading `{ signal }` everywhere.
|
|
19
|
+
*/
|
|
20
|
+
defaultSignal?: AbortSignal;
|
|
15
21
|
constructor(workflowRunId: string | Promise<string> | Promise<{
|
|
16
22
|
workflowRunId: string;
|
|
17
|
-
}>, client: RunListenerClient, runsClient?: RunsClient, parentWorkflowRunId?: string, standaloneTaskName?: string);
|
|
23
|
+
}>, client: RunListenerClient, runsClient?: RunsClient, parentWorkflowRunId?: string, standaloneTaskName?: string, defaultSignal?: AbortSignal);
|
|
18
24
|
get runId(): Promise<string>;
|
|
19
25
|
getWorkflowRunId(): Promise<string>;
|
|
20
26
|
stream(): Promise<AsyncGenerator<StepRunEvent, void, unknown>>;
|
package/util/workflow-run-ref.js
CHANGED
|
@@ -50,12 +50,13 @@ function getWorkflowRunId(workflowRunId) {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
class WorkflowRunRef {
|
|
53
|
-
constructor(workflowRunId, client, runsClient, parentWorkflowRunId, standaloneTaskName) {
|
|
53
|
+
constructor(workflowRunId, client, runsClient, parentWorkflowRunId, standaloneTaskName, defaultSignal) {
|
|
54
54
|
this.workflowRunId = workflowRunId;
|
|
55
55
|
this.parentWorkflowRunId = parentWorkflowRunId;
|
|
56
56
|
this.client = client;
|
|
57
57
|
this.runs = runsClient;
|
|
58
58
|
this._standaloneTaskName = standaloneTaskName;
|
|
59
|
+
this.defaultSignal = defaultSignal;
|
|
59
60
|
}
|
|
60
61
|
// TODO docstrings
|
|
61
62
|
get runId() {
|
|
@@ -88,8 +89,9 @@ class WorkflowRunRef {
|
|
|
88
89
|
(() => __awaiter(this, void 0, void 0, function* () {
|
|
89
90
|
var _a, e_1, _b, _c;
|
|
90
91
|
var _d, _e;
|
|
92
|
+
const signal = this.defaultSignal;
|
|
91
93
|
try {
|
|
92
|
-
for (var _f = true, _g = __asyncValues(streamable.stream()), _h; _h = yield _g.next(), _a = _h.done, !_a; _f = true) {
|
|
94
|
+
for (var _f = true, _g = __asyncValues(streamable.stream({ signal })), _h; _h = yield _g.next(), _a = _h.done, !_a; _f = true) {
|
|
93
95
|
_c = _h.value;
|
|
94
96
|
_f = false;
|
|
95
97
|
const event = _c;
|
|
@@ -143,7 +145,7 @@ class WorkflowRunRef {
|
|
|
143
145
|
}
|
|
144
146
|
finally { if (e_1) throw e_1.error; }
|
|
145
147
|
}
|
|
146
|
-
}))();
|
|
148
|
+
}))().catch(reject);
|
|
147
149
|
});
|
|
148
150
|
});
|
|
149
151
|
}
|
package/v1/client/admin.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Priority, RateLimitDuration, RunsClient } from './..';
|
|
|
4
4
|
import { RunListenerClient } from '../../clients/listeners/run-listener/child-listener-client';
|
|
5
5
|
import { Api } from '../../clients/rest/generated/Api';
|
|
6
6
|
import { WorkflowServiceClient } from '../../protoc/workflows';
|
|
7
|
+
import { AdminServiceClient, CreateWorkflowVersionRequest } from '../../protoc/v1/workflows';
|
|
7
8
|
import { Logger } from '../../util/logger';
|
|
8
9
|
export type WorkflowRun<T = object> = {
|
|
9
10
|
workflowName: string;
|
|
@@ -28,11 +29,17 @@ export type WorkflowRun<T = object> = {
|
|
|
28
29
|
};
|
|
29
30
|
export declare class AdminClient {
|
|
30
31
|
config: ClientConfig;
|
|
31
|
-
|
|
32
|
+
workflowsGrpc: WorkflowServiceClient;
|
|
33
|
+
adminGrpc: AdminServiceClient;
|
|
32
34
|
listenerClient: RunListenerClient;
|
|
33
35
|
runs: RunsClient;
|
|
34
36
|
logger: Logger;
|
|
35
37
|
constructor(config: ClientConfig, api: Api, runs: RunsClient);
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new workflow or updates an existing workflow via the v1 admin service.
|
|
40
|
+
* @param workflow a workflow definition to create
|
|
41
|
+
*/
|
|
42
|
+
putWorkflow(workflow: CreateWorkflowVersionRequest): Promise<import("../../protoc/v1/workflows").CreateWorkflowVersionResponse>;
|
|
36
43
|
/**
|
|
37
44
|
* Run a new instance of a workflow with the given input. This will create a new workflow run and return the ID of the
|
|
38
45
|
* new run.
|
package/v1/client/admin.js
CHANGED
|
@@ -29,6 +29,7 @@ const workflow_run_ref_1 = __importDefault(require("../../util/workflow-run-ref"
|
|
|
29
29
|
const grpc_helpers_1 = require("../../util/grpc-helpers");
|
|
30
30
|
const child_listener_client_1 = require("../../clients/listeners/run-listener/child-listener-client");
|
|
31
31
|
const workflows_1 = require("../../protoc/workflows");
|
|
32
|
+
const workflows_2 = require("../../protoc/v1/workflows");
|
|
32
33
|
const retrier_1 = require("../../util/retrier");
|
|
33
34
|
const batch_1 = require("../../util/batch");
|
|
34
35
|
const apply_namespace_1 = require("../../util/apply-namespace");
|
|
@@ -37,10 +38,25 @@ class AdminClient {
|
|
|
37
38
|
this.config = config;
|
|
38
39
|
this.logger = config.logger(`Admin`, config.log_level);
|
|
39
40
|
const { client, channel, factory } = (0, grpc_helpers_1.createGrpcClient)(config, workflows_1.WorkflowServiceDefinition);
|
|
40
|
-
this.
|
|
41
|
+
this.workflowsGrpc = client;
|
|
42
|
+
this.adminGrpc = factory.create(workflows_2.AdminServiceDefinition, channel);
|
|
41
43
|
this.listenerClient = new child_listener_client_1.RunListenerClient(config, channel, factory, api);
|
|
42
44
|
this.runs = runs;
|
|
43
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new workflow or updates an existing workflow via the v1 admin service.
|
|
48
|
+
* @param workflow a workflow definition to create
|
|
49
|
+
*/
|
|
50
|
+
putWorkflow(workflow) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
try {
|
|
53
|
+
return yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.adminGrpc.putWorkflow(workflow); }), this.logger);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
throw new hatchet_error_1.default(e.message);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
44
60
|
/**
|
|
45
61
|
* Run a new instance of a workflow with the given input. This will create a new workflow run and return the ID of the
|
|
46
62
|
* new run.
|
|
@@ -52,14 +68,14 @@ class AdminClient {
|
|
|
52
68
|
runWorkflow(workflowName, input, options) {
|
|
53
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
70
|
try {
|
|
55
|
-
const computedName = (0, apply_namespace_1.applyNamespace)(workflowName, this.config.namespace);
|
|
71
|
+
const computedName = (0, apply_namespace_1.applyNamespace)(workflowName, this.config.namespace).toLowerCase();
|
|
56
72
|
const inputStr = JSON.stringify(input);
|
|
57
73
|
const opts = options !== null && options !== void 0 ? options : {};
|
|
58
74
|
const { additionalMetadata, parentStepRunId, parentTaskRunExternalId } = opts, rest = __rest(opts, ["additionalMetadata", "parentStepRunId", "parentTaskRunExternalId"]);
|
|
59
75
|
const request = Object.assign(Object.assign({ name: computedName, input: inputStr }, rest), {
|
|
60
76
|
// API expects `parentTaskRunExternalId`; accept old names as aliases.
|
|
61
77
|
parentTaskRunExternalId: parentTaskRunExternalId !== null && parentTaskRunExternalId !== void 0 ? parentTaskRunExternalId : parentStepRunId, additionalMetadata: additionalMetadata ? JSON.stringify(additionalMetadata) : undefined, priority: opts.priority });
|
|
62
|
-
const resp = yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.
|
|
78
|
+
const resp = yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.workflowsGrpc.triggerWorkflow(request); }), this.logger);
|
|
63
79
|
const id = resp.workflowRunId;
|
|
64
80
|
const ref = new workflow_run_ref_1.default(id, this.listenerClient, this.runs, options === null || options === void 0 ? void 0 : options.parentId,
|
|
65
81
|
// eslint-disable-next-line no-underscore-dangle
|
|
@@ -82,7 +98,7 @@ class AdminClient {
|
|
|
82
98
|
return __awaiter(this, arguments, void 0, function* (workflowRuns, batchSize = 500) {
|
|
83
99
|
// Prepare workflows to be triggered in bulk
|
|
84
100
|
const workflowRequests = workflowRuns.map(({ workflowName, input, options }) => {
|
|
85
|
-
const computedName = (0, apply_namespace_1.applyNamespace)(workflowName, this.config.namespace);
|
|
101
|
+
const computedName = (0, apply_namespace_1.applyNamespace)(workflowName, this.config.namespace).toLowerCase();
|
|
86
102
|
const inputStr = JSON.stringify(input);
|
|
87
103
|
const opts = options !== null && options !== void 0 ? options : {};
|
|
88
104
|
const { additionalMetadata, parentStepRunId, parentTaskRunExternalId } = opts, rest = __rest(opts, ["additionalMetadata", "parentStepRunId", "parentTaskRunExternalId"]);
|
|
@@ -101,7 +117,7 @@ class AdminClient {
|
|
|
101
117
|
workflows: payloads,
|
|
102
118
|
});
|
|
103
119
|
// Call the bulk trigger workflow method for this batch
|
|
104
|
-
const bulkTriggerWorkflowResponse = yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.
|
|
120
|
+
const bulkTriggerWorkflowResponse = yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.workflowsGrpc.bulkTriggerWorkflow(request); }), this.logger);
|
|
105
121
|
this.logger.debug(`batch ${batchIndex + 1} of ${batches.length}`);
|
|
106
122
|
// Map the results back to their original indices
|
|
107
123
|
const batchResults = bulkTriggerWorkflowResponse.workflowRunIds.map((resp, index) => {
|
|
@@ -127,7 +143,7 @@ class AdminClient {
|
|
|
127
143
|
limit,
|
|
128
144
|
duration,
|
|
129
145
|
};
|
|
130
|
-
yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.
|
|
146
|
+
yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.workflowsGrpc.putRateLimit(request); }), this.logger);
|
|
131
147
|
});
|
|
132
148
|
}
|
|
133
149
|
}
|
package/v1/client/client.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { ClientConfig, HatchetClientOptions, LegacyHatchetClient, TaskMiddleware, InferMiddlewareBefore, InferMiddlewareAfter } from '../../clients/hatchet-client';
|
|
2
2
|
import { AxiosRequestConfig } from 'axios';
|
|
3
3
|
import WorkflowRunRef from '../../util/workflow-run-ref';
|
|
4
|
-
import { Workflow as V0Workflow } from '../../workflow';
|
|
5
|
-
import { V0DurableContext } from '../../step';
|
|
6
4
|
import { Api } from '../../clients/rest';
|
|
5
|
+
import { EventClient } from '../../clients/event/event-client';
|
|
6
|
+
import { DispatcherClient } from '../../clients/dispatcher/dispatcher-client';
|
|
7
|
+
import { Logger } from '../../util/logger';
|
|
7
8
|
import { RunListenerClient } from '../../clients/listeners/run-listener/child-listener-client';
|
|
9
|
+
import { DurableListenerClient } from '../../clients/listeners/durable-listener/durable-listener-client';
|
|
8
10
|
import { CreateTaskWorkflowOpts, CreateWorkflowOpts, RunOpts, BaseWorkflowDeclaration, WorkflowDeclaration, TaskWorkflowDeclaration, CreateDurableTaskWorkflowOpts } from '../declaration';
|
|
11
|
+
import type { LegacyWorkflow } from '../../legacy/legacy-transformer';
|
|
9
12
|
import { IHatchetClient } from './client.interface';
|
|
10
13
|
import { CreateWorkerOpts, Worker } from './worker/worker';
|
|
11
14
|
import { MetricsClient } from './features/metrics';
|
|
@@ -21,6 +24,7 @@ import { CronClient } from './features/crons';
|
|
|
21
24
|
import { CELClient } from './features/cel';
|
|
22
25
|
import { TenantClient } from './features/tenant';
|
|
23
26
|
import { WebhooksClient } from './features/webhooks';
|
|
27
|
+
import { DurableContext } from './worker/context';
|
|
24
28
|
type MergeIfNonEmpty<Base, Extra extends Record<string, any>> = keyof Extra extends never ? Base : Base & Extra;
|
|
25
29
|
/**
|
|
26
30
|
* HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
|
|
@@ -31,16 +35,20 @@ type MergeIfNonEmpty<Base, Extra extends Record<string, any>> = keyof Extra exte
|
|
|
31
35
|
* @template MiddlewareAfter - Extra fields merged into task output by post-middleware hooks. Inferred from middleware config.
|
|
32
36
|
*/
|
|
33
37
|
export declare class HatchetClient<GlobalInput extends Record<string, any> = {}, GlobalOutput extends Record<string, any> = {}, MiddlewareBefore extends Record<string, any> = {}, MiddlewareAfter extends Record<string, any> = {}> implements IHatchetClient {
|
|
34
|
-
|
|
35
|
-
_v0: LegacyHatchetClient;
|
|
38
|
+
private _v0;
|
|
36
39
|
_api: Api;
|
|
37
40
|
_listener: RunListenerClient;
|
|
41
|
+
private _options;
|
|
42
|
+
private _axiosConfig;
|
|
43
|
+
private _clientFactory;
|
|
44
|
+
private _credentials;
|
|
38
45
|
/**
|
|
39
46
|
* @deprecated v0 client will be removed in a future release, please upgrade to v1
|
|
40
47
|
*/
|
|
41
48
|
get v0(): LegacyHatchetClient;
|
|
42
49
|
/** The tenant ID for the Hatchet client */
|
|
43
50
|
tenantId: string;
|
|
51
|
+
logger: Logger;
|
|
44
52
|
_isV1: boolean | undefined;
|
|
45
53
|
get isV1(): boolean;
|
|
46
54
|
/**
|
|
@@ -112,7 +120,7 @@ export declare class HatchetClient<GlobalInput extends Record<string, any> = {},
|
|
|
112
120
|
* @param options Durable task configuration options with function that defines types
|
|
113
121
|
* @returns A TaskWorkflowDeclaration instance with inferred types
|
|
114
122
|
*/
|
|
115
|
-
durableTask<Fn extends (input: I, ctx:
|
|
123
|
+
durableTask<Fn extends (input: I, ctx: DurableContext<I>) => O | Promise<O>, I extends InputType = Parameters<Fn>[0], O extends OutputType = ReturnType<Fn> extends Promise<infer P> ? P extends OutputType ? P : void : ReturnType<Fn> extends OutputType ? ReturnType<Fn> : void>(options: {
|
|
116
124
|
fn: Fn;
|
|
117
125
|
} & Omit<CreateDurableTaskWorkflowOpts<I, O>, 'fn'>): TaskWorkflowDeclaration<I, O, GlobalInput, GlobalOutput, MiddlewareBefore, MiddlewareAfter>;
|
|
118
126
|
/**
|
|
@@ -124,7 +132,7 @@ export declare class HatchetClient<GlobalInput extends Record<string, any> = {},
|
|
|
124
132
|
* @param options - Configuration options for the workflow run
|
|
125
133
|
* @returns A WorkflowRunRef containing the run ID and methods to interact with the run
|
|
126
134
|
*/
|
|
127
|
-
runNoWait<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> |
|
|
135
|
+
runNoWait<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> | LegacyWorkflow | string, input: I, options: RunOpts): Promise<WorkflowRunRef<O>>;
|
|
128
136
|
/**
|
|
129
137
|
* @alias run
|
|
130
138
|
* Triggers a workflow run and waits for the result.
|
|
@@ -135,7 +143,7 @@ export declare class HatchetClient<GlobalInput extends Record<string, any> = {},
|
|
|
135
143
|
* @param options - Configuration options for the workflow run
|
|
136
144
|
* @returns A promise that resolves with the workflow result
|
|
137
145
|
*/
|
|
138
|
-
runAndWait<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> |
|
|
146
|
+
runAndWait<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> | LegacyWorkflow | string, input: I, options?: RunOpts): Promise<O>;
|
|
139
147
|
/**
|
|
140
148
|
* Triggers a workflow run and waits for the result.
|
|
141
149
|
* @template I - The input type for the workflow
|
|
@@ -145,7 +153,7 @@ export declare class HatchetClient<GlobalInput extends Record<string, any> = {},
|
|
|
145
153
|
* @param options - Configuration options for the workflow run
|
|
146
154
|
* @returns A promise that resolves with the workflow result
|
|
147
155
|
*/
|
|
148
|
-
run<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> |
|
|
156
|
+
run<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> | LegacyWorkflow | string, input: I, options?: RunOpts): Promise<O>;
|
|
149
157
|
private _cel;
|
|
150
158
|
/**
|
|
151
159
|
* Get the CEL client for debugging CEL expressions
|
|
@@ -180,17 +188,33 @@ export declare class HatchetClient<GlobalInput extends Record<string, any> = {},
|
|
|
180
188
|
* @alias scheduled
|
|
181
189
|
*/
|
|
182
190
|
get schedules(): ScheduleClient;
|
|
191
|
+
private _dispatcher;
|
|
183
192
|
/**
|
|
184
|
-
* Get the
|
|
185
|
-
* @returns A
|
|
193
|
+
* Get the dispatcher client for sending action events and managing worker registration
|
|
194
|
+
* @returns A dispatcher client instance
|
|
186
195
|
*/
|
|
187
|
-
get
|
|
196
|
+
get dispatcher(): DispatcherClient;
|
|
197
|
+
private _event;
|
|
188
198
|
/**
|
|
189
199
|
* Get the event client for creating and managing event workflow runs
|
|
190
200
|
* @returns A event client instance
|
|
201
|
+
*/
|
|
202
|
+
get events(): EventClient;
|
|
203
|
+
private _durableListener;
|
|
204
|
+
/**
|
|
205
|
+
* Get the durable listener client for managing durable event subscriptions
|
|
206
|
+
* @returns A durable listener client instance
|
|
207
|
+
*/
|
|
208
|
+
get durableListener(): DurableListenerClient;
|
|
209
|
+
/**
|
|
210
|
+
* Get the run listener client for streaming workflow run results
|
|
211
|
+
* @returns A run listener client instance
|
|
212
|
+
*/
|
|
213
|
+
get listener(): RunListenerClient;
|
|
214
|
+
/**
|
|
191
215
|
* @deprecated use client.events instead
|
|
192
216
|
*/
|
|
193
|
-
get event():
|
|
217
|
+
get event(): EventClient;
|
|
194
218
|
private _metrics;
|
|
195
219
|
/**
|
|
196
220
|
* Get the metrics client for creating and managing metrics
|
|
@@ -262,12 +286,6 @@ export declare class HatchetClient<GlobalInput extends Record<string, any> = {},
|
|
|
262
286
|
* @returns A promise that resolves with a new HatchetWorker instance
|
|
263
287
|
*/
|
|
264
288
|
worker(name: string, options?: CreateWorkerOpts | number): Promise<Worker>;
|
|
265
|
-
/**
|
|
266
|
-
* Register a webhook with the worker
|
|
267
|
-
* @param workflows - The workflows to register on the webhooks
|
|
268
|
-
* @returns A promise that resolves when the webhook is registered
|
|
269
|
-
*/
|
|
270
|
-
v0webhooks(workflows: V0Workflow[]): import("../../clients/worker/handler").WebhookHandler;
|
|
271
289
|
runRef<T extends Record<string, any> = any>(id: string): WorkflowRunRef<T>;
|
|
272
290
|
}
|
|
273
291
|
export {};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EventClient } from '../../clients/event/event-client';
|
|
2
|
+
import { DispatcherClient } from '../../clients/dispatcher/dispatcher-client';
|
|
3
|
+
import { Logger } from '../../util/logger';
|
|
4
|
+
import { LegacyHatchetClient } from '../../legacy/legacy-client';
|
|
2
5
|
import { MetricsClient } from './features/metrics';
|
|
3
6
|
import { RunsClient } from './features/runs';
|
|
4
7
|
import { WorkersClient } from './features/workers';
|
|
@@ -8,8 +11,12 @@ import { ScheduleClient } from './features/schedules';
|
|
|
8
11
|
import { CronClient } from './features/crons';
|
|
9
12
|
import { CELClient } from './features/cel';
|
|
10
13
|
export interface IHatchetClient {
|
|
11
|
-
|
|
14
|
+
/** @deprecated v0 client will be removed in a future release, please upgrade to v1 */
|
|
15
|
+
v0: LegacyHatchetClient;
|
|
12
16
|
cel: CELClient;
|
|
17
|
+
dispatcher: DispatcherClient;
|
|
18
|
+
events: EventClient;
|
|
19
|
+
logger: Logger;
|
|
13
20
|
metrics: MetricsClient;
|
|
14
21
|
runs: RunsClient;
|
|
15
22
|
workflows: WorkflowsClient;
|
package/v1/client/client.js
CHANGED
|
@@ -21,10 +21,13 @@ const config_loader_1 = require("../../util/config-loader");
|
|
|
21
21
|
const hatchet_logger_1 = require("../../clients/hatchet-client/hatchet-logger");
|
|
22
22
|
const zod_1 = require("zod");
|
|
23
23
|
const event_client_1 = require("../../clients/event/event-client");
|
|
24
|
+
const dispatcher_client_1 = require("../../clients/dispatcher/dispatcher-client");
|
|
24
25
|
const child_listener_client_1 = require("../../clients/listeners/run-listener/child-listener-client");
|
|
26
|
+
const durable_listener_client_1 = require("../../clients/listeners/durable-listener/durable-listener-client");
|
|
25
27
|
const grpc_helpers_1 = require("../../util/grpc-helpers");
|
|
26
28
|
const nice_grpc_1 = require("nice-grpc");
|
|
27
29
|
const declaration_1 = require("../declaration");
|
|
30
|
+
const legacy_transformer_1 = require("../../legacy/legacy-transformer");
|
|
28
31
|
const worker_1 = require("./worker/worker");
|
|
29
32
|
const metrics_1 = require("./features/metrics");
|
|
30
33
|
const workers_1 = require("./features/workers");
|
|
@@ -51,6 +54,9 @@ class HatchetClient {
|
|
|
51
54
|
* @deprecated v0 client will be removed in a future release, please upgrade to v1
|
|
52
55
|
*/
|
|
53
56
|
get v0() {
|
|
57
|
+
if (!this._v0) {
|
|
58
|
+
this._v0 = new hatchet_client_1.LegacyHatchetClient(this._config, this._options, this._axiosConfig, this.runs, this._listener, this.events, this.dispatcher, this.logger, this.durableListener);
|
|
59
|
+
}
|
|
54
60
|
return this._v0;
|
|
55
61
|
}
|
|
56
62
|
get isV1() {
|
|
@@ -77,11 +83,14 @@ class HatchetClient {
|
|
|
77
83
|
const clientConfig = Object.assign(Object.assign({}, valid), { logger: logConstructor });
|
|
78
84
|
this._config = clientConfig;
|
|
79
85
|
this.tenantId = clientConfig.tenant_id;
|
|
86
|
+
this.logger = clientConfig.logger('HatchetClient', clientConfig.log_level);
|
|
80
87
|
this._api = (0, rest_1.default)(clientConfig.api_url, clientConfig.token, axiosConfig);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
this.
|
|
88
|
+
this._clientFactory = (0, nice_grpc_1.createClientFactory)().use((0, grpc_helpers_1.addTokenMiddleware)(this.config.token));
|
|
89
|
+
this._credentials =
|
|
90
|
+
(_a = options === null || options === void 0 ? void 0 : options.credentials) !== null && _a !== void 0 ? _a : config_loader_1.ConfigLoader.createCredentials(this.config.tls_config);
|
|
91
|
+
this._listener = new child_listener_client_1.RunListenerClient(this.config, (0, grpc_helpers_1.channelFactory)(this.config, this._credentials), this._clientFactory, this.api);
|
|
92
|
+
this._options = options;
|
|
93
|
+
this._axiosConfig = axiosConfig;
|
|
85
94
|
}
|
|
86
95
|
catch (e) {
|
|
87
96
|
if (e instanceof zod_1.z.ZodError) {
|
|
@@ -178,16 +187,7 @@ class HatchetClient {
|
|
|
178
187
|
*/
|
|
179
188
|
runNoWait(workflow, input, options) {
|
|
180
189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
-
|
|
182
|
-
if (typeof workflow === 'string') {
|
|
183
|
-
name = workflow;
|
|
184
|
-
}
|
|
185
|
-
else if ('id' in workflow) {
|
|
186
|
-
name = workflow.id;
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
throw new Error('unable to identify workflow');
|
|
190
|
-
}
|
|
190
|
+
const name = (0, legacy_transformer_1.getWorkflowName)(workflow);
|
|
191
191
|
return this.admin.runWorkflow(name, input, options);
|
|
192
192
|
});
|
|
193
193
|
}
|
|
@@ -273,16 +273,44 @@ class HatchetClient {
|
|
|
273
273
|
get schedules() {
|
|
274
274
|
return this.scheduled;
|
|
275
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* Get the dispatcher client for sending action events and managing worker registration
|
|
278
|
+
* @returns A dispatcher client instance
|
|
279
|
+
*/
|
|
280
|
+
get dispatcher() {
|
|
281
|
+
if (!this._dispatcher) {
|
|
282
|
+
this._dispatcher = new dispatcher_client_1.DispatcherClient(this._config, (0, grpc_helpers_1.channelFactory)(this._config, this._credentials), this._clientFactory);
|
|
283
|
+
}
|
|
284
|
+
return this._dispatcher;
|
|
285
|
+
}
|
|
276
286
|
/**
|
|
277
287
|
* Get the event client for creating and managing event workflow runs
|
|
278
288
|
* @returns A event client instance
|
|
279
289
|
*/
|
|
280
290
|
get events() {
|
|
281
|
-
|
|
291
|
+
if (!this._event) {
|
|
292
|
+
this._event = new event_client_1.EventClient(this._config, (0, grpc_helpers_1.channelFactory)(this._config, this._credentials), this._clientFactory, this.api);
|
|
293
|
+
}
|
|
294
|
+
return this._event;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Get the durable listener client for managing durable event subscriptions
|
|
298
|
+
* @returns A durable listener client instance
|
|
299
|
+
*/
|
|
300
|
+
get durableListener() {
|
|
301
|
+
if (!this._durableListener) {
|
|
302
|
+
this._durableListener = new durable_listener_client_1.DurableListenerClient(this._config, (0, grpc_helpers_1.channelFactory)(this._config, this._credentials), this._clientFactory, this.api);
|
|
303
|
+
}
|
|
304
|
+
return this._durableListener;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Get the run listener client for streaming workflow run results
|
|
308
|
+
* @returns A run listener client instance
|
|
309
|
+
*/
|
|
310
|
+
get listener() {
|
|
311
|
+
return this._listener;
|
|
282
312
|
}
|
|
283
313
|
/**
|
|
284
|
-
* Get the event client for creating and managing event workflow runs
|
|
285
|
-
* @returns A event client instance
|
|
286
314
|
* @deprecated use client.events instead
|
|
287
315
|
*/
|
|
288
316
|
get event() {
|
|
@@ -389,7 +417,7 @@ class HatchetClient {
|
|
|
389
417
|
*/
|
|
390
418
|
get admin() {
|
|
391
419
|
if (!this._admin) {
|
|
392
|
-
this._admin = new admin_1.AdminClient(this.
|
|
420
|
+
this._admin = new admin_1.AdminClient(this._config, this.api, this.runs);
|
|
393
421
|
}
|
|
394
422
|
return this._admin;
|
|
395
423
|
}
|
|
@@ -406,15 +434,7 @@ class HatchetClient {
|
|
|
406
434
|
else {
|
|
407
435
|
opts = options || {};
|
|
408
436
|
}
|
|
409
|
-
return worker_1.Worker.create(this,
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Register a webhook with the worker
|
|
413
|
-
* @param workflows - The workflows to register on the webhooks
|
|
414
|
-
* @returns A promise that resolves when the webhook is registered
|
|
415
|
-
*/
|
|
416
|
-
v0webhooks(workflows) {
|
|
417
|
-
return this._v0.webhooks(workflows);
|
|
437
|
+
return worker_1.Worker.create(this, name, opts);
|
|
418
438
|
}
|
|
419
439
|
runRef(id) {
|
|
420
440
|
return this.runs.runRef(id);
|