brakit 0.7.4 → 0.7.5

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/api.d.ts CHANGED
@@ -101,6 +101,54 @@ type TelemetryEvent = {
101
101
  data: Omit<TracedQuery, "id">;
102
102
  };
103
103
 
104
+ interface SessionMetric {
105
+ sessionId: string;
106
+ startedAt: number;
107
+ avgDurationMs: number;
108
+ p95DurationMs: number;
109
+ requestCount: number;
110
+ errorCount: number;
111
+ avgQueryCount: number;
112
+ avgQueryTimeMs: number;
113
+ avgFetchTimeMs: number;
114
+ }
115
+ interface EndpointMetrics {
116
+ endpoint: string;
117
+ sessions: SessionMetric[];
118
+ dataPoints?: LiveRequestPoint[];
119
+ }
120
+ interface MetricsData {
121
+ version: 1;
122
+ endpoints: EndpointMetrics[];
123
+ }
124
+ interface LiveRequestPoint {
125
+ timestamp: number;
126
+ durationMs: number;
127
+ statusCode: number;
128
+ queryCount: number;
129
+ queryTimeMs: number;
130
+ fetchTimeMs: number;
131
+ }
132
+ interface LiveEndpointSummary {
133
+ p95Ms: number;
134
+ errorRate: number;
135
+ avgQueryCount: number;
136
+ totalRequests: number;
137
+ avgQueryTimeMs: number;
138
+ avgFetchTimeMs: number;
139
+ avgAppTimeMs: number;
140
+ }
141
+ interface LiveEndpointData {
142
+ endpoint: string;
143
+ requests: LiveRequestPoint[];
144
+ summary: LiveEndpointSummary;
145
+ }
146
+ interface RequestMetrics {
147
+ queryCount: number;
148
+ queryTimeMs: number;
149
+ fetchTimeMs: number;
150
+ }
151
+
104
152
  type SecuritySeverity = "critical" | "warning" | "info";
