@opra/mongodb 1.0.0-alpha.30 → 1.0.0-alpha.32

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.
@@ -33,15 +33,6 @@ class MongoCollectionService extends mongo_entity_service_js_1.MongoEntityServic
33
33
  if (!(await this.exists(id, options)))
34
34
  throw new common_1.ResourceNotAvailableError(this.getResourceName(), id);
35
35
  }
36
- /**
37
- * Creates a new document in the MongoDB collection.
38
- * Interceptors will be called before performing db operation
39
- *
40
- * @param {PartialDTO<T>} input - The input data for creating the document.
41
- * @param {MongoEntityService.CreateOptions} [options] - The options for creating the document.
42
- * @returns {Promise<PartialDTO<T>>} A promise that resolves to the created document.
43
- * @throws {Error} if an unknown error occurs while creating the document.
44
- */
45
36
  async create(input, options) {
46
37
  const command = {
47
38
  crud: 'create',
@@ -163,13 +154,6 @@ class MongoCollectionService extends mongo_entity_service_js_1.MongoEntityServic
163
154
  async existsOne(options) {
164
155
  return !!(await this.findOne({ ...options, projection: ['_id'] }));
165
156
  }
166
- /**
167
- * Finds a document by its ID.
168
- *
169
- * @param {MongoAdapter.AnyId} id - The ID of the document.
170
- * @param {MongoEntityService.FindOneOptions<T>} [options] - The options for the find query.
171
- * @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
172
- */
173
157
  async findById(id, options) {
174
158
  const command = {
175
159
  crud: 'read',
@@ -185,12 +169,6 @@ class MongoCollectionService extends mongo_entity_service_js_1.MongoEntityServic
185
169
  return this._findById(command);
186
170
  });
187
171
  }
188
- /**
189
- * Finds a document in the collection that matches the specified options.
190
- *
191
- * @param {MongoEntityService.FindOneOptions<T>} [options] - The options for the query.
192
- * @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
193
- */
194
172
  async findOne(options) {
195
173
  const command = {
196
174
  crud: 'read',
@@ -204,12 +182,6 @@ class MongoCollectionService extends mongo_entity_service_js_1.MongoEntityServic
204
182
  return this._findOne(command);
205
183
  });
206
184
  }
207
- /**
208
- * Finds multiple documents in the MongoDB collection.
209
- *
210
- * @param {MongoEntityService.FindManyOptions<T>} options - The options for the find operation.
211
- * @return A Promise that resolves to an array of partial outputs of type T.
212
- */
213
185
  async findMany(options) {
214
186
  const command = {
215
187
  crud: 'read',
@@ -224,13 +196,6 @@ class MongoCollectionService extends mongo_entity_service_js_1.MongoEntityServic
224
196
  return this._findMany(command);
225
197
  });
226
198
  }
227
- /**
228
- * Finds multiple documents in the collection and returns both records (max limit)
229
- * and total count that matched the given criteria
230
- *
231
- * @param {MongoEntityService.FindManyOptions<T>} [options] - The options for the find operation.
232
- * @return A Promise that resolves to an array of partial outputs of type T.
233
- */
234
199
  async findManyWithCount(options) {
235
200
  const command = {
236
201
  crud: 'read',
@@ -244,30 +209,12 @@ class MongoCollectionService extends mongo_entity_service_js_1.MongoEntityServic
244
209
  return this._findManyWithCount(command);
245
210
  });
246
211
  }
247
- /**
248
- * Retrieves a document from the collection by its ID. Throws error if not found.
249
- *
250
- * @param {MongoAdapter.AnyId} id - The ID of the document to retrieve.
251
- * @param {MongoEntityService.FindOneOptions<T>} [options] - Optional options for the findOne operation.
252
- * @returns {Promise<PartialDTO<T>>} - A promise that resolves to the retrieved document,
253
- * or rejects with a ResourceNotFoundError if the document does not exist.
254
- * @throws {ResourceNotAvailableError} - If the document with the specified ID does not exist.
255
- */
256
212
  async get(id, options) {
257
213
  const out = await this.findById(id, options);
258
214
  if (!out)
259
215
  throw new common_1.ResourceNotAvailableError(this.getResourceName(), id);
260
216
  return out;
261
217
  }
262
- /**
263
- * Updates a document with the given id in the collection.
264
- *
265
- * @param {MongoAdapter.AnyId} id - The id of the document to update.
266
- * @param {PatchDTO<T>|UpdateFilter<T>} input - The partial input object containing the fields to update.
267
- * @param {MongoEntityService.UpdateOneOptions<T>} [options] - The options for the update operation.
268
- * @returns {Promise<PartialDTO<T> | undefined>} A promise that resolves to the updated document or
269
- * undefined if the document was not found.
270
- */
271
218
  async update(id, input, options) {
272
219
  const isUpdateFilter = Array.isArray(input) || !!Object.keys(input).find(x => x.startsWith('$'));
273
220
  const command = {
@@ -55,15 +55,6 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
55
55
  throw new common_1.ResourceNotAvailableError(this.getResourceName() + '.' + this.nestedKey, documentId + '/' + id);
56
56
  }
57
57
  }
