@runnerpro/backend 1.16.11 → 1.16.12

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.
@@ -54,8 +54,10 @@ const query = (queryText, values = []) => __awaiter(void 0, void 0, void 0, func
54
54
  });
55
55
  }
56
56
  catch (error) {
57
+ // Logging mejorado con información detallada del error
58
+ const enhancedError = enhancePostgreSQLError(error, queryText, values);
57
59
  // eslint-disable-next-line no-console
58
- console.error('PG query error', error);
60
+ console.error('PG query error', enhancedError);
59
61
  return [];
60
62
  }
61
63
  });
@@ -81,8 +83,10 @@ const queryWithClient = (queryText, values = [], _retry = false) => __awaiter(vo
81
83
  });
82
84
  }
83
85
  catch (error) {
86
+ // Logging mejorado con información detallada del error
87
+ const enhancedError = enhancePostgreSQLError(error, queryText, values);
84
88
  // eslint-disable-next-line no-console
85
- console.error('PG query error', error);
89
+ console.error('PG query error', enhancedError);
86
90
  // Liberar conexión como rota si es necesario
87
91
  if (['EPIPE', 'ECONNRESET', '57P01', 'ECONNREFUSED'].includes(error.code)) {
88
92
  if (client) {
@@ -197,6 +201,81 @@ function camelize(str) {
197
201
  function sleep(ms) {
198
202
  return new Promise((resolve) => setTimeout(resolve, ms));
199
203
  }
204
+ // ✅ Función para mejorar el logging de errores PostgreSQL
205
+ function enhancePostgreSQLError(error, queryText, values = []) {
206
+ const enhancedError = Object.assign(Object.assign({}, error), {
207
+ // Información básica del error
208
+ message: error.message, code: error.code, severity: error.severity, detail: error.detail, hint: error.hint, position: error.position,
209
+ // Información de la query que falló
210
+ query: {
211
+ original: queryText,
212
+ parsed: getParseQuery(queryText, values),
213
+ values: values,
214
+ length: queryText.length
215
+ },
216
+ // Información contextual del error
217
+ context: {
218
+ // Si hay posición del error, extraer el contexto
219
+ errorPosition: error.position ? parseInt(error.position) : null,
220
+ errorContext: error.position ? getErrorContext(queryText, parseInt(error.position)) : null,
221
+ // Información de tabla y columna si está disponible
222
+ table: error.table || extractTableFromQuery(queryText),
223
+ column: error.column || extractColumnFromQuery(queryText, error.position),
224
+ schema: error.schema,
225
+ // Información adicional
226
+ constraint: error.constraint,
227
+ dataType: error.dataType,
228
+ file: error.file,
229
+ line: error.line,
230
+ routine: error.routine
231
+ },
232
+ // Timestamp del error
233
+ timestamp: new Date().toISOString(),
234
+ // Stack trace completo
235
+ stack: error.stack });
236
+ return enhancedError;
237
+ }
238
+ // ✅ Función para extraer contexto del error en la query
239
+ function getErrorContext(queryText, position, contextLength = 50) {
240
+ if (!position || position < 0)
241
+ return null;
242
+ const start = Math.max(0, position - contextLength);
243
+ const end = Math.min(queryText.length, position + contextLength);
244
+ const before = queryText.substring(start, position);
245
+ const after = queryText.substring(position, end);
246
+ return {
247
+ before: before,
248
+ after: after,
249
+ position: position - start, // Posición relativa en el contexto
250
+ fullContext: queryText.substring(start, end)
251
+ };
252
+ }
253
+ // ✅ Función para extraer nombre de tabla de la query
254
+ function extractTableFromQuery(queryText) {
255
+ const tableRegex = /(?:FROM|UPDATE|INSERT\s+INTO|DELETE\s+FROM)\s+([a-zA-Z_][a-zA-Z0-9_]*)/i;
256
+ const match = queryText.match(tableRegex);
257
+ return match ? match[1] : null;
258
+ }
259
+ // ✅ Función para extraer nombre de columna de la query
260
+ function extractColumnFromQuery(queryText, position) {
261
+ if (!position)
262
+ return null;
263
+ // Buscar la palabra más cercana a la posición del error
264
+ const words = queryText.split(/\s+/);
265
+ let currentPos = 0;
266
+ for (const word of words) {
267
+ const wordStart = queryText.indexOf(word, currentPos);
268
+ const wordEnd = wordStart + word.length;
269
+ if (position >= wordStart && position <= wordEnd) {
270
+ // Verificar si parece un nombre de columna
271
+ if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(word)) {
272
+ return word;
273
+ }
274
+ }
275
+ currentPos = wordEnd;
276
+ }
277
+ return null;
278
+ }
200
279
  // ✅ Manejo de cierre mejorado
201
280
  const gracefulShutdown = () => __awaiter(void 0, void 0, void 0, function* () {
202
281
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/db/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,IAAI,CAAC;AAI5B,QAAA,MAAM,IAAI,iBAaR,CAAC;AASH,QAAA,MAAM,KAAK,cAAqB,MAAM,WAAU,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,iBAuB5E,CAAC;AAGF,QAAA,MAAM,eAAe,cAAqB,MAAM,WAAU,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,0BAiDtF,CAAC;AAGF,QAAA,MAAM,UAAU,YAAmB,GAAG,EAAE,uCAmBvC,CAAC;AAGF,QAAA,MAAM,gBAAgB,cACT,MAAM,WACT,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,qCAyBtC,CAAC;AAGF,QAAA,MAAM,SAAS,QAAS,MAAM,EAAE,WAM/B,CAAC;AAkDF,OAAO,EACL,KAAK,EAAE,oCAAoC;AAC3C,eAAe,EAAE,wBAAwB;AACzC,gBAAgB,EAAE,uBAAuB;AACzC,UAAU,EAAE,aAAa;AACzB,SAAS,EAAE,WAAW;AACtB,IAAI,GACL,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/db/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,IAAI,CAAC;AAI5B,QAAA,MAAM,IAAI,iBAaR,CAAC;AASH,QAAA,MAAM,KAAK,cAAqB,MAAM,WAAU,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,iBAyB5E,CAAC;AAGF,QAAA,MAAM,eAAe,cAAqB,MAAM,WAAU,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,0BAmDtF,CAAC;AAGF,QAAA,MAAM,UAAU,YAAmB,GAAG,EAAE,uCAmBvC,CAAC;AAGF,QAAA,MAAM,gBAAgB,cACT,MAAM,WACT,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,qCAyBtC,CAAC;AAGF,QAAA,MAAM,SAAS,QAAS,MAAM,EAAE,WAM/B,CAAC;AAoJF,OAAO,EACL,KAAK,EAAE,oCAAoC;AAC3C,eAAe,EAAE,wBAAwB;AACzC,gBAAgB,EAAE,uBAAuB;AACzC,UAAU,EAAE,aAAa;AACzB,SAAS,EAAE,WAAW;AACtB,IAAI,GACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.16.11",
3
+ "version": "1.16.12",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"