Skip to main content

Class: ModelWatcher

Defined in: watchers/model.watcher.ts:112

ModelWatcher tracks ORM operations (TypeORM and Prisma) including entity changes, query performance, and data modifications while masking sensitive fields.

Implements​

  • OnModuleInit
  • OnModuleDestroy

Constructors​

Constructor​

new ModelWatcher(collector, nestlensConfig, entitySubscriber?): ModelWatcher

Defined in: watchers/model.watcher.ts:140

Parameters​

collector​

CollectorService

nestlensConfig​

NestLensConfig

entitySubscriber?​

unknown

Returns​

ModelWatcher

Methods​

onModuleDestroy()​

onModuleDestroy(): void

Defined in: watchers/model.watcher.ts:255

Puts the subscriber's hooks back.

The subscriber belongs to the application and outlives this module, so without this the host goes on recording through a watcher whose collector is gone — and a process that builds the module more than once against the same subscriber, as tests and nest start --hmr do, wraps each round on top of the last.

Returns​

void

Implementation of​

OnModuleDestroy.onModuleDestroy


onModuleInit()​

onModuleInit(): void

Defined in: watchers/model.watcher.ts:187

Returns​

void

Implementation of​

OnModuleInit.onModuleInit


setupPrismaClient()​

setupPrismaClient<T>(prismaClient): T

Defined in: watchers/model.watcher.ts:280

Records what a Prisma client runs, and hands back the client to use.

Two integrations, because Prisma has had two. $use is the middleware API of Prisma 5 and earlier; Prisma removed it in 6.0 — the package does not carry it at all — and client extensions took its place. This watcher knew only the first, so on Prisma 6 and 7 the documented setup recorded nothing and said Invalid Prisma client provided, blaming a client that was perfectly valid.

Use the client this returns. A middleware is installed into the client it was given, so there it is the same object; an extension is not — Prisma returns a new client with the extension applied, and queries run through the original are not recorded. Returning it either way makes one line correct on both:

this.prisma = this.modelWatcher.setupPrismaClient(this.prisma);

Type Parameters​

T​

T

Parameters​

prismaClient​

T

Returns​

T