@prisma-next/mongo-runtime 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/index.d.mts +17 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +31 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +50 -0
- package/src/exports/index.ts +2 -0
- package/src/mongo-runtime.ts +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @prisma-next/mongo-runtime
|
|
2
|
+
|
|
3
|
+
MongoDB runtime executor for Prisma Next.
|
|
4
|
+
|
|
5
|
+
## Responsibilities
|
|
6
|
+
|
|
7
|
+
- **Runtime executor**: `createMongoRuntime()` composes adapter and driver into a `MongoRuntime` that executes query plans
|
|
8
|
+
- **Command lowering**: Translates ORM query plans into MongoDB commands (`FindCommand`, `AggregateCommand`)
|
|
9
|
+
- **`$lookup` pipeline**: Builds aggregation pipelines for reference-relation includes
|
|
10
|
+
- **Lifecycle management**: Connection lifecycle via `close()`
|
|
11
|
+
|
|
12
|
+
## Dependencies
|
|
13
|
+
|
|
14
|
+
- **Depends on**:
|
|
15
|
+
- `@prisma-next/mongo-core` (contract types, query plan types, lowering context)
|
|
16
|
+
- `@prisma-next/runtime-executor` (`AsyncIterableResult` return type)
|
|
17
|
+
- **Depended on by**:
|
|
18
|
+
- Integration tests (`test/integration/test/mongo/`)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AsyncIterableResult } from "@prisma-next/runtime-executor";
|
|
2
|
+
import { MongoAdapter, MongoDriver, MongoLoweringContext, MongoQueryPlan } from "@prisma-next/mongo-core";
|
|
3
|
+
|
|
4
|
+
//#region src/mongo-runtime.d.ts
|
|
5
|
+
interface MongoRuntimeOptions {
|
|
6
|
+
readonly adapter: MongoAdapter;
|
|
7
|
+
readonly driver: MongoDriver;
|
|
8
|
+
readonly loweringContext: MongoLoweringContext;
|
|
9
|
+
}
|
|
10
|
+
interface MongoRuntime {
|
|
11
|
+
execute<Row>(plan: MongoQueryPlan<Row>): AsyncIterableResult<Row>;
|
|
12
|
+
close(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
declare function createMongoRuntime(options: MongoRuntimeOptions): MongoRuntime;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { type MongoRuntime, type MongoRuntimeOptions, createMongoRuntime };
|
|
17
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/mongo-runtime.ts"],"sourcesContent":[],"mappings":";;;;UAQiB,mBAAA;oBACG;EADH,SAAA,MAAA,EAEE,WAFiB;EAChB,SAAA,eAAA,EAEQ,oBAFR;;AAEQ,UAGX,YAAA,CAHW;EAAoB,OAAA,CAAA,GAAA,CAAA,CAAA,IAAA,EAI3B,cAJ2B,CAIZ,GAJY,CAAA,CAAA,EAIL,mBAJK,CAIe,GAJf,CAAA;EAG/B,KAAA,EAAA,EAEN,OAFkB,CAAA,IAAA,CAAA;;AACR,iBA+BL,kBAAA,CA/BK,OAAA,EA+BuB,mBA/BvB,CAAA,EA+B6C,YA/B7C"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AsyncIterableResult } from "@prisma-next/runtime-executor";
|
|
2
|
+
|
|
3
|
+
//#region src/mongo-runtime.ts
|
|
4
|
+
var MongoRuntimeImpl = class {
|
|
5
|
+
#adapter;
|
|
6
|
+
#driver;
|
|
7
|
+
#loweringContext;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.#adapter = options.adapter;
|
|
10
|
+
this.#driver = options.driver;
|
|
11
|
+
this.#loweringContext = options.loweringContext;
|
|
12
|
+
}
|
|
13
|
+
execute(plan) {
|
|
14
|
+
const executionPlan = this.#adapter.lower(plan, this.#loweringContext);
|
|
15
|
+
const iterable = this.#driver.execute(executionPlan.wireCommand);
|
|
16
|
+
async function* toGenerator() {
|
|
17
|
+
yield* iterable;
|
|
18
|
+
}
|
|
19
|
+
return new AsyncIterableResult(toGenerator());
|
|
20
|
+
}
|
|
21
|
+
async close() {
|
|
22
|
+
await this.#driver.close();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
function createMongoRuntime(options) {
|
|
26
|
+
return new MongoRuntimeImpl(options);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { createMongoRuntime };
|
|
31
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["#adapter","#driver","#loweringContext"],"sources":["../src/mongo-runtime.ts"],"sourcesContent":["import type {\n MongoAdapter,\n MongoDriver,\n MongoLoweringContext,\n MongoQueryPlan,\n} from '@prisma-next/mongo-core';\nimport { AsyncIterableResult } from '@prisma-next/runtime-executor';\n\nexport interface MongoRuntimeOptions {\n readonly adapter: MongoAdapter;\n readonly driver: MongoDriver;\n readonly loweringContext: MongoLoweringContext;\n}\n\nexport interface MongoRuntime {\n execute<Row>(plan: MongoQueryPlan<Row>): AsyncIterableResult<Row>;\n close(): Promise<void>;\n}\n\nclass MongoRuntimeImpl implements MongoRuntime {\n readonly #adapter: MongoAdapter;\n readonly #driver: MongoDriver;\n readonly #loweringContext: MongoLoweringContext;\n\n constructor(options: MongoRuntimeOptions) {\n this.#adapter = options.adapter;\n this.#driver = options.driver;\n this.#loweringContext = options.loweringContext;\n }\n\n execute<Row>(plan: MongoQueryPlan<Row>): AsyncIterableResult<Row> {\n const executionPlan = this.#adapter.lower(plan, this.#loweringContext);\n const iterable = this.#driver.execute<Row>(executionPlan.wireCommand);\n\n async function* toGenerator(): AsyncGenerator<Row, void, unknown> {\n yield* iterable;\n }\n\n return new AsyncIterableResult(toGenerator());\n }\n\n async close(): Promise<void> {\n await this.#driver.close();\n }\n}\n\nexport function createMongoRuntime(options: MongoRuntimeOptions): MongoRuntime {\n return new MongoRuntimeImpl(options);\n}\n"],"mappings":";;;AAmBA,IAAM,mBAAN,MAA+C;CAC7C,CAASA;CACT,CAASC;CACT,CAASC;CAET,YAAY,SAA8B;AACxC,QAAKF,UAAW,QAAQ;AACxB,QAAKC,SAAU,QAAQ;AACvB,QAAKC,kBAAmB,QAAQ;;CAGlC,QAAa,MAAqD;EAChE,MAAM,gBAAgB,MAAKF,QAAS,MAAM,MAAM,MAAKE,gBAAiB;EACtE,MAAM,WAAW,MAAKD,OAAQ,QAAa,cAAc,YAAY;EAErE,gBAAgB,cAAkD;AAChE,UAAO;;AAGT,SAAO,IAAI,oBAAoB,aAAa,CAAC;;CAG/C,MAAM,QAAuB;AAC3B,QAAM,MAAKA,OAAQ,OAAO;;;AAI9B,SAAgB,mBAAmB,SAA4C;AAC7E,QAAO,IAAI,iBAAiB,QAAQ"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prisma-next/mongo-runtime",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"description": "MongoDB runtime implementation for Prisma Next",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsdown",
|
|
9
|
+
"test": "vitest run --passWithNoTests",
|
|
10
|
+
"test:coverage": "vitest run --coverage --passWithNoTests",
|
|
11
|
+
"typecheck": "tsc --noEmit",
|
|
12
|
+
"lint": "biome check . --error-on-warnings",
|
|
13
|
+
"lint:fix": "biome check --write .",
|
|
14
|
+
"lint:fix:unsafe": "biome check --write --unsafe .",
|
|
15
|
+
"clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@prisma-next/contract": "workspace:*",
|
|
19
|
+
"@prisma-next/mongo-core": "workspace:*",
|
|
20
|
+
"@prisma-next/runtime-executor": "workspace:*"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@prisma-next/adapter-mongo": "workspace:*",
|
|
24
|
+
"@prisma-next/driver-mongo": "workspace:*",
|
|
25
|
+
"@prisma-next/test-utils": "workspace:*",
|
|
26
|
+
"@prisma-next/tsconfig": "workspace:*",
|
|
27
|
+
"@prisma-next/tsdown": "workspace:*",
|
|
28
|
+
"mongodb": "^6.16.0",
|
|
29
|
+
"mongodb-memory-server": "^10.4.0",
|
|
30
|
+
"tsdown": "catalog:",
|
|
31
|
+
"typescript": "catalog:",
|
|
32
|
+
"vitest": "catalog:"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"src"
|
|
37
|
+
],
|
|
38
|
+
"exports": {
|
|
39
|
+
".": "./dist/index.mjs",
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"main": "./dist/index.mjs",
|
|
43
|
+
"module": "./dist/index.mjs",
|
|
44
|
+
"types": "./dist/index.d.mts",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/prisma/prisma-next.git",
|
|
48
|
+
"directory": "packages/2-mongo-family/5-runtime"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MongoAdapter,
|
|
3
|
+
MongoDriver,
|
|
4
|
+
MongoLoweringContext,
|
|
5
|
+
MongoQueryPlan,
|
|
6
|
+
} from '@prisma-next/mongo-core';
|
|
7
|
+
import { AsyncIterableResult } from '@prisma-next/runtime-executor';
|
|
8
|
+
|
|
9
|
+
export interface MongoRuntimeOptions {
|
|
10
|
+
readonly adapter: MongoAdapter;
|
|
11
|
+
readonly driver: MongoDriver;
|
|
12
|
+
readonly loweringContext: MongoLoweringContext;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface MongoRuntime {
|
|
16
|
+
execute<Row>(plan: MongoQueryPlan<Row>): AsyncIterableResult<Row>;
|
|
17
|
+
close(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class MongoRuntimeImpl implements MongoRuntime {
|
|
21
|
+
readonly #adapter: MongoAdapter;
|
|
22
|
+
readonly #driver: MongoDriver;
|
|
23
|
+
readonly #loweringContext: MongoLoweringContext;
|
|
24
|
+
|
|
25
|
+
constructor(options: MongoRuntimeOptions) {
|
|
26
|
+
this.#adapter = options.adapter;
|
|
27
|
+
this.#driver = options.driver;
|
|
28
|
+
this.#loweringContext = options.loweringContext;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
execute<Row>(plan: MongoQueryPlan<Row>): AsyncIterableResult<Row> {
|
|
32
|
+
const executionPlan = this.#adapter.lower(plan, this.#loweringContext);
|
|
33
|
+
const iterable = this.#driver.execute<Row>(executionPlan.wireCommand);
|
|
34
|
+
|
|
35
|
+
async function* toGenerator(): AsyncGenerator<Row, void, unknown> {
|
|
36
|
+
yield* iterable;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return new AsyncIterableResult(toGenerator());
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async close(): Promise<void> {
|
|
43
|
+
await this.#driver.close();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function createMongoRuntime(options: MongoRuntimeOptions): MongoRuntime {
|
|
48
|
+
return new MongoRuntimeImpl(options);
|
|
49
|
+
}
|