@hatchet-dev/typescript-sdk 0.0.1

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 (120) hide show
  1. package/.eslintrc.json +36 -0
  2. package/.prettierrc.json +6 -0
  3. package/README.md +4 -0
  4. package/dist/hatchet/clients/admin/admin-client.d.ts +14 -0
  5. package/dist/hatchet/clients/admin/admin-client.js +50 -0
  6. package/dist/hatchet/clients/admin/admin-client.test.d.ts +1 -0
  7. package/dist/hatchet/clients/admin/admin-client.test.js +101 -0
  8. package/dist/hatchet/clients/dispatcher/action-listener.d.ts +24 -0
  9. package/dist/hatchet/clients/dispatcher/action-listener.js +113 -0
  10. package/dist/hatchet/clients/dispatcher/action-listener.test.d.ts +4 -0
  11. package/dist/hatchet/clients/dispatcher/action-listener.test.js +277 -0
  12. package/dist/hatchet/clients/dispatcher/dispatcher-client.d.ts +17 -0
  13. package/dist/hatchet/clients/dispatcher/dispatcher-client.js +46 -0
  14. package/dist/hatchet/clients/dispatcher/dispatcher-client.test.d.ts +1 -0
  15. package/dist/hatchet/clients/dispatcher/dispatcher-client.test.js +99 -0
  16. package/dist/hatchet/clients/event/event-client.d.ts +9 -0
  17. package/dist/hatchet/clients/event/event-client.js +28 -0
  18. package/dist/hatchet/clients/event/event-client.test.d.ts +1 -0
  19. package/dist/hatchet/clients/event/event-client.test.js +60 -0
  20. package/dist/hatchet/clients/hatchet-client/client-config.d.ts +72 -0
  21. package/dist/hatchet/clients/hatchet-client/client-config.js +17 -0
  22. package/dist/hatchet/clients/hatchet-client/hatchet-client.d.ts +26 -0
  23. package/dist/hatchet/clients/hatchet-client/hatchet-client.js +133 -0
  24. package/dist/hatchet/clients/hatchet-client/hatchet-client.test.d.ts +2 -0
  25. package/dist/hatchet/clients/hatchet-client/hatchet-client.test.js +135 -0
  26. package/dist/hatchet/clients/hatchet-client/index.d.ts +2 -0
  27. package/dist/hatchet/clients/hatchet-client/index.js +18 -0
  28. package/dist/hatchet/clients/worker/index.d.ts +1 -0
  29. package/dist/hatchet/clients/worker/index.js +17 -0
  30. package/dist/hatchet/clients/worker/worker.d.ts +31 -0
  31. package/dist/hatchet/clients/worker/worker.js +228 -0
  32. package/dist/hatchet/clients/worker/worker.test.d.ts +1 -0
  33. package/dist/hatchet/clients/worker/worker.test.js +256 -0
  34. package/dist/hatchet/index.d.ts +2 -0
  35. package/dist/hatchet/index.js +4 -0
  36. package/dist/hatchet/sdk.d.ts +2 -0
  37. package/dist/hatchet/sdk.js +4 -0
  38. package/dist/hatchet/step.d.ts +30 -0
  39. package/dist/hatchet/step.js +63 -0
  40. package/dist/hatchet/util/config-loader/config-loader.d.ts +13 -0
  41. package/dist/hatchet/util/config-loader/config-loader.js +85 -0
  42. package/dist/hatchet/util/config-loader/config-loader.test.d.ts +1 -0
  43. package/dist/hatchet/util/config-loader/config-loader.test.js +72 -0
  44. package/dist/hatchet/util/config-loader/index.d.ts +1 -0
  45. package/dist/hatchet/util/config-loader/index.js +17 -0
  46. package/dist/hatchet/util/errors/hatchet-error.d.ts +4 -0
  47. package/dist/hatchet/util/errors/hatchet-error.js +9 -0
  48. package/dist/hatchet/util/hatchet-promise/hatchet-promise.d.ts +6 -0
  49. package/dist/hatchet/util/hatchet-promise/hatchet-promise.js +12 -0
  50. package/dist/hatchet/util/hatchet-promise/hatchet-promise.test.d.ts +1 -0
  51. package/dist/hatchet/util/hatchet-promise/hatchet-promise.test.js +40 -0
  52. package/dist/hatchet/util/logger/index.d.ts +1 -0
  53. package/dist/hatchet/util/logger/index.js +17 -0
  54. package/dist/hatchet/util/logger/logger.d.ts +12 -0
  55. package/dist/hatchet/util/logger/logger.js +37 -0
  56. package/dist/hatchet/util/sleep.d.ts +2 -0
  57. package/dist/hatchet/util/sleep.js +6 -0
  58. package/dist/hatchet/workflow.d.ts +78 -0
  59. package/dist/hatchet/workflow.js +44 -0
  60. package/dist/protoc/dispatcher/dispatcher.d.ts +273 -0
  61. package/dist/protoc/dispatcher/dispatcher.js +918 -0
  62. package/dist/protoc/dispatcher/index.d.ts +1 -0
  63. package/dist/protoc/dispatcher/index.js +17 -0
  64. package/dist/protoc/events/events.d.ts +165 -0
  65. package/dist/protoc/events/events.js +443 -0
  66. package/dist/protoc/google/protobuf/timestamp.d.ts +121 -0
  67. package/dist/protoc/google/protobuf/timestamp.js +110 -0
  68. package/dist/protoc/google/protobuf/wrappers.d.ts +160 -0
  69. package/dist/protoc/google/protobuf/wrappers.js +527 -0
  70. package/dist/protoc/workflows/index.d.ts +1 -0
  71. package/dist/protoc/workflows/index.js +17 -0
  72. package/dist/protoc/workflows/workflows.d.ts +438 -0
  73. package/dist/protoc/workflows/workflows.js +1814 -0
  74. package/examples/dag-worker.ts +55 -0
  75. package/examples/example-event.ts +7 -0
  76. package/examples/simple-worker.ts +39 -0
  77. package/generate-protoc.sh +10 -0
  78. package/hatchet/clients/admin/admin-client.test.ts +116 -0
  79. package/hatchet/clients/admin/admin-client.ts +43 -0
  80. package/hatchet/clients/dispatcher/action-listener.test.ts +270 -0
  81. package/hatchet/clients/dispatcher/action-listener.ts +91 -0
  82. package/hatchet/clients/dispatcher/dispatcher-client.test.ts +111 -0
  83. package/hatchet/clients/dispatcher/dispatcher-client.ts +47 -0
  84. package/hatchet/clients/event/event-client.test.ts +72 -0
  85. package/hatchet/clients/event/event-client.ts +32 -0
  86. package/hatchet/clients/hatchet-client/client-config.ts +22 -0
  87. package/hatchet/clients/hatchet-client/fixtures/.hatchet-invalid.yaml +6 -0
  88. package/hatchet/clients/hatchet-client/fixtures/.hatchet.yaml +8 -0
  89. package/hatchet/clients/hatchet-client/hatchet-client.test.ts +162 -0
  90. package/hatchet/clients/hatchet-client/hatchet-client.ts +136 -0
  91. package/hatchet/clients/hatchet-client/index.ts +2 -0
  92. package/hatchet/clients/worker/index.ts +1 -0
  93. package/hatchet/clients/worker/worker.test.ts +347 -0
  94. package/hatchet/clients/worker/worker.ts +229 -0
  95. package/hatchet/index.ts +3 -0
  96. package/hatchet/sdk.ts +3 -0
  97. package/hatchet/step.ts +48 -0
  98. package/hatchet/util/config-loader/config-loader.test.ts +79 -0
  99. package/hatchet/util/config-loader/config-loader.ts +91 -0
  100. package/hatchet/util/config-loader/fixtures/.hatchet-invalid.yaml +6 -0
  101. package/hatchet/util/config-loader/fixtures/.hatchet.yaml +8 -0
  102. package/hatchet/util/config-loader/index.ts +1 -0
  103. package/hatchet/util/errors/hatchet-error.ts +8 -0
  104. package/hatchet/util/hatchet-promise/hatchet-promise.test.ts +32 -0
  105. package/hatchet/util/hatchet-promise/hatchet-promise.ts +13 -0
  106. package/hatchet/util/logger/index.ts +1 -0
  107. package/hatchet/util/logger/logger.ts +44 -0
  108. package/hatchet/util/sleep.ts +6 -0
  109. package/hatchet/workflow.ts +30 -0
  110. package/jest.config.ts +205 -0
  111. package/package.json +65 -0
  112. package/protoc/dispatcher/dispatcher.ts +1101 -0
  113. package/protoc/dispatcher/index.ts +1 -0
  114. package/protoc/events/events.ts +519 -0
  115. package/protoc/events/index.ts +1 -0
  116. package/protoc/google/protobuf/timestamp.ts +210 -0
  117. package/protoc/google/protobuf/wrappers.ts +657 -0
  118. package/protoc/workflows/index.ts +1 -0
  119. package/protoc/workflows/workflows.ts +2158 -0
  120. package/tsconfig.json +120 -0
