@hatchet-dev/typescript-sdk 1.2.0-alpha.1 → 1.2.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 (44) hide show
  1. package/clients/admin/admin-client.d.ts +3 -1
  2. package/clients/admin/admin-client.js +1 -1
  3. package/clients/hatchet-client/features/cron-client.d.ts +3 -0
  4. package/clients/hatchet-client/features/cron-client.js +2 -0
  5. package/clients/hatchet-client/features/schedule-client.d.ts +3 -0
  6. package/clients/hatchet-client/features/schedule-client.js +2 -0
  7. package/clients/rest/generated/data-contracts.d.ts +24 -0
  8. package/clients/worker/worker.js +1 -0
  9. package/package.json +2 -3
  10. package/protoc/dispatcher/dispatcher.d.ts +1 -0
  11. package/protoc/dispatcher/dispatcher.js +17 -1
  12. package/protoc/v1/workflows.d.ts +2 -0
  13. package/protoc/v1/workflows.js +19 -1
  14. package/protoc/workflows/workflows.d.ts +2 -0
  15. package/protoc/workflows/workflows.js +17 -1
  16. package/step.d.ts +15 -34
  17. package/step.js +25 -42
  18. package/v1/client/client.d.ts +3 -11
  19. package/v1/client/client.interface.d.ts +0 -2
  20. package/v1/client/client.js +14 -35
  21. package/v1/client/worker.js +2 -4
  22. package/v1/declaration.d.ts +26 -3
  23. package/v1/declaration.js +55 -64
  24. package/v1/examples/cancellations/run.js +4 -4
  25. package/v1/examples/priority/run.js +41 -0
  26. package/v1/examples/{middleware → priority}/worker.js +3 -8
  27. package/v1/examples/priority/workflow.d.ts +8 -0
  28. package/v1/examples/priority/workflow.js +50 -0
  29. package/v1/index.d.ts +1 -0
  30. package/v1/index.js +1 -0
  31. package/v1/task.d.ts +0 -5
  32. package/version.d.ts +1 -1
  33. package/version.js +1 -1
  34. package/v1/examples/middleware/hatchet-client.d.ts +0 -2
  35. package/v1/examples/middleware/hatchet-client.js +0 -32
  36. package/v1/examples/middleware/run.js +0 -34
  37. package/v1/examples/middleware/workflow.d.ts +0 -9
  38. package/v1/examples/middleware/workflow.js +0 -37
  39. package/v1/next/index.d.ts +0 -1
  40. package/v1/next/index.js +0 -17
  41. package/v1/next/middleware/middleware.d.ts +0 -27
  42. package/v1/next/middleware/middleware.js +0 -121
  43. /package/v1/examples/{middleware → priority}/run.d.ts +0 -0
  44. /package/v1/examples/{middleware → priority}/worker.d.ts +0 -0
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- /* eslint-disable no-console */
13
- const workflow_1 = require("./workflow");
14
- function main() {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- // ❓ Running a Task
17
- const res = yield workflow_1.withMiddleware.run({
18
- Message: 'HeLlO WoRlD',
19
- });
20
- // 👀 Access the results of the Task
21
- console.log(res);
22
- // !!
23
- });
24
- }
25
- if (require.main === module) {
26
- main()
27
- .then(() => {
28
- process.exit(0);
29
- })
30
- .catch((err) => {
31
- console.error(err);
32
- process.exit(1);
33
- });
34
- }
@@ -1,9 +0,0 @@
1
- export type SimpleInput = {
2
- Message: string;
3
- };
4
- export type SimpleOutput = {
5
- TransformedMessage: string;
6
- };
7
- export declare const withMiddleware: import("../..").TaskWorkflowDeclaration<SimpleInput, {
8
- TransformedMessage: string;
9
- }>;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withMiddleware = void 0;
4
- const hatchet_client_1 = require("./hatchet-client");
5
- exports.withMiddleware = hatchet_client_1.hatchet.task({
6
- name: 'with-middleware',
7
- middleware: [
8
- {
9
- input: {
10
- deserialize: (input) => {
11
- console.log('task-input-deserialize', input);
12
- return input;
13
- },
14
- serialize: (input) => {
15
- console.log('task-input-serialize', input);
16
- return input;
17
- },
18
- },
19
- output: {
20
- deserialize: (input) => {
21
- console.log('task-output-deserialize', input);
22
- return input;
23
- },
24
- serialize: (input) => {
25
- console.log('task-output-serialize', input);
26
- return input;
27
- },
28
- },
29
- },
30
- ],
31
- fn: (input) => {
32
- return {
33
- TransformedMessage: input.Message.toLowerCase(),
34
- };
35
- },
36
- });
37
- // !!
@@ -1 +0,0 @@
1
- export * from './middleware/middleware';
package/v1/next/index.js DELETED
@@ -1,17 +0,0 @@
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("./middleware/middleware"), exports);
@@ -1,27 +0,0 @@
1
- import { JsonObject } from '../../types';
2
- import { BaseWorkflowDeclaration } from '../../declaration';
3
- import { HatchetClient } from '../../client/client';
4
- type SingleMiddleware<T> = (input: JsonObject) => T | Promise<T>;
5
- type SingleSerialize<T> = (input: T) => JsonObject | Promise<JsonObject>;
6
- export interface Serializable<T = any> {
7
- deserialize: SingleMiddleware<T>;
8
- serialize: SingleSerialize<T>;
9
- }
10
- export interface Middleware {
11
- input: Serializable;
12
- output: Serializable;
13
- }
14
- export interface MiddlewareChain {
15
- middlewares: Middleware[];
16
- }
17
- export type MiddlewareFn<T = any> = (input: any) => T | Promise<T>;
18
- /**
19
- * Binds middleware to a workflow's tasks
20
- * @param wf - The workflow declaration to bind middleware to
21
- * @param client - The HatchetClient instance
22
- * @returns The workflow with middleware bound to its tasks
23
- */
24
- export declare function bindMiddleware(wf: BaseWorkflowDeclaration<any, any>, client: HatchetClient): Promise<BaseWorkflowDeclaration<any, any>>;
25
- export declare function serializeInput(input: JsonObject, middleware?: Middleware[]): Promise<JsonObject>;
26
- export declare function deserializeOutput(output: JsonObject, middleware?: Middleware[]): Promise<JsonObject>;
27
- export {};
@@ -1,121 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.bindMiddleware = bindMiddleware;
13
- exports.serializeInput = serializeInput;
14
- exports.deserializeOutput = deserializeOutput;
15
- // Helper to compose middleware functions
16
- const composeMiddleware = (fns) => {
17
- return (input) => __awaiter(void 0, void 0, void 0, function* () {
18
- let result = input;
19
- for (const fn of fns) {
20
- result = yield fn(result);
21
- }
22
- return result;
23
- });
24
- };
25
- // Get all deserialize functions in the correct order
26
- const getDeserializeChain = (middleware) => {
27
- return middleware.map((m) => m.input.deserialize);
28
- };
29
- // Get all serialize functions in the correct order
30
- const getSerializeChain = (middleware) => {
31
- return middleware.map((m) => m.input.serialize);
32
- };
33
- /**
34
- * Binds middleware to a workflow's tasks
35
- * @param wf - The workflow declaration to bind middleware to
36
- * @param client - The HatchetClient instance
37
- * @returns The workflow with middleware bound to its tasks
38
- */
39
- function bindMiddleware(wf, client) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- const tasks = wf.definition._tasks.map((task) => {
42
- if (!task.middleware) {
43
- // eslint-disable-next-line no-param-reassign
44
- task.middleware = [
45
- {
46
- input: {
47
- deserialize: (input) => input,
48
- serialize: (input) => input,
49
- },
50
- output: {
51
- deserialize: (input) => input,
52
- serialize: (input) => input,
53
- },
54
- },
55
- ];
56
- }
57
- const originalFn = task.fn;
58
- // Build input middleware chain
59
- let inputDeserializeChain = [];
60
- let inputSerializeChain = [];
61
- if (task.middleware) {
62
- inputDeserializeChain = getDeserializeChain(task.middleware);
63
- inputSerializeChain = getSerializeChain(task.middleware);
64
- }
65
- // Build output middleware chain
66
- let outputDeserializeChain = [];
67
- let outputSerializeChain = [];
68
- if (task.middleware) {
69
- outputDeserializeChain = getDeserializeChain(task.middleware);
70
- outputSerializeChain = getSerializeChain(task.middleware);
71
- }
72
- // Add client middleware if present
73
- if (client.middleware) {
74
- inputDeserializeChain = [...getDeserializeChain(client.middleware), ...inputDeserializeChain];
75
- inputSerializeChain = [...inputSerializeChain, ...getSerializeChain(client.middleware)];
76
- outputDeserializeChain = [
77
- ...getDeserializeChain(client.middleware),
78
- ...outputDeserializeChain,
79
- ];
80
- outputSerializeChain = [...outputSerializeChain, ...getSerializeChain(client.middleware)];
81
- }
82
- // Compose the middleware with the original function
83
- // eslint-disable-next-line no-param-reassign
84
- task.fn = (input, ctx) => __awaiter(this, void 0, void 0, function* () {
85
- console.log('fn input', input);
86
- // Apply input deserialize chain
87
- const deserializedInput = yield composeMiddleware(inputDeserializeChain)(input);
88
- // Run the original function
89
- const result = yield originalFn(deserializedInput, ctx);
90
- // Apply output serialize chain
91
- return composeMiddleware(outputSerializeChain)(result);
92
- });
93
- return task;
94
- });
95
- // eslint-disable-next-line no-param-reassign
96
- wf.definition._tasks = tasks;
97
- return wf;
98
- });
99
- }
100
- function serializeInput(input, middleware) {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- let serialized = input;
103
- if (middleware) {
104
- for (const m of middleware) {
105
- serialized = yield m.input.serialize(serialized);
106
- }
107
- }
108
- return serialized;
109
- });
110
- }
111
- function deserializeOutput(output, middleware) {
112
- return __awaiter(this, void 0, void 0, function* () {
113
- let deserialized = output;
114
- if (middleware) {
115
- for (const m of middleware) {
116
- deserialized = yield m.output.deserialize(deserialized);
117
- }
118
- }
119
- return deserialized;
120
- });
121
- }
File without changes