@warlock.js/cascade 4.0.47 → 4.0.58
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 +31 -0
- package/cjs/context/database-transaction-context.d.ts.map +1 -0
- package/cjs/context/database-transaction-context.js +34 -0
- package/cjs/context/database-transaction-context.js.map +1 -0
- package/cjs/contracts/database-driver.contract.d.ts +143 -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 +45 -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 +365 -0
- package/cjs/contracts/migration-driver.contract.d.ts.map +1 -0
- package/cjs/contracts/query-builder.contract.d.ts +1128 -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 +104 -0
- package/cjs/data-source/data-source-registry.d.ts.map +1 -0
- package/cjs/data-source/data-source-registry.js +138 -0
- package/cjs/data-source/data-source-registry.js.map +1 -0
- package/cjs/data-source/data-source.d.ts +106 -0
- package/cjs/data-source/data-source.d.ts.map +1 -0
- package/cjs/data-source/data-source.js +77 -0
- package/cjs/data-source/data-source.js.map +1 -0
- package/cjs/database-dirty-tracker.d.ts +253 -0
- package/cjs/database-dirty-tracker.d.ts.map +1 -0
- package/cjs/database-dirty-tracker.js +389 -0
- package/cjs/database-dirty-tracker.js.map +1 -0
- package/cjs/drivers/mongo/mongo-id-generator.d.ts +116 -0
- package/cjs/drivers/mongo/mongo-id-generator.d.ts.map +1 -0
- package/cjs/drivers/mongo/mongo-id-generator.js +149 -0
- package/cjs/drivers/mongo/mongo-id-generator.js.map +1 -0
- package/cjs/drivers/mongo/mongo-migration-driver.d.ts +228 -0
- package/cjs/drivers/mongo/mongo-migration-driver.d.ts.map +1 -0
- package/cjs/drivers/mongo/mongo-migration-driver.js +524 -0
- package/cjs/drivers/mongo/mongo-migration-driver.js.map +1 -0
- package/cjs/drivers/mongo/mongo-query-builder.d.ts +922 -0
- package/cjs/drivers/mongo/mongo-query-builder.d.ts.map +1 -0
- package/cjs/drivers/mongo/mongo-query-builder.js +1740 -0
- package/cjs/drivers/mongo/mongo-query-builder.js.map +1 -0
- package/cjs/drivers/mongo/mongo-query-operations.d.ts +226 -0
- package/cjs/drivers/mongo/mongo-query-operations.d.ts.map +1 -0
- package/cjs/drivers/mongo/mongo-query-operations.js +270 -0
- package/cjs/drivers/mongo/mongo-query-operations.js.map +1 -0
- package/cjs/drivers/mongo/mongo-query-parser.d.ts +262 -0
- package/cjs/drivers/mongo/mongo-query-parser.d.ts.map +1 -0
- package/cjs/drivers/mongo/mongo-query-parser.js +1351 -0
- package/cjs/drivers/mongo/mongo-query-parser.js.map +1 -0
- package/cjs/drivers/mongo/mongo-sync-adapter.d.ts +79 -0
- package/cjs/drivers/mongo/mongo-sync-adapter.d.ts.map +1 -0
- package/cjs/drivers/mongo/mongo-sync-adapter.js +146 -0
- package/cjs/drivers/mongo/mongo-sync-adapter.js.map +1 -0
- package/cjs/drivers/mongo/mongodb-blueprint.d.ts +30 -0
- package/cjs/drivers/mongo/mongodb-blueprint.d.ts.map +1 -0
- package/cjs/drivers/mongo/mongodb-blueprint.js +51 -0
- package/cjs/drivers/mongo/mongodb-blueprint.js.map +1 -0
- package/cjs/drivers/mongo/mongodb-driver.d.ts +188 -0
- package/cjs/drivers/mongo/mongodb-driver.d.ts.map +1 -0
- package/cjs/drivers/mongo/mongodb-driver.js +411 -0
- package/cjs/drivers/mongo/mongodb-driver.js.map +1 -0
- package/cjs/drivers/mongo/types.d.ts +43 -0
- package/cjs/drivers/mongo/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/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 +41 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js +1 -267
- package/cjs/index.js.map +1 -1
- package/cjs/migration/column-builder.d.ts +167 -0
- package/cjs/migration/column-builder.d.ts.map +1 -0
- package/cjs/migration/column-builder.js +217 -0
- package/cjs/migration/column-builder.js.map +1 -0
- package/cjs/migration/foreign-key-builder.d.ts +110 -0
- package/cjs/migration/foreign-key-builder.d.ts.map +1 -0
- package/cjs/migration/foreign-key-builder.js +129 -0
- package/cjs/migration/foreign-key-builder.js.map +1 -0
- package/cjs/migration/index.d.ts +6 -0
- package/cjs/migration/index.d.ts.map +1 -0
- package/cjs/migration/migration-runner.d.ts +231 -0
- package/cjs/migration/migration-runner.d.ts.map +1 -0
- package/cjs/migration/migration-runner.js +443 -0
- package/cjs/migration/migration-runner.js.map +1 -0
- package/cjs/migration/migration.js +1346 -0
- package/cjs/migration/migration.js.map +1 -0
- package/cjs/migration/types.d.ts +132 -0
- package/cjs/migration/types.d.ts.map +1 -0
- package/cjs/model/model.d.ts +1267 -0
- package/cjs/model/model.d.ts.map +1 -0
- package/cjs/model/model.js +1463 -0
- package/cjs/model/model.js.map +1 -0
- package/cjs/model/register-model.d.ts +80 -0
- package/cjs/model/register-model.d.ts.map +1 -0
- package/cjs/model/register-model.js +91 -0
- package/cjs/model/register-model.js.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 +209 -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 +425 -0
- package/cjs/restorer/database-restorer.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/types.d.ts +45 -0
- package/cjs/types.d.ts.map +1 -0
- package/cjs/utils/connect-to-database.d.ts +246 -0
- package/cjs/utils/connect-to-database.d.ts.map +1 -0
- package/cjs/utils/connect-to-database.js +92 -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/once-connected.d.ts +146 -0
- package/cjs/utils/once-connected.d.ts.map +1 -0
- package/cjs/utils/once-connected.js +252 -0
- package/cjs/utils/once-connected.js.map +1 -0
- package/cjs/validation/database-seal-plugins.d.ts +2 -0
- package/cjs/validation/database-seal-plugins.d.ts.map +1 -0
- package/cjs/validation/database-seal-plugins.js +4 -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 +42 -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 +402 -0
- package/cjs/writer/database-writer.js.map +1 -0
- package/esm/context/database-data-source-context.d.ts +29 -0
- package/esm/context/database-data-source-context.d.ts.map +1 -0
- package/esm/context/database-data-source-context.js +28 -0
- package/esm/context/database-data-source-context.js.map +1 -0
- package/esm/context/database-transaction-context.d.ts +31 -0
- package/esm/context/database-transaction-context.d.ts.map +1 -0
- package/esm/context/database-transaction-context.js +34 -0
- package/esm/context/database-transaction-context.js.map +1 -0
- package/esm/contracts/database-driver.contract.d.ts +143 -0
- package/esm/contracts/database-driver.contract.d.ts.map +1 -0
- package/esm/contracts/database-id-generator.contract.d.ts +109 -0
- package/esm/contracts/database-id-generator.contract.d.ts.map +1 -0
- package/esm/contracts/database-remover.contract.d.ts +104 -0
- package/esm/contracts/database-remover.contract.d.ts.map +1 -0
- package/esm/contracts/database-restorer.contract.d.ts +143 -0
- package/esm/contracts/database-restorer.contract.d.ts.map +1 -0
- package/esm/contracts/database-writer.contract.d.ts +119 -0
- package/esm/contracts/database-writer.contract.d.ts.map +1 -0
- package/esm/contracts/driver-blueprint.contract.d.ts +45 -0
- package/esm/contracts/driver-blueprint.contract.d.ts.map +1 -0
- package/esm/contracts/index.d.ts +10 -0
- package/esm/contracts/index.d.ts.map +1 -0
- package/esm/contracts/migration-driver.contract.d.ts +365 -0
- package/esm/contracts/migration-driver.contract.d.ts.map +1 -0
- package/esm/contracts/query-builder.contract.d.ts +1128 -0
- package/esm/contracts/query-builder.contract.d.ts.map +1 -0
- package/esm/contracts/sync-adapter.contract.d.ts +58 -0
- package/esm/contracts/sync-adapter.contract.d.ts.map +1 -0
- package/esm/data-source/data-source-registry.d.ts +104 -0
- package/esm/data-source/data-source-registry.d.ts.map +1 -0
- package/esm/data-source/data-source-registry.js +138 -0
- package/esm/data-source/data-source-registry.js.map +1 -0
- package/esm/data-source/data-source.d.ts +106 -0
- package/esm/data-source/data-source.d.ts.map +1 -0
- package/esm/data-source/data-source.js +77 -0
- package/esm/data-source/data-source.js.map +1 -0
- package/esm/database-dirty-tracker.d.ts +253 -0
- package/esm/database-dirty-tracker.d.ts.map +1 -0
- package/esm/database-dirty-tracker.js +389 -0
- package/esm/database-dirty-tracker.js.map +1 -0
- package/esm/drivers/mongo/mongo-id-generator.d.ts +116 -0
- package/esm/drivers/mongo/mongo-id-generator.d.ts.map +1 -0
- package/esm/drivers/mongo/mongo-id-generator.js +149 -0
- package/esm/drivers/mongo/mongo-id-generator.js.map +1 -0
- package/esm/drivers/mongo/mongo-migration-driver.d.ts +228 -0
- package/esm/drivers/mongo/mongo-migration-driver.d.ts.map +1 -0
- package/esm/drivers/mongo/mongo-migration-driver.js +524 -0
- package/esm/drivers/mongo/mongo-migration-driver.js.map +1 -0
- package/esm/drivers/mongo/mongo-query-builder.d.ts +922 -0
- package/esm/drivers/mongo/mongo-query-builder.d.ts.map +1 -0
- package/esm/drivers/mongo/mongo-query-builder.js +1740 -0
- package/esm/drivers/mongo/mongo-query-builder.js.map +1 -0
- package/esm/drivers/mongo/mongo-query-operations.d.ts +226 -0
- package/esm/drivers/mongo/mongo-query-operations.d.ts.map +1 -0
- package/esm/drivers/mongo/mongo-query-operations.js +270 -0
- package/esm/drivers/mongo/mongo-query-operations.js.map +1 -0
- package/esm/drivers/mongo/mongo-query-parser.d.ts +262 -0
- package/esm/drivers/mongo/mongo-query-parser.d.ts.map +1 -0
- package/esm/drivers/mongo/mongo-query-parser.js +1351 -0
- package/esm/drivers/mongo/mongo-query-parser.js.map +1 -0
- package/esm/drivers/mongo/mongo-sync-adapter.d.ts +79 -0
- package/esm/drivers/mongo/mongo-sync-adapter.d.ts.map +1 -0
- package/esm/drivers/mongo/mongo-sync-adapter.js +146 -0
- package/esm/drivers/mongo/mongo-sync-adapter.js.map +1 -0
- package/esm/drivers/mongo/mongodb-blueprint.d.ts +30 -0
- package/esm/drivers/mongo/mongodb-blueprint.d.ts.map +1 -0
- package/esm/drivers/mongo/mongodb-blueprint.js +51 -0
- package/esm/drivers/mongo/mongodb-blueprint.js.map +1 -0
- package/esm/drivers/mongo/mongodb-driver.d.ts +188 -0
- package/esm/drivers/mongo/mongodb-driver.d.ts.map +1 -0
- package/esm/drivers/mongo/mongodb-driver.js +411 -0
- package/esm/drivers/mongo/mongodb-driver.js.map +1 -0
- package/esm/drivers/mongo/types.d.ts +43 -0
- package/esm/drivers/mongo/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/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 +41 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +1 -40
- package/esm/index.js.map +1 -1
- package/esm/migration/column-builder.d.ts +167 -0
- package/esm/migration/column-builder.d.ts.map +1 -0
- package/esm/migration/column-builder.js +217 -0
- package/esm/migration/column-builder.js.map +1 -0
- package/esm/migration/foreign-key-builder.d.ts +110 -0
- package/esm/migration/foreign-key-builder.d.ts.map +1 -0
- package/esm/migration/foreign-key-builder.js +129 -0
- package/esm/migration/foreign-key-builder.js.map +1 -0
- package/esm/migration/index.d.ts +6 -0
- package/esm/migration/index.d.ts.map +1 -0
- package/esm/migration/migration-runner.d.ts +231 -0
- package/esm/migration/migration-runner.d.ts.map +1 -0
- package/esm/migration/migration-runner.js +443 -0
- package/esm/migration/migration-runner.js.map +1 -0
- package/esm/migration/migration.js +1346 -0
- package/esm/migration/migration.js.map +1 -0
- package/esm/migration/types.d.ts +132 -0
- package/esm/migration/types.d.ts.map +1 -0
- package/esm/model/model.d.ts +1267 -0
- package/esm/model/model.d.ts.map +1 -0
- package/esm/model/model.js +1463 -0
- package/esm/model/model.js.map +1 -0
- package/esm/model/register-model.d.ts +80 -0
- package/esm/model/register-model.d.ts.map +1 -0
- package/esm/model/register-model.js +91 -0
- package/esm/model/register-model.js.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 +209 -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 +425 -0
- package/esm/restorer/database-restorer.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/types.d.ts +45 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/utils/connect-to-database.d.ts +246 -0
- package/esm/utils/connect-to-database.d.ts.map +1 -0
- package/esm/utils/connect-to-database.js +92 -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/once-connected.d.ts +146 -0
- package/esm/utils/once-connected.d.ts.map +1 -0
- package/esm/utils/once-connected.js +252 -0
- package/esm/utils/once-connected.js.map +1 -0
- package/esm/validation/database-seal-plugins.d.ts +2 -0
- package/esm/validation/database-seal-plugins.d.ts.map +1 -0
- package/esm/validation/database-seal-plugins.js +4 -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 +42 -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 +402 -0
- package/esm/writer/database-writer.js.map +1 -0
- package/package.json +61 -52
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { WriterContract, WriterOptions, WriterResult } from "../contracts/database-writer.contract";
|
|
2
|
+
import type { Model } from "../model/model";
|
|
3
|
+
/**
|
|
4
|
+
* Database writer service that orchestrates model persistence.
|
|
5
|
+
*
|
|
6
|
+
* Handles the complete save pipeline:
|
|
7
|
+
* 1. Check for changes (skip if no changes and not new)
|
|
8
|
+
* 2. Emit `saving` event (for data enrichment)
|
|
9
|
+
* 3. Emit `validating` event
|
|
10
|
+
* 4. Validate and cast data via @warlock.js/seal schema
|
|
11
|
+
* 5. Emit `validated` event
|
|
12
|
+
* 6. Generate ID (for new NoSQL records)
|
|
13
|
+
* 7. Emit `creating`/`updating` events
|
|
14
|
+
* 8. Execute insert or update via driver
|
|
15
|
+
* 9. Merge returned data into model
|
|
16
|
+
* 10. Reset dirty tracker and update `isNew` flag
|
|
17
|
+
* 11. Emit `saved` and `created`/`updated` events
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const user = new User({ name: "Alice", email: "alice@example.com" });
|
|
22
|
+
* const writer = new DatabaseWriter(user);
|
|
23
|
+
* await writer.save();
|
|
24
|
+
*
|
|
25
|
+
* console.log(user.get("id")); // 1 (auto-generated)
|
|
26
|
+
* console.log(user.get("_id")); // ObjectId("...")
|
|
27
|
+
*
|
|
28
|
+
* // Update existing record
|
|
29
|
+
* user.set("name", "Alice Smith");
|
|
30
|
+
* await writer.save();
|
|
31
|
+
* // Only updates the "name" field (partial update)
|
|
32
|
+
*
|
|
33
|
+
* // Silent save (no events)
|
|
34
|
+
* await writer.save({ skipEvents: true });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class DatabaseWriter implements WriterContract {
|
|
38
|
+
/** The model instance being persisted */
|
|
39
|
+
private readonly model;
|
|
40
|
+
/** Model constructor reference */
|
|
41
|
+
private readonly ctor;
|
|
42
|
+
/** Data source containing driver and ID generator */
|
|
43
|
+
private readonly dataSource;
|
|
44
|
+
/** Database driver for executing queries */
|
|
45
|
+
private readonly driver;
|
|
46
|
+
/** Table/collection name */
|
|
47
|
+
private readonly table;
|
|
48
|
+
/** Primary key field name */
|
|
49
|
+
private readonly primaryKey;
|
|
50
|
+
/** Validation schema (if defined) */
|
|
51
|
+
private readonly schema?;
|
|
52
|
+
/** Strict mode configuration */
|
|
53
|
+
private readonly strictMode;
|
|
54
|
+
/**
|
|
55
|
+
* Create a new writer instance for a model.
|
|
56
|
+
*
|
|
57
|
+
* @param model - The model instance to persist
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const user = new User({ name: "Alice" });
|
|
62
|
+
* const writer = new DatabaseWriter(user);
|
|
63
|
+
* await writer.save();
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
constructor(model: Model);
|
|
67
|
+
/**
|
|
68
|
+
* Save the model instance to the database.
|
|
69
|
+
*
|
|
70
|
+
* @param options - Save options
|
|
71
|
+
* @returns Result with success status, document, and metadata
|
|
72
|
+
* @throws {ValidationError} If validation fails
|
|
73
|
+
*/
|
|
74
|
+
save(options?: WriterOptions): Promise<WriterResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Validate and cast model data using the schema.
|
|
77
|
+
*
|
|
78
|
+
* Updates the model's data in-place with validated/casted values.
|
|
79
|
+
*
|
|
80
|
+
* @param isInsert - Whether this is an insert operation
|
|
81
|
+
* @param options - Save options
|
|
82
|
+
* @throws {ValidationError} If validation fails
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
private validateAndCast;
|
|
86
|
+
/**
|
|
87
|
+
* Perform an insert operation.
|
|
88
|
+
*
|
|
89
|
+
* @param options - Save options
|
|
90
|
+
* @returns Insert result
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
93
|
+
private performInsert;
|
|
94
|
+
/**
|
|
95
|
+
* Perform an update operation.
|
|
96
|
+
*
|
|
97
|
+
* @param options - Save options
|
|
98
|
+
* @returns Update result
|
|
99
|
+
* @private
|
|
100
|
+
*/
|
|
101
|
+
private performUpdate;
|
|
102
|
+
/**
|
|
103
|
+
* Generate ID for the model if auto-generation is enabled.
|
|
104
|
+
*
|
|
105
|
+
* @private
|
|
106
|
+
*/
|
|
107
|
+
private generateIdIfNeeded;
|
|
108
|
+
/**
|
|
109
|
+
* Build update operations from the model's dirty tracker.
|
|
110
|
+
*
|
|
111
|
+
* Handles both modified fields ($set) and removed fields ($unset).
|
|
112
|
+
*
|
|
113
|
+
* @returns Update operations for the driver
|
|
114
|
+
* @private
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* // Model with changes
|
|
119
|
+
* user.set("name", "Alice");
|
|
120
|
+
* user.unset("tempField");
|
|
121
|
+
*
|
|
122
|
+
* const operations = this.buildUpdateOperations();
|
|
123
|
+
* // {
|
|
124
|
+
* // $set: { name: "Alice" },
|
|
125
|
+
* // $unset: { tempField: 1 }
|
|
126
|
+
* // }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
private buildUpdateOperations;
|
|
130
|
+
/**
|
|
131
|
+
* Resolve the initial ID from model configuration.
|
|
132
|
+
*
|
|
133
|
+
* Priority:
|
|
134
|
+
* 1. Model.initialId (explicit value)
|
|
135
|
+
* 2. Model.randomInitialId (random or function)
|
|
136
|
+
* 3. Default: 1
|
|
137
|
+
*
|
|
138
|
+
* @returns The initial ID value
|
|
139
|
+
* @private
|
|
140
|
+
*/
|
|
141
|
+
private resolveInitialId;
|
|
142
|
+
/**
|
|
143
|
+
* Resolve the increment value from model configuration.
|
|
144
|
+
*
|
|
145
|
+
* Priority:
|
|
146
|
+
* 1. Model.incrementIdBy (explicit value)
|
|
147
|
+
* 2. Model.randomIncrement (random or function)
|
|
148
|
+
* 3. Default: 1
|
|
149
|
+
*
|
|
150
|
+
* @returns The increment value
|
|
151
|
+
* @private
|
|
152
|
+
*/
|
|
153
|
+
private resolveIncrementBy;
|
|
154
|
+
/**
|
|
155
|
+
* Generate a random integer between min and max (inclusive).
|
|
156
|
+
*
|
|
157
|
+
* @param min - Minimum value
|
|
158
|
+
* @param max - Maximum value
|
|
159
|
+
* @returns Random integer
|
|
160
|
+
* @private
|
|
161
|
+
*/
|
|
162
|
+
private randomInt;
|
|
163
|
+
/**
|
|
164
|
+
* Trigger sync operations after successful save.
|
|
165
|
+
* Only syncs on updates (not creates) unless sync config specifies embedOnCreate.
|
|
166
|
+
*
|
|
167
|
+
* @param changedFields - Fields that were changed (for filtering)
|
|
168
|
+
* @private
|
|
169
|
+
*/
|
|
170
|
+
/**
|
|
171
|
+
* Trigger sync operations after successful save.
|
|
172
|
+
*
|
|
173
|
+
* Emits a model.updated event that ModelSyncOperation listens to.
|
|
174
|
+
* The sync is handled by registered sync operations, not directly here.
|
|
175
|
+
*
|
|
176
|
+
* @param changedFields - Fields that were changed (for filtering)
|
|
177
|
+
* @private
|
|
178
|
+
*/
|
|
179
|
+
private triggerSync;
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=database-writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-writer.d.ts","sourceRoot":"","sources":["../../src/writer/database-writer.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,YAAY,EACb,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAc,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAMxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,cAAe,YAAW,cAAc;IACnD,yCAAyC;IACzC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAE9B,kCAAkC;IAClC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAoB;IAEzC,qDAAqD;IACrD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IAExC,4CAA4C;IAC5C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IAExC,4BAA4B;IAC5B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAE/B,6BAA6B;IAC7B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IAEpC,qCAAqC;IACrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAkB;IAE1C,gCAAgC;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IAExC;;;;;;;;;;;OAWG;gBACgB,KAAK,EAAE,KAAK;IAW/B;;;;;;OAMG;IACU,IAAI,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IA0DrE;;;;;;;;;OASG;YACW,eAAe;IA8D7B;;;;;;OAMG;YACW,aAAa;IAsC3B;;;;;;OAMG;YACW,aAAa;IAoC3B;;;;OAIG;YACW,kBAAkB;IAwBhC;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,qBAAqB;IA4B7B;;;;;;;;;;OAUG;IACH,OAAO,CAAC,gBAAgB;IAcxB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,kBAAkB;IAc1B;;;;;;;OAOG;IACH,OAAO,CAAC,SAAS;IAIjB;;;;;;OAMG;IACH;;;;;;;;OAQG;YACW,WAAW;CAI1B"}
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
'use strict';var events=require('@mongez/events'),seal=require('@warlock.js/seal'),modelEvents=require('../sync/model-events.js'),databaseWriterValidationError=require('../validation/database-writer-validation-error.js');require('../validation/database-seal-plugins.js');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var events__default=/*#__PURE__*/_interopDefault(events);/**
|
|
2
|
+
* Database writer service that orchestrates model persistence.
|
|
3
|
+
*
|
|
4
|
+
* Handles the complete save pipeline:
|
|
5
|
+
* 1. Check for changes (skip if no changes and not new)
|
|
6
|
+
* 2. Emit `saving` event (for data enrichment)
|
|
7
|
+
* 3. Emit `validating` event
|
|
8
|
+
* 4. Validate and cast data via @warlock.js/seal schema
|
|
9
|
+
* 5. Emit `validated` event
|
|
10
|
+
* 6. Generate ID (for new NoSQL records)
|
|
11
|
+
* 7. Emit `creating`/`updating` events
|
|
12
|
+
* 8. Execute insert or update via driver
|
|
13
|
+
* 9. Merge returned data into model
|
|
14
|
+
* 10. Reset dirty tracker and update `isNew` flag
|
|
15
|
+
* 11. Emit `saved` and `created`/`updated` events
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const user = new User({ name: "Alice", email: "alice@example.com" });
|
|
20
|
+
* const writer = new DatabaseWriter(user);
|
|
21
|
+
* await writer.save();
|
|
22
|
+
*
|
|
23
|
+
* console.log(user.get("id")); // 1 (auto-generated)
|
|
24
|
+
* console.log(user.get("_id")); // ObjectId("...")
|
|
25
|
+
*
|
|
26
|
+
* // Update existing record
|
|
27
|
+
* user.set("name", "Alice Smith");
|
|
28
|
+
* await writer.save();
|
|
29
|
+
* // Only updates the "name" field (partial update)
|
|
30
|
+
*
|
|
31
|
+
* // Silent save (no events)
|
|
32
|
+
* await writer.save({ skipEvents: true });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
class DatabaseWriter {
|
|
36
|
+
/** The model instance being persisted */
|
|
37
|
+
model;
|
|
38
|
+
/** Model constructor reference */
|
|
39
|
+
ctor;
|
|
40
|
+
/** Data source containing driver and ID generator */
|
|
41
|
+
dataSource;
|
|
42
|
+
/** Database driver for executing queries */
|
|
43
|
+
driver;
|
|
44
|
+
/** Table/collection name */
|
|
45
|
+
table;
|
|
46
|
+
/** Primary key field name */
|
|
47
|
+
primaryKey;
|
|
48
|
+
/** Validation schema (if defined) */
|
|
49
|
+
schema;
|
|
50
|
+
/** Strict mode configuration */
|
|
51
|
+
strictMode;
|
|
52
|
+
/**
|
|
53
|
+
* Create a new writer instance for a model.
|
|
54
|
+
*
|
|
55
|
+
* @param model - The model instance to persist
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const user = new User({ name: "Alice" });
|
|
60
|
+
* const writer = new DatabaseWriter(user);
|
|
61
|
+
* await writer.save();
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
constructor(model) {
|
|
65
|
+
this.model = model;
|
|
66
|
+
this.ctor = model.constructor;
|
|
67
|
+
this.dataSource = this.ctor.getDataSource();
|
|
68
|
+
this.driver = this.dataSource.driver;
|
|
69
|
+
this.table = this.ctor.table;
|
|
70
|
+
this.primaryKey = this.ctor.primaryKey;
|
|
71
|
+
this.schema = this.ctor.schema;
|
|
72
|
+
this.strictMode = this.ctor.strictMode;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Save the model instance to the database.
|
|
76
|
+
*
|
|
77
|
+
* @param options - Save options
|
|
78
|
+
* @returns Result with success status, document, and metadata
|
|
79
|
+
* @throws {ValidationError} If validation fails
|
|
80
|
+
*/
|
|
81
|
+
async save(options = {}) {
|
|
82
|
+
const isInsert = this.model.isNew;
|
|
83
|
+
// 1. Check if model has changes (skip if no changes and not new)
|
|
84
|
+
if (!isInsert && !this.model.hasChanges()) {
|
|
85
|
+
return {
|
|
86
|
+
success: true,
|
|
87
|
+
document: this.model.data,
|
|
88
|
+
isNew: false,
|
|
89
|
+
modifiedCount: 0,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// 2. Emit saving event (before validation for data enrichment)
|
|
93
|
+
if (!options.skipEvents) {
|
|
94
|
+
await this.model.emitEvent("saving", {
|
|
95
|
+
isInsert,
|
|
96
|
+
options,
|
|
97
|
+
mode: isInsert ? "insert" : "update",
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// 3. Validate and cast data
|
|
101
|
+
await this.validateAndCast(isInsert, options);
|
|
102
|
+
// 4. Execute insert or update
|
|
103
|
+
let result;
|
|
104
|
+
if (isInsert) {
|
|
105
|
+
result = await this.performInsert(options);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
result = await this.performUpdate(options);
|
|
109
|
+
}
|
|
110
|
+
// 5. Reset dirty tracker and update isNew flag
|
|
111
|
+
const changedFields = isInsert ? [] : this.model.getDirtyColumns();
|
|
112
|
+
this.model.dirtyTracker.reset();
|
|
113
|
+
this.model.isNew = false;
|
|
114
|
+
// 6. Emit post-save events
|
|
115
|
+
if (!options.skipEvents) {
|
|
116
|
+
await this.model.emitEvent("saved");
|
|
117
|
+
await this.model.emitEvent(isInsert ? "created" : "updated");
|
|
118
|
+
}
|
|
119
|
+
// 7. Trigger sync operations (fire-and-forget, non-blocking)
|
|
120
|
+
if (!options.skipSync && !isInsert) {
|
|
121
|
+
void this.triggerSync(changedFields);
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
success: true,
|
|
125
|
+
document: this.model.data,
|
|
126
|
+
isNew: isInsert,
|
|
127
|
+
modifiedCount: isInsert ? undefined : result.modifiedCount,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Validate and cast model data using the schema.
|
|
132
|
+
*
|
|
133
|
+
* Updates the model's data in-place with validated/casted values.
|
|
134
|
+
*
|
|
135
|
+
* @param isInsert - Whether this is an insert operation
|
|
136
|
+
* @param options - Save options
|
|
137
|
+
* @throws {ValidationError} If validation fails
|
|
138
|
+
* @private
|
|
139
|
+
*/
|
|
140
|
+
async validateAndCast(isInsert, options) {
|
|
141
|
+
// Emit validating event
|
|
142
|
+
if (!options.skipEvents) {
|
|
143
|
+
await this.model.emitEvent("validating", {
|
|
144
|
+
isInsert,
|
|
145
|
+
options,
|
|
146
|
+
mode: isInsert ? "insert" : "update",
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
// Skip validation if requested or no schema defined
|
|
150
|
+
if (options.skipValidation || !this.schema) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
// Clone schema for partial data (updates only)
|
|
154
|
+
const validationSchema = isInsert
|
|
155
|
+
? this.schema.clone()
|
|
156
|
+
: this.schema.clone(Object.keys(this.model.data)).extend({
|
|
157
|
+
id: seal.v.int(),
|
|
158
|
+
_id: seal.v.any(),
|
|
159
|
+
createdAt: seal.v.date(),
|
|
160
|
+
updatedAt: seal.v.date(),
|
|
161
|
+
});
|
|
162
|
+
// Apply strict mode
|
|
163
|
+
if (this.strictMode === "strip") {
|
|
164
|
+
validationSchema.stripUnknown();
|
|
165
|
+
}
|
|
166
|
+
else if (this.strictMode === "fail") {
|
|
167
|
+
validationSchema.allowUnknown(false);
|
|
168
|
+
}
|
|
169
|
+
else if (this.strictMode === "allow") {
|
|
170
|
+
validationSchema.allowUnknown(true);
|
|
171
|
+
}
|
|
172
|
+
// Run validation
|
|
173
|
+
const result = await seal.v.validate(validationSchema, this.model.data, {
|
|
174
|
+
context: {
|
|
175
|
+
model: this.model,
|
|
176
|
+
},
|
|
177
|
+
...seal.getSealConfig(),
|
|
178
|
+
});
|
|
179
|
+
if (!result.isValid) {
|
|
180
|
+
const error = new databaseWriterValidationError.DatabaseWriterValidationError(`[${this.model.constructor.name} Model] ${isInsert ? "Insert" : "Update"} Validation failed`, result.errors);
|
|
181
|
+
if (!options.skipEvents) {
|
|
182
|
+
await this.model.emitEvent("validated", { result, error });
|
|
183
|
+
}
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
// Update model data with validated/casted data
|
|
187
|
+
this.model.replaceData(result.data);
|
|
188
|
+
// Emit validated event
|
|
189
|
+
if (!options.skipEvents) {
|
|
190
|
+
await this.model.emitEvent("validated", { result });
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Perform an insert operation.
|
|
195
|
+
*
|
|
196
|
+
* @param options - Save options
|
|
197
|
+
* @returns Insert result
|
|
198
|
+
* @private
|
|
199
|
+
*/
|
|
200
|
+
async performInsert(options) {
|
|
201
|
+
// Generate ID if needed (NoSQL only)
|
|
202
|
+
await this.generateIdIfNeeded();
|
|
203
|
+
// Get data to insert (already validated and casted)
|
|
204
|
+
const dataToInsert = this.model.data;
|
|
205
|
+
// add createdAt and updatedAt to the data
|
|
206
|
+
const createdAtColumn = this.ctor.createdAtColumn ?? "createdAt";
|
|
207
|
+
if (createdAtColumn) {
|
|
208
|
+
dataToInsert[createdAtColumn] = new Date();
|
|
209
|
+
}
|
|
210
|
+
const updatedAtColumn = this.ctor.updatedAtColumn ?? "updatedAt";
|
|
211
|
+
if (updatedAtColumn) {
|
|
212
|
+
dataToInsert[updatedAtColumn] = new Date();
|
|
213
|
+
}
|
|
214
|
+
// Emit creating event
|
|
215
|
+
if (!options.skipEvents) {
|
|
216
|
+
await this.model.emitEvent("creating");
|
|
217
|
+
}
|
|
218
|
+
// INSERT: use full validated data
|
|
219
|
+
const result = await this.driver.insert(this.table, dataToInsert);
|
|
220
|
+
// Merge returned data (e.g., generated _id, timestamps)
|
|
221
|
+
// Note: We use merge here because the result might not include all fields
|
|
222
|
+
// (e.g., our generated 'id' field), and we don't want to lose them
|
|
223
|
+
this.model.merge(result.document);
|
|
224
|
+
// Reset dirty tracker immediately after merge to prevent
|
|
225
|
+
// database-generated fields (like _id) from being marked as dirty
|
|
226
|
+
this.model.dirtyTracker.reset();
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Perform an update operation.
|
|
231
|
+
*
|
|
232
|
+
* @param options - Save options
|
|
233
|
+
* @returns Update result
|
|
234
|
+
* @private
|
|
235
|
+
*/
|
|
236
|
+
async performUpdate(options) {
|
|
237
|
+
// Emit updating event
|
|
238
|
+
if (!options.skipEvents) {
|
|
239
|
+
await this.model.emitEvent("updating");
|
|
240
|
+
}
|
|
241
|
+
if (this.ctor.updatedAtColumn !== false) {
|
|
242
|
+
this.model.set(this.ctor.updatedAtColumn ?? "updatedAt", new Date());
|
|
243
|
+
}
|
|
244
|
+
if (options.replace) {
|
|
245
|
+
const document = await this.driver.replace(this.table, {
|
|
246
|
+
[this.primaryKey]: this.model.get(this.primaryKey),
|
|
247
|
+
}, this.model.data);
|
|
248
|
+
if (document) {
|
|
249
|
+
this.model.replaceData(document);
|
|
250
|
+
}
|
|
251
|
+
return { modifiedCount: document ? 1 : 0 };
|
|
252
|
+
}
|
|
253
|
+
// Build operations from dirty tracker
|
|
254
|
+
const operations = this.buildUpdateOperations();
|
|
255
|
+
// Build filter using primary key
|
|
256
|
+
const filter = { [this.primaryKey]: this.model.get(this.primaryKey) };
|
|
257
|
+
// Execute update with operations
|
|
258
|
+
return await this.driver.update(this.table, filter, operations);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Generate ID for the model if auto-generation is enabled.
|
|
262
|
+
*
|
|
263
|
+
* @private
|
|
264
|
+
*/
|
|
265
|
+
async generateIdIfNeeded() {
|
|
266
|
+
if (!this.ctor.autoGenerateId || this.model.get("id")) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const idGenerator = this.dataSource.idGenerator;
|
|
270
|
+
if (!idGenerator) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
// Resolve ID generation options from model configuration
|
|
274
|
+
const initialId = this.resolveInitialId();
|
|
275
|
+
const incrementIdBy = this.resolveIncrementBy();
|
|
276
|
+
const id = await idGenerator.generateNextId({
|
|
277
|
+
table: this.table,
|
|
278
|
+
initialId,
|
|
279
|
+
incrementIdBy,
|
|
280
|
+
});
|
|
281
|
+
this.model.set("id", id);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Build update operations from the model's dirty tracker.
|
|
285
|
+
*
|
|
286
|
+
* Handles both modified fields ($set) and removed fields ($unset).
|
|
287
|
+
*
|
|
288
|
+
* @returns Update operations for the driver
|
|
289
|
+
* @private
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```typescript
|
|
293
|
+
* // Model with changes
|
|
294
|
+
* user.set("name", "Alice");
|
|
295
|
+
* user.unset("tempField");
|
|
296
|
+
*
|
|
297
|
+
* const operations = this.buildUpdateOperations();
|
|
298
|
+
* // {
|
|
299
|
+
* // $set: { name: "Alice" },
|
|
300
|
+
* // $unset: { tempField: 1 }
|
|
301
|
+
* // }
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
buildUpdateOperations() {
|
|
305
|
+
const operations = {};
|
|
306
|
+
// Get dirty columns (modified fields)
|
|
307
|
+
const dirtyColumns = this.model.getDirtyColumns();
|
|
308
|
+
if (dirtyColumns.length > 0) {
|
|
309
|
+
operations.$set = {};
|
|
310
|
+
for (const column of dirtyColumns) {
|
|
311
|
+
const value = this.model.get(column);
|
|
312
|
+
if (value === undefined)
|
|
313
|
+
continue;
|
|
314
|
+
operations.$set[column] = this.model.get(column);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
// Get removed columns
|
|
318
|
+
const removedColumns = this.model.getRemovedColumns();
|
|
319
|
+
if (removedColumns.length > 0) {
|
|
320
|
+
operations.$unset = {};
|
|
321
|
+
for (const column of removedColumns) {
|
|
322
|
+
operations.$unset[column] = 1;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return operations;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Resolve the initial ID from model configuration.
|
|
329
|
+
*
|
|
330
|
+
* Priority:
|
|
331
|
+
* 1. Model.initialId (explicit value)
|
|
332
|
+
* 2. Model.randomInitialId (random or function)
|
|
333
|
+
* 3. Default: 1
|
|
334
|
+
*
|
|
335
|
+
* @returns The initial ID value
|
|
336
|
+
* @private
|
|
337
|
+
*/
|
|
338
|
+
resolveInitialId() {
|
|
339
|
+
if (this.ctor.initialId) {
|
|
340
|
+
return this.ctor.initialId;
|
|
341
|
+
}
|
|
342
|
+
if (this.ctor.randomInitialId) {
|
|
343
|
+
return typeof this.ctor.randomInitialId === "function"
|
|
344
|
+
? this.ctor.randomInitialId()
|
|
345
|
+
: this.randomInt(10000, 499999);
|
|
346
|
+
}
|
|
347
|
+
return 1; // Default initial ID
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Resolve the increment value from model configuration.
|
|
351
|
+
*
|
|
352
|
+
* Priority:
|
|
353
|
+
* 1. Model.incrementIdBy (explicit value)
|
|
354
|
+
* 2. Model.randomIncrement (random or function)
|
|
355
|
+
* 3. Default: 1
|
|
356
|
+
*
|
|
357
|
+
* @returns The increment value
|
|
358
|
+
* @private
|
|
359
|
+
*/
|
|
360
|
+
resolveIncrementBy() {
|
|
361
|
+
if (this.ctor.incrementIdBy) {
|
|
362
|
+
return this.ctor.incrementIdBy;
|
|
363
|
+
}
|
|
364
|
+
if (this.ctor.randomIncrement) {
|
|
365
|
+
return typeof this.ctor.randomIncrement === "function"
|
|
366
|
+
? this.ctor.randomIncrement()
|
|
367
|
+
: this.randomInt(1, 10);
|
|
368
|
+
}
|
|
369
|
+
return 1; // Default increment
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Generate a random integer between min and max (inclusive).
|
|
373
|
+
*
|
|
374
|
+
* @param min - Minimum value
|
|
375
|
+
* @param max - Maximum value
|
|
376
|
+
* @returns Random integer
|
|
377
|
+
* @private
|
|
378
|
+
*/
|
|
379
|
+
randomInt(min, max) {
|
|
380
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Trigger sync operations after successful save.
|
|
384
|
+
* Only syncs on updates (not creates) unless sync config specifies embedOnCreate.
|
|
385
|
+
*
|
|
386
|
+
* @param changedFields - Fields that were changed (for filtering)
|
|
387
|
+
* @private
|
|
388
|
+
*/
|
|
389
|
+
/**
|
|
390
|
+
* Trigger sync operations after successful save.
|
|
391
|
+
*
|
|
392
|
+
* Emits a model.updated event that ModelSyncOperation listens to.
|
|
393
|
+
* The sync is handled by registered sync operations, not directly here.
|
|
394
|
+
*
|
|
395
|
+
* @param changedFields - Fields that were changed (for filtering)
|
|
396
|
+
* @private
|
|
397
|
+
*/
|
|
398
|
+
async triggerSync(changedFields) {
|
|
399
|
+
// Emit model.updated event - ModelSyncOperation listens to these
|
|
400
|
+
await events__default.default.triggerAll(modelEvents.getModelUpdatedEvent(this.ctor), this.model, changedFields);
|
|
401
|
+
}
|
|
402
|
+
}exports.DatabaseWriter=DatabaseWriter;//# sourceMappingURL=database-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-writer.js","sources":["../../src/writer/database-writer.ts"],"sourcesContent":[null],"names":["v","getSealConfig","DatabaseWriterValidationError","events","getModelUpdatedEvent"],"mappings":"yYAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCG;MACU,cAAc,CAAA;;AAER,IAAA,KAAK,CAAQ;;AAGb,IAAA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AAC,IAAI,CAAC,eAAe,KAAK,UAAU;AACpD,kBAAE,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;kBAC3B,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACnC,SAAA;QAED,OAAO,CAAC,CAAC;KACV;AAED;;;;;;;;;;AAUG;IACK,kBAAkB,GAAA;AACxB,QAAA,IAAI,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;AAC3B,YAAA,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC;AAChC,SAAA;AAED,QAAA,IAAI,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;AAC7B,YAAA,OAAO,OAAO,IAAI,CAAC,IAAI,CAAC,eAAe,KAAK,UAAU;AACpD,kBAAE,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;kBAC3B,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC3B,SAAA;QAED,OAAO,CAAC,CAAC;KACV;AAED;;;;;;;AAOG;IACK,SAAS,CAAC,GAAW,EAAE,GAAW,EAAA;AACxC,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;KAC1D;AAED;;;;;;AAMG;AACH;;;;;;;;AAQG;IACK,MAAM,WAAW,CAAC,aAAuB,EAAA;;AAE/C,QAAA,MAAMC,uBAAM,CAAC,UAAU,CAACC,gCAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;KACrF;AACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Context } from "@warlock.js/context";
|
|
2
|
+
import type { DataSource } from "../data-source/data-source";
|
|
3
|
+
type DataSourceContextValue = string | DataSource;
|
|
4
|
+
type DataSourceContextStore = {
|
|
5
|
+
dataSource?: DataSourceContextValue;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Database DataSource Context
|
|
9
|
+
*
|
|
10
|
+
* Manages the active database connection/data source using AsyncLocalStorage.
|
|
11
|
+
* Extends the base Context class for consistent API.
|
|
12
|
+
*/
|
|
13
|
+
declare class DatabaseDataSourceContext extends Context<DataSourceContextStore> {
|
|
14
|
+
/**
|
|
15
|
+
* Get the current data source
|
|
16
|
+
*/
|
|
17
|
+
getDataSource(): DataSourceContextValue | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Set the data source in context
|
|
20
|
+
*/
|
|
21
|
+
setDataSource(dataSource: DataSourceContextValue): void;
|
|
22
|
+
/**
|
|
23
|
+
* Build the initial data source store with defaults
|
|
24
|
+
*/
|
|
25
|
+
buildStore(): DataSourceContextStore;
|
|
26
|
+
}
|
|
27
|
+
export declare const databaseDataSourceContext: DatabaseDataSourceContext;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=database-data-source-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-data-source-context.d.ts","sourceRoot":"","sources":["../../src/context/database-data-source-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D,KAAK,sBAAsB,GAAG,MAAM,GAAG,UAAU,CAAC;AAElD,KAAK,sBAAsB,GAAG;IAC5B,UAAU,CAAC,EAAE,sBAAsB,CAAC;CACrC,CAAC;AAEF;;;;;GAKG;AACH,cAAM,yBAA0B,SAAQ,OAAO,CAAC,sBAAsB,CAAC;IACrE;;OAEG;IACI,aAAa,IAAI,sBAAsB,GAAG,SAAS;IAI1D;;OAEG;IACI,aAAa,CAAC,UAAU,EAAE,sBAAsB,GAAG,IAAI;IAI9D;;OAEG;IACI,UAAU,IAAI,sBAAsB;CAG5C;AAED,eAAO,MAAM,yBAAyB,2BAAkC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {contextManager,Context}from'@warlock.js/context';/**
|
|
2
|
+
* Database DataSource Context
|
|
3
|
+
*
|
|
4
|
+
* Manages the active database connection/data source using AsyncLocalStorage.
|
|
5
|
+
* Extends the base Context class for consistent API.
|
|
6
|
+
*/
|
|
7
|
+
class DatabaseDataSourceContext extends Context {
|
|
8
|
+
/**
|
|
9
|
+
* Get the current data source
|
|
10
|
+
*/
|
|
11
|
+
getDataSource() {
|
|
12
|
+
return this.get("dataSource");
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Set the data source in context
|
|
16
|
+
*/
|
|
17
|
+
setDataSource(dataSource) {
|
|
18
|
+
this.set("dataSource", dataSource);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build the initial data source store with defaults
|
|
22
|
+
*/
|
|
23
|
+
buildStore() {
|
|
24
|
+
return { dataSource: undefined };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const databaseDataSourceContext = new DatabaseDataSourceContext();
|
|
28
|
+
contextManager.register("db.datasource", databaseDataSourceContext);export{databaseDataSourceContext};//# sourceMappingURL=database-data-source-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-data-source-context.js","sources":["../../src/context/database-data-source-context.ts"],"sourcesContent":[null],"names":[],"mappings":"yDASA;;;;;AAKG;AACH,MAAM,yBAA0B,SAAQ,OAA+B,CAAA;AACrE;;AAEG;IACI,aAAa,GAAA;AAClB,QAAA,OAAO,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;KAC/B;AAED;;AAEG;AACI,IAAA,aAAa,CAAC,UAAkC,EAAA;AACrD,QAAA,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;KACpC;AAED;;AAEG;IACI,UAAU,GAAA;AACf,QAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;KAClC;AACF,CAAA;AAEY,MAAA,yBAAyB,GAAG,IAAI,yBAAyB,GAAG;AAEzE,cAAc,CAAC,QAAQ,CAAC,eAAe,EAAE,yBAAyB,CAAC"}
|