@mikro-orm/mongodb 7.1.0-dev.1 → 7.1.0-dev.3
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/MongoDriver.d.ts +1 -0
- package/MongoDriver.js +21 -0
- package/MongoMikroORM.d.ts +4 -4
- package/package.json +2 -2
package/MongoDriver.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare class MongoDriver extends DatabaseDriver<MongoConnection> {
|
|
|
20
20
|
streamVirtual<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): AsyncIterableIterator<EntityData<T>>;
|
|
21
21
|
count<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options?: CountOptions<T>): Promise<number>;
|
|
22
22
|
nativeInsert<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
|
|
23
|
+
nativeClone<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, overrides?: EntityData<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
|
|
23
24
|
nativeInsertMany<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
|
|
24
25
|
nativeUpdate<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T> & UpsertOptions<T>): Promise<QueryResult<T>>;
|
|
25
26
|
nativeUpdateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateOptions<T> & UpsertManyOptions<T>): Promise<QueryResult<T>>;
|
package/MongoDriver.js
CHANGED
|
@@ -148,6 +148,27 @@ export class MongoDriver extends DatabaseDriver {
|
|
|
148
148
|
data = this.renameFields(entityName, data);
|
|
149
149
|
return this.rethrow(this.getConnection('write').insertOne(entityName, data, options.ctx));
|
|
150
150
|
}
|
|
151
|
+
async nativeClone(entityName, where, overrides, options = {}) {
|
|
152
|
+
const meta = this.metadata.find(entityName);
|
|
153
|
+
const pk = meta.getPrimaryProps()[0].fieldNames[0] ?? '_id';
|
|
154
|
+
const normalizedWhere = Utils.isPrimaryKey(where) ? { [pk]: where } : where;
|
|
155
|
+
const renameWhere = this.renameFields(entityName, normalizedWhere);
|
|
156
|
+
const source = await this.rethrow(this.getConnection('read').find(entityName, renameWhere, { ctx: options.ctx, limit: 1 }));
|
|
157
|
+
if (!source.length) {
|
|
158
|
+
throw new Error('Cannot clone: no entity found matching the given condition');
|
|
159
|
+
}
|
|
160
|
+
const doc = source[0];
|
|
161
|
+
delete doc[pk];
|
|
162
|
+
if (overrides) {
|
|
163
|
+
const mapped = this.renameFields(entityName, overrides);
|
|
164
|
+
Object.assign(doc, mapped);
|
|
165
|
+
}
|
|
166
|
+
if (meta.versionProperty) {
|
|
167
|
+
const vProp = meta.properties[meta.versionProperty];
|
|
168
|
+
doc[vProp.fieldNames[0]] = vProp.runtimeType === 'Date' ? new Date() : 1;
|
|
169
|
+
}
|
|
170
|
+
return this.rethrow(this.getConnection('write').insertOne(entityName, doc, options.ctx));
|
|
171
|
+
}
|
|
151
172
|
async nativeInsertMany(entityName, data, options = {}) {
|
|
152
173
|
data = data.map(item => {
|
|
153
174
|
this.handleVersionProperty(entityName, item);
|
package/MongoMikroORM.d.ts
CHANGED
|
@@ -2,17 +2,17 @@ import { type AnyEntity, type EntityClass, type EntitySchema, MikroORM, type Opt
|
|
|
2
2
|
import { MongoDriver } from './MongoDriver.js';
|
|
3
3
|
import type { MongoEntityManager } from './MongoEntityManager.js';
|
|
4
4
|
/** Configuration options for the MongoDB driver. */
|
|
5
|
-
export type MongoOptions<EM extends MongoEntityManager = MongoEntityManager, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> = Partial<Options<MongoDriver, EM, Entities>>;
|
|
5
|
+
export type MongoOptions<EM extends MongoEntityManager = MongoEntityManager, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> = Partial<Options<MongoDriver, EM, Entities>>;
|
|
6
6
|
/** Creates a type-safe configuration object for the MongoDB driver. */
|
|
7
|
-
export declare function defineMongoConfig<EM extends MongoEntityManager = MongoEntityManager, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: MongoOptions<EM, Entities>): MongoOptions<EM, Entities>;
|
|
7
|
+
export declare function defineMongoConfig<EM extends MongoEntityManager = MongoEntityManager, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: MongoOptions<EM, Entities>): MongoOptions<EM, Entities>;
|
|
8
8
|
/**
|
|
9
9
|
* @inheritDoc
|
|
10
10
|
*/
|
|
11
|
-
export declare class MongoMikroORM<EM extends MongoEntityManager = MongoEntityManager, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends MikroORM<MongoDriver, EM, Entities> {
|
|
11
|
+
export declare class MongoMikroORM<EM extends MongoEntityManager = MongoEntityManager, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends MikroORM<MongoDriver, EM, Entities> {
|
|
12
12
|
/**
|
|
13
13
|
* @inheritDoc
|
|
14
14
|
*/
|
|
15
|
-
static init<D extends IDatabaseDriver = MongoDriver, EM extends EntityManager<D> = D[typeof EntityManagerType] & EntityManager<D>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Partial<Options<D, EM, Entities>>): Promise<MikroORM<D, EM, Entities>>;
|
|
15
|
+
static init<D extends IDatabaseDriver = MongoDriver, EM extends EntityManager<D> = D[typeof EntityManagerType] & EntityManager<D>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Partial<Options<D, EM, Entities>>): Promise<MikroORM<D, EM, Entities>>;
|
|
16
16
|
/**
|
|
17
17
|
* @inheritDoc
|
|
18
18
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/mongodb",
|
|
3
|
-
"version": "7.1.0-dev.
|
|
3
|
+
"version": "7.1.0-dev.3",
|
|
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
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@mikro-orm/core": "^7.0.11"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.1.0-dev.
|
|
56
|
+
"@mikro-orm/core": "7.1.0-dev.3"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|