@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/util/abort-error.js
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbortError = void 0;
|
|
3
4
|
exports.createAbortError = createAbortError;
|
|
4
5
|
exports.isAbortError = isAbortError;
|
|
5
6
|
exports.rethrowIfAborted = rethrowIfAborted;
|
|
7
|
+
exports.bindAbortSignalHandler = bindAbortSignalHandler;
|
|
6
8
|
exports.throwIfAborted = throwIfAborted;
|
|
9
|
+
const events_1 = require("events");
|
|
10
|
+
class AbortError extends Error {
|
|
11
|
+
constructor(message = 'Operation aborted') {
|
|
12
|
+
super(message);
|
|
13
|
+
this.code = 'ABORT_ERR';
|
|
14
|
+
this.name = 'AbortError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.AbortError = AbortError;
|
|
7
18
|
function createAbortError(message = 'Operation aborted') {
|
|
8
|
-
|
|
9
|
-
err.name = 'AbortError';
|
|
10
|
-
err.code = 'ABORT_ERR';
|
|
11
|
-
return err;
|
|
19
|
+
return new AbortError(message);
|
|
12
20
|
}
|
|
13
21
|
function isAbortError(err) {
|
|
14
|
-
|
|
22
|
+
if (err instanceof AbortError) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return (err instanceof Error &&
|
|
26
|
+
(err.name === 'AbortError' || err.code === 'ABORT_ERR'));
|
|
15
27
|
}
|
|
16
28
|
/**
|
|
17
29
|
* Helper to be used inside broad `catch` blocks so cancellation isn't accidentally swallowed.
|
|
@@ -26,6 +38,19 @@ function rethrowIfAborted(err) {
|
|
|
26
38
|
throw err;
|
|
27
39
|
}
|
|
28
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Attach an `abort` listener to a signal, disabling the Node.js
|
|
43
|
+
* `MaxListenersExceededWarning` first.
|
|
44
|
+
*
|
|
45
|
+
* A single durable task can attach many concurrent listeners to the same signal
|
|
46
|
+
* (fan-out children, parallel waitFor calls, etc.), easily exceeding the default
|
|
47
|
+
* cap of 10. Setting max to 0 (unlimited) is safe here because every listener is
|
|
48
|
+
* removed on settlement.
|
|
49
|
+
*/
|
|
50
|
+
function bindAbortSignalHandler(signal, handler) {
|
|
51
|
+
(0, events_1.setMaxListeners)(0, signal);
|
|
52
|
+
signal.addEventListener('abort', handler, { once: true });
|
|
53
|
+
}
|
|
29
54
|
/**
|
|
30
55
|
* Throws an AbortError if the provided signal is aborted.
|
|
31
56
|
*
|
|
@@ -74,7 +74,7 @@ class ConfigLoader {
|
|
|
74
74
|
apiUrl =
|
|
75
75
|
(_x = (_w = (_v = override === null || override === void 0 ? void 0 : override.api_url) !== null && _v !== void 0 ? _v : yaml === null || yaml === void 0 ? void 0 : yaml.api_url) !== null && _w !== void 0 ? _w : this.env('HATCHET_CLIENT_API_URL')) !== null && _x !== void 0 ? _x : addresses.serverUrl;
|
|
76
76
|
}
|
|
77
|
-
catch (
|
|
77
|
+
catch (_9) {
|
|
78
78
|
grpcBroadcastAddress =
|
|
79
79
|
(_z = (_y = override === null || override === void 0 ? void 0 : override.host_port) !== null && _y !== void 0 ? _y : yaml === null || yaml === void 0 ? void 0 : yaml.host_port) !== null && _z !== void 0 ? _z : this.env('HATCHET_CLIENT_HOST_PORT');
|
|
80
80
|
apiUrl = (_1 = (_0 = override === null || override === void 0 ? void 0 : override.api_url) !== null && _0 !== void 0 ? _0 : yaml === null || yaml === void 0 ? void 0 : yaml.api_url) !== null && _1 !== void 0 ? _1 : this.env('HATCHET_CLIENT_API_URL');
|
|
@@ -119,10 +119,11 @@ class ConfigLoader {
|
|
|
119
119
|
return config;
|
|
120
120
|
}
|
|
121
121
|
catch (e) {
|
|
122
|
-
if (!path)
|
|
122
|
+
if (!path) {
|
|
123
123
|
return undefined;
|
|
124
|
+
}
|
|
124
125
|
if (e instanceof zod_1.z.ZodError) {
|
|
125
|
-
throw new Error(`Invalid yaml config: ${e.message}
|
|
126
|
+
throw new Error(`Invalid yaml config: ${e.message}`, { cause: e });
|
|
126
127
|
}
|
|
127
128
|
throw e;
|
|
128
129
|
}
|
|
@@ -2,12 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTenantIdFromJWT = getTenantIdFromJWT;
|
|
4
4
|
exports.getAddressesFromJWT = getAddressesFromJWT;
|
|
5
|
+
const parse_1 = require("../parse");
|
|
5
6
|
function getTenantIdFromJWT(token) {
|
|
6
7
|
const claims = extractClaimsFromJWT(token);
|
|
8
|
+
if (claims.sub === undefined) {
|
|
9
|
+
throw new Error('Invalid token: missing sub');
|
|
10
|
+
}
|
|
7
11
|
return claims.sub;
|
|
8
12
|
}
|
|
9
13
|
function getAddressesFromJWT(token) {
|
|
10
14
|
const claims = extractClaimsFromJWT(token);
|
|
15
|
+
if (claims.server_url === undefined || claims.grpc_broadcast_address === undefined) {
|
|
16
|
+
throw new Error('Invalid token: missing server_url or grpc_broadcast_address');
|
|
17
|
+
}
|
|
11
18
|
return {
|
|
12
19
|
serverUrl: claims.server_url,
|
|
13
20
|
grpcBroadcastAddress: claims.grpc_broadcast_address,
|
|
@@ -18,8 +25,8 @@ function extractClaimsFromJWT(token) {
|
|
|
18
25
|
if (parts.length !== 3) {
|
|
19
26
|
throw new Error('Invalid token format');
|
|
20
27
|
}
|
|
21
|
-
const claimsPart = parts
|
|
28
|
+
const [_, claimsPart] = parts;
|
|
22
29
|
const claimsData = atob(claimsPart.replace(/-/g, '+').replace(/_/g, '/'));
|
|
23
|
-
const claims =
|
|
30
|
+
const claims = (0, parse_1.parseJSON)(claimsData);
|
|
24
31
|
return claims;
|
|
25
32
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.EvictionNotSupportedError = void 0;
|
|
7
|
+
const v1_1 = require("../../v1");
|
|
8
|
+
const hatchet_error_1 = __importDefault(require("./hatchet-error"));
|
|
9
|
+
class EvictionNotSupportedError extends hatchet_error_1.default {
|
|
10
|
+
constructor(engineVersion) {
|
|
11
|
+
const versionInfo = engineVersion ? ` (engine ${engineVersion})` : '';
|
|
12
|
+
super(`Durable eviction is not supported by the connected engine${versionInfo}. ` +
|
|
13
|
+
`Please upgrade your Hatchet engine to ${v1_1.MinEngineVersion.DURABLE_EVICTION} or later.`);
|
|
14
|
+
this.name = 'EvictionNotSupportedError';
|
|
15
|
+
this.engineVersion = engineVersion;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.EvictionNotSupportedError = EvictionNotSupportedError;
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
/** Returns a string message from an unknown value (e.g. from a catch block). */
|
|
2
|
+
export declare function getErrorMessage(e: unknown): string;
|
|
1
3
|
declare class HatchetError extends Error {
|
|
2
|
-
constructor(message: string
|
|
4
|
+
constructor(message: string, options?: {
|
|
5
|
+
cause?: unknown;
|
|
6
|
+
});
|
|
3
7
|
}
|
|
8
|
+
export declare function toHatchetError(e: unknown, defaultMessageOrOptions?: string | {
|
|
9
|
+
defaultMessage?: string;
|
|
10
|
+
prefix?: string;
|
|
11
|
+
}): HatchetError;
|
|
4
12
|
export default HatchetError;
|
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getErrorMessage = getErrorMessage;
|
|
4
|
+
exports.toHatchetError = toHatchetError;
|
|
5
|
+
/** Returns a string message from an unknown value (e.g. from a catch block). */
|
|
6
|
+
function getErrorMessage(e) {
|
|
7
|
+
return e instanceof Error ? e.message : String(e);
|
|
8
|
+
}
|
|
3
9
|
class HatchetError extends Error {
|
|
4
|
-
constructor(message) {
|
|
5
|
-
super(message);
|
|
10
|
+
constructor(message, options) {
|
|
11
|
+
super(message, options);
|
|
6
12
|
this.name = 'HatchetError';
|
|
7
13
|
}
|
|
8
14
|
}
|
|
15
|
+
function toHatchetError(e, defaultMessageOrOptions = 'An error occurred') {
|
|
16
|
+
var _a;
|
|
17
|
+
if (e instanceof HatchetError) {
|
|
18
|
+
return e;
|
|
19
|
+
}
|
|
20
|
+
const opts = typeof defaultMessageOrOptions === 'string'
|
|
21
|
+
? { defaultMessage: defaultMessageOrOptions }
|
|
22
|
+
: defaultMessageOrOptions;
|
|
23
|
+
const defaultMessage = (_a = opts.defaultMessage) !== null && _a !== void 0 ? _a : 'An error occurred';
|
|
24
|
+
let message = getErrorMessage(e) || defaultMessage;
|
|
25
|
+
if (opts.prefix) {
|
|
26
|
+
message = opts.prefix + message;
|
|
27
|
+
}
|
|
28
|
+
return new HatchetError(message, { cause: e });
|
|
29
|
+
}
|
|
9
30
|
exports.default = HatchetError;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import HatchetError from './hatchet-error';
|
|
2
|
+
export declare class NonDeterminismError extends HatchetError {
|
|
3
|
+
taskExternalId: string;
|
|
4
|
+
invocationCount: number;
|
|
5
|
+
nodeId: number;
|
|
6
|
+
constructor(taskExternalId: string, invocationCount: number, nodeId: number, message: string);
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NonDeterminismError = void 0;
|
|
7
|
+
const hatchet_error_1 = __importDefault(require("./hatchet-error"));
|
|
8
|
+
class NonDeterminismError extends hatchet_error_1.default {
|
|
9
|
+
constructor(taskExternalId, invocationCount, nodeId, message) {
|
|
10
|
+
const detail = message
|
|
11
|
+
? message
|
|
12
|
+
: `Non-determinism detected in task ${taskExternalId} on invocation ${invocationCount} at node ${nodeId}`;
|
|
13
|
+
super(`${detail}\n` +
|
|
14
|
+
`Check out our documentation for more details on expectations of durable tasks: https://docs.hatchet.run/v1/patterns/mixing-patterns`);
|
|
15
|
+
this.name = 'NonDeterminismError';
|
|
16
|
+
this.taskExternalId = taskExternalId;
|
|
17
|
+
this.invocationCount = invocationCount;
|
|
18
|
+
this.nodeId = nodeId;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.NonDeterminismError = NonDeterminismError;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type TaskRunTerminationReason = 'cancelled' | 'evicted';
|
|
2
|
+
export declare class TaskRunTerminatedError extends Error {
|
|
3
|
+
readonly reason: TaskRunTerminationReason;
|
|
4
|
+
constructor(reason: TaskRunTerminationReason, message?: string);
|
|
5
|
+
}
|
|
6
|
+
export declare function isTaskRunTerminatedError(err: unknown): err is TaskRunTerminatedError;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaskRunTerminatedError = void 0;
|
|
4
|
+
exports.isTaskRunTerminatedError = isTaskRunTerminatedError;
|
|
5
|
+
class TaskRunTerminatedError extends Error {
|
|
6
|
+
constructor(reason, message) {
|
|
7
|
+
super(message !== null && message !== void 0 ? message : reason);
|
|
8
|
+
this.name = 'TaskRunTerminatedError';
|
|
9
|
+
this.reason = reason;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.TaskRunTerminatedError = TaskRunTerminatedError;
|
|
13
|
+
function isTaskRunTerminatedError(err) {
|
|
14
|
+
return err instanceof TaskRunTerminatedError;
|
|
15
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the gRPC status code from an unknown value (e.g. from a catch block).
|
|
3
|
+
* Used for checking Status.CANCELLED, Status.UNAVAILABLE, etc.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getGrpcErrorCode(e: unknown): number | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Returns the gRPC error details string from an unknown value (e.g. from a catch block).
|
|
8
|
+
*/
|
|
9
|
+
export declare function getGrpcErrorDetails(e: unknown): string | undefined;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGrpcErrorCode = getGrpcErrorCode;
|
|
4
|
+
exports.getGrpcErrorDetails = getGrpcErrorDetails;
|
|
5
|
+
/**
|
|
6
|
+
* Returns the gRPC status code from an unknown value (e.g. from a catch block).
|
|
7
|
+
* Used for checking Status.CANCELLED, Status.UNAVAILABLE, etc.
|
|
8
|
+
*/
|
|
9
|
+
function getGrpcErrorCode(e) {
|
|
10
|
+
if (e != null && typeof e === 'object' && 'code' in e) {
|
|
11
|
+
const { code } = e;
|
|
12
|
+
return typeof code === 'number' ? code : undefined;
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns the gRPC error details string from an unknown value (e.g. from a catch block).
|
|
18
|
+
*/
|
|
19
|
+
function getGrpcErrorDetails(e) {
|
|
20
|
+
if (e != null && typeof e === 'object' && 'details' in e) {
|
|
21
|
+
const { details } = e;
|
|
22
|
+
return typeof details === 'string' ? details : undefined;
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
/** Canonical reasons when cancelling a HatchetPromise (e.g. worker shutdown). */
|
|
2
|
+
export declare enum CancellationReason {
|
|
3
|
+
CANCELLED_BY_WORKER = "Cancelled by worker",
|
|
4
|
+
EVICTED_BY_WORKER = "Evicted by worker"
|
|
5
|
+
}
|
|
1
6
|
declare class HatchetPromise<T> {
|
|
2
|
-
cancel: (reason?:
|
|
7
|
+
cancel: (reason?: CancellationReason) => void;
|
|
3
8
|
promise: Promise<T>;
|
|
4
9
|
/**
|
|
5
10
|
* The original (non-cancelable) promise passed to the constructor.
|
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CancellationReason = void 0;
|
|
4
|
+
const task_run_terminated_error_1 = require("../errors/task-run-terminated-error");
|
|
5
|
+
/** Canonical reasons when cancelling a HatchetPromise (e.g. worker shutdown). */
|
|
6
|
+
var CancellationReason;
|
|
7
|
+
(function (CancellationReason) {
|
|
8
|
+
CancellationReason["CANCELLED_BY_WORKER"] = "Cancelled by worker";
|
|
9
|
+
CancellationReason["EVICTED_BY_WORKER"] = "Evicted by worker";
|
|
10
|
+
})(CancellationReason || (exports.CancellationReason = CancellationReason = {}));
|
|
11
|
+
const reasonToTermination = {
|
|
12
|
+
[CancellationReason.CANCELLED_BY_WORKER]: 'cancelled',
|
|
13
|
+
[CancellationReason.EVICTED_BY_WORKER]: 'evicted',
|
|
14
|
+
};
|
|
3
15
|
class HatchetPromise {
|
|
4
16
|
constructor(promise) {
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
17
|
this.cancel = (_reason) => { };
|
|
7
18
|
this.inner = Promise.resolve(promise);
|
|
8
19
|
this.promise = new Promise((resolve, reject) => {
|
|
9
|
-
this.cancel =
|
|
20
|
+
this.cancel = (reason) => {
|
|
21
|
+
const termination = reason ? reasonToTermination[reason] : 'cancelled';
|
|
22
|
+
reject(new task_run_terminated_error_1.TaskRunTerminatedError(termination, reason));
|
|
23
|
+
};
|
|
10
24
|
this.inner.then(resolve).catch(reject);
|
|
11
25
|
});
|
|
12
26
|
}
|
package/util/logger/logger.js
CHANGED
package/util/parse.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function parseJSON(json: string):
|
|
1
|
+
export declare function parseJSON<T = any>(json: string): T;
|
package/util/parse.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseJSON = parseJSON;
|
|
4
|
+
const hatchet_error_1 = require("./errors/hatchet-error");
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
6
|
function parseJSON(json) {
|
|
5
7
|
try {
|
|
6
8
|
const firstParse = JSON.parse(json);
|
|
@@ -9,11 +11,11 @@ function parseJSON(json) {
|
|
|
9
11
|
try {
|
|
10
12
|
return JSON.parse(firstParse);
|
|
11
13
|
}
|
|
12
|
-
catch (
|
|
14
|
+
catch (_a) {
|
|
13
15
|
return firstParse;
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
catch (e) {
|
|
17
|
-
throw new Error(`Could not parse JSON: ${e
|
|
19
|
+
throw new Error(`Could not parse JSON: ${(0, hatchet_error_1.getErrorMessage)(e)}`, { cause: e });
|
|
18
20
|
}
|
|
19
21
|
}
|
package/util/retrier.js
CHANGED
|
@@ -20,14 +20,13 @@ const MAX_JITTER = 100; // milliseconds
|
|
|
20
20
|
function retrier(fn_1, logger_1) {
|
|
21
21
|
return __awaiter(this, arguments, void 0, function* (fn, logger, retries = DEFAULT_RETRY_COUNT, interval = DEFAULT_RETRY_INTERVAL) {
|
|
22
22
|
let lastError;
|
|
23
|
-
// eslint-disable-next-line no-plusplus
|
|
24
23
|
for (let i = 0; i < retries; i++) {
|
|
25
24
|
try {
|
|
26
25
|
return yield fn();
|
|
27
26
|
}
|
|
28
27
|
catch (e) {
|
|
29
|
-
lastError = e;
|
|
30
|
-
logger.error(`Error: ${
|
|
28
|
+
lastError = e instanceof Error ? e : new Error(String(e));
|
|
29
|
+
logger.error(`Error: ${lastError.message}`);
|
|
31
30
|
// Calculate exponential backoff with random jitter
|
|
32
31
|
const exponentialDelay = interval * 2 ** i * 1000;
|
|
33
32
|
const jitter = Math.random() * MAX_JITTER;
|
package/util/sleep.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { Duration } from '../v1/client/duration';
|
|
1
2
|
/**
|
|
2
3
|
* Sleeps for a given number of milliseconds without blocking the event loop
|
|
3
4
|
*
|
|
4
5
|
* WARNING: This is not a durable sleep. It will not be honored if the worker is
|
|
5
6
|
* restarted or crashes.
|
|
6
7
|
*
|
|
7
|
-
* @param
|
|
8
|
+
* @param duration - The number of milliseconds to sleep, or a Duration (e.g. "5s", \{ seconds: 5 \})
|
|
8
9
|
* @param signal - Optional AbortSignal; if aborted, the promise rejects with Error('Cancelled').
|
|
9
10
|
* Use in task handlers so cancellation can interrupt long sleeps.
|
|
10
11
|
* @returns A promise that resolves after the given number of milliseconds (or rejects on abort)
|
|
11
12
|
*/
|
|
12
|
-
declare function sleep(
|
|
13
|
+
declare function sleep(duration: number | Duration, signal?: AbortSignal): Promise<void>;
|
|
13
14
|
export default sleep;
|
package/util/sleep.js
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const duration_1 = require("../v1/client/duration");
|
|
3
4
|
/**
|
|
4
5
|
* Sleeps for a given number of milliseconds without blocking the event loop
|
|
5
6
|
*
|
|
6
7
|
* WARNING: This is not a durable sleep. It will not be honored if the worker is
|
|
7
8
|
* restarted or crashes.
|
|
8
9
|
*
|
|
9
|
-
* @param
|
|
10
|
+
* @param duration - The number of milliseconds to sleep, or a Duration (e.g. "5s", \{ seconds: 5 \})
|
|
10
11
|
* @param signal - Optional AbortSignal; if aborted, the promise rejects with Error('Cancelled').
|
|
11
12
|
* Use in task handlers so cancellation can interrupt long sleeps.
|
|
12
13
|
* @returns A promise that resolves after the given number of milliseconds (or rejects on abort)
|
|
13
14
|
*/
|
|
14
|
-
function sleep(
|
|
15
|
+
function sleep(duration, signal) {
|
|
16
|
+
const timeout = typeof duration === 'number' ? duration : (0, duration_1.durationToMs)(duration);
|
|
15
17
|
if (!signal) {
|
|
16
18
|
return new Promise((resolve) => {
|
|
17
|
-
setTimeout(resolve,
|
|
19
|
+
setTimeout(resolve, timeout);
|
|
18
20
|
});
|
|
19
21
|
}
|
|
20
22
|
return new Promise((resolve, reject) => {
|
|
21
23
|
const timer = setTimeout(() => {
|
|
22
24
|
signal.removeEventListener('abort', onAbort);
|
|
23
25
|
resolve();
|
|
24
|
-
},
|
|
26
|
+
}, timeout);
|
|
25
27
|
const onAbort = () => {
|
|
26
28
|
clearTimeout(timer);
|
|
27
29
|
reject(new Error('Cancelled'));
|
package/util/workflow-run-ref.js
CHANGED
|
@@ -18,6 +18,7 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.DedupeViolationErr = void 0;
|
|
20
20
|
const nice_grpc_1 = require("nice-grpc");
|
|
21
|
+
const grpc_error_1 = require("./grpc-error");
|
|
21
22
|
const dispatcher_1 = require("../protoc/dispatcher");
|
|
22
23
|
class DedupeViolationErr extends Error {
|
|
23
24
|
constructor(message) {
|
|
@@ -28,6 +29,7 @@ class DedupeViolationErr extends Error {
|
|
|
28
29
|
exports.DedupeViolationErr = DedupeViolationErr;
|
|
29
30
|
function getWorkflowRunId(workflowRunId) {
|
|
30
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
var _a;
|
|
31
33
|
if (typeof workflowRunId === 'string') {
|
|
32
34
|
return workflowRunId;
|
|
33
35
|
}
|
|
@@ -40,8 +42,8 @@ function getWorkflowRunId(workflowRunId) {
|
|
|
40
42
|
return resolved.workflowRunId;
|
|
41
43
|
}
|
|
42
44
|
catch (e) {
|
|
43
|
-
if (
|
|
44
|
-
throw new DedupeViolationErr(
|
|
45
|
+
if ((0, grpc_error_1.getGrpcErrorCode)(e) === nice_grpc_1.Status.ALREADY_EXISTS) {
|
|
46
|
+
throw new DedupeViolationErr((_a = (0, grpc_error_1.getGrpcErrorDetails)(e)) !== null && _a !== void 0 ? _a : '');
|
|
45
47
|
}
|
|
46
48
|
throw e;
|
|
47
49
|
}
|
|
@@ -117,7 +119,7 @@ class WorkflowRunRef {
|
|
|
117
119
|
try {
|
|
118
120
|
outputs[readableStepName] = JSON.parse(stepRun.output || '{}');
|
|
119
121
|
}
|
|
120
|
-
catch (
|
|
122
|
+
catch (_c) {
|
|
121
123
|
outputs[readableStepName] = stepRun.output;
|
|
122
124
|
}
|
|
123
125
|
});
|
package/v1/client/admin.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ClientConfig } from '../../clients/hatchet-client/client-config';
|
|
2
2
|
import WorkflowRunRef from '../../util/workflow-run-ref';
|
|
3
|
-
import { Priority, RateLimitDuration, RunsClient } from './..';
|
|
3
|
+
import { Priority, RateLimitDuration, RunsClient, WorkerLabelComparator } from './..';
|
|
4
4
|
import { RunListenerClient } from '../../clients/listeners/run-listener/child-listener-client';
|
|
5
5
|
import { Api } from '../../clients/rest/generated/Api';
|
|
6
|
-
import {
|
|
6
|
+
import { WorkflowServiceClient } from '../../protoc/workflows';
|
|
7
7
|
import { AdminServiceClient, CreateWorkflowVersionRequest } from '../../protoc/v1/workflows';
|
|
8
8
|
import { Logger } from '../../util/logger';
|
|
9
9
|
type DesiredWorkerLabelOpt = {
|
package/v1/client/admin.js
CHANGED
|
@@ -91,9 +91,7 @@ class AdminClient {
|
|
|
91
91
|
: {} });
|
|
92
92
|
const resp = yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.workflowsGrpc.triggerWorkflow(request); }), this.logger);
|
|
93
93
|
const id = resp.workflowRunId;
|
|
94
|
-
const ref = new workflow_run_ref_1.default(id, this.listenerClient, this.runs, options === null || options === void 0 ? void 0 : options.parentId,
|
|
95
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
96
|
-
options === null || options === void 0 ? void 0 : options._standaloneTaskName);
|
|
94
|
+
const ref = new workflow_run_ref_1.default(id, this.listenerClient, this.runs, options === null || options === void 0 ? void 0 : options.parentId, options === null || options === void 0 ? void 0 : options._standaloneTaskName);
|
|
97
95
|
yield ref.getWorkflowRunId();
|
|
98
96
|
return ref;
|
|
99
97
|
}
|
|
@@ -139,9 +137,7 @@ class AdminClient {
|
|
|
139
137
|
const batchResults = bulkTriggerWorkflowResponse.workflowRunIds.map((resp, index) => {
|
|
140
138
|
const originalIndex = originalIndices[index];
|
|
141
139
|
const { options } = workflowRuns[originalIndex];
|
|
142
|
-
return new workflow_run_ref_1.default(resp, this.listenerClient, this.runs, options === null || options === void 0 ? void 0 : options.parentId,
|
|
143
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
144
|
-
options === null || options === void 0 ? void 0 : options._standaloneTaskName);
|
|
140
|
+
return new workflow_run_ref_1.default(resp, this.listenerClient, this.runs, options === null || options === void 0 ? void 0 : options.parentId, options === null || options === void 0 ? void 0 : options._standaloneTaskName);
|
|
145
141
|
});
|
|
146
142
|
results.push(...batchResults);
|
|
147
143
|
}
|
package/v1/client/client.d.ts
CHANGED
|
@@ -17,19 +17,9 @@ import { CreateTaskWorkflowOpts, CreateWorkflowOpts, RunOpts, BaseWorkflowDeclar
|
|
|
17
17
|
import type { LegacyWorkflow } from '../../legacy/legacy-transformer';
|
|
18
18
|
import { IHatchetClient } from './client.interface';
|
|
19
19
|
import { CreateWorkerOpts, Worker } from './worker/worker';
|
|
20
|
-
import { MetricsClient } from './features
|
|
21
|
-
import { WorkersClient } from './features/workers';
|
|
22
|
-
import { WorkflowsClient } from './features/workflows';
|
|
23
|
-
import { RunsClient } from './features/runs';
|
|
20
|
+
import { CELClient, CronClient, FiltersClient, LogsClient, MetricsClient, RatelimitsClient, RunsClient, ScheduleClient, TenantClient, WebhooksClient, WorkersClient, WorkflowsClient } from './features';
|
|
24
21
|
import { InputType, OutputType, UnknownInputType, StrictWorkflowOutputType, Resolved } from '../types';
|
|
25
|
-
import { RatelimitsClient } from './features';
|
|
26
22
|
import { AdminClient } from './admin';
|
|
27
|
-
import { FiltersClient } from './features/filters';
|
|
28
|
-
import { ScheduleClient } from './features/schedules';
|
|
29
|
-
import { CronClient } from './features/crons';
|
|
30
|
-
import { CELClient } from './features/cel';
|
|
31
|
-
import { TenantClient } from './features/tenant';
|
|
32
|
-
import { WebhooksClient } from './features/webhooks';
|
|
33
23
|
import { DurableContext } from './worker/context';
|
|
34
24
|
type MergeIfNonEmpty<Base, Extra extends Record<string, any>> = keyof Extra extends never ? Base : Base & Extra;
|
|
35
25
|
/**
|
|
@@ -256,6 +246,12 @@ export declare class HatchetClient<GlobalInput extends Record<string, any> = {},
|
|
|
256
246
|
* @returns A webhooks client instance
|
|
257
247
|
*/
|
|
258
248
|
get webhooks(): WebhooksClient;
|
|
249
|
+
private _logs;
|
|
250
|
+
/**
|
|
251
|
+
* Get the logs client for creating and managing logs
|
|
252
|
+
* @returns A logs client instance
|
|
253
|
+
*/
|
|
254
|
+
get logs(): LogsClient;
|
|
259
255
|
private _ratelimits;
|
|
260
256
|
/**
|
|
261
257
|
* Get the rate limits client for creating and managing rate limits
|
|
@@ -2,15 +2,8 @@ import { EventClient } from '../../clients/event/event-client';
|
|
|
2
2
|
import { DispatcherClient } from '../../clients/dispatcher/dispatcher-client';
|
|
3
3
|
import { Logger } from '../../util/logger';
|
|
4
4
|
import { LegacyHatchetClient } from '../../legacy/legacy-client';
|
|
5
|
-
import { MetricsClient } from './features
|
|
6
|
-
import { RunsClient } from './features/runs';
|
|
7
|
-
import { WorkersClient } from './features/workers';
|
|
8
|
-
import { WorkflowsClient } from './features/workflows';
|
|
5
|
+
import { CronClient, MetricsClient, RunsClient, ScheduleClient, WebhooksClient, WorkersClient, WorkflowsClient, CELClient, LogsClient, TenantClient, FiltersClient, RatelimitsClient } from './features';
|
|
9
6
|
import { AdminClient } from './admin';
|
|
10
|
-
import { ScheduleClient } from './features/schedules';
|
|
11
|
-
import { CronClient } from './features/crons';
|
|
12
|
-
import { CELClient } from './features/cel';
|
|
13
|
-
import { WebhooksClient } from './features/webhooks';
|
|
14
7
|
export interface IHatchetClient {
|
|
15
8
|
/** @deprecated v0 client will be removed in a future release, please upgrade to v1 */
|
|
16
9
|
v0: LegacyHatchetClient;
|
|
@@ -18,11 +11,15 @@ export interface IHatchetClient {
|
|
|
18
11
|
dispatcher: DispatcherClient;
|
|
19
12
|
events: EventClient;
|
|
20
13
|
logger: Logger;
|
|
14
|
+
logs: LogsClient;
|
|
21
15
|
metrics: MetricsClient;
|
|
22
16
|
runs: RunsClient;
|
|
23
17
|
workflows: WorkflowsClient;
|
|
24
18
|
workers: WorkersClient;
|
|
25
19
|
webhooks: WebhooksClient;
|
|
20
|
+
tenant: TenantClient;
|
|
21
|
+
filters: FiltersClient;
|
|
22
|
+
ratelimits: RatelimitsClient;
|
|
26
23
|
scheduled: ScheduleClient;
|
|
27
24
|
crons: CronClient;
|
|
28
25
|
admin: AdminClient;
|