@flowerforce/flowerbase 1.3.1-beta.3 → 1.3.1-beta.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/dist/features/functions/utils.d.ts +8 -7
- package/dist/features/functions/utils.d.ts.map +1 -1
- package/dist/features/functions/utils.js +16 -3
- package/dist/utils/crypto/index.js +1 -1
- package/package.json +1 -1
- package/src/features/functions/utils.ts +19 -5
- package/src/utils/crypto/index.ts +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Document } from 'mongodb';
|
|
1
2
|
import { ExecuteQueryParams, Functions } from './interface';
|
|
2
3
|
/**
|
|
3
4
|
* > Loads the functions config json file
|
|
@@ -15,12 +16,12 @@ export declare const executeQuery: ({ currentMethod, query, update, filter, opti
|
|
|
15
16
|
findOne: () => Promise<unknown>;
|
|
16
17
|
count: () => Promise<number>;
|
|
17
18
|
deleteOne: () => Promise<unknown>;
|
|
18
|
-
insertOne: () => Promise<import("mongodb
|
|
19
|
-
updateOne: () => Promise<unknown> | import("mongodb
|
|
20
|
-
findOneAndUpdate: () => Promise<
|
|
21
|
-
aggregate: () => Promise<
|
|
22
|
-
insertMany: () => Promise<import("mongodb
|
|
23
|
-
updateMany: () => Promise<import("mongodb
|
|
24
|
-
deleteMany: () => Promise<import("mongodb
|
|
19
|
+
insertOne: () => Promise<import("mongodb").InsertOneResult<Document>>;
|
|
20
|
+
updateOne: () => Promise<unknown> | import("mongodb").FindCursor<any> | import("mongodb").ChangeStream<Document, Document> | import("mongodb").AggregationCursor<Document>;
|
|
21
|
+
findOneAndUpdate: () => Promise<Document | null>;
|
|
22
|
+
aggregate: () => Promise<Document[]>;
|
|
23
|
+
insertMany: () => Promise<import("mongodb").InsertManyResult<Document>>;
|
|
24
|
+
updateMany: () => Promise<import("mongodb").UpdateResult<Document>>;
|
|
25
|
+
deleteMany: () => Promise<import("mongodb").DeleteResult>;
|
|
25
26
|
}>;
|
|
26
27
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/functions/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/functions/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGlC,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE3D;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAU,gBAAuB,KAAG,OAAO,CAAC,SAAS,CAwB9E,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAU,+GAWhC,kBAAkB;;;;;;;;;;;;EA4EpB,CAAA"}
|
|
@@ -70,16 +70,29 @@ const executeQuery = (_a) => __awaiter(void 0, [_a], void 0, function* ({ curren
|
|
|
70
70
|
: typeof returnNewDocument === 'boolean'
|
|
71
71
|
? { returnDocument: returnNewDocument ? 'after' : 'before' }
|
|
72
72
|
: undefined;
|
|
73
|
+
const parsedOptions = resolvedOptions ? bson_1.EJSON.deserialize(resolvedOptions) : undefined;
|
|
73
74
|
return {
|
|
74
75
|
find: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
-
return yield
|
|
76
|
+
return yield (() => {
|
|
77
|
+
const cursor = currentMethod(bson_1.EJSON.deserialize(resolvedQuery));
|
|
78
|
+
if (parsedOptions === null || parsedOptions === void 0 ? void 0 : parsedOptions.sort) {
|
|
79
|
+
cursor.sort(parsedOptions.sort);
|
|
80
|
+
}
|
|
81
|
+
if (typeof (parsedOptions === null || parsedOptions === void 0 ? void 0 : parsedOptions.skip) === 'number') {
|
|
82
|
+
cursor.skip(parsedOptions.skip);
|
|
83
|
+
}
|
|
84
|
+
if (typeof (parsedOptions === null || parsedOptions === void 0 ? void 0 : parsedOptions.limit) === 'number') {
|
|
85
|
+
cursor.limit(parsedOptions.limit);
|
|
86
|
+
}
|
|
87
|
+
return cursor.toArray();
|
|
88
|
+
})();
|
|
76
89
|
}),
|
|
77
90
|
findOne: () => currentMethod(bson_1.EJSON.deserialize(resolvedQuery)),
|
|
78
|
-
count: () => currentMethod(bson_1.EJSON.deserialize(resolvedQuery),
|
|
91
|
+
count: () => currentMethod(bson_1.EJSON.deserialize(resolvedQuery), parsedOptions),
|
|
79
92
|
deleteOne: () => currentMethod(bson_1.EJSON.deserialize(resolvedQuery)),
|
|
80
93
|
insertOne: () => currentMethod(bson_1.EJSON.deserialize(document)),
|
|
81
94
|
updateOne: () => currentMethod(bson_1.EJSON.deserialize(resolvedQuery), bson_1.EJSON.deserialize(resolvedUpdate)),
|
|
82
|
-
findOneAndUpdate: () => currentMethod(bson_1.EJSON.deserialize(resolvedQuery), bson_1.EJSON.deserialize(resolvedUpdate),
|
|
95
|
+
findOneAndUpdate: () => currentMethod(bson_1.EJSON.deserialize(resolvedQuery), bson_1.EJSON.deserialize(resolvedUpdate), parsedOptions),
|
|
83
96
|
aggregate: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
97
|
return (yield currentMethod(bson_1.EJSON.deserialize(pipeline), {}, // TODO -> ADD OPTIONS
|
|
85
98
|
isClient)).toArray();
|
|
@@ -36,7 +36,7 @@ exports.hashPassword = hashPassword;
|
|
|
36
36
|
const comparePassword = (plaintext, storedPassword) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
37
|
const [storedHash, storedSalt] = storedPassword.split('.');
|
|
38
38
|
if (!storedHash || !storedSalt) {
|
|
39
|
-
throw new Error(
|
|
39
|
+
throw new Error('Invalid credentials');
|
|
40
40
|
}
|
|
41
41
|
const storedBuffer = Buffer.from(storedHash, 'hex');
|
|
42
42
|
const buffer = (yield scrypt(plaintext, storedSalt, 64));
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
|
+
import { Document } from 'mongodb'
|
|
3
4
|
import { EJSON } from 'bson'
|
|
4
5
|
import { GetOperatorsFunction } from '../../services/mongodb-atlas/model'
|
|
5
6
|
import { ExecuteQueryParams, Functions } from './interface'
|
|
@@ -65,11 +66,24 @@ export const executeQuery = async ({
|
|
|
65
66
|
: typeof returnNewDocument === 'boolean'
|
|
66
67
|
? { returnDocument: returnNewDocument ? 'after' : 'before' }
|
|
67
68
|
: undefined
|
|
69
|
+
const parsedOptions = resolvedOptions ? EJSON.deserialize(resolvedOptions) : undefined
|
|
68
70
|
return {
|
|
69
71
|
find: async () =>
|
|
70
|
-
await (
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
await (() => {
|
|
73
|
+
const cursor = (currentMethod as ReturnType<GetOperatorsFunction>['find'])(
|
|
74
|
+
EJSON.deserialize(resolvedQuery)
|
|
75
|
+
)
|
|
76
|
+
if (parsedOptions?.sort) {
|
|
77
|
+
cursor.sort(parsedOptions.sort as Document)
|
|
78
|
+
}
|
|
79
|
+
if (typeof parsedOptions?.skip === 'number') {
|
|
80
|
+
cursor.skip(parsedOptions.skip)
|
|
81
|
+
}
|
|
82
|
+
if (typeof parsedOptions?.limit === 'number') {
|
|
83
|
+
cursor.limit(parsedOptions.limit)
|
|
84
|
+
}
|
|
85
|
+
return cursor.toArray()
|
|
86
|
+
})(),
|
|
73
87
|
findOne: () =>
|
|
74
88
|
(currentMethod as ReturnType<GetOperatorsFunction>['findOne'])(
|
|
75
89
|
EJSON.deserialize(resolvedQuery)
|
|
@@ -77,7 +91,7 @@ export const executeQuery = async ({
|
|
|
77
91
|
count: () =>
|
|
78
92
|
(currentMethod as ReturnType<GetOperatorsFunction>['count'])(
|
|
79
93
|
EJSON.deserialize(resolvedQuery),
|
|
80
|
-
|
|
94
|
+
parsedOptions
|
|
81
95
|
),
|
|
82
96
|
deleteOne: () =>
|
|
83
97
|
(currentMethod as ReturnType<GetOperatorsFunction>['deleteOne'])(
|
|
@@ -92,7 +106,7 @@ export const executeQuery = async ({
|
|
|
92
106
|
(currentMethod as ReturnType<GetOperatorsFunction>['findOneAndUpdate'])(
|
|
93
107
|
EJSON.deserialize(resolvedQuery),
|
|
94
108
|
EJSON.deserialize(resolvedUpdate),
|
|
95
|
-
|
|
109
|
+
parsedOptions
|
|
96
110
|
),
|
|
97
111
|
aggregate: async () =>
|
|
98
112
|
(await (currentMethod as ReturnType<GetOperatorsFunction>['aggregate'])(
|
|
@@ -24,7 +24,7 @@ export const comparePassword = async (plaintext: string, storedPassword: string)
|
|
|
24
24
|
const [storedHash, storedSalt] = storedPassword.split('.')
|
|
25
25
|
|
|
26
26
|
if (!storedHash || !storedSalt) {
|
|
27
|
-
throw new Error(
|
|
27
|
+
throw new Error('Invalid credentials');
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const storedBuffer = Buffer.from(storedHash, 'hex')
|