@abinnovision/nestjs-hatchet 0.4.0 → 0.5.0-beta.2

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 (45) hide show
  1. package/README.md +11 -1
  2. package/dist/sdk/types.d.ts +1 -1
  3. package/dist/sdk-export/index.cjs +9 -0
  4. package/dist/sdk-export/index.d.ts +7 -0
  5. package/dist/sdk-export/index.mjs +2 -0
  6. package/package.json +14 -4
  7. package/dist/__fixtures__/test-hosts.d.cts +0 -76
  8. package/dist/__fixtures__/test-hosts.d.ts +0 -76
  9. package/dist/abstracts/hosts.d.cts +0 -66
  10. package/dist/abstracts/index.d.cts +0 -1
  11. package/dist/client/client.d.cts +0 -48
  12. package/dist/client/index.d.cts +0 -1
  13. package/dist/events/event-definition.d.cts +0 -71
  14. package/dist/events/index.d.cts +0 -2
  15. package/dist/execution/context/factory.d.cts +0 -22
  16. package/dist/execution/context/index.d.cts +0 -4
  17. package/dist/execution/context/types.d.cts +0 -108
  18. package/dist/execution/host-run/adapter-factory.d.cts +0 -12
  19. package/dist/execution/host-run/function-type.d.cts +0 -24
  20. package/dist/execution/host-run/index.d.cts +0 -2
  21. package/dist/execution/index.d.cts +0 -2
  22. package/dist/explorer/declaration-builder.service.d.cts +0 -70
  23. package/dist/explorer/index.d.cts +0 -1
  24. package/dist/explorer/worker-management.service.d.cts +0 -34
  25. package/dist/hatchet.module-config.d.cts +0 -31
  26. package/dist/hatchet.module.d.cts +0 -23
  27. package/dist/index.d.cts +0 -9
  28. package/dist/interceptor/index.d.cts +0 -1
  29. package/dist/interceptor/interceptor.d.cts +0 -13
  30. package/dist/internal/registrations.d.cts +0 -19
  31. package/dist/metadata/accessor.d.cts +0 -33
  32. package/dist/metadata/decorators/host.decorator.d.cts +0 -19
  33. package/dist/metadata/decorators/index.d.cts +0 -6
  34. package/dist/metadata/decorators/task.decorator.d.cts +0 -6
  35. package/dist/metadata/decorators/workflow-task.decorator.d.cts +0 -10
  36. package/dist/metadata/index.d.cts +0 -6
  37. package/dist/metadata/keys.d.cts +0 -3
  38. package/dist/metadata/translator.d.cts +0 -10
  39. package/dist/references/helpers.d.cts +0 -27
  40. package/dist/references/index.d.cts +0 -3
  41. package/dist/references/refs.d.cts +0 -27
  42. package/dist/references/shared.d.cts +0 -172
  43. package/dist/sdk/hatchet-client.factory.d.cts +0 -5
  44. package/dist/sdk/index.d.cts +0 -1
  45. package/dist/sdk/types.d.cts +0 -7
package/README.md CHANGED
@@ -7,7 +7,17 @@ handling for building robust workflows.
7
7
  ## Installation
8
8
 
9
9
  ```bash
10
- yarn add @abinnovision/nestjs-hatchet @hatchet-dev/typescript-sdk
10
+ yarn add @abinnovision/nestjs-hatchet
11
+ ```
12
+
13
+ ### Hatchet SDK Re-export
14
+
15
+ This package includes a patched version of `@hatchet-dev/typescript-sdk` that properly
16
+ exports the `v1` subdirectory. You can import SDK types and classes directly without
17
+ adding the Hatchet SDK as a separate dependency:
18
+
19
+ ```typescript
20
+ import { HatchetClient, Context } from "@abinnovision/nestjs-hatchet/sdk";
11
21
  ```
12
22
 
13
23
  ## Quick Start
@@ -3,5 +3,5 @@
3
3
  * Used internally to avoid deep subpath imports from the SDK.
4
4
  */
5
5
  export interface WorkflowRunRef<T> {
6
- get output(): Promise<T>;
6
+ readonly output: Promise<T>;
7
7
  }
