Skip to content

Commit 891b6bf

Browse files
committed
Collection: swap Collection.aggregate pipeline and schema parameter positions
1 parent 60419b4 commit 891b6bf

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

.changeset/six-carrots-suffer.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"effect-mongodb": patch
3+
---
4+
5+
Swap `Collection.aggregate` pipeline and schema parameter positions
6+
7+
```typescript
8+
// Before
9+
Collection.aggregate(pipeline, schema)
10+
11+
// After
12+
Collection.aggregate(schema, pipeline)
13+
```

packages/effect-mongodb/dtslint/Collection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ const MyAggregatedType = Schema.Struct({
186186
const groupByBirthday = [{ $group: { _id: "$birthday", birthdays: { $sum: 1 } } }]
187187

188188
// $ExpectType AggregationCursor<{ readonly _id: Date; readonly birthdays: number; }, { readonly _id: string; readonly birthdays: number; }, never>
189-
Collection.aggregate(collection, groupByBirthday, MyAggregatedType)
189+
Collection.aggregate(collection, MyAggregatedType, groupByBirthday)
190190

191191
// $ExpectType AggregationCursor<{ readonly _id: Date; readonly birthdays: number; }, { readonly _id: string; readonly birthdays: number; }, never>
192-
F.pipe(collection, Collection.aggregate(groupByBirthday, MyAggregatedType))
192+
F.pipe(collection, Collection.aggregate(MyAggregatedType, groupByBirthday))
193193

194194
// -------------------------------------------------------------------------------------
195195
// estimatedDocumentCount

packages/effect-mongodb/examples/aggregate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const program = Effect.gen(function*(_) {
3333
]))
3434

3535
const items = yield* _(
36-
Collection.aggregate(sourceCollection, [
36+
Collection.aggregate(sourceCollection, MyTypeAggregation, [
3737
{
3838
$group: {
3939
_id: "$source",
@@ -43,7 +43,7 @@ const program = Effect.gen(function*(_) {
4343
{
4444
$sort: { _id: 1 }
4545
}
46-
], MyTypeAggregation),
46+
]),
4747
AggregationCursor.toArray
4848
)
4949

packages/effect-mongodb/src/Collection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,24 +438,24 @@ export const dropIndex: {
438438

439439
export const aggregate: {
440440
<B extends Document, BI extends Document, BR>(
441-
pipeline: ReadonlyArray<Document>,
442441
schema: Schema.Schema<B, BI, BR>,
442+
pipeline: ReadonlyArray<Document>,
443443
options?: AggregateOptions
444444
): <A extends Document, I extends Document, R>(
445445
collection: Collection<A, I, R>
446446
) => AggregationCursor.AggregationCursor<B, BI, BR>
447447
<A extends Document, I extends Document, R, B extends Document, BI extends Document, BR>(
448448
collection: Collection<A, I, R>,
449-
pipeline: ReadonlyArray<Document>,
450449
schema: Schema.Schema<B, BI, BR>,
450+
pipeline: ReadonlyArray<Document>,
451451
options?: AggregateOptions
452452
): AggregationCursor.AggregationCursor<B, BI, BR>
453453
} = F.dual(
454454
(args) => isCollection(args[0]),
455455
<A extends Document, I extends Document, R, B extends Document, BI extends Document, BR>(
456456
collection: Collection<A, I, R>,
457-
pipeline: ReadonlyArray<Document>,
458457
schema: Schema.Schema<B, BI, BR>,
458+
pipeline: ReadonlyArray<Document>,
459459
options?: AggregateOptions
460460
): AggregationCursor.AggregationCursor<B, BI, BR> =>
461461
new AggregationCursor.AggregationCursor<B, BI, BR>({

packages/effect-mongodb/test/Collection.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describeMongo("Collection", (ctx) => {
4545

4646
const _1990 = "1990-01-01T00:00:00.000Z"
4747
return yield* _(
48-
Collection.aggregate(collection, [
48+
Collection.aggregate(collection, UserAggregation, [
4949
{
5050
$match: {
5151
birthday: { $lt: _1990 }
@@ -60,7 +60,7 @@ describeMongo("Collection", (ctx) => {
6060
{
6161
$sort: { _id: 1 }
6262
}
63-
], UserAggregation),
63+
]),
6464
AggregationCursor.toArray
6565
)
6666
})

0 commit comments

Comments
 (0)