@prisma-next/driver-mongo 0.3.0-dev.147 → 0.3.0-dev.162
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.d.mts +17 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +55 -0
- package/dist/control.mjs.map +1 -0
- package/dist/driver-info-CwDLvmz0.mjs +13 -0
- package/dist/driver-info-CwDLvmz0.mjs.map +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -6
- package/src/core/driver-info.ts +3 -0
- package/src/exports/control.ts +65 -0
- package/src/mongo-driver.ts +2 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Db, MongoClient } from "mongodb";
|
|
2
|
+
import { ControlDriverDescriptor, ControlDriverInstance } from "@prisma-next/framework-components/control";
|
|
3
|
+
|
|
4
|
+
//#region src/exports/control.d.ts
|
|
5
|
+
declare class MongoControlDriver implements ControlDriverInstance<'mongo', 'mongo'> {
|
|
6
|
+
#private;
|
|
7
|
+
readonly familyId: "mongo";
|
|
8
|
+
readonly targetId: "mongo";
|
|
9
|
+
readonly db: Db;
|
|
10
|
+
constructor(db: Db, client: MongoClient);
|
|
11
|
+
query(_sql: string, _params?: readonly unknown[]): Promise<never>;
|
|
12
|
+
close(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
declare const mongoControlDriverDescriptor: ControlDriverDescriptor<'mongo', 'mongo', MongoControlDriver>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { MongoControlDriver, mongoControlDriverDescriptor as default };
|
|
17
|
+
//# sourceMappingURL=control.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/exports/control.ts"],"sourcesContent":[],"mappings":";;;;cASa,kBAAA,YAA8B;;EAA9B,SAAA,QAAA,EAAA,OAAmB;EAGjB,SAAA,QAAA,EAAA,OAAA;EAGG,SAAA,EAAA,EAHH,EAGG;EAAY,WAAA,CAAA,EAAA,EAAZ,EAAY,EAAA,MAAA,EAAA,WAAA;EAKuB,KAAA,CAAA,IAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAAA,SAAA,OAAA,EAAA,CAAA,EAAA,OAAA,CAAA,KAAA,CAAA;EAIpC,KAAA,CAAA,CAAA,EAAA,OAAA,CAAA,IAAA,CAAA;;cAKX,4BApB0D,EAoB5B,uBApB4B,CAAA,OAAA,EAAA,OAAA,EAoBc,kBApBd,CAAA"}
|
package/dist/control.mjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { t as DRIVER_INFO } from "./driver-info-CwDLvmz0.mjs";
|
|
2
|
+
import { MongoClient } from "mongodb";
|
|
3
|
+
import { errorRuntime } from "@prisma-next/errors/execution";
|
|
4
|
+
import { redactDatabaseUrl } from "@prisma-next/utils/redact-db-url";
|
|
5
|
+
|
|
6
|
+
//#region src/exports/control.ts
|
|
7
|
+
var MongoControlDriver = class {
|
|
8
|
+
familyId = "mongo";
|
|
9
|
+
targetId = "mongo";
|
|
10
|
+
db;
|
|
11
|
+
#client;
|
|
12
|
+
constructor(db, client) {
|
|
13
|
+
this.db = db;
|
|
14
|
+
this.#client = client;
|
|
15
|
+
}
|
|
16
|
+
query(_sql, _params) {
|
|
17
|
+
throw new Error("MongoDB control driver does not support SQL queries");
|
|
18
|
+
}
|
|
19
|
+
async close() {
|
|
20
|
+
await this.#client.close();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const mongoControlDriverDescriptor = {
|
|
24
|
+
kind: "driver",
|
|
25
|
+
familyId: "mongo",
|
|
26
|
+
targetId: "mongo",
|
|
27
|
+
id: "mongo",
|
|
28
|
+
version: DRIVER_INFO.version,
|
|
29
|
+
capabilities: {},
|
|
30
|
+
async create(url) {
|
|
31
|
+
const client = new MongoClient(url, {
|
|
32
|
+
serverSelectionTimeoutMS: 5e3,
|
|
33
|
+
connectTimeoutMS: 5e3,
|
|
34
|
+
driverInfo: DRIVER_INFO
|
|
35
|
+
});
|
|
36
|
+
try {
|
|
37
|
+
await client.connect();
|
|
38
|
+
return new MongoControlDriver(client.db(), client);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
try {
|
|
41
|
+
await client.close();
|
|
42
|
+
} catch {}
|
|
43
|
+
throw errorRuntime("Database connection failed", {
|
|
44
|
+
why: error instanceof Error ? error.message : String(error),
|
|
45
|
+
fix: "Verify the MongoDB URL, ensure the database is reachable, and confirm credentials/permissions",
|
|
46
|
+
meta: { ...redactDatabaseUrl(url) }
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var control_default = mongoControlDriverDescriptor;
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { MongoControlDriver, control_default as default };
|
|
55
|
+
//# sourceMappingURL=control.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.mjs","names":["#client","mongoControlDriverDescriptor: ControlDriverDescriptor<'mongo', 'mongo', MongoControlDriver>"],"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,AAAS,WAAW;CACpB,AAAS,WAAW;CACpB,AAAS;CACT,CAASA;CAET,YAAY,IAAQ,QAAqB;AACvC,OAAK,KAAK;AACV,QAAKA,SAAU;;CAGjB,MAAM,MAAc,SAA8C;AAChE,QAAM,IAAI,MAAM,sDAAsD;;CAGxE,MAAM,QAAuB;AAC3B,QAAM,MAAKA,OAAQ,OAAO;;;AAI9B,MAAMC,+BACJ;CACE,MAAM;CACN,UAAU;CACV,UAAU;CACV,IAAI;CACJ,SAAS,YAAY;CACrB,cAAc,EAAE;CAChB,MAAM,OAAO,KAA0C;EACrD,MAAM,SAAS,IAAI,YAAY,KAAK;GAClC,0BAA0B;GAC1B,kBAAkB;GAClB,YAAY;GACb,CAAC;AACF,MAAI;AACF,SAAM,OAAO,SAAS;AAEtB,UAAO,IAAI,mBADA,OAAO,IAAI,EACY,OAAO;WAClC,OAAO;AACd,OAAI;AACF,UAAM,OAAO,OAAO;WACd;AAKR,SAAM,aAAa,8BAA8B;IAC/C,KAHc,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;IAIpE,KAAK;IACL,MAAM,EAAE,GAJO,kBAAkB,IAAI,EAIhB;IACtB,CAAC;;;CAGP;AAEH,sBAAe"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region package.json
|
|
2
|
+
var version = "0.3.0-dev.162";
|
|
3
|
+
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/core/driver-info.ts
|
|
6
|
+
const DRIVER_INFO = {
|
|
7
|
+
name: "Prisma",
|
|
8
|
+
version
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { DRIVER_INFO as t };
|
|
13
|
+
//# sourceMappingURL=driver-info-CwDLvmz0.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver-info-CwDLvmz0.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"}
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/mongo-driver.ts"],"sourcesContent":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/mongo-driver.ts"],"sourcesContent":[],"mappings":";;;iBAkIsB,iBAAA,+BAAgD,QAAQ"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as DRIVER_INFO } from "./driver-info-CwDLvmz0.mjs";
|
|
1
2
|
import { MongoClient } from "mongodb";
|
|
2
3
|
|
|
3
4
|
//#region src/mongo-driver.ts
|
|
@@ -74,7 +75,7 @@ var MongoDriverImpl = class {
|
|
|
74
75
|
}
|
|
75
76
|
};
|
|
76
77
|
async function createMongoDriver(uri, dbName) {
|
|
77
|
-
const client = new MongoClient(uri);
|
|
78
|
+
const client = new MongoClient(uri, { driverInfo: DRIVER_INFO });
|
|
78
79
|
await client.connect();
|
|
79
80
|
return new MongoDriverImpl(client.db(dbName), client);
|
|
80
81
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -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';\n\nclass MongoDriverImpl implements MongoDriver {\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 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 const client = new MongoClient(uri);\n await client.connect();\n const db = client.db(dbName);\n return new MongoDriverImpl(db, client);\n}\n"],"mappings":"
|
|
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\nclass MongoDriverImpl implements MongoDriver {\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 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 const client = new MongoClient(uri, { driverInfo: DRIVER_INFO });\n await client.connect();\n const db = client.db(dbName);\n return new MongoDriverImpl(db, client);\n}\n"],"mappings":";;;;AAsBA,IAAM,kBAAN,MAA6C;CAC3C,CAASA;CACT,CAASC;CAET,YAAY,IAAQ,QAAqB;AACvC,QAAKD,KAAM;AACX,QAAKC,SAAU;;CAGjB,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,YAAY;GACpD,KAAK,YACH,QAAO,MAAKC,wBAAyB,YAAY;GACnD,KAAK,aACH,QAAO,MAAKC,yBAA0B,YAAY;GACpD,KAAK,mBACH,QAAO,MAAKC,+BAAgC,YAAY;GAC1D,KAAK,mBACH,QAAO,MAAKC,+BAAgC,YAAY;GAC1D,KAAK,YACH,QAAO,MAAKC,wBAA8B,YAAY;GAExD,SAAS;IACP,MAAMC,cAAqB;AAC3B,UAAM,IAAI,MAAM,8BAA+B,YAAiC,OAAO;;;;CAK7F,MAAM,QAAuB;AAC3B,QAAM,MAAKV,OAAQ,OAAO;;CAG5B,QAAOC,wBAAyB,KAA2D;AAGzF,QAAM,EAAE,aADO,MADI,MAAKF,GAAI,WAAW,IAAI,WAAW,CACtB,UAAU,IAAI,SAAS,EAC5B,YAAY;;CAGzC,QAAOG,wBAAyB,KAA2D;EAEzF,MAAM,SAAS,MADI,MAAKH,GAAI,WAAW,IAAI,WAAW,CACtB,UAAU,IAAI,QAAQ,IAAI,OAAO;AACjE,QAAM;GAAE,cAAc,OAAO;GAAc,eAAe,OAAO;GAAe;;CAGlF,QAAOI,yBAA0B,KAA6D;EAE5F,MAAM,SAAS,MADI,MAAKJ,GAAI,WAAW,IAAI,WAAW,CACtB,WAAW,IAAI,UAAuC;AAEtF,QAAM;GAAE,aADY,OAAO,OAAO,OAAO,YAAY;GAChC,eAAe,OAAO;GAAe;;CAG5D,QAAOK,yBAA0B,KAA6D;EAE5F,MAAM,SAAS,MADI,MAAKL,GAAI,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;CACzF,MAAM,SAAS,IAAI,YAAY,KAAK,EAAE,YAAY,aAAa,CAAC;AAChE,OAAM,OAAO,SAAS;AAEtB,QAAO,IAAI,gBADA,OAAO,GAAG,OAAO,EACG,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/driver-mongo",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.162",
|
|
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/
|
|
10
|
-
"@prisma-next/mongo-
|
|
9
|
+
"@prisma-next/framework-components": "0.3.0-dev.162",
|
|
10
|
+
"@prisma-next/mongo-lowering": "0.3.0-dev.162",
|
|
11
|
+
"@prisma-next/mongo-wire": "0.3.0-dev.162",
|
|
12
|
+
"@prisma-next/utils": "0.3.0-dev.162",
|
|
13
|
+
"@prisma-next/errors": "0.3.0-dev.162"
|
|
11
14
|
},
|
|
12
15
|
"devDependencies": {
|
|
13
|
-
"mongodb-memory-server": "
|
|
16
|
+
"mongodb-memory-server": "10.4.3",
|
|
14
17
|
"tsdown": "0.18.4",
|
|
15
18
|
"typescript": "5.9.3",
|
|
16
19
|
"vitest": "4.0.17",
|
|
17
20
|
"@prisma-next/test-utils": "0.0.1",
|
|
18
|
-
"@prisma-next/
|
|
19
|
-
"@prisma-next/
|
|
21
|
+
"@prisma-next/tsconfig": "0.0.0",
|
|
22
|
+
"@prisma-next/tsdown": "0.0.0"
|
|
20
23
|
},
|
|
21
24
|
"files": [
|
|
22
25
|
"dist",
|
|
@@ -24,6 +27,7 @@
|
|
|
24
27
|
],
|
|
25
28
|
"exports": {
|
|
26
29
|
".": "./dist/index.mjs",
|
|
30
|
+
"./control": "./dist/control.mjs",
|
|
27
31
|
"./package.json": "./package.json"
|
|
28
32
|
},
|
|
29
33
|
"main": "./dist/index.mjs",
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { errorRuntime } from '@prisma-next/errors/execution';
|
|
2
|
+
import type {
|
|
3
|
+
ControlDriverDescriptor,
|
|
4
|
+
ControlDriverInstance,
|
|
5
|
+
} from '@prisma-next/framework-components/control';
|
|
6
|
+
import { redactDatabaseUrl } from '@prisma-next/utils/redact-db-url';
|
|
7
|
+
import { type Db, MongoClient } from 'mongodb';
|
|
8
|
+
import { DRIVER_INFO } from '../core/driver-info';
|
|
9
|
+
|
|
10
|
+
export class MongoControlDriver implements ControlDriverInstance<'mongo', 'mongo'> {
|
|
11
|
+
readonly familyId = 'mongo' as const;
|
|
12
|
+
readonly targetId = 'mongo' as const;
|
|
13
|
+
readonly db: Db;
|
|
14
|
+
readonly #client: MongoClient;
|
|
15
|
+
|
|
16
|
+
constructor(db: Db, client: MongoClient) {
|
|
17
|
+
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
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const mongoControlDriverDescriptor: ControlDriverDescriptor<'mongo', 'mongo', MongoControlDriver> =
|
|
31
|
+
{
|
|
32
|
+
kind: 'driver',
|
|
33
|
+
familyId: 'mongo',
|
|
34
|
+
targetId: 'mongo',
|
|
35
|
+
id: 'mongo',
|
|
36
|
+
version: DRIVER_INFO.version,
|
|
37
|
+
capabilities: {},
|
|
38
|
+
async create(url: string): Promise<MongoControlDriver> {
|
|
39
|
+
const client = new MongoClient(url, {
|
|
40
|
+
serverSelectionTimeoutMS: 5000,
|
|
41
|
+
connectTimeoutMS: 5000,
|
|
42
|
+
driverInfo: DRIVER_INFO,
|
|
43
|
+
});
|
|
44
|
+
try {
|
|
45
|
+
await client.connect();
|
|
46
|
+
const db = client.db();
|
|
47
|
+
return new MongoControlDriver(db, client);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
try {
|
|
50
|
+
await client.close();
|
|
51
|
+
} catch {
|
|
52
|
+
// ignore cleanup error
|
|
53
|
+
}
|
|
54
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
55
|
+
const redacted = redactDatabaseUrl(url);
|
|
56
|
+
throw errorRuntime('Database connection failed', {
|
|
57
|
+
why: message,
|
|
58
|
+
fix: 'Verify the MongoDB URL, ensure the database is reachable, and confirm credentials/permissions',
|
|
59
|
+
meta: { ...redacted },
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export default mongoControlDriverDescriptor;
|
package/src/mongo-driver.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
UpdateOneWireCommand,
|
|
19
19
|
} from '@prisma-next/mongo-wire';
|
|
20
20
|
import { type Db, MongoClient } from 'mongodb';
|
|
21
|
+
import { DRIVER_INFO } from './core/driver-info';
|
|
21
22
|
|
|
22
23
|
class MongoDriverImpl implements MongoDriver {
|
|
23
24
|
readonly #db: Db;
|
|
@@ -128,7 +129,7 @@ class MongoDriverImpl implements MongoDriver {
|
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
export async function createMongoDriver(uri: string, dbName: string): Promise<MongoDriver> {
|
|
131
|
-
const client = new MongoClient(uri);
|
|
132
|
+
const client = new MongoClient(uri, { driverInfo: DRIVER_INFO });
|
|
132
133
|
await client.connect();
|
|
133
134
|
const db = client.db(dbName);
|
|
134
135
|
return new MongoDriverImpl(db, client);
|