@hatchet-dev/typescript-sdk 1.0.2 → 1.0.3
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/package.json +1 -1
- package/v1/client/client.d.ts +3 -3
- package/v1/declaration.d.ts +6 -6
- package/v1/declaration.js +3 -3
- package/v1/examples/cancellations/workflow.d.ts +2 -2
- package/v1/examples/concurrency-rr/workflow.js +2 -2
- package/v1/examples/durable-sleep/workflow.d.ts +1 -1
- package/v1/examples/durable-sleep/workflow.js +1 -1
- package/v1/examples/on_failure/workflow.d.ts +1 -1
- package/v1/examples/on_success/workflow.d.ts +1 -1
- package/v1/examples/rate_limit/run.d.ts +1 -0
- package/v1/examples/rate_limit/run.js +29 -0
- package/v1/examples/rate_limit/worker.d.ts +1 -0
- package/v1/examples/rate_limit/worker.js +24 -0
- package/v1/examples/rate_limit/workflow.d.ts +5 -0
- package/v1/examples/rate_limit/workflow.js +40 -0
- package/v1/examples/retries/workflow.d.ts +3 -3
- package/v1/examples/retries/workflow.js +7 -4
- package/v1/examples/simple/run.js +2 -4
- package/v1/examples/sticky/workflow.d.ts +1 -1
- package/v1/examples/timeouts/workflow.d.ts +2 -2
- package/v1/index.d.ts +1 -0
- package/v1/index.js +1 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/package.json
CHANGED
package/v1/client/client.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export declare class HatchetClient implements IHatchetClient {
|
|
|
51
51
|
* @returns A new Workflow instance
|
|
52
52
|
* @note It is possible to create an orphaned workflow if no client is available using @hatchet/client CreateWorkflow
|
|
53
53
|
*/
|
|
54
|
-
workflow<T extends JsonObject =
|
|
54
|
+
workflow<T extends JsonObject | unknown = unknown, K extends JsonObject | unknown = unknown>(options: CreateWorkflowOpts): WorkflowDeclaration<T, K>;
|
|
55
55
|
/**
|
|
56
56
|
* Creates a new task workflow.
|
|
57
57
|
* Types can be explicitly specified as generics or inferred from the function signature.
|
|
@@ -60,14 +60,14 @@ export declare class HatchetClient implements IHatchetClient {
|
|
|
60
60
|
* @param options Task configuration options
|
|
61
61
|
* @returns A TaskWorkflowDeclaration instance
|
|
62
62
|
*/
|
|
63
|
-
task<T extends JsonObject, K extends JsonObject>(options: CreateTaskWorkflowOpts<T, K>): TaskWorkflowDeclaration<T, K>;
|
|
63
|
+
task<T extends JsonObject | unknown, K extends JsonObject | unknown>(options: CreateTaskWorkflowOpts<T, K>): TaskWorkflowDeclaration<T, K>;
|
|
64
64
|
/**
|
|
65
65
|
* Creates a new task workflow with types inferred from the function parameter.
|
|
66
66
|
* @template Fn The type of the task function with input and output extending JsonObject
|
|
67
67
|
* @param options Task configuration options with function that defines types
|
|
68
68
|
* @returns A TaskWorkflowDeclaration instance with inferred types
|
|
69
69
|
*/
|
|
70
|
-
task<Fn extends (input: I, ctx?: any) => O | Promise<O>, I extends JsonObject = Parameters<Fn>[0], O extends JsonObject = ReturnType<Fn> extends Promise<infer P> ? P extends JsonObject ? P : never : ReturnType<Fn> extends JsonObject ? ReturnType<Fn> : never>(options: {
|
|
70
|
+
task<Fn extends (input: I, ctx?: any) => O | Promise<O>, I extends JsonObject | unknown = Parameters<Fn>[0], O extends JsonObject | unknown = ReturnType<Fn> extends Promise<infer P> ? P extends JsonObject ? P : never : ReturnType<Fn> extends JsonObject ? ReturnType<Fn> : never>(options: {
|
|
71
71
|
fn: Fn;
|
|
72
72
|
} & Omit<CreateTaskWorkflowOpts<I, O>, 'fn'>): TaskWorkflowDeclaration<I, O>;
|
|
73
73
|
/**
|
package/v1/declaration.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export type CreateBaseWorkflowOpts = {
|
|
|
55
55
|
onEvents?: string[];
|
|
56
56
|
concurrency?: TaskConcurrency;
|
|
57
57
|
};
|
|
58
|
-
export type CreateTaskWorkflowOpts<T extends JsonObject =
|
|
58
|
+
export type CreateTaskWorkflowOpts<T extends JsonObject | unknown = unknown, K extends JsonObject | unknown = unknown> = CreateBaseWorkflowOpts & CreateBaseTaskOpts<T, K, TaskFn<T, K>>;
|
|
59
59
|
/**
|
|
60
60
|
* Options for creating a new workflow.
|
|
61
61
|
*/
|
|
@@ -144,7 +144,7 @@ export type WorkflowDefinition = CreateWorkflowOpts & {
|
|
|
144
144
|
* @template T The input type for the workflow.
|
|
145
145
|
* @template K The return type of the workflow.
|
|
146
146
|
*/
|
|
147
|
-
export declare class BaseWorkflowDeclaration<T extends JsonObject, K extends JsonObject> {
|
|
147
|
+
export declare class BaseWorkflowDeclaration<T extends JsonObject | unknown, K extends JsonObject | unknown> {
|
|
148
148
|
/**
|
|
149
149
|
* The Hatchet client instance used to execute the workflow.
|
|
150
150
|
*/
|
|
@@ -242,7 +242,7 @@ export declare class BaseWorkflowDeclaration<T extends JsonObject, K extends Jso
|
|
|
242
242
|
*/
|
|
243
243
|
get name(): string;
|
|
244
244
|
}
|
|
245
|
-
export declare class WorkflowDeclaration<T extends JsonObject, K extends JsonObject> extends BaseWorkflowDeclaration<T, K> {
|
|
245
|
+
export declare class WorkflowDeclaration<T extends JsonObject | unknown = unknown, K extends JsonObject | unknown = unknown> extends BaseWorkflowDeclaration<T, K> {
|
|
246
246
|
/**
|
|
247
247
|
* Adds a task to the workflow.
|
|
248
248
|
* The return type will be either the property on K that corresponds to the task name,
|
|
@@ -292,7 +292,7 @@ export declare class WorkflowDeclaration<T extends JsonObject, K extends JsonObj
|
|
|
292
292
|
fn: (input: T, ctx: DurableContext<T>) => TaskOutputType<K, Name, L> | Promise<TaskOutputType<K, Name, L>>;
|
|
293
293
|
}): CreateWorkflowDurableTaskOpts<T, TaskOutputType<K, Name, L>>;
|
|
294
294
|
}
|
|
295
|
-
export declare class TaskWorkflowDeclaration<T extends JsonObject, K extends JsonObject> extends BaseWorkflowDeclaration<T, K> {
|
|
295
|
+
export declare class TaskWorkflowDeclaration<T extends JsonObject | unknown = unknown, K extends JsonObject | unknown = unknown> extends BaseWorkflowDeclaration<T, K> {
|
|
296
296
|
private _standalone_task_name;
|
|
297
297
|
constructor(options: CreateTaskWorkflowOpts<T, K>, client?: IHatchetClient);
|
|
298
298
|
run(input: T, options?: RunOpts): Promise<K>;
|
|
@@ -306,7 +306,7 @@ export declare class TaskWorkflowDeclaration<T extends JsonObject, K extends Jso
|
|
|
306
306
|
* @param client Optional Hatchet client instance.
|
|
307
307
|
* @returns A new TaskWorkflowDeclaration with inferred types.
|
|
308
308
|
*/
|
|
309
|
-
export declare function CreateTaskWorkflow<Fn extends (input: I, ctx?: any) => O | Promise<O>, I extends JsonObject = Parameters<Fn>[0], O extends JsonObject = ReturnType<Fn> extends Promise<infer P> ? P extends JsonObject ? P : never : ReturnType<Fn> extends JsonObject ? ReturnType<Fn> : never>(options: {
|
|
309
|
+
export declare function CreateTaskWorkflow<Fn extends (input: I, ctx?: any) => O | Promise<O>, I extends JsonObject | unknown = Parameters<Fn>[0], O extends JsonObject | unknown = ReturnType<Fn> extends Promise<infer P> ? P extends JsonObject ? P : never : ReturnType<Fn> extends JsonObject ? ReturnType<Fn> : never>(options: {
|
|
310
310
|
fn: Fn;
|
|
311
311
|
} & Omit<CreateTaskWorkflowOpts<I, O>, 'fn'>, client?: IHatchetClient): TaskWorkflowDeclaration<I, O>;
|
|
312
312
|
/**
|
|
@@ -317,7 +317,7 @@ export declare function CreateTaskWorkflow<Fn extends (input: I, ctx?: any) => O
|
|
|
317
317
|
* @param client Optional Hatchet client instance.
|
|
318
318
|
* @returns A new Workflow instance.
|
|
319
319
|
*/
|
|
320
|
-
export declare function CreateWorkflow<T extends JsonObject =
|
|
320
|
+
export declare function CreateWorkflow<T extends JsonObject | unknown = unknown, K extends JsonObject | unknown = unknown>(options: CreateWorkflowOpts, client?: IHatchetClient): WorkflowDeclaration<T, K>;
|
|
321
321
|
/**
|
|
322
322
|
* Creates a new durable task workflow declaration with types inferred from the function parameter.
|
|
323
323
|
* @template Fn The type of the durable task function
|
package/v1/declaration.js
CHANGED
|
@@ -81,7 +81,7 @@ class BaseWorkflowDeclaration {
|
|
|
81
81
|
}
|
|
82
82
|
const scheduled = this.client._v0.schedule.create(this.definition.name, {
|
|
83
83
|
triggerAt: enqueueAt,
|
|
84
|
-
input,
|
|
84
|
+
input: input,
|
|
85
85
|
additionalMetadata: options === null || options === void 0 ? void 0 : options.additionalMetadata,
|
|
86
86
|
});
|
|
87
87
|
return scheduled;
|
|
@@ -118,7 +118,7 @@ class BaseWorkflowDeclaration {
|
|
|
118
118
|
}
|
|
119
119
|
const cronDef = this.client._v0.cron.create(this.definition.name, {
|
|
120
120
|
expression,
|
|
121
|
-
input,
|
|
121
|
+
input: input,
|
|
122
122
|
additionalMetadata: options === null || options === void 0 ? void 0 : options.additionalMetadata,
|
|
123
123
|
name,
|
|
124
124
|
});
|
|
@@ -288,7 +288,7 @@ class TaskWorkflowDeclaration extends BaseWorkflowDeclaration {
|
|
|
288
288
|
run: { get: () => super.run }
|
|
289
289
|
});
|
|
290
290
|
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
-
const res = yield _super.run.call(this, input, options);
|
|
291
|
+
const res = (yield _super.run.call(this, input, options));
|
|
292
292
|
if (Array.isArray(res)) {
|
|
293
293
|
return res.map((r) => r[this._standalone_task_name]);
|
|
294
294
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const cancellation: import("../..").TaskWorkflowDeclaration<
|
|
2
|
-
Completed:
|
|
1
|
+
export declare const cancellation: import("../..").TaskWorkflowDeclaration<unknown, {
|
|
2
|
+
Completed: boolean;
|
|
3
3
|
}>;
|
|
@@ -15,11 +15,11 @@ const hatchet_client_1 = require("../hatchet-client");
|
|
|
15
15
|
const sleep = (ms) => new Promise((resolve) => {
|
|
16
16
|
setTimeout(resolve, ms);
|
|
17
17
|
});
|
|
18
|
-
// ❓
|
|
18
|
+
// ❓ Concurrency Strategy With Key
|
|
19
19
|
exports.simpleConcurrency = hatchet_client_1.hatchet.workflow({
|
|
20
20
|
name: 'simple-concurrency',
|
|
21
21
|
concurrency: {
|
|
22
|
-
maxRuns:
|
|
22
|
+
maxRuns: 1,
|
|
23
23
|
limitStrategy: workflow_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
|
|
24
24
|
expression: 'input.GroupKey',
|
|
25
25
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const durableSleep: import("../..").WorkflowDeclaration<
|
|
1
|
+
export declare const durableSleep: import("../..").WorkflowDeclaration<unknown, unknown>;
|
|
@@ -23,7 +23,7 @@ exports.durableSleep.durableTask({
|
|
|
23
23
|
console.log('sleeping for 5s');
|
|
24
24
|
const sleepRes = yield ctx.sleepFor('5s');
|
|
25
25
|
console.log('done sleeping for 5s', sleepRes);
|
|
26
|
-
// wait for an event or a sleep
|
|
26
|
+
// wait for either an event or a sleep
|
|
27
27
|
const res = yield ctx.waitFor((0, conditions_1.Or)({
|
|
28
28
|
eventKey: 'user:event',
|
|
29
29
|
}, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const failureWorkflow: import("../..").WorkflowDeclaration<
|
|
1
|
+
export declare const failureWorkflow: import("../..").WorkflowDeclaration<unknown, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const onSuccessDag: import("../..").WorkflowDeclaration<
|
|
1
|
+
export declare const onSuccessDag: import("../..").WorkflowDeclaration<unknown, unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
/* eslint-disable no-console */
|
|
13
|
+
const workflow_1 = require("./workflow");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
const res = yield workflow_1.rateLimitWorkflow.run({ userId: 'abc' });
|
|
18
|
+
console.log(res);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
console.log('error', e);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (require.main === module) {
|
|
26
|
+
main()
|
|
27
|
+
.catch(console.error)
|
|
28
|
+
.finally(() => process.exit(0));
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
13
|
+
const workflow_1 = require("./workflow");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const worker = yield hatchet_client_1.hatchet.worker('rate-limit-worker', {
|
|
17
|
+
workflows: [workflow_1.rateLimitWorkflow],
|
|
18
|
+
});
|
|
19
|
+
yield worker.start();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rateLimitWorkflow = void 0;
|
|
4
|
+
const workflows_1 = require("../../../protoc/v1/workflows");
|
|
5
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
6
|
+
exports.rateLimitWorkflow = hatchet_client_1.hatchet.workflow({
|
|
7
|
+
name: 'RateLimitWorkflow',
|
|
8
|
+
});
|
|
9
|
+
// !!
|
|
10
|
+
// ❓ Static
|
|
11
|
+
const RATE_LIMIT_KEY = 'test-limit';
|
|
12
|
+
const task1 = exports.rateLimitWorkflow.task({
|
|
13
|
+
name: 'task1',
|
|
14
|
+
fn: (input) => {
|
|
15
|
+
console.log('executed task1');
|
|
16
|
+
},
|
|
17
|
+
rateLimits: [
|
|
18
|
+
{
|
|
19
|
+
staticKey: RATE_LIMIT_KEY,
|
|
20
|
+
units: 1,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
// !!
|
|
25
|
+
// ❓ Dynamic
|
|
26
|
+
const task2 = exports.rateLimitWorkflow.task({
|
|
27
|
+
name: 'task2',
|
|
28
|
+
fn: (input) => {
|
|
29
|
+
console.log('executed task2 for user: ', input.userId);
|
|
30
|
+
},
|
|
31
|
+
rateLimits: [
|
|
32
|
+
{
|
|
33
|
+
dynamicKey: 'input.userId',
|
|
34
|
+
units: 1,
|
|
35
|
+
limit: 10,
|
|
36
|
+
duration: workflows_1.RateLimitDuration.MINUTE,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
});
|
|
40
|
+
// !!
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare const retries: import("../..").TaskWorkflowDeclaration<
|
|
2
|
-
export declare const retriesWithCount: import("../..").TaskWorkflowDeclaration<
|
|
1
|
+
export declare const retries: import("../..").TaskWorkflowDeclaration<unknown, never>;
|
|
2
|
+
export declare const retriesWithCount: import("../..").TaskWorkflowDeclaration<unknown, {
|
|
3
3
|
message: string;
|
|
4
4
|
}>;
|
|
5
|
-
export declare const withBackoff: import("../..").TaskWorkflowDeclaration<
|
|
5
|
+
export declare const withBackoff: import("../..").TaskWorkflowDeclaration<unknown, never>;
|
|
@@ -21,7 +21,7 @@ exports.retries = hatchet_client_1.hatchet.task({
|
|
|
21
21
|
}),
|
|
22
22
|
});
|
|
23
23
|
// !!
|
|
24
|
-
// ❓
|
|
24
|
+
// ❓ Retries with Count
|
|
25
25
|
exports.retriesWithCount = hatchet_client_1.hatchet.task({
|
|
26
26
|
name: 'retriesWithCount',
|
|
27
27
|
retries: 3,
|
|
@@ -38,13 +38,16 @@ exports.retriesWithCount = hatchet_client_1.hatchet.task({
|
|
|
38
38
|
}),
|
|
39
39
|
});
|
|
40
40
|
// !!
|
|
41
|
-
// ❓
|
|
41
|
+
// ❓ Retries with Backoff
|
|
42
42
|
exports.withBackoff = hatchet_client_1.hatchet.task({
|
|
43
43
|
name: 'withBackoff',
|
|
44
|
-
retries:
|
|
44
|
+
retries: 10,
|
|
45
45
|
backoff: {
|
|
46
|
-
|
|
46
|
+
// 👀 Maximum number of seconds to wait between retries
|
|
47
47
|
maxSeconds: 10,
|
|
48
|
+
// 👀 Factor to increase the wait time between retries.
|
|
49
|
+
// This sequence will be 2s, 4s, 8s, 10s, 10s, 10s... due to the maxSeconds limit
|
|
50
|
+
factor: 2,
|
|
48
51
|
},
|
|
49
52
|
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
53
|
throw new Error('intentional failure');
|
|
@@ -10,16 +10,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
/* eslint-disable no-console */
|
|
13
|
-
// ❓ Running a Task with Results
|
|
14
13
|
const workflow_1 = require("./workflow");
|
|
15
|
-
// ...
|
|
16
14
|
function main() {
|
|
17
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
//
|
|
16
|
+
// ❓ Running a Task
|
|
19
17
|
const res = yield workflow_1.simple.run({
|
|
20
18
|
Message: 'HeLlO WoRlD',
|
|
21
19
|
});
|
|
22
|
-
// 👀 Access the results of the
|
|
20
|
+
// 👀 Access the results of the Task
|
|
23
21
|
console.log(res.TransformedMessage);
|
|
24
22
|
// !!
|
|
25
23
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const cancellation: import("../..").TaskWorkflowDeclaration<
|
|
2
|
-
Completed:
|
|
1
|
+
export declare const cancellation: import("../..").TaskWorkflowDeclaration<unknown, {
|
|
2
|
+
Completed: boolean;
|
|
3
3
|
}>;
|
package/v1/index.d.ts
CHANGED
package/v1/index.js
CHANGED
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.0.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.0.3";
|
package/version.js
CHANGED