@abinnovision/nestjs-hatchet 0.2.4 → 0.3.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/CHANGELOG.md +24 -0
- package/dist/__fixtures__/test-hosts.d.ts +1 -1
- package/dist/__fixtures__/test-hosts.js +10 -10
- package/dist/accessor/host-accessor.d.ts +9 -1
- package/dist/accessor/host-accessor.js +10 -0
- package/dist/accessor/host-opts-translator.d.ts +14 -0
- package/dist/accessor/host-opts-translator.js +25 -0
- package/dist/accessor/host-opts.d.ts +31 -0
- package/dist/accessor/host-opts.js +27 -0
- package/dist/accessor/index.d.ts +1 -0
- package/dist/accessor/opts-translator.d.ts +10 -0
- package/dist/accessor/opts-translator.js +26 -0
- package/dist/client/client.d.ts +2 -2
- package/dist/client/client.js +5 -5
- package/dist/context/context-factory.d.ts +14 -8
- package/dist/context/context-factory.js +52 -25
- package/dist/context/context.d.ts +60 -3
- package/dist/context/context.js +2 -0
- package/dist/context/index.d.ts +1 -1
- package/dist/context/test-narrowing.d.ts +5 -0
- package/dist/context/test-narrowing.js +17 -0
- package/dist/context/trigger-guards.d.ts +22 -0
- package/dist/context/trigger-guards.js +2 -0
- package/dist/decorators/host-opts.d.ts +19 -0
- package/dist/decorators/host-opts.js +2 -0
- package/dist/decorators/host.decorator.d.ts +15 -2
- package/dist/decorators/host.decorator.js +2 -2
- package/dist/decorators/workflow-task.decorators.d.ts +1 -1
- package/dist/events/index.d.ts +2 -1
- package/dist/events/index.js +4 -15
- package/dist/execution/context/factory.d.ts +22 -0
- package/dist/execution/context/factory.js +70 -0
- package/dist/execution/context/index.d.ts +4 -0
- package/dist/execution/context/index.js +8 -0
- package/dist/execution/context/types.d.ts +108 -0
- package/dist/execution/context/types.js +4 -0
- package/dist/execution/host-run/adapter-factory.d.ts +12 -0
- package/dist/execution/host-run/adapter-factory.js +45 -0
- package/dist/execution/host-run/function-type.d.ts +24 -0
- package/dist/execution/host-run/function-type.js +2 -0
- package/dist/execution/host-run/index.d.ts +2 -0
- package/dist/execution/host-run/index.js +6 -0
- package/dist/execution/index.d.ts +2 -0
- package/dist/execution/index.js +2 -0
- package/dist/explorer/declaration-builder.service.d.ts +14 -7
- package/dist/explorer/declaration-builder.service.js +85 -38
- package/dist/explorer/worker-management.service.js +2 -2
- package/dist/hatchet.module.d.ts +1 -1
- package/dist/hatchet.module.js +5 -5
- package/dist/index.d.ts +3 -4
- package/dist/index.js +3 -4
- package/dist/interaction/host-run/adapter-factory.js +2 -2
- package/dist/interceptor/index.d.ts +1 -1
- package/dist/interceptor/index.js +3 -15
- package/dist/interceptor/interceptor.d.ts +1 -1
- package/dist/internal/consts.d.ts +19 -0
- package/dist/internal/consts.js +25 -0
- package/dist/internal/registrations.d.ts +19 -0
- package/dist/internal/registrations.js +25 -0
- package/dist/internal/shared-consts.d.ts +1 -4
- package/dist/internal/shared-consts.js +1 -4
- package/dist/metadata/accessor.d.ts +33 -0
- package/dist/metadata/accessor.js +65 -0
- package/dist/metadata/decorators/host.decorator.d.ts +19 -0
- package/dist/metadata/decorators/host.decorator.js +18 -0
- package/dist/metadata/decorators/index.d.ts +6 -0
- package/dist/metadata/decorators/index.js +9 -0
- package/dist/metadata/decorators/task.decorator.d.ts +6 -0
- package/dist/metadata/decorators/task.decorator.js +15 -0
- package/dist/metadata/decorators/workflow-task.decorator.d.ts +10 -0
- package/dist/metadata/decorators/workflow-task.decorator.js +14 -0
- package/dist/metadata/index.d.ts +6 -0
- package/dist/metadata/index.js +10 -0
- package/dist/metadata/keys.d.ts +3 -0
- package/dist/metadata/keys.js +6 -0
- package/dist/metadata/translator.d.ts +10 -0
- package/dist/metadata/translator.js +26 -0
- package/dist/ref/helpers.d.ts +1 -0
- package/dist/ref/index.d.ts +3 -3
- package/dist/ref/index.js +5 -17
- package/dist/ref/shared.d.ts +7 -0
- package/dist/references/helpers.d.ts +27 -0
- package/dist/references/helpers.js +31 -0
- package/dist/references/index.d.ts +3 -0
- package/dist/references/index.js +7 -0
- package/dist/references/refs.d.ts +27 -0
- package/dist/references/refs.js +2 -0
- package/dist/references/shared.d.ts +172 -0
- package/dist/references/shared.js +2 -0
- package/dist/sdk/hatchet-client.factory.js +4 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.0](https://github.com/abinnovision/nestjs-commons/compare/nestjs-hatchet-v0.2.4...nestjs-hatchet-v0.3.0) (2026-01-10)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add execution wrapper support for tasks and workflows ([#54](https://github.com/abinnovision/nestjs-commons/issues/54)) ([8f96d3d](https://github.com/abinnovision/nestjs-commons/commit/8f96d3deb9ad40392a9d3328990c851947abf663))
|
|
9
|
+
* add hatchet integration ([#44](https://github.com/abinnovision/nestjs-commons/issues/44)) ([59a2138](https://github.com/abinnovision/nestjs-commons/commit/59a2138788ea2a262ad70b3298429dd518345d1c))
|
|
10
|
+
* allow event definitions to be used in onEvents from @Host(...) ([#80](https://github.com/abinnovision/nestjs-commons/issues/80)) ([2408228](https://github.com/abinnovision/nestjs-commons/commit/2408228f2aeb7a70ddc9e2119b5f1c1614a807c0))
|
|
11
|
+
* normalize hatchet inputs depending on trigger source ([#78](https://github.com/abinnovision/nestjs-commons/issues/78)) ([3cf5485](https://github.com/abinnovision/nestjs-commons/commit/3cf5485800b3a4f64fb191d0a7335136cf24725c))
|
|
12
|
+
* normalize hatchet inputs depending on trigger source ([#79](https://github.com/abinnovision/nestjs-commons/issues/79)) ([e91f113](https://github.com/abinnovision/nestjs-commons/commit/e91f11341fc5fdd02e9254c9671eabf0fddf49b1))
|
|
13
|
+
* rename execution wrapper to interceptor and remove unused code ([#58](https://github.com/abinnovision/nestjs-commons/issues/58)) ([b9dacbd](https://github.com/abinnovision/nestjs-commons/commit/b9dacbdca8ad41312768a98ed559f4c030ca7b5a))
|
|
14
|
+
* scope down the public api ([#81](https://github.com/abinnovision/nestjs-commons/issues/81)) ([4924861](https://github.com/abinnovision/nestjs-commons/commit/4924861c54cfceabf567565f704c52a1b75209a1))
|
|
15
|
+
* support multiple interceptors ([#59](https://github.com/abinnovision/nestjs-commons/issues/59)) ([f686508](https://github.com/abinnovision/nestjs-commons/commit/f686508b6f4e61d03846173c061152e0481a2b48))
|
|
16
|
+
* update worker configuration structure ([#56](https://github.com/abinnovision/nestjs-commons/issues/56)) ([3de8fb4](https://github.com/abinnovision/nestjs-commons/commit/3de8fb44e9814bb2a12d1a1b9081c03945f398cb))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* align exports in package.json ([#70](https://github.com/abinnovision/nestjs-commons/issues/70)) ([58956c5](https://github.com/abinnovision/nestjs-commons/commit/58956c5ea55394b65c6af405f4c6ac45555dc94a))
|
|
22
|
+
* remove dual registration of host providers ([#64](https://github.com/abinnovision/nestjs-commons/issues/64)) ([2c262f2](https://github.com/abinnovision/nestjs-commons/commit/2c262f2877a7676854324ac841ae5f58f9dbd97f))
|
|
23
|
+
* resolve interceptor using ModuleRef ([#67](https://github.com/abinnovision/nestjs-commons/issues/67)) ([aedb022](https://github.com/abinnovision/nestjs-commons/commit/aedb0223d4b8aa99a967420bf211c176da04a293))
|
|
24
|
+
* simplify ref types ([#60](https://github.com/abinnovision/nestjs-commons/issues/60)) ([79680d1](https://github.com/abinnovision/nestjs-commons/commit/79680d12c5b0aa2fc9201a574c36f743f5518c43))
|
|
25
|
+
* streamline context and interaction exports for public api ([#61](https://github.com/abinnovision/nestjs-commons/issues/61)) ([529deb1](https://github.com/abinnovision/nestjs-commons/commit/529deb1a30577debc40f94a23eb1ad99e2aaf2ae))
|
|
26
|
+
|
|
3
27
|
## [0.2.3](https://github.com/abinnovision/nestjs-commons/compare/nestjs-hatchet-v0.2.2...nestjs-hatchet-v0.2.3) (2025-12-16)
|
|
4
28
|
|
|
5
29
|
|
|
@@ -13,7 +13,7 @@ exports.NoMethodsWorkflow = exports.TestWorkflow = exports.NoSchemaTask = export
|
|
|
13
13
|
exports.setParamTypes = setParamTypes;
|
|
14
14
|
const zod_1 = require("zod");
|
|
15
15
|
const abstracts_1 = require("../abstracts");
|
|
16
|
-
const
|
|
16
|
+
const metadata_1 = require("../metadata");
|
|
17
17
|
// ============ TaskHost Fixtures ============
|
|
18
18
|
/** Standard TaskHost with string data schema */
|
|
19
19
|
let TestTask = class TestTask extends (0, abstracts_1.taskHost)(zod_1.z.object({ data: zod_1.z.string() })) {
|
|
@@ -23,13 +23,13 @@ let TestTask = class TestTask extends (0, abstracts_1.taskHost)(zod_1.z.object({
|
|
|
23
23
|
};
|
|
24
24
|
exports.TestTask = TestTask;
|
|
25
25
|
__decorate([
|
|
26
|
-
(0,
|
|
26
|
+
(0, metadata_1.Task)({}),
|
|
27
27
|
__metadata("design:type", Function),
|
|
28
28
|
__metadata("design:paramtypes", [Object]),
|
|
29
29
|
__metadata("design:returntype", void 0)
|
|
30
30
|
], TestTask.prototype, "execute", null);
|
|
31
31
|
exports.TestTask = TestTask = __decorate([
|
|
32
|
-
(0,
|
|
32
|
+
(0, metadata_1.Host)({ name: "test-task" })
|
|
33
33
|
], TestTask);
|
|
34
34
|
/** TaskHost without any decorated methods (invalid) */
|
|
35
35
|
let NoMethodsTask = class NoMethodsTask extends (0, abstracts_1.taskHost)() {
|
|
@@ -39,7 +39,7 @@ let NoMethodsTask = class NoMethodsTask extends (0, abstracts_1.taskHost)() {
|
|
|
39
39
|
};
|
|
40
40
|
exports.NoMethodsTask = NoMethodsTask;
|
|
41
41
|
exports.NoMethodsTask = NoMethodsTask = __decorate([
|
|
42
|
-
(0,
|
|
42
|
+
(0, metadata_1.Host)({ name: "no-methods-task" })
|
|
43
43
|
], NoMethodsTask);
|
|
44
44
|
/** TaskHost without input schema */
|
|
45
45
|
let NoSchemaTask = class NoSchemaTask extends (0, abstracts_1.taskHost)() {
|
|
@@ -49,13 +49,13 @@ let NoSchemaTask = class NoSchemaTask extends (0, abstracts_1.taskHost)() {
|
|
|
49
49
|
};
|
|
50
50
|
exports.NoSchemaTask = NoSchemaTask;
|
|
51
51
|
__decorate([
|
|
52
|
-
(0,
|
|
52
|
+
(0, metadata_1.Task)({}),
|
|
53
53
|
__metadata("design:type", Function),
|
|
54
54
|
__metadata("design:paramtypes", [Object]),
|
|
55
55
|
__metadata("design:returntype", void 0)
|
|
56
56
|
], NoSchemaTask.prototype, "execute", null);
|
|
57
57
|
exports.NoSchemaTask = NoSchemaTask = __decorate([
|
|
58
|
-
(0,
|
|
58
|
+
(0, metadata_1.Host)({ name: "no-schema-task" })
|
|
59
59
|
], NoSchemaTask);
|
|
60
60
|
// ============ WorkflowHost Fixtures ============
|
|
61
61
|
/** Standard WorkflowHost with two-step DAG */
|
|
@@ -69,19 +69,19 @@ let TestWorkflow = class TestWorkflow extends (0, abstracts_1.workflowHost)(zod_
|
|
|
69
69
|
};
|
|
70
70
|
exports.TestWorkflow = TestWorkflow;
|
|
71
71
|
__decorate([
|
|
72
|
-
(0,
|
|
72
|
+
(0, metadata_1.WorkflowTask)({ parents: [] }),
|
|
73
73
|
__metadata("design:type", Function),
|
|
74
74
|
__metadata("design:paramtypes", [Object]),
|
|
75
75
|
__metadata("design:returntype", void 0)
|
|
76
76
|
], TestWorkflow.prototype, "step1", null);
|
|
77
77
|
__decorate([
|
|
78
|
-
(0,
|
|
78
|
+
(0, metadata_1.WorkflowTask)({ parents: ["step1"] }),
|
|
79
79
|
__metadata("design:type", Function),
|
|
80
80
|
__metadata("design:paramtypes", [Object]),
|
|
81
81
|
__metadata("design:returntype", void 0)
|
|
82
82
|
], TestWorkflow.prototype, "step2", null);
|
|
83
83
|
exports.TestWorkflow = TestWorkflow = __decorate([
|
|
84
|
-
(0,
|
|
84
|
+
(0, metadata_1.Host)({ name: "test-workflow" })
|
|
85
85
|
], TestWorkflow);
|
|
86
86
|
/** WorkflowHost without any decorated methods (invalid) */
|
|
87
87
|
let NoMethodsWorkflow = class NoMethodsWorkflow extends (0, abstracts_1.workflowHost)() {
|
|
@@ -91,7 +91,7 @@ let NoMethodsWorkflow = class NoMethodsWorkflow extends (0, abstracts_1.workflow
|
|
|
91
91
|
};
|
|
92
92
|
exports.NoMethodsWorkflow = NoMethodsWorkflow;
|
|
93
93
|
exports.NoMethodsWorkflow = NoMethodsWorkflow = __decorate([
|
|
94
|
-
(0,
|
|
94
|
+
(0, metadata_1.Host)({ name: "no-methods-workflow" })
|
|
95
95
|
], NoMethodsWorkflow);
|
|
96
96
|
// ============ Test Utilities ============
|
|
97
97
|
/** Sets design:paramtypes metadata for a method (needed in vitest) */
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
import type { SdkHostOpts } from "./opts-translator";
|
|
1
2
|
import type { HostOpts, TaskOpts, WorkflowTaskOpts } from "../decorators";
|
|
2
|
-
import type { AnyHost, AnyHostCtor } from "../ref";
|
|
3
|
+
import type { AnyHost, AnyHostCtor } from "../ref/shared";
|
|
3
4
|
/**
|
|
4
5
|
* Accessor for host metadata and methods.
|
|
5
6
|
*/
|
|
6
7
|
declare class HostAccessor {
|
|
7
8
|
readonly ctor: AnyHostCtor;
|
|
8
9
|
constructor(ctor: AnyHostCtor);
|
|
10
|
+
/**
|
|
11
|
+
* Returns raw enhanced metadata from @Host() decorator.
|
|
12
|
+
*/
|
|
9
13
|
get metadata(): HostOpts;
|
|
14
|
+
/**
|
|
15
|
+
* Returns SDK-compatible options for workflow declarations.
|
|
16
|
+
*/
|
|
17
|
+
get sdkOpts(): SdkHostOpts;
|
|
10
18
|
get name(): string;
|
|
11
19
|
get isWorkflow(): boolean;
|
|
12
20
|
get isTask(): boolean;
|
|
@@ -5,6 +5,7 @@ exports.fromInstance = fromInstance;
|
|
|
5
5
|
/* eslint-disable @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-assignment */
|
|
6
6
|
const abstracts_1 = require("../abstracts");
|
|
7
7
|
const internal_1 = require("../internal");
|
|
8
|
+
const opts_translator_1 = require("./opts-translator");
|
|
8
9
|
/**
|
|
9
10
|
* Accessor for host metadata and methods.
|
|
10
11
|
*/
|
|
@@ -13,9 +14,18 @@ class HostAccessor {
|
|
|
13
14
|
constructor(ctor) {
|
|
14
15
|
this.ctor = ctor;
|
|
15
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Returns raw enhanced metadata from @Host() decorator.
|
|
19
|
+
*/
|
|
16
20
|
get metadata() {
|
|
17
21
|
return Reflect.getMetadata(internal_1.METADATA_KEY_HOST_OPTS, this.ctor);
|
|
18
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns SDK-compatible options for workflow declarations.
|
|
25
|
+
*/
|
|
26
|
+
get sdkOpts() {
|
|
27
|
+
return (0, opts_translator_1.translateHostOpts)(this.metadata);
|
|
28
|
+
}
|
|
19
29
|
get name() {
|
|
20
30
|
return this.metadata.name;
|
|
21
31
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HostOpts } from "../decorators";
|
|
2
|
+
import type { CreateBaseWorkflowOpts } from "@hatchet-dev/typescript-sdk";
|
|
3
|
+
/**
|
|
4
|
+
* SDK-compatible host options.
|
|
5
|
+
*/
|
|
6
|
+
export type SdkHostOpts = Omit<CreateBaseWorkflowOpts, "on">;
|
|
7
|
+
/**
|
|
8
|
+
* Translates onEvents to SDK-compatible string array.
|
|
9
|
+
*/
|
|
10
|
+
export declare function translateOnEvents(onEvents: HostOpts["onEvents"] | undefined): string[] | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Translates enhanced HostOpts to SDK-compatible SdkHostOpts.
|
|
13
|
+
*/
|
|
14
|
+
export declare function translateHostOpts(opts: HostOpts): SdkHostOpts;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.translateOnEvents = translateOnEvents;
|
|
4
|
+
exports.translateHostOpts = translateHostOpts;
|
|
5
|
+
/**
|
|
6
|
+
* Translates onEvents to SDK-compatible string array.
|
|
7
|
+
*/
|
|
8
|
+
function translateOnEvents(onEvents) {
|
|
9
|
+
if (!onEvents || onEvents.length === 0) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
return onEvents.map((e) => (typeof e === "string" ? e : e.name));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Translates enhanced HostOpts to SDK-compatible SdkHostOpts.
|
|
16
|
+
*/
|
|
17
|
+
function translateHostOpts(opts) {
|
|
18
|
+
const { onEvents, ...passthrough } = opts;
|
|
19
|
+
const translatedOnEvents = translateOnEvents(onEvents);
|
|
20
|
+
// Only include onEvents if it has values (exactOptionalPropertyTypes compliance)
|
|
21
|
+
if (translatedOnEvents) {
|
|
22
|
+
return { ...passthrough, onEvents: translatedOnEvents };
|
|
23
|
+
}
|
|
24
|
+
return passthrough;
|
|
25
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CreateBaseWorkflowOpts } from "@hatchet-dev/typescript-sdk";
|
|
2
|
+
import type { AnyEventDefinition } from "../events";
|
|
3
|
+
/**
|
|
4
|
+
* SDK-compatible host options.
|
|
5
|
+
*/
|
|
6
|
+
export type SdkHostOpts = Omit<CreateBaseWorkflowOpts, "on">;
|
|
7
|
+
/**
|
|
8
|
+
* Input type for onEvents - accepts strings or EventDefinitions.
|
|
9
|
+
*/
|
|
10
|
+
export type OnEventsInput = ReadonlyArray<string | AnyEventDefinition>;
|
|
11
|
+
/**
|
|
12
|
+
* Properties we enhance beyond SDK types.
|
|
13
|
+
*/
|
|
14
|
+
interface EnhancedProperties {
|
|
15
|
+
name: string;
|
|
16
|
+
onEvents?: OnEventsInput;
|
|
17
|
+
}
|
|
18
|
+
type PassthroughProperties = Omit<CreateBaseWorkflowOpts, "on" | keyof EnhancedProperties>;
|
|
19
|
+
/**
|
|
20
|
+
* Enhanced HostOpts for @Host() decorator.
|
|
21
|
+
*/
|
|
22
|
+
export type HostOpts = EnhancedProperties & PassthroughProperties;
|
|
23
|
+
/**
|
|
24
|
+
* Translates onEvents to SDK-compatible string array.
|
|
25
|
+
*/
|
|
26
|
+
export declare function translateOnEvents(onEvents: OnEventsInput | undefined): string[] | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Translates enhanced HostOpts to SDK-compatible SdkHostOpts.
|
|
29
|
+
*/
|
|
30
|
+
export declare function translateHostOpts(opts: HostOpts): SdkHostOpts;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.translateOnEvents = translateOnEvents;
|
|
4
|
+
exports.translateHostOpts = translateHostOpts;
|
|
5
|
+
/**
|
|
6
|
+
* Translates onEvents to SDK-compatible string array.
|
|
7
|
+
*/
|
|
8
|
+
function translateOnEvents(onEvents) {
|
|
9
|
+
if (!onEvents || onEvents.length === 0)
|
|
10
|
+
return undefined;
|
|
11
|
+
return onEvents.map((e) => (typeof e === "string" ? e : e.name));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Translates enhanced HostOpts to SDK-compatible SdkHostOpts.
|
|
15
|
+
*/
|
|
16
|
+
function translateHostOpts(opts) {
|
|
17
|
+
const { onEvents, ...passthrough } = opts;
|
|
18
|
+
const translatedOnEvents = translateOnEvents(onEvents);
|
|
19
|
+
// Only include onEvents if it has values (exactOptionalPropertyTypes compliance)
|
|
20
|
+
if (translatedOnEvents) {
|
|
21
|
+
return {
|
|
22
|
+
...passthrough,
|
|
23
|
+
onEvents: translatedOnEvents,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return passthrough;
|
|
27
|
+
}
|
package/dist/accessor/index.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HostOpts } from "../decorators";
|
|
2
|
+
import type { CreateBaseWorkflowOpts } from "@hatchet-dev/typescript-sdk";
|
|
3
|
+
/**
|
|
4
|
+
* SDK-compatible host options.
|
|
5
|
+
*/
|
|
6
|
+
export type SdkHostOpts = Omit<CreateBaseWorkflowOpts, "on">;
|
|
7
|
+
/**
|
|
8
|
+
* Translates enhanced HostOpts to SDK-compatible SdkHostOpts.
|
|
9
|
+
*/
|
|
10
|
+
export declare const translateHostOpts: (opts: HostOpts) => SdkHostOpts;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.translateHostOpts = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Translates onEvents to SDK-compatible string array.
|
|
6
|
+
*/
|
|
7
|
+
const translateOnEvents = (onEvents) => {
|
|
8
|
+
// If no onEvents provided, return undefined
|
|
9
|
+
if (!onEvents || onEvents.length === 0) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
return onEvents.map((e) => (typeof e === "string" ? e : e.name));
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Translates enhanced HostOpts to SDK-compatible SdkHostOpts.
|
|
16
|
+
*/
|
|
17
|
+
const translateHostOpts = (opts) => {
|
|
18
|
+
const { onEvents, ...passthrough } = opts;
|
|
19
|
+
const translatedOnEvents = translateOnEvents(onEvents);
|
|
20
|
+
// Only include onEvents if it has values
|
|
21
|
+
if (translatedOnEvents) {
|
|
22
|
+
return { ...passthrough, onEvents: translatedOnEvents };
|
|
23
|
+
}
|
|
24
|
+
return passthrough;
|
|
25
|
+
};
|
|
26
|
+
exports.translateHostOpts = translateHostOpts;
|
package/dist/client/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HatchetClient } from "@hatchet-dev/typescript-sdk";
|
|
2
2
|
import { PushEventOptions } from "@hatchet-dev/typescript-sdk/clients/event/event-client";
|
|
3
|
-
import {
|
|
4
|
-
import type { HostRunFn } from "../
|
|
3
|
+
import type { AnyEventDefinition, EventInput } from "../events";
|
|
4
|
+
import type { HostRunFn } from "../execution";
|
|
5
5
|
import type { Event } from "@hatchet-dev/typescript-sdk/protoc/events";
|
|
6
6
|
/**
|
|
7
7
|
* Options for emitting events.
|
package/dist/client/client.js
CHANGED
|
@@ -12,14 +12,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.Client = void 0;
|
|
13
13
|
const typescript_sdk_1 = require("@hatchet-dev/typescript-sdk");
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
|
-
const
|
|
16
|
-
const
|
|
15
|
+
const event_definition_1 = require("../events/event-definition");
|
|
16
|
+
const host_run_1 = require("../execution/host-run");
|
|
17
17
|
let Client = class Client {
|
|
18
18
|
client;
|
|
19
19
|
run;
|
|
20
20
|
constructor(client) {
|
|
21
21
|
this.client = client;
|
|
22
|
-
this.run = (0,
|
|
22
|
+
this.run = (0, host_run_1.createHostRunForAdmin)(client);
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Access to the underlying HatchetClient SDK.
|
|
@@ -42,7 +42,7 @@ let Client = class Client {
|
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
44
|
async emit(event, input, options) {
|
|
45
|
-
return await this.client.events.push(event.name, { ...input, [
|
|
45
|
+
return await this.client.events.push(event.name, { ...input, [event_definition_1.EVENT_MARKER]: event.name }, options);
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Emit multiple events of the same type.
|
|
@@ -65,7 +65,7 @@ let Client = class Client {
|
|
|
65
65
|
return [];
|
|
66
66
|
}
|
|
67
67
|
const result = await this.client.events.bulkPush(event.name, inputs.map((input) => ({
|
|
68
|
-
payload: { ...input, [
|
|
68
|
+
payload: { ...input, [event_definition_1.EVENT_MARKER]: event.name },
|
|
69
69
|
})), options);
|
|
70
70
|
return result.events;
|
|
71
71
|
}
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
1
|
+
import { type BaseCtx, type HostTriggerConfig, type TaskCtx, type WorkflowCtx } from "./context";
|
|
2
|
+
/**
|
|
3
|
+
* Arguments for context factory functions.
|
|
4
|
+
* Derived from BaseCtx using Pick to ensure type alignment.
|
|
5
|
+
*/
|
|
6
|
+
type CreateCtxArgs<I> = Pick<BaseCtx<I>, "fromSDK" | "triggerSource"> & {
|
|
7
|
+
input: I;
|
|
8
|
+
hostConfig: HostTriggerConfig;
|
|
9
|
+
};
|
|
3
10
|
/**
|
|
4
11
|
* Creates a TaskCtx from SDK Context for standalone task execution.
|
|
5
12
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param validatedInput Optional validated/transformed input to use instead of raw SDK input.
|
|
13
|
+
* @param args The arguments for creating the task context.
|
|
8
14
|
*/
|
|
9
|
-
export declare
|
|
15
|
+
export declare const createTaskCtx: <I>(args: CreateCtxArgs<I>) => TaskCtx<any>;
|
|
10
16
|
/**
|
|
11
17
|
* Creates a WorkflowCtx from SDK Context for workflow task execution.
|
|
12
18
|
*
|
|
13
|
-
* @param
|
|
14
|
-
* @param validatedInput Optional validated/transformed input to use instead of raw SDK input.
|
|
19
|
+
* @param args The arguments for creating the workflow context.
|
|
15
20
|
*/
|
|
16
|
-
export declare
|
|
21
|
+
export declare const createWorkflowCtx: <I>(args: CreateCtxArgs<I>) => WorkflowCtx<any>;
|
|
22
|
+
export {};
|
|
@@ -1,43 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTaskCtx =
|
|
4
|
-
|
|
3
|
+
exports.createWorkflowCtx = exports.createTaskCtx = void 0;
|
|
4
|
+
const context_1 = require("./context");
|
|
5
5
|
const adapter_factory_1 = require("../interaction/host-run/adapter-factory");
|
|
6
|
+
/**
|
|
7
|
+
* Creates the helper methods derived from the SDK context.
|
|
8
|
+
* These are methods that wrap SDK functionality.
|
|
9
|
+
*/
|
|
10
|
+
const createContextHelpers = (fromSDK) => ({
|
|
11
|
+
run: (0, adapter_factory_1.createHostRunForContext)(fromSDK),
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* Creates the trigger guard methods bound to the context's trigger source.
|
|
15
|
+
*/
|
|
16
|
+
const createTriggerGuards = (triggerSource, input) => ({
|
|
17
|
+
isRun: () => triggerSource === "run",
|
|
18
|
+
isCron: () => triggerSource === "cron",
|
|
19
|
+
isEvent: (eventDef) => {
|
|
20
|
+
if (triggerSource !== "event") {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
// If no event definition is provided, then we validate against any event.
|
|
24
|
+
if (!eventDef) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return eventDef.isCtx({ input });
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* Maps the args to the 1:1 context properties.
|
|
32
|
+
*/
|
|
33
|
+
const mapContextProperties = (args) => ({
|
|
34
|
+
fromSDK: args.fromSDK,
|
|
35
|
+
input: args.input,
|
|
36
|
+
triggerSource: args.triggerSource,
|
|
37
|
+
hostConfig: args.hostConfig,
|
|
38
|
+
});
|
|
6
39
|
/**
|
|
7
40
|
* Creates a TaskCtx from SDK Context for standalone task execution.
|
|
8
41
|
*
|
|
9
|
-
* @param
|
|
10
|
-
* @param validatedInput Optional validated/transformed input to use instead of raw SDK input.
|
|
42
|
+
* @param args The arguments for creating the task context.
|
|
11
43
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
run,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
44
|
+
const createTaskCtx = (args) => ({
|
|
45
|
+
[context_1.TASK_MARKER]: true,
|
|
46
|
+
...mapContextProperties(args),
|
|
47
|
+
...createContextHelpers(args.fromSDK),
|
|
48
|
+
...createTriggerGuards(args.triggerSource, args.input),
|
|
49
|
+
});
|
|
50
|
+
exports.createTaskCtx = createTaskCtx;
|
|
22
51
|
/**
|
|
23
52
|
* Creates a WorkflowCtx from SDK Context for workflow task execution.
|
|
24
53
|
*
|
|
25
|
-
* @param
|
|
26
|
-
* @param validatedInput Optional validated/transformed input to use instead of raw SDK input.
|
|
54
|
+
* @param args The arguments for creating the workflow context.
|
|
27
55
|
*/
|
|
28
|
-
|
|
29
|
-
const run = (0, adapter_factory_1.createHostRunForContext)(sdkCtx);
|
|
56
|
+
const createWorkflowCtx = (args) => {
|
|
30
57
|
const parent = async (method) => {
|
|
31
58
|
const methodName = method.name;
|
|
32
59
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
33
|
-
return await
|
|
60
|
+
return await args.fromSDK.parentOutput(methodName);
|
|
34
61
|
};
|
|
35
|
-
// Cast needed because TASK_MARKER is a phantom type for compile-time detection only
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
37
62
|
return {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
63
|
+
[context_1.TASK_MARKER]: true,
|
|
64
|
+
...mapContextProperties(args),
|
|
65
|
+
...createContextHelpers(args.fromSDK),
|
|
66
|
+
...createTriggerGuards(args.triggerSource, args.input),
|
|
41
67
|
parent,
|
|
42
68
|
};
|
|
43
|
-
}
|
|
69
|
+
};
|
|
70
|
+
exports.createWorkflowCtx = createWorkflowCtx;
|
|
@@ -1,9 +1,34 @@
|
|
|
1
1
|
import type { TaskHost, WorkflowHost } from "../abstracts";
|
|
2
|
+
import type { AnyEventDefinition, EventOutput } from "../events";
|
|
2
3
|
import type { HostRunFn } from "../interaction";
|
|
3
|
-
import type { AnyTaskFn, OutputOfTaskFn } from "../ref";
|
|
4
|
+
import type { AnyTaskFn, OutputOfTaskFn } from "../ref/shared";
|
|
4
5
|
import type { Context } from "@hatchet-dev/typescript-sdk";
|
|
5
|
-
declare const TASK_MARKER: unique symbol;
|
|
6
|
+
export declare const TASK_MARKER: unique symbol;
|
|
6
7
|
export type TaskMarker = typeof TASK_MARKER;
|
|
8
|
+
/**
|
|
9
|
+
* Type representing the source that triggered the task execution.
|
|
10
|
+
*
|
|
11
|
+
* - "run": Triggered with default payload via direct run.
|
|
12
|
+
* - "event": Triggered by an event.
|
|
13
|
+
* - "cron": Triggered by a cron schedule.
|
|
14
|
+
*
|
|
15
|
+
* Note that the detection of trigger source is best-effort and may not be accurate in all cases.
|
|
16
|
+
* Hatchet does not currently provide first-class support for distinguishing all trigger sources.
|
|
17
|
+
*/
|
|
18
|
+
export type TriggerSource = "run" | "event" | "cron";
|
|
19
|
+
/**
|
|
20
|
+
* Configuration extracted from host decorator for trigger introspection.
|
|
21
|
+
*/
|
|
22
|
+
export interface HostTriggerConfig {
|
|
23
|
+
/**
|
|
24
|
+
* Event names this host listens to
|
|
25
|
+
*/
|
|
26
|
+
onEvents: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Cron schedules this host responds to
|
|
29
|
+
*/
|
|
30
|
+
onCrons: string[];
|
|
31
|
+
}
|
|
7
32
|
/**
|
|
8
33
|
* Type for the context when a task is running. This is universal for standalone and workflow tasks.
|
|
9
34
|
* This partially implements the `Context` type from the SDK.
|
|
@@ -11,6 +36,14 @@ export type TaskMarker = typeof TASK_MARKER;
|
|
|
11
36
|
* @template I The input type of the task.
|
|
12
37
|
*/
|
|
13
38
|
export interface BaseCtx<I> {
|
|
39
|
+
/**
|
|
40
|
+
* Host metadata accessor for introspection.
|
|
41
|
+
*/
|
|
42
|
+
readonly hostConfig: HostTriggerConfig;
|
|
43
|
+
/**
|
|
44
|
+
* The source that triggered the task execution.
|
|
45
|
+
*/
|
|
46
|
+
triggerSource: TriggerSource;
|
|
14
47
|
/**
|
|
15
48
|
* Provides access to the underlying SDK context.
|
|
16
49
|
*/
|
|
@@ -23,6 +56,31 @@ export interface BaseCtx<I> {
|
|
|
23
56
|
* Function to run other tasks within the context of this task.
|
|
24
57
|
*/
|
|
25
58
|
run: HostRunFn;
|
|
59
|
+
/**
|
|
60
|
+
* Returns true if triggered via direct run.
|
|
61
|
+
* When true, ctx.input is the validated host schema type.
|
|
62
|
+
*/
|
|
63
|
+
isRun: () => this is BaseCtx<I> & {
|
|
64
|
+
triggerSource: "run";
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Returns true if triggered via event.
|
|
68
|
+
* Optionally accepts an EventDefinition to check for a specific event type.
|
|
69
|
+
*
|
|
70
|
+
* @param eventDef Optional event definition to check for specific event
|
|
71
|
+
*/
|
|
72
|
+
isEvent: <E extends AnyEventDefinition>(eventDef?: E) => this is BaseCtx<I> & {
|
|
73
|
+
triggerSource: "event";
|
|
74
|
+
input: E extends AnyEventDefinition ? EventOutput<E> : unknown;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Returns true if triggered via cron schedule.
|
|
78
|
+
* When true, ctx.input is void/empty.
|
|
79
|
+
*/
|
|
80
|
+
isCron: () => this is BaseCtx<I> & {
|
|
81
|
+
triggerSource: "cron";
|
|
82
|
+
input: never;
|
|
83
|
+
};
|
|
26
84
|
}
|
|
27
85
|
/**
|
|
28
86
|
* Context type of the run of a standalone task.
|
|
@@ -48,4 +106,3 @@ export type WorkflowCtx<T extends WorkflowHost<any>> = BaseCtx<T extends Workflo
|
|
|
48
106
|
* This is essentially BaseCtx with the input type extracted from the host.
|
|
49
107
|
*/
|
|
50
108
|
export type HelperCtx<T extends TaskHost<any> | WorkflowHost<any>> = BaseCtx<T extends TaskHost<infer I> ? I : T extends WorkflowHost<infer I> ? I : never>;
|
|
51
|
-
export {};
|
package/dist/context/context.js
CHANGED
package/dist/context/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { BaseCtx, TaskCtx, WorkflowCtx, HelperCtx } from "./context";
|
|
1
|
+
export type { BaseCtx, TaskCtx, WorkflowCtx, HelperCtx, TriggerSource, HostTriggerConfig, } from "./context";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.testNarrowing = testNarrowing;
|
|
4
|
+
function testNarrowing(ctx) {
|
|
5
|
+
// Before narrowing
|
|
6
|
+
const source1 = ctx.triggerSource; // Should be "run" | "event" | "cron"
|
|
7
|
+
if (ctx.isRun()) {
|
|
8
|
+
// After narrowing - should be just "run"
|
|
9
|
+
const source2 = ctx.triggerSource; // Does this compile?
|
|
10
|
+
console.log(source2);
|
|
11
|
+
}
|
|
12
|
+
if (ctx.isCron()) {
|
|
13
|
+
const source3 = ctx.triggerSource; // Does this compile?
|
|
14
|
+
console.log(source3);
|
|
15
|
+
}
|
|
16
|
+
console.log(source1);
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BaseCtx } from "./context";
|
|
2
|
+
/**
|
|
3
|
+
* Context when triggered via direct run (client.run()).
|
|
4
|
+
* Input is validated against host's inputSchema.
|
|
5
|
+
*/
|
|
6
|
+
export interface RunCtx<I> extends BaseCtx<I> {
|
|
7
|
+
triggerSource: "run";
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Context when triggered via event (client.emit()).
|
|
11
|
+
* Input contains event marker and payload.
|
|
12
|
+
*/
|
|
13
|
+
export interface EventCtx extends BaseCtx<Record<string, unknown>> {
|
|
14
|
+
triggerSource: "event";
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Context when triggered via cron schedule.
|
|
18
|
+
* Input is empty/undefined.
|
|
19
|
+
*/
|
|
20
|
+
export interface CronCtx extends BaseCtx<Record<string, never>> {
|
|
21
|
+
triggerSource: "cron";
|
|
22
|
+
}
|