@prisma-next/driver-mongo 0.4.0-dev.9 → 0.4.1

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/dist/control.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as DRIVER_INFO } from "./driver-info-CZ4wILJD.mjs";
1
+ import { t as DRIVER_INFO } from "./driver-info-BLTErzWO.mjs";
2
2
  import { MongoClient } from "mongodb";
3
3
  import { errorRuntime } from "@prisma-next/errors/execution";
4
4
  import { redactDatabaseUrl } from "@prisma-next/utils/redact-db-url";
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.4.0-dev.9";
2
+ var version = "0.4.1";
3
3
 
4
4
  //#endregion
5
5
  //#region src/core/driver-info.ts
@@ -10,4 +10,4 @@ const DRIVER_INFO = {
10
10
 
11
11
  //#endregion
12
12
  export { DRIVER_INFO as t };
13
- //# sourceMappingURL=driver-info-CZ4wILJD.mjs.map
13
+ //# sourceMappingURL=driver-info-BLTErzWO.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"driver-info-CZ4wILJD.mjs","names":[],"sources":["../package.json","../src/core/driver-info.ts"],"sourcesContent":["","import { version } from '../../package.json' with { type: 'json' };\n\nexport const DRIVER_INFO = { name: 'Prisma', version } as const;\n"],"mappings":";;;;;ACEA,MAAa,cAAc;CAAE,MAAM;CAAU;CAAS"}
1
+ {"version":3,"file":"driver-info-BLTErzWO.mjs","names":[],"sources":["../package.json","../src/core/driver-info.ts"],"sourcesContent":["","import { version } from '../../package.json' with { type: 'json' };\n\nexport const DRIVER_INFO = { name: 'Prisma', version } as const;\n"],"mappings":";;;;;ACEA,MAAa,cAAc;CAAE,MAAM;CAAU;CAAS"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/mongo-driver.ts"],"sourcesContent":[],"mappings":";;;;;cAsBa,eAAA,YAA2B;;EAA3B,QAAA,WAAgB,CAAA;EASuC,OAAA,cAAA,CAAA,GAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAAR,OAAQ,CAAA,eAAA,CAAA;EAAR,OAAA,MAAA,CAAA,EAAA,EAMxC,EANwC,CAAA,EAMnC,eANmC;EAMxC,OAAA,CAAA,MAIJ,MAJI,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,CAAA,WAAA,EAIkC,mBAJlC,CAAA,EAIwD,aAJxD,CAIsE,GAJtE,CAAA;EAAK,KAAA,CAAA,CAAA,EAgCR,OAhCQ,CAAA,IAAA,CAAA;;AAI6B,iBAmGhC,iBAAA,CAnGgC,GAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAmGgB,OAnGhB,CAmGwB,WAnGxB,CAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/mongo-driver.ts"],"sourcesContent":[],"mappings":";;;;;cAsBa,eAAA,YAA2B;;EAA3B,QAAA,WAAgB,CAAA;EASuC,OAAA,cAAA,CAAA,GAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAAR,OAAQ,CAAA,eAAA,CAAA;EAAR,OAAA,MAAA,CAAA,EAAA,EAMxC,EANwC,CAAA,EAMnC,eANmC;EAMxC,OAAA,CAAA,MAIJ,MAJI,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,CAAA,WAAA,EAIkC,mBAJlC,CAAA,EAIwD,aAJxD,CAIsE,GAJtE,CAAA;EAAK,KAAA,CAAA,CAAA,EAgCR,OAhCQ,CAAA,IAAA,CAAA;;AAI6B,iBAgHhC,iBAAA,CAhHgC,GAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAgHgB,OAhHhB,CAgHwB,WAhHxB,CAAA"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as DRIVER_INFO } from "./driver-info-CZ4wILJD.mjs";
1
+ import { t as DRIVER_INFO } from "./driver-info-BLTErzWO.mjs";
2
2
  import { MongoClient } from "mongodb";
3
3
 
4
4
  //#region src/mongo-driver.ts
@@ -41,10 +41,12 @@ var MongoDriverImpl = class MongoDriverImpl {
41
41
  yield { insertedId: (await this.#db.collection(cmd.collection).insertOne(cmd.document)).insertedId };
42
42
  }
43
43
  async *#executeUpdateOneCommand(cmd) {
44
- const result = await this.#db.collection(cmd.collection).updateOne(cmd.filter, cmd.update);
44
+ const result = await this.#db.collection(cmd.collection).updateOne(cmd.filter, cmd.update, { upsert: cmd.upsert });
45
45
  yield {
46
46
  matchedCount: result.matchedCount,
47
- modifiedCount: result.modifiedCount
47
+ modifiedCount: result.modifiedCount,
48
+ upsertedCount: result.upsertedCount,
49
+ upsertedId: result.upsertedId ?? void 0
48
50
  };
49
51
  }
50
52
  async *#executeInsertManyCommand(cmd) {
@@ -55,10 +57,12 @@ var MongoDriverImpl = class MongoDriverImpl {
55
57
  };
56
58
  }
57
59
  async *#executeUpdateManyCommand(cmd) {
58
- const result = await this.#db.collection(cmd.collection).updateMany(cmd.filter, cmd.update);
60
+ const result = await this.#db.collection(cmd.collection).updateMany(cmd.filter, cmd.update, { upsert: cmd.upsert });
59
61
  yield {
60
62
  matchedCount: result.matchedCount,
61
- modifiedCount: result.modifiedCount
63
+ modifiedCount: result.modifiedCount,
64
+ upsertedCount: result.upsertedCount,
65
+ upsertedId: result.upsertedId ?? void 0
62
66
  };
63
67
  }
64
68
  async *#executeDeleteOneCommand(cmd) {
@@ -69,13 +73,14 @@ var MongoDriverImpl = class MongoDriverImpl {
69
73
  }
70
74
  async *#executeFindOneAndUpdateCommand(cmd) {
71
75
  const result = await this.#db.collection(cmd.collection).findOneAndUpdate(cmd.filter, cmd.update, {
72
- returnDocument: "after",
73
- upsert: cmd.upsert
76
+ upsert: cmd.upsert,
77
+ ...cmd.returnDocument != null ? { returnDocument: cmd.returnDocument } : {},
78
+ ...cmd.sort != null ? { sort: cmd.sort } : {}
74
79
  });
