Skip to content

Commit 75f7c60

Browse files
update pipeline stage types
1 parent 93c493f commit 75f7c60

2 files changed

Lines changed: 46 additions & 38 deletions

File tree

src/collection/types/expressions.ts

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,68 @@ export type Expression =
1616
export type AnyExpression = Expression;
1717

1818
export type AccumulatorOperator = {
19-
$accumulator?: any;
19+
$accumulator?: {
20+
init: Expression;
21+
initArgs?: Expression[];
22+
accumulate: Expression;
23+
accumulateArgs: Expression[];
24+
merge: Expression;
25+
finalize?: Expression;
26+
lang: "js";
27+
};
2028
$addToSet?: Expression;
2129
$avg?: Expression;
22-
$bottom?: any;
23-
$bottomN?: any;
24-
$count?: any;
30+
$bottom?: { sortBy: Record<string, 1 | -1>; output: Expression | Expression[] };
31+
$bottomN?: { sortBy: Record<string, 1 | -1>; output: Expression | Expression[]; n: Expression };
32+
$count?: Record<string, never>;
2533
$first?: Expression;
26-
$firstN?: any;
34+
$firstN?: { input: Expression; n: Expression };
2735
$last?: Expression;
28-
$lastN?: any;
36+
$lastN?: { input: Expression; n: Expression };
2937
$max?: Expression;
30-
$maxN?: any;
38+
$maxN?: { input: Expression; n: Expression };
3139
$mergeObjects?: Expression;
3240
$min?: Expression;
33-
$minN?: any;
41+
$minN?: { input: Expression; n: Expression };
3442
$push?: Expression;
3543
$stdDevPop?: Expression;
3644
$stdDevSamp?: Expression;
3745
$sum?: Expression;
38-
$top?: any;
39-
$topN?: any;
46+
$top?: { sortBy: Record<string, 1 | -1>; output: Expression | Expression[] };
47+
$topN?: { sortBy: Record<string, 1 | -1>; output: Expression | Expression[]; n: Expression };
4048
};
4149

4250
export type WindowOperator = {
4351
$addToSet?: Expression;
4452
$avg?: Expression;
45-
$bottom?: any;
46-
$bottomN?: any;
47-
$count?: any;
48-
$covariancePop?: any;
49-
$covarianceSamp?: any;
50-
$denseRank?: any;
51-
$derivative?: any;
52-
$documentNumber?: any;
53-
$expMovingAvg?: any;
53+
$bottom?: { sortBy: Record<string, 1 | -1>; output: Expression | Expression[] };
54+
$bottomN?: { sortBy: Record<string, 1 | -1>; output: Expression | Expression[]; n: Expression };
55+
$count?: Record<string, never>;
56+
$covariancePop?: Expression | [Expression, Expression];
57+
$covarianceSamp?: Expression | [Expression, Expression];
58+
$denseRank?: Record<string, never>;
59+
$derivative?: { input: Expression; unit?: string };
60+
$documentNumber?: Record<string, never>;
61+
$expMovingAvg?: { input: Expression; N: number } | { input: Expression; alpha: number };
5462
$first?: Expression;
55-
$firstN?: any;
56-
$integral?: any;
63+
$firstN?: { input: Expression; n: Expression };
64+
$integral?: { input: Expression; unit?: string };
5765
$last?: Expression;
58-
$lastN?: any;
59-
$linearFill?: any;
60-
$locf?: any;
66+
$lastN?: { input: Expression; n: Expression };
67+
$linearFill?: Expression;
68+
$locf?: Expression;
6169
$max?: Expression;
62-
$maxN?: any;
70+
$maxN?: { input: Expression; n: Expression };
6371
$min?: Expression;
64-
$minN?: any;
72+
$minN?: { input: Expression; n: Expression };
6573
$push?: Expression;
66-
$rank?: any;
67-
$shift?: any;
74+
$rank?: Record<string, never>;
75+
$shift?: { output: Expression; by: number; default?: Expression };
6876
$stdDevPop?: Expression;
6977
$stdDevSamp?: Expression;
7078
$sum?: Expression;
71-
$top?: any;
72-
$topN?: any;
79+
$top?: { sortBy: Record<string, 1 | -1>; output: Expression | Expression[] };
80+
$topN?: { sortBy: Record<string, 1 | -1>; output: Expression | Expression[]; n: Expression };
7381
};
7482

7583
export type ObjectExpressionOperator = {

src/collection/types/pipeline-stage.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ export interface Bucket {
6262
/** [`$bucket` reference](https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/) */
6363
$bucket: {
6464
groupBy: Expression;
65-
boundaries: any[];
66-
default?: any;
65+
boundaries: Expression[];
66+
default?: Expression;
6767
output?: Record<string, AccumulatorOperator>;
6868
};
6969
}
@@ -134,7 +134,7 @@ export interface Facet {
134134
$facet: Record<string, FacetPipelineStage[]>;
135135
}
136136

137-
export type FacetPipelineStage<T = any> = Exclude<
137+
export type FacetPipelineStage<T = Document> = Exclude<
138138
PipelineStage<T>,
139139
CollStats | Facet | GeoNear | IndexStats | Out | Merge<T> | PlanCacheStats
140140
>;
@@ -175,7 +175,7 @@ export interface GraphLookup {
175175

176176
export interface Group {
177177
/** [`$group` reference](https://www.mongodb.com/docs/manual/reference/operator/aggregation/group) */
178-
$group: { _id: any } | { [key: string]: AccumulatorOperator };
178+
$group: { _id: Expression } | { [key: string]: AccumulatorOperator };
179179
}
180180

181181
export interface IndexStats {
@@ -273,7 +273,7 @@ export interface Search {
273273
maxCharsToExamine?: number;
274274
maxNumPassages?: number;
275275
};
276-
[operator: string]: any;
276+
[operator: string]: unknown;
277277
};
278278
}
279279

@@ -287,19 +287,19 @@ export interface SearchMeta {
287287
maxCharsToExamine?: number;
288288
maxNumPassages?: number;
289289
};
290-
[operator: string]: any;
290+
[operator: string]: unknown;
291291
};
292292
}
293293

294294
export interface Set {
295295
/** [`$set` reference](https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/) */
296-
$set: Record<string, AnyExpression | any>;
296+
$set: Record<string, AnyExpression>;
297297
}
298298

299299
export interface SetWindowFields {
300300
/** [`$setWindowFields` reference](https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/) */
301301
$setWindowFields: {
302-
partitionBy?: any;
302+
partitionBy?: Expression;
303303
sortBy?: Record<string, 1 | -1>;
304304
output: Record<
305305
string,

0 commit comments

Comments
 (0)