@dnax/core 0.8.5 → 0.8.7
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/app/ctrl.ts +1 -0
- package/driver/mongo/rest.ts +45 -0
- package/package.json +4 -3
- package/types/index.ts +2 -1
- package/utils/index.ts +2 -0
package/app/ctrl.ts
CHANGED
package/driver/mongo/rest.ts
CHANGED
|
@@ -43,6 +43,18 @@ type optionCb = {
|
|
|
43
43
|
elementAt?: Number | null;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
type QueryBatchType<T extends "findOne" | "find"> = {
|
|
47
|
+
as: string;
|
|
48
|
+
collection: string;
|
|
49
|
+
action: T;
|
|
50
|
+
filter: {
|
|
51
|
+
id: string;
|
|
52
|
+
_id: string;
|
|
53
|
+
params: T extends "findOne" ? findOneParam : findParam;
|
|
54
|
+
};
|
|
55
|
+
options: optionCb;
|
|
56
|
+
};
|
|
57
|
+
|
|
46
58
|
const omitUpdate = [
|
|
47
59
|
"$set._id",
|
|
48
60
|
"$set.id",
|
|
@@ -418,6 +430,39 @@ class useRest {
|
|
|
418
430
|
}
|
|
419
431
|
});
|
|
420
432
|
}
|
|
433
|
+
/**
|
|
434
|
+
*
|
|
435
|
+
* @param queries
|
|
436
|
+
* @returns [{ [key: string]: any }]
|
|
437
|
+
*/
|
|
438
|
+
async batch<T extends "findOne" | "find">(queries: QueryBatchType<T>[]) {
|
|
439
|
+
return new Promise(async (resolve, reject) => {
|
|
440
|
+
try {
|
|
441
|
+
let result = {} as any;
|
|
442
|
+
for await (let query of queries) {
|
|
443
|
+
let resultName = query.as || query.collection;
|
|
444
|
+
if (query.action == "findOne") {
|
|
445
|
+
result[resultName] = await this.findOne(
|
|
446
|
+
query.collection,
|
|
447
|
+
query.filter.id,
|
|
448
|
+
query.filter.params,
|
|
449
|
+
query.options
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
if (query.action == "find") {
|
|
453
|
+
result[resultName] = await this.find(
|
|
454
|
+
query.collection,
|
|
455
|
+
query.filter.params,
|
|
456
|
+
query.options
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return resolve(result);
|
|
461
|
+
} catch (err) {
|
|
462
|
+
return reject(err);
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
}
|
|
421
466
|
|
|
422
467
|
/**
|
|
423
468
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dnax/core",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.7",
|
|
4
4
|
"module": "index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@types/bun": "latest",
|
|
11
|
-
"@types/nodemailer": "^6.4.15"
|
|
11
|
+
"@types/nodemailer": "^6.4.15",
|
|
12
|
+
"@types/uuid": "^10.0.0"
|
|
12
13
|
},
|
|
13
14
|
"peerDependencies": {
|
|
14
15
|
"typescript": "^5.0.0"
|
|
@@ -44,4 +45,4 @@
|
|
|
44
45
|
"urlencode": "^2.0.0",
|
|
45
46
|
"uuid": "^10.0.0"
|
|
46
47
|
}
|
|
47
|
-
}
|
|
48
|
+
}
|
package/types/index.ts
CHANGED
package/utils/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import generateUniqueId from "generate-unique-id";
|
|
|
9
9
|
import dayjs from "dayjs";
|
|
10
10
|
import { Otp } from "../lib/opt";
|
|
11
11
|
import collect from "collect.js";
|
|
12
|
+
import * as uuid from "uuid";
|
|
12
13
|
import * as urlencode from "urlencode";
|
|
13
14
|
|
|
14
15
|
const JWT_SECRET = process?.env?.JWT_SECRET || "secret-libv";
|
|
@@ -294,6 +295,7 @@ const password = {
|
|
|
294
295
|
};
|
|
295
296
|
|
|
296
297
|
export {
|
|
298
|
+
uuid,
|
|
297
299
|
pick,
|
|
298
300
|
password, // Hash and verify Password utils
|
|
299
301
|
email, // smtp utils
|