75
80
  if (result) yield result;
76
81
  }
77
82
  async *#executeFindOneAndDeleteCommand(cmd) {
78
- const result = await this.#db.collection(cmd.collection).findOneAndDelete(cmd.filter);
83
+ const result = await this.#db.collection(cmd.collection).findOneAndDelete(cmd.filter, { ...cmd.sort != null ? { sort: cmd.sort } : {} });
79
84
  if (result) yield result;
80
85
  }
81
86
  async *#executeAggregateCommand(cmd) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["#db","#client","#executeInsertOneCommand","#executeUpdateOneCommand","#executeInsertManyCommand","#executeUpdateManyCommand","#executeDeleteOneCommand","#executeDeleteManyCommand","#executeFindOneAndUpdateCommand","#executeFindOneAndDeleteCommand","#executeAggregateCommand","_exhaustive: never"],"sources":["../src/mongo-driver.ts"],"sourcesContent":["import type { MongoDriver } from '@prisma-next/mongo-lowering';\nimport type {\n AggregateWireCommand,\n AnyMongoWireCommand,\n DeleteManyResult,\n DeleteManyWireCommand,\n DeleteOneResult,\n DeleteOneWireCommand,\n FindOneAndDeleteWireCommand,\n FindOneAndUpdateWireCommand,\n InsertManyResult,\n InsertManyWireCommand,\n InsertOneResult,\n InsertOneWireCommand,\n UpdateManyResult,\n UpdateManyWireCommand,\n UpdateOneResult,\n UpdateOneWireCommand,\n} from '@prisma-next/mongo-wire';\nimport { type Db, MongoClient } from 'mongodb';\nimport { DRIVER_INFO } from './core/driver-info';\n\nexport class MongoDriverImpl implements MongoDriver {\n readonly #db: Db;\n readonly #client: MongoClient | undefined;\n\n private constructor(db: Db, client: MongoClient | undefined) {\n this.#db = db;\n this.#client = client;\n }\n\n static async fromConnection(uri: string, dbName: string): Promise<MongoDriverImpl> {\n const client = new MongoClient(uri, { driverInfo: DRIVER_INFO });\n await client.connect();\n return new MongoDriverImpl(client.db(dbName), client);\n }\n\n static fromDb(db: Db): MongoDriverImpl {\n return new MongoDriverImpl(db, undefined);\n }\n\n execute<Row = Record<string, unknown>>(wireCommand: AnyMongoWireCommand): AsyncIterable<Row> {\n switch (wireCommand.kind) {\n case 'insertOne':\n return this.#executeInsertOneCommand(wireCommand) as AsyncIterable<Row>;\n case 'updateOne':\n return this.#executeUpdateOneCommand(wireCommand) as AsyncIterable<Row>;\n case 'insertMany':\n return this.#executeInsertManyCommand(wireCommand) as AsyncIterable<Row>;\n case 'updateMany':\n return this.#executeUpdateManyCommand(wireCommand) as AsyncIterable<Row>;\n case 'deleteOne':\n return this.#executeDeleteOneCommand(wireCommand) as AsyncIterable<Row>;\n case 'deleteMany':\n return this.#executeDeleteManyCommand(wireCommand) as AsyncIterable<Row>;\n case 'findOneAndUpdate':\n return this.#executeFindOneAndUpdateCommand(wireCommand) as AsyncIterable<Row>;\n case 'findOneAndDelete':\n return this.#executeFindOneAndDeleteCommand(wireCommand) as AsyncIterable<Row>;\n case 'aggregate':\n return this.#executeAggregateCommand<Row>(wireCommand);\n // v8 ignore next 4\n default: {\n const _exhaustive: never = wireCommand;\n throw new Error(`Unknown wire command kind: ${(_exhaustive as { kind: string }).kind}`);\n }\n }\n }\n\n async close(): Promise<void> {\n await this.#client?.close();\n }\n\n async *#executeInsertOneCommand(cmd: InsertOneWireCommand): AsyncIterable<InsertOneResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.insertOne(cmd.document);\n yield { insertedId: result.insertedId };\n }\n\n async *#executeUpdateOneCommand(cmd: UpdateOneWireCommand): AsyncIterable<UpdateOneResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.updateOne(cmd.filter, cmd.update);\n yield { matchedCount: result.matchedCount, modifiedCount: result.modifiedCount };\n }\n\n async *#executeInsertManyCommand(cmd: InsertManyWireCommand): AsyncIterable<InsertManyResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.insertMany(cmd.documents as Record<string, unknown>[]);\n const insertedIds = Object.values(result.insertedIds);\n yield { insertedIds, insertedCount: result.insertedCount };\n }\n\n async *#executeUpdateManyCommand(cmd: UpdateManyWireCommand): AsyncIterable<UpdateManyResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.updateMany(cmd.filter, cmd.update);\n yield { matchedCount: result.matchedCount, modifiedCount: result.modifiedCount };\n }\n\n async *#executeDeleteOneCommand(cmd: DeleteOneWireCommand): AsyncIterable<DeleteOneResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.deleteOne(cmd.filter);\n yield { deletedCount: result.deletedCount };\n }\n\n async *#executeDeleteManyCommand(cmd: DeleteManyWireCommand): AsyncIterable<DeleteManyResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.deleteMany(cmd.filter);\n yield { deletedCount: result.deletedCount };\n }\n\n async *#executeFindOneAndUpdateCommand(\n cmd: FindOneAndUpdateWireCommand,\n ): AsyncIterable<Record<string, unknown>> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.findOneAndUpdate(cmd.filter, cmd.update, {\n returnDocument: 'after',\n upsert: cmd.upsert,\n });\n if (result) {\n yield result as Record<string, unknown>;\n }\n }\n\n async *#executeFindOneAndDeleteCommand(\n cmd: FindOneAndDeleteWireCommand,\n ): AsyncIterable<Record<string, unknown>> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.findOneAndDelete(cmd.filter);\n if (result) {\n yield result as Record<string, unknown>;\n }\n }\n\n async *#executeAggregateCommand<Row>(cmd: AggregateWireCommand): AsyncIterable<Row> {\n const collection = this.#db.collection(cmd.collection);\n const cursor = collection.aggregate(cmd.pipeline as Record<string, unknown>[]);\n yield* cursor as AsyncIterable<Row>;\n }\n}\n\nexport async function createMongoDriver(uri: string, dbName: string): Promise<MongoDriver> {\n return MongoDriverImpl.fromConnection(uri, dbName);\n}\n"],"mappings":";;;;AAsBA,IAAa,kBAAb,MAAa,gBAAuC;CAClD,CAASA;CACT,CAASC;CAET,AAAQ,YAAY,IAAQ,QAAiC;AAC3D,QAAKD,KAAM;AACX,QAAKC,SAAU;;CAGjB,aAAa,eAAe,KAAa,QAA0C;EACjF,MAAM,SAAS,IAAI,YAAY,KAAK,EAAE,YAAY,aAAa,CAAC;AAChE,QAAM,OAAO,SAAS;AACtB,SAAO,IAAI,gBAAgB,OAAO,GAAG,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,WAAW,IAAI,WAAW,CACtB,WAAW,IAAI,QAAQ,IAAI,OAAO;AAClE,QAAM;GAAE,cAAc,OAAO;GAAc,eAAe,OAAO;GAAe;;CAGlF,QAAOM,wBAAyB,KAA2D;AAGzF,QAAM,EAAE,eADO,MADI,MAAKN,GAAI,WAAW,IAAI,WAAW,CACtB,UAAU,IAAI,OAAO,EACxB,cAAc;;CAG7C,QAAOO,yBAA0B,KAA6D;AAG5F,QAAM,EAAE,eADO,MADI,MAAKP,GAAI,WAAW,IAAI,WAAW,CACtB,WAAW,IAAI,OAAO,EACzB,cAAc;;CAG7C,QAAOQ,+BACL,KACwC;EAExC,MAAM,SAAS,MADI,MAAKR,GAAI,WAAW,IAAI,WAAW,CACtB,iBAAiB,IAAI,QAAQ,IAAI,QAAQ;GACvE,gBAAgB;GAChB,QAAQ,IAAI;GACb,CAAC;AACF,MAAI,OACF,OAAM;;CAIV,QAAOS,+BACL,KACwC;EAExC,MAAM,SAAS,MADI,MAAKT,GAAI,WAAW,IAAI,WAAW,CACtB,iBAAiB,IAAI,OAAO;AAC5D,MAAI,OACF,OAAM;;CAIV,QAAOU,wBAA8B,KAA+C;AAGlF,SAFmB,MAAKV,GAAI,WAAW,IAAI,WAAW,CAC5B,UAAU,IAAI,SAAsC;;;AAKlF,eAAsB,kBAAkB,KAAa,QAAsC;AACzF,QAAO,gBAAgB,eAAe,KAAK,OAAO"}
