@angelitosystems/nest-devtools 1.0.10 → 1.0.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.
package/dist/index.cjs CHANGED
@@ -953,10 +953,20 @@ var DatabaseInstrumentation = class {
953
953
  attach() {
954
954
  const cleanup = [];
955
955
  if (!this.config.capture.database) return () => cleanup.forEach((fn) => fn());
956
- if (this.tryAttachTypeOrm()) cleanup.push(this.detachTypeOrm());
957
- if (this.tryAttachPrisma()) cleanup.push(this.detachPrisma());
958
- if (this.tryAttachMongoose()) cleanup.push(this.detachMongoose());
959
- return () => cleanup.forEach((fn) => fn());
956
+ let disposed = false;
957
+ queueMicrotask(() => {
958
+ if (disposed) return;
959
+ try {
960
+ if (this.tryAttachTypeOrm()) cleanup.push(this.detachTypeOrm());
961
+ if (this.tryAttachPrisma()) cleanup.push(this.detachPrisma());
962
+ if (this.tryAttachMongoose()) cleanup.push(this.detachMongoose());
963
+ } catch {
964
+ }
965
+ });
966
+ return () => {
967
+ disposed = true;
968
+ cleanup.splice(0).forEach((fn) => fn());
969
+ };
960
970
  }
961
971
  tryAttachTypeOrm() {
962
972
  try {
@@ -1049,6 +1059,12 @@ var DatabaseInstrumentation = class {
1049
1059
  });
1050
1060
  return true;
1051
1061
  }
1062
+ if (typeof prisma.$on === "function") {
1063
+ prisma.$on("query", (event) => {
1064
+ this.endQuery(event.query ?? "prisma.query", event.params ? [event.params] : [], event.duration ?? 0);
1065
+ });
1066
+ return true;
1067
+ }
1052
1068
  const original = prisma.$queryRaw ?? prisma.$executeRaw ?? null;
1053
1069
  if (!original) return false;
1054
1070
  const wrapped = (query, parameters) => {
@@ -1192,7 +1208,7 @@ var DatabaseInstrumentation = class {
1192
1208
  }
1193
1209
  resolveTypeOrmDataSource(app) {
1194
1210
  try {
1195
- const dataSource = this.findProvider(app, (value) => typeof value?.query === "function" && typeof value?.manager === "object");
1211
+ const dataSource = this.findProvider(app, /data.?source|typeorm/i, (value) => typeof value?.query === "function" && typeof value?.manager === "object");
1196
1212
  if (dataSource) return dataSource;
1197
1213
  return null;
1198
1214
  } catch {
@@ -1201,8 +1217,12 @@ var DatabaseInstrumentation = class {
1201
1217
  }
1202
1218
  resolvePrismaClient(app) {
1203
1219
  try {
1204
- const prisma = this.safeGet(app, "PrismaService") ?? this.safeGet(app, "PrismaClient") ?? this.safeGet(app, "prisma") ?? this.findProvider(app, (value) => typeof value?.$queryRaw === "function");
1205
- if (prisma && typeof prisma.$queryRaw === "function") return prisma;
1220
+ const prisma = this.findProvider(
1221
+ app,
1222
+ /prisma/i,
1223
+ (value) => typeof value?.$queryRaw === "function" && typeof value?.$connect === "function" && typeof value?.$disconnect === "function"
1224
+ );
1225
+ if (prisma && typeof prisma.$queryRaw === "function" && typeof prisma.$connect === "function") return prisma;
1206
1226
  return null;
1207
1227
  } catch {
1208
1228
  return null;
@@ -1210,27 +1230,25 @@ var DatabaseInstrumentation = class {
1210
1230
  }
1211
1231
  resolveMongoose(app) {
1212
1232
  try {
1213
- const mongoose = this.safeGet(app, "MongooseService") ?? this.safeGet(app, "Mongoose") ?? this.safeGet(app, "mongoose") ?? this.findProvider(app, (value) => typeof value?.plugin === "function");
1233
+ const mongoose = this.findProvider(app, /mongoose/i, (value) => typeof value?.plugin === "function");
1214
1234
  if (mongoose && typeof mongoose.plugin === "function") return mongoose;
1215
1235
  return null;
1216
1236
  } catch {
1217
1237
  return null;
1218
1238
  }
1219
1239
  }
1220
- safeGet(app, token) {
1221
- try {
1222
- return app?.get?.(token, { strict: false }) ?? null;
1223
- } catch {
1224
- return null;
1225
- }
1226
- }
1227
- findProvider(app, predicate) {
1240
+ findProvider(app, namePattern, predicate) {
1228
1241
  try {
1229
1242
  const modules = app?.container?.getModules?.() ?? /* @__PURE__ */ new Map();
1230
1243
  for (const module2 of modules.values()) {
1231
- for (const wrapper of module2.providers?.values?.() ?? []) {
1232
- const instance = wrapper?.instance;
1233
- if (instance && predicate(instance)) return instance;
1244
+ for (const [token, wrapper] of module2.providers?.entries?.() ?? []) {
1245
+ const name = String(wrapper?.name ?? wrapper?.metatype?.name ?? token ?? "");
1246
+ if (!namePattern.test(name)) continue;
1247
+ try {
1248
+ const instance = wrapper?.instance;
1249
+ if (instance && predicate(instance)) return instance;
1250
+ } catch {
1251
+ }
1234
1252
  }
1235
1253
  }
1236
1254
  return null;
@@ -1410,7 +1428,7 @@ function detectNestJsVersion() {
1410
1428
  }
1411
1429
 
1412
1430
  // src/version.ts
1413
- var SDK_VERSION = "1.0.10";
1431
+ var SDK_VERSION = "1.0.12";
1414
1432
 
1415
1433
  // src/banner.ts
1416
1434
  var RESET = "\x1B[0m";
@@ -1595,7 +1613,7 @@ var NestDevTools = class {
1595
1613
  registerCleanup(new WebsocketInstrumentation({ config, projectInfo }).attach());
1596
1614
  }
1597
1615
  if (config.capture.database) {
1598
- registerCleanup(new DatabaseInstrumentation({ config, projectInfo }).attach());
1616
+ registerCleanup(new DatabaseInstrumentation({ config, projectInfo, app }).attach());
1599
1617
  }
1600
1618
  registerCleanup(new QueueEventInstrumentation({ config, projectInfo }).attach());
1601
1619
  printStartupBanner({