@warlock.js/devtools 5.59.0 → 5.61.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.
Files changed (154) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/cjs/{app-versions-DfpPZOI2.cjs → app-versions-C_ZyzuvD.cjs} +1 -116
  3. package/cjs/app-versions-C_ZyzuvD.cjs.map +1 -0
  4. package/cjs/attach-D5aMqUnA.cjs +1342 -0
  5. package/cjs/attach-D5aMqUnA.cjs.map +1 -0
  6. package/cjs/{auth-B3wyjJnQ.cjs → auth-ChHh5E7j.cjs} +6 -6
  7. package/cjs/{auth-B3wyjJnQ.cjs.map → auth-ChHh5E7j.cjs.map} +1 -1
  8. package/cjs/{boot-nczSvJ_F.cjs → boot-D0nF-7w3.cjs} +78 -14
  9. package/cjs/boot-D0nF-7w3.cjs.map +1 -0
  10. package/cjs/{capture-CuyT8Vab.cjs → capture-D2k0GnBN.cjs} +23 -422
  11. package/cjs/capture-D2k0GnBN.cjs.map +1 -0
  12. package/cjs/{cascade-store-CuRRYzt_.cjs → cascade-store-DUT2Laha.cjs} +3 -3
  13. package/cjs/{cascade-store-CuRRYzt_.cjs.map → cascade-store-DUT2Laha.cjs.map} +1 -1
  14. package/cjs/{collector-CJbQbzzK.cjs → collector-BfC4v87v.cjs} +4 -46
  15. package/cjs/collector-BfC4v87v.cjs.map +1 -0
  16. package/cjs/{current-request-id-CeQhRz9Q.cjs → current-request-id-Badec-TH.cjs} +2 -2
  17. package/cjs/{current-request-id-CeQhRz9Q.cjs.map → current-request-id-Badec-TH.cjs.map} +1 -1
  18. package/cjs/{errors-BadbSDX8.cjs → errors-DNQ-g49I.cjs} +198 -1
  19. package/cjs/errors-DNQ-g49I.cjs.map +1 -0
  20. package/cjs/extract-8kaX_cUV.cjs +1103 -0
  21. package/cjs/extract-8kaX_cUV.cjs.map +1 -0
  22. package/cjs/{http-Biauhqi0.cjs → http-1nnpAoI7.cjs} +33 -10
  23. package/cjs/http-1nnpAoI7.cjs.map +1 -0
  24. package/cjs/index.cjs +1 -1
  25. package/cjs/{insights-BjJA6Ret.cjs → insights-COA3u37q.cjs} +54 -22
  26. package/cjs/insights-COA3u37q.cjs.map +1 -0
  27. package/cjs/migrations-BQdNOL5_.cjs +30 -0
  28. package/cjs/migrations-BQdNOL5_.cjs.map +1 -0
  29. package/cjs/{migrations-BP4cYTGo.cjs → models-DF1agAm4.cjs} +106 -24
  30. package/cjs/models-DF1agAm4.cjs.map +1 -0
  31. package/cjs/{process-panel-DskSA7Cm.cjs → process-panel-D3D9Y_dc.cjs} +4 -4
  32. package/cjs/{process-panel-DskSA7Cm.cjs.map → process-panel-D3D9Y_dc.cjs.map} +1 -1
  33. package/cjs/production/index.cjs +4 -4
  34. package/cjs/query-shape-DShKQa0x.cjs +45 -0
  35. package/cjs/query-shape-DShKQa0x.cjs.map +1 -0
  36. package/cjs/redact-DQ28mDzr.cjs +533 -0
  37. package/cjs/redact-DQ28mDzr.cjs.map +1 -0
  38. package/cjs/runs-DECWPGnq.cjs +390 -0
  39. package/cjs/runs-DECWPGnq.cjs.map +1 -0
  40. package/cjs/{server-D3XRbSSb.cjs → server-DLT3uPef.cjs} +8 -7
  41. package/cjs/{server-D3XRbSSb.cjs.map → server-DLT3uPef.cjs.map} +1 -1
  42. package/cjs/{src-QcNghoYN.cjs → src-BZiSv8A1.cjs} +182 -24
  43. package/cjs/src-BZiSv8A1.cjs.map +1 -0
  44. package/cjs/{store-CNFv3wVp.cjs → store-EFn4wp0T.cjs} +2 -2
  45. package/cjs/{stream-route-BqyAlfxQ.cjs → stream-route-B6WAjbPG.cjs} +111 -22
  46. package/cjs/stream-route-B6WAjbPG.cjs.map +1 -0
  47. package/esm/ai/attach.mjs +92 -0
  48. package/esm/ai/attach.mjs.map +1 -0
  49. package/esm/ai/options.mjs +31 -0
  50. package/esm/ai/options.mjs.map +1 -0
  51. package/esm/ai/reports/aggregate.mjs +330 -0
  52. package/esm/ai/reports/aggregate.mjs.map +1 -0
  53. package/esm/ai/reports/evaluate.mjs +108 -0
  54. package/esm/ai/reports/evaluate.mjs.map +1 -0
  55. package/esm/ai/reports/range.mjs +121 -0
  56. package/esm/ai/reports/range.mjs.map +1 -0
  57. package/esm/ai/reports/runs.d.mts +2 -0
  58. package/esm/ai/reports/runs.mjs +212 -0
  59. package/esm/ai/reports/runs.mjs.map +1 -0
  60. package/esm/ai/reports/service.mjs +132 -0
  61. package/esm/ai/reports/service.mjs.map +1 -0
  62. package/esm/ai/rollup/cascade-store.mjs +84 -0
  63. package/esm/ai/rollup/cascade-store.mjs.map +1 -0
  64. package/esm/ai/rollup/categories.mjs +67 -0
  65. package/esm/ai/rollup/categories.mjs.map +1 -0
  66. package/esm/ai/rollup/extract.mjs +225 -0
  67. package/esm/ai/rollup/extract.mjs.map +1 -0
  68. package/esm/ai/rollup/file-store.mjs +147 -0
  69. package/esm/ai/rollup/file-store.mjs.map +1 -0
  70. package/esm/ai/rollup/histogram.mjs +42 -0
  71. package/esm/ai/rollup/histogram.mjs.map +1 -0
  72. package/esm/ai/rollup/increment-error.mjs +19 -0
  73. package/esm/ai/rollup/increment-error.mjs.map +1 -0
  74. package/esm/ai/rollup/index.mjs +9 -0
  75. package/esm/ai/rollup/mapping.mjs +69 -0
  76. package/esm/ai/rollup/mapping.mjs.map +1 -0
  77. package/esm/ai/rollup/memory-store.mjs +26 -0
  78. package/esm/ai/rollup/memory-store.mjs.map +1 -0
  79. package/esm/ai/rollup/writer.mjs +113 -0
  80. package/esm/ai/rollup/writer.mjs.map +1 -0
  81. package/esm/ai/types.d.mts +29 -0
  82. package/esm/ai/types.d.mts.map +1 -0
  83. package/esm/devtools-connector.d.mts.map +1 -1
  84. package/esm/devtools-connector.mjs +58 -3
  85. package/esm/devtools-connector.mjs.map +1 -1
  86. package/esm/index.d.mts +3 -2
  87. package/esm/options.mjs +4 -0
  88. package/esm/options.mjs.map +1 -1
  89. package/esm/production/boot.mjs +70 -3
  90. package/esm/production/boot.mjs.map +1 -1
  91. package/esm/production/contracts.d.mts +388 -6
  92. package/esm/production/contracts.d.mts.map +1 -1
  93. package/esm/production/contracts.mjs +64 -2
  94. package/esm/production/contracts.mjs.map +1 -1
  95. package/esm/production/errors.mjs +8 -0
  96. package/esm/production/errors.mjs.map +1 -1
  97. package/esm/production/http/access.mjs +6 -0
  98. package/esm/production/http/access.mjs.map +1 -1
  99. package/esm/production/http/mount.mjs +21 -2
  100. package/esm/production/http/mount.mjs.map +1 -1
  101. package/esm/production/http/share.mjs.map +1 -1
  102. package/esm/production/index.d.mts +2 -2
  103. package/esm/production/insights/jobs.mjs +45 -11
  104. package/esm/production/insights/jobs.mjs.map +1 -1
  105. package/esm/production/store/migrations.d.mts +1 -1
  106. package/esm/production/store/migrations.d.mts.map +1 -1
  107. package/esm/production/store/migrations.mjs +4 -2
  108. package/esm/production/store/migrations.mjs.map +1 -1
  109. package/esm/production/store/models/ai-rollup.migration.mjs +48 -0
  110. package/esm/production/store/models/ai-rollup.migration.mjs.map +1 -0
  111. package/esm/production/store/models/ai-rollup.model.mjs +13 -0
  112. package/esm/production/store/models/ai-rollup.model.mjs.map +1 -0
  113. package/esm/production/store/models/index.mjs +3 -1
  114. package/esm/server/ai-report-routes.mjs +72 -0
  115. package/esm/server/ai-report-routes.mjs.map +1 -0
  116. package/esm/server/ai-routes.mjs +22 -1
  117. package/esm/server/ai-routes.mjs.map +1 -1
  118. package/esm/server/index.mjs +2 -0
  119. package/esm/server/index.mjs.map +1 -1
  120. package/esm/server/panel-routes.mjs.map +1 -1
  121. package/esm/server/ui-assets.mjs +4 -7
  122. package/esm/server/ui-assets.mjs.map +1 -1
  123. package/esm/sources/agent-trace-source.d.mts.map +1 -1
  124. package/esm/sources/agent-trace-source.mjs.map +1 -1
  125. package/esm/sources/ai-source.d.mts +2 -0
  126. package/esm/sources/ai-source.d.mts.map +1 -1
  127. package/esm/sources/ai-source.mjs +58 -17
  128. package/esm/sources/ai-source.mjs.map +1 -1
  129. package/esm/types.d.mts +13 -3
  130. package/esm/types.d.mts.map +1 -1
  131. package/llms-full.txt +61 -22
  132. package/package.json +8 -8
  133. package/skills/SKILL.md +61 -22
  134. package/ui/dashboard/assets/app.css +1 -1
  135. package/ui/dashboard/assets/app.js +12 -5
  136. package/ui/dashboard/build-info.json +7 -7
  137. package/cjs/ai-source-BdvMfyKw.cjs +0 -448
  138. package/cjs/ai-source-BdvMfyKw.cjs.map +0 -1
  139. package/cjs/app-versions-DfpPZOI2.cjs.map +0 -1
  140. package/cjs/boot-nczSvJ_F.cjs.map +0 -1
  141. package/cjs/capture-CuyT8Vab.cjs.map +0 -1
  142. package/cjs/collector-CJbQbzzK.cjs.map +0 -1
  143. package/cjs/errors-BadbSDX8.cjs.map +0 -1
  144. package/cjs/histogram-DTOGnNBW.cjs +0 -102
  145. package/cjs/histogram-DTOGnNBW.cjs.map +0 -1
  146. package/cjs/http-Biauhqi0.cjs.map +0 -1
  147. package/cjs/insights-BjJA6Ret.cjs.map +0 -1
  148. package/cjs/migrations-BP4cYTGo.cjs.map +0 -1
  149. package/cjs/options-B9FHbRAJ.cjs +0 -205
  150. package/cjs/options-B9FHbRAJ.cjs.map +0 -1
  151. package/cjs/panels-D1ITm-jc.cjs +0 -384
  152. package/cjs/panels-D1ITm-jc.cjs.map +0 -1
  153. package/cjs/src-QcNghoYN.cjs.map +0 -1
  154. package/cjs/stream-route-BqyAlfxQ.cjs.map +0 -1
