@mikro-orm/mongodb 6.5.7-dev.2 → 6.5.7-dev.21
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/MongoConnection.js +19 -9
- package/MongoDriver.d.ts +1 -0
- package/MongoDriver.js +24 -3
- package/index.mjs +4 -0
- package/package.json +2 -2
package/MongoConnection.js
CHANGED
|
@@ -294,12 +294,19 @@ class MongoConnection extends core_1.Connection {
|
|
|
294
294
|
createUpdatePayload(row, upsertOptions) {
|
|
295
295
|
const doc = { $set: row };
|
|
296
296
|
const $unset = {};
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
297
|
+
const $inc = {};
|
|
298
|
+
for (const k of core_1.Utils.keys(row)) {
|
|
299
|
+
const item = row[k];
|
|
300
|
+
if (typeof item === 'undefined') {
|
|
301
|
+
$unset[k] = '';
|
|
302
|
+
delete row[k];
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (core_1.Utils.isPlainObject(item) && '$inc' in item) {
|
|
306
|
+
$inc[k] = item.$inc;
|
|
307
|
+
delete row[k];
|
|
308
|
+
}
|
|
309
|
+
}
|
|
303
310
|
if (upsertOptions) {
|
|
304
311
|
if (upsertOptions.onConflictAction === 'ignore') {
|
|
305
312
|
doc.$setOnInsert = doc.$set;
|
|
@@ -325,9 +332,12 @@ class MongoConnection extends core_1.Connection {
|
|
|
325
332
|
}
|
|
326
333
|
if (core_1.Utils.hasObjectKeys($unset)) {
|
|
327
334
|
doc.$unset = $unset;
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
335
|
+
}
|
|
336
|
+
if (core_1.Utils.hasObjectKeys($inc)) {
|
|
337
|
+
doc.$inc = $inc;
|
|
338
|
+
}
|
|
339
|
+
if (!core_1.Utils.hasObjectKeys(doc.$set)) {
|
|
340
|
+
delete doc.$set;
|
|
331
341
|
}
|
|
332
342
|
return doc;
|
|
333
343
|
}
|
package/MongoDriver.d.ts
CHANGED
|
@@ -26,4 +26,5 @@ export declare class MongoDriver extends DatabaseDriver<MongoConnection> {
|
|
|
26
26
|
private convertObjectIds;
|
|
27
27
|
private buildFilterById;
|
|
28
28
|
protected buildFields<T extends object, P extends string = never>(entityName: string, populate: PopulateOptions<T>[], fields?: readonly EntityField<T, P>[], exclude?: string[]): string[] | undefined;
|
|
29
|
+
private handleVersionProperty;
|
|
29
30
|
}
|
package/MongoDriver.js
CHANGED
|
@@ -82,11 +82,15 @@ class MongoDriver extends core_1.DatabaseDriver {
|
|
|
82
82
|
return this.rethrow(this.getConnection('read').countDocuments(entityName, where, ctx));
|
|
83
83
|
}
|
|
84
84
|
async nativeInsert(entityName, data, options = {}) {
|
|
85
|
+
this.handleVersionProperty(entityName, data);
|
|
85
86
|
data = this.renameFields(entityName, data);
|
|
86
87
|
return this.rethrow(this.getConnection('write').insertOne(entityName, data, options.ctx));
|
|
87
88
|
}
|
|
88
89
|
async nativeInsertMany(entityName, data, options = {}) {
|
|
89
|
-
data = data.map(
|
|
90
|
+
data = data.map(item => {
|
|
91
|
+
this.handleVersionProperty(entityName, item);
|
|
92
|
+
return this.renameFields(entityName, item);
|
|
93
|
+
});
|
|
90
94
|
const meta = this.metadata.find(entityName);
|
|
91
95
|
/* istanbul ignore next */
|
|
92
96
|
const pk = meta?.getPrimaryProps()[0].fieldNames[0] ?? '_id';
|
|
@@ -98,8 +102,9 @@ class MongoDriver extends core_1.DatabaseDriver {
|
|
|
98
102
|
if (core_1.Utils.isPrimaryKey(where)) {
|
|
99
103
|
where = this.buildFilterById(entityName, where);
|
|
100
104
|
}
|
|
101
|
-
|
|
105
|
+
this.handleVersionProperty(entityName, data, true);
|
|
102
106
|
data = this.renameFields(entityName, data);
|
|
107
|
+
where = this.renameFields(entityName, where, true);
|
|
103
108
|
options = { ...options };
|
|
104
109
|
const meta = this.metadata.find(entityName);
|
|
105
110
|
/* istanbul ignore next */
|
|
@@ -122,7 +127,10 @@ class MongoDriver extends core_1.DatabaseDriver {
|
|
|
122
127
|
}
|
|
123
128
|
return row;
|
|
124
129
|
});
|
|
125
|
-
data = data.map(row =>
|
|
130
|
+
data = data.map(row => {
|
|
131
|
+
this.handleVersionProperty(entityName, row, true);
|
|
132
|
+
return this.renameFields(entityName, row);
|
|
133
|
+
});
|
|
126
134
|
options = { ...options };
|
|
127
135
|
const meta = this.metadata.find(entityName);
|
|
128
136
|
/* istanbul ignore next */
|
|
@@ -309,5 +317,18 @@ class MongoDriver extends core_1.DatabaseDriver {
|
|
|
309
317
|
}
|
|
310
318
|
return ret.length > 0 ? ret : undefined;
|
|
311
319
|
}
|
|
320
|
+
handleVersionProperty(entityName, data, update = false) {
|
|
321
|
+
const meta = this.metadata.find(entityName);
|
|
322
|
+
if (!meta?.versionProperty) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const versionProperty = meta.properties[meta.versionProperty];
|
|
326
|
+
if (versionProperty.runtimeType === 'Date') {
|
|
327
|
+
data[versionProperty.name] ??= new Date();
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
data[versionProperty.name] ??= update ? { $inc: 1 } : 1;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
312
333
|
}
|
|
313
334
|
exports.MongoDriver = MongoDriver;
|
package/index.mjs
CHANGED
|
@@ -50,6 +50,7 @@ export const DeadlockException = mod.DeadlockException;
|
|
|
50
50
|
export const DecimalType = mod.DecimalType;
|
|
51
51
|
export const DefaultLogger = mod.DefaultLogger;
|
|
52
52
|
export const DeferMode = mod.DeferMode;
|
|
53
|
+
export const DefineConfig = mod.DefineConfig;
|
|
53
54
|
export const DoubleType = mod.DoubleType;
|
|
54
55
|
export const DriverException = mod.DriverException;
|
|
55
56
|
export const EagerProps = mod.EagerProps;
|
|
@@ -90,6 +91,7 @@ export const ForeignKeyConstraintViolationException = mod.ForeignKeyConstraintVi
|
|
|
90
91
|
export const Formula = mod.Formula;
|
|
91
92
|
export const GeneratedCacheAdapter = mod.GeneratedCacheAdapter;
|
|
92
93
|
export const GroupOperator = mod.GroupOperator;
|
|
94
|
+
export const Hidden = mod.Hidden;
|
|
93
95
|
export const HiddenProps = mod.HiddenProps;
|
|
94
96
|
export const Hydrator = mod.Hydrator;
|
|
95
97
|
export const IdentityMap = mod.IdentityMap;
|
|
@@ -139,6 +141,7 @@ export const OneToManyOptionsBuilder = mod.OneToManyOptionsBuilder;
|
|
|
139
141
|
export const OneToManyOptionsBuilderOnlyMappedBy = mod.OneToManyOptionsBuilderOnlyMappedBy;
|
|
140
142
|
export const OneToOne = mod.OneToOne;
|
|
141
143
|
export const OneToOneOptionsBuilder = mod.OneToOneOptionsBuilder;
|
|
144
|
+
export const Opt = mod.Opt;
|
|
142
145
|
export const OptimisticLockError = mod.OptimisticLockError;
|
|
143
146
|
export const OptionalProps = mod.OptionalProps;
|
|
144
147
|
export const PlainObject = mod.PlainObject;
|
|
@@ -162,6 +165,7 @@ export const ReferenceKind = mod.ReferenceKind;
|
|
|
162
165
|
export const ReferenceOptionsBuilder = mod.ReferenceOptionsBuilder;
|
|
163
166
|
export const ReflectMetadataProvider = mod.ReflectMetadataProvider;
|
|
164
167
|
export const RequestContext = mod.RequestContext;
|
|
168
|
+
export const RequiredNullable = mod.RequiredNullable;
|
|
165
169
|
export const SCALAR_TYPES = mod.SCALAR_TYPES;
|
|
166
170
|
export const ScalarReference = mod.ScalarReference;
|
|
167
171
|
export const SerializationContext = mod.SerializationContext;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/mongodb",
|
|
3
|
-
"version": "6.5.7-dev.
|
|
3
|
+
"version": "6.5.7-dev.21",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -65,6 +65,6 @@
|
|
|
65
65
|
"@mikro-orm/core": "^6.5.6"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"@mikro-orm/core": "6.5.7-dev.
|
|
68
|
+
"@mikro-orm/core": "6.5.7-dev.21"
|
|
69
69
|
}
|
|
70
70
|
}
|