@warlock.js/cascade 5.31.0 → 5.32.0
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/CHANGELOG.md +11 -0
- package/cjs/index.cjs +104 -85
- package/cjs/index.cjs.map +1 -1
- package/esm/context/database-data-source-context.d.mts +2 -3
- package/esm/context/database-data-source-context.d.mts.map +1 -1
- package/esm/context/database-transaction-context.d.mts +2 -3
- package/esm/context/database-transaction-context.d.mts.map +1 -1
- package/esm/contracts/database-driver.contract.d.mts +56 -36
- package/esm/contracts/database-driver.contract.d.mts.map +1 -1
- package/esm/contracts/database-id-generator.contract.d.mts +7 -5
- package/esm/contracts/database-id-generator.contract.d.mts.map +1 -1
- package/esm/contracts/database-remover.contract.d.mts +3 -5
- package/esm/contracts/database-remover.contract.d.mts.map +1 -1
- package/esm/contracts/database-restorer.contract.d.mts +6 -6
- package/esm/contracts/database-restorer.contract.d.mts.map +1 -1
- package/esm/contracts/database-writer.contract.d.mts +4 -6
- package/esm/contracts/database-writer.contract.d.mts.map +1 -1
- package/esm/contracts/driver-blueprint.contract.d.mts +2 -3
- package/esm/contracts/driver-blueprint.contract.d.mts.map +1 -1
- package/esm/contracts/index.d.mts +2 -1
- package/esm/contracts/migration-driver.contract.d.mts +101 -53
- package/esm/contracts/migration-driver.contract.d.mts.map +1 -1
- package/esm/contracts/query-builder.contract.d.mts +51 -33
- package/esm/contracts/query-builder.contract.d.mts.map +1 -1
- package/esm/contracts/sync-adapter.contract.d.mts +25 -14
- package/esm/contracts/sync-adapter.contract.d.mts.map +1 -1
- package/esm/data-source/data-source-registry.d.mts +4 -5
- package/esm/data-source/data-source-registry.d.mts.map +1 -1
- package/esm/data-source/data-source.d.mts +8 -5
- package/esm/data-source/data-source.d.mts.map +1 -1
- package/esm/database-dirty-tracker.d.mts +2 -2
- package/esm/database-dirty-tracker.d.mts.map +1 -1
- package/esm/database-dirty-tracker.mjs +3 -2
- package/esm/database-dirty-tracker.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-driver.d.mts +3 -4
- package/esm/drivers/mongodb/mongodb-driver.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-id-generator.d.mts +2 -3
- package/esm/drivers/mongodb/mongodb-id-generator.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.d.mts +1 -3
- package/esm/drivers/mongodb/mongodb-migration-driver.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-builder.d.mts +2 -3
- package/esm/drivers/mongodb/mongodb-query-builder.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-builder.mjs +8 -5
- package/esm/drivers/mongodb/mongodb-query-builder.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-operations.d.mts +1 -3
- package/esm/drivers/mongodb/mongodb-query-operations.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-parser.d.mts +7 -6
- package/esm/drivers/mongodb/mongodb-query-parser.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-parser.mjs +2 -6
- package/esm/drivers/mongodb/mongodb-query-parser.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-sync-adapter.d.mts +1 -3
- package/esm/drivers/mongodb/mongodb-sync-adapter.d.mts.map +1 -1
- package/esm/drivers/mongodb/types.d.mts +11 -9
- package/esm/drivers/mongodb/types.d.mts.map +1 -1
- package/esm/drivers/postgres/index.d.mts +2 -1
- package/esm/drivers/postgres/index.mjs +1 -1
- package/esm/drivers/postgres/naming.mjs +1 -1
- package/esm/drivers/postgres/postgres-blueprint.d.mts +1 -3
- package/esm/drivers/postgres/postgres-blueprint.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-dialect.d.mts +4 -6
- package/esm/drivers/postgres/postgres-dialect.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-driver.d.mts +4 -5
- package/esm/drivers/postgres/postgres-driver.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-migration-driver.d.mts +1 -3
- package/esm/drivers/postgres/postgres-migration-driver.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-migration-driver.mjs +13 -10
- package/esm/drivers/postgres/postgres-migration-driver.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-query-builder.d.mts +4 -4
- package/esm/drivers/postgres/postgres-query-builder.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-query-builder.mjs +14 -10
- package/esm/drivers/postgres/postgres-query-builder.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-query-parser.d.mts +16 -11
- package/esm/drivers/postgres/postgres-query-parser.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-query-parser.mjs +1 -1
- package/esm/drivers/postgres/postgres-query-parser.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-sql-serializer.mjs +13 -10
- package/esm/drivers/postgres/postgres-sql-serializer.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-ttl-purge.mjs +1 -1
- package/esm/drivers/postgres/postgres-type-converters.mjs +2 -2
- package/esm/drivers/postgres/postgres-type-converters.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-update-validator.mjs +1 -1
- package/esm/drivers/postgres/postgres-update-validator.mjs.map +1 -1
- package/esm/drivers/postgres/types.d.mts +87 -45
- package/esm/drivers/postgres/types.d.mts.map +1 -1
- package/esm/drivers/sql/sql-dialect.contract.d.mts +1 -3
- package/esm/drivers/sql/sql-dialect.contract.d.mts.map +1 -1
- package/esm/drivers/sql/sql-types.d.mts +113 -59
- package/esm/drivers/sql/sql-types.d.mts.map +1 -1
- package/esm/errors/missing-data-source.error.d.mts +1 -2
- package/esm/errors/missing-data-source.error.d.mts.map +1 -1
- package/esm/errors/transaction-rollback.error.d.mts +1 -2
- package/esm/errors/transaction-rollback.error.d.mts.map +1 -1
- package/esm/errors/undefined-where-value.error.d.mts +1 -2
- package/esm/errors/undefined-where-value.error.d.mts.map +1 -1
- package/esm/errors/unsafe-filter.error.d.mts +1 -2
- package/esm/errors/unsafe-filter.error.d.mts.map +1 -1
- package/esm/errors/unsafe-raw-expression.error.d.mts +1 -2
- package/esm/errors/unsafe-raw-expression.error.d.mts.map +1 -1
- package/esm/errors/unsupported-lean-operation.error.d.mts +1 -2
- package/esm/errors/unsupported-lean-operation.error.d.mts.map +1 -1
- package/esm/errors/unsupported-lock-for-update.error.d.mts +1 -2
- package/esm/errors/unsupported-lock-for-update.error.d.mts.map +1 -1
- package/esm/errors/unsupported-query-operation.error.d.mts +1 -2
- package/esm/errors/unsupported-query-operation.error.d.mts.map +1 -1
- package/esm/errors/unsupported-update-operation.error.d.mts +1 -2
- package/esm/errors/unsupported-update-operation.error.d.mts.map +1 -1
- package/esm/events/model-events.d.mts +8 -6
- package/esm/events/model-events.d.mts.map +1 -1
- package/esm/expressions/aggregate-expressions.d.mts +7 -7
- package/esm/expressions/aggregate-expressions.d.mts.map +1 -1
- package/esm/expressions/column-expressions.d.mts +11 -11
- package/esm/expressions/column-expressions.d.mts.map +1 -1
- package/esm/index.d.mts +7 -2
- package/esm/index.mjs +1 -1
- package/esm/migration/column-builder.d.mts +2 -3
- package/esm/migration/column-builder.d.mts.map +1 -1
- package/esm/migration/column-helpers.d.mts +49 -50
- package/esm/migration/column-helpers.d.mts.map +1 -1
- package/esm/migration/column-helpers.mjs +1 -1
- package/esm/migration/foreign-key-builder.d.mts +2 -3
- package/esm/migration/foreign-key-builder.d.mts.map +1 -1
- package/esm/migration/index.d.mts +3 -2
- package/esm/migration/index.mjs +2 -2
- package/esm/migration/migration-runner.d.mts +7 -6
- package/esm/migration/migration-runner.d.mts.map +1 -1
- package/esm/migration/migration-runner.mjs +15 -11
- package/esm/migration/migration-runner.mjs.map +1 -1
- package/esm/migration/migration.d.mts +50 -32
- package/esm/migration/migration.d.mts.map +1 -1
- package/esm/migration/migration.mjs +1 -3
- package/esm/migration/migration.mjs.map +1 -1
- package/esm/migration/sql-serializer.d.mts +1 -3
- package/esm/migration/sql-serializer.d.mts.map +1 -1
- package/esm/migration/types.d.mts +7 -7
- package/esm/migration/types.d.mts.map +1 -1
- package/esm/model/methods/accessor-methods.mjs +1 -1
- package/esm/model/methods/accessor-methods.mjs.map +1 -1
- package/esm/model/methods/meta-methods.mjs +4 -2
- package/esm/model/methods/meta-methods.mjs.map +1 -1
- package/esm/model/methods/query-methods.mjs +1 -1
- package/esm/model/methods/write-methods.d.mts +3 -2
- package/esm/model/methods/write-methods.d.mts.map +1 -1
- package/esm/model/methods/write-methods.mjs +5 -2
- package/esm/model/methods/write-methods.mjs.map +1 -1
- package/esm/model/model.d.mts +9 -9
- package/esm/model/model.d.mts.map +1 -1
- package/esm/model/model.types.d.mts +7 -7
- package/esm/model/model.types.d.mts.map +1 -1
- package/esm/model/register-model.d.mts +13 -15
- package/esm/model/register-model.d.mts.map +1 -1
- package/esm/model/relation-decorators.d.mts +6 -8
- package/esm/model/relation-decorators.d.mts.map +1 -1
- package/esm/operations/database.d.mts +13 -8
- package/esm/operations/database.d.mts.map +1 -1
- package/esm/operations/index.d.mts +2 -1
- package/esm/operations/index.mjs +1 -1
- package/esm/operations/migrations.d.mts +18 -14
- package/esm/operations/migrations.d.mts.map +1 -1
- package/esm/query-builder/query-builder.d.mts +2 -4
- package/esm/query-builder/query-builder.d.mts.map +1 -1
- package/esm/query-builder/query-builder.mjs +12 -11
- package/esm/query-builder/query-builder.mjs.map +1 -1
- package/esm/relations/index.d.mts +2 -1
- package/esm/relations/index.mjs +1 -1
- package/esm/relations/key-conventions.mjs +2 -1
- package/esm/relations/key-conventions.mjs.map +1 -1
- package/esm/relations/pivot-operations.d.mts +3 -5
- package/esm/relations/pivot-operations.d.mts.map +1 -1
- package/esm/relations/relation-hydrator.d.mts +3 -5
- package/esm/relations/relation-hydrator.d.mts.map +1 -1
- package/esm/relations/relation-loader.d.mts +2 -4
- package/esm/relations/relation-loader.d.mts.map +1 -1
- package/esm/relations/relation-loader.mjs +4 -5
- package/esm/relations/relation-loader.mjs.map +1 -1
- package/esm/relations/types.d.mts +14 -15
- package/esm/relations/types.d.mts.map +1 -1
- package/esm/remover/database-remover.d.mts +1 -3
- package/esm/remover/database-remover.d.mts.map +1 -1
- package/esm/restorer/database-restorer.d.mts +1 -3
- package/esm/restorer/database-restorer.d.mts.map +1 -1
- package/esm/restorer/database-restorer.mjs +2 -1
- package/esm/restorer/database-restorer.mjs.map +1 -1
- package/esm/sql-database-dirty-tracker.d.mts +1 -3
- package/esm/sql-database-dirty-tracker.d.mts.map +1 -1
- package/esm/sync/model-events.mjs +1 -1
- package/esm/sync/model-sync-operation.d.mts +2 -4
- package/esm/sync/model-sync-operation.d.mts.map +1 -1
- package/esm/sync/model-sync.d.mts +3 -4
- package/esm/sync/model-sync.d.mts.map +1 -1
- package/esm/sync/sync-context.d.mts +2 -4
- package/esm/sync/sync-context.d.mts.map +1 -1
- package/esm/sync/sync-fanout.mjs +1 -1
- package/esm/sync/sync-manager.d.mts +2 -4
- package/esm/sync/sync-manager.d.mts.map +1 -1
- package/esm/sync/types.d.mts +121 -64
- package/esm/sync/types.d.mts.map +1 -1
- package/esm/transactions/after-commit.d.mts +2 -2
- package/esm/transactions/after-commit.d.mts.map +1 -1
- package/esm/types.d.mts +7 -8
- package/esm/types.d.mts.map +1 -1
- package/esm/utils/connect-to-database.d.mts +7 -8
- package/esm/utils/connect-to-database.d.mts.map +1 -1
- package/esm/utils/database-writer.utils.d.mts +3 -4
- package/esm/utils/database-writer.utils.d.mts.map +1 -1
- package/esm/utils/define-model.d.mts +3 -5
- package/esm/utils/define-model.d.mts.map +1 -1
- package/esm/utils/escape-regex.d.mts +3 -4
- package/esm/utils/escape-regex.d.mts.map +1 -1
- package/esm/utils/once-connected.d.mts +2 -4
- package/esm/utils/once-connected.d.mts.map +1 -1
- package/esm/utils/sanitize-filter.d.mts +3 -4
- package/esm/utils/sanitize-filter.d.mts.map +1 -1
- package/esm/validation/database-seal-plugins.d.mts +2 -1
- package/esm/validation/database-writer-validation-error.d.mts +1 -3
- package/esm/validation/database-writer-validation-error.d.mts.map +1 -1
- package/esm/validation/index.d.mts +3 -1
- package/esm/validation/index.mjs +1 -1
- package/esm/validation/plugins/database-rules-plugin.d.mts +2 -3
- package/esm/validation/plugins/database-rules-plugin.d.mts.map +1 -1
- package/esm/validation/plugins/embed-validator-plugin.d.mts +4 -3
- package/esm/validation/plugins/embed-validator-plugin.d.mts.map +1 -1
- package/esm/validation/types.d.mts +14 -10
- package/esm/validation/types.d.mts.map +1 -1
- package/esm/validation/validators/embed-validator.d.mts +2 -3
- package/esm/validation/validators/embed-validator.d.mts.map +1 -1
- package/esm/writer/database-writer.d.mts +1 -3
- package/esm/writer/database-writer.d.mts.map +1 -1
- package/esm/writer/database-writer.mjs +1 -1
- package/esm/writer/database-writer.mjs.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,17 @@ All notable changes to `@warlock.js/cascade` are documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). `@warlock.js/*` packages are released in lockstep — every package shares the same version number, so a version below may list only the changes that affected this package.
|
|
6
6
|
|
|
7
|
+
## 5.32.0 - 2026-10-18
|
|
8
|
+
|
|
9
|
+
### Security
|
|
10
|
+
|
|
11
|
+
- Upgrade esbuild to ^0.28.2, past the Windows development-server advisory [GHSA-g7r4-m6w7-qqqr](https://github.com/advisories/GHSA-g7r4-m6w7-qqqr) (patched in 0.28.1).
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Replace the unused classic TypeScript import-organizer development dependency with `@ianvs/prettier-plugin-sort-imports`, compatible with TypeScript 7.
|
|
16
|
+
- Pin the package development compiler to TypeScript 7.0.2 and use explicit Node types and source roots with supported module resolution.
|
|
17
|
+
|
|
7
18
|
## 5.31.0 - 2026-10-18
|
|
8
19
|
|
|
9
20
|
### Fixed
|
package/cjs/index.cjs
CHANGED
|
@@ -20,7 +20,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
20
20
|
}
|
|
21
21
|
return to;
|
|
22
22
|
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
24
24
|
value: mod,
|
|
25
25
|
enumerable: true
|
|
26
26
|
}) : target, mod));
|
|
@@ -1148,13 +1148,14 @@ var DatabaseDirtyTracker = class {
|
|
|
1148
1148
|
updateDirtyState() {
|
|
1149
1149
|
this.dirtyColumns.clear();
|
|
1150
1150
|
this.removedColumns.clear();
|
|
1151
|
-
const keys = new Set([...Object.keys(this.initialFlattened), ...Object.keys(this.currentFlattened)]);
|
|
1151
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(this.initialFlattened), ...Object.keys(this.currentFlattened)]);
|
|
1152
1152
|
for (const key of keys) {
|
|
1153
1153
|
const hasCurrent = this.currentFlattened[key] !== void 0 || key in this.currentFlattened;
|
|
1154
1154
|
const hasInitial = this.initialFlattened[key] !== void 0 || key in this.initialFlattened;
|
|
1155
1155
|
if (!hasCurrent && hasInitial) this.removedColumns.add(key);
|
|
1156
1156
|
const initialValue = this.initialFlattened[key];
|
|
1157
|
-
|
|
1157
|
+
const currentValue = hasCurrent ? this.currentFlattened[key] : void 0;
|
|
1158
|
+
if (!(0, _mongez_reinforcements.areEqual)(initialValue, currentValue)) this.dirtyColumns.add(key);
|
|
1158
1159
|
}
|
|
1159
1160
|
}
|
|
1160
1161
|
/**
|
|
@@ -1540,7 +1541,8 @@ const DEFAULT_PIVOT_ORDER = "alphabetical";
|
|
|
1540
1541
|
* snake("organizationId") // "organization_id"
|
|
1541
1542
|
*/
|
|
1542
1543
|
function snake(input) {
|
|
1543
|
-
|
|
1544
|
+
const normalised = input.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").replace(/([a-z\d])([A-Z])/g, "$1_$2");
|
|
1545
|
+
return (0, _mongez_reinforcements.toSnakeCase)(normalised).toLowerCase();
|
|
1544
1546
|
}
|
|
1545
1547
|
/**
|
|
1546
1548
|
* Build a key column name from a model/relation name, honouring the data
|
|
@@ -2175,9 +2177,7 @@ var RelationLoader = class RelationLoader {
|
|
|
2175
2177
|
case "belongsTo":
|
|
2176
2178
|
await this.loadBelongsTo(rootRelation, definition, constraint);
|
|
2177
2179
|
break;
|
|
2178
|
-
case "belongsToMany":
|
|
2179
|
-
await this.loadBelongsToMany(rootRelation, definition, constraint);
|
|
2180
|
-
break;
|
|
2180
|
+
case "belongsToMany": await this.loadBelongsToMany(rootRelation, definition, constraint);
|
|
2181
2181
|
}
|
|
2182
2182
|
if (children.length > 0) await this.loadNestedRelations(rootRelation, children, childConstraints);
|
|
2183
2183
|
}
|
|
@@ -2331,7 +2331,8 @@ var RelationLoader = class RelationLoader {
|
|
|
2331
2331
|
if (relatedModels.length === 0) return;
|
|
2332
2332
|
const parentDefinition = this.getRelationDefinition(parentRelation);
|
|
2333
2333
|
if (!parentDefinition) return;
|
|
2334
|
-
|
|
2334
|
+
const RelatedModelClass = this.resolveModelClass(parentDefinition.model);
|
|
2335
|
+
await new RelationLoader(relatedModels, RelatedModelClass).load(remainingPaths, constraints);
|
|
2335
2336
|
}
|
|
2336
2337
|
/**
|
|
2337
2338
|
* Parses a dot-notation relation path into segments.
|
|
@@ -2367,7 +2368,7 @@ var RelationLoader = class RelationLoader {
|
|
|
2367
2368
|
*/
|
|
2368
2369
|
applySelect(query, definition, requiredKeys) {
|
|
2369
2370
|
if (!definition.select || definition.select.length === 0) return;
|
|
2370
|
-
query.select([
|
|
2371
|
+
query.select([.../* @__PURE__ */ new Set([...definition.select, ...requiredKeys])]);
|
|
2371
2372
|
}
|
|
2372
2373
|
/**
|
|
2373
2374
|
* Gets the relation definition from the model class.
|
|
@@ -3598,7 +3599,7 @@ function unsetFields(model, ...fields) {
|
|
|
3598
3599
|
*/
|
|
3599
3600
|
function stripIdentityColumns(model, values) {
|
|
3600
3601
|
if (model.isNew) return values;
|
|
3601
|
-
const identityColumns = new Set([
|
|
3602
|
+
const identityColumns = /* @__PURE__ */ new Set([
|
|
3602
3603
|
model.getPrimaryKey(),
|
|
3603
3604
|
"id",
|
|
3604
3605
|
"_id"
|
|
@@ -4894,7 +4895,7 @@ var DatabaseWriter = class {
|
|
|
4894
4895
|
*/
|
|
4895
4896
|
buildUpdateOperations() {
|
|
4896
4897
|
const operations = {};
|
|
4897
|
-
const identityColumns = new Set([
|
|
4898
|
+
const identityColumns = /* @__PURE__ */ new Set([
|
|
4898
4899
|
this.primaryKey,
|
|
4899
4900
|
"id",
|
|
4900
4901
|
"_id"
|
|
@@ -4970,8 +4971,10 @@ function applyDefaultsToModel(ModelClass, defaults) {
|
|
|
4970
4971
|
if (defaults.updatedAtColumn !== void 0 && !isExplicitStatic(ModelClass, "updatedAtColumn")) ModelClass.updatedAtColumn = defaults.updatedAtColumn;
|
|
4971
4972
|
if (defaults.deleteStrategy !== void 0 && !isExplicitStatic(ModelClass, "deleteStrategy")) ModelClass.deleteStrategy = defaults.deleteStrategy;
|
|
4972
4973
|
if (defaults.deletedAtColumn !== void 0 && !isExplicitStatic(ModelClass, "deletedAtColumn")) ModelClass.deletedAtColumn = defaults.deletedAtColumn;
|
|
4973
|
-
if (defaults.trashTable !== void 0 && !isExplicitStatic(ModelClass, "trashTable"))
|
|
4974
|
-
|
|
4974
|
+
if (defaults.trashTable !== void 0 && !isExplicitStatic(ModelClass, "trashTable")) {
|
|
4975
|
+
if (typeof defaults.trashTable === "function") ModelClass.trashTable = defaults.trashTable(ModelClass.table);
|
|
4976
|
+
else ModelClass.trashTable = defaults.trashTable;
|
|
4977
|
+
}
|
|
4975
4978
|
if (defaults.strictMode !== void 0 && !isExplicitStatic(ModelClass, "strictMode")) ModelClass.strictMode = defaults.strictMode;
|
|
4976
4979
|
}
|
|
4977
4980
|
async function generateModelNextId(model) {
|
|
@@ -5882,7 +5885,8 @@ var DatabaseRestorer = class {
|
|
|
5882
5885
|
}
|
|
5883
5886
|
delete newData._id;
|
|
5884
5887
|
delete newData.id;
|
|
5885
|
-
|
|
5888
|
+
const model = new this.ctor(newData);
|
|
5889
|
+
return await new DatabaseWriter(model).prepareForInsert({
|
|
5886
5890
|
skipEvents: true,
|
|
5887
5891
|
skipValidation: true
|
|
5888
5892
|
});
|
|
@@ -6117,7 +6121,10 @@ async function createManyBulk(ModelClass, chunks) {
|
|
|
6117
6121
|
const results = await driver.insertMany(table, preparedDocuments);
|
|
6118
6122
|
models.forEach((model, index) => {
|
|
6119
6123
|
const result = results[index];
|
|
6120
|
-
if (result)
|
|
6124
|
+
if (result) {
|
|
6125
|
+
const returnedDocument = "document" in result ? result.document : result;
|
|
6126
|
+
mergeDriverFields(model, returnedDocument);
|
|
6127
|
+
}
|
|
6121
6128
|
model.dirtyTracker.reset();
|
|
6122
6129
|
model.isNew = false;
|
|
6123
6130
|
});
|
|
@@ -6150,7 +6157,7 @@ async function upsertRecord(ModelClass, filter, data, options) {
|
|
|
6150
6157
|
const setData = { ...tempModel.data };
|
|
6151
6158
|
const setOnInsert = {};
|
|
6152
6159
|
const now = /* @__PURE__ */ new Date();
|
|
6153
|
-
for (const key of new Set([
|
|
6160
|
+
for (const key of /* @__PURE__ */ new Set([
|
|
6154
6161
|
"id",
|
|
6155
6162
|
"_id",
|
|
6156
6163
|
ModelClass.primaryKey
|
|
@@ -10637,17 +10644,18 @@ var QueryBuilder = class QueryBuilder {
|
|
|
10637
10644
|
having(...args) {
|
|
10638
10645
|
if (args.length === 1) {
|
|
10639
10646
|
const input = args[0];
|
|
10640
|
-
if (Array.isArray(input))
|
|
10641
|
-
|
|
10642
|
-
|
|
10643
|
-
|
|
10644
|
-
|
|
10645
|
-
|
|
10646
|
-
|
|
10647
|
-
|
|
10648
|
-
|
|
10649
|
-
|
|
10650
|
-
|
|
10647
|
+
if (Array.isArray(input)) {
|
|
10648
|
+
if (input.length === 2) this.addOperation("having", {
|
|
10649
|
+
field: input[0],
|
|
10650
|
+
operator: "=",
|
|
10651
|
+
value: input[1]
|
|
10652
|
+
});
|
|
10653
|
+
else this.addOperation("having", {
|
|
10654
|
+
field: input[0],
|
|
10655
|
+
operator: input[1],
|
|
10656
|
+
value: input[2]
|
|
10657
|
+
});
|
|
10658
|
+
} else for (const [key, value] of Object.entries(input)) this.addOperation("having", {
|
|
10651
10659
|
field: key,
|
|
10652
10660
|
operator: "=",
|
|
10653
10661
|
value
|
|
@@ -12125,10 +12133,7 @@ var MongoQueryParser = class {
|
|
|
12125
12133
|
case "selectConcat":
|
|
12126
12134
|
projection[op.data.alias] = this.buildConcatExpression(op.data.fields);
|
|
12127
12135
|
break;
|
|
12128
|
-
case "selectCoalesce":
|
|
12129
|
-
projection[op.data.alias] = this.buildCoalesceExpression(op.data.fields);
|
|
12130
|
-
break;
|
|
12131
|
-
default: break;
|
|
12136
|
+
case "selectCoalesce": projection[op.data.alias] = this.buildCoalesceExpression(op.data.fields);
|
|
12132
12137
|
}
|
|
12133
12138
|
for (const callback of driverCallbacks) callback(projection);
|
|
12134
12139
|
return Object.keys(projection).length > 0 ? { $project: projection } : null;
|
|
@@ -12186,7 +12191,6 @@ var MongoQueryParser = class {
|
|
|
12186
12191
|
if (stage) return stage;
|
|
12187
12192
|
break;
|
|
12188
12193
|
}
|
|
12189
|
-
default: break;
|
|
12190
12194
|
}
|
|
12191
12195
|
return null;
|
|
12192
12196
|
}
|
|
@@ -13150,9 +13154,10 @@ var MongoQueryBuilder = class MongoQueryBuilder extends QueryBuilder {
|
|
|
13150
13154
|
* @param args - The arguments passed to where/orWhere
|
|
13151
13155
|
*/
|
|
13152
13156
|
addWhereClause(prefix, args) {
|
|
13153
|
-
if (args.length === 1)
|
|
13154
|
-
|
|
13155
|
-
|
|
13157
|
+
if (args.length === 1) {
|
|
13158
|
+
if (typeof args[0] === "function") this.operationsHelper.addMatchOperation(`${prefix}:callback`, args[0]);
|
|
13159
|
+
else this.operationsHelper.addMatchOperation(`${prefix}:object`, sanitizeFilter(args[0]));
|
|
13160
|
+
} else if (args.length === 2) this.operationsHelper.addMatchOperation(prefix, {
|
|
13156
13161
|
field: args[0],
|
|
13157
13162
|
operator: "=",
|
|
13158
13163
|
value: sanitizeFilterValue(args[1], String(args[0]))
|
|
@@ -13787,7 +13792,8 @@ var MongoQueryBuilder = class MongoQueryBuilder extends QueryBuilder {
|
|
|
13787
13792
|
if (this.fetchingCallback) await this.fetchingCallback(this);
|
|
13788
13793
|
if (this.isLean) {
|
|
13789
13794
|
assertLeanCompatible(this);
|
|
13790
|
-
|
|
13795
|
+
const leanRecords = await this.execute();
|
|
13796
|
+
return stripHiddenFromLeanRecords(leanRecords, this.modelClass);
|
|
13791
13797
|
}
|
|
13792
13798
|
const rawRecords = await this.execute();
|
|
13793
13799
|
if (this.hydratingCallback) await this.hydratingCallback(rawRecords, {
|
|
@@ -13977,7 +13983,8 @@ var MongoQueryBuilder = class MongoQueryBuilder extends QueryBuilder {
|
|
|
13977
13983
|
*/
|
|
13978
13984
|
async increment(field, amount = 1) {
|
|
13979
13985
|
const filter = this.buildFilter();
|
|
13980
|
-
|
|
13986
|
+
const result = await this.dataSource.driver.findOneAndUpdate(this.table, filter, { $inc: { [field]: amount } }, { returnDocument: "after" });
|
|
13987
|
+
return (0, _mongez_reinforcements.get)(result, field, 0);
|
|
13981
13988
|
}
|
|
13982
13989
|
/**
|
|
13983
13990
|
* Decrements a numeric field by the specified amount.
|
|
@@ -15771,7 +15778,7 @@ const toFiniteNumber = (value) => {
|
|
|
15771
15778
|
return Number.isFinite(n) ? n : value;
|
|
15772
15779
|
};
|
|
15773
15780
|
/** OID → converter. json/jsonb are already parsed by pg, so they are absent. */
|
|
15774
|
-
const CONVERTERS = new Map([
|
|
15781
|
+
const CONVERTERS = /* @__PURE__ */ new Map([
|
|
15775
15782
|
[20, toSafeInteger],
|
|
15776
15783
|
[1700, toFiniteNumber],
|
|
15777
15784
|
[1082, toDate],
|
|
@@ -15779,7 +15786,7 @@ const CONVERTERS = new Map([
|
|
|
15779
15786
|
[1184, toDate]
|
|
15780
15787
|
]);
|
|
15781
15788
|
/** Built-in OIDs whose text must never be reinterpreted (text, varchar, bpchar, name, json, jsonb, uuid). */
|
|
15782
|
-
const LITERAL_TEXT_OIDS = new Set([
|
|
15789
|
+
const LITERAL_TEXT_OIDS = /* @__PURE__ */ new Set([
|
|
15783
15790
|
18,
|
|
15784
15791
|
19,
|
|
15785
15792
|
25,
|
|
@@ -16100,9 +16107,10 @@ var PostgresMigrationDriver = class {
|
|
|
16100
16107
|
const quotedTable = this.driver.dialect.quoteIdentifier(table);
|
|
16101
16108
|
const quotedColumn = this.driver.dialect.quoteIdentifier(column.name);
|
|
16102
16109
|
let sqlType;
|
|
16103
|
-
if (column.autoIncrement)
|
|
16104
|
-
|
|
16105
|
-
|
|
16110
|
+
if (column.autoIncrement) {
|
|
16111
|
+
if (column.type === "bigInteger") sqlType = "BIGSERIAL";
|
|
16112
|
+
else sqlType = "SERIAL";
|
|
16113
|
+
} else sqlType = this.driver.dialect.getSqlType(column.type, {
|
|
16106
16114
|
length: column.length,
|
|
16107
16115
|
precision: column.precision,
|
|
16108
16116
|
scale: column.scale,
|
|
@@ -16114,13 +16122,15 @@ var PostgresMigrationDriver = class {
|
|
|
16114
16122
|
if (column.generated.stored) sql += " STORED";
|
|
16115
16123
|
} else {
|
|
16116
16124
|
if (!column.autoIncrement && column.nullable === false) sql += " NOT NULL";
|
|
16117
|
-
if (column.defaultValue !== void 0)
|
|
16118
|
-
|
|
16119
|
-
|
|
16120
|
-
|
|
16121
|
-
|
|
16122
|
-
|
|
16123
|
-
|
|
16125
|
+
if (column.defaultValue !== void 0) {
|
|
16126
|
+
if (typeof column.defaultValue === "object" && column.defaultValue !== null && column.defaultValue.__type === "CURRENT_TIMESTAMP") sql += " DEFAULT NOW()";
|
|
16127
|
+
else if (column.isRawDefault === false) {
|
|
16128
|
+
const escaped = String(column.defaultValue).replace(/'/g, "''");
|
|
16129
|
+
sql += ` DEFAULT '${escaped}'`;
|
|
16130
|
+
} else if (typeof column.defaultValue === "boolean") sql += ` DEFAULT ${column.defaultValue ? "TRUE" : "FALSE"}`;
|
|
16131
|
+
else if (typeof column.defaultValue === "number") sql += ` DEFAULT ${column.defaultValue}`;
|
|
16132
|
+
else sql += ` DEFAULT ${column.defaultValue}`;
|
|
16133
|
+
}
|
|
16124
16134
|
if (column.primary) sql += " PRIMARY KEY";
|
|
16125
16135
|
if (column.unique) sql += " UNIQUE";
|
|
16126
16136
|
}
|
|
@@ -16803,7 +16813,7 @@ var PostgresQueryParser = class PostgresQueryParser {
|
|
|
16803
16813
|
* @returns DriverQuery with `query` (SQL string) and `bindings` (parameter values)
|
|
16804
16814
|
*/
|
|
16805
16815
|
parse() {
|
|
16806
|
-
const JOIN_TYPES = new Set([
|
|
16816
|
+
const JOIN_TYPES = /* @__PURE__ */ new Set([
|
|
16807
16817
|
"join",
|
|
16808
16818
|
"leftJoin",
|
|
16809
16819
|
"rightJoin",
|
|
@@ -17928,7 +17938,7 @@ var PostgresQueryBuilder = class PostgresQueryBuilder extends QueryBuilder {
|
|
|
17928
17938
|
if (timing === "before") beforeOps.push(...temp.operations);
|
|
17929
17939
|
else afterOps.push(...temp.operations);
|
|
17930
17940
|
}
|
|
17931
|
-
const HAS_OP_TYPES = new Set([
|
|
17941
|
+
const HAS_OP_TYPES = /* @__PURE__ */ new Set([
|
|
17932
17942
|
"has",
|
|
17933
17943
|
"whereHas",
|
|
17934
17944
|
"orWhereHas",
|
|
@@ -18081,8 +18091,10 @@ var PostgresQueryBuilder = class PostgresQueryBuilder extends QueryBuilder {
|
|
|
18081
18091
|
if (!def) throw new Error(`Relation "${segName}" not found on model ${currentModel?.name ?? "unknown"}`);
|
|
18082
18092
|
let selectColumns = segColumns ?? def.select;
|
|
18083
18093
|
let constraintOps;
|
|
18084
|
-
if (i === segments.length - 1 && constraint !== void 0)
|
|
18085
|
-
|
|
18094
|
+
if (i === segments.length - 1 && constraint !== void 0) {
|
|
18095
|
+
if (typeof constraint === "string") selectColumns = constraint.split(",").filter(Boolean);
|
|
18096
|
+
else constraintOps = this._resolveConstraintOps(constraint);
|
|
18097
|
+
}
|
|
18086
18098
|
const alias = currentPath.replace(/\./g, "_");
|
|
18087
18099
|
this.joinRelations.set(currentPath, {
|
|
18088
18100
|
alias,
|
|
@@ -18590,7 +18602,7 @@ var PostgresQueryBuilder = class PostgresQueryBuilder extends QueryBuilder {
|
|
|
18590
18602
|
*/
|
|
18591
18603
|
applyHasRelations() {
|
|
18592
18604
|
if (this.hasRelationsApplied) return;
|
|
18593
|
-
const HAS_OP_TYPES = new Set([
|
|
18605
|
+
const HAS_OP_TYPES = /* @__PURE__ */ new Set([
|
|
18594
18606
|
"has",
|
|
18595
18607
|
"whereHas",
|
|
18596
18608
|
"orWhereHas",
|
|
@@ -18914,12 +18926,14 @@ var PostgresQueryBuilder = class PostgresQueryBuilder extends QueryBuilder {
|
|
|
18914
18926
|
const RelatedModel = resolveModelClass(config.model);
|
|
18915
18927
|
if (!RelatedModel) continue;
|
|
18916
18928
|
const childKeys = Array.from(this.joinRelations.keys()).filter((p) => p.startsWith(`${path}.`)).map((p) => p.split(".")[path.split(".").length]).filter((segment) => segment !== void 0);
|
|
18917
|
-
if (config.type === "hasMany")
|
|
18918
|
-
const
|
|
18919
|
-
|
|
18920
|
-
|
|
18921
|
-
|
|
18922
|
-
|
|
18929
|
+
if (config.type === "hasMany") {
|
|
18930
|
+
const instances = (Array.isArray(data) ? data : []).map((row) => {
|
|
18931
|
+
const rowData = { ...row };
|
|
18932
|
+
for (const childKey of childKeys) delete rowData[childKey];
|
|
18933
|
+
return RelatedModel.hydrate(rowData);
|
|
18934
|
+
});
|
|
18935
|
+
attachLoadedRelation(model, key, instances);
|
|
18936
|
+
} else {
|
|
18923
18937
|
const modelData = { ...data };
|
|
18924
18938
|
for (const childKey of childKeys) delete modelData[childKey];
|
|
18925
18939
|
const relatedInstance = RelatedModel.hydrate(modelData);
|
|
@@ -19079,9 +19093,10 @@ var PostgresSQLSerializer = class extends SQLSerializer {
|
|
|
19079
19093
|
const quotedTable = this.dialect.quoteIdentifier(table);
|
|
19080
19094
|
const quotedColumn = this.dialect.quoteIdentifier(column.name);
|
|
19081
19095
|
let sqlType;
|
|
19082
|
-
if (column.autoIncrement)
|
|
19083
|
-
|
|
19084
|
-
|
|
19096
|
+
if (column.autoIncrement) {
|
|
19097
|
+
if (column.type === "bigInteger") sqlType = "BIGSERIAL";
|
|
19098
|
+
else sqlType = "SERIAL";
|
|
19099
|
+
} else sqlType = this.dialect.getSqlType(column.type, {
|
|
19085
19100
|
length: column.length,
|
|
19086
19101
|
precision: column.precision,
|
|
19087
19102
|
scale: column.scale,
|
|
@@ -19093,13 +19108,15 @@ var PostgresSQLSerializer = class extends SQLSerializer {
|
|
|
19093
19108
|
if (column.generated.stored) sql += " STORED";
|
|
19094
19109
|
} else {
|
|
19095
19110
|
if (!column.autoIncrement && column.nullable === false) sql += " NOT NULL";
|
|
19096
|
-
if (column.defaultValue !== void 0)
|
|
19097
|
-
|
|
19098
|
-
|
|
19099
|
-
|
|
19100
|
-
|
|
19101
|
-
|
|
19102
|
-
|
|
19111
|
+
if (column.defaultValue !== void 0) {
|
|
19112
|
+
if (typeof column.defaultValue === "object" && column.defaultValue !== null && column.defaultValue.__type === "CURRENT_TIMESTAMP") sql += " DEFAULT NOW()";
|
|
19113
|
+
else if (column.isRawDefault === false) {
|
|
19114
|
+
const escaped = String(column.defaultValue).replace(/'/g, "''");
|
|
19115
|
+
sql += ` DEFAULT '${escaped}'`;
|
|
19116
|
+
} else if (typeof column.defaultValue === "boolean") sql += ` DEFAULT ${column.defaultValue ? "TRUE" : "FALSE"}`;
|
|
19117
|
+
else if (typeof column.defaultValue === "number") sql += ` DEFAULT ${column.defaultValue}`;
|
|
19118
|
+
else sql += ` DEFAULT ${column.defaultValue}`;
|
|
19119
|
+
}
|
|
19103
19120
|
if (column.primary) sql += " PRIMARY KEY";
|
|
19104
19121
|
if (column.unique) sql += " UNIQUE";
|
|
19105
19122
|
}
|
|
@@ -19257,7 +19274,7 @@ var PostgresSQLSerializer = class extends SQLSerializer {
|
|
|
19257
19274
|
* `$setOnInsert` only contributes to the INSERT half of an upsert; on a plain
|
|
19258
19275
|
* update it is a no-op, exactly as in MongoDB.
|
|
19259
19276
|
*/
|
|
19260
|
-
const SUPPORTED_OPERATORS = new Set([
|
|
19277
|
+
const SUPPORTED_OPERATORS = /* @__PURE__ */ new Set([
|
|
19261
19278
|
"$set",
|
|
19262
19279
|
"$unset",
|
|
19263
19280
|
"$inc",
|
|
@@ -22590,9 +22607,7 @@ var Migration = class {
|
|
|
22590
22607
|
case "setSchemaValidation":
|
|
22591
22608
|
await this.driver.setSchemaValidation(this.table, op.payload);
|
|
22592
22609
|
break;
|
|
22593
|
-
case "removeSchemaValidation":
|
|
22594
|
-
await this.driver.removeSchemaValidation(this.table);
|
|
22595
|
-
break;
|
|
22610
|
+
case "removeSchemaValidation": await this.driver.removeSchemaValidation(this.table);
|
|
22596
22611
|
}
|
|
22597
22612
|
}
|
|
22598
22613
|
/**
|
|
@@ -24634,8 +24649,8 @@ var SQLGrammar = class {
|
|
|
24634
24649
|
/** Name of the lock document Mongo migrations claim inside the migrations collection. */
|
|
24635
24650
|
const MIGRATION_LOCK_NAME = "__warlock_migration_lock__";
|
|
24636
24651
|
const MIGRATION_LOCK_KEY = "warlock:migrations";
|
|
24637
|
-
const MIGRATION_LOCK_TTL_MS =
|
|
24638
|
-
const MIGRATION_LOCK_WAIT_MS =
|
|
24652
|
+
const MIGRATION_LOCK_TTL_MS = 6e5;
|
|
24653
|
+
const MIGRATION_LOCK_WAIT_MS = 6e4;
|
|
24639
24654
|
const MIGRATION_LOCK_RETRY_MS = 1e3;
|
|
24640
24655
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
24641
24656
|
/**
|
|
@@ -24742,7 +24757,7 @@ var MigrationRunner = class {
|
|
|
24742
24757
|
}
|
|
24743
24758
|
/** Distinct data sources across the registered migrations (runner's own included). */
|
|
24744
24759
|
getSources() {
|
|
24745
|
-
const sources = new Set([this.getDataSource()]);
|
|
24760
|
+
const sources = /* @__PURE__ */ new Set([this.getDataSource()]);
|
|
24746
24761
|
for (const MigrationClass of this.migrations) sources.add(this.sourceOf(MigrationClass));
|
|
24747
24762
|
return [...sources];
|
|
24748
24763
|
}
|
|
@@ -25312,17 +25327,21 @@ var MigrationRunner = class {
|
|
|
25312
25327
|
};
|
|
25313
25328
|
if (shouldUseTransaction && databaseDriver.transaction) await databaseDriver.transaction(async () => {
|
|
25314
25329
|
await applyMigration();
|
|
25315
|
-
if (record)
|
|
25316
|
-
|
|
25317
|
-
|
|
25318
|
-
|
|
25330
|
+
if (record) {
|
|
25331
|
+
if (direction === "up") {
|
|
25332
|
+
const batch = options.batch ?? await this.getNextBatchNumber(dataSource);
|
|
25333
|
+
await this.recordMigration(name, batch, MigrationClass.createdAt ? parseCreatedAt(MigrationClass.createdAt) : /* @__PURE__ */ new Date(), dataSource);
|
|
25334
|
+
} else await this.removeMigrationRecord(name, dataSource);
|
|
25335
|
+
}
|
|
25319
25336
|
});
|
|
25320
25337
|
else {
|
|
25321
25338
|
await applyMigration();
|
|
25322
|
-
if (record)
|
|
25323
|
-
|
|
25324
|
-
|
|
25325
|
-
|
|
25339
|
+
if (record) {
|
|
25340
|
+
if (direction === "up") {
|
|
25341
|
+
const batch = options.batch ?? await this.getNextBatchNumber(dataSource);
|
|
25342
|
+
await this.recordMigration(name, batch, MigrationClass.createdAt ? parseCreatedAt(MigrationClass.createdAt) : /* @__PURE__ */ new Date(), dataSource);
|
|
25343
|
+
} else await this.removeMigrationRecord(name, dataSource);
|
|
25344
|
+
}
|
|
25326
25345
|
}
|
|
25327
25346
|
}
|
|
25328
25347
|
} catch (err) {
|