@opra/mongodb 0.33.3 → 0.33.4

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.
@@ -15,76 +15,63 @@ export declare class MongoService<T extends mongodb.Document> extends ApiService
15
15
  protected _dataType: Type | string;
16
16
  /**
17
17
  * Represents the name of a collection in MongoDB
18
- *
19
- * @type {string | Function} collectionName
20
18
  */
21
19
  collectionName?: string | ((_this: any) => string);
22
20
  /**
23
21
  * Represents the name of a resource.
24
- *
25
22
  * @type {string}
26
23
  */
27
24
  resourceName?: string | ((_this: any) => string);
28
25
  /**
29
26
  * Represents a MongoDB database object.
30
- * @type {mongodb.Db | Function}
31
27
  */
32
28
  db?: mongodb.Db | ((_this: any) => mongodb.Db);
33
29
  /**
34
30
  * Represents a MongoDB ClientSession.
35
- *
36
- * @type {mongodb.ClientSession}
37
31
  */
38
32
  session?: mongodb.ClientSession | ((_this: any) => mongodb.ClientSession);
39
33
  /**
40
34
  * Generates a new id for new inserting Document.
41
35
  *
42
36
  * @protected
43
- * @returns {AnyId} A new instance of AnyId.
44
37
  */
45
38
  $idGenerator?: (_this: any) => AnyId;
46
39
  /**
47
40
  * Callback function for handling errors.
48
41
  *
49
42
  * @param {unknown} error - The error object.
50
- * @param {object} _this - The context object.
51
- * @return {void|Promise<void>} - A void value or a promise that resolves to void.
43
+ * @param _this - The context object.
52
44
  */
53
45
  $onError?: (error: unknown, _this: any) => void | Promise<void>;
54
46
  /**
55
47
  * Constructs a new instance
56
48
  *
57
- * @param {Type | string} dataType - The data type of the array elements.
58
- * @param {MongoService.Options} [options] - The options for the array service.
49
+ * @param dataType - The data type of the array elements.
50
+ * @param [options] - The options for the array service.
59
51
  * @constructor
60
52
  */
61
53
  constructor(dataType: Type | string, options?: MongoService.Options);
62
54
  /**
63
55
  * Retrieves the data type of the document
64
56
  *
65
- * @returns {ComplexType} The complex data type of the field.
66
57
  * @throws {NotAcceptableError} If the data type is not a ComplexType.
67
58
  */
68
59
  getDataType(): ComplexType;
69
60
  /**
70
61
  * Retrieves the encoder for the specified operation.
71
62
  *
72
- * @param {String} operation - The operation to retrieve the encoder for. Valid values are 'create' and 'update'.
73
- * @returns {IsObject.Validator<T>} - The encoder for the specified operation.
63
+ * @param operation - The operation to retrieve the encoder for. Valid values are 'create' and 'update'.
74
64
  */
75
65
  getEncoder(operation: 'create' | 'update'): IsObject.Validator<T>;
76
66
  /**
77
67
  * Retrieves the decoder.
78
- *
79
- * @returns {IsObject.Validator<T>} - The encoder for the specified operation.
80
68
  */
81
69
  getDecoder(): IsObject.Validator<T>;
82
70
  /**
83
71
  * Executes the provided function within a transaction.
84
72
  *
85
- * @param {WithTransactionCallback} callback - The function to be executed within the transaction.
86
- * @param {TransactionOptions} [options] - Optional options for the transaction.
87
- * @returns {Promise<any>} - A promise that resolves with the result of the function execution within the transaction.
73
+ * @param callback - The function to be executed within the transaction.
74
+ * @param [options] - Optional options for the transaction.
88
75
  */
89
76
  withTransaction(callback: WithTransactionCallback, options?: TransactionOptions): Promise<any>;