1
+ {"version":3,"file":"index.mjs","names":["#db","#client","#executeInsertOneCommand","#executeUpdateOneCommand","#executeInsertManyCommand","#executeUpdateManyCommand","#executeDeleteOneCommand","#executeDeleteManyCommand","#executeFindOneAndUpdateCommand","#executeFindOneAndDeleteCommand","#executeAggregateCommand","_exhaustive: never"],"sources":["../src/mongo-driver.ts"],"sourcesContent":["import type { MongoDriver } from '@prisma-next/mongo-lowering';\nimport type {\n AggregateWireCommand,\n AnyMongoWireCommand,\n DeleteManyResult,\n DeleteManyWireCommand,\n DeleteOneResult,\n DeleteOneWireCommand,\n FindOneAndDeleteWireCommand,\n FindOneAndUpdateWireCommand,\n InsertManyResult,\n InsertManyWireCommand,\n InsertOneResult,\n InsertOneWireCommand,\n UpdateManyResult,\n UpdateManyWireCommand,\n UpdateOneResult,\n UpdateOneWireCommand,\n} from '@prisma-next/mongo-wire';\nimport { type Db, MongoClient } from 'mongodb';\nimport { DRIVER_INFO } from './core/driver-info';\n\nexport class MongoDriverImpl implements MongoDriver {\n readonly #db: Db;\n readonly #client: MongoClient | undefined;\n\n private constructor(db: Db, client: MongoClient | undefined) {\n this.#db = db;\n this.#client = client;\n }\n\n static async fromConnection(uri: string, dbName: string): Promise<MongoDriverImpl> {\n const client = new MongoClient(uri, { driverInfo: DRIVER_INFO });\n await client.connect();\n return new MongoDriverImpl(client.db(dbName), client);\n }\n\n static fromDb(db: Db): MongoDriverImpl {\n return new MongoDriverImpl(db, undefined);\n }\n\n execute<Row = Record<string, unknown>>(wireCommand: AnyMongoWireCommand): AsyncIterable<Row> {\n switch (wireCommand.kind) {\n case 'insertOne':\n return this.#executeInsertOneCommand(wireCommand) as AsyncIterable<Row>;\n case 'updateOne':\n return this.#executeUpdateOneCommand(wireCommand) as AsyncIterable<Row>;\n case 'insertMany':\n return this.#executeInsertManyCommand(wireCommand) as AsyncIterable<Row>;\n case 'updateMany':\n return this.#executeUpdateManyCommand(wireCommand) as AsyncIterable<Row>;\n case 'deleteOne':\n return this.#executeDeleteOneCommand(wireCommand) as AsyncIterable<Row>;\n case 'deleteMany':\n return this.#executeDeleteManyCommand(wireCommand) as AsyncIterable<Row>;\n case 'findOneAndUpdate':\n return this.#executeFindOneAndUpdateCommand(wireCommand) as AsyncIterable<Row>;\n case 'findOneAndDelete':\n return this.#executeFindOneAndDeleteCommand(wireCommand) as AsyncIterable<Row>;\n case 'aggregate':\n return this.#executeAggregateCommand<Row>(wireCommand);\n // v8 ignore next 4\n default: {\n const _exhaustive: never = wireCommand;\n throw new Error(`Unknown wire command kind: ${(_exhaustive as { kind: string }).kind}`);\n }\n }\n }\n\n async close(): Promise<void> {\n await this.#client?.close();\n }\n\n async *#executeInsertOneCommand(cmd: InsertOneWireCommand): AsyncIterable<InsertOneResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.insertOne(cmd.document);\n yield { insertedId: result.insertedId };\n }\n\n async *#executeUpdateOneCommand(cmd: UpdateOneWireCommand): AsyncIterable<UpdateOneResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.updateOne(cmd.filter, cmd.update, { upsert: cmd.upsert });\n yield {\n matchedCount: result.matchedCount,\n modifiedCount: result.modifiedCount,\n upsertedCount: result.upsertedCount,\n upsertedId: result.upsertedId ?? undefined,\n };\n }\n\n async *#executeInsertManyCommand(cmd: InsertManyWireCommand): AsyncIterable<InsertManyResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.insertMany(cmd.documents as Record<string, unknown>[]);\n const insertedIds = Object.values(result.insertedIds);\n yield { insertedIds, insertedCount: result.insertedCount };\n }\n\n async *#executeUpdateManyCommand(cmd: UpdateManyWireCommand): AsyncIterable<UpdateManyResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.updateMany(cmd.filter, cmd.update, { upsert: cmd.upsert });\n yield {\n matchedCount: result.matchedCount,\n modifiedCount: result.modifiedCount,\n upsertedCount: result.upsertedCount,\n upsertedId: result.upsertedId ?? undefined,\n };\n }\n\n async *#executeDeleteOneCommand(cmd: DeleteOneWireCommand): AsyncIterable<DeleteOneResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.deleteOne(cmd.filter);\n yield { deletedCount: result.deletedCount };\n }\n\n async *#executeDeleteManyCommand(cmd: DeleteManyWireCommand): AsyncIterable<DeleteManyResult> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.deleteMany(cmd.filter);\n yield { deletedCount: result.deletedCount };\n }\n\n async *#executeFindOneAndUpdateCommand(\n cmd: FindOneAndUpdateWireCommand,\n ): AsyncIterable<Record<string, unknown>> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.findOneAndUpdate(cmd.filter, cmd.update, {\n upsert: cmd.upsert,\n ...(cmd.returnDocument != null ? { returnDocument: cmd.returnDocument } : {}),\n ...(cmd.sort != null ? { sort: cmd.sort } : {}),\n });\n if (result) {\n yield result as Record<string, unknown>;\n }\n }\n\n async *#executeFindOneAndDeleteCommand(\n cmd: FindOneAndDeleteWireCommand,\n ): AsyncIterable<Record<string, unknown>> {\n const collection = this.#db.collection(cmd.collection);\n const result = await collection.findOneAndDelete(cmd.filter, {\n ...(cmd.sort != null ? { sort: cmd.sort } : {}),\n });\n if (result) {\n yield result as Record<string, unknown>;\n }\n }\n\n async *#executeAggregateCommand<Row>(cmd: AggregateWireCommand): AsyncIterable<Row> {\n const collection = this.#db.collection(cmd.collection);\n const cursor = collection.aggregate(cmd.pipeline as Record<string, unknown>[]);\n yield* cursor as AsyncIterable<Row>;\n }\n}\n\nexport async function createMongoDriver(uri: string, dbName: string): Promise<MongoDriver> {\n return MongoDriverImpl.fromConnection(uri, dbName);\n}\n"],"mappings":";;;;AAsBA,IAAa,kBAAb,MAAa,gBAAuC;CAClD,CAASA;CACT,CAASC;CAET,AAAQ,YAAY,IAAQ,QAAiC;AAC3D,QAAKD,KAAM;AACX,QAAKC,SAAU;;CAGjB,aAAa,eAAe,KAAa,QAA0C;EACjF,MAAM,SAAS,IAAI,YAAY,KAAK,EAAE,YAAY,aAAa,CAAC;AAChE,QAAM,OAAO,SAAS;AACtB,SAAO,IAAI,gBAAgB,OAAO,GAAG,OAAO,EAAE,OAAO;;CAGvD,OAAO,OAAO,IAAyB;AACrC,SAAO,IAAI,gBAAgB,IAAI,OAAU;;CAG3C,QAAuC,aAAsD;AAC3F,UAAQ,YAAY,MAApB;GACE,KAAK,YACH,QAAO,MAAKC,wBAAyB,YAAY;GACnD,KAAK,YACH,QAAO,MAAKC,wBAAyB,YAAY;GACnD,KAAK,aACH,QAAO,MAAKC,yBAA0B,YAAY;GACpD,KAAK,aACH,QAAO,MAAKC,yBAA0B,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,EAAE,eADO,MADI,MAAKN,GAAI,WAAW,IAAI,WAAW,CACtB,UAAU,IAAI,OAAO,EACxB,cAAc;;CAG7C,QAAOO,yBAA0B,KAA6D;AAG5F,QAAM,EAAE,eADO,MADI,MAAKP,GAAI,WAAW,IAAI,WAAW,CACtB,WAAW,IAAI,OAAO,EACzB,cAAc;;CAG7C,QAAOQ,+BACL,KACwC;EAExC,MAAM,SAAS,MADI,MAAKR,GAAI,WAAW,IAAI,WAAW,CACtB,iBAAiB,IAAI,QAAQ,IAAI,QAAQ;GACvE,QAAQ,IAAI;GACZ,GAAI,IAAI,kBAAkB,OAAO,EAAE,gBAAgB,IAAI,gBAAgB,GAAG,EAAE;GAC5E,GAAI,IAAI,QAAQ,OAAO,EAAE,MAAM,IAAI,MAAM,GAAG,EAAE;GAC/C,CAAC;AACF,MAAI,OACF,OAAM;;CAIV,QAAOS,+BACL,KACwC;EAExC,MAAM,SAAS,MADI,MAAKT,GAAI,WAAW,IAAI,WAAW,CACtB,iBAAiB,IAAI,QAAQ,EAC3D,GAAI,IAAI,QAAQ,OAAO,EAAE,MAAM,IAAI,MAAM,GAAG,EAAE,EAC/C,CAAC;AACF,MAAI,OACF,OAAM;;CAIV,QAAOU,wBAA8B,KAA+C;AAGlF,SAFmB,MAAKV,GAAI,WAAW,IAAI,WAAW,CAC5B,UAAU,IAAI,SAAsC;;;AAKlF,eAAsB,kBAAkB,KAAa,QAAsC;AACzF,QAAO,gBAAgB,eAAe,KAAK,OAAO"}
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@prisma-next/driver-mongo",
3
- "version": "0.4.0-dev.9",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "MongoDB driver for Prisma Next",
7
7
  "dependencies": {
8
8
  "mongodb": "^6.16.0",
9
- "@prisma-next/errors": "0.4.0-dev.9",
10
- "@prisma-next/framework-components": "0.4.0-dev.9",
11
- "@prisma-next/mongo-lowering": "0.4.0-dev.9",
12
- "@prisma-next/utils": "0.4.0-dev.9",
13
- "@prisma-next/mongo-wire": "0.4.0-dev.9"
9
+ "@prisma-next/errors": "0.4.1",
10
+ "@prisma-next/mongo-lowering": "0.4.1",
11
+ "@prisma-next/mongo-wire": "0.4.1",
12
+ "@prisma-next/framework-components": "0.4.1",
13
+ "@prisma-next/utils": "0.4.1"
14
14
  },
