@dnax/core 0.17.1 → 0.17.3

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 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
- // udpateOne
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
@@ -13,8 +13,11 @@ function setApiStudio(app: InstanceType<typeof Hono>) {
13
13
  "tenant_id",
14
14
  ]);
15
15
  });
16
+
16
17
  let config = {
17
18
  collections: collections,
19
+ serverId: Cfg.server?.id,
20
+ tenantId: c?.req?.header()["tenant-id"],
18
21
  };
19
22
 
20
23
  return c.json(config);
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(config: 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
 
@@ -20,7 +20,7 @@ async function connectToMongo(t: Tenant) {
20
20
  resolve(t);
21
21
  })
22
22
  .catch((error) => {
23
- console.error(error?.message);
23
+ console.error(`Failed to connect Tenant ${t.id} : `, error?.message);
24
24
  t.database.isConnected = false;
25
25
  });
26
26
 
@@ -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<object[]> {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.17.1",
3
+ "version": "0.17.3",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
@@ -12,7 +12,9 @@
12
12
  "@types/mime-types": "^2.1.4",
13
13
  "@types/nodemailer": "^6.4.15",
14
14
  "@types/pidusage": "^2.0.5",
15
- "@types/uuid": "^10.0.0"
15
+ "@types/uuid": "^10.0.0",
16
+ "@types/dot-object": "^2.1.6",
17
+ "@types/jsonwebtoken": "9.0.6"
16
18
  },
17
19
  "peerDependencies": {
18
20
  "typescript": "^5.0.0"
@@ -21,28 +23,23 @@
21
23
  "@clack/prompts": "^0.7.0",
22
24
  "@colors/colors": "^1.6.0",
23
25
  "@lukeed/ms": "^2.0.2",
24
- "@mistralai/mistralai": "^1.3.4",
25
26
  "@orama/orama": "^2.0.23",
26
- "@types/dot-object": "^2.1.6",
27
- "@types/jsonwebtoken": "^9.0.6",
28
27
  "bentocache": "^1.0.0-beta.9",
29
28
  "boxen": "^7.1.1",
30
- "chokidar": "^3.6.0",
29
+ "chokidar": "3.6.0",
31
30
  "clean-deep": "^3.4.0",
32
- "cohere-ai": "^7.14.0",
33
31
  "collect.js": "^4.36.1",
34
32
  "consola": "^3.2.3",
35
33
  "cookie": "^0.6.0",
36
- "croner": "^8.1.1",
34
+ "croner": "8.1.1",
37
35
  "deepcopy": "^2.1.0",
38
36
  "docxtemplater": "^3.54.1",
39
- "dot-object": "^2.1.5",
37
+ "dot-object": "2.1.5",
40
38
  "find-open-port": "^2.0.3",
41
39
  "fs-extra": "^11.2.0",
42
40
  "generate-unique-id": "^2.0.3",
43
- "groq-sdk": "^0.8.0",
44
- "hono": "^4.6.3",
45
- "joi": "^17.13.3",
41
+ "hono": "4.6.14",
42
+ "joi": "17.13.3",
46
43
  "json-joy": "16.8.0",
47
44
  "jsonwebtoken": "^9.0.2",
48
45
  "libreoffice-convert": "^1.6.0",
@@ -51,8 +48,6 @@
51
48
  "moment": "^2.30.1",
52
49
  "mongodb": "^6.11.0",
53
50
  "nodemailer": "^6.9.14",
54
- "ollama": "^0.5.10",
55
- "openai": "^4.73.1",
56
51
  "pidusage": "^3.0.2",
57
52
  "pizzip": "^3.1.7",
58
53
  "radash": "^12.1.0",
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 = {