90
77
  /**
@@ -92,103 +79,101 @@ export declare class MongoService<T extends mongodb.Document> extends ApiService
92
79
  * one will be added to each of the documents missing it by the driver, mutating the document. This behavior
93
80
  * can be overridden by setting the **forceServerObjectId** flag.
94
81
  *
95
- * @param {T} doc - The document to be inserted.
96
- * @param {mongodb.InsertOneOptions} options - The options for the insert operation.
97
- * @returns {Promise<mongodb.InsertOneWriteOpResult<mongodb.OptionalId<T>>>} - A promise that resolves with the result of the insert operation.
82
+ * @param doc - The document to insert
83
+ * @param options - Optional settings for the command
98
84
  * @protected
99
85
  */
100
86
  protected __insertOne(doc: mongodb.OptionalUnlessRequiredId<T>, options?: mongodb.InsertOneOptions): Promise<mongodb.InsertOneResult<T>>;
101
87
  /**
102
88
  * Gets the number of documents matching the filter.
103
89
  *
104
- * @param {mongodb.Filter<T>} filter - The filter used to match documents.
105
- * @param {mongodb.CountOptions} options - The options for counting documents.
106
- * @returns {Promise<number>} - The number of documents matching the filter.
90
+ * @param filter - The filter used to match documents.
91
+ * @param options - The options for counting documents.
107
92
  * @protected
108
93
  */
109
94
  protected __countDocuments(filter?: mongodb.Filter<T>, options?: mongodb.CountOptions): Promise<number>;
110
95
  /**
111
96
  * Delete a document from a collection
112
97
  *
113
- * @param {mongodb.Filter<T>} filter - The filter used to select the document to remove
114
- * @param {mongodb.DeleteOptions} options - Optional settings for the command
115
- * @return {Promise<mongodb.DeleteResult>} A Promise that resolves to the result of the delete operation
98
+ * @param filter - The filter used to select the document to remove
99
+ * @param options - Optional settings for the command
100
+ * @protected
116
101
  */
117
102
  protected __deleteOne(filter?: mongodb.Filter<T>, options?: mongodb.DeleteOptions): Promise<mongodb.DeleteResult>;
118
103
  /**
119
- * Deletes multiple documents from a collection.
104
+ * Delete multiple documents from a collection
120
105
  *
121
- * @param {mongodb.Filter<T>} [filter] - The filter object specifying the documents to delete.
122
- * If not provided, all documents in the collection will be deleted.
123
- * @param {mongodb.DeleteOptions} [options] - The options for the delete operation.
124
- * @returns {Promise<mongodb.DeleteResult>} A promise that resolves with the delete result object.
106
+ * @param filter - The filter used to select the documents to remove
107
+ * @param options - Optional settings for the command
125
108
  * @protected
126
109
  */
127
110
  protected __deleteMany(filter?: mongodb.Filter<T>, options?: mongodb.DeleteOptions): Promise<mongodb.DeleteResult>;
128
111
  /**
129
- * Create a new Change Stream, watching for new changes
130
- * (insertions, updates, replacements, deletions, and invalidations) in this collection.
112
+ * Gets the number of documents matching the filter.
113
+ *
114
+ * @param field - Field of the document to find distinct values for
115
+ * @param filter - The filter for filtering the set of documents to which we apply the distinct filter.
116
+ * @param options - Optional settings for the command
117
+ * @protected
118
+ */
119
+ protected __distinct(field: string, filter?: mongodb.Filter<T>, options?: mongodb.DistinctOptions): Promise<any[]>;
120
+ /**
121
+ * Execute an aggregation framework pipeline against the collection, needs MongoDB \>= 2.2
131
122
  *
132
- * @param {mongodb.Document[]} pipeline - The pipeline of aggregation stages to apply to the collection.
133
- * @param {mongodb.AggregateOptions} options - The options to customize the aggregation.
134
- * @returns {Promise<mongodb.ChangeStream<T>>} - A promise that resolves to a Change Stream that represents the result of the aggregation.
123
+ * @param pipeline - An array of aggregation pipelines to execute
124
+ * @param options - Optional settings for the command
135
125
  * @protected
136
126
  */
