@hatchet-dev/typescript-sdk 1.12.1 → 1.13.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/hatchet-client/client-config.d.ts +59 -0
- package/clients/hatchet-client/client-config.js +7 -0
- package/clients/worker/worker.js +25 -1
- package/package.json +1 -1
- package/step.d.ts +18 -18
- package/v1/client/client.d.ts +30 -14
- package/v1/client/client.js +32 -4
- package/v1/client/worker/worker-internal.js +24 -1
- package/v1/declaration.d.ts +63 -15
- package/v1/declaration.js +66 -2
- package/v1/examples/cancellations/workflow.d.ts +2 -2
- package/v1/examples/child_workflows/workflow.d.ts +4 -4
- package/v1/examples/concurrency-rr/workflow.d.ts +2 -2
- package/v1/examples/dag/interface-workflow.d.ts +1 -1
- package/v1/examples/dag/workflow.d.ts +1 -1
- package/v1/examples/dag_match_condition/complex-workflow.d.ts +1 -1
- package/v1/examples/dag_match_condition/workflow.d.ts +1 -1
- package/v1/examples/deep/workflow.d.ts +6 -6
- package/v1/examples/durable-event/workflow.d.ts +2 -2
- package/v1/examples/durable-sleep/workflow.d.ts +1 -1
- package/v1/examples/hatchet-client.d.ts +1 -1
- package/v1/examples/high-memory/workflow-with-child.d.ts +2 -2
- package/v1/examples/inferred-typing/workflow.d.ts +4 -4
- package/v1/examples/landing_page/event-signaling.d.ts +1 -1
- package/v1/examples/landing_page/flow-control.d.ts +1 -1
- package/v1/examples/landing_page/task-routing.d.ts +1 -1
- package/v1/examples/middleware/client.d.ts +26 -0
- package/v1/examples/middleware/client.js +39 -0
- package/v1/examples/middleware/recipes.d.ts +1 -0
- package/v1/examples/middleware/recipes.js +95 -0
- package/v1/examples/middleware/run.d.ts +1 -0
- package/v1/examples/middleware/run.js +29 -0
- package/v1/examples/middleware/worker.d.ts +1 -0
- package/v1/examples/middleware/worker.js +24 -0
- package/v1/examples/middleware/workflow.d.ts +15 -0
- package/v1/examples/middleware/workflow.js +18 -0
- package/v1/examples/migration-guides/hatchet-client.d.ts +1 -1
- package/v1/examples/migration-guides/mergent.d.ts +1 -1
- package/v1/examples/multiple_wf_concurrency/workflow.d.ts +1 -1
- package/v1/examples/non_retryable/workflow.d.ts +1 -1
- package/v1/examples/on_cron/workflow.d.ts +1 -1
- package/v1/examples/on_event/workflow.d.ts +3 -3
- package/v1/examples/on_failure/workflow.d.ts +1 -1
- package/v1/examples/on_success/workflow.d.ts +1 -1
- package/v1/examples/priority/workflow.d.ts +4 -4
- package/v1/examples/quickstart/hatchet-client.d.ts +1 -1
- package/v1/examples/quickstart/workflows/first-task.d.ts +1 -1
- package/v1/examples/retries/workflow.d.ts +3 -3
- package/v1/examples/simple/stub-workflow.d.ts +1 -1
- package/v1/examples/simple/workflow-with-child.d.ts +2 -2
- package/v1/examples/simple/workflow.d.ts +1 -1
- package/v1/examples/simple/zod.d.ts +1 -1
- package/v1/examples/sticky/workflow.d.ts +1 -1
- package/v1/examples/streaming/workflow.d.ts +1 -1
- package/v1/examples/timeouts/workflow.d.ts +1 -1
- package/v1/examples/with_timeouts/workflow.d.ts +2 -2
- package/v1/types.d.ts +10 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/workflow.d.ts +56 -56
package/v1/declaration.js
CHANGED
|
@@ -327,18 +327,36 @@ class WorkflowDeclaration extends BaseWorkflowDeclaration {
|
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
329
|
exports.WorkflowDeclaration = WorkflowDeclaration;
|
|
330
|
+
/**
|
|
331
|
+
* A standalone task workflow that can be run, scheduled, or triggered via cron.
|
|
332
|
+
*
|
|
333
|
+
* @template I - The task-specific input type.
|
|
334
|
+
* @template O - The task output type.
|
|
335
|
+
* @template GlobalInput - Global input type from the client, merged into all run/schedule/cron input signatures.
|
|
336
|
+
* @template MiddlewareBefore - Extra fields added to the task fn input by pre-middleware hooks.
|
|
337
|
+
* @template MiddlewareAfter - Extra fields merged into the task output by post-middleware hooks.
|
|
338
|
+
*/
|
|
330
339
|
class TaskWorkflowDeclaration extends BaseWorkflowDeclaration {
|
|
331
340
|
constructor(options, client) {
|
|
332
341
|
super(Object.assign({}, options), client);
|
|
333
342
|
this._standalone_task_name = options.name;
|
|
334
343
|
this.definition._tasks.push(Object.assign({}, options));
|
|
335
344
|
}
|
|
345
|
+
runAndWait(input, options) {
|
|
346
|
+
const _super = Object.create(null, {
|
|
347
|
+
runAndWait: { get: () => super.runAndWait }
|
|
348
|
+
});
|
|
349
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
350
|
+
return Array.isArray(input)
|
|
351
|
+
? _super.runAndWait.call(this, input, options, this._standalone_task_name)
|
|
352
|
+
: _super.runAndWait.call(this, input, options, this._standalone_task_name);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
336
355
|
run(input, options) {
|
|
337
356
|
const _super = Object.create(null, {
|
|
338
357
|
run: { get: () => super.run }
|
|
339
358
|
});
|
|
340
359
|
return __awaiter(this, void 0, void 0, function* () {
|
|
341
|
-
// note: typescript is not smart enough to infer that input is an array
|
|
342
360
|
return Array.isArray(input)
|
|
343
361
|
? _super.run.call(this, input, options, this._standalone_task_name)
|
|
344
362
|
: _super.run.call(this, input, options, this._standalone_task_name);
|
|
@@ -349,12 +367,58 @@ class TaskWorkflowDeclaration extends BaseWorkflowDeclaration {
|
|
|
349
367
|
runNoWait: { get: () => super.runNoWait }
|
|
350
368
|
});
|
|
351
369
|
return __awaiter(this, void 0, void 0, function* () {
|
|
352
|
-
// note: typescript is not smart enough to infer that input is an array
|
|
353
370
|
return Array.isArray(input)
|
|
354
371
|
? _super.runNoWait.call(this, input, options, this._standalone_task_name)
|
|
355
372
|
: _super.runNoWait.call(this, input, options, this._standalone_task_name);
|
|
356
373
|
});
|
|
357
374
|
}
|
|
375
|
+
/**
|
|
376
|
+
* Schedules the task to run at a specific date and time.
|
|
377
|
+
* @param enqueueAt - The date when the task should be triggered.
|
|
378
|
+
* @param input - The input data for the task, including global input fields.
|
|
379
|
+
* @param options - Optional configuration for this task run.
|
|
380
|
+
* @returns A promise that resolves with the scheduled workflow details.
|
|
381
|
+
*/
|
|
382
|
+
schedule(enqueueAt, input, options) {
|
|
383
|
+
const _super = Object.create(null, {
|
|
384
|
+
schedule: { get: () => super.schedule }
|
|
385
|
+
});
|
|
386
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
387
|
+
return _super.schedule.call(this, enqueueAt, input, options);
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Schedules the task to run after a specified delay.
|
|
392
|
+
* @param duration - The delay in seconds before the task should run.
|
|
393
|
+
* @param input - The input data for the task, including global input fields.
|
|
394
|
+
* @param options - Optional configuration for this task run.
|
|
395
|
+
* @returns A promise that resolves with the scheduled workflow details.
|
|
396
|
+
*/
|
|
397
|
+
delay(duration, input, options) {
|
|
398
|
+
const _super = Object.create(null, {
|
|
399
|
+
delay: { get: () => super.delay }
|
|
400
|
+
});
|
|
401
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
402
|
+
return _super.delay.call(this, duration, input, options);
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Creates a cron schedule for the task.
|
|
407
|
+
* @param name - The name of the cron schedule.
|
|
408
|
+
* @param expression - The cron expression defining the schedule.
|
|
409
|
+
* @param input - The input data for the task, including global input fields.
|
|
410
|
+
* @param options - Optional configuration for this task run.
|
|
411
|
+
* @returns A promise that resolves with the cron workflow details.
|
|
412
|
+
*/
|
|
413
|
+
cron(name, expression, input, options) {
|
|
414
|
+
const _super = Object.create(null, {
|
|
415
|
+
cron: { get: () => super.cron }
|
|
416
|
+
});
|
|
417
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
418
|
+
return _super.cron.call(this, name, expression, input, options);
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
/** Returns the underlying task definition for this declaration. */
|
|
358
422
|
get taskDef() {
|
|
359
423
|
return this.definition._tasks[0];
|
|
360
424
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const cancellation: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
|
|
2
2
|
Completed: true;
|
|
3
|
-
}>;
|
|
4
|
-
export declare const abortSignal: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, void>;
|
|
3
|
+
}, {}, {}, {}, {}>;
|
|
4
|
+
export declare const abortSignal: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, void, {}, {}, {}, {}>;
|
|
@@ -3,17 +3,17 @@ type ChildInput = {
|
|
|
3
3
|
};
|
|
4
4
|
export declare const child: import("../..").TaskWorkflowDeclaration<ChildInput, {
|
|
5
5
|
Value: number;
|
|
6
|
-
}>;
|
|
6
|
+
}, {}, {}, {}, {}>;
|
|
7
7
|
type ParentInput = {
|
|
8
8
|
N: number;
|
|
9
9
|
};
|
|
10
10
|
export declare const parent: import("../..").TaskWorkflowDeclaration<ParentInput, {
|
|
11
11
|
Result: number;
|
|
12
|
-
}>;
|
|
12
|
+
}, {}, {}, {}, {}>;
|
|
13
13
|
export declare const parentSingleChild: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
|
|
14
14
|
Result: number;
|
|
15
|
-
}>;
|
|
15
|
+
}, {}, {}, {}, {}>;
|
|
16
16
|
export declare const withErrorHandling: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
|
|
17
17
|
Result: number;
|
|
18
|
-
}>;
|
|
18
|
+
}, {}, {}, {}, {}>;
|
|
19
19
|
export {};
|
|
@@ -7,6 +7,6 @@ type SimpleOutput = {
|
|
|
7
7
|
TransformedMessage: string;
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
|
-
export declare const simpleConcurrency: import("../..").WorkflowDeclaration<SimpleInput, SimpleOutput>;
|
|
11
|
-
export declare const multipleConcurrencyKeys: import("../..").WorkflowDeclaration<SimpleInput, SimpleOutput>;
|
|
10
|
+
export declare const simpleConcurrency: import("../..").WorkflowDeclaration<SimpleInput, SimpleOutput, {}>;
|
|
11
|
+
export declare const multipleConcurrencyKeys: import("../..").WorkflowDeclaration<SimpleInput, SimpleOutput, {}>;
|
|
12
12
|
export {};
|
|
@@ -8,5 +8,5 @@ interface DagOutput extends WorkflowOutputType {
|
|
|
8
8
|
Transformed: string;
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
-
export declare const dag: import("../..").WorkflowDeclaration<DagInput, DagOutput>;
|
|
11
|
+
export declare const dag: import("../..").WorkflowDeclaration<DagInput, DagOutput, {}>;
|
|
12
12
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const taskConditionWorkflow: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}>;
|
|
1
|
+
export declare const taskConditionWorkflow: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}, {}>;
|
|
@@ -7,12 +7,12 @@ type Output = {
|
|
|
7
7
|
Sum: number;
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
|
-
export declare const child1: import("../..").WorkflowDeclaration<SimpleInput, Output>;
|
|
11
|
-
export declare const child2: import("../..").WorkflowDeclaration<SimpleInput, Output>;
|
|
12
|
-
export declare const child3: import("../..").WorkflowDeclaration<SimpleInput, Output>;
|
|
13
|
-
export declare const child4: import("../..").WorkflowDeclaration<SimpleInput, Output>;
|
|
14
|
-
export declare const child5: import("../..").WorkflowDeclaration<SimpleInput, Output>;
|
|
10
|
+
export declare const child1: import("../..").WorkflowDeclaration<SimpleInput, Output, {}>;
|
|
11
|
+
export declare const child2: import("../..").WorkflowDeclaration<SimpleInput, Output, {}>;
|
|
12
|
+
export declare const child3: import("../..").WorkflowDeclaration<SimpleInput, Output, {}>;
|
|
13
|
+
export declare const child4: import("../..").WorkflowDeclaration<SimpleInput, Output, {}>;
|
|
14
|
+
export declare const child5: import("../..").WorkflowDeclaration<SimpleInput, Output, {}>;
|
|
15
15
|
export declare const parent: import("../..").WorkflowDeclaration<SimpleInput, {
|
|
16
16
|
parent: Output["transformer"];
|
|
17
|
-
}>;
|
|
17
|
+
}, {}>;
|
|
18
18
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const durableEvent: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
|
|
2
2
|
Value: string;
|
|
3
|
-
}>;
|
|
3
|
+
}, {}, {}, {}, {}>;
|
|
4
4
|
export declare const durableEventWithFilter: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
|
|
5
5
|
Value: string;
|
|
6
|
-
}>;
|
|
6
|
+
}, {}, {}, {}, {}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const durableSleep: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}>;
|
|
1
|
+
export declare const durableSleep: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}, {}>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { HatchetClient } from './..';
|
|
2
|
-
export declare const hatchet: HatchetClient
|
|
2
|
+
export declare const hatchet: HatchetClient<{}, {}, {}, {}>;
|
|
@@ -6,7 +6,7 @@ export type ParentInput = {
|
|
|
6
6
|
};
|
|
7
7
|
export declare const child: import("../..").TaskWorkflowDeclaration<ChildInput, {
|
|
8
8
|
TransformedMessage: string;
|
|
9
|
-
}>;
|
|
9
|
+
}, {}, {}, {}, {}>;
|
|
10
10
|
export declare const parent: import("../..").TaskWorkflowDeclaration<ParentInput, {
|
|
11
11
|
TransformedMessage: string;
|
|
12
|
-
}>;
|
|
12
|
+
}, {}, {}, {}, {}>;
|
|
@@ -4,12 +4,12 @@ type SimpleInput = {
|
|
|
4
4
|
type SimpleOutput = {
|
|
5
5
|
TransformedMessage: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const declaredType: import("../..").TaskWorkflowDeclaration<SimpleInput, SimpleOutput>;
|
|
7
|
+
export declare const declaredType: import("../..").TaskWorkflowDeclaration<SimpleInput, SimpleOutput, {}, {}, {}, {}>;
|
|
8
8
|
export declare const inferredType: import("../..").TaskWorkflowDeclaration<SimpleInput, {
|
|
9
9
|
TransformedMessage: string;
|
|
10
|
-
}>;
|
|
10
|
+
}, {}, {}, {}, {}>;
|
|
11
11
|
export declare const inferredTypeDurable: import("../..").TaskWorkflowDeclaration<SimpleInput, {
|
|
12
12
|
TransformedMessage: string;
|
|
13
|
-
}>;
|
|
14
|
-
export declare const crazyWorkflow: import("../..").WorkflowDeclaration<any, any>;
|
|
13
|
+
}, {}, {}, {}, {}>;
|
|
14
|
+
export declare const crazyWorkflow: import("../..").WorkflowDeclaration<any, any, {}>;
|
|
15
15
|
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { HatchetClient } from '../..';
|
|
2
|
+
export type GlobalInputType = {
|
|
3
|
+
first: number;
|
|
4
|
+
second: number;
|
|
5
|
+
};
|
|
6
|
+
export type GlobalOutputType = {
|
|
7
|
+
extra: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const hatchetWithMiddleware: HatchetClient<GlobalInputType, GlobalOutputType, {
|
|
10
|
+
dependency: string;
|
|
11
|
+
first: number;
|
|
12
|
+
second: number;
|
|
13
|
+
}, {
|
|
14
|
+
additionalData: number;
|
|
15
|
+
extra: number;
|
|
16
|
+
}>;
|
|
17
|
+
export declare const hatchetWithMiddlewareChaining: HatchetClient<GlobalInputType, {}, {
|
|
18
|
+
dependency: string;
|
|
19
|
+
first: number;
|
|
20
|
+
second: number;
|
|
21
|
+
} & {
|
|
22
|
+
anotherDep: boolean;
|
|
23
|
+
first: number;
|
|
24
|
+
second: number;
|
|
25
|
+
dependency: string;
|
|
26
|
+
}, any>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hatchetWithMiddlewareChaining = exports.hatchetWithMiddleware = void 0;
|
|
4
|
+
// > Init a client with middleware
|
|
5
|
+
const v1_1 = require("../..");
|
|
6
|
+
const myMiddleware = {
|
|
7
|
+
before: (input, ctx) => {
|
|
8
|
+
console.log('before', input.first);
|
|
9
|
+
return Object.assign(Object.assign({}, input), { dependency: 'abc-123' });
|
|
10
|
+
},
|
|
11
|
+
after: (output, ctx, input) => {
|
|
12
|
+
return Object.assign(Object.assign({}, output), { additionalData: 2 });
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
exports.hatchetWithMiddleware = v1_1.HatchetClient.init().withMiddleware(myMiddleware);
|
|
16
|
+
// !!
|
|
17
|
+
// > Chaining middleware
|
|
18
|
+
const firstMiddleware = {
|
|
19
|
+
before: (input, ctx) => {
|
|
20
|
+
console.log('before', input.first);
|
|
21
|
+
return Object.assign(Object.assign({}, input), { dependency: 'abc-123' });
|
|
22
|
+
},
|
|
23
|
+
after: (output, ctx, input) => {
|
|
24
|
+
return Object.assign(Object.assign({}, output), { firstExtra: 3 });
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
const secondMiddleware = {
|
|
28
|
+
before: (input, ctx) => {
|
|
29
|
+
console.log('before', input.dependency); // available from previous middleware
|
|
30
|
+
return Object.assign(Object.assign({}, input), { anotherDep: true });
|
|
31
|
+
},
|
|
32
|
+
after: (output, ctx, input) => {
|
|
33
|
+
return Object.assign(Object.assign({}, output), { secondExtra: 4 });
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
exports.hatchetWithMiddlewareChaining = v1_1.HatchetClient.init()
|
|
37
|
+
.withMiddleware(firstMiddleware)
|
|
38
|
+
.withMiddleware(secondMiddleware);
|
|
39
|
+
// !!
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
// These snippets demonstrate common middleware patterns.
|
|
4
|
+
// They reference external packages (@aws-sdk/*) that are NOT
|
|
5
|
+
// dependencies of the Hatchet SDK — install them in your own project.
|
|
6
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
// > End-to-end encryption
|
|
17
|
+
const v1_1 = require("../..");
|
|
18
|
+
const crypto_1 = require("crypto");
|
|
19
|
+
// !!
|
|
20
|
+
// > Offloading large payloads to S3
|
|
21
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
22
|
+
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
23
|
+
const ALGORITHM = 'aes-256-gcm';
|
|
24
|
+
const KEY = Buffer.from(process.env.ENCRYPTION_KEY, 'hex');
|
|
25
|
+
function encrypt(plaintext) {
|
|
26
|
+
const iv = (0, crypto_1.randomBytes)(16);
|
|
27
|
+
const cipher = (0, crypto_1.createCipheriv)(ALGORITHM, KEY, iv);
|
|
28
|
+
const encrypted = Buffer.concat([cipher.update(plaintext, 'utf8'), cipher.final()]);
|
|
29
|
+
return {
|
|
30
|
+
ciphertext: encrypted.toString('base64'),
|
|
31
|
+
iv: iv.toString('base64'),
|
|
32
|
+
tag: cipher.getAuthTag().toString('base64'),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function decrypt(ciphertext, iv, tag) {
|
|
36
|
+
const decipher = (0, crypto_1.createDecipheriv)(ALGORITHM, KEY, Buffer.from(iv, 'base64'));
|
|
37
|
+
decipher.setAuthTag(Buffer.from(tag, 'base64'));
|
|
38
|
+
return decipher.update(ciphertext, 'base64', 'utf8') + decipher.final('utf8');
|
|
39
|
+
}
|
|
40
|
+
const e2eEncryption = {
|
|
41
|
+
before: (input) => {
|
|
42
|
+
if (!input.encrypted)
|
|
43
|
+
return input;
|
|
44
|
+
const { ciphertext, iv, tag } = input.encrypted;
|
|
45
|
+
const decrypted = JSON.parse(decrypt(ciphertext, iv, tag));
|
|
46
|
+
return Object.assign(Object.assign(Object.assign({}, input), decrypted), { encrypted: undefined });
|
|
47
|
+
},
|
|
48
|
+
after: (output) => {
|
|
49
|
+
const payload = JSON.stringify(output);
|
|
50
|
+
return { encrypted: encrypt(payload) };
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
const encryptionClient = v1_1.HatchetClient.init().withMiddleware(e2eEncryption);
|
|
54
|
+
const s3 = new client_s3_1.S3Client({ region: process.env.AWS_REGION });
|
|
55
|
+
const BUCKET = process.env.S3_BUCKET;
|
|
56
|
+
const PAYLOAD_THRESHOLD = 256 * 1024; // 256 KB
|
|
57
|
+
function uploadToS3(data) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const key = `hatchet-payloads/${(0, crypto_1.randomUUID)()}.json`;
|
|
60
|
+
yield s3.send(new client_s3_1.PutObjectCommand({
|
|
61
|
+
Bucket: BUCKET,
|
|
62
|
+
Key: key,
|
|
63
|
+
Body: JSON.stringify(data),
|
|
64
|
+
ContentType: 'application/json',
|
|
65
|
+
}));
|
|
66
|
+
return (0, s3_request_presigner_1.getSignedUrl)(s3, new client_s3_1.GetObjectCommand({ Bucket: BUCKET, Key: key }), {
|
|
67
|
+
expiresIn: 3600,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function downloadFromS3(url) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const res = yield fetch(url);
|
|
74
|
+
return res.json();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const s3Offload = {
|
|
78
|
+
before: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
+
if (input.s3Url) {
|
|
80
|
+
const restored = (yield downloadFromS3(input.s3Url));
|
|
81
|
+
return Object.assign(Object.assign({}, restored), { s3Url: undefined });
|
|
82
|
+
}
|
|
83
|
+
return input;
|
|
84
|
+
}),
|
|
85
|
+
after: (output) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
+
const serialized = JSON.stringify(output);
|
|
87
|
+
if (serialized.length > PAYLOAD_THRESHOLD) {
|
|
88
|
+
const url = yield uploadToS3(output);
|
|
89
|
+
return { s3Url: url };
|
|
90
|
+
}
|
|
91
|
+
return output;
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
const s3Client = v1_1.HatchetClient.init().withMiddleware(s3Offload);
|
|
95
|
+
// !!
|
|
@@ -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
|
+
const workflow_1 = require("./workflow");
|
|
13
|
+
function main() {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
// > Running a task with middleware
|
|
16
|
+
const result = yield workflow_1.taskWithMiddleware.run({
|
|
17
|
+
message: 'hello', // string (from TaskInput)
|
|
18
|
+
first: 1, // number (from GlobalInputType)
|
|
19
|
+
second: 2, // number (from GlobalInputType)
|
|
20
|
+
});
|
|
21
|
+
console.log('result', result.message); // string (from TaskOutput)
|
|
22
|
+
console.log('result', result.extra); // number (from GlobalOutputType)
|
|
23
|
+
console.log('result', result.additionalData); // number (from Post Middleware)
|
|
24
|
+
// !!
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (require.main === module) {
|
|
28
|
+
main();
|
|
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 client_1 = require("./client");
|
|
13
|
+
const workflow_1 = require("./workflow");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const worker = yield client_1.hatchetWithMiddleware.worker('task-with-middleware', {
|
|
17
|
+
workflows: [workflow_1.taskWithMiddleware],
|
|
18
|
+
});
|
|
19
|
+
yield worker.start();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type TaskInput = {
|
|
2
|
+
message: string;
|
|
3
|
+
};
|
|
4
|
+
type TaskOutput = {
|
|
5
|
+
message: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const taskWithMiddleware: import("../..").TaskWorkflowDeclaration<TaskInput, TaskOutput, import("./client").GlobalInputType, import("./client").GlobalOutputType, {
|
|
8
|
+
dependency: string;
|
|
9
|
+
first: number;
|
|
10
|
+
second: number;
|
|
11
|
+
}, {
|
|
12
|
+
additionalData: number;
|
|
13
|
+
extra: number;
|
|
14
|
+
}>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.taskWithMiddleware = void 0;
|
|
4
|
+
const client_1 = require("./client");
|
|
5
|
+
exports.taskWithMiddleware = client_1.hatchetWithMiddleware.task({
|
|
6
|
+
name: 'task-with-middleware',
|
|
7
|
+
fn: (input, _ctx) => {
|
|
8
|
+
console.log('task', input.message); // string (from TaskInput)
|
|
9
|
+
console.log('task', input.first); // number (from GlobalInputType)
|
|
10
|
+
console.log('task', input.second); // number (from GlobalInputType)
|
|
11
|
+
console.log('task', input.dependency); // string (from Pre Middleware)
|
|
12
|
+
return {
|
|
13
|
+
message: input.message,
|
|
14
|
+
extra: 1,
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
// !!
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import HatchetClient from '../../../sdk';
|
|
2
|
-
export declare const hatchet: HatchetClient
|
|
2
|
+
export declare const hatchet: HatchetClient<{}, {}, {}, {}>;
|
|
@@ -19,5 +19,5 @@ type ImageProcessOutput = {
|
|
|
19
19
|
appliedFilters: string[];
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
|
-
export declare const imageProcessor: import("../..").TaskWorkflowDeclaration<ImageProcessInput, ImageProcessOutput>;
|
|
22
|
+
export declare const imageProcessor: import("../..").TaskWorkflowDeclaration<ImageProcessInput, ImageProcessOutput, {}, {}, {}, {}>;
|
|
23
23
|
export {};
|
|
@@ -7,5 +7,5 @@ type SimpleOutput = {
|
|
|
7
7
|
TransformedMessage: string;
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
|
-
export declare const multiConcurrency: import("../..").WorkflowDeclaration<SimpleInput, SimpleOutput>;
|
|
10
|
+
export declare const multiConcurrency: import("../..").WorkflowDeclaration<SimpleInput, SimpleOutput, {}>;
|
|
11
11
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const nonRetryableWorkflow: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}>;
|
|
1
|
+
export declare const nonRetryableWorkflow: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}, {}>;
|
|
@@ -8,12 +8,12 @@ type LowerOutput = {
|
|
|
8
8
|
TransformedMessage: string;
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
|
-
export declare const lower: import("../..").WorkflowDeclaration<Input, LowerOutput>;
|
|
12
|
-
export declare const lowerWithFilter: import("../..").WorkflowDeclaration<Input, LowerOutput>;
|
|
11
|
+
export declare const lower: import("../..").WorkflowDeclaration<Input, LowerOutput, {}>;
|
|
12
|
+
export declare const lowerWithFilter: import("../..").WorkflowDeclaration<Input, LowerOutput, {}>;
|
|
13
13
|
type UpperOutput = {
|
|
14
14
|
upper: {
|
|
15
15
|
TransformedMessage: string;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
-
export declare const upper: import("../..").WorkflowDeclaration<Input, UpperOutput>;
|
|
18
|
+
export declare const upper: import("../..").WorkflowDeclaration<Input, UpperOutput, {}>;
|
|
19
19
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const failureWorkflow: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}>;
|
|
1
|
+
export declare const failureWorkflow: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}, {}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const onSuccessDag: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}>;
|
|
1
|
+
export declare const onSuccessDag: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}, {}>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Priority } from '../..';
|
|
2
2
|
export declare const priority: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
|
|
3
3
|
priority: Priority | undefined;
|
|
4
|
-
}>;
|
|
5
|
-
export declare const priorityWf: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}>;
|
|
6
|
-
export declare const priorityTasks: (import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}> | import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
|
|
4
|
+
}, {}, {}, {}, {}>;
|
|
5
|
+
export declare const priorityWf: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}, {}>;
|
|
6
|
+
export declare const priorityTasks: (import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}, {}> | import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
|
|
7
7
|
priority: Priority | undefined;
|
|
8
|
-
}>)[];
|
|
8
|
+
}, {}, {}, {}, {}>)[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import Hatchet from '../../../sdk';
|
|
2
|
-
export declare const hatchet: Hatchet
|
|
2
|
+
export declare const hatchet: Hatchet<{}, {}, {}, {}>;
|
|
@@ -4,5 +4,5 @@ type SimpleInput = {
|
|
|
4
4
|
type SimpleOutput = {
|
|
5
5
|
TransformedMessage: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const firstTask: import("../../..").TaskWorkflowDeclaration<SimpleInput, SimpleOutput>;
|
|
7
|
+
export declare const firstTask: import("../../..").TaskWorkflowDeclaration<SimpleInput, SimpleOutput, {}, {}, {}, {}>;
|
|
8
8
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare const retries: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, never>;
|
|
1
|
+
export declare const retries: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, never, {}, {}, {}, {}>;
|
|
2
2
|
export declare const retriesWithCount: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
|
|
3
3
|
message: string;
|
|
4
|
-
}>;
|
|
5
|
-
export declare const withBackoff: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, never>;
|
|
4
|
+
}, {}, {}, {}, {}>;
|
|
5
|
+
export declare const withBackoff: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, never, {}, {}, {}, {}>;
|