@abinnovision/nestjs-hatchet 0.1.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 (88) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +201 -0
  3. package/README.md +223 -0
  4. package/dist/__fixtures__/test-hosts.d.ts +76 -0
  5. package/dist/__fixtures__/test-hosts.js +100 -0
  6. package/dist/__mocks__/hatchet-client.mock.d.ts +5 -0
  7. package/dist/__mocks__/hatchet-client.mock.js +9 -0
  8. package/dist/__mocks__/sdk-context.mock.d.ts +5 -0
  9. package/dist/__mocks__/sdk-context.mock.js +14 -0
  10. package/dist/abstracts/hosts.d.ts +66 -0
  11. package/dist/abstracts/hosts.js +69 -0
  12. package/dist/abstracts/index.d.ts +1 -0
  13. package/dist/abstracts/index.js +17 -0
  14. package/dist/accessor/host-accessor.d.ts +25 -0
  15. package/dist/accessor/host-accessor.js +55 -0
  16. package/dist/accessor/index.d.ts +1 -0
  17. package/dist/accessor/index.js +6 -0
  18. package/dist/client/client.d.ts +51 -0
  19. package/dist/client/client.js +77 -0
  20. package/dist/client/client.service.d.ts +58 -0
  21. package/dist/client/client.service.js +76 -0
  22. package/dist/client/index.d.ts +1 -0
  23. package/dist/client/index.js +17 -0
  24. package/dist/context/context-factory.d.ts +16 -0
  25. package/dist/context/context-factory.js +43 -0
  26. package/dist/context/context.d.ts +51 -0
  27. package/dist/context/context.js +2 -0
  28. package/dist/context/index.d.ts +2 -0
  29. package/dist/context/index.js +18 -0
  30. package/dist/decorator-utils/accessors.d.ts +20 -0
  31. package/dist/decorator-utils/accessors.js +33 -0
  32. package/dist/decorator-utils/index.d.ts +1 -0
  33. package/dist/decorator-utils/index.js +17 -0
  34. package/dist/decorators/host.decorator.d.ts +6 -0
  35. package/dist/decorators/host.decorator.js +19 -0
  36. package/dist/decorators/index.d.ts +3 -0
  37. package/dist/decorators/index.js +19 -0
  38. package/dist/decorators/task.decorator.d.ts +6 -0
  39. package/dist/decorators/task.decorator.js +15 -0
  40. package/dist/decorators/workflow-task.decorators.d.ts +10 -0
  41. package/dist/decorators/workflow-task.decorators.js +14 -0
  42. package/dist/events/event-definition.d.ts +71 -0
  43. package/dist/events/event-definition.js +82 -0
  44. package/dist/events/index.d.ts +1 -0
  45. package/dist/events/index.js +17 -0
  46. package/dist/explorer/declaration-builder.service.d.ts +48 -0
  47. package/dist/explorer/declaration-builder.service.js +209 -0
  48. package/dist/explorer/exceptions/index.d.ts +1 -0
  49. package/dist/explorer/exceptions/index.js +2 -0
  50. package/dist/explorer/index.d.ts +1 -0
  51. package/dist/explorer/index.js +2 -0
  52. package/dist/explorer/utils.d.ts +19 -0
  53. package/dist/explorer/utils.js +44 -0
  54. package/dist/explorer/worker-management.service.d.ts +23 -0
  55. package/dist/explorer/worker-management.service.js +81 -0
  56. package/dist/hatchet.module-config.d.ts +21 -0
  57. package/dist/hatchet.module-config.js +4 -0
  58. package/dist/hatchet.module.d.ts +12 -0
  59. package/dist/hatchet.module.js +68 -0
  60. package/dist/index.d.ts +9 -0
  61. package/dist/index.js +24 -0
  62. package/dist/interaction/host-run/adapter-factory.d.ts +12 -0
  63. package/dist/interaction/host-run/adapter-factory.js +45 -0
  64. package/dist/interaction/host-run/function-type.d.ts +24 -0
  65. package/dist/interaction/host-run/function-type.js +2 -0
  66. package/dist/interaction/host-run/index.d.ts +2 -0
  67. package/dist/interaction/host-run/index.js +18 -0
  68. package/dist/interaction/index.d.ts +1 -0
  69. package/dist/interaction/index.js +17 -0
  70. package/dist/internal/index.d.ts +2 -0
  71. package/dist/internal/index.js +18 -0
  72. package/dist/internal/shared-consts.d.ts +12 -0
  73. package/dist/internal/shared-consts.js +17 -0
  74. package/dist/internal/shared-decorators.d.ts +1 -0
  75. package/dist/internal/shared-decorators.js +5 -0
  76. package/dist/ref/helpers.d.ts +31 -0
  77. package/dist/ref/helpers.js +56 -0
  78. package/dist/ref/index.d.ts +3 -0
  79. package/dist/ref/index.js +19 -0
  80. package/dist/ref/refs.d.ts +45 -0
  81. package/dist/ref/refs.js +2 -0
  82. package/dist/ref/shared.d.ts +91 -0
  83. package/dist/ref/shared.js +2 -0
  84. package/dist/sdk/hatchet-client.factory.d.ts +5 -0
  85. package/dist/sdk/hatchet-client.factory.js +46 -0
  86. package/dist/sdk/index.d.ts +1 -0
  87. package/dist/sdk/index.js +17 -0
  88. package/package.json +68 -0
