@prisma-next/mongo-lowering 0.11.0 → 0.12.0
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 +1 -1
- package/dist/index.d.mts +123 -15
- package/dist/index.d.mts.map +1 -1
- package/package.json +18 -7
- package/src/adapter-types.ts +143 -14
- package/src/exports/index.ts +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Adapter and driver interface contracts for the MongoDB transport layer.
|
|
|
4
4
|
|
|
5
5
|
## Responsibilities
|
|
6
6
|
|
|
7
|
-
- **Adapter interface**: `MongoAdapter` — defines `lower(plan: MongoQueryPlan): Promise<AnyMongoWireCommand
|
|
7
|
+
- **Adapter interface**: `MongoAdapter` — defines `lower(plan: MongoQueryPlan): Promise<AnyMongoWireCommand>` (one-shot `resolveParams(structuralLower(plan))`), plus the two-phase split `structuralLower` / `resolveParams` used by `@prisma-next/mongo-runtime` so `beforeExecute` middleware can mutate `MongoParamRef` leaves before codec resolution. Those phase methods are public on this SPI (unlike SQL's private `lowerToDraft` / `encodeDraftParams` on the SQL runtime) because lowering is target-owned through the adapter on the execution stack. Rationale and SQL contrast: [ADR 215 — Mongo family: lifecycle parity and intentional placement asymmetries](../../../../docs/architecture%20docs/adrs/ADR%20215%20-%20Runtime%20middleware%20lifecycle%20beforeExecute%20before%20encodeParams.md#mongo-family-lifecycle-parity-and-intentional-placement-asymmetries).
|
|
8
8
|
- **Driver interface**: `MongoDriver` — defines `execute<Row>(wireCommand): AsyncIterable<Row>` and `close()`, the contract for sending wire commands to a MongoDB instance
|
|
9
9
|
|
|
10
10
|
## Dependencies
|
package/dist/index.d.mts
CHANGED
|
@@ -3,26 +3,134 @@ import { MongoQueryPlan } from "@prisma-next/mongo-query-ast/execution";
|
|
|
3
3
|
import { AnyMongoWireCommand } from "@prisma-next/mongo-wire";
|
|
4
4
|
|
|
5
5
|
//#region src/adapter-types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Intermediate state produced by structural lowering. `MongoParamRef` leaves
|
|
8
|
+
* remain in place — they have not yet been resolved through codecs. The
|
|
9
|
+
* runtime defers value resolution past the `beforeExecute` middleware chain
|
|
10
|
+
* so middleware can walk and rewrite `MongoParamRef` nodes before encoding.
|
|
11
|
+
*
|
|
12
|
+
* All document/filter/update slots that may carry `MongoParamRef` nodes are
|
|
13
|
+
* typed as `Record<string, unknown>` to allow heterogeneous values. Raw
|
|
14
|
+
* command variants carry already-resolved `Record<string, unknown>` values
|
|
15
|
+
* and pass through unchanged.
|
|
16
|
+
*/
|
|
17
|
+
type MongoLoweredDraft = {
|
|
18
|
+
readonly kind: 'insertOne';
|
|
19
|
+
readonly collection: string;
|
|
20
|
+
readonly document: Record<string, unknown>;
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: 'insertMany';
|
|
23
|
+
readonly collection: string;
|
|
24
|
+
readonly documents: ReadonlyArray<Record<string, unknown>>;
|
|
25
|
+
} | {
|
|
26
|
+
readonly kind: 'updateOne';
|
|
27
|
+
readonly collection: string;
|
|
28
|
+
readonly filter: Record<string, unknown>;
|
|
29
|
+
readonly update: Record<string, unknown> | ReadonlyArray<Record<string, unknown>>;
|
|
30
|
+
readonly upsert: boolean | undefined;
|
|
31
|
+
} | {
|
|
32
|
+
readonly kind: 'updateMany';
|
|
33
|
+
readonly collection: string;
|
|
34
|
+
readonly filter: Record<string, unknown>;
|
|
35
|
+
readonly update: Record<string, unknown> | ReadonlyArray<Record<string, unknown>>;
|
|
36
|
+
readonly upsert: boolean | undefined;
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: 'deleteOne';
|
|
39
|
+
readonly collection: string;
|
|
40
|
+
readonly filter: Record<string, unknown>;
|
|
41
|
+
} | {
|
|
42
|
+
readonly kind: 'deleteMany';
|
|
43
|
+
readonly collection: string;
|
|
44
|
+
readonly filter: Record<string, unknown>;
|
|
45
|
+
} | {
|
|
46
|
+
readonly kind: 'findOneAndUpdate';
|
|
47
|
+
readonly collection: string;
|
|
48
|
+
readonly filter: Record<string, unknown>;
|
|
49
|
+
readonly update: Record<string, unknown> | ReadonlyArray<Record<string, unknown>>;
|
|
50
|
+
readonly upsert: boolean | undefined;
|
|
51
|
+
readonly sort: Record<string, 1 | -1> | undefined;
|
|
52
|
+
readonly returnDocument: 'before' | 'after' | undefined;
|
|
53
|
+
} | {
|
|
54
|
+
readonly kind: 'findOneAndDelete';
|
|
55
|
+
readonly collection: string;
|
|
56
|
+
readonly filter: Record<string, unknown>;
|
|
57
|
+
readonly sort: Record<string, 1 | -1> | undefined;
|
|
58
|
+
} | {
|
|
59
|
+
readonly kind: 'aggregate';
|
|
60
|
+
readonly collection: string;
|
|
61
|
+
readonly pipeline: ReadonlyArray<Record<string, unknown>>;
|
|
62
|
+
} | {
|
|
63
|
+
readonly kind: 'rawInsertOne';
|
|
64
|
+
readonly collection: string;
|
|
65
|
+
readonly document: Record<string, unknown>;
|
|
66
|
+
} | {
|
|
67
|
+
readonly kind: 'rawInsertMany';
|
|
68
|
+
readonly collection: string;
|
|
69
|
+
readonly documents: ReadonlyArray<Record<string, unknown>>;
|
|
70
|
+
} | {
|
|
71
|
+
readonly kind: 'rawUpdateOne';
|
|
72
|
+
readonly collection: string;
|
|
73
|
+
readonly filter: Record<string, unknown>;
|
|
74
|
+
readonly update: Record<string, unknown> | ReadonlyArray<Record<string, unknown>>;
|
|
75
|
+
} | {
|
|
76
|
+
readonly kind: 'rawUpdateMany';
|
|
77
|
+
readonly collection: string;
|
|
78
|
+
readonly filter: Record<string, unknown>;
|
|
79
|
+
readonly update: Record<string, unknown> | ReadonlyArray<Record<string, unknown>>;
|
|
80
|
+
} | {
|
|
81
|
+
readonly kind: 'rawDeleteOne';
|
|
82
|
+
readonly collection: string;
|
|
83
|
+
readonly filter: Record<string, unknown>;
|
|
84
|
+
} | {
|
|
85
|
+
readonly kind: 'rawDeleteMany';
|
|
86
|
+
readonly collection: string;
|
|
87
|
+
readonly filter: Record<string, unknown>;
|
|
88
|
+
} | {
|
|
89
|
+
readonly kind: 'rawFindOneAndUpdate';
|
|
90
|
+
readonly collection: string;
|
|
91
|
+
readonly filter: Record<string, unknown>;
|
|
92
|
+
readonly update: Record<string, unknown> | ReadonlyArray<Record<string, unknown>>;
|
|
93
|
+
readonly upsert: boolean;
|
|
94
|
+
readonly sort: Record<string, 1 | -1> | undefined;
|
|
95
|
+
readonly returnDocument: 'before' | 'after' | undefined;
|
|
96
|
+
} | {
|
|
97
|
+
readonly kind: 'rawFindOneAndDelete';
|
|
98
|
+
readonly collection: string;
|
|
99
|
+
readonly filter: Record<string, unknown>;
|
|
100
|
+
readonly sort: Record<string, 1 | -1> | undefined;
|
|
101
|
+
} | {
|
|
102
|
+
readonly kind: 'rawAggregate';
|
|
103
|
+
readonly collection: string;
|
|
104
|
+
readonly pipeline: ReadonlyArray<Record<string, unknown>>;
|
|
105
|
+
};
|
|
6
106
|
interface MongoAdapter {
|
|
7
107
|
/**
|
|
8
108
|
* Lower a `MongoQueryPlan` to a driver-ready wire command.
|
|
9
109
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* ctx per execute and threads the same reference through
|
|
13
|
-
* `lower → resolveValue → codec.encode`, so codec authors observe
|
|
14
|
-
* **signal identity** across the whole encode dispatch. The `signal`
|
|
15
|
-
* field inside the ctx may be `undefined`, but the ctx object itself
|
|
16
|
-
* is always present.
|
|
17
|
-
*
|
|
18
|
-
* Implementations are expected to:
|
|
19
|
-
* - Pass `ctx` through to every `resolveValue` call so the per-level
|
|
20
|
-
* `Promise.all` race can observe the signal.
|
|
21
|
-
* - Surface `RUNTIME.ABORTED { phase: 'encode' }` (via `runtimeAborted`)
|
|
22
|
-
* from inside `resolveValue` when the signal aborts mid-flight; no
|
|
23
|
-
* adapter-level abort handling is required beyond ctx forwarding.
|
|
110
|
+
* Equivalent to `resolveParams(structuralLower(plan), ctx)`. Preserved for
|
|
111
|
+
* callers that do not need the two-phase split.
|
|
24
112
|
*/
|
|
25
113
|
lower(plan: MongoQueryPlan, ctx: CodecCallContext): Promise<AnyMongoWireCommand>;
|
|
114
|
+
/**
|
|
115
|
+
* Phase 1 of the two-phase lowering pipeline.
|
|
116
|
+
*
|
|
117
|
+
* Transforms the plan's command AST into the lowered wire shape **without**
|
|
118
|
+
* calling `resolveValue` on any `MongoParamRef` leaf. All filter predicates,
|
|
119
|
+
* document fields, and pipeline stage values that carry `MongoParamRef`
|
|
120
|
+
* nodes are preserved in the returned `MongoLoweredDraft` so that the
|
|
121
|
+
* `beforeExecute` middleware chain can inspect and rewrite them before
|
|
122
|
+
* encoding runs. Synchronous — no I/O or codec calls.
|
|
123
|
+
*/
|
|
124
|
+
structuralLower(plan: MongoQueryPlan): MongoLoweredDraft;
|
|
125
|
+
/**
|
|
126
|
+
* Phase 2 of the two-phase lowering pipeline.
|
|
127
|
+
*
|
|
128
|
+
* Walks the `MongoLoweredDraft` produced by `structuralLower`, resolves
|
|
129
|
+
* every `MongoParamRef` leaf through the codec registry, and constructs the
|
|
130
|
+
* frozen `AnyMongoWireCommand` ready for the driver. The same abort-signal
|
|
131
|
+
* forwarding and `RUNTIME.ABORTED` surface contract as `lower` applies.
|
|
132
|
+
*/
|
|
133
|
+
resolveParams(draft: MongoLoweredDraft, ctx: CodecCallContext): Promise<AnyMongoWireCommand>;
|
|
26
134
|
}
|
|
27
135
|
//#endregion
|
|
28
136
|
//#region src/driver-types.d.ts
|
|
@@ -31,5 +139,5 @@ interface MongoDriver {
|
|
|
31
139
|
close(): Promise<void>;
|
|
32
140
|
}
|
|
33
141
|
//#endregion
|
|
34
|
-
export { type MongoAdapter, type MongoDriver };
|
|
142
|
+
export { type MongoAdapter, type MongoDriver, type MongoLoweredDraft };
|
|
35
143
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/adapter-types.ts","../src/driver-types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"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
2
2
|
"name": "@prisma-next/mongo-lowering",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "Adapter and driver interfaces for Prisma Next MongoDB lowering",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/framework-components": "0.
|
|
10
|
-
"@prisma-next/mongo-query-ast": "0.
|
|
11
|
-
"@prisma-next/mongo-wire": "0.
|
|
9
|
+
"@prisma-next/framework-components": "0.12.0",
|
|
10
|
+
"@prisma-next/mongo-query-ast": "0.12.0",
|
|
11
|
+
"@prisma-next/mongo-wire": "0.12.0"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@prisma-next/tsconfig": "0.
|
|
15
|
-
"@prisma-next/tsdown": "0.
|
|
14
|
+
"@prisma-next/tsconfig": "0.12.0",
|
|
15
|
+
"@prisma-next/tsdown": "0.12.0",
|
|
16
16
|
"tsdown": "0.22.0",
|
|
17
17
|
"typescript": "5.9.3",
|
|
18
18
|
"vitest": "4.1.6"
|
|
19
19
|
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"typescript": ">=5.9"
|
|
22
|
+
},
|
|
23
|
+
"peerDependenciesMeta": {
|
|
24
|
+
"typescript": {
|
|
25
|
+
"optional": true
|
|
26
|
+
}
|
|
27
|
+
},
|
|
20
28
|
"files": [
|
|
21
29
|
"dist",
|
|
22
30
|
"src"
|
|
23
31
|
],
|
|
32
|
+
"types": "./dist/index.d.mts",
|
|
24
33
|
"exports": {
|
|
25
34
|
".": "./dist/index.mjs",
|
|
26
35
|
"./package.json": "./package.json"
|
|
27
36
|
},
|
|
28
|
-
"
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=24"
|
|
39
|
+
},
|
|
29
40
|
"repository": {
|
|
30
41
|
"type": "git",
|
|
31
42
|
"url": "https://github.com/prisma/prisma-next.git",
|
package/src/adapter-types.ts
CHANGED
|
@@ -2,24 +2,153 @@ import type { CodecCallContext } from '@prisma-next/framework-components/codec';
|
|
|
2
2
|
import type { MongoQueryPlan } from '@prisma-next/mongo-query-ast/execution';
|
|
3
3
|
import type { AnyMongoWireCommand } from '@prisma-next/mongo-wire';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Intermediate state produced by structural lowering. `MongoParamRef` leaves
|
|
7
|
+
* remain in place — they have not yet been resolved through codecs. The
|
|
8
|
+
* runtime defers value resolution past the `beforeExecute` middleware chain
|
|
9
|
+
* so middleware can walk and rewrite `MongoParamRef` nodes before encoding.
|
|
10
|
+
*
|
|
11
|
+
* All document/filter/update slots that may carry `MongoParamRef` nodes are
|
|
12
|
+
* typed as `Record<string, unknown>` to allow heterogeneous values. Raw
|
|
13
|
+
* command variants carry already-resolved `Record<string, unknown>` values
|
|
14
|
+
* and pass through unchanged.
|
|
15
|
+
*/
|
|
16
|
+
export type MongoLoweredDraft =
|
|
17
|
+
| {
|
|
18
|
+
readonly kind: 'insertOne';
|
|
19
|
+
readonly collection: string;
|
|
20
|
+
readonly document: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
| {
|
|
23
|
+
readonly kind: 'insertMany';
|
|
24
|
+
readonly collection: string;
|
|
25
|
+
readonly documents: ReadonlyArray<Record<string, unknown>>;
|
|
26
|
+
}
|
|
27
|
+
| {
|
|
28
|
+
readonly kind: 'updateOne';
|
|
29
|
+
readonly collection: string;
|
|
30
|
+
readonly filter: Record<string, unknown>;
|
|
31
|
+
readonly update: Record<string, unknown> | ReadonlyArray<Record<string, unknown>>;
|
|
32
|
+
readonly upsert: boolean | undefined;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
readonly kind: 'updateMany';
|
|
36
|
+
readonly collection: string;
|
|
37
|
+
readonly filter: Record<string, unknown>;
|
|
38
|
+
readonly update: Record<string, unknown> | ReadonlyArray<Record<string, unknown>>;
|
|
39
|
+
readonly upsert: boolean | undefined;
|
|
40
|
+
}
|
|
41
|
+
| {
|
|
42
|
+
readonly kind: 'deleteOne';
|
|
43
|
+
readonly collection: string;
|
|
44
|
+
readonly filter: Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
| {
|
|
47
|
+
readonly kind: 'deleteMany';
|
|
48
|
+
readonly collection: string;
|
|
49
|
+
readonly filter: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
| {
|
|
52
|
+
readonly kind: 'findOneAndUpdate';
|
|
53
|
+
readonly collection: string;
|
|
54
|
+
readonly filter: Record<string, unknown>;
|
|
55
|
+
readonly update: Record<string, unknown> | ReadonlyArray<Record<string, unknown>>;
|
|
56
|
+
readonly upsert: boolean | undefined;
|
|
57
|
+
readonly sort: Record<string, 1 | -1> | undefined;
|
|
58
|
+
readonly returnDocument: 'before' | 'after' | undefined;
|
|
59
|
+
}
|
|
60
|
+
| {
|
|
61
|
+
readonly kind: 'findOneAndDelete';
|
|
62
|
+
readonly collection: string;
|
|
63
|
+
readonly filter: Record<string, unknown>;
|
|
64
|
+
readonly sort: Record<string, 1 | -1> | undefined;
|
|
65
|
+
}
|
|
66
|
+
| {
|
|
67
|
+
readonly kind: 'aggregate';
|
|
68
|
+
readonly collection: string;
|
|
69
|
+
readonly pipeline: ReadonlyArray<Record<string, unknown>>;
|
|
70
|
+
}
|
|
71
|
+
| {
|
|
72
|
+
readonly kind: 'rawInsertOne';
|
|
73
|
+
readonly collection: string;
|
|
74
|
+
readonly document: Record<string, unknown>;
|
|
75
|
+
}
|
|
76
|
+
| {
|
|
77
|
+
readonly kind: 'rawInsertMany';
|
|
78
|
+
readonly collection: string;
|
|
79
|
+
readonly documents: ReadonlyArray<Record<string, unknown>>;
|
|
80
|
+
}
|
|
81
|
+
| {
|
|
82
|
+
readonly kind: 'rawUpdateOne';
|
|
83
|
+
readonly collection: string;
|
|
84
|
+
readonly filter: Record<string, unknown>;
|
|
85
|
+
readonly update: Record<string, unknown> | ReadonlyArray<Record<string, unknown>>;
|
|
86
|
+
}
|
|
87
|
+
| {
|
|
88
|
+
readonly kind: 'rawUpdateMany';
|
|
89
|
+
readonly collection: string;
|
|
90
|
+
readonly filter: Record<string, unknown>;
|
|
91
|
+
readonly update: Record<string, unknown> | ReadonlyArray<Record<string, unknown>>;
|
|
92
|
+
}
|
|
93
|
+
| {
|
|
94
|
+
readonly kind: 'rawDeleteOne';
|
|
95
|
+
readonly collection: string;
|
|
96
|
+
readonly filter: Record<string, unknown>;
|
|
97
|
+
}
|
|
98
|
+
| {
|
|
99
|
+
readonly kind: 'rawDeleteMany';
|
|
100
|
+
readonly collection: string;
|
|
101
|
+
readonly filter: Record<string, unknown>;
|
|
102
|
+
}
|
|
103
|
+
| {
|
|
104
|
+
readonly kind: 'rawFindOneAndUpdate';
|
|
105
|
+
readonly collection: string;
|
|
106
|
+
readonly filter: Record<string, unknown>;
|
|
107
|
+
readonly update: Record<string, unknown> | ReadonlyArray<Record<string, unknown>>;
|
|
108
|
+
readonly upsert: boolean;
|
|
109
|
+
readonly sort: Record<string, 1 | -1> | undefined;
|
|
110
|
+
readonly returnDocument: 'before' | 'after' | undefined;
|
|
111
|
+
}
|
|
112
|
+
| {
|
|
113
|
+
readonly kind: 'rawFindOneAndDelete';
|
|
114
|
+
readonly collection: string;
|
|
115
|
+
readonly filter: Record<string, unknown>;
|
|
116
|
+
readonly sort: Record<string, 1 | -1> | undefined;
|
|
117
|
+
}
|
|
118
|
+
| {
|
|
119
|
+
readonly kind: 'rawAggregate';
|
|
120
|
+
readonly collection: string;
|
|
121
|
+
readonly pipeline: ReadonlyArray<Record<string, unknown>>;
|
|
122
|
+
};
|
|
123
|
+
|
|
5
124
|
export interface MongoAdapter {
|
|
6
125
|
/**
|
|
7
126
|
* Lower a `MongoQueryPlan` to a driver-ready wire command.
|
|
8
127
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* ctx per execute and threads the same reference through
|
|
12
|
-
* `lower → resolveValue → codec.encode`, so codec authors observe
|
|
13
|
-
* **signal identity** across the whole encode dispatch. The `signal`
|
|
14
|
-
* field inside the ctx may be `undefined`, but the ctx object itself
|
|
15
|
-
* is always present.
|
|
16
|
-
*
|
|
17
|
-
* Implementations are expected to:
|
|
18
|
-
* - Pass `ctx` through to every `resolveValue` call so the per-level
|
|
19
|
-
* `Promise.all` race can observe the signal.
|
|
20
|
-
* - Surface `RUNTIME.ABORTED { phase: 'encode' }` (via `runtimeAborted`)
|
|
21
|
-
* from inside `resolveValue` when the signal aborts mid-flight; no
|
|
22
|
-
* adapter-level abort handling is required beyond ctx forwarding.
|
|
128
|
+
* Equivalent to `resolveParams(structuralLower(plan), ctx)`. Preserved for
|
|
129
|
+
* callers that do not need the two-phase split.
|
|
23
130
|
*/
|
|
24
131
|
lower(plan: MongoQueryPlan, ctx: CodecCallContext): Promise<AnyMongoWireCommand>;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Phase 1 of the two-phase lowering pipeline.
|
|
135
|
+
*
|
|
136
|
+
* Transforms the plan's command AST into the lowered wire shape **without**
|
|
137
|
+
* calling `resolveValue` on any `MongoParamRef` leaf. All filter predicates,
|
|
138
|
+
* document fields, and pipeline stage values that carry `MongoParamRef`
|
|
139
|
+
* nodes are preserved in the returned `MongoLoweredDraft` so that the
|
|
140
|
+
* `beforeExecute` middleware chain can inspect and rewrite them before
|
|
141
|
+
* encoding runs. Synchronous — no I/O or codec calls.
|
|
142
|
+
*/
|
|
143
|
+
structuralLower(plan: MongoQueryPlan): MongoLoweredDraft;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Phase 2 of the two-phase lowering pipeline.
|
|
147
|
+
*
|
|
148
|
+
* Walks the `MongoLoweredDraft` produced by `structuralLower`, resolves
|
|
149
|
+
* every `MongoParamRef` leaf through the codec registry, and constructs the
|
|
150
|
+
* frozen `AnyMongoWireCommand` ready for the driver. The same abort-signal
|
|
151
|
+
* forwarding and `RUNTIME.ABORTED` surface contract as `lower` applies.
|
|
152
|
+
*/
|
|
153
|
+
resolveParams(draft: MongoLoweredDraft, ctx: CodecCallContext): Promise<AnyMongoWireCommand>;
|
|
25
154
|
}
|
package/src/exports/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { MongoAdapter } from '../adapter-types';
|
|
1
|
+
export type { MongoAdapter, MongoLoweredDraft } from '../adapter-types';
|
|
2
2
|
export type { MongoDriver } from '../driver-types';
|