@prisma-next/driver-mongo 0.12.0 → 0.13.0-dev.2

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.
@@ -1,15 +1,14 @@
1
+ import { t as MongoDriverImpl } from "./mongo-driver-CXhojUq7.mjs";
1
2
  import { Db, MongoClient } from "mongodb";
2
- import { ControlDriverDescriptor, ControlDriverInstance } from "@prisma-next/framework-components/control";
3
+ import { ControlDriverDescriptor } from "@prisma-next/framework-components/control";
4
+ import { MongoControlDriverInstance } from "@prisma-next/mongo-lowering";
3
5
 
4
6
  //#region src/exports/control.d.ts
5
- declare class MongoControlDriver implements ControlDriverInstance<'mongo', 'mongo'> {
6
- #private;
7
+ declare class MongoControlDriver extends MongoDriverImpl implements MongoControlDriverInstance {
7
8
  readonly familyId: "mongo";
8
9
  readonly targetId: "mongo";
9
10
  readonly db: Db;
10
- constructor(db: Db, client: MongoClient);
11
- query(_sql: string, _params?: readonly unknown[]): Promise<never>;
12
- close(): Promise<void>;
11
+ constructor(db: Db, mongoClient: MongoClient);
13
12
  }
14
13
  declare const mongoControlDriverDescriptor: ControlDriverDescriptor<'mongo', 'mongo', MongoControlDriver>;
15
14
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"control.d.mts","names":[],"sources":["../src/exports/control.ts"],"mappings":";;;;cASa,kBAAA,YAA8B,qBAAA;EAAA;WAChC,QAAA;EAAA,SACA,QAAA;EAAA,SACA,EAAA,EAAI,EAAA;cAGD,EAAA,EAAI,EAAA,EAAI,MAAA,EAAQ,WAAA;EAK5B,KAAA,CAAM,IAAA,UAAc,OAAA,wBAA+B,OAAA;EAI7C,KAAA,CAAA,GAAS,OAAA;AAAA;AAAA,cAKX,4BAAA,EAA8B,uBAAuB,mBAAmB,kBAAA"}
1
+ {"version":3,"file":"control.d.mts","names":[],"sources":["../src/exports/control.ts"],"mappings":";;;;;;cAQa,kBAAA,SAA2B,eAAA,YAA2B,0BAAA;EAAA,SACxD,QAAA;EAAA,SACA,QAAA;EAAA,SACS,EAAA,EAAI,EAAA;cAEV,EAAA,EAAI,EAAA,EAAI,WAAA,EAAa,WAAA;AAAA;AAAA,cAM7B,4BAAA,EAA8B,uBAAuB,mBAAmB,kBAAA"}
package/dist/control.mjs CHANGED
@@ -1,22 +1,15 @@
1
- import { t as DRIVER_INFO } from "./driver-info-FCZA4IPt.mjs";
1
+ import { r as DRIVER_INFO, t as MongoDriverImpl } from "./mongo-driver-XIMDZ-VX.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";
5
5
  //#region src/exports/control.ts
