@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
|
@@ -18,10 +18,10 @@ const common_1 = require("@nestjs/common");
|
|
|
18
18
|
const core_1 = require("@nestjs/core");
|
|
19
19
|
const directed_graph_typed_1 = require("directed-graph-typed");
|
|
20
20
|
const abstracts_1 = require("../abstracts");
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
21
|
+
const event_definition_1 = require("../events/event-definition");
|
|
22
|
+
const context_1 = require("../execution/context");
|
|
23
|
+
const registrations_1 = require("../internal/registrations");
|
|
24
|
+
const accessor_1 = require("../metadata/accessor");
|
|
25
25
|
let DeclarationBuilderService = class DeclarationBuilderService {
|
|
26
26
|
moduleRef;
|
|
27
27
|
interceptorRegistration;
|
|
@@ -51,8 +51,8 @@ let DeclarationBuilderService = class DeclarationBuilderService {
|
|
|
51
51
|
// First, validate the host.
|
|
52
52
|
this.validateTaskHost(host);
|
|
53
53
|
const accessor = (0, accessor_1.fromInstance)(host);
|
|
54
|
-
// Get the host options
|
|
55
|
-
const hostOpts = accessor.
|
|
54
|
+
// Get the SDK-compatible host options.
|
|
55
|
+
const hostOpts = accessor.sdkOpts;
|
|
56
56
|
// Get the single decorated method name.
|
|
57
57
|
const methodName = accessor.methods[0];
|
|
58
58
|
if (!methodName) {
|
|
@@ -65,14 +65,17 @@ let DeclarationBuilderService = class DeclarationBuilderService {
|
|
|
65
65
|
return new typescript_sdk_1.TaskWorkflowDeclaration({
|
|
66
66
|
...hostOpts,
|
|
67
67
|
fn: async (_, ctx) => {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
const partial = await this.preProcessContext(host, ctx);
|
|
69
|
+
// Create the task context from the SDK context and the partial.
|
|
70
|
+
const taskCtx = (0, context_1.createTaskCtx)({ fromSDK: ctx, ...partial });
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
72
|
+
const result = await this.executeWithInterceptors(taskCtx, async () => {
|
|
71
73
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
|
|
72
74
|
const fn = proto[methodName];
|
|
73
75
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
|
|
74
76
|
return await fn.call(host, taskCtx);
|
|
75
77
|
});
|
|
78
|
+
return result;
|
|
76
79
|
},
|
|
77
80
|
});
|
|
78
81
|
}
|
|
@@ -81,11 +84,8 @@ let DeclarationBuilderService = class DeclarationBuilderService {
|
|
|
81
84
|
this.validateWorkflowHost(host);
|
|
82
85
|
const accessor = (0, accessor_1.fromInstance)(host);
|
|
83
86
|
const graph = this.buildWorkflowHostGraph(host);
|
|
84
|
-
const hostOpts = accessor.metadata;
|
|
85
87
|
// Construct an unbound declaration for it.
|
|
86
|
-
const workflowDec = new typescript_sdk_1.WorkflowDeclaration(
|
|
87
|
-
...hostOpts,
|
|
88
|
-
});
|
|
88
|
+
const workflowDec = new typescript_sdk_1.WorkflowDeclaration(accessor.sdkOpts);
|
|
89
89
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
90
90
|
const proto = Object.getPrototypeOf(host);
|
|
91
91
|
// Mapping of task name to task declaration.
|
|
@@ -108,9 +108,12 @@ let DeclarationBuilderService = class DeclarationBuilderService {
|
|
|
108
108
|
name: method,
|
|
109
109
|
parents: parentsResolved,
|
|
110
110
|
fn: async (_, ctx) => {
|
|
111
|
-
const
|
|
112
|
-
// Create the workflow context from the SDK context and
|
|
113
|
-
const workflowCtx = (0,
|
|
111
|
+
const partial = await this.preProcessContext(host, ctx);
|
|
112
|
+
// Create the workflow context from the SDK context and the partial
|
|
113
|
+
const workflowCtx = (0, context_1.createWorkflowCtx)({
|
|
114
|
+
fromSDK: ctx,
|
|
115
|
+
...partial,
|
|
116
|
+
});
|
|
114
117
|
return await this.executeWithInterceptors(workflowCtx, async () => {
|
|
115
118
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
116
119
|
const fn = proto[method];
|
|
@@ -200,30 +203,46 @@ let DeclarationBuilderService = class DeclarationBuilderService {
|
|
|
200
203
|
return graph;
|
|
201
204
|
}
|
|
202
205
|
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* Event validation is handled by the event's isCtx() method instead.
|
|
206
|
+
* Pre-processes the context by inferring the trigger source and
|
|
207
|
+
* validating the input (if applicable).
|
|
206
208
|
*
|
|
207
|
-
* @returns The
|
|
209
|
+
* @returns The pre-processed context properties including hostConfig.
|
|
208
210
|
*/
|
|
209
|
-
async
|
|
210
|
-
//
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
//
|
|
217
|
-
|
|
218
|
-
|
|
211
|
+
async preProcessContext(host, context) {
|
|
212
|
+
// Infer the trigger source.
|
|
213
|
+
const triggerSource = this.inferTriggerSource(context);
|
|
214
|
+
// Extract the input from the context.
|
|
215
|
+
// We default to an empty object if input is undefined.
|
|
216
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
217
|
+
const input = context.input ?? {};
|
|
218
|
+
// Build the host trigger config for introspection.
|
|
219
|
+
const accessor = (0, accessor_1.fromInstance)(host);
|
|
220
|
+
// Construct the host trigger config (uses translated SDK opts for onEvents).
|
|
221
|
+
const hostConfig = {
|
|
222
|
+
onEvents: accessor.sdkOpts.onEvents ?? [],
|
|
223
|
+
onCrons: accessor.metadata.onCrons ?? [],
|
|
224
|
+
};
|
|
225
|
+
// Only run validation for "run" triggers.
|
|
226
|
+
// All other triggers skip validation here.
|
|
227
|
+
if (triggerSource === "run") {
|
|
228
|
+
// Resolve the schema from the host.
|
|
229
|
+
const schema = host.inputSchema();
|
|
230
|
+
// If there is no schema, return the input as is (after normalizing).
|
|
231
|
+
if (!schema) {
|
|
232
|
+
return { input, triggerSource, hostConfig };
|
|
233
|
+
}
|
|
234
|
+
// Validate the input against the schema.
|
|
235
|
+
const result = await schema["~standard"].validate(input);
|
|
236
|
+
// If the result is successful, return the transformed value.
|
|
237
|
+
if ("value" in result) {
|
|
238
|
+
return { input: result.value, triggerSource, hostConfig };
|
|
239
|
+
}
|
|
240
|
+
throw new Error(`Input validation failed: ${JSON.stringify(result.issues)}`);
|
|
219
241
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if ("value" in result) {
|
|
224
|
-
return result.value;
|
|
242
|
+
else {
|
|
243
|
+
// For non-"run" triggers, skip validation and return the input as is.
|
|
244
|
+
return { input, triggerSource, hostConfig };
|
|
225
245
|
}
|
|
226
|
-
throw new Error(`Input validation failed: ${JSON.stringify(result.issues)}`);
|
|
227
246
|
}
|
|
228
247
|
/**
|
|
229
248
|
* Executes a function, optionally intercepted by the interceptors.
|
|
@@ -246,12 +265,40 @@ let DeclarationBuilderService = class DeclarationBuilderService {
|
|
|
246
265
|
}
|
|
247
266
|
return await next();
|
|
248
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Infers the trigger source from the given context.
|
|
270
|
+
*
|
|
271
|
+
* @param ctx The context.
|
|
272
|
+
* @returns The inferred trigger source.
|
|
273
|
+
* @private
|
|
274
|
+
*/
|
|
275
|
+
inferTriggerSource(ctx) {
|
|
276
|
+
// If the input contains the EVENT_MARKER, it's an event trigger.
|
|
277
|
+
// This is specific to event triggers from this library.
|
|
278
|
+
if (typeof ctx.input === "object" && event_definition_1.EVENT_MARKER in ctx.input) {
|
|
279
|
+
return "event";
|
|
280
|
+
}
|
|
281
|
+
// Additional metadata can also indicate cron or event triggers.
|
|
282
|
+
const metadata = ctx.additionalMetadata();
|
|
283
|
+
// Check for cron metadata key.
|
|
284
|
+
if ("hatchet__cron_name" in metadata) {
|
|
285
|
+
return "cron";
|
|
286
|
+
}
|
|
287
|
+
// Check for event metadata key.
|
|
288
|
+
if ("hatchet__event_key" in metadata) {
|
|
289
|
+
return "event";
|
|
290
|
+
}
|
|
291
|
+
// Default to "run" for direct runs.
|
|
292
|
+
// We cannot reliably detect other sources at this time.
|
|
293
|
+
// The "other" source is reserved for future use.
|
|
294
|
+
return "run";
|
|
295
|
+
}
|
|
249
296
|
};
|
|
250
297
|
exports.DeclarationBuilderService = DeclarationBuilderService;
|
|
251
298
|
exports.DeclarationBuilderService = DeclarationBuilderService = __decorate([
|
|
252
299
|
(0, common_1.Injectable)(),
|
|
253
300
|
__param(1, (0, common_1.Optional)()),
|
|
254
|
-
__param(1, (0, common_1.Inject)(
|
|
301
|
+
__param(1, (0, common_1.Inject)(registrations_1.InterceptorRegistration)),
|
|
255
302
|
__metadata("design:paramtypes", [core_1.ModuleRef,
|
|
256
|
-
|
|
303
|
+
registrations_1.InterceptorRegistration])
|
|
257
304
|
], DeclarationBuilderService);
|
|
@@ -18,8 +18,8 @@ const typescript_sdk_1 = require("@hatchet-dev/typescript-sdk");
|
|
|
18
18
|
const common_1 = require("@nestjs/common");
|
|
19
19
|
const core_1 = require("@nestjs/core");
|
|
20
20
|
const hatchet_module_config_1 = require("../hatchet.module-config");
|
|
21
|
-
const internal_1 = require("../internal");
|
|
22
21
|
const declaration_builder_service_1 = require("./declaration-builder.service");
|
|
22
|
+
const registrations_1 = require("../internal/registrations");
|
|
23
23
|
let WorkerManagementService = class WorkerManagementService {
|
|
24
24
|
static { WorkerManagementService_1 = this; }
|
|
25
25
|
client;
|
|
@@ -75,7 +75,7 @@ let WorkerManagementService = class WorkerManagementService {
|
|
|
75
75
|
* Discovers all feature registrations from forFeature() calls.
|
|
76
76
|
*/
|
|
77
77
|
discoverFeatureRegistrations() {
|
|
78
|
-
return this.moduleRef.get(
|
|
78
|
+
return this.moduleRef.get(registrations_1.HatchetFeatureRegistration, {
|
|
79
79
|
strict: false,
|
|
80
80
|
each: true,
|
|
81
81
|
});
|
package/dist/hatchet.module.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DynamicModule, Type } from "@nestjs/common";
|
|
2
2
|
import { HatchetModuleConfig } from "./hatchet.module-config";
|
|
3
3
|
import { Interceptor } from "./interceptor";
|
|
4
|
-
import type { AnyCallableRef } from "./
|
|
4
|
+
import type { AnyCallableRef } from "./references";
|
|
5
5
|
/**
|
|
6
6
|
* Extra options for the module (processed at module definition time).
|
|
7
7
|
*/
|
package/dist/hatchet.module.js
CHANGED
|
@@ -12,7 +12,7 @@ const client_1 = require("./client");
|
|
|
12
12
|
const declaration_builder_service_1 = require("./explorer/declaration-builder.service");
|
|
13
13
|
const worker_management_service_1 = require("./explorer/worker-management.service");
|
|
14
14
|
const hatchet_module_config_1 = require("./hatchet.module-config");
|
|
15
|
-
const
|
|
15
|
+
const registrations_1 = require("./internal/registrations");
|
|
16
16
|
const sdk_1 = require("./sdk");
|
|
17
17
|
const { ConfigurableModuleClass } = new common_1.ConfigurableModuleBuilder({
|
|
18
18
|
optionsInjectionToken: hatchet_module_config_1.hatchetModuleConfigToken,
|
|
@@ -28,8 +28,8 @@ const { ConfigurableModuleClass } = new common_1.ConfigurableModuleBuilder({
|
|
|
28
28
|
...(extras.interceptors?.length
|
|
29
29
|
? [
|
|
30
30
|
{
|
|
31
|
-
provide:
|
|
32
|
-
useValue: new
|
|
31
|
+
provide: registrations_1.InterceptorRegistration,
|
|
32
|
+
useValue: new registrations_1.InterceptorRegistration(extras.interceptors),
|
|
33
33
|
},
|
|
34
34
|
]
|
|
35
35
|
: []),
|
|
@@ -57,8 +57,8 @@ let HatchetModule = class HatchetModule extends ConfigurableModuleClass {
|
|
|
57
57
|
module: HatchetFeatureModule,
|
|
58
58
|
providers: [
|
|
59
59
|
{
|
|
60
|
-
provide:
|
|
61
|
-
useValue: new
|
|
60
|
+
provide: registrations_1.HatchetFeatureRegistration,
|
|
61
|
+
useValue: new registrations_1.HatchetFeatureRegistration(hostRefs),
|
|
62
62
|
},
|
|
63
63
|
],
|
|
64
64
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
export * from "./hatchet.module";
|
|
2
2
|
export * from "./abstracts";
|
|
3
3
|
export * from "./client";
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
4
|
+
export * from "./execution";
|
|
5
|
+
export * from "./metadata";
|
|
6
6
|
export * from "./events";
|
|
7
7
|
export * from "./interceptor";
|
|
8
|
-
export * from "./
|
|
9
|
-
export * from "./ref";
|
|
8
|
+
export * from "./references";
|
|
10
9
|
export { HatchetModuleConfig } from "./hatchet.module-config";
|
package/dist/index.js
CHANGED
|
@@ -17,9 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./hatchet.module"), exports);
|
|
18
18
|
__exportStar(require("./abstracts"), exports);
|
|
19
19
|
__exportStar(require("./client"), exports);
|
|
20
|
-
__exportStar(require("./
|
|
21
|
-
__exportStar(require("./
|
|
20
|
+
__exportStar(require("./execution"), exports);
|
|
21
|
+
__exportStar(require("./metadata"), exports);
|
|
22
22
|
__exportStar(require("./events"), exports);
|
|
23
23
|
__exportStar(require("./interceptor"), exports);
|
|
24
|
-
__exportStar(require("./
|
|
25
|
-
__exportStar(require("./ref"), exports);
|
|
24
|
+
__exportStar(require("./references"), exports);
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createHostRunForContext = createHostRunForContext;
|
|
4
4
|
exports.createHostRunForAdmin = createHostRunForAdmin;
|
|
5
|
-
const
|
|
5
|
+
const helpers_1 = require("../../ref/helpers");
|
|
6
6
|
/**
|
|
7
7
|
* Creates a HostRunFn using the provided runner strategy.
|
|
8
8
|
* This is the shared implementation for both context and admin runners.
|
|
9
9
|
*/
|
|
10
10
|
function createHostRunFn(runner) {
|
|
11
11
|
return async (ref, input, options) => {
|
|
12
|
-
const workflowName = (0,
|
|
12
|
+
const workflowName = (0, helpers_1.getRefAccessor)(ref).name;
|
|
13
13
|
const wait = options?.wait ?? true;
|
|
14
14
|
if (Array.isArray(input)) {
|
|
15
15
|
const results = await Promise.all(input.map((i) => runner(workflowName, i, options)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { Interceptor } from "./interceptor";
|
|
@@ -1,17 +1,5 @@
|
|
|
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.Interceptor = void 0;
|
|
4
|
+
var interceptor_1 = require("./interceptor");
|
|
5
|
+
Object.defineProperty(exports, "Interceptor", { enumerable: true, get: function () { return interceptor_1.Interceptor; } });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Interceptor } from "../interceptor";
|
|
2
|
+
import type { AnyHostCtor } from "../references/shared";
|
|
3
|
+
import type { Type } from "@nestjs/common";
|
|
4
|
+
/**
|
|
5
|
+
* Token class for feature registration discovery.
|
|
6
|
+
* Each forFeature() call creates a provider with this class as token.
|
|
7
|
+
*/
|
|
8
|
+
export declare class HatchetFeatureRegistration {
|
|
9
|
+
readonly refs: AnyHostCtor[];
|
|
10
|
+
constructor(refs: AnyHostCtor[]);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Token class for interceptor registration.
|
|
14
|
+
* Stores interceptor class references for later resolution via ModuleRef.
|
|
15
|
+
*/
|
|
16
|
+
export declare class InterceptorRegistration {
|
|
17
|
+
readonly refs: Type<Interceptor>[];
|
|
18
|
+
constructor(refs: Type<Interceptor>[]);
|
|
19
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InterceptorRegistration = exports.HatchetFeatureRegistration = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Token class for feature registration discovery.
|
|
6
|
+
* Each forFeature() call creates a provider with this class as token.
|
|
7
|
+
*/
|
|
8
|
+
class HatchetFeatureRegistration {
|
|
9
|
+
refs;
|
|
10
|
+
constructor(refs) {
|
|
11
|
+
this.refs = refs;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.HatchetFeatureRegistration = HatchetFeatureRegistration;
|
|
15
|
+
/**
|
|
16
|
+
* Token class for interceptor registration.
|
|
17
|
+
* Stores interceptor class references for later resolution via ModuleRef.
|
|
18
|
+
*/
|
|
19
|
+
class InterceptorRegistration {
|
|
20
|
+
refs;
|
|
21
|
+
constructor(refs) {
|
|
22
|
+
this.refs = refs;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.InterceptorRegistration = InterceptorRegistration;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Interceptor } from "../interceptor";
|
|
2
|
+
import type { AnyHostCtor } from "../references/shared";
|
|
3
|
+
import type { Type } from "@nestjs/common";
|
|
4
|
+
/**
|
|
5
|
+
* Token class for feature registration discovery.
|
|
6
|
+
* Each forFeature() call creates a provider with this class as token.
|
|
7
|
+
*/
|
|
8
|
+
export declare class HatchetFeatureRegistration {
|
|
9
|
+
readonly refs: AnyHostCtor[];
|
|
10
|
+
constructor(refs: AnyHostCtor[]);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Token class for interceptor registration.
|
|
14
|
+
* Stores interceptor class references for later resolution via ModuleRef.
|
|
15
|
+
*/
|
|
16
|
+
export declare class InterceptorRegistration {
|
|
17
|
+
readonly refs: Type<Interceptor>[];
|
|
18
|
+
constructor(refs: Type<Interceptor>[]);
|
|
19
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InterceptorRegistration = exports.HatchetFeatureRegistration = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Token class for feature registration discovery.
|
|
6
|
+
* Each forFeature() call creates a provider with this class as token.
|
|
7
|
+
*/
|
|
8
|
+
class HatchetFeatureRegistration {
|
|
9
|
+
refs;
|
|
10
|
+
constructor(refs) {
|
|
11
|
+
this.refs = refs;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.HatchetFeatureRegistration = HatchetFeatureRegistration;
|
|
15
|
+
/**
|
|
16
|
+
* Token class for interceptor registration.
|
|
17
|
+
* Stores interceptor class references for later resolution via ModuleRef.
|
|
18
|
+
*/
|
|
19
|
+
class InterceptorRegistration {
|
|
20
|
+
refs;
|
|
21
|
+
constructor(refs) {
|
|
22
|
+
this.refs = refs;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.InterceptorRegistration = InterceptorRegistration;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { Interceptor } from "../interceptor";
|
|
2
|
-
import type { AnyHostCtor } from "../
|
|
2
|
+
import type { AnyHostCtor } from "../references/shared";
|
|
3
3
|
import type { Type } from "@nestjs/common";
|
|
4
|
-
export declare const METADATA_KEY_HOST_OPTS = "hatchet:host:opts";
|
|
5
|
-
export declare const METADATA_KEY_TASK_OPTS = "hatchet:task:opts";
|
|
6
|
-
export declare const METADATA_KEY_WORKFLOW_TASK_OPTS = "hatchet:workflow:task:opts";
|
|
7
4
|
/**
|
|
8
5
|
* Token class for feature registration discovery.
|
|
9
6
|
* Each forFeature() call creates a provider with this class as token.
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InterceptorRegistration = exports.HatchetFeatureRegistration =
|
|
4
|
-
exports.METADATA_KEY_HOST_OPTS = "hatchet:host:opts";
|
|
5
|
-
exports.METADATA_KEY_TASK_OPTS = "hatchet:task:opts";
|
|
6
|
-
exports.METADATA_KEY_WORKFLOW_TASK_OPTS = "hatchet:workflow:task:opts";
|
|
3
|
+
exports.InterceptorRegistration = exports.HatchetFeatureRegistration = void 0;
|
|
7
4
|
/**
|
|
8
5
|
* Token class for feature registration discovery.
|
|
9
6
|
* Each forFeature() call creates a provider with this class as token.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { HostOpts, TaskOpts, WorkflowTaskOpts } from "./decorators";
|
|
2
|
+
import type { SdkHostOpts } from "./translator";
|
|
3
|
+
import type { AnyHost, AnyHostCtor } from "../references/shared";
|
|
4
|
+
/**
|
|
5
|
+
* Accessor for host metadata and methods.
|
|
6
|
+
*/
|
|
7
|
+
declare class HostAccessor {
|
|
8
|
+
readonly ctor: AnyHostCtor;
|
|
9
|
+
constructor(ctor: AnyHostCtor);
|
|
10
|
+
/**
|
|
11
|
+
* Returns raw enhanced metadata from @Host() decorator.
|
|
12
|
+
*/
|
|
13
|
+
get metadata(): HostOpts;
|
|
14
|
+
/**
|
|
15
|
+
* Returns SDK-compatible options for workflow declarations.
|
|
16
|
+
*/
|
|
17
|
+
get sdkOpts(): SdkHostOpts;
|
|
18
|
+
get name(): string;
|
|
19
|
+
get isWorkflow(): boolean;
|
|
20
|
+
get isTask(): boolean;
|
|
21
|
+
get methods(): string[];
|
|
22
|
+
getWorkflowTaskMeta(method: string): WorkflowTaskOpts<any>;
|
|
23
|
+
getTaskMeta(method: string): TaskOpts;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create accessor from host constructor.
|
|
27
|
+
*/
|
|
28
|
+
export declare function fromCtor(ctor: AnyHostCtor): HostAccessor;
|
|
29
|
+
/**
|
|
30
|
+
* Create accessor from host instance.
|
|
31
|
+
*/
|
|
32
|
+
export declare function fromInstance(instance: AnyHost): HostAccessor;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromCtor = fromCtor;
|
|
4
|
+
exports.fromInstance = fromInstance;
|
|
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
|
+
const abstracts_1 = require("../abstracts");
|
|
7
|
+
const keys_1 = require("./keys");
|
|
8
|
+
const translator_1 = require("./translator");
|
|
9
|
+
/**
|
|
10
|
+
* Accessor for host metadata and methods.
|
|
11
|
+
*/
|
|
12
|
+
class HostAccessor {
|
|
13
|
+
ctor;
|
|
14
|
+
constructor(ctor) {
|
|
15
|
+
this.ctor = ctor;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Returns raw enhanced metadata from @Host() decorator.
|
|
19
|
+
*/
|
|
20
|
+
get metadata() {
|
|
21
|
+
return Reflect.getMetadata(keys_1.METADATA_KEY_HOST_OPTS, this.ctor);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns SDK-compatible options for workflow declarations.
|
|
25
|
+
*/
|
|
26
|
+
get sdkOpts() {
|
|
27
|
+
return (0, translator_1.translateHostOpts)(this.metadata);
|
|
28
|
+
}
|
|
29
|
+
get name() {
|
|
30
|
+
return this.metadata.name;
|
|
31
|
+
}
|
|
32
|
+
get isWorkflow() {
|
|
33
|
+
return this.ctor.prototype instanceof abstracts_1.WorkflowHost;
|
|
34
|
+
}
|
|
35
|
+
get isTask() {
|
|
36
|
+
return this.ctor.prototype instanceof abstracts_1.TaskHost;
|
|
37
|
+
}
|
|
38
|
+
get methods() {
|
|
39
|
+
const markerKey = this.isWorkflow
|
|
40
|
+
? keys_1.METADATA_KEY_WORKFLOW_TASK_OPTS
|
|
41
|
+
: keys_1.METADATA_KEY_TASK_OPTS;
|
|
42
|
+
const proto = this.ctor.prototype;
|
|
43
|
+
return Object.getOwnPropertyNames(proto)
|
|
44
|
+
.filter((name) => name !== "constructor" && typeof proto[name] === "function")
|
|
45
|
+
.filter((method) => Reflect.getMetadata(markerKey, proto[method]) !== undefined);
|
|
46
|
+
}
|
|
47
|
+
getWorkflowTaskMeta(method) {
|
|
48
|
+
return Reflect.getMetadata(keys_1.METADATA_KEY_WORKFLOW_TASK_OPTS, this.ctor.prototype[method]);
|
|
49
|
+
}
|
|
50
|
+
getTaskMeta(method) {
|
|
51
|
+
return Reflect.getMetadata(keys_1.METADATA_KEY_TASK_OPTS, this.ctor.prototype[method]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create accessor from host constructor.
|
|
56
|
+
*/
|
|
57
|
+
function fromCtor(ctor) {
|
|
58
|
+
return new HostAccessor(ctor);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create accessor from host instance.
|
|
62
|
+
*/
|
|
63
|
+
function fromInstance(instance) {
|
|
64
|
+
return new HostAccessor(instance.constructor);
|
|
65
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AnyEventDefinition } from "../../events";
|
|
2
|
+
import type { CreateBaseWorkflowOpts } from "@hatchet-dev/typescript-sdk";
|
|
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;
|
|
15
|
+
/**
|
|
16
|
+
* Decorator to mark a class as a host (for either a workflow or a task).
|
|
17
|
+
*/
|
|
18
|
+
export declare const Host: (opts: HostOpts) => ClassDecorator;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Host = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const keys_1 = require("../keys");
|
|
6
|
+
/**
|
|
7
|
+
* Decorator to mark a class as a host (for either a workflow or a task).
|
|
8
|
+
*/
|
|
9
|
+
const Host = (opts) => {
|
|
10
|
+
return (target) => {
|
|
11
|
+
// Make the workflow injectable.
|
|
12
|
+
(0, common_1.Injectable)()(target);
|
|
13
|
+
// Add the workflow options.
|
|
14
|
+
Reflect.defineMetadata(keys_1.METADATA_KEY_HOST_OPTS, opts, target);
|
|
15
|
+
return target;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
exports.Host = Host;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Host } from "./host.decorator";
|
|
2
|
+
export type { HostOpts } from "./host.decorator";
|
|
3
|
+
export { Task } from "./task.decorator";
|
|
4
|
+
export type { TaskOpts } from "./task.decorator";
|
|
5
|
+
export { WorkflowTask } from "./workflow-task.decorator";
|
|
6
|
+
export type { WorkflowTaskOpts } from "./workflow-task.decorator";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkflowTask = exports.Task = exports.Host = void 0;
|
|
4
|
+
var host_decorator_1 = require("./host.decorator");
|
|
5
|
+
Object.defineProperty(exports, "Host", { enumerable: true, get: function () { return host_decorator_1.Host; } });
|
|
6
|
+
var task_decorator_1 = require("./task.decorator");
|
|
7
|
+
Object.defineProperty(exports, "Task", { enumerable: true, get: function () { return task_decorator_1.Task; } });
|
|
8
|
+
var workflow_task_decorator_1 = require("./workflow-task.decorator");
|
|
9
|
+
Object.defineProperty(exports, "WorkflowTask", { enumerable: true, get: function () { return workflow_task_decorator_1.WorkflowTask; } });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CreateBaseWorkflowOpts, CreateTaskWorkflowOpts } from "@hatchet-dev/typescript-sdk";
|
|
2
|
+
export type TaskOpts = Omit<CreateTaskWorkflowOpts, "fn" | "name" | keyof CreateBaseWorkflowOpts>;
|
|
3
|
+
/**
|
|
4
|
+
* Decorator to mark a method as a Hatchet task.
|
|
5
|
+
*/
|
|
6
|
+
export declare const Task: (opts: TaskOpts) => MethodDecorator;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Task = void 0;
|
|
4
|
+
const keys_1 = require("../keys");
|
|
5
|
+
/**
|
|
6
|
+
* Decorator to mark a method as a Hatchet task.
|
|
7
|
+
*/
|
|
8
|
+
const Task = (opts) => {
|
|
9
|
+
return (_target, _propertyKey, descriptor) => {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
11
|
+
Reflect.defineMetadata(keys_1.METADATA_KEY_TASK_OPTS, opts, descriptor.value);
|
|
12
|
+
return descriptor;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.Task = Task;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WorkflowCtx } from "../../execution";
|
|
2
|
+
import type { ContextMethodKeys, WorkflowHostCtor } from "../../references/shared";
|
|
3
|
+
import type { CreateWorkflowTaskOpts } from "@hatchet-dev/typescript-sdk/v1/task";
|
|
4
|
+
export type WorkflowTaskOpts<C extends WorkflowHostCtor<any>> = Omit<CreateWorkflowTaskOpts, "fn" | "parents" | "name"> & {
|
|
5
|
+
parents?: ContextMethodKeys<InstanceType<C>, WorkflowCtx<any>>[];
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Decorator to mark a method as a workflow task.
|
|
9
|
+
*/
|
|
10
|
+
export declare function WorkflowTask<C extends WorkflowHostCtor<any>>(opts: WorkflowTaskOpts<C>): MethodDecorator;
|