@warlock.js/cascade 4.0.162 → 4.0.164
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/cjs/context/database-data-source-context.d.ts +29 -0
- package/cjs/context/database-data-source-context.d.ts.map +1 -0
- package/cjs/context/database-data-source-context.js +28 -0
- package/cjs/context/database-data-source-context.js.map +1 -0
- package/cjs/context/database-transaction-context.d.ts +35 -0
- package/cjs/context/database-transaction-context.d.ts.map +1 -0
- package/cjs/context/database-transaction-context.js +40 -0
- package/cjs/context/database-transaction-context.js.map +1 -0
- package/cjs/contracts/database-driver.contract.d.ts +450 -0
- package/cjs/contracts/database-driver.contract.d.ts.map +1 -0
- package/cjs/contracts/database-id-generator.contract.d.ts +109 -0
- package/cjs/contracts/database-id-generator.contract.d.ts.map +1 -0
- package/cjs/contracts/database-remover.contract.d.ts +104 -0
- package/cjs/contracts/database-remover.contract.d.ts.map +1 -0
- package/cjs/contracts/database-restorer.contract.d.ts +143 -0
- package/cjs/contracts/database-restorer.contract.d.ts.map +1 -0
- package/cjs/contracts/database-writer.contract.d.ts +119 -0
- package/cjs/contracts/database-writer.contract.d.ts.map +1 -0
- package/cjs/contracts/driver-blueprint.contract.d.ts +49 -0
- package/cjs/contracts/driver-blueprint.contract.d.ts.map +1 -0
- package/cjs/contracts/index.d.ts +10 -0
- package/cjs/contracts/index.d.ts.map +1 -0
- package/cjs/contracts/migration-driver.contract.d.ts +522 -0
- package/cjs/contracts/migration-driver.contract.d.ts.map +1 -0
- package/cjs/contracts/query-builder.contract.d.ts +1609 -0
- package/cjs/contracts/query-builder.contract.d.ts.map +1 -0
- package/cjs/contracts/sync-adapter.contract.d.ts +58 -0
- package/cjs/contracts/sync-adapter.contract.d.ts.map +1 -0
- package/cjs/data-source/data-source-registry.d.ts +108 -0
- package/cjs/data-source/data-source-registry.d.ts.map +1 -0
- package/cjs/data-source/data-source-registry.js +145 -0
- package/cjs/data-source/data-source-registry.js.map +1 -0
- package/cjs/data-source/data-source.d.ts +147 -0
- package/cjs/data-source/data-source.d.ts.map +1 -0
- package/cjs/data-source/data-source.js +83 -0
- package/cjs/data-source/data-source.js.map +1 -0
- package/cjs/database-dirty-tracker.d.ts +252 -0
- package/cjs/database-dirty-tracker.d.ts.map +1 -0
- package/cjs/database-dirty-tracker.js +386 -0
- package/cjs/database-dirty-tracker.js.map +1 -0
- package/cjs/drivers/mongodb/mongodb-blueprint.d.ts +30 -0
- package/cjs/drivers/mongodb/mongodb-blueprint.d.ts.map +1 -0
- package/cjs/drivers/mongodb/mongodb-blueprint.js +51 -0
- package/cjs/drivers/mongodb/mongodb-blueprint.js.map +1 -0
- package/cjs/drivers/mongodb/mongodb-driver.d.ts +325 -0
- package/cjs/drivers/mongodb/mongodb-driver.d.ts.map +1 -0
- package/cjs/drivers/mongodb/mongodb-driver.js +838 -0
- package/cjs/drivers/mongodb/mongodb-driver.js.map +1 -0
- package/cjs/drivers/mongodb/mongodb-id-generator.d.ts +116 -0
- package/cjs/drivers/mongodb/mongodb-id-generator.d.ts.map +1 -0
- package/cjs/drivers/mongodb/mongodb-id-generator.js +149 -0
- package/cjs/drivers/mongodb/mongodb-id-generator.js.map +1 -0
- package/cjs/drivers/mongodb/mongodb-migration-driver.d.ts +317 -0
- package/cjs/drivers/mongodb/mongodb-migration-driver.d.ts.map +1 -0
- package/cjs/drivers/mongodb/mongodb-migration-driver.js +666 -0
- package/cjs/drivers/mongodb/mongodb-migration-driver.js.map +1 -0
- package/cjs/drivers/mongodb/mongodb-query-builder.d.ts +1122 -0
- package/cjs/drivers/mongodb/mongodb-query-builder.d.ts.map +1 -0
- package/cjs/drivers/mongodb/mongodb-query-builder.js +1988 -0
- package/cjs/drivers/mongodb/mongodb-query-builder.js.map +1 -0
- package/cjs/drivers/mongodb/mongodb-query-operations.d.ts +226 -0
- package/cjs/drivers/mongodb/mongodb-query-operations.d.ts.map +1 -0
- package/cjs/drivers/mongodb/mongodb-query-operations.js +270 -0
- package/cjs/drivers/mongodb/mongodb-query-operations.js.map +1 -0
- package/cjs/drivers/mongodb/mongodb-query-parser.d.ts +262 -0
- package/cjs/drivers/mongodb/mongodb-query-parser.d.ts.map +1 -0
- package/cjs/drivers/mongodb/mongodb-query-parser.js +1351 -0
- package/cjs/drivers/mongodb/mongodb-query-parser.js.map +1 -0
- package/cjs/drivers/mongodb/mongodb-sync-adapter.d.ts +79 -0
- package/cjs/drivers/mongodb/mongodb-sync-adapter.d.ts.map +1 -0
- package/cjs/drivers/mongodb/mongodb-sync-adapter.js +146 -0
- package/cjs/drivers/mongodb/mongodb-sync-adapter.js.map +1 -0
- package/cjs/drivers/mongodb/types.d.ts +43 -0
- package/cjs/drivers/mongodb/types.d.ts.map +1 -0
- package/cjs/drivers/postgres/index.d.ts +16 -0
- package/cjs/drivers/postgres/index.d.ts.map +1 -0
- package/cjs/drivers/postgres/postgres-blueprint.d.ts +64 -0
- package/cjs/drivers/postgres/postgres-blueprint.d.ts.map +1 -0
- package/cjs/drivers/postgres/postgres-blueprint.js +121 -0
- package/cjs/drivers/postgres/postgres-blueprint.js.map +1 -0
- package/cjs/drivers/postgres/postgres-dialect.d.ts +136 -0
- package/cjs/drivers/postgres/postgres-dialect.d.ts.map +1 -0
- package/cjs/drivers/postgres/postgres-dialect.js +268 -0
- package/cjs/drivers/postgres/postgres-dialect.js.map +1 -0
- package/cjs/drivers/postgres/postgres-driver.d.ts +432 -0
- package/cjs/drivers/postgres/postgres-driver.d.ts.map +1 -0
- package/cjs/drivers/postgres/postgres-driver.js +1010 -0
- package/cjs/drivers/postgres/postgres-driver.js.map +1 -0
- package/cjs/drivers/postgres/postgres-migration-driver.d.ts +397 -0
- package/cjs/drivers/postgres/postgres-migration-driver.d.ts.map +1 -0
- package/cjs/drivers/postgres/postgres-migration-driver.js +900 -0
- package/cjs/drivers/postgres/postgres-migration-driver.js.map +1 -0
- package/cjs/drivers/postgres/postgres-query-builder.d.ts +254 -0
- package/cjs/drivers/postgres/postgres-query-builder.d.ts.map +1 -0
- package/cjs/drivers/postgres/postgres-query-builder.js +933 -0
- package/cjs/drivers/postgres/postgres-query-builder.js.map +1 -0
- package/cjs/drivers/postgres/postgres-query-parser.d.ts +328 -0
- package/cjs/drivers/postgres/postgres-query-parser.d.ts.map +1 -0
- package/cjs/drivers/postgres/postgres-query-parser.js +868 -0
- package/cjs/drivers/postgres/postgres-query-parser.js.map +1 -0
- package/cjs/drivers/postgres/postgres-sql-serializer.d.ts +37 -0
- package/cjs/drivers/postgres/postgres-sql-serializer.d.ts.map +1 -0
- package/cjs/drivers/postgres/postgres-sql-serializer.js +400 -0
- package/cjs/drivers/postgres/postgres-sql-serializer.js.map +1 -0
- package/cjs/drivers/postgres/postgres-sync-adapter.d.ts +83 -0
- package/cjs/drivers/postgres/postgres-sync-adapter.d.ts.map +1 -0
- package/cjs/drivers/postgres/postgres-sync-adapter.js +197 -0
- package/cjs/drivers/postgres/postgres-sync-adapter.js.map +1 -0
- package/cjs/drivers/postgres/types.d.ts +144 -0
- package/cjs/drivers/postgres/types.d.ts.map +1 -0
- package/cjs/drivers/sql/index.d.ts +10 -0
- package/cjs/drivers/sql/index.d.ts.map +1 -0
- package/cjs/drivers/sql/sql-dialect.contract.d.ts +204 -0
- package/cjs/drivers/sql/sql-dialect.contract.d.ts.map +1 -0
- package/cjs/drivers/sql/sql-types.d.ts +202 -0
- package/cjs/drivers/sql/sql-types.d.ts.map +1 -0
- package/cjs/errors/missing-data-source.error.d.ts +22 -0
- package/cjs/errors/missing-data-source.error.d.ts.map +1 -0
- package/cjs/errors/missing-data-source.error.js +29 -0
- package/cjs/errors/missing-data-source.error.js.map +1 -0
- package/cjs/errors/transaction-rollback.error.d.ts +20 -0
- package/cjs/errors/transaction-rollback.error.d.ts.map +1 -0
- package/cjs/errors/transaction-rollback.error.js +27 -0
- package/cjs/errors/transaction-rollback.error.js.map +1 -0
- package/cjs/events/model-events.d.ts +231 -0
- package/cjs/events/model-events.d.ts.map +1 -0
- package/cjs/events/model-events.js +259 -0
- package/cjs/events/model-events.js.map +1 -0
- package/cjs/expressions/aggregate-expressions.d.ts +215 -0
- package/cjs/expressions/aggregate-expressions.d.ts.map +1 -0
- package/cjs/expressions/aggregate-expressions.js +221 -0
- package/cjs/expressions/aggregate-expressions.js.map +1 -0
- package/cjs/expressions/index.d.ts +2 -0
- package/cjs/expressions/index.d.ts.map +1 -0
- package/cjs/index.d.ts +45 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js +1 -0
- package/cjs/index.js.map +1 -0
- package/cjs/migration/column-builder.d.ts +417 -0
- package/cjs/migration/column-builder.d.ts.map +1 -0
- package/cjs/migration/column-builder.js +586 -0
- package/cjs/migration/column-builder.js.map +1 -0
- package/cjs/migration/column-helpers.d.ts +275 -0
- package/cjs/migration/column-helpers.d.ts.map +1 -0
- package/cjs/migration/column-helpers.js +389 -0
- package/cjs/migration/column-helpers.js.map +1 -0
- package/cjs/migration/foreign-key-builder.d.ts +103 -0
- package/cjs/migration/foreign-key-builder.d.ts.map +1 -0
- package/cjs/migration/foreign-key-builder.js +121 -0
- package/cjs/migration/foreign-key-builder.js.map +1 -0
- package/cjs/migration/index.d.ts +7 -0
- package/cjs/migration/index.d.ts.map +1 -0
- package/cjs/migration/migration-runner.d.ts +278 -0
- package/cjs/migration/migration-runner.d.ts.map +1 -0
- package/cjs/migration/migration-runner.js +815 -0
- package/cjs/migration/migration-runner.js.map +1 -0
- package/cjs/migration/migration.d.ts +1992 -0
- package/cjs/migration/migration.d.ts.map +1 -0
- package/cjs/migration/migration.js +2162 -0
- package/cjs/migration/migration.js.map +1 -0
- package/cjs/migration/sql-grammar.d.ts +61 -0
- package/cjs/migration/sql-grammar.d.ts.map +1 -0
- package/cjs/migration/sql-grammar.js +164 -0
- package/cjs/migration/sql-grammar.js.map +1 -0
- package/cjs/migration/sql-serializer.d.ts +22 -0
- package/cjs/migration/sql-serializer.d.ts.map +1 -0
- package/cjs/migration/sql-serializer.js +26 -0
- package/cjs/migration/sql-serializer.js.map +1 -0
- package/cjs/migration/types.d.ts +155 -0
- package/cjs/migration/types.d.ts.map +1 -0
- package/cjs/model/methods/accessor-methods.d.ts +13 -0
- package/cjs/model/methods/accessor-methods.d.ts.map +1 -0
- package/cjs/model/methods/accessor-methods.js +51 -0
- package/cjs/model/methods/accessor-methods.js.map +1 -0
- package/cjs/model/methods/delete-methods.d.ts +10 -0
- package/cjs/model/methods/delete-methods.d.ts.map +1 -0
- package/cjs/model/methods/delete-methods.js +10 -0
- package/cjs/model/methods/delete-methods.js.map +1 -0
- package/cjs/model/methods/dirty-methods.d.ts +10 -0
- package/cjs/model/methods/dirty-methods.d.ts.map +1 -0
- package/cjs/model/methods/dirty-methods.js +15 -0
- package/cjs/model/methods/dirty-methods.js.map +1 -0
- package/cjs/model/methods/hydration-methods.d.ts +10 -0
- package/cjs/model/methods/hydration-methods.d.ts.map +1 -0
- package/cjs/model/methods/hydration-methods.js +57 -0
- package/cjs/model/methods/hydration-methods.js.map +1 -0
- package/cjs/model/methods/instance-event-methods.d.ts +7 -0
- package/cjs/model/methods/instance-event-methods.d.ts.map +1 -0
- package/cjs/model/methods/instance-event-methods.js +15 -0
- package/cjs/model/methods/instance-event-methods.js.map +1 -0
- package/cjs/model/methods/meta-methods.d.ts +7 -0
- package/cjs/model/methods/meta-methods.d.ts.map +1 -0
- package/cjs/model/methods/meta-methods.js +78 -0
- package/cjs/model/methods/meta-methods.js.map +1 -0
- package/cjs/model/methods/query-methods.d.ts +24 -0
- package/cjs/model/methods/query-methods.d.ts.map +1 -0
- package/cjs/model/methods/query-methods.js +164 -0
- package/cjs/model/methods/query-methods.js.map +1 -0
- package/cjs/model/methods/restore-methods.d.ts +10 -0
- package/cjs/model/methods/restore-methods.d.ts.map +1 -0
- package/cjs/model/methods/restore-methods.js +13 -0
- package/cjs/model/methods/restore-methods.js.map +1 -0
- package/cjs/model/methods/scope-methods.d.ts +7 -0
- package/cjs/model/methods/scope-methods.d.ts.map +1 -0
- package/cjs/model/methods/scope-methods.js +15 -0
- package/cjs/model/methods/scope-methods.js.map +1 -0
- package/cjs/model/methods/serialization-methods.d.ts +3 -0
- package/cjs/model/methods/serialization-methods.d.ts.map +1 -0
- package/cjs/model/methods/serialization-methods.js +27 -0
- package/cjs/model/methods/serialization-methods.js.map +1 -0
- package/cjs/model/methods/static-event-methods.d.ts +9 -0
- package/cjs/model/methods/static-event-methods.d.ts.map +1 -0
- package/cjs/model/methods/static-event-methods.js +29 -0
- package/cjs/model/methods/static-event-methods.js.map +1 -0
- package/cjs/model/methods/write-methods.d.ts +10 -0
- package/cjs/model/methods/write-methods.d.ts.map +1 -0
- package/cjs/model/methods/write-methods.js +52 -0
- package/cjs/model/methods/write-methods.js.map +1 -0
- package/cjs/model/model.d.ts +1647 -0
- package/cjs/model/model.d.ts.map +1 -0
- package/cjs/model/model.js +1657 -0
- package/cjs/model/model.js.map +1 -0
- package/cjs/model/model.types.d.ts +44 -0
- package/cjs/model/model.types.d.ts.map +1 -0
- package/cjs/model/register-model.d.ts +81 -0
- package/cjs/model/register-model.d.ts.map +1 -0
- package/cjs/model/register-model.js +94 -0
- package/cjs/model/register-model.js.map +1 -0
- package/cjs/query-builder/query-builder.d.ts +556 -0
- package/cjs/query-builder/query-builder.d.ts.map +1 -0
- package/cjs/query-builder/query-builder.js +1070 -0
- package/cjs/query-builder/query-builder.js.map +1 -0
- package/cjs/relations/helpers.d.ts +156 -0
- package/cjs/relations/helpers.d.ts.map +1 -0
- package/cjs/relations/helpers.js +202 -0
- package/cjs/relations/helpers.js.map +1 -0
- package/cjs/relations/index.d.ts +35 -0
- package/cjs/relations/index.d.ts.map +1 -0
- package/cjs/relations/pivot-operations.d.ts +160 -0
- package/cjs/relations/pivot-operations.d.ts.map +1 -0
- package/cjs/relations/pivot-operations.js +293 -0
- package/cjs/relations/pivot-operations.js.map +1 -0
- package/cjs/relations/relation-hydrator.d.ts +68 -0
- package/cjs/relations/relation-hydrator.d.ts.map +1 -0
- package/cjs/relations/relation-hydrator.js +81 -0
- package/cjs/relations/relation-hydrator.js.map +1 -0
- package/cjs/relations/relation-loader.d.ts +194 -0
- package/cjs/relations/relation-loader.d.ts.map +1 -0
- package/cjs/relations/relation-loader.js +466 -0
- package/cjs/relations/relation-loader.js.map +1 -0
- package/cjs/relations/types.d.ts +306 -0
- package/cjs/relations/types.d.ts.map +1 -0
- package/cjs/remover/database-remover.d.ts +100 -0
- package/cjs/remover/database-remover.d.ts.map +1 -0
- package/cjs/remover/database-remover.js +214 -0
- package/cjs/remover/database-remover.js.map +1 -0
- package/cjs/restorer/database-restorer.d.ts +131 -0
- package/cjs/restorer/database-restorer.d.ts.map +1 -0
- package/cjs/restorer/database-restorer.js +434 -0
- package/cjs/restorer/database-restorer.js.map +1 -0
- package/cjs/sql-database-dirty-tracker.d.ts +13 -0
- package/cjs/sql-database-dirty-tracker.d.ts.map +1 -0
- package/cjs/sql-database-dirty-tracker.js +14 -0
- package/cjs/sql-database-dirty-tracker.js.map +1 -0
- package/cjs/sync/index.d.ts +12 -0
- package/cjs/sync/index.d.ts.map +1 -0
- package/cjs/sync/model-events.d.ts +62 -0
- package/cjs/sync/model-events.d.ts.map +1 -0
- package/cjs/sync/model-events.js +49 -0
- package/cjs/sync/model-events.js.map +1 -0
- package/cjs/sync/model-sync-operation.d.ts +163 -0
- package/cjs/sync/model-sync-operation.d.ts.map +1 -0
- package/cjs/sync/model-sync-operation.js +292 -0
- package/cjs/sync/model-sync-operation.js.map +1 -0
- package/cjs/sync/model-sync.d.ts +130 -0
- package/cjs/sync/model-sync.d.ts.map +1 -0
- package/cjs/sync/model-sync.js +178 -0
- package/cjs/sync/model-sync.js.map +1 -0
- package/cjs/sync/sync-context.d.ts +70 -0
- package/cjs/sync/sync-context.d.ts.map +1 -0
- package/cjs/sync/sync-context.js +101 -0
- package/cjs/sync/sync-context.js.map +1 -0
- package/cjs/sync/sync-manager.d.ts +213 -0
- package/cjs/sync/sync-manager.d.ts.map +1 -0
- package/cjs/sync/sync-manager.js +689 -0
- package/cjs/sync/sync-manager.js.map +1 -0
- package/cjs/sync/types.d.ts +289 -0
- package/cjs/sync/types.d.ts.map +1 -0
- package/cjs/test-migrations/test-enhanced-features.migration.d.ts +15 -0
- package/cjs/test-migrations/test-enhanced-features.migration.d.ts.map +1 -0
- package/cjs/types.d.ts +371 -0
- package/cjs/types.d.ts.map +1 -0
- package/cjs/utils/connect-to-database.d.ts +307 -0
- package/cjs/utils/connect-to-database.d.ts.map +1 -0
- package/cjs/utils/connect-to-database.js +130 -0
- package/cjs/utils/connect-to-database.js.map +1 -0
- package/cjs/utils/database-writer.utils.d.ts +15 -0
- package/cjs/utils/database-writer.utils.d.ts.map +1 -0
- package/cjs/utils/database-writer.utils.js +14 -0
- package/cjs/utils/database-writer.utils.js.map +1 -0
- package/cjs/utils/define-model.js +100 -0
- package/cjs/utils/define-model.js.map +1 -0
- package/cjs/utils/is-valid-date-value.d.ts +5 -0
- package/cjs/utils/is-valid-date-value.d.ts.map +1 -0
- package/cjs/utils/is-valid-date-value.js +25 -0
- package/cjs/utils/is-valid-date-value.js.map +1 -0
- package/cjs/utils/once-connected.d.ts +146 -0
- package/cjs/utils/once-connected.d.ts.map +1 -0
- package/cjs/utils/once-connected.js +251 -0
- package/cjs/utils/once-connected.js.map +1 -0
- package/cjs/validation/database-seal-plugins.d.ts +12 -0
- package/cjs/validation/database-seal-plugins.d.ts.map +1 -0
- package/cjs/validation/database-seal-plugins.js +1 -0
- package/cjs/validation/database-seal-plugins.js.map +1 -0
- package/cjs/validation/database-writer-validation-error.d.ts +97 -0
- package/cjs/validation/database-writer-validation-error.d.ts.map +1 -0
- package/cjs/validation/database-writer-validation-error.js +160 -0
- package/cjs/validation/database-writer-validation-error.js.map +1 -0
- package/cjs/validation/index.d.ts +3 -0
- package/cjs/validation/index.d.ts.map +1 -0
- package/cjs/validation/mutators/embed-mutator.d.ts +9 -0
- package/cjs/validation/mutators/embed-mutator.d.ts.map +1 -0
- package/cjs/validation/mutators/embed-mutator.js +33 -0
- package/cjs/validation/mutators/embed-mutator.js.map +1 -0
- package/cjs/validation/plugins/embed-validator-plugin.d.ts +24 -0
- package/cjs/validation/plugins/embed-validator-plugin.d.ts.map +1 -0
- package/cjs/validation/plugins/embed-validator-plugin.js +18 -0
- package/cjs/validation/plugins/embed-validator-plugin.js.map +1 -0
- package/cjs/validation/rules/database-model-rule.d.ts +7 -0
- package/cjs/validation/rules/database-model-rule.d.ts.map +1 -0
- package/cjs/validation/rules/database-model-rule.js +27 -0
- package/cjs/validation/rules/database-model-rule.js.map +1 -0
- package/cjs/validation/transformers/embed-model-transformer.d.ts +3 -0
- package/cjs/validation/transformers/embed-model-transformer.d.ts.map +1 -0
- package/cjs/validation/transformers/embed-model-transformer.js +18 -0
- package/cjs/validation/transformers/embed-model-transformer.js.map +1 -0
- package/cjs/validation/validators/embed-validator.d.ts +21 -0
- package/cjs/validation/validators/embed-validator.d.ts.map +1 -0
- package/cjs/validation/validators/embed-validator.js +43 -0
- package/cjs/validation/validators/embed-validator.js.map +1 -0
- package/cjs/writer/database-writer.d.ts +181 -0
- package/cjs/writer/database-writer.d.ts.map +1 -0
- package/cjs/writer/database-writer.js +407 -0
- package/cjs/writer/database-writer.js.map +1 -0
- package/esm/data-source/data-source-registry.d.ts +108 -0
- package/esm/data-source/data-source-registry.d.ts.map +1 -0
- package/esm/data-source/data-source-registry.js +145 -0
- package/esm/data-source/data-source-registry.js.map +1 -0
- package/esm/data-source/data-source.d.ts +147 -0
- package/esm/data-source/data-source.d.ts.map +1 -0
- package/esm/data-source/data-source.js +83 -0
- package/esm/data-source/data-source.js.map +1 -0
- package/esm/database-dirty-tracker.d.ts +252 -0
- package/esm/database-dirty-tracker.d.ts.map +1 -0
- package/esm/database-dirty-tracker.js +386 -0
- package/esm/database-dirty-tracker.js.map +1 -0
- package/esm/drivers/mongodb/mongodb-blueprint.d.ts +30 -0
- package/esm/drivers/mongodb/mongodb-blueprint.d.ts.map +1 -0
- package/esm/drivers/mongodb/mongodb-blueprint.js +51 -0
- package/esm/drivers/mongodb/mongodb-blueprint.js.map +1 -0
- package/esm/drivers/mongodb/mongodb-driver.d.ts +325 -0
- package/esm/drivers/mongodb/mongodb-driver.d.ts.map +1 -0
- package/esm/drivers/mongodb/mongodb-driver.js +838 -0
- package/esm/drivers/mongodb/mongodb-driver.js.map +1 -0
- package/esm/drivers/mongodb/mongodb-id-generator.d.ts +116 -0
- package/esm/drivers/mongodb/mongodb-id-generator.d.ts.map +1 -0
- package/esm/drivers/mongodb/mongodb-id-generator.js +149 -0
- package/esm/drivers/mongodb/mongodb-id-generator.js.map +1 -0
- package/esm/drivers/mongodb/mongodb-migration-driver.d.ts +317 -0
- package/esm/drivers/mongodb/mongodb-migration-driver.d.ts.map +1 -0
- package/esm/drivers/mongodb/mongodb-migration-driver.js +666 -0
- package/esm/drivers/mongodb/mongodb-migration-driver.js.map +1 -0
- package/esm/drivers/mongodb/mongodb-query-builder.d.ts +1122 -0
- package/esm/drivers/mongodb/mongodb-query-builder.d.ts.map +1 -0
- package/esm/drivers/mongodb/mongodb-query-builder.js +1988 -0
- package/esm/drivers/mongodb/mongodb-query-builder.js.map +1 -0
- package/esm/drivers/mongodb/mongodb-query-operations.d.ts +226 -0
- package/esm/drivers/mongodb/mongodb-query-operations.d.ts.map +1 -0
- package/esm/drivers/mongodb/mongodb-query-operations.js +270 -0
- package/esm/drivers/mongodb/mongodb-query-operations.js.map +1 -0
- package/esm/drivers/mongodb/mongodb-query-parser.d.ts +262 -0
- package/esm/drivers/mongodb/mongodb-query-parser.d.ts.map +1 -0
- package/esm/drivers/mongodb/mongodb-query-parser.js +1351 -0
- package/esm/drivers/mongodb/mongodb-query-parser.js.map +1 -0
- package/esm/drivers/mongodb/mongodb-sync-adapter.d.ts +79 -0
- package/esm/drivers/mongodb/mongodb-sync-adapter.d.ts.map +1 -0
- package/esm/drivers/mongodb/mongodb-sync-adapter.js +146 -0
- package/esm/drivers/mongodb/mongodb-sync-adapter.js.map +1 -0
- package/esm/drivers/mongodb/types.d.ts +43 -0
- package/esm/drivers/mongodb/types.d.ts.map +1 -0
- package/esm/drivers/postgres/index.d.ts +16 -0
- package/esm/drivers/postgres/index.d.ts.map +1 -0
- package/esm/drivers/postgres/postgres-blueprint.d.ts +64 -0
- package/esm/drivers/postgres/postgres-blueprint.d.ts.map +1 -0
- package/esm/drivers/postgres/postgres-blueprint.js +121 -0
- package/esm/drivers/postgres/postgres-blueprint.js.map +1 -0
- package/esm/drivers/postgres/postgres-dialect.d.ts +136 -0
- package/esm/drivers/postgres/postgres-dialect.d.ts.map +1 -0
- package/esm/drivers/postgres/postgres-dialect.js +268 -0
- package/esm/drivers/postgres/postgres-dialect.js.map +1 -0
- package/esm/drivers/postgres/postgres-driver.d.ts +432 -0
- package/esm/drivers/postgres/postgres-driver.d.ts.map +1 -0
- package/esm/drivers/postgres/postgres-driver.js +1010 -0
- package/esm/drivers/postgres/postgres-driver.js.map +1 -0
- package/esm/drivers/postgres/postgres-migration-driver.d.ts +397 -0
- package/esm/drivers/postgres/postgres-migration-driver.d.ts.map +1 -0
- package/esm/drivers/postgres/postgres-migration-driver.js +900 -0
- package/esm/drivers/postgres/postgres-migration-driver.js.map +1 -0
- package/esm/drivers/postgres/postgres-query-builder.d.ts +254 -0
- package/esm/drivers/postgres/postgres-query-builder.d.ts.map +1 -0
- package/esm/drivers/postgres/postgres-query-builder.js +933 -0
- package/esm/drivers/postgres/postgres-query-builder.js.map +1 -0
- package/esm/drivers/postgres/postgres-query-parser.d.ts +328 -0
- package/esm/drivers/postgres/postgres-query-parser.d.ts.map +1 -0
- package/esm/drivers/postgres/postgres-query-parser.js +868 -0
- package/esm/drivers/postgres/postgres-query-parser.js.map +1 -0
- package/esm/drivers/postgres/postgres-sql-serializer.d.ts +37 -0
- package/esm/drivers/postgres/postgres-sql-serializer.d.ts.map +1 -0
- package/esm/drivers/postgres/postgres-sql-serializer.js +400 -0
- package/esm/drivers/postgres/postgres-sql-serializer.js.map +1 -0
- package/esm/drivers/postgres/postgres-sync-adapter.d.ts +83 -0
- package/esm/drivers/postgres/postgres-sync-adapter.d.ts.map +1 -0
- package/esm/drivers/postgres/postgres-sync-adapter.js +197 -0
- package/esm/drivers/postgres/postgres-sync-adapter.js.map +1 -0
- package/esm/drivers/postgres/types.d.ts +144 -0
- package/esm/drivers/postgres/types.d.ts.map +1 -0
- package/esm/drivers/sql/index.d.ts +10 -0
- package/esm/drivers/sql/index.d.ts.map +1 -0
- package/esm/drivers/sql/sql-dialect.contract.d.ts +204 -0
- package/esm/drivers/sql/sql-dialect.contract.d.ts.map +1 -0
- package/esm/drivers/sql/sql-types.d.ts +202 -0
- package/esm/drivers/sql/sql-types.d.ts.map +1 -0
- package/esm/errors/missing-data-source.error.d.ts +22 -0
- package/esm/errors/missing-data-source.error.d.ts.map +1 -0
- package/esm/errors/missing-data-source.error.js +29 -0
- package/esm/errors/missing-data-source.error.js.map +1 -0
- package/esm/errors/transaction-rollback.error.d.ts +20 -0
- package/esm/errors/transaction-rollback.error.d.ts.map +1 -0
- package/esm/errors/transaction-rollback.error.js +27 -0
- package/esm/errors/transaction-rollback.error.js.map +1 -0
- package/esm/events/model-events.d.ts +231 -0
- package/esm/events/model-events.d.ts.map +1 -0
- package/esm/events/model-events.js +259 -0
- package/esm/events/model-events.js.map +1 -0
- package/esm/expressions/aggregate-expressions.d.ts +215 -0
- package/esm/expressions/aggregate-expressions.d.ts.map +1 -0
- package/esm/expressions/aggregate-expressions.js +221 -0
- package/esm/expressions/aggregate-expressions.js.map +1 -0
- package/esm/expressions/index.d.ts +2 -0
- package/esm/expressions/index.d.ts.map +1 -0
- package/esm/index.d.ts +45 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -0
- package/esm/migration/column-builder.d.ts +417 -0
- package/esm/migration/column-builder.d.ts.map +1 -0
- package/esm/migration/column-builder.js +586 -0
- package/esm/migration/column-builder.js.map +1 -0
- package/esm/migration/column-helpers.d.ts +275 -0
- package/esm/migration/column-helpers.d.ts.map +1 -0
- package/esm/migration/column-helpers.js +389 -0
- package/esm/migration/column-helpers.js.map +1 -0
- package/esm/migration/foreign-key-builder.d.ts +103 -0
- package/esm/migration/foreign-key-builder.d.ts.map +1 -0
- package/esm/migration/foreign-key-builder.js +121 -0
- package/esm/migration/foreign-key-builder.js.map +1 -0
- package/esm/migration/index.d.ts +7 -0
- package/esm/migration/index.d.ts.map +1 -0
- package/esm/migration/migration-runner.d.ts +278 -0
- package/esm/migration/migration-runner.d.ts.map +1 -0
- package/esm/migration/migration-runner.js +815 -0
- package/esm/migration/migration-runner.js.map +1 -0
- package/esm/migration/migration.d.ts +1992 -0
- package/esm/migration/migration.d.ts.map +1 -0
- package/esm/migration/migration.js +2162 -0
- package/esm/migration/migration.js.map +1 -0
- package/esm/migration/sql-grammar.d.ts +61 -0
- package/esm/migration/sql-grammar.d.ts.map +1 -0
- package/esm/migration/sql-grammar.js +164 -0
- package/esm/migration/sql-grammar.js.map +1 -0
- package/esm/migration/sql-serializer.d.ts +22 -0
- package/esm/migration/sql-serializer.d.ts.map +1 -0
- package/esm/migration/sql-serializer.js +26 -0
- package/esm/migration/sql-serializer.js.map +1 -0
- package/esm/migration/types.d.ts +155 -0
- package/esm/migration/types.d.ts.map +1 -0
- package/esm/model/methods/accessor-methods.d.ts +13 -0
- package/esm/model/methods/accessor-methods.d.ts.map +1 -0
- package/esm/model/methods/accessor-methods.js +51 -0
- package/esm/model/methods/accessor-methods.js.map +1 -0
- package/esm/model/methods/delete-methods.d.ts +10 -0
- package/esm/model/methods/delete-methods.d.ts.map +1 -0
- package/esm/model/methods/delete-methods.js +10 -0
- package/esm/model/methods/delete-methods.js.map +1 -0
- package/esm/model/methods/dirty-methods.d.ts +10 -0
- package/esm/model/methods/dirty-methods.d.ts.map +1 -0
- package/esm/model/methods/dirty-methods.js +15 -0
- package/esm/model/methods/dirty-methods.js.map +1 -0
- package/esm/model/methods/hydration-methods.d.ts +10 -0
- package/esm/model/methods/hydration-methods.d.ts.map +1 -0
- package/esm/model/methods/hydration-methods.js +57 -0
- package/esm/model/methods/hydration-methods.js.map +1 -0
- package/esm/model/methods/instance-event-methods.d.ts +7 -0
- package/esm/model/methods/instance-event-methods.d.ts.map +1 -0
- package/esm/model/methods/instance-event-methods.js +15 -0
- package/esm/model/methods/instance-event-methods.js.map +1 -0
- package/esm/model/methods/meta-methods.d.ts +7 -0
- package/esm/model/methods/meta-methods.d.ts.map +1 -0
- package/esm/model/methods/meta-methods.js +78 -0
- package/esm/model/methods/meta-methods.js.map +1 -0
- package/esm/model/methods/query-methods.d.ts +24 -0
- package/esm/model/methods/query-methods.d.ts.map +1 -0
- package/esm/model/methods/query-methods.js +164 -0
- package/esm/model/methods/query-methods.js.map +1 -0
- package/esm/model/methods/restore-methods.d.ts +10 -0
- package/esm/model/methods/restore-methods.d.ts.map +1 -0
- package/esm/model/methods/restore-methods.js +13 -0
- package/esm/model/methods/restore-methods.js.map +1 -0
- package/esm/model/methods/scope-methods.d.ts +7 -0
- package/esm/model/methods/scope-methods.d.ts.map +1 -0
- package/esm/model/methods/scope-methods.js +15 -0
- package/esm/model/methods/scope-methods.js.map +1 -0
- package/esm/model/methods/serialization-methods.d.ts +3 -0
- package/esm/model/methods/serialization-methods.d.ts.map +1 -0
- package/esm/model/methods/serialization-methods.js +27 -0
- package/esm/model/methods/serialization-methods.js.map +1 -0
- package/esm/model/methods/static-event-methods.d.ts +9 -0
- package/esm/model/methods/static-event-methods.d.ts.map +1 -0
- package/esm/model/methods/static-event-methods.js +29 -0
- package/esm/model/methods/static-event-methods.js.map +1 -0
- package/esm/model/methods/write-methods.d.ts +10 -0
- package/esm/model/methods/write-methods.d.ts.map +1 -0
- package/esm/model/methods/write-methods.js +52 -0
- package/esm/model/methods/write-methods.js.map +1 -0
- package/esm/model/model.d.ts +1647 -0
- package/esm/model/model.d.ts.map +1 -0
- package/esm/model/model.js +1657 -0
- package/esm/model/model.js.map +1 -0
- package/esm/model/model.types.d.ts +44 -0
- package/esm/model/model.types.d.ts.map +1 -0
- package/esm/model/register-model.d.ts +81 -0
- package/esm/model/register-model.d.ts.map +1 -0
- package/esm/model/register-model.js +94 -0
- package/esm/model/register-model.js.map +1 -0
- package/esm/query-builder/query-builder.d.ts +556 -0
- package/esm/query-builder/query-builder.d.ts.map +1 -0
- package/esm/query-builder/query-builder.js +1070 -0
- package/esm/query-builder/query-builder.js.map +1 -0
- package/esm/relations/helpers.d.ts +156 -0
- package/esm/relations/helpers.d.ts.map +1 -0
- package/esm/relations/helpers.js +202 -0
- package/esm/relations/helpers.js.map +1 -0
- package/esm/relations/index.d.ts +35 -0
- package/esm/relations/index.d.ts.map +1 -0
- package/esm/relations/pivot-operations.d.ts +160 -0
- package/esm/relations/pivot-operations.d.ts.map +1 -0
- package/esm/relations/pivot-operations.js +293 -0
- package/esm/relations/pivot-operations.js.map +1 -0
- package/esm/relations/relation-hydrator.d.ts +68 -0
- package/esm/relations/relation-hydrator.d.ts.map +1 -0
- package/esm/relations/relation-hydrator.js +81 -0
- package/esm/relations/relation-hydrator.js.map +1 -0
- package/esm/relations/relation-loader.d.ts +194 -0
- package/esm/relations/relation-loader.d.ts.map +1 -0
- package/esm/relations/relation-loader.js +466 -0
- package/esm/relations/relation-loader.js.map +1 -0
- package/esm/relations/types.d.ts +306 -0
- package/esm/relations/types.d.ts.map +1 -0
- package/esm/remover/database-remover.d.ts +100 -0
- package/esm/remover/database-remover.d.ts.map +1 -0
- package/esm/remover/database-remover.js +214 -0
- package/esm/remover/database-remover.js.map +1 -0
- package/esm/restorer/database-restorer.d.ts +131 -0
- package/esm/restorer/database-restorer.d.ts.map +1 -0
- package/esm/restorer/database-restorer.js +434 -0
- package/esm/restorer/database-restorer.js.map +1 -0
- package/esm/sql-database-dirty-tracker.d.ts +13 -0
- package/esm/sql-database-dirty-tracker.d.ts.map +1 -0
- package/esm/sql-database-dirty-tracker.js +14 -0
- package/esm/sql-database-dirty-tracker.js.map +1 -0
- package/esm/sync/index.d.ts +12 -0
- package/esm/sync/index.d.ts.map +1 -0
- package/esm/sync/model-events.d.ts +62 -0
- package/esm/sync/model-events.d.ts.map +1 -0
- package/esm/sync/model-events.js +49 -0
- package/esm/sync/model-events.js.map +1 -0
- package/esm/sync/model-sync-operation.d.ts +163 -0
- package/esm/sync/model-sync-operation.d.ts.map +1 -0
- package/esm/sync/model-sync-operation.js +292 -0
- package/esm/sync/model-sync-operation.js.map +1 -0
- package/esm/sync/model-sync.d.ts +130 -0
- package/esm/sync/model-sync.d.ts.map +1 -0
- package/esm/sync/model-sync.js +178 -0
- package/esm/sync/model-sync.js.map +1 -0
- package/esm/sync/sync-context.d.ts +70 -0
- package/esm/sync/sync-context.d.ts.map +1 -0
- package/esm/sync/sync-context.js +101 -0
- package/esm/sync/sync-context.js.map +1 -0
- package/esm/sync/sync-manager.d.ts +213 -0
- package/esm/sync/sync-manager.d.ts.map +1 -0
- package/esm/sync/sync-manager.js +689 -0
- package/esm/sync/sync-manager.js.map +1 -0
- package/esm/sync/types.d.ts +289 -0
- package/esm/sync/types.d.ts.map +1 -0
- package/esm/test-migrations/test-enhanced-features.migration.d.ts +15 -0
- package/esm/test-migrations/test-enhanced-features.migration.d.ts.map +1 -0
- package/esm/types.d.ts +371 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/utils/connect-to-database.d.ts +307 -0
- package/esm/utils/connect-to-database.d.ts.map +1 -0
- package/esm/utils/connect-to-database.js +130 -0
- package/esm/utils/connect-to-database.js.map +1 -0
- package/esm/utils/database-writer.utils.d.ts +15 -0
- package/esm/utils/database-writer.utils.d.ts.map +1 -0
- package/esm/utils/database-writer.utils.js +14 -0
- package/esm/utils/database-writer.utils.js.map +1 -0
- package/esm/utils/define-model.js +100 -0
- package/esm/utils/define-model.js.map +1 -0
- package/esm/utils/is-valid-date-value.d.ts +5 -0
- package/esm/utils/is-valid-date-value.d.ts.map +1 -0
- package/esm/utils/is-valid-date-value.js +25 -0
- package/esm/utils/is-valid-date-value.js.map +1 -0
- package/esm/utils/once-connected.d.ts +146 -0
- package/esm/utils/once-connected.d.ts.map +1 -0
- package/esm/utils/once-connected.js +251 -0
- package/esm/utils/once-connected.js.map +1 -0
- package/esm/validation/database-seal-plugins.d.ts +12 -0
- package/esm/validation/database-seal-plugins.d.ts.map +1 -0
- package/esm/validation/database-seal-plugins.js +1 -0
- package/esm/validation/database-seal-plugins.js.map +1 -0
- package/esm/validation/database-writer-validation-error.d.ts +97 -0
- package/esm/validation/database-writer-validation-error.d.ts.map +1 -0
- package/esm/validation/database-writer-validation-error.js +160 -0
- package/esm/validation/database-writer-validation-error.js.map +1 -0
- package/esm/validation/index.d.ts +3 -0
- package/esm/validation/index.d.ts.map +1 -0
- package/esm/validation/mutators/embed-mutator.d.ts +9 -0
- package/esm/validation/mutators/embed-mutator.d.ts.map +1 -0
- package/esm/validation/mutators/embed-mutator.js +33 -0
- package/esm/validation/mutators/embed-mutator.js.map +1 -0
- package/esm/validation/plugins/embed-validator-plugin.d.ts +24 -0
- package/esm/validation/plugins/embed-validator-plugin.d.ts.map +1 -0
- package/esm/validation/plugins/embed-validator-plugin.js +18 -0
- package/esm/validation/plugins/embed-validator-plugin.js.map +1 -0
- package/esm/validation/rules/database-model-rule.d.ts +7 -0
- package/esm/validation/rules/database-model-rule.d.ts.map +1 -0
- package/esm/validation/rules/database-model-rule.js +27 -0
- package/esm/validation/rules/database-model-rule.js.map +1 -0
- package/esm/validation/transformers/embed-model-transformer.d.ts +3 -0
- package/esm/validation/transformers/embed-model-transformer.d.ts.map +1 -0
- package/esm/validation/transformers/embed-model-transformer.js +18 -0
- package/esm/validation/transformers/embed-model-transformer.js.map +1 -0
- package/esm/validation/validators/embed-validator.d.ts +21 -0
- package/esm/validation/validators/embed-validator.d.ts.map +1 -0
- package/esm/validation/validators/embed-validator.js +43 -0
- package/esm/validation/validators/embed-validator.js.map +1 -0
- package/esm/writer/database-writer.d.ts +181 -0
- package/esm/writer/database-writer.d.ts.map +1 -0
- package/esm/writer/database-writer.js +407 -0
- package/esm/writer/database-writer.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,838 @@
|
|
|
1
|
+
'use strict';var copper=require('@mongez/copper'),logger=require('@warlock.js/logger'),node_events=require('node:events'),databaseTransactionContext=require('../../context/database-transaction-context.js'),dataSourceRegistry=require('../../data-source/data-source-registry.js'),databaseDirtyTracker=require('../../database-dirty-tracker.js'),transactionRollback_error=require('../../errors/transaction-rollback.error.js'),isValidDateValue=require('../../utils/is-valid-date-value.js'),mongodbBlueprint=require('./mongodb-blueprint.js'),mongodbIdGenerator=require('./mongodb-id-generator.js'),mongodbMigrationDriver=require('./mongodb-migration-driver.js'),mongodbQueryBuilder=require('./mongodb-query-builder.js'),mongodbSyncAdapter=require('./mongodb-sync-adapter.js');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}const DEFAULT_TRANSACTION_OPTIONS = {
|
|
2
|
+
readPreference: "primary",
|
|
3
|
+
readConcern: { level: "local" },
|
|
4
|
+
writeConcern: { w: "majority" },
|
|
5
|
+
};
|
|
6
|
+
// ============================================================
|
|
7
|
+
// Lazy-loaded MongoDB SDK Types
|
|
8
|
+
// ============================================================
|
|
9
|
+
/**
|
|
10
|
+
* Cached MongoDB module (loaded once, reused)
|
|
11
|
+
*/
|
|
12
|
+
let MongoDBClient;
|
|
13
|
+
let ObjectId;
|
|
14
|
+
let isModuleExists = null;
|
|
15
|
+
let loadingPromise;
|
|
16
|
+
/**
|
|
17
|
+
* Installation instructions for MongoDB package
|
|
18
|
+
*/
|
|
19
|
+
const MONGODB_INSTALL_INSTRUCTIONS = `
|
|
20
|
+
MongoDB driver requires the mongodb package.
|
|
21
|
+
Install it with:
|
|
22
|
+
|
|
23
|
+
npm install mongodb
|
|
24
|
+
|
|
25
|
+
Or with your preferred package manager:
|
|
26
|
+
|
|
27
|
+
pnpm add mongodb
|
|
28
|
+
yarn add mongodb
|
|
29
|
+
`.trim();
|
|
30
|
+
/**
|
|
31
|
+
* Load MongoDB module
|
|
32
|
+
*/
|
|
33
|
+
async function loadMongoDB() {
|
|
34
|
+
try {
|
|
35
|
+
loadingPromise = Promise.resolve().then(function(){return /*#__PURE__*/_interopNamespace(require('mongodb'))});
|
|
36
|
+
MongoDBClient = await loadingPromise;
|
|
37
|
+
ObjectId = MongoDBClient.ObjectId;
|
|
38
|
+
isModuleExists = true;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
isModuleExists = false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
loadMongoDB();
|
|
45
|
+
function isMongoDBDriverLoaded() {
|
|
46
|
+
return isModuleExists;
|
|
47
|
+
}
|
|
48
|
+
async function assertModuleIsLoaded() {
|
|
49
|
+
if (isModuleExists === false) {
|
|
50
|
+
throw new Error(MONGODB_INSTALL_INSTRUCTIONS);
|
|
51
|
+
}
|
|
52
|
+
if (isModuleExists === null) {
|
|
53
|
+
await loadingPromise;
|
|
54
|
+
return await assertModuleIsLoaded();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* MongoDB driver implementation that fulfils the Cascade driver contract.
|
|
59
|
+
*
|
|
60
|
+
* It encapsulates the native Mongo client, exposes lifecycle events, and
|
|
61
|
+
* provides helpers for CRUD, transactions, atomic updates, and sync adapters.
|
|
62
|
+
*/
|
|
63
|
+
class MongoDbDriver {
|
|
64
|
+
config;
|
|
65
|
+
driverOptions;
|
|
66
|
+
events = new node_events.EventEmitter();
|
|
67
|
+
client;
|
|
68
|
+
database;
|
|
69
|
+
connected = false;
|
|
70
|
+
syncAdapterInstance;
|
|
71
|
+
migrationDriverInstance;
|
|
72
|
+
transactionOptions;
|
|
73
|
+
idGeneratorInstance;
|
|
74
|
+
_blueprint;
|
|
75
|
+
get blueprint() {
|
|
76
|
+
if (!this._blueprint) {
|
|
77
|
+
this._blueprint = new mongodbBlueprint.MongoDBBlueprint(this.database);
|
|
78
|
+
}
|
|
79
|
+
return this._blueprint;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The name of this driver.
|
|
83
|
+
*/
|
|
84
|
+
name = "mongodb";
|
|
85
|
+
/**
|
|
86
|
+
* Current database name
|
|
87
|
+
*/
|
|
88
|
+
_databaseName;
|
|
89
|
+
/**
|
|
90
|
+
* MongoDB driver model defaults.
|
|
91
|
+
*
|
|
92
|
+
* MongoDB follows NoSQL conventions:
|
|
93
|
+
* - camelCase naming for fields (createdAt, updatedAt, deletedAt)
|
|
94
|
+
* - Manual ID generation (auto-increment id field separate from _id)
|
|
95
|
+
* - Timestamps enabled by default
|
|
96
|
+
* - Trash delete strategy with per-collection trash tables
|
|
97
|
+
*/
|
|
98
|
+
modelDefaults = {
|
|
99
|
+
namingConvention: "camelCase",
|
|
100
|
+
createdAtColumn: "createdAt",
|
|
101
|
+
updatedAtColumn: "updatedAt",
|
|
102
|
+
deletedAtColumn: "deletedAt",
|
|
103
|
+
timestamps: true,
|
|
104
|
+
autoGenerateId: true,
|
|
105
|
+
strictMode: "strip",
|
|
106
|
+
deleteStrategy: "trash",
|
|
107
|
+
trashTable: (table) => `${table}Trash`, // Per-collection trash (usersTrash, productsTrash)
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Create a new MongoDB driver using the supplied connection options.
|
|
111
|
+
*
|
|
112
|
+
* @param config - Connection configuration
|
|
113
|
+
* @param driverOptions - Driver-specific options
|
|
114
|
+
*/
|
|
115
|
+
constructor(config, driverOptions) {
|
|
116
|
+
this.config = config;
|
|
117
|
+
this.driverOptions = driverOptions;
|
|
118
|
+
this.transactionOptions = {
|
|
119
|
+
...DEFAULT_TRANSACTION_OPTIONS,
|
|
120
|
+
...driverOptions?.transactionOptions,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get data base name
|
|
125
|
+
*/
|
|
126
|
+
get databaseName() {
|
|
127
|
+
if (!this._databaseName) {
|
|
128
|
+
this.resolveDatabaseName();
|
|
129
|
+
}
|
|
130
|
+
return this._databaseName;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Resolve database name either from config or uri
|
|
134
|
+
*/
|
|
135
|
+
resolveDatabaseName() {
|
|
136
|
+
if (this.config.database) {
|
|
137
|
+
this._databaseName = this.config.database;
|
|
138
|
+
}
|
|
139
|
+
else if (this.config.uri) {
|
|
140
|
+
this._databaseName = this.config.uri.split("/").pop()?.split("?")?.[0];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Indicates whether the driver currently maintains an active connection.
|
|
145
|
+
*/
|
|
146
|
+
get isConnected() {
|
|
147
|
+
return this.connected;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get the MongoDB database instance.
|
|
151
|
+
*
|
|
152
|
+
* @returns The MongoDB Db instance
|
|
153
|
+
* @throws {Error} If not connected
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const db = driver.getDatabase();
|
|
158
|
+
* const collection = db.collection("users");
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
getDatabase() {
|
|
162
|
+
if (!this.database) {
|
|
163
|
+
throw new Error("Database not available. Ensure the driver is connected before accessing the database.");
|
|
164
|
+
}
|
|
165
|
+
return this.database;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Get the ID generator instance for this driver.
|
|
169
|
+
*
|
|
170
|
+
* Creates a MongoIdGenerator on first access if autoGenerateId is enabled.
|
|
171
|
+
*
|
|
172
|
+
* @returns The ID generator instance, or undefined if disabled
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const idGenerator = driver.getIdGenerator();
|
|
177
|
+
* if (idGenerator) {
|
|
178
|
+
* const id = await idGenerator.generateNextId({ table: "users" });
|
|
179
|
+
* }
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
getIdGenerator() {
|
|
183
|
+
// Return undefined if ID generation is disabled
|
|
184
|
+
if (this.driverOptions?.autoGenerateId === false) {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
// Create ID generator lazily on first access
|
|
188
|
+
if (!this.idGeneratorInstance) {
|
|
189
|
+
this.idGeneratorInstance = new mongodbIdGenerator.MongoIdGenerator(this, this.driverOptions?.counterCollection);
|
|
190
|
+
}
|
|
191
|
+
return this.idGeneratorInstance;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Establish a MongoDB connection using the configured options.
|
|
195
|
+
* Throws if the connection attempt fails.
|
|
196
|
+
*/
|
|
197
|
+
async connect() {
|
|
198
|
+
if (this.connected) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
await assertModuleIsLoaded();
|
|
202
|
+
const uri = this.resolveUri();
|
|
203
|
+
const { MongoClient, ObjectId: ObjectIdMongoDB } = MongoDBClient;
|
|
204
|
+
ObjectId = ObjectIdMongoDB;
|
|
205
|
+
const client = new MongoClient(uri, this.buildClientOptions());
|
|
206
|
+
try {
|
|
207
|
+
logger.log.info("database.mongodb", "connection", `Connecting to database ${copper.colors.bold(copper.colors.yellowBright(this.databaseName))}`);
|
|
208
|
+
await client.connect();
|
|
209
|
+
this.client = client;
|
|
210
|
+
this.database = client.db(this.databaseName);
|
|
211
|
+
this.connected = true;
|
|
212
|
+
logger.log.success("database.mongodb", "connection", "Connected to database");
|
|
213
|
+
client.on("close", () => {
|
|
214
|
+
if (this.connected) {
|
|
215
|
+
this.connected = false;
|
|
216
|
+
this.emit("disconnected");
|
|
217
|
+
logger.log.warn("database.mongodb", "connection", "Disconnected from database");
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
if (this.config.logging) {
|
|
221
|
+
const ignoredCommands = ["isMaster", "hello", "ping", "saslStart", "saslContinue"];
|
|
222
|
+
client.on("commandStarted", (event) => {
|
|
223
|
+
if (ignoredCommands.includes(event.commandName))
|
|
224
|
+
return;
|
|
225
|
+
let cmdStr = JSON.stringify(event.command);
|
|
226
|
+
if (cmdStr.length > 300) {
|
|
227
|
+
cmdStr = cmdStr.substring(0, 300) + "...";
|
|
228
|
+
}
|
|
229
|
+
logger.log.info({
|
|
230
|
+
module: "database.mongodb",
|
|
231
|
+
action: "query.executing",
|
|
232
|
+
message: `[${event.commandName}] ${cmdStr}`,
|
|
233
|
+
context: { command: event.command },
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
client.on("commandSucceeded", (event) => {
|
|
237
|
+
if (ignoredCommands.includes(event.commandName))
|
|
238
|
+
return;
|
|
239
|
+
logger.log.success({
|
|
240
|
+
module: "database.mongodb",
|
|
241
|
+
action: "query.executed",
|
|
242
|
+
message: `[${event.duration.toFixed(2)}ms] [${event.commandName}]`,
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
client.on("commandFailed", (event) => {
|
|
246
|
+
if (ignoredCommands.includes(event.commandName))
|
|
247
|
+
return;
|
|
248
|
+
logger.log.error({
|
|
249
|
+
module: "database.mongodb",
|
|
250
|
+
action: "query.error",
|
|
251
|
+
message: `[${event.duration.toFixed(2)}ms] [${event.commandName}]`,
|
|
252
|
+
context: { failure: event.failure },
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
this.emit("connected");
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
await client.close().catch(() => undefined);
|
|
260
|
+
this.emit("disconnected");
|
|
261
|
+
logger.log.error("database.mongodb", "connection", `Failed to connect to database: ${error.message}`);
|
|
262
|
+
throw error;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Close the underlying MongoDB connection.
|
|
267
|
+
*/
|
|
268
|
+
async disconnect() {
|
|
269
|
+
if (!this.client) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
try {
|
|
273
|
+
await this.client.close();
|
|
274
|
+
}
|
|
275
|
+
finally {
|
|
276
|
+
this.connected = false;
|
|
277
|
+
this.emit("disconnected");
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Subscribe to driver lifecycle events.
|
|
282
|
+
*/
|
|
283
|
+
on(event, listener) {
|
|
284
|
+
this.events.on(event, listener);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Insert a single document into the given collection.
|
|
288
|
+
*/
|
|
289
|
+
async insert(table, document, options) {
|
|
290
|
+
const collection = this.getDatabaseInstance().collection(table);
|
|
291
|
+
const mongoOptions = this.withSession(options);
|
|
292
|
+
const result = await collection.insertOne(document, mongoOptions);
|
|
293
|
+
return {
|
|
294
|
+
document: {
|
|
295
|
+
...document,
|
|
296
|
+
_id: result.insertedId,
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Insert multiple documents into the given collection.
|
|
302
|
+
*/
|
|
303
|
+
async insertMany(table, documents, options) {
|
|
304
|
+
const collection = this.getDatabaseInstance().collection(table);
|
|
305
|
+
const mongoOptions = this.withSession(options);
|
|
306
|
+
const result = await collection.insertMany(documents, mongoOptions);
|
|
307
|
+
return documents.map((document, index) => {
|
|
308
|
+
const insertedId = result.insertedIds[index];
|
|
309
|
+
return {
|
|
310
|
+
document: {
|
|
311
|
+
...document,
|
|
312
|
+
_id: insertedId,
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Update a single document that matches the provided filter.
|
|
319
|
+
*/
|
|
320
|
+
async update(table, filter, update, options) {
|
|
321
|
+
const collection = this.getDatabaseInstance().collection(table);
|
|
322
|
+
const mongoOptions = this.withSession(options);
|
|
323
|
+
const result = await collection.updateOne(filter, update, mongoOptions);
|
|
324
|
+
return { modifiedCount: result.modifiedCount };
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Replace a single document that matches the provided filter.
|
|
328
|
+
*/
|
|
329
|
+
async replace(table, filter, document, options) {
|
|
330
|
+
const collection = this.getDatabaseInstance().collection(table);
|
|
331
|
+
const result = await collection.findOneAndReplace(filter, document);
|
|
332
|
+
return result?.value;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Find one and update a single document that matches the provided filter and return the updated document
|
|
336
|
+
*/
|
|
337
|
+
async findOneAndUpdate(table, filter, update, options) {
|
|
338
|
+
const collection = this.getDatabaseInstance().collection(table);
|
|
339
|
+
const mongoOptions = this.withSession(options);
|
|
340
|
+
const result = await collection.findOneAndUpdate(filter, update, {
|
|
341
|
+
returnDocument: "after",
|
|
342
|
+
...mongoOptions,
|
|
343
|
+
});
|
|
344
|
+
return result;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Upsert (insert or update) a single document.
|
|
348
|
+
*
|
|
349
|
+
* Uses MongoDB's findOneAndUpdate with upsert option.
|
|
350
|
+
*
|
|
351
|
+
* @param table - Target collection name
|
|
352
|
+
* @param filter - Filter conditions to find existing document
|
|
353
|
+
* @param document - Document data to insert or update
|
|
354
|
+
* @param options - Optional upsert options
|
|
355
|
+
* @returns The upserted document
|
|
356
|
+
*/
|
|
357
|
+
async upsert(table, filter, document, options) {
|
|
358
|
+
const collection = this.getDatabaseInstance().collection(table);
|
|
359
|
+
const mongoOptions = this.withSession(options);
|
|
360
|
+
// Use $set to update all fields from document
|
|
361
|
+
const update = { $set: document };
|
|
362
|
+
const result = await collection.findOneAndUpdate(filter, update, {
|
|
363
|
+
upsert: true,
|
|
364
|
+
returnDocument: "after",
|
|
365
|
+
...mongoOptions,
|
|
366
|
+
});
|
|
367
|
+
return result;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Find one and delete a single document that matches the provided filter and return the deleted document.
|
|
371
|
+
*
|
|
372
|
+
* @param table - Target collection name
|
|
373
|
+
* @param filter - Filter conditions
|
|
374
|
+
* @param options - Optional delete options
|
|
375
|
+
* @returns The deleted document or null if not found
|
|
376
|
+
*/
|
|
377
|
+
async findOneAndDelete(table, filter, options) {
|
|
378
|
+
const collection = this.getDatabaseInstance().collection(table);
|
|
379
|
+
const mongoOptions = this.withSession(options);
|
|
380
|
+
const result = await collection.findOneAndDelete(filter, mongoOptions || {});
|
|
381
|
+
return result;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Update multiple documents that match the provided filter.
|
|
385
|
+
*/
|
|
386
|
+
async updateMany(table, filter, update, options) {
|
|
387
|
+
const collection = this.getDatabaseInstance().collection(table);
|
|
388
|
+
const mongoOptions = this.withSession(options);
|
|
389
|
+
const result = await collection.updateMany(filter, update, mongoOptions);
|
|
390
|
+
return { modifiedCount: result.modifiedCount };
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Delete a single document that matches the provided filter.
|
|
394
|
+
*/
|
|
395
|
+
async delete(table, filter = {}, options) {
|
|
396
|
+
const collection = this.getDatabaseInstance().collection(table);
|
|
397
|
+
const mongoOptions = this.withSession(options);
|
|
398
|
+
const result = await collection.deleteOne(filter, mongoOptions);
|
|
399
|
+
return result.deletedCount > 0 ? 1 : 0;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Delete documents that match the provided filter.
|
|
403
|
+
*/
|
|
404
|
+
async deleteMany(table, filter = {}, options) {
|
|
405
|
+
const collection = this.getDatabaseInstance().collection(table);
|
|
406
|
+
const mongoOptions = this.withSession(options);
|
|
407
|
+
const result = await collection.deleteMany(filter, mongoOptions);
|
|
408
|
+
return result.deletedCount ?? 0;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Remove all records from a collection.
|
|
412
|
+
*
|
|
413
|
+
* This uses deleteMany with an empty filter to remove all documents.
|
|
414
|
+
* For very large collections, consider using the migration driver's
|
|
415
|
+
* dropTable + createTable approach for better performance.
|
|
416
|
+
*/
|
|
417
|
+
async truncateTable(table, options) {
|
|
418
|
+
const collection = this.getDatabaseInstance().collection(table);
|
|
419
|
+
const mongoOptions = this.withSession(options);
|
|
420
|
+
const result = await collection.deleteMany({}, mongoOptions);
|
|
421
|
+
return result.deletedCount ?? 0;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Serialize the given data
|
|
425
|
+
*/
|
|
426
|
+
serialize(data) {
|
|
427
|
+
for (const [key, value] of Object.entries(data)) {
|
|
428
|
+
if (value === undefined) {
|
|
429
|
+
continue; // Skip undefined values
|
|
430
|
+
}
|
|
431
|
+
if (value instanceof ObjectId) {
|
|
432
|
+
value.toString();
|
|
433
|
+
}
|
|
434
|
+
else if (value instanceof Date) {
|
|
435
|
+
value.toISOString();
|
|
436
|
+
}
|
|
437
|
+
else if (typeof value === "bigint") {
|
|
438
|
+
value.toString();
|
|
439
|
+
}
|
|
440
|
+
else ;
|
|
441
|
+
}
|
|
442
|
+
return data;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Get the dirty tracker for this driver.
|
|
446
|
+
*/
|
|
447
|
+
getDirtyTracker(data) {
|
|
448
|
+
return new databaseDirtyTracker.DatabaseDirtyTracker(data);
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Deserialize the given data
|
|
452
|
+
*/
|
|
453
|
+
deserialize(data) {
|
|
454
|
+
if (data._id && typeof data._id === "string") {
|
|
455
|
+
data._id = new ObjectId(data._id);
|
|
456
|
+
}
|
|
457
|
+
for (const [key, value] of Object.entries(data)) {
|
|
458
|
+
// Only re-inflate strings — Mongo driver already returns Date objects from DB reads
|
|
459
|
+
if (typeof value === "string" && isValidDateValue.isValidDateValue(value)) {
|
|
460
|
+
data[key] = new Date(value);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return data;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Provide a Mongo-backed query builder instance for the given collection.
|
|
467
|
+
*/
|
|
468
|
+
queryBuilder(table) {
|
|
469
|
+
return new mongodbQueryBuilder.MongoQueryBuilder(table, dataSourceRegistry.dataSourceRegistry.get());
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Begin a MongoDB transaction, returning commit/rollback helpers.
|
|
473
|
+
*/
|
|
474
|
+
async beginTransaction() {
|
|
475
|
+
const client = this.getClientInstance();
|
|
476
|
+
const session = client.startSession();
|
|
477
|
+
await session.startTransaction(this.transactionOptions);
|
|
478
|
+
databaseTransactionContext.databaseTransactionContext.enter({ session });
|
|
479
|
+
let finished = false;
|
|
480
|
+
const finalize = async (operation) => {
|
|
481
|
+
if (finished)
|
|
482
|
+
return;
|
|
483
|
+
try {
|
|
484
|
+
await operation();
|
|
485
|
+
}
|
|
486
|
+
finally {
|
|
487
|
+
finished = true;
|
|
488
|
+
databaseTransactionContext.databaseTransactionContext.exit();
|
|
489
|
+
await session.endSession().catch(() => undefined);
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
return {
|
|
493
|
+
context: session,
|
|
494
|
+
commit: async () => {
|
|
495
|
+
await finalize(async () => {
|
|
496
|
+
try {
|
|
497
|
+
await session.commitTransaction();
|
|
498
|
+
}
|
|
499
|
+
catch (error) {
|
|
500
|
+
await session.abortTransaction().catch(() => undefined);
|
|
501
|
+
throw error;
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
},
|
|
505
|
+
rollback: async () => {
|
|
506
|
+
await finalize(async () => {
|
|
507
|
+
await session.abortTransaction();
|
|
508
|
+
});
|
|
509
|
+
},
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Execute a function within a transaction scope (recommended pattern).
|
|
514
|
+
*
|
|
515
|
+
* Automatically commits on success, rolls back on any error, and guarantees
|
|
516
|
+
* resource cleanup. This is the recommended way to use transactions.
|
|
517
|
+
*
|
|
518
|
+
* **MongoDB Requirements:**
|
|
519
|
+
* - Requires MongoDB 4.0+ with replica set or sharded cluster
|
|
520
|
+
* - Standalone MongoDB instances do not support transactions
|
|
521
|
+
*
|
|
522
|
+
* @param fn - Async function to execute within transaction
|
|
523
|
+
* @param options - Transaction options (read preference, write concern, etc.)
|
|
524
|
+
* @returns The return value of the callback function
|
|
525
|
+
* @throws {Error} If transaction fails, is explicitly rolled back, or replica set not configured
|
|
526
|
+
*/
|
|
527
|
+
async transaction(fn, options) {
|
|
528
|
+
// Prevent nested transaction() calls
|
|
529
|
+
if (databaseTransactionContext.databaseTransactionContext.hasActiveTransaction()) {
|
|
530
|
+
throw new Error("Nested transaction() calls are not supported. " +
|
|
531
|
+
"Use beginTransaction() with savepoints for advanced transaction patterns.");
|
|
532
|
+
}
|
|
533
|
+
// Check if MongoDB is running as a replica set (required for transactions)
|
|
534
|
+
await this.ensureReplicaSetAvailable();
|
|
535
|
+
const client = this.getClientInstance();
|
|
536
|
+
const session = client.startSession();
|
|
537
|
+
try {
|
|
538
|
+
await session.startTransaction({
|
|
539
|
+
...this.transactionOptions,
|
|
540
|
+
...options,
|
|
541
|
+
});
|
|
542
|
+
// Set transaction context for queries within callback
|
|
543
|
+
databaseTransactionContext.databaseTransactionContext.enter({ session });
|
|
544
|
+
try {
|
|
545
|
+
// Create transaction context with rollback method
|
|
546
|
+
const ctx = {
|
|
547
|
+
rollback(reason) {
|
|
548
|
+
throw new transactionRollback_error.TransactionRollbackError(reason);
|
|
549
|
+
},
|
|
550
|
+
};
|
|
551
|
+
// Execute callback
|
|
552
|
+
const result = await fn(ctx);
|
|
553
|
+
// Auto-commit on success
|
|
554
|
+
await session.commitTransaction();
|
|
555
|
+
return result;
|
|
556
|
+
}
|
|
557
|
+
catch (error) {
|
|
558
|
+
// Auto-rollback on any error (including explicit rollback)
|
|
559
|
+
await session.abortTransaction().catch(() => undefined);
|
|
560
|
+
throw error;
|
|
561
|
+
}
|
|
562
|
+
finally {
|
|
563
|
+
// Guaranteed context cleanup
|
|
564
|
+
databaseTransactionContext.databaseTransactionContext.exit();
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
finally {
|
|
568
|
+
// Guaranteed session cleanup
|
|
569
|
+
await session.endSession().catch(() => undefined);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Execute atomic operations (typically $inc/$set style updates) against documents.
|
|
574
|
+
*
|
|
575
|
+
* Uses `updateMany` so callers can atomically modify any set of documents.
|
|
576
|
+
*/
|
|
577
|
+
async atomic(table, filter, operations, options) {
|
|
578
|
+
const collection = this.getDatabaseInstance().collection(table);
|
|
579
|
+
const mongoOptions = this.withSession(options);
|
|
580
|
+
const result = await collection.updateMany(filter, operations, mongoOptions);
|
|
581
|
+
return { modifiedCount: result.modifiedCount };
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Lazily create (and cache) the Mongo sync adapter.
|
|
585
|
+
* The adapter uses this driver instance to ensure all operations
|
|
586
|
+
* participate in active transactions via the session context.
|
|
587
|
+
*/
|
|
588
|
+
syncAdapter() {
|
|
589
|
+
if (!this.syncAdapterInstance) {
|
|
590
|
+
this.syncAdapterInstance = new mongodbSyncAdapter.MongoSyncAdapter(this);
|
|
591
|
+
}
|
|
592
|
+
return this.syncAdapterInstance;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Lazily create (and cache) the Mongo migration driver.
|
|
596
|
+
* The migration driver handles schema operations like indexes, collections, etc.
|
|
597
|
+
*/
|
|
598
|
+
migrationDriver() {
|
|
599
|
+
if (!this.migrationDriverInstance) {
|
|
600
|
+
this.migrationDriverInstance = new mongodbMigrationDriver.MongoMigrationDriver(this);
|
|
601
|
+
}
|
|
602
|
+
return this.migrationDriverInstance;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Expose the underlying Mongo client for advanced consumers.
|
|
606
|
+
*/
|
|
607
|
+
getClient() {
|
|
608
|
+
return this.getClientInstance();
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Retrieve the active Mongo client, throwing if the driver is disconnected.
|
|
612
|
+
*/
|
|
613
|
+
getClientInstance() {
|
|
614
|
+
if (!this.client) {
|
|
615
|
+
throw new Error("Mongo driver is not connected.");
|
|
616
|
+
}
|
|
617
|
+
return this.client;
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Retrieve the active Mongo database, throwing if the driver is disconnected.
|
|
621
|
+
* @private
|
|
622
|
+
*/
|
|
623
|
+
getDatabaseInstance() {
|
|
624
|
+
if (!this.database) {
|
|
625
|
+
throw new Error("Mongo driver is not connected to a database.");
|
|
626
|
+
}
|
|
627
|
+
return this.database;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Resolve the Mongo connection string based on provided options.
|
|
631
|
+
*/
|
|
632
|
+
resolveUri() {
|
|
633
|
+
if (this.config.uri) {
|
|
634
|
+
return this.config.uri;
|
|
635
|
+
}
|
|
636
|
+
const host = this.config.host ?? "localhost";
|
|
637
|
+
const port = this.config.port ?? 27017;
|
|
638
|
+
return `mongodb://${host}:${port}`;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Build the Mongo client options derived from the driver configuration.
|
|
642
|
+
*/
|
|
643
|
+
buildClientOptions() {
|
|
644
|
+
const baseOptions = {
|
|
645
|
+
...(this.config.clientOptions ?? {}),
|
|
646
|
+
};
|
|
647
|
+
if (this.config.logging) {
|
|
648
|
+
baseOptions.monitorCommands = true;
|
|
649
|
+
}
|
|
650
|
+
if (this.config.username && !baseOptions.auth) {
|
|
651
|
+
baseOptions.auth = {
|
|
652
|
+
username: this.config.username,
|
|
653
|
+
password: this.config.password,
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
if (this.config.authSource && !baseOptions.authSource) {
|
|
657
|
+
baseOptions.authSource = this.config.authSource;
|
|
658
|
+
}
|
|
659
|
+
return baseOptions;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Emit a driver lifecycle event.
|
|
663
|
+
*/
|
|
664
|
+
emit(event, ...args) {
|
|
665
|
+
this.events.emit(event, ...args);
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Ensure MongoDB is running as a replica set (required for transactions).
|
|
669
|
+
*
|
|
670
|
+
* @throws {Error} If MongoDB is running as a standalone instance
|
|
671
|
+
*/
|
|
672
|
+
async ensureReplicaSetAvailable() {
|
|
673
|
+
try {
|
|
674
|
+
const admin = this.database.admin();
|
|
675
|
+
const status = await admin.serverStatus();
|
|
676
|
+
if (!status.repl) {
|
|
677
|
+
throw new Error("MongoDB transactions require a replica set or sharded cluster. " +
|
|
678
|
+
"Standalone MongoDB instances do not support transactions.\n\n" +
|
|
679
|
+
"For local development:\n" +
|
|
680
|
+
" - Run MongoDB with --replSet flag: mongod --replSet rs0\n" +
|
|
681
|
+
" - Or use Docker with replica set configuration\n" +
|
|
682
|
+
" - Or use MongoDB Atlas (cloud) which provides replica sets by default");
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
catch (error) {
|
|
686
|
+
if (error.message?.includes("replica set")) {
|
|
687
|
+
throw error;
|
|
688
|
+
}
|
|
689
|
+
throw new Error(`Failed to check MongoDB replica set status: ${error.message}`);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Attach the active transaction session (when available) to Mongo options.
|
|
694
|
+
*/
|
|
695
|
+
withSession(options) {
|
|
696
|
+
const session = databaseTransactionContext.databaseTransactionContext.getSession();
|
|
697
|
+
if (!session) {
|
|
698
|
+
return options;
|
|
699
|
+
}
|
|
700
|
+
const baseOptions = options ? { ...options } : {};
|
|
701
|
+
baseOptions.session = session;
|
|
702
|
+
return baseOptions;
|
|
703
|
+
}
|
|
704
|
+
// ============================================================
|
|
705
|
+
// SQL Compatibility Operations (Not supported in MongoDB)
|
|
706
|
+
// ============================================================
|
|
707
|
+
/**
|
|
708
|
+
* Return a SQL serializer for this driver's dialect.
|
|
709
|
+
* Not supported for MongoDB.
|
|
710
|
+
*/
|
|
711
|
+
getSQLSerializer() {
|
|
712
|
+
throw new Error("MongoDB driver does not support SQL serialization.");
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Execute a raw SQL query.
|
|
716
|
+
* Not supported for MongoDB.
|
|
717
|
+
*/
|
|
718
|
+
async query(_sql, _params) {
|
|
719
|
+
throw new Error("MongoDB driver does not support raw SQL queries.");
|
|
720
|
+
}
|
|
721
|
+
// ============================================================
|
|
722
|
+
// Database Lifecycle Operations
|
|
723
|
+
// ============================================================
|
|
724
|
+
/**
|
|
725
|
+
* Create a new database.
|
|
726
|
+
*
|
|
727
|
+
* In MongoDB, databases are created automatically when data is first written.
|
|
728
|
+
* This method creates an empty collection to ensure the database exists.
|
|
729
|
+
*
|
|
730
|
+
* @param name - Database name to create
|
|
731
|
+
* @returns true if created, false if already exists
|
|
732
|
+
*/
|
|
733
|
+
async createDatabase(name) {
|
|
734
|
+
const client = this.getClientInstance();
|
|
735
|
+
// Check if database already exists
|
|
736
|
+
if (await this.databaseExists(name)) {
|
|
737
|
+
return false;
|
|
738
|
+
}
|
|
739
|
+
try {
|
|
740
|
+
// MongoDB creates databases on first write, so create a system collection
|
|
741
|
+
const db = client.db(name);
|
|
742
|
+
await db.createCollection("__init__");
|
|
743
|
+
// Drop the temp collection
|
|
744
|
+
await db.collection("__init__").drop();
|
|
745
|
+
logger.log.success("database", "lifecycle", `Created database ${name}`);
|
|
746
|
+
return true;
|
|
747
|
+
}
|
|
748
|
+
catch (error) {
|
|
749
|
+
logger.log.error("database", "lifecycle", `Failed to create database ${name}: ${error}`);
|
|
750
|
+
throw error;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Drop a database.
|
|
755
|
+
*
|
|
756
|
+
* @param name - Database name to drop
|
|
757
|
+
* @returns true if dropped, false if didn't exist
|
|
758
|
+
*/
|
|
759
|
+
async dropDatabase(name) {
|
|
760
|
+
const client = this.getClientInstance();
|
|
761
|
+
// Check if database exists
|
|
762
|
+
if (!(await this.databaseExists(name))) {
|
|
763
|
+
return false;
|
|
764
|
+
}
|
|
765
|
+
try {
|
|
766
|
+
await client.db(name).dropDatabase();
|
|
767
|
+
logger.log.success("database", "lifecycle", `Dropped database ${name}`);
|
|
768
|
+
return true;
|
|
769
|
+
}
|
|
770
|
+
catch (error) {
|
|
771
|
+
logger.log.error("database", "lifecycle", `Failed to drop database ${name}: ${error}`);
|
|
772
|
+
throw error;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Check if a database exists.
|
|
777
|
+
*
|
|
778
|
+
* @param name - Database name to check
|
|
779
|
+
* @returns true if database exists
|
|
780
|
+
*/
|
|
781
|
+
async databaseExists(name) {
|
|
782
|
+
const client = this.getClientInstance();
|
|
783
|
+
const result = await client.db("admin").admin().listDatabases();
|
|
784
|
+
return result.databases.some((db) => db.name === name);
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* List all databases.
|
|
788
|
+
*
|
|
789
|
+
* @returns Array of database names
|
|
790
|
+
*/
|
|
791
|
+
async listDatabases() {
|
|
792
|
+
const client = this.getClientInstance();
|
|
793
|
+
const result = await client.db("admin").admin().listDatabases();
|
|
794
|
+
return result.databases
|
|
795
|
+
.map((db) => db.name)
|
|
796
|
+
.filter((name) => !["admin", "local", "config"].includes(name));
|
|
797
|
+
}
|
|
798
|
+
// ============================================================
|
|
799
|
+
// Table/Collection Management Operations
|
|
800
|
+
// ============================================================
|
|
801
|
+
/**
|
|
802
|
+
* Drop a collection.
|
|
803
|
+
*
|
|
804
|
+
* @param name - Collection name to drop
|
|
805
|
+
* @throws Error if collection doesn't exist
|
|
806
|
+
*/
|
|
807
|
+
async dropTable(name) {
|
|
808
|
+
const db = this.getDatabaseInstance();
|
|
809
|
+
await db.collection(name).drop();
|
|
810
|
+
logger.log.success("database", "collection", `Dropped collection ${name}`);
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Drop a collection if it exists.
|
|
814
|
+
*
|
|
815
|
+
* @param name - Collection name to drop
|
|
816
|
+
*/
|
|
817
|
+
async dropTableIfExists(name) {
|
|
818
|
+
if (await this.blueprint.tableExists(name)) {
|
|
819
|
+
await this.dropTable(name);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Drop all collections in the current database.
|
|
824
|
+
*
|
|
825
|
+
* Useful for `migrate:fresh` command.
|
|
826
|
+
*/
|
|
827
|
+
async dropAllTables() {
|
|
828
|
+
const collections = await this.blueprint.listTables();
|
|
829
|
+
if (collections.length === 0) {
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
const db = this.getDatabaseInstance();
|
|
833
|
+
for (const collection of collections) {
|
|
834
|
+
await db.collection(collection).drop();
|
|
835
|
+
}
|
|
836
|
+
logger.log.success("database", "collection", `Dropped ${collections.length} collections`);
|
|
837
|
+
}
|
|
838
|
+
}exports.MongoDbDriver=MongoDbDriver;exports.isMongoDBDriverLoaded=isMongoDBDriverLoaded;//# sourceMappingURL=mongodb-driver.js.map
|