@@ -0,0 +1,79 @@
1
+ import { ConfigLoader } from './config-loader';
2
+
3
+ fdescribe('ConfigLoader', () => {
4
+ beforeEach(() => {
5
+ process.env.HATCHET_CLIENT_HOST_PORT = 'HOST_PORT';
6
+ process.env.HATCHET_CLIENT_TLS_CERT_FILE = 'TLS_CERT_FILE';
7
+ process.env.HATCHET_CLIENT_TLS_KEY_FILE = 'TLS_KEY_FILE';
8
+ process.env.HATCHET_CLIENT_TLS_ROOT_CA_FILE = 'TLS_ROOT_CA_FILE';
9
+ process.env.HATCHET_CLIENT_TLS_SERVER_NAME = 'TLS_SERVER_NAME';
10
+ });
11
+
12
+ it('should load from environment variables', () => {
13
+ const config = 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
+
27
+ it('should throw an error if the file is not found', () => {
28
+ expect(() =>
29
+ ConfigLoader.load_client_config({
30
+ path: './fixtures/not-found.yaml',
31
+ })
32
+ ).toThrow();
33
+ });
34
+
35
+ xit('should throw an error if the yaml file fails validation', () => {
36
+ expect(() =>
37
+ // This test is failing because there is no invalid state of the yaml file, need to update with tls and mtls settings
38
+ ConfigLoader.load_client_config({
39
+ path: './fixtures/.hatchet-invalid.yaml',
40
+ })
41
+ ).toThrow();
42
+ });
43
+
44
+ it('should favor yaml config over env vars', () => {
45
+ const config = ConfigLoader.load_client_config({
46
+ path: './fixtures/.hatchet.yaml',
47
+ });
48
+ expect(config).toEqual({
49
+ token: 'TOKEN_YAML',
50
+ host_port: 'HOST_PORT_YAML',
51
+ log_level: 'INFO',
52
+ tls_config: {
53
+ tls_strategy: 'tls',
54
+ cert_file: 'TLS_CERT_FILE_YAML',
55
+ key_file: 'TLS_KEY_FILE_YAML',
56
+ ca_file: 'TLS_ROOT_CA_FILE_YAML',
57
+ server_name: 'TLS_SERVER_NAME_YAML',
58
+ },
59
+ });
60
+ });
61
+
62
+ xit('should attempt to load the root .hatchet.yaml config', () => {
63
+ // i'm not sure the best way to test this, maybe spy on readFileSync called with
64
+ const config = ConfigLoader.load_client_config({
65
+ path: './fixtures/.hatchet.yaml',
66
+ });
67
+ expect(config).toEqual({
68
+ token: 'TOKEN_YAML',
69
+ host_port: 'HOST_PORT_YAML',
70
+ tls_config: {
71
+ tls_strategy: 'tls',
72
+ cert_file: 'TLS_CERT_FILE_YAML',
73
+ key_file: 'TLS_KEY_FILE_YAML',
74
+ ca_file: 'TLS_ROOT_CA_FILE_YAML',
75
+ server_name: 'TLS_SERVER_NAME_YAML',
76
+ },
77
+ });
78
+ });
79
+ });
@@ -0,0 +1,91 @@
1
+ import { parse } from 'yaml';
2
+ import { readFileSync } from 'fs';
3
+ import * as p from 'path';
4
+ import { z } from 'zod';
5
+ import { ClientConfig, ClientConfigSchema } from '@clients/hatchet-client';
6
+ import { ChannelCredentials } from 'nice-grpc';
7
+ import { LogLevel } from '../logger/logger';
8
+
9
+ type EnvVars =
10
+ | 'HATCHET_CLIENT_TOKEN'
11
+ | 'HATCHET_CLIENT_TLS_STRATEGY'
12
+ | 'HATCHET_CLIENT_HOST_PORT'
13
+ | 'HATCHET_CLIENT_TLS_CERT_FILE'
14
+ | 'HATCHET_CLIENT_TLS_KEY_FILE'
15
+ | 'HATCHET_CLIENT_TLS_ROOT_CA_FILE'
16
+ | 'HATCHET_CLIENT_TLS_SERVER_NAME'
17
+ | 'HATCHET_CLIENT_LOG_LEVEL';
18
+
19
+ type TLSStrategy = 'tls' | 'mtls';
20
+
21
+ interface LoadClientConfigOptions {
22
+ path?: string;
23
+ }
24
+
25
+ const DEFAULT_CONFIG_FILE = '.hatchet.yaml';
26
+
27
+ export class ConfigLoader {
28
+ static load_client_config(config?: LoadClientConfigOptions): Partial<ClientConfig> {
29
+ const yaml = this.load_yaml_config(config?.path);
30
+ const tlsConfig = {
31
+ tls_strategy:
32
+ yaml?.tls_config?.tls_strategy ??
33
+ (this.env('HATCHET_CLIENT_TLS_STRATEGY') as TLSStrategy | undefined) ??
34
+ 'tls',
35
+ cert_file: yaml?.tls_config?.cert_file ?? this.env('HATCHET_CLIENT_TLS_CERT_FILE')!,
36
+ key_file: yaml?.tls_config?.key_file ?? this.env('HATCHET_CLIENT_TLS_KEY_FILE')!,
37
+ ca_file: yaml?.tls_config?.ca_file ?? this.env('HATCHET_CLIENT_TLS_ROOT_CA_FILE')!,
38
+ server_name: yaml?.tls_config?.server_name ?? this.env('HATCHET_CLIENT_TLS_SERVER_NAME')!,
39
+ };
40
+
41
+ return {
42
+ token: yaml?.token ?? this.env('HATCHET_CLIENT_TOKEN'),
43
+ host_port: yaml?.host_port ?? this.env('HATCHET_CLIENT_HOST_PORT'),
44
+ tls_config: tlsConfig,
45
+ log_level: yaml?.log_level ?? (this.env('HATCHET_CLIENT_LOG_LEVEL') as LogLevel) ?? 'INFO',
46
+ };
47
+ }
48
+
49
+ static get default_yaml_config_path() {
50
+ return p.join(process.cwd(), DEFAULT_CONFIG_FILE);
51
+ }
52
+
53
+ static createCredentials(config: ClientConfig['tls_config']): ChannelCredentials {
54
+ if (config.tls_strategy === 'tls') {
55
+ const rootCerts = config.ca_file ? readFileSync(config.ca_file) : undefined;
56
+ return ChannelCredentials.createSsl(rootCerts);
57
+ }
58
+
59
+ const rootCerts = config.ca_file ? readFileSync(config.ca_file) : null;
60
+ const privateKey = config.key_file ? readFileSync(config.key_file) : null;
61
+ const certChain = config.cert_file ? readFileSync(config.cert_file) : null;
62
+ return ChannelCredentials.createSsl(rootCerts, privateKey, certChain);
63
+ }
64
+
65
+ static load_yaml_config(path?: string): ClientConfig | undefined {
66
+ try {
67
+ const configFile = readFileSync(
68
+ p.join(__dirname, path ?? this.default_yaml_config_path),
69
+ 'utf8'
70
+ );
71
+
72
+ const config = parse(configFile);
73
+
74
+ ClientConfigSchema.partial().parse(config);
75
+
76
+ return config as ClientConfig;
77
+ } catch (e) {
78
+ if (!path) return undefined;
79
+
80
+ if (e instanceof z.ZodError) {
81
+ throw new Error(`Invalid yaml config: ${e.message}`);
82
+ }
83
+
84
+ throw e;
85
+ }
86
+ }
87
+
88
+ private static env(name: EnvVars): string | undefined {
89
+ return process.env[name];
90
+ }
91
+ }
@@ -0,0 +1,6 @@
1
+ tenant_id: 'TENANT_ID_YAML'
2
+ host_port: 'HOST_PORT_YAML'
3
+ tls_config:
4
+ cert_file: 'TLS_CERT_FILE_YAML'
5
+ key_file: 'TLS_KEY_FILE_YAML'
6
+ ca_file: 'TLS_ROOT_CA_FILE_YAML'
@@ -0,0 +1,8 @@
1
+ token: 'TOKEN_YAML'
2
+ tenant_id: 'TENANT_ID_YAML'
3
+ host_port: 'HOST_PORT_YAML'
4
+ tls_config:
5
+ cert_file: 'TLS_CERT_FILE_YAML'
6
+ key_file: 'TLS_KEY_FILE_YAML'
7
+ ca_file: 'TLS_ROOT_CA_FILE_YAML'
8
+ server_name: 'TLS_SERVER_NAME_YAML'
@@ -0,0 +1 @@
1
+ export * from './config-loader';
@@ -0,0 +1,8 @@
1
+ class HatchetError extends Error {
2
+ constructor(message: string) {
3
+ super(message);
4
+ this.name = 'HatchetError';
5
+ }
6
+ }
7
+
8
+ export default HatchetError;
@@ -0,0 +1,32 @@
1
+ import HatchetPromise from './hatchet-promise';
2
+
3
+ describe('HatchetPromise', () => {
4
+ it('should resolve the original promise if not canceled', async () => {
5
+ const hatchetPromise = new HatchetPromise(
6
+ new Promise((resolve) => {
7
+ setTimeout(() => resolve('RESOLVED'), 500);
8
+ })
9
+ );
10
+ const result = await hatchetPromise.promise;
11
+ expect(result).toEqual('RESOLVED');
12
+ });
13
+ it('should resolve the cancel promise if canceled', async () => {
14
+ const hatchetPromise = new HatchetPromise(
15
+ new Promise((resolve) => {
16
+ setTimeout(() => resolve('RESOLVED'), 500);
17
+ })
18
+ );
19
+
20
+ const result = hatchetPromise.promise;
21
+ setTimeout(() => {
22
+ hatchetPromise.cancel();
23
+ }, 100);
24
+
25
+ try {
26
+ await result;
27
+ expect(true).toEqual(false); // this should not be reached
28
+ } catch (e) {
29
+ expect(e).toEqual(undefined);
30
+ }
31
+ });
32
+ });
@@ -0,0 +1,13 @@
1
+ class HatchetPromise<T> {
2
+ cancel: Function = (reason: any) => {};
3
+ promise: Promise<T>;
4
+
5
+ constructor(promise: Promise<T>) {
6
+ this.promise = new Promise((resolve, reject) => {
7
+ this.cancel = reject;
8
+ Promise.resolve(promise).then(resolve).catch(reject);
9
+ });
10
+ }
11
+ }
12
+
13
+ export default HatchetPromise;
@@ -0,0 +1 @@
1
+ export * from './logger';
@@ -0,0 +1,44 @@
1
+ export type LogLevel = 'OFF' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
2
+
3
+ // eslint-disable-next-line no-shadow
4
+ enum LogLevelEnum {
5
+ OFF = -1,
6
+ DEBUG = 0,
7
+ INFO = 1,
8
+ WARN = 2,
9
+ ERROR = 3,
10
+ }
11
+
12
+ export class Logger {
13
+ private logLevel: LogLevel;
14
+ private context: string;
15
+
16
+ constructor(context: string, logLevel: LogLevel = 'INFO') {
17
+ this.logLevel = logLevel;
18
+ this.context = context;
19
+ }
20
+
21
+ private log(level: LogLevel, message: string): void {
22
+ if (LogLevelEnum[level] >= LogLevelEnum[this.logLevel]) {
23
+ console.log(`🪓 [${level}/${this.context}] ${message}`);
24
+ }
25
+ }
26
+
27
+ debug(message: string): void {
28
+ this.log('DEBUG', message);
29
+ }
30
+
31
+ info(message: string): void {
32
+ this.log('INFO', message);
33
+ }
34
+
35
+ warn(message: string): void {
36
+ this.log('WARN', message);
37
+ }
38
+
39
+ error(message: string): void {
40
+ this.log('ERROR', message);
41
+ }
42
+ }
43
+
44
+ export default Logger;
@@ -0,0 +1,6 @@
1
+ const sleep = (ms: number) =>
2
+ new Promise((resolve) => {
3
+ setTimeout(resolve, ms);
4
+ });
5
+
6
+ export default sleep;
@@ -0,0 +1,30 @@
1
+ import * as z from 'zod';
2
+
3
+ import { CreateStep, CreateStepSchema } from './step';
4
+
5
+ const CronConfigSchema = z.object({
6
+ cron: z.string(),
7
+ event: z.undefined(),
8
+ });
9
+
10
+ const EventConfigSchema = z.object({
11
+ cron: z.undefined(),
12
+ event: z.string(),
13
+ });
14
+
15
+ const OnConfigSchema = z.union([CronConfigSchema, EventConfigSchema]);
16
+
17
+ const StepsSchema = z.array(CreateStepSchema);
18
+
19
+ export type Steps = z.infer<typeof StepsSchema>;
20
+
21
+ export const CreateWorkflowSchema = z.object({
22
+ id: z.string(),
23
+ description: z.string(),
24
+ on: OnConfigSchema,
25
+ steps: StepsSchema,
26
+ });
27
+
28
+ export interface Workflow extends z.infer<typeof CreateWorkflowSchema> {
29
+ steps: CreateStep<any>[];
30
+ }
package/jest.config.ts ADDED
@@ -0,0 +1,205 @@
1
+ /**
2
+ * For a detailed explanation regarding each configuration property, visit:
3
+ * https://jestjs.io/docs/configuration
4
+ */
5
+
6
+ import type { Config } from 'jest';
7
+
8
+ const config: Config = {
9
+ // All imported modules in your tests should be mocked automatically
10
+ // automock: false,
11
+
12
+ // Stop running tests after `n` failures
13
+ // bail: 0,
14
+
15
+ // The directory where Jest should store its cached dependency information
16
+ // cacheDirectory: "/private/var/folders/tx/gj6zfqv915j4ww47qf9wsz7m0000gn/T/jest_dx",
17
+
18
+ // Automatically clear mock calls, instances, contexts and results before every test
19
+ clearMocks: true,
20
+
21
+ // Indicates whether the coverage information should be collected while executing the test
22
+ collectCoverage: false,
23
+
24
+ // An array of glob patterns indicating a set of files for which coverage information should be collected
25
+ // collectCoverageFrom: undefined,
26
+
27
+ // The directory where Jest should output its coverage files
28
+ coverageDirectory: 'coverage',
29
+
30
+ // An array of regexp pattern strings used to skip coverage collection
31
+ // coveragePathIgnorePatterns: [
32
+ // "/node_modules/"
33
+ // ],
34
+
35
+ // Indicates which provider should be used to instrument code for coverage
36
+ coverageProvider: 'v8',
37
+
38
+ // A list of reporter names that Jest uses when writing coverage reports
39
+ // coverageReporters: [
40
+ // "json",
41
+ // "text",
42
+ // "lcov",
43
+ // "clover"
44
+ // ],
45
+
46
+ // An object that configures minimum threshold enforcement for coverage results
47
+ // coverageThreshold: undefined,
48
+
49
+ // A path to a custom dependency extractor
50
+ // dependencyExtractor: undefined,
51
+
52
+ // Make calling deprecated APIs throw helpful error messages
53
+ // errorOnDeprecated: false,
54
+
55
+ // The default configuration for fake timers
56
+ // fakeTimers: {
57
+ // "enableGlobally": false
58
+ // },
59
+
60
+ // Force coverage collection from ignored files using an array of glob patterns
61
+ // forceCoverageMatch: [],
62
+
63
+ // A path to a module which exports an async function that is triggered once before all test suites
64
+ // globalSetup: undefined,
65
+
66
+ // A path to a module which exports an async function that is triggered once after all test suites
67
+ // globalTeardown: undefined,
68
+
69
+ // A set of global variables that need to be available in all test environments
70
+ // globals: {},
71
+
72
+ // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
73
+ // maxWorkers: "50%",
74
+
75
+ // An array of directory names to be searched recursively up from the requiring module's location
76
+ // moduleDirectories: [
77
+ // "node_modules"
78
+ // ],
79
+
80
+ // An array of file extensions your modules use
81
+ // moduleFileExtensions: [
82
+ // "js",
83
+ // "mjs",
84
+ // "cjs",
85
+ // "jsx",
86
+ // "ts",
87
+ // "tsx",
88
+ // "json",
89
+ // "node"
90
+ // ],
91
+
92
+ // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
93
+ // moduleNameMapper: {},
94
+
95
+ // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
96
+ // modulePathIgnorePatterns: [],
97
+
98
+ // Activates notifications for test results
99
+ // notify: false,
100
+
101
+ // An enum that specifies notification mode. Requires { notify: true }
102
+ // notifyMode: "failure-change",
103
+
104
+ // A preset that is used as a base for Jest's configuration
105
+ // preset: undefined,
106
+
107
+ // Run tests from one or more projects
108
+ // projects: undefined,
109
+
110
+ // Use this configuration option to add custom reporters to Jest
111
+ // reporters: undefined,
112
+
113
+ // Automatically reset mock state before every test
114
+ // resetMocks: false,
115
+
116
+ // Reset the module registry before running each individual test
117
+ // resetModules: false,
118
+
119
+ // A path to a custom resolver
120
+ // resolver: undefined,
121
+
122
+ // Automatically restore mock state and implementation before every test
123
+ // restoreMocks: false,
124
+
125
+ // The root directory that Jest should scan for tests and modules within
126
+ // rootDir: undefined,
127
+
128
+ // A list of paths to directories that Jest should use to search for files in
129
+ // roots: [
130
+ // "<rootDir>"
131
+ // ],
132
+
133
+ // Allows you to use a custom runner instead of Jest's default test runner
134
+ // runner: "jest-runner",
135
+
136
+ // The paths to modules that run some code to configure or set up the testing environment before each test
137
+ // setupFiles: [],
138
+
139
+ // A list of paths to modules that run some code to configure or set up the testing framework before each test
140
+ // setupFilesAfterEnv: [],
141
+
142
+ // The number of seconds after which a test is considered as slow and reported as such in the results.
143
+ // slowTestThreshold: 5,
144
+
145
+ // A list of paths to snapshot serializer modules Jest should use for snapshot testing
146
+ // snapshotSerializers: [],
147
+
148
+ // The test environment that will be used for testing
149
+ // testEnvironment: "jest-environment-node",
150
+
151
+ // Options that will be passed to the testEnvironment
152
+ // testEnvironmentOptions: {},
153
+
154
+ // Adds a location field to test results
155
+ // testLocationInResults: false,
156
+
157
+ // The glob patterns Jest uses to detect test files
158
+ // testMatch: [
159
+ // "**/__tests__/**/*.[jt]s?(x)",
160
+ // "**/?(*.)+(spec|test).[tj]s?(x)"
161
+ // ],
162
+
163
+ // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
164
+ testPathIgnorePatterns: ['/node_modules/', '/dist/'],
165
+
166
+ // The regexp pattern or array of patterns that Jest uses to detect test files
167
+ // testRegex: [],
168
+
169
+ // This option allows the use of a custom results processor
170
+ // testResultsProcessor: undefined,
171
+
172
+ // This option allows use of a custom test runner
173
+ // testRunner: "jest-circus/runner",
174
+
175
+ // A map from regular expressions to paths to transformers
176
+ transform: {
177
+ '^.+\\.(js|ts)$': ['ts-jest', { tsconfig: './tsconfig.json' }],
178
+ },
179
+ moduleNameMapper: {
180
+ '^@hatchet(.*)$': '<rootDir>/hatchet$1',
181
+ '^@protoc/(.*)$': '<rootDir>/protoc/$1',
182
+ '^@util/(.*)$': '<rootDir>/hatchet/util/$1',
183
+ '^@models/(.*)$': '<rootDir>/hatchet/models/$1',
184
+ '^@clients/(.*)$': '<rootDir>/hatchet/clients/$1',
185
+ },
186
+ // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
187
+ // transformIgnorePatterns: [
188
+ // "/node_modules/",
189
+ // "\\.pnp\\.[^\\/]+$"
190
+ // ],
191
+
192
+ // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
193
+ // unmockedModulePathPatterns: undefined,
194
+
195
+ // Indicates whether each individual test should be reported during the run
196
+ // verbose: undefined,
197
+
198
+ // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
199
+ // watchPathIgnorePatterns: [],
200
+
201
+ // Whether to use watchman for file crawling
202
+ // watchman: true,
203
+ };
204
+
205
+ export default config;
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@hatchet-dev/typescript-sdk",
3
+ "version": "0.0.1",
4
+ "description": "Background task orchestration & visibility for developers",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/hatchet-dev/hatchet.git"
10
+ },
11
+ "publishConfig": {
12
+ "@hatchet:registry": "https://npm.pkg.github.com"
13
+ },
14
+ "keywords": [],
15
+ "author": "",
16
+ "license": "MIT",
17
+ "devDependencies": {
18
+ "@types/jest": "^29.5.11",
19
+ "@typescript-eslint/eslint-plugin": "^6.4.0",
20
+ "autoprefixer": "^10.4.16",
21
+ "dotenv-cli": "^7.3.0",
22
+ "eslint": "^8.56.0",
23
+ "eslint-config-airbnb-typescript": "^17.1.0",
24
+ "eslint-config-prettier": "^9.1.0",
25
+ "eslint-config-standard-with-typescript": "^43.0.0",
26
+ "eslint-import-resolver-typescript": "^3.6.1",
27
+ "eslint-plugin-import": "^2.29.1",
28
+ "eslint-plugin-jest": "^27.6.3",
29
+ "eslint-plugin-n": "^15.0.0 || ^16.0.0 ",
30
+ "eslint-plugin-prettier": "^5.0.1",
31
+ "eslint-plugin-promise": "^6.0.0",
32
+ "eslint-plugin-unused-imports": "^3.0.0",
33
+ "grpc-tools": "^1.12.4",
34
+ "jest": "^29.7.0",
35
+ "prettier": "^3.1.1",
36
+ "ts-jest": "^29.1.1",
37
+ "ts-node": "^10.9.2",
38
+ "ts-proto": "^1.167.0",
39
+ "typescript": "^5.3.3"
40
+ },
41
+ "dependencies": {
42
+ "long": "^5.2.3",
43
+ "nice-grpc": "^2.1.7",
44
+ "nice-grpc-common": "^2.0.2",
45
+ "protobufjs": "^7.2.6",
46
+ "yaml": "^2.3.4",
47
+ "zod": "^3.22.4"
48
+ },
49
+ "scripts": {
50
+ "build": "tsc",
51
+ "test": "jest",
52
+ "test:watch": "jest --watch",
53
+ "generate": "./generate-protoc.sh",
54
+ "lint:check": "npm run eslint:check && npm run prettier:check",
55
+ "lint:fix": "npm run eslint:fix && npm run prettier:fix",
56
+ "eslint:check": "eslint \"{hatchet,tests}/**/*.{ts,tsx,js}\"",
57
+ "eslint:fix": "eslint \"{hatchet,tests}/**/*.{ts,tsx,js}\" --fix",
58
+ "prettier:check": "prettier \"hatchet/**/*.{ts,tsx}\" --list-different",
59
+ "prettier:fix": "prettier \"hatchet/**/*.{ts,tsx}\" --write",
60
+ "exec": "npx dotenv -- ts-node -r tsconfig-paths/register --project tsconfig.json",
61
+ "example:event": "npm run exec -- ./examples/example-event.ts",
62
+ "worker:simple": "npm run exec -- ./examples/simple-worker.ts",
63
+ "worker:dag": "npm run exec -- ./examples/dag-worker.ts"
64
+ }
65
+ }