@hatchet-dev/typescript-sdk 1.15.1 → 1.16.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/admin/admin-client.js +8 -9
- package/clients/dispatcher/action-listener.js +42 -6
- 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/pooled-durable-listener-client.js +10 -8
- 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 +8 -5
- package/clients/rest/generated/Api.d.ts +21 -1
- package/clients/rest/generated/Api.js +20 -0
- package/clients/rest/generated/data-contracts.d.ts +46 -1
- package/clients/rest/generated/data-contracts.js +4 -0
- package/legacy/examples/affinity-workers.js +0 -1
- 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 +1 -1
- package/legacy/legacy-transformer.js +2 -4
- package/legacy/step.d.ts +14 -14
- package/legacy/step.js +6 -16
- package/legacy/workflow.d.ts +56 -56
- package/package.json +20 -29
- package/util/abort-error.d.ts +5 -1
- package/util/abort-error.js +15 -5
- package/util/config-loader/config-loader.js +4 -3
- package/util/config-loader/token.js +9 -2
- package/util/errors/hatchet-error.d.ts +9 -1
- package/util/errors/hatchet-error.js +23 -2
- package/util/grpc-error.d.ts +9 -0
- package/util/grpc-error.js +25 -0
- package/util/hatchet-promise/hatchet-promise.d.ts +5 -1
- package/util/hatchet-promise/hatchet-promise.js +6 -1
- 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/workflow-run-ref.js +5 -3
- package/v1/client/admin.js +2 -6
- package/v1/client/client.d.ts +7 -11
- package/v1/client/client.interface.d.ts +6 -7
- package/v1/client/client.js +33 -39
- 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.js +0 -1
- 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.js +11 -24
- package/v1/client/worker/deprecated/deprecation.js +8 -4
- package/v1/client/worker/deprecated/legacy-worker.js +2 -2
- package/v1/client/worker/health-server.js +3 -3
- package/v1/client/worker/slot-utils.js +0 -3
- package/v1/client/worker/worker-internal.js +40 -11
- package/v1/client/worker/worker.js +2 -1
- package/v1/conditions/base.js +0 -1
- package/v1/conditions/index.js +2 -4
- package/v1/conditions/transformer.d.ts +2 -2
- package/v1/conditions/transformer.js +5 -4
- package/v1/declaration.d.ts +1 -1
- package/v1/declaration.js +12 -7
- package/v1/examples/__e2e__/harness.js +4 -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/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.js +2 -3
- package/v1/examples/durable-event/event.js +0 -1
- package/v1/examples/durable-event/run.js +0 -2
- 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_sleep/event.js +0 -1
- package/v1/examples/durable_sleep/run.js +0 -2
- 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/slot-types.js +0 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
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/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.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,14 +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
7
|
export interface IHatchetClient {
|
|
14
8
|
/** @deprecated v0 client will be removed in a future release, please upgrade to v1 */
|
|
15
9
|
v0: LegacyHatchetClient;
|
|
@@ -17,10 +11,15 @@ export interface IHatchetClient {
|
|
|
17
11
|
dispatcher: DispatcherClient;
|
|
18
12
|
events: EventClient;
|
|
19
13
|
logger: Logger;
|
|
14
|
+
logs: LogsClient;
|
|
20
15
|
metrics: MetricsClient;
|
|
21
16
|
runs: RunsClient;
|
|
22
17
|
workflows: WorkflowsClient;
|
|
23
18
|
workers: WorkersClient;
|
|
19
|
+
webhooks: WebhooksClient;
|
|
20
|
+
tenant: TenantClient;
|
|
21
|
+
filters: FiltersClient;
|
|
22
|
+
ratelimits: RatelimitsClient;
|
|
24
23
|
scheduled: ScheduleClient;
|
|
25
24
|
crons: CronClient;
|
|
26
25
|
admin: AdminClient;
|
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
|
}
|
|
@@ -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) {
|
|
@@ -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;
|
|
@@ -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 &&
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The Hatchet Context class provides helper methods and useful data to tasks at runtime. It is passed as the second argument to all tasks and durable tasks.
|
|
4
|
+
*
|
|
5
|
+
* There are two types of context classes you'll encounter:
|
|
6
|
+
*
|
|
7
|
+
* - Context - The standard context for regular tasks with methods for logging, task output retrieval, cancellation, and more.
|
|
8
|
+
* - DurableContext - An extended context for durable tasks that includes additional methods for durable execution.
|
|
9
|
+
* @module Context
|
|
10
|
+
*/
|
|
2
11
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
12
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
13
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -13,17 +22,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
22
|
};
|
|
14
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
24
|
exports.DurableContext = exports.Context = exports.ContextWorker = void 0;
|
|
16
|
-
/**
|
|
17
|
-
* The Hatchet Context class provides helper methods and useful data to tasks at runtime. It is passed as the second argument to all tasks and durable tasks.
|
|
18
|
-
*
|
|
19
|
-
* There are two types of context classes you'll encounter:
|
|
20
|
-
*
|
|
21
|
-
* - Context - The standard context for regular tasks with methods for logging, task output retrieval, cancellation, and more.
|
|
22
|
-
* - DurableContext - An extended context for durable tasks that includes additional methods for durable execution.
|
|
23
|
-
* @module Context
|
|
24
|
-
*/
|
|
25
|
-
/* eslint-disable no-underscore-dangle */
|
|
26
|
-
/* eslint-disable max-classes-per-file */
|
|
27
25
|
const declaration_1 = require("../../declaration");
|
|
28
26
|
const hatchet_error_1 = __importDefault(require("../../../util/errors/hatchet-error"));
|
|
29
27
|
const parse_1 = require("../../../util/parse");
|
|
@@ -402,7 +400,6 @@ class Context {
|
|
|
402
400
|
return __awaiter(this, void 0, void 0, function* () {
|
|
403
401
|
const refs = yield this.spawnBulk(children);
|
|
404
402
|
refs.forEach((ref) => {
|
|
405
|
-
// eslint-disable-next-line no-param-reassign
|
|
406
403
|
ref.defaultSignal = this.abortController.signal;
|
|
407
404
|
});
|
|
408
405
|
return refs;
|
|
@@ -431,7 +428,6 @@ class Context {
|
|
|
431
428
|
return __awaiter(this, void 0, void 0, function* () {
|
|
432
429
|
const run = yield this.spawn(workflow, input, options);
|
|
433
430
|
// Ensure waiting for the child result aborts when this task is cancelled.
|
|
434
|
-
// eslint-disable-next-line no-param-reassign
|
|
435
431
|
run.defaultSignal = this.abortController.signal;
|
|
436
432
|
return run.output;
|
|
437
433
|
});
|
|
@@ -560,7 +556,6 @@ class Context {
|
|
|
560
556
|
}
|
|
561
557
|
// `signal` must never be sent over the wire.
|
|
562
558
|
const optsWithoutSignal = Object.assign({}, opts);
|
|
563
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
564
559
|
delete optsWithoutSignal.signal;
|
|
565
560
|
const resp = {
|
|
566
561
|
workflowName: name,
|
|
@@ -582,7 +577,6 @@ class Context {
|
|
|
582
577
|
resp.forEach((ref, index) => {
|
|
583
578
|
const wf = workflows[index].workflow;
|
|
584
579
|
if (wf instanceof declaration_1.TaskWorkflowDeclaration) {
|
|
585
|
-
// eslint-disable-next-line no-param-reassign
|
|
586
580
|
ref._standaloneTaskName = wf._standalone_task_name;
|
|
587
581
|
}
|
|
588
582
|
res.push(ref);
|
|
@@ -608,13 +602,7 @@ class Context {
|
|
|
608
602
|
return __awaiter(this, void 0, void 0, function* () {
|
|
609
603
|
this.throwIfCancelled();
|
|
610
604
|
const { workflowRunId, taskRunExternalId } = this.action;
|
|
611
|
-
|
|
612
|
-
if (typeof workflow === 'string') {
|
|
613
|
-
workflowName = workflow;
|
|
614
|
-
}
|
|
615
|
-
else {
|
|
616
|
-
workflowName = workflow.name;
|
|
617
|
-
}
|
|
605
|
+
const workflowName = typeof workflow === 'string' ? workflow : workflow.name;
|
|
618
606
|
const name = (0, apply_namespace_1.applyNamespace)(workflowName, this.v1.config.namespace).toLowerCase();
|
|
619
607
|
const opts = options || {};
|
|
620
608
|
const { sticky } = opts;
|
|
@@ -670,8 +658,7 @@ class DurableContext extends Context {
|
|
|
670
658
|
waitFor(conditions) {
|
|
671
659
|
return __awaiter(this, void 0, void 0, function* () {
|
|
672
660
|
this.throwIfCancelled();
|
|
673
|
-
const pbConditions = (0, transformer_1.conditionsToPb)((0, conditions_1.Render)(condition_1.Action.CREATE, conditions));
|
|
674
|
-
// eslint-disable-next-line no-plusplus
|
|
661
|
+
const pbConditions = (0, transformer_1.conditionsToPb)((0, conditions_1.Render)(condition_1.Action.CREATE, conditions), this.v1.config.namespace);
|
|
675
662
|
const key = `waitFor-${this.waitKey++}`;
|
|
676
663
|
yield this.v1.durableListener.registerDurableEvent({
|
|
677
664
|
taskId: this.action.taskRunExternalId,
|