@opra/mongodb 0.31.13 → 0.32.0
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 +65 -10
- package/cjs/adapter-utils/prepare-patch.js +1 -0
- package/cjs/adapter-utils/prepare-projection.js +40 -40
- package/cjs/index.js +2 -0
- package/cjs/mongo-array-service.js +344 -0
- package/cjs/mongo-collection-service.js +243 -81
- package/cjs/mongo-service.js +119 -13
- package/cjs/mongo-singleton-service.js +61 -48
- package/cjs/types.js +2 -0
- package/esm/adapter-utils/prepare-filter.js +65 -10
- package/esm/adapter-utils/prepare-patch.js +1 -0
- package/esm/adapter-utils/prepare-projection.js +38 -37
- package/esm/index.js +2 -0
- package/esm/mongo-array-service.js +339 -0
- package/esm/mongo-collection-service.js +243 -81
- package/esm/mongo-service.js +119 -13
- package/esm/mongo-singleton-service.js +61 -47
- package/esm/types.js +1 -0
- package/package.json +4 -4
- package/types/adapter-utils/prepare-filter.d.ts +10 -2
- package/types/adapter-utils/prepare-projection.d.ts +7 -3
- package/types/index.d.ts +2 -0
- package/types/mongo-array-service.d.ts +193 -0
- package/types/mongo-collection-service.d.ts +120 -18
- package/types/mongo-service.d.ts +91 -11
- package/types/mongo-singleton-service.d.ts +42 -7
- package/types/types.d.ts +2 -0
package/types/mongo-service.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import mongodb
|
|
1
|
+
import mongodb from 'mongodb';
|
|
2
2
|
import { StrictOmit, Type } from 'ts-gems';
|
|
3
3
|
import { ComplexType } from '@opra/common';
|
|
4
4
|
import { ApiService, PartialOutput, RequestContext } from '@opra/core';
|
|
@@ -16,25 +16,105 @@ export declare class MongoService<T extends mongodb.Document> extends ApiService
|
|
|
16
16
|
session?: mongodb.ClientSession;
|
|
17
17
|
resourceName?: string;
|
|
18
18
|
constructor(dataType: Type | string, options?: MongoService.Options);
|
|
19
|
+
getDataType(): ComplexType;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new instance for given context
|
|
22
|
+
*
|
|
23
|
+
* @param source
|
|
24
|
+
*/
|
|
19
25
|
forContext(source: ApiService): this;
|
|
20
26
|
forContext(context: RequestContext, attributes?: {
|
|
21
27
|
db?: mongodb.Db;
|
|
22
28
|
session?: mongodb.ClientSession;
|
|
23
29
|
}): this;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Inserts a single document into MongoDB. If documents passed in do not contain the **_id** field,
|
|
32
|
+
* one will be added to each of the documents missing it by the driver, mutating the document. This behavior
|
|
33
|
+
* can be overridden by setting the **forceServerObjectId** flag.
|
|
34
|
+
*
|
|
35
|
+
* @param doc
|
|
36
|
+
* @param options
|
|
37
|
+
* @protected
|
|
38
|
+
*/
|
|
39
|
+
protected __insertOne(doc: mongodb.OptionalUnlessRequiredId<T>, options?: mongodb.InsertOneOptions): Promise<mongodb.InsertOneResult<T>>;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the number of documents matching the filter.
|
|
42
|
+
*
|
|
43
|
+
* @param filter
|
|
44
|
+
* @param options
|
|
45
|
+
* @protected
|
|
46
|
+
*/
|
|
47
|
+
protected __countDocuments(filter?: mongodb.Filter<T>, options?: mongodb.CountOptions): Promise<number>;
|
|
48
|
+
/**
|
|
49
|
+
* Delete a document from a collection
|
|
50
|
+
*
|
|
51
|
+
* @param filter - The filter used to select the document to remove
|
|
52
|
+
* @param options - Optional settings for the command
|
|
53
|
+
*/
|
|
54
|
+
protected __deleteOne(filter?: mongodb.Filter<T>, options?: mongodb.DeleteOptions): Promise<mongodb.DeleteResult>;
|
|
55
|
+
/**
|
|
56
|
+
* Delete multiple documents from a collection
|
|
57
|
+
*
|
|
58
|
+
* @param filter
|
|
59
|
+
* @param options
|
|
60
|
+
* @protected
|
|
61
|
+
*/
|
|
62
|
+
protected __deleteMany(filter?: mongodb.Filter<T>, options?: mongodb.DeleteOptions): Promise<mongodb.DeleteResult>;
|
|
63
|
+
/**
|
|
64
|
+
* Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this collection.
|
|
65
|
+
*
|
|
66
|
+
* @param pipeline
|
|
67
|
+
* @param options
|
|
68
|
+
* @protected
|
|
69
|
+
*/
|
|
70
|
+
protected __aggregate(pipeline?: mongodb.Document[], options?: mongodb.AggregateOptions): Promise<mongodb.AggregationCursor<T>>;
|
|
71
|
+
/**
|
|
72
|
+
* Fetches the first document that matches the filter
|
|
73
|
+
*
|
|
74
|
+
* @param filter
|
|
75
|
+
* @param options
|
|
76
|
+
* @protected
|
|
77
|
+
*/
|
|
78
|
+
protected __findOne(filter: mongodb.Filter<T>, options?: mongodb.FindOptions): Promise<PartialOutput<T> | undefined>;
|
|
79
|
+
/**
|
|
80
|
+
* Creates a cursor for a filter that can be used to iterate over results from MongoDB
|
|
81
|
+
*
|
|
82
|
+
* @param filter
|
|
83
|
+
* @param options
|
|
84
|
+
* @protected
|
|
85
|
+
*/
|
|
86
|
+
protected __find(filter: mongodb.Filter<T>, options?: mongodb.FindOptions): Promise<mongodb.FindCursor<T>>;
|
|
87
|
+
/**
|
|
88
|
+
* Update a single document in a collection
|
|
89
|
+
*
|
|
90
|
+
* @param filter
|
|
91
|
+
* @param update
|
|
92
|
+
* @param options
|
|
93
|
+
* @protected
|
|
94
|
+
*/
|
|
95
|
+
protected __updateOne(filter: mongodb.Filter<T>, update: mongodb.UpdateFilter<T>, options?: mongodb.UpdateOptions): Promise<mongodb.UpdateResult<T>>;
|
|
96
|
+
/**
|
|
97
|
+
* Find a document and update it in one atomic operation. Requires a write lock for the duration of the operation.
|
|
98
|
+
*
|
|
99
|
+
* @param filter
|
|
100
|
+
* @param doc
|
|
101
|
+
* @param options
|
|
102
|
+
* @protected
|
|
103
|
+
*/
|
|
104
|
+
protected __findOneAndUpdate(filter: mongodb.Filter<T>, doc: mongodb.UpdateFilter<T>, options?: mongodb.FindOneAndUpdateOptions): Promise<mongodb.WithId<T> | null>;
|
|
105
|
+
/**
|
|
106
|
+
* Update multiple documents in a collection
|
|
107
|
+
*
|
|
108
|
+
* @param filter
|
|
109
|
+
* @param doc
|
|
110
|
+
* @param options
|
|
111
|
+
* @protected
|
|
112
|
+
*/
|
|
113
|
+
protected __updateMany(filter: mongodb.Filter<T>, doc: mongodb.UpdateFilter<T> | Partial<T>, options?: StrictOmit<mongodb.UpdateOptions, 'upsert'>): Promise<mongodb.UpdateResult<T>>;
|
|
32
114
|
protected _onError(error: unknown): Promise<void>;
|
|
33
115
|
protected getDatabase(): mongodb.Db | Promise<mongodb.Db>;
|
|
34
|
-
protected getDataType(): ComplexType;
|
|
35
116
|
protected getCollection(db: mongodb.Db): Promise<mongodb.Collection<T>>;
|
|
36
117
|
protected getCollectionName(): string;
|
|
37
118
|
protected _cacheMatch(service: MongoService<any>, context: RequestContext, attributes?: any): boolean;
|
|
38
119
|
protected onError?(error: unknown): void | Promise<void>;
|
|
39
|
-
protected transformData?(row: PartialOutput<T>): PartialOutput<T>;
|
|
40
120
|
}
|
|
@@ -9,13 +9,47 @@ import { MongoService } from './mongo-service.js';
|
|
|
9
9
|
*/
|
|
10
10
|
export declare class MongoSingletonService<T extends mongodb.Document> extends MongoService<T> {
|
|
11
11
|
protected _id: any;
|
|
12
|
+
collectionKey: string;
|
|
12
13
|
constructor(dataType: Type | string, options?: MongoSingletonService.Options);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Fetches the Document. Throws error undefined if not found.
|
|
16
|
+
*
|
|
17
|
+
* @param options
|
|
18
|
+
*/
|
|
19
|
+
assert(options?: MongoSingletonService.GetOptions<T>): Promise<PartialOutput<any>>;
|
|
20
|
+
/**
|
|
21
|
+
* Inserts the document into MongoDB
|
|
22
|
+
*
|
|
23
|
+
* @param doc
|
|
24
|
+
* @param options
|
|
25
|
+
*/
|
|
26
|
+
create(doc: mongodb.OptionalUnlessRequiredId<T>, options?: MongoSingletonService.CreateOptions): Promise<PartialOutput<T>>;
|
|
27
|
+
/**
|
|
28
|
+
* Delete the document from a collection
|
|
29
|
+
*
|
|
30
|
+
* @param options
|
|
31
|
+
*/
|
|
32
|
+
delete(options?: MongoSingletonService.DeleteOptions<T>): Promise<number>;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if the document exists.
|
|
35
|
+
* Returns true if document exists, false otherwise
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
exists(): Promise<boolean>;
|
|
39
|
+
/**
|
|
40
|
+
* Fetches the document
|
|
41
|
+
*
|
|
42
|
+
* @param options
|
|
43
|
+
*/
|
|
44
|
+
get(options?: MongoSingletonService.GetOptions<T>): Promise<PartialOutput<T> | undefined>;
|
|
45
|
+
/**
|
|
46
|
+
* Updates a single document.
|
|
47
|
+
* Returns updated document
|
|
48
|
+
*
|
|
49
|
+
* @param doc
|
|
50
|
+
* @param options
|
|
51
|
+
*/
|
|
52
|
+
update(doc: PartialInput<T>, options?: MongoSingletonService.UpdateOptions<T>): Promise<PartialOutput<T> | undefined>;
|
|
19
53
|
}
|
|
20
54
|
/**
|
|
21
55
|
*
|
|
@@ -23,6 +57,7 @@ export declare class MongoSingletonService<T extends mongodb.Document> extends M
|
|
|
23
57
|
*/
|
|
24
58
|
export declare namespace MongoSingletonService {
|
|
25
59
|
interface Options extends MongoService.Options {
|
|
60
|
+
collectionKey?: string;
|
|
26
61
|
_id?: any;
|
|
27
62
|
}
|
|
28
63
|
interface CreateOptions extends mongodb.InsertOneOptions {
|
|
@@ -39,7 +74,7 @@ export declare namespace MongoSingletonService {
|
|
|
39
74
|
include?: string[];
|
|
40
75
|
filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
|
|
41
76
|
}
|
|
42
|
-
interface UpdateOptions<T> extends mongodb.
|
|
77
|
+
interface UpdateOptions<T> extends mongodb.FindOneAndUpdateOptions {
|
|
43
78
|
pick?: string[];
|
|
44
79
|
omit?: string[];
|
|
45
80
|
include?: string[];
|
package/types/types.d.ts
ADDED