58
- /**
59
- * Adds a single item into the array field.
60
- *
61
- * @param {MongoAdapter.AnyId} documentId - The ID of the parent document.
62
- * @param {T} input - The item to be added to the array field.
63
- * @param {MongoNestedService.CreateOptions} [options] - Optional options for the create operation.
64
- * @return {Promise<PartialDTO<T>>} - A promise that resolves with the partial output of the created item.
65
- * @throws {ResourceNotAvailableError} - If the parent document is not found.
66
- */
67
58
  async create(documentId, input, options) {
68
59
  const command = {
69
60
  crud: 'create',
@@ -280,14 +271,6 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
280
271
  return !!(await this._findOne(findCommand));
281
272
  });
282
273
  }
283
- /**
284
- * Finds an element in array field by its parent ID and ID.
285
- *
286
- * @param {MongoAdapter.AnyId} documentId - The ID of the document.
287
- * @param {MongoAdapter.AnyId} nestedId - The ID of the document.
288
- * @param {MongoNestedService.FindOneOptions<T>} [options] - The optional options for the operation.
289
- * @returns {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the found document or undefined if not found.
290
- */
291
274
  async findById(documentId, nestedId, options) {
292
275
  const command = {
293
276
  crud: 'read',
@@ -325,13 +308,6 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
325
308
  const rows = await this._findMany(findManyCommand);
326
309
  return rows?.[0];
327
310
  }
328
- /**
329
- * Finds the first array element that matches the given parentId.
330
- *
331
- * @param {MongoAdapter.AnyId} documentId - The ID of the document.
332
- * @param {MongoNestedService.FindOneOptions<T>} [options] - Optional options to customize the query.
333
- * @returns {Promise<PartialDTO<T> | undefined>} A promise that resolves to the first matching document, or `undefined` if no match is found.
334
- */
335
311
  async findOne(documentId, options) {
336
312
  const command = {
337
313
  crud: 'read',
@@ -360,13 +336,6 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
360
336
  const rows = await this._findMany(findManyCommand);
361
337
  return rows?.[0];
362
338
  }
363
- /**
364
- * Finds multiple elements in an array field.
365
- *
366
- * @param {MongoAdapter.AnyId} documentId - The ID of the parent document.
367
- * @param {MongoNestedService.FindManyOptions<T>} [options] - The options for finding the documents.
368
- * @returns {Promise<PartialDTO<T>[]>} - The found documents.
369
- */
370
339
  async findMany(documentId, options) {
371
340
  const command = {
372
341
  crud: 'read',
@@ -430,13 +399,6 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
430
399
  await cursor.close();
431
400
  }
432
401
  }
433
- /**
434
- * Finds multiple elements in an array field.
435
- *
436
- * @param {MongoAdapter.AnyId} documentId - The ID of the parent document.
437
- * @param {MongoNestedService.FindManyOptions<T>} [options] - The options for finding the documents.
438
- * @returns {Promise<PartialDTO<T>[]>} - The found documents.
439
- */
440
402
  async findManyWithCount(documentId, options) {
441
403
  const command = {
442
404
  crud: 'read',
@@ -512,15 +474,6 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
512
474
  await cursor.close();
513
475
  }
514
476
  }
515
- /**
516
- * Retrieves a specific item from the array of a document.
517
- *
518
- * @param {MongoAdapter.AnyId} documentId - The ID of the document.
519
- * @param {MongoAdapter.AnyId} nestedId - The ID of the item.
520
- * @param {MongoNestedService.FindOneOptions<T>} [options] - The options for finding the item.
521
- * @returns {Promise<PartialDTO<T>>} - The item found.
522
- * @throws {ResourceNotAvailableError} - If the item is not found.
523
- */
524
477
  async get(documentId, nestedId, options) {
525
478
  const out = await this.findById(documentId, nestedId, options);
526
479
  if (!out) {
@@ -528,16 +481,6 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
528
481
  }
529
482
  return out;
530
483
  }
531
- /**
532
- * Updates an array element with new data and returns the updated element
533
- *
534
- * @param {AnyId} documentId - The ID of the document to update.
535
- * @param {AnyId} nestedId - The ID of the item to update within the document.
536
- * @param {PatchDTO<T>} input - The new data to update the item with.
537
- * @param {MongoNestedService.UpdateOneOptions<T>} [options] - Additional update options.
538
- * @returns {Promise<PartialDTO<T> | undefined>} The updated item or undefined if it does not exist.
539
- * @throws {Error} If an error occurs while updating the item.
540
- */
541
484
  async update(documentId, nestedId, input, options) {
542
485
  const command = {
543
486
  crud: 'update',
@@ -34,14 +34,6 @@ class MongoSingletonService extends mongo_entity_service_js_1.MongoEntityService
34
34
  if (!(await this.exists(options)))
35
35
  throw new common_1.ResourceNotAvailableError(this.getResourceName());
36
36
  }
37
- /**
38
- * Creates the document in the database.
39
- *
40
- * @param {PartialDTO<T>} input - The partial input to create the document with.
41
- * @param {MongoEntityService.CreateOptions} [options] - The options for creating the document.
42
- * @return {Promise<PartialDTO<T>>} A promise that resolves to the partial output of the created document.
43
- * @throws {Error} Throws an error if an unknown error occurs while creating the document.
44
- */
45
37
  async create(input, options) {
46
38
  const command = {
47
39
  crud: 'create',
@@ -95,12 +87,6 @@ class MongoSingletonService extends mongo_entity_service_js_1.MongoEntityService
95
87
  return !!(await this._findById(findCommand));
96
88
  });
97
89
  }
98
- /**
99
- * Fetches the document if it exists. Returns undefined if not found.
100
- *
101
- * @param {MongoEntityService.FindOneOptions<T>} [options] - The options for finding the document.
102
- * @returns {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the found document or undefined if not found.
103
- */
104
90
  async find(options) {
105
91
  const command = {
106
92
  crud: 'read',
@@ -116,27 +102,12 @@ class MongoSingletonService extends mongo_entity_service_js_1.MongoEntityService
116
102
  return this._findById(command);
117
103
  });
118
104
  }
119
- /**
120
- * Fetches the document from the Mongo collection service. Throws error if not found.
121
- *
122
- * @param {MongoEntityService.FindOneOptions<T>} options - The options to customize the query.
123
- * @return {Promise<PartialDTO<T>>} - A promise that resolves to the fetched document.
124
- * @throws {ResourceNotAvailableError} - If the document is not found in the collection.
125
- */
126
105
  async get(options) {
127
106
  const out = await this.find(options);
128
107
  if (!out)
129
108
  throw new common_1.ResourceNotAvailableError(this.getResourceName());
130
109
  return out;
131
110
  }
132
- /**
133
- * Updates a document in the MongoDB collection.
134
- *
135
- * @param {PatchDTO<T>} input - The partial input to update the document.
136
- * @param {MongoEntityService.UpdateOneOptions<T>} [options] - The update options.
137
- *
138
- * @return {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the updated document or undefined if not found.
139
- */
140
111
  async update(input, options) {
141
112
  const isUpdateFilter = Array.isArray(input) || !!Object.keys(input).find(x => x.startsWith('$'));
142
113
  const command = {
@@ -30,15 +30,6 @@ export class MongoCollectionService extends MongoEntityService {
30
30
  if (!(await this.exists(id, options)))
31
31
  throw new ResourceNotAvailableError(this.getResourceName(), id);
32
32
  }
33
- /**
34
- * Creates a new document in the MongoDB collection.
35
- * Interceptors will be called before performing db operation
36
- *
37
- * @param {PartialDTO<T>} input - The input data for creating the document.
38
- * @param {MongoEntityService.CreateOptions} [options] - The options for creating the document.
39
- * @returns {Promise<PartialDTO<T>>} A promise that resolves to the created document.
40
- * @throws {Error} if an unknown error occurs while creating the document.
41
- */
42
33
  async create(input, options) {
43
34
  const command = {
44
35
  crud: 'create',
@@ -160,13 +151,6 @@ export class MongoCollectionService extends MongoEntityService {
160
151
  async existsOne(options) {
161
152
  return !!(await this.findOne({ ...options, projection: ['_id'] }));
162
153
  }
163
- /**
164
- * Finds a document by its ID.
165
- *
166
- * @param {MongoAdapter.AnyId} id - The ID of the document.
167
- * @param {MongoEntityService.FindOneOptions<T>} [options] - The options for the find query.
168
- * @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
169
- */
170
154
  async findById(id, options) {
171
155
  const command = {
172
156
  crud: 'read',
@@ -182,12 +166,6 @@ export class MongoCollectionService extends MongoEntityService {
182
166
  return this._findById(command);
183
167
  });
184
168
  }
185
- /**
186
- * Finds a document in the collection that matches the specified options.
187
- *
188
- * @param {MongoEntityService.FindOneOptions<T>} [options] - The options for the query.
189
- * @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
190
- */
191
169
  async findOne(options) {
192
170
  const command = {
193
171
  crud: 'read',
@@ -201,12 +179,6 @@ export class MongoCollectionService extends MongoEntityService {
201
179
  return this._findOne(command);
202
180
  });
203
181
  }
204
- /**
205
- * Finds multiple documents in the MongoDB collection.
206
- *
207
- * @param {MongoEntityService.FindManyOptions<T>} options - The options for the find operation.
208
- * @return A Promise that resolves to an array of partial outputs of type T.
209
- */
210
182
  async findMany(options) {
211
183
  const command = {
212
184
  crud: 'read',
@@ -221,13 +193,6 @@ export class MongoCollectionService extends MongoEntityService {
221
193
  return this._findMany(command);
222
194
  });
223
195
  }
224
- /**
225
- * Finds multiple documents in the collection and returns both records (max limit)
226
- * and total count that matched the given criteria
227
- *
228
- * @param {MongoEntityService.FindManyOptions<T>} [options] - The options for the find operation.
229
- * @return A Promise that resolves to an array of partial outputs of type T.
230
- */
231
196
  async findManyWithCount(options) {
232
197
  const command = {
233
198
  crud: 'read',
@@ -241,30 +206,12 @@ export class MongoCollectionService extends MongoEntityService {
241
206
  return this._findManyWithCount(command);
242
207
  });
243
208
  }
244
- /**
245
- * Retrieves a document from the collection by its ID. Throws error if not found.
246
- *
247
- * @param {MongoAdapter.AnyId} id - The ID of the document to retrieve.
248
- * @param {MongoEntityService.FindOneOptions<T>} [options] - Optional options for the findOne operation.
249
- * @returns {Promise<PartialDTO<T>>} - A promise that resolves to the retrieved document,
250
- * or rejects with a ResourceNotFoundError if the document does not exist.
251
- * @throws {ResourceNotAvailableError} - If the document with the specified ID does not exist.
252
- */
253
209
  async get(id, options) {
254
210
  const out = await this.findById(id, options);
255
211
  if (!out)
256
212
  throw new ResourceNotAvailableError(this.getResourceName(), id);
257
213
  return out;
258
214
  }
259
- /**
260
- * Updates a document with the given id in the collection.
261
- *
262
- * @param {MongoAdapter.AnyId} id - The id of the document to update.
263
- * @param {PatchDTO<T>|UpdateFilter<T>} input - The partial input object containing the fields to update.
264
- * @param {MongoEntityService.UpdateOneOptions<T>} [options] - The options for the update operation.
265
- * @returns {Promise<PartialDTO<T> | undefined>} A promise that resolves to the updated document or
266
- * undefined if the document was not found.
267
- */
268
215
  async update(id, input, options) {
269
216
  const isUpdateFilter = Array.isArray(input) || !!Object.keys(input).find(x => x.startsWith('$'));
270
217
  const command = {
@@ -51,15 +51,6 @@ export class MongoNestedService extends MongoService {
51
51
  throw new ResourceNotAvailableError(this.getResourceName() + '.' + this.nestedKey, documentId + '/' + id);
52
52
  }
53
53
  }
54
- /**
55
- * Adds a single item into the array field.
56
- *
57
- * @param {MongoAdapter.AnyId} documentId - The ID of the parent document.
58
- * @param {T} input - The item to be added to the array field.
59
- * @param {MongoNestedService.CreateOptions} [options] - Optional options for the create operation.
60
- * @return {Promise<PartialDTO<T>>} - A promise that resolves with the partial output of the created item.
61
- * @throws {ResourceNotAvailableError} - If the parent document is not found.
62
- */
63
54
  async create(documentId, input, options) {
64
55
  const command = {
65
56
  crud: 'create',
@@ -276,14 +267,6 @@ export class MongoNestedService extends MongoService {
276
267
  return !!(await this._findOne(findCommand));
277
268
  });
278
269
  }
279
- /**
280
- * Finds an element in array field by its parent ID and ID.
281
- *
282
- * @param {MongoAdapter.AnyId} documentId - The ID of the document.
283
- * @param {MongoAdapter.AnyId} nestedId - The ID of the document.
284
- * @param {MongoNestedService.FindOneOptions<T>} [options] - The optional options for the operation.
285
- * @returns {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the found document or undefined if not found.
286
- */
287
270
  async findById(documentId, nestedId, options) {
288
271
  const command = {
289
272
  crud: 'read',
@@ -321,13 +304,6 @@ export class MongoNestedService extends MongoService {
321
304
  const rows = await this._findMany(findManyCommand);
322
305
  return rows?.[0];
323
306
  }
324
- /**
325
- * Finds the first array element that matches the given parentId.
326
- *
327
- * @param {MongoAdapter.AnyId} documentId - The ID of the document.
328
- * @param {MongoNestedService.FindOneOptions<T>} [options] - Optional options to customize the query.
329
- * @returns {Promise<PartialDTO<T> | undefined>} A promise that resolves to the first matching document, or `undefined` if no match is found.
330
- */
331
307
  async findOne(documentId, options) {
332
308
  const command = {
333
309
  crud: 'read',
@@ -356,13 +332,6 @@ export class MongoNestedService extends MongoService {
356
332
  const rows = await this._findMany(findManyCommand);
357
333
  return rows?.[0];
358
334
  }
359
- /**
360
- * Finds multiple elements in an array field.
361
- *
362
- * @param {MongoAdapter.AnyId} documentId - The ID of the parent document.
363
- * @param {MongoNestedService.FindManyOptions<T>} [options] - The options for finding the documents.
364
- * @returns {Promise<PartialDTO<T>[]>} - The found documents.
365
- */
366
335
  async findMany(documentId, options) {
367
336
  const command = {
368
337
  crud: 'read',
@@ -426,13 +395,6 @@ export class MongoNestedService extends MongoService {
426
395
  await cursor.close();
427
396
  }
428
397
  }
429
- /**
430
- * Finds multiple elements in an array field.
431
- *
432
- * @param {MongoAdapter.AnyId} documentId - The ID of the parent document.
433
- * @param {MongoNestedService.FindManyOptions<T>} [options] - The options for finding the documents.
434
- * @returns {Promise<PartialDTO<T>[]>} - The found documents.
435
- */
436
398
  async findManyWithCount(documentId, options) {
437
399
  const command = {
438
400
  crud: 'read',
@@ -508,15 +470,6 @@ export class MongoNestedService extends MongoService {
508
470
  await cursor.close();
509
471
  }
510
472
  }
511
- /**
512
- * Retrieves a specific item from the array of a document.
513
- *
514
- * @param {MongoAdapter.AnyId} documentId - The ID of the document.
515
- * @param {MongoAdapter.AnyId} nestedId - The ID of the item.
516
- * @param {MongoNestedService.FindOneOptions<T>} [options] - The options for finding the item.
517
- * @returns {Promise<PartialDTO<T>>} - The item found.
518
- * @throws {ResourceNotAvailableError} - If the item is not found.
519
- */
520
473
  async get(documentId, nestedId, options) {
521
474
  const out = await this.findById(documentId, nestedId, options);
522
475
  if (!out) {
@@ -524,16 +477,6 @@ export class MongoNestedService extends MongoService {
524
477
  }
525
478
  return out;
526
479
  }
527
- /**
528
- * Updates an array element with new data and returns the updated element
529
- *
530
- * @param {AnyId} documentId - The ID of the document to update.
531
- * @param {AnyId} nestedId - The ID of the item to update within the document.
532
- * @param {PatchDTO<T>} input - The new data to update the item with.
533
- * @param {MongoNestedService.UpdateOneOptions<T>} [options] - Additional update options.
534
- * @returns {Promise<PartialDTO<T> | undefined>} The updated item or undefined if it does not exist.
535
- * @throws {Error} If an error occurs while updating the item.
536
- */
537
480
  async update(documentId, nestedId, input, options) {
538
481
  const command = {
539
482
  crud: 'update',
@@ -31,14 +31,6 @@ export class MongoSingletonService extends MongoEntityService {
31
31
  if (!(await this.exists(options)))
32
32
  throw new ResourceNotAvailableError(this.getResourceName());
33
33
  }
34
- /**
35
- * Creates the document in the database.
36
- *
37
- * @param {PartialDTO<T>} input - The partial input to create the document with.
38
- * @param {MongoEntityService.CreateOptions} [options] - The options for creating the document.
39
- * @return {Promise<PartialDTO<T>>} A promise that resolves to the partial output of the created document.
40
- * @throws {Error} Throws an error if an unknown error occurs while creating the document.
41
- */
42
34
  async create(input, options) {
43
35
  const command = {
44
36
  crud: 'create',
@@ -92,12 +84,6 @@ export class MongoSingletonService extends MongoEntityService {
92
84
  return !!(await this._findById(findCommand));
93
85
  });
94
86
  }
95
- /**
96
- * Fetches the document if it exists. Returns undefined if not found.
97
- *
98
- * @param {MongoEntityService.FindOneOptions<T>} [options] - The options for finding the document.
99
- * @returns {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the found document or undefined if not found.
100
- */
101
87
  async find(options) {
102
88
  const command = {
103
89
  crud: 'read',
@@ -113,27 +99,12 @@ export class MongoSingletonService extends MongoEntityService {
113
99
  return this._findById(command);
114
100
  });
115
101
  }
116
- /**
117
- * Fetches the document from the Mongo collection service. Throws error if not found.
118
- *
119
- * @param {MongoEntityService.FindOneOptions<T>} options - The options to customize the query.
120
- * @return {Promise<PartialDTO<T>>} - A promise that resolves to the fetched document.
121
- * @throws {ResourceNotAvailableError} - If the document is not found in the collection.
122
- */
123
102
  async get(options) {
124
103
  const out = await this.find(options);
125
104
  if (!out)
126
105
  throw new ResourceNotAvailableError(this.getResourceName());
127
106
  return out;
128
107
  }
129
- /**
130
- * Updates a document in the MongoDB collection.
131
- *
132
- * @param {PatchDTO<T>} input - The partial input to update the document.
133
- * @param {MongoEntityService.UpdateOneOptions<T>} [options] - The update options.
134
- *
135
- * @return {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the updated document or undefined if not found.
136
- */
137
108
  async update(input, options) {
138
109
  const isUpdateFilter = Array.isArray(input) || !!Object.keys(input).find(x => x.startsWith('$'));
139
110
  const command = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/mongodb",
3
- "version": "1.0.0-alpha.30",
3
+ "version": "1.0.0-alpha.32",
4
4
  "description": "Opra MongoDB adapter package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -38,8 +38,8 @@
38
38
  "ts-gems": "^3.4.0"
39
39
  },
40
40
  "peerDependencies": {
41
- "@opra/common": "^1.0.0-alpha.30",
42
- "@opra/core": "^1.0.0-alpha.30",
41
+ "@opra/common": "^1.0.0-alpha.32",
42
+ "@opra/core": "^1.0.0-alpha.32",
43
43
  "mongodb": ">= 6.0.0"
44
44
  },
45
45
  "type": "module",
@@ -1,5 +1,5 @@
1
1
  import mongodb, { UpdateFilter } from 'mongodb';
2
- import { PartialDTO, PatchDTO, Type } from 'ts-gems';
2
+ import { PartialDTO, PatchDTO, RequiredSome, Type } from 'ts-gems';
3
3
  import { MongoAdapter } from './mongo-adapter.js';
4
4
  import { MongoEntityService } from './mongo-entity-service.js';
5
5
  /**
@@ -55,7 +55,8 @@ export declare class MongoCollectionService<T extends mongodb.Document> extends
55
55
  * @returns {Promise<PartialDTO<T>>} A promise that resolves to the created document.
56
56
  * @throws {Error} if an unknown error occurs while creating the document.
57
57
  */
58
- create(input: PartialDTO<T>, options?: MongoEntityService.CreateOptions): Promise<PartialDTO<T>>;
58
+ create(input: PartialDTO<T>, options: RequiredSome<MongoEntityService.CreateOptions, 'projection'>): Promise<PartialDTO<T>>;
59
+ create(input: PartialDTO<T>, options?: MongoEntityService.CreateOptions): Promise<T>;
59
60
  /**
60
61
  * Returns the count of documents in the collection based on the provided options.
61
62
  *
@@ -107,21 +108,24 @@ export declare class MongoCollectionService<T extends mongodb.Document> extends
107
108
  * @param {MongoEntityService.FindOneOptions<T>} [options] - The options for the find query.
108
109
  * @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
109
110
  */
110
- findById(id: MongoAdapter.AnyId, options?: MongoEntityService.FindOneOptions<T>): Promise<PartialDTO<T> | undefined>;
111
+ findById(id: MongoAdapter.AnyId, options: RequiredSome<MongoEntityService.FindOneOptions<T>, 'projection'>): Promise<PartialDTO<T> | undefined>;
112
+ findById(id: MongoAdapter.AnyId, options?: MongoEntityService.FindOneOptions<T>): Promise<T | undefined>;
111
113
  /**
112
114
  * Finds a document in the collection that matches the specified options.
113
115
  *
114
116
  * @param {MongoEntityService.FindOneOptions<T>} [options] - The options for the query.
115
117
  * @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
116
118
  */
117
- findOne(options?: MongoEntityService.FindOneOptions<T>): Promise<PartialDTO<T> | undefined>;
119
+ findOne(options: RequiredSome<MongoEntityService.FindOneOptions<T>, 'projection'>): Promise<PartialDTO<T> | undefined>;
120
+ findOne(options?: MongoEntityService.FindOneOptions<T>): Promise<T | undefined>;
118
121
  /**
119
122
  * Finds multiple documents in the MongoDB collection.
120
123
  *
121
124
  * @param {MongoEntityService.FindManyOptions<T>} options - The options for the find operation.
122
125
  * @return A Promise that resolves to an array of partial outputs of type T.
123
126
  */
124
- findMany(options?: MongoEntityService.FindManyOptions<T>): Promise<PartialDTO<T>[]>;
127
+ findMany(options: RequiredSome<MongoEntityService.FindManyOptions<T>, 'projection'>): Promise<PartialDTO<T>[]>;
128
+ findMany(options?: MongoEntityService.FindManyOptions<T>): Promise<T[]>;
125
129
  /**
126
130
  * Finds multiple documents in the collection and returns both records (max limit)
127
131
  * and total count that matched the given criteria
@@ -129,10 +133,14 @@ export declare class MongoCollectionService<T extends mongodb.Document> extends
129
133
  * @param {MongoEntityService.FindManyOptions<T>} [options] - The options for the find operation.
130
134
  * @return A Promise that resolves to an array of partial outputs of type T.
131
135
  */
132
- findManyWithCount(options?: MongoEntityService.FindManyOptions<T>): Promise<{
136
+ findManyWithCount(options: RequiredSome<MongoEntityService.FindManyOptions<T>, 'projection'>): Promise<{
133
137
  count: number;
134
138
  items: PartialDTO<T>[];
135
139
  }>;
140
+ findManyWithCount(options?: MongoEntityService.FindManyOptions<T>): Promise<{
141
+ count: number;
142
+ items: T[];
143
+ }>;
136
144
  /**
137
145
  * Retrieves a document from the collection by its ID. Throws error if not found.
138
146
  *
@@ -142,7 +150,8 @@ export declare class MongoCollectionService<T extends mongodb.Document> extends
142
150
  * or rejects with a ResourceNotFoundError if the document does not exist.
143
151
  * @throws {ResourceNotAvailableError} - If the document with the specified ID does not exist.
144
152
  */
145
- get(id: MongoAdapter.AnyId, options?: MongoEntityService.FindOneOptions<T>): Promise<PartialDTO<T>>;
153
+ get(id: MongoAdapter.AnyId, options: RequiredSome<MongoEntityService.FindOneOptions<T>, 'projection'>): Promise<PartialDTO<T>>;
154
+ get(id: MongoAdapter.AnyId, options?: MongoEntityService.FindOneOptions<T>): Promise<T>;
146
155
  /**
147
156
  * Updates a document with the given id in the collection.
148
157
  *
@@ -152,7 +161,8 @@ export declare class MongoCollectionService<T extends mongodb.Document> extends
152
161
  * @returns {Promise<PartialDTO<T> | undefined>} A promise that resolves to the updated document or
153
162
  * undefined if the document was not found.
154
163
  */
155
- update(id: MongoAdapter.AnyId, input: PatchDTO<T> | UpdateFilter<T>, options?: MongoEntityService.UpdateOneOptions<T>): Promise<PartialDTO<T> | undefined>;
164
+ update(id: MongoAdapter.AnyId, input: PatchDTO<T> | UpdateFilter<T>, options: RequiredSome<MongoEntityService.UpdateOneOptions<T>, 'projection'>): Promise<PartialDTO<T> | undefined>;
165
+ update(id: MongoAdapter.AnyId, input: PatchDTO<T> | UpdateFilter<T>, options?: MongoEntityService.UpdateOneOptions<T>): Promise<T | undefined>;
156
166
  /**
157
167
  * Updates a document in the collection with the specified ID.
158
168
  *
@@ -149,7 +149,8 @@ export declare class MongoNestedService<T extends mongodb.Document> extends Mong
149
149
  * @return {Promise<PartialDTO<T>>} - A promise that resolves with the partial output of the created item.
150
150
  * @throws {ResourceNotAvailableError} - If the parent document is not found.
151
151
  */
152
- create(documentId: MongoAdapter.AnyId, input: PartialDTO<T>, options?: MongoNestedService.CreateOptions): Promise<PartialDTO<T>>;
152
+ create(documentId: MongoAdapter.AnyId, input: PartialDTO<T>, options: RequiredSome<MongoNestedService.CreateOptions, 'projection'>): Promise<PartialDTO<T>>;
153
+ create(documentId: MongoAdapter.AnyId, input: PartialDTO<T>, options?: MongoNestedService.CreateOptions): Promise<T>;
153
154
  protected _create(command: MongoNestedService.CreateCommand): Promise<PartialDTO<T>>;
154
155
  /**
155
156
  * Counts the number of documents in the collection that match the specified parentId and options.
@@ -204,7 +205,8 @@ export declare class MongoNestedService<T extends mongodb.Document> extends Mong
204
205
  * @param {MongoNestedService.FindOneOptions<T>} [options] - The optional options for the operation.
205
206
  * @returns {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the found document or undefined if not found.
206
207
  */
207
- findById(documentId: MongoAdapter.AnyId, nestedId: MongoAdapter.AnyId, options?: MongoNestedService.FindOneOptions<T>): Promise<PartialDTO<T> | undefined>;
208
+ findById(documentId: MongoAdapter.AnyId, nestedId: MongoAdapter.AnyId, options: RequiredSome<MongoNestedService.FindOneOptions<T>, 'projection'>): Promise<PartialDTO<T> | undefined>;
209
+ findById(documentId: MongoAdapter.AnyId, nestedId: MongoAdapter.AnyId, options?: MongoNestedService.FindOneOptions<T>): Promise<T | undefined>;
208
210
  protected _findById(command: MongoNestedService.FindOneCommand<T>): Promise<PartialDTO<T> | undefined>;
209
211
  /**
210
212
  * Finds the first array element that matches the given parentId.
@@ -213,7 +215,8 @@ export declare class MongoNestedService<T extends mongodb.Document> extends Mong
213
215
  * @param {MongoNestedService.FindOneOptions<T>} [options] - Optional options to customize the query.
214
216
  * @returns {Promise<PartialDTO<T> | undefined>} A promise that resolves to the first matching document, or `undefined` if no match is found.
215
217
  */
216
- findOne(documentId: MongoAdapter.AnyId, options?: MongoNestedService.FindOneOptions<T>): Promise<PartialDTO<T> | undefined>;
218
+ findOne(documentId: MongoAdapter.AnyId, options: RequiredSome<MongoNestedService.FindOneOptions<T>, 'projection'>): Promise<PartialDTO<T> | undefined>;
219
+ findOne(documentId: MongoAdapter.AnyId, options?: MongoNestedService.FindOneOptions<T>): Promise<T | undefined>;
217
220
  protected _findOne(command: MongoNestedService.FindOneCommand<T>): Promise<PartialDTO<T> | undefined>;
218
221
  /**
219
222
  * Finds multiple elements in an array field.
@@ -222,7 +225,8 @@ export declare class MongoNestedService<T extends mongodb.Document> extends Mong
222
225
  * @param {MongoNestedService.FindManyOptions<T>} [options] - The options for finding the documents.
223
226
  * @returns {Promise<PartialDTO<T>[]>} - The found documents.
224
227
  */
225
- findMany(documentId: MongoAdapter.AnyId, options?: MongoNestedService.FindManyOptions<T>): Promise<PartialDTO<T>[]>;
228
+ findMany(documentId: MongoAdapter.AnyId, options: RequiredSome<MongoNestedService.FindManyOptions<T>, 'projection'>): Promise<PartialDTO<T>[]>;
229
+ findMany(documentId: MongoAdapter.AnyId, options?: MongoNestedService.FindManyOptions<T>): Promise<T[]>;
226
230
  protected _findMany(command: MongoNestedService.FindManyCommand<T>): Promise<PartialDTO<T>[]>;
227
231
  /**
228
232
  * Finds multiple elements in an array field.
@@ -231,10 +235,14 @@ export declare class MongoNestedService<T extends mongodb.Document> extends Mong
231
235
  * @param {MongoNestedService.FindManyOptions<T>} [options] - The options for finding the documents.
232
236
  * @returns {Promise<PartialDTO<T>[]>} - The found documents.
233
237
  */
234
- findManyWithCount(documentId: MongoAdapter.AnyId, options?: MongoNestedService.FindManyOptions<T>): Promise<{
238
+ findManyWithCount(documentId: MongoAdapter.AnyId, options: RequiredSome<MongoNestedService.FindManyOptions<T>, 'projection'>): Promise<{
235
239
  count: number;
236
240
  items: PartialDTO<T>[];
237
241
  }>;
242
+ findManyWithCount(documentId: MongoAdapter.AnyId, options?: MongoNestedService.FindManyOptions<T>): Promise<{
243
+ count: number;
244
+ items: T[];
245
+ }>;
238
246
  protected _findManyWithCount(command: MongoNestedService.FindManyCommand<T>): Promise<{
239
247
  count: number;
240
248
  items: PartialDTO<T>[];
@@ -248,7 +256,8 @@ export declare class MongoNestedService<T extends mongodb.Document> extends Mong
248
256
  * @returns {Promise<PartialDTO<T>>} - The item found.
249
257
  * @throws {ResourceNotAvailableError} - If the item is not found.
250
258
  */
251
- get(documentId: MongoAdapter.AnyId, nestedId: MongoAdapter.AnyId, options?: MongoNestedService.FindOneOptions<T>): Promise<PartialDTO<T>>;
259
+ get(documentId: MongoAdapter.AnyId, nestedId: MongoAdapter.AnyId, options: RequiredSome<MongoNestedService.FindOneOptions<T>, 'projection'>): Promise<PartialDTO<T>>;
260
+ get(documentId: MongoAdapter.AnyId, nestedId: MongoAdapter.AnyId, options?: MongoNestedService.FindOneOptions<T>): Promise<T>;
252
261
  /**
253
262
  * Updates an array element with new data and returns the updated element
254
263
  *
@@ -259,7 +268,8 @@ export declare class MongoNestedService<T extends mongodb.Document> extends Mong
259
268
  * @returns {Promise<PartialDTO<T> | undefined>} The updated item or undefined if it does not exist.
260
269
  * @throws {Error} If an error occurs while updating the item.
261
270
  */
262
- update(documentId: MongoAdapter.AnyId, nestedId: MongoAdapter.AnyId, input: PatchDTO<T>, options?: MongoNestedService.UpdateOneOptions<T>): Promise<PartialDTO<T> | undefined>;
271
+ update(documentId: MongoAdapter.AnyId, nestedId: MongoAdapter.AnyId, input: PatchDTO<T>, options: RequiredSome<MongoNestedService.UpdateOneOptions<T>, 'projection'>): Promise<PartialDTO<T> | undefined>;
272
+ update(documentId: MongoAdapter.AnyId, nestedId: MongoAdapter.AnyId, input: PatchDTO<T>, options?: MongoNestedService.UpdateOneOptions<T>): Promise<T | undefined>;
263
273
  /**
264
274
  * Update an array element with new data. Returns 1 if document updated 0 otherwise.
265
275
  *
@@ -1,5 +1,5 @@
1
1
  import mongodb, { UpdateFilter } from 'mongodb';
2
- import { PartialDTO, PatchDTO, Type } from 'ts-gems';
2
+ import { PartialDTO, PatchDTO, RequiredSome, Type } from 'ts-gems';
3
3
  import { MongoAdapter } from './mongo-adapter.js';
4
4
  import { MongoEntityService } from './mongo-entity-service.js';
5
5
  /**
@@ -53,7 +53,8 @@ export declare class MongoSingletonService<T extends mongodb.Document> extends M
53
53
  * @return {Promise<PartialDTO<T>>} A promise that resolves to the partial output of the created document.
54
54
  * @throws {Error} Throws an error if an unknown error occurs while creating the document.
55
55
  */
56
- create(input: PartialDTO<T>, options?: MongoEntityService.CreateOptions): Promise<PartialDTO<T>>;
56
+ create(input: PartialDTO<T>, options: RequiredSome<MongoEntityService.CreateOptions, 'projection'>): Promise<PartialDTO<T>>;
57
+ create(input: PartialDTO<T>, options?: MongoEntityService.CreateOptions): Promise<T>;
57
58
  /**
58
59
  * Deletes a record from the database
59
60
  *
@@ -74,7 +75,8 @@ export declare class MongoSingletonService<T extends mongodb.Document> extends M
74
75
  * @param {MongoEntityService.FindOneOptions<T>} [options] - The options for finding the document.
75
76
  * @returns {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the found document or undefined if not found.
76
77
  */
77
- find(options?: MongoEntityService.FindOneOptions<T>): Promise<PartialDTO<T> | undefined>;
78
+ find(options: RequiredSome<MongoEntityService.FindOneOptions<T>, 'projection'>): Promise<PartialDTO<T> | undefined>;
79
+ find(options?: MongoEntityService.FindOneOptions<T>): Promise<T | undefined>;
78
80
  /**
79
81
  * Fetches the document from the Mongo collection service. Throws error if not found.
80
82
  *
@@ -82,7 +84,8 @@ export declare class MongoSingletonService<T extends mongodb.Document> extends M
82
84
  * @return {Promise<PartialDTO<T>>} - A promise that resolves to the fetched document.
83
85
  * @throws {ResourceNotAvailableError} - If the document is not found in the collection.
84
86
  */
85
- get(options?: MongoEntityService.FindOneOptions<T>): Promise<PartialDTO<T>>;
87
+ get(options: RequiredSome<MongoEntityService.FindOneOptions<T>, 'projection'>): Promise<PartialDTO<T>>;
88
+ get(options?: MongoEntityService.FindOneOptions<T>): Promise<T>;
86
89
  /**
87
90
  * Updates a document in the MongoDB collection.
88
91
  *
@@ -91,7 +94,8 @@ export declare class MongoSingletonService<T extends mongodb.Document> extends M
91
94
  *
92
95
  * @return {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the updated document or undefined if not found.
93
96
  */
94
- update(input: PatchDTO<T> | UpdateFilter<T>, options?: MongoEntityService.UpdateOneOptions<T>): Promise<PartialDTO<T> | undefined>;
97
+ update(input: PatchDTO<T> | UpdateFilter<T>, options: RequiredSome<MongoEntityService.UpdateOneOptions<T>, 'projection'>): Promise<PartialDTO<T> | undefined>;
98
+ update(input: PatchDTO<T> | UpdateFilter<T>, options?: MongoEntityService.UpdateOneOptions<T>): Promise<T | undefined>;
95
99
  /**
96
100
  * Updates a document in the MongoDB collection.
97
101
  *