@secondlayer/shared 13.3.0 → 13.5.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 (42) hide show
  1. package/dist/src/archive/range-digest.d.ts +50 -0
  2. package/dist/src/archive/semantic-digest-builder.d.ts +50 -0
  3. package/dist/src/coverage/index.d.ts +50 -0
  4. package/dist/src/db/index.d.ts +54 -1
  5. package/dist/src/db/index.js +4 -1
  6. package/dist/src/db/index.js.map +3 -3
  7. package/dist/src/db/queries/chain-reorgs.d.ts +50 -0
  8. package/dist/src/db/queries/chain-reorgs.js +4 -1
  9. package/dist/src/db/queries/chain-reorgs.js.map +3 -3
  10. package/dist/src/db/queries/contracts.d.ts +50 -0
  11. package/dist/src/db/queries/instance.d.ts +50 -0
  12. package/dist/src/db/queries/integrity.d.ts +50 -0
  13. package/dist/src/db/queries/subgraph-gaps.d.ts +50 -0
  14. package/dist/src/db/queries/subgraph-operations.d.ts +50 -0
  15. package/dist/src/db/queries/subgraphs.d.ts +50 -0
  16. package/dist/src/db/queries/sync-scope.d.ts +50 -0
  17. package/dist/src/db/queries/webhooks.d.ts +50 -0
  18. package/dist/src/db/schema.d.ts +51 -1
  19. package/dist/src/index.d.ts +169 -7
  20. package/dist/src/index.js +239 -87
  21. package/dist/src/index.js.map +6 -4
  22. package/dist/src/insights/index.d.ts +1540 -0
  23. package/dist/src/insights/index.js +2284 -0
  24. package/dist/src/insights/index.js.map +29 -0
  25. package/dist/src/insights/thresholds.d.ts +56 -0
  26. package/dist/src/insights/thresholds.js +86 -0
  27. package/dist/src/insights/thresholds.js.map +10 -0
  28. package/dist/src/leader.d.ts +3 -1
  29. package/dist/src/leader.js +3 -1
  30. package/dist/src/leader.js.map +3 -3
  31. package/dist/src/node/local-client.d.ts +50 -0
  32. package/dist/src/queue/listener.js +4 -1
  33. package/dist/src/queue/listener.js.map +3 -3
  34. package/dist/src/schemas/index.d.ts +95 -7
  35. package/dist/src/schemas/index.js +180 -87
  36. package/dist/src/schemas/index.js.map +4 -3
  37. package/dist/src/schemas/insights.d.ts +89 -0
  38. package/dist/src/schemas/insights.js +98 -0
  39. package/dist/src/schemas/insights.js.map +10 -0
  40. package/migrations/0169_subgraph_health_history.ts +54 -0
  41. package/migrations/0170_insights.ts +63 -0
  42. package/package.json +13 -1
