@opra/mongodb 1.0.0-alpha.17 → 1.0.0-alpha.19
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/adapter-utils/prepare-filter.js +1 -1
- package/cjs/adapter-utils/prepare-key-values.js +1 -1
- package/cjs/adapter-utils/prepare-patch.js +1 -1
- package/cjs/adapter-utils/prepare-projection.js +2 -3
- package/cjs/adapter-utils/prepare-sort.js +1 -1
- package/cjs/mongo-collection-service.js +111 -94
- package/cjs/mongo-entity-service.js +86 -69
- package/cjs/mongo-nested-service.js +236 -120
- package/cjs/mongo-service.js +31 -22
- package/cjs/mongo-singleton-service.js +61 -41
- package/esm/mongo-collection-service.js +111 -94
- package/esm/mongo-entity-service.js +86 -69
- package/esm/mongo-nested-service.js +236 -120
- package/esm/mongo-service.js +31 -22
- package/esm/mongo-singleton-service.js +61 -41
- package/package.json +5 -4
- package/types/mongo-collection-service.d.ts +32 -62
- package/types/mongo-entity-service.d.ts +73 -47
- package/types/mongo-nested-service.d.ts +55 -20
- package/types/mongo-service.d.ts +28 -26
- package/types/mongo-singleton-service.d.ts +19 -29
package/esm/mongo-service.js
CHANGED
|
@@ -20,20 +20,20 @@ export class MongoService extends ServiceBase {
|
|
|
20
20
|
this._outputCodecs = {};
|
|
21
21
|
this._dataType_ = dataType;
|
|
22
22
|
this.db = options?.db;
|
|
23
|
-
this
|
|
24
|
-
this
|
|
25
|
-
this
|
|
26
|
-
if (!this
|
|
23
|
+
this.documentFilter = options?.documentFilter;
|
|
24
|
+
this.interceptor = options?.interceptor;
|
|
25
|
+
this.collectionName = options?.collectionName;
|
|
26
|
+
if (!this.collectionName) {
|
|
27
27
|
if (typeof dataType === 'string')
|
|
28
|
-
this
|
|
28
|
+
this.collectionName = dataType;
|
|
29
29
|
if (typeof dataType === 'function') {
|
|
30
30
|
const metadata = Reflect.getMetadata(DATATYPE_METADATA, dataType);
|
|
31
31
|
if (metadata)
|
|
32
|
-
this
|
|
32
|
+
this.collectionName = metadata.name;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
this
|
|
36
|
-
this
|
|
35
|
+
this.resourceName = options?.resourceName;
|
|
36
|
+
this.idGenerator = options?.idGenerator;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* Retrieves the collection name.
|
|
@@ -43,7 +43,7 @@ export class MongoService extends ServiceBase {
|
|
|
43
43
|
* @throws {Error} If the collection name is not defined.
|
|
44
44
|
*/
|
|
45
45
|
getCollectionName() {
|
|
46
|
-
const out = typeof this
|
|
46
|
+
const out = typeof this.collectionName === 'function' ? this.collectionName(this) : this.collectionName;
|
|
47
47
|
if (out)
|
|
48
48
|
return out;
|
|
49
49
|
throw new Error('collectionName is not defined');
|
|
@@ -56,9 +56,7 @@ export class MongoService extends ServiceBase {
|
|
|
56
56
|
* @throws {Error} If the resource name is not defined.
|
|
57
57
|
*/
|
|
58
58
|
getResourceName() {
|
|
59
|
-
const out = typeof this
|
|
60
|
-
? this.$resourceName(this)
|
|
61
|
-
: this.$resourceName || this.getCollectionName();
|
|
59
|
+
const out = typeof this.resourceName === 'function' ? this.resourceName(this) : this.resourceName || this.getCollectionName();
|
|
62
60
|
if (out)
|
|
63
61
|
return out;
|
|
64
62
|
throw new Error('resourceName is not defined');
|
|
@@ -367,8 +365,8 @@ export class MongoService extends ServiceBase {
|
|
|
367
365
|
* @protected
|
|
368
366
|
* @returns {MongoAdapter.AnyId} The generated ID.
|
|
369
367
|
*/
|
|
370
|
-
_generateId() {
|
|
371
|
-
return typeof this
|
|
368
|
+
_generateId(command) {
|
|
369
|
+
return typeof this.idGenerator === 'function' ? this.idGenerator(command, this) : new ObjectId();
|
|
372
370
|
}
|
|
373
371
|
/**
|
|
374
372
|
* Retrieves the common filter used for querying documents.
|
|
@@ -378,18 +376,29 @@ export class MongoService extends ServiceBase {
|
|
|
378
376
|
* @returns {FilterInput | Promise<FilterInput> | undefined} The common filter or a Promise
|
|
379
377
|
* that resolves to the common filter, or undefined if not available.
|
|
380
378
|
*/
|
|
381
|
-
_getDocumentFilter(
|
|
382
|
-
return typeof this
|
|
379
|
+
_getDocumentFilter(command) {
|
|
380
|
+
return typeof this.documentFilter === 'function' ? this.documentFilter(command, this) : this.documentFilter;
|
|
383
381
|
}
|
|
384
|
-
async
|
|
382
|
+
async _executeCommand(command, commandFn) {
|
|
383
|
+
let proto;
|
|
384
|
+
const next = async () => {
|
|
385
|
+
proto = proto ? Object.getPrototypeOf(proto) : this;
|
|
386
|
+
while (proto) {
|
|
387
|
+
if (proto.interceptor) {
|
|
388
|
+
return await proto.interceptor.call(this, next, command, this);
|
|
389
|
+
}
|
|
390
|
+
proto = Object.getPrototypeOf(proto);
|
|
391
|
+
if (!(proto instanceof MongoService))
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
return commandFn();
|
|
395
|
+
};
|
|
385
396
|
try {
|
|
386
|
-
|
|
387
|
-
return this.$interceptor(callback, info, this);
|
|
388
|
-
return callback();
|
|
397
|
+
return await next();
|
|
389
398
|
}
|
|
390
399
|
catch (e) {
|
|
391
|
-
Error.captureStackTrace(e, this.
|
|
392
|
-
await this
|
|
400
|
+
Error.captureStackTrace(e, this._executeCommand);
|
|
401
|
+
await this.onError?.(e, this);
|
|
393
402
|
throw e;
|
|
394
403
|
}
|
|
395
404
|
}
|
|
@@ -23,7 +23,7 @@ export class MongoSingletonService extends MongoEntityService {
|
|
|
23
23
|
/**
|
|
24
24
|
* Asserts the existence of a resource based on the given options.
|
|
25
25
|
*
|
|
26
|
-
* @param {
|
|
26
|
+
* @param {MongoEntityService.ExistsOptions<T>} [options]
|
|
27
27
|
* @returns {Promise<void>} A Promise that resolves when the resource exists.
|
|
28
28
|
* @throws {ResourceNotAvailableError} If the resource does not exist.
|
|
29
29
|
*/
|
|
@@ -35,72 +35,88 @@ export class MongoSingletonService extends MongoEntityService {
|
|
|
35
35
|
* Creates the document in the database.
|
|
36
36
|
*
|
|
37
37
|
* @param {PartialDTO<T>} input - The partial input to create the document with.
|
|
38
|
-
* @param {
|
|
38
|
+
* @param {MongoEntityService.CreateOptions} [options] - The options for creating the document.
|
|
39
39
|
* @return {Promise<PartialDTO<T>>} A promise that resolves to the partial output of the created document.
|
|
40
40
|
* @throws {Error} Throws an error if an unknown error occurs while creating the document.
|
|
41
41
|
*/
|
|
42
42
|
async create(input, options) {
|
|
43
|
-
|
|
44
|
-
const info = {
|
|
43
|
+
const command = {
|
|
45
44
|
crud: 'create',
|
|
46
45
|
method: 'create',
|
|
47
46
|
byId: false,
|
|
48
|
-
documentId: this._id,
|
|
49
47
|
input,
|
|
50
48
|
options,
|
|
51
49
|
};
|
|
52
|
-
|
|
50
|
+
input._id = this._id;
|
|
51
|
+
return this._executeCommand(command, () => this._create(command));
|
|
53
52
|
}
|
|
54
53
|
/**
|
|
55
54
|
* Deletes a record from the database
|
|
56
55
|
*
|
|
57
|
-
* @param {
|
|
56
|
+
* @param {MongoEntityService.DeleteOptions<T>} options - The options for deleting the record
|
|
58
57
|
* @returns {Promise<number>} The number of records deleted
|
|
59
58
|
*/
|
|
60
59
|
async delete(options) {
|
|
61
|
-
const
|
|
60
|
+
const command = {
|
|
62
61
|
crud: 'delete',
|
|
63
62
|
method: 'delete',
|
|
64
63
|
byId: true,
|
|
65
64
|
documentId: this._id,
|
|
66
65
|
options,
|
|
67
66
|
};
|
|
68
|
-
return this.
|
|
69
|
-
const filter = MongoAdapter.prepareFilter([await this._getDocumentFilter(
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
return this._executeCommand(command, async () => {
|
|
68
|
+
const filter = MongoAdapter.prepareFilter([await this._getDocumentFilter(command), command.options?.filter]);
|
|
69
|
+
command.options = { ...command.options, filter };
|
|
70
|
+
return this._delete(command);
|
|
71
|
+
});
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* Checks if the document exists in the database.
|
|
75
75
|
*
|
|
76
|
+
* @param {MongoEntityService.FindOneOptions<T>} [options] - The options for finding the document.
|
|
76
77
|
* @return {Promise<boolean>} - A promise that resolves to a boolean value indicating if the document exists.
|
|
77
78
|
*/
|
|
78
79
|
async exists(options) {
|
|
79
|
-
|
|
80
|
+
const command = {
|
|
81
|
+
crud: 'read',
|
|
82
|
+
method: 'exists',
|
|
83
|
+
byId: true,
|
|
84
|
+
documentId: this._id,
|
|
85
|
+
options,
|
|
86
|
+
};
|
|
87
|
+
return this._executeCommand(command, async () => {
|
|
88
|
+
const documentFilter = await this._getDocumentFilter(command);
|
|
89
|
+
const filter = MongoAdapter.prepareFilter([documentFilter, command.options?.filter]);
|
|
90
|
+
const findCommand = command;
|
|
91
|
+
findCommand.options = { ...command.options, filter, projection: ['_id'] };
|
|
92
|
+
return !!(await this._findById(findCommand));
|
|
93
|
+
});
|
|
80
94
|
}
|
|
81
95
|
/**
|
|
82
96
|
* Fetches the document if it exists. Returns undefined if not found.
|
|
83
97
|
*
|
|
84
|
-
* @param {
|
|
98
|
+
* @param {MongoEntityService.FindOneOptions<T>} [options] - The options for finding the document.
|
|
85
99
|
* @returns {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the found document or undefined if not found.
|
|
86
100
|
*/
|
|
87
101
|
async find(options) {
|
|
88
|
-
const
|
|
102
|
+
const command = {
|
|
89
103
|
crud: 'read',
|
|
90
|
-
method: '
|
|
104
|
+
method: 'findById',
|
|
91
105
|
byId: true,
|
|
92
106
|
documentId: this._id,
|
|
93
107
|
options,
|
|
94
108
|
};
|
|
95
|
-
return this.
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
109
|
+
return this._executeCommand(command, async () => {
|
|
110
|
+
const documentFilter = await this._getDocumentFilter(command);
|
|
111
|
+
const filter = MongoAdapter.prepareFilter([documentFilter, command.options?.filter]);
|
|
112
|
+
command.options = { ...command.options, filter };
|
|
113
|
+
return this._findById(command);
|
|
114
|
+
});
|
|
99
115
|
}
|
|
100
116
|
/**
|
|
101
117
|
* Fetches the document from the Mongo collection service. Throws error if not found.
|
|
102
118
|
*
|
|
103
|
-
* @param {
|
|
119
|
+
* @param {MongoEntityService.FindOneOptions<T>} options - The options to customize the query.
|
|
104
120
|
* @return {Promise<PartialDTO<T>>} - A promise that resolves to the fetched document.
|
|
105
121
|
* @throws {ResourceNotAvailableError} - If the document is not found in the collection.
|
|
106
122
|
*/
|
|
@@ -114,44 +130,48 @@ export class MongoSingletonService extends MongoEntityService {
|
|
|
114
130
|
* Updates a document in the MongoDB collection.
|
|
115
131
|
*
|
|
116
132
|
* @param {PatchDTO<T>} input - The partial input to update the document.
|
|
117
|
-
* @param {
|
|
133
|
+
* @param {MongoEntityService.UpdateOneOptions<T>} [options] - The update options.
|
|
118
134
|
*
|
|
119
|
-
* @return {Promise<
|
|
135
|
+
* @return {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the updated document or undefined if not found.
|
|
120
136
|
*/
|
|
121
|
-
async
|
|
122
|
-
const
|
|
137
|
+
async update(input, options) {
|
|
138
|
+
const isUpdateFilter = Array.isArray(input) || !!Object.keys(input).find(x => x.startsWith('$'));
|
|
139
|
+
const command = {
|
|
123
140
|
crud: 'update',
|
|
124
141
|
method: 'update',
|
|
125
|
-
byId: true,
|
|
126
142
|
documentId: this._id,
|
|
127
|
-
|
|
143
|
+
byId: true,
|
|
144
|
+
input: isUpdateFilter ? undefined : input,
|
|
145
|
+
inputRaw: isUpdateFilter ? input : undefined,
|
|
128
146
|
options,
|
|
129
147
|
};
|
|
130
|
-
return this.
|
|
131
|
-
const filter = MongoAdapter.prepareFilter([await this._getDocumentFilter(
|
|
132
|
-
|
|
133
|
-
|
|
148
|
+
return this._executeCommand(command, async () => {
|
|
149
|
+
const filter = MongoAdapter.prepareFilter([await this._getDocumentFilter(command), command.options?.filter]);
|
|
150
|
+
command.options = { ...command.options, filter };
|
|
151
|
+
return this._update(command);
|
|
152
|
+
});
|
|
134
153
|
}
|
|
135
154
|
/**
|
|
136
155
|
* Updates a document in the MongoDB collection.
|
|
137
156
|
*
|
|
138
157
|
* @param {PatchDTO<T>} input - The partial input to update the document.
|
|
139
|
-
* @param {
|
|
158
|
+
* @param {MongoEntityService.UpdateOneOptions<T>} [options] - The update options.
|
|
140
159
|
*
|
|
141
|
-
* @return {Promise<
|
|
160
|
+
* @return {Promise<number>} - A promise that resolves to the updated document or undefined if not found.
|
|
142
161
|
*/
|
|
143
|
-
async
|
|
144
|
-
const
|
|
162
|
+
async updateOnly(input, options) {
|
|
163
|
+
const command = {
|
|
145
164
|
crud: 'update',
|
|
146
|
-
method: '
|
|
147
|
-
byId: true,
|
|
165
|
+
method: 'updateOnly',
|
|
148
166
|
documentId: this._id,
|
|
167
|
+
byId: true,
|
|
149
168
|
input,
|
|
150
169
|
options,
|
|
151
170
|
};
|
|
152
|
-
return this.
|
|
153
|
-
const filter = MongoAdapter.prepareFilter([await this._getDocumentFilter(
|
|
154
|
-
|
|
155
|
-
|
|
171
|
+
return this._executeCommand(command, async () => {
|
|
172
|
+
const filter = MongoAdapter.prepareFilter([await this._getDocumentFilter(command), command.options?.filter]);
|
|
173
|
+
command.options = { ...command.options, filter };
|
|
174
|
+
return this._updateOnly(command);
|
|
175
|
+
});
|
|
156
176
|
}
|
|
157
177
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/mongodb",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.19",
|
|
4
4
|
"description": "Opra MongoDB adapter package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"lodash.omit": "^4.5.0",
|
|
31
|
-
"putil-isplainobject": "^1.1.5"
|
|
31
|
+
"putil-isplainobject": "^1.1.5",
|
|
32
|
+
"valgen": "^5.6.0"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@faker-js/faker": "^8.4.1",
|
|
@@ -36,8 +37,8 @@
|
|
|
36
37
|
"ts-gems": "^3.4.0"
|
|
37
38
|
},
|
|
38
39
|
"peerDependencies": {
|
|
39
|
-
"@opra/common": "^1.0.0-alpha.
|
|
40
|
-
"@opra/core": "^1.0.0-alpha.
|
|
40
|
+
"@opra/common": "^1.0.0-alpha.19",
|
|
41
|
+
"@opra/core": "^1.0.0-alpha.19",
|
|
41
42
|
"mongodb": ">= 6.0.0"
|
|
42
43
|
},
|
|
43
44
|
"type": "module",
|
|
@@ -2,7 +2,6 @@ import mongodb, { UpdateFilter } from 'mongodb';
|
|
|
2
2
|
import { PartialDTO, PatchDTO, Type } from 'ts-gems';
|
|
3
3
|
import { MongoAdapter } from './mongo-adapter.js';
|
|
4
4
|
import { MongoEntityService } from './mongo-entity-service.js';
|
|
5
|
-
import { MongoService } from './mongo-service.js';
|
|
6
5
|
/**
|
|
7
6
|
*
|
|
8
7
|
* @namespace MongoCollectionService
|
|
@@ -17,28 +16,6 @@ export declare namespace MongoCollectionService {
|
|
|
17
16
|
interface Options extends MongoEntityService.Options {
|
|
18
17
|
defaultLimit?: number;
|
|
19
18
|
}
|
|
20
|
-
interface CreateOptions extends MongoEntityService.CreateOptions {
|
|
21
|
-
}
|
|
22
|
-
interface CountOptions<T> extends MongoEntityService.CountOptions<T> {
|
|
23
|
-
}
|
|
24
|
-
interface DeleteOptions<T> extends MongoEntityService.DeleteOptions<T> {
|
|
25
|
-
}
|
|
26
|
-
interface DeleteManyOptions<T> extends MongoEntityService.DeleteManyOptions<T> {
|
|
27
|
-
}
|
|
28
|
-
interface DistinctOptions<T> extends MongoEntityService.DistinctOptions<T> {
|
|
29
|
-
}
|
|
30
|
-
interface ExistsOptions<T> extends MongoService.ExistsOptions<T> {
|
|
31
|
-
}
|
|
32
|
-
interface ExistsOneOptions<T> extends MongoService.ExistsOneOptions<T> {
|
|
33
|
-
}
|
|
34
|
-
interface FindOneOptions<T> extends MongoEntityService.FindOneOptions<T> {
|
|
35
|
-
}
|
|
36
|
-
interface FindManyOptions<T> extends MongoEntityService.FindManyOptions<T> {
|
|
37
|
-
}
|
|
38
|
-
interface UpdateOptions<T> extends MongoEntityService.UpdateOptions<T> {
|
|
39
|
-
}
|
|
40
|
-
interface UpdateManyOptions<T> extends MongoEntityService.UpdateManyOptions<T> {
|
|
41
|
-
}
|
|
42
19
|
}
|
|
43
20
|
/**
|
|
44
21
|
* @class MongoCollectionService
|
|
@@ -64,95 +41,95 @@ export declare class MongoCollectionService<T extends mongodb.Document> extends
|
|
|
64
41
|
* Throws a ResourceNotFoundError if the resource does not exist.
|
|
65
42
|
*
|
|
66
43
|
* @param {MongoAdapter.AnyId} id - The ID of the resource to assert.
|
|
67
|
-
* @param {
|
|
44
|
+
* @param {MongoEntityService.ExistsOptions<T>} [options] - Optional options for checking the existence.
|
|
68
45
|
* @returns {Promise<void>} - A Promise that resolves when the resource exists.
|
|
69
46
|
* @throws {ResourceNotAvailableError} - If the resource does not exist.
|
|
70
47
|
*/
|
|
71
|
-
assert(id: MongoAdapter.AnyId, options?:
|
|
48
|
+
assert(id: MongoAdapter.AnyId, options?: MongoEntityService.ExistsOptions<T>): Promise<void>;
|
|
72
49
|
/**
|
|
73
50
|
* Creates a new document in the MongoDB collection.
|
|
74
51
|
* Interceptors will be called before performing db operation
|
|
75
52
|
*
|
|
76
53
|
* @param {PartialDTO<T>} input - The input data for creating the document.
|
|
77
|
-
* @param {
|
|
54
|
+
* @param {MongoEntityService.CreateOptions} [options] - The options for creating the document.
|
|
78
55
|
* @returns {Promise<PartialDTO<T>>} A promise that resolves to the created document.
|
|
79
56
|
* @throws {Error} if an unknown error occurs while creating the document.
|
|
80
57
|
*/
|
|
81
|
-
create(input: PartialDTO<T>, options?:
|
|
58
|
+
create(input: PartialDTO<T>, options?: MongoEntityService.CreateOptions): Promise<PartialDTO<T>>;
|
|
82
59
|
/**
|
|
83
60
|
* Returns the count of documents in the collection based on the provided options.
|
|
84
61
|
*
|
|
85
|
-
* @param {
|
|
62
|
+
* @param {MongoEntityService.CountOptions<T>} options - The options for the count operation.
|
|
86
63
|
* @return {Promise<number>} - A promise that resolves to the count of documents in the collection.
|
|
87
64
|
*/
|
|
88
|
-
count(options?:
|
|
65
|
+
count(options?: MongoEntityService.CountOptions<T>): Promise<number>;
|
|
89
66
|
/**
|
|
90
67
|
* Deletes a document from the collection.
|
|
91
68
|
*
|
|
92
69
|
* @param {MongoAdapter.AnyId} id - The ID of the document to delete.
|
|
93
|
-
* @param {
|
|
70
|
+
* @param {MongoEntityService.DeleteOptions<T>} [options] - Optional delete options.
|
|
94
71
|
* @return {Promise<number>} - A Promise that resolves to the number of documents deleted.
|
|
95
72
|
*/
|
|
96
|
-
delete(id: MongoAdapter.AnyId, options?:
|
|
73
|
+
delete(id: MongoAdapter.AnyId, options?: MongoEntityService.DeleteOptions<T>): Promise<number>;
|
|
97
74
|
/**
|
|
98
75
|
* Deletes multiple documents from the collection that meet the specified filter criteria.
|
|
99
76
|
*
|
|
100
|
-
* @param {
|
|
77
|
+
* @param {MongoEntityService.DeleteManyOptions<T>} options - The options for the delete operation.
|
|
101
78
|
* @return {Promise<number>} - A promise that resolves to the number of documents deleted.
|
|
102
79
|
*/
|
|
103
|
-
deleteMany(options?:
|
|
80
|
+
deleteMany(options?: MongoEntityService.DeleteManyOptions<T>): Promise<number>;
|
|
104
81
|
/**
|
|
105
82
|
* The distinct command returns a list of distinct values for the given key across a collection.
|
|
106
83
|
* @param {string} field
|
|
107
|
-
* @param {
|
|
84
|
+
* @param {MongoEntityService.DistinctOptions<T>} [options]
|
|
108
85
|
* @protected
|
|
109
86
|
*/
|
|
110
|
-
distinct(field: string, options?:
|
|
87
|
+
distinct(field: string, options?: MongoEntityService.DistinctOptions<T>): Promise<any[]>;
|
|
111
88
|
/**
|
|
112
89
|
* Checks if an object with the given id exists.
|
|
113
90
|
*
|
|
114
91
|
* @param {MongoAdapter.AnyId} id - The id of the object to check.
|
|
115
|
-
* @param {
|
|
92
|
+
* @param {MongoEntityService.ExistsOptions<T>} [options] - The options for the query (optional).
|
|
116
93
|
* @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the object exists or not.
|
|
117
94
|
*/
|
|
118
|
-
exists(id: MongoAdapter.AnyId, options?:
|
|
95
|
+
exists(id: MongoAdapter.AnyId, options?: MongoEntityService.ExistsOptions<T>): Promise<boolean>;
|
|
119
96
|
/**
|
|
120
97
|
* Checks if an object with the given arguments exists.
|
|
121
98
|
*
|
|
122
|
-
* @param {
|
|
99
|
+
* @param {MongoEntityService.ExistsOneOptions} [options] - The options for the query (optional).
|
|
123
100
|
* @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the object exists or not.
|
|
124
101
|
*/
|
|
125
|
-
existsOne(options?:
|
|
102
|
+
existsOne(options?: MongoEntityService.ExistsOptions<T>): Promise<boolean>;
|
|
126
103
|
/**
|
|
127
104
|
* Finds a document by its ID.
|
|
128
105
|
*
|
|
129
106
|
* @param {MongoAdapter.AnyId} id - The ID of the document.
|
|
130
|
-
* @param {
|
|
107
|
+
* @param {MongoEntityService.FindOneOptions<T>} [options] - The options for the find query.
|
|
131
108
|
* @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
|
|
132
109
|
*/
|
|
133
|
-
findById(id: MongoAdapter.AnyId, options?:
|
|
110
|
+
findById(id: MongoAdapter.AnyId, options?: MongoEntityService.FindOneOptions<T>): Promise<PartialDTO<T> | undefined>;
|
|
134
111
|
/**
|
|
135
112
|
* Finds a document in the collection that matches the specified options.
|
|
136
113
|
*
|
|
137
|
-
* @param {
|
|
114
|
+
* @param {MongoEntityService.FindOneOptions<T>} [options] - The options for the query.
|
|
138
115
|
* @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
|
|
139
116
|
*/
|
|
140
|
-
findOne(options?:
|
|
117
|
+
findOne(options?: MongoEntityService.FindOneOptions<T>): Promise<PartialDTO<T> | undefined>;
|
|
141
118
|
/**
|
|
142
119
|
* Finds multiple documents in the MongoDB collection.
|
|
143
120
|
*
|
|
144
|
-
* @param {
|
|
121
|
+
* @param {MongoEntityService.FindManyOptions<T>} options - The options for the find operation.
|
|
145
122
|
* @return A Promise that resolves to an array of partial outputs of type T.
|
|
146
123
|
*/
|
|
147
|
-
findMany(options?:
|
|
124
|
+
findMany(options?: MongoEntityService.FindManyOptions<T>): Promise<PartialDTO<T>[]>;
|
|
148
125
|
/**
|
|
149
126
|
* Finds multiple documents in the collection and returns both records (max limit)
|
|
150
127
|
* and total count that matched the given criteria
|
|
151
128
|
*
|
|
152
|
-
* @param {
|
|
129
|
+
* @param {MongoEntityService.FindManyOptions<T>} [options] - The options for the find operation.
|
|
153
130
|
* @return A Promise that resolves to an array of partial outputs of type T.
|
|
154
131
|
*/
|
|
155
|
-
findManyWithCount(options?:
|
|
132
|
+
findManyWithCount(options?: MongoEntityService.FindManyOptions<T>): Promise<{
|
|
156
133
|
count: number;
|
|
157
134
|
items: PartialDTO<T>[];
|
|
158
135
|
}>;
|
|
@@ -160,44 +137,37 @@ export declare class MongoCollectionService<T extends mongodb.Document> extends
|
|
|
160
137
|
* Retrieves a document from the collection by its ID. Throws error if not found.
|
|
161
138
|
*
|
|
162
139
|
* @param {MongoAdapter.AnyId} id - The ID of the document to retrieve.
|
|
163
|
-
* @param {
|
|
140
|
+
* @param {MongoEntityService.FindOneOptions<T>} [options] - Optional options for the findOne operation.
|
|
164
141
|
* @returns {Promise<PartialDTO<T>>} - A promise that resolves to the retrieved document,
|
|
165
142
|
* or rejects with a ResourceNotFoundError if the document does not exist.
|
|
166
143
|
* @throws {ResourceNotAvailableError} - If the document with the specified ID does not exist.
|
|
167
144
|
*/
|
|
168
|
-
get(id: MongoAdapter.AnyId, options?:
|
|
145
|
+
get(id: MongoAdapter.AnyId, options?: MongoEntityService.FindOneOptions<T>): Promise<PartialDTO<T>>;
|
|
169
146
|
/**
|
|
170
147
|
* Updates a document with the given id in the collection.
|
|
171
148
|
*
|
|
172
149
|
* @param {MongoAdapter.AnyId} id - The id of the document to update.
|
|
173
150
|
* @param {PatchDTO<T>|UpdateFilter<T>} input - The partial input object containing the fields to update.
|
|
174
|
-
* @param {
|
|
151
|
+
* @param {MongoEntityService.UpdateOneOptions<T>} [options] - The options for the update operation.
|
|
175
152
|
* @returns {Promise<PartialDTO<T> | undefined>} A promise that resolves to the updated document or
|
|
176
153
|
* undefined if the document was not found.
|
|
177
154
|
*/
|
|
178
|
-
update(id: MongoAdapter.AnyId, input: PatchDTO<T> | UpdateFilter<T>, options?:
|
|
155
|
+
update(id: MongoAdapter.AnyId, input: PatchDTO<T> | UpdateFilter<T>, options?: MongoEntityService.UpdateOneOptions<T>): Promise<PartialDTO<T> | undefined>;
|
|
179
156
|
/**
|
|
180
157
|
* Updates a document in the collection with the specified ID.
|
|
181
158
|
*
|
|
182
159
|
* @param {MongoAdapter.AnyId} id - The ID of the document to update.
|
|
183
160
|
* @param {PatchDTO<T>|UpdateFilter<T>} input - The partial input data to update the document with.
|
|
184
|
-
* @param {
|
|
161
|
+
* @param {MongoEntityService.UpdateOneOptions<T>} [options] - The options for updating the document.
|
|
185
162
|
* @returns {Promise<number>} - A promise that resolves to the number of documents modified.
|
|
186
163
|
*/
|
|
187
|
-
updateOnly(id: MongoAdapter.AnyId, input: PatchDTO<T> | UpdateFilter<T>, options?:
|
|
164
|
+
updateOnly(id: MongoAdapter.AnyId, input: PatchDTO<T> | UpdateFilter<T>, options?: MongoEntityService.UpdateOneOptions<T>): Promise<number>;
|
|
188
165
|
/**
|
|
189
166
|
* Updates multiple documents in the collection based on the specified input and options.
|
|
190
167
|
*
|
|
191
168
|
* @param {PatchDTO<T>|UpdateFilter<T>} input - The partial input to update the documents with.
|
|
192
|
-
* @param {
|
|
169
|
+
* @param {MongoEntityService.UpdateManyOptions<T>} options - The options for updating the documents.
|
|
193
170
|
* @return {Promise<number>} - A promise that resolves to the number of documents matched and modified.
|
|
194
171
|
*/
|
|
195
|
-
updateMany(input: PatchDTO<T> | UpdateFilter<T>, options?:
|
|
196
|
-
/**
|
|
197
|
-
* Generates an ID.
|
|
198
|
-
*
|
|
199
|
-
* @protected
|
|
200
|
-
* @returns {MongoAdapter.AnyId} The generated ID.
|
|
201
|
-
*/
|
|
202
|
-
protected _generateId(): MongoAdapter.AnyId;
|
|
172
|
+
updateMany(input: PatchDTO<T> | UpdateFilter<T>, options?: MongoEntityService.UpdateManyOptions<T>): Promise<number>;
|
|
203
173
|
}
|