15
15
  "devDependencies": {
16
16
  "mongodb-memory-server": "10.4.3",
@@ -79,8 +79,13 @@ export class MongoDriverImpl implements MongoDriver {
79
79
 
80
80
  async *#executeUpdateOneCommand(cmd: UpdateOneWireCommand): AsyncIterable<UpdateOneResult> {
81
81
  const collection = this.#db.collection(cmd.collection);
82
- const result = await collection.updateOne(cmd.filter, cmd.update);
83
- yield { matchedCount: result.matchedCount, modifiedCount: result.modifiedCount };
82
+ const result = await collection.updateOne(cmd.filter, cmd.update, { upsert: cmd.upsert });
83
+ yield {
84
+ matchedCount: result.matchedCount,
85
+ modifiedCount: result.modifiedCount,
86
+ upsertedCount: result.upsertedCount,
87
+ upsertedId: result.upsertedId ?? undefined,
88
+ };
84
89
  }
85
90
 
86
91
  async *#executeInsertManyCommand(cmd: InsertManyWireCommand): AsyncIterable<InsertManyResult> {
@@ -92,8 +97,13 @@ export class MongoDriverImpl implements MongoDriver {
92
97
 
93
98
  async *#executeUpdateManyCommand(cmd: UpdateManyWireCommand): AsyncIterable<UpdateManyResult> {
94
99
  const collection = this.#db.collection(cmd.collection);
95
- const result = await collection.updateMany(cmd.filter, cmd.update);
96
- yield { matchedCount: result.matchedCount, modifiedCount: result.modifiedCount };
100
+ const result = await collection.updateMany(cmd.filter, cmd.update, { upsert: cmd.upsert });
101
+ yield {
102
+ matchedCount: result.matchedCount,
103
+ modifiedCount: result.modifiedCount,
104
+ upsertedCount: result.upsertedCount,
105
+ upsertedId: result.upsertedId ?? undefined,
106
+ };
97
107
  }
98
108
 
99
109
  async *#executeDeleteOneCommand(cmd: DeleteOneWireCommand): AsyncIterable<DeleteOneResult> {
@@ -113,8 +123,9 @@ export class MongoDriverImpl implements MongoDriver {
113
123
  ): AsyncIterable<Record<string, unknown>> {
114
124
  const collection = this.#db.collection(cmd.collection);
115
125
  const result = await collection.findOneAndUpdate(cmd.filter, cmd.update, {
116
- returnDocument: 'after',
117
126
  upsert: cmd.upsert,
127
+ ...(cmd.returnDocument != null ? { returnDocument: cmd.returnDocument } : {}),
128
+ ...(cmd.sort != null ? { sort: cmd.sort } : {}),
118
129
  });
119
130
  if (result) {
120
131
  yield result as Record<string, unknown>;
@@ -125,7 +136,9 @@ export class MongoDriverImpl implements MongoDriver {
125
136
  cmd: FindOneAndDeleteWireCommand,
126
137
  ): AsyncIterable<Record<string, unknown>> {
127
138
  const collection = this.#db.collection(cmd.collection);
128
- const result = await collection.findOneAndDelete(cmd.filter);
139
+ const result = await collection.findOneAndDelete(cmd.filter, {
140
+ ...(cmd.sort != null ? { sort: cmd.sort } : {}),
141
+ });
129
142
  if (result) {
130
143
  yield result as Record<string, unknown>;
131
144
  }