@dnax/core 0.32.0 → 0.34.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,21 @@ 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
+ response = pick(response, col?.api?.fields?.select || []);
572
+ }
573
+ if (
574
+ col?.api?.fields?.hidden?.length &&
575
+ Array.isArray(col?.api?.fields?.hidden?.length)
576
+ ) {
577
+ let privateFields = col?.api?.fields?.hidden || [];
578
+ privateFields.push("password");
579
+ response = omit(response, privateFields);
580
+ } else {
581
+ response = omit(response, ["password"]);
568
582
  }
569
583
 
570
584
  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.32.0",
3
+ "version": "0.34.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
  },
@@ -109,8 +109,17 @@ function isDate(date: string): boolean {
109
109
  const dateRegex3 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/;
110
110
  // le regex pour cette forme 2024-11-30T21:36:12+00:00
111
111
  const dateRegex4 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}$/;
112
+
113
+ // le regex pour cette forme 2024-11-30 21:36:12+00:00
112
114
  const dateRegex5 = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\+\d{2}:\d{2}$/;
113
115
  const dateRegex6 = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\+\d{2}$/;
116
+
117
+ // le regex pour cette forme 2024-11-30T21:36
118
+ const dateRegex7 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/;
119
+
120
+ // le regex pour cette forme 2024-11-30 21:36
121
+ const dateRegex8 = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/;
122
+
114
123
  let isDate_ =
115
124
  !isNaN(Date.parse(date)) &&
116
125
  (dateRegex.test(date) ||
@@ -118,7 +127,9 @@ function isDate(date: string): boolean {
118
127
  dateRegex4.test(date) ||
119
128
  dateRegex5.test(date) ||
120
129
  dateRegex6.test(date) ||
121
- dateRegex3.test(date));
130
+ dateRegex3.test(date) ||
131
+ dateRegex7.test(date) ||
132
+ dateRegex8.test(date));
122
133
  if (isDate_) return true;
123
134
  try {
124
135
  isDate_ = moment(date, "YYYY-MM-DD", true).isValid();
@@ -151,7 +162,7 @@ async function verifyHashPassword(
151
162
  }
152
163
  }
153
164
 
154
- function toDate(data: object | string): object | string {
165
+ function toDate(data: any | string): object | string {
155
166
  if (data) {
156
167
  if (typeof data == "string" && isDate(data)) {
157
168
  data = new Date(data);
@@ -284,9 +295,9 @@ function pick(data: object | object[], keys: string[]): object {
284
295
  return result;
285
296
  };
286
297
 
287
- const setDeepValue = (obj, keys, value) => {
298
+ const setDeepValue = (obj: any, keys: string[], value: any) => {
288
299
  let current = obj;
289
- keys.forEach((key, index) => {
300
+ keys.forEach((key: any, index: number) => {
290
301
  if (index === keys.length - 1) {
291
302
  current[key] = value;
292
303
  } else {