@forzalabs/remora 1.0.22 → 1.1.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 (111) hide show
  1. package/actions/automap.js +26 -42
  2. package/actions/compile.js +27 -43
  3. package/actions/create_consumer.js +24 -40
  4. package/actions/create_producer.js +16 -32
  5. package/actions/debug.js +18 -34
  6. package/actions/deploy.js +30 -46
  7. package/actions/discover.js +13 -29
  8. package/actions/init.js +29 -45
  9. package/actions/mock.js +16 -32
  10. package/actions/run.js +34 -52
  11. package/actions/sample.js +42 -58
  12. package/index.js +109 -119
  13. package/package.json +4 -4
  14. package/workers/ExecutorWorker.js +18 -34
  15. package/Constants.js +0 -34
  16. package/core/Affirm.js +0 -42
  17. package/core/Algo.js +0 -160
  18. package/core/dste/DSTE.js +0 -113
  19. package/core/logger/DebugLogService.js +0 -48
  20. package/core/logger/DevelopmentLogService.js +0 -70
  21. package/core/logger/LocalLogService.js +0 -70
  22. package/core/logger/Logger.js +0 -54
  23. package/database/DatabaseEngine.js +0 -149
  24. package/database/DatabaseStructure.js +0 -27
  25. package/definitions/DatasetDefinitions.js +0 -2
  26. package/definitions/ExecutorDefinitions.js +0 -2
  27. package/definitions/ProcessENV.js +0 -169
  28. package/definitions/agents/DestinationDriver.js +0 -2
  29. package/definitions/agents/SourceDriver.js +0 -2
  30. package/definitions/cli.js +0 -2
  31. package/definitions/database/ApiKeys.js +0 -2
  32. package/definitions/database/Stored.js +0 -7
  33. package/definitions/database/UsageStat.js +0 -2
  34. package/definitions/database/User.js +0 -2
  35. package/definitions/json_schemas/consumer-schema.json +0 -1226
  36. package/definitions/json_schemas/producer-schema.json +0 -308
  37. package/definitions/json_schemas/project-schema.json +0 -100
  38. package/definitions/json_schemas/source-schema.json +0 -249
  39. package/definitions/requests/ConsumerRequest.js +0 -2
  40. package/definitions/requests/Developer.js +0 -2
  41. package/definitions/requests/Mapping.js +0 -2
  42. package/definitions/requests/ProducerRequest.js +0 -2
  43. package/definitions/requests/Request.js +0 -2
  44. package/definitions/resources/Compiled.js +0 -2
  45. package/definitions/resources/Consumer.js +0 -2
  46. package/definitions/resources/Environment.js +0 -2
  47. package/definitions/resources/Library.js +0 -2
  48. package/definitions/resources/Producer.js +0 -2
  49. package/definitions/resources/Project.js +0 -2
  50. package/definitions/resources/Schema.js +0 -2
  51. package/definitions/resources/Source.js +0 -2
  52. package/definitions/temp.js +0 -2
  53. package/definitions/transform/Transformations.js +0 -2
  54. package/drivers/DeltaShareDriver.js +0 -186
  55. package/drivers/DriverFactory.js +0 -72
  56. package/drivers/DriverHelper.js +0 -248
  57. package/drivers/HttpApiDriver.js +0 -208
  58. package/drivers/RedshiftDriver.js +0 -184
  59. package/drivers/files/LocalDestinationDriver.js +0 -146
  60. package/drivers/files/LocalSourceDriver.js +0 -405
  61. package/drivers/s3/S3DestinationDriver.js +0 -197
  62. package/drivers/s3/S3SourceDriver.js +0 -495
  63. package/engines/CryptoEngine.js +0 -75
  64. package/engines/Environment.js +0 -170
  65. package/engines/ProcessENVManager.js +0 -112
  66. package/engines/RandomEngine.js +0 -47
  67. package/engines/SecretManager.js +0 -23
  68. package/engines/UserManager.js +0 -66
  69. package/engines/ai/AutoMapperEngine.js +0 -37
  70. package/engines/ai/DeveloperEngine.js +0 -497
  71. package/engines/ai/LLM.js +0 -255
  72. package/engines/consumer/ConsumerManager.js +0 -218
  73. package/engines/consumer/ConsumerOnFinishManager.js +0 -202
  74. package/engines/dataset/Dataset.js +0 -824
  75. package/engines/dataset/DatasetManager.js +0 -211
  76. package/engines/dataset/DatasetRecord.js +0 -120
  77. package/engines/dataset/DatasetRecordPool.js +0 -77
  78. package/engines/execution/RequestExecutor.js +0 -67
  79. package/engines/parsing/CSVParser.js +0 -60
  80. package/engines/parsing/LineParser.js +0 -71
  81. package/engines/parsing/ParseCompression.js +0 -101
  82. package/engines/parsing/ParseHelper.js +0 -18
  83. package/engines/parsing/ParseManager.js +0 -54
  84. package/engines/parsing/XLSParser.js +0 -87
  85. package/engines/parsing/XMLParser.js +0 -115
  86. package/engines/producer/ProducerEngine.js +0 -127
  87. package/engines/producer/ProducerManager.js +0 -43
  88. package/engines/scheduler/CronScheduler.js +0 -222
  89. package/engines/scheduler/QueueManager.js +0 -314
  90. package/engines/schema/SchemaValidator.js +0 -67
  91. package/engines/transform/JoinEngine.js +0 -232
  92. package/engines/transform/TransformationEngine.js +0 -277
  93. package/engines/transform/TypeCaster.js +0 -59
  94. package/engines/usage/DataframeManager.js +0 -55
  95. package/engines/usage/UsageDataManager.js +0 -151
  96. package/engines/usage/UsageManager.js +0 -65
  97. package/engines/validation/Validator.js +0 -216
  98. package/executors/ConsumerExecutor.js +0 -280
  99. package/executors/Executor.js +0 -177
  100. package/executors/ExecutorOrchestrator.js +0 -331
  101. package/executors/ExecutorPerformance.js +0 -17
  102. package/executors/ExecutorProgress.js +0 -54
  103. package/executors/ExecutorScope.js +0 -52
  104. package/executors/OutputExecutor.js +0 -118
  105. package/executors/ProducerExecutor.js +0 -108
  106. package/helper/Helper.js +0 -149
  107. package/helper/Logger.js +0 -84
  108. package/helper/Runtime.js +0 -20
  109. package/helper/Settings.js +0 -13
  110. package/licencing/LicenceManager.js +0 -64
  111. package/settings.js +0 -12
