@hatchet-dev/typescript-sdk 0.0.2 → 0.0.7

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 (74) hide show
  1. package/package.json +27 -19
  2. package/README.md +0 -4
  3. package/dist/clients/admin/admin-client.d.ts +0 -14
  4. package/dist/clients/admin/admin-client.js +0 -50
  5. package/dist/clients/admin/admin-client.test.d.ts +0 -1
  6. package/dist/clients/admin/admin-client.test.js +0 -101
  7. package/dist/clients/dispatcher/action-listener.d.ts +0 -24
  8. package/dist/clients/dispatcher/action-listener.js +0 -113
  9. package/dist/clients/dispatcher/action-listener.test.d.ts +0 -4
  10. package/dist/clients/dispatcher/action-listener.test.js +0 -277
  11. package/dist/clients/dispatcher/dispatcher-client.d.ts +0 -17
  12. package/dist/clients/dispatcher/dispatcher-client.js +0 -46
  13. package/dist/clients/dispatcher/dispatcher-client.test.d.ts +0 -1
  14. package/dist/clients/dispatcher/dispatcher-client.test.js +0 -99
  15. package/dist/clients/event/event-client.d.ts +0 -9
  16. package/dist/clients/event/event-client.js +0 -28
  17. package/dist/clients/event/event-client.test.d.ts +0 -1
  18. package/dist/clients/event/event-client.test.js +0 -60
  19. package/dist/clients/hatchet-client/client-config.d.ts +0 -72
  20. package/dist/clients/hatchet-client/client-config.js +0 -17
  21. package/dist/clients/hatchet-client/hatchet-client.d.ts +0 -26
  22. package/dist/clients/hatchet-client/hatchet-client.js +0 -133
  23. package/dist/clients/hatchet-client/hatchet-client.test.d.ts +0 -2
  24. package/dist/clients/hatchet-client/hatchet-client.test.js +0 -135
  25. package/dist/clients/hatchet-client/index.d.ts +0 -2
  26. package/dist/clients/hatchet-client/index.js +0 -18
  27. package/dist/clients/worker/index.d.ts +0 -1
  28. package/dist/clients/worker/index.js +0 -17
  29. package/dist/clients/worker/worker.d.ts +0 -31
  30. package/dist/clients/worker/worker.js +0 -228
  31. package/dist/clients/worker/worker.test.d.ts +0 -1
  32. package/dist/clients/worker/worker.test.js +0 -256
  33. package/dist/index.d.ts +0 -2
  34. package/dist/index.js +0 -4
  35. package/dist/protoc/dispatcher/dispatcher.d.ts +0 -273
  36. package/dist/protoc/dispatcher/dispatcher.js +0 -918
  37. package/dist/protoc/dispatcher/index.d.ts +0 -1
  38. package/dist/protoc/dispatcher/index.js +0 -17
  39. package/dist/protoc/events/events.d.ts +0 -165
  40. package/dist/protoc/events/events.js +0 -443
  41. package/dist/protoc/events/index.d.ts +0 -1
  42. package/dist/protoc/events/index.js +0 -17
  43. package/dist/protoc/google/protobuf/timestamp.d.ts +0 -121
  44. package/dist/protoc/google/protobuf/timestamp.js +0 -110
  45. package/dist/protoc/google/protobuf/wrappers.d.ts +0 -160
  46. package/dist/protoc/google/protobuf/wrappers.js +0 -527
  47. package/dist/protoc/workflows/index.d.ts +0 -1
  48. package/dist/protoc/workflows/index.js +0 -17
  49. package/dist/protoc/workflows/workflows.d.ts +0 -438
  50. package/dist/protoc/workflows/workflows.js +0 -1814
  51. package/dist/sdk.d.ts +0 -2
  52. package/dist/sdk.js +0 -4
  53. package/dist/step.d.ts +0 -30
  54. package/dist/step.js +0 -63
  55. package/dist/util/config-loader/config-loader.d.ts +0 -13
  56. package/dist/util/config-loader/config-loader.js +0 -85
  57. package/dist/util/config-loader/config-loader.test.d.ts +0 -1
  58. package/dist/util/config-loader/config-loader.test.js +0 -72
  59. package/dist/util/config-loader/index.d.ts +0 -1
  60. package/dist/util/config-loader/index.js +0 -17
  61. package/dist/util/errors/hatchet-error.d.ts +0 -4
  62. package/dist/util/errors/hatchet-error.js +0 -9
  63. package/dist/util/hatchet-promise/hatchet-promise.d.ts +0 -6
  64. package/dist/util/hatchet-promise/hatchet-promise.js +0 -12
  65. package/dist/util/hatchet-promise/hatchet-promise.test.d.ts +0 -1
  66. package/dist/util/hatchet-promise/hatchet-promise.test.js +0 -40
  67. package/dist/util/logger/index.d.ts +0 -1
  68. package/dist/util/logger/index.js +0 -17
  69. package/dist/util/logger/logger.d.ts +0 -12
  70. package/dist/util/logger/logger.js +0 -37
  71. package/dist/util/sleep.d.ts +0 -2
  72. package/dist/util/sleep.js +0 -6
  73. package/dist/workflow.d.ts +0 -78
  74. package/dist/workflow.js +0 -44
