@ductape/sdk 0.0.4-v6 → 0.0.4-v60
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/dist/agents/agent-context.d.ts +98 -0
- package/dist/agents/agent-context.js +588 -0
- package/dist/agents/agent-context.js.map +1 -0
- package/dist/agents/agent-executor.d.ts +180 -0
- package/dist/agents/agent-executor.js +715 -0
- package/dist/agents/agent-executor.js.map +1 -0
- package/dist/agents/agents.service.d.ts +310 -0
- package/dist/agents/agents.service.js +1249 -0
- package/dist/agents/agents.service.js.map +1 -0
- package/dist/agents/index.d.ts +55 -0
- package/dist/agents/index.js +110 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/memory-manager.d.ts +182 -0
- package/dist/agents/memory-manager.js +383 -0
- package/dist/agents/memory-manager.js.map +1 -0
- package/dist/agents/tool-registry.d.ts +141 -0
- package/dist/agents/tool-registry.js +355 -0
- package/dist/agents/tool-registry.js.map +1 -0
- package/dist/agents/types/agents.types.d.ts +1227 -0
- package/dist/agents/types/agents.types.js +12 -0
- package/dist/agents/types/agents.types.js.map +1 -0
- package/dist/agents/types/index.d.ts +6 -0
- package/dist/agents/types/index.js +23 -0
- package/dist/agents/types/index.js.map +1 -0
- package/dist/agents/vector-store-adapter.d.ts +108 -0
- package/dist/agents/vector-store-adapter.js +213 -0
- package/dist/agents/vector-store-adapter.js.map +1 -0
- package/dist/api/services/appApi.service.d.ts +51 -5
- package/dist/api/services/appApi.service.js +101 -3
- 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 +334 -2
- package/dist/api/services/processorApi.service.js +264 -2
- package/dist/api/services/processorApi.service.js.map +1 -1
- package/dist/api/services/productsApi.service.d.ts +108 -1
- package/dist/api/services/productsApi.service.js +150 -3
- package/dist/api/services/productsApi.service.js.map +1 -1
- package/dist/api/services/resilienceApi.service.d.ts +106 -0
- package/dist/api/services/resilienceApi.service.js +224 -0
- package/dist/api/services/resilienceApi.service.js.map +1 -0
- package/dist/api/services/secretsApi.service.d.ts +50 -0
- package/dist/api/services/secretsApi.service.js +124 -0
- package/dist/api/services/secretsApi.service.js.map +1 -0
- package/dist/api/services/workflowApi.service.d.ts +199 -0
- package/dist/api/services/workflowApi.service.js +183 -0
- package/dist/api/services/workflowApi.service.js.map +1 -0
- package/dist/api/services/workspaceApi.service.d.ts +8 -0
- package/dist/api/services/workspaceApi.service.js +20 -0
- package/dist/api/services/workspaceApi.service.js.map +1 -1
- package/dist/api/urls.d.ts +65 -1
- package/dist/api/urls.js +90 -18
- package/dist/api/urls.js.map +1 -1
- package/dist/api/utils/auth.utils.d.ts +1 -3
- package/dist/api/utils/auth.utils.js.map +1 -1
- package/dist/api/utils/cache.utils.d.ts +1 -1
- package/dist/api/utils/cache.utils.js +2 -2
- 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 +41 -33
- package/dist/apps/services/app.service.js +472 -184
- package/dist/apps/services/app.service.js.map +1 -1
- package/dist/apps/utils/auth-context-manager.d.ts +137 -0
- package/dist/apps/utils/auth-context-manager.js +248 -0
- package/dist/apps/utils/auth-context-manager.js.map +1 -0
- package/dist/apps/utils/credential-manager.d.ts +128 -0
- package/dist/apps/utils/credential-manager.js +199 -0
- package/dist/apps/utils/credential-manager.js.map +1 -0
- package/dist/apps/utils/index.d.ts +10 -0
- package/dist/apps/utils/index.js +54 -0
- package/dist/apps/utils/index.js.map +1 -0
- package/dist/apps/utils/input-helpers.d.ts +67 -0
- package/dist/apps/utils/input-helpers.js +185 -0
- package/dist/apps/utils/input-helpers.js.map +1 -0
- package/dist/apps/utils/input-resolver.d.ts +165 -0
- package/dist/apps/utils/input-resolver.js +477 -0
- package/dist/apps/utils/input-resolver.js.map +1 -0
- package/dist/apps/utils/oauth-manager.d.ts +196 -0
- package/dist/apps/utils/oauth-manager.js +429 -0
- package/dist/apps/utils/oauth-manager.js.map +1 -0
- 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/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/bin.d.ts +26 -0
- package/dist/bin.js +28 -0
- package/dist/bin.js.map +1 -0
- package/dist/brokers/brokers.service.d.ts +289 -0
- package/dist/brokers/brokers.service.js +722 -0
- package/dist/brokers/brokers.service.js.map +1 -0
- package/dist/brokers/index.d.ts +46 -0
- package/dist/brokers/index.js +83 -0
- package/dist/brokers/index.js.map +1 -0
- package/dist/brokers/types/index.d.ts +314 -0
- package/dist/brokers/types/index.js +8 -0
- package/dist/brokers/types/index.js.map +1 -0
- package/dist/brokers/utils/broker.util.d.ts +33 -0
- package/dist/brokers/utils/broker.util.js +125 -0
- package/dist/brokers/utils/broker.util.js.map +1 -0
- package/dist/brokers/utils/providers/aws-sqs.service.d.ts +16 -0
- package/dist/brokers/utils/providers/aws-sqs.service.js +71 -0
- package/dist/brokers/utils/providers/aws-sqs.service.js.map +1 -0
- package/dist/brokers/utils/providers/google-pubsub.service.d.ts +16 -0
- package/dist/brokers/utils/providers/google-pubsub.service.js +43 -0
- package/dist/brokers/utils/providers/google-pubsub.service.js.map +1 -0
- package/dist/brokers/utils/providers/index.d.ts +6 -0
- package/dist/brokers/utils/providers/index.js +16 -0
- package/dist/brokers/utils/providers/index.js.map +1 -0
- package/dist/brokers/utils/providers/kafka.service.d.ts +23 -0
- package/dist/brokers/utils/providers/kafka.service.js +131 -0
- package/dist/brokers/utils/providers/kafka.service.js.map +1 -0
- package/dist/brokers/utils/providers/nats.service.d.ts +18 -0
- package/dist/brokers/utils/providers/nats.service.js +63 -0
- package/dist/brokers/utils/providers/nats.service.js.map +1 -0
- package/dist/brokers/utils/providers/rabbitmq.service.d.ts +15 -0
- package/dist/brokers/utils/providers/rabbitmq.service.js +151 -0
- package/dist/brokers/utils/providers/rabbitmq.service.js.map +1 -0
- package/dist/brokers/utils/providers/redis.service.d.ts +18 -0
- package/dist/brokers/utils/providers/redis.service.js +93 -0
- package/dist/brokers/utils/providers/redis.service.js.map +1 -0
- package/dist/cache/cache.manager.d.ts +159 -0
- package/dist/cache/cache.manager.js +265 -0
- package/dist/cache/cache.manager.js.map +1 -0
- package/dist/cache/cache.service.d.ts +186 -0
- package/dist/cache/cache.service.js +437 -0
- package/dist/cache/cache.service.js.map +1 -0
- package/dist/cache/index.d.ts +52 -0
- package/dist/cache/index.js +79 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/types/index.d.ts +106 -0
- package/dist/cache/types/index.js +6 -0
- package/dist/cache/types/index.js.map +1 -0
- 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/actions/action-manager.d.ts +170 -0
- package/dist/database/actions/action-manager.js +465 -0
- package/dist/database/actions/action-manager.js.map +1 -0
- package/dist/database/actions/index.d.ts +6 -0
- package/dist/database/actions/index.js +13 -0
- package/dist/database/actions/index.js.map +1 -0
- package/dist/database/adapters/adapter.factory.d.ts +62 -0
- package/dist/database/adapters/adapter.factory.js +97 -0
- package/dist/database/adapters/adapter.factory.js.map +1 -0
- package/dist/database/adapters/base.adapter.d.ts +393 -0
- package/dist/database/adapters/base.adapter.js +150 -0
- package/dist/database/adapters/base.adapter.js.map +1 -0
- package/dist/database/adapters/cassandra.adapter.d.ts +91 -0
- package/dist/database/adapters/cassandra.adapter.js +1075 -0
- package/dist/database/adapters/cassandra.adapter.js.map +1 -0
- package/dist/database/adapters/dynamodb.adapter.d.ts +109 -0
- package/dist/database/adapters/dynamodb.adapter.js +1534 -0
- package/dist/database/adapters/dynamodb.adapter.js.map +1 -0
- package/dist/database/adapters/index.d.ts +11 -0
- package/dist/database/adapters/index.js +27 -0
- package/dist/database/adapters/index.js.map +1 -0
- package/dist/database/adapters/mariadb.adapter.d.ts +100 -0
- package/dist/database/adapters/mariadb.adapter.js +247 -0
- package/dist/database/adapters/mariadb.adapter.js.map +1 -0
- package/dist/database/adapters/mongodb.adapter.d.ts +120 -0
- package/dist/database/adapters/mongodb.adapter.js +1253 -0
- package/dist/database/adapters/mongodb.adapter.js.map +1 -0
- package/dist/database/adapters/mysql.adapter.d.ts +85 -0
- package/dist/database/adapters/mysql.adapter.js +1313 -0
- package/dist/database/adapters/mysql.adapter.js.map +1 -0
- package/dist/database/adapters/postgresql.adapter.d.ts +88 -0
- package/dist/database/adapters/postgresql.adapter.js +1434 -0
- package/dist/database/adapters/postgresql.adapter.js.map +1 -0
- package/dist/database/databases.service.d.ts +1388 -0
- package/dist/database/databases.service.js +2821 -0
- package/dist/database/databases.service.js.map +1 -0
- package/dist/database/index.d.ts +46 -0
- package/dist/database/index.js +109 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/migrations/index.d.ts +6 -0
- package/dist/database/migrations/index.js +12 -0
- package/dist/database/migrations/index.js.map +1 -0
- package/dist/database/migrations/migration-engine.d.ts +132 -0
- package/dist/database/migrations/migration-engine.js +1356 -0
- package/dist/database/migrations/migration-engine.js.map +1 -0
- package/dist/database/operators/aggregation-builder.d.ts +67 -0
- package/dist/database/operators/aggregation-builder.js +841 -0
- package/dist/database/operators/aggregation-builder.js.map +1 -0
- package/dist/database/operators/index.d.ts +7 -0
- package/dist/database/operators/index.js +15 -0
- package/dist/database/operators/index.js.map +1 -0
- package/dist/database/operators/query-builder.d.ts +59 -0
- package/dist/database/operators/query-builder.js +397 -0
- package/dist/database/operators/query-builder.js.map +1 -0
- package/dist/database/presave/decrypt.d.ts +25 -0
- package/dist/database/presave/decrypt.js +146 -0
- package/dist/database/presave/decrypt.js.map +1 -0
- package/dist/database/presave/index.d.ts +9 -0
- package/dist/database/presave/index.js +18 -0
- package/dist/database/presave/index.js.map +1 -0
- package/dist/database/presave/presave-processor.d.ts +148 -0
- package/dist/database/presave/presave-processor.js +702 -0
- package/dist/database/presave/presave-processor.js.map +1 -0
- package/dist/database/schema/index.d.ts +7 -0
- package/dist/database/schema/index.js +13 -0
- package/dist/database/schema/index.js.map +1 -0
- package/dist/database/schema/schema-manager.d.ts +258 -0
- package/dist/database/schema/schema-manager.js +637 -0
- package/dist/database/schema/schema-manager.js.map +1 -0
- package/dist/database/transactions/index.d.ts +6 -0
- package/dist/database/transactions/index.js +13 -0
- package/dist/database/transactions/index.js.map +1 -0
- package/dist/database/transactions/transaction-manager.d.ts +113 -0
- package/dist/database/transactions/transaction-manager.js +344 -0
- package/dist/database/transactions/transaction-manager.js.map +1 -0
- package/dist/database/triggers/index.d.ts +7 -0
- package/dist/database/triggers/index.js +14 -0
- package/dist/database/triggers/index.js.map +1 -0
- package/dist/database/triggers/trigger-processor.d.ts +239 -0
- package/dist/database/triggers/trigger-processor.js +1034 -0
- package/dist/database/triggers/trigger-processor.js.map +1 -0
- package/dist/database/types/action.interface.d.ts +148 -0
- package/dist/database/types/action.interface.js +6 -0
- package/dist/database/types/action.interface.js.map +1 -0
- package/dist/database/types/aggregation.interface.d.ts +185 -0
- package/dist/database/types/aggregation.interface.js +6 -0
- package/dist/database/types/aggregation.interface.js.map +1 -0
- package/dist/database/types/connection.interface.d.ts +137 -0
- package/dist/database/types/connection.interface.js +6 -0
- package/dist/database/types/connection.interface.js.map +1 -0
- package/dist/database/types/enums.d.ts +195 -0
- package/dist/database/types/enums.js +244 -0
- package/dist/database/types/enums.js.map +1 -0
- package/dist/database/types/index.d.ts +14 -0
- package/dist/database/types/index.js +31 -0
- package/dist/database/types/index.js.map +1 -0
- package/dist/database/types/migration.interface.d.ts +686 -0
- package/dist/database/types/migration.interface.js +9 -0
- package/dist/database/types/migration.interface.js.map +1 -0
- package/dist/database/types/presave.interface.d.ts +292 -0
- package/dist/database/types/presave.interface.js +60 -0
- package/dist/database/types/presave.interface.js.map +1 -0
- package/dist/database/types/query.interface.d.ts +205 -0
- package/dist/database/types/query.interface.js +6 -0
- package/dist/database/types/query.interface.js.map +1 -0
- package/dist/database/types/schema.interface.d.ts +398 -0
- package/dist/database/types/schema.interface.js +6 -0
- package/dist/database/types/schema.interface.js.map +1 -0
- package/dist/database/types/transaction.interface.d.ts +84 -0
- package/dist/database/types/transaction.interface.js +6 -0
- package/dist/database/types/transaction.interface.js.map +1 -0
- package/dist/database/types/trigger.interface.d.ts +612 -0
- package/dist/database/types/trigger.interface.js +121 -0
- package/dist/database/types/trigger.interface.js.map +1 -0
- package/dist/database/types/write.interface.d.ts +216 -0
- package/dist/database/types/write.interface.js +6 -0
- package/dist/database/types/write.interface.js.map +1 -0
- package/dist/database/utils/database-error.d.ts +96 -0
- package/dist/database/utils/database-error.js +221 -0
- package/dist/database/utils/database-error.js.map +1 -0
- package/dist/database/utils/index.d.ts +6 -0
- package/dist/database/utils/index.js +11 -0
- package/dist/database/utils/index.js.map +1 -0
- package/dist/graph/adapters/adapter.factory.d.ts +47 -0
- package/dist/graph/adapters/adapter.factory.js +77 -0
- package/dist/graph/adapters/adapter.factory.js.map +1 -0
- package/dist/graph/adapters/arangodb.adapter.d.ts +86 -0
- package/dist/graph/adapters/arangodb.adapter.js +1522 -0
- package/dist/graph/adapters/arangodb.adapter.js.map +1 -0
- package/dist/graph/adapters/base.adapter.d.ts +245 -0
- package/dist/graph/adapters/base.adapter.js +64 -0
- package/dist/graph/adapters/base.adapter.js.map +1 -0
- package/dist/graph/adapters/index.d.ts +11 -0
- package/dist/graph/adapters/index.js +21 -0
- package/dist/graph/adapters/index.js.map +1 -0
- package/dist/graph/adapters/memgraph.adapter.d.ts +110 -0
- package/dist/graph/adapters/memgraph.adapter.js +1345 -0
- package/dist/graph/adapters/memgraph.adapter.js.map +1 -0
- package/dist/graph/adapters/neo4j.adapter.d.ts +81 -0
- package/dist/graph/adapters/neo4j.adapter.js +1198 -0
- package/dist/graph/adapters/neo4j.adapter.js.map +1 -0
- package/dist/graph/adapters/neptune.adapter.d.ts +82 -0
- package/dist/graph/adapters/neptune.adapter.js +1313 -0
- package/dist/graph/adapters/neptune.adapter.js.map +1 -0
- package/dist/graph/graphs.service.d.ts +546 -0
- package/dist/graph/graphs.service.js +1893 -0
- package/dist/graph/graphs.service.js.map +1 -0
- package/dist/graph/index.d.ts +57 -0
- package/dist/graph/index.js +77 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/transactions/index.d.ts +4 -0
- package/dist/graph/transactions/index.js +9 -0
- package/dist/graph/transactions/index.js.map +1 -0
- package/dist/graph/transactions/transaction-manager.d.ts +61 -0
- package/dist/graph/transactions/transaction-manager.js +126 -0
- package/dist/graph/transactions/transaction-manager.js.map +1 -0
- package/dist/graph/types/connection.interface.d.ts +149 -0
- package/dist/graph/types/connection.interface.js +9 -0
- package/dist/graph/types/connection.interface.js.map +1 -0
- package/dist/graph/types/enums.d.ts +101 -0
- package/dist/graph/types/enums.js +114 -0
- package/dist/graph/types/enums.js.map +1 -0
- package/dist/graph/types/index.d.ts +13 -0
- package/dist/graph/types/index.js +20 -0
- package/dist/graph/types/index.js.map +1 -0
- package/dist/graph/types/node.interface.d.ts +248 -0
- package/dist/graph/types/node.interface.js +9 -0
- package/dist/graph/types/node.interface.js.map +1 -0
- package/dist/graph/types/query.interface.d.ts +175 -0
- package/dist/graph/types/query.interface.js +9 -0
- package/dist/graph/types/query.interface.js.map +1 -0
- package/dist/graph/types/relationship.interface.d.ts +207 -0
- package/dist/graph/types/relationship.interface.js +9 -0
- package/dist/graph/types/relationship.interface.js.map +1 -0
- package/dist/graph/types/schema.interface.d.ts +295 -0
- package/dist/graph/types/schema.interface.js +9 -0
- package/dist/graph/types/schema.interface.js.map +1 -0
- package/dist/graph/types/transaction.interface.d.ts +55 -0
- package/dist/graph/types/transaction.interface.js +9 -0
- package/dist/graph/types/transaction.interface.js.map +1 -0
- package/dist/graph/types/traversal.interface.d.ts +181 -0
- package/dist/graph/types/traversal.interface.js +9 -0
- package/dist/graph/types/traversal.interface.js.map +1 -0
- package/dist/graph/utils/graph-error.d.ts +71 -0
- package/dist/graph/utils/graph-error.js +142 -0
- package/dist/graph/utils/graph-error.js.map +1 -0
- package/dist/graph/utils/index.d.ts +4 -0
- package/dist/graph/utils/index.js +9 -0
- package/dist/graph/utils/index.js.map +1 -0
- package/dist/imports/imports.service.d.ts +3 -3
- package/dist/imports/imports.service.js +8 -7
- package/dist/imports/imports.service.js.map +1 -1
- package/dist/imports/imports.types.d.ts +8 -0
- package/dist/imports/repos/openApi.repo.d.ts +1 -1
- package/dist/imports/repos/openApi.repo.js +414 -47
- package/dist/imports/repos/openApi.repo.js.map +1 -1
- package/dist/imports/repos/postmanV21.repo.d.ts +1 -1
- package/dist/imports/repos/postmanV21.repo.js +126 -83
- package/dist/imports/repos/postmanV21.repo.js.map +1 -1
- package/dist/index.d.ts +3239 -285
- package/dist/index.js +4705 -687
- package/dist/index.js.map +1 -1
- package/dist/init.interface.d.ts +407 -0
- package/dist/init.interface.js +3 -0
- package/dist/init.interface.js.map +1 -0
- package/dist/inputs/inputs.service.d.ts +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/jobs/index.d.ts +38 -0
- package/dist/jobs/index.js +50 -0
- package/dist/jobs/index.js.map +1 -0
- package/dist/jobs/jobs.service.d.ts +154 -0
- package/dist/jobs/jobs.service.js +491 -0
- package/dist/jobs/jobs.service.js.map +1 -0
- package/dist/jobs/jobs.state.d.ts +113 -0
- package/dist/jobs/jobs.state.js +447 -0
- package/dist/jobs/jobs.state.js.map +1 -0
- package/dist/jobs/types.d.ts +449 -0
- package/dist/jobs/types.js +74 -0
- package/dist/jobs/types.js.map +1 -0
- package/dist/logs/logs.types.d.ts +16 -1
- package/dist/logs/logs.types.js +5 -0
- package/dist/logs/logs.types.js.map +1 -1
- package/dist/models/index.d.ts +6 -0
- package/dist/models/index.js +11 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/models.service.d.ts +137 -0
- package/dist/models/models.service.js +195 -0
- package/dist/models/models.service.js.map +1 -0
- package/dist/notifications/index.d.ts +13 -0
- package/dist/notifications/index.js +26 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/notifications/notifications.service.d.ts +257 -0
- package/dist/notifications/notifications.service.js +656 -0
- package/dist/notifications/notifications.service.js.map +1 -0
- package/dist/notifications/types/index.d.ts +4 -0
- package/dist/notifications/types/index.js +21 -0
- package/dist/notifications/types/index.js.map +1 -0
- package/dist/notifications/types/notifications.types.d.ts +400 -0
- package/dist/notifications/types/notifications.types.js +49 -0
- package/dist/notifications/types/notifications.types.js.map +1 -0
- 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.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/services/processor.service.d.ts +120 -73
- package/dist/processor/services/processor.service.js +1705 -1294
- 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 +87 -21
- 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 +330 -77
- package/dist/products/services/products.service.js +2586 -397
- package/dist/products/services/products.service.js.map +1 -1
- 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 +7 -1
- package/dist/products/validators/index.js +16 -1
- package/dist/products/validators/index.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productAgent.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.productAgent.validator.js +266 -0
- package/dist/products/validators/joi-validators/create.productAgent.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productDatabase.validator.js +5 -0
- package/dist/products/validators/joi-validators/create.productDatabase.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.js +89 -0
- package/dist/products/validators/joi-validators/create.productGraph.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.productMessageBrokers.validator.js +81 -25
- package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productModel.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.productModel.validator.js +132 -0
- package/dist/products/validators/joi-validators/create.productModel.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productNotification.validator.js +133 -45
- package/dist/products/validators/joi-validators/create.productNotification.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productStorage.validator.js +77 -18
- package/dist/products/validators/joi-validators/create.productStorage.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productVector.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.productVector.validator.js +135 -0
- package/dist/products/validators/joi-validators/create.productVector.validator.js.map +1 -0
- 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.productDatabase.validator.js +5 -0
- package/dist/products/validators/joi-validators/update.productDatabase.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.js +88 -0
- package/dist/products/validators/joi-validators/update.productGraph.validator.js.map +1 -0
- package/dist/resilience/fallback.service.d.ts +140 -0
- package/dist/resilience/fallback.service.js +764 -0
- package/dist/resilience/fallback.service.js.map +1 -0
- package/dist/resilience/healthcheck.service.d.ts +159 -0
- package/dist/resilience/healthcheck.service.js +943 -0
- package/dist/resilience/healthcheck.service.js.map +1 -0
- package/dist/resilience/index.d.ts +104 -0
- package/dist/resilience/index.js +140 -0
- package/dist/resilience/index.js.map +1 -0
- package/dist/resilience/quota.service.d.ts +82 -0
- package/dist/resilience/quota.service.js +516 -0
- package/dist/resilience/quota.service.js.map +1 -0
- package/dist/resilience/resilience.service.d.ts +98 -0
- package/dist/resilience/resilience.service.js +560 -0
- package/dist/resilience/resilience.service.js.map +1 -0
- package/dist/resilience/types/index.d.ts +513 -0
- package/dist/resilience/types/index.js +29 -0
- package/dist/resilience/types/index.js.map +1 -0
- package/dist/secrets/index.d.ts +10 -0
- package/dist/secrets/index.js +33 -0
- package/dist/secrets/index.js.map +1 -0
- package/dist/secrets/secrets.resolver.d.ts +52 -0
- package/dist/secrets/secrets.resolver.js +233 -0
- package/dist/secrets/secrets.resolver.js.map +1 -0
- package/dist/secrets/secrets.service.d.ts +93 -0
- package/dist/secrets/secrets.service.js +258 -0
- package/dist/secrets/secrets.service.js.map +1 -0
- package/dist/secrets/secrets.types.d.ts +188 -0
- package/dist/secrets/secrets.types.js +87 -0
- package/dist/secrets/secrets.types.js.map +1 -0
- package/dist/sessions/index.d.ts +50 -0
- package/dist/sessions/index.js +93 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/sessions/sessions.helper.d.ts +68 -0
- package/dist/sessions/sessions.helper.js +116 -0
- package/dist/sessions/sessions.helper.js.map +1 -0
- package/dist/sessions/sessions.resolver.d.ts +150 -0
- package/dist/sessions/sessions.resolver.js +356 -0
- package/dist/sessions/sessions.resolver.js.map +1 -0
- package/dist/sessions/sessions.service.d.ts +170 -0
- package/dist/sessions/sessions.service.js +736 -0
- package/dist/sessions/sessions.service.js.map +1 -0
- package/dist/sessions/types/index.d.ts +290 -0
- package/dist/sessions/types/index.js +6 -0
- package/dist/sessions/types/index.js.map +1 -0
- package/dist/storage/index.d.ts +66 -0
- package/dist/storage/index.js +98 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/storage.service.d.ts +151 -0
- package/dist/storage/storage.service.js +522 -0
- package/dist/storage/storage.service.js.map +1 -0
- package/dist/storage/types/index.d.ts +207 -0
- package/dist/storage/types/index.js +6 -0
- package/dist/storage/types/index.js.map +1 -0
- package/dist/storage/utils/storage.util.d.ts +51 -0
- package/dist/storage/utils/storage.util.js +402 -0
- package/dist/storage/utils/storage.util.js.map +1 -0
- package/dist/test/index.d.ts +3 -0
- package/dist/test/index.js +11 -0
- package/dist/test/index.js.map +1 -0
- package/dist/test/test.appBuilder.d.ts +0 -1
- package/dist/test/test.appBuilder.js +0 -15
- package/dist/test/test.appBuilder.js.map +1 -1
- package/dist/test/test.broker.kafka.js +172 -0
- package/dist/test/test.broker.kafka.js.map +1 -0
- package/dist/test/test.broker.nats.js +193 -0
- package/dist/test/test.broker.nats.js.map +1 -0
- package/dist/test/test.broker.pubsub.js +171 -0
- package/dist/test/test.broker.pubsub.js.map +1 -0
- package/dist/test/test.broker.rabbitmq.js +164 -0
- package/dist/test/test.broker.rabbitmq.js.map +1 -0
- package/dist/test/test.broker.redis.js +168 -0
- package/dist/test/test.broker.redis.js.map +1 -0
- package/dist/test/test.broker.sqs.d.ts +1 -0
- package/dist/test/test.broker.sqs.js +158 -0
- package/dist/test/test.broker.sqs.js.map +1 -0
- package/dist/test/test.caches.d.ts +1 -0
- package/dist/test/test.caches.js +231 -0
- package/dist/test/test.caches.js.map +1 -0
- package/dist/test/test.database.d.ts +1 -0
- package/dist/test/test.database.dynamo.d.ts +1 -0
- package/dist/test/test.database.dynamo.js +265 -0
- package/dist/test/test.database.dynamo.js.map +1 -0
- package/dist/test/test.database.js +140 -0
- package/dist/test/test.database.js.map +1 -0
- package/dist/test/test.database.mongo.d.ts +1 -0
- package/dist/test/test.database.mongo.js +371 -0
- package/dist/test/test.database.mongo.js.map +1 -0
- package/dist/test/test.database.mysql.d.ts +1 -0
- package/dist/test/test.database.mysql.js +415 -0
- package/dist/test/test.database.mysql.js.map +1 -0
- package/dist/test/test.database.postgres.d.ts +1 -0
- package/dist/test/test.database.postgres.js +412 -0
- package/dist/test/test.database.postgres.js.map +1 -0
- package/dist/test/test.email.brevo.d.ts +1 -0
- package/dist/test/test.email.brevo.js +326 -0
- package/dist/test/test.email.brevo.js.map +1 -0
- package/dist/test/test.email.mailgun.d.ts +1 -0
- package/dist/test/test.email.mailgun.js +352 -0
- package/dist/test/test.email.mailgun.js.map +1 -0
- package/dist/test/test.email.postmark.d.ts +1 -0
- package/dist/test/test.email.postmark.js +316 -0
- package/dist/test/test.email.postmark.js.map +1 -0
- package/dist/test/test.email.sendgrid.d.ts +1 -0
- package/dist/test/test.email.sendgrid.js +365 -0
- package/dist/test/test.email.sendgrid.js.map +1 -0
- package/dist/test/test.email.smtp.d.ts +1 -0
- package/dist/test/test.email.smtp.js +323 -0
- package/dist/test/test.email.smtp.js.map +1 -0
- package/dist/test/test.graph.arangodb.d.ts +1 -0
- package/dist/test/test.graph.arangodb.js +358 -0
- package/dist/test/test.graph.arangodb.js.map +1 -0
- package/dist/test/test.graph.memgraph.d.ts +1 -0
- package/dist/test/test.graph.memgraph.js +320 -0
- package/dist/test/test.graph.memgraph.js.map +1 -0
- package/dist/test/test.graph.neo4j.d.ts +1 -0
- package/dist/test/test.graph.neo4j.js +218 -0
- package/dist/test/test.graph.neo4j.js.map +1 -0
- package/dist/test/test.graph.neptune.d.ts +1 -0
- package/dist/test/test.graph.neptune.js +331 -0
- package/dist/test/test.graph.neptune.js.map +1 -0
- package/dist/test/test.health.js +1 -0
- package/dist/test/test.health.js.map +1 -0
- package/dist/test/test.import.d.ts +0 -1
- package/dist/test/test.import.js +0 -1459
- package/dist/test/test.import.js.map +1 -1
- package/dist/test/test.import.openapi.d.ts +0 -1
- package/dist/test/test.import.openapi.js +0 -75
- package/dist/test/test.import.openapi.js.map +1 -1
- package/dist/test/test.imports.js +14 -55
- package/dist/test/test.imports.js.map +1 -1
- package/dist/test/test.logs.d.ts +0 -1
- package/dist/test/test.logs.js +0 -17
- package/dist/test/test.logs.js.map +1 -1
- package/dist/test/test.notifications.d.ts +1 -0
- package/dist/test/test.notifications.js +198 -0
- package/dist/test/test.notifications.js.map +1 -0
- package/dist/test/test.notifiers.js +1 -0
- package/dist/test/test.notifiers.js.map +1 -0
- package/dist/test/test.processor.d.ts +0 -1
- package/dist/test/test.processor.js +0 -122
- package/dist/test/test.processor.js.map +1 -1
- package/dist/test/test.productBuilder.d.ts +0 -1
- package/dist/test/test.productBuilder.js +0 -660
- package/dist/test/test.productBuilder.js.map +1 -1
- package/dist/test/test.products.js +1 -0
- package/dist/test/test.products.js.map +1 -0
- package/dist/test/test.push.expo.d.ts +1 -0
- package/dist/test/test.push.expo.js +442 -0
- package/dist/test/test.push.expo.js.map +1 -0
- package/dist/test/test.push.firebase.d.ts +1 -0
- package/dist/test/test.push.firebase.js +409 -0
- package/dist/test/test.push.firebase.js.map +1 -0
- package/dist/test/test.session.d.ts +1 -0
- package/dist/test/test.session.js +299 -0
- package/dist/test/test.session.js.map +1 -0
- package/dist/test/test.sms.nexmo.d.ts +1 -0
- package/dist/test/test.sms.nexmo.js +278 -0
- package/dist/test/test.sms.nexmo.js.map +1 -0
- package/dist/test/test.sms.twilio.d.ts +1 -0
- package/dist/test/test.sms.twilio.js +275 -0
- package/dist/test/test.sms.twilio.js.map +1 -0
- package/dist/test/test.storage.d.ts +1 -0
- package/dist/test/test.storage.js +202 -0
- package/dist/test/test.storage.js.map +1 -0
- package/dist/test/test.triggers.d.ts +1 -0
- package/dist/test/test.triggers.js +314 -0
- package/dist/test/test.triggers.js.map +1 -0
- package/dist/test/test.vector.pinecone.d.ts +1 -0
- package/dist/test/test.vector.pinecone.js +238 -0
- package/dist/test/test.vector.pinecone.js.map +1 -0
- package/dist/test/test.vector.qdrant.d.ts +1 -0
- package/dist/test/test.vector.qdrant.js +307 -0
- package/dist/test/test.vector.qdrant.js.map +1 -0
- package/dist/test/test.vector.weaviate.d.ts +1 -0
- package/dist/test/test.vector.weaviate.js +325 -0
- package/dist/test/test.vector.weaviate.js.map +1 -0
- package/dist/types/appBuilder.types.d.ts +10 -13
- package/dist/types/enums.d.ts +11 -1
- package/dist/types/enums.js +10 -0
- package/dist/types/enums.js.map +1 -1
- package/dist/types/index.types.d.ts +6 -4
- package/dist/types/index.types.js +0 -1
- package/dist/types/index.types.js.map +1 -1
- 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 +245 -20
- package/dist/types/processor.types.js +9 -1
- package/dist/types/processor.types.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +906 -24
- package/dist/types/productsBuilder.types.js +173 -2
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/dist/types/request-tracker.interface.js +1 -0
- package/dist/types/request-tracker.interface.js.map +1 -0
- package/dist/types/requests.types.d.ts +2 -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/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +24 -52
- package/dist/utils/index.js.map +1 -1
- package/dist/vector/adapters/base.adapter.d.ts +152 -0
- package/dist/vector/adapters/base.adapter.js +137 -0
- package/dist/vector/adapters/base.adapter.js.map +1 -0
- package/dist/vector/adapters/index.d.ts +10 -0
- package/dist/vector/adapters/index.js +19 -0
- package/dist/vector/adapters/index.js.map +1 -0
- package/dist/vector/adapters/memory.adapter.d.ts +85 -0
- package/dist/vector/adapters/memory.adapter.js +505 -0
- package/dist/vector/adapters/memory.adapter.js.map +1 -0
- package/dist/vector/adapters/pinecone.adapter.d.ts +52 -0
- package/dist/vector/adapters/pinecone.adapter.js +400 -0
- package/dist/vector/adapters/pinecone.adapter.js.map +1 -0
- package/dist/vector/adapters/qdrant.adapter.d.ts +56 -0
- package/dist/vector/adapters/qdrant.adapter.js +392 -0
- package/dist/vector/adapters/qdrant.adapter.js.map +1 -0
- package/dist/vector/adapters/weaviate.adapter.d.ts +64 -0
- package/dist/vector/adapters/weaviate.adapter.js +478 -0
- package/dist/vector/adapters/weaviate.adapter.js.map +1 -0
- package/dist/vector/index.d.ts +47 -0
- package/dist/vector/index.js +72 -0
- package/dist/vector/index.js.map +1 -0
- package/dist/vector/types/connection.interface.d.ts +151 -0
- package/dist/vector/types/connection.interface.js +8 -0
- package/dist/vector/types/connection.interface.js.map +1 -0
- package/dist/vector/types/embedding.interface.d.ts +144 -0
- package/dist/vector/types/embedding.interface.js +8 -0
- package/dist/vector/types/embedding.interface.js.map +1 -0
- package/dist/vector/types/enums.d.ts +104 -0
- package/dist/vector/types/enums.js +113 -0
- package/dist/vector/types/enums.js.map +1 -0
- package/dist/vector/types/index.d.ts +9 -0
- package/dist/vector/types/index.js +16 -0
- package/dist/vector/types/index.js.map +1 -0
- package/dist/vector/types/vector.interface.d.ts +315 -0
- package/dist/vector/types/vector.interface.js +8 -0
- package/dist/vector/types/vector.interface.js.map +1 -0
- package/dist/vector/utils/index.d.ts +6 -0
- package/dist/vector/utils/index.js +11 -0
- package/dist/vector/utils/index.js.map +1 -0
- package/dist/vector/utils/vector-error.d.ts +69 -0
- package/dist/vector/utils/vector-error.js +116 -0
- package/dist/vector/utils/vector-error.js.map +1 -0
- package/dist/vector/vector-database.service.d.ts +408 -0
- package/dist/vector/vector-database.service.js +545 -0
- package/dist/vector/vector-database.service.js.map +1 -0
- package/dist/vector/vector.service.d.ts +245 -0
- package/dist/vector/vector.service.js +384 -0
- package/dist/vector/vector.service.js.map +1 -0
- package/dist/workflows/index.d.ts +30 -0
- package/dist/workflows/index.js +64 -0
- package/dist/workflows/index.js.map +1 -0
- package/dist/workflows/types/index.d.ts +6 -0
- package/dist/workflows/types/index.js +23 -0
- package/dist/workflows/types/index.js.map +1 -0
- package/dist/workflows/types/workflows.types.d.ts +1035 -0
- package/dist/workflows/types/workflows.types.js +13 -0
- package/dist/workflows/types/workflows.types.js.map +1 -0
- package/dist/workflows/workflow-builder.d.ts +70 -0
- package/dist/workflows/workflow-builder.js +338 -0
- package/dist/workflows/workflow-builder.js.map +1 -0
- package/dist/workflows/workflow-executor.d.ts +208 -0
- package/dist/workflows/workflow-executor.js +1194 -0
- package/dist/workflows/workflow-executor.js.map +1 -0
- package/dist/workflows/workflows.service.d.ts +404 -0
- package/dist/workflows/workflows.service.js +1620 -0
- package/dist/workflows/workflows.service.js.map +1 -0
- package/package.json +54 -11
- package/dist/actions/actions.repo.js +0 -13
- package/dist/actions/actions.repo.js.map +0 -1
- package/dist/actions/actions.service.js +0 -24
- package/dist/actions/actions.service.js.map +0 -1
- package/dist/actions/utils/actions.util.read.js +0 -427
- package/dist/actions/utils/actions.util.read.js.map +0 -1
- package/dist/api/services/integrationsApi.service.d.ts +0 -18
- package/dist/api/services/integrationsApi.service.js +0 -80
- package/dist/api/services/integrationsApi.service.js.map +0 -1
- package/dist/appBuilder/services/app.service.d.ts +0 -111
- package/dist/appBuilder/services/app.service.js +0 -737
- package/dist/appBuilder/services/app.service.js.map +0 -1
- package/dist/appBuilder/services/appBuilder.service.d.ts +0 -111
- package/dist/appBuilder/services/appBuilder.service.js +0 -662
- package/dist/appBuilder/services/appBuilder.service.js.map +0 -1
- package/dist/appBuilder/utils/objects.utils.d.ts +0 -3
- package/dist/appBuilder/utils/objects.utils.js +0 -9
- package/dist/appBuilder/utils/objects.utils.js.map +0 -1
- package/dist/appBuilder/utils/string.utils.d.ts +0 -2
- package/dist/appBuilder/utils/string.utils.js +0 -57
- package/dist/appBuilder/utils/string.utils.js.map +0 -1
- package/dist/appBuilder/validators/index.d.ts +0 -19
- package/dist/appBuilder/validators/index.js +0 -40
- package/dist/appBuilder/validators/index.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.app.validator.js +0 -10
- package/dist/appBuilder/validators/joi-validators/create.app.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appAction.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appAction.validator.js +0 -20
- package/dist/appBuilder/validators/joi-validators/create.appAction.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appActionResponse.validator.d.ts +0 -7
- package/dist/appBuilder/validators/joi-validators/create.appActionResponse.validator.js +0 -44
- package/dist/appBuilder/validators/joi-validators/create.appActionResponse.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appAuth.validator.d.ts +0 -3
- package/dist/appBuilder/validators/joi-validators/create.appAuth.validator.js +0 -31
- package/dist/appBuilder/validators/joi-validators/create.appAuth.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appBody.validators.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appBody.validators.js +0 -11
- package/dist/appBuilder/validators/joi-validators/create.appBody.validators.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appConstants.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appConstants.validator.js +0 -12
- package/dist/appBuilder/validators/joi-validators/create.appConstants.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appEnv.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appEnv.validator.js +0 -17
- package/dist/appBuilder/validators/joi-validators/create.appEnv.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appEvent.validator.d.ts +0 -5
- package/dist/appBuilder/validators/joi-validators/create.appEvent.validator.js +0 -30
- package/dist/appBuilder/validators/joi-validators/create.appEvent.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/create.appVariable.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/create.appVariable.validator.js +0 -14
- package/dist/appBuilder/validators/joi-validators/create.appVariable.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/sample.validator.d.ts +0 -5
- package/dist/appBuilder/validators/joi-validators/sample.validator.js +0 -26
- package/dist/appBuilder/validators/joi-validators/sample.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.app.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.app.validator.js +0 -34
- package/dist/appBuilder/validators/joi-validators/update.app.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appAction.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appAction.validator.js +0 -23
- package/dist/appBuilder/validators/joi-validators/update.appAction.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appActionResponse.validator.d.ts +0 -3
- package/dist/appBuilder/validators/joi-validators/update.appActionResponse.validator.js +0 -21
- package/dist/appBuilder/validators/joi-validators/update.appActionResponse.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appAuth.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appAuth.validator.js +0 -19
- package/dist/appBuilder/validators/joi-validators/update.appAuth.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appConstants.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appConstants.validator.js +0 -12
- package/dist/appBuilder/validators/joi-validators/update.appConstants.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appEnv.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appEnv.validator.js +0 -17
- package/dist/appBuilder/validators/joi-validators/update.appEnv.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appEvent.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appEvent.validator.js +0 -16
- package/dist/appBuilder/validators/joi-validators/update.appEvent.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.appVariables.validator.d.ts +0 -4
- package/dist/appBuilder/validators/joi-validators/update.appVariables.validator.js +0 -14
- package/dist/appBuilder/validators/joi-validators/update.appVariables.validator.js.map +0 -1
- package/dist/appBuilder/validators/joi-validators/update.validation.entityData.validator.js +0 -27
- package/dist/appBuilder/validators/joi-validators/update.validation.entityData.validator.js.map +0 -1
- package/dist/apps/validators/joi-validators/create.appEvent.validator.d.ts +0 -5
- package/dist/apps/validators/joi-validators/create.appEvent.validator.js +0 -30
- package/dist/apps/validators/joi-validators/create.appEvent.validator.js.map +0 -1
- package/dist/apps/validators/joi-validators/update.appEvent.validator.d.ts +0 -4
- package/dist/apps/validators/joi-validators/update.appEvent.validator.js +0 -16
- package/dist/apps/validators/joi-validators/update.appEvent.validator.js.map +0 -1
- package/dist/clients/integrations.client.d.ts +0 -2
- package/dist/clients/integrations.client.js +0 -26
- package/dist/clients/integrations.client.js.map +0 -1
- package/dist/integrationsBuilder/services/integration.service.d.ts +0 -138
- package/dist/integrationsBuilder/services/integration.service.js +0 -1148
- package/dist/integrationsBuilder/services/integration.service.js.map +0 -1
- package/dist/integrationsBuilder/services/integrationBuilder.service.d.ts +0 -130
- package/dist/integrationsBuilder/services/integrationBuilder.service.js +0 -1017
- package/dist/integrationsBuilder/services/integrationBuilder.service.js.map +0 -1
- package/dist/integrationsBuilder/utils/objects.utils.d.ts +0 -2
- package/dist/integrationsBuilder/utils/objects.utils.js +0 -48
- package/dist/integrationsBuilder/utils/objects.utils.js.map +0 -1
- package/dist/integrationsBuilder/utils/string.utils.d.ts +0 -1
- package/dist/integrationsBuilder/utils/string.utils.js +0 -9
- package/dist/integrationsBuilder/utils/string.utils.js.map +0 -1
- package/dist/integrationsBuilder/validators/index.d.ts +0 -18
- package/dist/integrationsBuilder/validators/index.js +0 -38
- package/dist/integrationsBuilder/validators/index.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.js +0 -10
- package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.d.ts +0 -4
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.js +0 -26
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.js +0 -10
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.js +0 -60
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.js +0 -9
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.js.map +0 -1
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.d.ts +0 -3
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.js +0 -8
- package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.js.map +0 -1
- package/dist/postman.d.ts +0 -1
- package/dist/postman.js +0 -21674
- package/dist/postman.js.map +0 -1
- package/dist/processor/utils/mongo.util.js +0 -152
- package/dist/processor/utils/mongo.util.js.map +0 -1
- package/dist/processor/utils/postgres.util.d.ts +0 -14
- package/dist/processor/utils/postgres.util.js +0 -83
- package/dist/processor/utils/postgres.util.js.map +0 -1
- package/dist/products/validators/joi-validators/create.product.validator.d.ts +0 -3
- package/dist/products/validators/joi-validators/create.product.validator.js +0 -10
- package/dist/products/validators/joi-validators/create.product.validator.js.map +0 -1
- package/dist/test.appBuilder.js +0 -14
- package/dist/test.appBuilder.js.map +0 -1
- package/dist/test.import.js +0 -24
- package/dist/test.import.js.map +0 -1
- package/dist/test.imports.js +0 -28
- package/dist/test.imports.js.map +0 -1
- package/dist/test.integrationBuilder.js +0 -276
- package/dist/test.integrationBuilder.js.map +0 -1
- package/dist/test.processor.js +0 -23
- package/dist/test.processor.js.map +0 -1
- package/dist/test.utils.js +0 -25
- package/dist/test.utils.js.map +0 -1
- package/dist/types/integrationsBuilder.types.d.ts +0 -276
- package/dist/types/integrationsBuilder.types.js +0 -51
- package/dist/types/integrationsBuilder.types.js.map +0 -1
- /package/dist/{actions/actions.repo.d.ts → pricing/pricing.repo.d.ts} +0 -0
- /package/dist/{appBuilder/validators/joi-validators/create.app.validator.d.ts → products/validators/joi-validators/create.productGraph.validator.d.ts} +0 -0
- /package/dist/{appBuilder/validators/joi-validators/update.validation.entityData.validator.d.ts → products/validators/joi-validators/update.productGraph.validator.d.ts} +0 -0
- /package/dist/{test.appBuilder.d.ts → test/test.broker.kafka.d.ts} +0 -0
- /package/dist/{test.imports.d.ts → test/test.broker.nats.d.ts} +0 -0
- /package/dist/{test.integrationBuilder.d.ts → test/test.broker.pubsub.d.ts} +0 -0
- /package/dist/{test.processor.d.ts → test/test.broker.rabbitmq.d.ts} +0 -0
- /package/dist/{test.utils.d.ts → test/test.broker.redis.d.ts} +0 -0
- /package/dist/{actions/actions.service.d.ts → test/test.health.d.ts} +0 -0
- /package/dist/{actions/utils/actions.util.read.d.ts → test/test.notifiers.d.ts} +0 -0
- /package/dist/{processor/utils/mongo.util.d.ts → test/test.products.d.ts} +0 -0
- /package/dist/{test.import.d.ts → types/request-tracker.interface.d.ts} +0 -0
|
@@ -0,0 +1,2821 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* DatabaseService - Main ORM Service Class
|
|
4
|
+
*
|
|
5
|
+
* This is the primary entry point for all database operations in the Ductape SDK.
|
|
6
|
+
* It provides a unified interface for querying, writing, transactions, schema management,
|
|
7
|
+
* migrations, and database actions across multiple database types.
|
|
8
|
+
*
|
|
9
|
+
* Supported databases: PostgreSQL, MySQL, MongoDB, DynamoDB, MariaDB, Cassandra
|
|
10
|
+
*/
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
+
}) : function(o, v) {
|
|
25
|
+
o["default"] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
+
var ownKeys = function(o) {
|
|
29
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
+
var ar = [];
|
|
31
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
return ownKeys(o);
|
|
35
|
+
};
|
|
36
|
+
return function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
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
|
+
exports.databaseService = exports.DatabaseConnection = exports.DatabaseService = void 0;
|
|
49
|
+
const enums_1 = require("./types/enums");
|
|
50
|
+
const presave_processor_1 = require("./presave/presave-processor");
|
|
51
|
+
const adapter_factory_1 = require("./adapters/adapter.factory");
|
|
52
|
+
const query_builder_1 = require("./operators/query-builder");
|
|
53
|
+
const aggregation_builder_1 = require("./operators/aggregation-builder");
|
|
54
|
+
const transaction_manager_1 = require("./transactions/transaction-manager");
|
|
55
|
+
const schema_manager_1 = require("./schema/schema-manager");
|
|
56
|
+
const migration_engine_1 = require("./migrations/migration-engine");
|
|
57
|
+
const action_manager_1 = require("./actions/action-manager");
|
|
58
|
+
const trigger_processor_1 = require("./triggers/trigger-processor");
|
|
59
|
+
const trigger_interface_1 = require("./types/trigger.interface");
|
|
60
|
+
const database_error_1 = require("./utils/database-error");
|
|
61
|
+
const products_service_1 = __importDefault(require("../products/services/products.service"));
|
|
62
|
+
const types_1 = require("../types");
|
|
63
|
+
const cache_manager_1 = require("../cache/cache.manager");
|
|
64
|
+
const processor_service_1 = __importDefault(require("../processor/services/processor.service"));
|
|
65
|
+
const crypto_1 = require("crypto");
|
|
66
|
+
const logs_service_1 = __importDefault(require("../logs/logs.service"));
|
|
67
|
+
const logs_types_1 = require("../logs/logs.types");
|
|
68
|
+
const processor_utils_1 = require("../processor/utils/processor.utils");
|
|
69
|
+
const secrets_1 = require("../secrets");
|
|
70
|
+
/**
|
|
71
|
+
* Main Database Service class
|
|
72
|
+
* Provides unified ORM interface for all supported databases
|
|
73
|
+
*/
|
|
74
|
+
class DatabaseService {
|
|
75
|
+
/**
|
|
76
|
+
* Create a new DatabaseService instance
|
|
77
|
+
* @param config - Optional configuration for authentication and workspace context
|
|
78
|
+
*/
|
|
79
|
+
constructor(config) {
|
|
80
|
+
this.adapters = new Map();
|
|
81
|
+
this.connectionContexts = new Map();
|
|
82
|
+
this.currentContext = null;
|
|
83
|
+
this.schemaManagers = new Map();
|
|
84
|
+
this.migrationEngines = new Map();
|
|
85
|
+
/** Service configuration */
|
|
86
|
+
this.config = null;
|
|
87
|
+
/** ProductBuilder instances cache (keyed by product tag) */
|
|
88
|
+
this.productBuilders = new Map();
|
|
89
|
+
/** LogService instance for logging operations */
|
|
90
|
+
this.logService = null;
|
|
91
|
+
/** Current product ID for logging */
|
|
92
|
+
this.productId = '';
|
|
93
|
+
/** CacheManager for two-tier caching (Redis + remote) */
|
|
94
|
+
this.cacheManager = null;
|
|
95
|
+
/** Private keys cache for products (keyed by product tag) */
|
|
96
|
+
this.privateKeys = new Map();
|
|
97
|
+
this.config = config || null;
|
|
98
|
+
this.adapterFactory = new adapter_factory_1.AdapterFactory();
|
|
99
|
+
this.transactionManager = new transaction_manager_1.TransactionManager();
|
|
100
|
+
this.actionManager = new action_manager_1.ActionManager(this);
|
|
101
|
+
this._privateKey = (config === null || config === void 0 ? void 0 : config.private_key) || '';
|
|
102
|
+
// Initialize CacheManager if Redis client is provided
|
|
103
|
+
if (config === null || config === void 0 ? void 0 : config.redis_client) {
|
|
104
|
+
this.cacheManager = new cache_manager_1.CacheManager({
|
|
105
|
+
workspace_id: config.workspace_id,
|
|
106
|
+
public_key: config.public_key,
|
|
107
|
+
user_id: config.user_id,
|
|
108
|
+
token: config.token,
|
|
109
|
+
env_type: config.env_type,
|
|
110
|
+
redis_client: config.redis_client,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get or create a SchemaManager for the given adapter key or current context
|
|
116
|
+
*/
|
|
117
|
+
getSchemaManager(adapterKey) {
|
|
118
|
+
// If no key provided, use current context
|
|
119
|
+
if (!adapterKey) {
|
|
120
|
+
if (!this.currentContext) {
|
|
121
|
+
throw new database_error_1.DatabaseError('No active database connection. Please connect first.', enums_1.DatabaseErrorType.CONNECTION_ERROR);
|
|
122
|
+
}
|
|
123
|
+
adapterKey = this.buildContextKey(this.currentContext.database, this.currentContext.env);
|
|
124
|
+
}
|
|
125
|
+
let manager = this.schemaManagers.get(adapterKey);
|
|
126
|
+
if (!manager) {
|
|
127
|
+
const adapter = this.adapters.get(adapterKey);
|
|
128
|
+
if (!adapter) {
|
|
129
|
+
throw new database_error_1.DatabaseError(`No adapter found for key: ${adapterKey}`, enums_1.DatabaseErrorType.NOT_FOUND);
|
|
130
|
+
}
|
|
131
|
+
manager = new schema_manager_1.SchemaManager(adapter);
|
|
132
|
+
this.schemaManagers.set(adapterKey, manager);
|
|
133
|
+
}
|
|
134
|
+
return manager;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get or create a MigrationEngine for the given adapter key or current context
|
|
138
|
+
*/
|
|
139
|
+
getMigrationEngine(adapterKey) {
|
|
140
|
+
// If no key provided, use current context
|
|
141
|
+
if (!adapterKey) {
|
|
142
|
+
if (!this.currentContext) {
|
|
143
|
+
throw new database_error_1.DatabaseError('No active database connection. Please connect first.', enums_1.DatabaseErrorType.CONNECTION_ERROR);
|
|
144
|
+
}
|
|
145
|
+
adapterKey = this.buildContextKey(this.currentContext.database, this.currentContext.env);
|
|
146
|
+
}
|
|
147
|
+
let engine = this.migrationEngines.get(adapterKey);
|
|
148
|
+
if (!engine) {
|
|
149
|
+
const adapter = this.adapters.get(adapterKey);
|
|
150
|
+
if (!adapter) {
|
|
151
|
+
throw new database_error_1.DatabaseError(`No adapter found for key: ${adapterKey}`, enums_1.DatabaseErrorType.NOT_FOUND);
|
|
152
|
+
}
|
|
153
|
+
engine = new migration_engine_1.MigrationEngine(adapter);
|
|
154
|
+
this.migrationEngines.set(adapterKey, engine);
|
|
155
|
+
}
|
|
156
|
+
return engine;
|
|
157
|
+
}
|
|
158
|
+
// ==================== PRODUCT BUILDER MANAGEMENT ====================
|
|
159
|
+
/**
|
|
160
|
+
* Create a new ProductBuilder instance
|
|
161
|
+
*/
|
|
162
|
+
createNewProductBuilder() {
|
|
163
|
+
if (!this.config) {
|
|
164
|
+
throw new database_error_1.DatabaseError('DatabaseService not configured. Please provide config when initializing.', enums_1.DatabaseErrorType.CONFIGURATION_ERROR);
|
|
165
|
+
}
|
|
166
|
+
return new products_service_1.default({
|
|
167
|
+
workspace_id: this.config.workspace_id,
|
|
168
|
+
public_key: this.config.public_key,
|
|
169
|
+
user_id: this.config.user_id,
|
|
170
|
+
token: this.config.token,
|
|
171
|
+
env_type: this.config.env_type,
|
|
172
|
+
access_key: this.config.access_key,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Get or create a ProductBuilder instance for the given product tag
|
|
177
|
+
*/
|
|
178
|
+
async getProductBuilder(productTag) {
|
|
179
|
+
let builder = this.productBuilders.get(productTag);
|
|
180
|
+
if (!builder) {
|
|
181
|
+
builder = this.createNewProductBuilder();
|
|
182
|
+
await builder.initializeProductByTag(productTag);
|
|
183
|
+
this.productBuilders.set(productTag, builder);
|
|
184
|
+
// Update productId for logging
|
|
185
|
+
this.productId = builder.fetchProductId() || '';
|
|
186
|
+
// Cache private key for caching operations
|
|
187
|
+
const privateKey = builder.fetchPrivateKey();
|
|
188
|
+
if (privateKey) {
|
|
189
|
+
this.privateKeys.set(productTag, privateKey);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return builder;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Initialize logging service
|
|
196
|
+
*/
|
|
197
|
+
initializeLogService() {
|
|
198
|
+
if (!this.logService && this.config) {
|
|
199
|
+
this.logService = new logs_service_1.default({
|
|
200
|
+
product_id: this.productId,
|
|
201
|
+
workspace_id: this.config.workspace_id,
|
|
202
|
+
public_key: this.config.public_key,
|
|
203
|
+
user_id: this.config.user_id,
|
|
204
|
+
token: this.config.token,
|
|
205
|
+
env_type: this.config.env_type,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Create a new ProcessorService instance for job scheduling
|
|
211
|
+
*/
|
|
212
|
+
createNewProcessor() {
|
|
213
|
+
if (!this.config) {
|
|
214
|
+
throw new database_error_1.DatabaseError('DatabaseService not configured. Please provide config when initializing.', enums_1.DatabaseErrorType.CONFIGURATION_ERROR);
|
|
215
|
+
}
|
|
216
|
+
return new processor_service_1.default({
|
|
217
|
+
workspace_id: this.config.workspace_id,
|
|
218
|
+
public_key: this.config.public_key,
|
|
219
|
+
user_id: this.config.user_id,
|
|
220
|
+
token: this.config.token,
|
|
221
|
+
env_type: this.config.env_type,
|
|
222
|
+
private_key: this._privateKey,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
// ==================== DATABASE CRUD OPERATIONS ====================
|
|
226
|
+
/**
|
|
227
|
+
* Register a new database configuration for a product
|
|
228
|
+
* @param productTag - The product tag
|
|
229
|
+
* @param data - The database configuration data
|
|
230
|
+
*/
|
|
231
|
+
async registerDatabase(productTag, data) {
|
|
232
|
+
const builder = await this.getProductBuilder(productTag);
|
|
233
|
+
return builder.createDatabase(data);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Fetch all databases for a product
|
|
237
|
+
* @param productTag - The product tag
|
|
238
|
+
* @returns Array of database configurations
|
|
239
|
+
*/
|
|
240
|
+
async fetchAllDatabases(productTag) {
|
|
241
|
+
const builder = await this.getProductBuilder(productTag);
|
|
242
|
+
return builder.fetchDatabases();
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Fetch a specific database by tag
|
|
246
|
+
* @param productTag - The product tag
|
|
247
|
+
* @param databaseTag - The database tag
|
|
248
|
+
* @returns The database configuration or null if not found
|
|
249
|
+
*/
|
|
250
|
+
async fetchDatabase(productTag, databaseTag) {
|
|
251
|
+
const builder = await this.getProductBuilder(productTag);
|
|
252
|
+
return builder.fetchDatabase(databaseTag);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Update a database configuration
|
|
256
|
+
* @param productTag - The product tag
|
|
257
|
+
* @param databaseTag - The database tag
|
|
258
|
+
* @param data - The data to update
|
|
259
|
+
*/
|
|
260
|
+
async updateDatabase(productTag, databaseTag, data) {
|
|
261
|
+
const builder = await this.getProductBuilder(productTag);
|
|
262
|
+
// Process connection URLs in envs if provided
|
|
263
|
+
if (data.envs && data.envs.length > 0) {
|
|
264
|
+
const secretsService = (0, secrets_1.getSecretsService)();
|
|
265
|
+
const processedEnvs = [];
|
|
266
|
+
for (const env of data.envs) {
|
|
267
|
+
let connectionUrl = env.connection_url;
|
|
268
|
+
const secretCheck = (0, secrets_1.isSecretReference)(connectionUrl);
|
|
269
|
+
// If not already a secret reference and we have a secrets service, store it as a secret
|
|
270
|
+
if (!secretCheck.isSecret && secretsService) {
|
|
271
|
+
const secretKey = this.generateDbSecretKey(productTag, databaseTag, env.slug);
|
|
272
|
+
try {
|
|
273
|
+
const exists = await secretsService.exists(secretKey);
|
|
274
|
+
if (exists) {
|
|
275
|
+
await secretsService.update(secretKey, { value: connectionUrl });
|
|
276
|
+
console.log(`[Secrets] Updated existing secret '${secretKey}' for database '${databaseTag}' in environment '${env.slug}'`);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
await secretsService.create({
|
|
280
|
+
key: secretKey,
|
|
281
|
+
value: connectionUrl,
|
|
282
|
+
description: `Database connection URL for ${databaseTag} in ${env.slug}`,
|
|
283
|
+
scope: [productTag, databaseTag],
|
|
284
|
+
envs: [env.slug],
|
|
285
|
+
});
|
|
286
|
+
console.log(`[Secrets] Created new secret '${secretKey}' for database '${databaseTag}' in environment '${env.slug}'`);
|
|
287
|
+
}
|
|
288
|
+
// Update the connection URL to use the secret reference
|
|
289
|
+
connectionUrl = `$Secret{${secretKey}}`;
|
|
290
|
+
console.log(`[Secrets] Connection URL converted to secret reference: $Secret{${secretKey}}`);
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
console.warn(`[Secrets] Failed to store database connection URL as secret: ${error}`);
|
|
294
|
+
// Continue with the original connection URL
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
processedEnvs.push(Object.assign(Object.assign({}, env), { connection_url: connectionUrl }));
|
|
298
|
+
}
|
|
299
|
+
data = Object.assign(Object.assign({}, data), { envs: processedEnvs });
|
|
300
|
+
}
|
|
301
|
+
return builder.updateDatabase(databaseTag, data);
|
|
302
|
+
}
|
|
303
|
+
// ==================== DATABASE TRIGGER OPERATIONS ====================
|
|
304
|
+
/**
|
|
305
|
+
* Create a database trigger
|
|
306
|
+
* @param productTag - The product tag
|
|
307
|
+
* @param data - The trigger configuration
|
|
308
|
+
*/
|
|
309
|
+
async createTrigger(productTag, data) {
|
|
310
|
+
const builder = await this.getProductBuilder(productTag);
|
|
311
|
+
return builder.createDatabaseTrigger(data);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Update a database trigger
|
|
315
|
+
* @param productTag - The product tag
|
|
316
|
+
* @param data - The trigger configuration
|
|
317
|
+
*/
|
|
318
|
+
async updateTrigger(productTag, data) {
|
|
319
|
+
const builder = await this.getProductBuilder(productTag);
|
|
320
|
+
return builder.updateDatabaseTrigger(data);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Fetch a database trigger
|
|
324
|
+
* @param productTag - The product tag
|
|
325
|
+
* @param tag - The trigger tag (format: database_tag:trigger_tag)
|
|
326
|
+
*/
|
|
327
|
+
async fetchTrigger(productTag, tag) {
|
|
328
|
+
const builder = await this.getProductBuilder(productTag);
|
|
329
|
+
return builder.fetchDatabaseTrigger(tag);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Fetch all triggers for a database
|
|
333
|
+
* @param productTag - The product tag
|
|
334
|
+
* @param databaseTag - The database tag
|
|
335
|
+
*/
|
|
336
|
+
async fetchTriggers(productTag, databaseTag) {
|
|
337
|
+
const builder = await this.getProductBuilder(productTag);
|
|
338
|
+
return builder.fetchDatabaseTriggers(databaseTag);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Delete a database trigger
|
|
342
|
+
* @param productTag - The product tag
|
|
343
|
+
* @param tag - The trigger tag (format: database_tag:trigger_tag)
|
|
344
|
+
*/
|
|
345
|
+
async deleteTrigger(productTag, tag) {
|
|
346
|
+
const builder = await this.getProductBuilder(productTag);
|
|
347
|
+
return builder.deleteDatabaseTrigger(tag);
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Get the current service configuration
|
|
351
|
+
*/
|
|
352
|
+
getConfig() {
|
|
353
|
+
return this.config;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Update the service configuration (used after auth is complete)
|
|
357
|
+
*/
|
|
358
|
+
updateConfig(config) {
|
|
359
|
+
if (this.config) {
|
|
360
|
+
this.config = Object.assign(Object.assign({}, this.config), config);
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
this.config = config;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Get workspace ID from config
|
|
368
|
+
*/
|
|
369
|
+
getWorkspaceId() {
|
|
370
|
+
var _a;
|
|
371
|
+
return ((_a = this.config) === null || _a === void 0 ? void 0 : _a.workspace_id) || null;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Get user ID from config
|
|
375
|
+
*/
|
|
376
|
+
getUserId() {
|
|
377
|
+
var _a;
|
|
378
|
+
return ((_a = this.config) === null || _a === void 0 ? void 0 : _a.user_id) || null;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Get authentication token from config
|
|
382
|
+
*/
|
|
383
|
+
getToken() {
|
|
384
|
+
var _a;
|
|
385
|
+
return ((_a = this.config) === null || _a === void 0 ? void 0 : _a.token) || null;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Get environment type from config
|
|
389
|
+
*/
|
|
390
|
+
getEnvType() {
|
|
391
|
+
var _a;
|
|
392
|
+
return ((_a = this.config) === null || _a === void 0 ? void 0 : _a.env_type) || null;
|
|
393
|
+
}
|
|
394
|
+
// ==================== CONNECTION MANAGEMENT ====================
|
|
395
|
+
/**
|
|
396
|
+
* Create/register a new database configuration
|
|
397
|
+
*
|
|
398
|
+
* @example
|
|
399
|
+
* // Persist to product
|
|
400
|
+
* await ductape.database.create({
|
|
401
|
+
* product: 'my-product',
|
|
402
|
+
* name: 'User Database',
|
|
403
|
+
* tag: 'users-db',
|
|
404
|
+
* type: 'postgresql',
|
|
405
|
+
* description: 'Stores user accounts and profiles',
|
|
406
|
+
* envs: [
|
|
407
|
+
* { slug: 'dev', connection_url: 'postgresql://localhost:5432/myapp_dev' },
|
|
408
|
+
* { slug: 'prd', connection_url: 'postgresql://prod-host:5432/myapp_prod' },
|
|
409
|
+
* ],
|
|
410
|
+
* });
|
|
411
|
+
*
|
|
412
|
+
* // Local only (not persisted)
|
|
413
|
+
* await ductape.database.create({
|
|
414
|
+
* name: 'Temp Database',
|
|
415
|
+
* tag: 'temp-db',
|
|
416
|
+
* type: 'postgresql',
|
|
417
|
+
* envs: [{ slug: 'dev', connection_url: 'postgresql://localhost:5432/temp' }],
|
|
418
|
+
* });
|
|
419
|
+
*/
|
|
420
|
+
async create(config) {
|
|
421
|
+
var _a;
|
|
422
|
+
// Validate required fields
|
|
423
|
+
if (!config.name || !config.tag || !config.type || !((_a = config.envs) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
424
|
+
throw new database_error_1.DatabaseError('Missing required fields: name, tag, type, and envs are required', enums_1.DatabaseErrorType.VALIDATION_ERROR);
|
|
425
|
+
}
|
|
426
|
+
const exists = await this.fetchDatabase(config.product, config.tag);
|
|
427
|
+
console.log(`[DatabaseService] Creating database config: ${config.product} : ${config.tag} (exists: ${!!exists})`);
|
|
428
|
+
if (exists) {
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
// Validate database type
|
|
432
|
+
if (!Object.values(enums_1.DatabaseType).includes(config.type)) {
|
|
433
|
+
throw new database_error_1.DatabaseError(`Unsupported database type: ${config.type}. Supported types: ${Object.values(enums_1.DatabaseType).join(', ')}`, enums_1.DatabaseErrorType.VALIDATION_ERROR);
|
|
434
|
+
}
|
|
435
|
+
// Process connection URLs - store as secrets if not already secret references
|
|
436
|
+
const secretsService = (0, secrets_1.getSecretsService)();
|
|
437
|
+
const processedEnvs = [];
|
|
438
|
+
for (const env of config.envs) {
|
|
439
|
+
let connectionUrl = env.connection_url;
|
|
440
|
+
const secretCheck = (0, secrets_1.isSecretReference)(connectionUrl);
|
|
441
|
+
// If not already a secret reference and we have a secrets service, store it as a secret
|
|
442
|
+
if (!secretCheck.isSecret && secretsService && config.product) {
|
|
443
|
+
const secretKey = this.generateDbSecretKey(config.product, config.tag, env.slug);
|
|
444
|
+
try {
|
|
445
|
+
const exists = await secretsService.exists(secretKey);
|
|
446
|
+
if (exists) {
|
|
447
|
+
await secretsService.update(secretKey, { value: connectionUrl });
|
|
448
|
+
console.log(`[Secrets] Updated existing secret '${secretKey}' for database '${config.tag}' in environment '${env.slug}'`);
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
await secretsService.create({
|
|
452
|
+
key: secretKey,
|
|
453
|
+
value: connectionUrl,
|
|
454
|
+
description: `Database connection URL for ${config.tag} in ${env.slug}`,
|
|
455
|
+
scope: [config.product, config.tag],
|
|
456
|
+
envs: [env.slug],
|
|
457
|
+
});
|
|
458
|
+
console.log(`[Secrets] Created new secret '${secretKey}' for database '${config.tag}' in environment '${env.slug}'`);
|
|
459
|
+
}
|
|
460
|
+
// Update the connection URL to use the secret reference
|
|
461
|
+
connectionUrl = `$Secret{${secretKey}}`;
|
|
462
|
+
console.log(`[Secrets] Connection URL converted to secret reference: $Secret{${secretKey}}`);
|
|
463
|
+
}
|
|
464
|
+
catch (error) {
|
|
465
|
+
console.log(error);
|
|
466
|
+
console.warn(`[Secrets] Failed to store database connection URL as secret: ${secretKey} : ${error}`);
|
|
467
|
+
// Continue with the original connection URL
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
processedEnvs.push(Object.assign(Object.assign({}, env), { connection_url: connectionUrl }));
|
|
471
|
+
}
|
|
472
|
+
// Persist to ProductBuilder if product is specified
|
|
473
|
+
if (config.product) {
|
|
474
|
+
const productBuilder = await this.getProductBuilder(config.product);
|
|
475
|
+
await productBuilder.createDatabase({
|
|
476
|
+
name: config.name,
|
|
477
|
+
tag: config.tag,
|
|
478
|
+
type: config.type, // DatabaseType maps to DatabaseTypes enum
|
|
479
|
+
description: config.description,
|
|
480
|
+
envs: processedEnvs.map(env => ({
|
|
481
|
+
slug: env.slug,
|
|
482
|
+
connection_url: env.connection_url,
|
|
483
|
+
description: env.description,
|
|
484
|
+
})),
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
// Store the configuration locally - prepare the adapter for each environment
|
|
488
|
+
for (const envConfig of processedEnvs) {
|
|
489
|
+
const contextKey = this.buildContextKey(config.tag, envConfig.slug);
|
|
490
|
+
const adapter = this.adapterFactory.create(config.type);
|
|
491
|
+
this.adapters.set(contextKey, adapter);
|
|
492
|
+
this.connectionContexts.set(contextKey, {
|
|
493
|
+
database: config.tag,
|
|
494
|
+
env: envConfig.slug,
|
|
495
|
+
type: config.type,
|
|
496
|
+
connectionUrl: envConfig.connection_url,
|
|
497
|
+
connected: false,
|
|
498
|
+
name: config.name,
|
|
499
|
+
description: config.description,
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Generate a secret key for database connection URLs
|
|
505
|
+
* Format: DB_{PRODUCT}_{ASSET_TAG}_{ENV}_{KEY}
|
|
506
|
+
*
|
|
507
|
+
* Where:
|
|
508
|
+
* - PRODUCT = productTag.split('.')[1] (second part after workspace)
|
|
509
|
+
* - ASSET_TAG = if dbTag starts with same workspace prefix, use second part; otherwise sanitize full tag
|
|
510
|
+
* - All parts are automatically capitalized
|
|
511
|
+
*/
|
|
512
|
+
generateDbSecretKey(product, dbTag, env) {
|
|
513
|
+
const sanitize = (str) => str.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
514
|
+
// Support both ':' and '.' delimiters for product tags (e.g., 'ductape:rematch' or 'ductape.rematch')
|
|
515
|
+
const productParts = product.includes(':') ? product.split(':') : product.split('.');
|
|
516
|
+
const productKey = productParts[1] || productParts[0]; // Use product name (index 1), fallback to index 0
|
|
517
|
+
const workspace = productParts[0];
|
|
518
|
+
// Support both ':' and '.' delimiters for database tags
|
|
519
|
+
const dbParts = dbTag.includes(':') ? dbTag.split(':') : dbTag.split('.');
|
|
520
|
+
let assetTag;
|
|
521
|
+
if (dbParts.length > 1 && dbParts[0] === workspace) {
|
|
522
|
+
// Same workspace prefix, use second part
|
|
523
|
+
assetTag = dbParts[1];
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
// Different or no prefix, use full tag
|
|
527
|
+
assetTag = dbTag;
|
|
528
|
+
}
|
|
529
|
+
return `DB_${sanitize(productKey)}_${sanitize(assetTag)}_${sanitize(env)}_URL`;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Connect to a database
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
* const result = await ductape.database.connect({
|
|
536
|
+
* env: 'dev',
|
|
537
|
+
* product: 'my-app',
|
|
538
|
+
* database: 'users-db',
|
|
539
|
+
* });
|
|
540
|
+
* console.log('Connected:', result.connected);
|
|
541
|
+
* console.log('Database Version:', result.version);
|
|
542
|
+
* console.log('Latency:', result.latency, 'ms');
|
|
543
|
+
*
|
|
544
|
+
* // With the returned connection object, you can use scoped operations:
|
|
545
|
+
* const db = await ductape.databases.connect({ env: 'dev', product: 'my-app', database: 'users-db' });
|
|
546
|
+
* await db.triggers.create({ tag: 'my-trigger', ... });
|
|
547
|
+
*/
|
|
548
|
+
async connect(config) {
|
|
549
|
+
var _a, _b, _c, _d, _e, _f;
|
|
550
|
+
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
551
|
+
const contextKey = this.buildContextKey(config.database, config.env);
|
|
552
|
+
console.log(`[DatabaseService] Starting connection process...`);
|
|
553
|
+
console.log(`[DatabaseService] Config:`, JSON.stringify(config, null, 2));
|
|
554
|
+
console.log(`[DatabaseService] Context key: ${contextKey}`);
|
|
555
|
+
let adapter = this.adapters.get(contextKey);
|
|
556
|
+
let context = this.connectionContexts.get(contextKey);
|
|
557
|
+
console.log(`[DatabaseService] Adapter exists: ${!!adapter}`);
|
|
558
|
+
console.log(`[DatabaseService] Context exists: ${!!context}`);
|
|
559
|
+
// If not found locally, fetch from the remote API
|
|
560
|
+
if (!adapter || !context) {
|
|
561
|
+
console.log(`[DatabaseService] Adapter or context not found locally, fetching from remote...`);
|
|
562
|
+
if (!config.product) {
|
|
563
|
+
throw new database_error_1.DatabaseError(`Database '${config.database}' not found locally. Please provide 'product' to fetch from remote.`, enums_1.DatabaseErrorType.NOT_FOUND);
|
|
564
|
+
}
|
|
565
|
+
console.log(`[DatabaseService] Initializing product builder for: ${config.product}`);
|
|
566
|
+
// Initialize product builder to get productId for logging
|
|
567
|
+
await this.getProductBuilder(config.product);
|
|
568
|
+
console.log(`[DatabaseService] Fetching database config from API...`);
|
|
569
|
+
// Fetch the database config from the API
|
|
570
|
+
const dbConfig = await this.fetchDatabase(config.product, config.database);
|
|
571
|
+
console.log(`[DatabaseService] Database config received:`, JSON.stringify(dbConfig, null, 2));
|
|
572
|
+
if (!dbConfig) {
|
|
573
|
+
throw new database_error_1.DatabaseError(`Database '${config.database}' not found for product '${config.product}'.`, enums_1.DatabaseErrorType.NOT_FOUND);
|
|
574
|
+
}
|
|
575
|
+
console.log(`[DatabaseService] Looking for environment: ${config.env}`);
|
|
576
|
+
console.log(`[DatabaseService] Available environments:`, dbConfig.envs.map(e => e.slug).join(', '));
|
|
577
|
+
// Find the environment connection URL
|
|
578
|
+
const envConfig = dbConfig.envs.find((e) => e.slug === config.env);
|
|
579
|
+
if (!envConfig) {
|
|
580
|
+
throw new database_error_1.DatabaseError(`Environment '${config.env}' not found for database '${config.database}'. Available environments: ${dbConfig.envs.map(e => e.slug).join(', ')}`, enums_1.DatabaseErrorType.NOT_FOUND);
|
|
581
|
+
}
|
|
582
|
+
console.log(`[DatabaseService] Environment config found:`, JSON.stringify(envConfig, null, 2));
|
|
583
|
+
// Create and store the adapter and context
|
|
584
|
+
const databaseType = this.convertDatabaseType(dbConfig.type);
|
|
585
|
+
console.log(`[DatabaseService] Database type: ${dbConfig.type} -> ${databaseType}`);
|
|
586
|
+
console.log(`[DatabaseService] Creating adapter...`);
|
|
587
|
+
adapter = this.adapterFactory.create(databaseType);
|
|
588
|
+
console.log(`[DatabaseService] Adapter created successfully`);
|
|
589
|
+
// Resolve secret references in connection URL
|
|
590
|
+
let connectionUrl = envConfig.connection_url;
|
|
591
|
+
console.log(`[DatabaseService] Raw connection URL: ${connectionUrl}`);
|
|
592
|
+
const secretCheck = (0, secrets_1.isSecretReference)(connectionUrl);
|
|
593
|
+
console.log(`[DatabaseService] Is secret reference: ${secretCheck.isSecret}`);
|
|
594
|
+
if (secretCheck.isSecret) {
|
|
595
|
+
console.log(`[DatabaseService] Resolving secret reference...`);
|
|
596
|
+
const secretsService = (0, secrets_1.getSecretsService)();
|
|
597
|
+
if (secretsService) {
|
|
598
|
+
const resolved = await secretsService.resolve(connectionUrl, { env: config.env });
|
|
599
|
+
connectionUrl = resolved.value;
|
|
600
|
+
console.log(`[DatabaseService] Secret resolved successfully`);
|
|
601
|
+
console.log(`[DatabaseService] Resolved connection URL: ${connectionUrl}`);
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
throw new database_error_1.DatabaseError(`Connection URL contains secret reference '${connectionUrl}' but secrets service is not initialized. ` +
|
|
605
|
+
`Please ensure the Ductape client is properly initialized.`, enums_1.DatabaseErrorType.CONNECTION_ERROR);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
console.log(`[DatabaseService] Creating database config: ${config.product}:${config.database} : ${dbConfig.name} (exists: ${!!context})`);
|
|
609
|
+
context = {
|
|
610
|
+
database: config.database,
|
|
611
|
+
env: config.env,
|
|
612
|
+
type: databaseType,
|
|
613
|
+
connectionUrl,
|
|
614
|
+
connected: false,
|
|
615
|
+
name: dbConfig.name,
|
|
616
|
+
description: dbConfig.description,
|
|
617
|
+
};
|
|
618
|
+
console.log(`[DatabaseService] Context created:`, JSON.stringify(Object.assign(Object.assign({}, context), { connectionUrl: '***REDACTED***' }), null, 2));
|
|
619
|
+
this.adapters.set(contextKey, adapter);
|
|
620
|
+
this.connectionContexts.set(contextKey, context);
|
|
621
|
+
console.log(`[DatabaseService] Adapter and context stored with key: ${contextKey}`);
|
|
622
|
+
}
|
|
623
|
+
// Initialize logging
|
|
624
|
+
this.initializeLogService();
|
|
625
|
+
const baseLogs = {
|
|
626
|
+
product_tag: config.product || '',
|
|
627
|
+
workspace_id: ((_a = this.config) === null || _a === void 0 ? void 0 : _a.workspace_id) || '',
|
|
628
|
+
env: config.env,
|
|
629
|
+
process_id,
|
|
630
|
+
type: logs_types_1.LogEventTypes.DATABASE,
|
|
631
|
+
parent_tag: config.database,
|
|
632
|
+
data: { database: config.database, env: config.env },
|
|
633
|
+
};
|
|
634
|
+
(_b = this.logService) === null || _b === void 0 ? void 0 : _b.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database connect - initiated', status: logs_types_1.LogEventStatus.PROCESSING }));
|
|
635
|
+
console.log(`[DatabaseService] Calling adapter.connect() with connectionUrl...`);
|
|
636
|
+
console.log(`[DatabaseService] Connection URL length: ${context.connectionUrl.length}`);
|
|
637
|
+
console.log(`[DatabaseService] Connection URL preview: ${context.connectionUrl.substring(0, 20)}...`);
|
|
638
|
+
try {
|
|
639
|
+
console.log(`[DatabaseService] Invoking adapter.connect()...`);
|
|
640
|
+
await adapter.connect({
|
|
641
|
+
connectionUrl: context.connectionUrl,
|
|
642
|
+
});
|
|
643
|
+
console.log(`[DatabaseService] adapter.connect() completed successfully`);
|
|
644
|
+
context.connected = true;
|
|
645
|
+
context.product = config.product;
|
|
646
|
+
this.currentContext = context;
|
|
647
|
+
console.log(`[DatabaseService] Connection established and context updated`);
|
|
648
|
+
(_c = this.logService) === null || _c === void 0 ? void 0 : _c.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database connect - success', successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS }));
|
|
649
|
+
(_d = this.logService) === null || _d === void 0 ? void 0 : _d.publish();
|
|
650
|
+
// Return a DatabaseConnection object for scoped operations
|
|
651
|
+
return new DatabaseConnection(this, config.database, config.env, config.product || '');
|
|
652
|
+
}
|
|
653
|
+
catch (error) {
|
|
654
|
+
(_e = this.logService) === null || _e === void 0 ? void 0 : _e.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database connect - failed', failed_execution: true, data: { database: config.database, env: config.env, error: String(error) }, status: logs_types_1.LogEventStatus.FAIL }));
|
|
655
|
+
await ((_f = this.logService) === null || _f === void 0 ? void 0 : _f.publish());
|
|
656
|
+
throw new database_error_1.DatabaseError(`Failed to connect to database: ${error.message}`, enums_1.DatabaseErrorType.CONNECTION_ERROR, error);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Test database connection without establishing persistent connection
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* const result = await ductape.database.testConnection({
|
|
664
|
+
* env: 'dev',
|
|
665
|
+
* product: 'my-app',
|
|
666
|
+
* database: 'users-db',
|
|
667
|
+
* });
|
|
668
|
+
* if (result.connected) {
|
|
669
|
+
* console.log('Connection successful!');
|
|
670
|
+
* } else {
|
|
671
|
+
* console.error('Connection failed:', result.error);
|
|
672
|
+
* }
|
|
673
|
+
*/
|
|
674
|
+
async testConnection(config) {
|
|
675
|
+
const contextKey = this.buildContextKey(config.database, config.env);
|
|
676
|
+
let adapter = this.adapters.get(contextKey);
|
|
677
|
+
let context = this.connectionContexts.get(contextKey);
|
|
678
|
+
if (!adapter || !context) {
|
|
679
|
+
return {
|
|
680
|
+
connected: false,
|
|
681
|
+
error: `Database '${config.database}' not found for environment '${config.env}'`,
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
const startTime = Date.now();
|
|
685
|
+
try {
|
|
686
|
+
const result = await adapter.testConnection({
|
|
687
|
+
connectionUrl: context.connectionUrl,
|
|
688
|
+
});
|
|
689
|
+
return {
|
|
690
|
+
connected: result.connected,
|
|
691
|
+
version: result.version,
|
|
692
|
+
latency: Date.now() - startTime,
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
catch (error) {
|
|
696
|
+
return {
|
|
697
|
+
connected: false,
|
|
698
|
+
error: error.message,
|
|
699
|
+
latency: Date.now() - startTime,
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Disconnect from the current database
|
|
705
|
+
*/
|
|
706
|
+
async disconnect() {
|
|
707
|
+
if (this.currentContext) {
|
|
708
|
+
const contextKey = this.buildContextKey(this.currentContext.database, this.currentContext.env);
|
|
709
|
+
const adapter = this.adapters.get(contextKey);
|
|
710
|
+
if (adapter) {
|
|
711
|
+
await adapter.disconnect();
|
|
712
|
+
this.currentContext.connected = false;
|
|
713
|
+
}
|
|
714
|
+
this.currentContext = null;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Close all database connections
|
|
719
|
+
*
|
|
720
|
+
* @example
|
|
721
|
+
* await ductape.database.closeAll();
|
|
722
|
+
*/
|
|
723
|
+
async closeAll() {
|
|
724
|
+
const disconnectPromises = [];
|
|
725
|
+
for (const [key, adapter] of this.adapters) {
|
|
726
|
+
disconnectPromises.push(adapter.disconnect());
|
|
727
|
+
const context = this.connectionContexts.get(key);
|
|
728
|
+
if (context) {
|
|
729
|
+
context.connected = false;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
await Promise.all(disconnectPromises);
|
|
733
|
+
this.currentContext = null;
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Fetch all registered databases
|
|
737
|
+
*
|
|
738
|
+
* @example
|
|
739
|
+
* const databases = await ductape.database.fetchAll();
|
|
740
|
+
* databases.forEach((db) => {
|
|
741
|
+
* console.log(`${db.name} (${db.tag}): ${db.type}`);
|
|
742
|
+
* });
|
|
743
|
+
*/
|
|
744
|
+
async fetchAll(product) {
|
|
745
|
+
const databases = new Map();
|
|
746
|
+
for (const [key, context] of this.connectionContexts) {
|
|
747
|
+
if (!databases.has(context.database)) {
|
|
748
|
+
databases.set(context.database, {
|
|
749
|
+
product,
|
|
750
|
+
name: context.name || context.database,
|
|
751
|
+
tag: context.database,
|
|
752
|
+
type: context.type,
|
|
753
|
+
description: context.description,
|
|
754
|
+
envs: [],
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
databases.get(context.database).envs.push({
|
|
758
|
+
slug: context.env,
|
|
759
|
+
connection_url: context.connectionUrl,
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
return Array.from(databases.values());
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Fetch a specific database configuration
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* const usersDb = await ductape.database.fetch('users-db');
|
|
769
|
+
* console.log('Database:', usersDb.name);
|
|
770
|
+
* console.log('Type:', usersDb.type);
|
|
771
|
+
* console.log('Environments:', usersDb.envs);
|
|
772
|
+
*/
|
|
773
|
+
async fetch(product, database) {
|
|
774
|
+
const databases = await this.fetchAll(product);
|
|
775
|
+
return databases.find((db) => db.tag === database) || null;
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Update a local database configuration
|
|
779
|
+
*
|
|
780
|
+
* @example
|
|
781
|
+
* await ductape.database.updateLocalConfig('users-db', {
|
|
782
|
+
* name: 'User Database v2',
|
|
783
|
+
* description: 'Updated user storage',
|
|
784
|
+
* envs: [
|
|
785
|
+
* { slug: 'dev', connection_url: 'postgresql://new-dev-host:5432/myapp' },
|
|
786
|
+
* ],
|
|
787
|
+
* });
|
|
788
|
+
*/
|
|
789
|
+
async updateLocalConfig(tag, updates) {
|
|
790
|
+
for (const [key, context] of this.connectionContexts) {
|
|
791
|
+
if (context.database === tag) {
|
|
792
|
+
if (updates.name) {
|
|
793
|
+
context.name = updates.name;
|
|
794
|
+
}
|
|
795
|
+
if (updates.description) {
|
|
796
|
+
context.description = updates.description;
|
|
797
|
+
}
|
|
798
|
+
if (updates.envs) {
|
|
799
|
+
const envUpdate = updates.envs.find((e) => e.slug === context.env);
|
|
800
|
+
if (envUpdate) {
|
|
801
|
+
context.connectionUrl = envUpdate.connection_url;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
// ==================== QUERY OPERATIONS ====================
|
|
808
|
+
/**
|
|
809
|
+
* Query records from a table
|
|
810
|
+
*
|
|
811
|
+
* @example
|
|
812
|
+
* // With established connection
|
|
813
|
+
* const result = await ductape.database.query({
|
|
814
|
+
* table: 'users',
|
|
815
|
+
* where: { status: 'active' },
|
|
816
|
+
* orderBy: { column: 'created_at', order: 'DESC' },
|
|
817
|
+
* limit: 10,
|
|
818
|
+
* });
|
|
819
|
+
*
|
|
820
|
+
* // With explicit connection params
|
|
821
|
+
* const result = await ductape.database.query({
|
|
822
|
+
* env: 'prd',
|
|
823
|
+
* product: 'my-app',
|
|
824
|
+
* database: 'main-db',
|
|
825
|
+
* table: 'users',
|
|
826
|
+
* });
|
|
827
|
+
*/
|
|
828
|
+
async query(options) {
|
|
829
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
830
|
+
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
831
|
+
this.initializeLogService();
|
|
832
|
+
// Session log fields (will be populated if session is provided)
|
|
833
|
+
let sessionLogFields = {};
|
|
834
|
+
let resolvedOptions = options;
|
|
835
|
+
// Process session if provided
|
|
836
|
+
if (options.session && options.product) {
|
|
837
|
+
const builder = await this.getProductBuilder(options.product);
|
|
838
|
+
const privateKey = builder.fetchPrivateKey();
|
|
839
|
+
if (privateKey) {
|
|
840
|
+
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../sessions')));
|
|
841
|
+
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env);
|
|
842
|
+
if (sessionResult.error) {
|
|
843
|
+
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
844
|
+
}
|
|
845
|
+
resolvedOptions = sessionResult.input;
|
|
846
|
+
sessionLogFields = sessionResult.logFields;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
const baseLogs = Object.assign({ product_tag: options.product || '', workspace_id: ((_a = this.config) === null || _a === void 0 ? void 0 : _a.workspace_id) || '', env: options.env || '', process_id, type: logs_types_1.LogEventTypes.DATABASE, parent_tag: options.database || '', data: { table: options.table, operation: 'query' } }, sessionLogFields);
|
|
850
|
+
(_b = this.logService) === null || _b === void 0 ? void 0 : _b.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database query - initiated', status: logs_types_1.LogEventStatus.PROCESSING }));
|
|
851
|
+
try {
|
|
852
|
+
// Check cache if cache tag is provided
|
|
853
|
+
const privateKey = options.product ? this.privateKeys.get(options.product) : undefined;
|
|
854
|
+
if (options.cache && this.cacheManager && privateKey) {
|
|
855
|
+
const cacheOptions = {
|
|
856
|
+
cache_tag: options.cache,
|
|
857
|
+
product_tag: options.product || '',
|
|
858
|
+
component_tag: options.database || '',
|
|
859
|
+
component_type: 'database',
|
|
860
|
+
input: { table: options.table, where: options.where, select: options.select, orderBy: options.orderBy, limit: options.limit, offset: options.offset },
|
|
861
|
+
privateKey,
|
|
862
|
+
};
|
|
863
|
+
const cached = await this.cacheManager.fetch(cacheOptions);
|
|
864
|
+
if (cached.hit && cached.data) {
|
|
865
|
+
(_c = this.logService) === null || _c === void 0 ? void 0 : _c.add(Object.assign(Object.assign({}, baseLogs), { message: `Database query - cache hit (${cached.source})`, successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS }));
|
|
866
|
+
(_d = this.logService) === null || _d === void 0 ? void 0 : _d.publish();
|
|
867
|
+
return cached.data;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
const adapter = this.getAdapter(resolvedOptions);
|
|
871
|
+
const queryBuilder = new query_builder_1.QueryBuilder(adapter.getDatabaseType());
|
|
872
|
+
const builtQuery = queryBuilder.buildQuery(resolvedOptions);
|
|
873
|
+
const result = await adapter.query(builtQuery);
|
|
874
|
+
// Store in cache if cache tag is provided
|
|
875
|
+
if (options.cache && this.cacheManager && privateKey) {
|
|
876
|
+
const cacheOptions = {
|
|
877
|
+
cache_tag: options.cache,
|
|
878
|
+
product_tag: options.product || '',
|
|
879
|
+
component_tag: options.database || '',
|
|
880
|
+
component_type: 'database',
|
|
881
|
+
input: { table: options.table, where: options.where, select: options.select, orderBy: options.orderBy, limit: options.limit, offset: options.offset },
|
|
882
|
+
privateKey,
|
|
883
|
+
};
|
|
884
|
+
await this.cacheManager.store(cacheOptions, result);
|
|
885
|
+
}
|
|
886
|
+
(_e = this.logService) === null || _e === void 0 ? void 0 : _e.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database query - success', successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS }));
|
|
887
|
+
(_f = this.logService) === null || _f === void 0 ? void 0 : _f.publish();
|
|
888
|
+
return result;
|
|
889
|
+
}
|
|
890
|
+
catch (error) {
|
|
891
|
+
(_g = this.logService) === null || _g === void 0 ? void 0 : _g.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database query - failed', failed_execution: true, data: { table: options.table, operation: 'query', error: String(error) }, status: logs_types_1.LogEventStatus.FAIL }));
|
|
892
|
+
await ((_h = this.logService) === null || _h === void 0 ? void 0 : _h.publish());
|
|
893
|
+
throw error;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Execute a raw query
|
|
898
|
+
*
|
|
899
|
+
* @example
|
|
900
|
+
* // PostgreSQL
|
|
901
|
+
* const result = await ductape.database.raw({
|
|
902
|
+
* query: 'SELECT * FROM users WHERE created_at > $1 AND status = $2',
|
|
903
|
+
* params: [new Date('2024-01-01'), 'active'],
|
|
904
|
+
* });
|
|
905
|
+
*
|
|
906
|
+
* // MySQL
|
|
907
|
+
* const result = await ductape.database.raw({
|
|
908
|
+
* query: 'SELECT * FROM users WHERE created_at > ? AND status = ?',
|
|
909
|
+
* params: [new Date('2024-01-01'), 'active'],
|
|
910
|
+
* });
|
|
911
|
+
*
|
|
912
|
+
* // MongoDB
|
|
913
|
+
* const result = await ductape.database.raw({
|
|
914
|
+
* query: { status: 'active', created_at: { $gte: new Date('2024-01-01') } },
|
|
915
|
+
* collection: 'users',
|
|
916
|
+
* });
|
|
917
|
+
*/
|
|
918
|
+
async raw(options) {
|
|
919
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
920
|
+
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
921
|
+
this.initializeLogService();
|
|
922
|
+
const baseLogs = {
|
|
923
|
+
product_tag: options.product || '',
|
|
924
|
+
workspace_id: ((_a = this.config) === null || _a === void 0 ? void 0 : _a.workspace_id) || '',
|
|
925
|
+
env: options.env || '',
|
|
926
|
+
process_id,
|
|
927
|
+
type: logs_types_1.LogEventTypes.DATABASE,
|
|
928
|
+
parent_tag: options.database || '',
|
|
929
|
+
data: { operation: 'raw' },
|
|
930
|
+
};
|
|
931
|
+
(_b = this.logService) === null || _b === void 0 ? void 0 : _b.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database raw query - initiated', status: logs_types_1.LogEventStatus.PROCESSING }));
|
|
932
|
+
try {
|
|
933
|
+
// Check cache if cache tag is provided
|
|
934
|
+
const privateKey = options.product ? this.privateKeys.get(options.product) : undefined;
|
|
935
|
+
if (options.cache && this.cacheManager && privateKey) {
|
|
936
|
+
const cacheOptions = {
|
|
937
|
+
cache_tag: options.cache,
|
|
938
|
+
product_tag: options.product || '',
|
|
939
|
+
component_tag: options.database || '',
|
|
940
|
+
component_type: 'database',
|
|
941
|
+
input: { query: options.query, params: options.params, collection: options.collection },
|
|
942
|
+
privateKey,
|
|
943
|
+
};
|
|
944
|
+
const cached = await this.cacheManager.fetch(cacheOptions);
|
|
945
|
+
if (cached.hit && cached.data) {
|
|
946
|
+
(_c = this.logService) === null || _c === void 0 ? void 0 : _c.add(Object.assign(Object.assign({}, baseLogs), { message: `Database raw query - cache hit (${cached.source})`, successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS }));
|
|
947
|
+
(_d = this.logService) === null || _d === void 0 ? void 0 : _d.publish();
|
|
948
|
+
return cached.data;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
const adapter = this.getAdapter(options);
|
|
952
|
+
const result = await adapter.raw(options);
|
|
953
|
+
// Store in cache if cache tag is provided
|
|
954
|
+
if (options.cache && this.cacheManager && privateKey) {
|
|
955
|
+
const cacheOptions = {
|
|
956
|
+
cache_tag: options.cache,
|
|
957
|
+
product_tag: options.product || '',
|
|
958
|
+
component_tag: options.database || '',
|
|
959
|
+
component_type: 'database',
|
|
960
|
+
input: { query: options.query, params: options.params, collection: options.collection },
|
|
961
|
+
privateKey,
|
|
962
|
+
};
|
|
963
|
+
await this.cacheManager.store(cacheOptions, result);
|
|
964
|
+
}
|
|
965
|
+
(_e = this.logService) === null || _e === void 0 ? void 0 : _e.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database raw query - success', successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS }));
|
|
966
|
+
(_f = this.logService) === null || _f === void 0 ? void 0 : _f.publish();
|
|
967
|
+
return result;
|
|
968
|
+
}
|
|
969
|
+
catch (error) {
|
|
970
|
+
(_g = this.logService) === null || _g === void 0 ? void 0 : _g.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database raw query - failed', failed_execution: true, data: { operation: 'raw', error: String(error) }, status: logs_types_1.LogEventStatus.FAIL }));
|
|
971
|
+
await ((_h = this.logService) === null || _h === void 0 ? void 0 : _h.publish());
|
|
972
|
+
throw error;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
// ==================== WRITE OPERATIONS ====================
|
|
976
|
+
/**
|
|
977
|
+
* Insert one or more records
|
|
978
|
+
*
|
|
979
|
+
* @example
|
|
980
|
+
* // Single record
|
|
981
|
+
* const result = await ductape.database.insert({
|
|
982
|
+
* table: 'users',
|
|
983
|
+
* data: {
|
|
984
|
+
* name: 'Jane Doe',
|
|
985
|
+
* email: 'jane@example.com',
|
|
986
|
+
* status: 'active',
|
|
987
|
+
* },
|
|
988
|
+
* returning: true,
|
|
989
|
+
* });
|
|
990
|
+
*
|
|
991
|
+
* // Multiple records
|
|
992
|
+
* const result = await ductape.database.insert({
|
|
993
|
+
* table: 'users',
|
|
994
|
+
* data: [
|
|
995
|
+
* { name: 'User 1', email: 'user1@example.com' },
|
|
996
|
+
* { name: 'User 2', email: 'user2@example.com' },
|
|
997
|
+
* ],
|
|
998
|
+
* });
|
|
999
|
+
*
|
|
1000
|
+
* // With conflict handling (upsert)
|
|
1001
|
+
* const result = await ductape.database.insert({
|
|
1002
|
+
* table: 'users',
|
|
1003
|
+
* data: { email: 'john@example.com', name: 'John' },
|
|
1004
|
+
* onConflict: {
|
|
1005
|
+
* columns: ['email'],
|
|
1006
|
+
* action: 'update',
|
|
1007
|
+
* update: ['name'],
|
|
1008
|
+
* },
|
|
1009
|
+
* });
|
|
1010
|
+
*/
|
|
1011
|
+
async insert(options) {
|
|
1012
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1013
|
+
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
1014
|
+
this.initializeLogService();
|
|
1015
|
+
// Session log fields (will be populated if session is provided)
|
|
1016
|
+
let sessionLogFields = {};
|
|
1017
|
+
let resolvedOptions = options;
|
|
1018
|
+
// Process session if provided
|
|
1019
|
+
if (options.session && options.product) {
|
|
1020
|
+
const builder = await this.getProductBuilder(options.product);
|
|
1021
|
+
const privateKey = builder.fetchPrivateKey();
|
|
1022
|
+
if (privateKey) {
|
|
1023
|
+
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../sessions')));
|
|
1024
|
+
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env);
|
|
1025
|
+
if (sessionResult.error) {
|
|
1026
|
+
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
1027
|
+
}
|
|
1028
|
+
resolvedOptions = sessionResult.input;
|
|
1029
|
+
sessionLogFields = sessionResult.logFields;
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
const baseLogs = Object.assign({ product_tag: options.product || '', workspace_id: ((_a = this.config) === null || _a === void 0 ? void 0 : _a.workspace_id) || '', env: options.env || '', process_id, type: logs_types_1.LogEventTypes.DATABASE, parent_tag: options.database || '', data: { table: options.table, operation: 'insert' } }, sessionLogFields);
|
|
1033
|
+
(_b = this.logService) === null || _b === void 0 ? void 0 : _b.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database insert - initiated', status: logs_types_1.LogEventStatus.PROCESSING }));
|
|
1034
|
+
try {
|
|
1035
|
+
// Apply pre-save operations if specified
|
|
1036
|
+
let processedData = resolvedOptions.data;
|
|
1037
|
+
if (resolvedOptions.preSave && resolvedOptions.preSave.length > 0) {
|
|
1038
|
+
const processor = new presave_processor_1.PreSaveProcessor(resolvedOptions.preSaveConfig);
|
|
1039
|
+
const preSaveResult = await processor.process(resolvedOptions.data, resolvedOptions.preSave);
|
|
1040
|
+
processedData = preSaveResult.data;
|
|
1041
|
+
}
|
|
1042
|
+
const adapter = this.getAdapter(resolvedOptions);
|
|
1043
|
+
const result = await adapter.insert(Object.assign(Object.assign({}, resolvedOptions), { data: processedData }));
|
|
1044
|
+
(_c = this.logService) === null || _c === void 0 ? void 0 : _c.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database insert - success', successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS }));
|
|
1045
|
+
(_d = this.logService) === null || _d === void 0 ? void 0 : _d.publish();
|
|
1046
|
+
return result;
|
|
1047
|
+
}
|
|
1048
|
+
catch (error) {
|
|
1049
|
+
(_e = this.logService) === null || _e === void 0 ? void 0 : _e.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database insert - failed', failed_execution: true, data: { table: options.table, operation: 'insert', error: String(error) }, status: logs_types_1.LogEventStatus.FAIL }));
|
|
1050
|
+
await ((_f = this.logService) === null || _f === void 0 ? void 0 : _f.publish());
|
|
1051
|
+
throw error;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Update records matching conditions
|
|
1056
|
+
*
|
|
1057
|
+
* @example
|
|
1058
|
+
* // Simple update
|
|
1059
|
+
* const result = await ductape.database.update({
|
|
1060
|
+
* table: 'users',
|
|
1061
|
+
* data: { status: 'inactive' },
|
|
1062
|
+
* where: { last_login: { $LT: new Date('2023-01-01') } },
|
|
1063
|
+
* });
|
|
1064
|
+
*
|
|
1065
|
+
* // With increment/decrement
|
|
1066
|
+
* await ductape.database.update({
|
|
1067
|
+
* table: 'products',
|
|
1068
|
+
* data: { stock: { $inc: 10 } },
|
|
1069
|
+
* where: { id: productId },
|
|
1070
|
+
* });
|
|
1071
|
+
*/
|
|
1072
|
+
async update(options) {
|
|
1073
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1074
|
+
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
1075
|
+
this.initializeLogService();
|
|
1076
|
+
// Session log fields (will be populated if session is provided)
|
|
1077
|
+
let sessionLogFields = {};
|
|
1078
|
+
let resolvedOptions = options;
|
|
1079
|
+
// Process session if provided
|
|
1080
|
+
if (options.session && options.product) {
|
|
1081
|
+
const builder = await this.getProductBuilder(options.product);
|
|
1082
|
+
const privateKey = builder.fetchPrivateKey();
|
|
1083
|
+
if (privateKey) {
|
|
1084
|
+
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../sessions')));
|
|
1085
|
+
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env);
|
|
1086
|
+
if (sessionResult.error) {
|
|
1087
|
+
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
1088
|
+
}
|
|
1089
|
+
resolvedOptions = sessionResult.input;
|
|
1090
|
+
sessionLogFields = sessionResult.logFields;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
const baseLogs = Object.assign({ product_tag: options.product || '', workspace_id: ((_a = this.config) === null || _a === void 0 ? void 0 : _a.workspace_id) || '', env: options.env || '', process_id, type: logs_types_1.LogEventTypes.DATABASE, parent_tag: options.database || '', data: { table: options.table, operation: 'update' } }, sessionLogFields);
|
|
1094
|
+
(_b = this.logService) === null || _b === void 0 ? void 0 : _b.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database update - initiated', status: logs_types_1.LogEventStatus.PROCESSING }));
|
|
1095
|
+
try {
|
|
1096
|
+
// Apply pre-save operations if specified
|
|
1097
|
+
let processedData = resolvedOptions.data;
|
|
1098
|
+
if (resolvedOptions.preSave && resolvedOptions.preSave.length > 0) {
|
|
1099
|
+
const processor = new presave_processor_1.PreSaveProcessor(resolvedOptions.preSaveConfig);
|
|
1100
|
+
const preSaveResult = await processor.process(resolvedOptions.data, resolvedOptions.preSave);
|
|
1101
|
+
processedData = preSaveResult.data;
|
|
1102
|
+
}
|
|
1103
|
+
const adapter = this.getAdapter(resolvedOptions);
|
|
1104
|
+
const result = await adapter.update(Object.assign(Object.assign({}, resolvedOptions), { data: processedData }));
|
|
1105
|
+
(_c = this.logService) === null || _c === void 0 ? void 0 : _c.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database update - success', successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS }));
|
|
1106
|
+
(_d = this.logService) === null || _d === void 0 ? void 0 : _d.publish();
|
|
1107
|
+
return result;
|
|
1108
|
+
}
|
|
1109
|
+
catch (error) {
|
|
1110
|
+
(_e = this.logService) === null || _e === void 0 ? void 0 : _e.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database update - failed', failed_execution: true, data: { table: options.table, operation: 'update', error: String(error) }, status: logs_types_1.LogEventStatus.FAIL }));
|
|
1111
|
+
await ((_f = this.logService) === null || _f === void 0 ? void 0 : _f.publish());
|
|
1112
|
+
throw error;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* Delete records matching conditions
|
|
1117
|
+
*
|
|
1118
|
+
* @example
|
|
1119
|
+
* const result = await ductape.database.delete({
|
|
1120
|
+
* table: 'users',
|
|
1121
|
+
* where: { status: 'deleted' },
|
|
1122
|
+
* });
|
|
1123
|
+
* console.log('Deleted count:', result.count);
|
|
1124
|
+
*/
|
|
1125
|
+
async delete(options) {
|
|
1126
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1127
|
+
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
1128
|
+
this.initializeLogService();
|
|
1129
|
+
// Session log fields (will be populated if session is provided)
|
|
1130
|
+
let sessionLogFields = {};
|
|
1131
|
+
let resolvedOptions = options;
|
|
1132
|
+
// Process session if provided
|
|
1133
|
+
if (options.session && options.product) {
|
|
1134
|
+
const builder = await this.getProductBuilder(options.product);
|
|
1135
|
+
const privateKey = builder.fetchPrivateKey();
|
|
1136
|
+
if (privateKey) {
|
|
1137
|
+
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../sessions')));
|
|
1138
|
+
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env);
|
|
1139
|
+
if (sessionResult.error) {
|
|
1140
|
+
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
1141
|
+
}
|
|
1142
|
+
resolvedOptions = sessionResult.input;
|
|
1143
|
+
sessionLogFields = sessionResult.logFields;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
const baseLogs = Object.assign({ product_tag: options.product || '', workspace_id: ((_a = this.config) === null || _a === void 0 ? void 0 : _a.workspace_id) || '', env: options.env || '', process_id, type: logs_types_1.LogEventTypes.DATABASE, parent_tag: options.database || '', data: { table: options.table, operation: 'delete' } }, sessionLogFields);
|
|
1147
|
+
(_b = this.logService) === null || _b === void 0 ? void 0 : _b.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database delete - initiated', status: logs_types_1.LogEventStatus.PROCESSING }));
|
|
1148
|
+
try {
|
|
1149
|
+
const adapter = this.getAdapter(resolvedOptions);
|
|
1150
|
+
const result = await adapter.delete(resolvedOptions);
|
|
1151
|
+
(_c = this.logService) === null || _c === void 0 ? void 0 : _c.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database delete - success', successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS }));
|
|
1152
|
+
(_d = this.logService) === null || _d === void 0 ? void 0 : _d.publish();
|
|
1153
|
+
return result;
|
|
1154
|
+
}
|
|
1155
|
+
catch (error) {
|
|
1156
|
+
(_e = this.logService) === null || _e === void 0 ? void 0 : _e.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database delete - failed', failed_execution: true, data: { table: options.table, operation: 'delete', error: String(error) }, status: logs_types_1.LogEventStatus.FAIL }));
|
|
1157
|
+
await ((_f = this.logService) === null || _f === void 0 ? void 0 : _f.publish());
|
|
1158
|
+
throw error;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* Insert or update a record based on conflict keys
|
|
1163
|
+
*
|
|
1164
|
+
* @example
|
|
1165
|
+
* const result = await ductape.database.upsert({
|
|
1166
|
+
* table: 'user_preferences',
|
|
1167
|
+
* data: {
|
|
1168
|
+
* user_id: 123,
|
|
1169
|
+
* theme: 'dark',
|
|
1170
|
+
* language: 'en',
|
|
1171
|
+
* },
|
|
1172
|
+
* conflictKeys: ['user_id'],
|
|
1173
|
+
* });
|
|
1174
|
+
* console.log('Operation:', result.operation); // 'inserted' or 'updated'
|
|
1175
|
+
*/
|
|
1176
|
+
async upsert(options) {
|
|
1177
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1178
|
+
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
1179
|
+
this.initializeLogService();
|
|
1180
|
+
// Session log fields (will be populated if session is provided)
|
|
1181
|
+
let sessionLogFields = {};
|
|
1182
|
+
let resolvedOptions = options;
|
|
1183
|
+
// Process session if provided
|
|
1184
|
+
if (options.session && options.product) {
|
|
1185
|
+
const builder = await this.getProductBuilder(options.product);
|
|
1186
|
+
const privateKey = builder.fetchPrivateKey();
|
|
1187
|
+
if (privateKey) {
|
|
1188
|
+
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../sessions')));
|
|
1189
|
+
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env);
|
|
1190
|
+
if (sessionResult.error) {
|
|
1191
|
+
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
1192
|
+
}
|
|
1193
|
+
resolvedOptions = sessionResult.input;
|
|
1194
|
+
sessionLogFields = sessionResult.logFields;
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
const baseLogs = Object.assign({ product_tag: options.product || '', workspace_id: ((_a = this.config) === null || _a === void 0 ? void 0 : _a.workspace_id) || '', env: options.env || '', process_id, type: logs_types_1.LogEventTypes.DATABASE, parent_tag: options.database || '', data: { table: options.table, operation: 'upsert' } }, sessionLogFields);
|
|
1198
|
+
(_b = this.logService) === null || _b === void 0 ? void 0 : _b.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database upsert - initiated', status: logs_types_1.LogEventStatus.PROCESSING }));
|
|
1199
|
+
try {
|
|
1200
|
+
const adapter = this.getAdapter(resolvedOptions);
|
|
1201
|
+
const result = await adapter.upsert(resolvedOptions);
|
|
1202
|
+
(_c = this.logService) === null || _c === void 0 ? void 0 : _c.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database upsert - success', successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS }));
|
|
1203
|
+
(_d = this.logService) === null || _d === void 0 ? void 0 : _d.publish();
|
|
1204
|
+
return result;
|
|
1205
|
+
}
|
|
1206
|
+
catch (error) {
|
|
1207
|
+
(_e = this.logService) === null || _e === void 0 ? void 0 : _e.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database upsert - failed', failed_execution: true, data: { table: options.table, operation: 'upsert', error: String(error) }, status: logs_types_1.LogEventStatus.FAIL }));
|
|
1208
|
+
await ((_f = this.logService) === null || _f === void 0 ? void 0 : _f.publish());
|
|
1209
|
+
throw error;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
// ==================== AGGREGATION OPERATIONS ====================
|
|
1213
|
+
/**
|
|
1214
|
+
* Count records
|
|
1215
|
+
*
|
|
1216
|
+
* @example
|
|
1217
|
+
* const count = await ductape.database.count({
|
|
1218
|
+
* table: 'users',
|
|
1219
|
+
* where: { status: 'active' },
|
|
1220
|
+
* });
|
|
1221
|
+
*/
|
|
1222
|
+
async count(options) {
|
|
1223
|
+
const adapter = this.getAdapter(options);
|
|
1224
|
+
return adapter.count(options);
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Sum values of a column
|
|
1228
|
+
*
|
|
1229
|
+
* @example
|
|
1230
|
+
* const totalRevenue = await ductape.database.sum({
|
|
1231
|
+
* table: 'orders',
|
|
1232
|
+
* column: 'total',
|
|
1233
|
+
* where: { status: 'completed' },
|
|
1234
|
+
* });
|
|
1235
|
+
*/
|
|
1236
|
+
async sum(options) {
|
|
1237
|
+
const adapter = this.getAdapter(options);
|
|
1238
|
+
return adapter.sum(options);
|
|
1239
|
+
}
|
|
1240
|
+
/**
|
|
1241
|
+
* Calculate average of a column
|
|
1242
|
+
*
|
|
1243
|
+
* @example
|
|
1244
|
+
* const avgOrderValue = await ductape.database.avg({
|
|
1245
|
+
* table: 'orders',
|
|
1246
|
+
* column: 'total',
|
|
1247
|
+
* });
|
|
1248
|
+
*/
|
|
1249
|
+
async avg(options) {
|
|
1250
|
+
const adapter = this.getAdapter(options);
|
|
1251
|
+
return adapter.avg(options);
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
* Get minimum value of a column
|
|
1255
|
+
*
|
|
1256
|
+
* @example
|
|
1257
|
+
* const minPrice = await ductape.database.min({
|
|
1258
|
+
* table: 'products',
|
|
1259
|
+
* column: 'price',
|
|
1260
|
+
* });
|
|
1261
|
+
*/
|
|
1262
|
+
async min(options) {
|
|
1263
|
+
const adapter = this.getAdapter(options);
|
|
1264
|
+
return adapter.min(options);
|
|
1265
|
+
}
|
|
1266
|
+
/**
|
|
1267
|
+
* Get maximum value of a column
|
|
1268
|
+
*
|
|
1269
|
+
* @example
|
|
1270
|
+
* const maxPrice = await ductape.database.max({
|
|
1271
|
+
* table: 'products',
|
|
1272
|
+
* column: 'price',
|
|
1273
|
+
* });
|
|
1274
|
+
*/
|
|
1275
|
+
async max(options) {
|
|
1276
|
+
const adapter = this.getAdapter(options);
|
|
1277
|
+
return adapter.max(options);
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Perform multiple aggregations in one query
|
|
1281
|
+
*
|
|
1282
|
+
* @example
|
|
1283
|
+
* const stats = await ductape.database.aggregate({
|
|
1284
|
+
* table: 'orders',
|
|
1285
|
+
* operations: {
|
|
1286
|
+
* total_revenue: { $SUM: 'total' },
|
|
1287
|
+
* order_count: { $COUNT: '*' },
|
|
1288
|
+
* avg_order_value: { $AVG: 'total' },
|
|
1289
|
+
* },
|
|
1290
|
+
* where: { status: 'completed' },
|
|
1291
|
+
* });
|
|
1292
|
+
*/
|
|
1293
|
+
async aggregate(options) {
|
|
1294
|
+
const adapter = this.getAdapter(options);
|
|
1295
|
+
const aggregationBuilder = new aggregation_builder_1.AggregationBuilder(adapter.getDatabaseType());
|
|
1296
|
+
const builtAggregation = aggregationBuilder.buildAggregation(options);
|
|
1297
|
+
return adapter.aggregate(builtAggregation);
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
* Group records and perform aggregations
|
|
1301
|
+
*
|
|
1302
|
+
* @example
|
|
1303
|
+
* const salesByCategory = await ductape.database.groupBy({
|
|
1304
|
+
* table: 'products',
|
|
1305
|
+
* groupBy: ['category'],
|
|
1306
|
+
* operations: {
|
|
1307
|
+
* total_sales: { $SUM: 'sales_count' },
|
|
1308
|
+
* avg_price: { $AVG: 'price' },
|
|
1309
|
+
* },
|
|
1310
|
+
* having: {
|
|
1311
|
+
* total_sales: { $GT: 100 },
|
|
1312
|
+
* },
|
|
1313
|
+
* });
|
|
1314
|
+
*/
|
|
1315
|
+
async groupBy(options) {
|
|
1316
|
+
const adapter = this.getAdapter(options);
|
|
1317
|
+
const aggregationBuilder = new aggregation_builder_1.AggregationBuilder(adapter.getDatabaseType());
|
|
1318
|
+
const builtGroupBy = aggregationBuilder.buildGroupBy(options);
|
|
1319
|
+
return adapter.groupBy(builtGroupBy);
|
|
1320
|
+
}
|
|
1321
|
+
// ==================== TRANSACTION OPERATIONS ====================
|
|
1322
|
+
/**
|
|
1323
|
+
* Execute operations within a transaction (callback API - recommended)
|
|
1324
|
+
*
|
|
1325
|
+
* @example
|
|
1326
|
+
* const order = await ductape.database.transaction({
|
|
1327
|
+
* env: 'prd',
|
|
1328
|
+
* product: 'my-app',
|
|
1329
|
+
* database: 'main-db',
|
|
1330
|
+
* }, async (transaction) => {
|
|
1331
|
+
* const order = await ductape.database.insert({
|
|
1332
|
+
* table: 'orders',
|
|
1333
|
+
* data: { customer_id: 123, total: 99.99 },
|
|
1334
|
+
* transaction,
|
|
1335
|
+
* });
|
|
1336
|
+
*
|
|
1337
|
+
* await ductape.database.insert({
|
|
1338
|
+
* table: 'order_items',
|
|
1339
|
+
* data: items.map(item => ({ order_id: order.insertedIds[0], ...item })),
|
|
1340
|
+
* transaction,
|
|
1341
|
+
* });
|
|
1342
|
+
*
|
|
1343
|
+
* return order;
|
|
1344
|
+
* });
|
|
1345
|
+
*/
|
|
1346
|
+
async transaction(options, callback) {
|
|
1347
|
+
const adapter = this.getAdapter(options);
|
|
1348
|
+
return this.transactionManager.executeTransaction(adapter, options, callback);
|
|
1349
|
+
}
|
|
1350
|
+
/**
|
|
1351
|
+
* Begin a transaction manually
|
|
1352
|
+
*
|
|
1353
|
+
* @example
|
|
1354
|
+
* const transaction = await ductape.database.beginTransaction({
|
|
1355
|
+
* env: 'prd',
|
|
1356
|
+
* product: 'my-app',
|
|
1357
|
+
* database: 'main-db',
|
|
1358
|
+
* isolationLevel: 'REPEATABLE_READ',
|
|
1359
|
+
* });
|
|
1360
|
+
*
|
|
1361
|
+
* try {
|
|
1362
|
+
* await ductape.database.insert({ table: 'accounts', data: {...}, transaction });
|
|
1363
|
+
* await transaction.commit();
|
|
1364
|
+
* } catch (error) {
|
|
1365
|
+
* await transaction.rollback();
|
|
1366
|
+
* throw error;
|
|
1367
|
+
* }
|
|
1368
|
+
*/
|
|
1369
|
+
async beginTransaction(options) {
|
|
1370
|
+
const adapter = this.getAdapter(options);
|
|
1371
|
+
return this.transactionManager.beginTransaction(adapter, options);
|
|
1372
|
+
}
|
|
1373
|
+
// ==================== SCHEMA OPERATIONS ====================
|
|
1374
|
+
/**
|
|
1375
|
+
* Create a new table
|
|
1376
|
+
*
|
|
1377
|
+
* @example
|
|
1378
|
+
* import { SchemaHelpers } from '@ductape/sdk';
|
|
1379
|
+
*
|
|
1380
|
+
* await ductape.database.createTable(
|
|
1381
|
+
* { env: 'dev', product: 'my-app', database: 'main-db' },
|
|
1382
|
+
* {
|
|
1383
|
+
* name: 'products',
|
|
1384
|
+
* columns: [
|
|
1385
|
+
* SchemaHelpers.id(),
|
|
1386
|
+
* SchemaHelpers.string('name', 255, false),
|
|
1387
|
+
* SchemaHelpers.decimal('price', 10, 2),
|
|
1388
|
+
* ...SchemaHelpers.timestamps(),
|
|
1389
|
+
* ],
|
|
1390
|
+
* },
|
|
1391
|
+
* { ifNotExists: true }
|
|
1392
|
+
* );
|
|
1393
|
+
*/
|
|
1394
|
+
async createTable(connectionConfigOrDefinition, tableDefinitionOrOptions, options) {
|
|
1395
|
+
// Check if first arg is a table definition (no connectionConfig provided)
|
|
1396
|
+
if ('columns' in connectionConfigOrDefinition || 'name' in connectionConfigOrDefinition && !('env' in connectionConfigOrDefinition)) {
|
|
1397
|
+
// Using current context - connectionConfigOrDefinition is actually tableDefinition
|
|
1398
|
+
const adapter = this.getAdapter();
|
|
1399
|
+
return adapter.createTable(connectionConfigOrDefinition, tableDefinitionOrOptions);
|
|
1400
|
+
}
|
|
1401
|
+
// Using explicit connection config
|
|
1402
|
+
const adapter = this.getAdapter(connectionConfigOrDefinition);
|
|
1403
|
+
return adapter.createTable(tableDefinitionOrOptions, options);
|
|
1404
|
+
}
|
|
1405
|
+
/**
|
|
1406
|
+
* Alter an existing table
|
|
1407
|
+
*
|
|
1408
|
+
* @example
|
|
1409
|
+
* import { ColumnAlterationType, ColumnType } from '@ductape/sdk';
|
|
1410
|
+
*
|
|
1411
|
+
* // Add column
|
|
1412
|
+
* await ductape.database.alterTable(
|
|
1413
|
+
* { env: 'dev', product: 'my-app', database: 'main-db' },
|
|
1414
|
+
* 'products',
|
|
1415
|
+
* [{ type: ColumnAlterationType.ADD, column: { name: 'sku', type: ColumnType.STRING, length: 50 } }]
|
|
1416
|
+
* );
|
|
1417
|
+
*
|
|
1418
|
+
* // Drop column
|
|
1419
|
+
* await ductape.database.alterTable(
|
|
1420
|
+
* { env: 'dev', product: 'my-app', database: 'main-db' },
|
|
1421
|
+
* 'products',
|
|
1422
|
+
* [{ type: ColumnAlterationType.DROP, columnName: 'old_field' }]
|
|
1423
|
+
* );
|
|
1424
|
+
*
|
|
1425
|
+
* // Rename column
|
|
1426
|
+
* await ductape.database.alterTable(
|
|
1427
|
+
* { env: 'dev', product: 'my-app', database: 'main-db' },
|
|
1428
|
+
* 'products',
|
|
1429
|
+
* [{ type: ColumnAlterationType.RENAME, oldName: 'old_name', newName: 'new_name' }]
|
|
1430
|
+
* );
|
|
1431
|
+
*/
|
|
1432
|
+
async alterTable(connectionConfigOrTableName, tableNameOrAlterations, alterations) {
|
|
1433
|
+
// Check if first arg is a string (tableName - no connectionConfig provided)
|
|
1434
|
+
if (typeof connectionConfigOrTableName === 'string') {
|
|
1435
|
+
const adapter = this.getAdapter();
|
|
1436
|
+
return adapter.alterTable(connectionConfigOrTableName, tableNameOrAlterations);
|
|
1437
|
+
}
|
|
1438
|
+
// Using explicit connection config
|
|
1439
|
+
const adapter = this.getAdapter(connectionConfigOrTableName);
|
|
1440
|
+
return adapter.alterTable(tableNameOrAlterations, alterations);
|
|
1441
|
+
}
|
|
1442
|
+
/**
|
|
1443
|
+
* Drop a table
|
|
1444
|
+
*
|
|
1445
|
+
* @example
|
|
1446
|
+
* await ductape.database.dropTable(
|
|
1447
|
+
* { env: 'dev', product: 'my-app', database: 'main-db' },
|
|
1448
|
+
* 'old_table'
|
|
1449
|
+
* );
|
|
1450
|
+
*/
|
|
1451
|
+
async dropTable(connectionConfigOrTableName, tableName) {
|
|
1452
|
+
// Check if first arg is a string (tableName - no connectionConfig provided)
|
|
1453
|
+
if (typeof connectionConfigOrTableName === 'string') {
|
|
1454
|
+
const adapter = this.getAdapter();
|
|
1455
|
+
return adapter.dropTable(connectionConfigOrTableName, true);
|
|
1456
|
+
}
|
|
1457
|
+
// Using explicit connection config
|
|
1458
|
+
const adapter = this.getAdapter(connectionConfigOrTableName);
|
|
1459
|
+
return adapter.dropTable(tableName, true);
|
|
1460
|
+
}
|
|
1461
|
+
/**
|
|
1462
|
+
* List all tables in the database
|
|
1463
|
+
*
|
|
1464
|
+
* @example
|
|
1465
|
+
* const tables = await ductape.database.listTables({
|
|
1466
|
+
* env: 'dev',
|
|
1467
|
+
* product: 'my-app',
|
|
1468
|
+
* database: 'main-db',
|
|
1469
|
+
* });
|
|
1470
|
+
*/
|
|
1471
|
+
async listTables(connectionConfig) {
|
|
1472
|
+
const adapter = this.getAdapter(connectionConfig);
|
|
1473
|
+
return adapter.listTables();
|
|
1474
|
+
}
|
|
1475
|
+
/**
|
|
1476
|
+
* Check if a table exists
|
|
1477
|
+
*
|
|
1478
|
+
* @example
|
|
1479
|
+
* const exists = await ductape.database.tableExists(
|
|
1480
|
+
* { env: 'dev', product: 'my-app', database: 'main-db' },
|
|
1481
|
+
* 'users'
|
|
1482
|
+
* );
|
|
1483
|
+
*/
|
|
1484
|
+
async tableExists(connectionConfigOrTableName, tableName) {
|
|
1485
|
+
// Check if first arg is a string (tableName - no connectionConfig provided)
|
|
1486
|
+
if (typeof connectionConfigOrTableName === 'string') {
|
|
1487
|
+
const adapter = this.getAdapter();
|
|
1488
|
+
return adapter.tableExists(connectionConfigOrTableName);
|
|
1489
|
+
}
|
|
1490
|
+
// Using explicit connection config
|
|
1491
|
+
const adapter = this.getAdapter(connectionConfigOrTableName);
|
|
1492
|
+
return adapter.tableExists(tableName);
|
|
1493
|
+
}
|
|
1494
|
+
/**
|
|
1495
|
+
* Get the schema of a table
|
|
1496
|
+
*
|
|
1497
|
+
* @example
|
|
1498
|
+
* const schema = await ductape.database.getTableSchema(
|
|
1499
|
+
* { env: 'dev', product: 'my-app', database: 'main-db' },
|
|
1500
|
+
* 'users'
|
|
1501
|
+
* );
|
|
1502
|
+
* console.log('Table:', schema.name);
|
|
1503
|
+
* console.log('Columns:', schema.columns);
|
|
1504
|
+
* console.log('Indexes:', schema.indexes);
|
|
1505
|
+
*/
|
|
1506
|
+
async getTableSchema(connectionConfigOrTableName, tableName) {
|
|
1507
|
+
// Check if first arg is a string (tableName - no connectionConfig provided)
|
|
1508
|
+
if (typeof connectionConfigOrTableName === 'string') {
|
|
1509
|
+
const adapter = this.getAdapter();
|
|
1510
|
+
return adapter.getTableSchema(connectionConfigOrTableName);
|
|
1511
|
+
}
|
|
1512
|
+
// Using explicit connection config
|
|
1513
|
+
const adapter = this.getAdapter(connectionConfigOrTableName);
|
|
1514
|
+
return adapter.getTableSchema(tableName);
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Create an index
|
|
1518
|
+
*
|
|
1519
|
+
* @example
|
|
1520
|
+
* await ductape.database.createIndex({
|
|
1521
|
+
* env: 'dev',
|
|
1522
|
+
* product: 'my-app',
|
|
1523
|
+
* database: 'main-db',
|
|
1524
|
+
* table: 'users',
|
|
1525
|
+
* index: {
|
|
1526
|
+
* name: 'idx_users_email',
|
|
1527
|
+
* table: 'users',
|
|
1528
|
+
* columns: [{ name: 'email' }],
|
|
1529
|
+
* unique: true,
|
|
1530
|
+
* },
|
|
1531
|
+
* ifNotExists: true,
|
|
1532
|
+
* concurrent: true, // PostgreSQL: create without locking
|
|
1533
|
+
* });
|
|
1534
|
+
*/
|
|
1535
|
+
async createIndex(options) {
|
|
1536
|
+
const adapter = this.getAdapter(options);
|
|
1537
|
+
return adapter.createIndex(options.index, options.ifNotExists, options.concurrent);
|
|
1538
|
+
}
|
|
1539
|
+
/**
|
|
1540
|
+
* Drop an index
|
|
1541
|
+
*
|
|
1542
|
+
* @example
|
|
1543
|
+
* await ductape.database.dropIndex({
|
|
1544
|
+
* env: 'dev',
|
|
1545
|
+
* product: 'my-app',
|
|
1546
|
+
* database: 'main-db',
|
|
1547
|
+
* table: 'users',
|
|
1548
|
+
* indexName: 'idx_users_old',
|
|
1549
|
+
* ifExists: true,
|
|
1550
|
+
* concurrent: true,
|
|
1551
|
+
* });
|
|
1552
|
+
*/
|
|
1553
|
+
async dropIndex(options) {
|
|
1554
|
+
const adapter = this.getAdapter(options);
|
|
1555
|
+
return adapter.dropIndex(options.table, options.indexName, options.ifExists, options.concurrent, options.cascade);
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* List all indexes on a table
|
|
1559
|
+
*
|
|
1560
|
+
* @example
|
|
1561
|
+
* const indexes = await ductape.database.listIndexes({
|
|
1562
|
+
* env: 'dev',
|
|
1563
|
+
* product: 'my-app',
|
|
1564
|
+
* database: 'main-db',
|
|
1565
|
+
* table: 'users',
|
|
1566
|
+
* includeSystem: false,
|
|
1567
|
+
* });
|
|
1568
|
+
*/
|
|
1569
|
+
async listIndexes(options) {
|
|
1570
|
+
const adapter = this.getAdapter(options);
|
|
1571
|
+
return adapter.listIndexes(options.table, options.includeSystem);
|
|
1572
|
+
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Get index statistics
|
|
1575
|
+
*
|
|
1576
|
+
* @example
|
|
1577
|
+
* // All indexes on a table
|
|
1578
|
+
* const stats = await ductape.database.getIndexStatistics(
|
|
1579
|
+
* { env: 'prd', product: 'my-app', database: 'main-db' },
|
|
1580
|
+
* 'users'
|
|
1581
|
+
* );
|
|
1582
|
+
*
|
|
1583
|
+
* // Specific index
|
|
1584
|
+
* const emailStats = await ductape.database.getIndexStatistics(
|
|
1585
|
+
* { env: 'prd', product: 'my-app', database: 'main-db' },
|
|
1586
|
+
* 'users',
|
|
1587
|
+
* 'idx_users_email'
|
|
1588
|
+
* );
|
|
1589
|
+
*/
|
|
1590
|
+
async getIndexStatistics(connectionConfig, tableName, indexName) {
|
|
1591
|
+
const adapter = this.getAdapter(connectionConfig);
|
|
1592
|
+
return adapter.getIndexStatistics(tableName, indexName);
|
|
1593
|
+
}
|
|
1594
|
+
// ==================== MIGRATION OPERATIONS ====================
|
|
1595
|
+
/**
|
|
1596
|
+
* Run a migration
|
|
1597
|
+
*
|
|
1598
|
+
* @example
|
|
1599
|
+
* const result = await ductape.database.runMigration([migration]);
|
|
1600
|
+
* console.log('Migrated:', result.size);
|
|
1601
|
+
*/
|
|
1602
|
+
async runMigration(migrations, options) {
|
|
1603
|
+
const engine = this.getMigrationEngine();
|
|
1604
|
+
return engine.migrate(migrations, options);
|
|
1605
|
+
}
|
|
1606
|
+
/**
|
|
1607
|
+
* Rollback migrations
|
|
1608
|
+
*
|
|
1609
|
+
* @example
|
|
1610
|
+
* const result = await ductape.database.rollbackMigration([migration], 1);
|
|
1611
|
+
* console.log('Rolled back:', result.size);
|
|
1612
|
+
*/
|
|
1613
|
+
async rollbackMigration(migrations, count = 1) {
|
|
1614
|
+
const engine = this.getMigrationEngine();
|
|
1615
|
+
return engine.rollback(migrations, count);
|
|
1616
|
+
}
|
|
1617
|
+
/**
|
|
1618
|
+
* Get migration history (applied migrations)
|
|
1619
|
+
*
|
|
1620
|
+
* @example
|
|
1621
|
+
* const history = await ductape.database.getMigrationHistory();
|
|
1622
|
+
* history.forEach((entry) => {
|
|
1623
|
+
* console.log('Tag:', entry.tag);
|
|
1624
|
+
* console.log('Applied at:', entry.appliedAt);
|
|
1625
|
+
* });
|
|
1626
|
+
*/
|
|
1627
|
+
async getMigrationHistory() {
|
|
1628
|
+
const engine = this.getMigrationEngine();
|
|
1629
|
+
return engine.getAppliedMigrations();
|
|
1630
|
+
}
|
|
1631
|
+
/**
|
|
1632
|
+
* Get status of all migrations
|
|
1633
|
+
*
|
|
1634
|
+
* @example
|
|
1635
|
+
* const status = await ductape.database.getMigrationStatus(allMigrations);
|
|
1636
|
+
* console.log('Pending:', status.pending);
|
|
1637
|
+
*/
|
|
1638
|
+
async getMigrationStatus(migrations) {
|
|
1639
|
+
const engine = this.getMigrationEngine();
|
|
1640
|
+
return engine.getStatus(migrations);
|
|
1641
|
+
}
|
|
1642
|
+
// ==================== MIGRATION CRUD OPERATIONS ====================
|
|
1643
|
+
/**
|
|
1644
|
+
* Migration management sub-object
|
|
1645
|
+
* Provides CRUD operations for database migrations via ProductBuilder
|
|
1646
|
+
*/
|
|
1647
|
+
get migration() {
|
|
1648
|
+
return {
|
|
1649
|
+
/**
|
|
1650
|
+
* Create a new database migration
|
|
1651
|
+
*
|
|
1652
|
+
* @example
|
|
1653
|
+
* await ductape.database.migration.create({
|
|
1654
|
+
* product: 'my-product',
|
|
1655
|
+
* database: 'main-db',
|
|
1656
|
+
* data: {
|
|
1657
|
+
* name: 'Add users table',
|
|
1658
|
+
* tag: 'main-db:add-users-table',
|
|
1659
|
+
* value: {
|
|
1660
|
+
* up: ['CREATE TABLE users (id SERIAL PRIMARY KEY, email VARCHAR(255))'],
|
|
1661
|
+
* down: ['DROP TABLE users'],
|
|
1662
|
+
* },
|
|
1663
|
+
* },
|
|
1664
|
+
* });
|
|
1665
|
+
*/
|
|
1666
|
+
create: async (options) => {
|
|
1667
|
+
const builder = await this.getProductBuilder(options.product);
|
|
1668
|
+
// Format tag as database:migration if not already formatted
|
|
1669
|
+
const tag = options.data.tag.includes(':')
|
|
1670
|
+
? options.data.tag
|
|
1671
|
+
: `${options.database}:${options.data.tag}`;
|
|
1672
|
+
await builder.createDatabaseMigration({
|
|
1673
|
+
name: options.data.name,
|
|
1674
|
+
tag,
|
|
1675
|
+
description: options.data.description,
|
|
1676
|
+
value: options.data.value,
|
|
1677
|
+
});
|
|
1678
|
+
},
|
|
1679
|
+
/**
|
|
1680
|
+
* Update an existing database migration
|
|
1681
|
+
*
|
|
1682
|
+
* @example
|
|
1683
|
+
* await ductape.database.migration.update({
|
|
1684
|
+
* product: 'my-product',
|
|
1685
|
+
* tag: 'main-db:add-users-table',
|
|
1686
|
+
* data: {
|
|
1687
|
+
* description: 'Updated description',
|
|
1688
|
+
* },
|
|
1689
|
+
* });
|
|
1690
|
+
*/
|
|
1691
|
+
update: async (options) => {
|
|
1692
|
+
const builder = await this.getProductBuilder(options.product);
|
|
1693
|
+
await builder.updateDatabaseMigration(Object.assign({ tag: options.tag }, options.data));
|
|
1694
|
+
},
|
|
1695
|
+
/**
|
|
1696
|
+
* Fetch a specific database migration
|
|
1697
|
+
*
|
|
1698
|
+
* @example
|
|
1699
|
+
* const migration = await ductape.database.migration.fetch({
|
|
1700
|
+
* product: 'my-product',
|
|
1701
|
+
* tag: 'main-db:add-users-table',
|
|
1702
|
+
* });
|
|
1703
|
+
*/
|
|
1704
|
+
fetch: async (options) => {
|
|
1705
|
+
const builder = await this.getProductBuilder(options.product);
|
|
1706
|
+
return builder.fetchDatabaseMigration(options.tag);
|
|
1707
|
+
},
|
|
1708
|
+
/**
|
|
1709
|
+
* Fetch all database migrations for a database
|
|
1710
|
+
*
|
|
1711
|
+
* @example
|
|
1712
|
+
* const migrations = await ductape.database.migration.fetchAll({
|
|
1713
|
+
* product: 'my-product',
|
|
1714
|
+
* database: 'main-db',
|
|
1715
|
+
* });
|
|
1716
|
+
*/
|
|
1717
|
+
fetchAll: async (options) => {
|
|
1718
|
+
const builder = await this.getProductBuilder(options.product);
|
|
1719
|
+
return builder.fetchDatabaseMigrations(options.database);
|
|
1720
|
+
},
|
|
1721
|
+
/**
|
|
1722
|
+
* Delete a database migration
|
|
1723
|
+
*
|
|
1724
|
+
* @example
|
|
1725
|
+
* await ductape.database.migration.delete({
|
|
1726
|
+
* product: 'my-product',
|
|
1727
|
+
* tag: 'main-db:add-users-table',
|
|
1728
|
+
* });
|
|
1729
|
+
*/
|
|
1730
|
+
delete: async (options) => {
|
|
1731
|
+
const builder = await this.getProductBuilder(options.product);
|
|
1732
|
+
return builder.deleteDatabaseMigration(options.tag);
|
|
1733
|
+
},
|
|
1734
|
+
/**
|
|
1735
|
+
* Run a database migration (up)
|
|
1736
|
+
* @deprecated Migration execution has been deprecated
|
|
1737
|
+
*/
|
|
1738
|
+
run: async (_options) => {
|
|
1739
|
+
throw new Error('Migration execution has been deprecated');
|
|
1740
|
+
},
|
|
1741
|
+
/**
|
|
1742
|
+
* Rollback a database migration (down)
|
|
1743
|
+
* @deprecated Migration execution has been deprecated
|
|
1744
|
+
*/
|
|
1745
|
+
rollback: async (_options) => {
|
|
1746
|
+
throw new Error('Migration execution has been deprecated');
|
|
1747
|
+
},
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
// ==================== ACTION OPERATIONS ====================
|
|
1751
|
+
/**
|
|
1752
|
+
* Action management sub-object
|
|
1753
|
+
*/
|
|
1754
|
+
get action() {
|
|
1755
|
+
return {
|
|
1756
|
+
/**
|
|
1757
|
+
* Create a new database action
|
|
1758
|
+
*
|
|
1759
|
+
* @example
|
|
1760
|
+
* await ductape.database.action.create({
|
|
1761
|
+
* name: 'Get Users Paginated',
|
|
1762
|
+
* tag: 'postgresdb:get-users-paginated',
|
|
1763
|
+
* tableName: 'users',
|
|
1764
|
+
* operation: DatabaseActionTypes.QUERY,
|
|
1765
|
+
* template: {
|
|
1766
|
+
* where: { is_active: true },
|
|
1767
|
+
* limit: '{{limit}}',
|
|
1768
|
+
* offset: '{{offset}}',
|
|
1769
|
+
* },
|
|
1770
|
+
* });
|
|
1771
|
+
*/
|
|
1772
|
+
create: async (options) => {
|
|
1773
|
+
return this.actionManager.create(options);
|
|
1774
|
+
},
|
|
1775
|
+
/**
|
|
1776
|
+
* Update an existing action
|
|
1777
|
+
*
|
|
1778
|
+
* @example
|
|
1779
|
+
* await ductape.database.action.update({
|
|
1780
|
+
* tag: 'postgresdb:get-users',
|
|
1781
|
+
* template: { where: { status: '{{status}}' } },
|
|
1782
|
+
* });
|
|
1783
|
+
*/
|
|
1784
|
+
update: async (options) => {
|
|
1785
|
+
return this.actionManager.update(options);
|
|
1786
|
+
},
|
|
1787
|
+
/**
|
|
1788
|
+
* Fetch a specific action
|
|
1789
|
+
*
|
|
1790
|
+
* @example
|
|
1791
|
+
* const action = await ductape.database.action.fetch('postgresdb:get-users');
|
|
1792
|
+
*/
|
|
1793
|
+
fetch: async (tag) => {
|
|
1794
|
+
return this.actionManager.fetch(tag);
|
|
1795
|
+
},
|
|
1796
|
+
/**
|
|
1797
|
+
* Fetch all actions for a database
|
|
1798
|
+
*
|
|
1799
|
+
* @example
|
|
1800
|
+
* const actions = await ductape.database.action.fetchAll('postgresdb');
|
|
1801
|
+
*/
|
|
1802
|
+
fetchAll: async (databaseTag) => {
|
|
1803
|
+
return this.actionManager.fetchAll(databaseTag);
|
|
1804
|
+
},
|
|
1805
|
+
/**
|
|
1806
|
+
* Delete a database action
|
|
1807
|
+
*
|
|
1808
|
+
* @example
|
|
1809
|
+
* await ductape.database.action.delete('postgresdb:get-users');
|
|
1810
|
+
*/
|
|
1811
|
+
delete: async (tag) => {
|
|
1812
|
+
return this.actionManager.delete(tag);
|
|
1813
|
+
},
|
|
1814
|
+
/**
|
|
1815
|
+
* Dispatches a database action to run as a scheduled job.
|
|
1816
|
+
* @param {IDBActionDispatchInput} data - The database action dispatch input.
|
|
1817
|
+
* @returns {Promise<IDispatchResult>} The dispatch result with job ID and status.
|
|
1818
|
+
* @example
|
|
1819
|
+
* // Schedule a database action to run in 1 hour
|
|
1820
|
+
* await ductape.databases.action.dispatch({
|
|
1821
|
+
* product: 'my-product',
|
|
1822
|
+
* env: 'production',
|
|
1823
|
+
* database: 'users-db',
|
|
1824
|
+
* event: 'cleanup-inactive',
|
|
1825
|
+
* input: { query: { inactive: true } },
|
|
1826
|
+
* schedule: { start_at: Date.now() + 3600000 }
|
|
1827
|
+
* });
|
|
1828
|
+
*
|
|
1829
|
+
* // Run on a cron schedule
|
|
1830
|
+
* await ductape.databases.action.dispatch({
|
|
1831
|
+
* product: 'my-product',
|
|
1832
|
+
* env: 'production',
|
|
1833
|
+
* database: 'analytics-db',
|
|
1834
|
+
* event: 'aggregate-daily',
|
|
1835
|
+
* input: { query: {} },
|
|
1836
|
+
* schedule: { cron: '0 0 * * *' } // Daily at midnight
|
|
1837
|
+
* });
|
|
1838
|
+
*/
|
|
1839
|
+
dispatch: async (data) => {
|
|
1840
|
+
const processorService = this.createNewProcessor();
|
|
1841
|
+
const productBuilder = await this.getProductBuilder(data.product);
|
|
1842
|
+
const schedule = data.schedule || {};
|
|
1843
|
+
const startAt = typeof schedule.start_at === 'string'
|
|
1844
|
+
? new Date(schedule.start_at).getTime()
|
|
1845
|
+
: schedule.start_at || Date.now();
|
|
1846
|
+
// Generate job tag based on type, database, and event
|
|
1847
|
+
const jobTag = `database:${data.database}:${data.event}`;
|
|
1848
|
+
// Check if job exists, if not create it
|
|
1849
|
+
const existingJob = await productBuilder.fetchJob(jobTag);
|
|
1850
|
+
if (!existingJob) {
|
|
1851
|
+
await productBuilder.createJob({
|
|
1852
|
+
tag: jobTag,
|
|
1853
|
+
name: `Database: ${data.database}/${data.event}`,
|
|
1854
|
+
description: `Auto-created job for database action ${data.event} on database ${data.database}`,
|
|
1855
|
+
type: types_1.JobEventTypes.DATABASE_ACTION,
|
|
1856
|
+
app: data.database,
|
|
1857
|
+
event: data.event,
|
|
1858
|
+
executions: 0,
|
|
1859
|
+
intervals: schedule.every || 0,
|
|
1860
|
+
start_at: startAt,
|
|
1861
|
+
});
|
|
1862
|
+
}
|
|
1863
|
+
const jobInput = {
|
|
1864
|
+
product: data.product,
|
|
1865
|
+
env: data.env,
|
|
1866
|
+
event: jobTag,
|
|
1867
|
+
input: data.input,
|
|
1868
|
+
retries: data.retries || 0,
|
|
1869
|
+
start_at: startAt,
|
|
1870
|
+
session: data.session,
|
|
1871
|
+
cache: data.cache,
|
|
1872
|
+
repeat: schedule.cron || schedule.every ? {
|
|
1873
|
+
cron: schedule.cron,
|
|
1874
|
+
every: schedule.every,
|
|
1875
|
+
limit: schedule.limit,
|
|
1876
|
+
endDate: schedule.endDate,
|
|
1877
|
+
tz: schedule.tz,
|
|
1878
|
+
} : undefined,
|
|
1879
|
+
};
|
|
1880
|
+
await processorService.processJob(jobInput);
|
|
1881
|
+
const isRecurring = !!(schedule.cron || schedule.every);
|
|
1882
|
+
let nextRunAt;
|
|
1883
|
+
if (isRecurring && schedule.every) {
|
|
1884
|
+
nextRunAt = startAt + schedule.every;
|
|
1885
|
+
}
|
|
1886
|
+
return {
|
|
1887
|
+
job_id: (0, crypto_1.randomUUID)(),
|
|
1888
|
+
status: startAt > Date.now() ? 'scheduled' : 'queued',
|
|
1889
|
+
scheduled_at: startAt,
|
|
1890
|
+
recurring: isRecurring,
|
|
1891
|
+
next_run_at: nextRunAt,
|
|
1892
|
+
};
|
|
1893
|
+
},
|
|
1894
|
+
};
|
|
1895
|
+
}
|
|
1896
|
+
/**
|
|
1897
|
+
* Execute a database action
|
|
1898
|
+
*
|
|
1899
|
+
* @example
|
|
1900
|
+
* const users = await ductape.database.execute({
|
|
1901
|
+
* product: 'my-product',
|
|
1902
|
+
* env: 'prd',
|
|
1903
|
+
* database: 'postgresdb',
|
|
1904
|
+
* action: 'get-users-paginated',
|
|
1905
|
+
* input: {
|
|
1906
|
+
* limit: 25,
|
|
1907
|
+
* offset: 0,
|
|
1908
|
+
* },
|
|
1909
|
+
* });
|
|
1910
|
+
*/
|
|
1911
|
+
async execute(options) {
|
|
1912
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1913
|
+
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
1914
|
+
// Session log fields (will be populated if session is provided)
|
|
1915
|
+
let sessionLogFields = {};
|
|
1916
|
+
let resolvedOptions = options;
|
|
1917
|
+
// Initialize product builder and logging
|
|
1918
|
+
if (options.product) {
|
|
1919
|
+
const builder = await this.getProductBuilder(options.product);
|
|
1920
|
+
// Process session if provided
|
|
1921
|
+
if (options.session) {
|
|
1922
|
+
const privateKey = builder.fetchPrivateKey();
|
|
1923
|
+
if (privateKey) {
|
|
1924
|
+
const { processSessionForExecution } = await Promise.resolve().then(() => __importStar(require('../sessions')));
|
|
1925
|
+
const sessionResult = await processSessionForExecution(options.session, privateKey, options, options.env);
|
|
1926
|
+
if (sessionResult.error) {
|
|
1927
|
+
throw new Error(`Session validation failed: ${sessionResult.error}`);
|
|
1928
|
+
}
|
|
1929
|
+
resolvedOptions = sessionResult.input;
|
|
1930
|
+
sessionLogFields = sessionResult.logFields;
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
this.initializeLogService();
|
|
1935
|
+
const baseLogs = Object.assign({ product_tag: options.product || '', workspace_id: ((_a = this.config) === null || _a === void 0 ? void 0 : _a.workspace_id) || '', env: options.env, process_id, type: logs_types_1.LogEventTypes.DB_ACTION, parent_tag: options.database, child_tag: options.action, data: { database: options.database, action: options.action } }, sessionLogFields);
|
|
1936
|
+
(_b = this.logService) === null || _b === void 0 ? void 0 : _b.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database action execute - initiated', status: logs_types_1.LogEventStatus.PROCESSING }));
|
|
1937
|
+
try {
|
|
1938
|
+
const result = await this.actionManager.execute(resolvedOptions);
|
|
1939
|
+
(_c = this.logService) === null || _c === void 0 ? void 0 : _c.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database action execute - success', successful_execution: true, status: logs_types_1.LogEventStatus.SUCCESS }));
|
|
1940
|
+
(_d = this.logService) === null || _d === void 0 ? void 0 : _d.publish();
|
|
1941
|
+
return result;
|
|
1942
|
+
}
|
|
1943
|
+
catch (error) {
|
|
1944
|
+
(_e = this.logService) === null || _e === void 0 ? void 0 : _e.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database action execute - failed', failed_execution: true, data: { database: options.database, action: options.action, error: String(error) }, status: logs_types_1.LogEventStatus.FAIL }));
|
|
1945
|
+
await ((_f = this.logService) === null || _f === void 0 ? void 0 : _f.publish());
|
|
1946
|
+
throw error;
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
/**
|
|
1950
|
+
* Dispatches a database operation to run as a scheduled job.
|
|
1951
|
+
* Use this for direct database operations (query, insert, update, delete, etc.).
|
|
1952
|
+
* @param {IDBOperationDispatchInput} data - The database operation dispatch input.
|
|
1953
|
+
* @returns {Promise<IDispatchResult>} The dispatch result with job ID and status.
|
|
1954
|
+
* @example
|
|
1955
|
+
* // Schedule a database operation to run in 1 hour
|
|
1956
|
+
* await ductape.databases.dispatch({
|
|
1957
|
+
* product: 'my-product',
|
|
1958
|
+
* env: 'production',
|
|
1959
|
+
* database: 'users-db',
|
|
1960
|
+
* operation: 'deleteMany',
|
|
1961
|
+
* input: { filter: { inactive: true, lastLogin: { $lt: '2024-01-01' } } },
|
|
1962
|
+
* schedule: { start_at: Date.now() + 3600000 }
|
|
1963
|
+
* });
|
|
1964
|
+
*
|
|
1965
|
+
* // Run daily database cleanup
|
|
1966
|
+
* await ductape.databases.dispatch({
|
|
1967
|
+
* product: 'my-product',
|
|
1968
|
+
* env: 'production',
|
|
1969
|
+
* database: 'logs-db',
|
|
1970
|
+
* operation: 'deleteMany',
|
|
1971
|
+
* input: { filter: { createdAt: { $lt: '$DateAdd($Now(), -30, "days")' } } },
|
|
1972
|
+
* schedule: { cron: '0 3 * * *' } // Daily at 3 AM
|
|
1973
|
+
* });
|
|
1974
|
+
*/
|
|
1975
|
+
async dispatch(data) {
|
|
1976
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1977
|
+
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
1978
|
+
const processorService = this.createNewProcessor();
|
|
1979
|
+
const productBuilder = await this.getProductBuilder(data.product);
|
|
1980
|
+
const schedule = data.schedule || {};
|
|
1981
|
+
const startAt = typeof schedule.start_at === 'string'
|
|
1982
|
+
? new Date(schedule.start_at).getTime()
|
|
1983
|
+
: schedule.start_at || Date.now();
|
|
1984
|
+
// Generate job tag based on type, database, and operation
|
|
1985
|
+
const jobTag = `database-operation:${data.database}:${data.operation}`;
|
|
1986
|
+
// Initialize logging
|
|
1987
|
+
this.initializeLogService();
|
|
1988
|
+
const baseLogs = {
|
|
1989
|
+
product_tag: data.product,
|
|
1990
|
+
workspace_id: ((_a = this.config) === null || _a === void 0 ? void 0 : _a.workspace_id) || '',
|
|
1991
|
+
env: data.env,
|
|
1992
|
+
process_id,
|
|
1993
|
+
type: logs_types_1.LogEventTypes.DATABASE,
|
|
1994
|
+
parent_tag: data.database,
|
|
1995
|
+
child_tag: data.operation,
|
|
1996
|
+
data: { database: data.database, operation: data.operation },
|
|
1997
|
+
};
|
|
1998
|
+
(_b = this.logService) === null || _b === void 0 ? void 0 : _b.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database dispatch - initiated', status: logs_types_1.LogEventStatus.PROCESSING }));
|
|
1999
|
+
try {
|
|
2000
|
+
// Check if job exists, if not create it
|
|
2001
|
+
const existingJob = await productBuilder.fetchJob(jobTag);
|
|
2002
|
+
if (!existingJob) {
|
|
2003
|
+
await productBuilder.createJob({
|
|
2004
|
+
tag: jobTag,
|
|
2005
|
+
name: `Database Operation: ${data.database}/${data.operation}`,
|
|
2006
|
+
description: `Auto-created job for database operation ${data.operation} on database ${data.database}`,
|
|
2007
|
+
type: types_1.JobEventTypes.DATABASE_OPERATION,
|
|
2008
|
+
app: data.database,
|
|
2009
|
+
event: data.operation,
|
|
2010
|
+
executions: 0,
|
|
2011
|
+
intervals: schedule.every || 0,
|
|
2012
|
+
start_at: startAt,
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
const jobInput = {
|
|
2016
|
+
product: data.product,
|
|
2017
|
+
env: data.env,
|
|
2018
|
+
event: jobTag,
|
|
2019
|
+
input: data.input,
|
|
2020
|
+
retries: data.retries || 0,
|
|
2021
|
+
start_at: startAt,
|
|
2022
|
+
session: data.session,
|
|
2023
|
+
cache: data.cache,
|
|
2024
|
+
repeat: schedule.cron || schedule.every ? {
|
|
2025
|
+
cron: schedule.cron,
|
|
2026
|
+
every: schedule.every,
|
|
2027
|
+
limit: schedule.limit,
|
|
2028
|
+
endDate: schedule.endDate,
|
|
2029
|
+
tz: schedule.tz,
|
|
2030
|
+
} : undefined,
|
|
2031
|
+
};
|
|
2032
|
+
await processorService.processJob(jobInput);
|
|
2033
|
+
const isRecurring = !!(schedule.cron || schedule.every);
|
|
2034
|
+
let nextRunAt;
|
|
2035
|
+
if (isRecurring && schedule.every) {
|
|
2036
|
+
nextRunAt = startAt + schedule.every;
|
|
2037
|
+
}
|
|
2038
|
+
const job_id = (0, crypto_1.randomUUID)();
|
|
2039
|
+
(_c = this.logService) === null || _c === void 0 ? void 0 : _c.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database dispatch - success', successful_execution: true, data: { database: data.database, operation: data.operation, job_id }, status: logs_types_1.LogEventStatus.SUCCESS }));
|
|
2040
|
+
(_d = this.logService) === null || _d === void 0 ? void 0 : _d.publish();
|
|
2041
|
+
return {
|
|
2042
|
+
job_id,
|
|
2043
|
+
status: startAt > Date.now() ? 'scheduled' : 'queued',
|
|
2044
|
+
scheduled_at: startAt,
|
|
2045
|
+
recurring: isRecurring,
|
|
2046
|
+
next_run_at: nextRunAt,
|
|
2047
|
+
};
|
|
2048
|
+
}
|
|
2049
|
+
catch (error) {
|
|
2050
|
+
(_e = this.logService) === null || _e === void 0 ? void 0 : _e.add(Object.assign(Object.assign({}, baseLogs), { message: 'Database dispatch - failed', failed_execution: true, data: { database: data.database, operation: data.operation, error: String(error) }, status: logs_types_1.LogEventStatus.FAIL }));
|
|
2051
|
+
await ((_f = this.logService) === null || _f === void 0 ? void 0 : _f.publish());
|
|
2052
|
+
throw error;
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
// ==================== HELPER METHODS ====================
|
|
2056
|
+
/**
|
|
2057
|
+
* Get the appropriate adapter for the operation
|
|
2058
|
+
*/
|
|
2059
|
+
getAdapter(options) {
|
|
2060
|
+
// If options specify env and database, use those
|
|
2061
|
+
if ((options === null || options === void 0 ? void 0 : options.env) && (options === null || options === void 0 ? void 0 : options.database)) {
|
|
2062
|
+
const contextKey = this.buildContextKey(options.database, options.env);
|
|
2063
|
+
const adapter = this.adapters.get(contextKey);
|
|
2064
|
+
if (!adapter) {
|
|
2065
|
+
throw new database_error_1.DatabaseError(`No adapter found for database '${options.database}' in environment '${options.env}'`, enums_1.DatabaseErrorType.NOT_FOUND);
|
|
2066
|
+
}
|
|
2067
|
+
return adapter;
|
|
2068
|
+
}
|
|
2069
|
+
// Otherwise use current context
|
|
2070
|
+
if (!this.currentContext) {
|
|
2071
|
+
throw new database_error_1.DatabaseError('No database connection established. Call connect() first or provide env and database options.', enums_1.DatabaseErrorType.CONNECTION_ERROR);
|
|
2072
|
+
}
|
|
2073
|
+
const contextKey = this.buildContextKey(this.currentContext.database, this.currentContext.env);
|
|
2074
|
+
const adapter = this.adapters.get(contextKey);
|
|
2075
|
+
if (!adapter) {
|
|
2076
|
+
throw new database_error_1.DatabaseError('No adapter found for current connection context', enums_1.DatabaseErrorType.CONNECTION_ERROR);
|
|
2077
|
+
}
|
|
2078
|
+
return adapter;
|
|
2079
|
+
}
|
|
2080
|
+
/**
|
|
2081
|
+
* Get the current connection context
|
|
2082
|
+
*/
|
|
2083
|
+
getCurrentContext() {
|
|
2084
|
+
return this.currentContext;
|
|
2085
|
+
}
|
|
2086
|
+
/**
|
|
2087
|
+
* Get a connection-scoped interface for a specific database/environment.
|
|
2088
|
+
* This ensures schema operations are isolated to a specific connection.
|
|
2089
|
+
*
|
|
2090
|
+
* @example
|
|
2091
|
+
* const usersDb = db.connection('users-db', 'dev');
|
|
2092
|
+
* await usersDb.schema.create('users', { ... });
|
|
2093
|
+
*
|
|
2094
|
+
* const ordersDb = db.connection('orders-db', 'dev');
|
|
2095
|
+
* await ordersDb.schema.create('orders', { ... }); // Different connection
|
|
2096
|
+
*/
|
|
2097
|
+
connection(database, env, product = '') {
|
|
2098
|
+
return new DatabaseConnection(this, database, env, product);
|
|
2099
|
+
}
|
|
2100
|
+
/**
|
|
2101
|
+
* Build a context key from database and environment
|
|
2102
|
+
*/
|
|
2103
|
+
buildContextKey(database, env) {
|
|
2104
|
+
return `${database}:${env}`;
|
|
2105
|
+
}
|
|
2106
|
+
/**
|
|
2107
|
+
* Convert DatabaseTypes (from product API) to DatabaseType (ORM internal)
|
|
2108
|
+
*/
|
|
2109
|
+
convertDatabaseType(type) {
|
|
2110
|
+
// Map from DatabaseTypes enum values to DatabaseType enum
|
|
2111
|
+
const typeMap = {
|
|
2112
|
+
'postgresql': enums_1.DatabaseType.POSTGRESQL,
|
|
2113
|
+
'mongodb': enums_1.DatabaseType.MONGODB,
|
|
2114
|
+
'mysql': enums_1.DatabaseType.MYSQL,
|
|
2115
|
+
'dynamodb': enums_1.DatabaseType.DYNAMODB,
|
|
2116
|
+
'mariadb': enums_1.DatabaseType.MARIADB,
|
|
2117
|
+
'cassandra': enums_1.DatabaseType.CASSANDRA,
|
|
2118
|
+
};
|
|
2119
|
+
const normalizedType = String(type).toLowerCase();
|
|
2120
|
+
const mappedType = typeMap[normalizedType];
|
|
2121
|
+
if (!mappedType) {
|
|
2122
|
+
throw new database_error_1.DatabaseError(`Unsupported database type: ${type}. Supported types: ${Object.keys(typeMap).join(', ')}`, enums_1.DatabaseErrorType.VALIDATION_ERROR);
|
|
2123
|
+
}
|
|
2124
|
+
return mappedType;
|
|
2125
|
+
}
|
|
2126
|
+
// ==================== SIMPLIFIED SCHEMA API ====================
|
|
2127
|
+
/**
|
|
2128
|
+
* Simplified schema operations API (Mongoose-style)
|
|
2129
|
+
*
|
|
2130
|
+
* @example
|
|
2131
|
+
* await db.connect({ env: 'dev', product: 'my-app', database: 'users-db' });
|
|
2132
|
+
*
|
|
2133
|
+
* // Create a table with Mongoose-style schema
|
|
2134
|
+
* await db.schema.create('users', {
|
|
2135
|
+
* id: { type: 'uuid', primaryKey: true },
|
|
2136
|
+
* email: { type: 'string', length: 255, required: true, unique: true },
|
|
2137
|
+
* name: { type: 'string', length: 100 },
|
|
2138
|
+
* age: 'integer', // Shorthand
|
|
2139
|
+
* status: { type: 'enum', enum: ['active', 'inactive'], default: 'active' },
|
|
2140
|
+
* }, { timestamps: true });
|
|
2141
|
+
*/
|
|
2142
|
+
get schema() {
|
|
2143
|
+
return {
|
|
2144
|
+
/**
|
|
2145
|
+
* Create a collection/table with Mongoose-style schema definition
|
|
2146
|
+
*/
|
|
2147
|
+
create: (name, definition, options) => this.schemaCreate(name, definition, options),
|
|
2148
|
+
/**
|
|
2149
|
+
* Drop a collection/table
|
|
2150
|
+
*/
|
|
2151
|
+
drop: (name, options) => this.schemaDrop(name, options),
|
|
2152
|
+
/**
|
|
2153
|
+
* Add a field to a collection
|
|
2154
|
+
*/
|
|
2155
|
+
addField: (collection, fieldName, definition) => this.schemaAddField(collection, fieldName, definition),
|
|
2156
|
+
/**
|
|
2157
|
+
* Drop a field from a collection
|
|
2158
|
+
*/
|
|
2159
|
+
dropField: (collection, fieldName) => this.schemaDropField(collection, fieldName),
|
|
2160
|
+
/**
|
|
2161
|
+
* Rename a field in a collection
|
|
2162
|
+
*/
|
|
2163
|
+
renameField: (collection, oldName, newName) => this.schemaRenameField(collection, oldName, newName),
|
|
2164
|
+
/**
|
|
2165
|
+
* Modify a field's definition
|
|
2166
|
+
*/
|
|
2167
|
+
modifyField: (collection, fieldName, changes) => this.schemaModifyField(collection, fieldName, changes),
|
|
2168
|
+
/**
|
|
2169
|
+
* Create an index on a collection
|
|
2170
|
+
*/
|
|
2171
|
+
createIndex: (collection, fields, options) => this.schemaCreateIndex(collection, fields, options),
|
|
2172
|
+
/**
|
|
2173
|
+
* Drop an index from a collection
|
|
2174
|
+
*/
|
|
2175
|
+
dropIndex: (collection, indexName) => this.schemaDropIndex(collection, indexName),
|
|
2176
|
+
/**
|
|
2177
|
+
* Add a constraint (SQL databases only)
|
|
2178
|
+
*/
|
|
2179
|
+
addConstraint: (collection, constraint) => this.schemaAddConstraint(collection, constraint),
|
|
2180
|
+
/**
|
|
2181
|
+
* Drop a constraint (SQL databases only)
|
|
2182
|
+
*/
|
|
2183
|
+
dropConstraint: (collection, constraintName) => this.schemaDropConstraint(collection, constraintName),
|
|
2184
|
+
/**
|
|
2185
|
+
* Rename a collection/table
|
|
2186
|
+
*/
|
|
2187
|
+
rename: (oldName, newName) => this.schemaRename(oldName, newName),
|
|
2188
|
+
/**
|
|
2189
|
+
* Check if a collection/table exists
|
|
2190
|
+
*/
|
|
2191
|
+
exists: (name) => this.schemaExists(name),
|
|
2192
|
+
/**
|
|
2193
|
+
* List all collections/tables
|
|
2194
|
+
*/
|
|
2195
|
+
list: (schemaName) => this.schemaList(schemaName),
|
|
2196
|
+
/**
|
|
2197
|
+
* Get detailed schema information for a collection
|
|
2198
|
+
*/
|
|
2199
|
+
describe: (name) => this.schemaDescribe(name),
|
|
2200
|
+
/**
|
|
2201
|
+
* List indexes on a collection
|
|
2202
|
+
*/
|
|
2203
|
+
indexes: (collection) => this.schemaListIndexes(collection),
|
|
2204
|
+
};
|
|
2205
|
+
}
|
|
2206
|
+
// ==================== PRIVATE SCHEMA IMPLEMENTATION ====================
|
|
2207
|
+
/**
|
|
2208
|
+
* Create a collection with Mongoose-style definition
|
|
2209
|
+
*/
|
|
2210
|
+
async schemaCreate(name, definition, options) {
|
|
2211
|
+
var _a;
|
|
2212
|
+
const schemaManager = this.getSchemaManager();
|
|
2213
|
+
const fields = this.convertToFieldDefinitions(definition, options === null || options === void 0 ? void 0 : options.timestamps);
|
|
2214
|
+
// Convert simple index definitions to the expected format
|
|
2215
|
+
const indexes = (_a = options === null || options === void 0 ? void 0 : options.indexes) === null || _a === void 0 ? void 0 : _a.map(idx => ({
|
|
2216
|
+
name: idx.name || `idx_${name}_${Array.isArray(idx.fields) ? (typeof idx.fields[0] === 'string' ? idx.fields.join('_') : idx.fields.map((f) => f.name).join('_')) : idx.fields}`,
|
|
2217
|
+
fields: this.normalizeIndexFields(idx.fields),
|
|
2218
|
+
unique: idx.unique,
|
|
2219
|
+
}));
|
|
2220
|
+
return schemaManager.createCollection(name, fields, {
|
|
2221
|
+
autoApply: true,
|
|
2222
|
+
indexes,
|
|
2223
|
+
sqlOptions: options === null || options === void 0 ? void 0 : options.sqlOptions,
|
|
2224
|
+
mongoOptions: options === null || options === void 0 ? void 0 : options.mongoOptions,
|
|
2225
|
+
dynamoOptions: options === null || options === void 0 ? void 0 : options.dynamoOptions,
|
|
2226
|
+
cassandraOptions: options === null || options === void 0 ? void 0 : options.cassandraOptions,
|
|
2227
|
+
});
|
|
2228
|
+
}
|
|
2229
|
+
/**
|
|
2230
|
+
* Drop a collection
|
|
2231
|
+
*/
|
|
2232
|
+
async schemaDrop(name, options) {
|
|
2233
|
+
const schemaManager = this.getSchemaManager();
|
|
2234
|
+
return schemaManager.dropCollection(name, {
|
|
2235
|
+
autoApply: true,
|
|
2236
|
+
ifExists: options === null || options === void 0 ? void 0 : options.ifExists,
|
|
2237
|
+
cascade: options === null || options === void 0 ? void 0 : options.cascade,
|
|
2238
|
+
});
|
|
2239
|
+
}
|
|
2240
|
+
/**
|
|
2241
|
+
* Add a field to a collection
|
|
2242
|
+
*/
|
|
2243
|
+
async schemaAddField(collection, fieldName, definition) {
|
|
2244
|
+
const schemaManager = this.getSchemaManager();
|
|
2245
|
+
const field = this.convertFieldDefinition(fieldName, definition);
|
|
2246
|
+
return schemaManager.addField(collection, field, { autoApply: true });
|
|
2247
|
+
}
|
|
2248
|
+
/**
|
|
2249
|
+
* Drop a field from a collection
|
|
2250
|
+
*/
|
|
2251
|
+
async schemaDropField(collection, fieldName) {
|
|
2252
|
+
const schemaManager = this.getSchemaManager();
|
|
2253
|
+
return schemaManager.dropField(collection, fieldName, { autoApply: true });
|
|
2254
|
+
}
|
|
2255
|
+
/**
|
|
2256
|
+
* Rename a field
|
|
2257
|
+
*/
|
|
2258
|
+
async schemaRenameField(collection, oldName, newName) {
|
|
2259
|
+
const schemaManager = this.getSchemaManager();
|
|
2260
|
+
return schemaManager.renameField(collection, oldName, newName, { autoApply: true });
|
|
2261
|
+
}
|
|
2262
|
+
/**
|
|
2263
|
+
* Modify a field's definition
|
|
2264
|
+
*/
|
|
2265
|
+
async schemaModifyField(collection, fieldName, changes) {
|
|
2266
|
+
const schemaManager = this.getSchemaManager();
|
|
2267
|
+
const fieldChanges = {};
|
|
2268
|
+
if (changes.type) {
|
|
2269
|
+
fieldChanges.type = this.normalizeFieldType(changes.type);
|
|
2270
|
+
}
|
|
2271
|
+
if (changes.minLength !== undefined) {
|
|
2272
|
+
fieldChanges.minLength = changes.minLength;
|
|
2273
|
+
}
|
|
2274
|
+
if (changes.maxLength !== undefined) {
|
|
2275
|
+
fieldChanges.maxLength = changes.maxLength;
|
|
2276
|
+
}
|
|
2277
|
+
if (changes.precision !== undefined) {
|
|
2278
|
+
fieldChanges.precision = changes.precision;
|
|
2279
|
+
}
|
|
2280
|
+
if (changes.scale !== undefined) {
|
|
2281
|
+
fieldChanges.scale = changes.scale;
|
|
2282
|
+
}
|
|
2283
|
+
if (changes.required !== undefined) {
|
|
2284
|
+
fieldChanges.nullable = !changes.required;
|
|
2285
|
+
}
|
|
2286
|
+
if (changes.unique !== undefined) {
|
|
2287
|
+
fieldChanges.unique = changes.unique;
|
|
2288
|
+
}
|
|
2289
|
+
if (changes.default !== undefined) {
|
|
2290
|
+
fieldChanges.defaultValue = changes.default;
|
|
2291
|
+
}
|
|
2292
|
+
if (changes.enum !== undefined) {
|
|
2293
|
+
fieldChanges.enumValues = changes.enum;
|
|
2294
|
+
}
|
|
2295
|
+
return schemaManager.modifyField(collection, fieldName, fieldChanges, { autoApply: true });
|
|
2296
|
+
}
|
|
2297
|
+
/**
|
|
2298
|
+
* Create an index
|
|
2299
|
+
*/
|
|
2300
|
+
async schemaCreateIndex(collection, fields, options) {
|
|
2301
|
+
const schemaManager = this.getSchemaManager();
|
|
2302
|
+
const normalizedFields = this.normalizeIndexFields(fields);
|
|
2303
|
+
const indexName = (options === null || options === void 0 ? void 0 : options.name) || `idx_${collection}_${normalizedFields.map(f => f.name).join('_')}`;
|
|
2304
|
+
return schemaManager.createIndex(collection, indexName, normalizedFields, {
|
|
2305
|
+
autoApply: true,
|
|
2306
|
+
unique: options === null || options === void 0 ? void 0 : options.unique,
|
|
2307
|
+
sparse: options === null || options === void 0 ? void 0 : options.sparse,
|
|
2308
|
+
sqlOptions: (options === null || options === void 0 ? void 0 : options.where) ? { where: options.where } : undefined,
|
|
2309
|
+
mongoOptions: (options === null || options === void 0 ? void 0 : options.expireAfterSeconds) ? { expireAfterSeconds: options.expireAfterSeconds } : undefined,
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
/**
|
|
2313
|
+
* Drop an index
|
|
2314
|
+
*/
|
|
2315
|
+
async schemaDropIndex(collection, indexName) {
|
|
2316
|
+
const schemaManager = this.getSchemaManager();
|
|
2317
|
+
return schemaManager.dropIndex(collection, indexName, { autoApply: true, ifExists: true });
|
|
2318
|
+
}
|
|
2319
|
+
/**
|
|
2320
|
+
* Add a constraint (SQL only)
|
|
2321
|
+
*/
|
|
2322
|
+
async schemaAddConstraint(collection, constraint) {
|
|
2323
|
+
const schemaManager = this.getSchemaManager();
|
|
2324
|
+
return schemaManager.addConstraint(collection, constraint, { autoApply: true });
|
|
2325
|
+
}
|
|
2326
|
+
/**
|
|
2327
|
+
* Drop a constraint (SQL only)
|
|
2328
|
+
*/
|
|
2329
|
+
async schemaDropConstraint(collection, constraintName) {
|
|
2330
|
+
const schemaManager = this.getSchemaManager();
|
|
2331
|
+
return schemaManager.dropConstraint(collection, constraintName, { autoApply: true });
|
|
2332
|
+
}
|
|
2333
|
+
/**
|
|
2334
|
+
* Rename a collection
|
|
2335
|
+
*/
|
|
2336
|
+
async schemaRename(oldName, newName) {
|
|
2337
|
+
const schemaManager = this.getSchemaManager();
|
|
2338
|
+
return schemaManager.renameCollection(oldName, newName, { autoApply: true });
|
|
2339
|
+
}
|
|
2340
|
+
/**
|
|
2341
|
+
* Check if collection exists
|
|
2342
|
+
*/
|
|
2343
|
+
async schemaExists(name) {
|
|
2344
|
+
const schemaManager = this.getSchemaManager();
|
|
2345
|
+
return schemaManager.collectionExists(name);
|
|
2346
|
+
}
|
|
2347
|
+
/**
|
|
2348
|
+
* List all collections
|
|
2349
|
+
*/
|
|
2350
|
+
async schemaList(schemaName) {
|
|
2351
|
+
const schemaManager = this.getSchemaManager();
|
|
2352
|
+
return schemaManager.listCollections(schemaName);
|
|
2353
|
+
}
|
|
2354
|
+
/**
|
|
2355
|
+
* Describe a collection's schema
|
|
2356
|
+
*/
|
|
2357
|
+
async schemaDescribe(name) {
|
|
2358
|
+
const schemaManager = this.getSchemaManager();
|
|
2359
|
+
return schemaManager.getCollectionSchema(name);
|
|
2360
|
+
}
|
|
2361
|
+
/**
|
|
2362
|
+
* List indexes on a collection
|
|
2363
|
+
*/
|
|
2364
|
+
async schemaListIndexes(collection) {
|
|
2365
|
+
const schemaManager = this.getSchemaManager();
|
|
2366
|
+
return schemaManager.listIndexes(collection);
|
|
2367
|
+
}
|
|
2368
|
+
// ==================== SCHEMA CONVERSION HELPERS ====================
|
|
2369
|
+
/**
|
|
2370
|
+
* Convert Mongoose-style schema definition to IFieldDefinition array
|
|
2371
|
+
*/
|
|
2372
|
+
convertToFieldDefinitions(definition, timestamps) {
|
|
2373
|
+
const fields = [];
|
|
2374
|
+
for (const [name, config] of Object.entries(definition)) {
|
|
2375
|
+
fields.push(this.convertFieldDefinition(name, config));
|
|
2376
|
+
}
|
|
2377
|
+
if (timestamps) {
|
|
2378
|
+
fields.push({ name: 'created_at', type: 'timestamp', defaultValue: 'NOW()', nullable: false }, { name: 'updated_at', type: 'timestamp', defaultValue: 'NOW()', nullable: false });
|
|
2379
|
+
}
|
|
2380
|
+
return fields;
|
|
2381
|
+
}
|
|
2382
|
+
/**
|
|
2383
|
+
* Convert a single field definition
|
|
2384
|
+
*/
|
|
2385
|
+
convertFieldDefinition(name, config) {
|
|
2386
|
+
// Handle shorthand: { name: 'string' }
|
|
2387
|
+
if (typeof config === 'string') {
|
|
2388
|
+
return { name, type: this.normalizeFieldType(config) };
|
|
2389
|
+
}
|
|
2390
|
+
// Validate autoIncrement only works with numeric types
|
|
2391
|
+
if (config.autoIncrement) {
|
|
2392
|
+
const normalizedType = this.normalizeFieldType(config.type);
|
|
2393
|
+
const numericTypes = ['integer', 'int', 'bigint', 'smallint', 'number', 'float', 'double', 'decimal'];
|
|
2394
|
+
if (!numericTypes.includes(normalizedType.toLowerCase())) {
|
|
2395
|
+
throw new database_error_1.DatabaseError(`autoIncrement can only be used with numeric types (integer, bigint, number, etc.), but field '${name}' has type '${config.type}'`, enums_1.DatabaseErrorType.VALIDATION_ERROR);
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
// Handle full definition
|
|
2399
|
+
return {
|
|
2400
|
+
name,
|
|
2401
|
+
type: this.normalizeFieldType(config.type),
|
|
2402
|
+
nullable: config.required === undefined ? true : !config.required,
|
|
2403
|
+
unique: config.unique,
|
|
2404
|
+
primaryKey: config.primaryKey,
|
|
2405
|
+
autoGenerate: config.autoIncrement,
|
|
2406
|
+
defaultValue: config.default,
|
|
2407
|
+
minLength: config.minLength,
|
|
2408
|
+
maxLength: config.maxLength,
|
|
2409
|
+
precision: config.precision,
|
|
2410
|
+
scale: config.scale,
|
|
2411
|
+
enumValues: config.enum,
|
|
2412
|
+
comment: config.comment,
|
|
2413
|
+
};
|
|
2414
|
+
}
|
|
2415
|
+
/**
|
|
2416
|
+
* Normalize Mongoose-style type names to FieldType
|
|
2417
|
+
*/
|
|
2418
|
+
normalizeFieldType(type) {
|
|
2419
|
+
const typeMap = {
|
|
2420
|
+
'String': 'string',
|
|
2421
|
+
'Number': 'integer',
|
|
2422
|
+
'Boolean': 'boolean',
|
|
2423
|
+
'Date': 'datetime',
|
|
2424
|
+
'ObjectId': 'uuid',
|
|
2425
|
+
'Array': 'array',
|
|
2426
|
+
'Object': 'json',
|
|
2427
|
+
'Mixed': 'json',
|
|
2428
|
+
};
|
|
2429
|
+
return typeMap[type] || type;
|
|
2430
|
+
}
|
|
2431
|
+
/**
|
|
2432
|
+
* Normalize index fields to IIndexFieldDefinition array
|
|
2433
|
+
*/
|
|
2434
|
+
normalizeIndexFields(fields) {
|
|
2435
|
+
if (fields.length === 0) {
|
|
2436
|
+
return [];
|
|
2437
|
+
}
|
|
2438
|
+
// Check if first element is a string
|
|
2439
|
+
if (typeof fields[0] === 'string') {
|
|
2440
|
+
return fields.map(name => ({ name }));
|
|
2441
|
+
}
|
|
2442
|
+
return fields;
|
|
2443
|
+
}
|
|
2444
|
+
/**
|
|
2445
|
+
* Get adapter by context key (used by DatabaseConnection)
|
|
2446
|
+
* @internal
|
|
2447
|
+
*/
|
|
2448
|
+
getAdapterByContextKey(contextKey) {
|
|
2449
|
+
const adapter = this.adapters.get(contextKey);
|
|
2450
|
+
if (!adapter) {
|
|
2451
|
+
throw new database_error_1.DatabaseError(`No adapter found for context '${contextKey}'. Call connect() first.`, enums_1.DatabaseErrorType.CONNECTION_ERROR);
|
|
2452
|
+
}
|
|
2453
|
+
return adapter;
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
exports.DatabaseService = DatabaseService;
|
|
2457
|
+
/**
|
|
2458
|
+
* Connection-scoped database interface.
|
|
2459
|
+
* Provides isolated schema, query, and aggregation operations for a specific database/environment.
|
|
2460
|
+
*/
|
|
2461
|
+
class DatabaseConnection {
|
|
2462
|
+
constructor(service, database, env, product) {
|
|
2463
|
+
this.service = service;
|
|
2464
|
+
this._database = database;
|
|
2465
|
+
this._env = env;
|
|
2466
|
+
this._product = product;
|
|
2467
|
+
this.contextKey = `${database}:${env}`;
|
|
2468
|
+
this.triggerProcessor = new trigger_processor_1.TriggerProcessor({}, null);
|
|
2469
|
+
}
|
|
2470
|
+
/** Database tag */
|
|
2471
|
+
get database() {
|
|
2472
|
+
return this._database;
|
|
2473
|
+
}
|
|
2474
|
+
/** Environment slug */
|
|
2475
|
+
get env() {
|
|
2476
|
+
return this._env;
|
|
2477
|
+
}
|
|
2478
|
+
/** Product tag */
|
|
2479
|
+
get product() {
|
|
2480
|
+
return this._product;
|
|
2481
|
+
}
|
|
2482
|
+
/** Get the adapter for this connection */
|
|
2483
|
+
getAdapter() {
|
|
2484
|
+
return this.service.getAdapterByContextKey(this.contextKey);
|
|
2485
|
+
}
|
|
2486
|
+
/**
|
|
2487
|
+
* Schema operations scoped to this connection
|
|
2488
|
+
*/
|
|
2489
|
+
get schema() {
|
|
2490
|
+
const adapter = () => this.getAdapter();
|
|
2491
|
+
const service = this.service;
|
|
2492
|
+
return {
|
|
2493
|
+
create: async (name, definition, options) => {
|
|
2494
|
+
var _a;
|
|
2495
|
+
const schemaManager = new schema_manager_1.SchemaManager(adapter());
|
|
2496
|
+
const fields = service.convertToFieldDefinitions(definition, options === null || options === void 0 ? void 0 : options.timestamps);
|
|
2497
|
+
const indexes = (_a = options === null || options === void 0 ? void 0 : options.indexes) === null || _a === void 0 ? void 0 : _a.map(idx => ({
|
|
2498
|
+
name: idx.name || `idx_${name}_${Array.isArray(idx.fields) ? (typeof idx.fields[0] === 'string' ? idx.fields.join('_') : idx.fields.map((f) => f.name).join('_')) : idx.fields}`,
|
|
2499
|
+
fields: service.normalizeIndexFields(idx.fields),
|
|
2500
|
+
unique: idx.unique,
|
|
2501
|
+
}));
|
|
2502
|
+
return schemaManager.createCollection(name, fields, {
|
|
2503
|
+
autoApply: true,
|
|
2504
|
+
indexes,
|
|
2505
|
+
sqlOptions: options === null || options === void 0 ? void 0 : options.sqlOptions,
|
|
2506
|
+
mongoOptions: options === null || options === void 0 ? void 0 : options.mongoOptions,
|
|
2507
|
+
dynamoOptions: options === null || options === void 0 ? void 0 : options.dynamoOptions,
|
|
2508
|
+
cassandraOptions: options === null || options === void 0 ? void 0 : options.cassandraOptions,
|
|
2509
|
+
});
|
|
2510
|
+
},
|
|
2511
|
+
drop: async (name, options) => {
|
|
2512
|
+
const schemaManager = new schema_manager_1.SchemaManager(adapter());
|
|
2513
|
+
return schemaManager.dropCollection(name, {
|
|
2514
|
+
autoApply: true,
|
|
2515
|
+
ifExists: options === null || options === void 0 ? void 0 : options.ifExists,
|
|
2516
|
+
cascade: options === null || options === void 0 ? void 0 : options.cascade,
|
|
2517
|
+
});
|
|
2518
|
+
},
|
|
2519
|
+
addField: async (collection, fieldName, definition) => {
|
|
2520
|
+
const schemaManager = new schema_manager_1.SchemaManager(adapter());
|
|
2521
|
+
const field = service.convertFieldDefinition(fieldName, definition);
|
|
2522
|
+
return schemaManager.addField(collection, field, { autoApply: true });
|
|
2523
|
+
},
|
|
2524
|
+
dropField: async (collection, fieldName) => {
|
|
2525
|
+
const schemaManager = new schema_manager_1.SchemaManager(adapter());
|
|
2526
|
+
return schemaManager.dropField(collection, fieldName, { autoApply: true });
|
|
2527
|
+
},
|
|
2528
|
+
renameField: async (collection, oldName, newName) => {
|
|
2529
|
+
const schemaManager = new schema_manager_1.SchemaManager(adapter());
|
|
2530
|
+
return schemaManager.renameField(collection, oldName, newName, { autoApply: true });
|
|
2531
|
+
},
|
|
2532
|
+
modifyField: async (collection, fieldName, changes) => {
|
|
2533
|
+
const schemaManager = new schema_manager_1.SchemaManager(adapter());
|
|
2534
|
+
const fieldChanges = {};
|
|
2535
|
+
if (changes.type)
|
|
2536
|
+
fieldChanges.type = service.normalizeFieldType(changes.type);
|
|
2537
|
+
if (changes.minLength !== undefined)
|
|
2538
|
+
fieldChanges.minLength = changes.minLength;
|
|
2539
|
+
if (changes.maxLength !== undefined)
|
|
2540
|
+
fieldChanges.maxLength = changes.maxLength;
|
|
2541
|
+
if (changes.precision !== undefined)
|
|
2542
|
+
fieldChanges.precision = changes.precision;
|
|
2543
|
+
if (changes.scale !== undefined)
|
|
2544
|
+
fieldChanges.scale = changes.scale;
|
|
2545
|
+
if (changes.required !== undefined)
|
|
2546
|
+
fieldChanges.nullable = !changes.required;
|
|
2547
|
+
if (changes.unique !== undefined)
|
|
2548
|
+
fieldChanges.unique = changes.unique;
|
|
2549
|
+
if (changes.default !== undefined)
|
|
2550
|
+
fieldChanges.defaultValue = changes.default;
|
|
2551
|
+
if (changes.enum !== undefined)
|
|
2552
|
+
fieldChanges.enumValues = changes.enum;
|
|
2553
|
+
return schemaManager.modifyField(collection, fieldName, fieldChanges, { autoApply: true });
|
|
2554
|
+
},
|
|
2555
|
+
createIndex: async (collection, fields, options) => {
|
|
2556
|
+
const schemaManager = new schema_manager_1.SchemaManager(adapter());
|
|
2557
|
+
const normalizedFields = service.normalizeIndexFields(fields);
|
|
2558
|
+
const indexName = (options === null || options === void 0 ? void 0 : options.name) || `idx_${collection}_${normalizedFields.map((f) => f.name).join('_')}`;
|
|
2559
|
+
return schemaManager.createIndex(collection, indexName, normalizedFields, {
|
|
2560
|
+
autoApply: true,
|
|
2561
|
+
unique: options === null || options === void 0 ? void 0 : options.unique,
|
|
2562
|
+
sparse: options === null || options === void 0 ? void 0 : options.sparse,
|
|
2563
|
+
sqlOptions: (options === null || options === void 0 ? void 0 : options.where) ? { where: options.where } : undefined,
|
|
2564
|
+
mongoOptions: (options === null || options === void 0 ? void 0 : options.expireAfterSeconds) ? { expireAfterSeconds: options.expireAfterSeconds } : undefined,
|
|
2565
|
+
});
|
|
2566
|
+
},
|
|
2567
|
+
dropIndex: async (collection, indexName) => {
|
|
2568
|
+
const schemaManager = new schema_manager_1.SchemaManager(adapter());
|
|
2569
|
+
return schemaManager.dropIndex(collection, indexName, { autoApply: true, ifExists: true });
|
|
2570
|
+
},
|
|
2571
|
+
addConstraint: async (collection, constraint) => {
|
|
2572
|
+
const schemaManager = new schema_manager_1.SchemaManager(adapter());
|
|
2573
|
+
return schemaManager.addConstraint(collection, constraint, { autoApply: true });
|
|
2574
|
+
},
|
|
2575
|
+
dropConstraint: async (collection, constraintName) => {
|
|
2576
|
+
const schemaManager = new schema_manager_1.SchemaManager(adapter());
|
|
2577
|
+
return schemaManager.dropConstraint(collection, constraintName, { autoApply: true });
|
|
2578
|
+
},
|
|
2579
|
+
rename: async (oldName, newName) => {
|
|
2580
|
+
const schemaManager = new schema_manager_1.SchemaManager(adapter());
|
|
2581
|
+
return schemaManager.renameCollection(oldName, newName, { autoApply: true });
|
|
2582
|
+
},
|
|
2583
|
+
exists: async (name) => {
|
|
2584
|
+
const schemaManager = new schema_manager_1.SchemaManager(adapter());
|
|
2585
|
+
return schemaManager.collectionExists(name);
|
|
2586
|
+
},
|
|
2587
|
+
list: async (schemaName) => {
|
|
2588
|
+
const schemaManager = new schema_manager_1.SchemaManager(adapter());
|
|
2589
|
+
return schemaManager.listCollections(schemaName);
|
|
2590
|
+
},
|
|
2591
|
+
describe: async (name) => {
|
|
2592
|
+
const schemaManager = new schema_manager_1.SchemaManager(adapter());
|
|
2593
|
+
return schemaManager.getCollectionSchema(name);
|
|
2594
|
+
},
|
|
2595
|
+
indexes: async (collection) => {
|
|
2596
|
+
const schemaManager = new schema_manager_1.SchemaManager(adapter());
|
|
2597
|
+
return schemaManager.listIndexes(collection);
|
|
2598
|
+
},
|
|
2599
|
+
};
|
|
2600
|
+
}
|
|
2601
|
+
// Query operations scoped to this connection
|
|
2602
|
+
query(options) {
|
|
2603
|
+
return this.service.query(Object.assign(Object.assign({}, options), { database: this._database, env: this._env }));
|
|
2604
|
+
}
|
|
2605
|
+
insert(options) {
|
|
2606
|
+
return this.service.insert(Object.assign(Object.assign({}, options), { database: this._database, env: this._env }));
|
|
2607
|
+
}
|
|
2608
|
+
update(options) {
|
|
2609
|
+
return this.service.update(Object.assign(Object.assign({}, options), { database: this._database, env: this._env }));
|
|
2610
|
+
}
|
|
2611
|
+
delete(options) {
|
|
2612
|
+
return this.service.delete(Object.assign(Object.assign({}, options), { database: this._database, env: this._env }));
|
|
2613
|
+
}
|
|
2614
|
+
upsert(options) {
|
|
2615
|
+
return this.service.upsert(Object.assign(Object.assign({}, options), { database: this._database, env: this._env }));
|
|
2616
|
+
}
|
|
2617
|
+
raw(options) {
|
|
2618
|
+
return this.service.raw(Object.assign(Object.assign({}, options), { database: this._database, env: this._env }));
|
|
2619
|
+
}
|
|
2620
|
+
// Aggregation operations scoped to this connection
|
|
2621
|
+
count(options) {
|
|
2622
|
+
return this.service.count(Object.assign(Object.assign({}, options), { database: this._database, env: this._env }));
|
|
2623
|
+
}
|
|
2624
|
+
sum(options) {
|
|
2625
|
+
return this.service.sum(Object.assign(Object.assign({}, options), { database: this._database, env: this._env }));
|
|
2626
|
+
}
|
|
2627
|
+
avg(options) {
|
|
2628
|
+
return this.service.avg(Object.assign(Object.assign({}, options), { database: this._database, env: this._env }));
|
|
2629
|
+
}
|
|
2630
|
+
min(options) {
|
|
2631
|
+
return this.service.min(Object.assign(Object.assign({}, options), { database: this._database, env: this._env }));
|
|
2632
|
+
}
|
|
2633
|
+
max(options) {
|
|
2634
|
+
return this.service.max(Object.assign(Object.assign({}, options), { database: this._database, env: this._env }));
|
|
2635
|
+
}
|
|
2636
|
+
aggregate(options) {
|
|
2637
|
+
return this.service.aggregate(Object.assign(Object.assign({}, options), { database: this._database, env: this._env }));
|
|
2638
|
+
}
|
|
2639
|
+
groupBy(options) {
|
|
2640
|
+
return this.service.groupBy(Object.assign(Object.assign({}, options), { database: this._database, env: this._env }));
|
|
2641
|
+
}
|
|
2642
|
+
/**
|
|
2643
|
+
* Trigger operations scoped to this connection
|
|
2644
|
+
*/
|
|
2645
|
+
get triggers() {
|
|
2646
|
+
const connection = this;
|
|
2647
|
+
return {
|
|
2648
|
+
/**
|
|
2649
|
+
* Create a trigger and store it on the backend
|
|
2650
|
+
* @param data - Trigger configuration (tag should be just the trigger name, database tag is added automatically)
|
|
2651
|
+
*/
|
|
2652
|
+
create: async (data) => {
|
|
2653
|
+
var _a;
|
|
2654
|
+
if (!connection._product) {
|
|
2655
|
+
throw new Error('Product tag is required to create triggers. Use connect() with product parameter.');
|
|
2656
|
+
}
|
|
2657
|
+
// Auto-prefix with database tag if not already prefixed
|
|
2658
|
+
const tag = ((_a = data.tag) === null || _a === void 0 ? void 0 : _a.includes(':')) ? data.tag : `${connection._database}:${data.tag}`;
|
|
2659
|
+
return connection.service.createTrigger(connection._product, Object.assign(Object.assign({}, data), { tag }));
|
|
2660
|
+
},
|
|
2661
|
+
/**
|
|
2662
|
+
* Update an existing trigger on the backend
|
|
2663
|
+
* @param data - Trigger configuration
|
|
2664
|
+
*/
|
|
2665
|
+
update: async (data) => {
|
|
2666
|
+
var _a;
|
|
2667
|
+
if (!connection._product) {
|
|
2668
|
+
throw new Error('Product tag is required to update triggers. Use connect() with product parameter.');
|
|
2669
|
+
}
|
|
2670
|
+
const tag = ((_a = data.tag) === null || _a === void 0 ? void 0 : _a.includes(':')) ? data.tag : `${connection._database}:${data.tag}`;
|
|
2671
|
+
return connection.service.updateTrigger(connection._product, Object.assign(Object.assign({}, data), { tag }));
|
|
2672
|
+
},
|
|
2673
|
+
/**
|
|
2674
|
+
* Fetch a specific trigger from the backend
|
|
2675
|
+
* @param triggerTag - The trigger tag (without database prefix)
|
|
2676
|
+
*/
|
|
2677
|
+
fetch: async (triggerTag) => {
|
|
2678
|
+
if (!connection._product) {
|
|
2679
|
+
throw new Error('Product tag is required to fetch triggers. Use connect() with product parameter.');
|
|
2680
|
+
}
|
|
2681
|
+
const tag = triggerTag.includes(':') ? triggerTag : `${connection._database}:${triggerTag}`;
|
|
2682
|
+
return connection.service.fetchTrigger(connection._product, tag);
|
|
2683
|
+
},
|
|
2684
|
+
/**
|
|
2685
|
+
* Fetch all triggers for this database from the backend
|
|
2686
|
+
* @deprecated Use list() instead
|
|
2687
|
+
*/
|
|
2688
|
+
fetchAll: async () => {
|
|
2689
|
+
if (!connection._product) {
|
|
2690
|
+
throw new Error('Product tag is required to fetch triggers. Use connect() with product parameter.');
|
|
2691
|
+
}
|
|
2692
|
+
return connection.service.fetchTriggers(connection._product, connection._database);
|
|
2693
|
+
},
|
|
2694
|
+
/**
|
|
2695
|
+
* List all triggers for this database from the backend
|
|
2696
|
+
* @param options - Optional filters (table, event, enabled)
|
|
2697
|
+
*/
|
|
2698
|
+
list: async (options) => {
|
|
2699
|
+
if (!connection._product) {
|
|
2700
|
+
throw new Error('Product tag is required to list triggers. Use connect() with product parameter.');
|
|
2701
|
+
}
|
|
2702
|
+
let triggers = await connection.service.fetchTriggers(connection._product, connection._database);
|
|
2703
|
+
// Apply filters if provided
|
|
2704
|
+
if (options === null || options === void 0 ? void 0 : options.table) {
|
|
2705
|
+
triggers = triggers.filter(t => { var _a; return (_a = t.tables) === null || _a === void 0 ? void 0 : _a.includes(options.table); });
|
|
2706
|
+
}
|
|
2707
|
+
if (options === null || options === void 0 ? void 0 : options.event) {
|
|
2708
|
+
triggers = triggers.filter(t => { var _a; return (_a = t.events) === null || _a === void 0 ? void 0 : _a.includes(options.event); });
|
|
2709
|
+
}
|
|
2710
|
+
if ((options === null || options === void 0 ? void 0 : options.enabled) !== undefined) {
|
|
2711
|
+
triggers = triggers.filter(t => t.enabled === options.enabled);
|
|
2712
|
+
}
|
|
2713
|
+
return triggers;
|
|
2714
|
+
},
|
|
2715
|
+
/**
|
|
2716
|
+
* Delete a trigger from the backend
|
|
2717
|
+
* @param triggerTag - The trigger tag (without database prefix)
|
|
2718
|
+
*/
|
|
2719
|
+
delete: async (triggerTag) => {
|
|
2720
|
+
if (!connection._product) {
|
|
2721
|
+
throw new Error('Product tag is required to delete triggers. Use connect() with product parameter.');
|
|
2722
|
+
}
|
|
2723
|
+
const tag = triggerTag.includes(':') ? triggerTag : `${connection._database}:${triggerTag}`;
|
|
2724
|
+
await connection.service.deleteTrigger(connection._product, tag);
|
|
2725
|
+
return true;
|
|
2726
|
+
},
|
|
2727
|
+
/**
|
|
2728
|
+
* Register a trigger in memory for the current session (does not persist to backend)
|
|
2729
|
+
* @deprecated Use create() for persistent triggers
|
|
2730
|
+
*/
|
|
2731
|
+
register: (table, trigger) => {
|
|
2732
|
+
connection.triggerProcessor.register(table, trigger);
|
|
2733
|
+
},
|
|
2734
|
+
/**
|
|
2735
|
+
* Register multiple triggers in memory (does not persist to backend)
|
|
2736
|
+
* @deprecated Use create() for persistent triggers
|
|
2737
|
+
*/
|
|
2738
|
+
registerAll: (triggers) => {
|
|
2739
|
+
connection.triggerProcessor.registerAll(triggers);
|
|
2740
|
+
},
|
|
2741
|
+
/**
|
|
2742
|
+
* Unregister a trigger from memory
|
|
2743
|
+
*/
|
|
2744
|
+
unregister: (table, triggerName) => {
|
|
2745
|
+
return connection.triggerProcessor.unregister(table, triggerName);
|
|
2746
|
+
},
|
|
2747
|
+
/**
|
|
2748
|
+
* Get all triggers for a table and event
|
|
2749
|
+
*/
|
|
2750
|
+
getTriggersForEvent: (table, event) => {
|
|
2751
|
+
return connection.triggerProcessor.getTriggersForEvent(table, event);
|
|
2752
|
+
},
|
|
2753
|
+
/**
|
|
2754
|
+
* Execute all triggers for an event
|
|
2755
|
+
*/
|
|
2756
|
+
execute: async (event, context) => {
|
|
2757
|
+
return connection.triggerProcessor.executeTriggers(event, Object.assign(Object.assign({}, context), { database: connection._database, env: connection._env }));
|
|
2758
|
+
},
|
|
2759
|
+
/**
|
|
2760
|
+
* Load triggers from the backend and register them in memory
|
|
2761
|
+
*/
|
|
2762
|
+
load: async () => {
|
|
2763
|
+
if (!connection._product) {
|
|
2764
|
+
throw new Error('Product tag is required to load triggers. Use connect() with product parameter.');
|
|
2765
|
+
}
|
|
2766
|
+
const backendTriggers = await connection.service.fetchTriggers(connection._product, connection._database);
|
|
2767
|
+
for (const trigger of backendTriggers) {
|
|
2768
|
+
// Convert backend trigger format to ITriggerDefinition
|
|
2769
|
+
const definition = {
|
|
2770
|
+
name: trigger.tag,
|
|
2771
|
+
description: trigger.description,
|
|
2772
|
+
events: trigger.events, // TriggerEventType maps to TriggerEvent
|
|
2773
|
+
tables: trigger.tables,
|
|
2774
|
+
condition: trigger.condition,
|
|
2775
|
+
actions: trigger.actions.map(action => (Object.assign(Object.assign({}, action.config), { type: action.type, name: action.name, condition: action.condition, timing: action.timing, retry: action.retry, timeout: action.timeout, continueOnError: action.continueOnError }))),
|
|
2776
|
+
enabled: trigger.enabled,
|
|
2777
|
+
priority: trigger.priority,
|
|
2778
|
+
tags: trigger.tags,
|
|
2779
|
+
};
|
|
2780
|
+
// Register for all tables specified, or use '*' for all
|
|
2781
|
+
const tables = trigger.tables && trigger.tables.length > 0 ? trigger.tables : ['*'];
|
|
2782
|
+
for (const table of tables) {
|
|
2783
|
+
connection.triggerProcessor.register(table, definition);
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
},
|
|
2787
|
+
/**
|
|
2788
|
+
* Set the Ductape instance for trigger actions
|
|
2789
|
+
*/
|
|
2790
|
+
setDuctapeInstance: (instance) => {
|
|
2791
|
+
connection.triggerProcessor.setDuctapeInstance(instance);
|
|
2792
|
+
},
|
|
2793
|
+
/**
|
|
2794
|
+
* Get the trigger processor instance
|
|
2795
|
+
*/
|
|
2796
|
+
getProcessor: () => {
|
|
2797
|
+
return connection.triggerProcessor;
|
|
2798
|
+
},
|
|
2799
|
+
/**
|
|
2800
|
+
* Trigger action builders
|
|
2801
|
+
*/
|
|
2802
|
+
Trigger: trigger_processor_1.Trigger,
|
|
2803
|
+
/**
|
|
2804
|
+
* Trigger events enum
|
|
2805
|
+
*/
|
|
2806
|
+
TriggerEvent: trigger_interface_1.TriggerEvent,
|
|
2807
|
+
/**
|
|
2808
|
+
* Trigger timing enum
|
|
2809
|
+
*/
|
|
2810
|
+
TriggerTiming: trigger_interface_1.TriggerTiming,
|
|
2811
|
+
/**
|
|
2812
|
+
* Trigger action types enum
|
|
2813
|
+
*/
|
|
2814
|
+
TriggerActionType: trigger_interface_1.TriggerActionType,
|
|
2815
|
+
};
|
|
2816
|
+
}
|
|
2817
|
+
}
|
|
2818
|
+
exports.DatabaseConnection = DatabaseConnection;
|
|
2819
|
+
// Export singleton instance for convenience
|
|
2820
|
+
exports.databaseService = new DatabaseService();
|
|
2821
|
+
//# sourceMappingURL=databases.service.js.map
|