@opra/mongodb 0.32.2 → 0.32.3

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.
@@ -1,6 +1,5 @@
1
1
  import mongodb from 'mongodb';
2
2
  import { StrictOmit, Type } from 'ts-gems';
3
- import vg from 'valgen';
4
3
  import * as OpraCommon from '@opra/common';
5
4
  import { ComplexType, PartialInput } from '@opra/common';
6
5
  import { PartialOutput } from '@opra/core';
@@ -8,169 +7,240 @@ import { MongoCollectionService } from './mongo-collection-service.js';
8
7
  import { MongoService } from './mongo-service.js';
9
8
  import { AnyId } from './types.js';
10
9
  /**
11
- *
12
- * @class MongoArrayService
10
+ * A class that provides methods to perform operations on an array field in a MongoDB collection.
11
+ * @template T The type of the array item.
13
12
  */
14
13
  export declare class MongoArrayService<T extends mongodb.Document> extends MongoService<T> {
15
- protected _encoders: Record<string, vg.Validator>;
14
+ /**
15
+ * Represents the key for a collection.
16
+ *
17
+ * @type {string}
18
+ */
16
19
  collectionKey: string;
17
- arrayKey: string;
18
- defaultLimit: number;
20
+ /**
21
+ * Represents the name of the array field in parent document
22
+ *
23
+ * @type {string} FieldName
24
+ */
19
25
  fieldName: string;
20
- constructor(dataType: Type | string, fieldName: string, options?: MongoArrayService.Options);
21
- getArrayDataType(): ComplexType;
22
26
  /**
23
- * Checks if array item exists. Throws error if not.
27
+ * Represents the key field of an array.
28
+ *
29
+ * @type {string} arrayKey
30
+ */
31
+ arrayKey: string;
32
+ /**
33
+ * Represents the default limit value for a certain operation.
24
34
  *
25
- * @param parentId
26
- * @param id
35
+ * @type {number}
27
36
  */
28
- assert(parentId: AnyId, id: AnyId): Promise<void>;
37
+ defaultLimit: number;
38
+ constructor(dataType: Type | string, fieldName: string, options?: MongoArrayService.Options);
29
39
  /**
30
- * Adds a single item into array field.
40
+ * Retrieves the data type of the array field
31
41
  *
32
- * @param parentId
33
- * @param input
34
- * @param options
42
+ * @returns {ComplexType} The complex data type of the field.
43
+ * @throws {NotAcceptableError} If the data type is not a ComplexType.
35
44
  */
36
- create(parentId: AnyId, input: T, options?: MongoArrayService.CreateOptions): Promise<PartialOutput<T>>;
45
+ getDataType(): ComplexType;
37
46
  /**
38
- * Gets the number of array items matching the filter.
39
- * @param parentId
40
- * @param options
47
+ * Asserts whether a resource with the specified parentId and id exists.
48
+ * Throws a ResourceNotFoundError if the resource does not exist.
49
+ *
50
+ * @param {AnyId} documentId - The ID of the parent document.
51
+ * @param {AnyId} id - The ID of the resource.
52
+ * @return {Promise<void>} - A promise that resolves with no value upon success.
53
+ * @throws {ResourceNotFoundError} - If the resource does not exist.
41
54
  */
42
- count(parentId: AnyId, options?: MongoArrayService.CountOptions<T>): Promise<number>;
55
+ assert(documentId: AnyId, id: AnyId): Promise<void>;
43
56
  /**
44
- * Removes one item from an array field
57
+ * Adds a single item into the array field.
45
58
  *
46
- * @param parentId
47
- * @param id
48
- * @param options
59
+ * @param {AnyId} documentId - The ID of the parent document.
60
+ * @param {T} input - The item to be added to the array field.
61
+ * @param {MongoArrayService.CreateOptions} [options] - Optional options for the create operation.
62
+ * @return {Promise<PartialOutput<T>>} - A promise that resolves with the partial output of the created item.
63
+ * @throws {ResourceNotFoundError} - If the parent document is not found.
49
64
  */
50
- delete(parentId: AnyId, id: AnyId, options?: MongoArrayService.DeleteOptions<T>): Promise<number>;
65
+ create(documentId: AnyId, input: T, options?: MongoArrayService.CreateOptions): Promise<PartialOutput<T>>;
51
66
  /**
52
- * Removes multiple items from an array field
67
+ * Counts the number of documents in the collection that match the specified parentId and options.
53
68
  *
54
- * @param parentId
55
- * @param options
69
+ * @param {AnyId} documentId - The ID of the parent document.
70
+ * @param {object} options - Optional parameters for counting.
71
+ * @param {object} options.filter - The filter object to apply to the count operation.
72
+ * @returns {Promise<number>} - A promise that resolves to the count of documents.
56
73
  */
57
- deleteMany(parentId: AnyId, options?: MongoArrayService.DeleteManyOptions<T>): Promise<number>;
74
+ count(documentId: AnyId, options?: MongoArrayService.CountOptions<T>): Promise<number>;
58
75
  /**
59
- * Returns true if item exists, false otherwise
76
+ * Deletes an element from an array within a document in the MongoDB collection.
60
77
  *
61
- * @param parentId
62
- * @param id
78
+ * @param {AnyId} documentId - The ID of the parent document.
79
+ * @param {AnyId} id - The ID of the element to delete from the array.
80
+ * @param {MongoArrayService.DeleteOptions<T>} [options] - Additional options for the delete operation.
81
+ * @return {Promise<number>} - A Promise that resolves to the number of elements deleted (1 if successful, 0 if not).
63
82
  */
64
- exists(parentId: AnyId, id: AnyId): Promise<boolean>;
83
+ delete(documentId: AnyId, id: AnyId, options?: MongoArrayService.DeleteOptions<T>): Promise<number>;
65
84
  /**
66
- * Fetches the first item in an array field that matches by id.
85
+ * Deletes multiple items from a collection based on the parent ID and optional filter.
67
86
  *
68
- * @param parentId
69
- * @param id
70
- * @param options
87
+ * @param {AnyId} documentId - The ID of the parent document.
88
+ * @param {MongoArrayService.DeleteManyOptions<T>} options - Optional options to specify a filter.
89
+ * @returns {Promise<number>} - A Promise that resolves to the number of items deleted.
71
90
  */
72
- findById(parentId: AnyId, id: AnyId, options?: MongoArrayService.FindOneOptions): Promise<PartialOutput<T> | undefined>;
91
+ deleteMany(documentId: AnyId, options?: MongoArrayService.DeleteManyOptions<T>): Promise<number>;
73
92
  /**
74
- * Fetches the first item in an array field that matches the filter. Returns undefined if not found.
93
+ * Checks if an array element with the given parentId and id exists.
75
94
  *
76
- * @param parentId
77
- * @param options
95
+ * @param {AnyId} documentId - The ID of the parent document.
96
+ * @param {AnyId} id - The id of the record.
97
+ * @returns {Promise<boolean>} - A promise that resolves to a boolean indicating if the record exists or not.
78
98
  */
79
- findOne(parentId: AnyId, options?: MongoArrayService.FindOneOptions): Promise<PartialOutput<T> | undefined>;
99
+ exists(documentId: AnyId, id: AnyId): Promise<boolean>;
80
100
  /**
81
- * Fetches all items in an array field that matches the filter
101
+ * Finds an element in array field by its parent ID and ID.
82
102
  *
83
- * @param parentId
84
- * @param options
103
+ * @param {AnyId} documentId - The ID of the document.
104
+ * @param {AnyId} id - The ID of the document.
105
+ * @param {MongoArrayService.FindOneOptions} [options] - The optional options for the operation.
106
+ * @returns {Promise<PartialOutput<T> | undefined>} - A promise that resolves to the found document or undefined if not found.
85
107
  */
86
- findMany(parentId: AnyId, options?: MongoArrayService.FindManyOptions<T>): Promise<PartialOutput<T>[] | undefined>;
108
+ findById(documentId: AnyId, id: AnyId, options?: MongoArrayService.FindOneOptions): Promise<PartialOutput<T> | undefined>;
87
109
  /**
88
- * Fetches the first item in an array field that matches the item id. Throws error undefined if not found.
110
+ * Finds the first array element that matches the given parentId.
89
111
  *
90
- * @param parentId
91
- * @param id
92
- * @param options
112
+ * @param {AnyId} documentId - The ID of the document.
113
+ * @param {MongoArrayService.FindOneOptions} [options] - Optional options to customize the query.
114
+ * @returns {Promise<PartialOutput<T> | undefined>} A promise that resolves to the first matching document, or `undefined` if no match is found.
93
115
  */
94
- get(parentId: AnyId, id: AnyId, options?: MongoArrayService.FindOneOptions<T>): Promise<PartialOutput<T>>;
116
+ findOne(documentId: AnyId, options?: MongoArrayService.FindOneOptions): Promise<PartialOutput<T> | undefined>;
95
117
  /**
96
- * Update a single item in array field
118
+ * Finds multiple elements in an array field.
97
119
  *
98
- * @param parentId
99
- * @param id
100
- * @param input
101
- * @param options
120
+ * @param {AnyId} documentId - The ID of the parent document.
121
+ * @param {MongoArrayService.FindManyOptions<T>} [options] - The options for finding the documents.
122
+ * @returns {Promise<PartialOutput<T>[] | undefined>} - The found documents.
102
123
  */
103
- update(parentId: AnyId, id: AnyId, input: PartialInput<T>, options?: MongoArrayService.UpdateOptions<T>): Promise<PartialOutput<T> | undefined>;
124
+ findMany(documentId: AnyId, options?: MongoArrayService.FindManyOptions<T>): Promise<PartialOutput<T>[] | undefined>;
104
125
  /**
105
- * Update a single item in array field
106
- * Returns how many master documents updated (not array items)
126
+ * Retrieves a specific item from the array of a document.
107
127
  *
108
- * @param parentId
109
- * @param id
110
- * @param doc
111
- * @param options
128
+ * @param {AnyId} documentId - The ID of the document.
129
+ * @param {AnyId} id - The ID of the item.
130
+ * @param {MongoArrayService.FindOneOptions<T>} [options] - The options for finding the item.
131
+ * @returns {Promise<PartialOutput<T>>} - The item found.
132
+ * @throws {ResourceNotFoundError} - If the item is not found.
112
133
  */
113
- updateOnly(parentId: AnyId, id: AnyId, doc: PartialInput<T>, options?: MongoArrayService.UpdateOptions<T>): Promise<number>;
134
+ get(documentId: AnyId, id: AnyId, options?: MongoArrayService.FindOneOptions<T>): Promise<PartialOutput<T>>;
114
135
  /**
115
- * Update multiple items in array field, returns how many master documents updated (not array items)
136
+ * Updates an array element with new data and returns the updated element
116
137
  *
117
- * @param parentId
118
- * @param input
119
- * @param options
138
+ * @param {AnyId} documentId - The ID of the document to update.
139
+ * @param {AnyId} id - The ID of the item to update within the document.
140
+ * @param {PartialInput<T>} input - The new data to update the item with.
141
+ * @param {MongoArrayService.UpdateOptions<T>} [options] - Additional update options.
142
+ * @returns {Promise<PartialOutput<T> | undefined>} The updated item or undefined if it does not exist.
143
+ * @throws {Error} If an error occurs while updating the item.
120
144
  */
121
- updateMany(parentId: AnyId, input: PartialInput<T>, options?: MongoArrayService.UpdateManyOptions<T>): Promise<number>;
145
+ update(documentId: AnyId, id: AnyId, input: PartialInput<T>, options?: MongoArrayService.UpdateOptions<T>): Promise<PartialOutput<T> | undefined>;
122
146
  /**
123
- * Update multiple items in array field and returns number of updated array items
147
+ * Update an array element with new data. Returns 1 if document updated 0 otherwise.
124
148
  *
125
- * @param parentId
126
- * @param doc
127
- * @param options
149
+ * @param {AnyId} documentId - The ID of the parent document.
150
+ * @param {AnyId} id - The ID of the document to update.
151
+ * @param {PartialInput<T>} doc - The partial input object containing the fields to update.
152
+ * @param {MongoArrayService.UpdateOptions<T>} [options] - Optional update options.
153
+ * @returns {Promise<number>} - A promise that resolves to the number of elements updated.
128
154
  */
129
- updateManyReturnCount(parentId: AnyId, doc: PartialInput<T>, options?: MongoArrayService.UpdateManyOptions<T>): Promise<number>;
155
+ updateOnly(documentId: AnyId, id: AnyId, doc: PartialInput<T>, options?: MongoArrayService.UpdateOptions<T>): Promise<number>;
130
156
  /**
131
- * Generates Id value
157
+ * Updates multiple array elements in document
132
158
  *
133
- * @protected
159
+ * @param {AnyId} documentId - The ID of the document to update.
160
+ * @param {PartialInput<T>} input - The updated data for the document(s).
161
+ * @param {MongoArrayService.UpdateManyOptions<T>} [options] - Additional options for the update operation.
162
+ * @returns {Promise<number>} - A promise that resolves to the number of documents updated.
134
163
  */
135
- protected _generateId(): AnyId;
164
+ updateMany(documentId: AnyId, input: PartialInput<T>, options?: MongoArrayService.UpdateManyOptions<T>): Promise<number>;
136
165
  /**
137
- * Generates a new Validator for encoding or returns from cache if already generated before
138
- * @param operation
139
- * @protected
166
+ * Updates multiple elements and returns the count of elements that were updated.
167
+ *
168
+ * @param {AnyId} documentId - The ID of the document to update.
169
+ * @param {PartialInput<T>} doc - The partial document to update with.
170
+ * @param {MongoArrayService.UpdateManyOptions<T>} [options] - The options for updating multiple documents.
171
+ * @return {Promise<number>} A promise that resolves to the number of elements updated.
140
172
  */
141
- protected _getEncoder(operation: 'create' | 'update'): vg.Validator;
173
+ updateManyReturnCount(documentId: AnyId, doc: PartialInput<T>, options?: MongoArrayService.UpdateManyOptions<T>): Promise<number>;
142
174
  /**
143
- * Generates a new Valgen Validator for encode operation
175
+ * Generates a new id for new inserting Document.
144
176
  *
145
- * @param operation
146
177
  * @protected
178
+ * @returns {AnyId} A new instance of AnyId.
147
179
  */
148
- protected _generateEncoder(operation: 'create' | 'update'): vg.Validator;
180
+ protected _generateId(): AnyId;
149
181
  }
