@prisma-next/mongo-runtime 0.5.0-dev.4 → 0.5.0-dev.42
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 +76 -5
- package/dist/index.d.mts +154 -13
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +178 -59
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -16
- package/src/codecs/decoding.ts +170 -0
- package/src/exports/index.ts +17 -0
- package/src/mongo-execution-plan.ts +28 -0
- package/src/mongo-execution-stack.ts +171 -0
- package/src/mongo-middleware.ts +17 -6
- package/src/mongo-runtime.ts +114 -73
package/README.md
CHANGED
|
@@ -2,18 +2,89 @@
|
|
|
2
2
|
|
|
3
3
|
MongoDB runtime executor for Prisma Next.
|
|
4
4
|
|
|
5
|
+
## Package Classification
|
|
6
|
+
|
|
7
|
+
- **Domain**: mongo
|
|
8
|
+
- **Layer**: runtime
|
|
9
|
+
- **Plane**: runtime
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
The Mongo runtime package implements the Mongo family runtime by extending the abstract `RuntimeCore` base class from `@prisma-next/framework-components/runtime` with Mongo-specific lowering and driver dispatch. It provides the public runtime API for MongoDB, layering Mongo concerns (adapter lowering and wire-command dispatch) on top of the shared middleware lifecycle.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
The runtime takes a **`MongoExecutionContext`** built from a **`MongoExecutionStack`** (target + adapter + optional driver + extension packs). The context aggregates codec contributions from each stack component into a single registry — users do not construct or thread a `MongoCodecRegistry` themselves. This mirrors the SQL pattern (see `packages/2-sql/5-runtime/src/sql-context.ts`).
|
|
18
|
+
|
|
19
|
+
Typed reads that attach a **`resultShape`** on the query plan are decoded after the driver yields each row: scalars and scalar arrays run through their `codecId` entries; `kind: 'unknown'` subtrees are passed through unchanged; plans without `resultShape` (for example raw commands) leave rows as the driver returned them.
|
|
20
|
+
|
|
21
|
+
Example:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import mongoRuntimeAdapter from '@prisma-next/adapter-mongo/runtime';
|
|
25
|
+
import { createMongoDriver } from '@prisma-next/driver-mongo';
|
|
26
|
+
import {
|
|
27
|
+
createMongoExecutionContext,
|
|
28
|
+
createMongoExecutionStack,
|
|
29
|
+
createMongoRuntime,
|
|
30
|
+
} from '@prisma-next/mongo-runtime';
|
|
31
|
+
import mongoRuntimeTarget from '@prisma-next/target-mongo/runtime';
|
|
32
|
+
|
|
33
|
+
const stack = createMongoExecutionStack({
|
|
34
|
+
target: mongoRuntimeTarget,
|
|
35
|
+
adapter: mongoRuntimeAdapter,
|
|
36
|
+
});
|
|
37
|
+
const context = createMongoExecutionContext({ contract, stack });
|
|
38
|
+
|
|
39
|
+
const runtime = createMongoRuntime({
|
|
40
|
+
context,
|
|
41
|
+
driver: await createMongoDriver(url, dbName),
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Custom or third-party codecs (encryption, vendor scalars) are contributed via an extension-pack descriptor whose `codecInstances` list includes them; `createMongoExecutionContext` folds them into the same registry. Duplicate codec ids across contributors throw `RUNTIME.DUPLICATE_CODEC` at composition time.
|
|
46
|
+
|
|
5
47
|
## Responsibilities
|
|
6
48
|
|
|
7
|
-
- **
|
|
49
|
+
- **Stack/context composition**: `createMongoExecutionStack` and `createMongoExecutionContext` mirror SQL's `createSqlExecutionStack` / `createExecutionContext`. The context aggregates codec contributions from `[stack.target, stack.adapter, ...stack.extensionPacks]` into a single `MongoCodecRegistry`.
|
|
50
|
+
- **Runtime executor**: `createMongoRuntime({ context, driver, ... })` composes context and driver into a `MongoRuntime` with a single `execute(plan)` entry point accepting `MongoQueryPlan<Row>` from `@prisma-next/mongo-query-ast`. The adapter is reached via `context.stack.adapter` (instantiated lazily through the stack's `create(stack)` factory). Execution lowers the plan through the adapter, runs the wire command on the driver, then **optionally decodes** each row when `plan.resultShape` is present.
|
|
8
51
|
- **Unified flow**: There is no separate `execute` vs `executeCommand`; all operations use `execute(plan)`.
|
|
9
|
-
- **Lowering**: Happens in the adapter (`lower(plan)`),
|
|
10
|
-
- **
|
|
52
|
+
- **Lowering**: Happens in the adapter (`lower(plan)`), wrapped by the runtime's `lower` override into a `MongoExecutionPlan`.
|
|
53
|
+
- **Middleware lifecycle inheritance**: `MongoRuntime` extends `RuntimeCore<MongoQueryPlan, MongoExecutionPlan, MongoMiddleware>` and inherits the `beforeExecute` / `onRow` / `afterExecute` lifecycle from the framework via `runWithMiddleware`. Mongo does **not** override `runBeforeCompile` (Mongo middleware has no `beforeCompile` hook today).
|
|
54
|
+
- **Lifecycle management**: Connection lifecycle via `close()`.
|
|
11
55
|
|
|
12
56
|
## Dependencies
|
|
13
57
|
|
|
14
58
|
- **Depends on**:
|
|
59
|
+
- `@prisma-next/mongo-codec` (`MongoCodecRegistry` for decode)
|
|
15
60
|
- `@prisma-next/mongo-lowering` (`MongoAdapter`, `MongoDriver` interfaces)
|
|
16
61
|
- `@prisma-next/mongo-query-ast` (`MongoQueryPlan`, `AnyMongoCommand` — the typed plan shape)
|
|
17
|
-
- `@prisma-next/
|
|
62
|
+
- `@prisma-next/framework-components` (`RuntimeCore` base class, `runWithMiddleware` helper, `RuntimeMiddleware` SPI, `AsyncIterableResult` return type, `RuntimeAdapterDescriptor` / `ExecutionStack` for the stack composition model)
|
|
18
63
|
- **Depended on by**:
|
|
19
|
-
- Integration tests (`test/integration/test/mongo/`)
|
|
64
|
+
- Integration tests (`test/integration/test/mongo/` and `test/integration/test/cross-package/cross-family-middleware.test.ts`)
|
|
65
|
+
|
|
66
|
+
## Architecture
|
|
67
|
+
|
|
68
|
+
`MongoRuntimeImpl` extends `RuntimeCore<MongoQueryPlan, MongoExecutionPlan, MongoMiddleware>` and overrides:
|
|
69
|
+
|
|
70
|
+
- `lower(plan)` — calls the adapter's `lower(plan)` and wraps the resulting wire command into a `MongoExecutionPlan`.
|
|
71
|
+
- `runDriver(exec)` — dispatches the wire command to the Mongo driver via `driver.execute(exec.command)`.
|
|
72
|
+
- `close()` — closes the underlying driver.
|
|
73
|
+
|
|
74
|
+
`MongoRuntimeImpl` extends `RuntimeCore` but **overrides `execute`** so that after `runWithMiddleware` yields a raw driver row, the runtime can **`decodeMongoRow`** when the lowered plan carries `resultShape`, then yield the decoded row. `lower(plan)` copies `resultShape` from the query plan onto `MongoExecutionPlan`. Middleware `onRow` still sees the raw driver row (decode happens after the middleware loop for that row, before the consumer receives the value).
|
|
75
|
+
|
|
76
|
+
The execution template is: `lower` → `runWithMiddleware` (driver loop + middleware) → **per-row decode when `exec.resultShape` is set** → yield to consumer.
|
|
77
|
+
|
|
78
|
+
```mermaid
|
|
79
|
+
flowchart LR
|
|
80
|
+
Plan[MongoQueryPlan] --> Runtime[MongoRuntime]
|
|
81
|
+
Runtime -.extends.-> Core[RuntimeCore]
|
|
82
|
+
Runtime --> Adapter[MongoAdapter.lower]
|
|
83
|
+
Adapter --> Exec[MongoExecutionPlan]
|
|
84
|
+
Runtime --> Driver[MongoDriver.execute]
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Related Subsystems
|
|
88
|
+
|
|
89
|
+
- **[Runtime & Middleware Framework](../../../../docs/architecture%20docs/subsystems/4.%20Runtime%20&%20Middleware%20Framework.md)** — Runtime execution pipeline
|
|
90
|
+
- **[Adapters & Targets](../../../../docs/architecture%20docs/subsystems/5.%20Adapters%20&%20Targets.md)** — Adapter and driver responsibilities
|
package/dist/index.d.mts
CHANGED
|
@@ -1,30 +1,171 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { RuntimeAdapterDescriptor, RuntimeAdapterInstance, RuntimeDriverDescriptor, RuntimeDriverInstance, RuntimeExtensionDescriptor, RuntimeExtensionInstance, RuntimeTargetDescriptor, RuntimeTargetInstance, RuntimeTargetInstance as RuntimeTargetInstance$1 } from "@prisma-next/framework-components/execution";
|
|
2
|
+
import { AfterExecuteResult, AsyncIterableResult, ExecutionPlan, RuntimeExecuteOptions, RuntimeMiddleware, RuntimeMiddlewareContext } from "@prisma-next/framework-components/runtime";
|
|
3
|
+
import { MongoCodec, MongoCodecRegistry } from "@prisma-next/mongo-codec";
|
|
4
|
+
import { MongoQueryPlan, MongoResultShape } from "@prisma-next/mongo-query-ast/execution";
|
|
5
|
+
import { AnyMongoWireCommand } from "@prisma-next/mongo-wire";
|
|
3
6
|
import { MongoAdapter, MongoDriver } from "@prisma-next/mongo-lowering";
|
|
4
7
|
|
|
8
|
+
//#region src/mongo-execution-plan.d.ts
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Mongo-domain execution plan: a query lowered to the wire-command shape
|
|
12
|
+
* that a Mongo driver can run.
|
|
13
|
+
*
|
|
14
|
+
* The plan carries:
|
|
15
|
+
* - `command` — the wire command (e.g. `InsertOneWireCommand`,
|
|
16
|
+
* `AggregateWireCommand`) produced by `MongoAdapter.lower(plan)`
|
|
17
|
+
* - `meta` — family-agnostic plan metadata (target, lane, hashes, ...)
|
|
18
|
+
* - `_row` — phantom row type, propagated from the originating
|
|
19
|
+
* `MongoQueryPlan`
|
|
20
|
+
*
|
|
21
|
+
* Extends the framework-level `ExecutionPlan<Row>` marker so generic SPIs
|
|
22
|
+
* (`RuntimeExecutor<MongoExecutionPlan>`,
|
|
23
|
+
* `RuntimeMiddleware<MongoExecutionPlan>`) can be parameterized over it.
|
|
24
|
+
*
|
|
25
|
+
* Lives in the runtime layer (alongside `MongoRuntime`) because the wire
|
|
26
|
+
* command shape lives in the transport layer (`@prisma-next/mongo-wire`),
|
|
27
|
+
* which the lanes layer (`mongo-query-ast`, where `MongoQueryPlan` lives)
|
|
28
|
+
* cannot depend on.
|
|
29
|
+
*/
|
|
30
|
+
interface MongoExecutionPlan<Row = unknown> extends ExecutionPlan<Row> {
|
|
31
|
+
readonly command: AnyMongoWireCommand;
|
|
32
|
+
readonly resultShape?: MongoResultShape;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/mongo-execution-stack.d.ts
|
|
36
|
+
/**
|
|
37
|
+
* Mongo-specific static contributions a runtime descriptor declares.
|
|
38
|
+
*
|
|
39
|
+
* Mirrors `SqlStaticContributions` in shape: a `codecs()` getter that yields
|
|
40
|
+
* a `MongoCodecRegistry` populated with this contributor's codecs. The
|
|
41
|
+
* registry is then walked by `createMongoExecutionContext` and folded into
|
|
42
|
+
* the single per-execution registry the runtime reads from at decode time.
|
|
43
|
+
*/
|
|
44
|
+
interface MongoStaticContributions {
|
|
45
|
+
readonly codecs: () => MongoCodecRegistry;
|
|
46
|
+
}
|
|
47
|
+
interface MongoRuntimeTargetDescriptor<TTargetId extends string = 'mongo', TTargetInstance extends RuntimeTargetInstance$1<'mongo', TTargetId> = RuntimeTargetInstance$1<'mongo', TTargetId>> extends RuntimeTargetDescriptor<'mongo', TTargetId, TTargetInstance>, MongoStaticContributions {}
|
|
48
|
+
interface MongoRuntimeAdapterInstance<TTargetId extends string = 'mongo'> extends RuntimeAdapterInstance<'mongo', TTargetId>, MongoAdapter {}
|
|
49
|
+
interface MongoRuntimeAdapterDescriptor<TTargetId extends string = 'mongo', TAdapterInstance extends RuntimeAdapterInstance<'mongo', TTargetId> = MongoRuntimeAdapterInstance<TTargetId>> extends RuntimeAdapterDescriptor<'mongo', TTargetId, TAdapterInstance>, MongoStaticContributions {}
|
|
50
|
+
interface MongoRuntimeExtensionInstance<TTargetId extends string = 'mongo'> extends RuntimeExtensionInstance<'mongo', TTargetId> {}
|
|
51
|
+
interface MongoRuntimeExtensionDescriptor<TTargetId extends string = 'mongo'> extends RuntimeExtensionDescriptor<'mongo', TTargetId, MongoRuntimeExtensionInstance<TTargetId>>, MongoStaticContributions {
|
|
52
|
+
create(): MongoRuntimeExtensionInstance<TTargetId>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The Mongo execution stack: target + adapter + optional driver + extension
|
|
56
|
+
* packs. Mirrors `SqlExecutionStack`. Constructed via
|
|
57
|
+
* `createMongoExecutionStack`.
|
|
58
|
+
*/
|
|
59
|
+
interface MongoExecutionStack<TTargetId extends string = 'mongo'> {
|
|
60
|
+
readonly target: MongoRuntimeTargetDescriptor<TTargetId>;
|
|
61
|
+
readonly adapter: MongoRuntimeAdapterDescriptor<TTargetId>;
|
|
62
|
+
readonly driver: RuntimeDriverDescriptor<'mongo', TTargetId, unknown, RuntimeDriverInstance<'mongo', TTargetId>> | undefined;
|
|
63
|
+
readonly extensionPacks: readonly MongoRuntimeExtensionDescriptor<TTargetId>[];
|
|
64
|
+
}
|
|
65
|
+
declare function createMongoExecutionStack<TTargetId extends string = 'mongo'>(options: {
|
|
66
|
+
readonly target: MongoRuntimeTargetDescriptor<TTargetId>;
|
|
67
|
+
readonly adapter: MongoRuntimeAdapterDescriptor<TTargetId>;
|
|
68
|
+
readonly driver?: RuntimeDriverDescriptor<'mongo', TTargetId, unknown, RuntimeDriverInstance<'mongo', TTargetId>> | undefined;
|
|
69
|
+
readonly extensionPacks?: readonly MongoRuntimeExtensionDescriptor<TTargetId>[] | undefined;
|
|
70
|
+
}): MongoExecutionStack<TTargetId>;
|
|
71
|
+
/**
|
|
72
|
+
* Read-only view of the codec registry exposed on `MongoExecutionContext`.
|
|
73
|
+
*
|
|
74
|
+
* Hides `register()` and the iterator from public surface — users do not
|
|
75
|
+
* mutate the per-execution codec registry. Internal aggregation in
|
|
76
|
+
* `createMongoExecutionContext` keeps using the full `MongoCodecRegistry`
|
|
77
|
+
* (it needs `register()`).
|
|
78
|
+
*/
|
|
79
|
+
interface MongoCodecLookup {
|
|
80
|
+
get(id: string): MongoCodec<string> | undefined;
|
|
81
|
+
has(id: string): boolean;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Per-execution context aggregated from a `MongoExecutionStack`.
|
|
85
|
+
*
|
|
86
|
+
* Carries the user's contract, a read-only lookup over the codec registry
|
|
87
|
+
* composed from every stack contributor, and a back-reference to the stack
|
|
88
|
+
* itself so the runtime can reach the adapter without users threading it
|
|
89
|
+
* explicitly.
|
|
90
|
+
*
|
|
91
|
+
* Mirrors SQL's `ExecutionContext` in role; Mongo's flavour is leaner
|
|
92
|
+
* because there are no parameterised codecs, JSON-schema validators, or
|
|
93
|
+
* mutation-default generators in scope yet.
|
|
94
|
+
*/
|
|
95
|
+
interface MongoExecutionContext<TTargetId extends string = 'mongo'> {
|
|
96
|
+
readonly contract: unknown;
|
|
97
|
+
readonly codecs: MongoCodecLookup;
|
|
98
|
+
readonly stack: MongoExecutionStack<TTargetId>;
|
|
99
|
+
}
|
|
100
|
+
declare function createMongoExecutionContext<TTargetId extends string = 'mongo'>(options: {
|
|
101
|
+
readonly contract: unknown;
|
|
102
|
+
readonly stack: MongoExecutionStack<TTargetId>;
|
|
103
|
+
}): MongoExecutionContext<TTargetId>;
|
|
104
|
+
//#endregion
|
|
5
105
|
//#region src/mongo-middleware.d.ts
|
|
6
106
|
interface MongoMiddlewareContext extends RuntimeMiddlewareContext {}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Mongo-domain middleware. Extends the framework `RuntimeMiddleware`
|
|
109
|
+
* parameterized over `MongoExecutionPlan` because `runWithMiddleware`
|
|
110
|
+
* (driven by `RuntimeCore`) invokes the lifecycle hooks with the
|
|
111
|
+
* post-lowering plan.
|
|
112
|
+
*
|
|
113
|
+
* `familyId` is optional so generic cross-family middleware (e.g.
|
|
114
|
+
* telemetry) — which carry no `familyId` — remain assignable. When
|
|
115
|
+
* present, it must be `'mongo'`; the runtime rejects mismatches at
|
|
116
|
+
* construction time via `checkMiddlewareCompatibility`.
|
|
117
|
+
*/
|
|
118
|
+
interface MongoMiddleware extends RuntimeMiddleware<MongoExecutionPlan> {
|
|
119
|
+
readonly familyId?: 'mongo';
|
|
120
|
+
beforeExecute?(plan: MongoExecutionPlan, ctx: MongoMiddlewareContext): Promise<void>;
|
|
121
|
+
onRow?(row: Record<string, unknown>, plan: MongoExecutionPlan, ctx: MongoMiddlewareContext): Promise<void>;
|
|
122
|
+
afterExecute?(plan: MongoExecutionPlan, result: AfterExecuteResult, ctx: MongoMiddlewareContext): Promise<void>;
|
|
12
123
|
}
|
|
13
124
|
//#endregion
|
|
14
125
|
//#region src/mongo-runtime.d.ts
|
|
126
|
+
/**
|
|
127
|
+
* Mongo runtime options.
|
|
128
|
+
*
|
|
129
|
+
* The runtime takes a {@link MongoExecutionContext} (built via
|
|
130
|
+
* `createMongoExecutionContext`) and a driver. Codec resolution flows from
|
|
131
|
+
* the context — there is no `codecs` field on this options bag. The adapter
|
|
132
|
+
* is reached via `context.stack.adapter` (instantiated lazily through the
|
|
133
|
+
* stack's `create(stack)` factory). See ADR — Mongo result-shape as a
|
|
134
|
+
* structural plan field, § Codec registry: stack aggregation, not user
|
|
135
|
+
* threading.
|
|
136
|
+
*/
|
|
15
137
|
interface MongoRuntimeOptions {
|
|
16
|
-
readonly
|
|
138
|
+
readonly context: MongoExecutionContext;
|
|
17
139
|
readonly driver: MongoDriver;
|
|
18
|
-
readonly
|
|
19
|
-
readonly targetId: string;
|
|
20
|
-
readonly middleware?: readonly RuntimeMiddleware[];
|
|
140
|
+
readonly middleware?: readonly MongoMiddleware[];
|
|
21
141
|
readonly mode?: 'strict' | 'permissive';
|
|
22
142
|
}
|
|
23
143
|
interface MongoRuntime {
|
|
24
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Execute a `MongoQueryPlan` and return an async iterable of rows.
|
|
146
|
+
*
|
|
147
|
+
* The optional `options.signal` is threaded through
|
|
148
|
+
* `lower → adapter.lower → resolveValue → codec.encode` so codec authors
|
|
149
|
+
* who forward the signal to their underlying SDK get true cancellation
|
|
150
|
+
* of in-flight network calls. The runtime additionally observes the
|
|
151
|
+
* signal at two boundaries:
|
|
152
|
+
*
|
|
153
|
+
* - **Already-aborted at entry** — first `next()` throws
|
|
154
|
+
* `RUNTIME.ABORTED { phase: 'stream' }` before any work is done.
|
|
155
|
+
* (Inherited from `RuntimeCore.execute`.)
|
|
156
|
+
* - **Mid-encode abort** — surfaces as
|
|
157
|
+
* `RUNTIME.ABORTED { phase: 'encode' }` from inside `resolveValue`'s
|
|
158
|
+
* per-level `Promise.all` race.
|
|
159
|
+
*
|
|
160
|
+
* Mongo's read path decodes rows via `resultShape` (per ADR 209). The
|
|
161
|
+
* same `CodecCallContext` is forwarded into each `codec.decode(wire, ctx)`
|
|
162
|
+
* call, so async decoders that respect the signal get cancellation; the
|
|
163
|
+
* runtime itself does not currently emit a `phase: 'decode'` envelope.
|
|
164
|
+
*/
|
|
165
|
+
execute<Row>(plan: MongoQueryPlan<Row>, options?: RuntimeExecuteOptions): AsyncIterableResult<Row>;
|
|
25
166
|
close(): Promise<void>;
|
|
26
167
|
}
|
|
27
168
|
declare function createMongoRuntime(options: MongoRuntimeOptions): MongoRuntime;
|
|
28
169
|
//#endregion
|
|
29
|
-
export { type MongoMiddleware, type MongoMiddlewareContext, type MongoRuntime, type MongoRuntimeOptions, createMongoRuntime };
|
|
170
|
+
export { type MongoCodecLookup, type MongoExecutionContext, type MongoExecutionPlan, type MongoExecutionStack, type MongoMiddleware, type MongoMiddlewareContext, type MongoRuntime, type MongoRuntimeAdapterDescriptor, type MongoRuntimeAdapterInstance, type MongoRuntimeExtensionDescriptor, type MongoRuntimeExtensionInstance, type MongoRuntimeOptions, type MongoRuntimeTargetDescriptor, type MongoStaticContributions, type RuntimeTargetInstance, createMongoExecutionContext, createMongoExecutionStack, createMongoRuntime };
|
|
30
171
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/mongo-middleware.ts","../src/mongo-runtime.ts"],"sourcesContent":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/mongo-execution-plan.ts","../src/mongo-execution-stack.ts","../src/mongo-middleware.ts","../src/mongo-runtime.ts"],"sourcesContent":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
|
|
1
|
+
import { createExecutionStack } from "@prisma-next/framework-components/execution";
|
|
2
|
+
import { AsyncIterableResult, RuntimeCore, checkAborted, checkMiddlewareCompatibility, runWithMiddleware, runtimeError } from "@prisma-next/framework-components/runtime";
|
|
3
|
+
import { createMongoCodecRegistry } from "@prisma-next/mongo-codec";
|
|
4
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
2
5
|
|
|
6
|
+
//#region src/mongo-execution-stack.ts
|
|
7
|
+
function createMongoExecutionStack(options) {
|
|
8
|
+
return createExecutionStack({
|
|
9
|
+
target: options.target,
|
|
10
|
+
adapter: options.adapter,
|
|
11
|
+
driver: options.driver,
|
|
12
|
+
extensionPacks: options.extensionPacks
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function createMongoExecutionContext(options) {
|
|
16
|
+
const registry = createMongoCodecRegistry();
|
|
17
|
+
const owners = /* @__PURE__ */ new Map();
|
|
18
|
+
const contributors = [
|
|
19
|
+
options.stack.target,
|
|
20
|
+
options.stack.adapter,
|
|
21
|
+
...options.stack.extensionPacks
|
|
22
|
+
];
|
|
23
|
+
for (const contributor of contributors) {
|
|
24
|
+
const contributed = contributor.codecs();
|
|
25
|
+
for (const codec of iterateCodecs(contributed)) {
|
|
26
|
+
const existingOwner = owners.get(codec.id);
|
|
27
|
+
if (existingOwner !== void 0) throw runtimeError("RUNTIME.DUPLICATE_CODEC", `Duplicate Mongo codec id '${codec.id}' contributed by '${contributor.id}' (already registered by '${existingOwner}').`, {
|
|
28
|
+
codecId: codec.id,
|
|
29
|
+
existingOwner,
|
|
30
|
+
incomingOwner: contributor.id
|
|
31
|
+
});
|
|
32
|
+
registry.register(codec);
|
|
33
|
+
owners.set(codec.id, contributor.id);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return Object.freeze({
|
|
37
|
+
contract: options.contract,
|
|
38
|
+
codecs: registry,
|
|
39
|
+
stack: options.stack
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function* iterateCodecs(registry) {
|
|
43
|
+
yield* registry.values();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/codecs/decoding.ts
|
|
48
|
+
const WIRE_PREVIEW_LIMIT = 100;
|
|
49
|
+
function previewWireValue(wireValue) {
|
|
50
|
+
if (typeof wireValue === "string") return wireValue.length > WIRE_PREVIEW_LIMIT ? `${wireValue.substring(0, WIRE_PREVIEW_LIMIT)}...` : wireValue;
|
|
51
|
+
return String(wireValue).substring(0, WIRE_PREVIEW_LIMIT);
|
|
52
|
+
}
|
|
53
|
+
function wrapDecodeFailure(error, collection, path, codecId, wireValue) {
|
|
54
|
+
const wrapped = runtimeError("RUNTIME.DECODE_FAILED", `Failed to decode field ${path} in collection '${collection}' with codec '${codecId}': ${error instanceof Error ? error.message : String(error)}`, {
|
|
55
|
+
collection,
|
|
56
|
+
path,
|
|
57
|
+
codec: codecId,
|
|
58
|
+
wirePreview: previewWireValue(wireValue)
|
|
59
|
+
});
|
|
60
|
+
wrapped.cause = error;
|
|
61
|
+
throw wrapped;
|
|
62
|
+
}
|
|
63
|
+
async function decodeMongoRow(row, shape, registry, collection, ctx = {}) {
|
|
64
|
+
if (shape.kind === "unknown") return row;
|
|
65
|
+
if (typeof row !== "object" || row === null) return row;
|
|
66
|
+
const rowObj = row;
|
|
67
|
+
const out = {};
|
|
68
|
+
const tasks = [];
|
|
69
|
+
function scheduleLeaf(path, codecId, wire, assign) {
|
|
70
|
+
const codec = registry.get(codecId);
|
|
71
|
+
if (!codec) {
|
|
72
|
+
assign(wire);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
tasks.push((async () => {
|
|
76
|
+
try {
|
|
77
|
+
assign(await codec.decode(wire, ctx));
|
|
78
|
+
} catch (error) {
|
|
79
|
+
wrapDecodeFailure(error, collection, path, codecId, wire);
|
|
80
|
+
}
|
|
81
|
+
})());
|
|
82
|
+
}
|
|
83
|
+
function walkField(value, fieldShape, path, assign) {
|
|
84
|
+
switch (fieldShape.kind) {
|
|
85
|
+
case "unknown":
|
|
86
|
+
assign(value);
|
|
87
|
+
return;
|
|
88
|
+
case "leaf":
|
|
89
|
+
if (value === null || value === void 0) {
|
|
90
|
+
assign(value);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
scheduleLeaf(path, fieldShape.codecId, value, assign);
|
|
94
|
+
return;
|
|
95
|
+
case "document": {
|
|
96
|
+
if (value === null || value === void 0) {
|
|
97
|
+
assign(value);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
101
|
+
assign(value);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const vObj = value;
|
|
105
|
+
const nested = { ...vObj };
|
|
106
|
+
assign(nested);
|
|
107
|
+
for (const [fk, fShape] of Object.entries(fieldShape.fields)) walkField(vObj[fk], fShape, `${path}.${fk}`, (v) => {
|
|
108
|
+
nested[fk] = v;
|
|
109
|
+
});
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
case "array": {
|
|
113
|
+
if (value === null || value === void 0) {
|
|
114
|
+
assign(value);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (!Array.isArray(value)) {
|
|
118
|
+
assign(value);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const arr = [];
|
|
122
|
+
assign(arr);
|
|
123
|
+
for (let i = 0; i < value.length; i++) {
|
|
124
|
+
const el = value[i];
|
|
125
|
+
walkField(el, fieldShape.element, `${path}.${i}`, (v) => {
|
|
126
|
+
arr[i] = v;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/* v8 ignore stop */
|
|
133
|
+
}
|
|
134
|
+
for (const [k, fShape] of Object.entries(shape.fields)) walkField(rowObj[k], fShape, k, (v) => {
|
|
135
|
+
out[k] = v;
|
|
136
|
+
});
|
|
137
|
+
for (const k of Object.keys(rowObj)) if (!Object.hasOwn(shape.fields, k)) out[k] = rowObj[k];
|
|
138
|
+
await Promise.all(tasks);
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
//#endregion
|
|
3
143
|
//#region src/mongo-runtime.ts
|
|
4
144
|
function noop() {}
|
|
5
|
-
|
|
6
|
-
return Date.now();
|
|
7
|
-
}
|
|
8
|
-
var MongoRuntimeImpl = class {
|
|
145
|
+
var MongoRuntimeImpl = class extends RuntimeCore {
|
|
9
146
|
#adapter;
|
|
10
147
|
#driver;
|
|
11
|
-
#
|
|
12
|
-
#middlewareContext;
|
|
148
|
+
#codecs;
|
|
13
149
|
constructor(options) {
|
|
14
|
-
this.#adapter = options.adapter;
|
|
15
|
-
this.#driver = options.driver;
|
|
16
150
|
const middleware = options.middleware ? [...options.middleware] : [];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
contract: options.contract,
|
|
151
|
+
const targetId = options.context.stack.target.targetId;
|
|
152
|
+
for (const mw of middleware) checkMiddlewareCompatibility(mw, "mongo", targetId);
|
|
153
|
+
const ctx = {
|
|
154
|
+
contract: options.context.contract,
|
|
21
155
|
mode: options.mode ?? "strict",
|
|
22
|
-
now,
|
|
156
|
+
now: () => Date.now(),
|
|
23
157
|
log: {
|
|
24
158
|
info: noop,
|
|
25
159
|
warn: noop,
|
|
26
160
|
error: noop
|
|
27
161
|
}
|
|
28
162
|
};
|
|
163
|
+
super({
|
|
164
|
+
middleware,
|
|
165
|
+
ctx
|
|
166
|
+
});
|
|
167
|
+
this.#adapter = options.context.stack.adapter.create(options.context.stack);
|
|
168
|
+
this.#driver = options.driver;
|
|
169
|
+
this.#codecs = options.context.codecs;
|
|
29
170
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
throw error;
|
|
52
|
-
} finally {
|
|
53
|
-
const latencyMs = ctx.now() - startedAt;
|
|
54
|
-
for (const mw of middleware) {
|
|
55
|
-
if (!mw.afterExecute) continue;
|
|
56
|
-
if (failed) {
|
|
57
|
-
try {
|
|
58
|
-
await mw.afterExecute(plan, {
|
|
59
|
-
rowCount,
|
|
60
|
-
latencyMs,
|
|
61
|
-
completed
|
|
62
|
-
}, ctx);
|
|
63
|
-
} catch {}
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
await mw.afterExecute(plan, {
|
|
67
|
-
rowCount,
|
|
68
|
-
latencyMs,
|
|
69
|
-
completed
|
|
70
|
-
}, ctx);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
171
|
+
async lower(plan, ctx) {
|
|
172
|
+
return {
|
|
173
|
+
command: await this.#adapter.lower(plan, ctx),
|
|
174
|
+
meta: plan.meta,
|
|
175
|
+
...ifDefined("resultShape", plan.resultShape)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
runDriver(exec) {
|
|
179
|
+
return this.#driver.execute(exec.command);
|
|
180
|
+
}
|
|
181
|
+
execute(plan, options) {
|
|
182
|
+
const self = this;
|
|
183
|
+
const signal = options?.signal;
|
|
184
|
+
const codecCtx = signal === void 0 ? {} : { signal };
|
|
185
|
+
const generator = async function* () {
|
|
186
|
+
checkAborted(codecCtx, "stream");
|
|
187
|
+
const compiled = await self.runBeforeCompile(plan);
|
|
188
|
+
const exec = await self.lower(compiled, codecCtx);
|
|
189
|
+
const stream = runWithMiddleware(exec, self.middleware, self.ctx, () => self.runDriver(exec));
|
|
190
|
+
for await (const rawRow of stream) if (exec.resultShape === void 0) yield rawRow;
|
|
191
|
+
else yield await decodeMongoRow(rawRow, exec.resultShape, self.#codecs, exec.command.collection, codecCtx);
|
|
73
192
|
};
|
|
74
|
-
return new AsyncIterableResult(
|
|
193
|
+
return new AsyncIterableResult(generator());
|
|
75
194
|
}
|
|
76
195
|
async close() {
|
|
77
196
|
await this.#driver.close();
|
|
@@ -82,5 +201,5 @@ function createMongoRuntime(options) {
|
|
|
82
201
|
}
|
|
83
202
|
|
|
84
203
|
//#endregion
|
|
85
|
-
export { createMongoRuntime };
|
|
204
|
+
export { createMongoExecutionContext, createMongoExecutionStack, createMongoRuntime };
|
|
86
205
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["#adapter","#driver","#middleware","#middlewareContext"],"sources":["../src/mongo-runtime.ts"],"sourcesContent":["import type {\n RuntimeMiddleware,\n RuntimeMiddlewareContext,\n} from '@prisma-next/framework-components/runtime';\nimport {\n AsyncIterableResult,\n checkMiddlewareCompatibility,\n} from '@prisma-next/framework-components/runtime';\nimport type { MongoAdapter, MongoDriver } from '@prisma-next/mongo-lowering';\nimport type { MongoQueryPlan } from '@prisma-next/mongo-query-ast/execution';\n\nfunction noop() {}\nfunction now() {\n return Date.now();\n}\n\nexport interface MongoRuntimeOptions {\n readonly adapter: MongoAdapter;\n readonly driver: MongoDriver;\n readonly contract: unknown;\n readonly targetId: string;\n readonly middleware?: readonly RuntimeMiddleware[];\n readonly mode?: 'strict' | 'permissive';\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 #middleware: readonly RuntimeMiddleware[];\n readonly #middlewareContext: RuntimeMiddlewareContext;\n\n constructor(options: MongoRuntimeOptions) {\n this.#adapter = options.adapter;\n this.#driver = options.driver;\n\n const middleware = options.middleware ? [...options.middleware] : [];\n for (const mw of middleware) {\n checkMiddlewareCompatibility(mw, 'mongo', options.targetId);\n }\n this.#middleware = middleware;\n\n this.#middlewareContext = {\n contract: options.contract,\n mode: options.mode ?? 'strict',\n now,\n log: { info: noop, warn: noop, error: noop },\n };\n }\n\n execute<Row>(plan: MongoQueryPlan<Row>): AsyncIterableResult<Row> {\n const adapter = this.#adapter;\n const driver = this.#driver;\n const middleware = this.#middleware;\n const ctx = this.#middlewareContext;\n\n const iterator = async function* (): AsyncGenerator<Row, void, unknown> {\n const startedAt = ctx.now();\n let rowCount = 0;\n let completed = false;\n let failed = false;\n\n try {\n for (const mw of middleware) {\n if (mw.beforeExecute) {\n await mw.beforeExecute(plan, ctx);\n }\n }\n\n const wireCommand = adapter.lower(plan);\n\n for await (const row of driver.execute<Row>(wireCommand)) {\n for (const mw of middleware) {\n if (mw.onRow) {\n await mw.onRow(row as Record<string, unknown>, plan, ctx);\n }\n }\n rowCount++;\n yield row;\n }\n\n completed = true;\n } catch (error) {\n failed = true;\n throw error;\n } finally {\n const latencyMs = ctx.now() - startedAt;\n for (const mw of middleware) {\n if (!mw.afterExecute) continue;\n\n if (failed) {\n try {\n await mw.afterExecute(plan, { rowCount, latencyMs, completed }, ctx);\n } catch {\n // Ignore errors from afterExecute during error handling\n }\n continue;\n }\n\n await mw.afterExecute(plan, { rowCount, latencyMs, completed }, ctx);\n }\n }\n };\n\n return new AsyncIterableResult(iterator());\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":";;;AAWA,SAAS,OAAO;AAChB,SAAS,MAAM;AACb,QAAO,KAAK,KAAK;;AAiBnB,IAAM,mBAAN,MAA+C;CAC7C,CAASA;CACT,CAASC;CACT,CAASC;CACT,CAASC;CAET,YAAY,SAA8B;AACxC,QAAKH,UAAW,QAAQ;AACxB,QAAKC,SAAU,QAAQ;EAEvB,MAAM,aAAa,QAAQ,aAAa,CAAC,GAAG,QAAQ,WAAW,GA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
|
1
|
+
{"version":3,"file":"index.mjs","names":["contributors: ReadonlyArray<MongoStaticContributions & { readonly id: string }>","out: Record<string, unknown>","tasks: Array<Promise<void>>","nested: Record<string, unknown>","arr: unknown[]","#adapter","#driver","#codecs","ctx: MongoMiddlewareContext","codecCtx: CodecCallContext"],"sources":["../src/mongo-execution-stack.ts","../src/codecs/decoding.ts","../src/mongo-runtime.ts"],"sourcesContent":["import {\n createExecutionStack,\n type ExecutionStack,\n type RuntimeAdapterDescriptor,\n type RuntimeAdapterInstance,\n type RuntimeDriverDescriptor,\n type RuntimeDriverInstance,\n type RuntimeExtensionDescriptor,\n type RuntimeExtensionInstance,\n type RuntimeTargetDescriptor,\n type RuntimeTargetInstance,\n} from '@prisma-next/framework-components/execution';\nimport { runtimeError } from '@prisma-next/framework-components/runtime';\nimport type { MongoCodec } from '@prisma-next/mongo-codec';\nimport { createMongoCodecRegistry, type MongoCodecRegistry } from '@prisma-next/mongo-codec';\nimport type { MongoAdapter } from '@prisma-next/mongo-lowering';\n\n/**\n * Mongo-specific static contributions a runtime descriptor declares.\n *\n * Mirrors `SqlStaticContributions` in shape: a `codecs()` getter that yields\n * a `MongoCodecRegistry` populated with this contributor's codecs. The\n * registry is then walked by `createMongoExecutionContext` and folded into\n * the single per-execution registry the runtime reads from at decode time.\n */\nexport interface MongoStaticContributions {\n readonly codecs: () => MongoCodecRegistry;\n}\n\nexport interface MongoRuntimeTargetDescriptor<\n TTargetId extends string = 'mongo',\n TTargetInstance extends RuntimeTargetInstance<'mongo', TTargetId> = RuntimeTargetInstance<\n 'mongo',\n TTargetId\n >,\n> extends RuntimeTargetDescriptor<'mongo', TTargetId, TTargetInstance>,\n MongoStaticContributions {}\n\nexport interface MongoRuntimeAdapterInstance<TTargetId extends string = 'mongo'>\n extends RuntimeAdapterInstance<'mongo', TTargetId>,\n MongoAdapter {}\n\nexport interface MongoRuntimeAdapterDescriptor<\n TTargetId extends string = 'mongo',\n TAdapterInstance extends RuntimeAdapterInstance<\n 'mongo',\n TTargetId\n > = MongoRuntimeAdapterInstance<TTargetId>,\n> extends RuntimeAdapterDescriptor<'mongo', TTargetId, TAdapterInstance>,\n MongoStaticContributions {}\n\nexport interface MongoRuntimeExtensionInstance<TTargetId extends string = 'mongo'>\n extends RuntimeExtensionInstance<'mongo', TTargetId> {}\n\nexport interface MongoRuntimeExtensionDescriptor<TTargetId extends string = 'mongo'>\n extends RuntimeExtensionDescriptor<'mongo', TTargetId, MongoRuntimeExtensionInstance<TTargetId>>,\n MongoStaticContributions {\n create(): MongoRuntimeExtensionInstance<TTargetId>;\n}\n\n/**\n * The Mongo execution stack: target + adapter + optional driver + extension\n * packs. Mirrors `SqlExecutionStack`. Constructed via\n * `createMongoExecutionStack`.\n */\nexport interface MongoExecutionStack<TTargetId extends string = 'mongo'> {\n readonly target: MongoRuntimeTargetDescriptor<TTargetId>;\n readonly adapter: MongoRuntimeAdapterDescriptor<TTargetId>;\n readonly driver:\n | RuntimeDriverDescriptor<\n 'mongo',\n TTargetId,\n unknown,\n RuntimeDriverInstance<'mongo', TTargetId>\n >\n | undefined;\n readonly extensionPacks: readonly MongoRuntimeExtensionDescriptor<TTargetId>[];\n}\n\nexport function createMongoExecutionStack<TTargetId extends string = 'mongo'>(options: {\n readonly target: MongoRuntimeTargetDescriptor<TTargetId>;\n readonly adapter: MongoRuntimeAdapterDescriptor<TTargetId>;\n readonly driver?:\n | RuntimeDriverDescriptor<\n 'mongo',\n TTargetId,\n unknown,\n RuntimeDriverInstance<'mongo', TTargetId>\n >\n | undefined;\n readonly extensionPacks?: readonly MongoRuntimeExtensionDescriptor<TTargetId>[] | undefined;\n}): MongoExecutionStack<TTargetId> {\n const stack = createExecutionStack({\n target: options.target,\n adapter: options.adapter,\n driver: options.driver,\n extensionPacks: options.extensionPacks,\n });\n return stack as ExecutionStack<'mongo', TTargetId> as MongoExecutionStack<TTargetId>;\n}\n\n/**\n * Read-only view of the codec registry exposed on `MongoExecutionContext`.\n *\n * Hides `register()` and the iterator from public surface — users do not\n * mutate the per-execution codec registry. Internal aggregation in\n * `createMongoExecutionContext` keeps using the full `MongoCodecRegistry`\n * (it needs `register()`).\n */\nexport interface MongoCodecLookup {\n get(id: string): MongoCodec<string> | undefined;\n has(id: string): boolean;\n}\n\n/**\n * Per-execution context aggregated from a `MongoExecutionStack`.\n *\n * Carries the user's contract, a read-only lookup over the codec registry\n * composed from every stack contributor, and a back-reference to the stack\n * itself so the runtime can reach the adapter without users threading it\n * explicitly.\n *\n * Mirrors SQL's `ExecutionContext` in role; Mongo's flavour is leaner\n * because there are no parameterised codecs, JSON-schema validators, or\n * mutation-default generators in scope yet.\n */\nexport interface MongoExecutionContext<TTargetId extends string = 'mongo'> {\n readonly contract: unknown;\n readonly codecs: MongoCodecLookup;\n readonly stack: MongoExecutionStack<TTargetId>;\n}\n\nexport function createMongoExecutionContext<TTargetId extends string = 'mongo'>(options: {\n readonly contract: unknown;\n readonly stack: MongoExecutionStack<TTargetId>;\n}): MongoExecutionContext<TTargetId> {\n const registry = createMongoCodecRegistry();\n const owners = new Map<string, string>();\n\n const contributors: ReadonlyArray<MongoStaticContributions & { readonly id: string }> = [\n options.stack.target,\n options.stack.adapter,\n ...options.stack.extensionPacks,\n ];\n\n for (const contributor of contributors) {\n const contributed = contributor.codecs();\n for (const codec of iterateCodecs(contributed)) {\n const existingOwner = owners.get(codec.id);\n if (existingOwner !== undefined) {\n throw runtimeError(\n 'RUNTIME.DUPLICATE_CODEC',\n `Duplicate Mongo codec id '${codec.id}' contributed by '${contributor.id}' (already registered by '${existingOwner}').`,\n { codecId: codec.id, existingOwner, incomingOwner: contributor.id },\n );\n }\n registry.register(codec);\n owners.set(codec.id, contributor.id);\n }\n }\n\n return Object.freeze({\n contract: options.contract,\n codecs: registry,\n stack: options.stack,\n });\n}\n\nfunction* iterateCodecs(registry: MongoCodecRegistry): Iterable<MongoCodec<string>> {\n yield* registry.values();\n}\n","import type { CodecCallContext } from '@prisma-next/framework-components/codec';\nimport { runtimeError } from '@prisma-next/framework-components/runtime';\nimport type { MongoFieldShape, MongoResultShape } from '@prisma-next/mongo-query-ast/execution';\nimport type { MongoCodecLookup } from '../mongo-execution-stack';\n\nconst WIRE_PREVIEW_LIMIT = 100;\n\nfunction previewWireValue(wireValue: unknown): string {\n if (typeof wireValue === 'string') {\n return wireValue.length > WIRE_PREVIEW_LIMIT\n ? `${wireValue.substring(0, WIRE_PREVIEW_LIMIT)}...`\n : wireValue;\n }\n return String(wireValue).substring(0, WIRE_PREVIEW_LIMIT);\n}\n\nfunction wrapDecodeFailure(\n error: unknown,\n collection: string,\n path: string,\n codecId: string,\n wireValue: unknown,\n): never {\n const message = error instanceof Error ? error.message : String(error);\n const wrapped = runtimeError(\n 'RUNTIME.DECODE_FAILED',\n `Failed to decode field ${path} in collection '${collection}' with codec '${codecId}': ${message}`,\n {\n collection,\n path,\n codec: codecId,\n wirePreview: previewWireValue(wireValue),\n },\n );\n wrapped.cause = error;\n throw wrapped;\n}\n\nexport async function decodeMongoRow(\n row: unknown,\n shape: MongoResultShape,\n registry: MongoCodecLookup,\n collection: string,\n ctx: CodecCallContext = {},\n): Promise<unknown> {\n if (shape.kind === 'unknown') {\n return row;\n }\n if (typeof row !== 'object' || row === null) {\n return row;\n }\n const rowObj = row as Record<string, unknown>;\n const out: Record<string, unknown> = {};\n const tasks: Array<Promise<void>> = [];\n\n function scheduleLeaf(\n path: string,\n codecId: string,\n wire: unknown,\n assign: (v: unknown) => void,\n ): void {\n const codec = registry.get(codecId);\n if (!codec) {\n assign(wire);\n return;\n }\n tasks.push(\n (async () => {\n try {\n assign(await codec.decode(wire, ctx));\n } catch (error) {\n wrapDecodeFailure(error, collection, path, codecId, wire);\n }\n })(),\n );\n }\n\n function walkField(\n value: unknown,\n fieldShape: MongoFieldShape,\n path: string,\n assign: (v: unknown) => void,\n ): void {\n // Exhaustive over `MongoFieldShape['kind']` by construction:\n // adding a new variant must add a corresponding arm or the\n // `satisfies never` below would error at type-check time.\n switch (fieldShape.kind) {\n case 'unknown':\n assign(value);\n return;\n case 'leaf':\n if (value === null || value === undefined) {\n assign(value);\n return;\n }\n scheduleLeaf(path, fieldShape.codecId, value, assign);\n return;\n case 'document': {\n if (value === null || value === undefined) {\n assign(value);\n return;\n }\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n assign(value);\n return;\n }\n const vObj = value as Record<string, unknown>;\n // Pre-seed with a shallow copy so unshaped subdocument keys\n // round-trip verbatim. Subsequent walkField assignments overwrite\n // shaped keys with their decoded values. Mirrors the top-level\n // pass-through invariant — the decode path is structurally\n // additive at every nesting depth, not just the root.\n const nested: Record<string, unknown> = { ...vObj };\n assign(nested);\n for (const [fk, fShape] of Object.entries(fieldShape.fields)) {\n walkField(vObj[fk], fShape, `${path}.${fk}`, (v) => {\n nested[fk] = v;\n });\n }\n return;\n }\n case 'array': {\n if (value === null || value === undefined) {\n assign(value);\n return;\n }\n if (!Array.isArray(value)) {\n assign(value);\n return;\n }\n const arr: unknown[] = [];\n assign(arr);\n for (let i = 0; i < value.length; i++) {\n const el = value[i];\n walkField(el, fieldShape.element, `${path}.${i}`, (v) => {\n arr[i] = v;\n });\n }\n return;\n }\n }\n // The switch above is exhaustive over `MongoFieldShape['kind']`. The\n // `satisfies never` below is a compile-time guard that fails if a new\n // variant is added without a corresponding arm.\n /* v8 ignore start */\n fieldShape satisfies never;\n /* v8 ignore stop */\n }\n\n for (const [k, fShape] of Object.entries(shape.fields)) {\n walkField(rowObj[k], fShape, k, (v) => {\n out[k] = v;\n });\n }\n\n // Pass through any row fields the shape does not describe. The shape is a\n // partial, lane-vouched description of what the runtime knows how to decode;\n // fields outside that description (e.g. polymorphic variant fields the base\n // model's shape doesn't enumerate, sidecar fields a future schema migration\n // adds) round-trip verbatim. Drop semantics belongs to explicit projection\n // (`select` / `$project`), not to the structural decode path.\n for (const k of Object.keys(rowObj)) {\n if (!Object.hasOwn(shape.fields, k)) {\n out[k] = rowObj[k];\n }\n }\n\n await Promise.all(tasks);\n return out;\n}\n","import type { CodecCallContext } from '@prisma-next/framework-components/codec';\nimport {\n AsyncIterableResult,\n checkAborted,\n checkMiddlewareCompatibility,\n RuntimeCore,\n type RuntimeExecuteOptions,\n runWithMiddleware,\n} from '@prisma-next/framework-components/runtime';\nimport type { MongoAdapter, MongoDriver } from '@prisma-next/mongo-lowering';\nimport type { MongoQueryPlan } from '@prisma-next/mongo-query-ast/execution';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { decodeMongoRow } from './codecs/decoding';\nimport type { MongoExecutionPlan } from './mongo-execution-plan';\nimport type { MongoCodecLookup, MongoExecutionContext } from './mongo-execution-stack';\nimport type { MongoMiddleware, MongoMiddlewareContext } from './mongo-middleware';\n\nfunction noop() {}\n\n/**\n * Mongo runtime options.\n *\n * The runtime takes a {@link MongoExecutionContext} (built via\n * `createMongoExecutionContext`) and a driver. Codec resolution flows from\n * the context — there is no `codecs` field on this options bag. The adapter\n * is reached via `context.stack.adapter` (instantiated lazily through the\n * stack's `create(stack)` factory). See ADR — Mongo result-shape as a\n * structural plan field, § Codec registry: stack aggregation, not user\n * threading.\n */\nexport interface MongoRuntimeOptions {\n readonly context: MongoExecutionContext;\n readonly driver: MongoDriver;\n readonly middleware?: readonly MongoMiddleware[];\n readonly mode?: 'strict' | 'permissive';\n}\n\nexport interface MongoRuntime {\n /**\n * Execute a `MongoQueryPlan` and return an async iterable of rows.\n *\n * The optional `options.signal` is threaded through\n * `lower → adapter.lower → resolveValue → codec.encode` so codec authors\n * who forward the signal to their underlying SDK get true cancellation\n * of in-flight network calls. The runtime additionally observes the\n * signal at two boundaries:\n *\n * - **Already-aborted at entry** — first `next()` throws\n * `RUNTIME.ABORTED { phase: 'stream' }` before any work is done.\n * (Inherited from `RuntimeCore.execute`.)\n * - **Mid-encode abort** — surfaces as\n * `RUNTIME.ABORTED { phase: 'encode' }` from inside `resolveValue`'s\n * per-level `Promise.all` race.\n *\n * Mongo's read path decodes rows via `resultShape` (per ADR 209). The\n * same `CodecCallContext` is forwarded into each `codec.decode(wire, ctx)`\n * call, so async decoders that respect the signal get cancellation; the\n * runtime itself does not currently emit a `phase: 'decode'` envelope.\n */\n execute<Row>(\n plan: MongoQueryPlan<Row>,\n options?: RuntimeExecuteOptions,\n ): AsyncIterableResult<Row>;\n close(): Promise<void>;\n}\n\nclass MongoRuntimeImpl\n extends RuntimeCore<MongoQueryPlan, MongoExecutionPlan, MongoMiddleware>\n implements MongoRuntime\n{\n readonly #adapter: MongoAdapter;\n readonly #driver: MongoDriver;\n readonly #codecs: MongoCodecLookup;\n\n constructor(options: MongoRuntimeOptions) {\n const middleware = options.middleware ? [...options.middleware] : [];\n const targetId = options.context.stack.target.targetId;\n for (const mw of middleware) {\n checkMiddlewareCompatibility(mw, 'mongo', targetId);\n }\n\n const ctx: MongoMiddlewareContext = {\n contract: options.context.contract,\n mode: options.mode ?? 'strict',\n now: () => Date.now(),\n log: { info: noop, warn: noop, error: noop },\n };\n\n super({ middleware, ctx });\n\n const adapterDescriptor = options.context.stack.adapter;\n const adapterInstance = adapterDescriptor.create(options.context.stack);\n this.#adapter = adapterInstance;\n this.#driver = options.driver;\n this.#codecs = options.context.codecs;\n }\n\n protected override async lower(\n plan: MongoQueryPlan,\n ctx: CodecCallContext,\n ): Promise<MongoExecutionPlan> {\n return {\n command: await this.#adapter.lower(plan, ctx),\n meta: plan.meta,\n ...ifDefined('resultShape', plan.resultShape),\n };\n }\n\n protected override runDriver(exec: MongoExecutionPlan): AsyncIterable<Record<string, unknown>> {\n return this.#driver.execute<Record<string, unknown>>(exec.command);\n }\n\n override execute<Row>(\n plan: MongoQueryPlan & { readonly _row?: Row },\n options?: RuntimeExecuteOptions,\n ): AsyncIterableResult<Row> {\n const self = this;\n const signal = options?.signal;\n const codecCtx: CodecCallContext = signal === undefined ? {} : { signal };\n const generator = async function* (): AsyncGenerator<Row, void, unknown> {\n checkAborted(codecCtx, 'stream');\n const compiled = await self.runBeforeCompile(plan);\n const exec = await self.lower(compiled, codecCtx);\n const stream = runWithMiddleware<MongoExecutionPlan, Record<string, unknown>>(\n exec,\n self.middleware,\n self.ctx,\n () => self.runDriver(exec),\n );\n for await (const rawRow of stream) {\n if (exec.resultShape === undefined) {\n yield rawRow as Row;\n } else {\n // Source the collection from the lowered exec rather than the\n // pre-lowering plan: a `runBeforeCompile` middleware is allowed to\n // rewrite collection names during compilation, and the wire\n // command carried by `exec` is always authoritative for what just\n // ran.\n const decoded = await decodeMongoRow(\n rawRow,\n exec.resultShape,\n self.#codecs,\n exec.command.collection,\n codecCtx,\n );\n yield decoded as Row;\n }\n }\n };\n return new AsyncIterableResult(generator());\n }\n\n override 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":";;;;;;AA+EA,SAAgB,0BAA8D,SAY3C;AAOjC,QANc,qBAAqB;EACjC,QAAQ,QAAQ;EAChB,SAAS,QAAQ;EACjB,QAAQ,QAAQ;EAChB,gBAAgB,QAAQ;EACzB,CAAC;;AAmCJ,SAAgB,4BAAgE,SAG3C;CACnC,MAAM,WAAW,0BAA0B;CAC3C,MAAM,yBAAS,IAAI,KAAqB;CAExC,MAAMA,eAAkF;EACtF,QAAQ,MAAM;EACd,QAAQ,MAAM;EACd,GAAG,QAAQ,MAAM;EAClB;AAED,MAAK,MAAM,eAAe,cAAc;EACtC,MAAM,cAAc,YAAY,QAAQ;AACxC,OAAK,MAAM,SAAS,cAAc,YAAY,EAAE;GAC9C,MAAM,gBAAgB,OAAO,IAAI,MAAM,GAAG;AAC1C,OAAI,kBAAkB,OACpB,OAAM,aACJ,2BACA,6BAA6B,MAAM,GAAG,oBAAoB,YAAY,GAAG,4BAA4B,cAAc,MACnH;IAAE,SAAS,MAAM;IAAI;IAAe,eAAe,YAAY;IAAI,CACpE;AAEH,YAAS,SAAS,MAAM;AACxB,UAAO,IAAI,MAAM,IAAI,YAAY,GAAG;;;AAIxC,QAAO,OAA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