@forinda/kickjs-devtools 3.2.0 → 4.0.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/README.md CHANGED
@@ -1,60 +1,37 @@
1
1
  # @forinda/kickjs-devtools
2
2
 
3
- Development introspection dashboard for KickJS — routes, DI container, metrics, and health.
3
+ Dev introspection dashboard — routes, DI container state, request metrics, p50/p95/p99 latency, error-rate alerts, dependency graph, SSE stream. Mounted under `/_debug` and gated by an auto-generated token.
4
4
 
5
5
  ## Install
6
6
 
7
7
  ```bash
8
- # Using the KickJS CLI (recommended — installs as dev dependency)
9
8
  kick add devtools
10
-
11
- # Manual install
12
- pnpm add -D @forinda/kickjs-devtools
13
9
  ```
14
10
 
15
- ## Features
16
-
17
- - `DevToolsAdapter` — lifecycle adapter that mounts debug endpoints
18
- - Route inspection, DI container state, request metrics, health checks
19
- - Config exposure with prefix-based redaction
20
- - Error rate threshold alerts
21
- - Reactive state snapshot via `/_debug/state`
22
-
23
- ## Debug Endpoints
24
-
25
- | Endpoint | Description |
26
- |----------|-------------|
27
- | `GET /_debug/routes` | All registered routes with middleware |
28
- | `GET /_debug/container` | DI container state |
29
- | `GET /_debug/metrics` | Request counts, error rate, latency |
30
- | `GET /_debug/health` | Health status (200 or 503) |
31
- | `GET /_debug/state` | Full reactive state snapshot |
32
- | `GET /_debug/config` | Sanitized environment variables |
33
-
34
11
  ## Quick Example
35
12
 
36
- ```typescript
13
+ ```ts
14
+ import { bootstrap, getEnv } from '@forinda/kickjs'
37
15
  import { DevToolsAdapter } from '@forinda/kickjs-devtools'
16
+ import { modules } from './modules'
38
17
 
