@opra/mongodb 0.33.13 → 1.0.0-alpha.2
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 +20 -28
- package/cjs/adapter-utils/prepare-projection.js +40 -39
- package/cjs/index.js +1 -2
- package/cjs/mongo-adapter.js +66 -1
- package/cjs/mongo-collection-service.js +72 -313
- package/cjs/mongo-entity-service.js +329 -0
- package/cjs/{mongo-array-service.js → mongo-nested-service.js} +231 -225
- package/cjs/mongo-service.js +124 -183
- package/cjs/mongo-singleton-service.js +28 -124
- package/esm/adapter-utils/prepare-filter.js +20 -28
- package/esm/adapter-utils/prepare-projection.js +39 -38
- package/esm/index.js +1 -2
- package/esm/mongo-adapter.js +66 -1
- package/esm/mongo-collection-service.js +73 -313
- package/esm/mongo-entity-service.js +324 -0
- package/esm/mongo-nested-service.js +569 -0
- package/esm/mongo-service.js +125 -184
- package/esm/mongo-singleton-service.js +29 -125
- package/package.json +9 -8
- package/types/adapter-utils/prepare-filter.d.ts +2 -3
- package/types/adapter-utils/prepare-projection.d.ts +4 -13
- package/types/index.d.ts +1 -2
- package/types/mongo-adapter.d.ts +14 -1
- package/types/mongo-collection-service.d.ts +88 -251
- package/types/mongo-entity-service.d.ts +149 -0
- package/types/mongo-nested-service.d.ts +258 -0
- package/types/mongo-service.d.ts +208 -82
- package/types/mongo-singleton-service.d.ts +39 -148
- package/cjs/types.js +0 -2
- package/esm/mongo-array-service.js +0 -563
- package/esm/types.js +0 -1
- package/types/mongo-array-service.d.ts +0 -409
- package/types/types.d.ts +0 -3
|
@@ -1,60 +1,45 @@
|
|
|
1
1
|
import mongodb from 'mongodb';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import { FilterInput } from './adapter-utils/prepare-filter.js';
|
|
2
|
+
import { PartialDTO, PatchDTO, Type } from 'ts-gems';
|
|
3
|
+
import { MongoAdapter } from './mongo-adapter.js';
|
|
4
|
+
import { MongoEntityService } from './mongo-entity-service.js';
|
|
6
5
|
import { MongoService } from './mongo-service.js';
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @namespace MongoSingletonService
|
|
9
|
+
*/
|
|
10
|
+
export declare namespace MongoSingletonService {
|
|
11
|
+
/**
|
|
12
|
+
* The constructor options of MongoSingletonService.
|
|
13
|
+
*
|
|
14
|
+
* @interface Options
|
|
15
|
+
* @extends MongoService.Options
|
|
16
|
+
*/
|
|
17
|
+
interface Options extends MongoEntityService.Options {
|
|
18
|
+
_id?: MongoAdapter.AnyId;
|
|
19
|
+
}
|
|
20
|
+
interface CreateOptions extends MongoEntityService.CreateOptions {
|
|
21
|
+
}
|
|
22
|
+
interface DeleteOptions<T> extends MongoEntityService.DeleteOptions<T> {
|
|
23
|
+
}
|
|
24
|
+
interface ExistsOptions<T> extends MongoService.ExistsOptions<T> {
|
|
25
|
+
}
|
|
26
|
+
interface FindOneOptions<T> extends MongoEntityService.FindOneOptions<T> {
|
|
27
|
+
}
|
|
28
|
+
interface UpdateOptions<T> extends MongoEntityService.UpdateOptions<T> {
|
|
29
|
+
}
|
|
30
|
+
}
|
|
8
31
|
/**
|
|
9
32
|
* A class that provides access to a MongoDB collection, with support for singleton document operations.
|
|
10
33
|
* @class MongoSingletonService
|
|
11
34
|
* @extends MongoService
|
|
12
35
|
* @template T - The type of document stored in the collection
|
|
13
36
|
*/
|
|
14
|
-
export declare class MongoSingletonService<T extends mongodb.Document> extends
|
|
37
|
+
export declare class MongoSingletonService<T extends mongodb.Document> extends MongoEntityService<T> {
|
|
15
38
|
/**
|
|
16
39
|
* Represents a unique identifier for singleton record
|
|
17
|
-
* @type {AnyId} _id
|
|
18
|
-
*/
|
|
19
|
-
_id: AnyId;
|
|
20
|
-
/**
|
|
21
|
-
* Represents the key for a collection.
|
|
22
|
-
*
|
|
23
|
-
* @type {string}
|
|
24
|
-
*/
|
|
25
|
-
collectionKey: string;
|
|
26
|
-
/**
|
|
27
|
-
* Represents a common filter function for a MongoCollectionService.
|
|
28
|
-
*
|
|
29
|
-
* @type {FilterInput | Function}
|
|
40
|
+
* @type {MongoAdapter.AnyId} _id
|
|
30
41
|
*/
|
|
31
|
-
|
|
32
|
-
crud: MongoService.CrudOp;
|
|
33
|
-
method: string;
|
|
34
|
-
documentId?: AnyId;
|
|
35
|
-
input?: Record<string, any>;
|
|
36
|
-
options?: Record<string, any>;
|
|
37
|
-
}, _this: this) => FilterInput | Promise<FilterInput> | undefined);
|
|
38
|
-
/**
|
|
39
|
-
* Interceptor function for handling callback execution with provided arguments.
|
|
40
|
-
*
|
|
41
|
-
* @param {Function} callback - The callback function to be intercepted.
|
|
42
|
-
* @param {Object} args - The arguments object containing the following properties:
|
|
43
|
-
* @param {string} crud - The CRUD operation type.
|
|
44
|
-
* @param {string} method - The method name.
|
|
45
|
-
* @param {AnyId} documentId - The document ID (optional).
|
|
46
|
-
* @param {Object} input - The input object (optional).
|
|
47
|
-
* @param {Object} options - Additional options (optional).
|
|
48
|
-
* @param {Object} _this - The reference to the current object.
|
|
49
|
-
* @returns {Promise<any>} - The promise that resolves to the result of the callback execution.
|
|
50
|
-
*/
|
|
51
|
-
$interceptor?: (callback: (...args: any[]) => any, args: {
|
|
52
|
-
crud: MongoService.CrudOp;
|
|
53
|
-
method: string;
|
|
54
|
-
documentId?: AnyId;
|
|
55
|
-
input?: Record<string, any>;
|
|
56
|
-
options?: Record<string, any>;
|
|
57
|
-
}, _this: any) => Promise<any>;
|
|
42
|
+
_id: MongoAdapter.AnyId;
|
|
58
43
|
/**
|
|
59
44
|
* Constructs a new instance
|
|
60
45
|
*
|
|
@@ -66,20 +51,20 @@ export declare class MongoSingletonService<T extends mongodb.Document> extends M
|
|
|
66
51
|
/**
|
|
67
52
|
* Asserts the existence of a resource based on the given options.
|
|
68
53
|
*
|
|
54
|
+
* @param {MongoSingletonService.ExistsOptions<T>} [options]
|
|
69
55
|
* @returns {Promise<void>} A Promise that resolves when the resource exists.
|
|
70
56
|
* @throws {ResourceNotAvailableError} If the resource does not exist.
|
|
71
57
|
*/
|
|
72
|
-
assert(options?: MongoSingletonService.ExistsOptions): Promise<void>;
|
|
58
|
+
assert(options?: MongoSingletonService.ExistsOptions<T>): Promise<void>;
|
|
73
59
|
/**
|
|
74
60
|
* Creates the document in the database.
|
|
75
61
|
*
|
|
76
|
-
* @param {
|
|
62
|
+
* @param {PartialDTO<T>} input - The partial input to create the document with.
|
|
77
63
|
* @param {MongoSingletonService.CreateOptions} [options] - The options for creating the document.
|
|
78
64
|
* @return {Promise<PartialDTO<T>>} A promise that resolves to the partial output of the created document.
|
|
79
65
|
* @throws {Error} Throws an error if an unknown error occurs while creating the document.
|
|
80
66
|
*/
|
|
81
67
|
create(input: PartialDTO<T>, options?: MongoSingletonService.CreateOptions): Promise<PartialDTO<T>>;
|
|
82
|
-
protected _create(input: PartialDTO<T>, options?: MongoSingletonService.CreateOptions): Promise<PartialDTO<T>>;
|
|
83
68
|
/**
|
|
84
69
|
* Deletes a record from the database
|
|
85
70
|
*
|
|
@@ -87,29 +72,27 @@ export declare class MongoSingletonService<T extends mongodb.Document> extends M
|
|
|
87
72
|
* @returns {Promise<number>} The number of records deleted
|
|
88
73
|
*/
|
|
89
74
|
delete(options?: MongoSingletonService.DeleteOptions<T>): Promise<number>;
|
|
90
|
-
protected _delete(options?: MongoSingletonService.DeleteOptions<T>): Promise<number>;
|
|
91
75
|
/**
|
|
92
76
|
* Checks if the document exists in the database.
|
|
93
77
|
*
|
|
94
78
|
* @return {Promise<boolean>} - A promise that resolves to a boolean value indicating if the document exists.
|
|
95
79
|
*/
|
|
96
|
-
exists(options?: MongoSingletonService.ExistsOptions): Promise<boolean>;
|
|
80
|
+
exists(options?: MongoSingletonService.ExistsOptions<T>): Promise<boolean>;
|
|
97
81
|
/**
|
|
98
82
|
* Fetches the document if it exists. Returns undefined if not found.
|
|
99
83
|
*
|
|
100
|
-
* @param {MongoSingletonService.
|
|
84
|
+
* @param {MongoSingletonService.FindOneOptions<T>} [options] - The options for finding the document.
|
|
101
85
|
* @returns {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the found document or undefined if not found.
|
|
102
86
|
*/
|
|
103
|
-
|
|
104
|
-
protected _findOne(options?: MongoSingletonService.FindOptions<T>): Promise<PartialDTO<T> | undefined>;
|
|
87
|
+
find(options?: MongoSingletonService.FindOneOptions<T>): Promise<PartialDTO<T> | undefined>;
|
|
105
88
|
/**
|
|
106
89
|
* Fetches the document from the Mongo collection service. Throws error if not found.
|
|
107
90
|
*
|
|
108
|
-
* @param {
|
|
91
|
+
* @param {MongoSingletonService.FindOneOptions<T>} options - The options to customize the query.
|
|
109
92
|
* @return {Promise<PartialDTO<T>>} - A promise that resolves to the fetched document.
|
|
110
93
|
* @throws {ResourceNotAvailableError} - If the document is not found in the collection.
|
|
111
94
|
*/
|
|
112
|
-
get(options?: MongoSingletonService.
|
|
95
|
+
get(options?: MongoSingletonService.FindOneOptions<T>): Promise<PartialDTO<T>>;
|
|
113
96
|
/**
|
|
114
97
|
* Updates a document in the MongoDB collection.
|
|
115
98
|
*
|
|
@@ -119,7 +102,6 @@ export declare class MongoSingletonService<T extends mongodb.Document> extends M
|
|
|
119
102
|
* @return {Promise<number>} - A promise that resolves to the updated document or undefined if not found.
|
|
120
103
|
*/
|
|
121
104
|
updateOnly(input: PatchDTO<T>, options?: MongoSingletonService.UpdateOptions<T>): Promise<number>;
|
|
122
|
-
protected _updateOnly(input: PatchDTO<T>, options?: MongoSingletonService.UpdateOptions<T>): Promise<number>;
|
|
123
105
|
/**
|
|
124
106
|
* Updates a document in the MongoDB collection.
|
|
125
107
|
*
|
|
@@ -129,95 +111,4 @@ export declare class MongoSingletonService<T extends mongodb.Document> extends M
|
|
|
129
111
|
* @return {Promise<PartialDTO<T> | undefined>} - A promise that resolves to the updated document or undefined if not found.
|
|
130
112
|
*/
|
|
131
113
|
update(input: PatchDTO<T>, options?: MongoSingletonService.UpdateOptions<T>): Promise<PartialDTO<T> | undefined>;
|
|
132
|
-
protected _update(input: PatchDTO<T>, options?: MongoSingletonService.UpdateOptions<T>): Promise<PartialDTO<T> | undefined>;
|
|
133
|
-
/**
|
|
134
|
-
* Retrieves the common filter used for querying the document.
|
|
135
|
-
* This method is mostly used for security issues like securing multi-tenant applications.
|
|
136
|
-
*
|
|
137
|
-
* @protected
|
|
138
|
-
* @returns {FilterInput | Promise<FilterInput> | undefined} The common filter or a Promise
|
|
139
|
-
* that resolves to the common filter, or undefined if not available.
|
|
140
|
-
*/
|
|
141
|
-
protected _getDocumentFilter(args: {
|
|
142
|
-
crud: MongoService.CrudOp;
|
|
143
|
-
method: string;
|
|
144
|
-
documentId?: AnyId;
|
|
145
|
-
input?: Object;
|
|
146
|
-
options?: Record<string, any>;
|
|
147
|
-
}): FilterInput | Promise<FilterInput> | undefined;
|
|
148
|
-
protected _intercept(callback: (...args: any[]) => any, args: {
|
|
149
|
-
crud: MongoService.CrudOp;
|
|
150
|
-
method: string;
|
|
151
|
-
documentId?: AnyId;
|
|
152
|
-
input?: Object;
|
|
153
|
-
options?: Record<string, any>;
|
|
154
|
-
}): Promise<any>;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
*
|
|
158
|
-
* @namespace MongoSingletonService
|
|
159
|
-
*/
|
|
160
|
-
export declare namespace MongoSingletonService {
|
|
161
|
-
/**
|
|
162
|
-
* The constructor options of MongoSingletonService.
|
|
163
|
-
*
|
|
164
|
-
* @interface Options
|
|
165
|
-
* @extends MongoService.Options
|
|
166
|
-
*/
|
|
167
|
-
interface Options extends MongoService.Options {
|
|
168
|
-
collectionKey?: MongoSingletonService<any>['collectionKey'];
|
|
169
|
-
_id?: MongoSingletonService<any>['_id'];
|
|
170
|
-
documentFilter?: MongoSingletonService<any>['$documentFilter'];
|
|
171
|
-
interceptor?: MongoSingletonService<any>['$interceptor'];
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Represents options for creating the document.
|
|
175
|
-
*
|
|
176
|
-
* @interface
|
|
177
|
-
*/
|
|
178
|
-
interface CreateOptions extends mongodb.InsertOneOptions {
|
|
179
|
-
pick?: string[];
|
|
180
|
-
omit?: string[];
|
|
181
|
-
include?: string[];
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Represents options for deleting the document.
|
|
185
|
-
*
|
|
186
|
-
* @interface
|
|
187
|
-
* @template T - The type of the document.
|
|
188
|
-
*/
|
|
189
|
-
interface DeleteOptions<T> extends mongodb.DeleteOptions {
|
|
190
|
-
filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Represents options for finding the document.
|
|
194
|
-
*
|
|
195
|
-
* @interface
|
|
196
|
-
* @template T - The type of the document.
|
|
197
|
-
*/
|
|
198
|
-
interface FindOptions<T> extends StrictOmit<mongodb.FindOptions, 'sort' | 'limit' | 'skip'> {
|
|
199
|
-
pick?: string[];
|
|
200
|
-
omit?: string[];
|
|
201
|
-
include?: string[];
|
|
202
|
-
filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Represents options for updating the document.
|
|
206
|
-
*
|
|
207
|
-
* @interface
|
|
208
|
-
* @template T - The type of the document.
|
|
209
|
-
*/
|
|
210
|
-
interface UpdateOptions<T> extends mongodb.FindOneAndUpdateOptions {
|
|
211
|
-
pick?: string[];
|
|
212
|
-
omit?: string[];
|
|
213
|
-
include?: string[];
|
|
214
|
-
filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Represents options for checking the document exists
|
|
218
|
-
*
|
|
219
|
-
* @interface
|
|
220
|
-
*/
|
|
221
|
-
interface ExistsOptions extends Omit<mongodb.CommandOperationOptions, 'writeConcern'> {
|
|
222
|
-
}
|
|
223
114
|
}
|
package/cjs/types.js
DELETED