infront-logger 1.1.3 → 1.1.5

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/dist/index.es.js CHANGED
@@ -427,7 +427,8 @@ class MongooseLogger extends BaseLogger {
427
427
  }
428
428
  async explain(query) {
429
429
  if (this.options.explain && !query.options.explain) {
430
- this.ctx.explain = await query.clone().explain();
430
+ let { command, executionStats, queryPlanner } = await query.clone().explain();
431
+ this.ctx.explain = { command, executionStats, queryPlanner };
431
432
  }
432
433
  }
433
434
  result(res) {
@@ -449,16 +450,25 @@ class MongooseLogger extends BaseLogger {
449
450
  }
450
451
  }
451
452
  async function postHook(target, res) {
452
- var _a, _b, _c, _d, _e, _f;
453
- if (target.options.explain)
453
+ var _a, _b, _c, _d, _e, _f, _g;
454
+ if ((_a = target == null ? void 0 : target.options) == null ? void 0 : _a.explain)
454
455
  return;
455
456
  const op = target.constructor.name === "Aggregate" ? "aggregate" : target.op || target.$op;
456
- const collection = ((_a = target == null ? void 0 : target._collection) == null ? void 0 : _a.collectionName) || ((_b = target == null ? void 0 : target.collection) == null ? void 0 : _b.name) || ((_d = (_c = target == null ? void 0 : target._model) == null ? void 0 : _c.collection) == null ? void 0 : _d.collectionName);
457
- (_e = target == null ? void 0 : target.logger) == null ? void 0 : _e.operation(op).collection(collection).query(target._conditions).update(target._update).pipeline(target._pipeline).profile().result(res);
457
+ const collection = ((_b = target == null ? void 0 : target._collection) == null ? void 0 : _b.collectionName) || ((_c = target == null ? void 0 : target.collection) == null ? void 0 : _c.name) || ((_e = (_d = target == null ? void 0 : target._model) == null ? void 0 : _d.collection) == null ? void 0 : _e.collectionName);
458
+ if (!op || !collection) {
459
+ try {
460
+ let { logger, ...t } = target;
461
+ target == null ? void 0 : target.logger.profile().result(res).context("target", t).info(`DB query with bad target}`);
462
+ } catch (err) {
463
+ console.error(err);
464
+ }
465
+ return;
466
+ }
467
+ (_f = target == null ? void 0 : target.logger) == null ? void 0 : _f.operation(op).collection(collection).query(target._conditions).update(target._update).pipeline(target._pipeline).profile().result(res);
458
468
  if (explained.includes(op)) {
459
469
  await (target == null ? void 0 : target.logger.explain(target));
460
470
  }
461
- (_f = target == null ? void 0 : target.logger) == null ? void 0 : _f.info(`DB query: ${op} - ${collection}`);
471
+ (_g = target == null ? void 0 : target.logger) == null ? void 0 : _g.info(`DB query: ${op} - ${collection}`);
462
472
  }
463
473
  function plugin(options = {}) {
464
474
  return (schema) => {
package/dist/index.umd.js CHANGED
@@ -431,7 +431,8 @@
431
431
  }
432
432
  async explain(query) {
433
433
  if (this.options.explain && !query.options.explain) {
434
- this.ctx.explain = await query.clone().explain();
434
+ let { command, executionStats, queryPlanner } = await query.clone().explain();
435
+ this.ctx.explain = { command, executionStats, queryPlanner };
435
436
  }
436
437
  }
437
438
  result(res) {
@@ -453,16 +454,25 @@
453
454
  }
454
455
  }
455
456
  async function postHook(target, res) {
456
- var _a, _b, _c, _d, _e, _f;
457
- if (target.options.explain)
457
+ var _a, _b, _c, _d, _e, _f, _g;
458
+ if ((_a = target == null ? void 0 : target.options) == null ? void 0 : _a.explain)
458
459
  return;
459
460
  const op = target.constructor.name === "Aggregate" ? "aggregate" : target.op || target.$op;
460
- const collection = ((_a = target == null ? void 0 : target._collection) == null ? void 0 : _a.collectionName) || ((_b = target == null ? void 0 : target.collection) == null ? void 0 : _b.name) || ((_d = (_c = target == null ? void 0 : target._model) == null ? void 0 : _c.collection) == null ? void 0 : _d.collectionName);
461
- (_e = target == null ? void 0 : target.logger) == null ? void 0 : _e.operation(op).collection(collection).query(target._conditions).update(target._update).pipeline(target._pipeline).profile().result(res);
461
+ const collection = ((_b = target == null ? void 0 : target._collection) == null ? void 0 : _b.collectionName) || ((_c = target == null ? void 0 : target.collection) == null ? void 0 : _c.name) || ((_e = (_d = target == null ? void 0 : target._model) == null ? void 0 : _d.collection) == null ? void 0 : _e.collectionName);
462
+ if (!op || !collection) {
463
+ try {
464
+ let { logger, ...t } = target;
465
+ target == null ? void 0 : target.logger.profile().result(res).context("target", t).info(`DB query with bad target}`);
466
+ } catch (err) {
467
+ console.error(err);
468
+ }
469
+ return;
470
+ }
471
+ (_f = target == null ? void 0 : target.logger) == null ? void 0 : _f.operation(op).collection(collection).query(target._conditions).update(target._update).pipeline(target._pipeline).profile().result(res);
462
472
  if (explained.includes(op)) {
463
473
  await (target == null ? void 0 : target.logger.explain(target));
464
474
  }
465
- (_f = target == null ? void 0 : target.logger) == null ? void 0 : _f.info(`DB query: ${op} - ${collection}`);
475
+ (_g = target == null ? void 0 : target.logger) == null ? void 0 : _g.info(`DB query: ${op} - ${collection}`);
466
476
  }
467
477
  function plugin(options = {}) {
468
478
  return (schema) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "infront-logger",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "",
5
5
  "files": [
6
6
  "dist"