@dnax/core 0.33.0 → 0.35.0

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
@@ -20,6 +20,7 @@ import {
20
20
  jwt,
21
21
  fn,
22
22
  omit,
23
+ pick,
23
24
  stringToBoolean,
24
25
  } from "../utils";
25
26
  import { getAction } from "./ctrl";
@@ -31,7 +32,7 @@ import { getService } from "../lib/service";
31
32
  import { bentoCache, bentoKey } from "../lib/bento";
32
33
  import { MediaDrive } from "../lib/media";
33
34
  import { isStudio } from "../lib/studio";
34
- import { pick } from "radash";
35
+
35
36
  import { secureHeaders } from "hono/secure-headers";
36
37
  import { getTenant } from "../lib/tenant";
37
38
  import { checkPermission, getPermission } from "../lib/permissions";
@@ -563,8 +564,33 @@ function HonoInstance(): typeof app {
563
564
  }
564
565
  }
565
566
 
566
- if (col?.privateFields?.length) {
567
- response = omit(response, col?.privateFields || []);
567
+ if (
568
+ col?.api?.fields?.select?.length &&
569
+ Array.isArray(col?.api?.fields?.select?.length)
570
+ ) {
571
+ if (body?.withMeta) {
572
+ try {
573
+ response.data = pick(response.data, col?.api?.fields?.select || []);
574
+ } catch (err) {}
575
+ } else {
576
+ response = pick(response, col?.api?.fields?.select || []);
577
+ }
578
+ }
579
+ if (
580
+ col?.api?.fields?.hidden?.length &&
581
+ Array.isArray(col?.api?.fields?.hidden?.length)
582
+ ) {
583
+ let privateFields = col?.api?.fields?.hidden || [];
584
+ privateFields.push("password");
585
+ if (body?.withMeta) {
586
+ // If use Meta are included
587
+ try {
588
+ response.data = omit(response.data, privateFields);
589
+ } catch (e) {}
590
+ }
591
+ response = omit(response, privateFields);
592
+ } else {
593
+ response = omit(response, ["password"]);
568
594
  }
569
595
 
570
596
  return c.json(response);
@@ -1026,7 +1026,7 @@ class useRest {
1026
1026
  _id: new ObjectId(id),
1027
1027
  },
1028
1028
  {
1029
- ...formatData(omit(transformAllDate(update), omitUpdate)),
1029
+ ...formatData(omit(update, omitUpdate)),
1030
1030
  $currentDate: {
1031
1031
  updatedAt: true,
1032
1032
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.33.0",
3
+ "version": "0.35.0",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/types/index.ts CHANGED
@@ -349,7 +349,13 @@ export type Collection = {
349
349
  timestamps?: boolean;
350
350
  description?: string;
351
351
  fields?: Field[];
352
- privateFields?: string[];
352
+ api?: {
353
+ //privateFields?: string[];
354
+ fields: {
355
+ select?: string[];
356
+ hidden?: string[];
357
+ };
358
+ };
353
359
  allow?: ["dropCollection", "renameCollection"];
354
360
  indexes?: Array<{
355
361
  [key: string]: any;
package/utils/index.ts CHANGED
@@ -65,7 +65,7 @@ const jwt = {
65
65
  return jwto.sign({ session: payload }, JWT_SECRET, {
66
66
  ...options,
67
67
  });
68
- } catch (err) {
68
+ } catch (err: any) {
69
69
  console.error(err?.message);
70
70
  }
71
71
  },
@@ -162,7 +162,7 @@ async function verifyHashPassword(
162
162
  }
163
163
  }
164
164
 
165
- function toDate(data: object | string): object | string {
165
+ function toDate(data: any | string): object | string {
166
166
  if (data) {
167
167
  if (typeof data == "string" && isDate(data)) {
168
168
  data = new Date(data);
@@ -295,9 +295,9 @@ function pick(data: object | object[], keys: string[]): object {
295
295
  return result;
296
296
  };
297
297
 
298
- const setDeepValue = (obj, keys, value) => {
298
+ const setDeepValue = (obj: any, keys: string[], value: any) => {
299
299
  let current = obj;
300
- keys.forEach((key, index) => {
300
+ keys.forEach((key: any, index: number) => {
301
301
  if (index === keys.length - 1) {
302
302
  current[key] = value;
303
303
  } else {