@tmlmobilidade/interfaces 20250827.1513.21 → 20250827.1523.9
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.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Filter } from 'mongodb';
|
|
2
|
+
interface MatchStage<T> {
|
|
3
|
+
$match: Filter<T>;
|
|
4
|
+
}
|
|
5
|
+
interface ProjectStage<T> {
|
|
6
|
+
$project: Partial<Record<keyof T, 0 | 1>>;
|
|
7
|
+
}
|
|
8
|
+
interface GroupStage {
|
|
9
|
+
$group: {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
_id: Record<string, any> | string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
interface SortStage<T> {
|
|
15
|
+
$sort: Partial<Record<keyof T, -1 | 1>>;
|
|
16
|
+
}
|
|
17
|
+
interface LimitStage {
|
|
18
|
+
$limit: number;
|
|
19
|
+
}
|
|
20
|
+
interface SkipStage {
|
|
21
|
+
$skip: number;
|
|
22
|
+
}
|
|
23
|
+
type AggregationStage<T> = GroupStage | LimitStage | MatchStage<T> | ProjectStage<T> | SkipStage | SortStage<T>;
|
|
24
|
+
export type AggregationPipeline<T> = AggregationStage<T>[];
|
|
25
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,12 +2,18 @@ import { MongoConnector } from '@tmlmobilidade/connectors';
|
|
|
2
2
|
import { type UnixTimestamp } from '@tmlmobilidade/types';
|
|
3
3
|
import { Collection, DeleteOptions, DeleteResult, Document, Filter, FindOptions, IndexDescription, InsertOneOptions, InsertOneResult, MongoClientOptions, UpdateOptions, UpdateResult, WithId } from 'mongodb';
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
+
import { AggregationPipeline } from './aggregation-pipeline.js';
|
|
5
6
|
export declare abstract class MongoCollectionClass<T extends Document, TCreate, TUpdate> {
|
|
6
7
|
protected createSchema: null | z.ZodSchema;
|
|
7
8
|
protected mongoCollection: Collection<T>;
|
|
8
9
|
protected mongoConnector: MongoConnector;
|
|
9
10
|
protected updateSchema: null | z.ZodSchema;
|
|
10
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Aggregates documents in the collection.
|
|
13
|
+
* @param pipeline - The aggregation pipeline to execute
|
|
14
|
+
* @returns A promise that resolves to an array of aggregated documents
|
|
15
|
+
*/
|
|
16
|
+
aggregate(pipeline: AggregationPipeline<T>): Promise<T[]>;
|
|
11
17
|
/**
|
|
12
18
|
* Gets all documents in the collection.
|
|
13
19
|
* @returns A promise that resolves to an array of all documents
|
|
@@ -147,27 +153,3 @@ export declare abstract class MongoCollectionClass<T extends Document, TCreate,
|
|
|
147
153
|
protected abstract getCollectionName(): string;
|
|
148
154
|
protected abstract getEnvName(): string;
|
|
149
155
|
}
|
|
150
|
-
interface MatchStage<T> {
|
|
151
|
-
$match: Partial<T>;
|
|
152
|
-
}
|
|
153
|
-
interface ProjectStage<T> {
|
|
154
|
-
$project: Partial<Record<keyof T, 0 | 1>>;
|
|
155
|
-
}
|
|
156
|
-
interface GroupStage<T> {
|
|
157
|
-
$group: {
|
|
158
|
-
[key: string]: any;
|
|
159
|
-
_id: Record<string, keyof T> | string;
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
interface SortStage<T> {
|
|
163
|
-
$sort: Partial<Record<keyof T, -1 | 1>>;
|
|
164
|
-
}
|
|
165
|
-
interface LimitStage {
|
|
166
|
-
$limit: number;
|
|
167
|
-
}
|
|
168
|
-
interface SkipStage {
|
|
169
|
-
$skip: number;
|
|
170
|
-
}
|
|
171
|
-
type AggregationStage<T> = GroupStage<T> | LimitStage | MatchStage<T> | ProjectStage<T> | SkipStage | SortStage<T>;
|
|
172
|
-
export type AggregationPipeline<T> = AggregationStage<T>[];
|
|
173
|
-
export {};
|
|
@@ -8,6 +8,11 @@ export class MongoCollectionClass {
|
|
|
8
8
|
mongoCollection;
|
|
9
9
|
mongoConnector;
|
|
10
10
|
updateSchema = null;
|
|
11
|
+
/**
|
|
12
|
+
* Aggregates documents in the collection.
|
|
13
|
+
* @param pipeline - The aggregation pipeline to execute
|
|
14
|
+
* @returns A promise that resolves to an array of aggregated documents
|
|
15
|
+
*/
|
|
11
16
|
async aggregate(pipeline) {
|
|
12
17
|
return await this.mongoCollection.aggregate(pipeline).toArray();
|
|
13
18
|
}
|
package/package.json
CHANGED