39
- bootstrap({
18
+ export const app = await bootstrap({
40
19
  modules,
41
20
  adapters: [
42
- new DevToolsAdapter({
43
- enabled: true,
21
+ DevToolsAdapter({
22
+ secret: getEnv('NODE_ENV') === 'production' ? undefined : false,
44
23
  exposeConfig: true,
45
24
  configPrefixes: ['APP_', 'NODE_ENV', 'PORT'],
46
- errorRateThreshold: 0.3,
47
- onErrorRateExceeded: (rate) => {
48
- console.warn(`Error rate: ${(rate * 100).toFixed(1)}%`)
49
- },
50
25
  }),
51
26
  ],
52
27
  })
53
28
  ```
54
29
 
30
+ Endpoints (token-gated unless `secret: false`): `/_debug/{routes,container,metrics,health,state,config,graph,stream,ws,queues}` — plus a Vue + Tailwind dashboard at `/_debug/`.
31
+
55
32
  ## Documentation
56
33
 
57
- [Full documentation](https://forinda.github.io/kick-js/guide/devtools)
34
+ [forinda.github.io/kick-js/guide/devtools](https://forinda.github.io/kick-js/guide/devtools)
58
35
 
59
36
  ## License
60
37
 
package/dist/index.d.mts CHANGED
@@ -1,5 +1,7 @@
1
1
 
2
- import { AdapterContext, AdapterMiddleware, AppAdapter, ComputedRef, Ref } from "@forinda/kickjs";
2
+ import * as _$_forinda_kickjs0 from "@forinda/kickjs";
3
+ import { ComputedRef, Ref } from "@forinda/kickjs";
4
+ import { MemoryAnalyzer, RuntimeSampler } from "@forinda/kickjs-devtools-kit";
3
5
 
4
6
  //#region src/adapter.d.ts
5
7
  /** Per-route latency stats with percentile tracking */
@@ -35,10 +37,57 @@ interface DevToolsOptions {
35
37
  *
36
38
  * @example
37
39
  * ```ts
38
- * new DevToolsAdapter({ secret: process.env.DEVTOOLS_SECRET })
40
+ * DevToolsAdapter({ secret: getEnv('DEVTOOLS_SECRET') })
39
41
  * ```
40
42
  */
41
43
  secret?: string | false;
44
+ /**
45
+ * Tuning for the runtime sampler that powers `/_debug/runtime` and
46
+ * the upcoming Memory tab (architecture.md §23). Defaults to
47
+ * 1-second polling with a 60-sample (~1 minute) ring buffer.
48
+ *
49
+ * Set `runtime.enabled = false` to skip starting the sampler — the
50
+ * `/_debug/runtime` endpoint then returns 404 instead of an empty
51
+ * snapshot, signalling deliberate opt-out rather than a startup race.
52
+ */
53
+ runtime?: {
54
+ /** Whether to start the runtime sampler at all. Default: true. */enabled?: boolean; /** Polling interval in milliseconds. Default: 1000. */
55
+ intervalMs?: number; /** Ring-buffer size — number of past samples retained. Default: 60. */
56
+ bufferSize?: number;
57
+ };
58
+ }
59
+ /**
60
+ * Public reactive surface exposed by a DevToolsAdapter instance —
61
+ * counters, computed metrics, and the route latency map. Tests and
62
+ * peer adapters consume these directly to drive their own behavior.
63
+ */
64
+ interface DevToolsAdapterExtensions {
65
+ /** Total requests received. */
66
+ readonly requestCount: Ref<number>;
67
+ /** Total responses with status >= 500. */
68
+ readonly errorCount: Ref<number>;
69
+ /** Total responses with status >= 400 and < 500. */
70
+ readonly clientErrorCount: Ref<number>;
71
+ /** Server start time. */
72
+ readonly startedAt: Ref<number>;
73
+ /** Computed error rate (server errors / total requests). */
74
+ readonly errorRate: ComputedRef<number>;
75
+ /** Computed uptime in seconds. */
76
+ readonly uptimeSeconds: ComputedRef<number>;
77
+ /** Per-route latency tracking. */
78
+ readonly routeLatency: Record<string, RouteStats>;
79
+ /**
80
+ * Tier-1 runtime sampler from `@forinda/kickjs-devtools-kit`. `null`
81
+ * when `runtime.enabled` is `false`. Tests can `latest()` and
82
+ * `history()` directly without going through the HTTP endpoint.
83
+ */
84
+ readonly runtimeSampler: RuntimeSampler | null;
85
+ /**
86
+ * Memory analyzer fed by the runtime sampler. `null` when the
87
+ * sampler is disabled. Use `analyzer.health(sampler.history())` to
88
+ * compose a composite memory-health snapshot.
89
+ */
90
+ readonly memoryAnalyzer: MemoryAnalyzer | null;
42
91
  }
43
92
  /**
44
93
  * DevToolsAdapter — Vue-style reactive introspection for KickJS applications.
@@ -58,7 +107,7 @@ interface DevToolsOptions {
58
107
  * bootstrap({
59
108
  * modules: [UserModule],
60
109
  * adapters: [
61
- * new DevToolsAdapter({
110
+ * DevToolsAdapter({
62
111
  * enabled: process.env.NODE_ENV !== 'production',
63
112
  * exposeConfig: true,
64
113
  * configPrefixes: ['APP_', 'DATABASE_'],
@@ -67,52 +116,7 @@ interface DevToolsOptions {
67
116
  * })
68
117
  * ```
69
118
  */
70
- declare class DevToolsAdapter implements AppAdapter {
71
- readonly name = "DevToolsAdapter";
72
- private basePath;
73
- private enabled;
74
- private exposeConfig;
75
- private configPrefixes;
76
- private errorRateThreshold;
77
- private secret;
78
- /** Total requests received */
79
- readonly requestCount: Ref<number>;
80
- /** Total responses with status >= 500 */
81
- readonly errorCount: Ref<number>;
82
- /** Total responses with status >= 400 and < 500 */
83
- readonly clientErrorCount: Ref<number>;
84
- /** Server start time */
85
- readonly startedAt: Ref<number>;
86
- /** Computed error rate (server errors / total requests) */
87
- readonly errorRate: ComputedRef<number>;
88
- /** Computed uptime in seconds */
89
- readonly uptimeSeconds: ComputedRef<number>;
90
- /** Per-route latency tracking */
91
- readonly routeLatency: Record<string, RouteStats>;
92
- private routes;
93
- private container;
94
- private appRef;
95
- private adapterStatuses;
96
- private stopErrorWatch;
97
- private peerAdapters;
98
- constructor(options?: DevToolsOptions);
99
- /**
100
- * Resolve peer adapters at request time. Prefers live adapters from the
101
- * Application registry (survives HMR rebuild) and falls back to the
102
- * constructor-provided refs.
103
- */
104
- private getPeerAdapters;
105
- beforeMount({
106
- app,
107
- container
108
- }: AdapterContext): void;
109
- middleware(): AdapterMiddleware[];
110
- onRouteMount(controllerClass: any, mountPath: string): void;
111
- afterStart({}: AdapterContext): void;
112
- shutdown(): void;
113
- /** Find the public/devtools directory relative to the built dist or source */
114
- private resolvePublicDir;
115
- }
119
+ declare const DevToolsAdapter: _$_forinda_kickjs0.AdapterFactory<DevToolsOptions, DevToolsAdapterExtensions>;
116
120
  //#endregion
117
121
  export { DevToolsAdapter, type DevToolsOptions };
118
122
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/adapter.ts"],"mappings":";;;;;UAmCU,UAAA;EACR,KAAA;EACA,OAAA;EACA,KAAA;EACA,KAAA;EAJkB;EAMlB,OAAA;AAAA;AAAA,UAsBe,eAAA;EAxBf;EA0BA,QAAA;EAxBO;EA0BP,OAAA;EAJe;EAMf,YAAA;;EAEA,cAAA;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