@prisma-next/mongo-query-builder 0.5.0-dev.65 → 0.5.0-dev.67

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/index.d.mts CHANGED
@@ -4,7 +4,6 @@ import { MongoValue } from "@prisma-next/mongo-value";
4
4
  import { ContractField } from "@prisma-next/contract/types";
5
5
 
6
6
  //#region src/resolve-path.d.ts
7
-
8
7
  /**
9
8
  * Marker `DocField` variant representing a non-leaf (value-object) path in
10
9
  * a [NestedDocShape]. Extends `DocField` with a `fields` property carrying
@@ -21,10 +20,10 @@ import { ContractField } from "@prisma-next/contract/types";
21
20
  * nullable parent resolves to the leaf's own `nullable` — matching how
22
21
  * MongoDB treats missing intermediate documents).
23
22
  */
24
- interface ObjectField<N$1 extends NestedDocShape> extends DocField {
23
+ interface ObjectField<N extends NestedDocShape> extends DocField {
25
24
  readonly codecId: 'prisma/object@1';
26
25
  readonly nullable: boolean;
27
- readonly fields: N$1;
26
+ readonly fields: N;
28
27
  }
29
28
  /**
30
29
  * Marker `DocField` variant representing "an array of foreign-model rows"
@@ -40,10 +39,10 @@ interface ObjectField<N$1 extends NestedDocShape> extends DocField {
40
39
  * runtime shape is unchanged; the marker exists solely to thread the
41
40
  * foreign element type through the result-row resolver.
42
41
  */
43
- interface ModelArrayField<ModelName$1 extends string> extends DocField {
42
+ interface ModelArrayField<ModelName extends string> extends DocField {
44
43
  readonly codecId: 'prisma/modelArray@1';
45
44
  readonly nullable: false;
46
- readonly model: ModelName$1;
45
+ readonly model: ModelName;
47
46
  }
48
47
  /**
49
48
  * Phantom-symbol brand placed on `ModelToDocShape`'s output (and inherited
@@ -74,8 +73,8 @@ type ModelOriginBrand = typeof ModelOriginBrand;
74
73
  * `InferModelRow<TContract, ModelName>` rather than the per-field codec
75
74
  * walk. Use as `ModelToDocShape<TC, ModelName> & ModelOriginBranded<ModelName>`.
76
75
  */
77
- type ModelOriginBranded<ModelName$1 extends string> = {
78
- readonly [ModelOriginBrand]?: ModelName$1;
76
+ type ModelOriginBranded<ModelName extends string> = {
77
+ readonly [ModelOriginBrand]?: ModelName;
79
78
  };
80
79
  /**
81
80
  * Document shape that carries nested value-object sub-shapes.
@@ -150,11 +149,11 @@ type TranslateField<TContract extends ContractHasValueObjects, F> = F extends {
150
149
  * `VOs[VOName]['fields']` is preserved and the hover / indexed-access
151
150
  * surface stays concrete at instantiation time.
152
151
  */
153
- type VONestedShape<TContract extends ContractHasValueObjects, VOName$1 extends string> = TContract extends {
152
+ type VONestedShape<TContract extends ContractHasValueObjects, VOName extends string> = TContract extends {
154
153
  readonly valueObjects: infer VOs extends Record<string, {
155
154
  readonly fields: Record<string, unknown>;
156
155
  }>;
157
- } ? VOName$1 extends keyof VOs ? { readonly [K in keyof VOs[VOName$1]['fields'] & string]: TranslateField<TContract, VOs[VOName$1]['fields'][K]> } : never : never;
156
+ } ? VOName extends keyof VOs ? { readonly [K in keyof VOs[VOName]['fields'] & string]: TranslateField<TContract, VOs[VOName]['fields'][K]> } : never : never;
158
157
  /**
159
158
  * Build the `NestedDocShape` for a model. Scalar leaves resolve to their
160
159
  * concrete codec id; value-object fields recurse into the referenced
@@ -169,7 +168,7 @@ type VONestedShape<TContract extends ContractHasValueObjects, VOName$1 extends s
169
168
  * literal field record collapses `keyof` to `string` and the result hover
170
169
  * degrades to `{ readonly [x: string]: any }`.
171
170
  */
172
- type ModelNestedShape<TContract extends MongoContract, ModelName$1 extends string & keyof TContract['models']> = { readonly [K in keyof TContract['models'][ModelName$1]['fields'] & string]: TranslateField<TContract & ContractHasValueObjects, TContract['models'][ModelName$1]['fields'][K]> };
171
+ type ModelNestedShape<TContract extends MongoContract, ModelName extends string & keyof TContract['models']> = { readonly [K in keyof TContract['models'][ModelName]['fields'] & string]: TranslateField<TContract & ContractHasValueObjects, TContract['models'][ModelName]['fields'][K]> };
173
172
  /**
174
173
  * Resolve a dot-path against a `NestedDocShape`. Returns:
175
174
  * - the leaf `DocField` when `Path` terminates on a scalar/array leaf,
@@ -183,7 +182,7 @@ type ModelNestedShape<TContract extends MongoContract, ModelName$1 extends strin
183
182
  * rejects bad paths with a clear error instead of silently resolving to
184
183
  * `never`.
185
184
  */
186
- type ResolvePath<N$1 extends NestedDocShape, Path extends string> = Path extends `${infer Head}.${infer Rest}` ? Head extends keyof N$1 & string ? N$1[Head] extends ObjectField<infer Sub> ? ResolvePath<Sub, Rest> : never : never : Path extends keyof N$1 & string ? N$1[Path] : never;
185
+ type ResolvePath<N extends NestedDocShape, Path extends string> = Path extends `${infer Head}.${infer Rest}` ? Head extends keyof N & string ? N[Head] extends ObjectField<infer Sub> ? ResolvePath<Sub, Rest> : never : never : Path extends keyof N & string ? N[Path] : never;
187
186
  /**
188
187
  * Union of every valid dot-path within a `NestedDocShape`. Includes
189
188
  * top-level keys (scalar leaves *and* value-object roots) and every
@@ -202,14 +201,14 @@ type ResolvePath<N$1 extends NestedDocShape, Path extends string> = Path extends
202
201
  * open-ended `keyof` cannot resolve a specific literal path, so the
203
202
  * callable form must be disabled at the type level.
204
203
  */
205
- type ValidPaths<N$1 extends NestedDocShape> = string extends keyof N$1 ? never : { [K in keyof N$1 & string]: N$1[K] extends ObjectField<infer Sub> ? K | `${K}.${ValidPaths<Sub>}` : K }[keyof N$1 & string];
204
+ type ValidPaths<N extends NestedDocShape> = string extends keyof N ? never : { [K in keyof N & string]: N[K] extends ObjectField<infer Sub> ? K | `${K}.${ValidPaths<Sub>}` : K }[keyof N & string];
206
205
  /**
207
206
  * IDE-oriented alias for `ValidPaths`. Kept as a separate export so future
208
207
  * refinements (e.g. ArkType-style lazy expansion for very deep shapes) can
209
208
  * diverge from the strict `ValidPaths` constraint without breaking
210
209
  * downstream consumers. For now the two are intentionally equivalent.
211
210
  */
212
- type PathCompletions<N$1 extends NestedDocShape> = ValidPaths<N$1>;
211
+ type PathCompletions<N extends NestedDocShape> = ValidPaths<N>;
213
212
  //#endregion
214
213
  //#region src/types.d.ts
215
214
  interface DocField {
@@ -254,10 +253,10 @@ type ExtractCodecId<F> = F extends {
254
253
  } ? C : F extends {
255
254
  codecId: infer C extends string;
256
255
  } ? C : string;
257
- type ModelToDocShape<TContract extends MongoContract, ModelName$1 extends string & keyof TContract['models']> = { [K in keyof TContract['models'][ModelName$1]['fields'] & string]: {
258
- readonly codecId: ExtractCodecId<TContract['models'][ModelName$1]['fields'][K]>;
259
- readonly nullable: TContract['models'][ModelName$1]['fields'][K]['nullable'];
260
- } } & ModelOriginBranded<ModelName$1>;
256
+ type ModelToDocShape<TContract extends MongoContract, ModelName extends string & keyof TContract['models']> = { [K in keyof TContract['models'][ModelName]['fields'] & string]: {
257
+ readonly codecId: ExtractCodecId<TContract['models'][ModelName]['fields'][K]>;
258
+ readonly nullable: TContract['models'][ModelName]['fields'][K]['nullable'];
259
+ } } & ModelOriginBranded<ModelName>;
261
260
  /**
262
261
  * Per-field resolver. Walks `Shape`'s string keys, routing
263
262
  * `ModelArrayField` (the lookup marker) through `InferModelRow` and
@@ -350,7 +349,7 @@ type UnwrapArrayDocField<F extends DocField> = F;
350
349
  * `ResolveRow` still routes through `InferModelRow` and value-object
351
350
  * fields keep their concrete nested types.
352
351
  */
353
- type UnwoundShape<S extends DocShape, K$1 extends keyof S & string> = { [P in keyof S & string]: P extends K$1 ? UnwrapArrayDocField<S[P]> : S[P] } & (S extends ModelOriginBranded<infer ModelName extends string> ? ModelOriginBranded<ModelName> : unknown);
352
+ type UnwoundShape<S extends DocShape, K extends keyof S & string> = { [P in keyof S & string]: P extends K ? UnwrapArrayDocField<S[P]> : S[P] } & (S extends ModelOriginBranded<infer ModelName extends string> ? ModelOriginBranded<ModelName> : unknown);
354
353
  //#endregion
355
354
  //#region src/accumulator-helpers.d.ts
356
355
  declare const acc: {
@@ -537,7 +536,7 @@ interface LeafExpression<F extends DocField> extends TypedAggExpr<F> {
537
536
  * so the value object can be piped through `$addFields` /
538
537
  * `$replaceRoot` / etc. as-is.
539
538
  */
540
- interface ObjectExpression<N$1 extends NestedDocShape> extends TypedAggExpr<ObjectField<N$1>> {
539
+ interface ObjectExpression<N extends NestedDocShape> extends TypedAggExpr<ObjectField<N>> {
541
540
  readonly _path: string;
542
541
  exists(flag?: boolean): MongoFilterExpr;
543
542
  eq(value: null): MongoFilterExpr;
@@ -606,7 +605,7 @@ interface StageEmitters {
606
605
  * `f.rawPath(...)` remains available in that state for callers that need
607
606
  * an explicit unvalidated path.
608
607
  */
609
- type FieldAccessor<S extends DocShape, N$1 extends NestedDocShape = Record<string, never>> = { readonly [K in keyof S & string]: Expression<S[K]> } & (<P$1 extends ValidPaths<N$1>>(path: P$1) => Expression<ResolvePath<N$1, P$1>>) & {
608
+ type FieldAccessor<S extends DocShape, N extends NestedDocShape = Record<string, never>> = { readonly [K in keyof S & string]: Expression<S[K]> } & (<P extends ValidPaths<N>>(path: P) => Expression<ResolvePath<N, P>>) & {
610
609
  readonly stage: StageEmitters;
611
610
  /**
612
611
  * Escape hatch: build a `LeafExpression<F>` for an unvalidated string
@@ -634,7 +633,7 @@ type FieldAccessor<S extends DocShape, N$1 extends NestedDocShape = Record<strin
634
633
  * `undefined` to keep accidental coercion behaviour unsurprising —
635
634
  * matching the previous `FieldProxy` / `FilterProxy` semantics.
636
635
  */
637
- declare function createFieldAccessor<S extends DocShape, N$1 extends NestedDocShape = Record<string, never>>(): FieldAccessor<S, N$1>;
636
+ declare function createFieldAccessor<S extends DocShape, N extends NestedDocShape = Record<string, never>>(): FieldAccessor<S, N>;
638
637
  //#endregion
639
638
  //#region src/lookup-builder.d.ts
640
639
  /**
@@ -679,10 +678,10 @@ type LookupResultBrand = 'mongo-query-builder/lookup-result@1';
679
678
  * `PipelineChain.lookup`'s return type can encode the result-row
680
679
  * promotion precisely.
681
680
  */
682
- interface LookupResult<RootName extends string, ModelName$1 extends string, As extends string> {
681
+ interface LookupResult<RootName extends string, ModelName extends string, As extends string> {
683
682
  readonly _brand: LookupResultBrand;
684
683
  readonly _root: RootName;
685
- readonly _model: ModelName$1;
684
+ readonly _model: ModelName;
686
685
  readonly _localField: string;
687
686
  readonly _foreignField: string;
688
687
  readonly _as: As;
@@ -692,8 +691,8 @@ interface LookupResult<RootName extends string, ModelName$1 extends string, As e
692
691
  * model literals plus the captured local / foreign paths, and exposes
693
692
  * `.as(name)` to finalise the spec with the user-chosen field name.
694
693
  */
695
- interface LookupBuilderWithKey<RootName extends string, ModelName$1 extends string> {
696
- as<As extends string>(name: As): LookupResult<RootName, ModelName$1, As>;
694
+ interface LookupBuilderWithKey<RootName extends string, ModelName extends string> {
695
+ as<As extends string>(name: As): LookupResult<RootName, ModelName, As>;
697
696
  }
698
697
  /**
699
698
  * Builder returned by `from(name)`. Carries the foreign root / model
@@ -704,8 +703,8 @@ interface LookupBuilderWithKey<RootName extends string, ModelName$1 extends stri
704
703
  * `on(cb)` runs the user's callback to capture the leaf paths and
705
704
  * returns a `LookupBuilderWithKey` that exposes `.as(name)`.
706
705
  */
707
- interface LookupBuilder<TContract extends MongoContract, Shape extends DocShape, Nested extends Record<string, DocField>, RootName extends string, ModelName$1 extends string> {
708
- on(cb: (local: FieldAccessor<Shape, Nested>, foreign: ModelName$1 extends keyof TContract['models'] & string ? FieldAccessor<ModelToDocShape<TContract, ModelName$1>, ModelNestedShape<TContract, ModelName$1>> : never) => LookupOnResult): LookupBuilderWithKey<RootName, ModelName$1>;
706
+ interface LookupBuilder<TContract extends MongoContract, Shape extends DocShape, Nested extends Record<string, DocField>, RootName extends string, ModelName extends string> {
707
+ on(cb: (local: FieldAccessor<Shape, Nested>, foreign: ModelName extends keyof TContract['models'] & string ? FieldAccessor<ModelToDocShape<TContract, ModelName>, ModelNestedShape<TContract, ModelName>> : never) => LookupOnResult): LookupBuilderWithKey<RootName, ModelName>;
709
708
  }
710
709
  /**
711
710
  * Type of the `from` callable passed to `PipelineChain.lookup`'s outer
@@ -777,9 +776,9 @@ interface PipelineChainState {
777
776
  * marker table (and rationale per row) in
778
777
  * `docs/architecture docs/adrs/ADR 201 - State-machine pattern for typed DSL builders.md`.
779
778
  */
780
- declare class PipelineChain<TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>, Shape extends DocShape, U$1 extends UpdateEnabled = 'update-ok', F extends FindAndModifyEnabled = 'fam-ok', L extends LeadingMatch = 'leading', N$1 extends NestedDocShape = Record<string, never>> {
779
+ declare class PipelineChain<TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>, Shape extends DocShape, U extends UpdateEnabled = 'update-ok', F extends FindAndModifyEnabled = 'fam-ok', L extends LeadingMatch = 'leading', N extends NestedDocShape = Record<string, never>> {
781
780
  #private;
782
- readonly __updateCompat: U$1;
781
+ readonly __updateCompat: U;
783
782
  readonly __findAndModifyCompat: F;
784
783
  readonly __leadingMatch: L;
785
784
  constructor(contract: TContract, state: PipelineChainState);
@@ -791,27 +790,27 @@ declare class PipelineChain<TContract extends MongoContractWithTypeMaps<MongoCon
791
790
  * `deconstructUpdateChain` can only peel leading `$match` stages into the
792
791
  * wire-command filter.
793
792
  */
794
- match(filter: MongoFilterExpr): PipelineChain<TContract, Shape, L extends 'leading' ? U$1 : 'update-cleared', F, L, N$1>;
795
- match(fn: (fields: FieldAccessor<Shape, N$1>) => MongoFilterExpr): PipelineChain<TContract, Shape, L extends 'leading' ? U$1 : 'update-cleared', F, L, N$1>;
793
+ match(filter: MongoFilterExpr): PipelineChain<TContract, Shape, L extends 'leading' ? U : 'update-cleared', F, L, N>;
794
+ match(fn: (fields: FieldAccessor<Shape, N>) => MongoFilterExpr): PipelineChain<TContract, Shape, L extends 'leading' ? U : 'update-cleared', F, L, N>;
796
795
  /**
797
796
  * `$sort`. Clears `UpdateEnabled` (`update` has no per-document sort) but
798
797
  * preserves `FindAndModifyEnabled` (`findAndModify` has a `sort` slot).
799
798
  */
800
- sort(spec: SortSpec<Shape>): PipelineChain<TContract, Shape, 'update-cleared', F, 'past-leading', N$1>;
799
+ sort(spec: SortSpec<Shape>): PipelineChain<TContract, Shape, 'update-cleared', F, 'past-leading', N>;
801
800
  /**
802
801
  * `$limit`. Clears both markers — `limit` is incompatible with the `update`
803
802
  * wire command, and `findAndModify` already implies single-document
804
803
  * semantics (so `.limit(...)` adds no meaning, only ambiguity).
805
804
  */
806
- limit(n: number): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading', N$1>;
805
+ limit(n: number): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading', N>;
807
806
  /**
808
807
  * `$skip`. Clears both markers — MongoDB's `findAndModify` wire command
809
808
  * has no `skip` slot, so `deconstructFindAndModifyChain` rejects any
810
809
  * `$skip` at runtime; keeping the marker `fam-cleared` makes the type
811
810
  * system reflect the same constraint (see ADR 201 marker table).
812
811
  */
813
- skip(n: number): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading', N$1>;
814
- sample(n: number): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading', N$1>;
812
+ skip(n: number): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading', N>;
813
+ sample(n: number): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading', N>;
815
814
  /**
816
815
  * `$addFields`. Preserves `UpdateEnabled` (representable as
817
816
  * update-with-pipeline `$set`); clears `FindAndModifyEnabled` (no analogue
@@ -819,7 +818,7 @@ declare class PipelineChain<TContract extends MongoContractWithTypeMaps<MongoCon
819
818
  * preserved — newly added flat fields are reachable via property access
820
819
  * (`f.newField`) but do not themselves carry nested structure.
821
820
  */
822
- addFields<NewFields extends Record<string, TypedAggExpr<DocField>>>(fn: (fields: FieldAccessor<Shape, N$1>) => NewFields): PipelineChain<TContract, Shape & ExtractDocShape<NewFields>, U$1, 'fam-cleared', 'past-leading', N$1>;
821
+ addFields<NewFields extends Record<string, TypedAggExpr<DocField>>>(fn: (fields: FieldAccessor<Shape, N>) => NewFields): PipelineChain<TContract, Shape & ExtractDocShape<NewFields>, U, 'fam-cleared', 'past-leading', N>;
823
822
  /**
824
823
  * `$lookup`. Clears both markers — joins are not representable in either
825
824
  * the `update` or `findAndModify` wire commands. The original document's
@@ -833,7 +832,7 @@ declare class PipelineChain<TContract extends MongoContractWithTypeMaps<MongoCon
833
832
  * `ResolveRow` produces `Array<ForeignRow>` (with concrete leaf
834
833
  * types) instead of the legacy `unknown[]`.
835
834
  */
836
- lookup<RootName extends string, ModelName$1 extends string, As extends string>(fn: (from: LookupFrom<TContract, Shape, N$1>) => LookupResult<RootName, ModelName$1, As>): PipelineChain<TContract, Shape & Record<As, ModelArrayField<ModelName$1>>, 'update-cleared', 'fam-cleared', 'past-leading', N$1>;
835
+ lookup<RootName extends string, ModelName extends string, As extends string>(fn: (from: LookupFrom<TContract, Shape, N>) => LookupResult<RootName, ModelName, As>): PipelineChain<TContract, Shape & Record<As, ModelArrayField<ModelName>>, 'update-cleared', 'fam-cleared', 'past-leading', N>;
837
836
  /**
838
837
  * `$project`. Preserves `UpdateEnabled` (representable as update-with-pipeline
839
838
  * `$project` / `$unset`); clears `FindAndModifyEnabled` (use `.project()` on
@@ -844,8 +843,8 @@ declare class PipelineChain<TContract extends MongoContractWithTypeMaps<MongoCon
844
843
  * fundamentally rewrites the document, so dot-paths into the *source*
845
844
  * document are no longer meaningful downstream.
846
845
  */
847
- project<K$1 extends keyof Shape & string>(...keys: K$1[]): PipelineChain<TContract, Pick<Shape, K$1 | ('_id' extends keyof Shape ? '_id' : never)>, U$1, 'fam-cleared', 'past-leading'>;
848
- project<Spec extends Record<string, 1 | TypedAggExpr<DocField>>>(fn: (fields: FieldAccessor<Shape, N$1>) => Spec): PipelineChain<TContract, ProjectedShape<Shape, Spec>, U$1, 'fam-cleared', 'past-leading'>;
846
+ project<K extends keyof Shape & string>(...keys: K[]): PipelineChain<TContract, Pick<Shape, K | ('_id' extends keyof Shape ? '_id' : never)>, U, 'fam-cleared', 'past-leading'>;
847
+ project<Spec extends Record<string, 1 | TypedAggExpr<DocField>>>(fn: (fields: FieldAccessor<Shape, N>) => Spec): PipelineChain<TContract, ProjectedShape<Shape, Spec>, U, 'fam-cleared', 'past-leading'>;
849
848
  /**
850
849
  * `$unwind`. Clears both markers — array unrolling produces multiple output
851
850
  * documents per input, incompatible with both single-document update and
@@ -853,27 +852,27 @@ declare class PipelineChain<TContract extends MongoContractWithTypeMaps<MongoCon
853
852
  * replaces the unwound array slot with its element but leaves the rest
854
853
  * of the document structurally intact.
855
854
  */
856
- unwind<K$1 extends keyof Shape & string>(field: K$1, options?: {
855
+ unwind<K extends keyof Shape & string>(field: K, options?: {
857
856
  preserveNullAndEmptyArrays?: boolean;
858
- }): PipelineChain<TContract, UnwoundShape<Shape, K$1>, 'update-cleared', 'fam-cleared', 'past-leading', N$1>;
857
+ }): PipelineChain<TContract, UnwoundShape<Shape, K>, 'update-cleared', 'fam-cleared', 'past-leading', N>;
859
858
  /**
860
859
  * `$group`. Clears both markers — group output bears no relation to source
861
860
  * documents; neither `update` nor `findAndModify` can consume it. Nested
862
861
  * path shape is reset (the source document's path tree is gone).
863
862
  */
864
- group<Spec extends GroupSpec>(fn: (fields: FieldAccessor<Shape, N$1>) => Spec): PipelineChain<TContract, GroupedDocShape<Spec>, 'update-cleared', 'fam-cleared', 'past-leading'>;
863
+ group<Spec extends GroupSpec>(fn: (fields: FieldAccessor<Shape, N>) => Spec): PipelineChain<TContract, GroupedDocShape<Spec>, 'update-cleared', 'fam-cleared', 'past-leading'>;
865
864
  /**
866
865
  * `$replaceRoot`. Preserves `UpdateEnabled` (representable as
867
866
  * update-with-pipeline `$replaceRoot`); clears `FindAndModifyEnabled`.
868
867
  * Nested path shape is reset — the replaced root has no relation to
869
868
  * the original document structure.
870
869
  */
871
- replaceRoot<NewShape extends DocShape>(fn: (fields: FieldAccessor<Shape, N$1>) => Expression<DocField> | TypedAggExpr<DocField>): PipelineChain<TContract, NewShape, U$1, 'fam-cleared', 'past-leading'>;
870
+ replaceRoot<NewShape extends DocShape>(fn: (fields: FieldAccessor<Shape, N>) => Expression<DocField> | TypedAggExpr<DocField>): PipelineChain<TContract, NewShape, U, 'fam-cleared', 'past-leading'>;
872
871
  count<Field extends string>(field: Field): PipelineChain<TContract, Record<Field, {
873
872
  readonly codecId: 'mongo/double@1';
874
873
  readonly nullable: false;
875
874
  }>, 'update-cleared', 'fam-cleared', 'past-leading'>;
876
- sortByCount<F2 extends DocField>(fn: (fields: FieldAccessor<Shape, N$1>) => Expression<F2> | TypedAggExpr<F2>): PipelineChain<TContract, {
875
+ sortByCount<F2 extends DocField>(fn: (fields: FieldAccessor<Shape, N>) => Expression<F2> | TypedAggExpr<F2>): PipelineChain<TContract, {
877
876
  _id: F2;
878
877
  count: {
879
878
  readonly codecId: 'mongo/double@1';
@@ -884,7 +883,7 @@ declare class PipelineChain<TContract extends MongoContractWithTypeMaps<MongoCon
884
883
  * `$redact`. Preserves `UpdateEnabled`; clears `FindAndModifyEnabled`.
885
884
  * Shape- and nested-path-preserving (the document tree is unchanged).
886
885
  */
887
- redact(fn: (fields: FieldAccessor<Shape, N$1>) => Expression<DocField> | TypedAggExpr<DocField>): PipelineChain<TContract, Shape, U$1, 'fam-cleared', 'past-leading', N$1>;
886
+ redact(fn: (fields: FieldAccessor<Shape, N>) => Expression<DocField> | TypedAggExpr<DocField>): PipelineChain<TContract, Shape, U, 'fam-cleared', 'past-leading', N>;
888
887
  /**
889
888
  * `$out` write terminal. Materialises the pipeline output into
890
889
  * `collection` (optionally in `db`), replacing any prior contents. Unlike
@@ -914,7 +913,7 @@ declare class PipelineChain<TContract extends MongoContractWithTypeMaps<MongoCon
914
913
  whenMatched?: string | ReadonlyArray<MongoUpdatePipelineStage>;
915
914
  whenNotMatched?: string;
916
915
  }): MongoQueryPlan<unknown, AggregateCommand>;
917
- unionWith(collection: string, pipeline?: ReadonlyArray<MongoPipelineStage>): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading', N$1>;
916
+ unionWith(collection: string, pipeline?: ReadonlyArray<MongoPipelineStage>): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading', N>;
918
917
  bucket(options: {
919
918
  groupBy: MongoAggExpr;
920
919
  boundaries: ReadonlyArray<unknown>;
@@ -958,14 +957,14 @@ declare class PipelineChain<TContract extends MongoContractWithTypeMaps<MongoCon
958
957
  field: string;
959
958
  partitionByFields?: ReadonlyArray<string>;
960
959
  range: MongoDensifyRange;
961
- }): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading', N$1>;
960
+ }): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading', N>;
962
961
  fill(options: {
963
962
  partitionBy?: MongoAggExpr;
964
963
  partitionByFields?: ReadonlyArray<string>;
965
964
  sortBy?: Record<string, 1 | -1>;
966
965
  output: Record<string, MongoFillOutput>;
967
- }): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading', N$1>;
968
- search(config: Record<string, unknown>, index?: string): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading', N$1>;
966
+ }): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading', N>;
967
+ search(config: Record<string, unknown>, index?: string): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading', N>;
969
968
  searchMeta(config: Record<string, unknown>, index?: string): PipelineChain<TContract, DocShape, 'update-cleared', 'fam-cleared', 'past-leading'>;
970
969
  vectorSearch(options: {
971
970
  index: string;
@@ -974,7 +973,7 @@ declare class PipelineChain<TContract extends MongoContractWithTypeMaps<MongoCon
974
973
  numCandidates: number;
975
974
  limit: number;
976
975
  filter?: Record<string, unknown>;
977
- }): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading', N$1>;
976
+ }): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading', N>;
978
977
  pipe(stage: MongoPipelineStage): PipelineChain<TContract, Shape, 'update-cleared', 'fam-cleared', 'past-leading'>;
979
978
  pipe<NewShape extends DocShape>(stage: MongoPipelineStage): PipelineChain<TContract, NewShape, 'update-cleared', 'fam-cleared', 'past-leading'>;
980
979
  /**
@@ -995,14 +994,14 @@ declare class PipelineChain<TContract extends MongoContractWithTypeMaps<MongoCon
995
994
  * code. See `docs/architecture docs/adrs/ADR 201 - State-machine
996
995
  * pattern for typed DSL builders.md` for the marker-transition table.
997
996
  */
998
- updateMany(this: PipelineChain<TContract, Shape, 'update-ok', F, L, N$1>, updaterFn?: (fields: FieldAccessor<Shape, N$1>) => UpdaterResult): MongoQueryPlan<UpdateResult$1, UpdateManyCommand>;
997
+ updateMany(this: PipelineChain<TContract, Shape, 'update-ok', F, L, N>, updaterFn?: (fields: FieldAccessor<Shape, N>) => UpdaterResult): MongoQueryPlan<UpdateResult$1, UpdateManyCommand>;
999
998
  /**
1000
999
  * No-arg `updateOne()`: same as `updateMany()` but maps to a single-doc
1001
1000
  * update. Carries the same optional-callback/subclass-compat caveat
1002
1001
  * documented above — the callback form is reachable only via forced
1003
1002
  * casts in internal tests.
1004
1003
  */
1005
- updateOne(this: PipelineChain<TContract, Shape, 'update-ok', F, L, N$1>, updaterFn?: (fields: FieldAccessor<Shape, N$1>) => UpdaterResult): MongoQueryPlan<UpdateResult$1, UpdateOneCommand>;
1004
+ updateOne(this: PipelineChain<TContract, Shape, 'update-ok', F, L, N>, updaterFn?: (fields: FieldAccessor<Shape, N>) => UpdaterResult): MongoQueryPlan<UpdateResult$1, UpdateOneCommand>;
1006
1005
  /**
1007
1006
  * Find a single document matching the accumulated pipeline (which must
1008
1007
  * consist solely of leading `$match` stages followed by at most one
@@ -1016,7 +1015,7 @@ declare class PipelineChain<TContract extends MongoContractWithTypeMaps<MongoCon
1016
1015
  * runtime error is thrown as a defensive check (the type system should
1017
1016
  * prevent this).
1018
1017
  */
1019
- findOneAndUpdate(this: PipelineChain<TContract, Shape, U$1, 'fam-ok', L, N$1>, updaterFn: (fields: FieldAccessor<Shape, N$1>) => UpdaterResult, opts?: {
1018
+ findOneAndUpdate(this: PipelineChain<TContract, Shape, U, 'fam-ok', L, N>, updaterFn: (fields: FieldAccessor<Shape, N>) => UpdaterResult, opts?: {
1020
1019
  readonly upsert?: boolean;
1021
1020
  readonly returnDocument?: 'before' | 'after';
1022
1021
  }): MongoQueryPlan<ResolveRow<Shape, ExtractMongoCodecTypes<TContract>, TContract> | null, FindOneAndUpdateCommand>;
@@ -1024,7 +1023,7 @@ declare class PipelineChain<TContract extends MongoContractWithTypeMaps<MongoCon
1024
1023
  * Find a single document matching the accumulated pipeline and delete it.
1025
1024
  * Same marker gating and deconstruction as `findOneAndUpdate`.
1026
1025
  */
1027
- findOneAndDelete(this: PipelineChain<TContract, Shape, U$1, 'fam-ok', L, N$1>): MongoQueryPlan<ResolveRow<Shape, ExtractMongoCodecTypes<TContract>, TContract> | null, FindOneAndDeleteCommand>;
1026
+ findOneAndDelete(this: PipelineChain<TContract, Shape, U, 'fam-ok', L, N>): MongoQueryPlan<ResolveRow<Shape, ExtractMongoCodecTypes<TContract>, TContract> | null, FindOneAndDeleteCommand>;
1028
1027
  /**
1029
1028
  * Materialise the chain as a `MongoQueryPlan` wrapping an `AggregateCommand`.
1030
1029
  */
@@ -1214,14 +1213,14 @@ declare const fn: {
1214
1213
  * accidentally produce an unqualified write by forgetting to `.match(...)`
1215
1214
  * later in the chain. Bodies land in M2.
1216
1215
  */
1217
- declare class CollectionHandle<TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>, ModelName$1 extends keyof TContract['models'] & string> extends PipelineChain<TContract, ModelToDocShape<TContract, ModelName$1>, 'update-cleared', 'fam-cleared', 'leading', ModelNestedShape<TContract, ModelName$1>> {
1216
+ declare class CollectionHandle<TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>, ModelName extends keyof TContract['models'] & string> extends PipelineChain<TContract, ModelToDocShape<TContract, ModelName>, 'update-cleared', 'fam-cleared', 'leading', ModelNestedShape<TContract, ModelName>> {
1218
1217
  #private;
1219
- constructor(ctx: BindingContext<TContract>, modelName: ModelName$1);
1218
+ constructor(ctx: BindingContext<TContract>, modelName: ModelName);
1220
1219
  /**
1221
1220
  * Bound model name. Exposed so type tests can assert the binding without
1222
1221
  * flipping into a pipeline. Not part of the public-API contract.
1223
1222
  */
1224
- get _modelName(): ModelName$1;
1223
+ get _modelName(): ModelName;
1225
1224
  /**
1226
1225
  * Begin accumulating a filter. Transitions to `FilteredCollection`.
1227
1226
  *
@@ -1231,8 +1230,8 @@ declare class CollectionHandle<TContract extends MongoContractWithTypeMaps<Mongo
1231
1230
  * Mongo — but `FilteredCollection` makes the accumulated filter
1232
1231
  * addressable for the write/find-and-modify terminals landing in M2/M3.
1233
1232
  */
1234
- match(filter: MongoFilterExpr): FilteredCollection<TContract, ModelName$1>;
1235
- match(fn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName$1>, ModelNestedShape<TContract, ModelName$1>>) => MongoFilterExpr): FilteredCollection<TContract, ModelName$1>;
1233
+ match(filter: MongoFilterExpr): FilteredCollection<TContract, ModelName>;
1234
+ match(fn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName>, ModelNestedShape<TContract, ModelName>>) => MongoFilterExpr): FilteredCollection<TContract, ModelName>;
1236
1235
  /**
1237
1236
  * Insert a single document. Document fields are passed straight through to
1238
1237
  * the wire `InsertOneCommand` — codec normalisation happens at the
@@ -1255,7 +1254,7 @@ declare class CollectionHandle<TContract extends MongoContractWithTypeMaps<Mongo
1255
1254
  * unqualified write by forgetting to `.match(...)` first. Pair with
1256
1255
  * `.match(...).updateMany(...)` for the filtered case.
1257
1256
  */
1258
- updateAll(updaterFn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName$1>, ModelNestedShape<TContract, ModelName$1>>) => UpdaterResult): MongoQueryPlan<UpdateResult$1, UpdateManyCommand>;
1257
+ updateAll(updaterFn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName>, ModelNestedShape<TContract, ModelName>>) => UpdaterResult): MongoQueryPlan<UpdateResult$1, UpdateManyCommand>;
1259
1258
  /**
1260
1259
  * Delete *every* document in the collection. See `updateAll` for the
1261
1260
  * rationale around the unqualified-write surface being limited to this
@@ -1272,7 +1271,7 @@ declare class CollectionHandle<TContract extends MongoContractWithTypeMaps<Mongo
1272
1271
  * new document derived from the filter equality fields plus the update
1273
1272
  * spec when no match is found; otherwise updates the matched document.
1274
1273
  */
1275
- upsertOne(filterFn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName$1>, ModelNestedShape<TContract, ModelName$1>>) => MongoFilterExpr, updaterFn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName$1>, ModelNestedShape<TContract, ModelName$1>>) => UpdaterResult): MongoQueryPlan<UpdateResult$1, UpdateOneCommand>;
1274
+ upsertOne(filterFn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName>, ModelNestedShape<TContract, ModelName>>) => MongoFilterExpr, updaterFn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName>, ModelNestedShape<TContract, ModelName>>) => UpdaterResult): MongoQueryPlan<UpdateResult$1, UpdateOneCommand>;
1276
1275
  }
1277
1276
  /**
1278
1277
  * State reached after one or more `.match(...)` calls on `CollectionHandle`.
@@ -1298,10 +1297,10 @@ declare class CollectionHandle<TContract extends MongoContractWithTypeMaps<Mongo
1298
1297
  * — those are insert or unqualified-write operations that are nonsense
1299
1298
  * after a filter has been applied.
1300
1299
  */
1301
- declare class FilteredCollection<TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>, ModelName$1 extends keyof TContract['models'] & string> extends PipelineChain<TContract, ModelToDocShape<TContract, ModelName$1>, 'update-cleared', 'fam-cleared', 'leading', ModelNestedShape<TContract, ModelName$1>> {
1300
+ declare class FilteredCollection<TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>, ModelName extends keyof TContract['models'] & string> extends PipelineChain<TContract, ModelToDocShape<TContract, ModelName>, 'update-cleared', 'fam-cleared', 'leading', ModelNestedShape<TContract, ModelName>> {
1302
1301
  #private;
1303
- constructor(ctx: BindingContext<TContract>, modelName: ModelName$1, filters: ReadonlyArray<MongoFilterExpr>);
1304
- get _modelName(): ModelName$1;
1302
+ constructor(ctx: BindingContext<TContract>, modelName: ModelName, filters: ReadonlyArray<MongoFilterExpr>);
1303
+ get _modelName(): ModelName;
1305
1304
  /**
1306
1305
  * Accumulated filter list. Exposed for the M2/M3 write/find-and-modify
1307
1306
  * terminals to splat into wire-command `filter` slots; not part of the
@@ -1315,8 +1314,8 @@ declare class FilteredCollection<TContract extends MongoContractWithTypeMaps<Mon
1315
1314
  * second `$match` stage), so the write/find-and-modify terminals see a
1316
1315
  * single authoritative filter expression.
1317
1316
  */
1318
- match(filter: MongoFilterExpr): FilteredCollection<TContract, ModelName$1>;
1319
- match(fn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName$1>, ModelNestedShape<TContract, ModelName$1>>) => MongoFilterExpr): FilteredCollection<TContract, ModelName$1>;
1317
+ match(filter: MongoFilterExpr): FilteredCollection<TContract, ModelName>;
1318
+ match(fn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName>, ModelNestedShape<TContract, ModelName>>) => MongoFilterExpr): FilteredCollection<TContract, ModelName>;
1320
1319
  /**
1321
1320
  * Update every matching document. `updaterFn` receives a `FieldAccessor`
1322
1321
  * and returns an array of `TypedUpdateOp` (e.g. `[f.amount.inc(1),
@@ -1324,14 +1323,14 @@ declare class FilteredCollection<TContract extends MongoContractWithTypeMaps<Mon
1324
1323
  * update spec by `foldUpdateOps`, which throws on operator+path
1325
1324
  * collisions.
1326
1325
  */
1327
- updateMany(updaterFn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName$1>, ModelNestedShape<TContract, ModelName$1>>) => UpdaterResult): MongoQueryPlan<UpdateResult$1, UpdateManyCommand>;
1326
+ updateMany(updaterFn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName>, ModelNestedShape<TContract, ModelName>>) => UpdaterResult): MongoQueryPlan<UpdateResult$1, UpdateManyCommand>;
1328
1327
  /**
1329
1328
  * Update at most one matching document. The driver picks the document
1330
1329
  * (typically the first one matched by the underlying scan); no ordering
1331
1330
  * guarantee is implied — chain `.sort(...)` and use the M3
1332
1331
  * `.findOneAndUpdate(...)` terminal when ordering matters.
1333
1332
  */
1334
- updateOne(updaterFn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName$1>, ModelNestedShape<TContract, ModelName$1>>) => UpdaterResult): MongoQueryPlan<UpdateResult$1, UpdateOneCommand>;
1333
+ updateOne(updaterFn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName>, ModelNestedShape<TContract, ModelName>>) => UpdaterResult): MongoQueryPlan<UpdateResult$1, UpdateOneCommand>;
1335
1334
  /**
1336
1335
  * Delete every matching document.
1337
1336
  */
@@ -1347,7 +1346,7 @@ declare class FilteredCollection<TContract extends MongoContractWithTypeMaps<Mon
1347
1346
  * `CollectionHandle.upsertOne(f => filter, updaterFn)` but reuses the
1348
1347
  * already-accumulated `.match(...)` filter chain.
1349
1348
  */
1350
- upsertOne(updaterFn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName$1>, ModelNestedShape<TContract, ModelName$1>>) => UpdaterResult): MongoQueryPlan<UpdateResult$1, UpdateOneCommand>;
1349
+ upsertOne(updaterFn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName>, ModelNestedShape<TContract, ModelName>>) => UpdaterResult): MongoQueryPlan<UpdateResult$1, UpdateOneCommand>;
1351
1350
  /**
1352
1351
  * Find a single matching document and apply `updaterFn` to it.
1353
1352
  *
@@ -1355,15 +1354,15 @@ declare class FilteredCollection<TContract extends MongoContractWithTypeMaps<Mon
1355
1354
  * `opts.returnDocument` (default `'after'`) controls whether the row
1356
1355
  * stream yields the document as it was before or after the update.
1357
1356
  */
1358
- findOneAndUpdate(updaterFn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName$1>, ModelNestedShape<TContract, ModelName$1>>) => UpdaterResult, opts?: {
1357
+ findOneAndUpdate(updaterFn: (fields: FieldAccessor<ModelToDocShape<TContract, ModelName>, ModelNestedShape<TContract, ModelName>>) => UpdaterResult, opts?: {
1359
1358
  readonly upsert?: boolean;
1360
1359
  readonly returnDocument?: 'before' | 'after';
1361
- }): MongoQueryPlan<ResolveRow<ModelToDocShape<TContract, ModelName$1>, ExtractMongoCodecTypes<TContract>, TContract> | null, FindOneAndUpdateCommand>;
1360
+ }): MongoQueryPlan<ResolveRow<ModelToDocShape<TContract, ModelName>, ExtractMongoCodecTypes<TContract>, TContract> | null, FindOneAndUpdateCommand>;
1362
1361
  /**
1363
1362
  * Find a single matching document and delete it. Returns the deleted
1364
1363
  * document via the row stream.
1365
1364
  */
1366
- findOneAndDelete(): MongoQueryPlan<ResolveRow<ModelToDocShape<TContract, ModelName$1>, ExtractMongoCodecTypes<TContract>, TContract> | null, FindOneAndDeleteCommand>;
1365
+ findOneAndDelete(): MongoQueryPlan<ResolveRow<ModelToDocShape<TContract, ModelName>, ExtractMongoCodecTypes<TContract>, TContract> | null, FindOneAndDeleteCommand>;
1367
1366
  }
1368
1367
  /**
1369
1368
  * Bound execution context shared across the three state classes.
@@ -1387,8 +1386,8 @@ interface BindingContext<TContract extends MongoContractWithTypeMaps<MongoContra
1387
1386
  * cannot know what the caller's command yields.
1388
1387
  */
1389
1388
  interface QueryRoot<TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>> {
1390
- from<K$1 extends keyof TContract['roots'] & string>(rootName: K$1): CollectionHandle<TContract, TContract['roots'][K$1] & string & keyof TContract['models']>;
1391
- rawCommand<C$1 extends AnyMongoCommand>(command: C$1): MongoQueryPlan<unknown, C$1>;
1389
+ from<K extends keyof TContract['roots'] & string>(rootName: K): CollectionHandle<TContract, TContract['roots'][K] & string & keyof TContract['models']>;
1390
+ rawCommand<C extends AnyMongoCommand>(command: C): MongoQueryPlan<unknown, C>;
1392
1391
  }
1393
1392
  declare function mongoQuery<TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>>(options: {
1394
1393
  contractJson: unknown;