@abinnovision/nestjs-hatchet 0.2.2 → 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 +31 -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 +8 -4
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CreateBaseWorkflowOpts } from "@hatchet-dev/typescript-sdk";
|
|
2
|
+
import type { AnyEventDefinition } from "../events";
|
|
3
|
+
/**
|
|
4
|
+
* Input type for onEvents - accepts strings or EventDefinitions.
|
|
5
|
+
*/
|
|
6
|
+
export type OnEventsInput = ReadonlyArray<string | AnyEventDefinition>;
|
|
7
|
+
/**
|
|
8
|
+
* Properties we enhance beyond SDK types.
|
|
9
|
+
*/
|
|
10
|
+
interface EnhancedProperties {
|
|
11
|
+
name: string;
|
|
12
|
+
onEvents?: OnEventsInput;
|
|
13
|
+
}
|
|
14
|
+
type PassthroughProperties = Omit<CreateBaseWorkflowOpts, "on" | keyof EnhancedProperties>;
|
|
15
|
+
/**
|
|
16
|
+
* Enhanced HostOpts for @Host() decorator.
|
|
17
|
+
*/
|
|
18
|
+
export type HostOpts = EnhancedProperties & PassthroughProperties;
|
|
19
|
+
export {};
|
|
@@ -1,6 +1,19 @@
|
|
|
1
|
+
import type { AnyEventDefinition } from "../events";
|
|
1
2
|
import type { CreateBaseWorkflowOpts } from "@hatchet-dev/typescript-sdk";
|
|
2
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Properties we enhance beyond SDK types.
|
|
5
|
+
*/
|
|
6
|
+
interface EnhancedProperties {
|
|
7
|
+
name: string;
|
|
8
|
+
onEvents?: ReadonlyArray<string | AnyEventDefinition>;
|
|
9
|
+
}
|
|
10
|
+
type PassthroughProperties = Omit<CreateBaseWorkflowOpts, "on" | keyof EnhancedProperties>;
|
|
11
|
+
/**
|
|
12
|
+
* Enhanced HostOpts for @Host() decorator.
|
|
13
|
+
*/
|
|
14
|
+
export type HostOpts = EnhancedProperties & PassthroughProperties;
|
|
3
15
|
/**
|
|
4
16
|
* Decorator to mark a class as a host (for either a workflow or a task).
|
|
5
17
|
*/
|
|
6
|
-
export declare const Host: (
|
|
18
|
+
export declare const Host: (opts: HostOpts) => ClassDecorator;
|
|
19
|
+
export {};
|
|
@@ -6,12 +6,12 @@ const internal_1 = require("../internal");
|
|
|
6
6
|
/**
|
|
7
7
|
* Decorator to mark a class as a host (for either a workflow or a task).
|
|
8
8
|
*/
|
|
9
|
-
const Host = (
|
|
9
|
+
const Host = (opts) => {
|
|
10
10
|
return (target) => {
|
|
11
11
|
// Make the workflow injectable.
|
|
12
12
|
(0, common_1.Injectable)()(target);
|
|
13
13
|
// Add the workflow options.
|
|
14
|
-
Reflect.defineMetadata(internal_1.METADATA_KEY_HOST_OPTS,
|
|
14
|
+
Reflect.defineMetadata(internal_1.METADATA_KEY_HOST_OPTS, opts, target);
|
|
15
15
|
return target;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WorkflowCtx } from "../context";
|
|
2
|
-
import type { ContextMethodKeys, WorkflowHostCtor } from "../ref";
|
|
2
|
+
import type { ContextMethodKeys, WorkflowHostCtor } from "../ref/shared";
|
|
3
3
|
import type { CreateWorkflowTaskOpts } from "@hatchet-dev/typescript-sdk/v1/task";
|
|
4
4
|
export type WorkflowTaskOpts<C extends WorkflowHostCtor<any>> = Omit<CreateWorkflowTaskOpts, "fn" | "parents" | "name"> & {
|
|
5
5
|
parents?: ContextMethodKeys<InstanceType<C>, WorkflowCtx<any>>[];
|
package/dist/events/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { EventDefinition, defineEvent } from "./event-definition";
|
|
2
|
+
export type { AnyEventDefinition, EventInput, EventOutput, } from "./event-definition";
|
package/dist/events/index.js
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
3
|
+
exports.defineEvent = exports.EventDefinition = void 0;
|
|
4
|
+
var event_definition_1 = require("./event-definition");
|
|
5
|
+
Object.defineProperty(exports, "EventDefinition", { enumerable: true, get: function () { return event_definition_1.EventDefinition; } });
|
|
6
|
+
Object.defineProperty(exports, "defineEvent", { enumerable: true, get: function () { return event_definition_1.defineEvent; } });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type BaseCtx, type HostTriggerConfig, type TaskCtx, type WorkflowCtx } from "./types";
|
|
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
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Creates a TaskCtx from SDK Context for standalone task execution.
|
|
12
|
+
*
|
|
13
|
+
* @param args The arguments for creating the task context.
|
|
14
|
+
*/
|
|
15
|
+
export declare const createTaskCtx: <I>(args: CreateCtxArgs<I>) => TaskCtx<any>;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a WorkflowCtx from SDK Context for workflow task execution.
|
|
18
|
+
*
|
|
19
|
+
* @param args The arguments for creating the workflow context.
|
|
20
|
+
*/
|
|
21
|
+
export declare const createWorkflowCtx: <I>(args: CreateCtxArgs<I>) => WorkflowCtx<any>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWorkflowCtx = exports.createTaskCtx = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const adapter_factory_1 = require("../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
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Creates a TaskCtx from SDK Context for standalone task execution.
|
|
41
|
+
*
|
|
42
|
+
* @param args The arguments for creating the task context.
|
|
43
|
+
*/
|
|
44
|
+
const createTaskCtx = (args) => ({
|
|
45
|
+
[types_1.TASK_MARKER]: true,
|
|
46
|
+
...mapContextProperties(args),
|
|
47
|
+
...createContextHelpers(args.fromSDK),
|
|
48
|
+
...createTriggerGuards(args.triggerSource, args.input),
|
|
49
|
+
});
|
|
50
|
+
exports.createTaskCtx = createTaskCtx;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a WorkflowCtx from SDK Context for workflow task execution.
|
|
53
|
+
*
|
|
54
|
+
* @param args The arguments for creating the workflow context.
|
|
55
|
+
*/
|
|
56
|
+
const createWorkflowCtx = (args) => {
|
|
57
|
+
const parent = async (method) => {
|
|
58
|
+
const methodName = method.name;
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
60
|
+
return await args.fromSDK.parentOutput(methodName);
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
[types_1.TASK_MARKER]: true,
|
|
64
|
+
...mapContextProperties(args),
|
|
65
|
+
...createContextHelpers(args.fromSDK),
|
|
66
|
+
...createTriggerGuards(args.triggerSource, args.input),
|
|
67
|
+
parent,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
exports.createWorkflowCtx = createWorkflowCtx;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWorkflowCtx = exports.createTaskCtx = exports.TASK_MARKER = void 0;
|
|
4
|
+
var types_1 = require("./types");
|
|
5
|
+
Object.defineProperty(exports, "TASK_MARKER", { enumerable: true, get: function () { return types_1.TASK_MARKER; } });
|
|
6
|
+
var factory_1 = require("./factory");
|
|
7
|
+
Object.defineProperty(exports, "createTaskCtx", { enumerable: true, get: function () { return factory_1.createTaskCtx; } });
|
|
8
|
+
Object.defineProperty(exports, "createWorkflowCtx", { enumerable: true, get: function () { return factory_1.createWorkflowCtx; } });
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { TaskHost, WorkflowHost } from "../../abstracts";
|
|
2
|
+
import type { AnyEventDefinition, EventOutput } from "../../events";
|
|
3
|
+
import type { AnyTaskFn, OutputOfTaskFn } from "../../references/shared";
|
|
4
|
+
import type { HostRunFn } from "../host-run";
|
|
5
|
+
import type { Context } from "@hatchet-dev/typescript-sdk";
|
|
6
|
+
export declare const TASK_MARKER: unique symbol;
|
|
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
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Type for the context when a task is running. This is universal for standalone and workflow tasks.
|
|
34
|
+
* This partially implements the `Context` type from the SDK.
|
|
35
|
+
*
|
|
36
|
+
* @template I The input type of the task.
|
|
37
|
+
*/
|
|
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;
|
|
47
|
+
/**
|
|
48
|
+
* Provides access to the underlying SDK context.
|
|
49
|
+
*/
|
|
50
|
+
fromSDK: Context<I, any>;
|
|
51
|
+
/**
|
|
52
|
+
* The input to the task.
|
|
53
|
+
*/
|
|
54
|
+
input: I;
|
|
55
|
+
/**
|
|
56
|
+
* Function to run other tasks within the context of this task.
|
|
57
|
+
*/
|
|
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
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Context type of the run of a standalone task.
|
|
87
|
+
* Branded with TASK_MARKER for compile-time task method detection.
|
|
88
|
+
*/
|
|
89
|
+
export type TaskCtx<T extends TaskHost<any>> = BaseCtx<T extends TaskHost<infer I> ? I : never> & {
|
|
90
|
+
[TASK_MARKER]: true;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Context type of the run of a workflow task.
|
|
94
|
+
* Branded with TASK_MARKER for compile-time task method detection.
|
|
95
|
+
*/
|
|
96
|
+
export type WorkflowCtx<T extends WorkflowHost<any>> = BaseCtx<T extends WorkflowHost<infer I> ? I : never> & {
|
|
97
|
+
[TASK_MARKER]: true;
|
|
98
|
+
/**
|
|
99
|
+
* Provides the output of a parent task.
|
|
100
|
+
*/
|
|
101
|
+
parent: <F extends AnyTaskFn<any, any>>(method: F) => Promise<OutputOfTaskFn<F>>;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Context type for helper methods that need access to the task context
|
|
105
|
+
* but should not be counted as task methods.
|
|
106
|
+
* This is essentially BaseCtx with the input type extracted from the host.
|
|
107
|
+
*/
|
|
108
|
+
export type HelperCtx<T extends TaskHost<any> | WorkflowHost<any>> = BaseCtx<T extends TaskHost<infer I> ? I : T extends WorkflowHost<infer I> ? I : never>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { HostRunFn } from "./function-type";
|
|
2
|
+
import type { Context, HatchetClient } from "@hatchet-dev/typescript-sdk";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a HostRunFn that uses SDK Context for spawning child workflows.
|
|
5
|
+
* Used within task execution contexts.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createHostRunForContext(ctx: Context<any, any>): HostRunFn;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a HostRunFn that uses HatchetClient for external workflow triggering.
|
|
10
|
+
* Used by HClient for triggering workflows from outside task contexts.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createHostRunForAdmin(client: HatchetClient): HostRunFn;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createHostRunForContext = createHostRunForContext;
|
|
4
|
+
exports.createHostRunForAdmin = createHostRunForAdmin;
|
|
5
|
+
const helpers_1 = require("../../references/helpers");
|
|
6
|
+
/**
|
|
7
|
+
* Creates a HostRunFn using the provided runner strategy.
|
|
8
|
+
* This is the shared implementation for both context and admin runners.
|
|
9
|
+
*/
|
|
10
|
+
function createHostRunFn(runner) {
|
|
11
|
+
return async (ref, input, options) => {
|
|
12
|
+
const workflowName = (0, helpers_1.getRefAccessor)(ref).name;
|
|
13
|
+
const wait = options?.wait ?? true;
|
|
14
|
+
if (Array.isArray(input)) {
|
|
15
|
+
const results = await Promise.all(input.map((i) => runner(workflowName, i, options)));
|
|
16
|
+
if (wait) {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
18
|
+
return (await Promise.all(results.map((r) => r.output)));
|
|
19
|
+
}
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
21
|
+
return results;
|
|
22
|
+
}
|
|
23
|
+
const runRef = await runner(workflowName, input, options);
|
|
24
|
+
if (wait) {
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
26
|
+
return runRef.output;
|
|
27
|
+
}
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
29
|
+
return runRef;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates a HostRunFn that uses SDK Context for spawning child workflows.
|
|
34
|
+
* Used within task execution contexts.
|
|
35
|
+
*/
|
|
36
|
+
function createHostRunForContext(ctx) {
|
|
37
|
+
return createHostRunFn((workflowName, input, options) => ctx.runNoWaitChild(workflowName, input, options));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates a HostRunFn that uses HatchetClient for external workflow triggering.
|
|
41
|
+
* Used by HClient for triggering workflows from outside task contexts.
|
|
42
|
+
*/
|
|
43
|
+
function createHostRunForAdmin(client) {
|
|
44
|
+
return createHostRunFn((workflowName, input, options) => client.runNoWait(workflowName, input, options ?? {}));
|
|
45
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AnyCallableRef, InputOfRef, OutputOfRef } from "../../references";
|
|
2
|
+
import type { RunOpts } from "@hatchet-dev/typescript-sdk";
|
|
3
|
+
import type WorkflowRunRef from "@hatchet-dev/typescript-sdk/util/workflow-run-ref";
|
|
4
|
+
/**
|
|
5
|
+
* Describes the return type of the {@link HostRunFn} function.
|
|
6
|
+
*
|
|
7
|
+
* @param I The input type of the callable reference.
|
|
8
|
+
* @param R The callable reference.
|
|
9
|
+
* @param W Whether to wait for the task to complete before returning.
|
|
10
|
+
*/
|
|
11
|
+
export type HostRunReturn<I extends InputOfRef<R> | InputOfRef<R>[], R extends AnyCallableRef, W extends boolean> = I extends InputOfRef<R>[] ? W extends true ? OutputOfRef<R>[] : WorkflowRunRef<OutputOfRef<R>>[] : W extends true ? OutputOfRef<R> : WorkflowRunRef<OutputOfRef<R>>;
|
|
12
|
+
export interface HostRunOpts<W extends boolean> extends RunOpts {
|
|
13
|
+
/**
|
|
14
|
+
* Whether to wait for the task to complete before returning.
|
|
15
|
+
*
|
|
16
|
+
* @default true
|
|
17
|
+
*/
|
|
18
|
+
wait?: W;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Runs a child task or workflow. This can be used to run multiple tasks in parallel.
|
|
22
|
+
* If `wait` is set to `false`, a `WorkflowRunRef` is returned.
|
|
23
|
+
*/
|
|
24
|
+
export type HostRunFn = <R extends AnyCallableRef, I extends InputOfRef<R> | InputOfRef<R>[], W extends boolean = true>(ref: R, input: I, options?: HostRunOpts<W>) => Promise<HostRunReturn<I, R, W>>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createHostRunForAdmin = exports.createHostRunForContext = void 0;
|
|
4
|
+
var adapter_factory_1 = require("./adapter-factory");
|
|
5
|
+
Object.defineProperty(exports, "createHostRunForContext", { enumerable: true, get: function () { return adapter_factory_1.createHostRunForContext; } });
|
|
6
|
+
Object.defineProperty(exports, "createHostRunForAdmin", { enumerable: true, get: function () { return adapter_factory_1.createHostRunForAdmin; } });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TaskWorkflowDeclaration, WorkflowDeclaration } from "@hatchet-dev/typescript-sdk";
|
|
2
2
|
import { ModuleRef } from "@nestjs/core";
|
|
3
|
-
import { InterceptorRegistration } from "../internal";
|
|
4
|
-
import { AnyHost } from "../
|
|
3
|
+
import { InterceptorRegistration } from "../internal/registrations";
|
|
4
|
+
import { AnyHost } from "../references/shared";
|
|
5
5
|
export declare class DeclarationBuilderService {
|
|
6
6
|
private readonly moduleRef;
|
|
7
7
|
private readonly interceptorRegistration?;
|
|
@@ -44,13 +44,12 @@ export declare class DeclarationBuilderService {
|
|
|
44
44
|
*/
|
|
45
45
|
private buildWorkflowHostGraph;
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* Event validation is handled by the event's isCtx() method instead.
|
|
47
|
+
* Pre-processes the context by inferring the trigger source and
|
|
48
|
+
* validating the input (if applicable).
|
|
50
49
|
*
|
|
51
|
-
* @returns The
|
|
50
|
+
* @returns The pre-processed context properties including hostConfig.
|
|
52
51
|
*/
|
|
53
|
-
private
|
|
52
|
+
private preProcessContext;
|
|
54
53
|
/**
|
|
55
54
|
* Executes a function, optionally intercepted by the interceptors.
|
|
56
55
|
* Interceptors are chained in array order (first = outermost).
|
|
@@ -60,4 +59,12 @@ export declare class DeclarationBuilderService {
|
|
|
60
59
|
* @returns The result of the function.
|
|
61
60
|
*/
|
|
62
61
|
private executeWithInterceptors;
|
|
62
|
+
/**
|
|
63
|
+
* Infers the trigger source from the given context.
|
|
64
|
+
*
|
|
65
|
+
* @param ctx The context.
|
|
66
|
+
* @returns The inferred trigger source.
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
private inferTriggerSource;
|
|
63
70
|
}
|