@hatchet-dev/typescript-sdk 0.0.1 → 0.0.3

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 (109) hide show
  1. package/README.md +2 -3
  2. package/dist/{hatchet/clients → clients}/admin/admin-client.d.ts +2 -2
  3. package/dist/{hatchet/clients → clients}/admin/admin-client.js +2 -2
  4. package/dist/{hatchet/clients → clients}/dispatcher/action-listener.d.ts +3 -3
  5. package/dist/{hatchet/clients → clients}/dispatcher/action-listener.js +2 -2
  6. package/dist/{hatchet/clients → clients}/dispatcher/dispatcher-client.d.ts +3 -3
  7. package/dist/{hatchet/clients → clients}/dispatcher/dispatcher-client.js +2 -2
  8. package/dist/{hatchet/clients → clients}/event/event-client.d.ts +3 -3
  9. package/dist/{hatchet/clients → clients}/event/event-client.js +2 -2
  10. package/dist/{hatchet/clients → clients}/hatchet-client/hatchet-client.d.ts +6 -6
  11. package/dist/{hatchet/clients → clients}/hatchet-client/hatchet-client.js +6 -6
  12. package/dist/{hatchet/clients → clients}/worker/worker.d.ts +6 -6
  13. package/dist/{hatchet/clients → clients}/worker/worker.js +5 -5
  14. package/dist/index.d.ts +2 -0
  15. package/dist/{hatchet/index.js → index.js} +1 -1
  16. package/dist/protoc/events/index.js +17 -0
  17. package/dist/sdk.d.ts +2 -0
  18. package/dist/{hatchet/sdk.js → sdk.js} +1 -1
  19. package/dist/{hatchet/step.js → step.js} +1 -1
  20. package/dist/{hatchet/util → util}/config-loader/config-loader.d.ts +1 -1
  21. package/dist/{hatchet/util → util}/config-loader/config-loader.js +1 -1
  22. package/package.json +8 -5
  23. package/.eslintrc.json +0 -36
  24. package/.prettierrc.json +0 -6
  25. package/dist/hatchet/clients/admin/admin-client.test.d.ts +0 -1
  26. package/dist/hatchet/clients/admin/admin-client.test.js +0 -101
  27. package/dist/hatchet/clients/dispatcher/action-listener.test.d.ts +0 -4
  28. package/dist/hatchet/clients/dispatcher/action-listener.test.js +0 -277
  29. package/dist/hatchet/clients/dispatcher/dispatcher-client.test.d.ts +0 -1
  30. package/dist/hatchet/clients/dispatcher/dispatcher-client.test.js +0 -99
  31. package/dist/hatchet/clients/event/event-client.test.d.ts +0 -1
  32. package/dist/hatchet/clients/event/event-client.test.js +0 -60
  33. package/dist/hatchet/clients/hatchet-client/hatchet-client.test.d.ts +0 -2
  34. package/dist/hatchet/clients/hatchet-client/hatchet-client.test.js +0 -135
  35. package/dist/hatchet/clients/worker/worker.test.d.ts +0 -1
  36. package/dist/hatchet/clients/worker/worker.test.js +0 -256
  37. package/dist/hatchet/index.d.ts +0 -2
  38. package/dist/hatchet/sdk.d.ts +0 -2
  39. package/dist/hatchet/util/config-loader/config-loader.test.d.ts +0 -1
  40. package/dist/hatchet/util/config-loader/config-loader.test.js +0 -72
  41. package/dist/hatchet/util/hatchet-promise/hatchet-promise.test.d.ts +0 -1
  42. package/dist/hatchet/util/hatchet-promise/hatchet-promise.test.js +0 -40
  43. package/examples/dag-worker.ts +0 -55
  44. package/examples/example-event.ts +0 -7
  45. package/examples/simple-worker.ts +0 -39
  46. package/generate-protoc.sh +0 -10
  47. package/hatchet/clients/admin/admin-client.test.ts +0 -116
  48. package/hatchet/clients/admin/admin-client.ts +0 -43
  49. package/hatchet/clients/dispatcher/action-listener.test.ts +0 -270
  50. package/hatchet/clients/dispatcher/action-listener.ts +0 -91
  51. package/hatchet/clients/dispatcher/dispatcher-client.test.ts +0 -111
  52. package/hatchet/clients/dispatcher/dispatcher-client.ts +0 -47
  53. package/hatchet/clients/event/event-client.test.ts +0 -72
  54. package/hatchet/clients/event/event-client.ts +0 -32
  55. package/hatchet/clients/hatchet-client/client-config.ts +0 -22
  56. package/hatchet/clients/hatchet-client/fixtures/.hatchet-invalid.yaml +0 -6
  57. package/hatchet/clients/hatchet-client/fixtures/.hatchet.yaml +0 -8
  58. package/hatchet/clients/hatchet-client/hatchet-client.test.ts +0 -162
  59. package/hatchet/clients/hatchet-client/hatchet-client.ts +0 -136
  60. package/hatchet/clients/hatchet-client/index.ts +0 -2
  61. package/hatchet/clients/worker/index.ts +0 -1
  62. package/hatchet/clients/worker/worker.test.ts +0 -347
  63. package/hatchet/clients/worker/worker.ts +0 -229
  64. package/hatchet/index.ts +0 -3
  65. package/hatchet/sdk.ts +0 -3
  66. package/hatchet/step.ts +0 -48
  67. package/hatchet/util/config-loader/config-loader.test.ts +0 -79
  68. package/hatchet/util/config-loader/config-loader.ts +0 -91
  69. package/hatchet/util/config-loader/fixtures/.hatchet-invalid.yaml +0 -6
  70. package/hatchet/util/config-loader/fixtures/.hatchet.yaml +0 -8
  71. package/hatchet/util/config-loader/index.ts +0 -1
  72. package/hatchet/util/errors/hatchet-error.ts +0 -8
  73. package/hatchet/util/hatchet-promise/hatchet-promise.test.ts +0 -32
  74. package/hatchet/util/hatchet-promise/hatchet-promise.ts +0 -13
  75. package/hatchet/util/logger/index.ts +0 -1
  76. package/hatchet/util/logger/logger.ts +0 -44
  77. package/hatchet/util/sleep.ts +0 -6
  78. package/hatchet/workflow.ts +0 -30
  79. package/jest.config.ts +0 -205
  80. package/protoc/dispatcher/dispatcher.ts +0 -1101
  81. package/protoc/dispatcher/index.ts +0 -1
  82. package/protoc/events/events.ts +0 -519
  83. package/protoc/google/protobuf/timestamp.ts +0 -210
  84. package/protoc/google/protobuf/wrappers.ts +0 -657
  85. package/protoc/workflows/index.ts +0 -1
  86. package/protoc/workflows/workflows.ts +0 -2158
  87. package/tsconfig.json +0 -120
  88. /package/dist/{hatchet/clients → clients}/hatchet-client/client-config.d.ts +0 -0
  89. /package/dist/{hatchet/clients → clients}/hatchet-client/client-config.js +0 -0
  90. /package/dist/{hatchet/clients → clients}/hatchet-client/index.d.ts +0 -0
  91. /package/dist/{hatchet/clients → clients}/hatchet-client/index.js +0 -0
  92. /package/dist/{hatchet/clients → clients}/worker/index.d.ts +0 -0
  93. /package/dist/{hatchet/clients → clients}/worker/index.js +0 -0
  94. /package/{protoc/events/index.ts → dist/protoc/events/index.d.ts} +0 -0
  95. /package/dist/{hatchet/step.d.ts → step.d.ts} +0 -0
  96. /package/dist/{hatchet/util → util}/config-loader/index.d.ts +0 -0
  97. /package/dist/{hatchet/util → util}/config-loader/index.js +0 -0
  98. /package/dist/{hatchet/util → util}/errors/hatchet-error.d.ts +0 -0
  99. /package/dist/{hatchet/util → util}/errors/hatchet-error.js +0 -0
  100. /package/dist/{hatchet/util → util}/hatchet-promise/hatchet-promise.d.ts +0 -0
  101. /package/dist/{hatchet/util → util}/hatchet-promise/hatchet-promise.js +0 -0
  102. /package/dist/{hatchet/util → util}/logger/index.d.ts +0 -0
  103. /package/dist/{hatchet/util → util}/logger/index.js +0 -0
  104. /package/dist/{hatchet/util → util}/logger/logger.d.ts +0 -0
  105. /package/dist/{hatchet/util → util}/logger/logger.js +0 -0
  106. /package/dist/{hatchet/util → util}/sleep.d.ts +0 -0
  107. /package/dist/{hatchet/util → util}/sleep.js +0 -0
  108. /package/dist/{hatchet/workflow.d.ts → workflow.d.ts} +0 -0
  109. /package/dist/{hatchet/workflow.js → workflow.js} +0 -0
