@prisma-next/driver-mongo 0.13.0-dev.4 → 0.13.0-dev.40
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 +1 -1
- package/dist/control.mjs +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{mongo-driver-BD4kGuv9.mjs → mongo-driver-CK90BuEZ.mjs} +59 -2
- package/dist/mongo-driver-CK90BuEZ.mjs.map +1 -0
- package/dist/{mongo-driver-CXhojUq7.d.mts → mongo-driver-CQXDeYe6.d.mts} +9 -3
- package/dist/mongo-driver-CQXDeYe6.d.mts.map +1 -0
- package/package.json +9 -9
- package/src/mongo-driver.ts +101 -2
- package/dist/mongo-driver-BD4kGuv9.mjs.map +0 -1
- package/dist/mongo-driver-CXhojUq7.d.mts.map +0 -1
package/dist/control.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as MongoDriverImpl } from "./mongo-driver-
|
|
1
|
+
import { t as MongoDriverImpl } from "./mongo-driver-CQXDeYe6.mjs";
|
|
2
2
|
import { Db, MongoClient } from "mongodb";
|
|
3
3
|
import { ControlDriverDescriptor } from "@prisma-next/framework-components/control";
|
|
4
4
|
import { MongoControlDriverInstance } from "@prisma-next/mongo-lowering";
|
package/dist/control.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as DRIVER_INFO, t as MongoDriverImpl } from "./mongo-driver-
|
|
1
|
+
import { r as DRIVER_INFO, t as MongoDriverImpl } from "./mongo-driver-CK90BuEZ.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";
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as createMongoDriver, t as MongoDriverImpl } from "./mongo-driver-
|
|
1
|
+
import { n as createMongoDriver, t as MongoDriverImpl } from "./mongo-driver-CQXDeYe6.mjs";
|
|
2
2
|
export { MongoDriverImpl, createMongoDriver };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as createMongoDriver, t as MongoDriverImpl } from "./mongo-driver-
|
|
1
|
+
import { n as createMongoDriver, t as MongoDriverImpl } from "./mongo-driver-CK90BuEZ.mjs";
|
|
2
2
|
export { MongoDriverImpl, createMongoDriver };
|
|
@@ -3,7 +3,7 @@ import { MongoClient } from "mongodb";
|
|
|
3
3
|
//#region src/core/driver-info.ts
|
|
4
4
|
const DRIVER_INFO = {
|
|
5
5
|
name: "Prisma",
|
|
6
|
-
version: "0.13.0-dev.
|
|
6
|
+
version: "0.13.0-dev.40"
|
|
7
7
|
};
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/mongo-driver.ts
|
|
@@ -37,6 +37,17 @@ var MongoDriverImpl = class MongoDriverImpl {
|
|
|
37
37
|
default: throw new Error(`Unknown wire command kind: ${wireCommand.kind}`);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
+
async run(wireCommand) {
|
|
41
|
+
switch (wireCommand.kind) {
|
|
42
|
+
case "createCollection": return this.executeCreateCollectionCommand(wireCommand);
|
|
43
|
+
case "createIndex": return this.executeCreateIndexCommand(wireCommand);
|
|
44
|
+
case "dropCollection": return this.executeDropCollectionCommand(wireCommand);
|
|
45
|
+
case "dropIndex": return this.executeDropIndexCommand(wireCommand);
|
|
46
|
+
case "collMod": return this.executeCollModCommand(wireCommand);
|
|
47
|
+
// v8 ignore next 4
|
|
48
|
+
default: throw new Error(`Unknown DDL wire command kind: ${wireCommand.kind}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
40
51
|
async close() {
|
|
41
52
|
await this.client?.close();
|
|
42
53
|
}
|
|
@@ -89,6 +100,52 @@ var MongoDriverImpl = class MongoDriverImpl {
|
|
|
89
100
|
async *executeAggregateCommand(cmd) {
|
|
90
101
|
yield* this.db.collection(cmd.collection).aggregate(cmd.pipeline);
|
|
91
102
|
}
|
|
103
|
+
async executeCreateCollectionCommand(cmd) {
|
|
104
|
+
const { validator, validationLevel, validationAction, capped, size, max, timeseries, collation, changeStreamPreAndPostImages, clusteredIndex } = cmd;
|
|
105
|
+
await this.db.createCollection(cmd.collection, {
|
|
106
|
+
...validator !== void 0 ? { validator } : {},
|
|
107
|
+
...validationLevel !== void 0 ? { validationLevel } : {},
|
|
108
|
+
...validationAction !== void 0 ? { validationAction } : {},
|
|
109
|
+
...capped !== void 0 ? { capped } : {},
|
|
110
|
+
...size !== void 0 ? { size } : {},
|
|
111
|
+
...max !== void 0 ? { max } : {},
|
|
112
|
+
...timeseries !== void 0 ? { timeseries } : {},
|
|
113
|
+
...collation !== void 0 ? { collation } : {},
|
|
114
|
+
...changeStreamPreAndPostImages !== void 0 ? { changeStreamPreAndPostImages } : {},
|
|
115
|
+
...clusteredIndex !== void 0 ? { clusteredIndex } : {}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
async executeCreateIndexCommand(cmd) {
|
|
119
|
+
const { unique, sparse, expireAfterSeconds, partialFilterExpression, name, wildcardProjection, collation, weights, default_language, language_override } = cmd;
|
|
120
|
+
await this.db.collection(cmd.collection).createIndex(cmd.key, {
|
|
121
|
+
...unique !== void 0 ? { unique } : {},
|
|
122
|
+
...sparse !== void 0 ? { sparse } : {},
|
|
123
|
+
...expireAfterSeconds !== void 0 ? { expireAfterSeconds } : {},
|
|
124
|
+
...partialFilterExpression !== void 0 ? { partialFilterExpression } : {},
|
|
125
|
+
...name !== void 0 ? { name } : {},
|
|
126
|
+
...wildcardProjection !== void 0 ? { wildcardProjection } : {},
|
|
127
|
+
...collation !== void 0 ? { collation } : {},
|
|
128
|
+
...weights !== void 0 ? { weights } : {},
|
|
129
|
+
...default_language !== void 0 ? { default_language } : {},
|
|
130
|
+
...language_override !== void 0 ? { language_override } : {}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
async executeDropCollectionCommand(cmd) {
|
|
134
|
+
await this.db.collection(cmd.collection).drop();
|
|
135
|
+
}
|
|
136
|
+
async executeDropIndexCommand(cmd) {
|
|
137
|
+
await this.db.collection(cmd.collection).dropIndex(cmd.name);
|
|
138
|
+
}
|
|
139
|
+
async executeCollModCommand(cmd) {
|
|
140
|
+
const { validator, validationLevel, validationAction, changeStreamPreAndPostImages } = cmd;
|
|
141
|
+
await this.db.command({
|
|
142
|
+
collMod: cmd.collection,
|
|
143
|
+
...validator !== void 0 ? { validator } : {},
|
|
144
|
+
...validationLevel !== void 0 ? { validationLevel } : {},
|
|
145
|
+
...validationAction !== void 0 ? { validationAction } : {},
|
|
146
|
+
...changeStreamPreAndPostImages !== void 0 ? { changeStreamPreAndPostImages } : {}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
92
149
|
};
|
|
93
150
|
async function createMongoDriver(uri, dbName) {
|
|
94
151
|
return MongoDriverImpl.fromConnection(uri, dbName);
|
|
@@ -96,4 +153,4 @@ async function createMongoDriver(uri, dbName) {
|
|
|
96
153
|
//#endregion
|
|
97
154
|
export { createMongoDriver as n, DRIVER_INFO as r, MongoDriverImpl as t };
|
|
98
155
|
|
|
99
|
-
//# sourceMappingURL=mongo-driver-
|
|
156
|
+
//# sourceMappingURL=mongo-driver-CK90BuEZ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo-driver-CK90BuEZ.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 AnyMongoDdlWireCommand,\n AnyMongoDmlWireCommand,\n CollModWireCommand,\n CreateCollectionWireCommand,\n CreateIndexWireCommand,\n DeleteManyResult,\n DeleteManyWireCommand,\n DeleteOneResult,\n DeleteOneWireCommand,\n DropCollectionWireCommand,\n DropIndexWireCommand,\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: AnyMongoDmlWireCommand): 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 run(wireCommand: AnyMongoDdlWireCommand): Promise<void> {\n switch (wireCommand.kind) {\n case 'createCollection':\n return this.executeCreateCollectionCommand(wireCommand);\n case 'createIndex':\n return this.executeCreateIndexCommand(wireCommand);\n case 'dropCollection':\n return this.executeDropCollectionCommand(wireCommand);\n case 'dropIndex':\n return this.executeDropIndexCommand(wireCommand);\n case 'collMod':\n return this.executeCollModCommand(wireCommand);\n // v8 ignore next 4\n default: {\n const _exhaustive: never = wireCommand;\n throw new Error(`Unknown DDL 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 protected async executeCreateCollectionCommand(cmd: CreateCollectionWireCommand): Promise<void> {\n const {\n validator,\n validationLevel,\n validationAction,\n capped,\n size,\n max,\n timeseries,\n collation,\n changeStreamPreAndPostImages,\n clusteredIndex,\n } = cmd;\n await this.db.createCollection(cmd.collection, {\n ...(validator !== undefined ? { validator } : {}),\n ...(validationLevel !== undefined ? { validationLevel } : {}),\n ...(validationAction !== undefined ? { validationAction } : {}),\n ...(capped !== undefined ? { capped } : {}),\n ...(size !== undefined ? { size } : {}),\n ...(max !== undefined ? { max } : {}),\n ...(timeseries !== undefined ? { timeseries } : {}),\n ...(collation !== undefined ? { collation } : {}),\n ...(changeStreamPreAndPostImages !== undefined ? { changeStreamPreAndPostImages } : {}),\n ...(clusteredIndex !== undefined ? { clusteredIndex } : {}),\n });\n }\n\n protected async executeCreateIndexCommand(cmd: CreateIndexWireCommand): Promise<void> {\n const {\n unique,\n sparse,\n expireAfterSeconds,\n partialFilterExpression,\n name,\n wildcardProjection,\n collation,\n weights,\n default_language,\n language_override,\n } = cmd;\n await this.db.collection(cmd.collection).createIndex(cmd.key, {\n ...(unique !== undefined ? { unique } : {}),\n ...(sparse !== undefined ? { sparse } : {}),\n ...(expireAfterSeconds !== undefined ? { expireAfterSeconds } : {}),\n ...(partialFilterExpression !== undefined ? { partialFilterExpression } : {}),\n ...(name !== undefined ? { name } : {}),\n ...(wildcardProjection !== undefined ? { wildcardProjection } : {}),\n ...(collation !== undefined ? { collation } : {}),\n ...(weights !== undefined ? { weights } : {}),\n ...(default_language !== undefined ? { default_language } : {}),\n ...(language_override !== undefined ? { language_override } : {}),\n });\n }\n\n protected async executeDropCollectionCommand(cmd: DropCollectionWireCommand): Promise<void> {\n await this.db.collection(cmd.collection).drop();\n }\n\n protected async executeDropIndexCommand(cmd: DropIndexWireCommand): Promise<void> {\n await this.db.collection(cmd.collection).dropIndex(cmd.name);\n }\n\n protected async executeCollModCommand(cmd: CollModWireCommand): Promise<void> {\n const { validator, validationLevel, validationAction, changeStreamPreAndPostImages } = cmd;\n await this.db.command({\n collMod: cmd.collection,\n ...(validator !== undefined ? { validator } : {}),\n ...(validationLevel !== undefined ? { validationLevel } : {}),\n ...(validationAction !== undefined ? { validationAction } : {}),\n ...(changeStreamPreAndPostImages !== undefined ? { changeStreamPreAndPostImages } : {}),\n });\n }\n}\n\nexport async function createMongoDriver(uri: string, dbName: string):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AW,iBAAiB,kBAAkB,iCAAiC;EACvF,MAAM,KAAK,GAAG,QAAQ;GACpB,SAAS,IAAI;GACb,GAAI,cAAc,KAAA,IAAY,EAAE,UAAU,IAAI,CAAC;GAC/C,GAAI,oBAAoB,KAAA,IAAY,EAAE,gBAAgB,IAAI,CAAC;GAC3D,GAAI,qBAAqB,KAAA,IAAY,EAAE,iBAAiB,IAAI,CAAC;GAC7D,GAAI,iCAAiC,KAAA,IAAY,EAAE,6BAA6B,IAAI,CAAC;EACvF,CAAC;CACH;AACF;AAEA,eAAsB,kBAAkB,KAAa,QAAsC;CACzF,OAAO,gBAAgB,eAAe,KAAK,MAAM;AACnD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Db, MongoClient } from "mongodb";
|
|
2
2
|
import { MongoDriver } from "@prisma-next/mongo-lowering";
|
|
3
|
-
import { AggregateWireCommand,
|
|
3
|
+
import { AggregateWireCommand, AnyMongoDdlWireCommand, AnyMongoDmlWireCommand, CollModWireCommand, CreateCollectionWireCommand, CreateIndexWireCommand, DeleteManyResult, DeleteManyWireCommand, DeleteOneResult, DeleteOneWireCommand, DropCollectionWireCommand, DropIndexWireCommand, FindOneAndDeleteWireCommand, FindOneAndUpdateWireCommand, InsertManyResult, InsertManyWireCommand, InsertOneResult, InsertOneWireCommand, UpdateManyResult, UpdateManyWireCommand, UpdateOneResult, UpdateOneWireCommand } from "@prisma-next/mongo-wire";
|
|
4
4
|
|
|
5
5
|
//#region src/mongo-driver.d.ts
|
|
6
6
|
declare class MongoDriverImpl implements MongoDriver {
|
|
@@ -9,7 +9,8 @@ declare class MongoDriverImpl implements MongoDriver {
|
|
|
9
9
|
protected constructor(db: Db, client: MongoClient | undefined);
|
|
10
10
|
static fromConnection(uri: string, dbName: string): Promise<MongoDriverImpl>;
|
|
11
11
|
static fromDb(db: Db): MongoDriverImpl;
|
|
12
|
-
execute<Row = Record<string, unknown>>(wireCommand:
|
|
12
|
+
execute<Row = Record<string, unknown>>(wireCommand: AnyMongoDmlWireCommand): AsyncIterable<Row>;
|
|
13
|
+
run(wireCommand: AnyMongoDdlWireCommand): Promise<void>;
|
|
13
14
|
close(): Promise<void>;
|
|
14
15
|
protected executeInsertOneCommand(cmd: InsertOneWireCommand): AsyncIterable<InsertOneResult>;
|
|
15
16
|
protected executeUpdateOneCommand(cmd: UpdateOneWireCommand): AsyncIterable<UpdateOneResult>;
|
|
@@ -20,8 +21,13 @@ declare class MongoDriverImpl implements MongoDriver {
|
|
|
20
21
|
protected executeFindOneAndUpdateCommand(cmd: FindOneAndUpdateWireCommand): AsyncIterable<Record<string, unknown>>;
|
|
21
22
|
protected executeFindOneAndDeleteCommand(cmd: FindOneAndDeleteWireCommand): AsyncIterable<Record<string, unknown>>;
|
|
22
23
|
protected executeAggregateCommand<Row>(cmd: AggregateWireCommand): AsyncIterable<Row>;
|
|
24
|
+
protected executeCreateCollectionCommand(cmd: CreateCollectionWireCommand): Promise<void>;
|
|
25
|
+
protected executeCreateIndexCommand(cmd: CreateIndexWireCommand): Promise<void>;
|
|
26
|
+
protected executeDropCollectionCommand(cmd: DropCollectionWireCommand): Promise<void>;
|
|
27
|
+
protected executeDropIndexCommand(cmd: DropIndexWireCommand): Promise<void>;
|
|
28
|
+
protected executeCollModCommand(cmd: CollModWireCommand): Promise<void>;
|
|
23
29
|
}
|
|
24
30
|
declare function createMongoDriver(uri: string, dbName: string): Promise<MongoDriver>;
|
|
25
31
|
//#endregion
|
|
26
32
|
export { createMongoDriver as n, MongoDriverImpl as t };
|
|
27
|
-
//# sourceMappingURL=mongo-driver-
|
|
33
|
+
//# sourceMappingURL=mongo-driver-CQXDeYe6.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo-driver-CQXDeYe6.d.mts","names":[],"sources":["../src/mongo-driver.ts"],"mappings":";;;;;cA4Ba,eAAA,YAA2B,WAAA;EAAA,mBACnB,EAAA,EAAI,EAAA;EAAA,mBACJ,MAAA,EAAQ,WAAA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sB,GAAA,EAAK,kBAAA,GAAqB,OAAA;AAAA;AAAA,iBAY5C,iBAAA,CAAkB,GAAA,UAAa,MAAA,WAAiB,OAAO,CAAC,WAAA"}
|
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/driver-mongo",
|
|
3
|
-
"version": "0.13.0-dev.
|
|
3
|
+
"version": "0.13.0-dev.40",
|
|
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.13.0-dev.
|
|
10
|
-
"@prisma-next/framework-components": "0.13.0-dev.
|
|
11
|
-
"@prisma-next/mongo-lowering": "0.13.0-dev.
|
|
12
|
-
"@prisma-next/mongo-wire": "0.13.0-dev.
|
|
13
|
-
"@prisma-next/utils": "0.13.0-dev.
|
|
9
|
+
"@prisma-next/errors": "0.13.0-dev.40",
|
|
10
|
+
"@prisma-next/framework-components": "0.13.0-dev.40",
|
|
11
|
+
"@prisma-next/mongo-lowering": "0.13.0-dev.40",
|
|
12
|
+
"@prisma-next/mongo-wire": "0.13.0-dev.40",
|
|
13
|
+
"@prisma-next/utils": "0.13.0-dev.40"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"mongodb": "^7.2.0",
|
|
17
|
-
"@prisma-next/test-utils": "0.13.0-dev.
|
|
18
|
-
"@prisma-next/tsconfig": "0.13.0-dev.
|
|
19
|
-
"@prisma-next/tsdown": "0.13.0-dev.
|
|
17
|
+
"@prisma-next/test-utils": "0.13.0-dev.40",
|
|
18
|
+
"@prisma-next/tsconfig": "0.13.0-dev.40",
|
|
19
|
+
"@prisma-next/tsdown": "0.13.0-dev.40",
|
|
20
20
|
"mongodb-memory-server": "11.2.0",
|
|
21
21
|
"tsdown": "0.22.1",
|
|
22
22
|
"typescript": "5.9.3",
|
package/src/mongo-driver.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { MongoDriver } from '@prisma-next/mongo-lowering';
|
|
2
2
|
import type {
|
|
3
3
|
AggregateWireCommand,
|
|
4
|
-
|
|
4
|
+
AnyMongoDdlWireCommand,
|
|
5
|
+
AnyMongoDmlWireCommand,
|
|
6
|
+
CollModWireCommand,
|
|
7
|
+
CreateCollectionWireCommand,
|
|
8
|
+
CreateIndexWireCommand,
|
|
5
9
|
DeleteManyResult,
|
|
6
10
|
DeleteManyWireCommand,
|
|
7
11
|
DeleteOneResult,
|
|
8
12
|
DeleteOneWireCommand,
|
|
13
|
+
DropCollectionWireCommand,
|
|
14
|
+
DropIndexWireCommand,
|
|
9
15
|
FindOneAndDeleteWireCommand,
|
|
10
16
|
FindOneAndUpdateWireCommand,
|
|
11
17
|
InsertManyResult,
|
|
@@ -39,7 +45,7 @@ export class MongoDriverImpl implements MongoDriver {
|
|
|
39
45
|
return new MongoDriverImpl(db, undefined);
|
|
40
46
|
}
|
|
41
47
|
|
|
42
|
-
execute<Row = Record<string, unknown>>(wireCommand:
|
|
48
|
+
execute<Row = Record<string, unknown>>(wireCommand: AnyMongoDmlWireCommand): AsyncIterable<Row> {
|
|
43
49
|
switch (wireCommand.kind) {
|
|
44
50
|
case 'insertOne':
|
|
45
51
|
return this.executeInsertOneCommand(wireCommand) as AsyncIterable<Row>;
|
|
@@ -67,6 +73,26 @@ export class MongoDriverImpl implements MongoDriver {
|
|
|
67
73
|
}
|
|
68
74
|
}
|
|
69
75
|
|
|
76
|
+
async run(wireCommand: AnyMongoDdlWireCommand): Promise<void> {
|
|
77
|
+
switch (wireCommand.kind) {
|
|
78
|
+
case 'createCollection':
|
|
79
|
+
return this.executeCreateCollectionCommand(wireCommand);
|
|
80
|
+
case 'createIndex':
|
|
81
|
+
return this.executeCreateIndexCommand(wireCommand);
|
|
82
|
+
case 'dropCollection':
|
|
83
|
+
return this.executeDropCollectionCommand(wireCommand);
|
|
84
|
+
case 'dropIndex':
|
|
85
|
+
return this.executeDropIndexCommand(wireCommand);
|
|
86
|
+
case 'collMod':
|
|
87
|
+
return this.executeCollModCommand(wireCommand);
|
|
88
|
+
// v8 ignore next 4
|
|
89
|
+
default: {
|
|
90
|
+
const _exhaustive: never = wireCommand;
|
|
91
|
+
throw new Error(`Unknown DDL wire command kind: ${(_exhaustive as { kind: string }).kind}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
70
96
|
async close(): Promise<void> {
|
|
71
97
|
await this.client?.close();
|
|
72
98
|
}
|
|
@@ -161,6 +187,79 @@ export class MongoDriverImpl implements MongoDriver {
|
|
|
161
187
|
const cursor = collection.aggregate(cmd.pipeline as Record<string, unknown>[]);
|
|
162
188
|
yield* cursor as AsyncIterable<Row>;
|
|
163
189
|
}
|
|
190
|
+
|
|
191
|
+
protected async executeCreateCollectionCommand(cmd: CreateCollectionWireCommand): Promise<void> {
|
|
192
|
+
const {
|
|
193
|
+
validator,
|
|
194
|
+
validationLevel,
|
|
195
|
+
validationAction,
|
|
196
|
+
capped,
|
|
197
|
+
size,
|
|
198
|
+
max,
|
|
199
|
+
timeseries,
|
|
200
|
+
collation,
|
|
201
|
+
changeStreamPreAndPostImages,
|
|
202
|
+
clusteredIndex,
|
|
203
|
+
} = cmd;
|
|
204
|
+
await this.db.createCollection(cmd.collection, {
|
|
205
|
+
...(validator !== undefined ? { validator } : {}),
|
|
206
|
+
...(validationLevel !== undefined ? { validationLevel } : {}),
|
|
207
|
+
...(validationAction !== undefined ? { validationAction } : {}),
|
|
208
|
+
...(capped !== undefined ? { capped } : {}),
|
|
209
|
+
...(size !== undefined ? { size } : {}),
|
|
210
|
+
...(max !== undefined ? { max } : {}),
|
|
211
|
+
...(timeseries !== undefined ? { timeseries } : {}),
|
|
212
|
+
...(collation !== undefined ? { collation } : {}),
|
|
213
|
+
...(changeStreamPreAndPostImages !== undefined ? { changeStreamPreAndPostImages } : {}),
|
|
214
|
+
...(clusteredIndex !== undefined ? { clusteredIndex } : {}),
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
protected async executeCreateIndexCommand(cmd: CreateIndexWireCommand): Promise<void> {
|
|
219
|
+
const {
|
|
220
|
+
unique,
|
|
221
|
+
sparse,
|
|
222
|
+
expireAfterSeconds,
|
|
223
|
+
partialFilterExpression,
|
|
224
|
+
name,
|
|
225
|
+
wildcardProjection,
|
|
226
|
+
collation,
|
|
227
|
+
weights,
|
|
228
|
+
default_language,
|
|
229
|
+
language_override,
|
|
230
|
+
} = cmd;
|
|
231
|
+
await this.db.collection(cmd.collection).createIndex(cmd.key, {
|
|
232
|
+
...(unique !== undefined ? { unique } : {}),
|
|
233
|
+
...(sparse !== undefined ? { sparse } : {}),
|
|
234
|
+
...(expireAfterSeconds !== undefined ? { expireAfterSeconds } : {}),
|
|
235
|
+
...(partialFilterExpression !== undefined ? { partialFilterExpression } : {}),
|
|
236
|
+
...(name !== undefined ? { name } : {}),
|
|
237
|
+
...(wildcardProjection !== undefined ? { wildcardProjection } : {}),
|
|
238
|
+
...(collation !== undefined ? { collation } : {}),
|
|
239
|
+
...(weights !== undefined ? { weights } : {}),
|
|
240
|
+
...(default_language !== undefined ? { default_language } : {}),
|
|
241
|
+
...(language_override !== undefined ? { language_override } : {}),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
protected async executeDropCollectionCommand(cmd: DropCollectionWireCommand): Promise<void> {
|
|
246
|
+
await this.db.collection(cmd.collection).drop();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
protected async executeDropIndexCommand(cmd: DropIndexWireCommand): Promise<void> {
|
|
250
|
+
await this.db.collection(cmd.collection).dropIndex(cmd.name);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
protected async executeCollModCommand(cmd: CollModWireCommand): Promise<void> {
|
|
254
|
+
const { validator, validationLevel, validationAction, changeStreamPreAndPostImages } = cmd;
|
|
255
|
+
await this.db.command({
|
|
256
|
+
collMod: cmd.collection,
|
|
257
|
+
...(validator !== undefined ? { validator } : {}),
|
|
258
|
+
...(validationLevel !== undefined ? { validationLevel } : {}),
|
|
259
|
+
...(validationAction !== undefined ? { validationAction } : {}),
|
|
260
|
+
...(changeStreamPreAndPostImages !== undefined ? { changeStreamPreAndPostImages } : {}),
|
|
261
|
+
});
|
|
262
|
+
}
|
|
164
263
|
}
|
|
165
264
|
|
|
166
265
|
export async function createMongoDriver(uri: string, dbName: string): Promise<MongoDriver> {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mongo-driver-BD4kGuv9.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,KAAK,EAAE,YAAY,YAAY,CAAC;EAC/D,MAAM,OAAO,QAAQ;EACrB,OAAO,IAAI,gBAAgB,OAAO,GAAG,MAAM,GAAG,MAAM;CACtD;CAEA,OAAO,OAAO,IAAyB;EACrC,OAAO,IAAI,gBAAgB,IAAI,KAAA,CAAS;CAC1C;CAEA,QAAuC,aAAsD;EAC3F,QAAQ,YAAY,MAApB;GACE,KAAK,aACH,OAAO,KAAK,wBAAwB,WAAW;GACjD,KAAK,aACH,OAAO,KAAK,wBAAwB,WAAW;GACjD,KAAK,cACH,OAAO,KAAK,yBAAyB,WAAW;GAClD,KAAK,cACH,OAAO,KAAK,yBAAyB,WAAW;GAClD,KAAK,aACH,OAAO,KAAK,wBAAwB,WAAW;GACjD,KAAK,cACH,OAAO,KAAK,yBAAyB,WAAW;GAClD,KAAK,oBACH,OAAO,KAAK,+BAA+B,WAAW;GACxD,KAAK,oBACH,OAAO,KAAK,+BAA+B,WAAW;GACxD,KAAK,aACH,OAAO,KAAK,wBAA6B,WAAW;;GAEtD,SAEE,MAAM,IAAI,MAAM,8BAA+BA,YAAiC,MAAM;EAE1F;CACF;CAEA,MAAM,QAAuB;EAC3B,MAAM,KAAK,QAAQ,MAAM;CAC3B;CAEA,OAAiB,wBACf,KACgC;EAGhC,MAAM,EAAE,aAAY,MAFD,KAAK,GAAG,WAAW,IAAI,UACZ,CAAC,CAAC,UAAU,IAAI,QAAQ,EAA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