137
127
  protected __aggregate(pipeline?: mongodb.Document[], options?: mongodb.AggregateOptions): Promise<mongodb.AggregationCursor<T>>;
138
128
  /**
139
129
  * Fetches the first document that matches the filter
140
130
  *
141
- * @param {mongodb.Filter<T>} filter - The filter object to match documents against
142
- * @param {mongodb.FindOptions} [options] - The options to use when querying the collection
131
+ * @param filter - Query for find Operation
132
+ * @param options - Optional settings for the command
143
133
  * @protected
144
- * @returns {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the first matching document, or undefined if no match is found
145
134
  */
146
135
  protected __findOne(filter: mongodb.Filter<T>, options?: mongodb.FindOptions): Promise<PartialDTO<T> | undefined>;
147
136
  /**
148
- * Creates a cursor for a filter that can be used to iterate over results from MongoDB.
137
+ * Creates a cursor for a filter that can be used to iterate over results from MongoDB
149
138
  *
150
- * @param {mongodb.Filter<T>} filter - The filter to apply when searching for results.
151
- * @param {mongodb.FindOptions} [options] - The options to customize the search behavior.
152
- * @returns {mongodb.Cursor<T>} - The cursor object that can be used to iterate over the results.
139
+ * @param filter - The filter predicate. If unspecified,
140
+ * then all documents in the collection will match the predicate
141
+ * @param options - Optional settings for the command
153
142
  * @protected
154
143
  */
155
144
  protected __find(filter: mongodb.Filter<T>, options?: mongodb.FindOptions): Promise<mongodb.FindCursor<T>>;
156
145
  /**
157
- * Update a single document in a collection.
146
+ * Update a single document in a collection
158
147
  *
159
- * @param {mongodb.Filter<T>} filter - The filter to select the document(s) to update.
160
- * @param {mongodb.UpdateFilter<T>} update - The update operation to be applied on the selected document(s).
161
- * @param {mongodb.UpdateOptions} [options] - Optional settings for the update operation.
148
+ * @param filter - The filter used to select the document to update
149
+ * @param update - The update operations to be applied to the document
150
+ * @param options - Optional settings for the command
162
151
  * @protected
163
- * @returns {Promise<mongodb.UpdateResult>} - A promise that resolves to the result of the update operation.
164
152
  */
165
153
  protected __updateOne(filter: mongodb.Filter<T>, update: mongodb.UpdateFilter<T>, options?: mongodb.UpdateOptions): Promise<mongodb.UpdateResult<T>>;
166
154
  /**
167
155
  * Find a document and update it in one atomic operation. Requires a write lock for the duration of the operation.
168
156
  *
169
- * @param {mongodb.Filter<T>} filter - The filter to select the document to be updated.
170
- * @param {mongodb.UpdateFilter<T>} doc - The update document.
171
- * @param {mongodb.FindOneAndUpdateOptions} [options] - Optional options for the find one and update operation.
172
- * @returns {Promise<T | null>} - A promise that resolves to the updated document or null if no document matched the filter.
157
+ * @param filter - The filter used to select the document to update
158
+ * @param update - Update operations to be performed on the document
159
+ * @param options - Optional settings for the command
173
160
  * @protected
174
161
  */
175
- protected __findOneAndUpdate(filter: mongodb.Filter<T>, doc: mongodb.UpdateFilter<T>, options?: mongodb.FindOneAndUpdateOptions): Promise<mongodb.WithId<T> | null>;
162
+ protected __findOneAndUpdate(filter: mongodb.Filter<T>, update: mongodb.UpdateFilter<T>, options?: mongodb.FindOneAndUpdateOptions): Promise<mongodb.WithId<T> | null>;
176
163
  /**
177
- * Update multiple documents in a collection.
164
+ * Update multiple documents in a collection
178
165
  *
179
- * @param {mongodb.Filter<T>} filter - The filter used to select the documents to be updated.
180
- * @param {mongodb.UpdateFilter<T> | Partial<T>} doc - The updates to be applied to the selected documents.
181
- * @param {StrictOmit<mongodb.UpdateOptions, 'upsert'>} [options] - The optional settings for the update operation.
182
- * @return {Promise<mongodb.UpdateResult>} - A Promise that resolves to the result of the update operation.
166
+ * @param filter - The filter used to select the documents to update
167
+ * @param update - The update operations to be applied to the documents
168
+ * @param options - Optional settings for the command
183
169
  * @protected
184
170
  */
