@stravigor/devtools 0.4.2 → 0.4.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stravigor/devtools",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "type": "module",
5
5
  "description": "Debug inspector and performance monitor for the Strav framework",
6
6
  "license": "MIT",
@@ -18,7 +18,7 @@
18
18
  "tsconfig.json"
19
19
  ],
20
20
  "peerDependencies": {
21
- "@stravigor/core": "0.3.3"
21
+ "@stravigor/core": "0.4.3"
22
22
  },
23
23
  "scripts": {
24
24
  "test": "bun test tests/",
@@ -1,10 +1,19 @@
1
1
  import { ServiceProvider } from '@stravigor/core/core'
2
2
  import type { Application } from '@stravigor/core/core'
3
+ import type Context from '@stravigor/core/http/context'
4
+ import Router from '@stravigor/core/http/router'
3
5
  import DevtoolsManager from './devtools_manager.ts'
6
+ import { registerDashboard } from './dashboard/routes.ts'
4
7
 
5
8
  export interface DevtoolsProviderOptions {
6
- /** Whether to auto-create the devtools tables. Default: `true` */
9
+ /** Auto-create the devtools tables. Default: `true` */
7
10
  ensureTables?: boolean
11
+ /** Auto-register the request-tracking middleware on the router. Default: `true` */
12
+ middleware?: boolean
13
+ /** Auto-register the dashboard routes at `/_devtools`. Default: `true` */
14
+ dashboard?: boolean
15
+ /** Custom auth guard for the dashboard. Receives the request context, returns boolean. */
16
+ guard?: (ctx: Context) => boolean | Promise<boolean>
8
17
  }
9
18
 
10
19
  export default class DevtoolsProvider extends ServiceProvider {
@@ -25,6 +34,18 @@ export default class DevtoolsProvider extends ServiceProvider {
25
34
  if (this.options?.ensureTables !== false) {
26
35
  await DevtoolsManager.ensureTables()
27
36
  }
37
+
38
+ if (!DevtoolsManager.config.enabled) return
39
+
40
+ const router = app.resolve(Router)
41
+
42
+ if (this.options?.middleware !== false) {
43
+ router.use(DevtoolsManager.middleware())
44
+ }
45
+
46
+ if (this.options?.dashboard !== false) {
47
+ registerDashboard(router, this.options?.guard)
48
+ }
28
49
  }
29
50
 
30
51
  override shutdown(): void {