@ductape/sdk 0.0.4-v5 → 0.0.4-v51
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/README.md +1 -1
- package/dist/api/services/appApi.service.d.ts +48 -2
- package/dist/api/services/appApi.service.js +101 -2
- package/dist/api/services/appApi.service.js.map +1 -1
- package/dist/api/services/pricingApi.service.d.ts +10 -0
- package/dist/api/services/pricingApi.service.js +34 -0
- package/dist/api/services/pricingApi.service.js.map +1 -0
- package/dist/api/services/processorApi.service.d.ts +12 -2
- package/dist/api/services/processorApi.service.js +12 -2
- package/dist/api/services/processorApi.service.js.map +1 -1
- package/dist/api/services/productsApi.service.d.ts +40 -1
- package/dist/api/services/productsApi.service.js +105 -1
- package/dist/api/services/productsApi.service.js.map +1 -1
- package/dist/api/services/userApi.service.js +1 -0
- package/dist/api/services/userApi.service.js.map +1 -1
- package/dist/api/services/workspaceApi.service.js +1 -0
- package/dist/api/services/workspaceApi.service.js.map +1 -1
- package/dist/api/services/workspaceSecretsApi.service.d.ts +75 -0
- package/dist/api/services/workspaceSecretsApi.service.js +62 -0
- package/dist/api/services/workspaceSecretsApi.service.js.map +1 -0
- package/dist/api/urls.d.ts +6 -1
- package/dist/api/urls.js +12 -2
- package/dist/api/urls.js.map +1 -1
- package/dist/api/utils/cache.utils.d.ts +1 -1
- package/dist/api/utils/cache.utils.js +10 -4
- package/dist/api/utils/cache.utils.js.map +1 -1
- package/dist/api/utils/strings.utils.d.ts +2 -0
- package/dist/api/utils/strings.utils.js +14 -0
- package/dist/api/utils/strings.utils.js.map +1 -1
- package/dist/apps/services/app.service.d.ts +51 -33
- package/dist/apps/services/app.service.js +488 -244
- package/dist/apps/services/app.service.js.map +1 -1
- package/dist/apps/validators/joi-validators/create.appAction.validator.d.ts +1 -2
- package/dist/apps/validators/joi-validators/create.appAction.validator.js +21 -2
- package/dist/apps/validators/joi-validators/create.appAction.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/create.appWebhook.validator.d.ts +1 -2
- package/dist/apps/validators/joi-validators/create.appWebhook.validator.js +2 -15
- package/dist/apps/validators/joi-validators/create.appWebhook.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appAction.validator.js +11 -1
- package/dist/apps/validators/joi-validators/update.appAction.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appActionResponse.validator.d.ts +1 -1
- package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js +34 -1
- package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appWebhook.validator.d.ts +1 -2
- package/dist/apps/validators/joi-validators/update.appWebhook.validator.js +2 -14
- package/dist/apps/validators/joi-validators/update.appWebhook.validator.js.map +1 -1
- package/dist/clients/pricing.client.d.ts +3 -0
- package/dist/clients/pricing.client.js +33 -0
- package/dist/clients/pricing.client.js.map +1 -0
- package/dist/database/adapters/base.adapter.d.ts +176 -0
- package/dist/database/adapters/base.adapter.js +31 -0
- package/dist/database/adapters/base.adapter.js.map +1 -0
- package/dist/database/adapters/dynamodb.adapter.d.ts +91 -0
- package/dist/database/adapters/dynamodb.adapter.js +1608 -0
- package/dist/database/adapters/dynamodb.adapter.js.map +1 -0
- package/dist/database/adapters/mongodb.adapter.d.ts +71 -0
- package/dist/database/adapters/mongodb.adapter.js +1072 -0
- package/dist/database/adapters/mongodb.adapter.js.map +1 -0
- package/dist/database/adapters/mysql.adapter.d.ts +146 -0
- package/dist/database/adapters/mysql.adapter.js +1492 -0
- package/dist/database/adapters/mysql.adapter.js.map +1 -0
- package/dist/database/adapters/postgresql.adapter.d.ts +147 -0
- package/dist/database/adapters/postgresql.adapter.js +1603 -0
- package/dist/database/adapters/postgresql.adapter.js.map +1 -0
- package/dist/database/database.service.d.ts +232 -0
- package/dist/database/database.service.js +802 -0
- package/dist/database/database.service.js.map +1 -0
- package/dist/database/index.d.ts +18 -0
- package/dist/database/index.js +98 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/types/aggregation.types.d.ts +261 -0
- package/dist/database/types/aggregation.types.js +21 -0
- package/dist/database/types/aggregation.types.js.map +1 -0
- package/dist/database/types/connection.types.d.ts +132 -0
- package/dist/database/types/connection.types.js +6 -0
- package/dist/database/types/connection.types.js.map +1 -0
- package/dist/database/types/database.types.d.ts +175 -0
- package/dist/database/types/database.types.js +75 -0
- package/dist/database/types/database.types.js.map +1 -0
- package/dist/database/types/index.d.ts +12 -0
- package/dist/database/types/index.js +37 -0
- package/dist/database/types/index.js.map +1 -0
- package/dist/database/types/index.types.d.ts +220 -0
- package/dist/database/types/index.types.js +27 -0
- package/dist/database/types/index.types.js.map +1 -0
- package/dist/database/types/migration.types.d.ts +205 -0
- package/dist/database/types/migration.types.js +44 -0
- package/dist/database/types/migration.types.js.map +1 -0
- package/dist/database/types/query.types.d.ts +305 -0
- package/dist/database/types/query.types.js +57 -0
- package/dist/database/types/query.types.js.map +1 -0
- package/dist/database/types/result.types.d.ts +220 -0
- package/dist/database/types/result.types.js +6 -0
- package/dist/database/types/result.types.js.map +1 -0
- package/dist/database/types/schema.types.d.ts +190 -0
- package/dist/database/types/schema.types.js +69 -0
- package/dist/database/types/schema.types.js.map +1 -0
- package/dist/database/utils/helpers.d.ts +66 -0
- package/dist/database/utils/helpers.js +501 -0
- package/dist/database/utils/helpers.js.map +1 -0
- package/dist/database/utils/migration.utils.d.ts +151 -0
- package/dist/database/utils/migration.utils.js +476 -0
- package/dist/database/utils/migration.utils.js.map +1 -0
- package/dist/database/utils/transaction.d.ts +64 -0
- package/dist/database/utils/transaction.js +130 -0
- package/dist/database/utils/transaction.js.map +1 -0
- package/dist/database/validators/connection.validator.d.ts +20 -0
- package/dist/database/validators/connection.validator.js +267 -0
- package/dist/database/validators/connection.validator.js.map +1 -0
- package/dist/database/validators/query.validator.d.ts +31 -0
- package/dist/database/validators/query.validator.js +305 -0
- package/dist/database/validators/query.validator.js.map +1 -0
- package/dist/database/validators/schema.validator.d.ts +31 -0
- package/dist/database/validators/schema.validator.js +334 -0
- package/dist/database/validators/schema.validator.js.map +1 -0
- package/dist/graph/adapters/arangodb.adapter.d.ts +80 -0
- package/dist/graph/adapters/arangodb.adapter.js +1393 -0
- package/dist/graph/adapters/arangodb.adapter.js.map +1 -0
- package/dist/graph/adapters/base.adapter.d.ts +228 -0
- package/dist/graph/adapters/base.adapter.js +38 -0
- package/dist/graph/adapters/base.adapter.js.map +1 -0
- package/dist/graph/adapters/index.d.ts +10 -0
- package/dist/graph/adapters/index.js +23 -0
- package/dist/graph/adapters/index.js.map +1 -0
- package/dist/graph/adapters/memgraph.adapter.d.ts +85 -0
- package/dist/graph/adapters/memgraph.adapter.js +1491 -0
- package/dist/graph/adapters/memgraph.adapter.js.map +1 -0
- package/dist/graph/adapters/neo4j.adapter.d.ts +88 -0
- package/dist/graph/adapters/neo4j.adapter.js +1861 -0
- package/dist/graph/adapters/neo4j.adapter.js.map +1 -0
- package/dist/graph/adapters/neptune.adapter.d.ts +87 -0
- package/dist/graph/adapters/neptune.adapter.js +1430 -0
- package/dist/graph/adapters/neptune.adapter.js.map +1 -0
- package/dist/graph/graph.service.d.ts +278 -0
- package/dist/graph/graph.service.js +687 -0
- package/dist/graph/graph.service.js.map +1 -0
- package/dist/graph/index.d.ts +11 -0
- package/dist/graph/index.js +42 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/types/connection.types.d.ts +158 -0
- package/dist/graph/types/connection.types.js +43 -0
- package/dist/graph/types/connection.types.js.map +1 -0
- package/dist/graph/types/graph.types.d.ts +144 -0
- package/dist/graph/types/graph.types.js +84 -0
- package/dist/graph/types/graph.types.js.map +1 -0
- package/dist/graph/types/index.d.ts +11 -0
- package/dist/graph/types/index.js +35 -0
- package/dist/graph/types/index.js.map +1 -0
- package/dist/graph/types/node.types.d.ts +193 -0
- package/dist/graph/types/node.types.js +49 -0
- package/dist/graph/types/node.types.js.map +1 -0
- package/dist/graph/types/path.types.d.ts +224 -0
- package/dist/graph/types/path.types.js +38 -0
- package/dist/graph/types/path.types.js.map +1 -0
- package/dist/graph/types/query.types.d.ts +247 -0
- package/dist/graph/types/query.types.js +23 -0
- package/dist/graph/types/query.types.js.map +1 -0
- package/dist/graph/types/relationship.types.d.ts +224 -0
- package/dist/graph/types/relationship.types.js +35 -0
- package/dist/graph/types/relationship.types.js.map +1 -0
- package/dist/graph/types/result.types.d.ts +237 -0
- package/dist/graph/types/result.types.js +7 -0
- package/dist/graph/types/result.types.js.map +1 -0
- package/dist/graph/validators/index.d.ts +81 -0
- package/dist/graph/validators/index.js +243 -0
- package/dist/graph/validators/index.js.map +1 -0
- package/dist/imports/imports.service.d.ts +3 -3
- package/dist/imports/imports.service.js +7 -7
- package/dist/imports/imports.service.js.map +1 -1
- package/dist/imports/imports.types.d.ts +8 -0
- package/dist/imports/repos/postmanV21.repo.d.ts +1 -1
- package/dist/imports/repos/postmanV21.repo.js +29 -2
- package/dist/imports/repos/postmanV21.repo.js.map +1 -1
- package/dist/index.d.ts +1244 -150
- package/dist/index.js +1309 -209
- package/dist/index.js.map +1 -1
- package/dist/inputs/inputs.service.js +2 -2
- package/dist/inputs/inputs.service.js.map +1 -1
- package/dist/inputs/utils/inputs.utils.create.js +1 -1
- package/dist/inputs/utils/inputs.utils.create.js.map +1 -1
- package/dist/logs/logs.types.d.ts +5 -0
- package/dist/logs/logs.types.js +1 -0
- package/dist/logs/logs.types.js.map +1 -1
- package/dist/parsers/index.d.ts +3 -0
- package/dist/parsers/index.js +27 -0
- package/dist/parsers/index.js.map +1 -0
- package/dist/parsers/pipelines/postman.pipelines.d.ts +15 -0
- package/dist/parsers/pipelines/postman.pipelines.js +103 -0
- package/dist/parsers/pipelines/postman.pipelines.js.map +1 -0
- package/dist/parsers/types/postman.types.d.ts +200 -0
- package/dist/parsers/types/postman.types.js +3 -0
- package/dist/parsers/types/postman.types.js.map +1 -0
- package/dist/parsers/utils/postman.utils.d.ts +12 -0
- package/dist/parsers/utils/postman.utils.js +116 -0
- package/dist/parsers/utils/postman.utils.js.map +1 -0
- package/dist/parsers/validators/postman-auth.validators.d.ts +10 -0
- package/dist/parsers/validators/postman-auth.validators.js +127 -0
- package/dist/parsers/validators/postman-auth.validators.js.map +1 -0
- package/dist/parsers/validators/postman-request.validators.d.ts +13 -0
- package/dist/parsers/validators/postman-request.validators.js +139 -0
- package/dist/parsers/validators/postman-request.validators.js.map +1 -0
- package/dist/parsers/validators/postman-response.validators.d.ts +13 -0
- package/dist/parsers/validators/postman-response.validators.js +150 -0
- package/dist/parsers/validators/postman-response.validators.js.map +1 -0
- package/dist/parsers/validators/postman-variable.validators.d.ts +14 -0
- package/dist/parsers/validators/postman-variable.validators.js +163 -0
- package/dist/parsers/validators/postman-variable.validators.js.map +1 -0
- package/dist/pricing/pricing.repo.d.ts +0 -0
- package/dist/pricing/pricing.repo.js +1 -0
- package/dist/pricing/pricing.repo.js.map +1 -0
- package/dist/pricing/pricing.service.d.ts +24 -0
- package/dist/pricing/pricing.service.js +51 -0
- package/dist/pricing/pricing.service.js.map +1 -0
- package/dist/pricing/pricing.types.d.ts +76 -0
- package/dist/pricing/pricing.types.js +21 -0
- package/dist/pricing/pricing.types.js.map +1 -0
- package/dist/pricing/utils/string.utils.d.ts +1 -0
- package/dist/pricing/utils/string.utils.js +9 -0
- package/dist/pricing/utils/string.utils.js.map +1 -0
- package/dist/processor/repos/sms.repo.d.ts +4 -4
- package/dist/processor/repos/sms.repo.js +23 -10
- package/dist/processor/repos/sms.repo.js.map +1 -1
- package/dist/processor/services/messagebrokers/kafka.service.js +0 -2
- package/dist/processor/services/messagebrokers/kafka.service.js.map +1 -1
- package/dist/processor/services/messagebrokers/rabbitmq.service.d.ts +9 -1
- package/dist/processor/services/messagebrokers/rabbitmq.service.js +40 -11
- package/dist/processor/services/messagebrokers/rabbitmq.service.js.map +1 -1
- package/dist/processor/services/processor.service.d.ts +38 -10
- package/dist/processor/services/processor.service.js +533 -248
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/processor/services/request.service.d.ts +36 -0
- package/dist/processor/services/request.service.js +304 -0
- package/dist/processor/services/request.service.js.map +1 -0
- package/dist/processor/types/request.types.d.ts +14 -0
- package/dist/processor/types/request.types.js +3 -0
- package/dist/processor/types/request.types.js.map +1 -0
- package/dist/processor/utils/processor.utils.d.ts +3 -0
- package/dist/processor/utils/processor.utils.js +84 -22
- package/dist/processor/utils/processor.utils.js.map +1 -1
- package/dist/processor/utils/request.utils.d.ts +20 -0
- package/dist/processor/utils/request.utils.js +113 -0
- package/dist/processor/utils/request.utils.js.map +1 -0
- package/dist/products/services/products.service.d.ts +114 -77
- package/dist/products/services/products.service.js +805 -362
- package/dist/products/services/products.service.js.map +1 -1
- package/dist/products/services/utils/crypt.utils.d.ts +1 -0
- package/dist/products/services/utils/crypt.utils.js +17 -0
- package/dist/products/services/utils/crypt.utils.js.map +1 -0
- package/dist/products/services/utils/functions.utils.d.ts +13 -0
- package/dist/products/services/utils/functions.utils.js +289 -0
- package/dist/products/services/utils/functions.utils.js.map +1 -0
- package/dist/products/services/utils/objects.utils.d.ts +13 -0
- package/dist/products/services/utils/objects.utils.js +89 -0
- package/dist/products/services/utils/objects.utils.js.map +1 -0
- package/dist/products/services/utils/string.utils.d.ts +12 -0
- package/dist/products/services/utils/string.utils.js +168 -0
- package/dist/products/services/utils/string.utils.js.map +1 -0
- package/dist/products/utils/string.utils.d.ts +1 -1
- package/dist/products/utils/string.utils.js +14 -2
- package/dist/products/utils/string.utils.js.map +1 -1
- package/dist/products/validators/index.d.ts +4 -1
- package/dist/products/validators/index.js +7 -1
- package/dist/products/validators/index.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.d.ts +15 -4
- package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js +501 -109
- package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productEnv.validator.js +1 -0
- package/dist/products/validators/joi-validators/create.productEnv.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productGraph.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.productGraph.validator.js +82 -0
- package/dist/products/validators/joi-validators/create.productGraph.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productGraphAction.validator.d.ts +14 -0
- package/dist/products/validators/joi-validators/create.productGraphAction.validator.js +696 -0
- package/dist/products/validators/joi-validators/create.productGraphAction.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.d.ts +4 -0
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js +58 -0
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js +1 -0
- package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js +9 -4
- package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productNotification.validator.js +5 -2
- package/dist/products/validators/joi-validators/create.productNotification.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.userAuth.validator.js +1 -0
- package/dist/products/validators/joi-validators/create.userAuth.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.dataValue.validator.js +1 -0
- package/dist/products/validators/joi-validators/update.dataValue.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.d.ts +6 -0
- package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.js +28 -26
- package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productEnv.validator.js +3 -0
- package/dist/products/validators/joi-validators/update.productEnv.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productGraph.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/update.productGraph.validator.js +87 -0
- package/dist/products/validators/joi-validators/update.productGraph.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/update.productGraphAction.validator.d.ts +7 -0
- package/dist/products/validators/joi-validators/update.productGraphAction.validator.js +72 -0
- package/dist/products/validators/joi-validators/update.productGraphAction.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/update.productMessageBrokerTopic.validator.js +1 -0
- package/dist/products/validators/joi-validators/update.productMessageBrokerTopic.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.userAuth.validator.js +1 -0
- package/dist/products/validators/joi-validators/update.userAuth.validator.js.map +1 -1
- package/dist/test/test.health.d.ts +1 -0
- package/dist/test/test.health.js +49 -0
- package/dist/test/test.health.js.map +1 -0
- package/dist/test/test.import.js +51 -4
- package/dist/test/test.import.js.map +1 -1
- package/dist/test/test.imports.js +22 -7
- package/dist/test/test.imports.js.map +1 -1
- package/dist/test/test.notifiers.d.ts +1 -0
- package/dist/test/test.notifiers.js +85 -0
- package/dist/test/test.notifiers.js.map +1 -0
- package/dist/test/test.processor.js +30 -115
- package/dist/test/test.processor.js.map +1 -1
- package/dist/test/test.products.d.ts +1 -0
- package/dist/test/test.products.js +49 -0
- package/dist/test/test.products.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/appBuilder.types.d.ts +5 -12
- package/dist/types/enums.d.ts +4 -1
- package/dist/types/enums.js +3 -0
- package/dist/types/enums.js.map +1 -1
- package/dist/types/index.types.d.ts +4 -0
- package/dist/types/pricing.types.d.ts +4 -0
- package/dist/types/pricing.types.js +3 -0
- package/dist/types/pricing.types.js.map +1 -0
- package/dist/types/processor.types.d.ts +67 -11
- package/dist/types/processor.types.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +132 -14
- package/dist/types/productsBuilder.types.js +69 -4
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/dist/types/request-tracker.interface.d.ts +0 -0
- package/dist/types/request-tracker.interface.js +1 -0
- package/dist/types/request-tracker.interface.js.map +1 -0
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.js +5 -0
- package/dist/utils/constants.js.map +1 -0
- package/package.json +17 -3
|
@@ -0,0 +1,802 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Main Database Service
|
|
4
|
+
* Entry point for all database operations
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.DatabaseService = void 0;
|
|
11
|
+
const database_types_1 = require("./types/database.types");
|
|
12
|
+
const postgresql_adapter_1 = require("./adapters/postgresql.adapter");
|
|
13
|
+
const mongodb_adapter_1 = require("./adapters/mongodb.adapter");
|
|
14
|
+
const mysql_adapter_1 = require("./adapters/mysql.adapter");
|
|
15
|
+
const dynamodb_adapter_1 = require("./adapters/dynamodb.adapter");
|
|
16
|
+
const products_service_1 = __importDefault(require("../products/services/products.service"));
|
|
17
|
+
const index_types_1 = require("../types/index.types");
|
|
18
|
+
const productsBuilder_types_1 = require("../types/productsBuilder.types");
|
|
19
|
+
const logs_service_1 = __importDefault(require("../logs/logs.service"));
|
|
20
|
+
const logs_types_1 = require("../logs/logs.types");
|
|
21
|
+
const uuid_1 = require("uuid");
|
|
22
|
+
/**
|
|
23
|
+
* Main Database Service Class
|
|
24
|
+
*/
|
|
25
|
+
class DatabaseService {
|
|
26
|
+
constructor(config) {
|
|
27
|
+
this.connections = new Map();
|
|
28
|
+
this.adapters = new Map();
|
|
29
|
+
this.activeConnection = null;
|
|
30
|
+
this.config = config;
|
|
31
|
+
this.environment = config.env_type || index_types_1.EnvType.PRODUCTION;
|
|
32
|
+
this.initializeAdapters();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Initialize database adapters
|
|
36
|
+
*/
|
|
37
|
+
initializeAdapters() {
|
|
38
|
+
// Register PostgreSQL adapter
|
|
39
|
+
this.adapters.set(database_types_1.DatabaseType.POSTGRESQL, new postgresql_adapter_1.PostgreSQLAdapter());
|
|
40
|
+
// Register MongoDB adapter
|
|
41
|
+
this.adapters.set(database_types_1.DatabaseType.MONGODB, new mongodb_adapter_1.MongoDBAdapter());
|
|
42
|
+
// Register MySQL adapter
|
|
43
|
+
this.adapters.set(database_types_1.DatabaseType.MYSQL, new mysql_adapter_1.MySQLAdapter());
|
|
44
|
+
// Register DynamoDB adapter
|
|
45
|
+
this.adapters.set(database_types_1.DatabaseType.DYNAMODB, new dynamodb_adapter_1.DynamoDBAdapter());
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get adapter for database type
|
|
49
|
+
*/
|
|
50
|
+
getAdapter(type) {
|
|
51
|
+
const adapter = this.adapters.get(type);
|
|
52
|
+
if (!adapter) {
|
|
53
|
+
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.CONNECTION_ERROR, `No adapter registered for database type: ${type}`);
|
|
54
|
+
}
|
|
55
|
+
return adapter;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Resolve connection configuration from product database
|
|
59
|
+
*/
|
|
60
|
+
async resolveProductConnection(config) {
|
|
61
|
+
var _a;
|
|
62
|
+
try {
|
|
63
|
+
// Create ProductBuilder instance
|
|
64
|
+
const productBuilder = new products_service_1.default({
|
|
65
|
+
workspace_id: this.config.workspace_id,
|
|
66
|
+
user_id: this.config.user_id,
|
|
67
|
+
public_key: this.config.public_key,
|
|
68
|
+
token: this.config.token,
|
|
69
|
+
env_type: this.environment,
|
|
70
|
+
});
|
|
71
|
+
// Initialize the product by tag
|
|
72
|
+
await productBuilder.initializeProductByTag(config.product);
|
|
73
|
+
// Fetch the database configuration
|
|
74
|
+
const database = await productBuilder.fetchDatabase(config.database);
|
|
75
|
+
if (!database) {
|
|
76
|
+
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.CONNECTION_ERROR, `Database '${config.database}' not found in product '${config.product}'`);
|
|
77
|
+
}
|
|
78
|
+
// Find the environment configuration
|
|
79
|
+
const envConfig = (_a = database.envs) === null || _a === void 0 ? void 0 : _a.find((env) => env.slug === config.env);
|
|
80
|
+
if (!envConfig) {
|
|
81
|
+
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.CONNECTION_ERROR, `Environment '${config.env}' not found for database '${config.database}'`);
|
|
82
|
+
}
|
|
83
|
+
if (!envConfig.connection_url) {
|
|
84
|
+
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.CONNECTION_ERROR, `No connection URL configured for database '${config.database}' in environment '${config.env}'`);
|
|
85
|
+
}
|
|
86
|
+
// Parse the connection URL to create a database config
|
|
87
|
+
const dbConfig = this.parseConnectionUrl(envConfig.connection_url, database.type, config.env, config.database);
|
|
88
|
+
// Get the adapter for the database type
|
|
89
|
+
const adapter = this.getAdapter(dbConfig.type);
|
|
90
|
+
// Create connection using the parsed config
|
|
91
|
+
const connectionKey = `${config.product}-${config.database}-${config.env}`;
|
|
92
|
+
let connection = this.connections.get(connectionKey);
|
|
93
|
+
if (connection && connection.isConnected()) {
|
|
94
|
+
return { connection, adapter };
|
|
95
|
+
}
|
|
96
|
+
connection = await adapter.connect(dbConfig);
|
|
97
|
+
this.connections.set(connectionKey, connection);
|
|
98
|
+
return { connection, adapter };
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (error instanceof database_types_1.DatabaseError) {
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.CONNECTION_ERROR, `Failed to resolve product connection: ${error.message}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Parse connection URL into database config
|
|
109
|
+
*/
|
|
110
|
+
parseConnectionUrl(connectionUrl, dbType, env, databaseName) {
|
|
111
|
+
try {
|
|
112
|
+
// Map product database types to DatabaseType enum
|
|
113
|
+
const typeMapping = {
|
|
114
|
+
postgresql: database_types_1.DatabaseType.POSTGRESQL,
|
|
115
|
+
postgres: database_types_1.DatabaseType.POSTGRESQL,
|
|
116
|
+
mysql: database_types_1.DatabaseType.MYSQL,
|
|
117
|
+
mongodb: database_types_1.DatabaseType.MONGODB,
|
|
118
|
+
mongo: database_types_1.DatabaseType.MONGODB,
|
|
119
|
+
dynamodb: database_types_1.DatabaseType.DYNAMODB,
|
|
120
|
+
};
|
|
121
|
+
const mappedType = typeMapping[dbType.toLowerCase()];
|
|
122
|
+
if (!mappedType) {
|
|
123
|
+
throw new Error(`Unsupported database type: ${dbType}`);
|
|
124
|
+
}
|
|
125
|
+
// Parse the connection URL based on database type
|
|
126
|
+
if (mappedType === database_types_1.DatabaseType.MONGODB) {
|
|
127
|
+
// MongoDB connection string format: mongodb://[username:password@]host[:port][/database][?options]
|
|
128
|
+
return {
|
|
129
|
+
type: database_types_1.DatabaseType.MONGODB,
|
|
130
|
+
env,
|
|
131
|
+
database: databaseName,
|
|
132
|
+
options: {
|
|
133
|
+
connectionString: connectionUrl,
|
|
134
|
+
uri: connectionUrl,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
else if (mappedType === database_types_1.DatabaseType.DYNAMODB) {
|
|
139
|
+
// DynamoDB uses region/credentials rather than connection URL
|
|
140
|
+
// Connection URL format: dynamodb://region?accessKeyId=xxx&secretAccessKey=xxx
|
|
141
|
+
const url = new URL(connectionUrl);
|
|
142
|
+
const region = url.hostname;
|
|
143
|
+
const accessKeyId = url.searchParams.get('accessKeyId') || undefined;
|
|
144
|
+
const secretAccessKey = url.searchParams.get('secretAccessKey') || undefined;
|
|
145
|
+
const sessionToken = url.searchParams.get('sessionToken') || undefined;
|
|
146
|
+
return {
|
|
147
|
+
type: database_types_1.DatabaseType.DYNAMODB,
|
|
148
|
+
env,
|
|
149
|
+
database: databaseName,
|
|
150
|
+
options: {
|
|
151
|
+
region,
|
|
152
|
+
accessKeyId,
|
|
153
|
+
secretAccessKey,
|
|
154
|
+
sessionToken,
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
// PostgreSQL/MySQL connection string format: protocol://[user:password@]host[:port]/database[?options]
|
|
160
|
+
const url = new URL(connectionUrl);
|
|
161
|
+
const urlOptions = this.parseUrlOptions(url.searchParams);
|
|
162
|
+
return {
|
|
163
|
+
type: mappedType,
|
|
164
|
+
env,
|
|
165
|
+
database: url.pathname.slice(1) || databaseName,
|
|
166
|
+
options: Object.assign({ host: url.hostname, port: url.port ? parseInt(url.port) : mappedType === database_types_1.DatabaseType.POSTGRESQL ? 5432 : 3306, user: url.username || undefined, username: url.username || undefined, password: url.password || undefined }, urlOptions),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.CONNECTION_ERROR, `Failed to parse connection URL: ${error.message}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Parse URL search parameters into options object
|
|
176
|
+
*/
|
|
177
|
+
parseUrlOptions(params) {
|
|
178
|
+
const options = {};
|
|
179
|
+
params.forEach((value, key) => {
|
|
180
|
+
// Try to parse as number or boolean
|
|
181
|
+
if (value === 'true') {
|
|
182
|
+
options[key] = true;
|
|
183
|
+
}
|
|
184
|
+
else if (value === 'false') {
|
|
185
|
+
options[key] = false;
|
|
186
|
+
}
|
|
187
|
+
else if (!isNaN(Number(value))) {
|
|
188
|
+
options[key] = Number(value);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
options[key] = value;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return options;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Resolve connection config using active connection context
|
|
198
|
+
*/
|
|
199
|
+
resolveConnectionConfig(options) {
|
|
200
|
+
// If all parameters are provided, use them
|
|
201
|
+
if (options.env && options.product && options.database) {
|
|
202
|
+
return {
|
|
203
|
+
env: options.env,
|
|
204
|
+
product: options.product,
|
|
205
|
+
database: options.database,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
// If no active connection, throw error
|
|
209
|
+
if (!this.activeConnection) {
|
|
210
|
+
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.CONNECTION_ERROR, 'No active connection. Call connect() first or provide env, product, and database parameters.');
|
|
211
|
+
}
|
|
212
|
+
// Use active connection with any overrides
|
|
213
|
+
return {
|
|
214
|
+
env: options.env || this.activeConnection.env,
|
|
215
|
+
product: options.product || this.activeConnection.product,
|
|
216
|
+
database: options.database || this.activeConnection.database,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get or create a connection
|
|
221
|
+
*/
|
|
222
|
+
async getConnection(config) {
|
|
223
|
+
// Check if it's a product-based connection
|
|
224
|
+
if ('product' in config) {
|
|
225
|
+
return this.resolveProductConnection(config);
|
|
226
|
+
}
|
|
227
|
+
// Direct connection configuration
|
|
228
|
+
const adapter = this.getAdapter(config.type);
|
|
229
|
+
const connectionKey = `${config.type}-${config.env}-${config.database}`;
|
|
230
|
+
// Check if connection already exists
|
|
231
|
+
let connection = this.connections.get(connectionKey);
|
|
232
|
+
if (connection && connection.isConnected()) {
|
|
233
|
+
return { connection, adapter };
|
|
234
|
+
}
|
|
235
|
+
// Create new connection
|
|
236
|
+
connection = await adapter.connect(config);
|
|
237
|
+
this.connections.set(connectionKey, connection);
|
|
238
|
+
return { connection, adapter };
|
|
239
|
+
}
|
|
240
|
+
// ==================== Connection Methods ====================
|
|
241
|
+
/**
|
|
242
|
+
* Connect to a database
|
|
243
|
+
*/
|
|
244
|
+
async connect(config) {
|
|
245
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
246
|
+
// Store the active connection context
|
|
247
|
+
this.activeConnection = config;
|
|
248
|
+
return adapter.testConnection(connection);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Disconnect from a database
|
|
252
|
+
*/
|
|
253
|
+
async disconnect(config) {
|
|
254
|
+
const connectionKey = `${config.product}-${config.database}-${config.env}`;
|
|
255
|
+
const connection = this.connections.get(connectionKey);
|
|
256
|
+
if (connection) {
|
|
257
|
+
await connection.disconnect();
|
|
258
|
+
this.connections.delete(connectionKey);
|
|
259
|
+
// Clear active connection if it matches
|
|
260
|
+
if (this.activeConnection &&
|
|
261
|
+
this.activeConnection.product === config.product &&
|
|
262
|
+
this.activeConnection.database === config.database &&
|
|
263
|
+
this.activeConnection.env === config.env) {
|
|
264
|
+
this.activeConnection = null;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Test database connection
|
|
270
|
+
*/
|
|
271
|
+
async testConnection(config) {
|
|
272
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
273
|
+
return adapter.testConnection(connection);
|
|
274
|
+
}
|
|
275
|
+
// ==================== Transaction Methods ====================
|
|
276
|
+
/**
|
|
277
|
+
* Begin a new transaction
|
|
278
|
+
*/
|
|
279
|
+
async beginTransaction(config, options) {
|
|
280
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
281
|
+
return adapter.beginTransaction(connection, options);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Execute operations within a transaction (callback-based)
|
|
285
|
+
*/
|
|
286
|
+
async transaction(config, callback) {
|
|
287
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
288
|
+
return adapter.executeTransaction(connection, callback, config);
|
|
289
|
+
}
|
|
290
|
+
// ==================== Query Methods ====================
|
|
291
|
+
/**
|
|
292
|
+
* Execute a SELECT query
|
|
293
|
+
*/
|
|
294
|
+
async query(options) {
|
|
295
|
+
const config = this.resolveConnectionConfig(options);
|
|
296
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
297
|
+
return adapter.query(connection, options);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Insert records
|
|
301
|
+
*/
|
|
302
|
+
async insert(options) {
|
|
303
|
+
const config = this.resolveConnectionConfig(options);
|
|
304
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
305
|
+
return adapter.insert(connection, options);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Update records
|
|
309
|
+
*/
|
|
310
|
+
async update(options) {
|
|
311
|
+
const config = this.resolveConnectionConfig(options);
|
|
312
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
313
|
+
return adapter.update(connection, options);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Delete records
|
|
317
|
+
*/
|
|
318
|
+
async delete(options) {
|
|
319
|
+
const config = this.resolveConnectionConfig(options);
|
|
320
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
321
|
+
return adapter.delete(connection, options);
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Upsert records
|
|
325
|
+
*/
|
|
326
|
+
async upsert(options) {
|
|
327
|
+
const config = this.resolveConnectionConfig(options);
|
|
328
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
329
|
+
return adapter.upsert(connection, options);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Execute raw SQL/query
|
|
333
|
+
*/
|
|
334
|
+
async raw(options) {
|
|
335
|
+
const config = this.resolveConnectionConfig(options);
|
|
336
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
337
|
+
return adapter.executeRaw(connection, options);
|
|
338
|
+
}
|
|
339
|
+
// ==================== Aggregation Methods ====================
|
|
340
|
+
/**
|
|
341
|
+
* Count records
|
|
342
|
+
*/
|
|
343
|
+
async count(options) {
|
|
344
|
+
const config = this.resolveConnectionConfig(options);
|
|
345
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
346
|
+
return adapter.count(connection, options);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Sum column values
|
|
350
|
+
*/
|
|
351
|
+
async sum(options) {
|
|
352
|
+
const config = this.resolveConnectionConfig(options);
|
|
353
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
354
|
+
return adapter.sum(connection, options);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Get average value
|
|
358
|
+
*/
|
|
359
|
+
async avg(options) {
|
|
360
|
+
const config = this.resolveConnectionConfig(options);
|
|
361
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
362
|
+
return adapter.avg(connection, options);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Get minimum value
|
|
366
|
+
*/
|
|
367
|
+
async min(options) {
|
|
368
|
+
const config = this.resolveConnectionConfig(options);
|
|
369
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
370
|
+
return adapter.min(connection, options);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Get maximum value
|
|
374
|
+
*/
|
|
375
|
+
async max(options) {
|
|
376
|
+
const config = this.resolveConnectionConfig(options);
|
|
377
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
378
|
+
return adapter.max(connection, options);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Group by and aggregate
|
|
382
|
+
*/
|
|
383
|
+
async groupBy(options) {
|
|
384
|
+
const config = this.resolveConnectionConfig(options);
|
|
385
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
386
|
+
return adapter.groupBy(connection, options);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Multiple aggregations
|
|
390
|
+
*/
|
|
391
|
+
async aggregate(options) {
|
|
392
|
+
const config = this.resolveConnectionConfig(options);
|
|
393
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
394
|
+
return adapter.aggregate(connection, options);
|
|
395
|
+
}
|
|
396
|
+
// ==================== Schema Methods ====================
|
|
397
|
+
/**
|
|
398
|
+
* Create a table
|
|
399
|
+
*/
|
|
400
|
+
async createTable(config, schema, options) {
|
|
401
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
402
|
+
return adapter.createTable(connection, schema, options);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Drop a table
|
|
406
|
+
*/
|
|
407
|
+
async dropTable(config, tableName) {
|
|
408
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
409
|
+
return adapter.dropTable(connection, tableName);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Alter a table
|
|
413
|
+
*/
|
|
414
|
+
async alterTable(config, tableName, alterations, options) {
|
|
415
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
416
|
+
return adapter.alterTable(connection, tableName, alterations, options);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Get table schema
|
|
420
|
+
*/
|
|
421
|
+
async getTableSchema(config, tableName) {
|
|
422
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
423
|
+
return adapter.getTableSchema(connection, tableName);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* List all tables
|
|
427
|
+
*/
|
|
428
|
+
async listTables(config) {
|
|
429
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
430
|
+
return adapter.listTables(connection);
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Check if table exists
|
|
434
|
+
*/
|
|
435
|
+
async tableExists(config, tableName) {
|
|
436
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
437
|
+
return adapter.tableExists(connection, tableName);
|
|
438
|
+
}
|
|
439
|
+
// ==================== Index Methods ====================
|
|
440
|
+
/**
|
|
441
|
+
* Create an index
|
|
442
|
+
*/
|
|
443
|
+
async createIndex(options) {
|
|
444
|
+
const config = this.resolveConnectionConfig(options);
|
|
445
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
446
|
+
return adapter.createIndex(connection, options);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Drop an index
|
|
450
|
+
*/
|
|
451
|
+
async dropIndex(options) {
|
|
452
|
+
const config = this.resolveConnectionConfig(options);
|
|
453
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
454
|
+
return adapter.dropIndex(connection, options);
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* List indexes
|
|
458
|
+
*/
|
|
459
|
+
async listIndexes(options) {
|
|
460
|
+
const config = this.resolveConnectionConfig(options);
|
|
461
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
462
|
+
return adapter.listIndexes(connection, options);
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Get index statistics
|
|
466
|
+
*/
|
|
467
|
+
async getIndexStatistics(config, tableName, indexName) {
|
|
468
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
469
|
+
return adapter.getIndexStatistics(connection, tableName, indexName);
|
|
470
|
+
}
|
|
471
|
+
// ==================== Migration Methods ====================
|
|
472
|
+
/**
|
|
473
|
+
* Run migrations
|
|
474
|
+
*/
|
|
475
|
+
async runMigration(migration, options) {
|
|
476
|
+
const config = this.resolveConnectionConfig(options);
|
|
477
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
478
|
+
return adapter.runMigration(connection, migration, options);
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Rollback migration
|
|
482
|
+
*/
|
|
483
|
+
async rollbackMigration(migration, options) {
|
|
484
|
+
const config = this.resolveConnectionConfig(options);
|
|
485
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
486
|
+
return adapter.rollbackMigration(connection, migration, options);
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Get migration history
|
|
490
|
+
*/
|
|
491
|
+
async getMigrationHistory(options) {
|
|
492
|
+
const config = this.resolveConnectionConfig(options);
|
|
493
|
+
const { connection, adapter } = await this.getConnection(config);
|
|
494
|
+
return adapter.getMigrationHistory(connection, options);
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Get migration status
|
|
498
|
+
*/
|
|
499
|
+
async getMigrationStatus(options) {
|
|
500
|
+
// Get migration history from database
|
|
501
|
+
const history = await this.getMigrationHistory(options);
|
|
502
|
+
const appliedTags = new Set(history.map((h) => h.tag));
|
|
503
|
+
// Get defined migrations (from options or empty array)
|
|
504
|
+
const definedMigrations = options.definedMigrations || [];
|
|
505
|
+
// Calculate pending migrations
|
|
506
|
+
const pendingMigrations = definedMigrations
|
|
507
|
+
.filter((m) => !appliedTags.has(m.tag))
|
|
508
|
+
.map((m) => ({
|
|
509
|
+
tag: m.tag,
|
|
510
|
+
name: m.name,
|
|
511
|
+
description: m.description,
|
|
512
|
+
createdAt: m.createdAt || new Date(),
|
|
513
|
+
dependencies: m.dependencies,
|
|
514
|
+
}));
|
|
515
|
+
// Get last applied migration
|
|
516
|
+
const lastApplied = history.length > 0 ? history[0] : undefined;
|
|
517
|
+
return {
|
|
518
|
+
total: definedMigrations.length,
|
|
519
|
+
completed: history.length,
|
|
520
|
+
pending: pendingMigrations.length,
|
|
521
|
+
failed: 0, // Would need to track failed migrations separately
|
|
522
|
+
lastApplied,
|
|
523
|
+
pendingMigrations,
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
// ==================== Execute Action Methods ====================
|
|
527
|
+
/**
|
|
528
|
+
* Execute a database action by tag
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```typescript
|
|
532
|
+
* await ductape.database.execute({
|
|
533
|
+
* product: 'my-product',
|
|
534
|
+
* env: 'production',
|
|
535
|
+
* database: 'my-database',
|
|
536
|
+
* action: 'get-users',
|
|
537
|
+
* input: { limit: 10, offset: 0 }
|
|
538
|
+
* });
|
|
539
|
+
* ```
|
|
540
|
+
*/
|
|
541
|
+
async execute(options) {
|
|
542
|
+
const { product, env, database, action: actionTag, input = {} } = options;
|
|
543
|
+
const startTime = Date.now();
|
|
544
|
+
const processId = (0, uuid_1.v4)();
|
|
545
|
+
let logService = null;
|
|
546
|
+
let productTag = product;
|
|
547
|
+
try {
|
|
548
|
+
// Create ProductBuilder instance to fetch action
|
|
549
|
+
const productBuilder = new products_service_1.default({
|
|
550
|
+
workspace_id: this.config.workspace_id,
|
|
551
|
+
user_id: this.config.user_id,
|
|
552
|
+
public_key: this.config.public_key,
|
|
553
|
+
token: this.config.token,
|
|
554
|
+
env_type: this.environment,
|
|
555
|
+
redis_client: this.config.redis_client,
|
|
556
|
+
});
|
|
557
|
+
// Initialize the product
|
|
558
|
+
await productBuilder.initializeProductByTag(product);
|
|
559
|
+
productTag = product; // The product parameter is already the tag
|
|
560
|
+
// Initialize LogsService for fire-and-forget logging
|
|
561
|
+
logService = new logs_service_1.default({
|
|
562
|
+
workspace_id: this.config.workspace_id,
|
|
563
|
+
user_id: this.config.user_id,
|
|
564
|
+
public_key: this.config.public_key,
|
|
565
|
+
token: this.config.token,
|
|
566
|
+
product_id: productBuilder.fetchProductId(),
|
|
567
|
+
env_type: this.environment,
|
|
568
|
+
app_id: null,
|
|
569
|
+
});
|
|
570
|
+
// Fetch the database action
|
|
571
|
+
const fullActionTag = `${database}:${actionTag}`;
|
|
572
|
+
const dbAction = await productBuilder.fetchDatabaseAction(fullActionTag);
|
|
573
|
+
if (!dbAction) {
|
|
574
|
+
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `Database action '${fullActionTag}' not found in product '${product}'`);
|
|
575
|
+
}
|
|
576
|
+
// Get connection to the database
|
|
577
|
+
const connectionConfig = {
|
|
578
|
+
product,
|
|
579
|
+
env,
|
|
580
|
+
database,
|
|
581
|
+
};
|
|
582
|
+
const { connection, adapter } = await this.getConnection(connectionConfig);
|
|
583
|
+
// Process the action template with input parameters
|
|
584
|
+
const processedQuery = this.processActionTemplate(dbAction, input);
|
|
585
|
+
// Execute based on action type
|
|
586
|
+
let result;
|
|
587
|
+
switch (dbAction.type) {
|
|
588
|
+
// Query operations (READ is legacy alias for QUERY)
|
|
589
|
+
case productsBuilder_types_1.DatabaseActionTypes.QUERY:
|
|
590
|
+
case productsBuilder_types_1.DatabaseActionTypes.READ:
|
|
591
|
+
result = await adapter.query(connection, Object.assign({ table: dbAction.tableName }, processedQuery)).then(res => res.data);
|
|
592
|
+
break;
|
|
593
|
+
// Insert operations (CREATE is legacy alias for INSERT)
|
|
594
|
+
case productsBuilder_types_1.DatabaseActionTypes.INSERT:
|
|
595
|
+
case productsBuilder_types_1.DatabaseActionTypes.CREATE:
|
|
596
|
+
result = await adapter.insert(connection, {
|
|
597
|
+
table: dbAction.tableName,
|
|
598
|
+
data: processedQuery.data || input,
|
|
599
|
+
returning: true,
|
|
600
|
+
}).then(res => res.data);
|
|
601
|
+
break;
|
|
602
|
+
case productsBuilder_types_1.DatabaseActionTypes.UPDATE:
|
|
603
|
+
result = await adapter.update(connection, {
|
|
604
|
+
table: dbAction.tableName,
|
|
605
|
+
data: processedQuery.data || input,
|
|
606
|
+
where: processedQuery.where,
|
|
607
|
+
returning: true,
|
|
608
|
+
}).then(res => res.data);
|
|
609
|
+
break;
|
|
610
|
+
case productsBuilder_types_1.DatabaseActionTypes.DELETE:
|
|
611
|
+
result = await adapter.delete(connection, {
|
|
612
|
+
table: dbAction.tableName,
|
|
613
|
+
where: processedQuery.where,
|
|
614
|
+
returning: true,
|
|
615
|
+
}).then(res => res.data);
|
|
616
|
+
break;
|
|
617
|
+
case productsBuilder_types_1.DatabaseActionTypes.UPSERT:
|
|
618
|
+
result = await adapter.upsert(connection, {
|
|
619
|
+
table: dbAction.tableName,
|
|
620
|
+
data: processedQuery.data || input,
|
|
621
|
+
uniqueColumns: processedQuery.uniqueColumns || processedQuery.conflictKeys || [],
|
|
622
|
+
updateColumns: processedQuery.updateColumns,
|
|
623
|
+
returning: true,
|
|
624
|
+
}).then(res => res.data);
|
|
625
|
+
break;
|
|
626
|
+
// Aggregation operations
|
|
627
|
+
case productsBuilder_types_1.DatabaseActionTypes.COUNT:
|
|
628
|
+
result = await adapter.count(connection, {
|
|
629
|
+
table: dbAction.tableName,
|
|
630
|
+
where: processedQuery.where,
|
|
631
|
+
column: processedQuery.column,
|
|
632
|
+
distinct: processedQuery.distinct,
|
|
633
|
+
});
|
|
634
|
+
break;
|
|
635
|
+
case productsBuilder_types_1.DatabaseActionTypes.SUM:
|
|
636
|
+
result = await adapter.sum(connection, {
|
|
637
|
+
table: dbAction.tableName,
|
|
638
|
+
column: processedQuery.column,
|
|
639
|
+
where: processedQuery.where,
|
|
640
|
+
});
|
|
641
|
+
break;
|
|
642
|
+
case productsBuilder_types_1.DatabaseActionTypes.AVERAGE:
|
|
643
|
+
result = await adapter.avg(connection, {
|
|
644
|
+
table: dbAction.tableName,
|
|
645
|
+
column: processedQuery.column,
|
|
646
|
+
where: processedQuery.where,
|
|
647
|
+
});
|
|
648
|
+
break;
|
|
649
|
+
case productsBuilder_types_1.DatabaseActionTypes.MINIMUM:
|
|
650
|
+
result = await adapter.min(connection, {
|
|
651
|
+
table: dbAction.tableName,
|
|
652
|
+
column: processedQuery.column,
|
|
653
|
+
where: processedQuery.where,
|
|
654
|
+
});
|
|
655
|
+
break;
|
|
656
|
+
case productsBuilder_types_1.DatabaseActionTypes.MAXIMUM:
|
|
657
|
+
result = await adapter.max(connection, {
|
|
658
|
+
table: dbAction.tableName,
|
|
659
|
+
column: processedQuery.column,
|
|
660
|
+
where: processedQuery.where,
|
|
661
|
+
});
|
|
662
|
+
break;
|
|
663
|
+
case productsBuilder_types_1.DatabaseActionTypes.GROUP_BY:
|
|
664
|
+
result = await adapter.groupBy(connection, {
|
|
665
|
+
table: dbAction.tableName,
|
|
666
|
+
groupBy: processedQuery.groupBy || [],
|
|
667
|
+
aggregate: processedQuery.aggregate,
|
|
668
|
+
where: processedQuery.where,
|
|
669
|
+
having: processedQuery.having,
|
|
670
|
+
orderBy: processedQuery.orderBy,
|
|
671
|
+
limit: processedQuery.limit,
|
|
672
|
+
offset: processedQuery.offset,
|
|
673
|
+
});
|
|
674
|
+
break;
|
|
675
|
+
case productsBuilder_types_1.DatabaseActionTypes.AGGREGATE:
|
|
676
|
+
result = await adapter.aggregate(connection, {
|
|
677
|
+
table: dbAction.tableName,
|
|
678
|
+
operations: processedQuery.operations || {},
|
|
679
|
+
where: processedQuery.where,
|
|
680
|
+
groupBy: processedQuery.groupBy,
|
|
681
|
+
having: processedQuery.having,
|
|
682
|
+
});
|
|
683
|
+
break;
|
|
684
|
+
// Raw SQL query
|
|
685
|
+
case productsBuilder_types_1.DatabaseActionTypes.RAW_SQL:
|
|
686
|
+
result = await adapter.executeRaw(connection, {
|
|
687
|
+
query: processedQuery.query || processedQuery.raw,
|
|
688
|
+
params: processedQuery.params,
|
|
689
|
+
namedParams: processedQuery.namedParams,
|
|
690
|
+
}).then(res => res.rows);
|
|
691
|
+
break;
|
|
692
|
+
default:
|
|
693
|
+
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `Unsupported action type: ${dbAction.type}`);
|
|
694
|
+
}
|
|
695
|
+
// Fire-and-forget success logging
|
|
696
|
+
if (logService) {
|
|
697
|
+
logService.add({
|
|
698
|
+
process_id: processId,
|
|
699
|
+
product_tag: productTag,
|
|
700
|
+
env,
|
|
701
|
+
type: logs_types_1.LogEventTypes.DB_ACTION,
|
|
702
|
+
action: fullActionTag,
|
|
703
|
+
status: logs_types_1.LogEventStatus.SUCCESS,
|
|
704
|
+
start: startTime,
|
|
705
|
+
end: Date.now(),
|
|
706
|
+
data: { action: actionTag, database, actionType: dbAction.type },
|
|
707
|
+
});
|
|
708
|
+
logService.publish().catch(() => { }); // Silent fail - don't affect main request
|
|
709
|
+
}
|
|
710
|
+
return result;
|
|
711
|
+
}
|
|
712
|
+
catch (error) {
|
|
713
|
+
// Fire-and-forget failure logging
|
|
714
|
+
if (logService) {
|
|
715
|
+
logService.add({
|
|
716
|
+
process_id: processId,
|
|
717
|
+
product_tag: productTag,
|
|
718
|
+
env,
|
|
719
|
+
type: logs_types_1.LogEventTypes.DB_ACTION,
|
|
720
|
+
action: `${database}:${actionTag}`,
|
|
721
|
+
status: logs_types_1.LogEventStatus.FAIL,
|
|
722
|
+
start: startTime,
|
|
723
|
+
end: Date.now(),
|
|
724
|
+
data: { action: actionTag, database, error: error.message },
|
|
725
|
+
});
|
|
726
|
+
logService.publish().catch(() => { }); // Silent fail - don't affect main request
|
|
727
|
+
}
|
|
728
|
+
if (error instanceof database_types_1.DatabaseError) {
|
|
729
|
+
throw error;
|
|
730
|
+
}
|
|
731
|
+
throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `Failed to execute database action: ${error.message}`);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Process action template with input parameters
|
|
736
|
+
*/
|
|
737
|
+
processActionTemplate(action, input) {
|
|
738
|
+
let template = action.template;
|
|
739
|
+
// If template is a string, parse it as JSON
|
|
740
|
+
if (typeof template === 'string') {
|
|
741
|
+
try {
|
|
742
|
+
template = JSON.parse(template);
|
|
743
|
+
}
|
|
744
|
+
catch (_a) {
|
|
745
|
+
// If it's not valid JSON, return it as a raw query
|
|
746
|
+
return { raw: this.replaceTemplateParams(template, input) };
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
// Deep clone to avoid mutation
|
|
750
|
+
const processed = JSON.parse(JSON.stringify(template));
|
|
751
|
+
// Replace parameters in the template
|
|
752
|
+
return this.replaceParamsInObject(processed, input);
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Replace template parameters with actual values
|
|
756
|
+
*/
|
|
757
|
+
replaceTemplateParams(template, params) {
|
|
758
|
+
let result = template;
|
|
759
|
+
for (const [key, value] of Object.entries(params)) {
|
|
760
|
+
const placeholder = new RegExp(`\\{\\{${key}\\}\\}`, 'g');
|
|
761
|
+
result = result.replace(placeholder, typeof value === 'string' ? value : JSON.stringify(value));
|
|
762
|
+
}
|
|
763
|
+
return result;
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Recursively replace parameters in an object
|
|
767
|
+
*/
|
|
768
|
+
replaceParamsInObject(obj, params) {
|
|
769
|
+
if (typeof obj === 'string') {
|
|
770
|
+
// Check if it's a parameter placeholder
|
|
771
|
+
const match = obj.match(/^\{\{(\w+)\}\}$/);
|
|
772
|
+
if (match) {
|
|
773
|
+
const paramName = match[1];
|
|
774
|
+
return params[paramName] !== undefined ? params[paramName] : obj;
|
|
775
|
+
}
|
|
776
|
+
// Replace inline parameters
|
|
777
|
+
return this.replaceTemplateParams(obj, params);
|
|
778
|
+
}
|
|
779
|
+
if (Array.isArray(obj)) {
|
|
780
|
+
return obj.map(item => this.replaceParamsInObject(item, params));
|
|
781
|
+
}
|
|
782
|
+
if (obj && typeof obj === 'object') {
|
|
783
|
+
const result = {};
|
|
784
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
785
|
+
result[key] = this.replaceParamsInObject(value, params);
|
|
786
|
+
}
|
|
787
|
+
return result;
|
|
788
|
+
}
|
|
789
|
+
return obj;
|
|
790
|
+
}
|
|
791
|
+
// ==================== Utility Methods ====================
|
|
792
|
+
/**
|
|
793
|
+
* Close all connections
|
|
794
|
+
*/
|
|
795
|
+
async closeAll() {
|
|
796
|
+
const closePromises = Array.from(this.connections.values()).map((connection) => connection.disconnect());
|
|
797
|
+
await Promise.all(closePromises);
|
|
798
|
+
this.connections.clear();
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
exports.DatabaseService = DatabaseService;
|
|
802
|
+
//# sourceMappingURL=database.service.js.map
|