@@ -1,256 +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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const hatchet_client_1 = require("@clients/hatchet-client");
16
- const dispatcher_1 = require("@protoc/dispatcher");
17
- const action_listener_1 = require("@clients/dispatcher/action-listener");
18
- const nice_grpc_common_1 = require("nice-grpc-common");
19
- const action_listener_test_1 = require("@clients/dispatcher/action-listener.test");
20
- const zod_1 = require("zod");
21
- const sleep_1 = __importDefault(require("@util/sleep"));
22
- const nice_grpc_1 = require("nice-grpc");
23
- const worker_1 = require("./worker");
24
- const mockStart = {
25
- tenantId: 'TENANT_ID',
26
- jobId: 'job1',
27
- jobName: 'Job One',
28
- jobRunId: 'run1',
29
- stepId: 'step1',
30
- stepRunId: 'runStep1',
31
- actionId: 'action1',
32
- actionType: dispatcher_1.ActionType.START_STEP_RUN,
33
- actionPayload: JSON.stringify('{"input": {"data": 1}}'),
34
- };
35
- const mockCancel = Object.assign(Object.assign({}, mockStart), { actionType: dispatcher_1.ActionType.CANCEL_STEP_RUN });
36
- describe('Worker', () => {
37
- let hatchet;
38
- beforeEach(() => {
39
- hatchet = new hatchet_client_1.HatchetClient({
40
- token: 'TOKEN',
41
- log_level: 'OFF',
42
- host_port: 'HOST_PORT',
43
- tls_config: {
44
- cert_file: 'TLS_CERT_FILE',
45
- key_file: 'TLS_KEY_FILE',
46
- ca_file: 'TLS_ROOT_CA_FILE',
47
- server_name: 'TLS_SERVER_NAME',
48
- },
49
- }, {
50
- credentials: nice_grpc_1.ChannelCredentials.createInsecure(),
51
- });
52
- });
53
- describe('register_workflow', () => {
54
- it('should update the registry', () => __awaiter(void 0, void 0, void 0, function* () {
55
- const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
56
- const putWorkflowSpy = jest.spyOn(worker.client.admin, 'put_workflow').mockResolvedValue();
57
- const workflow = {
58
- id: 'workflow1',
59
- description: 'test',
60
- on: {
61
- event: 'user:create',
62
- },
63
- steps: [
64
- {
65
- name: 'step1',
66
- run: (ctx) => {
67
- return { test: 'test' };
68
- },
69
- },
70
- ],
71
- };
72
- yield worker.register_workflow(workflow);
73
- expect(putWorkflowSpy).toHaveBeenCalledTimes(1);
74
- expect(worker.action_registry).toEqual({
75
- [`default:step1`]: workflow.steps[0].run,
76
- });
77
- }));
78
- });
79
- describe('handle_start_step_run', () => {
80
- it('should start a step run', () => __awaiter(void 0, void 0, void 0, function* () {
81
- const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
82
- const putWorkflowSpy = jest.spyOn(worker.client.admin, 'put_workflow').mockResolvedValue();
83
- const getActionEventSpy = jest.spyOn(worker, 'get_action_event');
84
- const sendActionEventSpy = jest
85
- .spyOn(worker.client.dispatcher, 'send_action_event')
86
- .mockResolvedValue({
87
- tenantId: 'TENANT_ID',
88
- workerId: 'WORKER_ID',
89
- });
90
- const startSpy = jest.fn().mockReturnValue({ data: 4 });
91
- worker.action_registry = {
92
- [mockStart.actionId]: startSpy,
93
- };
94
- worker.handle_start_step_run(mockStart);
95
- yield (0, sleep_1.default)(100);
96
- expect(startSpy).toHaveBeenCalledTimes(1);
97
- expect(getActionEventSpy).toHaveBeenNthCalledWith(2, expect.anything(), dispatcher_1.ActionEventType.STEP_EVENT_TYPE_COMPLETED, { data: 4 });
98
- expect(worker.futures[mockStart.stepRunId]).toBeUndefined();
99
- expect(sendActionEventSpy).toHaveBeenCalledTimes(2);
100
- }));
101
- it('should fail gracefully', () => __awaiter(void 0, void 0, void 0, function* () {
102
- const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
103
- const getActionEventSpy = jest.spyOn(worker, 'get_action_event');
104
- const sendActionEventSpy = jest
105
- .spyOn(worker.client.dispatcher, 'send_action_event')
106
- .mockResolvedValue({
107
- tenantId: 'TENANT_ID',
108
- workerId: 'WORKER_ID',
109
- });
110
- const startSpy = jest.fn().mockRejectedValue(new Error('ERROR'));
111
- worker.action_registry = {
112
- [mockStart.actionId]: startSpy,
113
- };
114
- worker.handle_start_step_run(mockStart);
115
- yield (0, sleep_1.default)(100);
116
- expect(startSpy).toHaveBeenCalledTimes(1);
117
- expect(getActionEventSpy).toHaveBeenNthCalledWith(2, expect.anything(), dispatcher_1.ActionEventType.STEP_EVENT_TYPE_FAILED, expect.anything());
118
- expect(worker.futures[mockStart.stepRunId]).toBeUndefined();
119
- expect(sendActionEventSpy).toHaveBeenCalledTimes(2);
120
- }));
121
- });
122
- describe('handle_cancel_step_run', () => {
123
- it('should cancel a step run', () => {
124
- const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
125
- const cancelSpy = jest.fn().mockReturnValue(undefined);
126
- worker.futures = {
127
- [mockCancel.stepRunId]: {
128
- cancel: cancelSpy,
129
- },
130
- };
131
- worker.handle_cancel_step_run(mockCancel);
132
- expect(cancelSpy).toHaveBeenCalledTimes(1);
133
- expect(worker.futures[mockCancel.stepRunId]).toBeUndefined();
134
- });
135
- });
136
- describe('exit_gracefully', () => {
137
- xit('should call exit_gracefully on SIGTERM', () => __awaiter(void 0, void 0, void 0, function* () {
138
- const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
139
- // the spy is not working and the test is killing the test process
140
- const exitSpy = jest.spyOn(worker, 'exit_gracefully').mockImplementationOnce(() => {
141
- throw new Error('Simulated error');
142
- });
143
- process.emit('SIGTERM', 'SIGTERM');
144
- expect(exitSpy).toHaveBeenCalledTimes(1);
145
- }));
146
- xit('should call exit_gracefully on SIGINT', () => __awaiter(void 0, void 0, void 0, function* () {
147
- const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
148
- // This is killing the process (as it should) fix the spy at some point
149
- const exitSpy = jest.spyOn(worker, 'exit_gracefully').mockResolvedValue();
150
- process.emit('SIGINT', 'SIGINT');
151
- expect(exitSpy).toHaveBeenCalledTimes(1);
152
- }));
153
- xit('should unregister the listener and exit', () => __awaiter(void 0, void 0, void 0, function* () {
154
- const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
155
- jest.spyOn(process, 'exit').mockImplementation((number) => {
156
- throw new Error(`EXIT ${number}`);
157
- }); // This is killing the process (as it should) fix the spy at some point
158
- const mockActionListener = new action_listener_1.ActionListener(hatchet.dispatcher, (0, action_listener_test_1.mockListener)([mockStart, mockStart, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
159
- mockActionListener.unregister = jest.fn().mockResolvedValue((0, zod_1.never)());
160
- worker.listener = mockActionListener;
161
- expect(() => __awaiter(void 0, void 0, void 0, function* () {
162
- yield worker.exit_gracefully();
163
- })).toThrow('EXIT 0');
164
- expect(mockActionListener.unregister).toHaveBeenCalledTimes(1);
165
- }));
166
- it('should exit the process if handle_kill is true', () => __awaiter(void 0, void 0, void 0, function* () {
167
- const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
168
- const exitSpy = jest.spyOn(process, 'exit').mockReturnValue(undefined);
169
- yield worker.exit_gracefully();
170
- expect(exitSpy).toHaveBeenCalledTimes(1);
171
- }));
172
- });
173
- describe('start', () => {
174
- xit('should get actions and start runs', () => __awaiter(void 0, void 0, void 0, function* () {
175
- const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
176
- const startSpy = jest.spyOn(worker, 'handle_start_step_run').mockReturnValue();
177
- const cancelSpy = jest.spyOn(worker, 'handle_cancel_step_run').mockReturnValue();
178
- const mockActionListener = new action_listener_1.ActionListener(hatchet.dispatcher, (0, action_listener_test_1.mockListener)([mockStart, mockStart, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
179
- const getActionListenerSpy = jest
180
- .spyOn(worker.client.dispatcher, 'get_action_listener')
181
- .mockResolvedValue(mockActionListener);
182
- yield worker.start();
183
- expect(getActionListenerSpy).toHaveBeenCalledTimes(1);
184
- expect(startSpy).toHaveBeenCalledTimes(2);
185
- expect(cancelSpy).toHaveBeenCalledTimes(0);
186
- }));
187
- it('should get actions and cancel runs', () => __awaiter(void 0, void 0, void 0, function* () {
188
- const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
189
- const startSpy = jest.spyOn(worker, 'handle_start_step_run').mockReturnValue();
190
- const cancelSpy = jest.spyOn(worker, 'handle_cancel_step_run').mockReturnValue();
191
- const mockActionListner = new action_listener_1.ActionListener(hatchet.dispatcher, (0, action_listener_test_1.mockListener)([mockStart, mockCancel, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
192
- const getActionListenerSpy = jest
193
- .spyOn(worker.client.dispatcher, 'get_action_listener')
194
- .mockResolvedValue(mockActionListner);
195
- yield worker.start();
196
- expect(getActionListenerSpy).toHaveBeenCalledTimes(1);
197
- expect(startSpy).toHaveBeenCalledTimes(1);
198
- expect(cancelSpy).toHaveBeenCalledTimes(1);
199
- }));
200
- it('should retry 5 times to start a worker then throw an error', () => __awaiter(void 0, void 0, void 0, function* () {
201
- const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
202
- const startSpy = jest.spyOn(worker, 'handle_start_step_run').mockReturnValue();
203
- const cancelSpy = jest.spyOn(worker, 'handle_cancel_step_run').mockReturnValue();
204
- const mockActionListner = new action_listener_1.ActionListener(hatchet.dispatcher, (0, action_listener_test_1.mockListener)([mockStart, mockCancel, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
205
- const getActionListenerSpy = jest
206
- .spyOn(worker.client.dispatcher, 'get_action_listener')
207
- .mockImplementationOnce(() => {
208
- throw new Error('Simulated error');
209
- })
210
- .mockImplementationOnce(() => {
211
- throw new Error('Simulated error');
212
- })
213
- .mockImplementationOnce(() => {
214
- throw new Error('Simulated error');
215
- })
216
- .mockImplementationOnce(() => {
217
- throw new Error('Simulated error');
218
- })
219
- .mockImplementationOnce(() => {
220
- throw new Error('Simulated error');
221
- })
222
- .mockImplementationOnce(() => {
223
- throw new Error('Simulated error');
224
- });
225
- yield worker.start();
226
- expect(getActionListenerSpy).toHaveBeenCalledTimes(5);
227
- expect(startSpy).toHaveBeenCalledTimes(0);
228
- expect(cancelSpy).toHaveBeenCalledTimes(0);
229
- }));
230
- it('should successfully run after retrying < 5 times', () => __awaiter(void 0, void 0, void 0, function* () {
231
- const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
232
- const startSpy = jest.spyOn(worker, 'handle_start_step_run').mockReturnValue();
233
- const cancelSpy = jest.spyOn(worker, 'handle_cancel_step_run').mockReturnValue();
234
- const mockActionLister = new action_listener_1.ActionListener(hatchet.dispatcher, (0, action_listener_test_1.mockListener)([mockStart, mockCancel, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
235
- const getActionListenerSpy = jest
236
- .spyOn(worker.client.dispatcher, 'get_action_listener')
237
- .mockImplementationOnce(() => {
238
- throw new Error('Simulated error');
239
- })
240
- .mockImplementationOnce(() => {
241
- throw new Error('Simulated error');
242
- })
243
- .mockImplementationOnce(() => {
244
- throw new Error('Simulated error');
245
- })
246
- .mockImplementationOnce(() => {
247
- throw new Error('Simulated error');
248
- })
249
- .mockImplementationOnce(() => __awaiter(void 0, void 0, void 0, function* () { return mockActionLister; }));
250
- yield worker.start();
251
- expect(getActionListenerSpy).toHaveBeenCalledTimes(5);
252
- expect(startSpy).toHaveBeenCalledTimes(1);
253
- expect(cancelSpy).toHaveBeenCalledTimes(1);
254
- }));
255
- });
256
- });
@@ -1,2 +0,0 @@
1
- import { HatchetClient as Hatchet } from '@clients/hatchet-client';
2
- export default Hatchet;
@@ -1,2 +0,0 @@
1
- import { HatchetClient as Hatchet } from '@clients/hatchet-client';
2
- export default Hatchet;
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const config_loader_1 = require("./config-loader");
4
- fdescribe('ConfigLoader', () => {
5
- beforeEach(() => {
6
- process.env.HATCHET_CLIENT_HOST_PORT = 'HOST_PORT';
7
- process.env.HATCHET_CLIENT_TLS_CERT_FILE = 'TLS_CERT_FILE';
8
- process.env.HATCHET_CLIENT_TLS_KEY_FILE = 'TLS_KEY_FILE';
9
- process.env.HATCHET_CLIENT_TLS_ROOT_CA_FILE = 'TLS_ROOT_CA_FILE';
10
- process.env.HATCHET_CLIENT_TLS_SERVER_NAME = 'TLS_SERVER_NAME';
11
- });
12
- it('should load from environment variables', () => {
13
- const config = config_loader_1.ConfigLoader.load_client_config();
14
- expect(config).toEqual({
15
- host_port: 'HOST_PORT',
16
- log_level: 'INFO',
17
- tls_config: {
18
- tls_strategy: 'tls',
19
- cert_file: 'TLS_CERT_FILE',
20
- key_file: 'TLS_KEY_FILE',
21
- ca_file: 'TLS_ROOT_CA_FILE',
22
- server_name: 'TLS_SERVER_NAME',
23
- },
24
- });
25
- });
26
- it('should throw an error if the file is not found', () => {
27
- expect(() => config_loader_1.ConfigLoader.load_client_config({
28
- path: './fixtures/not-found.yaml',
29
- })).toThrow();
30
- });
31
- xit('should throw an error if the yaml file fails validation', () => {
32
- expect(() =>
33
- // This test is failing because there is no invalid state of the yaml file, need to update with tls and mtls settings
34
- config_loader_1.ConfigLoader.load_client_config({
35
- path: './fixtures/.hatchet-invalid.yaml',
36
- })).toThrow();
37
- });
38
- it('should favor yaml config over env vars', () => {
39
- const config = config_loader_1.ConfigLoader.load_client_config({
40
- path: './fixtures/.hatchet.yaml',
41
- });
42
- expect(config).toEqual({
43
- token: 'TOKEN_YAML',
44
- host_port: 'HOST_PORT_YAML',
45
- log_level: 'INFO',
46
- tls_config: {
47
- tls_strategy: 'tls',
48
- cert_file: 'TLS_CERT_FILE_YAML',
49
- key_file: 'TLS_KEY_FILE_YAML',
50
- ca_file: 'TLS_ROOT_CA_FILE_YAML',
51
- server_name: 'TLS_SERVER_NAME_YAML',
52
- },
53
- });
54
- });
55
- xit('should attempt to load the root .hatchet.yaml config', () => {
56
- // i'm not sure the best way to test this, maybe spy on readFileSync called with
57
- const config = config_loader_1.ConfigLoader.load_client_config({
58
- path: './fixtures/.hatchet.yaml',
59
- });
60
- expect(config).toEqual({
61
- token: 'TOKEN_YAML',
62
- host_port: 'HOST_PORT_YAML',
63
- tls_config: {
64
- tls_strategy: 'tls',
65
- cert_file: 'TLS_CERT_FILE_YAML',
66
- key_file: 'TLS_KEY_FILE_YAML',
67
- ca_file: 'TLS_ROOT_CA_FILE_YAML',
68
- server_name: 'TLS_SERVER_NAME_YAML',
69
- },
70
- });
71
- });
72
- });
@@ -1,40 +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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const hatchet_promise_1 = __importDefault(require("./hatchet-promise"));
16
- describe('HatchetPromise', () => {
17
- it('should resolve the original promise if not canceled', () => __awaiter(void 0, void 0, void 0, function* () {
18
- const hatchetPromise = new hatchet_promise_1.default(new Promise((resolve) => {
19
- setTimeout(() => resolve('RESOLVED'), 500);
20
- }));
21
- const result = yield hatchetPromise.promise;
22
- expect(result).toEqual('RESOLVED');
23
- }));
24
- it('should resolve the cancel promise if canceled', () => __awaiter(void 0, void 0, void 0, function* () {
25
- const hatchetPromise = new hatchet_promise_1.default(new Promise((resolve) => {
26
- setTimeout(() => resolve('RESOLVED'), 500);
27
- }));
28
- const result = hatchetPromise.promise;
29
- setTimeout(() => {
30
- hatchetPromise.cancel();
31
- }, 100);
32
- try {
33
- yield result;
34
- expect(true).toEqual(false); // this should not be reached
35
- }
36
- catch (e) {
37
- expect(e).toEqual(undefined);
38
- }
39
- }));
40
- });
@@ -1,55 +0,0 @@
1
- import Hatchet from '@hatchet/sdk';
2
- import { Workflow } from '@hatchet/workflow';
3
-
4
- const hatchet = Hatchet.init({
5
- log_level: 'OFF',
6
- });
7
-
8
- const sleep = (ms: number) =>
9
- new Promise((resolve) => {
10
- setTimeout(resolve, ms);
11
- });
12
-
13
- const workflow: Workflow = {
14
- id: 'dag-example',
15
- description: 'test',
16
- on: {
17
- event: 'user:create',
18
- },
19
- steps: [
20
- {
21
- name: 'dag-step1',
22
- run: async (ctx) => {
23
- console.log('executed step1!');
24
- await sleep(5000);
25
- return { step1: 'step1' };
26
- },
27
- },
28
- {
29
- name: 'dag-step2',
30
- parents: ['dag-step1'],
31
- run: (ctx) => {
32
- console.log('executed step2!');
33
- return { step2: 'step2' };
34
- },
35
- },
36
- {
37
- name: 'dag-step3',
38
- parents: ['dag-step1', 'dag-step2'],
39
- run: (ctx) => {
40
- console.log('executed step3!');
41
- return { step3: 'step3' };
42
- },
43
- },
44
- {
45
- name: 'dag-step4',
46
- parents: ['dag-step1', 'dag-step3'],
47
- run: (ctx) => {
48
- console.log('executed step4!');
49
- return { step4: 'step4' };
50
- },
51
- },
52
- ],
53
- };
54
-
55
- hatchet.run(workflow);
@@ -1,7 +0,0 @@
1
- import Hatchet from '@hatchet/sdk';
2
-
3
- const hatchet = Hatchet.init();
4
-
5
- hatchet.event.push('user:create', {
6
- test: 'test',
7
- });
@@ -1,39 +0,0 @@
1
- import Hatchet from '@hatchet/sdk';
2
- import { Workflow } from '@hatchet/workflow';
3
-
4
- const hatchet = Hatchet.init();
5
-
6
- const sleep = (ms: number) =>
7
- new Promise((resolve) => {
8
- setTimeout(resolve, ms);
9
- });
10
-
11
- const workflow: Workflow = {
12
- id: 'example',
13
- description: 'test',
14
- on: {
15
- event: 'user:create',
16
- },
17
- steps: [
18
- {
19
- name: 'step1',
20
- run: async (ctx) => {
21
- console.log('starting step1 with the following input', ctx.workflowInput());
22
- console.log('waiting 5 seconds...');
23
- await sleep(5000);
24
- console.log('executed step1!');
25
- return { step1: 'step1 results!' };
26
- },
27
- },
28
- {
29
- name: 'step2',
30
- parents: ['step1'],
31
- run: (ctx) => {
32
- console.log('executed step2 after step1 returned ', ctx.stepOutput('step1'));
33
- return { step2: 'step2 results!' };
34
- },
35
- },
36
- ],
37
- };
38
-
39
- hatchet.run(workflow);
@@ -1,10 +0,0 @@
1
- # Directory to write generated code to (.js and .d.ts files)
2
- OUT_DIR="./protoc"
3
-
4
- # Generate code
5
- ./node_modules/.bin/grpc_tools_node_protoc \
6
- --plugin=protoc-gen-ts_proto=./node_modules/.bin/protoc-gen-ts_proto \
7
- --ts_proto_out=$OUT_DIR \
8
- --ts_proto_opt=outputServices=nice-grpc,outputServices=generic-definitions,useExactTypes=false \
9
- --proto_path=../api-contracts \
10
- ../api-contracts/**/*.proto
@@ -1,116 +0,0 @@
1
- import { CreateWorkflowVersionOpts, WorkflowVersion } from '@protoc/workflows';
2
- import { AdminClient } from './admin-client';
3
- import { mockChannel, mockFactory } from '../hatchet-client/hatchet-client.test';
4
-
5
- describe('AdminClient', () => {
6
- let client: AdminClient;
7
-
8
- it('should create a client', () => {
9
- const x = new AdminClient(
10
- {
11
- token: 'TOKEN',
12
- host_port: 'HOST_PORT',
13
- tls_config: {
14
- cert_file: 'TLS_CERT_FILE',
15
- key_file: 'TLS_KEY_FILE',
16
- ca_file: 'TLS_ROOT_CA_FILE',
17
- server_name: 'TLS_SERVER_NAME',
18
- },
19
- },
20
- mockChannel,
21
- mockFactory
22
- );
23
-
24
- expect(x).toBeDefined();
25
- });
26
-
27
- beforeEach(() => {
28
- client = new AdminClient(
29
- {
30
- token: 'TOKEN',
31
- host_port: 'HOST_PORT',
32
- tls_config: {
33
- cert_file: 'TLS_CERT_FILE',
34
- key_file: 'TLS_KEY_FILE',
35
- ca_file: 'TLS_ROOT_CA_FILE',
36
- server_name: 'TLS_SERVER_NAME',
37
- },
38
- },
39
- mockChannel,
40
- mockFactory
41
- );
42
- });
43
-
44
- describe('put_workflow', () => {
45
- it('should throw an error if no version and not auto version', async () => {
46
- const workflow: CreateWorkflowVersionOpts = {
47
- name: 'workflow1',
48
- version: '',
49
- description: 'description1',
50
- eventTriggers: [],
51
- cronTriggers: [],
52
- scheduledTriggers: [],
53
- jobs: [],
54
- };
55
-
56
- expect(() => client.put_workflow(workflow, { autoVersion: false })).rejects.toThrow(
57
- 'PutWorkflow error: workflow version is required, or use autoVersion'
58
- );
59
- });
60
-
61
- it('should attempt to put the workflow', async () => {
62
- const workflow: CreateWorkflowVersionOpts = {
63
- name: 'workflow1',
64
- version: 'v0.0.1',
65
- description: 'description1',
66
- eventTriggers: [],
67
- cronTriggers: [],
68
- scheduledTriggers: [],
69
- jobs: [],
70
- };
71
-
72
- const putSpy = jest.spyOn(client.client, 'putWorkflow').mockResolvedValue({
73
- id: 'workflow1',
74
- version: 'v0.1.0',
75
- order: 1,
76
- workflowId: 'workflow1',
77
- jobs: [],
78
- createdAt: undefined,
79
- updatedAt: undefined,
80
- triggers: undefined,
81
- });
82
-
83
- await client.put_workflow(workflow);
84
-
85
- expect(putSpy).toHaveBeenCalled();
86
- });
87
- });
88
-
89
- describe('schedule_workflow', () => {
90
- it('should schedule a workflow', () => {
91
- const res: WorkflowVersion = {
92
- id: 'string',
93
- version: 'v0.0.1',
94
- order: 1,
95
- workflowId: 'string',
96
- jobs: [],
97
- createdAt: undefined,
98
- updatedAt: undefined,
99
- triggers: undefined,
100
- };
101
-
102
- const spy = jest.spyOn(client.client, 'scheduleWorkflow').mockResolvedValue(res);
103
-
104
- const now = new Date();
105
-
106
- client.schedule_workflow('workflowId', {
107
- schedules: [now],
108
- });
109
-
110
- expect(spy).toHaveBeenCalledWith({
111
- workflowId: 'workflowId',
112
- schedules: [now],
113
- });
114
- });
115
- });
116
- });
@@ -1,43 +0,0 @@
1
- import { Channel, ClientFactory } from 'nice-grpc';
2
- import {
3
- CreateWorkflowVersionOpts,
4
- WorkflowServiceClient,
5
- WorkflowServiceDefinition,
6
- } from '@protoc/workflows';
7
- import HatchetError from '@util/errors/hatchet-error';
8
- import { ClientConfig } from '@clients/hatchet-client/client-config';
9
-
10
- export class AdminClient {
11
- config: ClientConfig;
12
- client: WorkflowServiceClient;
13
-
14
- constructor(config: ClientConfig, channel: Channel, factory: ClientFactory) {
15
- this.config = config;
16
- this.client = factory.create(WorkflowServiceDefinition, channel);
17
- }
18
-
19
- async put_workflow(workflow: CreateWorkflowVersionOpts, options?: { autoVersion?: boolean }) {
20
- if (workflow.version === '' && !options?.autoVersion) {
21
- throw new HatchetError('PutWorkflow error: workflow version is required, or use autoVersion');
22
- }
23
-
24
- try {
25
- await this.client.putWorkflow({
26
- opts: workflow,
27
- });
28
- } catch (e: any) {
29
- throw new HatchetError(e.message);
30
- }
31
- }
32
-
33
- schedule_workflow(workflowId: string, options?: { schedules?: Date[] }) {
34
- try {
35
- this.client.scheduleWorkflow({
36
- workflowId,
37
- schedules: options?.schedules,
38
- });
39
- } catch (e: any) {
40
- throw new HatchetError(e.message);
41
- }
42
- }
43
- }