@opra/mongodb 0.33.2 → 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.
- package/cjs/mongo-collection-service.js +72 -21
- package/cjs/mongo-service.js +71 -66
- package/esm/mongo-collection-service.js +72 -21
- package/esm/mongo-service.js +71 -66
- package/package.json +3 -3
- package/types/mongo-collection-service.d.ts +27 -16
- package/types/mongo-service.d.ts +53 -70
package/types/mongo-service.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
58
|
-
* @param
|
|
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
|
|
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
|
|
86
|
-
* @param
|
|
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
|
|
96
|
-
* @param
|
|
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
|
|
105
|
-
* @param
|
|
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
|
|
114
|
-
* @param
|
|
115
|
-
* @
|
|
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
|
-
*
|
|
104
|
+
* Delete multiple documents from a collection
|
|
120
105
|
*
|
|
121
|
-
* @param
|
|
122
|
-
*
|
|
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
|
-
*
|
|
130
|
-
*
|
|
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
|
|
133
|
-
* @param
|
|
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
|
|
142
|
-
* @param
|
|
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
|
|
151
|
-
*
|
|
152
|
-
* @
|
|
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
|
|
160
|
-
* @param
|
|
161
|
-
* @param
|
|
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
|
|
170
|
-
* @param
|
|
171
|
-
* @param
|
|
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>,
|
|
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
|
|
180
|
-
* @param
|
|
181
|
-
* @param
|
|
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>,
|
|
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
|
|
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
|
|
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
|
|
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
|
|
214
|
+
* @param operation - The operation to generate the encoder for. Must be either 'create' or 'update'.
|
|
232
215
|
* @protected
|
|
233
|
-
* @returns
|
|
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
|
|
223
|
+
* @returns - The generated encoder for the specified operation.
|
|
241
224
|
*/
|
|
242
225
|
protected _generateDecoder(): IsObject.Validator<T>;
|
|
243
226
|
}
|