6
- var MongoControlDriver = class {
6
+ var MongoControlDriver = class extends MongoDriverImpl {
7
7
  familyId = "mongo";
8
8
  targetId = "mongo";
9
9
  db;
10
- #client;
11
- constructor(db, client) {
10
+ constructor(db, mongoClient) {
11
+ super(db, mongoClient);
12
12
  this.db = db;
13
- this.#client = client;
14
- }
15
- query(_sql, _params) {
16
- throw new Error("MongoDB control driver does not support SQL queries");
17
- }
18
- async close() {
19
- await this.#client.close();
20
13
  }
21
14
  };
22
15
  const mongoControlDriverDescriptor = {
@@ -1 +1 @@
1
- {"version":3,"file":"control.mjs","names":["#client"],"sources":["../src/exports/control.ts"],"sourcesContent":["import { errorRuntime } from '@prisma-next/errors/execution';\nimport type {\n ControlDriverDescriptor,\n ControlDriverInstance,\n} from '@prisma-next/framework-components/control';\nimport { redactDatabaseUrl } from '@prisma-next/utils/redact-db-url';\nimport { type Db, MongoClient } from 'mongodb';\nimport { DRIVER_INFO } from '../core/driver-info';\n\nexport class MongoControlDriver implements ControlDriverInstance<'mongo', 'mongo'> {\n readonly familyId = 'mongo' as const;\n readonly targetId = 'mongo' as const;\n readonly db: Db;\n readonly #client: MongoClient;\n\n constructor(db: Db, client: MongoClient) {\n this.db = db;\n this.#client = client;\n }\n\n query(_sql: string, _params?: readonly unknown[]): Promise<never> {\n throw new Error('MongoDB control driver does not support SQL queries');\n }\n\n async close(): Promise<void> {\n await this.#client.close();\n }\n}\n\nconst mongoControlDriverDescriptor: ControlDriverDescriptor<'mongo', 'mongo', MongoControlDriver> =\n {\n kind: 'driver',\n familyId: 'mongo',\n targetId: 'mongo',\n id: 'mongo',\n version: DRIVER_INFO.version,\n capabilities: {},\n async create(url: string): Promise<MongoControlDriver> {\n const client = new MongoClient(url, {\n serverSelectionTimeoutMS: 5000,\n connectTimeoutMS: 5000,\n driverInfo: DRIVER_INFO,\n });\n try {\n await client.connect();\n const db = client.db();\n return new MongoControlDriver(db, client);\n } catch (error) {\n try {\n await client.close();\n } catch {\n // ignore cleanup error\n }\n const message = error instanceof Error ? error.message : String(error);\n const redacted = redactDatabaseUrl(url);\n throw errorRuntime('Database connection failed', {\n why: message,\n fix: 'Verify the MongoDB URL, ensure the database is reachable, and confirm credentials/permissions',\n meta: { ...redacted },\n });\n }\n },\n };\n\nexport default mongoControlDriverDescriptor;\n"],"mappings":";;;;;AASA,IAAa,qBAAb,MAAmF;CACjF,WAAoB;CACpB,WAAoB;CACpB;CACA;CAEA,YAAY,IAAQ,QAAqB;EACvC,KAAK,KAAK;EACV,KAAKA,UAAU;CACjB;CAEA,MAAM,MAAc,SAA8C;EAChE,MAAM,IAAI,MAAM,qDAAqD;CACvE;CAEA,MAAM,QAAuB;EAC3B,MAAM,KAAKA,QAAQ,MAAM;CAC3B;AACF;AAEA,MAAM,+BACJ;CACE,MAAM;CACN,UAAU;CACV,UAAU;CACV,IAAI;CACJ,SAAS,YAAY;CACrB,cAAc,CAAC;CACf,MAAM,OAAO,KAA0C;EACrD,MAAM,SAAS,IAAI,YAAY,KAAK;GAClC,0BAA0B;GAC1B,kBAAkB;GAClB,YAAY;EACd,CAAC;EACD,IAAI;GACF,MAAM,OAAO,QAAQ;GAErB,OAAO,IAAI,mBADA,OAAO,GACa,GAAG,MAAM;EAC1C,SAAS,OAAO;GACd,IAAI;IACF,MAAM,OAAO,MAAM;GACrB,QAAQ,CAER;GAGA,MAAM,aAAa,8BAA8B;IAC/C,KAHc,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;IAInE,KAAK;IACL,MAAM,EAAE,GAJO,kBAAkB,GAIf,EAAE;GACtB,CAAC;EACH;CACF;AACF"}
1
+ {"version":3,"file":"control.mjs","names":[],"sources":["../src/exports/control.ts"],"sourcesContent":["import { errorRuntime } from '@prisma-next/errors/execution';\nimport type { ControlDriverDescriptor } from '@prisma-next/framework-components/control';\nimport type { MongoControlDriverInstance } from '@prisma-next/mongo-lowering';\nimport { redactDatabaseUrl } from '@prisma-next/utils/redact-db-url';\nimport { type Db, MongoClient } from 'mongodb';\nimport { DRIVER_INFO } from '../core/driver-info';\nimport { MongoDriverImpl } from '../mongo-driver';\n\nexport class MongoControlDriver extends MongoDriverImpl implements MongoControlDriverInstance {\n readonly familyId = 'mongo' as const;\n readonly targetId = 'mongo' as const;\n override readonly db: Db;\n\n constructor(db: Db, mongoClient: MongoClient) {\n super(db, mongoClient);\n this.db = db;\n }\n}\n\nconst mongoControlDriverDescriptor: ControlDriverDescriptor<'mongo', 'mongo', MongoControlDriver> =\n {\n kind: 'driver',\n familyId: 'mongo',\n targetId: 'mongo',\n id: 'mongo',\n version: DRIVER_INFO.version,\n capabilities: {},\n async create(url: string): Promise<MongoControlDriver> {\n const client = new MongoClient(url, {\n serverSelectionTimeoutMS: 5000,\n connectTimeoutMS: 5000,\n driverInfo: DRIVER_INFO,\n });\n try {\n await client.connect();\n const db = client.db();\n return new MongoControlDriver(db, client);\n } catch (error) {\n try {\n await client.close();\n } catch {\n // ignore cleanup error\n }\n const message = error instanceof Error ? error.message : String(error);\n const redacted = redactDatabaseUrl(url);\n throw errorRuntime('Database connection failed', {\n why: message,\n fix: 'Verify the MongoDB URL, ensure the database is reachable, and confirm credentials/permissions',\n meta: { ...redacted },\n });\n }\n },\n };\n\nexport default mongoControlDriverDescriptor;\n"],"mappings":";;;;;AAQA,IAAa,qBAAb,cAAwC,gBAAsD;CAC5F,WAAoB;CACpB,WAAoB;CACpB;CAEA,YAAY,IAAQ,aAA0B;EAC5C,MAAM,IAAI,WAAW;EACrB,KAAK,KAAK;CACZ;AACF;AAEA,MAAM,+BACJ;CACE,MAAM;CACN,UAAU;CACV,UAAU;CACV,IAAI;CACJ,SAAS,YAAY;CACrB,cAAc,CAAC;CACf,MAAM,OAAO,KAA0C;EACrD,MAAM,SAAS,IAAI,YAAY,KAAK;GAClC,0BAA0B;GAC1B,kBAAkB;GAClB,YAAY;EACd,CAAC;EACD,IAAI;GACF,MAAM,OAAO,QAAQ;GAErB,OAAO,IAAI,mBADA,OAAO,GACa,GAAG,MAAM;EAC1C,SAAS,OAAO;GACd,IAAI;IACF,MAAM,OAAO,MAAM;GACrB,QAAQ,CAER;GAGA,MAAM,aAAa,8BAA8B;IAC/C,KAHc,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;IAInE,KAAK;IACL,MAAM,EAAE,GAJO,kBAAkB,GAIf,EAAE;GACtB,CAAC;EACH;CACF;AACF"}
package/dist/index.d.mts CHANGED
@@ -1,17 +1,2 @@
1
- import { Db } from "mongodb";
2
- import { MongoDriver } from "@prisma-next/mongo-lowering";
3
- import { AnyMongoWireCommand } from "@prisma-next/mongo-wire";
4
-
5
- //#region src/mongo-driver.d.ts
6
- declare class MongoDriverImpl implements MongoDriver {
7
- #private;
8
- private constructor();
9
- static fromConnection(uri: string, dbName: string): Promise<MongoDriverImpl>;
10
- static fromDb(db: Db): MongoDriverImpl;
11
- execute<Row = Record<string, unknown>>(wireCommand: AnyMongoWireCommand): AsyncIterable<Row>;
12
- close(): Promise<void>;
13
- }
14
- declare function createMongoDriver(uri: string, dbName: string): Promise<MongoDriver>;
15
- //#endregion
16
- export { MongoDriverImpl, createMongoDriver };
17
- //# sourceMappingURL=index.d.mts.map
1
+ import { n as createMongoDriver, t as MongoDriverImpl } from "./mongo-driver-CXhojUq7.mjs";
2
+ export { MongoDriverImpl, createMongoDriver };
package/dist/index.mjs CHANGED
@@ -1,93 +1,2 @@
1
- import { t as DRIVER_INFO } from "./driver-info-FCZA4IPt.mjs";
2
- import { MongoClient } from "mongodb";
3
- //#region src/mongo-driver.ts
4
- var MongoDriverImpl = class MongoDriverImpl {
5
- #db;
6
- #client;
7
- constructor(db, client) {
8
- this.#db = db;
9
- this.#client = client;
10
- }
11
- static async fromConnection(uri, dbName) {
12
- const client = new MongoClient(uri, { driverInfo: DRIVER_INFO });
13
- await client.connect();
14
- return new MongoDriverImpl(client.db(dbName), client);
15
- }
16
- static fromDb(db) {
17
- return new MongoDriverImpl(db, void 0);
18
- }
19
- execute(wireCommand) {
20
- switch (wireCommand.kind) {
21
- case "insertOne": return this.#executeInsertOneCommand(wireCommand);
22
- case "updateOne": return this.#executeUpdateOneCommand(wireCommand);
23
- case "insertMany": return this.#executeInsertManyCommand(wireCommand);
24
- case "updateMany": return this.#executeUpdateManyCommand(wireCommand);
25
- case "deleteOne": return this.#executeDeleteOneCommand(wireCommand);
26
- case "deleteMany": return this.#executeDeleteManyCommand(wireCommand);
27
- case "findOneAndUpdate": return this.#executeFindOneAndUpdateCommand(wireCommand);
28
- case "findOneAndDelete": return this.#executeFindOneAndDeleteCommand(wireCommand);
29
- case "aggregate": return this.#executeAggregateCommand(wireCommand);
30
- // v8 ignore next 4
31
- default: throw new Error(`Unknown wire command kind: ${wireCommand.kind}`);
32
- }
33
- }
34
- async close() {
35
- await this.#client?.close();
36
- }
37
- async *#executeInsertOneCommand(cmd) {
38
- yield { insertedId: (await this.#db.collection(cmd.collection).insertOne(cmd.document)).insertedId };
39
- }
40
- async *#executeUpdateOneCommand(cmd) {
41
- const result = await this.#db.collection(cmd.collection).updateOne(cmd.filter, cmd.update, { upsert: cmd.upsert });
42
- yield {
43
- matchedCount: result.matchedCount,
44
- modifiedCount: result.modifiedCount,
45
- upsertedCount: result.upsertedCount,
46
- upsertedId: result.upsertedId ?? void 0
47
- };
48
- }
49
- async *#executeInsertManyCommand(cmd) {
50
- const result = await this.#db.collection(cmd.collection).insertMany(cmd.documents);
51
- yield {
52
- insertedIds: Object.values(result.insertedIds),
53
- insertedCount: result.insertedCount
54
- };
55
- }
56
- async *#executeUpdateManyCommand(cmd) {
57
- const result = await this.#db.collection(cmd.collection).updateMany(cmd.filter, cmd.update, { upsert: cmd.upsert });
58
- yield {
59
- matchedCount: result.matchedCount,
60
- modifiedCount: result.modifiedCount,
61
- upsertedCount: result.upsertedCount,
62
- upsertedId: result.upsertedId ?? void 0
63
- };
64
- }
65
- async *#executeDeleteOneCommand(cmd) {
66
- yield { deletedCount: (await this.#db.collection(cmd.collection).deleteOne(cmd.filter)).deletedCount };
67
- }
68
- async *#executeDeleteManyCommand(cmd) {
69
- yield { deletedCount: (await this.#db.collection(cmd.collection).deleteMany(cmd.filter)).deletedCount };
70
- }
71
- async *#executeFindOneAndUpdateCommand(cmd) {
72
- const result = await this.#db.collection(cmd.collection).findOneAndUpdate(cmd.filter, cmd.update, {
73
- upsert: cmd.upsert,
74
- ...cmd.returnDocument != null ? { returnDocument: cmd.returnDocument } : {},
75
- ...cmd.sort != null ? { sort: cmd.sort } : {}
76
- });
77
- if (result) yield result;
78
- }
79
- async *#executeFindOneAndDeleteCommand(cmd) {
80
- const result = await this.#db.collection(cmd.collection).findOneAndDelete(cmd.filter, { ...cmd.sort != null ? { sort: cmd.sort } : {} });
81
- if (result) yield result;
82
- }
83
- async *#executeAggregateCommand(cmd) {
84
- yield* this.#db.collection(cmd.collection).aggregate(cmd.pipeline);
85
- }
86
- };
87
- async function createMongoDriver(uri, dbName) {
88
- return MongoDriverImpl.fromConnection(uri, dbName);
89
- }
90
- //#endregion
1
+ import { n as createMongoDriver, t as MongoDriverImpl } from "./mongo-driver-XIMDZ-VX.mjs";
91
2
  export { MongoDriverImpl, createMongoDriver };
