@dnax/core 0.47.0 → 0.47.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 CHANGED
@@ -555,7 +555,10 @@ function HonoInstance(): typeof app {
555
555
  response = await rest.findOne(
556
556
  collection,
557
557
  body?.id || body._id,
558
- body?.params || {}
558
+ body?.params || {},
559
+ {
560
+ withMeta: body?.withMeta || false,
561
+ }
559
562
  );
560
563
  }
561
564
  if (action == "insertOne") {
@@ -691,6 +694,15 @@ function HonoInstance(): typeof app {
691
694
  }
692
695
  }
693
696
 
697
+ if (
698
+ !col?.api?.fields?.hidden &&
699
+ !col?.api?.fields?.select &&
700
+ body?.withMeta
701
+ ) {
702
+ response.data = omit(response.data, ["password"]);
703
+ response.meta = response.meta || {};
704
+ }
705
+
694
706
  return c.json(response);
695
707
  } catch (err: any) {
696
708
  if (Cfg?.debug) console.log(err?.message | err);
@@ -813,10 +813,14 @@ class useRest {
813
813
  collection: string,
814
814
  id: string,
815
815
  params?: findOneParam,
816
- options?: Omit<optionCb, "elementAt" | "withMeta">
816
+ options?: Omit<optionCb, "elementAt">
817
817
  ): Promise<object | null> {
818
818
  return new Promise(async (resolve, reject) => {
819
819
  try {
820
+ let meta = {
821
+ total: 0,
822
+ count: 0,
823
+ };
820
824
  let sharedData = {};
821
825
  let docs: Array<any> | any = [];
822
826
  let useHook = options?.useHook ?? this.#useHook;
@@ -907,6 +911,7 @@ class useRest {
907
911
  params: params,
908
912
  session: sessionStorage(),
909
913
  result: docs,
914
+ meta: meta,
910
915
  rest: new useRest({
911
916
  useHook: false,
912
917
  tenant_id: this.#tenant_id,
@@ -914,6 +919,15 @@ class useRest {
914
919
  });
915
920
  }
916
921
 
922
+ if (options?.withMeta) {
923
+ meta.count = docs?.length || 0;
924
+ meta.total = docs?.length || 0;
925
+ resolve({
926
+ data: docs?.length ? toJson(docs[0]) : null,
927
+ meta: meta,
928
+ });
929
+ }
930
+
917
931
  return resolve(docs?.length ? toJson(docs[0]) : null);
918
932
  } catch (err) {
919
933
  return reject(err);
@@ -932,6 +946,7 @@ class useRest {
932
946
  let result = {
933
947
  doc: null,
934
948
  };
949
+ let meta = {};
935
950
  let sharedData = {};
936
951
  let useHook = options?.useHook ?? this.#useHook;
937
952
  let useCustomApi = options?.useCustomApi ?? this.#useCustomApi;
@@ -951,6 +966,7 @@ class useRest {
951
966
  driver: "mongodb",
952
967
  action: "updateOne",
953
968
  update: update,
969
+
954
970
  session: sessionStorage(),
955
971
  rest: new useRest({
956
972
  useHook: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.47.0",
3
+ "version": "0.47.2",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/types/index.ts CHANGED
@@ -211,7 +211,7 @@ export type hooksCtx = (ctx: {
211
211
  sharedData?: any;
212
212
  action?: Actions;
213
213
  c?: Context;
214
- meta?: { total: number; count: number; [key: string]: any };
214
+ meta?: { total?: number; count?: number; [key: string]: any };
215
215
  rest: InstanceType<typeof useRest>;
216
216
  session?: sessionCtx;
217
217
  io: socketIoType;