@@ -0,0 +1,45 @@
1
+ import type { ContextMethodKeys, TaskHostCtor, WorkflowHostCtor } from "./shared";
2
+ /**
3
+ * Reference to a task within a {@link TaskHost}
4
+ */
5
+ export interface TaskRef<C extends TaskHostCtor<any>, I, O> {
6
+ readonly host: C;
7
+ readonly method: ContextMethodKeys<InstanceType<C>>;
8
+ readonly __types: {
9
+ input: I;
10
+ output: O;
11
+ };
12
+ }
13
+ /**
14
+ * Reference to a workflow as a {@link WorkflowHost}
15
+ */
16
+ export interface WorkflowRef<C extends WorkflowHostCtor<any>, I, O> {
17
+ readonly host: C;
18
+ readonly __types: {
19
+ input: I;
20
+ output: O;
21
+ };
22
+ }
23
+ /**
24
+ * Reference to a task within a {@link WorkflowHost}, without the knowledge of the {@link WorkflowHost} itself.
25
+ */
26
+ export interface WorkflowTaskRef<I, O> {
27
+ readonly method: string;
28
+ readonly __types: {
29
+ input: I;
30
+ output: O;
31
+ };
32
+ }
33
+ /**
34
+ * Represents any callable reference.
35
+ * Note that externally only TaskRef and WorkflowRef are supported.
36
+ */
37
+ export type AnyCallableRef = TaskRef<any, any, any> | WorkflowRef<any, any, any>;
38
+ /**
39
+ * Extracts the input type of the callable reference.
40
+ */
41
+ export type InputOfRef<R extends AnyCallableRef> = R extends TaskRef<any, infer I, any> ? I : R extends WorkflowRef<any, infer I, any> ? I : never;
42
+ /**
43
+ * Extracts the output type of the callable reference.
44
+ */
45
+ export type OutputOfRef<R extends AnyCallableRef> = R extends TaskRef<any, any, infer O> ? O : R extends WorkflowRef<any, any, infer O> ? O : never;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,91 @@
1
+ import type { TaskHost, WorkflowHost } from "../abstracts";
2
+ import type { BaseCtx, TaskMarker } from "../context/context";
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
+ export type WorkflowHostCtor<I> = abstract new (...args: any[]) => WorkflowHost<I>;
23
+ /**
24
+ * Represents a task host constructor type.
25
+ */
26
+ export type TaskHostCtor<I> = abstract new (...args: any[]) => TaskHost<I>;
27
+ 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 {
28
+ [K in TaskMarker]: true;
29
+ } ? CI extends C ? true : false : false : false : false;
30
+ /**
31
+ * Extracts the keys of any host that matches the "task"-runnable signature.
32
+ */
33
+ export type ContextMethodKeys<T extends AnyHost, C extends BaseCtx<any> = any> = {
34
+ [K in keyof T]: T[K] extends (...args: any) => any ? IsTaskRunnableSignature<T[K], C> extends true ? K : never : never;
35
+ }[keyof T];
36
+ /**
37
+ * Extracts the input type of a method of a class which takes a context as the first argument.
38
+ */
39
+ export type AnyTaskInput<T extends AnyHostCtor, M extends ContextMethodKeys<InstanceType<T>>> = InstanceType<T>[M] extends (...args: any) => any ? Parameters<InstanceType<T>[M]> extends [BaseCtx<infer I>, ...any[]] ? I : never : never;
40
+ /**
41
+ * Extracts the output type of a method of a class which takes a context as the first argument.
42
+ */
43
+ export type AnyTaskOutput<T extends AnyHostCtor, M extends ContextMethodKeys<InstanceType<T>>> = InstanceType<T>[M] extends (...args: any) => any ? Awaited<ReturnType<InstanceType<T>[M]>> : never;
44
+ /**
45
+ * Extracts the input type of a workflow host.
46
+ */
47
+ export type WorkflowInput<T extends WorkflowHostCtor<any>> = InstanceType<T> extends WorkflowHost<infer I> ? I : never;
48
+ /**
49
+ * Extracts the output types of all the methods of a workflow host.
50
+ */
51
+ export type WorkflowTasksOutputMap<C extends WorkflowHost<any>> = {
52
+ [K in ContextMethodKeys<C>]: C[K] extends (...a: any[]) => infer R ? Awaited<R> : never;
53
+ };
54
+ /**
55
+ * Extracts the output type of a workflow host.
56
+ */
57
+ export type WorkflowOutput<T extends WorkflowHostCtor<any>> = WorkflowTasksOutputMap<InstanceType<T>>;
58
+ export type AnyTaskFn<C extends BaseCtx<any>, O> = (ctx: C) => Promise<O> | O;
59
+ export type OutputOfTaskFn<T extends AnyTaskFn<any, any>> = IsTaskRunnableSignature<T> extends true ? Awaited<ReturnType<T>> : never;
60
+ /**
61
+ * Error type for invalid TaskHost - shows as a readable string literal in error messages.
62
+ */
63
+ export type InvalidTaskHost<Reason extends string> = `Error: ${Reason}`;
64
+ /**
65
+ * Error type for invalid WorkflowHost - shows as a readable string literal in error messages.
66
+ */
67
+ export type InvalidWorkflowHost<Reason extends string> = `Error: ${Reason}`;
68
+ /**
69
+ * Validates that a TaskHost has exactly one task method.
70
+ * Returns the host type if valid, or an error type with a descriptive message.
71
+ */
72
+ 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;
73
+ /**
74
+ * Validates that a WorkflowHost has at least one workflow task method.
75
+ * Returns the host type if valid, or an error type with a descriptive message.
76
+ */
77
+ 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;
78
+ /**
79
+ * Extracts the single task method key from a TaskHost.
80
+ * Since a TaskHost must have exactly one task method, this resolves to that method's key.
81
+ */
82
+ export type TaskMethodKey<T extends TaskHostCtor<any>> = ContextMethodKeys<InstanceType<T>, BaseCtx<any>>;
83
+ /**
84
+ * Extracts the input type from the single task method of a TaskHost.
85
+ */
86
+ export type TaskInput<T extends TaskHostCtor<any>> = AnyTaskInput<T, TaskMethodKey<T>>;
87
+ /**
88
+ * Extracts the output type from the single task method of a TaskHost.
89
+ */
90
+ export type TaskOutput<T extends TaskHostCtor<any>> = AnyTaskOutput<T, TaskMethodKey<T>>;
91
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import type { FactoryProvider } from "@nestjs/common";
2
+ /**
3
+ * Factory provider for the HatchetClient.
4
+ */
5
+ export declare const hatchetClientFactory: FactoryProvider;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hatchetClientFactory = void 0;
4
+ const typescript_sdk_1 = require("@hatchet-dev/typescript-sdk");
5
+ const common_1 = require("@nestjs/common");
6
+ const hatchet_module_config_1 = require("../hatchet.module-config");
7
+ /**
8
+ * Creates a logger that matches the Hatchet logger interface based on the given context.
9
+ *
10
+ * @param loggingContext The context to log under.
11
+ */
12
+ const loggerFactory = (loggingContext) => {
13
+ // Create a child logger for each context.
14
+ const logger = new common_1.Logger(`HatchetClient/${loggingContext}`);
15
+ /// Create a logger that matches the Hatchet logger interface.
16
+ return {
17
+ debug: (message, extra) => {
18
+ logger.debug(message, extra);
19
+ },
20
+ info: (message, extra) => {
21
+ logger.log(message, extra);
22
+ },
23
+ green: (message, extra) => {
24
+ logger.log(message, extra);
25
+ },
26
+ warn: (message, error, extra) => {
27
+ logger.warn(message, { ...extra, err: error });
28
+ },
29
+ error: (message, error, extra) => {
30
+ logger.error(message, { ...extra, err: error });
31
+ },
32
+ };
33
+ };
34
+ /**
35
+ * Factory provider for the HatchetClient.
36
+ */
37
+ exports.hatchetClientFactory = {
38
+ provide: typescript_sdk_1.HatchetClient,
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
+ },
46
+ };
@@ -0,0 +1 @@
1
+ export * from "./hatchet-client.factory";
@@ -0,0 +1,17 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./hatchet-client.factory"), exports);
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/package.json",
3
+ "name": "@abinnovision/nestjs-hatchet",
4
+ "version": "0.1.0",
5
+ "keywords": [
6
+ "nestjs",
7
+ "hatchet"
8
+ ],
9
+ "repository": {
10
+ "url": "https://github.com/abinnovision/nestjs-commons"
11
+ },
12
+ "license": "Apache-2.0",
13
+ "author": {
14
+ "name": "AB INNOVISION GmbH",
15
+ "email": "info@abinnovision.com",
16
+ "url": "https://abinnovision.com/"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "require": "./dist/index.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "scripts": {
28
+ "build": "tsc --project tsconfig.build.json",
29
+ "format:check": "prettier --check '{{src,test}/**/*,*}.{js,jsx,ts,tsx,json,json5,yml,yaml,md}'",
30
+ "format:fix": "prettier --write '{{src,test}/**/*,*}.{js,jsx,ts,tsx,json,json5,yml,yaml,md}'",
31
+ "lint:check": "eslint '{{src,test}/**/*,*}.{js,jsx,ts,tsx}'",
32
+ "lint:fix": "eslint '{{src,test}/**/*,*}.{js,jsx,ts,tsx}' --fix",
33
+ "test-unit": "vitest --run --coverage --config vitest.config.mts",
34
+ "test-unit:watch": "vitest --config vitest.config.mts"
35
+ },
36
+ "lint-staged": {
37
+ "src/**/*.{ts,js}": [
38
+ "eslint --fix",
39
+ "prettier --write"
40
+ ],
41
+ "*.{js,ts,json,json5,yaml,yml,md}": [
42
+ "prettier --write"
43
+ ]
44
+ },
45
+ "prettier": "@abinnovision/prettier-config",
46
+ "dependencies": {
47
+ "@hatchet-dev/typescript-sdk": "^1.10.0",
48
+ "@standard-schema/spec": "^1.0.0",
49
+ "directed-graph-typed": "^2.1.0"
50
+ },
51
+ "devDependencies": {
52
+ "@abinnovision/eslint-config-base": "^3.0.2",
53
+ "@abinnovision/prettier-config": "^2.1.5",
54
+ "@swc/core": "^1.11.5",
55
+ "eslint": "^9.21.0",
56
+ "prettier": "^3.5.0",
57
+ "reflect-metadata": "^0.2.2",
58
+ "rxjs": "^7.8.1",
59
+ "typescript": "^5.9.3",
60
+ "vitest": "^4.0.15",
61
+ "vitest-mock-extended": "^3.1.0",
62
+ "zod": "^3.24.1"
63
+ },
64
+ "peerDependencies": {
65
+ "@nestjs/common": "^11.0.0",
66
+ "@nestjs/core": "^11.0.0"
67
+ }
68
+ }