@@ -0,0 +1,9 @@
1
+ var _hatchet_dev_typescript_sdk = require("@hatchet-dev/typescript-sdk");
2
+ Object.keys(_hatchet_dev_typescript_sdk).forEach(function(k) {
3
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
4
+ enumerable: true,
5
+ get: function() {
6
+ return _hatchet_dev_typescript_sdk[k];
7
+ }
8
+ });
9
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Re-exports the @hatchet-dev/typescript-sdk entrypoint.
3
+ *
4
+ * This allows consumers to import SDK types and classes from @abinnovision/nestjs-hatchet/sdk
5
+ * without depending on the Hatchet SDK directly.
6
+ */
7
+ export * from "@hatchet-dev/typescript-sdk";
@@ -0,0 +1,2 @@
1
+ export * from "@hatchet-dev/typescript-sdk";
2
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@abinnovision/nestjs-hatchet",
4
- "version": "0.4.0",
4
+ "version": "0.5.0-beta.2",
5
5
  "keywords": [
6
6
  "nestjs",
7
7
  "hatchet"
@@ -25,9 +25,19 @@
25
25
  "default": "./dist/index.mjs"
26
26
  },
27
27
  "require": {
28
- "types": "./dist/index.d.cts",
28
+ "types": "./dist/index.d.ts",
29
29
  "default": "./dist/index.cjs"
30
30
  }
31
+ },
32
+ "./sdk": {
33
+ "import": {
34
+ "types": "./dist/sdk-export/index.d.ts",
35
+ "default": "./dist/sdk-export/index.mjs"
36
+ },
37
+ "require": {
38
+ "types": "./dist/sdk-export/index.d.ts",
39
+ "default": "./dist/sdk-export/index.cjs"
40
+ }
31
41
  }
32
42
  },
33
43
  "main": "./dist/index.cjs",
@@ -38,7 +48,7 @@
38
48
  "README.md"
39
49
  ],
40
50
  "scripts": {
41
- "build": "tsdown && tsc --project tsconfig.build.json --emitDeclarationOnly && find dist -name '*.d.ts' -exec sh -c 'cp \"$1\" \"${1%.d.ts}.d.cts\"' _ {} \\; && publint",
51
+ "build": "tsdown && tsc --project tsconfig.build.json --emitDeclarationOnly && publint",
42
52
  "format:check": "prettier --check '{{src,test}/**/*,*}.{js,jsx,ts,tsx,json,json5,yml,yaml,md}'",
43
53
  "format:fix": "prettier --write '{{src,test}/**/*,*}.{js,jsx,ts,tsx,json,json5,yml,yaml,md}'",
44
54
  "lint:check": "eslint '{{src,test}/**/*,*}.{js,jsx,ts,tsx}'",
@@ -57,7 +67,7 @@
57
67
  },
58
68
  "prettier": "@abinnovision/prettier-config",
59
69
  "dependencies": {
60
- "@hatchet-dev/typescript-sdk": "^1.10.0",
70
+ "@hatchet-dev/typescript-sdk": "^1.17.2",
61
71
  "@standard-schema/spec": "^1.0.0",
62
72
  "directed-graph-typed": "^2.1.0"
63
73
  },