@@ -1,6 +1,7 @@
1
- const require_collector = require("./collector-CJbQbzzK.cjs");
2
- const require_errors = require("./errors-BadbSDX8.cjs");
3
- const require_histogram = require("./histogram-DTOGnNBW.cjs");
1
+ const require_errors = require("./errors-DNQ-g49I.cjs");
2
+ const require_collector = require("./collector-BfC4v87v.cjs");
3
+ const require_query_shape = require("./query-shape-DShKQa0x.cjs");
4
+ const require_redact = require("./redact-DQ28mDzr.cjs");
4
5
  let _warlock_js_logger = require("@warlock.js/logger");
5
6
 
6
7
  //#region ../../packages/devtools/src/production/capture/dev-stats.ts
@@ -347,406 +348,6 @@ function createShapeExplainer(input) {
347
348
  };
348
349
  }
349
350
 
350
- //#endregion
351
- //#region ../../packages/devtools/src/production/capture/stats-stores.ts
352
- const SHAPE_MAX$1 = 2e3;
353
- const MESSAGE_MAX = 500;
354
- const STACK_MAX = 4e3;
355
- const LOG_MESSAGE_MAX$3 = 1e3;
356
- const PHASES_PER_ROUTE = 30;
357
- const MONGO_EXPLAINABLE = /* @__PURE__ */ new Set([
358
- "find",
359
- "aggregate",
360
- "count"
361
- ]);
362
- const SQL_START = /^(?:\s|--[^\n]*(?:\n|$)|\/\*[\s\S]*?\*\/)*(select|with)\b/i;
363
- /** Whether a normalized query shape can be explained (a Postgres `SELECT`/`WITH`, or a MongoDB `find`/`aggregate`/`count`). */
364
- function isExplainableShape(driver, shape) {
365
- if (driver === "postgres") return SQL_START.test(shape);
366
- const space = shape.indexOf(" ");
367
- const head = space === -1 ? shape : shape.slice(0, space);
368
- const command = head.slice(head.lastIndexOf(".") + 1);
369
- return MONGO_EXPLAINABLE.has(command);
370
- }
371
- const shapeIds = /* @__PURE__ */ new Map();
372
- const SHAPE_ID_CACHE = 2e3;
373
- /** `shortId` of a query shape, remembered: the same few hundred shapes arrive over and over. */
374
- function shapeIdOf(shape) {
375
- let id = shapeIds.get(shape);
376
- if (id === void 0) {
377
- if (shapeIds.size >= SHAPE_ID_CACHE) shapeIds.clear();
378
- id = require_histogram.shortId(shape);
379
- shapeIds.set(shape, id);
380
- }
381
- return id;
382
- }
383
- function truncate(value, maximum) {
384
- return value.length > maximum ? value.slice(0, maximum) : value;
385
- }
386
- function copyHistogram(histogram) {
387
- return {
388
- ...histogram,
389
- counts: [...histogram.counts]
390
- };
391
- }
392
- /** Bounded per-shape query statistics. */
393
- function createQueryStats(limits) {
394
- const entries = /* @__PURE__ */ new Map();
395
- let evictedCount = 0;
396
- const touch = (shape, driver, connection, at) => {
397
- const id = shapeIdOf(shape);
398
- let entry = entries.get(id);
399
- if (entry) {
400
- entries.delete(id);
401
- entry.stats.lastSeen = Math.max(entry.stats.lastSeen, at);
402
- } else entry = {
403
- example: void 0,
404
- stats: {
405
- id,
406
- shape: truncate(shape, SHAPE_MAX$1),
407
- driver,
408
- connection,
409
- count: 0,
410
- errors: 0,
411
- histogram: require_histogram.createHistogram(),
412
- nPlusOne: {
413
- requests: 0,
414
- maxPerRequest: 0
415
- },
416
- slowest: null,
417
- firstSeen: at,
418
- lastSeen: at,
419
- explainable: isExplainableShape(driver, shape)
420
- }
421
- };
422
- entries.set(id, entry);
423
- while (entries.size > limits.maxShapes) {
424
- const oldest = entries.keys().next().value;
425
- entries.delete(oldest);
426
- evictedCount++;
427
- }
428
- return entry;
429
- };
430
- return {
431
- record(query) {
432
- const entry = touch(query.shape, query.driver, query.connection, query.at);
433
- entry.stats.count++;
434
- if (query.failed) entry.stats.errors++;
435
- require_histogram.recordDuration(entry.stats.histogram, query.durationMs);
436
- const slowest = entry.stats.slowest;
437
- if (!slowest || query.durationMs > slowest.durationMs) entry.stats.slowest = {
438
- durationMs: query.durationMs,
439
- at: query.at,
440
- route: query.route,
441
- requestId: query.requestId,
442
- instance: limits.instance
443
- };
444
- },
445
- recordNPlusOne(shape, count) {
446
- const known = entries.get(shapeIdOf(shape))?.stats;
447
- const entry = touch(shape, known?.driver ?? "postgres", known?.connection ?? "", Date.now());
448
- entry.stats.nPlusOne.requests++;
449
- if (count > entry.stats.nPlusOne.maxPerRequest) entry.stats.nPlusOne.maxPerRequest = count;
450
- },
451
- rememberExample(query) {
452
- const entry = touch(query.shape, query.driver, query.connection, query.startedAt);
453
- if (!entry.example || query.durationMs > entry.example.durationMs) entry.example = {
454
- ...query,
455
- ...query.bindings === void 0 ? {} : { bindings: [...query.bindings] }
456
- };
457
- const slowest = entry.stats.slowest;
458
- if (!slowest || query.durationMs > slowest.durationMs) entry.stats.slowest = {
459
- durationMs: query.durationMs,
460
- at: query.startedAt,
461
- route: null,
462
- requestId: null,
463
- instance: limits.instance
464
- };
465
- },
466
- example(shapeId) {
467
- return entries.get(shapeId)?.example;
468
- },
469
- snapshot(limit) {
470
- return [...entries.values()].map(({ stats }) => stats).sort((a, b) => b.histogram.sumMs - a.histogram.sumMs).slice(0, Math.max(0, limit)).map((stats) => ({
471
- ...stats,
472
- histogram: copyHistogram(stats.histogram),
473
- nPlusOne: { ...stats.nPlusOne },
474
- slowest: stats.slowest ? { ...stats.slowest } : null
475
- }));
476
- },
477
- evicted: () => evictedCount,
478
- clear() {
479
- entries.clear();
480
- }
481
- };
482
- }
483
- /** Bounded per-route statistics. */
484
- function createRouteStats(limits) {
485
- const entries = /* @__PURE__ */ new Map();
486
- let evictedCount = 0;
487
- return {
488
- record(request) {
489
- const route = request.route === "" ? "(unmatched)" : request.route;
490
- const key = `${request.method} ${route}`;
491
- let entry = entries.get(key);
492
- if (entry) entries.delete(key);
493
- else entry = {
494
- phases: /* @__PURE__ */ new Map(),
495
- stats: {
496
- key,
497
- method: request.method,
498
- route,
499
- count: 0,
500
- errors: 0,
501
- histogram: require_histogram.createHistogram(),
502
- phases: [],
503
- slowest: null
504
- }
505
- };
506
- entries.set(key, entry);
507
- while (entries.size > limits.maxRoutes) {
508
- entries.delete(entries.keys().next().value);
509
- evictedCount++;
510
- }
511
- entry.stats.count++;
512
- if (request.failed) entry.stats.errors++;
513
- require_histogram.recordDuration(entry.stats.histogram, request.durationMs);
514
- const slowest = entry.stats.slowest;
515
- if (!slowest || request.durationMs > slowest.durationMs) entry.stats.slowest = {
516
- durationMs: request.durationMs,
517
- at: request.at,
518
- requestId: request.requestId,
519
- instance: limits.instance
520
- };
521
- for (const phase of request.phases) {
522
- let stats = entry.phases.get(phase.name);
523
- if (!stats) {
524
- if (entry.phases.size >= PHASES_PER_ROUTE) {
525
- let smallest;
526
- for (const [name, candidate] of entry.phases) if (smallest === void 0 || candidate.sumMs < (entry.phases.get(smallest)?.sumMs ?? 0)) smallest = name;
527
- if (smallest !== void 0) entry.phases.delete(smallest);
528
- }
529
- stats = {
530
- name: phase.name,
531
- count: 0,
532
- sumMs: 0,
533
- maxMs: 0
534
- };
535
- entry.phases.set(phase.name, stats);
536
- }
537
- const duration = Number.isFinite(phase.durationMs) ? Math.max(0, phase.durationMs) : 0;
538
- stats.count++;
539
- stats.sumMs += duration;
540
- if (duration > stats.maxMs) stats.maxMs = duration;
541
- }
542
- },
543
- snapshot(limit) {
544
- return [...entries.values()].sort((a, b) => b.stats.histogram.sumMs - a.stats.histogram.sumMs).slice(0, Math.max(0, limit)).map(({ stats, phases }) => ({
545
- ...stats,
546
- histogram: copyHistogram(stats.histogram),
547
- slowest: stats.slowest ? { ...stats.slowest } : null,
548
- phases: [...phases.values()].sort((a, b) => b.sumMs - a.sumMs).slice(0, PHASES_PER_ROUTE).map((phase) => ({ ...phase }))
549
- }));
550
- },
551
- evicted: () => evictedCount,
552
- clear() {
553
- entries.clear();
554
- }
555
- };
556
- }
557
- const QUOTED$1 = /'(?:''|[^'])*'|"(?:\\.|[^"\\])*"/g;
558
- const UUID = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi;
559
- const EMAIL$1 = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
560
- const HEX_ID = /\b0x[0-9a-f]+\b|\b(?=[0-9a-f]*\d)[0-9a-f]{8,}\b/gi;
561
- /** A random id of letters and digits (request ids, tokens): 16+ characters with both. */
562
- const TOKEN_ID = /\b(?=[A-Za-z0-9_-]*\d)(?=[A-Za-z0-9_-]*[A-Za-z])[A-Za-z0-9_-]{16,}\b/g;
563
- const NUMBER = /\d+(?:\.\d+)?/g;
564
- /**
565
- * Replaces the parts of an error message that change between occurrences
566
- * (quoted strings, emails, UUIDs, hex ids, random ids such as request ids,
567
- * numbers) so equal errors group.
568
- */
569
- function normalizeErrorMessage(message) {
570
- return message.replace(QUOTED$1, "<str>").replace(UUID, "<uuid>").replace(EMAIL$1, "<email>").replace(HEX_ID, "<hex>").replace(TOKEN_ID, "<id>").replace(NUMBER, "<n>");
571
- }
572
- /** Bounded error groups. */
573
- function createErrorGroups(limits) {
574
- const groups = /* @__PURE__ */ new Map();
575
- let evictedCount = 0;
576
- return {
577
- record(input) {
578
- const id = require_histogram.shortId(`${input.source}\n${input.name ?? ""}\n${normalizeErrorMessage(input.message)}\n${input.route ?? ""}`);
579
- const known = groups.get(id);
580
- const message = truncate(input.message, MESSAGE_MAX);
581
- const stack = input.stack === null ? null : truncate(input.stack, STACK_MAX);
582
- if (known) {
583
- groups.delete(id);
584
- known.count++;
585
- known.message = message;
586
- known.lastSeen = Math.max(known.lastSeen, input.at);
587
- known.lastRequestId = input.requestId;
588
- known.status = input.status ?? known.status;
589
- if (stack !== null) known.stack = stack;
590
- groups.set(id, known);
591
- } else groups.set(id, {
592
- id,
593
- message,
594
- name: input.name,
595
- source: input.source,
596
- route: input.route,
597
- status: input.status,
598
- count: 1,
599
- firstSeen: input.at,
600
- lastSeen: input.at,
601
- lastRequestId: input.requestId,
602
- stack
603
- });
604
- while (groups.size > limits.maxGroups) {
605
- groups.delete(groups.keys().next().value);
606
- evictedCount++;
607
- }
608
- },
609
- snapshot(limit) {
610
- return [...groups.values()].sort((a, b) => b.lastSeen - a.lastSeen).slice(0, Math.max(0, limit)).map((group) => ({ ...group }));
611
- },
612
- evicted: () => evictedCount,
613
- clear() {
614
- groups.clear();
615
- }
616
- };
617
- }
618
- /** Recent warn/error log entries, bounded. */
619
- function createRecentLogs(limits) {
620
- const entries = [];
621
- return {
622
- record(entry) {
623
- entries.push({
624
- ...entry,
625
- message: truncate(entry.message, LOG_MESSAGE_MAX$3)
626
- });
627
- while (entries.length > limits.maxEntries) entries.shift();
628
- },
629
- snapshot(limit, filter = {}) {
630
- const module = filter.module?.toLowerCase();
631
- const result = [];
632
- for (let index = entries.length - 1; index >= 0 && result.length < limit; index--) {
633
- const entry = entries[index];
634
- if (filter.level && entry.level !== filter.level) continue;
635
- if (module && !entry.module.toLowerCase().includes(module)) continue;
636
- result.push({ ...entry });
637
- }
638
- return result;
639
- },
640
- clear() {
641
- entries.length = 0;
642
- }
643
- };
644
- }
645
-
646
- //#endregion
647
- //#region ../../packages/devtools/src/production/capture/redact.ts
648
- const SHAPE_MAX = 2e3;
649
- const ERROR_MAX = 500;
650
- const QUERY_ERROR_MAX = 300;
651
- const LOG_MESSAGE_MAX$2 = 1e3;
652
- const QUOTED = /'(?:''|[^'])*'|"(?:\\.|[^"\\])*"/g;
653
- const BRACES = /\{[^{}]*\}/g;
654
- const EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
655
- /**
656
- * Error text without the values a driver or a handler put in it (a duplicate
657
- * key message carries the key): quoted strings, emails and `{ … }` documents
658
- * become `?`, then the text is cut to `max` characters.
659
- */
660
- function scrubErrorText(text, max) {
661
- return truncate(text.replace(QUOTED, "?").replace(EMAIL, "?").replace(BRACES, "{?}"), max);
662
- }
663
- /** A database error message without the values the driver quoted in it. */
664
- function scrubQueryError(message) {
665
- return scrubErrorText(message, QUERY_ERROR_MAX);
666
- }
667
- function redactQuery(query) {
668
- const shape = truncate(query.shape || require_collector.queryShape(query), SHAPE_MAX);
669
- const sample = {
670
- id: query.id,
671
- connection: query.connection,
672
- driver: query.driver,
673
- sql: shape,
674
- shape,
675
- shapeId: shapeIdOf(query.shape || shape),
676
- startedAt: query.startedAt,
677
- durationMs: query.durationMs
678
- };
679
- if (query.collection !== void 0) sample.collection = query.collection;
680
- if (query.command !== void 0) sample.command = query.command;
681
- if (query.rowCount !== void 0) sample.rowCount = query.rowCount;
682
- if (query.error !== void 0) sample.error = scrubQueryError(query.error);
683
- return sample;
684
- }
685
- /**
686
- * Turns a sampled request into a stored sample with every value removed: SQL
687
- * replaced by its shape, no bindings, no Mongo pipeline, no log context, no
688
- * phase attributes, cache operations reduced to counts, no caller paths.
689
- * Headers, bodies, query strings and parameters are not part of a request
690
- * record and never appear.
691
- */
692
- function toStoredSample(request, instance, droppedQueries) {
693
- const path = request.path.split("?")[0] ?? request.path;
694
- const summary = {
695
- id: request.id,
696
- method: request.method,
697
- path,
698
- startedAt: request.startedAt,
699
- queryCount: request.queries.length + droppedQueries,
700
- warningCount: request.warnings.length,
701
- instance
702
- };
703
- if (request.route !== void 0) summary.route = request.route;
704
- if (request.status !== void 0) summary.status = request.status;
705
- if (request.durationMs !== void 0) summary.durationMs = request.durationMs;
706
- let hits = 0;
707
- let misses = 0;
708
- let writes = 0;
709
- for (const operation of request.cache) if (operation.type === "hit") hits++;
710
- else if (operation.type === "miss") misses++;
711
- else if (operation.type === "set") writes++;
712
- const detail = {
713
- ...summary,
714
- phases: request.phases.map((phase) => ({
715
- name: phase.name,
716
- startedAt: phase.startedAt,
717
- durationMs: phase.durationMs
718
- })),
719
- queries: request.queries.map(redactQuery),
720
- cache: {
721
- hits,
722
- misses,
723
- writes
724
- },
725
- logs: request.logs.map((entry) => ({
726
- level: entry.level,
727
- module: entry.module,
728
- action: entry.action,
729
- message: truncate(entry.message, LOG_MESSAGE_MAX$2),
730
- at: entry.at
731
- })),
732
- warnings: request.warnings.map((warning) => ({
733
- type: warning.type,
734
- message: warning.message,
735
- shape: truncate(warning.shape, SHAPE_MAX),
736
- count: warning.count
737
- })),
738
- droppedQueries
739
- };
740
- if (request.error !== void 0) detail.error = scrubErrorText(request.error, ERROR_MAX);
741
- return {
742
- id: request.id,
743
- instance,
744
- startedAt: request.startedAt,
745
- summary,
746
- detail
747
- };
748
- }
749
-
750
351
  //#endregion
