@dnax/core 0.0.4 → 0.0.6

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.
@@ -266,7 +266,7 @@ class useRest {
266
266
  c: this.#c,
267
267
  io: Cfg.io,
268
268
  driver: "mongodb",
269
- result: data,
269
+ result: toJson(data),
270
270
  action: "insertOne",
271
271
  session: sessionStorage(),
272
272
  rest: new useRest({
@@ -367,7 +367,7 @@ class useRest {
367
367
  io: Cfg.io,
368
368
  driver: "mongodb",
369
369
  action: "insertMany",
370
- result: data,
370
+ result: toJson(data),
371
371
  session: sessionStorage(),
372
372
  rest: new useRest({
373
373
  useHook: false,
@@ -709,7 +709,7 @@ class useRest {
709
709
  action: "updateOne",
710
710
  update: update,
711
711
  session: sessionStorage(),
712
- result: result.doc,
712
+ result: toJson(result.doc),
713
713
  rest: new useRest({
714
714
  useHook: false,
715
715
  tenant_id: this.#tenant_id,
@@ -965,7 +965,7 @@ class useRest {
965
965
  action: "updateMany",
966
966
  update: update,
967
967
  session: sessionStorage(),
968
- result: result.docs,
968
+ result: toJson(result.docs),
969
969
  io: Cfg.io,
970
970
  rest: new useRest({
971
971
  useHook: false,
@@ -1059,7 +1059,7 @@ class useRest {
1059
1059
  c: this.#c,
1060
1060
  driver: "mongodb",
1061
1061
  action: "deleteOne",
1062
- result: doc,
1062
+ result: toJson(doc),
1063
1063
  io: Cfg.io,
1064
1064
  session: sessionStorage(),
1065
1065
  rest: new useRest({
@@ -1097,7 +1097,7 @@ class useRest {
1097
1097
  return resolve(result!);
1098
1098
  }
1099
1099
 
1100
- let deletedIds: any = [];
1100
+ let deletedIds: any = ids || [];
1101
1101
 
1102
1102
  if (!ids) fn.error("List of id required", 400);
1103
1103
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {
@@ -19,7 +19,6 @@
19
19
  "consola": "^3.2.3",
20
20
  "cookie": "^0.6.0",
21
21
  "croner": "^8.0.2",
22
- "dayjs": "^1.11.11",
23
22
  "find-open-port": "^2.0.3",
24
23
  "generate-unique-id": "^2.0.3",
25
24
  "hono": "^4.4.3",
package/types/index.ts CHANGED
@@ -121,7 +121,7 @@ export type sessionCtx = {
121
121
 
122
122
  export type hooksCtx = (ctx: {
123
123
  filter?: any;
124
- result?: any;
124
+ result?: any | null | object | undefined;
125
125
  driver?: "mongodb" | "postgres";
126
126
  data?: object;
127
127
  params?: findParam;
package/utils/index.ts CHANGED
@@ -65,9 +65,13 @@ const jwt = {
65
65
  },
66
66
  };
67
67
 
68
- function toJson(data: object) {
69
- let obj = JSON.stringify(data);
70
- return JSON.parse(obj);
68
+ function toJson(data: object): object | null | undefined | any {
69
+ try {
70
+ let obj = JSON.stringify(data);
71
+ return JSON.parse(obj);
72
+ } catch (err) {
73
+ return data;
74
+ }
71
75
  }
72
76
 
73
77
  function isDate(date: string): boolean {
@@ -75,7 +79,7 @@ function isDate(date: string): boolean {
75
79
  let isDate_ = !isNaN(Date.parse(date)) && dateRegex.test(date);
76
80
  if (isDate_) return true;
77
81
  try {
78
- isDate_ = dayjs(date).isValid();
82
+ isDate_ = moment(date, "YYYY-MM-DD", true).isValid();
79
83
  } catch (err) {}
80
84
  return isDate_;
81
85
  }