@dudousxd/nestjs-telescope-mikro-orm 1.11.1 → 1.12.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.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @dudousxd/nestjs-telescope-mikro-orm
|
|
2
2
|
|
|
3
|
+
## 1.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#25](https://github.com/DavideCarvalho/nestjs-telescope/pull/25) [`b8b6dcd`](https://github.com/DavideCarvalho/nestjs-telescope/commit/b8b6dcd3bb2fc29d6c287b00d4d75c0a149a4b56) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Add a `silent` option to `telescopeMikroOrmLogger` so queries can be captured without spamming the console.
|
|
8
|
+
|
|
9
|
+
MikroORM only calls the logger while `debug` is enabled, but `debug` also echoes every query to stdout — which makes local debugging painful once Telescope is wired in. Passing `{ silent: true }` swaps MikroORM's writer for a no-op so queries still flow into Telescope (correlated to the active ALS batch, slow-tagged, hashed for N+1) while nothing is printed:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
loggerFactory: telescopeMikroOrmLogger(
|
|
13
|
+
(input) => telescope.record(input),
|
|
14
|
+
{ slowMs: 100, silent: true },
|
|
15
|
+
),
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`silent` defaults to `false`, preserving the previous tee-to-console behavior.
|
|
19
|
+
|
|
3
20
|
## 1.11.1
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -68,6 +68,23 @@ Queries recorded via `telescopeMikroOrmLogger` automatically inherit the active
|
|
|
68
68
|
ALS batch opened by the request middleware, so each query entry is correlated to
|
|
69
69
|
the request that triggered it.
|
|
70
70
|
|
|
71
|
+
### Capturing without console noise
|
|
72
|
+
|
|
73
|
+
Capture only works while MikroORM's `debug` is enabled — that's what makes it
|
|
74
|
+
call the logger. But `debug` also echoes every query to stdout, which drowns your
|
|
75
|
+
logs. To feed Telescope **without** the console spam, pass `silent: true`:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
loggerFactory: telescopeMikroOrmLogger(
|
|
79
|
+
(input) => telescope.record(input),
|
|
80
|
+
{ slowMs: 100, silent: true }, // record into Telescope, but no stdout echo
|
|
81
|
+
),
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Keep `debug: ['query']` enabled — `silent` swaps MikroORM's writer for a no-op,
|
|
85
|
+
so queries still flow into Telescope while nothing is printed. Leave `silent`
|
|
86
|
+
off (the default) if you want queries in both Telescope and the console.
|
|
87
|
+
|
|
71
88
|
## N+1 detection
|
|
72
89
|
|
|
73
90
|
```ts
|
|
@@ -152,7 +169,7 @@ How it works:
|
|
|
152
169
|
| Export | Description |
|
|
153
170
|
|--------|-------------|
|
|
154
171
|
| `MikroOrmQueryWatcher` | Watcher marker — add to `TelescopeModule.forRoot({ watchers })` |
|
|
155
|
-
| `telescopeMikroOrmLogger(record, opts?)` | `loggerFactory`-compatible factory; `opts.slowMs` defaults to `100` |
|
|
172
|
+
| `telescopeMikroOrmLogger(record, opts?)` | `loggerFactory`-compatible factory; `opts.slowMs` defaults to `100`, `opts.silent` (default `false`) suppresses MikroORM's console output while still recording |
|
|
156
173
|
| `TelescopeMikroOrmLogger` | `DefaultLogger` subclass (advanced: extend or instantiate directly) |
|
|
157
174
|
| `MikroOrmStorageProvider` | `StorageProvider` persisting entries to MySQL/SQLite; owns a dedicated scoped connection and self-heals its schema at boot |
|
|
158
175
|
| `TelescopeEntry` | `EntitySchema` for table `telescope_entries` (owned internally by the provider; exported for advanced use — you don't register it) |
|
|
@@ -3,6 +3,12 @@ import { DefaultLogger, type LogContext, type LoggerOptions } from '@mikro-orm/c
|
|
|
3
3
|
export interface TelescopeLoggerOptions {
|
|
4
4
|
/** Queries at/above this many ms get a 'slow' tag. Default 100. */
|
|
5
5
|
slowMs?: number;
|
|
6
|
+
/**
|
|
7
|
+
* Suppress MikroORM's own console output while still recording into Telescope.
|
|
8
|
+
* Enable this when `debug` is only turned on to feed Telescope and you don't
|
|
9
|
+
* want every query echoed to stdout. Default false.
|
|
10
|
+
*/
|
|
11
|
+
silent?: boolean;
|
|
6
12
|
}
|
|
7
13
|
/** A MikroORM DefaultLogger subclass that tees every executed query into
|
|
8
14
|
* `record`, while preserving MikroORM's own logging behavior via super. */
|
|
@@ -20,7 +26,8 @@ export declare class TelescopeMikroOrmLogger extends DefaultLogger {
|
|
|
20
26
|
* ```ts
|
|
21
27
|
* MikroORM.init({
|
|
22
28
|
* debug: ['query'],
|
|
23
|
-
*
|
|
29
|
+
* // Capture queries for Telescope without spamming the console:
|
|
30
|
+
* loggerFactory: telescopeMikroOrmLogger(record, { slowMs: 100, silent: true }),
|
|
24
31
|
* });
|
|
25
32
|
* ```
|
|
26
33
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telescope-mikro-orm.logger.d.ts","sourceRoot":"","sources":["../src/telescope-mikro-orm.logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,WAAW,EAAmB,MAAM,4BAA4B,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErF,MAAM,WAAW,sBAAsB;IACrC,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"telescope-mikro-orm.logger.d.ts","sourceRoot":"","sources":["../src/telescope-mikro-orm.logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,WAAW,EAAmB,MAAM,4BAA4B,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErF,MAAM,WAAW,sBAAsB;IACrC,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;4EAC4E;AAC5E,qBAAa,uBAAwB,SAAQ,aAAa;IAGtD,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAFvB,OAAO,EAAE,aAAa,EACL,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,EACrC,MAAM,EAAE,MAAM;IAMxB,QAAQ,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,UAAU,GAAG,IAAI;CAmBjE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,EACpC,OAAO,GAAE,sBAA2B,GACnC,CAAC,aAAa,EAAE,aAAa,KAAK,uBAAuB,CAY3D"}
|
|
@@ -38,12 +38,17 @@ export class TelescopeMikroOrmLogger extends DefaultLogger {
|
|
|
38
38
|
* ```ts
|
|
39
39
|
* MikroORM.init({
|
|
40
40
|
* debug: ['query'],
|
|
41
|
-
*
|
|
41
|
+
* // Capture queries for Telescope without spamming the console:
|
|
42
|
+
* loggerFactory: telescopeMikroOrmLogger(record, { slowMs: 100, silent: true }),
|
|
42
43
|
* });
|
|
43
44
|
* ```
|
|
44
45
|
*/
|
|
45
46
|
export function telescopeMikroOrmLogger(record, options = {}) {
|
|
46
47
|
const slowMs = options.slowMs ?? 100;
|
|
47
|
-
|
|
48
|
+
const silent = options.silent ?? false;
|
|
49
|
+
// When silent, swap MikroORM's writer for a no-op so `super.logQuery` records
|
|
50
|
+
// into Telescope but never echoes to stdout. Queries still flow because the
|
|
51
|
+
// host keeps `debug` enabled — only the console output is dropped.
|
|
52
|
+
return (loggerOptions) => new TelescopeMikroOrmLogger(silent ? { ...loggerOptions, writer: () => undefined } : loggerOptions, record, slowMs);
|
|
48
53
|
}
|
|
49
54
|
//# sourceMappingURL=telescope-mikro-orm.logger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telescope-mikro-orm.logger.js","sourceRoot":"","sources":["../src/telescope-mikro-orm.logger.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAE,SAAS,EAAoB,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAuC,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"telescope-mikro-orm.logger.js","sourceRoot":"","sources":["../src/telescope-mikro-orm.logger.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAE,SAAS,EAAoB,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAuC,MAAM,iBAAiB,CAAC;AAarF;4EAC4E;AAC5E,MAAM,OAAO,uBAAwB,SAAQ,aAAa;IAGrC;IACA;IAHnB,YACE,OAAsB,EACL,OAAqC,EACrC,MAAc;QAE/B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHE,YAAO,GAAP,OAAO,CAA8B;QACrC,WAAM,GAAN,MAAM,CAAQ;IAGjC,CAAC;IAED,+DAA+D;IACtD,QAAQ,CAAC,OAAuC;QACvD,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC;QAC1B,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,IAAI,GAAG,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;YACpE,MAAM,IAAI,GAAa,IAAI,KAAK,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5E,IAAI,CAAC,OAAO,CAAC;gBACX,IAAI,EAAE,SAAS,CAAC,KAAK;gBACrB,OAAO,EAAE;oBACP,GAAG;oBACH,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;oBAClE,IAAI;iBACL;gBACD,UAAU,EAAE,eAAe,CAAC,GAAG,CAAC;gBAChC,UAAU,EAAE,IAAI;gBAChB,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACrC,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;CACF;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAAoC,EACpC,UAAkC,EAAE;IAEpC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,GAAG,CAAC;IACrC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC;IACvC,8EAA8E;IAC9E,4EAA4E;IAC5E,mEAAmE;IACnE,OAAO,CAAC,aAA4B,EAAE,EAAE,CACtC,IAAI,uBAAuB,CACzB,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,aAAa,EACtE,MAAM,EACN,MAAM,CACP,CAAC;AACN,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudousxd/nestjs-telescope-mikro-orm",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "MikroORM query watcher for @dudousxd/nestjs-telescope.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@nestjs/common": ">=10.0.0",
|
|
33
33
|
"@nestjs/core": ">=10.0.0",
|
|
34
34
|
"reflect-metadata": ">=0.1.13",
|
|
35
|
-
"@dudousxd/nestjs-telescope": "^1.
|
|
35
|
+
"@dudousxd/nestjs-telescope": "^1.12.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@mikro-orm/core": "^7.0.0",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"supertest": "^7.0.0",
|
|
51
51
|
"typescript": "^5.4.0",
|
|
52
52
|
"vitest": "^3.0.0",
|
|
53
|
-
"@dudousxd/nestjs-telescope": "1.
|
|
53
|
+
"@dudousxd/nestjs-telescope": "1.12.0"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": ">=20"
|