@@ -1,76 +0,0 @@
1
- import type { TaskCtx, WorkflowCtx } from "../execution/index.js";
2
- declare const TestTask_base: {
3
- new (): {
4
- readonly __task_host_brand: void;
5
- readonly __task_host_input: {
6
- data: string;
7
- };
8
- readonly inputSchema: () => import("@standard-schema/spec").StandardSchemaV1<import("@hatchet-dev/typescript-sdk/index.js").JsonObject, {
9
- data: string;
10
- }> | undefined;
11
- };
12
- };
13
- /** Standard TaskHost with string data schema */
14
- export declare class TestTask extends TestTask_base {
15
- execute(ctx: TaskCtx<typeof this>): {
16
- result: string;
17
- };
18
- }
19
- declare const NoMethodsTask_base: {
20
- new (): {
21
- readonly __task_host_brand: void;
22
- readonly __task_host_input: unknown;
23
- readonly inputSchema: () => import("@standard-schema/spec").StandardSchemaV1<import("@hatchet-dev/typescript-sdk/index.js").JsonObject, unknown> | undefined;
24
- };
25
- };
26
- /** TaskHost without any decorated methods (invalid) */
27
- export declare class NoMethodsTask extends NoMethodsTask_base {
28
- notDecorated(): {};
29
- }
30
- declare const NoSchemaTask_base: {
31
- new (): {
32
- readonly __task_host_brand: void;
33
- readonly __task_host_input: unknown;
34
- readonly inputSchema: () => import("@standard-schema/spec").StandardSchemaV1<import("@hatchet-dev/typescript-sdk/index.js").JsonObject, unknown> | undefined;
35
- };
36
- };
37
- /** TaskHost without input schema */
38
- export declare class NoSchemaTask extends NoSchemaTask_base {
39
- execute(_ctx: TaskCtx<typeof this>): {
40
- result: string;
41
- };
42
- }
43
- declare const TestWorkflow_base: {
44
- new (): {
45
- readonly __workflow_host_brand: void;
46
- readonly __workflow_host_input: {
47
- id: string;
48
- };
49
- readonly inputSchema: () => import("@standard-schema/spec").StandardSchemaV1<import("@hatchet-dev/typescript-sdk/index.js").JsonObject, {
50
- id: string;
51
- }> | undefined;
52
- };
53
- };
54
- /** Standard WorkflowHost with two-step DAG */
55
- export declare class TestWorkflow extends TestWorkflow_base {
56
- step1(_ctx: WorkflowCtx<typeof this>): {
57
- step: number;
58
- };
59
- step2(_ctx: WorkflowCtx<typeof this>): {
60
- step: number;
61
- };
62
- }
63
- declare const NoMethodsWorkflow_base: {
64
- new (): {
65
- readonly __workflow_host_brand: void;
66
- readonly __workflow_host_input: unknown;
67
- readonly inputSchema: () => import("@standard-schema/spec").StandardSchemaV1<import("@hatchet-dev/typescript-sdk/index.js").JsonObject, unknown> | undefined;
68
- };
69
- };
70
- /** WorkflowHost without any decorated methods (invalid) */
71
- export declare class NoMethodsWorkflow extends NoMethodsWorkflow_base {
72
- notDecorated(): {};
73
- }
74
- /** Sets design:paramtypes metadata for a method (needed in vitest) */
75
- export declare function setParamTypes(target: object, method: string, types: unknown[]): void;
76
- export {};
@@ -1,76 +0,0 @@
1
- import type { TaskCtx, WorkflowCtx } from "../execution/index.js";
2
- declare const TestTask_base: {
3
- new (): {
4
- readonly __task_host_brand: void;
5
- readonly __task_host_input: {
6
- data: string;
7
- };
8
- readonly inputSchema: () => import("@standard-schema/spec").StandardSchemaV1<import("@hatchet-dev/typescript-sdk/index.js").JsonObject, {
9
- data: string;
10
- }> | undefined;
11
- };
12
- };
13
- /** Standard TaskHost with string data schema */
14
- export declare class TestTask extends TestTask_base {
15
- execute(ctx: TaskCtx<typeof this>): {
16
- result: string;
17
- };
18
- }
19
- declare const NoMethodsTask_base: {
20
- new (): {
21
- readonly __task_host_brand: void;
22
- readonly __task_host_input: unknown;
23
- readonly inputSchema: () => import("@standard-schema/spec").StandardSchemaV1<import("@hatchet-dev/typescript-sdk/index.js").JsonObject, unknown> | undefined;
24
- };
25
- };
26
- /** TaskHost without any decorated methods (invalid) */
27
- export declare class NoMethodsTask extends NoMethodsTask_base {
28
- notDecorated(): {};
29
- }
30
- declare const NoSchemaTask_base: {
31
- new (): {
32
- readonly __task_host_brand: void;
33
- readonly __task_host_input: unknown;
34
- readonly inputSchema: () => import("@standard-schema/spec").StandardSchemaV1<import("@hatchet-dev/typescript-sdk/index.js").JsonObject, unknown> | undefined;
35
- };
36
- };
37
- /** TaskHost without input schema */
38
- export declare class NoSchemaTask extends NoSchemaTask_base {
39
- execute(_ctx: TaskCtx<typeof this>): {
40
- result: string;
41
- };
42
- }
43
- declare const TestWorkflow_base: {
44
- new (): {
45
- readonly __workflow_host_brand: void;
46
- readonly __workflow_host_input: {
47
- id: string;
48
- };
49
- readonly inputSchema: () => import("@standard-schema/spec").StandardSchemaV1<import("@hatchet-dev/typescript-sdk/index.js").JsonObject, {
50
- id: string;
51
- }> | undefined;
52
- };
53
- };
54
- /** Standard WorkflowHost with two-step DAG */
55
- export declare class TestWorkflow extends TestWorkflow_base {
56
- step1(_ctx: WorkflowCtx<typeof this>): {
57
- step: number;
58
- };
59
- step2(_ctx: WorkflowCtx<typeof this>): {
60
- step: number;
61
- };
62
- }
63
- declare const NoMethodsWorkflow_base: {
64
- new (): {
65
- readonly __workflow_host_brand: void;
66
- readonly __workflow_host_input: unknown;
67
- readonly inputSchema: () => import("@standard-schema/spec").StandardSchemaV1<import("@hatchet-dev/typescript-sdk/index.js").JsonObject, unknown> | undefined;
68
- };
69
- };
70
- /** WorkflowHost without any decorated methods (invalid) */
71
- export declare class NoMethodsWorkflow extends NoMethodsWorkflow_base {
72
- notDecorated(): {};
73
- }
74
- /** Sets design:paramtypes metadata for a method (needed in vitest) */
75
- export declare function setParamTypes(target: object, method: string, types: unknown[]): void;
76
- export {};
@@ -1,66 +0,0 @@
1
- import type { InputType } from "@hatchet-dev/typescript-sdk";
2
- import type { StandardSchemaV1 } from "@standard-schema/spec";
3
- /**
4
- * Interface for classes that provide a schema for their input.
5
- */
6
- export interface InputSchemaProvider<T> {
7
- /**
8
- * Returns the schema for the input of the host.
9
- * If undefined, the input is not validated.
10
- */
11
- inputSchema: () => StandardSchemaV1<InputType, T> | undefined;
12
- }
13
- /**
14
- * Marker class for Hatchet workflow host classes.
15
- */
16
- export declare abstract class WorkflowHost<I> implements InputSchemaProvider<I> {
17
- readonly inputSchema: InputSchemaProvider<I>["inputSchema"];
18
- readonly __workflow_host_brand: void;
19
- readonly __workflow_host_input: I;
20
- /**
21
- * Constructor for the WorkflowHost class.
22
- *
23
- * @param inputSchema
24
- * @protected
25
- */
26
- protected constructor(inputSchema: InputSchemaProvider<I>["inputSchema"]);
27
- }
28
- /**
29
- * Marker class for Hatchet task host classes.
30
- */
31
- export declare abstract class TaskHost<I> implements InputSchemaProvider<I> {
32
- readonly inputSchema: InputSchemaProvider<I>["inputSchema"];
33
- readonly __task_host_brand: void;
34
- readonly __task_host_input: I;
35
- /**
36
- * Constructor for the TaskHost class.
37
- *
38
- * @param inputSchema
39
- * @protected
40
- */
41
- protected constructor(inputSchema: InputSchemaProvider<I>["inputSchema"]);
42
- }
43
- /**
44
- * Creates a new WorkflowHost class with the provided input schema.
45
- *
46
- * @param input The input schema.
47
- */
48
- export declare function workflowHost<I>(input?: ReturnType<InputSchemaProvider<I>["inputSchema"]>): {
49
- new (): {
50
- readonly __workflow_host_brand: void;
51
- readonly __workflow_host_input: I;
52
- readonly inputSchema: () => StandardSchemaV1<import("@hatchet-dev/typescript-sdk").JsonObject, I> | undefined;
53
- };
54
- };
55
- /**
56
- * Creates a new TaskHost class with the provided input schema.
57
- *
58
- * @param input The input schema.
59
- */
60
- export declare function taskHost<I>(input?: ReturnType<InputSchemaProvider<I>["inputSchema"]>): {
61
- new (): {
62
- readonly __task_host_brand: void;
63
- readonly __task_host_input: I;
64
- readonly inputSchema: () => StandardSchemaV1<import("@hatchet-dev/typescript-sdk").JsonObject, I> | undefined;
65
- };
66
- };
@@ -1 +0,0 @@
1
- export * from "./hosts.js";
@@ -1,48 +0,0 @@
1
- import { HatchetClient } from "@hatchet-dev/typescript-sdk";
2
- import type { AnyEventDefinition, EventInput } from "../events/index.js";
3
- import type { HostRunFn } from "../execution/index.js";
4
- type EventClient = HatchetClient["events"];
5
- type EventEmitOptions = Parameters<EventClient["push"]>[2];
6
- type Event = Awaited<ReturnType<EventClient["push"]>>;
7
- export declare class Client {
8
- private readonly client;
9
- readonly run: HostRunFn;
10
- constructor(client: HatchetClient);
11
- /**
12
- * Access to the underlying HatchetClient SDK.
13
- * Use for advanced features not wrapped by this library.
14
- */
15
- get sdk(): HatchetClient;
16
- /**
17
- * Emit a single event.
18
- *
19
- * @param event The event definition to emit.
20
- * @param input The event payload (must match the event's schema).
21
- * @param options Optional emit configuration.
22
- * @returns The emitted event.
23
- *
24
- * @example
25
- * ```typescript
26
- * await client.emit(UserCreatedEvent, { userId: "123", email: "user@example.com" });
27
- * ```
28
- */
29
- emit<E extends AnyEventDefinition>(event: E, input: EventInput<E>, options?: EventEmitOptions): Promise<Event>;
30
- /**
31
- * Emit multiple events of the same type.
32
- *
33
- * @param event The event definition to emit.
34
- * @param inputs Array of event payloads.
35
- * @param options Optional emit configuration.
36
- * @returns Array of emitted events.
37
- *
38
- * @example
39
- * ```typescript
40
- * await client.emitBulk(OrderPlacedEvent, [
41
- * { orderId: "1", userId: "123", total: 100 },
42
- * { orderId: "2", userId: "456", total: 200 },
43
- * ]);
44
- * ```
45
- */
46
- emitBulk<E extends AnyEventDefinition>(event: E, inputs: EventInput<E>[], options?: EventEmitOptions): Promise<Event[]>;
47
- }
48
- export {};
@@ -1 +0,0 @@
1
- export * from "./client.js";
@@ -1,71 +0,0 @@
1
- import type { StandardSchemaV1 } from "@standard-schema/spec";
2
- /**
3
- * Marker embedded in event payload to identify an event type.
4
- * Used by isCtx() type guard to determine which event triggered the workflow.
5
- */
6
- export declare const EVENT_MARKER = "__event_name";
7
- /**
8
- * Type-safe event definition.
9
- * Use with Client.emit() to publish events.
10
- *
11
- * @template TName The literal string type of the event name.
12
- * @template TSchema The StandardSchema type for input validation.
13
- */
14
- export declare class EventDefinition<TName extends string, TSchema extends StandardSchemaV1> {
15
- readonly name: TName;
16
- readonly schema: TSchema;
17
- /**
18
- * Phantom types for input/output inference.
19
- * Do not access at runtime - will throw.
20
- */
21
- readonly __types: {
22
- input: StandardSchemaV1.InferInput<TSchema>;
23
- output: StandardSchemaV1.InferOutput<TSchema>;
24
- };
25
- constructor(name: TName, schema: TSchema);
26
- /**
27
- * Type guard: checks if the context was triggered by this event.
28
- * Validates the input against the event schema and throws if malformed.
29
- *
30
- * @param ctx The context to check (TaskCtx, WorkflowCtx, HelperCtx, or SDK Context).
31
- * @returns True if the context input contains the event marker matching this event.
32
- * @throws Error if the event marker matches but the payload fails schema validation.
33
- */
34
- isCtx<C extends {
35
- input: unknown;
36
- }>(ctx: C): ctx is C & {
37
- input: StandardSchemaV1.InferOutput<TSchema> & {
38
- [EVENT_MARKER]: TName;
39
- };
40
- };
41
- }
42
- /**
43
- * Any event definition, used for generic constraints.
44
- */
45
- export type AnyEventDefinition = EventDefinition<string, StandardSchemaV1>;
46
- /**
47
- * Extracts the input type from an event definition.
48
- */
49
- export type EventInput<E extends AnyEventDefinition> = E["__types"]["input"];
50
- /**
51
- * Extracts the output type from an event definition.
52
- */
53
- export type EventOutput<E extends AnyEventDefinition> = E["__types"]["output"];
54
- /**
55
- * Factory function to create a type-safe event definition.
56
- *
57
- * @param name The event name (e.g., "user:created").
58
- * @param schema A StandardSchema-compatible schema (e.g., Zod schema).
59
- * @returns A new EventDefinition instance.
60
- *
61
- * @example
62
- * ```typescript
63
- * import { z } from "zod";
64
- *
65
- * const UserCreatedEvent = defineEvent("user:created", z.object({
66
- * userId: z.string(),
67
- * email: z.string().email(),
68
- * }));
69
- * ```
70
- */
71
- export declare const defineEvent: <TName extends string, TSchema extends StandardSchemaV1>(name: TName, schema: TSchema) => EventDefinition<TName, TSchema>;
@@ -1,2 +0,0 @@
1
- export { EventDefinition, defineEvent } from "./event-definition.js";
2
- export type { AnyEventDefinition, EventInput, EventOutput, } from "./event-definition.js";
@@ -1,22 +0,0 @@
1
- import { type BaseCtx, type HostTriggerConfig, type TaskCtx, type WorkflowCtx } from "./types.js";
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 {};
@@ -1,4 +0,0 @@
1
- export type { BaseCtx, TaskCtx, WorkflowCtx, HelperCtx, TriggerSource, HostTriggerConfig, } from "./types.js";
2
- export { TASK_MARKER } from "./types.js";
3
- export type { TaskMarker } from "./types.js";
4
- export { createTaskCtx, createWorkflowCtx } from "./factory.js";
@@ -1,108 +0,0 @@
1
- import type { TaskHost, WorkflowHost } from "../../abstracts/index.js";
2
- import type { AnyEventDefinition, EventOutput } from "../../events/index.js";
3
- import type { AnyTaskFn, OutputOfTaskFn } from "../../references/shared.js";
4
- import type { HostRunFn } from "../host-run/index.js";
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>;
@@ -1,12 +0,0 @@
1
- import type { HostRunFn } from "./function-type.js";
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;
@@ -1,24 +0,0 @@
1
- import type { AnyCallableRef, InputOfRef, OutputOfRef } from "../../references/index.js";
2
- import type { WorkflowRunRef } from "../../sdk/types.js";
3
- import type { RunOpts } from "@hatchet-dev/typescript-sdk";
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>>;
@@ -1,2 +0,0 @@
1
- export type { HostRunFn, HostRunOpts, HostRunReturn } from "./function-type.js";
2
- export { createHostRunForContext, createHostRunForAdmin, } from "./adapter-factory.js";
@@ -1,2 +0,0 @@
1
- export type { BaseCtx, TaskCtx, WorkflowCtx, HelperCtx, TriggerSource, HostTriggerConfig, } from "./context/index.js";
2
- export type { HostRunFn, HostRunOpts, HostRunReturn, } from "./host-run/index.js";
@@ -1,70 +0,0 @@
1
- import { TaskWorkflowDeclaration, WorkflowDeclaration } from "@hatchet-dev/typescript-sdk";
2
- import { ModuleRef } from "@nestjs/core";
3
- import { InterceptorRegistration } from "../internal/registrations.js";
4
- import { AnyHost } from "../references/shared.js";
5
- export declare class DeclarationBuilderService {
6
- private readonly moduleRef;
7
- private readonly interceptorRegistration?;
8
- private readonly interceptors;
9
- constructor(moduleRef: ModuleRef, interceptorRegistration?: InterceptorRegistration | undefined);
10
- /**
11
- * Creates a WorkflowDeclaration or TaskWorkflowDeclaration from the given host.
12
- *
13
- * @param host The host to create a declaration for.
14
- * @returns A WorkflowDeclaration or TaskWorkflowDeclaration.
15
- */
16
- createDeclaration(host: AnyHost): WorkflowDeclaration | TaskWorkflowDeclaration;
17
- private createTaskWorkflow;
18
- private createWorkflow;
19
- /**
20
- * Validates the given WorkflowHost with basic sanity checks.
21
- * This does not return, rather it throws an error if the host is invalid.
22
- *
23
- * @param input The host to validate.
24
- * @private
25
- */
26
- private validateWorkflowHost;
27
- /**
28
- * Validates the given TaskHost with basic sanity checks.
29
- * This does not return, rather it throws an error if the host is invalid.
30
- *
31
- * @param input The host to validate.
32
- * @private
33
- */
34
- private validateTaskHost;
35
- /**
36
- * Builds a directed graph of the workflow host.
37
- * The nodes are the methods of the host, and the edges are the dependencies between the methods.
38
- *
39
- * Note: This validates for cyclic dependencies and throws an
40
- *
41
- * @param host The host to build the graph for.
42
- * @returns The directed graph.
43
- * @private
44
- */
45
- private buildWorkflowHostGraph;
46
- /**
47
- * Pre-processes the context by inferring the trigger source and
48
- * validating the input (if applicable).
49
- *
50
- * @returns The pre-processed context properties including hostConfig.
51
- */
52
- private preProcessContext;
53
- /**
54
- * Executes a function, optionally intercepted by the interceptors.
55
- * Interceptors are chained in array order (first = outermost).
56
- *
57
- * @param ctx The context.
58
- * @param fn The function to execute.
59
- * @returns The result of the function.
60
- */
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;
70
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,34 +0,0 @@
1
- import { HatchetClient } from "@hatchet-dev/typescript-sdk";
2
- import { OnApplicationBootstrap } from "@nestjs/common";
3
- import { ModuleRef } from "@nestjs/core";
4
- import { type HatchetModuleConfig } from "../hatchet.module-config.js";
5
- import { DeclarationBuilderService } from "./declaration-builder.service.js";
6
- export declare class WorkerManagementService implements OnApplicationBootstrap {
7
- private readonly client;
8
- private readonly declarationBuilder;
9
- private readonly config;
10
- private readonly moduleRef;
11
- private static LOGGER;
12
- constructor(client: HatchetClient, declarationBuilder: DeclarationBuilderService, config: HatchetModuleConfig, moduleRef: ModuleRef);
13
- onApplicationBootstrap(): Promise<void>;
14
- private initWorker;
15
- /**
16
- * Builds declarations from the discovered feature registrations.
17
- */
18
- private buildDeclarations;
19
- /**
20
- * Discovers all feature registrations from forFeature() calls.
21
- */
22
- private discoverFeatureRegistrations;
23
- /**
24
- * Detects workflows registered on the Hatchet server that have no
25
- * corresponding local declaration. Logs a warning for each orphan found.
26
- */
27
- private detectOrphanWorkflows;
28
- /**
29
- * Fetches all workflows registered on the Hatchet server using pagination.
30
- *
31
- * @returns An array of workflow names registered on the server.
32
- */
33
- private fetchAllServerWorkflows;
34
- }
@@ -1,31 +0,0 @@
1
- import type { CreateWorkerOpts, HatchetClient } from "@hatchet-dev/typescript-sdk";
2
- type ClientConfig = HatchetClient["config"];
3
- /**
4
- * Configuration for the Hatchet worker.
5
- */
6
- type HatchetModuleWorkerConfig = {
7
- name: string;
8
- } & Omit<CreateWorkerOpts, "workflows">;
9
- /**
10
- * Configuration for the HatchetModule.
11
- */
12
- export interface HatchetModuleConfig {
13
- /**
14
- * Configuration for the Hatchet client.
15
- * Certain, internally managed options are omitted.
16
- */
17
- config: Partial<Omit<ClientConfig, "logger" | "log_level">>;
18
- /**
19
- * Configuration for the Hatchet worker.
20
- * If undefined, the worker will not be started.
21
- */
22
- worker: HatchetModuleWorkerConfig | undefined;
23
- /**
24
- * Whether to enable orphan workflow detection on application startup.
25
- *
26
- * @default true
27
- */
28
- enableOrphanDetection?: boolean | undefined;
29
- }
30
- export declare const hatchetModuleConfigToken: unique symbol;
31
- export {};
@@ -1,23 +0,0 @@
1
- import { DynamicModule, Type } from "@nestjs/common";
2
- import { type HatchetModuleConfig } from "./hatchet.module-config.js";
3
- import { Interceptor } from "./interceptor/index.js";
4
- import type { AnyCallableRef } from "./references/index.js";
5
- /**
6
- * Extra options for the module (processed at module definition time).
7
- */
8
- interface HatchetModuleExtras {
9
- /**
10
- * Optional interceptor classes to intercept all task/workflow executions.
11
- * Interceptors execute in array order (first = outermost).
12
- */
13
- interceptors?: Type<Interceptor>[] | undefined;
14
- }
15
- declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<HatchetModuleConfig, "forRoot", "create", HatchetModuleExtras>;
16
- export declare class HatchetModule extends ConfigurableModuleClass {
17
- /**
18
- * Registers workflows and tasks for the global worker.
19
- * Call this in feature modules to register their hosts.
20
- */
21
- static forFeature(...refs: AnyCallableRef[]): DynamicModule;
22
- }
23
- export {};
package/dist/index.d.cts DELETED
@@ -1,9 +0,0 @@
1
- export * from "./hatchet.module.js";
2
- export * from "./abstracts/index.js";
3
- export * from "./client/index.js";
4
- export * from "./execution/index.js";
5
- export * from "./metadata/index.js";
6
- export * from "./events/index.js";
7
- export * from "./interceptor/index.js";
8
- export * from "./references/index.js";
9
- export type { HatchetModuleConfig } from "./hatchet.module-config.js";
@@ -1 +0,0 @@
1
- export { Interceptor } from "./interceptor.js";
@@ -1,13 +0,0 @@
1
- import type { BaseCtx } from "../execution/index.js";
2
- /**
3
- * Token for optional interceptors injection.
4
- * Register providers with this token to intercept task/workflow execution.
5
- */
6
- export declare const INTERCEPTORS: unique symbol;
7
- /**
8
- * Abstract class for intercepting task/workflow execution.
9
- * Implement this to add cross-cutting concerns like ALS, tracing, logging.
10
- */
11
- export declare abstract class Interceptor {
12
- abstract intercept<T>(ctx: BaseCtx<any>, next: () => Promise<T>): Promise<T>;
13
- }
@@ -1,19 +0,0 @@
1
- import type { Interceptor } from "../interceptor/index.js";
2
- import type { AnyHostCtor } from "../references/shared.js";
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
- }
@@ -1,33 +0,0 @@
1
- import type { HostOpts, TaskOpts, WorkflowTaskOpts } from "./decorators/index.js";
2
- import type { SdkHostOpts } from "./translator.js";
3
- import type { AnyHost, AnyHostCtor } from "../references/shared.js";
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 {};
@@ -1,19 +0,0 @@
1
- import type { AnyEventDefinition } from "../../events/index.js";
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 {};
@@ -1,6 +0,0 @@
1
- export { Host } from "./host.decorator.js";
2
- export type { HostOpts } from "./host.decorator.js";
3
- export { Task } from "./task.decorator.js";
4
- export type { TaskOpts } from "./task.decorator.js";
5
- export { WorkflowTask } from "./workflow-task.decorator.js";
6
- export type { WorkflowTaskOpts } from "./workflow-task.decorator.js";
@@ -1,6 +0,0 @@
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;
@@ -1,10 +0,0 @@
1
- import type { WorkflowCtx } from "../../execution/index.js";
2
- import type { ContextMethodKeys, WorkflowHostCtor } from "../../references/shared.js";
3
- import type { CreateWorkflowTaskOpts } from "@hatchet-dev/typescript-sdk";
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;
@@ -1,6 +0,0 @@
1
- export { Host } from "./decorators/host.decorator.js";
2
- export type { HostOpts } from "./decorators/host.decorator.js";
3
- export { Task } from "./decorators/task.decorator.js";
4
- export type { TaskOpts } from "./decorators/task.decorator.js";
5
- export { WorkflowTask } from "./decorators/workflow-task.decorator.js";
6
- export type { WorkflowTaskOpts } from "./decorators/workflow-task.decorator.js";
@@ -1,3 +0,0 @@
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";
@@ -1,10 +0,0 @@
1
- import type { HostOpts } from "./decorators/index.js";
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;
@@ -1,27 +0,0 @@
1
- import type { AnyCallableRef, TaskRef, WorkflowRef } from "./refs.js";
2
- import type { AnyHostCtor, TaskHostCtor, ValidTaskHost, ValidWorkflowHost, WorkflowHostCtor } from "./shared.js";
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("../index.js").HostOpts;
20
- get sdkOpts(): import("../metadata/translator.js").SdkHostOpts;
21
- get name(): string;
22
- get isWorkflow(): boolean;
23
- get isTask(): boolean;
24
- get methods(): string[];
25
- getWorkflowTaskMeta(method: string): import("../index.js").WorkflowTaskOpts<any>;
26
- getTaskMeta(method: string): import("../index.js").TaskOpts;
27
- };
@@ -1,3 +0,0 @@
1
- export type { TaskRef, WorkflowRef, AnyCallableRef, InputOfRef, OutputOfRef, } from "./refs.js";
2
- export { taskRef, workflowRef } from "./helpers.js";
3
- export type { TaskInput, TaskOutput, WorkflowInput, WorkflowOutput, WorkflowTasksOutputMap, } from "./shared.js";
@@ -1,27 +0,0 @@
1
- import type { ContextMethodKeys, TaskHostCtor, TaskInput, TaskOutput, WorkflowHostCtor, WorkflowInput, WorkflowOutput } from "./shared.js";
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;
@@ -1,172 +0,0 @@
1
- import type { TaskHost, WorkflowHost } from "../abstracts/index.js";
2
- import type { BaseCtx, TaskMarker } from "../execution/context/types.js";
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 {};
@@ -1,5 +0,0 @@
1
- import type { FactoryProvider } from "@nestjs/common";
2
- /**
3
- * Factory provider for the HatchetClient.
4
- */
5
- export declare const hatchetClientFactory: FactoryProvider;
@@ -1 +0,0 @@
1
- export * from "./hatchet-client.factory.js";
@@ -1,7 +0,0 @@
1
- /**
2
- * Minimal compatible interface for the Hatchet SDK's WorkflowRunRef.
3
- * Used internally to avoid deep subpath imports from the SDK.
4
- */
5
- export interface WorkflowRunRef<T> {
6
- get output(): Promise<T>;
7
- }