185
- protected __updateMany(filter: mongodb.Filter<T>, doc: mongodb.UpdateFilter<T> | Partial<T>, options?: StrictOmit<mongodb.UpdateOptions, 'upsert'>): Promise<mongodb.UpdateResult<T>>;
171
+ protected __updateMany(filter: mongodb.Filter<T>, update: mongodb.UpdateFilter<T> | Partial<T>, options?: StrictOmit<mongodb.UpdateOptions, 'upsert'>): Promise<mongodb.UpdateResult<T>>;
186
172
  /**
187
173
  * Retrieves the database connection.
188
174
  *
189
175
  * @protected
190
176
  *
191
- * @returns {Promise<mongodb.Db>} The database connection.
192
177
  * @throws {Error} If the context or database is not set.
193
178
  */
194
179
  protected getDatabase(): mongodb.Db;
@@ -197,23 +182,21 @@ export declare class MongoService<T extends mongodb.Document> extends ApiService
197
182
  *
198
183
  * @protected
199
184
  *
200
- * @returns {Promise<mongodb.ClientSession>} The database connection.
201
185
  * @throws {Error} If the context or database is not set.
202
186
  */
203
187
  protected getSession(): mongodb.ClientSession | undefined;
204
188
  /**
205
189
  * Retrieves a MongoDB collection from the given database.
206
190
  *
207
- * @param {mongodb.Db} db - The MongoDB database.
191
+ * @param db - The MongoDB database.
208
192
  * @protected
209
- * @returns {Promise<mongodb.Collection<T>>} A promise that resolves to the MongoDB collection.
210
193
  */
211
194
  protected getCollection(db: mongodb.Db): Promise<mongodb.Collection<T>>;
212
195
  /**
213
196
  * Retrieves the collection name.
214
197
  *
215
198
  * @protected
216
- * @returns {string} The collection name.
199
+ * @returns The collection name.
217
200
  * @throws {Error} If the collection name is not defined.
218
201
  */
219
202
  getCollectionName(): string;
@@ -221,23 +204,23 @@ export declare class MongoService<T extends mongodb.Document> extends ApiService
221
204
  * Retrieves the resource name.
222
205
  *
223
206
  * @protected
224
- * @returns {string} The collection name.
207
+ * @returns {string} The resource name.
225
208
  * @throws {Error} If the collection name is not defined.
226
209
  */
227
210
  getResourceName(): string;
228
211
  /**
229
212
  * Generates an encoder for the specified operation.
230
213
  *
231
- * @param {string} operation - The operation to generate the encoder for. Must be either 'create' or 'update'.
214
+ * @param operation - The operation to generate the encoder for. Must be either 'create' or 'update'.
232
215
  * @protected
233
- * @returns {IsObject.Validator} - The generated encoder for the specified operation.
216
+ * @returns - The generated encoder for the specified operation.
234
217
  */
235
218
  protected _generateEncoder(operation: 'create' | 'update'): IsObject.Validator<T>;
236
219
  /**
237
220
  * Generates an encoder for the specified operation.
238
221
  *
239
222
  * @protected
240
- * @returns {IsObject.Validator} - The generated encoder for the specified operation.
223
+ * @returns - The generated encoder for the specified operation.
241
224
  */
242
225
  protected _generateDecoder(): IsObject.Validator<T>;
243
226
  }