package/core/dste/DSTE.js DELETED
@@ -1,113 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __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 () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __importDefault = (this && this.__importDefault) || function (mod) {
45
- return (mod && mod.__esModule) ? mod : { "default": mod };
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- const child_process_1 = require("child_process");
49
- const Affirm_1 = __importDefault(require("../Affirm"));
50
- const fs = __importStar(require("fs"));
51
- const path_1 = __importDefault(require("path"));
52
- /**
53
- * This class is used to abstract away all calls that are non-deterministic.
54
- * As of now they just return non-deterministic values, but in the future the implementation can be easily replaced with deterministic code
55
- */
56
- class DeterministicSimulationTestingEngine {
57
- constructor() {
58
- this.init = (options) => {
59
- (0, Affirm_1.default)(options, 'Invalid options');
60
- this._options = options;
61
- };
62
- /**
63
- * returns a random number between 0 and 1
64
- */
65
- this.random = () => Math.random();
66
- this.now = () => new Date();
67
- this.simulate = () => {
68
- const dir = __dirname;
69
- const root = path_1.default.join(dir, '..', '..', '..');
70
- const folders = fs.readdirSync(root);
71
- const testFolder = folders.find(x => x === '_tests');
72
- if (testFolder) {
73
- const baseCommand = `npx tsx ./${testFolder}`;
74
- const testFiles = fs.readdirSync(testFolder);
75
- for (let i = 0; i < testFiles.length; i++) {
76
- const testFile = testFiles[i];
77
- const command = `${baseCommand}/${testFile}`;
78
- console.log('starting command', command);
79
- const tt = (0, child_process_1.execSync)(command);
80
- console.log('completed command', tt);
81
- // TODO: I can't get the output back from this execution and not even the console gets logged
82
- }
83
- }
84
- };
85
- this.tests = (tests) => __awaiter(this, void 0, void 0, function* () {
86
- const results = yield Promise.all(tests);
87
- console.log(results.map(x => `- ${x.message}`).join('\n'));
88
- const count = results.length;
89
- const successCount = results.filter(x => x.success).length;
90
- const failCount = results.filter(x => !x.success).length;
91
- console.log(`\nTests summary:\n- test count: ${count}\n- successes: \x1b[42m${successCount}\x1b[0m\n- failures: \x1b[41m${failCount}\x1b[0m`);
92
- });
93
- this.test = (name, fn) => __awaiter(this, void 0, void 0, function* () {
94
- try {
95
- const res = yield Promise.resolve(fn());
96
- if (!res)
97
- return { message: `test "${name}"\x1b[41m failed.\x1b[0m`, success: false };
98
- else
99
- return { message: `test "${name}"\x1b[42m succeded.\x1b[0m`, success: true };
100
- }
101
- catch (error) {
102
- const myerror = error;
103
- return { message: `test "${name}"\x1b[41m crashed\x1b[0m with message: ${myerror.message}; trace: ${myerror.stack}`, success: false };
104
- }
105
- });
106
- }
107
- }
108
- /**
109
- * Deterministic Simulation Testing Engine
110
- */
111
- const DSTE = new DeterministicSimulationTestingEngine();
112
- DSTE.init({ seed: 0 }); // this is going to bite me in the butt...
113
- exports.default = DSTE;
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class DebugLogService {
4
- constructor() {
5
- this.id = 'DevelopmentLogService';
6
- this._folder = 'local_logs';
7
- this._file = 'logs.txt';
8
- this._path = this._folder + '/' + this._file;
9
- this.init = () => {
10
- return null;
11
- };
12
- this.log = (text) => {
13
- try {
14
- console.log(text);
15
- }
16
- catch (error) {
17
- console.error('ERROR on log', error);
18
- }
19
- finally {
20
- return null;
21
- }
22
- };
23
- this.info = (text) => {
24
- try {
25
- console.info(text);
26
- }
27
- catch (error) {
28
- console.error('ERROR on info', error);
29
- }
30
- finally {
31
- return null;
32
- }
33
- };
34
- this.error = (error) => {
35
- try {
36
- console.error(error);
37
- }
38
- catch (error) {
39
- console.error('ERROR on error', error);
40
- }
41
- finally {
42
- return null;
43
- }
44
- };
45
- }
46
- }
47
- const DebugLogger = new DebugLogService();
48
- exports.default = DebugLogger;
@@ -1,70 +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 fs_1 = require("fs");
7
- const path_1 = __importDefault(require("path"));
8
- class DevelopmentLogService {
9
- constructor() {
10
- this.id = 'DevelopmentLogService';
11
- this._folder = 'local_logs';
12
- this._file = 'logs.txt';
13
- this._path = path_1.default.join(this._folder, this._file);
14
- this.init = () => {
15
- if (!(0, fs_1.existsSync)(this._folder))
16
- (0, fs_1.mkdirSync)(this._folder);
17
- return null;
18
- };
19
- this.log = (text) => {
20
- try {
21
- console.log(text);
22
- this._write(text, 'LOG');
23
- }
24
- catch (error) {
25
- console.error('ERROR on log', error);
26
- }
27
- finally {
28
- return null;
29
- }
30
- };
31
- this.info = (text) => {
32
- try {
33
- console.info(text);
34
- this._write(text, 'INFO');
35
- }
36
- catch (error) {
37
- console.error('ERROR on info', error);
38
- }
39
- finally {
40
- return null;
41
- }
42
- };
43
- this.error = (error) => {
44
- try {
45
- console.error(error);
46
- this._write(error.message, 'INFO', error.name, error.stack);
47
- }
48
- catch (error) {
49
- console.error('ERROR on error', error);
50
- }
51
- finally {
52
- return null;
53
- }
54
- };
55
- this._write = (text, level, errName, stackTrace) => {
56
- if (!text || text.length === 0)
57
- return;
58
- const date = '"' + new Date().toJSON() + '"';
59
- const sanitizedLevel = '"' + level + '"';
60
- const sanitizedText = '"' + text.replace(new RegExp('"', 'g'), '"') + '"';
61
- const sanitizedErrName = '"' + (errName !== null && errName !== void 0 ? errName : '') + '"';
62
- const sanitizedStack = '"' + (stackTrace !== null && stackTrace !== void 0 ? stackTrace : '') + '"';
63
- const line = [date, sanitizedLevel, sanitizedText, sanitizedErrName, sanitizedStack];
64
- const sanitizedLine = line.join(',') + '\r\n';
65
- (0, fs_1.appendFileSync)(this._path, sanitizedLine);
66
- };
67
- }
68
- }
69
- const DevelopmentLogger = new DevelopmentLogService();
70
- exports.default = DevelopmentLogger;
@@ -1,70 +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 fs_1 = require("fs");
7
- const path_1 = __importDefault(require("path"));
8
- class LocalLogService {
9
- constructor() {
10
- this.id = 'DevelopmentLogService';
11
- this._folder = 'local_logs';
12
- this._file = 'logs.txt';
13
- this._path = path_1.default.join(this._folder, this._file);
14
- this.init = () => {
15
- if (!(0, fs_1.existsSync)(this._folder))
16
- (0, fs_1.mkdirSync)(this._folder);
17
- return null;
18
- };
19
- this.log = (text) => {
20
- try {
21
- console.log(text);
22
- this._write(text, 'LOG');
23
- }
24
- catch (error) {
25
- console.error('ERROR on log', error);
26
- }
27
- finally {
28
- return null;
29
- }
30
- };
31
- this.info = (text) => {
32
- try {
33
- console.info(text);
34
- this._write(text, 'INFO');
35
- }
36
- catch (error) {
37
- console.error('ERROR on info', error);
38
- }
39
- finally {
40
- return null;
41
- }
42
- };
43
- this.error = (error) => {
44
- try {
45
- console.error(error);
46
- this._write(error.message, 'INFO', error.name, error.stack);
47
- }
48
- catch (error) {
49
- console.error('ERROR on error', error);
50
- }
51
- finally {
52
- return null;
53
- }
54
- };
55
- this._write = (text, level, errName, stackTrace) => {
56
- if (!text || text.length === 0)
57
- return;
58
- const date = '"' + new Date().toJSON() + '"';
59
- const sanitizedLevel = '"' + level + '"';
60
- const sanitizedText = '"' + text.replace(new RegExp('"', 'g'), '"') + '"';
61
- const sanitizedErrName = '"' + (errName !== null && errName !== void 0 ? errName : '') + '"';
62
- const sanitizedStack = '"' + (stackTrace !== null && stackTrace !== void 0 ? stackTrace : '') + '"';
63
- const line = [date, sanitizedLevel, sanitizedText, sanitizedErrName, sanitizedStack];
64
- const sanitizedLine = line.join(',') + '\r\n';
65
- (0, fs_1.appendFileSync)(this._path, sanitizedLine);
66
- };
67
- }
68
- }
69
- const LocalLogger = new LocalLogService();
70
- exports.default = LocalLogger;
@@ -1,54 +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 Affirm_1 = __importDefault(require("../Affirm"));
16
- class LoggerService {
17
- constructor() {
18
- this.outputs = [];
19
- this.register = (service) => __awaiter(this, void 0, void 0, function* () {
20
- (0, Affirm_1.default)(this.outputs, 'Unassigned outputs in logging service');
21
- (0, Affirm_1.default)(service, 'Invalid service passed to logger.register');
22
- (0, Affirm_1.default)(service.id, 'Invalid id used for registering new logging output service');
23
- (0, Affirm_1.default)(!this.outputs.some(x => x.id === service.id), 'Trying to register logging output service that was already registered');
24
- try {
25
- yield service.init();
26
- this.outputs.push(service);
27
- }
28
- catch (error) {
29
- this.error(error);
30
- }
31
- });
32
- this.isRegistered = (id) => {
33
- (0, Affirm_1.default)(this.outputs, 'Unassigned outputs in logging service');
34
- (0, Affirm_1.default)(id, 'Invalid id used for checking if logging output service is registered');
35
- return this.outputs.some(x => x.id === id);
36
- };
37
- this.log = (text) => {
38
- this.outputs.forEach(x => x.log(text));
39
- };
40
- this.info = (text) => {
41
- this.outputs.forEach(x => x.info(text));
42
- };
43
- this.error = (error) => {
44
- if (error instanceof Error)
45
- this.outputs.forEach(x => x.error(error));
46
- else if (typeof error === 'string')
47
- this.outputs.forEach(x => x.error(new Error(error)));
48
- else
49
- this.outputs.forEach(x => x.error(new Error(error)));
50
- };
51
- }
52
- }
53
- const logger = new LoggerService();
54
- exports.default = logger;
@@ -1,149 +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 mongodb_1 = require("mongodb");
16
- const Helper_1 = __importDefault(require("../helper/Helper"));
17
- const Settings_1 = __importDefault(require("../helper/Settings"));
18
- const ProcessENVManager_1 = __importDefault(require("../engines/ProcessENVManager"));
19
- class DatabaseEngineClass {
20
- constructor() {
21
- this.MAX_TRY_CONNECTION = 3;
22
- this.db = () => this._db;
23
- this.connect = () => __awaiter(this, void 0, void 0, function* () {
24
- // WARNING: this was changed during the deployment to ECS...
25
- // I've reverted it, but maybe it needs to be changed or looked into...
26
- var _a;
27
- this._uri = ((_a = ProcessENVManager_1.default.getEnvVariable('MONGO_URI')) !== null && _a !== void 0 ? _a : Helper_1.default.isDev())
28
- ? 'mongodb://mongo:27017/remora'
29
- : 'mongodb://localhost:27017/remora';
30
- this._client = new mongodb_1.MongoClient(this._uri);
31
- const errors = [];
32
- this._client = new mongodb_1.MongoClient(this._uri);
33
- for (let i = 0; i < this.MAX_TRY_CONNECTION; i++) {
34
- try {
35
- console.log(`Attempting to connect to mongo "${this._uri}`);
36
- yield this._client.connect();
37
- this._db = this._client.db(Settings_1.default.db.name);
38
- this._connected = true;
39
- console.log('Connected to MongoDB');
40
- break;
41
- }
42
- catch (error) {
43
- errors.push((i + 1) + ': connection to MongoDB throws this error: ' + error);
44
- }
45
- }
46
- if (!this._connected)
47
- console.error(`Despite ${this.MAX_TRY_CONNECTION} retries it was not possible to connect to mongoDb, these are the errors encountered:\n` + errors.join('\n'));
48
- });
49
- this.disconnect = () => __awaiter(this, void 0, void 0, function* () {
50
- try {
51
- yield this._client.close();
52
- console.log('Disconnected from MongoDB');
53
- }
54
- catch (error) {
55
- console.error('Error disconnecting from MongoDB:', error);
56
- }
57
- });
58
- this.query = (collectionName, filter, options) => __awaiter(this, void 0, void 0, function* () {
59
- try {
60
- yield this._checkConnection();
61
- const collection = this._db.collection(collectionName);
62
- const result = yield collection.find(filter, options).toArray();
63
- return result;
64
- }
65
- catch (error) {
66
- console.error('Error getting documents:', error);
67
- throw error;
68
- }
69
- });
70
- this.aggregate = (collectionName, aggregation) => __awaiter(this, void 0, void 0, function* () {
71
- try {
72
- yield this._checkConnection();
73
- const collection = this._db.collection(collectionName);
74
- return yield collection.aggregate(aggregation).toArray();
75
- }
76
- catch (error) {
77
- console.error('Error aggregate documents:', error);
78
- throw error;
79
- }
80
- });
81
- this.get = (collectionName, id) => __awaiter(this, void 0, void 0, function* () {
82
- try {
83
- yield this._checkConnection();
84
- const collection = this._db.collection(collectionName);
85
- return yield collection.findOne({ _id: id });
86
- }
87
- catch (error) {
88
- console.error('Error finding document by ID:', error);
89
- throw error;
90
- }
91
- });
92
- this.findOne = (collectionName, query) => __awaiter(this, void 0, void 0, function* () {
93
- try {
94
- yield this._checkConnection();
95
- const collection = this._db.collection(collectionName);
96
- return yield collection.findOne(query);
97
- }
98
- catch (error) {
99
- console.error('Error finding one document:', error);
100
- throw error;
101
- }
102
- });
103
- this.upsert = (collectionName, id, update) => __awaiter(this, void 0, void 0, function* () {
104
- try {
105
- yield this._checkConnection();
106
- const collection = this._db.collection(collectionName);
107
- const result = yield collection.findOneAndUpdate({ _id: id }, { $set: update }, { upsert: true, returnDocument: 'after' });
108
- return result;
109
- }
110
- catch (error) {
111
- console.error('Error upserting document:', error);
112
- throw error;
113
- }
114
- });
115
- this.addToList = (collectionName, id, arrayField, arrayItem) => __awaiter(this, void 0, void 0, function* () {
116
- try {
117
- yield this._checkConnection();
118
- const collection = this._db.collection(collectionName);
119
- const result = yield collection.findOneAndUpdate({ _id: id }, { $push: { [arrayField]: arrayItem } }, { returnDocument: 'after' });
120
- return result;
121
- }
122
- catch (error) {
123
- console.error('Error adding item to list:', error);
124
- throw error;
125
- }
126
- });
127
- this.doUpdate = (collectionName, id, update) => __awaiter(this, void 0, void 0, function* () {
128
- try {
129
- yield this._checkConnection();
130
- const collection = this._db.collection(collectionName);
131
- const result = yield collection.findOneAndUpdate({ _id: id }, update, { returnDocument: 'after' });
132
- return result;
133
- }
134
- catch (error) {
135
- console.error('Error adding item to list:', error);
136
- throw error;
137
- }
138
- });
139
- this._checkConnection = () => __awaiter(this, void 0, void 0, function* () {
140
- if (this._connected)
141
- return;
142
- yield this.connect();
143
- if (!this._connected)
144
- throw new Error(`Can't to perform db operation: unable to connect to the database (${this._uri})`);
145
- });
146
- }
147
- }
148
- const DatabaseEngine = new DatabaseEngineClass();
149
- exports.default = DatabaseEngine;
@@ -1,27 +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 Settings_1 = __importDefault(require("../helper/Settings"));
7
- const DATABASE_STRUCTURE = {
8
- collections: [
9
- {
10
- name: Settings_1.default.db.collections.usage,
11
- indexes: [
12
- { consumer: 1 },
13
- { startedAt: 1 },
14
- { status: 1 }
15
- ]
16
- },
17
- {
18
- name: Settings_1.default.db.collections.users,
19
- indexes: []
20
- },
21
- {
22
- name: Settings_1.default.db.collections.apiKeys,
23
- indexes: []
24
- }
25
- ]
26
- };
27
- exports.default = DATABASE_STRUCTURE;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });