@drax/crud-back 0.49.0 → 0.51.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.
@@ -10,7 +10,7 @@ class AbstractService {
10
10
  async create(data) {
11
11
  try {
12
12
  if (this._schema) {
13
- await this._schema.parseAsync(data);
13
+ data = await this._schema.parseAsync(data);
14
14
  }
15
15
  if (this.transformCreate) {
16
16
  data = await this.transformCreate(data);
@@ -22,7 +22,11 @@ class AbstractService {
22
22
  return item;
23
23
  }
24
24
  catch (e) {
25
- console.error("Error creating", e);
25
+ console.error("Error create", {
26
+ name: e?.name,
27
+ message: e?.message,
28
+ stack: e?.stack,
29
+ });
26
30
  if (e instanceof ZodError) {
27
31
  throw ZodErrorToValidationError(e, data);
28
32
  }
@@ -32,7 +36,7 @@ class AbstractService {
32
36
  async update(id, data) {
33
37
  try {
34
38
  if (this._schema) {
35
- await this._schema.parseAsync(data);
39
+ data = await this._schema.parseAsync(data);
36
40
  }
37
41
  if (this.transformUpdate) {
38
42
  data = await this.transformUpdate(data);
@@ -44,7 +48,11 @@ class AbstractService {
44
48
  return item;
45
49
  }
46
50
  catch (e) {
47
- console.error("Error updating", e);
51
+ console.error("Error update", {
52
+ name: e?.name,
53
+ message: e?.message,
54
+ stack: e?.stack,
55
+ });
48
56
  if (e instanceof ZodError) {
49
57
  throw ZodErrorToValidationError(e, data);
50
58
  }
@@ -54,7 +62,7 @@ class AbstractService {
54
62
  async updatePartial(id, data) {
55
63
  try {
56
64
  if (this._schema) {
57
- await this._schema.partial().parseAsync(data);
65
+ data = await this._schema.partial().parseAsync(data);
58
66
  }
59
67
  const item = await this._repository.updatePartial(id, data);
60
68
  if (this.onUpdated) {
@@ -63,7 +71,11 @@ class AbstractService {
63
71
  return item;
64
72
  }
65
73
  catch (e) {
66
- console.error("Error updating", e);
74
+ console.error("Error updatePartial", {
75
+ name: e?.name,
76
+ message: e?.message,
77
+ stack: e?.stack,
78
+ });
67
79
  if (e instanceof ZodError) {
68
80
  throw ZodErrorToValidationError(e, data);
69
81
  }
@@ -82,7 +94,11 @@ class AbstractService {
82
94
  return result;
83
95
  }
84
96
  catch (e) {
85
- console.error("Error deleting", e);
97
+ console.error("Error delete", {
98
+ name: e?.name,
99
+ message: e?.message,
100
+ stack: e?.stack,
101
+ });
86
102
  throw e;
87
103
  }
88
104
  }
@@ -95,7 +111,11 @@ class AbstractService {
95
111
  return item;
96
112
  }
97
113
  catch (e) {
98
- console.error("Error finding Auto by id", e);
114
+ console.error("Error findById", {
115
+ name: e?.name,
116
+ message: e?.message,
117
+ stack: e?.stack,
118
+ });
99
119
  throw e;
100
120
  }
101
121
  }
@@ -108,7 +128,11 @@ class AbstractService {
108
128
  return items;
109
129
  }
110
130
  catch (e) {
111
- console.error("Error finding Auto by id", e);
131
+ console.error("Error findByIds", {
132
+ name: e?.name,
133
+ message: e?.message,
134
+ stack: e?.stack,
135
+ });
112
136
  throw e;
113
137
  }
114
138
  }
@@ -121,7 +145,11 @@ class AbstractService {
121
145
  return item;
122
146
  }
123
147
  catch (e) {
124
- console.error("Error finding Auto findOneBy", e);
148
+ console.error("Error findOneBy", {
149
+ name: e?.name,
150
+ message: e?.message,
151
+ stack: e?.stack,
152
+ });
125
153
  throw e;
126
154
  }
127
155
  }
@@ -134,7 +162,11 @@ class AbstractService {
134
162
  return items;
135
163
  }
136
164
  catch (e) {
137
- console.error("Error finding Auto findBy", e);
165
+ console.error("Error findBy", {
166
+ name: e?.name,
167
+ message: e?.message,
168
+ stack: e?.stack,
169
+ });
138
170
  throw e;
139
171
  }
140
172
  }
@@ -147,7 +179,11 @@ class AbstractService {
147
179
  return items;
148
180
  }
149
181
  catch (e) {
150
- console.error("Error fetching all Autos", e);
182
+ console.error("Error fetchAll", {
183
+ name: e?.name,
184
+ message: e?.message,
185
+ stack: e?.stack,
186
+ });
151
187
  throw e;
152
188
  }
153
189
  }
@@ -160,7 +196,11 @@ class AbstractService {
160
196
  return items;
161
197
  }
162
198
  catch (e) {
163
- console.error("Error fetching all Autos", e);
199
+ console.error("Error search", {
200
+ name: e?.name,
201
+ message: e?.message,
202
+ stack: e?.stack,
203
+ });
164
204
  throw e;
165
205
  }
166
206
  }
@@ -173,7 +213,11 @@ class AbstractService {
173
213
  return pagination;
174
214
  }
175
215
  catch (e) {
176
- console.error("Error paginating", e);
216
+ console.error("Error paginate", {
217
+ name: e?.name,
218
+ message: e?.message,
219
+ stack: e?.stack,
220
+ });
177
221
  throw e;
178
222
  }
179
223
  }
@@ -186,7 +230,11 @@ class AbstractService {
186
230
  return items;
187
231
  }
188
232
  catch (e) {
189
- console.error("Error find", e);
233
+ console.error("Error find", {
234
+ name: e?.name,
235
+ message: e?.message,
236
+ stack: e?.stack,
237
+ });
190
238
  throw e;
191
239
  }
192
240
  }
@@ -196,7 +244,11 @@ class AbstractService {
196
244
  return item;
197
245
  }
198
246
  catch (e) {
199
- console.error("Error findOne", e);
247
+ console.error("Error findOne", {
248
+ name: e?.name,
249
+ message: e?.message,
250
+ stack: e?.stack,
251
+ });
200
252
  throw e;
201
253
  }
202
254
  }
@@ -225,7 +277,11 @@ class AbstractService {
225
277
  }
226
278
  }
227
279
  catch (e) {
228
- console.error("Error exporting", e);
280
+ console.error("Error export", {
281
+ name: e?.name,
282
+ message: e?.message,
283
+ stack: e?.stack,
284
+ });
229
285
  throw e;
230
286
  }
231
287
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.49.0",
6
+ "version": "0.51.0",
7
7
  "description": "Crud utils across modules",
8
8
  "main": "dist/index.js",
9
9
  "types": "types/index.d.ts",
@@ -22,19 +22,21 @@
22
22
  "author": "Cristian Incarnato & Drax Team",
23
23
  "license": "ISC",
24
24
  "dependencies": {
25
- "@drax/common-back": "^0.49.0",
26
- "@drax/common-share": "^0.49.0",
27
- "@drax/identity-share": "^0.49.0",
28
- "@drax/media-back": "^0.49.0",
25
+ "@drax/common-back": "^0.51.0",
26
+ "@drax/common-share": "^0.51.0",
27
+ "@drax/identity-share": "^0.51.0",
28
+ "@drax/media-back": "^0.51.0",
29
29
  "@graphql-tools/load-files": "^7.0.0",
30
30
  "@graphql-tools/merge": "^9.0.4",
31
- "mongoose": "^8.6.3",
31
+ "mongoose": "^8.21.0",
32
32
  "mongoose-lean-virtuals": "^1.1.0",
33
33
  "mongoose-paginate-v2": "^1.8.3"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "dayjs": "^1.11.19",
37
- "mongoose-paginate-v2": "^1.8.3"
37
+ "mongoose-paginate-v2": "^1.8.3",
38
+ "zod": "^3.25.76",
39
+ "zod-to-json-schema": "3.24.6"
38
40
  },
39
41
  "devDependencies": {
40
42
  "@types/node": "^20.12.10",
@@ -45,5 +47,5 @@
45
47
  "tsc-alias": "^1.8.10",
46
48
  "typescript": "^5.6.2"
47
49
  },
48
- "gitHead": "ea99f6fd79d282e6efe02fca660d5733c13bb86d"
50
+ "gitHead": "a8fe4fe11637e3b899686b8dd8d658d62933ea5a"
49
51
  }
@@ -39,7 +39,7 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
39
39
  async create(data: C): Promise<T> {
40
40
  try {
41
41
  if (this._schema) {
42
- await this._schema.parseAsync(data)
42
+ data = await this._schema.parseAsync(data) as C
43
43
  }
44
44
  if (this.transformCreate) {
45
45
  data = await this.transformCreate(data)
@@ -50,7 +50,11 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
50
50
  }
51
51
  return item
52
52
  } catch (e) {
53
- console.error("Error creating", e)
53
+ console.error("Error create", {
54
+ name: e?.name,
55
+ message: e?.message,
56
+ stack: e?.stack,
57
+ });
54
58
  if (e instanceof ZodError) {
55
59
  throw ZodErrorToValidationError(e, data)
56
60
  }
@@ -61,7 +65,7 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
61
65
  async update(id: string, data: U): Promise<T> {
62
66
  try {
63
67
  if (this._schema) {
64
- await this._schema.parseAsync(data)
68
+ data = await this._schema.parseAsync(data) as U
65
69
  }
66
70
  if (this.transformUpdate) {
67
71
  data = await this.transformUpdate(data)
@@ -72,7 +76,11 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
72
76
  }
73
77
  return item
74
78
  } catch (e) {
75
- console.error("Error updating", e)
79
+ console.error("Error update", {
80
+ name: e?.name,
81
+ message: e?.message,
82
+ stack: e?.stack,
83
+ });
76
84
  if (e instanceof ZodError) {
77
85
  throw ZodErrorToValidationError(e, data)
78
86
  }
@@ -84,7 +92,7 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
84
92
  try {
85
93
 
86
94
  if (this._schema) {
87
- await this._schema.partial().parseAsync(data)
95
+ data = await this._schema.partial().parseAsync(data)
88
96
  }
89
97
 
90
98
  const item: T = await this._repository.updatePartial(id, data)
@@ -93,7 +101,11 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
93
101
  }
94
102
  return item
95
103
  } catch (e) {
96
- console.error("Error updating", e)
104
+ console.error("Error updatePartial", {
105
+ name: e?.name,
106
+ message: e?.message,
107
+ stack: e?.stack,
108
+ });
97
109
  if (e instanceof ZodError) {
98
110
  throw ZodErrorToValidationError(e, data)
99
111
  }
@@ -112,7 +124,11 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
112
124
  }
113
125
  return result;
114
126
  } catch (e) {
115
- console.error("Error deleting", e)
127
+ console.error("Error delete", {
128
+ name: e?.name,
129
+ message: e?.message,
130
+ stack: e?.stack,
131
+ });
116
132
  throw e;
117
133
  }
118
134
 
@@ -126,7 +142,11 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
126
142
  }
127
143
  return item
128
144
  } catch (e) {
129
- console.error("Error finding Auto by id", e)
145
+ console.error("Error findById", {
146
+ name: e?.name,
147
+ message: e?.message,
148
+ stack: e?.stack,
149
+ });
130
150
  throw e;
131
151
  }
132
152
  }
@@ -139,7 +159,11 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
139
159
  }
140
160
  return items
141
161
  } catch (e) {
142
- console.error("Error finding Auto by id", e)
162
+ console.error("Error findByIds", {
163
+ name: e?.name,
164
+ message: e?.message,
165
+ stack: e?.stack,
166
+ });
143
167
  throw e;
144
168
  }
145
169
  }
@@ -152,7 +176,11 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
152
176
  }
153
177
  return item
154
178
  } catch (e) {
155
- console.error("Error finding Auto findOneBy", e)
179
+ console.error("Error findOneBy", {
180
+ name: e?.name,
181
+ message: e?.message,
182
+ stack: e?.stack,
183
+ });
156
184
  throw e;
157
185
  }
158
186
 
@@ -167,7 +195,11 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
167
195
  }
168
196
  return items
169
197
  } catch (e) {
170
- console.error("Error finding Auto findBy", e)
198
+ console.error("Error findBy", {
199
+ name: e?.name,
200
+ message: e?.message,
201
+ stack: e?.stack,
202
+ });
171
203
  throw e;
172
204
  }
173
205
 
@@ -181,7 +213,11 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
181
213
  }
182
214
  return items
183
215
  } catch (e) {
184
- console.error("Error fetching all Autos", e)
216
+ console.error("Error fetchAll", {
217
+ name: e?.name,
218
+ message: e?.message,
219
+ stack: e?.stack,
220
+ });
185
221
  throw e;
186
222
  }
187
223
 
@@ -196,7 +232,11 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
196
232
  }
197
233
  return items
198
234
  } catch (e) {
199
- console.error("Error fetching all Autos", e)
235
+ console.error("Error search", {
236
+ name: e?.name,
237
+ message: e?.message,
238
+ stack: e?.stack,
239
+ });
200
240
  throw e;
201
241
  }
202
242
 
@@ -221,7 +261,11 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
221
261
 
222
262
  return pagination;
223
263
  } catch (e) {
224
- console.error("Error paginating", e)
264
+ console.error("Error paginate", {
265
+ name: e?.name,
266
+ message: e?.message,
267
+ stack: e?.stack,
268
+ });
225
269
  throw e;
226
270
  }
227
271
 
@@ -242,7 +286,11 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
242
286
  }
243
287
  return items;
244
288
  } catch (e) {
245
- console.error("Error find", e)
289
+ console.error("Error find", {
290
+ name: e?.name,
291
+ message: e?.message,
292
+ stack: e?.stack,
293
+ });
246
294
  throw e;
247
295
  }
248
296
 
@@ -256,7 +304,11 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
256
304
  let item = await this._repository.findOne({search, filters});
257
305
  return item;
258
306
  } catch (e) {
259
- console.error("Error findOne", e)
307
+ console.error("Error findOne", {
308
+ name: e?.name,
309
+ message: e?.message,
310
+ stack: e?.stack,
311
+ });
260
312
  throw e;
261
313
  }
262
314
 
@@ -301,7 +353,11 @@ abstract class AbstractService<T, C, U> implements IDraxCrudService<T, C, U> {
301
353
  }
302
354
 
303
355
  } catch (e) {
304
- console.error("Error exporting", e)
356
+ console.error("Error export", {
357
+ name: e?.name,
358
+ message: e?.message,
359
+ stack: e?.stack,
360
+ });
305
361
  throw e;
306
362
  }
307
363