92
-
93
- //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,27 @@
1
+ import { Db, MongoClient } from "mongodb";
2
+ import { MongoDriver } from "@prisma-next/mongo-lowering";
3
+ import { AggregateWireCommand, AnyMongoWireCommand, DeleteManyResult, DeleteManyWireCommand, DeleteOneResult, DeleteOneWireCommand, FindOneAndDeleteWireCommand, FindOneAndUpdateWireCommand, InsertManyResult, InsertManyWireCommand, InsertOneResult, InsertOneWireCommand, UpdateManyResult, UpdateManyWireCommand, UpdateOneResult, UpdateOneWireCommand } from "@prisma-next/mongo-wire";
4
+
5
+ //#region src/mongo-driver.d.ts
6
+ declare class MongoDriverImpl implements MongoDriver {
7
+ protected readonly db: Db;
8
+ protected readonly client: MongoClient | undefined;
9
+ protected constructor(db: Db, client: MongoClient | undefined);
10
+ static fromConnection(uri: string, dbName: string): Promise<MongoDriverImpl>;
11
+ static fromDb(db: Db): MongoDriverImpl;
12
+ execute<Row = Record<string, unknown>>(wireCommand: AnyMongoWireCommand): AsyncIterable<Row>;
13
+ close(): Promise<void>;
14
+ protected executeInsertOneCommand(cmd: InsertOneWireCommand): AsyncIterable<InsertOneResult>;
15
+ protected executeUpdateOneCommand(cmd: UpdateOneWireCommand): AsyncIterable<UpdateOneResult>;
16
+ protected executeInsertManyCommand(cmd: InsertManyWireCommand): AsyncIterable<InsertManyResult>;
17
+ protected executeUpdateManyCommand(cmd: UpdateManyWireCommand): AsyncIterable<UpdateManyResult>;
18
+ protected executeDeleteOneCommand(cmd: DeleteOneWireCommand): AsyncIterable<DeleteOneResult>;
19
+ protected executeDeleteManyCommand(cmd: DeleteManyWireCommand): AsyncIterable<DeleteManyResult>;
20
+ protected executeFindOneAndUpdateCommand(cmd: FindOneAndUpdateWireCommand): AsyncIterable<Record<string, unknown>>;
21
+ protected executeFindOneAndDeleteCommand(cmd: FindOneAndDeleteWireCommand): AsyncIterable<Record<string, unknown>>;
22
+ protected executeAggregateCommand<Row>(cmd: AggregateWireCommand): AsyncIterable<Row>;
23
+ }
24
+ declare function createMongoDriver(uri: string, dbName: string): Promise<MongoDriver>;
25
+ //#endregion
26
+ export { createMongoDriver as n, MongoDriverImpl as t };
27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+1,99 @@
1
+ import { MongoClient } from "mongodb";
2
+ //#endregion
3
+ //#region src/core/driver-info.ts
4
+ const DRIVER_INFO = {
5
+ name: "Prisma",
6
+ version: "0.13.0-dev.2"
7
+ };
8
+ //#endregion
9
+ //#region src/mongo-driver.ts
10
+ var MongoDriverImpl = class MongoDriverImpl {
11
+ db;
12
+ client;
13
+ constructor(db, client) {
14
+ this.db = db;
15
+ this.client = client;
16
+ }
17
+ static async fromConnection(uri, dbName) {
18
+ const client = new MongoClient(uri, { driverInfo: DRIVER_INFO });
19
+ await client.connect();
20
+ return new MongoDriverImpl(client.db(dbName), client);
21
+ }
22
+ static fromDb(db) {
23
+ return new MongoDriverImpl(db, void 0);
24
+ }
25
+ execute(wireCommand) {
26
+ switch (wireCommand.kind) {
27
+ case "insertOne": return this.executeInsertOneCommand(wireCommand);
28
+ case "updateOne": return this.executeUpdateOneCommand(wireCommand);
29
+ case "insertMany": return this.executeInsertManyCommand(wireCommand);
30
+ case "updateMany": return this.executeUpdateManyCommand(wireCommand);
31
+ case "deleteOne": return this.executeDeleteOneCommand(wireCommand);
32
+ case "deleteMany": return this.executeDeleteManyCommand(wireCommand);
33
+ case "findOneAndUpdate": return this.executeFindOneAndUpdateCommand(wireCommand);
34
+ case "findOneAndDelete": return this.executeFindOneAndDeleteCommand(wireCommand);
35
+ case "aggregate": return this.executeAggregateCommand(wireCommand);
36
+ // v8 ignore next 4
37
+ default: throw new Error(`Unknown wire command kind: ${wireCommand.kind}`);
38
+ }
39
+ }
40
+ async close() {
41
+ await this.client?.close();
42
+ }
43
+ async *executeInsertOneCommand(cmd) {
44
+ yield { insertedId: (await this.db.collection(cmd.collection).insertOne(cmd.document)).insertedId };
45
+ }
46
+ async *executeUpdateOneCommand(cmd) {
47
+ const result = await this.db.collection(cmd.collection).updateOne(cmd.filter, cmd.update, { upsert: cmd.upsert });
48
+ yield {
49
+ matchedCount: result.matchedCount,
50
+ modifiedCount: result.modifiedCount,
51
+ upsertedCount: result.upsertedCount,
52
+ upsertedId: result.upsertedId ?? void 0
53
+ };
54
+ }
55
+ async *executeInsertManyCommand(cmd) {
56
+ const result = await this.db.collection(cmd.collection).insertMany(cmd.documents);
57
+ yield {
58
+ insertedIds: Object.values(result.insertedIds),
59
+ insertedCount: result.insertedCount
60
+ };
61
+ }
62
+ async *executeUpdateManyCommand(cmd) {
63
+ const result = await this.db.collection(cmd.collection).updateMany(cmd.filter, cmd.update, { upsert: cmd.upsert });
64
+ yield {
65
+ matchedCount: result.matchedCount,
66
+ modifiedCount: result.modifiedCount,
67
+ upsertedCount: result.upsertedCount,
68
+ upsertedId: result.upsertedId ?? void 0
69
+ };
70
+ }
71
+ async *executeDeleteOneCommand(cmd) {
72
+ yield { deletedCount: (await this.db.collection(cmd.collection).deleteOne(cmd.filter)).deletedCount };
73
+ }
74
+ async *executeDeleteManyCommand(cmd) {
75
+ yield { deletedCount: (await this.db.collection(cmd.collection).deleteMany(cmd.filter)).deletedCount };
76
+ }
77
+ async *executeFindOneAndUpdateCommand(cmd) {
78
+ const result = await this.db.collection(cmd.collection).findOneAndUpdate(cmd.filter, cmd.update, {
79
+ upsert: cmd.upsert,
80
+ ...cmd.returnDocument != null ? { returnDocument: cmd.returnDocument } : {},
81
+ ...cmd.sort != null ? { sort: cmd.sort } : {}
82
+ });
83
+ if (result) yield result;
84
+ }
85
+ async *executeFindOneAndDeleteCommand(cmd) {
86
+ const result = await this.db.collection(cmd.collection).findOneAndDelete(cmd.filter, { ...cmd.sort != null ? { sort: cmd.sort } : {} });
87
+ if (result) yield result;
88
+ }
89
+ async *executeAggregateCommand(cmd) {
90
+ yield* this.db.collection(cmd.collection).aggregate(cmd.pipeline);
91
+ }
92
+ };
93
+ async function createMongoDriver(uri, dbName) {
94
+ return MongoDriverImpl.fromConnection(uri, dbName);
95
+ }
96
+ //#endregion
97
+ export { createMongoDriver as n, DRIVER_INFO as r, MongoDriverImpl as t };
98
+
99
+ //# sourceMappingURL=mongo-driver-XIMDZ-VX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo-driver-XIMDZ-VX.mjs","names":["_exhaustive"],"sources":["../package.json","../src/core/driver-info.ts","../src/mongo-driver.ts"],"sourcesContent":["","import { version } from '../../package.json' with { type: 'json' };\n\nexport const DRIVER_INFO = { name: 'Prisma', version } as const;\n","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 protected readonly db: Db;\n protected readonly client: MongoClient | undefined;\n\n protected 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 protected async *executeInsertOneCommand(\n cmd: InsertOneWireCommand,\n ): 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 protected async *executeUpdateOneCommand(\n cmd: UpdateOneWireCommand,\n ): 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 protected async *executeInsertManyCommand(\n cmd: InsertManyWireCommand,\n ): 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 protected async *executeUpdateManyCommand(\n cmd: UpdateManyWireCommand,\n ): 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 protected async *executeDeleteOneCommand(\n cmd: DeleteOneWireCommand,\n ): 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 protected async *executeDeleteManyCommand(\n cmd: DeleteManyWireCommand,\n ): 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 protected 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 protected 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 protected 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":";;;ACEA,MAAa,cAAc;CAAE,MAAM;CAAU;AAAQ;;;ACoBrD,IAAa,kBAAb,MAAa,gBAAuC;CAClD;CACA;CAEA,YAAsB,IAAQ,QAAiC;EAC7D,KAAK,KAAK;EACV,KAAK,SAAS;CAChB;CAEA,aAAa,eAAe,KAAa,QAA0C;EACjF,MAAM,SAAS,IAAI,YAAY,K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6B,KAA+C;EAG3F,OAFmB,KAAK,GAAG,WAAW,IAAI,UAClB,CAAC,CAAC,UAAU,IAAI,QAC5B;CACd;AACF;AAEA,eAAsB,kBAAkB,KAAa,QAAsC;CACzF,OAAO,gBAAgB,eAAe,KAAK,MAAM;AACnD"}
package/package.json CHANGED
@@ -1,26 +1,26 @@
1
1
  {
2
2
  "name": "@prisma-next/driver-mongo",
3
- "version": "0.12.0",
3
+ "version": "0.13.0-dev.2",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "description": "MongoDB driver for Prisma Next",
8
8
  "dependencies": {
9
- "@prisma-next/errors": "0.12.0",
10
- "@prisma-next/framework-components": "0.12.0",
11
- "@prisma-next/mongo-lowering": "0.12.0",
12
- "@prisma-next/mongo-wire": "0.12.0",
13
- "@prisma-next/utils": "0.12.0"
9
+ "@prisma-next/errors": "0.13.0-dev.2",
10
+ "@prisma-next/framework-components": "0.13.0-dev.2",
11
+ "@prisma-next/mongo-lowering": "0.13.0-dev.2",
12
+ "@prisma-next/mongo-wire": "0.13.0-dev.2",
13
+ "@prisma-next/utils": "0.13.0-dev.2"
14
14
  },
15
15
  "devDependencies": {
16
16
  "mongodb": "^7.2.0",
17
- "@prisma-next/test-utils": "0.12.0",
18
- "@prisma-next/tsconfig": "0.12.0",
19
- "@prisma-next/tsdown": "0.12.0",
20
- "mongodb-memory-server": "11.1.0",
21
- "tsdown": "0.22.0",
17
+ "@prisma-next/test-utils": "0.13.0-dev.2",
18
+ "@prisma-next/tsconfig": "0.13.0-dev.2",
19
+ "@prisma-next/tsdown": "0.13.0-dev.2",
20
+ "mongodb-memory-server": "11.2.0",
21
+ "tsdown": "0.22.1",
22
22
  "typescript": "5.9.3",
23
- "vitest": "4.1.6"
23
+ "vitest": "4.1.8"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "mongodb": "^7.0.0",
@@ -1,29 +1,19 @@
1
1
  import { errorRuntime } from '@prisma-next/errors/execution';
2
- import type {
3
- ControlDriverDescriptor,
4
- ControlDriverInstance,
5
- } from '@prisma-next/framework-components/control';
2
+ import type { ControlDriverDescriptor } from '@prisma-next/framework-components/control';
3
+ import type { MongoControlDriverInstance } from '@prisma-next/mongo-lowering';
6
4
  import { redactDatabaseUrl } from '@prisma-next/utils/redact-db-url';
7
5
  import { type Db, MongoClient } from 'mongodb';
8
6
  import { DRIVER_INFO } from '../core/driver-info';
7
+ import { MongoDriverImpl } from '../mongo-driver';
9
8
 
10
- export class MongoControlDriver implements ControlDriverInstance<'mongo', 'mongo'> {
9
+ export class MongoControlDriver extends MongoDriverImpl implements MongoControlDriverInstance {
11
10
  readonly familyId = 'mongo' as const;
12
11
  readonly targetId = 'mongo' as const;
13
- readonly db: Db;
14
- readonly #client: MongoClient;
12
+ override readonly db: Db;
15
13
 
16
- constructor(db: Db, client: MongoClient) {
14
+ constructor(db: Db, mongoClient: MongoClient) {
15
+ super(db, mongoClient);
17
16
  this.db = db;
18
- this.#client = client;
19
- }
20
-
21
- query(_sql: string, _params?: readonly unknown[]): Promise<never> {
22
- throw new Error('MongoDB control driver does not support SQL queries');
23
- }
24
-
25
- async close(): Promise<void> {
26
- await this.#client.close();
27
17
  }
28
18
  }
29
19
 
@@ -21,12 +21,12 @@ import { type Db, MongoClient } from 'mongodb';
21
21
  import { DRIVER_INFO } from './core/driver-info';
22
22
 
23
23
  export class MongoDriverImpl implements MongoDriver {
24
- readonly #db: Db;
25
- readonly #client: MongoClient | undefined;
24
+ protected readonly db: Db;
25
+ protected readonly client: MongoClient | undefined;
26
26
 
27
- private constructor(db: Db, client: MongoClient | undefined) {
28
- this.#db = db;
29
- this.#client = client;
27
+ protected constructor(db: Db, client: MongoClient | undefined) {
28
+ this.db = db;
29
+ this.client = client;
30
30
  }
31
31
 
32
32
  static async fromConnection(uri: string, dbName: string): Promise<MongoDriverImpl> {
@@ -42,23 +42,23 @@ export class MongoDriverImpl implements MongoDriver {
42
42
  execute<Row = Record<string, unknown>>(wireCommand: AnyMongoWireCommand): AsyncIterable<Row> {
43
43
  switch (wireCommand.kind) {
44
44
  case 'insertOne':
45
- return this.#executeInsertOneCommand(wireCommand) as AsyncIterable<Row>;
45
+ return this.executeInsertOneCommand(wireCommand) as AsyncIterable<Row>;
46
46
  case 'updateOne':
47
- return this.#executeUpdateOneCommand(wireCommand) as AsyncIterable<Row>;
47
+ return this.executeUpdateOneCommand(wireCommand) as AsyncIterable<Row>;
48
48
  case 'insertMany':
49
- return this.#executeInsertManyCommand(wireCommand) as AsyncIterable<Row>;
49
+ return this.executeInsertManyCommand(wireCommand) as AsyncIterable<Row>;
50
50
  case 'updateMany':
51
- return this.#executeUpdateManyCommand(wireCommand) as AsyncIterable<Row>;
51
+ return this.executeUpdateManyCommand(wireCommand) as AsyncIterable<Row>;
52
52
  case 'deleteOne':
53
- return this.#executeDeleteOneCommand(wireCommand) as AsyncIterable<Row>;
53
+ return this.executeDeleteOneCommand(wireCommand) as AsyncIterable<Row>;
54
54
  case 'deleteMany':
55
- return this.#executeDeleteManyCommand(wireCommand) as AsyncIterable<Row>;
55
+ return this.executeDeleteManyCommand(wireCommand) as AsyncIterable<Row>;
56
56
  case 'findOneAndUpdate':
57
- return this.#executeFindOneAndUpdateCommand(wireCommand) as AsyncIterable<Row>;
57
+ return this.executeFindOneAndUpdateCommand(wireCommand) as AsyncIterable<Row>;
58
58
  case 'findOneAndDelete':
59
- return this.#executeFindOneAndDeleteCommand(wireCommand) as AsyncIterable<Row>;
59
+ return this.executeFindOneAndDeleteCommand(wireCommand) as AsyncIterable<Row>;
60
60
  case 'aggregate':
61
- return this.#executeAggregateCommand<Row>(wireCommand);
61
+ return this.executeAggregateCommand<Row>(wireCommand);
62
62
  // v8 ignore next 4
63
63
  default: {
64
64
  const _exhaustive: never = wireCommand;
@@ -68,17 +68,21 @@ export class MongoDriverImpl implements MongoDriver {
68
68
  }
69
69
 
70
70
  async close(): Promise<void> {
71
- await this.#client?.close();
71
+ await this.client?.close();
72
72
  }
73
73
 
74
- async *#executeInsertOneCommand(cmd: InsertOneWireCommand): AsyncIterable<InsertOneResult> {
75
- const collection = this.#db.collection(cmd.collection);
74
+ protected async *executeInsertOneCommand(
75
+ cmd: InsertOneWireCommand,
76
+ ): AsyncIterable<InsertOneResult> {
77
+ const collection = this.db.collection(cmd.collection);
76
78
  const result = await collection.insertOne(cmd.document);
77
79
  yield { insertedId: result.insertedId };
78
80
  }
79
81
 
80
- async *#executeUpdateOneCommand(cmd: UpdateOneWireCommand): AsyncIterable<UpdateOneResult> {
81
- const collection = this.#db.collection(cmd.collection);
82
+ protected async *executeUpdateOneCommand(
83
+ cmd: UpdateOneWireCommand,
84
+ ): AsyncIterable<UpdateOneResult> {
85
+ const collection = this.db.collection(cmd.collection);
82
86
  const result = await collection.updateOne(cmd.filter, cmd.update, { upsert: cmd.upsert });
83
87
  yield {
84
88
  matchedCount: result.matchedCount,
@@ -88,15 +92,19 @@ export class MongoDriverImpl implements MongoDriver {
88
92
  };
89
93
  }
90
94
 
91
- async *#executeInsertManyCommand(cmd: InsertManyWireCommand): AsyncIterable<InsertManyResult> {
92
- const collection = this.#db.collection(cmd.collection);
95
+ protected async *executeInsertManyCommand(
96
+ cmd: InsertManyWireCommand,
97
+ ): AsyncIterable<InsertManyResult> {
98
+ const collection = this.db.collection(cmd.collection);
93
99
  const result = await collection.insertMany(cmd.documents as Record<string, unknown>[]);
94
100
  const insertedIds = Object.values(result.insertedIds);
95
101
  yield { insertedIds, insertedCount: result.insertedCount };
96
102
  }
97
103
 
98
- async *#executeUpdateManyCommand(cmd: UpdateManyWireCommand): AsyncIterable<UpdateManyResult> {
99
- const collection = this.#db.collection(cmd.collection);
104
+ protected async *executeUpdateManyCommand(
105
+ cmd: UpdateManyWireCommand,
106
+ ): AsyncIterable<UpdateManyResult> {
107
+ const collection = this.db.collection(cmd.collection);
100
108
  const result = await collection.updateMany(cmd.filter, cmd.update, { upsert: cmd.upsert });
101
109
  yield {
102
110
  matchedCount: result.matchedCount,
@@ -106,22 +114,26 @@ export class MongoDriverImpl implements MongoDriver {
106
114
  };
107
115
  }
108
116
 
109
- async *#executeDeleteOneCommand(cmd: DeleteOneWireCommand): AsyncIterable<DeleteOneResult> {
110
- const collection = this.#db.collection(cmd.collection);
117
+ protected async *executeDeleteOneCommand(
118
+ cmd: DeleteOneWireCommand,
119
+ ): AsyncIterable<DeleteOneResult> {
120
+ const collection = this.db.collection(cmd.collection);
111
121
  const result = await collection.deleteOne(cmd.filter);
112
122
  yield { deletedCount: result.deletedCount };
113
123
  }
114
124
 
115
- async *#executeDeleteManyCommand(cmd: DeleteManyWireCommand): AsyncIterable<DeleteManyResult> {
116
- const collection = this.#db.collection(cmd.collection);
125
+ protected async *executeDeleteManyCommand(
126
+ cmd: DeleteManyWireCommand,
127
+ ): AsyncIterable<DeleteManyResult> {
128
+ const collection = this.db.collection(cmd.collection);
117
129
  const result = await collection.deleteMany(cmd.filter);
118
130
  yield { deletedCount: result.deletedCount };
119
131
  }
120
132
 
121
- async *#executeFindOneAndUpdateCommand(
133
+ protected async *executeFindOneAndUpdateCommand(
122
134
  cmd: FindOneAndUpdateWireCommand,
123
135
  ): AsyncIterable<Record<string, unknown>> {
124
- const collection = this.#db.collection(cmd.collection);
136
+ const collection = this.db.collection(cmd.collection);
125
137
  const result = await collection.findOneAndUpdate(cmd.filter, cmd.update, {
126
138
  upsert: cmd.upsert,
127
139
  ...(cmd.returnDocument != null ? { returnDocument: cmd.returnDocument } : {}),
@@ -132,10 +144,10 @@ export class MongoDriverImpl implements MongoDriver {
132
144
  }
133
145
  }
134
146
 
135
- async *#executeFindOneAndDeleteCommand(
147
+ protected async *executeFindOneAndDeleteCommand(
136
148
  cmd: FindOneAndDeleteWireCommand,
137
149
  ): AsyncIterable<Record<string, unknown>> {
138
- const collection = this.#db.collection(cmd.collection);
150
+ const collection = this.db.collection(cmd.collection);
139
151
  const result = await collection.findOneAndDelete(cmd.filter, {
140
152
  ...(cmd.sort != null ? { sort: cmd.sort } : {}),
141
153
  });
@@ -144,8 +156,8 @@ export class MongoDriverImpl implements MongoDriver {
144
156
  }
145
157
  }
146
158
 
147
- async *#executeAggregateCommand<Row>(cmd: AggregateWireCommand): AsyncIterable<Row> {
148
- const collection = this.#db.collection(cmd.collection);
159
+ protected async *executeAggregateCommand<Row>(cmd: AggregateWireCommand): AsyncIterable<Row> {
160
+ const collection = this.db.collection(cmd.collection);
149
161
  const cursor = collection.aggregate(cmd.pipeline as Record<string, unknown>[]);
150
162
  yield* cursor as AsyncIterable<Row>;
151
163
  }
@@ -1,10 +0,0 @@
1
- //#endregion
2
- //#region src/core/driver-info.ts
3
- const DRIVER_INFO = {
4
- name: "Prisma",
5
- version: "0.12.0"
6
- };
7
- //#endregion
8
- export { DRIVER_INFO as t };
9
-
10
- //# sourceMappingURL=driver-info-FCZA4IPt.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"driver-info-FCZA4IPt.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;AAAQ"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/mongo-driver.ts"],"mappings":";;;;;cAsBa,eAAA,YAA2B,WAAA;EAAA;UAI/B,WAAA,CAAA;EAAA,OAKM,cAAA,CAAe,GAAA,UAAa,MAAA,WAAiB,OAAA,CAAQ,eAAA;EAAA,OAM3D,MAAA,CAAO,EAAA,EAAI,EAAA,GAAK,eAAA;EAIvB,OAAA,OAAc,MAAA,kBAAA,CAAyB,WAAA,EAAa,mBAAA,GAAsB,aAAA,CAAc,GAAA;EA4BlF,KAAA,CAAA,GAAS,OAAA;AAAA;AAAA,iBAoFK,iBAAA,CAAkB,GAAA,UAAa,MAAA,WAAiB,OAAO,CAAC,WAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":["#db","#client","#executeInsertOneCommand","#executeUpdateOneCommand","#executeInsertManyCommand","#executeUpdateManyCommand","#executeDeleteOneCommand","#executeDeleteManyCommand","#executeFindOneAndUpdateCommand","#executeFindOneAndDeleteCommand","#executeAggregateCommand","_exhaustive"],"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;CACA;CAEA,YAAoB,IAAQ,QAAiC;EAC3D,KAAKA,MAAM;EACX,KAAKC,UAAU;CACjB;CAEA,aAAa,eAAe,KAAa,QAA0C;EACjF,MAAM,SAAS,IAAI,YAAY,KAAK,EAAE,YAAY,YAAY,CAAC;EAC/D,MAAM,OAAO,QAAQ;EACrB,OAAO,IAAI,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