package/dist/src/index.js CHANGED
@@ -854,6 +854,7 @@ var TABLE_TO_DB = {
854
854
  subgraph_health_snapshots: "target",
855
855
  subgraph_gaps: "target",
856
856
  subgraph_violations: "target",
857
+ subgraph_error_groups: "target",
857
858
  subgraph_processing_stats: "target",
858
859
  account_credits: "target",
859
860
  archive_fetches: "target",
@@ -865,6 +866,8 @@ var TABLE_TO_DB = {
865
866
  contact_requests: "target",
866
867
  api_failed_requests: "target",
867
868
  api_request_log: "target",
869
+ insights: "target",
870
+ insight_mutes: "target",
868
871
  feedback_tickets: "target",
869
872
  service_heartbeats: "both"
870
873
  };
@@ -1255,8 +1258,94 @@ var BILLING_PAUSED_PREFIX = "billing_paused: ";
1255
1258
  function billingPausedCode(lastError) {
1256
1259
  return lastError?.startsWith(BILLING_PAUSED_PREFIX) ? lastError.slice(BILLING_PAUSED_PREFIX.length) : null;
1257
1260
  }
1258
- // src/schemas/webhooks.ts
1261
+ // src/schemas/insights.ts
1259
1262
  import { z as z3 } from "zod";
1263
+ var INSIGHT_SEVERITIES = [
1264
+ "losing",
1265
+ "will_fail",
1266
+ "costs",
1267
+ "recovered"
1268
+ ];
1269
+ var InsightSeveritySchema = z3.enum(INSIGHT_SEVERITIES);
1270
+ var InsightResourceKindSchema = z3.enum(["webhook", "subgraph", "account"]);
1271
+ var InsightEvidenceSchema = z3.discriminatedUnion("kind", [
1272
+ z3.object({
1273
+ kind: z3.literal("series"),
1274
+ title: z3.string(),
1275
+ series: z3.array(z3.object({
1276
+ name: z3.string(),
1277
+ role: z3.enum(["a", "context", "mark"]),
1278
+ points: z3.array(z3.number())
1279
+ })),
1280
+ labels: z3.array(z3.tuple([z3.number(), z3.string()])),
1281
+ unit: z3.string().optional()
1282
+ }),
1283
+ z3.object({
1284
+ kind: z3.literal("table"),
1285
+ title: z3.string(),
1286
+ columns: z3.array(z3.string()),
1287
+ rows: z3.array(z3.array(z3.union([z3.string(), z3.number()]))),
1288
+ markRow: z3.number().optional()
1289
+ }),
1290
+ z3.object({
1291
+ kind: z3.literal("shapes"),
1292
+ title: z3.string(),
1293
+ shapes: z3.array(z3.object({
1294
+ code: z3.string(),
1295
+ body: z3.string(),
1296
+ count: z3.number(),
1297
+ isNew: z3.boolean()
1298
+ }))
1299
+ }),
1300
+ z3.object({
1301
+ kind: z3.literal("timeline"),
1302
+ title: z3.string(),
1303
+ steps: z3.array(z3.object({
1304
+ what: z3.string(),
1305
+ at: z3.string(),
1306
+ note: z3.string().optional(),
1307
+ failed: z3.boolean()
1308
+ }))
1309
+ })
1310
+ ]);
1311
+ var InsightSchema = z3.object({
1312
+ id: z3.string(),
1313
+ rule: z3.string(),
1314
+ severity: InsightSeveritySchema,
1315
+ impact: z3.number(),
1316
+ resource: z3.object({
1317
+ kind: InsightResourceKindSchema,
1318
+ id: z3.string(),
1319
+ name: z3.string()
1320
+ }),
1321
+ line: z3.string(),
1322
+ meta: z3.string().optional(),
1323
+ lead: z3.string(),
1324
+ body: z3.string(),
1325
+ evidence: z3.array(InsightEvidenceSchema),
1326
+ handoff: z3.object({
1327
+ prompt: z3.string(),
1328
+ commands: z3.array(z3.string())
1329
+ }),
1330
+ how: z3.object({
1331
+ detector: z3.string(),
1332
+ facts: z3.array(z3.tuple([z3.string(), z3.string()])),
1333
+ label: z3.object({ cause: z3.string(), confidence: z3.number() }).optional()
1334
+ }),
1335
+ createdAt: z3.string(),
1336
+ resolvedAt: z3.string().nullable().optional()
1337
+ });
1338
+ var InsightListResponseSchema = z3.object({
1339
+ data: z3.array(InsightSchema)
1340
+ });
1341
+ var SEVERITY_ORDER = {
1342
+ losing: 0,
1343
+ will_fail: 1,
1344
+ costs: 2,
1345
+ recovered: 3
1346
+ };
1347
+ // src/schemas/webhooks.ts
1348
+ import { z as z4 } from "zod";
1260
1349
  var WEBHOOK_FORMATS = [
1261
1350
  "standard-webhooks",
1262
1351
  "inngest",
@@ -1282,7 +1371,7 @@ function webhookTimeoutMsCeiling() {
1282
1371
  return ceilingFromEnv("WEBHOOK_TIMEOUT_MS_CEILING", WEBHOOK_TIMEOUT_MS_CEILING_DEFAULT);
1283
1372
  }
1284
1373
  function maxRetriesField() {
1285
- return z3.number().int().min(0).optional().superRefine((v, ctx) => {
1374
+ return z4.number().int().min(0).optional().superRefine((v, ctx) => {
1286
1375
  if (v === undefined)
1287
1376
  return;
1288
1377
  const ceiling = webhookMaxRetriesCeiling();
@@ -1295,7 +1384,7 @@ function maxRetriesField() {
1295
1384
  });
1296
1385
  }
1297
1386
  function timeoutMsField() {
1298
- return z3.number().int().min(100).optional().superRefine((v, ctx) => {
1387
+ return z4.number().int().min(100).optional().superRefine((v, ctx) => {
1299
1388
  if (v === undefined)
1300
1389
  return;
1301
1390
  const ceiling = webhookTimeoutMsCeiling();
@@ -1307,8 +1396,8 @@ function timeoutMsField() {
1307
1396
  }
1308
1397
  });
1309
1398
  }
1310
- var webhookUrl = z3.string().trim().min(1).refine((value) => value.startsWith("http://") || value.startsWith("https://"), "must be an http(s) URL");
1311
- var name = z3.string().trim().min(1).max(128);
1399
+ var webhookUrl = z4.string().trim().min(1).refine((value) => value.startsWith("http://") || value.startsWith("https://"), "must be an http(s) URL");
1400
+ var name = z4.string().trim().min(1).max(128);
1312
1401
  var MANAGED_NAME_PREFIXES = {
1313
1402
  "sentinel:": "Sentinel"
1314
1403
  };
@@ -1319,8 +1408,8 @@ function managedByForName(name) {
1319
1408
  }
1320
1409
  return null;
1321
1410
  }
1322
- var WebhookStatusSchema = z3.enum(WEBHOOK_STATUSES);
1323
- var WebhookFormatSchema = z3.enum(WEBHOOK_FORMATS);
1411
+ var WebhookStatusSchema = z4.enum(WEBHOOK_STATUSES);
1412
+ var WebhookFormatSchema = z4.enum(WEBHOOK_FORMATS);
1324
1413
  var CHAIN_TRIGGER_TYPES = [
1325
1414
  "stx_transfer",
1326
1415
  "stx_mint",
@@ -1350,212 +1439,212 @@ var CHAIN_TRIGGER_TYPES = [
1350
1439
  "rune_transfer",
1351
1440
  "rune_burn"
1352
1441
  ];
1353
- var runeRef = z3.string().trim().min(1);
1354
- var triggerAmount = z3.union([
1355
- z3.string().trim().regex(/^\d+$/, "must be a non-negative integer string"),
1356
- z3.number().int().nonnegative()
1442
+ var runeRef = z4.string().trim().min(1);
1443
+ var triggerAmount = z4.union([
1444
+ z4.string().trim().regex(/^\d+$/, "must be a non-negative integer string"),
1445
+ z4.number().int().nonnegative()
1357
1446
  ]);
1358
- var triggerPattern = z3.string().trim().min(1);
1359
- var trait = z3.string().trim().min(1);
1360
- var printWhereValue = z3.string().min(1).max(256);
1361
- var PrintWhereSchema = z3.record(z3.string().trim().min(1).max(64), z3.union([printWhereValue, z3.array(printWhereValue).min(1).max(20)])).refine((o) => {
1447
+ var triggerPattern = z4.string().trim().min(1);
1448
+ var trait = z4.string().trim().min(1);
1449
+ var printWhereValue = z4.string().min(1).max(256);
1450
+ var PrintWhereSchema = z4.record(z4.string().trim().min(1).max(64), z4.union([printWhereValue, z4.array(printWhereValue).min(1).max(20)])).refine((o) => {
1362
1451
  const n = Object.keys(o).length;
1363
1452
  return n >= 1 && n <= 10;
1364
1453
  }, "where takes 1 to 10 keys");
1365
- var ChainTriggerSchema = z3.discriminatedUnion("type", [
1366
- z3.object({
1367
- type: z3.literal("stx_transfer"),
1454
+ var ChainTriggerSchema = z4.discriminatedUnion("type", [
1455
+ z4.object({
1456
+ type: z4.literal("stx_transfer"),
1368
1457
  sender: triggerPattern.optional(),
1369
1458
  recipient: triggerPattern.optional(),
1370
1459
  minAmount: triggerAmount.optional(),
1371
1460
  maxAmount: triggerAmount.optional()
1372
1461
  }).strict(),
1373
- z3.object({
1374
- type: z3.literal("stx_mint"),
1462
+ z4.object({
1463
+ type: z4.literal("stx_mint"),
1375
1464
  recipient: triggerPattern.optional(),
1376
1465
  minAmount: triggerAmount.optional()
1377
1466
  }).strict(),
1378
- z3.object({
1379
- type: z3.literal("stx_burn"),
1467
+ z4.object({
1468
+ type: z4.literal("stx_burn"),
1380
1469
  sender: triggerPattern.optional(),
1381
1470
  minAmount: triggerAmount.optional()
1382
1471
  }).strict(),
1383
- z3.object({
1384
- type: z3.literal("stx_lock"),
1472
+ z4.object({
1473
+ type: z4.literal("stx_lock"),
1385
1474
  lockedAddress: triggerPattern.optional(),
1386
1475
  minAmount: triggerAmount.optional()
1387
1476
  }).strict(),
1388
- z3.object({
1389
- type: z3.literal("ft_transfer"),
1477
+ z4.object({
1478
+ type: z4.literal("ft_transfer"),
1390
1479
  assetIdentifier: triggerPattern.optional(),
1391
1480
  sender: triggerPattern.optional(),
1392
1481
  recipient: triggerPattern.optional(),
1393
1482
  minAmount: triggerAmount.optional(),
1394
1483
  trait: trait.optional()
1395
1484
  }).strict(),
1396
- z3.object({
1397
- type: z3.literal("ft_mint"),
1485
+ z4.object({
1486
+ type: z4.literal("ft_mint"),
1398
1487
  assetIdentifier: triggerPattern.optional(),
1399
1488
  recipient: triggerPattern.optional(),
1400
1489
  minAmount: triggerAmount.optional(),
1401
1490
  trait: trait.optional()
1402
1491
  }).strict(),
1403
- z3.object({
1404
- type: z3.literal("ft_burn"),
1492
+ z4.object({
1493
+ type: z4.literal("ft_burn"),
1405
1494
  assetIdentifier: triggerPattern.optional(),
1406
1495
  sender: triggerPattern.optional(),
1407
1496
  minAmount: triggerAmount.optional(),
1408
1497
  trait: trait.optional()
1409
1498
  }).strict(),
1410
- z3.object({
1411
- type: z3.literal("nft_transfer"),
1499
+ z4.object({
1500
+ type: z4.literal("nft_transfer"),
1412
1501
  assetIdentifier: triggerPattern.optional(),
1413
1502
  sender: triggerPattern.optional(),
1414
1503
  recipient: triggerPattern.optional(),
1415
1504
  trait: trait.optional()
1416
1505
  }).strict(),
1417
- z3.object({
1418
- type: z3.literal("nft_mint"),
1506
+ z4.object({
1507
+ type: z4.literal("nft_mint"),
1419
1508
  assetIdentifier: triggerPattern.optional(),
1420
1509
  recipient: triggerPattern.optional(),
1421
1510
  trait: trait.optional()
1422
1511
  }).strict(),
1423
- z3.object({
1424
- type: z3.literal("nft_burn"),
1512
+ z4.object({
1513
+ type: z4.literal("nft_burn"),
1425
1514
  assetIdentifier: triggerPattern.optional(),
1426
1515
  sender: triggerPattern.optional(),
1427
1516
  trait: trait.optional()
1428
1517
  }).strict(),
1429
- z3.object({
1430
- type: z3.literal("contract_call"),
1518
+ z4.object({
1519
+ type: z4.literal("contract_call"),
1431
1520
  contractId: triggerPattern.optional(),
1432
1521
  functionName: triggerPattern.optional(),
1433
1522
  caller: triggerPattern.optional(),
1434
1523
  trait: trait.optional()
1435
1524
  }).strict(),
1436
- z3.object({
1437
- type: z3.literal("contract_deploy"),
1525
+ z4.object({
1526
+ type: z4.literal("contract_deploy"),
1438
1527
  deployer: triggerPattern.optional(),
1439
1528
  contractName: triggerPattern.optional()
1440
1529
  }).strict(),
1441
- z3.object({
1442
- type: z3.literal("print_event"),
1530
+ z4.object({
1531
+ type: z4.literal("print_event"),
1443
1532
  contractId: triggerPattern.optional(),
1444
1533
  topic: triggerPattern.optional(),
1445
1534
  trait: trait.optional(),
1446
1535
  where: PrintWhereSchema.optional()
1447
1536
  }).strict(),
1448
- z3.object({
1449
- type: z3.literal("nested_contract_call"),
1537
+ z4.object({
1538
+ type: z4.literal("nested_contract_call"),
1450
1539
  contractId: triggerPattern.optional(),
1451
1540
  functionName: triggerPattern.optional(),
1452
1541
  caller: triggerPattern.optional(),
1453
1542
  sender: triggerPattern.optional(),
1454
1543
  trait: trait.optional()
1455
1544
  }).strict(),
1456
- z3.object({
1457
- type: z3.literal("var_set"),
1545
+ z4.object({
1546
+ type: z4.literal("var_set"),
1458
1547
  contractId: triggerPattern.optional(),
1459
1548
  varName: triggerPattern.optional(),
1460
1549
  trait: trait.optional()
1461
1550
  }).strict(),
1462
- z3.object({
1463
- type: z3.literal("map_set"),
1551
+ z4.object({
1552
+ type: z4.literal("map_set"),
1464
1553
  contractId: triggerPattern.optional(),
1465
1554
  map: triggerPattern.optional(),
1466
1555
  trait: trait.optional()
1467
1556
  }).strict(),
1468
- z3.object({
1469
- type: z3.literal("map_insert"),
1557
+ z4.object({
1558
+ type: z4.literal("map_insert"),
1470
1559
  contractId: triggerPattern.optional(),
1471
1560
  map: triggerPattern.optional(),
1472
1561
  trait: trait.optional()
1473
1562
  }).strict(),
1474
- z3.object({
1475
- type: z3.literal("map_delete"),
1563
+ z4.object({
1564
+ type: z4.literal("map_delete"),
1476
1565
  contractId: triggerPattern.optional(),
1477
1566
  map: triggerPattern.optional(),
1478
1567
  trait: trait.optional()
1479
1568
  }).strict(),
1480
- z3.object({
1481
- type: z3.literal("sbtc_deposit"),
1569
+ z4.object({
1570
+ type: z4.literal("sbtc_deposit"),
1482
1571
  sender: triggerPattern.optional(),
1483
1572
  minAmount: triggerAmount.optional(),
1484
1573
  maxAmount: triggerAmount.optional(),
1485
1574
  bitcoinTxid: triggerPattern.optional(),
1486
- requestId: z3.number().int().nonnegative().optional()
1575
+ requestId: z4.number().int().nonnegative().optional()
1487
1576
  }).strict(),
1488
- z3.object({
1489
- type: z3.literal("sbtc_withdrawal_create"),
1577
+ z4.object({
1578
+ type: z4.literal("sbtc_withdrawal_create"),
1490
1579
  sender: triggerPattern.optional(),
1491
1580
  minAmount: triggerAmount.optional(),
1492
1581
  maxAmount: triggerAmount.optional(),
1493
- requestId: z3.number().int().nonnegative().optional()
1582
+ requestId: z4.number().int().nonnegative().optional()
1494
1583
  }).strict(),
1495
- z3.object({
1496
- type: z3.literal("sbtc_withdrawal_accept"),
1497
- requestId: z3.number().int().nonnegative().optional(),
1584
+ z4.object({
1585
+ type: z4.literal("sbtc_withdrawal_accept"),
1586
+ requestId: z4.number().int().nonnegative().optional(),
1498
1587
  sweepTxid: triggerPattern.optional()
1499
1588
  }).strict(),
1500
- z3.object({
1501
- type: z3.literal("sbtc_withdrawal_reject"),
1502
- requestId: z3.number().int().nonnegative().optional()
1589
+ z4.object({
1590
+ type: z4.literal("sbtc_withdrawal_reject"),
1591
+ requestId: z4.number().int().nonnegative().optional()
1503
1592
  }).strict(),
1504
- z3.object({
1505
- type: z3.literal("sbtc_withdrawal_swept_confirmed"),
1506
- requestId: z3.number().int().nonnegative().optional(),
1593
+ z4.object({
1594
+ type: z4.literal("sbtc_withdrawal_swept_confirmed"),
1595
+ requestId: z4.number().int().nonnegative().optional(),
1507
1596
  sweepTxid: triggerPattern.optional()
1508
1597
  }).strict(),
1509
- z3.object({
1510
- type: z3.literal("rune_etch"),
1598
+ z4.object({
1599
+ type: z4.literal("rune_etch"),
1511
1600
  rune: runeRef.optional()
1512
1601
  }).strict(),
1513
- z3.object({
1514
- type: z3.literal("rune_mint"),
1602
+ z4.object({
1603
+ type: z4.literal("rune_mint"),
1515
1604
  rune: runeRef.optional()
1516
1605
  }).strict(),
1517
- z3.object({
1518
- type: z3.literal("rune_transfer"),
1606
+ z4.object({
1607
+ type: z4.literal("rune_transfer"),
1519
1608
  rune: runeRef.optional(),
1520
1609
  address: triggerPattern.optional(),
1521
1610
  minAmount: triggerAmount.optional()
1522
1611
  }).strict(),
1523
- z3.object({
1524
- type: z3.literal("rune_burn"),
1612
+ z4.object({
1613
+ type: z4.literal("rune_burn"),
1525
1614
  rune: runeRef.optional()
1526
1615
  }).strict()
1527
1616
  ]);
1528
- var ChainTriggersSchema = z3.array(ChainTriggerSchema).min(1).max(50);
1617
+ var ChainTriggersSchema = z4.array(ChainTriggerSchema).min(1).max(50);
1529
1618
  var CHAIN_TRIGGER_FIELDS = Object.fromEntries(ChainTriggerSchema._zod.def.options.map((opt) => {
1530
1619
  const shape = opt._zod.def.shape;
1531
1620
  const type = shape.type._zod.def.values[0];
1532
1621
  return [type, Object.keys(shape).filter((k) => k !== "type")];
1533
1622
  }));
1534
- var CreateWebhookRequestSchema = z3.object({
1623
+ var CreateWebhookRequestSchema = z4.object({
1535
1624
  name,
1536
1625
  triggers: ChainTriggersSchema,
1537
1626
  url: webhookUrl,
1538
1627
  format: WebhookFormatSchema.default("standard-webhooks"),
1539
- authConfig: z3.record(z3.string(), z3.unknown()).optional(),
1628
+ authConfig: z4.record(z4.string(), z4.unknown()).optional(),
1540
1629
  maxRetries: maxRetriesField(),
1541
1630
  timeoutMs: timeoutMsField(),
1542
- concurrency: z3.number().int().min(1).max(100).optional()
1631
+ concurrency: z4.number().int().min(1).max(100).optional()
1543
1632
  });
1544
- var UpdateWebhookRequestSchema = z3.object({
1633
+ var UpdateWebhookRequestSchema = z4.object({
1545
1634
  name: name.optional(),
1546
1635
  url: webhookUrl.optional(),
1547
1636
  format: WebhookFormatSchema.optional(),
1548
- authConfig: z3.record(z3.string(), z3.unknown()).optional(),
1637
+ authConfig: z4.record(z4.string(), z4.unknown()).optional(),
1549
1638
  maxRetries: maxRetriesField(),
1550
1639
  timeoutMs: timeoutMsField(),
1551
- concurrency: z3.number().int().min(1).max(100).optional()
1640
+ concurrency: z4.number().int().min(1).max(100).optional()
1552
1641
  }).refine((value) => Object.keys(value).length > 0, {
1553
1642
  message: "At least one field must be provided"
1554
1643
  });
1555
- var ReplayWebhookRequestSchema = z3.object({
1556
- fromBlock: z3.number().int().nonnegative(),
1557
- toBlock: z3.number().int().nonnegative(),
1558
- force: z3.string().trim().min(1).max(64).optional()
1644
+ var ReplayWebhookRequestSchema = z4.object({
1645
+ fromBlock: z4.number().int().nonnegative(),
1646
+ toBlock: z4.number().int().nonnegative(),
1647
+ force: z4.string().trim().min(1).max(64).optional()
1559
1648
  }).refine((value) => value.fromBlock <= value.toBlock, {
1560
1649
  message: "fromBlock must be less than or equal to toBlock",
1561
1650
  path: ["toBlock"]
@@ -1997,6 +2086,61 @@ function generateSubgraphSpec(detail, format, options = {}) {
1997
2086
  return generateSubgraphAgentSchema(detail, options);
1998
2087
  return generateSubgraphMarkdown(detail, options);
1999
2088
  }
2089
+ // src/subgraphs/health.ts
2090
+ var HOUR_MS = 3600000;
2091
+ function positiveDeltas(values) {
2092
+ let total = 0;
2093
+ let prev = null;
2094
+ for (const value of values) {
2095
+ if (value === null)
2096
+ continue;
2097
+ if (prev !== null && value > prev)
2098
+ total += value - prev;
2099
+ prev = value;
2100
+ }
2101
+ return total;
2102
+ }
2103
+ function toNumber(value) {
2104
+ if (value === null)
2105
+ return null;
2106
+ const n = Number(value);
2107
+ return Number.isFinite(n) ? n : null;
2108
+ }
2109
+ function bucketHourly(snapshots, hours, now = Date.now()) {
2110
+ const sorted = snapshots.map((s) => ({ ...s, at: new Date(s.captured_at).getTime() })).sort((a, b) => a.at - b.at);
2111
+ const currentHourStart = Math.floor(now / HOUR_MS) * HOUR_MS;
2112
+ const out = [];
2113
+ for (let i = hours - 1;i >= 0; i--) {
2114
+ const start = currentHourStart - i * HOUR_MS;
2115
+ const end = start + HOUR_MS;
2116
+ const inHour = sorted.filter((s) => s.at >= start && s.at < end);
2117
+ if (inHour.length === 0) {
2118
+ out.push({
2119
+ hour: new Date(start).toISOString(),
2120
+ lagBlocks: null,
2121
+ rowsWritten: 0,
2122
+ errors: 0,
2123
+ eventsHandled: 0
2124
+ });
2125
+ continue;
2126
+ }
2127
+ const before = sorted.filter((s) => s.at < start).at(-1);
2128
+ const series = before ? [before, ...inHour] : inHour;
2129
+ const lags = inHour.map((s) => {
2130
+ const tip = toNumber(s.chain_tip);
2131
+ const cursor = toNumber(s.last_processed_block);
2132
+ return tip === null || cursor === null ? null : Math.max(0, tip - cursor);
2133
+ }).filter((lag) => lag !== null);
2134
+ out.push({
2135
+ hour: new Date(start).toISOString(),
2136
+ lagBlocks: lags.length > 0 ? Math.max(...lags) : null,
2137
+ rowsWritten: positiveDeltas(series.map((s) => toNumber(s.rows_written_total))),
2138
+ errors: positiveDeltas(series.map((s) => toNumber(s.total_errors))),
2139
+ eventsHandled: positiveDeltas(series.map((s) => toNumber(s.total_processed)))
2140
+ });
2141
+ }
2142
+ return out;
2143
+ }
2000
2144
  // src/crypto/hmac.ts
2001
2145
  var exports_hmac = {};
2002
2146
  __export(exports_hmac, {
@@ -2118,12 +2262,19 @@ export {
2118
2262
  EMPTY_RANGE_EVENT_INDEX_SENTINEL,
2119
2263
  ErrorCodes,
2120
2264
  ForbiddenError,
2265
+ INSIGHT_SEVERITIES,
2266
+ InsightEvidenceSchema,
2267
+ InsightListResponseSchema,
2268
+ InsightResourceKindSchema,
2269
+ InsightSchema,
2270
+ InsightSeveritySchema,
2121
2271
  KeyRotatedError,
2122
2272
  NotFoundError,
2123
2273
  PaymentRequiredError,
2124
2274
  RUNE_EVENT_TYPES,
2125
2275
  RateLimitError,
2126
2276
  ReplayWebhookRequestSchema,
2277
+ SEVERITY_ORDER,
2127
2278
  SOURCE_READ_COLUMNS,
2128
2279
  SOURCE_READ_PKS,
2129
2280
  SOURCE_READ_TYPES,
@@ -2147,6 +2298,7 @@ export {
2147
2298
  assertDbSplit,
2148
2299
  billingPausedCode,
2149
2300
  blockEndCursor,
2301
+ bucketHourly,
2150
2302
  closeDb,
2151
2303
  closeDbOrTimeout,
2152
2304
  committedHeight,
@@ -2186,5 +2338,5 @@ export {
2186
2338
  sql2 as sql
2187
2339
  };
2188
2340
 
2189
- //# debugId=4CA800A5189D0B1364756E2164756E21
2341
+ //# debugId=D95357BE1793CC7464756E2164756E21
2190
2342
  //# sourceMappingURL=index.js.map