@@ -1,17 +0,0 @@
1
- import { Channel, ClientFactory } from 'nice-grpc';
2
- import { DispatcherClient as PbDispatcherClient, ActionEvent } from '@hatchet/protoc/dispatcher';
3
- import { ClientConfig } from '../hatchet-client/client-config';
4
- import { ActionListener } from './action-listener';
5
- interface GetActionListenerOptions {
6
- workerName: string;
7
- services: string[];
8
- actions: string[];
9
- }
10
- export declare class DispatcherClient {
11
- config: ClientConfig;
12
- client: PbDispatcherClient;
13
- constructor(config: ClientConfig, channel: Channel, factory: ClientFactory);
14
- get_action_listener(options: GetActionListenerOptions): Promise<ActionListener>;
15
- send_action_event(in_: ActionEvent): Promise<import("@hatchet/protoc/dispatcher").ActionEventResponse>;
16
- }
17
- export {};
@@ -1,46 +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
- exports.DispatcherClient = void 0;
16
- const dispatcher_1 = require("@hatchet/protoc/dispatcher");
17
- const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
18
- const action_listener_1 = require("./action-listener");
19
- class DispatcherClient {
20
- constructor(config, channel, factory) {
21
- this.config = config;
22
- this.client = factory.create(dispatcher_1.DispatcherDefinition, channel);
23
- }
24
- get_action_listener(options) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- // Register the worker
27
- const registration = yield this.client.register(Object.assign({}, options));
28
- // Subscribe to the worker
29
- const listener = this.client.listen({
30
- workerId: registration.workerId,
31
- });
32
- return new action_listener_1.ActionListener(this, listener, registration.workerId);
33
- });
34
- }
35
- send_action_event(in_) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- try {
38
- return this.client.sendActionEvent(in_);
39
- }
40
- catch (e) {
41
- throw new hatchet_error_1.default(e.message);
42
- }
43
- });
44
- }
45
- }
46
- exports.DispatcherClient = DispatcherClient;
@@ -1 +0,0 @@
1
- export {};
@@ -1,99 +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
- const dispatcher_1 = require("@hatchet/protoc/dispatcher");
13
- const dispatcher_client_1 = require("./dispatcher-client");
14
- const hatchet_client_test_1 = require("../hatchet-client/hatchet-client.test");
15
- let client;
16
- describe('DispatcherClient', () => {
17
- it('should create a client', () => {
18
- const x = new dispatcher_client_1.DispatcherClient({
19
- token: 'TOKEN',
20
- host_port: 'HOST_PORT',
21
- log_level: 'OFF',
22
- tls_config: {
23
- cert_file: 'TLS_CERT_FILE',
24
- key_file: 'TLS_KEY_FILE',
25
- ca_file: 'TLS_ROOT_CA_FILE',
26
- server_name: 'TLS_SERVER_NAME',
27
- },
28
- }, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
29
- expect(x).toBeDefined();
30
- });
31
- beforeEach(() => {
32
- client = new dispatcher_client_1.DispatcherClient({
33
- token: 'TOKEN',
34
- host_port: 'HOST_PORT',
35
- log_level: 'OFF',
36
- tls_config: {
37
- cert_file: 'TLS_CERT_FILE',
38
- key_file: 'TLS_KEY_FILE',
39
- ca_file: 'TLS_ROOT_CA_FILE',
40
- server_name: 'TLS_SERVER_NAME',
41
- },
42
- }, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
43
- });
44
- describe('get_action_listener', () => {
45
- it('should register the worker', () => __awaiter(void 0, void 0, void 0, function* () {
46
- const clientSpy = jest.spyOn(client.client, 'register').mockResolvedValue({
47
- workerId: 'WORKER_ID',
48
- tenantId: 'TENANT_ID',
49
- workerName: 'WORKER_NAME',
50
- });
51
- const listenerSpy = jest.spyOn(client.client, 'listen');
52
- const listener = yield client.get_action_listener({
53
- workerName: 'WORKER_NAME',
54
- services: ['SERVICE'],
55
- actions: ['ACTION'],
56
- });
57
- expect(clientSpy).toHaveBeenCalledWith({
58
- workerName: 'WORKER_NAME',
59
- services: ['SERVICE'],
60
- actions: ['ACTION'],
61
- });
62
- expect(listenerSpy).toHaveBeenCalledWith({
63
- workerId: 'WORKER_ID',
64
- });
65
- expect(listener).toBeDefined();
66
- expect(listener.workerId).toEqual('WORKER_ID');
67
- }));
68
- });
69
- describe('send_action_event', () => {
70
- it('should send action events', () => {
71
- const clientSpy = jest.spyOn(client.client, 'sendActionEvent').mockResolvedValue({
72
- tenantId: 'TENANT_ID',
73
- workerId: 'WORKER_ID',
74
- });
75
- client.send_action_event({
76
- workerId: 'WORKER_ID',
77
- actionId: 'ACTION_ID',
78
- eventType: dispatcher_1.ActionEventType.STEP_EVENT_TYPE_COMPLETED,
79
- eventPayload: '{"foo":"bar"}',
80
- eventTimestamp: new Date(),
81
- jobId: 'a',
82
- jobRunId: 'b',
83
- stepId: 'c',
84
- stepRunId: 'd',
85
- });
86
- expect(clientSpy).toHaveBeenCalledWith({
87
- workerId: 'WORKER_ID',
88
- actionId: 'ACTION_ID',
89
- eventType: dispatcher_1.ActionEventType.STEP_EVENT_TYPE_COMPLETED,
90
- eventPayload: '{"foo":"bar"}',
91
- jobId: 'a',
92
- jobRunId: 'b',
93
- stepId: 'c',
94
- stepRunId: 'd',
95
- eventTimestamp: expect.any(Object),
96
- });
97
- });
98
- });
99
- });
@@ -1,9 +0,0 @@
1
- import { Channel, ClientFactory } from 'nice-grpc';
2
- import { EventsServiceClient } from '@hatchet/protoc/events/events';
3
- import { ClientConfig } from '../hatchet-client/client-config';
4
- export declare class EventClient {
5
- config: ClientConfig;
6
- client: EventsServiceClient;
7
- constructor(config: ClientConfig, channel: Channel, factory: ClientFactory);
8
- push<T>(type: string, input: T): Promise<import("@hatchet/protoc/events/events").Event>;
9
- }
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.EventClient = void 0;
7
- const events_1 = require("@hatchet/protoc/events/events");
8
- const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
9
- class EventClient {
10
- constructor(config, channel, factory) {
11
- this.config = config;
12
- this.client = factory.create(events_1.EventsServiceDefinition, channel);
13
- }
14
- push(type, input) {
15
- const req = {
16
- key: type,
17
- payload: JSON.stringify(input),
18
- eventTimestamp: new Date(),
19
- };
20
- try {
21
- return this.client.push(req);
22
- }
23
- catch (e) {
24
- throw new hatchet_error_1.default(e.message);
25
- }
26
- }
27
- }
28
- exports.EventClient = EventClient;
@@ -1 +0,0 @@
1
- export {};
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
7
- const event_client_1 = require("./event-client");
8
- const hatchet_client_test_1 = require("../hatchet-client/hatchet-client.test");
9
- let client;
10
- describe('EventClient', () => {
11
- it('should create a client', () => {
12
- const x = new event_client_1.EventClient({
13
- token: 'TOKEN',
14
- host_port: 'HOST_PORT',
15
- tls_config: {
16
- cert_file: 'TLS_CERT_FILE',
17
- key_file: 'TLS_KEY_FILE',
18
- ca_file: 'TLS_ROOT_CA_FILE',
19
- server_name: 'TLS_SERVER_NAME',
20
- },
21
- }, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
22
- expect(x).toBeDefined();
23
- });
24
- beforeEach(() => {
25
- client = new event_client_1.EventClient({
26
- token: 'TOKEN',
27
- host_port: 'HOST_PORT',
28
- tls_config: {
29
- cert_file: 'TLS_CERT_FILE',
30
- key_file: 'TLS_KEY_FILE',
31
- ca_file: 'TLS_ROOT_CA_FILE',
32
- server_name: 'TLS_SERVER_NAME',
33
- },
34
- }, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
35
- });
36
- it('should push events', () => {
37
- const clientSpy = jest.spyOn(client.client, 'push').mockResolvedValue({
38
- tenantId: 'x',
39
- eventId: 'y',
40
- key: 'z',
41
- eventTimestamp: new Date(),
42
- payload: 'string',
43
- });
44
- client.push('type', { foo: 'bar' });
45
- expect(clientSpy).toHaveBeenCalledWith({
46
- key: 'type',
47
- payload: '{"foo":"bar"}',
48
- eventTimestamp: expect.any(Date),
49
- });
50
- });
51
- it('should throw an error when push fails', () => {
52
- const clientSpy = jest.spyOn(client.client, 'push');
53
- clientSpy.mockImplementation(() => {
54
- throw new Error('foo');
55
- });
56
- expect(() => {
57
- client.push('type', { foo: 'bar' });
58
- }).toThrow(new hatchet_error_1.default('foo'));
59
- });
60
- });
@@ -1,72 +0,0 @@
1
- import { ChannelCredentials } from 'nice-grpc';
2
- import { z } from 'zod';
3
- declare const ClientTLSConfigSchema: z.ZodObject<{
4
- tls_strategy: z.ZodOptional<z.ZodEnum<["tls", "mtls"]>>;
5
- cert_file: z.ZodOptional<z.ZodString>;
6
- ca_file: z.ZodOptional<z.ZodString>;
7
- key_file: z.ZodOptional<z.ZodString>;
8
- server_name: z.ZodOptional<z.ZodString>;
9
- }, "strip", z.ZodTypeAny, {
10
- tls_strategy?: "tls" | "mtls" | undefined;
11
- cert_file?: string | undefined;
12
- ca_file?: string | undefined;
13
- key_file?: string | undefined;
14
- server_name?: string | undefined;
15
- }, {
16
- tls_strategy?: "tls" | "mtls" | undefined;
17
- cert_file?: string | undefined;
18
- ca_file?: string | undefined;
19
- key_file?: string | undefined;
20
- server_name?: string | undefined;
21
- }>;
22
- export declare const ClientConfigSchema: z.ZodObject<{
23
- token: z.ZodString;
24
- tls_config: z.ZodObject<{
25
- tls_strategy: z.ZodOptional<z.ZodEnum<["tls", "mtls"]>>;
26
- cert_file: z.ZodOptional<z.ZodString>;
27
- ca_file: z.ZodOptional<z.ZodString>;
28
- key_file: z.ZodOptional<z.ZodString>;
29
- server_name: z.ZodOptional<z.ZodString>;
30
- }, "strip", z.ZodTypeAny, {
31
- tls_strategy?: "tls" | "mtls" | undefined;
32
- cert_file?: string | undefined;
33
- ca_file?: string | undefined;
34
- key_file?: string | undefined;
35
- server_name?: string | undefined;
36
- }, {
37
- tls_strategy?: "tls" | "mtls" | undefined;
38
- cert_file?: string | undefined;
39
- ca_file?: string | undefined;
40
- key_file?: string | undefined;
41
- server_name?: string | undefined;
42
- }>;
43
- host_port: z.ZodString;
44
- log_level: z.ZodOptional<z.ZodEnum<["OFF", "DEBUG", "INFO", "WARN", "ERROR"]>>;
45
- }, "strip", z.ZodTypeAny, {
46
- token: string;
47
- tls_config: {
48
- tls_strategy?: "tls" | "mtls" | undefined;
49
- cert_file?: string | undefined;
50
- ca_file?: string | undefined;
51
- key_file?: string | undefined;
52
- server_name?: string | undefined;
53
- };
54
- host_port: string;
55
- log_level?: "OFF" | "DEBUG" | "INFO" | "WARN" | "ERROR" | undefined;
56
- }, {
57
- token: string;
58
- tls_config: {
59
- tls_strategy?: "tls" | "mtls" | undefined;
60
- cert_file?: string | undefined;
61
- ca_file?: string | undefined;
62
- key_file?: string | undefined;
63
- server_name?: string | undefined;
64
- };
65
- host_port: string;
66
- log_level?: "OFF" | "DEBUG" | "INFO" | "WARN" | "ERROR" | undefined;
67
- }>;
68
- export type ClientConfig = z.infer<typeof ClientConfigSchema> & {
69
- credentials?: ChannelCredentials;
70
- };
71
- export type ClientTLSConfig = z.infer<typeof ClientTLSConfigSchema>;
72
- export {};
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClientConfigSchema = void 0;
4
- const zod_1 = require("zod");
5
- const ClientTLSConfigSchema = zod_1.z.object({
6
- tls_strategy: zod_1.z.enum(['tls', 'mtls']).optional(),
7
- cert_file: zod_1.z.string().optional(),
8
- ca_file: zod_1.z.string().optional(),
9
- key_file: zod_1.z.string().optional(),
10
- server_name: zod_1.z.string().optional(),
11
- });
12
- exports.ClientConfigSchema = zod_1.z.object({
13
- token: zod_1.z.string(),
14
- tls_config: ClientTLSConfigSchema,
15
- host_port: zod_1.z.string(),
16
- log_level: zod_1.z.enum(['OFF', 'DEBUG', 'INFO', 'WARN', 'ERROR']).optional(),
17
- });
@@ -1,26 +0,0 @@
1
- import { EventClient } from '../event/event-client';
2
- import { DispatcherClient } from '../dispatcher/dispatcher-client';
3
- import { AdminClient } from '../admin/admin-client';
4
- import { Channel, ChannelCredentials } from 'nice-grpc';
5
- import { Workflow } from '@hatchet/workflow';
6
- import { Worker } from '../worker';
7
- import Logger from '@hatchet/util/logger/logger';
8
- import { ClientConfig } from './client-config';
9
- export interface HatchetClientOptions {
10
- config_path?: string;
11
- credentials?: ChannelCredentials;
12
- }
13
- export declare class HatchetClient {
14
- config: ClientConfig;
15
- credentials: ChannelCredentials;
16
- channel: Channel;
17
- event: EventClient;
18
- dispatcher: DispatcherClient;
19
- admin: AdminClient;
20
- logger: Logger;
21
- constructor(config?: Partial<ClientConfig>, options?: HatchetClientOptions);
22
- static with_host_port(host: string, port: number, config?: Partial<ClientConfig>, options?: HatchetClientOptions): HatchetClient;
23
- static init(config?: Partial<ClientConfig>, options?: HatchetClientOptions): HatchetClient;
24
- run(workflow: string | Workflow): Promise<Worker>;
25
- worker(workflow: string | Workflow): Promise<Worker>;
26
- }
@@ -1,133 +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 __asyncValues = (this && this.__asyncValues) || function (o) {
12
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
- var m = o[Symbol.asyncIterator], i;
14
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
- };
18
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
19
- var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
20
- var i, p;
21
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
22
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
23
- };
24
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
- function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
30
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
31
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
32
- function fulfill(value) { resume("next", value); }
33
- function reject(value) { resume("throw", value); }
34
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
35
- };
36
- var __importDefault = (this && this.__importDefault) || function (mod) {
37
- return (mod && mod.__esModule) ? mod : { "default": mod };
38
- };
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.HatchetClient = void 0;
41
- const zod_1 = require("zod");
42
- const config_loader_1 = require("../../util/config-loader");
43
- const event_client_1 = require("../event/event-client");
44
- const dispatcher_client_1 = require("../dispatcher/dispatcher-client");
45
- const admin_client_1 = require("../admin/admin-client");
46
- const nice_grpc_1 = require("nice-grpc");
47
- const worker_1 = require("../worker");
48
- const logger_1 = __importDefault(require("@hatchet/util/logger/logger"));
49
- const client_config_1 = require("./client-config");
50
- const addTokenMiddleware = (token) => function _(call, options) {
51
- return __asyncGenerator(this, arguments, function* _1() {
52
- var _a, e_1, _b, _c;
53
- const optionsWithAuth = Object.assign(Object.assign({}, options), { metadata: new nice_grpc_1.Metadata({ authorization: `bearer ${token}` }) });
54
- if (!call.responseStream) {
55
- const response = yield __await(yield* __asyncDelegator(__asyncValues(call.next(call.request, optionsWithAuth))));
56
- return yield __await(response);
57
- }
58
- try {
59
- for (var _d = true, _e = __asyncValues(call.next(call.request, optionsWithAuth)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
60
- _c = _f.value;
61
- _d = false;
62
- const response = _c;
63
- yield yield __await(response);
64
- }
65
- }
66
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
67
- finally {
68
- try {
69
- if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
70
- }
71
- finally { if (e_1) throw e_1.error; }
72
- }
73
- return yield __await(undefined);
74
- });
75
- };
76
- class HatchetClient {
77
- constructor(config, options) {
78
- // Initializes a new Client instance.
79
- // Loads config in the following order: config param > yaml file > env vars
80
- var _a;
81
- const loaded = config_loader_1.ConfigLoader.load_client_config({
82
- path: options === null || options === void 0 ? void 0 : options.config_path,
83
- });
84
- try {
85
- const valid = client_config_1.ClientConfigSchema.parse(Object.assign(Object.assign({}, loaded), Object.assign(Object.assign({}, config), { tls_config: Object.assign(Object.assign({}, loaded.tls_config), config === null || config === void 0 ? void 0 : config.tls_config) })));
86
- this.config = valid;
87
- }
88
- catch (e) {
89
- if (e instanceof zod_1.z.ZodError) {
90
- throw new Error(`Invalid client config: ${e.message}`);
91
- }
92
- throw e;
93
- }
94
- this.credentials =
95
- (_a = options === null || options === void 0 ? void 0 : options.credentials) !== null && _a !== void 0 ? _a : config_loader_1.ConfigLoader.createCredentials(this.config.tls_config);
96
- this.channel = (0, nice_grpc_1.createChannel)(this.config.host_port, this.credentials, {
97
- 'grpc.ssl_target_name_override': this.config.tls_config.server_name,
98
- });
99
- const clientFactory = (0, nice_grpc_1.createClientFactory)().use(addTokenMiddleware(this.config.token));
100
- this.event = new event_client_1.EventClient(this.config, this.channel, clientFactory);
101
- this.dispatcher = new dispatcher_client_1.DispatcherClient(this.config, this.channel, clientFactory);
102
- this.admin = new admin_client_1.AdminClient(this.config, this.channel, clientFactory);
103
- this.logger = new logger_1.default('HatchetClient', this.config.log_level);
104
- this.logger.info(`Initialized HatchetClient`);
105
- }
106
- static with_host_port(host, port, config, options) {
107
- return new HatchetClient(Object.assign(Object.assign({}, config), { host_port: `${host}:${port}` }), options);
108
- }
109
- static init(config, options) {
110
- return new HatchetClient(config, options);
111
- }
112
- run(workflow) {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- const worker = yield this.worker(workflow);
115
- worker.start();
116
- return worker;
117
- });
118
- }
119
- worker(workflow) {
120
- return __awaiter(this, void 0, void 0, function* () {
121
- const name = typeof workflow === 'string' ? workflow : workflow.id;
122
- const worker = new worker_1.Worker(this, {
123
- name,
124
- });
125
- if (typeof workflow !== 'string') {
126
- yield worker.register_workflow(workflow);
127
- return worker;
128
- }
129
- return worker;
130
- });
131
- }
132
- }
133
- exports.HatchetClient = HatchetClient;
@@ -1,2 +0,0 @@
1
- export declare const mockChannel: import("nice-grpc").Channel;
2
- export declare const mockFactory: import("nice-grpc").ClientFactory<{}>;
@@ -1,135 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mockFactory = exports.mockChannel = void 0;
4
- const nice_grpc_1 = require("nice-grpc");
5
- const hatchet_client_1 = require("./hatchet-client");
6
- exports.mockChannel = (0, nice_grpc_1.createChannel)('localhost:50051');
7
- exports.mockFactory = (0, nice_grpc_1.createClientFactory)();
8
- describe('Client', () => {
9
- beforeEach(() => {
10
- process.env.HATCHET_CLIENT_TOKEN = 'TOKEN_ENV';
11
- });
12
- it('should load from environment variables', () => {
13
- const hatchet = new hatchet_client_1.HatchetClient({
14
- token: 'TOKEN_ENV',
15
- host_port: 'HOST_PORT',
16
- log_level: 'OFF',
17
- tls_config: {
18
- cert_file: 'TLS_CERT_FILE',
19
- key_file: 'TLS_KEY_FILE',
20
- ca_file: 'TLS_ROOT_CA_FILE',
21
- server_name: 'TLS_SERVER_NAME',
22
- },
23
- }, {
24
- credentials: nice_grpc_1.ChannelCredentials.createInsecure(),
25
- });
26
- expect(hatchet.config).toEqual({
27
- token: 'TOKEN_ENV',
28
- host_port: 'HOST_PORT',
29
- log_level: 'OFF',
30
- tls_config: {
31
- tls_strategy: 'tls',
32
- cert_file: 'TLS_CERT_FILE',
33
- key_file: 'TLS_KEY_FILE',
34
- ca_file: 'TLS_ROOT_CA_FILE',
35
- server_name: 'TLS_SERVER_NAME',
36
- },
37
- });
38
- });
39
- it('should throw an error if the config param is invalid', () => {
40
- expect(() => new hatchet_client_1.HatchetClient({
41
- host_port: 'HOST_PORT',
42
- tls_config: {
43
- tls_strategy: 'tls',
44
- cert_file: 'TLS_CERT_FILE',
45
- key_file: 'TLS_KEY_FILE',
46
- ca_file: 'TLS_ROOT_CA_FILE',
47
- // @ts-ignore
48
- server_name: undefined,
49
- },
50
- })).toThrow();
51
- });
52
- it('should favor config param over yaml over env vars ', () => {
53
- const hatchet = new hatchet_client_1.HatchetClient({
54
- tls_config: {
55
- cert_file: 'TLS_CERT_FILE',
56
- key_file: 'TLS_KEY_FILE',
57
- ca_file: 'TLS_ROOT_CA_FILE',
58
- server_name: 'TLS_SERVER_NAME',
59
- },
60
- }, {
61
- config_path: './fixtures/.hatchet.yaml',
62
- credentials: nice_grpc_1.ChannelCredentials.createInsecure(),
63
- });
64
- expect(hatchet.config).toEqual({
65
- token: 'TOKEN_YAML',
66
- host_port: 'HOST_PORT_YAML',
67
- log_level: 'INFO',
68
- tls_config: {
69
- tls_strategy: 'tls',
70
- cert_file: 'TLS_CERT_FILE',
71
- key_file: 'TLS_KEY_FILE',
72
- ca_file: 'TLS_ROOT_CA_FILE',
73
- server_name: 'TLS_SERVER_NAME',
74
- },
75
- });
76
- });
77
- describe('with_host_port', () => {
78
- it('should set the host_port', () => {
79
- const hatchet = hatchet_client_1.HatchetClient.with_host_port('HOST', 1234, {
80
- token: 'TOKEN',
81
- tls_config: {
82
- tls_strategy: 'tls',
83
- cert_file: 'TLS_CERT_FILE',
84
- key_file: 'TLS_KEY_FILE',
85
- ca_file: 'TLS_ROOT_CA_FILE',
86
- server_name: 'TLS_SERVER_NAME',
87
- },
88
- }, {
89
- credentials: nice_grpc_1.ChannelCredentials.createInsecure(),
90
- });
91
- expect(hatchet.config).toEqual({
92
- token: 'TOKEN',
93
- host_port: 'HOST:1234',
94
- log_level: 'INFO',
95
- tls_config: {
96
- tls_strategy: 'tls',
97
- cert_file: 'TLS_CERT_FILE',
98
- key_file: 'TLS_KEY_FILE',
99
- ca_file: 'TLS_ROOT_CA_FILE',
100
- server_name: 'TLS_SERVER_NAME',
101
- },
102
- });
103
- });
104
- });
105
- describe('Worker', () => {
106
- let hatchet;
107
- beforeEach(() => {
108
- hatchet = new hatchet_client_1.HatchetClient({
109
- token: 'TOKEN',
110
- host_port: 'HOST_PORT',
111
- log_level: 'OFF',
112
- tls_config: {
113
- cert_file: 'TLS_CERT_FILE',
114
- key_file: 'TLS_KEY_FILE',
115
- ca_file: 'TLS_ROOT_CA_FILE',
116
- server_name: 'TLS_SERVER_NAME',
117
- },
118
- }, {
119
- credentials: nice_grpc_1.ChannelCredentials.createInsecure(),
120
- });
121
- });
122
- describe('run', () => {
123
- xit('should start a worker', () => {
124
- const worker = hatchet.run('workflow1');
125
- expect(worker).toBeDefined();
126
- });
127
- });
128
- describe('worker', () => {
129
- it('should start a worker', () => {
130
- const worker = hatchet.worker('workflow1');
131
- expect(worker).toBeDefined();
132
- });
133
- });
134
- });
135
- });
@@ -1,2 +0,0 @@
1
- export * from './hatchet-client';
2
- export * from './client-config';