751
352
  //#region ../../packages/devtools/src/production/capture/filter.ts
752
353
  /** Whether a stored sample's row passes a request filter (the same rules as the store). */
@@ -793,7 +394,7 @@ function errorMessage(error) {
793
394
  }
794
395
  /** A request's error message as the monitor keeps it: without the values in it (see `scrubErrorText`). */
795
396
  function requestErrorMessage(error) {
796
- return scrubErrorText(errorMessage(error), REQUEST_ERROR_MAX);
397
+ return require_redact.scrubErrorText(errorMessage(error), REQUEST_ERROR_MAX);
797
398
  }
798
399
  function touchesMonitorTables(event) {
799
400
  return event.sql !== void 0 && event.sql.includes("devtools_") || event.collection !== void 0 && event.collection.startsWith("devtools_");
@@ -813,16 +414,16 @@ function createCaptureEngine(deps) {
813
414
  ...deps.options,
814
415
  maxRequests: production.maxRequests
815
416
  });
816
- const queries = createQueryStats({
417
+ const queries = require_redact.createQueryStats({
817
418
  maxShapes: production.maxShapes,
818
419
  instance: instance.id
819
420
  });
820
- const routes = createRouteStats({
421
+ const routes = require_redact.createRouteStats({
821
422
  maxRoutes: production.maxRoutes,
822
423
  instance: instance.id
823
424
  });
824
- const errors = createErrorGroups({ maxGroups: production.maxErrorGroups });
825
- const logs = createRecentLogs({ maxEntries: 200 });
425
+ const errors = require_redact.createErrorGroups({ maxGroups: production.maxErrorGroups });
426
+ const logs = require_redact.createRecentLogs({ maxEntries: 200 });
826
427
  const active = /* @__PURE__ */ new Map();
827
428
  const recent = /* @__PURE__ */ new Map();
828
429
  const pending = [];
@@ -900,7 +501,7 @@ function createCaptureEngine(deps) {
900
501
  source: "request",
901
502
  message: error === void 0 ? `HTTP ${status}` : requestErrorMessage(error),
902
503
  name: error instanceof Error ? error.name : null,
903
- stack: error instanceof Error && error.stack !== void 0 ? scrubErrorText(error.stack, REQUEST_STACK_MAX) : null,
504
+ stack: error instanceof Error && error.stack !== void 0 ? require_redact.scrubErrorText(error.stack, REQUEST_STACK_MAX) : null,
904
505
  route: route ?? null,
905
506
  status: status ?? null,
906
507
  requestId: request.requestId,
@@ -933,7 +534,7 @@ function createCaptureEngine(deps) {
933
534
  });
934
535
  for (const warning of settled.warnings) queries.recordNPlusOne(warning.shape, warning.count);
935
536
  recordRequestError(request, result, route);
936
- enqueue(toStoredSample(settled, instance.id, state.dropped));
537
+ enqueue(require_redact.toStoredSample(settled, instance.id, state.dropped));
937
538
  };
938
539
  const finishUnsampled = (request, result) => {
939
540
  if (deps.isDashboardPath(request.path)) return;
@@ -989,13 +590,13 @@ function createCaptureEngine(deps) {
989
590
  if (event.command !== void 0) input.command = event.command;
990
591
  if (event.pipeline !== void 0) input.pipeline = event.pipeline;
991
592
  if (event.rowCount !== void 0) input.rowCount = event.rowCount;
992
- if (event.error !== void 0) input.error = scrubQueryError(errorMessage(event.error));
593
+ if (event.error !== void 0) input.error = require_redact.scrubQueryError(errorMessage(event.error));
993
594
  return input;
994
595
  };
995
596
  const exampleOf = (event) => ({
996
597
  ...queryInput(event),
997
598
  id: `x${++exampleSequence}`,
998
- shape: require_collector.queryShape(event)
599
+ shape: require_query_shape.queryShape(event)
999
600
  });
1000
601
  const recordQuery = (query, route, requestId) => {
1001
602
  queries.record({
@@ -1041,7 +642,7 @@ function createCaptureEngine(deps) {
1041
642
  const live = collector.getRequest(id);
1042
643
  if (!live) return null;
1043
644
  const dropped = active.get(id)?.dropped ?? 0;
1044
- const sample = toStoredSample(live, instance.id, dropped);
645
+ const sample = require_redact.toStoredSample(live, instance.id, dropped);
1045
646
  return sample.detail ?? sample.summary;
1046
647
  },
1047
648
  async clear() {
@@ -1124,7 +725,7 @@ function createCaptureEngine(deps) {
1124
725
  const wanted = logLevels.has(entry.level);
1125
726
  const state = requestId === void 0 ? void 0 : active.get(requestId);
1126
727
  if (!wanted && !state) return;
1127
- const message = truncate(entry.message, LOG_MESSAGE_MAX$1);
728
+ const message = require_redact.truncate(entry.message, LOG_MESSAGE_MAX$1);
1128
729
  const kept = {
1129
730
  level: entry.level,
1130
731
  module: entry.module,
@@ -1250,7 +851,7 @@ function createProductionCapture(deps) {
1250
851
  async attach() {
1251
852
  if (detach) return detach;
1252
853
  const disposers = [];
1253
- const { currentRequestId } = await Promise.resolve().then(() => require("./current-request-id-CeQhRz9Q.cjs")).then((n) => n.current_request_id_exports);
854
+ const { currentRequestId } = await Promise.resolve().then(() => require("./current-request-id-Badec-TH.cjs")).then((n) => n.current_request_id_exports);
1254
855
  try {
1255
856
  const { registerTracingHooks } = await import("@warlock.js/core");
1256
857
  disposers.push(registerTracingHooks({
@@ -1283,7 +884,7 @@ function createProductionCapture(deps) {
1283
884
  level,
1284
885
  module: data.module,
1285
886
  action: data.action,
1286
- message: level === "error" ? scrubErrorText(text, LOG_MESSAGE_MAX) : text,
887
+ message: level === "error" ? require_redact.scrubErrorText(text, LOG_MESSAGE_MAX) : text,
1287
888
  at: Date.now()
1288
889
  });
1289
890
  }
@@ -1332,11 +933,11 @@ function createProductionCapture(deps) {
1332
933
 
1333
934
  //#endregion
1334
935
  exports.attachDevelopmentStats = attachDevelopmentStats;
1335
- exports.createErrorGroups = createErrorGroups;
936
+ exports.createErrorGroups = require_redact.createErrorGroups;
1336
937
  exports.createProductionCapture = createProductionCapture;
1337
- exports.createQueryStats = createQueryStats;
1338
- exports.createRecentLogs = createRecentLogs;
1339
- exports.createRouteStats = createRouteStats;
938
+ exports.createQueryStats = require_redact.createQueryStats;
939
+ exports.createRecentLogs = require_redact.createRecentLogs;
940
+ exports.createRouteStats = require_redact.createRouteStats;
1340
941
  exports.createShapeExplainer = createShapeExplainer;
1341
- exports.toStoredSample = toStoredSample;
1342
- //# sourceMappingURL=capture-CuyT8Vab.cjs.map
942
+ exports.toStoredSample = require_redact.toStoredSample;
943
+ //# sourceMappingURL=capture-D2k0GnBN.cjs.map