105
153
  interface SecurityFinding {
106
154
  severity: SecuritySeverity;
@@ -140,7 +188,7 @@ declare class SecurityScanner {
140
188
  declare function createDefaultScanner(): SecurityScanner;
141
189
 
142
190
  type InsightSeverity = "critical" | "warning" | "info";
143
- type InsightType = "n1" | "cross-endpoint" | "redundant-query" | "error" | "error-hotspot" | "duplicate" | "slow" | "query-heavy" | "select-star" | "high-rows" | "large-response" | "response-overfetch" | "security";
191
+ type InsightType = "n1" | "cross-endpoint" | "redundant-query" | "error" | "error-hotspot" | "duplicate" | "slow" | "query-heavy" | "select-star" | "high-rows" | "large-response" | "response-overfetch" | "security" | "regression";
144
192
  interface Insight {
145
193
  severity: InsightSeverity;
146
194
  type: InsightType;
@@ -155,8 +203,44 @@ interface InsightContext {
155
203
  queries: readonly TracedQuery[];
156
204
  errors: readonly TracedError[];
157
205
  flows: readonly RequestFlow[];
206
+ fetches: readonly TracedFetch[];
207
+ previousMetrics?: readonly EndpointMetrics[];
158
208
  securityFindings?: readonly SecurityFinding[];
159
209
  }
210
+ interface EndpointGroup {
211
+ total: number;
212
+ errors: number;
213
+ totalDuration: number;
214
+ queryCount: number;
215
+ totalSize: number;
216
+ totalQueryTimeMs: number;
217
+ totalFetchTimeMs: number;
218
+ queryShapeDurations: Map<string, {
219
+ totalMs: number;
220
+ count: number;
221
+ label: string;
222
+ }>;
223
+ }
224
+ interface PreparedInsightContext extends InsightContext {
225
+ nonStatic: readonly TracedRequest[];
226
+ queriesByReq: ReadonlyMap<string, TracedQuery[]>;
227
+ fetchesByReq: ReadonlyMap<string, TracedFetch[]>;
228
+ reqById: ReadonlyMap<string, TracedRequest>;
229
+ endpointGroups: ReadonlyMap<string, EndpointGroup>;
230
+ }
231
+
232
+ interface InsightRule {
233
+ id: InsightType;
234
+ check(ctx: PreparedInsightContext): Insight[];
235
+ }
236
+
237
+ declare class InsightRunner {
238
+ private rules;
239
+ register(rule: InsightRule): void;
240
+ run(ctx: InsightContext): Insight[];
241
+ }
242
+
243
+ declare function createDefaultInsightRunner(): InsightRunner;
160
244
  declare function computeInsights(ctx: InsightContext): Insight[];
161
245
 
162
246
  declare function detectProject(rootDir: string): Promise<DetectedProject>;
@@ -170,8 +254,37 @@ declare class AdapterRegistry {
170
254
  getActive(): readonly BrakitAdapter[];
171
255
  }
172
256
 
257
+ interface MetricsPersistence {
258
+ load(): MetricsData;
259
+ save(data: MetricsData): void;
260
+ saveSync(data: MetricsData): void;
261
+ remove(): void;
262
+ }
263
+
264
+ declare class MetricsStore {
265
+ private persistence;
266
+ private data;
267
+ private endpointIndex;
268
+ private sessionId;
269
+ private sessionStart;
270
+ private flushTimer;
271
+ private accumulators;
272
+ private pendingPoints;
273
+ constructor(persistence: MetricsPersistence);
274
+ start(): void;
275
+ stop(): void;
276
+ recordRequest(req: TracedRequest, metrics: RequestMetrics): void;
277
+ getAll(): readonly EndpointMetrics[];
278
+ getEndpoint(endpoint: string): EndpointMetrics | undefined;
279
+ getLiveEndpoints(): LiveEndpointData[];
280
+ reset(): void;
281
+ flush(sync?: boolean): void;
282
+ private getOrCreateEndpoint;
283
+ }
284
+
173
285
  type AnalysisListener = (insights: Insight[], findings: SecurityFinding[]) => void;
174
286
  declare class AnalysisEngine {
287
+ private metricsStore;
175
288
  private debounceMs;
176
289
  private scanner;
177
290
  private cachedInsights;
@@ -182,7 +295,7 @@ declare class AnalysisEngine {
182
295
  private boundQueryListener;
183
296
  private boundErrorListener;
184
297
  private boundLogListener;
185
- constructor(debounceMs?: number);
298
+ constructor(metricsStore: MetricsStore, debounceMs?: number);
186
299
  start(): void;
187
300
  stop(): void;
188
301
  onUpdate(fn: AnalysisListener): void;
@@ -195,4 +308,4 @@ declare class AnalysisEngine {
195
308
 
196
309
  declare const VERSION: string;
197
310
 
198
- export { AdapterRegistry, AnalysisEngine, type BrakitAdapter, type BrakitConfig, type DetectedProject, type FlatHeaders, type Framework, type HttpMethod, type Insight, type InsightContext, type NormalizedOp, type RequestCategory, type RequestListener, type SecurityContext, type SecurityFinding, type SecurityRule, SecurityScanner, type SecuritySeverity, type TracedRequest, VERSION, computeInsights, createDefaultScanner, detectProject };
311
+ export { AdapterRegistry, AnalysisEngine, type BrakitAdapter, type BrakitConfig, type DetectedProject, type FlatHeaders, type Framework, type HttpMethod, type Insight, type InsightContext, type InsightRule, InsightRunner, type NormalizedOp, type RequestCategory, type RequestListener, type SecurityContext, type SecurityFinding, type SecurityRule, SecurityScanner, type SecuritySeverity, type TracedRequest, VERSION, computeInsights, createDefaultInsightRunner, createDefaultScanner, detectProject };