@hatchet-dev/typescript-sdk 1.6.3 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/clients/rest/generated/Api.d.ts +62 -1
- package/clients/rest/generated/Api.js +39 -0
- package/clients/rest/generated/data-contracts.d.ts +201 -161
- package/clients/rest/generated/data-contracts.js +168 -168
- package/package.json +2 -2
- package/protoc/v1/workflows.d.ts +11 -0
- package/protoc/v1/workflows.js +105 -3
- package/v1/client/client.d.ts +7 -0
- package/v1/client/client.js +29 -0
- package/v1/client/features/filters.d.ts +1 -0
- package/v1/client/features/filters.js +6 -0
- package/v1/client/features/runs.d.ts +1 -0
- package/v1/client/features/runs.js +7 -0
- package/v1/client/features/tenant.d.ts +15 -0
- package/v1/client/features/tenant.js +31 -0
- package/v1/client/worker/worker-internal.js +6 -1
- package/v1/declaration.d.ts +3 -1
- package/v1/examples/cancellations/workflow.js +2 -2
- package/v1/examples/on_event/workflow.d.ts +1 -0
- package/v1/examples/on_event/workflow.js +27 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -18,4 +18,5 @@ export declare class FiltersClient {
|
|
|
18
18
|
get(filterId: Parameters<typeof this.api.v1FilterGet>[1]): Promise<import("../../../clients/rest/generated/data-contracts").V1Filter>;
|
|
19
19
|
create(opts: Parameters<typeof this.api.v1FilterCreate>[1]): Promise<import("../../../clients/rest/generated/data-contracts").V1Filter>;
|
|
20
20
|
delete(filterId: Parameters<typeof this.api.v1FilterDelete>[1]): Promise<import("../../../clients/rest/generated/data-contracts").V1Filter>;
|
|
21
|
+
update(filterId: Parameters<typeof this.api.v1FilterDelete>[1], updates: Parameters<typeof this.api.v1FilterUpdate>[2]): Promise<import("../../../clients/rest/generated/data-contracts").V1Filter>;
|
|
21
22
|
}
|
|
@@ -55,5 +55,11 @@ class FiltersClient {
|
|
|
55
55
|
return data;
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
+
update(filterId, updates) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const { data } = yield this.api.v1FilterUpdate(this.tenantId, filterId, updates);
|
|
61
|
+
return data;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
58
64
|
}
|
|
59
65
|
exports.FiltersClient = FiltersClient;
|
|
@@ -62,6 +62,7 @@ export declare class RunsClient {
|
|
|
62
62
|
workflows: WorkflowsClient;
|
|
63
63
|
constructor(client: HatchetClient);
|
|
64
64
|
get<T = any>(run: string | WorkflowRunRef<T>): Promise<import("../../../clients/rest/generated/data-contracts").V1WorkflowRunDetails>;
|
|
65
|
+
get_status<T = any>(run: string | WorkflowRunRef<T>): Promise<V1TaskStatus>;
|
|
65
66
|
list(opts?: Partial<ListRunsOpts>): Promise<import("../../../clients/rest/generated/data-contracts").V1TaskSummaryList>;
|
|
66
67
|
cancel(opts: CancelRunOpts): Promise<import("axios").AxiosResponse<void, any>>;
|
|
67
68
|
replay(opts: ReplayRunOpts): Promise<import("axios").AxiosResponse<void, any>>;
|
|
@@ -26,6 +26,13 @@ class RunsClient {
|
|
|
26
26
|
return data;
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
+
get_status(run) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const runId = typeof run === 'string' ? run : yield run.getWorkflowRunId();
|
|
32
|
+
const { data } = yield this.api.v1WorkflowRunGetStatus(runId);
|
|
33
|
+
return data;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
29
36
|
list(opts) {
|
|
30
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
38
|
const { data } = yield this.api.v1WorkflowRunList(this.tenantId, Object.assign({}, (yield this.prepareListFilter(opts || {}))));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Tenant } from '../../../clients/rest/generated/data-contracts';
|
|
2
|
+
import { HatchetClient } from '../client';
|
|
3
|
+
/**
|
|
4
|
+
* Client for managing Tenants
|
|
5
|
+
*/
|
|
6
|
+
export declare class TenantClient {
|
|
7
|
+
api: HatchetClient['api'];
|
|
8
|
+
tenantId: string;
|
|
9
|
+
constructor(client: HatchetClient);
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves the current tenant.
|
|
12
|
+
* @returns The Tenant object.
|
|
13
|
+
*/
|
|
14
|
+
get(): Promise<Tenant>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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.TenantClient = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* Client for managing Tenants
|
|
15
|
+
*/
|
|
16
|
+
class TenantClient {
|
|
17
|
+
constructor(client) {
|
|
18
|
+
this.api = client.api;
|
|
19
|
+
this.tenantId = client.tenantId;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves the current tenant.
|
|
23
|
+
* @returns The Tenant object.
|
|
24
|
+
*/
|
|
25
|
+
get() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
return (yield this.api.tenantGet(this.tenantId)).data;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.TenantClient = TenantClient;
|
|
@@ -116,7 +116,7 @@ class V1Worker {
|
|
|
116
116
|
}
|
|
117
117
|
registerWorkflowV1(initWorkflow_1) {
|
|
118
118
|
return __awaiter(this, arguments, void 0, function* (initWorkflow, durable = false) {
|
|
119
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
119
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
120
120
|
// patch the namespace
|
|
121
121
|
const workflow = Object.assign(Object.assign({}, initWorkflow.definition), { name: (0, apply_namespace_1.applyNamespace)(initWorkflow.definition.name, this.client.config.namespace).toLowerCase() });
|
|
122
122
|
try {
|
|
@@ -240,6 +240,11 @@ class V1Worker {
|
|
|
240
240
|
});
|
|
241
241
|
}),
|
|
242
242
|
concurrency: concurrencySolo,
|
|
243
|
+
defaultFilters: (_x = (_w = workflow.defaultFilters) === null || _w === void 0 ? void 0 : _w.map((f) => ({
|
|
244
|
+
scope: f.scope,
|
|
245
|
+
expression: f.expression,
|
|
246
|
+
payload: f.payload ? JSON.stringify(f.payload) : undefined,
|
|
247
|
+
}))) !== null && _x !== void 0 ? _x : [],
|
|
243
248
|
});
|
|
244
249
|
this.registeredWorkflowPromises.push(registeredWorkflow);
|
|
245
250
|
yield registeredWorkflow;
|
package/v1/declaration.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import WorkflowRunRef from '../util/workflow-run-ref';
|
|
2
|
-
import { CronWorkflows, ScheduledWorkflows } from '../clients/rest/generated/data-contracts';
|
|
2
|
+
import { CronWorkflows, ScheduledWorkflows, V1CreateFilterRequest } from '../clients/rest/generated/data-contracts';
|
|
3
3
|
import { Workflow as WorkflowV0 } from '../workflow';
|
|
4
4
|
import { IHatchetClient } from './client/client.interface';
|
|
5
5
|
import { CreateWorkflowTaskOpts, CreateOnFailureTaskOpts, TaskFn, CreateWorkflowDurableTaskOpts, CreateBaseTaskOpts, CreateOnSuccessTaskOpts, Concurrency, DurableTaskFn } from './task';
|
|
@@ -39,6 +39,7 @@ export type TaskOutput<O, Key extends string, Fallback> = O extends Record<Key,
|
|
|
39
39
|
* Extracts a property from an object type based on task name, or falls back to inferred type
|
|
40
40
|
*/
|
|
41
41
|
export type TaskOutputType<O, TaskName extends string, InferredType extends OutputType> = TaskName extends keyof O ? O[TaskName] extends OutputType ? O[TaskName] : InferredType : InferredType;
|
|
42
|
+
type DefaultFilter = Omit<V1CreateFilterRequest, 'workflowId'>;
|
|
42
43
|
export type CreateBaseWorkflowOpts = {
|
|
43
44
|
/**
|
|
44
45
|
* The name of the workflow.
|
|
@@ -78,6 +79,7 @@ export type CreateBaseWorkflowOpts = {
|
|
|
78
79
|
* values: Priority.LOW, Priority.MEDIUM, Priority.HIGH (1, 2, or 3 )
|
|
79
80
|
*/
|
|
80
81
|
defaultPriority?: Priority;
|
|
82
|
+
defaultFilters?: DefaultFilter[];
|
|
81
83
|
};
|
|
82
84
|
export type CreateTaskWorkflowOpts<I extends InputType = UnknownInputType, O extends OutputType = void> = CreateBaseWorkflowOpts & CreateBaseTaskOpts<I, O, TaskFn<I, O>>;
|
|
83
85
|
export type CreateDurableTaskWorkflowOpts<I extends InputType = UnknownInputType, O extends OutputType = void> = CreateBaseWorkflowOpts & CreateBaseTaskOpts<I, O, DurableTaskFn<I, O>>;
|
|
@@ -19,9 +19,9 @@ const hatchet_client_1 = require("../hatchet-client");
|
|
|
19
19
|
// > Declaring a Task
|
|
20
20
|
exports.cancellation = hatchet_client_1.hatchet.task({
|
|
21
21
|
name: 'cancellation',
|
|
22
|
-
fn: (
|
|
22
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
23
|
yield (0, sleep_1.default)(10 * 1000);
|
|
24
|
-
if (cancelled) {
|
|
24
|
+
if (ctx.cancelled) {
|
|
25
25
|
throw new Error('Task was cancelled');
|
|
26
26
|
}
|
|
27
27
|
return {
|
|
@@ -9,6 +9,7 @@ type LowerOutput = {
|
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
11
|
export declare const lower: import("../..").WorkflowDeclaration<Input, LowerOutput>;
|
|
12
|
+
export declare const lowerWithFilter: import("../..").WorkflowDeclaration<Input, LowerOutput>;
|
|
12
13
|
type UpperOutput = {
|
|
13
14
|
upper: {
|
|
14
15
|
TransformedMessage: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.upper = exports.lower = exports.SIMPLE_EVENT = void 0;
|
|
3
|
+
exports.upper = exports.lowerWithFilter = exports.lower = exports.SIMPLE_EVENT = void 0;
|
|
4
4
|
const hatchet_client_1 = require("../hatchet-client");
|
|
5
5
|
exports.SIMPLE_EVENT = 'simple-event:create';
|
|
6
6
|
// > Run workflow on event
|
|
@@ -10,6 +10,24 @@ exports.lower = hatchet_client_1.hatchet.workflow({
|
|
|
10
10
|
onEvents: ['simple-event:create'],
|
|
11
11
|
});
|
|
12
12
|
// !!
|
|
13
|
+
// > Workflow with filter
|
|
14
|
+
exports.lowerWithFilter = hatchet_client_1.hatchet.workflow({
|
|
15
|
+
name: 'lower',
|
|
16
|
+
// 👀 Declare the event that will trigger the workflow
|
|
17
|
+
onEvents: ['simple-event:create'],
|
|
18
|
+
defaultFilters: [
|
|
19
|
+
{
|
|
20
|
+
expression: 'true',
|
|
21
|
+
scope: 'example-scope',
|
|
22
|
+
payload: {
|
|
23
|
+
mainCharacter: 'Anna',
|
|
24
|
+
supportingCharacter: 'Stiva',
|
|
25
|
+
location: 'Moscow',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
// !!
|
|
13
31
|
exports.lower.task({
|
|
14
32
|
name: 'lower',
|
|
15
33
|
fn: (input) => {
|
|
@@ -32,3 +50,11 @@ exports.upper.task({
|
|
|
32
50
|
};
|
|
33
51
|
},
|
|
34
52
|
});
|
|
53
|
+
// > Accessing the filter payload
|
|
54
|
+
exports.lowerWithFilter.task({
|
|
55
|
+
name: 'lowerWithFilter',
|
|
56
|
+
fn: (input, ctx) => {
|
|
57
|
+
console.log(ctx.filterPayload());
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
// !!
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.7.1";
|
package/version.js
CHANGED