@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.
Files changed (91) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/__fixtures__/test-hosts.d.ts +1 -1
  3. package/dist/__fixtures__/test-hosts.js +10 -10
  4. package/dist/accessor/host-accessor.d.ts +9 -1
  5. package/dist/accessor/host-accessor.js +10 -0
  6. package/dist/accessor/host-opts-translator.d.ts +14 -0
  7. package/dist/accessor/host-opts-translator.js +25 -0
  8. package/dist/accessor/host-opts.d.ts +31 -0
  9. package/dist/accessor/host-opts.js +27 -0
  10. package/dist/accessor/index.d.ts +1 -0
  11. package/dist/accessor/opts-translator.d.ts +10 -0
  12. package/dist/accessor/opts-translator.js +26 -0
  13. package/dist/client/client.d.ts +2 -2
  14. package/dist/client/client.js +5 -5
  15. package/dist/context/context-factory.d.ts +14 -8
  16. package/dist/context/context-factory.js +52 -25
  17. package/dist/context/context.d.ts +60 -3
  18. package/dist/context/context.js +2 -0
  19. package/dist/context/index.d.ts +1 -1
  20. package/dist/context/test-narrowing.d.ts +5 -0
  21. package/dist/context/test-narrowing.js +17 -0
  22. package/dist/context/trigger-guards.d.ts +22 -0
  23. package/dist/context/trigger-guards.js +2 -0
  24. package/dist/decorators/host-opts.d.ts +19 -0
  25. package/dist/decorators/host-opts.js +2 -0
  26. package/dist/decorators/host.decorator.d.ts +15 -2
  27. package/dist/decorators/host.decorator.js +2 -2
  28. package/dist/decorators/workflow-task.decorators.d.ts +1 -1
  29. package/dist/events/index.d.ts +2 -1
  30. package/dist/events/index.js +4 -15
  31. package/dist/execution/context/factory.d.ts +22 -0
  32. package/dist/execution/context/factory.js +70 -0
  33. package/dist/execution/context/index.d.ts +4 -0
  34. package/dist/execution/context/index.js +8 -0
  35. package/dist/execution/context/types.d.ts +108 -0
  36. package/dist/execution/context/types.js +4 -0
  37. package/dist/execution/host-run/adapter-factory.d.ts +12 -0
  38. package/dist/execution/host-run/adapter-factory.js +45 -0
  39. package/dist/execution/host-run/function-type.d.ts +24 -0
  40. package/dist/execution/host-run/function-type.js +2 -0
  41. package/dist/execution/host-run/index.d.ts +2 -0
  42. package/dist/execution/host-run/index.js +6 -0
  43. package/dist/execution/index.d.ts +2 -0
  44. package/dist/execution/index.js +2 -0
  45. package/dist/explorer/declaration-builder.service.d.ts +14 -7
  46. package/dist/explorer/declaration-builder.service.js +85 -38
  47. package/dist/explorer/worker-management.service.js +2 -2
  48. package/dist/hatchet.module.d.ts +1 -1
  49. package/dist/hatchet.module.js +5 -5
  50. package/dist/index.d.ts +3 -4
  51. package/dist/index.js +3 -4
  52. package/dist/interaction/host-run/adapter-factory.js +2 -2
  53. package/dist/interceptor/index.d.ts +1 -1
  54. package/dist/interceptor/index.js +3 -15
  55. package/dist/interceptor/interceptor.d.ts +1 -1
  56. package/dist/internal/consts.d.ts +19 -0
  57. package/dist/internal/consts.js +25 -0
  58. package/dist/internal/registrations.d.ts +19 -0
  59. package/dist/internal/registrations.js +25 -0
  60. package/dist/internal/shared-consts.d.ts +1 -4
  61. package/dist/internal/shared-consts.js +1 -4
  62. package/dist/metadata/accessor.d.ts +33 -0
  63. package/dist/metadata/accessor.js +65 -0
  64. package/dist/metadata/decorators/host.decorator.d.ts +19 -0
  65. package/dist/metadata/decorators/host.decorator.js +18 -0
  66. package/dist/metadata/decorators/index.d.ts +6 -0
  67. package/dist/metadata/decorators/index.js +9 -0
  68. package/dist/metadata/decorators/task.decorator.d.ts +6 -0
  69. package/dist/metadata/decorators/task.decorator.js +15 -0
  70. package/dist/metadata/decorators/workflow-task.decorator.d.ts +10 -0
  71. package/dist/metadata/decorators/workflow-task.decorator.js +14 -0
  72. package/dist/metadata/index.d.ts +6 -0
  73. package/dist/metadata/index.js +10 -0
  74. package/dist/metadata/keys.d.ts +3 -0
  75. package/dist/metadata/keys.js +6 -0
  76. package/dist/metadata/translator.d.ts +10 -0
  77. package/dist/metadata/translator.js +26 -0
  78. package/dist/ref/helpers.d.ts +1 -0
  79. package/dist/ref/index.d.ts +3 -3
  80. package/dist/ref/index.js +5 -17
  81. package/dist/ref/shared.d.ts +7 -0
  82. package/dist/references/helpers.d.ts +27 -0
  83. package/dist/references/helpers.js +31 -0
  84. package/dist/references/index.d.ts +3 -0
  85. package/dist/references/index.js +7 -0
  86. package/dist/references/refs.d.ts +27 -0
  87. package/dist/references/refs.js +2 -0
  88. package/dist/references/shared.d.ts +172 -0
  89. package/dist/references/shared.js +2 -0
  90. package/dist/sdk/hatchet-client.factory.js +4 -6
  91. package/package.json +8 -4
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkflowTask = WorkflowTask;
4
+ const keys_1 = require("../keys");
5
+ /**
6
+ * Decorator to mark a method as a workflow task.
7
+ */
8
+ function WorkflowTask(opts) {
9
+ return (_target, _propertyKey, descriptor) => {
10
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
11
+ Reflect.defineMetadata(keys_1.METADATA_KEY_WORKFLOW_TASK_OPTS, opts, descriptor.value);
12
+ return descriptor;
13
+ };
14
+ }
@@ -0,0 +1,6 @@
1
+ export { Host } from "./decorators/host.decorator";
2
+ export type { HostOpts } from "./decorators/host.decorator";
3
+ export { Task } from "./decorators/task.decorator";
4
+ export type { TaskOpts } from "./decorators/task.decorator";
5
+ export { WorkflowTask } from "./decorators/workflow-task.decorator";
6
+ export type { WorkflowTaskOpts } from "./decorators/workflow-task.decorator";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkflowTask = exports.Task = exports.Host = void 0;
4
+ // Decorators
5
+ var host_decorator_1 = require("./decorators/host.decorator");
6
+ Object.defineProperty(exports, "Host", { enumerable: true, get: function () { return host_decorator_1.Host; } });
7
+ var task_decorator_1 = require("./decorators/task.decorator");
8
+ Object.defineProperty(exports, "Task", { enumerable: true, get: function () { return task_decorator_1.Task; } });
9
+ var workflow_task_decorator_1 = require("./decorators/workflow-task.decorator");
10
+ Object.defineProperty(exports, "WorkflowTask", { enumerable: true, get: function () { return workflow_task_decorator_1.WorkflowTask; } });
@@ -0,0 +1,3 @@
1
+ export declare const METADATA_KEY_HOST_OPTS = "hatchet:host:opts";
2
+ export declare const METADATA_KEY_TASK_OPTS = "hatchet:task:opts";
3
+ export declare const METADATA_KEY_WORKFLOW_TASK_OPTS = "hatchet:workflow:task:opts";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.METADATA_KEY_WORKFLOW_TASK_OPTS = exports.METADATA_KEY_TASK_OPTS = exports.METADATA_KEY_HOST_OPTS = void 0;
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";
@@ -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;
@@ -17,6 +17,7 @@ export declare function workflowRef<C extends WorkflowHostCtor<any>>(host: Valid
17
17
  export declare function getRefAccessor(ref: AnyCallableRef): {
18
18
  readonly ctor: AnyHostCtor;
19
19
  get metadata(): import("..").HostOpts;
20
+ get sdkOpts(): import("../accessor").SdkHostOpts;
20
21
  get name(): string;
21
22
  get isWorkflow(): boolean;
22
23
  get isTask(): boolean;
@@ -1,3 +1,3 @@
1
- export * from "./refs";
2
- export * from "./helpers";
3
- export * from "./shared";
1
+ export type { TaskRef, WorkflowRef, AnyCallableRef, InputOfRef, OutputOfRef, } from "./refs";
2
+ export { taskRef, workflowRef } from "./helpers";
3
+ export type { TaskInput, TaskOutput, WorkflowInput, WorkflowOutput, WorkflowTasksOutputMap, } from "./shared";
package/dist/ref/index.js CHANGED
@@ -1,19 +1,7 @@
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
- __exportStar(require("./refs"), exports);
18
- __exportStar(require("./helpers"), exports);
19
- __exportStar(require("./shared"), exports);
3
+ exports.workflowRef = exports.taskRef = void 0;
4
+ // Public API - Factory functions
5
+ var helpers_1 = require("./helpers");
6
+ Object.defineProperty(exports, "taskRef", { enumerable: true, get: function () { return helpers_1.taskRef; } });
7
+ Object.defineProperty(exports, "workflowRef", { enumerable: true, get: function () { return helpers_1.workflowRef; } });
@@ -19,12 +19,14 @@ export type AnyHostCtor = WorkflowHostCtor<any> | TaskHostCtor<any>;
19
19
  /**
20
20
  * Represents a workflow host constructor type.
21
21
  *
22
+ * @internal Used in public signatures but not intended for direct external use.
22
23
  * @template I - The input type that the workflow accepts.
23
24
  */
24
25
  export type WorkflowHostCtor<I> = abstract new (...args: any[]) => WorkflowHost<I>;
25
26
  /**
26
27
  * Represents a task host constructor type.
27
28
  *
29
+ * @internal Used in public signatures but not intended for direct external use.
28
30
  * @template I - The input type that the task accepts.
29
31
  */
30
32
  export type TaskHostCtor<I> = abstract new (...args: any[]) => TaskHost<I>;
@@ -52,6 +54,7 @@ export type IsTaskRunnableSignature<F extends (...args: any[]) => any, C extends
52
54
  * For a TaskHost, this should return exactly one key.
53
55
  * For a WorkflowHost, this returns all workflow task method keys.
54
56
  *
57
+ * @internal Used by WorkflowTaskOpts but not intended for direct external use.
55
58
  * @template T - The host instance type.
56
59
  * @template C - Optional context type constraint.
57
60
  */
@@ -135,12 +138,14 @@ export type WorkflowOutput<T extends WorkflowHostCtor<any>> = WorkflowTasksOutpu
135
138
  /**
136
139
  * Error type for invalid TaskHost - shows as a readable string literal in error messages.
137
140
  *
141
+ * @internal Type-level error message, not intended for direct external use.
138
142
  * @template Reason - The error message to display.
139
143
  */
140
144
  export type InvalidTaskHost<Reason extends string> = `Error: ${Reason}`;
141
145
  /**
142
146
  * Error type for invalid WorkflowHost - shows as a readable string literal in error messages.
143
147
  *
148
+ * @internal Type-level error message, not intended for direct external use.
144
149
  * @template Reason - The error message to display.
145
150
  */
146
151
  export type InvalidWorkflowHost<Reason extends string> = `Error: ${Reason}`;
@@ -150,6 +155,7 @@ export type InvalidWorkflowHost<Reason extends string> = `Error: ${Reason}`;
150
155
  *
151
156
  * Used by {@link taskRef} to provide compile-time validation.
152
157
  *
158
+ * @internal Used in taskRef() signature but not intended for direct external use.
153
159
  * @template C - The task host constructor type to validate.
154
160
  */
155
161
  export type ValidTaskHost<C extends TaskHostCtor<any>> = ContextMethodKeys<InstanceType<C>, BaseCtx<any>> extends infer K ? [K] extends [never] ? InvalidTaskHost<"TaskHost must have exactly one method with TaskCtx parameter"> : IsUnion<K> extends true ? InvalidTaskHost<"TaskHost has multiple task methods - only one is allowed"> : C : never;
@@ -159,6 +165,7 @@ export type ValidTaskHost<C extends TaskHostCtor<any>> = ContextMethodKeys<Insta
159
165
  *
160
166
  * Used by {@link workflowRef} to provide compile-time validation.
161
167
  *
168
+ * @internal Used in workflowRef() signature but not intended for direct external use.
162
169
  * @template C - The workflow host constructor type to validate.
163
170
  */
164
171
  export type ValidWorkflowHost<C extends WorkflowHostCtor<any>> = ContextMethodKeys<InstanceType<C>, BaseCtx<any>> extends infer K ? [K] extends [never] ? InvalidWorkflowHost<"WorkflowHost must have at least one method with WorkflowCtx parameter"> : C : never;
@@ -0,0 +1,27 @@
1
+ import type { AnyCallableRef, TaskRef, WorkflowRef } from "./refs";
2
+ import type { AnyHostCtor, TaskHostCtor, ValidTaskHost, ValidWorkflowHost, WorkflowHostCtor } from "./shared";
3
+ /**
4
+ * Creates a reference to a task within a {@link TaskHost}.
5
+ * The task method is automatically resolved since a TaskHost has exactly one task.
6
+ * Compile-time validation ensures the host has exactly one task method.
7
+ */
8
+ export declare function taskRef<C extends TaskHostCtor<any>>(host: ValidTaskHost<C>): TaskRef<C>;
9
+ /**
10
+ * Creates a reference to a workflow as a {@link WorkflowHost}.
11
+ * Compile-time validation ensures the host has at least one workflow task method.
12
+ */
13
+ export declare function workflowRef<C extends WorkflowHostCtor<any>>(host: ValidWorkflowHost<C>): WorkflowRef<C>;
14
+ /**
15
+ * Gets the HostAccessor from a callable reference.
16
+ */
17
+ export declare function getRefAccessor(ref: AnyCallableRef): {
18
+ readonly ctor: AnyHostCtor;
19
+ get metadata(): import("..").HostOpts;
20
+ get sdkOpts(): import("../metadata/translator").SdkHostOpts;
21
+ get name(): string;
22
+ get isWorkflow(): boolean;
23
+ get isTask(): boolean;
24
+ get methods(): string[];
25
+ getWorkflowTaskMeta(method: string): import("..").WorkflowTaskOpts<any>;
26
+ getTaskMeta(method: string): import("..").TaskOpts;
27
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.taskRef = taskRef;
4
+ exports.workflowRef = workflowRef;
5
+ exports.getRefAccessor = getRefAccessor;
6
+ const accessor_1 = require("../metadata/accessor");
7
+ /**
8
+ * Creates a reference to a task within a {@link TaskHost}.
9
+ * The task method is automatically resolved since a TaskHost has exactly one task.
10
+ * Compile-time validation ensures the host has exactly one task method.
11
+ */
12
+ function taskRef(host) {
13
+ const accessor = (0, accessor_1.fromCtor)(host);
14
+ return {
15
+ host,
16
+ method: accessor.methods[0],
17
+ };
18
+ }
19
+ /**
20
+ * Creates a reference to a workflow as a {@link WorkflowHost}.
21
+ * Compile-time validation ensures the host has at least one workflow task method.
22
+ */
23
+ function workflowRef(host) {
24
+ return { host };
25
+ }
26
+ /**
27
+ * Gets the HostAccessor from a callable reference.
28
+ */
29
+ function getRefAccessor(ref) {
30
+ return (0, accessor_1.fromCtor)(ref.host);
31
+ }
@@ -0,0 +1,3 @@
1
+ export type { TaskRef, WorkflowRef, AnyCallableRef, InputOfRef, OutputOfRef, } from "./refs";
2
+ export { taskRef, workflowRef } from "./helpers";
3
+ export type { TaskInput, TaskOutput, WorkflowInput, WorkflowOutput, WorkflowTasksOutputMap, } from "./shared";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.workflowRef = exports.taskRef = void 0;
4
+ // *Ref functions
5
+ var helpers_1 = require("./helpers");
6
+ Object.defineProperty(exports, "taskRef", { enumerable: true, get: function () { return helpers_1.taskRef; } });
7
+ Object.defineProperty(exports, "workflowRef", { enumerable: true, get: function () { return helpers_1.workflowRef; } });
@@ -0,0 +1,27 @@
1
+ import type { ContextMethodKeys, TaskHostCtor, TaskInput, TaskOutput, WorkflowHostCtor, WorkflowInput, WorkflowOutput } from "./shared";
2
+ /**
3
+ * Reference to a task within a {@link TaskHost}
4
+ */
5
+ export interface TaskRef<C extends TaskHostCtor<any>> {
6
+ readonly host: C;
7
+ readonly method: ContextMethodKeys<InstanceType<C>>;
8
+ }
9
+ /**
10
+ * Reference to a workflow as a {@link WorkflowHost}
11
+ */
12
+ export interface WorkflowRef<C extends WorkflowHostCtor<any>> {
13
+ readonly host: C;
14
+ }
15
+ /**
16
+ * Represents any callable reference.
17
+ * Note that externally only TaskRef and WorkflowRef are supported.
18
+ */
19
+ export type AnyCallableRef = TaskRef<any> | WorkflowRef<any>;
20
+ /**
21
+ * Extracts the input type of the callable reference.
22
+ */
23
+ export type InputOfRef<R extends AnyCallableRef> = R extends TaskRef<infer C> ? TaskInput<C> : R extends WorkflowRef<infer C> ? WorkflowInput<C> : never;
24
+ /**
25
+ * Extracts the output type of the callable reference.
26
+ */
27
+ export type OutputOfRef<R extends AnyCallableRef> = R extends TaskRef<infer C> ? TaskOutput<C> : R extends WorkflowRef<infer C> ? WorkflowOutput<C> : never;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,172 @@
1
+ import type { TaskHost, WorkflowHost } from "../abstracts";
2
+ import type { BaseCtx, TaskMarker } from "../execution/context/types";
3
+ /**
4
+ * Converts a union to an intersection. Used for detecting if a type is a union.
5
+ */
6
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
7
+ /**
8
+ * Checks if a type is a union (more than one member).
9
+ */
10
+ type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
11
+ /**
12
+ * Represents any host instance type.
13
+ */
14
+ export type AnyHost = WorkflowHost<any> | TaskHost<any>;
15
+ /**
16
+ * Represents any host constructor type.
17
+ */
18
+ export type AnyHostCtor = WorkflowHostCtor<any> | TaskHostCtor<any>;
19
+ /**
20
+ * Represents a workflow host constructor type.
21
+ *
22
+ * @internal Used in public signatures but not intended for direct external use.
23
+ * @template I - The input type that the workflow accepts.
24
+ */
25
+ export type WorkflowHostCtor<I> = abstract new (...args: any[]) => WorkflowHost<I>;
26
+ /**
27
+ * Represents a task host constructor type.
28
+ *
29
+ * @internal Used in public signatures but not intended for direct external use.
30
+ * @template I - The input type that the task accepts.
31
+ */
32
+ export type TaskHostCtor<I> = abstract new (...args: any[]) => TaskHost<I>;
33
+ /**
34
+ * Checks if a function signature is a "runnable" task method.
35
+ *
36
+ * A method is considered runnable if its first parameter is a context type
37
+ * that includes the TaskMarker brand. This distinguishes actual task methods
38
+ * (decorated with `@Task()` or `@WorkflowTask()`) from helper methods that
39
+ * use `HelperCtx` which lacks the marker.
40
+ *
41
+ * @template F - The function type to check.
42
+ * @template C - The expected context type (defaults to any BaseCtx).
43
+ * @returns `true` if F is a task method, `false` otherwise.
44
+ */
45
+ export type IsTaskRunnableSignature<F extends (...args: any[]) => any, C extends BaseCtx<any> = any> = F extends (...args: any[]) => any ? Parameters<F> extends [infer CI, ...any[]] ? CI extends {
46
+ [K in TaskMarker]: true;
47
+ } ? CI extends C ? true : false : false : false : false;
48
+ /**
49
+ * Extracts method keys from a host that are "runnable" task methods.
50
+ *
51
+ * Uses {@link IsTaskRunnableSignature} to filter only methods whose first
52
+ * parameter has the TaskMarker brand (i.e., uses `TaskCtx` or `WorkflowCtx`).
53
+ *
54
+ * For a TaskHost, this should return exactly one key.
55
+ * For a WorkflowHost, this returns all workflow task method keys.
56
+ *
57
+ * @internal Used by WorkflowTaskOpts but not intended for direct external use.
58
+ * @template T - The host instance type.
59
+ * @template C - Optional context type constraint.
60
+ */
61
+ export type ContextMethodKeys<T extends AnyHost, C extends BaseCtx<any> = any> = {
62
+ [K in keyof T]: T[K] extends (...args: any) => any ? IsTaskRunnableSignature<T[K], C> extends true ? K : never : never;
63
+ }[keyof T];
64
+ /**
65
+ * Extracts the output (return) type of a specific task method.
66
+ *
67
+ * @template T - The host constructor type.
68
+ * @template M - The method key (must be a valid task method key).
69
+ * @returns The awaited return type of the method.
70
+ */
71
+ export type AnyTaskOutput<T extends AnyHostCtor, M extends ContextMethodKeys<InstanceType<T>>> = InstanceType<T>[M] extends (...args: any) => any ? Awaited<ReturnType<InstanceType<T>[M]>> : never;
72
+ /**
73
+ * Represents any task function signature.
74
+ *
75
+ * A task function takes a context as its first parameter and returns
76
+ * a value (sync or async).
77
+ *
78
+ * @template C - The context type.
79
+ * @template O - The output type.
80
+ */
81
+ export type AnyTaskFn<C extends BaseCtx<any>, O> = (ctx: C) => Promise<O> | O;
82
+ /**
83
+ * Extracts the output type from a task function, but only if it's a valid
84
+ * task method (has TaskMarker in its context parameter).
85
+ *
86
+ * Returns `never` for helper methods that use `HelperCtx`.
87
+ * This is used by the `parent()` method in workflows to get type-safe
88
+ * access to parent task outputs.
89
+ *
90
+ * @template T - The task function type.
91
+ */
92
+ export type OutputOfTaskFn<T extends AnyTaskFn<any, any>> = IsTaskRunnableSignature<T> extends true ? Awaited<ReturnType<T>> : never;
93
+ /**
94
+ * Extracts the single task method key from a TaskHost.
95
+ * Since a TaskHost must have exactly one task method, this resolves to that method's key.
96
+ *
97
+ * @template T - The task host constructor type.
98
+ */
99
+ export type TaskMethodKey<T extends TaskHostCtor<any>> = ContextMethodKeys<InstanceType<T>, BaseCtx<any>>;
100
+ /**
101
+ * Extracts the input type from a TaskHost.
102
+ *
103
+ * @template T - The task host constructor type.
104
+ */
105
+ export type TaskInput<T extends TaskHostCtor<any>> = InstanceType<T> extends TaskHost<infer I> ? I : never;
106
+ /**
107
+ * Extracts the output type from the single task method of a TaskHost.
108
+ *
109
+ * @template T - The task host constructor type.
110
+ */
111
+ export type TaskOutput<T extends TaskHostCtor<any>> = AnyTaskOutput<T, TaskMethodKey<T>>;
112
+ /**
113
+ * Extracts the input type from a WorkflowHost constructor.
114
+ *
115
+ * @template T - The workflow host constructor type.
116
+ */
117
+ export type WorkflowInput<T extends WorkflowHostCtor<any>> = InstanceType<T> extends WorkflowHost<infer I> ? I : never;
118
+ /**
119
+ * Maps each workflow task method to its output type.
120
+ *
121
+ * @template C - The workflow host instance type.
122
+ * @example
123
+ * ```ts
124
+ * // For a workflow with step1() returning { a: string } and step2() returning { b: number }
125
+ * type Output = WorkflowTasksOutputMap<MyWorkflow>;
126
+ * // Result: { step1: { a: string }; step2: { b: number } }
127
+ * ```
128
+ */
129
+ export type WorkflowTasksOutputMap<C extends WorkflowHost<any>> = {
130
+ [K in ContextMethodKeys<C>]: C[K] extends (...a: any[]) => infer R ? Awaited<R> : never;
131
+ };
132
+ /**
133
+ * Extracts the complete output type of a workflow (map of all task outputs).
134
+ *
135
+ * @template T - The workflow host constructor type.
136
+ */
137
+ export type WorkflowOutput<T extends WorkflowHostCtor<any>> = WorkflowTasksOutputMap<InstanceType<T>>;
138
+ /**
139
+ * Error type for invalid TaskHost - shows as a readable string literal in error messages.
140
+ *
141
+ * @internal Type-level error message, not intended for direct external use.
142
+ * @template Reason - The error message to display.
143
+ */
144
+ export type InvalidTaskHost<Reason extends string> = `Error: ${Reason}`;
145
+ /**
146
+ * Error type for invalid WorkflowHost - shows as a readable string literal in error messages.
147
+ *
148
+ * @internal Type-level error message, not intended for direct external use.
149
+ * @template Reason - The error message to display.
150
+ */
151
+ export type InvalidWorkflowHost<Reason extends string> = `Error: ${Reason}`;
152
+ /**
153
+ * Validates that a TaskHost has exactly one task method.
154
+ * Returns the host type if valid, or an error type with a descriptive message.
155
+ *
156
+ * Used by {@link taskRef} to provide compile-time validation.
157
+ *
158
+ * @internal Used in taskRef() signature but not intended for direct external use.
159
+ * @template C - The task host constructor type to validate.
160
+ */
161
+ export type ValidTaskHost<C extends TaskHostCtor<any>> = ContextMethodKeys<InstanceType<C>, BaseCtx<any>> extends infer K ? [K] extends [never] ? InvalidTaskHost<"TaskHost must have exactly one method with TaskCtx parameter"> : IsUnion<K> extends true ? InvalidTaskHost<"TaskHost has multiple task methods - only one is allowed"> : C : never;
162
+ /**
163
+ * Validates that a WorkflowHost has at least one workflow task method.
164
+ * Returns the host type if valid, or an error type with a descriptive message.
165
+ *
166
+ * Used by {@link workflowRef} to provide compile-time validation.
167
+ *
168
+ * @internal Used in workflowRef() signature but not intended for direct external use.
169
+ * @template C - The workflow host constructor type to validate.
170
+ */
171
+ export type ValidWorkflowHost<C extends WorkflowHostCtor<any>> = ContextMethodKeys<InstanceType<C>, BaseCtx<any>> extends infer K ? [K] extends [never] ? InvalidWorkflowHost<"WorkflowHost must have at least one method with WorkflowCtx parameter"> : C : never;
172
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -37,10 +37,8 @@ const loggerFactory = (loggingContext) => {
37
37
  exports.hatchetClientFactory = {
38
38
  provide: typescript_sdk_1.HatchetClient,
39
39
  inject: [hatchet_module_config_1.hatchetModuleConfigToken],
40
- useFactory: (opts) => {
41
- return new typescript_sdk_1.HatchetClient({
42
- ...opts.config,
43
- logger: loggerFactory,
44
- });
45
- },
40
+ useFactory: (opts) => new typescript_sdk_1.HatchetClient({
41
+ ...opts.config,
42
+ logger: loggerFactory,
43
+ }),
46
44
  };
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@abinnovision/nestjs-hatchet",
4
- "version": "0.2.2",
4
+ "version": "0.3.0",
5
5
  "keywords": [
6
6
  "nestjs",
7
7
  "hatchet"
8
8
  ],
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/abinnovision/nestjs-commons"
11
+ "url": "https://github.com/abinnovision/nestjs-commons.git",
12
+ "directory": "packages/hatchet"
12
13
  },
13
14
  "license": "Apache-2.0",
14
15
  "author": {
@@ -19,11 +20,14 @@
19
20
  "exports": {
20
21
  ".": {
21
22
  "types": "./dist/index.d.ts",
22
- "require": "./dist/index.js"
23
+ "require": "./dist/index.js",
24
+ "default": "./dist/index.js"
23
25
  }
24
26
  },
25
27
  "files": [
26
- "dist"
28
+ "dist",
29
+ "LICENSE",
30
+ "README.md"
27
31
  ],
28
32
  "scripts": {
29
33
  "build": "tsc --project tsconfig.build.json",