@radatek/microserver 2.3.7 → 2.3.8
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/microserver.d.ts +4 -2
- package/microserver.js +13 -17
- package/package.json +1 -1
package/microserver.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MicroServer
|
|
3
|
-
* @version 2.3.
|
|
3
|
+
* @version 2.3.8
|
|
4
4
|
* @package @radatek/microserver
|
|
5
5
|
* @copyright Darius Kisonas 2022
|
|
6
6
|
* @license MIT
|
|
@@ -495,8 +495,10 @@ export declare class ProxyPlugin extends Plugin {
|
|
|
495
495
|
}
|
|
496
496
|
/** User info */
|
|
497
497
|
export interface UserInfo {
|
|
498
|
+
/** User _id */
|
|
499
|
+
_id?: string;
|
|
498
500
|
/** User id */
|
|
499
|
-
id
|
|
501
|
+
id?: string;
|
|
500
502
|
/** User password plain or hash */
|
|
501
503
|
password?: string;
|
|
502
504
|
/** ACL options */
|
package/microserver.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MicroServer
|
|
3
|
-
* @version 2.3.
|
|
3
|
+
* @version 2.3.8
|
|
4
4
|
* @package @radatek/microserver
|
|
5
5
|
* @copyright Darius Kisonas 2022
|
|
6
6
|
* @license MIT
|
|
@@ -2912,23 +2912,21 @@ export class Model {
|
|
|
2912
2912
|
}
|
|
2913
2913
|
/** Find one document */
|
|
2914
2914
|
async findOne(query, options) {
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
if (!this.collection)
|
|
2915
|
+
const collection = await this.collection;
|
|
2916
|
+
if (!collection)
|
|
2918
2917
|
throw new AccessDenied('Database not configured');
|
|
2919
2918
|
options = { readOnly: true, ...this.options, ...options };
|
|
2920
|
-
const doc = await
|
|
2919
|
+
const doc = await collection.findOne(this.getFilter(query, options));
|
|
2921
2920
|
return doc ? this.document(doc, options) : undefined;
|
|
2922
2921
|
}
|
|
2923
2922
|
/** Find many documents */
|
|
2924
2923
|
async findMany(query, options) {
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
if (!this.collection)
|
|
2924
|
+
const collection = await this.collection;
|
|
2925
|
+
if (!collection)
|
|
2928
2926
|
throw new AccessDenied('Database not configured');
|
|
2929
2927
|
const res = [];
|
|
2930
2928
|
options = { readOnly: true, ...this.options, ...options };
|
|
2931
|
-
await
|
|
2929
|
+
await collection.find(this.getFilter(query || {}, options)).forEach((doc) => res.push(this.document(doc, options)));
|
|
2932
2930
|
return res;
|
|
2933
2931
|
}
|
|
2934
2932
|
/** Insert a new document */
|
|
@@ -2937,9 +2935,8 @@ export class Model {
|
|
|
2937
2935
|
}
|
|
2938
2936
|
/** Update one matching document */
|
|
2939
2937
|
async update(query, options) {
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
if (!this.collection)
|
|
2938
|
+
const collection = await this.collection;
|
|
2939
|
+
if (!collection)
|
|
2943
2940
|
throw new AccessDenied('Database not configured');
|
|
2944
2941
|
options = { ...this.options, ...options };
|
|
2945
2942
|
if (options?.validate !== false)
|
|
@@ -2952,19 +2949,18 @@ export class Model {
|
|
|
2952
2949
|
delete query[n];
|
|
2953
2950
|
}
|
|
2954
2951
|
}
|
|
2955
|
-
const res = await
|
|
2952
|
+
const res = await collection.findAndModify({ query: this.getFilter(query, { primaryKey: true, validate: false }), update: query, upsert: options?.insert });
|
|
2956
2953
|
if (!res)
|
|
2957
2954
|
throw new NotFound('Document not found');
|
|
2958
2955
|
return res;
|
|
2959
2956
|
}
|
|
2960
2957
|
/** Delete one matching document */
|
|
2961
2958
|
async delete(query, options) {
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
if (!this.collection)
|
|
2959
|
+
const collection = await this.collection;
|
|
2960
|
+
if (!collection)
|
|
2965
2961
|
throw new AccessDenied('Database not configured');
|
|
2966
2962
|
if (query._id)
|
|
2967
|
-
await
|
|
2963
|
+
await collection.deleteOne(this.getFilter(query, { ...this.options, ...options }));
|
|
2968
2964
|
}
|
|
2969
2965
|
/** Microserver middleware */
|
|
2970
2966
|
handler(req, res) {
|