@dnax/core 0.17.1 → 0.17.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/app/hono.ts +14 -4
- package/app/studio.ts +3 -0
- package/define/index.ts +13 -1
- package/driver/mongo/connect.ts +1 -1
- package/driver/mongo/rest.ts +35 -1
- package/package.json +1 -1
- package/types/index.ts +3 -1
package/app/hono.ts
CHANGED
|
@@ -37,6 +37,7 @@ import { getTenant } from "../lib/tenant";
|
|
|
37
37
|
import { checkPermission, getPermission } from "../lib/permissions";
|
|
38
38
|
import { ipRestriction } from "hono/ip-restriction";
|
|
39
39
|
import { logger } from "hono/logger";
|
|
40
|
+
import { csrf } from "hono/csrf";
|
|
40
41
|
import { v4 } from "uuid";
|
|
41
42
|
const cache = bentoCache.namespace("DNAX_API");
|
|
42
43
|
const app = new Hono();
|
|
@@ -52,6 +53,8 @@ function HonoInstance(): typeof app {
|
|
|
52
53
|
})
|
|
53
54
|
);
|
|
54
55
|
|
|
56
|
+
app.use(csrf());
|
|
57
|
+
|
|
55
58
|
app.use(
|
|
56
59
|
ipRestriction(getConnInfo, {
|
|
57
60
|
allowList: Cfg?.server?.whiteListIps || [],
|
|
@@ -427,8 +430,11 @@ function HonoInstance(): typeof app {
|
|
|
427
430
|
response = await rest.aggregate(collection, body.pipeline || []);
|
|
428
431
|
}
|
|
429
432
|
|
|
430
|
-
//
|
|
431
|
-
|
|
433
|
+
// count
|
|
434
|
+
if (action == "count") {
|
|
435
|
+
response = await rest.count(collection, body?.params || {});
|
|
436
|
+
}
|
|
437
|
+
// find
|
|
432
438
|
if (action == "find") {
|
|
433
439
|
let keyCache = bentoKey({
|
|
434
440
|
data: body,
|
|
@@ -439,7 +445,9 @@ function HonoInstance(): typeof app {
|
|
|
439
445
|
if (responseFromCache) {
|
|
440
446
|
response = responseFromCache;
|
|
441
447
|
} else {
|
|
442
|
-
response = await rest.find(collection, body?.params || {}
|
|
448
|
+
response = await rest.find(collection, body?.params || {}, {
|
|
449
|
+
withMeta: body?.withMeta || false,
|
|
450
|
+
});
|
|
443
451
|
await cache.set({
|
|
444
452
|
key: keyCache,
|
|
445
453
|
value: response,
|
|
@@ -447,7 +455,9 @@ function HonoInstance(): typeof app {
|
|
|
447
455
|
});
|
|
448
456
|
}
|
|
449
457
|
} else {
|
|
450
|
-
response = await rest.find(collection, body?.params || {}
|
|
458
|
+
response = await rest.find(collection, body?.params || {}, {
|
|
459
|
+
withMeta: body?.withMeta || false,
|
|
460
|
+
});
|
|
451
461
|
}
|
|
452
462
|
}
|
|
453
463
|
if (action == "findOne") {
|
package/app/studio.ts
CHANGED
package/define/index.ts
CHANGED
|
@@ -18,7 +18,19 @@ import { Cfg } from "../config/";
|
|
|
18
18
|
import { deepMerge, freeze } from "../utils";
|
|
19
19
|
import { config } from "valibot";
|
|
20
20
|
|
|
21
|
-
function Config(
|
|
21
|
+
function Config(
|
|
22
|
+
config: Omit<
|
|
23
|
+
Config,
|
|
24
|
+
| "permissions"
|
|
25
|
+
| "cwd"
|
|
26
|
+
| "collections"
|
|
27
|
+
| "endpoints"
|
|
28
|
+
| "services"
|
|
29
|
+
| "crons"
|
|
30
|
+
| "routes"
|
|
31
|
+
| "sockets"
|
|
32
|
+
>
|
|
33
|
+
) {
|
|
22
34
|
return config;
|
|
23
35
|
}
|
|
24
36
|
|
package/driver/mongo/connect.ts
CHANGED
package/driver/mongo/rest.ts
CHANGED
|
@@ -41,6 +41,7 @@ type optionCb = {
|
|
|
41
41
|
cleanDeep?: boolean;
|
|
42
42
|
useCustomApi?: boolean;
|
|
43
43
|
elementAt?: Number | null;
|
|
44
|
+
withMeta?: boolean;
|
|
44
45
|
};
|
|
45
46
|
|
|
46
47
|
type QueryBatchType<T extends "findOne" | "find"> = {
|
|
@@ -550,12 +551,18 @@ class useRest {
|
|
|
550
551
|
collection: string,
|
|
551
552
|
params: findParam,
|
|
552
553
|
options?: optionCb
|
|
553
|
-
): Promise<
|
|
554
|
+
): Promise<
|
|
555
|
+
object[] | { data: object[]; meta: { total: number; count: number } }
|
|
556
|
+
> {
|
|
554
557
|
return new Promise(async (resolve, reject) => {
|
|
555
558
|
try {
|
|
556
559
|
if (options?.cleanDeep) {
|
|
557
560
|
params = cleanDeep(params);
|
|
558
561
|
}
|
|
562
|
+
let meta: { total: number; count: number } = {
|
|
563
|
+
total: 0,
|
|
564
|
+
count: 0,
|
|
565
|
+
};
|
|
559
566
|
let useHook = options?.useHook ?? this.#useHook;
|
|
560
567
|
let useCustomApi = options?.useCustomApi ?? this.#useCustomApi;
|
|
561
568
|
let sharedData = {};
|
|
@@ -641,12 +648,39 @@ class useRest {
|
|
|
641
648
|
if (typeof options?.elementAt == "number" && options?.elementAt) {
|
|
642
649
|
resultDocs = resultDocs[options?.elementAt] ?? null;
|
|
643
650
|
}
|
|
651
|
+
|
|
652
|
+
if (options?.withMeta) {
|
|
653
|
+
meta.count = await this.#tenant.database.db
|
|
654
|
+
?.collection(collection)
|
|
655
|
+
.countDocuments({
|
|
656
|
+
...(params?.$match || {}),
|
|
657
|
+
})
|
|
658
|
+
.then((e) => e || 0)
|
|
659
|
+
.catch((err) => 0);
|
|
660
|
+
meta.total = await this.#tenant.database.db
|
|
661
|
+
?.collection(collection)
|
|
662
|
+
.estimatedDocumentCount();
|
|
663
|
+
|
|
664
|
+
return resolve({
|
|
665
|
+
data: resultDocs,
|
|
666
|
+
meta: meta,
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
|
|
644
670
|
return resolve(resultDocs);
|
|
645
671
|
} catch (err) {
|
|
646
672
|
return reject(err);
|
|
647
673
|
}
|
|
648
674
|
});
|
|
649
675
|
}
|
|
676
|
+
/**
|
|
677
|
+
*
|
|
678
|
+
* @param collection
|
|
679
|
+
* @param params
|
|
680
|
+
* @param options
|
|
681
|
+
* @returns
|
|
682
|
+
*/
|
|
683
|
+
|
|
650
684
|
async findOne(
|
|
651
685
|
collection: string,
|
|
652
686
|
id: string,
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
|
@@ -371,6 +371,7 @@ export type Config = {
|
|
|
371
371
|
};
|
|
372
372
|
|
|
373
373
|
server: {
|
|
374
|
+
id?: string;
|
|
374
375
|
logger?: Boolean | loggerFunction;
|
|
375
376
|
whiteListIps?: Array<string>;
|
|
376
377
|
blackListIps?: string[];
|
|
@@ -445,7 +446,8 @@ export type Q = {
|
|
|
445
446
|
| "auth"
|
|
446
447
|
| "upload"
|
|
447
448
|
| "execService"
|
|
448
|
-
| "batch"
|
|
449
|
+
| "batch"
|
|
450
|
+
| "count";
|
|
449
451
|
};
|
|
450
452
|
|
|
451
453
|
export type routeOption = {
|