@@ -3,12 +3,19 @@ import { ProtectedString } from './protectedString.js'
33import * as objectPath from 'object-path'
44import type {
55 Condition ,
6+ DeleteManyModel ,
7+ DeleteOneModel ,
8+ Document ,
69 Filter ,
10+ InsertOneModel ,
711 MatchKeysAndValues ,
812 OnlyFieldsOfType ,
913 PullOperator ,
1014 PushOperator ,
15+ ReplaceOneModel ,
1116 SetFields ,
17+ UpdateManyModel ,
18+ UpdateOneModel ,
1219} from 'mongodb'
1320import { clone } from './lib.js'
1421
@@ -90,6 +97,24 @@ export type MongoModifier<TDoc> = {
9097 $rename ?: Record < string , string >
9198}
9299
100+ /**
101+ * A bulkWrite operation, hand-rolled to match exactly the arms our in-memory mocks implement (see the
102+ * `bulkWrite` handlers in the meteor and job-worker collection mocks). Like {@link MongoModifier}, this is
103+ * intentionally NOT mongodb's `AnyBulkWriteOperation`:
104+ * - the `update` of the `updateOne`/`updateMany` arms is constrained to {@link MongoModifier}, so a whole
105+ * plain document cannot sneak in as a "modifier" via the bulkWrite path (the heaviest write path). Use
106+ * the `replaceOne` arm for a genuine full-document replacement.
107+ * - aggregation-pipeline updates (the `Document[]` form) are deliberately omitted, as `mongoModify` does
108+ * not implement them.
109+ */
110+ export type MongoBulkWriteOperation < TDoc extends Document > =
111+ | { insertOne : InsertOneModel < TDoc > }
112+ | { replaceOne : ReplaceOneModel < TDoc > }
113+ | { updateOne : Omit < UpdateOneModel < TDoc > , 'update' > & { update : MongoModifier < TDoc > } }
114+ | { updateMany : Omit < UpdateManyModel < TDoc > , 'update' > & { update : MongoModifier < TDoc > } }
115+ | { deleteOne : DeleteOneModel < TDoc > }
116+ | { deleteMany : DeleteManyModel < TDoc > }
117+
93118/** End of hacks */
94119
95120export function mongoWhereFilter < T , R extends Record < string , any > > ( items : R [ ] , selector : MongoQuery < T > ) : R [ ] {
0 commit comments