@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.
- package/.eslintrc.json +36 -0
- package/.prettierrc.json +6 -0
- package/README.md +4 -0
- package/dist/hatchet/clients/admin/admin-client.d.ts +14 -0
- package/dist/hatchet/clients/admin/admin-client.js +50 -0
- package/dist/hatchet/clients/admin/admin-client.test.d.ts +1 -0
- package/dist/hatchet/clients/admin/admin-client.test.js +101 -0
- package/dist/hatchet/clients/dispatcher/action-listener.d.ts +24 -0
- package/dist/hatchet/clients/dispatcher/action-listener.js +113 -0
- package/dist/hatchet/clients/dispatcher/action-listener.test.d.ts +4 -0
- package/dist/hatchet/clients/dispatcher/action-listener.test.js +277 -0
- package/dist/hatchet/clients/dispatcher/dispatcher-client.d.ts +17 -0
- package/dist/hatchet/clients/dispatcher/dispatcher-client.js +46 -0
- package/dist/hatchet/clients/dispatcher/dispatcher-client.test.d.ts +1 -0
- package/dist/hatchet/clients/dispatcher/dispatcher-client.test.js +99 -0
- package/dist/hatchet/clients/event/event-client.d.ts +9 -0
- package/dist/hatchet/clients/event/event-client.js +28 -0
- package/dist/hatchet/clients/event/event-client.test.d.ts +1 -0
- package/dist/hatchet/clients/event/event-client.test.js +60 -0
- package/dist/hatchet/clients/hatchet-client/client-config.d.ts +72 -0
- package/dist/hatchet/clients/hatchet-client/client-config.js +17 -0
- package/dist/hatchet/clients/hatchet-client/hatchet-client.d.ts +26 -0
- package/dist/hatchet/clients/hatchet-client/hatchet-client.js +133 -0
- package/dist/hatchet/clients/hatchet-client/hatchet-client.test.d.ts +2 -0
- package/dist/hatchet/clients/hatchet-client/hatchet-client.test.js +135 -0
- package/dist/hatchet/clients/hatchet-client/index.d.ts +2 -0
- package/dist/hatchet/clients/hatchet-client/index.js +18 -0
- package/dist/hatchet/clients/worker/index.d.ts +1 -0
- package/dist/hatchet/clients/worker/index.js +17 -0
- package/dist/hatchet/clients/worker/worker.d.ts +31 -0
- package/dist/hatchet/clients/worker/worker.js +228 -0
- package/dist/hatchet/clients/worker/worker.test.d.ts +1 -0
- package/dist/hatchet/clients/worker/worker.test.js +256 -0
- package/dist/hatchet/index.d.ts +2 -0
- package/dist/hatchet/index.js +4 -0
- package/dist/hatchet/sdk.d.ts +2 -0
- package/dist/hatchet/sdk.js +4 -0
- package/dist/hatchet/step.d.ts +30 -0
- package/dist/hatchet/step.js +63 -0
- package/dist/hatchet/util/config-loader/config-loader.d.ts +13 -0
- package/dist/hatchet/util/config-loader/config-loader.js +85 -0
- package/dist/hatchet/util/config-loader/config-loader.test.d.ts +1 -0
- package/dist/hatchet/util/config-loader/config-loader.test.js +72 -0
- package/dist/hatchet/util/config-loader/index.d.ts +1 -0
- package/dist/hatchet/util/config-loader/index.js +17 -0
- package/dist/hatchet/util/errors/hatchet-error.d.ts +4 -0
- package/dist/hatchet/util/errors/hatchet-error.js +9 -0
- package/dist/hatchet/util/hatchet-promise/hatchet-promise.d.ts +6 -0
- package/dist/hatchet/util/hatchet-promise/hatchet-promise.js +12 -0
- package/dist/hatchet/util/hatchet-promise/hatchet-promise.test.d.ts +1 -0
- package/dist/hatchet/util/hatchet-promise/hatchet-promise.test.js +40 -0
- package/dist/hatchet/util/logger/index.d.ts +1 -0
- package/dist/hatchet/util/logger/index.js +17 -0
- package/dist/hatchet/util/logger/logger.d.ts +12 -0
- package/dist/hatchet/util/logger/logger.js +37 -0
- package/dist/hatchet/util/sleep.d.ts +2 -0
- package/dist/hatchet/util/sleep.js +6 -0
- package/dist/hatchet/workflow.d.ts +78 -0
- package/dist/hatchet/workflow.js +44 -0
- package/dist/protoc/dispatcher/dispatcher.d.ts +273 -0
- package/dist/protoc/dispatcher/dispatcher.js +918 -0
- package/dist/protoc/dispatcher/index.d.ts +1 -0
- package/dist/protoc/dispatcher/index.js +17 -0
- package/dist/protoc/events/events.d.ts +165 -0
- package/dist/protoc/events/events.js +443 -0
- package/dist/protoc/google/protobuf/timestamp.d.ts +121 -0
- package/dist/protoc/google/protobuf/timestamp.js +110 -0
- package/dist/protoc/google/protobuf/wrappers.d.ts +160 -0
- package/dist/protoc/google/protobuf/wrappers.js +527 -0
- package/dist/protoc/workflows/index.d.ts +1 -0
- package/dist/protoc/workflows/index.js +17 -0
- package/dist/protoc/workflows/workflows.d.ts +438 -0
- package/dist/protoc/workflows/workflows.js +1814 -0
- package/examples/dag-worker.ts +55 -0
- package/examples/example-event.ts +7 -0
- package/examples/simple-worker.ts +39 -0
- package/generate-protoc.sh +10 -0
- package/hatchet/clients/admin/admin-client.test.ts +116 -0
- package/hatchet/clients/admin/admin-client.ts +43 -0
- package/hatchet/clients/dispatcher/action-listener.test.ts +270 -0
- package/hatchet/clients/dispatcher/action-listener.ts +91 -0
- package/hatchet/clients/dispatcher/dispatcher-client.test.ts +111 -0
- package/hatchet/clients/dispatcher/dispatcher-client.ts +47 -0
- package/hatchet/clients/event/event-client.test.ts +72 -0
- package/hatchet/clients/event/event-client.ts +32 -0
- package/hatchet/clients/hatchet-client/client-config.ts +22 -0
- package/hatchet/clients/hatchet-client/fixtures/.hatchet-invalid.yaml +6 -0
- package/hatchet/clients/hatchet-client/fixtures/.hatchet.yaml +8 -0
- package/hatchet/clients/hatchet-client/hatchet-client.test.ts +162 -0
- package/hatchet/clients/hatchet-client/hatchet-client.ts +136 -0
- package/hatchet/clients/hatchet-client/index.ts +2 -0
- package/hatchet/clients/worker/index.ts +1 -0
- package/hatchet/clients/worker/worker.test.ts +347 -0
- package/hatchet/clients/worker/worker.ts +229 -0
- package/hatchet/index.ts +3 -0
- package/hatchet/sdk.ts +3 -0
- package/hatchet/step.ts +48 -0
- package/hatchet/util/config-loader/config-loader.test.ts +79 -0
- package/hatchet/util/config-loader/config-loader.ts +91 -0
- package/hatchet/util/config-loader/fixtures/.hatchet-invalid.yaml +6 -0
- package/hatchet/util/config-loader/fixtures/.hatchet.yaml +8 -0
- package/hatchet/util/config-loader/index.ts +1 -0
- package/hatchet/util/errors/hatchet-error.ts +8 -0
- package/hatchet/util/hatchet-promise/hatchet-promise.test.ts +32 -0
- package/hatchet/util/hatchet-promise/hatchet-promise.ts +13 -0
- package/hatchet/util/logger/index.ts +1 -0
- package/hatchet/util/logger/logger.ts +44 -0
- package/hatchet/util/sleep.ts +6 -0
- package/hatchet/workflow.ts +30 -0
- package/jest.config.ts +205 -0
- package/package.json +65 -0
- package/protoc/dispatcher/dispatcher.ts +1101 -0
- package/protoc/dispatcher/index.ts +1 -0
- package/protoc/events/events.ts +519 -0
- package/protoc/events/index.ts +1 -0
- package/protoc/google/protobuf/timestamp.ts +210 -0
- package/protoc/google/protobuf/wrappers.ts +657 -0
- package/protoc/workflows/index.ts +1 -0
- package/protoc/workflows/workflows.ts +2158 -0
- package/tsconfig.json +120 -0
|
@@ -0,0 +1,85 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ConfigLoader = void 0;
|
|
27
|
+
const yaml_1 = require("yaml");
|
|
28
|
+
const fs_1 = require("fs");
|
|
29
|
+
const p = __importStar(require("path"));
|
|
30
|
+
const zod_1 = require("zod");
|
|
31
|
+
const hatchet_client_1 = require("@clients/hatchet-client");
|
|
32
|
+
const nice_grpc_1 = require("nice-grpc");
|
|
33
|
+
const DEFAULT_CONFIG_FILE = '.hatchet.yaml';
|
|
34
|
+
class ConfigLoader {
|
|
35
|
+
static load_client_config(config) {
|
|
36
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
37
|
+
const yaml = this.load_yaml_config(config === null || config === void 0 ? void 0 : config.path);
|
|
38
|
+
const tlsConfig = {
|
|
39
|
+
tls_strategy: (_c = (_b = (_a = yaml === null || yaml === void 0 ? void 0 : yaml.tls_config) === null || _a === void 0 ? void 0 : _a.tls_strategy) !== null && _b !== void 0 ? _b : this.env('HATCHET_CLIENT_TLS_STRATEGY')) !== null && _c !== void 0 ? _c : 'tls',
|
|
40
|
+
cert_file: (_e = (_d = yaml === null || yaml === void 0 ? void 0 : yaml.tls_config) === null || _d === void 0 ? void 0 : _d.cert_file) !== null && _e !== void 0 ? _e : this.env('HATCHET_CLIENT_TLS_CERT_FILE'),
|
|
41
|
+
key_file: (_g = (_f = yaml === null || yaml === void 0 ? void 0 : yaml.tls_config) === null || _f === void 0 ? void 0 : _f.key_file) !== null && _g !== void 0 ? _g : this.env('HATCHET_CLIENT_TLS_KEY_FILE'),
|
|
42
|
+
ca_file: (_j = (_h = yaml === null || yaml === void 0 ? void 0 : yaml.tls_config) === null || _h === void 0 ? void 0 : _h.ca_file) !== null && _j !== void 0 ? _j : this.env('HATCHET_CLIENT_TLS_ROOT_CA_FILE'),
|
|
43
|
+
server_name: (_l = (_k = yaml === null || yaml === void 0 ? void 0 : yaml.tls_config) === null || _k === void 0 ? void 0 : _k.server_name) !== null && _l !== void 0 ? _l : this.env('HATCHET_CLIENT_TLS_SERVER_NAME'),
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
token: (_m = yaml === null || yaml === void 0 ? void 0 : yaml.token) !== null && _m !== void 0 ? _m : this.env('HATCHET_CLIENT_TOKEN'),
|
|
47
|
+
host_port: (_o = yaml === null || yaml === void 0 ? void 0 : yaml.host_port) !== null && _o !== void 0 ? _o : this.env('HATCHET_CLIENT_HOST_PORT'),
|
|
48
|
+
tls_config: tlsConfig,
|
|
49
|
+
log_level: (_q = (_p = yaml === null || yaml === void 0 ? void 0 : yaml.log_level) !== null && _p !== void 0 ? _p : this.env('HATCHET_CLIENT_LOG_LEVEL')) !== null && _q !== void 0 ? _q : 'INFO',
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
static get default_yaml_config_path() {
|
|
53
|
+
return p.join(process.cwd(), DEFAULT_CONFIG_FILE);
|
|
54
|
+
}
|
|
55
|
+
static createCredentials(config) {
|
|
56
|
+
if (config.tls_strategy === 'tls') {
|
|
57
|
+
const rootCerts = config.ca_file ? (0, fs_1.readFileSync)(config.ca_file) : undefined;
|
|
58
|
+
return nice_grpc_1.ChannelCredentials.createSsl(rootCerts);
|
|
59
|
+
}
|
|
60
|
+
const rootCerts = config.ca_file ? (0, fs_1.readFileSync)(config.ca_file) : null;
|
|
61
|
+
const privateKey = config.key_file ? (0, fs_1.readFileSync)(config.key_file) : null;
|
|
62
|
+
const certChain = config.cert_file ? (0, fs_1.readFileSync)(config.cert_file) : null;
|
|
63
|
+
return nice_grpc_1.ChannelCredentials.createSsl(rootCerts, privateKey, certChain);
|
|
64
|
+
}
|
|
65
|
+
static load_yaml_config(path) {
|
|
66
|
+
try {
|
|
67
|
+
const configFile = (0, fs_1.readFileSync)(p.join(__dirname, path !== null && path !== void 0 ? path : this.default_yaml_config_path), 'utf8');
|
|
68
|
+
const config = (0, yaml_1.parse)(configFile);
|
|
69
|
+
hatchet_client_1.ClientConfigSchema.partial().parse(config);
|
|
70
|
+
return config;
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
if (!path)
|
|
74
|
+
return undefined;
|
|
75
|
+
if (e instanceof zod_1.z.ZodError) {
|
|
76
|
+
throw new Error(`Invalid yaml config: ${e.message}`);
|
|
77
|
+
}
|
|
78
|
+
throw e;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
static env(name) {
|
|
82
|
+
return process.env[name];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.ConfigLoader = ConfigLoader;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './config-loader';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./config-loader"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class HatchetPromise {
|
|
4
|
+
constructor(promise) {
|
|
5
|
+
this.cancel = (reason) => { };
|
|
6
|
+
this.promise = new Promise((resolve, reject) => {
|
|
7
|
+
this.cancel = reject;
|
|
8
|
+
Promise.resolve(promise).then(resolve).catch(reject);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.default = HatchetPromise;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './logger';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./logger"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type LogLevel = 'OFF' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
|
|
2
|
+
export declare class Logger {
|
|
3
|
+
private logLevel;
|
|
4
|
+
private context;
|
|
5
|
+
constructor(context: string, logLevel?: LogLevel);
|
|
6
|
+
private log;
|
|
7
|
+
debug(message: string): void;
|
|
8
|
+
info(message: string): void;
|
|
9
|
+
warn(message: string): void;
|
|
10
|
+
error(message: string): void;
|
|
11
|
+
}
|
|
12
|
+
export default Logger;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
// eslint-disable-next-line no-shadow
|
|
5
|
+
var LogLevelEnum;
|
|
6
|
+
(function (LogLevelEnum) {
|
|
7
|
+
LogLevelEnum[LogLevelEnum["OFF"] = -1] = "OFF";
|
|
8
|
+
LogLevelEnum[LogLevelEnum["DEBUG"] = 0] = "DEBUG";
|
|
9
|
+
LogLevelEnum[LogLevelEnum["INFO"] = 1] = "INFO";
|
|
10
|
+
LogLevelEnum[LogLevelEnum["WARN"] = 2] = "WARN";
|
|
11
|
+
LogLevelEnum[LogLevelEnum["ERROR"] = 3] = "ERROR";
|
|
12
|
+
})(LogLevelEnum || (LogLevelEnum = {}));
|
|
13
|
+
class Logger {
|
|
14
|
+
constructor(context, logLevel = 'INFO') {
|
|
15
|
+
this.logLevel = logLevel;
|
|
16
|
+
this.context = context;
|
|
17
|
+
}
|
|
18
|
+
log(level, message) {
|
|
19
|
+
if (LogLevelEnum[level] >= LogLevelEnum[this.logLevel]) {
|
|
20
|
+
console.log(`🪓 [${level}/${this.context}] ${message}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
debug(message) {
|
|
24
|
+
this.log('DEBUG', message);
|
|
25
|
+
}
|
|
26
|
+
info(message) {
|
|
27
|
+
this.log('INFO', message);
|
|
28
|
+
}
|
|
29
|
+
warn(message) {
|
|
30
|
+
this.log('WARN', message);
|
|
31
|
+
}
|
|
32
|
+
error(message) {
|
|
33
|
+
this.log('ERROR', message);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.Logger = Logger;
|
|
37
|
+
exports.default = Logger;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import { CreateStep } from './step';
|
|
3
|
+
declare const StepsSchema: z.ZodArray<z.ZodObject<{
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
name: string;
|
|
8
|
+
parents?: string[] | undefined;
|
|
9
|
+
}, {
|
|
10
|
+
name: string;
|
|
11
|
+
parents?: string[] | undefined;
|
|
12
|
+
}>, "many">;
|
|
13
|
+
export type Steps = z.infer<typeof StepsSchema>;
|
|
14
|
+
export declare const CreateWorkflowSchema: z.ZodObject<{
|
|
15
|
+
id: z.ZodString;
|
|
16
|
+
description: z.ZodString;
|
|
17
|
+
on: z.ZodUnion<[z.ZodObject<{
|
|
18
|
+
cron: z.ZodString;
|
|
19
|
+
event: z.ZodUndefined;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
cron: string;
|
|
22
|
+
event?: undefined;
|
|
23
|
+
}, {
|
|
24
|
+
cron: string;
|
|
25
|
+
event?: undefined;
|
|
26
|
+
}>, z.ZodObject<{
|
|
27
|
+
cron: z.ZodUndefined;
|
|
28
|
+
event: z.ZodString;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
event: string;
|
|
31
|
+
cron?: undefined;
|
|
32
|
+
}, {
|
|
33
|
+
event: string;
|
|
34
|
+
cron?: undefined;
|
|
35
|
+
}>]>;
|
|
36
|
+
steps: z.ZodArray<z.ZodObject<{
|
|
37
|
+
name: z.ZodString;
|
|
38
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
name: string;
|
|
41
|
+
parents?: string[] | undefined;
|
|
42
|
+
}, {
|
|
43
|
+
name: string;
|
|
44
|
+
parents?: string[] | undefined;
|
|
45
|
+
}>, "many">;
|
|
46
|
+
}, "strip", z.ZodTypeAny, {
|
|
47
|
+
description: string;
|
|
48
|
+
steps: {
|
|
49
|
+
name: string;
|
|
50
|
+
parents?: string[] | undefined;
|
|
51
|
+
}[];
|
|
52
|
+
id: string;
|
|
53
|
+
on: {
|
|
54
|
+
cron: string;
|
|
55
|
+
event?: undefined;
|
|
56
|
+
} | {
|
|
57
|
+
event: string;
|
|
58
|
+
cron?: undefined;
|
|
59
|
+
};
|
|
60
|
+
}, {
|
|
61
|
+
description: string;
|
|
62
|
+
steps: {
|
|
63
|
+
name: string;
|
|
64
|
+
parents?: string[] | undefined;
|
|
65
|
+
}[];
|
|
66
|
+
id: string;
|
|
67
|
+
on: {
|
|
68
|
+
cron: string;
|
|
69
|
+
event?: undefined;
|
|
70
|
+
} | {
|
|
71
|
+
event: string;
|
|
72
|
+
cron?: undefined;
|
|
73
|
+
};
|
|
74
|
+
}>;
|
|
75
|
+
export interface Workflow extends z.infer<typeof CreateWorkflowSchema> {
|
|
76
|
+
steps: CreateStep<any>[];
|
|
77
|
+
}
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.CreateWorkflowSchema = void 0;
|
|
27
|
+
const z = __importStar(require("zod"));
|
|
28
|
+
const step_1 = require("./step");
|
|
29
|
+
const CronConfigSchema = z.object({
|
|
30
|
+
cron: z.string(),
|
|
31
|
+
event: z.undefined(),
|
|
32
|
+
});
|
|
33
|
+
const EventConfigSchema = z.object({
|
|
34
|
+
cron: z.undefined(),
|
|
35
|
+
event: z.string(),
|
|
36
|
+
});
|
|
37
|
+
const OnConfigSchema = z.union([CronConfigSchema, EventConfigSchema]);
|
|
38
|
+
const StepsSchema = z.array(step_1.CreateStepSchema);
|
|
39
|
+
exports.CreateWorkflowSchema = z.object({
|
|
40
|
+
id: z.string(),
|
|
41
|
+
description: z.string(),
|
|
42
|
+
on: OnConfigSchema,
|
|
43
|
+
steps: StepsSchema,
|
|
44
|
+
});
|