Skip to content

Commit

Permalink
Collection: fix insertMany success return type InsertManyResult<I> to…
Browse files Browse the repository at this point in the history
… allow custom defined _id types
  • Loading branch information
devmatteini committed Jan 10, 2025
1 parent 3f9d487 commit bd026cf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-hairs-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect-mongodb": patch
---

Fix `Collection.insertMany` success return type `InsertManyResult<I>` to allow custom defined `_id` types
4 changes: 2 additions & 2 deletions packages/effect-mongodb/dtslint/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ F.pipe(collection, Collection.insertOne(myType))
// insertMany
// -------------------------------------------------------------------------------------

// $ExpectType Effect<InsertManyResult<Document>, MongoError | ParseError, never>
// $ExpectType Effect<InsertManyResult<{ readonly birthday: string; }>, MongoError | ParseError, never>
Collection.insertMany(collection, [myType])

// $ExpectType Effect<InsertManyResult<Document>, MongoError | ParseError, never>
// $ExpectType Effect<InsertManyResult<{ readonly birthday: string; }>, MongoError | ParseError, never>
F.pipe(collection, Collection.insertMany([myType]))

// -------------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions packages/effect-mongodb/src/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ export const insertOne: {
export const insertMany: {
<A extends Document>(docs: ReadonlyArray<A>, options?: BulkWriteOptions): <I extends Document, R>(
collection: Collection<A, I, R>
) => Effect.Effect<InsertManyResult, MongoError.MongoError | ParseResult.ParseError, R>
) => Effect.Effect<InsertManyResult<I>, MongoError.MongoError | ParseResult.ParseError, R>
<A extends Document, I extends Document, R>(
collection: Collection<A, I, R>,
docs: ReadonlyArray<A>,
options?: BulkWriteOptions
): Effect.Effect<InsertManyResult, MongoError.MongoError | ParseResult.ParseError, R>
): Effect.Effect<InsertManyResult<I>, MongoError.MongoError | ParseResult.ParseError, R>
} = F.dual((args) => isCollection(args[0]), <A extends Document, I extends Document, R>(
collection: Collection<A, I, R>,
docs: ReadonlyArray<A>,
options?: BulkWriteOptions
): Effect.Effect<InsertManyResult, MongoError.MongoError | ParseResult.ParseError, R> => {
): Effect.Effect<InsertManyResult<I>, MongoError.MongoError | ParseResult.ParseError, R> => {
return F.pipe(
docs,
Effect.forEach((doc) => collection.encode(doc)),
Expand Down

0 comments on commit bd026cf

Please sign in to comment.