150
182
  /**
151
183
  *
152
184
  * @namespace MongoArrayService
153
185
  */
154
186
  export declare namespace MongoArrayService {
187
+ /**
188
+ * The constructor options of MongoArrayService.
189
+ */
155
190
  interface Options extends MongoCollectionService.Options {
156
191
  arrayKey?: string;
157
192
  }
193
+ /**
194
+ * Represents options for creating objects.
195
+ *
196
+ * @interface
197
+ */
158
198
  interface CreateOptions extends mongodb.UpdateOptions {
159
199
  pick?: string[];
160
200
  omit?: string[];
161
201
  include?: string[];
162
202
  }
203
+ /**
204
+ * Represents options for counting a new object.
205
+ *
206
+ * @interface
207
+ * @template T - The type of the document.
208
+ */
163
209
  interface CountOptions<T> extends mongodb.AggregateOptions {
164
210
  filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
165
211
  }
212
+ /**
213
+ * Represents options for deleting single object.
214
+ *
215
+ * @interface
216
+ * @template T - The type of the document.
217
+ */
166
218
  interface DeleteOptions<T> extends mongodb.UpdateOptions {
167
219
  filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
168
220
  }
221
+ /**
222
+ * Represents options for deleting multiple objects.
223
+ *
224
+ * @interface
225
+ * @template T - The type of the document.
226
+ */
169
227
  interface DeleteManyOptions<T> extends mongodb.UpdateOptions {
170
228
  filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
171
229
  }
230
+ /**
231
+ * Represents options for finding single object.
232
+ *
233
+ * @interface
234
+ * @template T - The type of the document.
235
+ */
172
236
  interface FindOneOptions<T = any> extends StrictOmit<FindManyOptions<T>, 'count' | 'limit'> {
173
237
  }
238
+ /**
239
+ * Represents options for finding multiple objects.
240
+ *
241
+ * @interface
242
+ * @template T - The type of the document.
243
+ */
174
244
  interface FindManyOptions<T> extends mongodb.AggregateOptions {
175
245
  filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
176
246
  pick?: string[];
@@ -181,12 +251,24 @@ export declare namespace MongoArrayService {
181
251
  limit?: number;
182
252
  skip?: number;
183
253
  }
254
+ /**
255
+ * Represents options for updating single object.
256
+ *
257
+ * @interface
258
+ * @template T - The type of the document.
259
+ */
184
260
  interface UpdateOptions<T> extends mongodb.UpdateOptions {
185
261
  pick?: string[];
186
262
  omit?: string[];
187
263
  include?: string[];
188
264
  filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
189
265
  }
266
+ /**
267
+ * Represents options for updating multiple objects.
268
+ *
269
+ * @interface
270
+ * @template T - The type of the document.
271
+ */
190
272
  interface UpdateManyOptions<T> extends mongodb.UpdateOptions {
191
273
  filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
192
274
  }
@@ -1,155 +1,216 @@
1
1
  import mongodb from 'mongodb';
2
2
  import { StrictOmit, Type } from 'ts-gems';
3
- import vg from 'valgen';
4
3
  import * as OpraCommon from '@opra/common';
5
4
  import { PartialInput, PartialOutput } from '@opra/core';
6
5
  import { MongoService } from './mongo-service.js';
7
6
  import { AnyId } from './types.js';
8
7
  /**
9
- *
10
8
  * @class MongoCollectionService
9
+ * @template T - The type of the documents in the collection.
11
10
  */
12
11
  export declare class MongoCollectionService<T extends mongodb.Document> extends MongoService<T> {
13
- protected _encoders: Record<string, vg.Validator>;
12
+ /**
13
+ * Represents the key for a collection.
14
+ *
15
+ * @type {string}
16
+ */
14
17
  collectionKey: string;
18
+ /**
19
+ * Represents the default limit value for a certain operation.
20
+ *
21
+ * @type {number}
22
+ */
15
23
  defaultLimit: number;
16
24
  constructor(dataType: Type | string, options?: MongoCollectionService.Options);
17
25
  /**
18
- * Checks if document exists. Throws error if not.
26
+ * Asserts the existence of a resource with the given ID.
27
+ * Throws a ResourceNotFoundError if the resource does not exist.
19
28
  *
20
- * @param id
29
+ * @param {AnyId} id - The ID of the resource to assert.
30
+ * @returns {Promise<void>} - A Promise that resolves when the resource exists.
31
+ * @throws {ResourceNotFoundError} - If the resource does not exist.
21
32
  */
22
33
  assert(id: AnyId): Promise<void>;
23
34
  /**
24
- * Inserts a single document into MongoDB
35
+ * Creates a new document in the MongoDB collection.
25
36
  *
26
- * @param input
27
- * @param options
37
+ * @param {PartialInput<T>} input - The input data for creating the document.
38
+ * @param {MongoCollectionService.CreateOptions} [options] - The options for creating the document.
39
+ * @returns {Promise<PartialOutput<T>>} A promise that resolves to the created document.
40
+ * @throws {Error} if an unknown error occurs while creating the document.
28
41
  */
29
42
  create(input: PartialInput<T>, options?: MongoCollectionService.CreateOptions): Promise<PartialOutput<T>>;
30
43
  /**
31
- * Gets the number of documents matching the filter.
44
+ * Returns the count of documents in the collection based on the provided options.
32
45
  *
33
- * @param options
46
+ * @param {MongoCollectionService.CountOptions<T>} options - The options for the count operation.
47
+ * @return {Promise<number>} - A promise that resolves to the count of documents in the collection.
34
48
  */
35
49
  count(options?: MongoCollectionService.CountOptions<T>): Promise<number>;
36
50
  /**
37
- * Delete a document from a collection
51
+ * Deletes a document from the collection.
38
52
  *
39
- * @param id
40
- * @param options
53
+ * @param {AnyId} id - The ID of the document to delete.
54
+ * @param {MongoCollectionService.DeleteOptions<T>} [options] - Optional delete options.
55
+ * @return {Promise<number>} - A Promise that resolves to the number of documents deleted.
41
56
  */
42
57
  delete(id: AnyId, options?: MongoCollectionService.DeleteOptions<T>): Promise<number>;
43
58
  /**
44
- * Delete multiple documents from a collection
59
+ * Deletes multiple documents from the collection that meet the specified filter criteria.
45
60
  *
46
- * @param options
61
+ * @param {MongoCollectionService.DeleteManyOptions<T>} options - The options for the delete operation.
62
+ * @return {Promise<number>} - A promise that resolves to the number of documents deleted.
47
63
  */
48
64
  deleteMany(options?: MongoCollectionService.DeleteManyOptions<T>): Promise<number>;
49
65
  /**
50
- * Checks if document exists.
51
- * Returns true if document exists, false otherwise
66
+ * Checks if an object with the given id exists.
52
67
  *
53
- * @param id
68
+ * @param {AnyId} id - The id of the object to check.
69
+ * @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the object exists or not.
54
70
  */
55
71
  exists(id: AnyId): Promise<boolean>;
56
72
  /**
57
- * Fetches the first document matches by id.
73
+ * Finds a document by its ID.
58
74
  *
59
- * @param id
60
- * @param options
75
+ * @param {AnyId} id - The ID of the document.
76
+ * @param {MongoCollectionService.FindOneOptions} [options] - The options for the find query.
77
+ * @return {Promise<PartialOutput<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
61
78
  */
62
79
  findById(id: AnyId, options?: MongoCollectionService.FindOneOptions): Promise<PartialOutput<T | undefined>>;
63
80
  /**
64
- * Fetches the first document that matches the filter.
65
- * Returns undefined if not found.
81
+ * Finds a document in the collection that matches the specified options.
66
82
  *
67
- * @param options
83
+ * @param {MongoCollectionService.FindOneOptions} options - The options for the query.
84
+ * @return {Promise<PartialOutput<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
68
85
  */
69
86
  findOne(options?: MongoCollectionService.FindOneOptions): Promise<PartialOutput<T> | undefined>;
70
87
  /**
71
- * Fetches all document that matches the filter
88
+ * Finds multiple documents in the MongoDB collection.
89
+ *
90
+ * @param options - The options for the find operation.
91
+ * - pick: string[] - An array of fields to include in the returned documents.
92
+ * - include: string[] - An array of fields to include in the returned documents.
93
+ * - omit: string[] - An array of fields to exclude from the returned documents.
94
+ * - sort: Record<string, number> - The sorting criteria.
95
+ * - skip: number - The number of documents to skip.
96
+ * - limit: number - The maximum number of documents to return.
97
+ * - filter: FilterQuery<T> - The filter conditions to apply to the find operation.
98
+ * - count: boolean - If set to true, returns the total count of matching documents.
72
99
  *
73
- * @param options
100
+ * @return A Promise that resolves to an array of partial outputs of type T.
74
101
  */
75
102
  findMany(options?: MongoCollectionService.FindManyOptions<T>): Promise<PartialOutput<T>[]>;
76
103
  /**
77
- * Fetches the first Document that matches the id. Throws error undefined if not found.
104
+ * Retrieves a document from the collection by its ID. Throws error if not found.
78
105
  *
79
- * @param id
80
- * @param options
106
+ * @param {*} id - The ID of the document to retrieve.
107
+ * @param {MongoCollectionService.FindOneOptions} [options] - Optional options for the findOne operation.
108
+ * @returns {Promise<PartialOutput<T>>} - A promise that resolves to the retrieved document,
109
+ * or rejects with a ResourceNotFoundError if the document does not exist.
110
+ * @throws {ResourceNotFoundError} - If the document with the specified ID does not exist.
81
111
  */
82
112
  get(id: AnyId, options?: MongoCollectionService.FindOneOptions): Promise<PartialOutput<T>>;
83
113
  /**
84
- * Updates a single document.
85
- * Returns updated document
114
+ * Updates a document with the given id in the collection.
86
115
  *
87
- * @param id
88
- * @param input
89
- * @param options
116
+ * @param {any} id - The id of the document to update.
117
+ * @param {PartialInput<T>} input - The partial input object containing the fields to update.
118
+ * @param {MongoCollectionService.UpdateOptions<T>} [options] - The options for the update operation.
119
+ * @returns {Promise<PartialOutput<T> | undefined>} A promise that resolves to the updated document or
120
+ * undefined if the document was not found.
90
121
  */
91
122
  update(id: any, input: PartialInput<T>, options?: MongoCollectionService.UpdateOptions<T>): Promise<PartialOutput<T> | undefined>;
92
123
  /**
93
- * Updates a single document
94
- * Returns number of updated documents
124
+ * Updates a document in the collection with the specified ID.
95
125
  *
96
- * @param id
97
- * @param input
98
- * @param options
126
+ * @param {any} id - The ID of the document to update.
127
+ * @param {PartialInput<T>} input - The partial input data to update the document with.
128
+ * @param {MongoCollectionService.UpdateOptions<T>} options - The options for updating the document.
129
+ * @returns {Promise<number>} - A promise that resolves to the number of documents modified.
99
130
  */
100
131
  updateOnly(id: any, input: PartialInput<T>, options?: MongoCollectionService.UpdateOptions<T>): Promise<number>;
101
132
  /**
102
- * Update multiple documents in a collection
133
+ * Updates multiple documents in the collection based on the specified input and options.
103
134
  *
104
- * @param input
105
- * @param options
135
+ * @param {OpraCommon.PartialInput<T>} input - The partial input to update the documents with.
136
+ * @param {MongoCollectionService.UpdateManyOptions<T>} options - The options for updating the documents.
137
+ * @return {Promise<number>} - A promise that resolves to the number of documents matched and modified.
106
138
  */
107
139
  updateMany(input: OpraCommon.PartialInput<T>, options?: MongoCollectionService.UpdateManyOptions<T>): Promise<number>;
108
140
  /**
109
- * Generates Id value
141
+ * Generates a new id for new inserting Document.
110
142
  *
111
143
  * @protected
144
+ * @returns {AnyId} A new instance of AnyId.
112
145
  */
113
146
  protected _generateId(): AnyId;
114
- /**
115
- * Generates a new Validator for encoding or returns from cache if already generated before
116
- * @param operation
117
- * @protected
118
- */
119
- protected _getEncoder(operation: 'create' | 'update'): vg.Validator;
120
- /**
121
- * Generates a new Valgen Validator for encode operation
122
- *
123
- * @param operation
124
- * @protected
125
- */
126
- protected _generateEncoder(operation: 'create' | 'update'): vg.Validator;
127
147
  }
128
148
  /**
129
149
  *
130
150
  * @namespace MongoCollectionService
131
151
  */
132
152
  export declare namespace MongoCollectionService {
153
+ /**
154
+ * The constructor options of MongoCollectionService.
155
+ *
156
+ * @interface Options
157
+ * @extends MongoService.Options
158
+ */
133
159
  interface Options extends MongoService.Options {
134
160
  collectionKey?: string;
135
161
  defaultLimit?: number;
136
162
  }
163
+ /**
164
+ * Represents options for creating a new document.
165
+ *
166
+ * @interface
167
+ */
137
168
  interface CreateOptions extends mongodb.InsertOneOptions {
138
169
  pick?: string[];
139
170
  omit?: string[];
140
171
  include?: string[];
141
172
  }
173
+ /**
174
+ * Represents options for counting document.
175
+ *
176
+ * @interface
177
+ * @template T - The type of the document.
178
+ */
142
179
  interface CountOptions<T> extends mongodb.CountOptions {
143
180
  filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
144
181
  }
182
+ /**
183
+ * Represents options for deleting single document.
184
+ *
185
+ * @interface
186
+ * @template T - The type of the document.
187
+ */
145
188
  interface DeleteOptions<T> extends mongodb.DeleteOptions {
146
189
  filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
147
190
  }
191
+ /**
192
+ * Represents options for deleting multiple documents.
193
+ *
194
+ * @interface
195
+ * @template T - The type of the document.
196
+ */
148
197
  interface DeleteManyOptions<T> extends mongodb.DeleteOptions {
149
198
  filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
150
199
  }
200
+ /**
201
+ * Represents options for finding single document.
202
+ *
203
+ * @interface
204
+ * @template T - The type of the document.
205
+ */
151
206
  interface FindOneOptions<T = any> extends StrictOmit<FindManyOptions<T>, 'count' | 'limit'> {
152
207
  }
208
+ /**
209
+ * Represents options for finding multiple documents.
210
+ *
211
+ * @interface
212
+ * @template T - The type of the document.
213
+ */
153
214
  interface FindManyOptions<T> extends mongodb.AggregateOptions {
154
215
  filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
155
216
  pick?: string[];
@@ -160,12 +221,24 @@ export declare namespace MongoCollectionService {
160
221
  skip?: number;
161
222
  count?: boolean;
162
223
  }
224
+ /**
225
+ * Represents options for updating single document.
226
+ *
227
+ * @interface
228
+ * @template T - The type of the document.
229
+ */
163
230
  interface UpdateOptions<T> extends StrictOmit<mongodb.FindOneAndUpdateOptions, 'projection' | 'returnDocument' | 'includeResultMetadata'> {
164
231
  pick?: string[];
165
232
  omit?: string[];
166
233
  include?: string[];
167
234
  filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
168
235
  }
236
+ /**
237
+ * Represents options for updating multiple documents.
238
+ *
239
+ * @interface
240
+ * @template T - The type of the document.
241
+ */
169
242
  interface UpdateManyOptions<T> extends StrictOmit<mongodb.UpdateOptions, 'upsert'> {
170
243
  filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
171
244
  }