@dnax/core 0.30.1 → 0.30.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.
@@ -631,6 +631,22 @@ class useRest {
631
631
 
632
632
  result.docs = toJson(result.docs);
633
633
 
634
+ if (options?.withMeta) {
635
+ meta.count = await this.#tenant.database.db
636
+ ?.collection(collection)
637
+ .countDocuments({
638
+ ...(params?.$match || {}),
639
+ })
640
+ .then((e) => e || 0)
641
+ .catch((err) => 0);
642
+ meta.total = await this.#tenant.database.db
643
+ ?.collection(collection)
644
+ .estimatedDocumentCount();
645
+ } else {
646
+ meta.total = result.docs.length;
647
+ meta.count = result.docs.length;
648
+ }
649
+
634
650
  if (col?.hooks?.afterFind && useHook) {
635
651
  await col.hooks.afterFind({
636
652
  sharedData: sharedData,
@@ -638,6 +654,7 @@ class useRest {
638
654
  io: Cfg.io,
639
655
  driver: "mongodb",
640
656
  action: "find",
657
+ meta: meta,
641
658
  count: result?.docs?.length || 0,
642
659
  params: params,
643
660
  session: sessionStorage(),
@@ -656,17 +673,6 @@ class useRest {
656
673
  }
657
674
 
658
675
  if (options?.withMeta) {
659
- meta.count = await this.#tenant.database.db
660
- ?.collection(collection)
661
- .countDocuments({
662
- ...(params?.$match || {}),
663
- })
664
- .then((e) => e || 0)
665
- .catch((err) => 0);
666
- meta.total = await this.#tenant.database.db
667
- ?.collection(collection)
668
- .estimatedDocumentCount();
669
-
670
676
  return resolve({
671
677
  data: resultDocs,
672
678
  meta: meta,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.30.1",
3
+ "version": "0.30.3",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/types/index.ts CHANGED
@@ -200,6 +200,7 @@ export type hooksCtx = (ctx: {
200
200
  sharedData?: any;
201
201
  action?: Actions;
202
202
  c?: Context;
203
+ meta?: { total: number; count: number; [key: string]: any };
203
204
  rest: InstanceType<typeof useRest>;
204
205
  session?: sessionCtx;
205
206
  io: socketIoType;