@opra/mongodb 1.26.2 → 1.26.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -1
- package/adapter/mongo-adapter.d.ts +45 -0
- package/adapter/mongo-adapter.js +23 -0
- package/adapter/mongo-patch-generator.d.ts +12 -0
- package/adapter/mongo-patch-generator.js +22 -10
- package/adapter/prepare-filter.d.ts +4 -6
- package/adapter/prepare-filter.js +4 -6
- package/adapter/prepare-key-values.d.ts +9 -0
- package/adapter/prepare-key-values.js +9 -0
- package/adapter/prepare-projection.d.ts +8 -0
- package/adapter/prepare-projection.js +13 -5
- package/adapter/prepare-sort.d.ts +6 -0
- package/adapter/prepare-sort.js +6 -0
- package/package.json +4 -4
- package/services/mongo-collection-service.d.ts +133 -84
- package/services/mongo-collection-service.js +36 -38
- package/services/mongo-entity-service.d.ts +71 -23
- package/services/mongo-entity-service.js +39 -40
- package/services/mongo-nested-service.d.ts +136 -87
- package/services/mongo-nested-service.js +62 -70
- package/services/mongo-service.d.ts +60 -34
- package/services/mongo-service.js +10 -15
- package/services/mongo-singleton-service.d.ts +49 -46
- package/services/mongo-singleton-service.js +25 -28
- package/types.d.ts +9 -3
|
@@ -12,34 +12,26 @@ import { MongoService } from './mongo-service.js';
|
|
|
12
12
|
export class MongoNestedService extends MongoService {
|
|
13
13
|
/**
|
|
14
14
|
* Represents the name of the array field in parent document
|
|
15
|
-
*
|
|
16
|
-
* @type {string}
|
|
17
15
|
*/
|
|
18
16
|
fieldName;
|
|
19
17
|
/**
|
|
20
18
|
* Represents the value of a nested array key field
|
|
21
|
-
*
|
|
22
|
-
* @type {string}
|
|
23
19
|
*/
|
|
24
20
|
nestedKey;
|
|
25
21
|
/**
|
|
26
22
|
* Represents the default limit value for a certain operation.
|
|
27
|
-
*
|
|
28
|
-
* @type {number}
|
|
29
23
|
*/
|
|
30
24
|
defaultLimit;
|
|
31
25
|
/**
|
|
32
26
|
* Represents a common array filter function
|
|
33
|
-
*
|
|
34
|
-
* @type {FilterInput | Function}
|
|
35
27
|
*/
|
|
36
28
|
nestedFilter;
|
|
37
29
|
/**
|
|
38
30
|
* Constructs a new instance
|
|
39
31
|
*
|
|
40
|
-
* @param
|
|
41
|
-
* @param
|
|
42
|
-
* @param
|
|
32
|
+
* @param dataType - The data type of the array elements.
|
|
33
|
+
* @param fieldName - The name of the field in the document representing the array.
|
|
34
|
+
* @param [options] - The options for the array service.
|
|
43
35
|
* @constructor
|
|
44
36
|
*/
|
|
45
37
|
constructor(dataType, fieldName, options) {
|
|
@@ -50,10 +42,10 @@ export class MongoNestedService extends MongoService {
|
|
|
50
42
|
this.nestedFilter = options?.nestedFilter;
|
|
51
43
|
}
|
|
52
44
|
/**
|
|
53
|
-
* Retrieves the data type of the array field
|
|
45
|
+
* Retrieves the data type of the array field.
|
|
54
46
|
*
|
|
55
|
-
* @returns
|
|
56
|
-
* @throws {NotAcceptableError} If the data type is not a ComplexType.
|
|
47
|
+
* @returns The complex data type of the field.
|
|
48
|
+
* @throws {@link NotAcceptableError} If the data type is not a ComplexType.
|
|
57
49
|
*/
|
|
58
50
|
get dataType() {
|
|
59
51
|
const t = super.dataType.getField(this.fieldName, this.scope).type;
|
|
@@ -64,10 +56,10 @@ export class MongoNestedService extends MongoService {
|
|
|
64
56
|
/**
|
|
65
57
|
* Create a copy of this instance with given properties and context applied.
|
|
66
58
|
*
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
-
* @param
|
|
70
|
-
* @
|
|
59
|
+
* @param context - The execution context or service base to associate with this instance.
|
|
60
|
+
* @param [overwriteProperties] - An optional object containing properties to overwrite in the current instance.
|
|
61
|
+
* @param [overwriteContext] - An optional partial context to apply and potentially overwrite parts of the provided execution context.
|
|
62
|
+
* @returns The current instance with the specified properties and context applied.
|
|
71
63
|
* @template P
|
|
72
64
|
* @template C
|
|
73
65
|
*/
|
|
@@ -78,11 +70,11 @@ export class MongoNestedService extends MongoService {
|
|
|
78
70
|
* Asserts whether a resource with the specified parentId and id exists.
|
|
79
71
|
* Throws a ResourceNotFoundError if the resource does not exist.
|
|
80
72
|
*
|
|
81
|
-
* @param
|
|
82
|
-
* @param
|
|
83
|
-
* @param
|
|
84
|
-
* @
|
|
85
|
-
* @throws {ResourceNotAvailableError} - If the resource does not exist.
|
|
73
|
+
* @param documentId - The ID of the parent document.
|
|
74
|
+
* @param id - The ID of the resource.
|
|
75
|
+
* @param options - Optional parameters for checking resource existence.
|
|
76
|
+
* @returns A promise that resolves with no value upon success.
|
|
77
|
+
* @throws {@link ResourceNotAvailableError} - If the resource does not exist.
|
|
86
78
|
*/
|
|
87
79
|
async assert(documentId, id, options) {
|
|
88
80
|
if (!(await this.exists(documentId, id, options))) {
|
|
@@ -127,11 +119,11 @@ export class MongoNestedService extends MongoService {
|
|
|
127
119
|
/**
|
|
128
120
|
* Adds a single item into the array field.
|
|
129
121
|
*
|
|
130
|
-
* @param
|
|
131
|
-
* @param
|
|
132
|
-
* @param
|
|
133
|
-
* @
|
|
134
|
-
* @throws {ResourceNotAvailableError} - If the parent document is not found.
|
|
122
|
+
* @param documentId - The ID of the parent document.
|
|
123
|
+
* @param input - The item to be added to the array field.
|
|
124
|
+
* @param [options] - Optional options for the create operation.
|
|
125
|
+
* @returns A promise that resolves create operation result
|
|
126
|
+
* @throws {@link ResourceNotAvailableError} - If the parent document is not found.
|
|
135
127
|
*/
|
|
136
128
|
async createOnly(documentId, input, options) {
|
|
137
129
|
const command = {
|
|
@@ -175,9 +167,9 @@ export class MongoNestedService extends MongoService {
|
|
|
175
167
|
/**
|
|
176
168
|
* Counts the number of documents in the collection that match the specified parentId and options.
|
|
177
169
|
*
|
|
178
|
-
* @param
|
|
179
|
-
* @param
|
|
180
|
-
* @returns
|
|
170
|
+
* @param documentId - The ID of the parent document.
|
|
171
|
+
* @param [options] - Optional parameters for counting.
|
|
172
|
+
* @returns A promise that resolves to the count of documents.
|
|
181
173
|
*/
|
|
182
174
|
async count(documentId, options) {
|
|
183
175
|
const command = {
|
|
@@ -232,10 +224,10 @@ export class MongoNestedService extends MongoService {
|
|
|
232
224
|
/**
|
|
233
225
|
* Deletes an element from an array within a document in the MongoDB collection.
|
|
234
226
|
*
|
|
235
|
-
* @param
|
|
236
|
-
* @param
|
|
237
|
-
* @param
|
|
238
|
-
* @
|
|
227
|
+
* @param documentId - The ID of the parent document.
|
|
228
|
+
* @param nestedId - The ID of the element to delete from the nested array.
|
|
229
|
+
* @param [options] - Additional options for the delete operation.
|
|
230
|
+
* @returns A Promise that resolves to the number of elements deleted (1 if successful, 0 if not).
|
|
239
231
|
*/
|
|
240
232
|
async delete(documentId, nestedId, options) {
|
|
241
233
|
const command = {
|
|
@@ -285,9 +277,9 @@ export class MongoNestedService extends MongoService {
|
|
|
285
277
|
/**
|
|
286
278
|
* Deletes multiple items from a collection based on the parent ID and optional filter.
|
|
287
279
|
*
|
|
288
|
-
* @param
|
|
289
|
-
* @param
|
|
290
|
-
* @returns
|
|
280
|
+
* @param documentId - The ID of the parent document.
|
|
281
|
+
* @param [options] - Optional options to specify a filter.
|
|
282
|
+
* @returns A Promise that resolves to the number of items deleted.
|
|
291
283
|
*/
|
|
292
284
|
async deleteMany(documentId, options) {
|
|
293
285
|
const command = {
|
|
@@ -340,10 +332,10 @@ export class MongoNestedService extends MongoService {
|
|
|
340
332
|
/**
|
|
341
333
|
* Checks if an array element with the given parentId and id exists.
|
|
342
334
|
*
|
|
343
|
-
* @param
|
|
344
|
-
* @param
|
|
345
|
-
* @param
|
|
346
|
-
* @returns
|
|
335
|
+
* @param documentId - The ID of the parent document.
|
|
336
|
+
* @param nestedId - The id of the record.
|
|
337
|
+
* @param [options] - The options for the exists method.
|
|
338
|
+
* @returns A promise that resolves to a boolean indicating if the record exists or not.
|
|
347
339
|
*/
|
|
348
340
|
async exists(documentId, nestedId, options) {
|
|
349
341
|
const command = {
|
|
@@ -370,9 +362,9 @@ export class MongoNestedService extends MongoService {
|
|
|
370
362
|
/**
|
|
371
363
|
* Checks if an object with the given arguments exists.
|
|
372
364
|
*
|
|
373
|
-
* @param
|
|
374
|
-
* @param
|
|
375
|
-
* @
|
|
365
|
+
* @param documentId - The ID of the parent document.
|
|
366
|
+
* @param [options] - The options for the query (optional).
|
|
367
|
+
* @returns A Promise that resolves to a boolean indicating whether the object exists or not.
|
|
376
368
|
*/
|
|
377
369
|
async existsOne(documentId, options) {
|
|
378
370
|
const command = {
|
|
@@ -506,10 +498,10 @@ export class MongoNestedService extends MongoService {
|
|
|
506
498
|
{ $unwind: { path: '$' + this.fieldName } },
|
|
507
499
|
{ $replaceRoot: { newRoot: '$' + this.fieldName } },
|
|
508
500
|
];
|
|
509
|
-
|
|
501
|
+
/* Pre-Stages */
|
|
510
502
|
if (options?.preStages)
|
|
511
503
|
stages.push(...options.preStages);
|
|
512
|
-
|
|
504
|
+
/* Filter */
|
|
513
505
|
if (options?.filter || options?.nestedFilter) {
|
|
514
506
|
const optionsFilter = MongoAdapter.prepareFilter([
|
|
515
507
|
options?.filter,
|
|
@@ -517,22 +509,22 @@ export class MongoNestedService extends MongoService {
|
|
|
517
509
|
]);
|
|
518
510
|
stages.push({ $match: optionsFilter });
|
|
519
511
|
}
|
|
520
|
-
|
|
512
|
+
/* Sort */
|
|
521
513
|
if (options?.sort) {
|
|
522
514
|
const sort = MongoAdapter.prepareSort(options.sort);
|
|
523
515
|
if (sort)
|
|
524
516
|
stages.push({ $sort: sort });
|
|
525
517
|
}
|
|
526
|
-
|
|
518
|
+
/* Skip */
|
|
527
519
|
if (options?.skip)
|
|
528
520
|
stages.push({ $skip: options.skip });
|
|
529
|
-
|
|
521
|
+
/* Limit */
|
|
530
522
|
stages.push({ $limit: limit });
|
|
531
523
|
const dataType = this.dataType;
|
|
532
524
|
const projection = MongoAdapter.prepareProjection(dataType, options?.projection, this._dataTypeScope);
|
|
533
525
|
if (projection)
|
|
534
526
|
stages.push({ $project: projection });
|
|
535
|
-
|
|
527
|
+
/* Post-Stages */
|
|
536
528
|
if (options?.postStages)
|
|
537
529
|
stages.push(...options.postStages);
|
|
538
530
|
const db = this.getDatabase();
|
|
@@ -598,10 +590,10 @@ export class MongoNestedService extends MongoService {
|
|
|
598
590
|
},
|
|
599
591
|
},
|
|
600
592
|
];
|
|
601
|
-
|
|
593
|
+
/* Pre-Stages */
|
|
602
594
|
if (options?.preStages)
|
|
603
595
|
dataStages.push(...options.preStages);
|
|
604
|
-
|
|
596
|
+
/* Filter */
|
|
605
597
|
if (options?.filter || options?.nestedFilter) {
|
|
606
598
|
const optionsFilter = MongoAdapter.prepareFilter([
|
|
607
599
|
options?.filter,
|
|
@@ -609,18 +601,18 @@ export class MongoNestedService extends MongoService {
|
|
|
609
601
|
]);
|
|
610
602
|
dataStages.push({ $match: optionsFilter });
|
|
611
603
|
}
|
|
612
|
-
|
|
604
|
+
/* Sort */
|
|
613
605
|
if (options?.sort) {
|
|
614
606
|
const sort = MongoAdapter.prepareSort(options.sort);
|
|
615
607
|
if (sort)
|
|
616
608
|
dataStages.push({ $sort: sort });
|
|
617
609
|
}
|
|
618
|
-
|
|
610
|
+
/* Skip */
|
|
619
611
|
if (options?.skip)
|
|
620
612
|
dataStages.push({ $skip: options.skip });
|
|
621
|
-
|
|
613
|
+
/* Limit */
|
|
622
614
|
dataStages.push({ $limit: limit });
|
|
623
|
-
|
|
615
|
+
/* Post-Stages */
|
|
624
616
|
if (options?.postStages)
|
|
625
617
|
dataStages.push(...options.postStages);
|
|
626
618
|
const dataType = this.dataType;
|
|
@@ -704,11 +696,11 @@ export class MongoNestedService extends MongoService {
|
|
|
704
696
|
/**
|
|
705
697
|
* Update an array element with new data. Returns 1 if document updated 0 otherwise.
|
|
706
698
|
*
|
|
707
|
-
* @param
|
|
708
|
-
* @param
|
|
709
|
-
* @param
|
|
710
|
-
* @param
|
|
711
|
-
* @returns
|
|
699
|
+
* @param documentId - The ID of the parent document.
|
|
700
|
+
* @param nestedId - The ID of the document to update.
|
|
701
|
+
* @param input - The partial input object containing the fields to update.
|
|
702
|
+
* @param [options] - Optional update options.
|
|
703
|
+
* @returns A promise that resolves to the number of elements updated.
|
|
712
704
|
*/
|
|
713
705
|
async updateOnly(documentId, nestedId, input, options) {
|
|
714
706
|
const command = {
|
|
@@ -755,10 +747,10 @@ export class MongoNestedService extends MongoService {
|
|
|
755
747
|
/**
|
|
756
748
|
* Updates multiple array elements in document
|
|
757
749
|
*
|
|
758
|
-
* @param
|
|
759
|
-
* @param
|
|
760
|
-
* @param
|
|
761
|
-
* @returns
|
|
750
|
+
* @param documentId - The ID of the document to update.
|
|
751
|
+
* @param input - The updated data for the document(s).
|
|
752
|
+
* @param [options] - Additional options for the update operation.
|
|
753
|
+
* @returns A promise that resolves to the number of documents updated.
|
|
762
754
|
*/
|
|
763
755
|
async updateMany(documentId, input, options) {
|
|
764
756
|
const command = {
|
|
@@ -831,7 +823,7 @@ export class MongoNestedService extends MongoService {
|
|
|
831
823
|
* This method is mostly used for security issues like securing multi-tenant applications.
|
|
832
824
|
*
|
|
833
825
|
* @protected
|
|
834
|
-
* @returns
|
|
826
|
+
* @returns The common filter or a Promise
|
|
835
827
|
* that resolves to the common filter, or undefined if not available.
|
|
836
828
|
*/
|
|
837
829
|
_getNestedFilter(args) {
|
|
@@ -842,7 +834,7 @@ export class MongoNestedService extends MongoService {
|
|
|
842
834
|
async _executeCommand(command, commandFn) {
|
|
843
835
|
try {
|
|
844
836
|
const result = await super._executeCommand(command, async () => {
|
|
845
|
-
|
|
837
|
+
/* Call before[X] hooks */
|
|
846
838
|
if (command.crud === 'create')
|
|
847
839
|
await this._beforeCreate(command);
|
|
848
840
|
else if (command.crud === 'update' && command.byId) {
|
|
@@ -857,10 +849,10 @@ export class MongoNestedService extends MongoService {
|
|
|
857
849
|
else if (command.crud === 'delete' && !command.byId) {
|
|
858
850
|
await this._beforeDeleteMany(command);
|
|
859
851
|
}
|
|
860
|
-
|
|
852
|
+
/* Call command function */
|
|
861
853
|
return commandFn();
|
|
862
854
|
});
|
|
863
|
-
|
|
855
|
+
/* Call after[X] hooks */
|
|
864
856
|
if (command.crud === 'create')
|
|
865
857
|
await this._afterCreate(command, result);
|
|
866
858
|
else if (command.crud === 'update' && command.byId) {
|
|
@@ -5,23 +5,57 @@ import type { Nullish, StrictOmit, Type } from 'ts-gems';
|
|
|
5
5
|
import type { vg } from 'valgen';
|
|
6
6
|
import { MongoAdapter } from '../adapter/mongo-adapter.js';
|
|
7
7
|
/**
|
|
8
|
-
* The namespace for the MongoService.
|
|
9
|
-
*
|
|
10
|
-
* @namespace MongoService
|
|
8
|
+
* The namespace for the MongoService, containing types and options.
|
|
11
9
|
*/
|
|
12
10
|
export declare namespace MongoService {
|
|
11
|
+
/**
|
|
12
|
+
* Options for initializing MongoService.
|
|
13
|
+
*/
|
|
13
14
|
interface Options extends ServiceBase.Options {
|
|
15
|
+
/**
|
|
16
|
+
* The MongoDB client or database instance.
|
|
17
|
+
*/
|
|
14
18
|
db?: MongoService<any>['db'];
|
|
19
|
+
/**
|
|
20
|
+
* Optional MongoDB client session for transactions.
|
|
21
|
+
*/
|
|
15
22
|
session?: MongoService<any>['session'];
|
|
23
|
+
/**
|
|
24
|
+
* The name of the collection.
|
|
25
|
+
*/
|
|
16
26
|
collectionName?: MongoService<any>['collectionName'];
|
|
27
|
+
/**
|
|
28
|
+
* The name of the resource managed by this service.
|
|
29
|
+
*/
|
|
17
30
|
resourceName?: MongoService<any>['resourceName'];
|
|
31
|
+
/**
|
|
32
|
+
* Optional common filter applied to all read/write operations.
|
|
33
|
+
*/
|
|
18
34
|
documentFilter?: MongoService<any>['documentFilter'];
|
|
35
|
+
/**
|
|
36
|
+
* Optional interceptor for the service operations.
|
|
37
|
+
*/
|
|
19
38
|
interceptor?: MongoService<any>['interceptor'];
|
|
39
|
+
/**
|
|
40
|
+
* Optional function to generate IDs for new documents.
|
|
41
|
+
*/
|
|
20
42
|
idGenerator?: MongoService<any>['idGenerator'];
|
|
43
|
+
/**
|
|
44
|
+
* Optional scope for the service.
|
|
45
|
+
*/
|
|
21
46
|
scope?: MongoService<any>['scope'];
|
|
47
|
+
/**
|
|
48
|
+
* Optional error handler.
|
|
49
|
+
*/
|
|
22
50
|
onError?: MongoService<any>['onError'];
|
|
23
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Represents the CRUD operation types.
|
|
54
|
+
*/
|
|
24
55
|
type CrudOp = 'create' | 'read' | 'replace' | 'update' | 'delete';
|
|
56
|
+
/**
|
|
57
|
+
* Information about the command being executed.
|
|
58
|
+
*/
|
|
25
59
|
interface CommandInfo {
|
|
26
60
|
crud: CrudOp;
|
|
27
61
|
method: string;
|
|
@@ -31,57 +65,54 @@ export declare namespace MongoService {
|
|
|
31
65
|
input?: any;
|
|
32
66
|
options?: any;
|
|
33
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Type definition for a document filter.
|
|
70
|
+
*/
|
|
34
71
|
type DocumentFilter = MongoAdapter.FilterInput | ((args: CommandInfo, _this: MongoService<any>) => MongoAdapter.FilterInput | Promise<MongoAdapter.FilterInput> | undefined);
|
|
35
72
|
/**
|
|
36
|
-
* Represents options for "create" operation
|
|
37
|
-
*
|
|
38
|
-
* @interface
|
|
73
|
+
* Represents options for "create" operation.
|
|
39
74
|
*/
|
|
40
75
|
interface CreateOptions extends mongodb.InsertOneOptions {
|
|
41
76
|
projection?: string | string[] | Document | '*';
|
|
42
77
|
}
|
|
43
78
|
/**
|
|
44
|
-
* Represents options for "count" operation
|
|
79
|
+
* Represents options for "count" operation.
|
|
45
80
|
*
|
|
46
|
-
* @interface
|
|
47
81
|
* @template T - The type of the document.
|
|
48
82
|
*/
|
|
49
83
|
interface CountOptions<T> extends mongodb.CountOptions {
|
|
50
84
|
filter?: MongoAdapter.FilterInput<T>;
|
|
51
85
|
}
|
|
52
86
|
/**
|
|
53
|
-
* Represents options for "delete" operation
|
|
87
|
+
* Represents options for "delete" operation.
|
|
54
88
|
*
|
|
55
|
-
* @interface
|
|
56
89
|
* @template T - The type of the document.
|
|
57
90
|
*/
|
|
58
91
|
interface DeleteOptions<T> extends mongodb.DeleteOptions {
|
|
59
92
|
filter?: MongoAdapter.FilterInput<T>;
|
|
60
93
|
}
|
|
61
94
|
/**
|
|
62
|
-
* Represents options for "deleteMany" operation
|
|
95
|
+
* Represents options for "deleteMany" operation.
|
|
63
96
|
*
|
|
64
|
-
* @interface
|
|
65
97
|
* @template T - The type of the document.
|
|
66
98
|
*/
|
|
67
99
|
interface DeleteManyOptions<T> extends mongodb.DeleteOptions {
|
|
68
100
|
filter?: MongoAdapter.FilterInput<T>;
|
|
69
101
|
}
|
|
70
102
|
/**
|
|
71
|
-
* Represents options for "distinct" operation
|
|
103
|
+
* Represents options for "distinct" operation.
|
|
72
104
|
*
|
|
73
|
-
* @interface
|
|
74
105
|
* @template T - The type of the document.
|
|
75
106
|
*/
|
|
76
107
|
interface DistinctOptions<T> extends mongodb.DistinctOptions {
|
|
77
108
|
filter?: MongoAdapter.FilterInput<T>;
|
|
78
109
|
}
|
|
79
110
|
/**
|
|
80
|
-
* Represents options for "exists" operation
|
|
111
|
+
* Represents options for "exists" operation.
|
|
81
112
|
*
|
|
82
|
-
* @
|
|
113
|
+
* @template T - The type of the document.
|
|
83
114
|
*/
|
|
84
|
-
interface ExistsOptions<T> extends Omit<mongodb.CommandOperationOptions, '
|
|
115
|
+
interface ExistsOptions<T> extends Omit<mongodb.CommandOperationOptions, 'session'> {
|
|
85
116
|
filter?: MongoAdapter.FilterInput<T>;
|
|
86
117
|
}
|
|
87
118
|
/**
|
|
@@ -141,9 +172,9 @@ export interface MongoService {
|
|
|
141
172
|
* Interceptor function for handling callback execution with provided arguments.
|
|
142
173
|
* @type Function
|
|
143
174
|
* @param next - The callback function to be intercepted.
|
|
144
|
-
* @param
|
|
175
|
+
* @param command - The arguments object containing the following properties:
|
|
145
176
|
* @param _this - The reference to the current object.
|
|
146
|
-
* @returns
|
|
177
|
+
* @returns The promise that resolves to the result of the callback execution.
|
|
147
178
|
*/
|
|
148
179
|
interceptor?(next: () => any, command: MongoService.CommandInfo, _this: any): Promise<any>;
|
|
149
180
|
}
|
|
@@ -168,7 +199,6 @@ export declare class MongoService<T extends mongodb.Document = mongodb.Document>
|
|
|
168
199
|
collectionName?: string | ((_this: any) => string);
|
|
169
200
|
/**
|
|
170
201
|
* Represents the name of a resource.
|
|
171
|
-
* @type {string}
|
|
172
202
|
*/
|
|
173
203
|
resourceName?: string | ((_this: any) => string);
|
|
174
204
|
/**
|
|
@@ -187,14 +217,12 @@ export declare class MongoService<T extends mongodb.Document = mongodb.Document>
|
|
|
187
217
|
/**
|
|
188
218
|
* Callback function for handling errors.
|
|
189
219
|
*
|
|
190
|
-
* @param
|
|
220
|
+
* @param error - The error object.
|
|
191
221
|
* @param _this - The context object.
|
|
192
222
|
*/
|
|
193
223
|
onError?: (error: unknown, _this: any) => void | Promise<void>;
|
|
194
224
|
/**
|
|
195
225
|
* Represents a common filter function for a MongoService.
|
|
196
|
-
*
|
|
197
|
-
* @type {FilterInput | Function}
|
|
198
226
|
*/
|
|
199
227
|
documentFilter?: MongoService.DocumentFilter | MongoService.DocumentFilter[];
|
|
200
228
|
/**
|
|
@@ -211,21 +239,21 @@ export declare class MongoService<T extends mongodb.Document = mongodb.Document>
|
|
|
211
239
|
*
|
|
212
240
|
* @protected
|
|
213
241
|
* @returns The collection name.
|
|
214
|
-
* @throws {Error} If the collection name is not defined.
|
|
242
|
+
* @throws {@link Error} If the collection name is not defined.
|
|
215
243
|
*/
|
|
216
244
|
getCollectionName(): string;
|
|
217
245
|
/**
|
|
218
246
|
* Retrieves the resource name.
|
|
219
247
|
*
|
|
220
248
|
* @protected
|
|
221
|
-
* @returns
|
|
222
|
-
* @throws {Error} If the resource name is not defined.
|
|
249
|
+
* @returns The resource name.
|
|
250
|
+
* @throws {@link Error} If the resource name is not defined.
|
|
223
251
|
*/
|
|
224
252
|
getResourceName(): string;
|
|
225
253
|
/**
|
|
226
|
-
* Retrieves the OPRA data type
|
|
254
|
+
* Retrieves the OPRA data type.
|
|
227
255
|
*
|
|
228
|
-
* @throws {NotAcceptableError} If the data type is not a ComplexType.
|
|
256
|
+
* @throws {@link NotAcceptableError} If the data type is not a ComplexType.
|
|
229
257
|
*/
|
|
230
258
|
get dataType(): ComplexType;
|
|
231
259
|
/**
|
|
@@ -239,16 +267,14 @@ export declare class MongoService<T extends mongodb.Document = mongodb.Document>
|
|
|
239
267
|
* Retrieves the database connection.
|
|
240
268
|
*
|
|
241
269
|
* @protected
|
|
242
|
-
*
|
|
243
|
-
* @throws {Error} If the context or database is not set.
|
|
270
|
+
* @throws {@link Error} If the context or database is not set.
|
|
244
271
|
*/
|
|
245
272
|
protected getDatabase(): mongodb.Db;
|
|
246
273
|
/**
|
|
247
274
|
* Retrieves the database session.
|
|
248
275
|
*
|
|
249
276
|
* @protected
|
|
250
|
-
*
|
|
251
|
-
* @throws {Error} If the context or database is not set.
|
|
277
|
+
* @throws {@link Error} If the context or database is not set.
|
|
252
278
|
*/
|
|
253
279
|
protected getSession(): mongodb.ClientSession | undefined;
|
|
254
280
|
/**
|
|
@@ -262,7 +288,7 @@ export declare class MongoService<T extends mongodb.Document = mongodb.Document>
|
|
|
262
288
|
* Generates an ID.
|
|
263
289
|
*
|
|
264
290
|
* @protected
|
|
265
|
-
* @returns
|
|
291
|
+
* @returns The generated ID.
|
|
266
292
|
*/
|
|
267
293
|
protected _generateId(command: MongoService.CommandInfo): MongoAdapter.AnyId;
|
|
268
294
|
/**
|
|
@@ -270,7 +296,7 @@ export declare class MongoService<T extends mongodb.Document = mongodb.Document>
|
|
|
270
296
|
* This method is mostly used for security issues like securing multi-tenant applications.
|
|
271
297
|
*
|
|
272
298
|
* @protected
|
|
273
|
-
* @returns
|
|
299
|
+
* @returns The common filter or a Promise
|
|
274
300
|
* that resolves to the common filter, or undefined if not available.
|
|
275
301
|
*/
|
|
276
302
|
protected _getDocumentFilter(command: MongoService.CommandInfo): MongoAdapter.FilterInput | Promise<MongoAdapter.FilterInput> | undefined;
|
|
@@ -24,7 +24,6 @@ export class MongoService extends ServiceBase {
|
|
|
24
24
|
collectionName;
|
|
25
25
|
/**
|
|
26
26
|
* Represents the name of a resource.
|
|
27
|
-
* @type {string}
|
|
28
27
|
*/
|
|
29
28
|
resourceName;
|
|
30
29
|
/**
|
|
@@ -43,14 +42,12 @@ export class MongoService extends ServiceBase {
|
|
|
43
42
|
/**
|
|
44
43
|
* Callback function for handling errors.
|
|
45
44
|
*
|
|
46
|
-
* @param
|
|
45
|
+
* @param error - The error object.
|
|
47
46
|
* @param _this - The context object.
|
|
48
47
|
*/
|
|
49
48
|
onError;
|
|
50
49
|
/**
|
|
51
50
|
* Represents a common filter function for a MongoService.
|
|
52
|
-
*
|
|
53
|
-
* @type {FilterInput | Function}
|
|
54
51
|
*/
|
|
55
52
|
documentFilter;
|
|
56
53
|
/**
|
|
@@ -99,7 +96,7 @@ export class MongoService extends ServiceBase {
|
|
|
99
96
|
*
|
|
100
97
|
* @protected
|
|
101
98
|
* @returns The collection name.
|
|
102
|
-
* @throws {Error} If the collection name is not defined.
|
|
99
|
+
* @throws {@link Error} If the collection name is not defined.
|
|
103
100
|
*/
|
|
104
101
|
getCollectionName() {
|
|
105
102
|
const out = typeof this.collectionName === 'function'
|
|
@@ -113,8 +110,8 @@ export class MongoService extends ServiceBase {
|
|
|
113
110
|
* Retrieves the resource name.
|
|
114
111
|
*
|
|
115
112
|
* @protected
|
|
116
|
-
* @returns
|
|
117
|
-
* @throws {Error} If the resource name is not defined.
|
|
113
|
+
* @returns The resource name.
|
|
114
|
+
* @throws {@link Error} If the resource name is not defined.
|
|
118
115
|
*/
|
|
119
116
|
getResourceName() {
|
|
120
117
|
const out = typeof this.resourceName === 'function'
|
|
@@ -125,9 +122,9 @@ export class MongoService extends ServiceBase {
|
|
|
125
122
|
throw new Error('resourceName is not defined');
|
|
126
123
|
}
|
|
127
124
|
/**
|
|
128
|
-
* Retrieves the OPRA data type
|
|
125
|
+
* Retrieves the OPRA data type.
|
|
129
126
|
*
|
|
130
|
-
* @throws {NotAcceptableError} If the data type is not a ComplexType.
|
|
127
|
+
* @throws {@link NotAcceptableError} If the data type is not a ComplexType.
|
|
131
128
|
*/
|
|
132
129
|
get dataType() {
|
|
133
130
|
if (this._dataType && this._dataTypeScope !== this.scope)
|
|
@@ -187,8 +184,7 @@ export class MongoService extends ServiceBase {
|
|
|
187
184
|
* Retrieves the database connection.
|
|
188
185
|
*
|
|
189
186
|
* @protected
|
|
190
|
-
*
|
|
191
|
-
* @throws {Error} If the context or database is not set.
|
|
187
|
+
* @throws {@link Error} If the context or database is not set.
|
|
192
188
|
*/
|
|
193
189
|
getDatabase() {
|
|
194
190
|
const ctx = this.context;
|
|
@@ -204,8 +200,7 @@ export class MongoService extends ServiceBase {
|
|
|
204
200
|
* Retrieves the database session.
|
|
205
201
|
*
|
|
206
202
|
* @protected
|
|
207
|
-
*
|
|
208
|
-
* @throws {Error} If the context or database is not set.
|
|
203
|
+
* @throws {@link Error} If the context or database is not set.
|
|
209
204
|
*/
|
|
210
205
|
getSession() {
|
|
211
206
|
const ctx = this.context;
|
|
@@ -229,7 +224,7 @@ export class MongoService extends ServiceBase {
|
|
|
229
224
|
* Generates an ID.
|
|
230
225
|
*
|
|
231
226
|
* @protected
|
|
232
|
-
* @returns
|
|
227
|
+
* @returns The generated ID.
|
|
233
228
|
*/
|
|
234
229
|
_generateId(command) {
|
|
235
230
|
return typeof this.idGenerator === 'function'
|
|
@@ -241,7 +236,7 @@ export class MongoService extends ServiceBase {
|
|
|
241
236
|
* This method is mostly used for security issues like securing multi-tenant applications.
|
|
242
237
|
*
|
|
243
238
|
* @protected
|
|
244
|
-
* @returns
|
|
239
|
+
* @returns The common filter or a Promise
|
|
245
240
|
* that resolves to the common filter, or undefined if not available.
|
|
246
241
|
*/
|
|
247
242
|
_getDocumentFilter(command) {
|