@secondlayer/shared 13.3.0 → 13.4.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/dist/src/archive/range-digest.d.ts +19 -0
- package/dist/src/archive/semantic-digest-builder.d.ts +19 -0
- package/dist/src/coverage/index.d.ts +19 -0
- package/dist/src/db/index.d.ts +21 -1
- package/dist/src/db/index.js +2 -1
- package/dist/src/db/index.js.map +3 -3
- package/dist/src/db/queries/chain-reorgs.d.ts +19 -0
- package/dist/src/db/queries/chain-reorgs.js +2 -1
- package/dist/src/db/queries/chain-reorgs.js.map +3 -3
- package/dist/src/db/queries/contracts.d.ts +19 -0
- package/dist/src/db/queries/instance.d.ts +19 -0
- package/dist/src/db/queries/integrity.d.ts +19 -0
- package/dist/src/db/queries/subgraph-gaps.d.ts +19 -0
- package/dist/src/db/queries/subgraph-operations.d.ts +19 -0
- package/dist/src/db/queries/subgraphs.d.ts +19 -0
- package/dist/src/db/queries/sync-scope.d.ts +19 -0
- package/dist/src/db/queries/webhooks.d.ts +19 -0
- package/dist/src/db/schema.d.ts +20 -1
- package/dist/src/index.d.ts +42 -1
- package/dist/src/index.js +58 -1
- package/dist/src/index.js.map +5 -4
- package/dist/src/node/local-client.d.ts +19 -0
- package/dist/src/queue/listener.js +2 -1
- package/dist/src/queue/listener.js.map +3 -3
- package/migrations/0169_subgraph_health_history.ts +54 -0
- package/package.json +1 -1
package/dist/src/index.d.ts
CHANGED
|
@@ -577,8 +577,26 @@ interface SubgraphHealthSnapshotsTable {
|
|
|
577
577
|
total_processed: number;
|
|
578
578
|
total_errors: number;
|
|
579
579
|
last_processed_block: number | null;
|
|
580
|
+
chain_tip: string | number | null;
|
|
581
|
+
rows_written_total: string | number | null;
|
|
582
|
+
storage_bytes: string | number | null;
|
|
580
583
|
captured_at: Generated<Date>;
|
|
581
584
|
}
|
|
585
|
+
/** Handler errors grouped by fingerprint. Cap 50/subgraph. */
|
|
586
|
+
interface SubgraphErrorGroupsTable {
|
|
587
|
+
id: Generated<string>;
|
|
588
|
+
subgraph_name: string;
|
|
589
|
+
fingerprint: string;
|
|
590
|
+
source_name: string;
|
|
591
|
+
event_type: string | null;
|
|
592
|
+
message: string;
|
|
593
|
+
frame: string | null;
|
|
594
|
+
count: Generated<string | number>;
|
|
595
|
+
sample_tx_id: string | null;
|
|
596
|
+
sample_block_height: string | number | null;
|
|
597
|
+
first_seen: Generated<Date>;
|
|
598
|
+
last_seen: Generated<Date>;
|
|
599
|
+
}
|
|
582
600
|
interface ProcessedStripeEventsTable {
|
|
583
601
|
event_id: string;
|
|
584
602
|
event_type: string;
|
|
@@ -1055,6 +1073,7 @@ interface Database {
|
|
|
1055
1073
|
subgraph_processing_stats: SubgraphProcessingStatsTable;
|
|
1056
1074
|
subgraph_gaps: SubgraphGapsTable;
|
|
1057
1075
|
subgraph_violations: SubgraphViolationsTable;
|
|
1076
|
+
subgraph_error_groups: SubgraphErrorGroupsTable;
|
|
1058
1077
|
subgraph_operations: SubgraphOperationsTable;
|
|
1059
1078
|
processed_stripe_events: ProcessedStripeEventsTable;
|
|
1060
1079
|
account_spend_caps: AccountSpendCapsTable;
|
|
@@ -2475,6 +2494,7 @@ declare const TABLE_TO_DB: {
|
|
|
2475
2494
|
subgraph_health_snapshots: string
|
|
2476
2495
|
subgraph_gaps: string
|
|
2477
2496
|
subgraph_violations: string
|
|
2497
|
+
subgraph_error_groups: string
|
|
2478
2498
|
subgraph_processing_stats: string
|
|
2479
2499
|
account_credits: string
|
|
2480
2500
|
archive_fetches: string
|
|
@@ -3066,6 +3086,27 @@ declare function generateSubgraphAgentSchema(detail: SubgraphDetail, options?: S
|
|
|
3066
3086
|
declare function generateSubgraphOpenApi(detail: SubgraphDetail, options?: SubgraphSpecOptions): Record<string, unknown>;
|
|
3067
3087
|
declare function generateSubgraphMarkdown(detail: SubgraphDetail, options?: SubgraphSpecOptions): string;
|
|
3068
3088
|
declare function generateSubgraphSpec(detail: SubgraphDetail, format: SubgraphSpecFormat, options?: SubgraphSpecOptions): Record<string, unknown> | SubgraphAgentSchema | string;
|
|
3089
|
+
interface HealthSnapshotPoint {
|
|
3090
|
+
captured_at: Date | string;
|
|
3091
|
+
chain_tip: string | number | null;
|
|
3092
|
+
last_processed_block: string | number | null;
|
|
3093
|
+
rows_written_total: string | number | null;
|
|
3094
|
+
total_errors: string | number;
|
|
3095
|
+
total_processed: string | number;
|
|
3096
|
+
}
|
|
3097
|
+
interface HealthHour {
|
|
3098
|
+
hour: string;
|
|
3099
|
+
lagBlocks: number | null;
|
|
3100
|
+
rowsWritten: number;
|
|
3101
|
+
errors: number;
|
|
3102
|
+
eventsHandled: number;
|
|
3103
|
+
}
|
|
3104
|
+
/**
|
|
3105
|
+
* Bucket snapshots into the last `hours` UTC hours (oldest first, ending with
|
|
3106
|
+
* the hour containing `now`). The delta for an hour also spans the boundary
|
|
3107
|
+
* from the previous hour's last snapshot, so no growth falls between buckets.
|
|
3108
|
+
*/
|
|
3109
|
+
declare function bucketHourly(snapshots: HealthSnapshotPoint[], hours: number, now?: number): HealthHour[];
|
|
3069
3110
|
/** The etch a `rune_etch` event created — everything a consumer needs to
|
|
3070
3111
|
* render a fresh rune without a second lookup, minus what the envelope
|
|
3071
3112
|
* already carries (`rune_id`). Mirrors 058's `RuneEntry` shape
|
|
@@ -3456,4 +3497,4 @@ declare function publicKeyPemFromPrivate(privateKeyPem: string): string;
|
|
|
3456
3497
|
declare function ed25519KeyId(publicKeyPem: string): string;
|
|
3457
3498
|
declare function signEd25519(payload: string, privateKey: KeyObject): string;
|
|
3458
3499
|
declare function verifyEd25519(payload: string, signatureBase64: string, publicKey: KeyObject): boolean;
|
|
3459
|
-
export { Account, AccountBalanceAlerts, AccountBalanceAlertsTable, AccountCredits, AccountCreditsTable, AccountSpendCap, AccountSpendCapsTable, AccountsTable, ApiFailedRequest, ApiFailedRequestsTable, ApiKey, ApiKeysTable, ApiRequestLogRow, ApiRequestLogTable, ArchiveFetch, ArchiveFetchesTable, AuthenticationError, AuthorizationError, BILLING_PAUSED_PREFIX, Block, BlocksTable, BnsMarketplaceAction, BnsMarketplaceEventsTable, BnsNameEventTopic, BnsNameEventsTable, BnsNamesTable, BnsNamespaceEventStatus, BnsNamespaceEventsTable, BnsNamespacesTable, BurnBlockRewardSlotsTable, BurnBlockRewardsTable, CHAIN_TRIGGER_FIELDS, CHAIN_TRIGGER_TYPES, CODE_TO_STATUS, ChainApplyDeliveryOf, ChainApplyEnvelope, ChainApplyEnvelopeOf, ChainEventEnvelope, ChainFtBurnData, ChainFtMintData, ChainFtTransferData, ChainNftBurnData, ChainNftMintData, ChainNftTransferData, ChainPrintEventData, ChainReadCacheTable, ChainReorgOrphanedEntry, ChainReorgRollbackDelivery, ChainReorgRollbackEnvelope, ChainReorgsTable, ChainStxBurnData, ChainStxLockData, ChainStxMintData, ChainStxTransferData, ChainTestDelivery, ChainTxLevelEvent, ChainWebhookDelivery, ChainWebhookEnvelope, ContactRequest, ContactRequestsTable, Contract, ContractsTable, CoverageSegmentsTable, CreateWebhookRequest, CreateWebhookRequestSchema, CreateWebhookResponse, DB_TO_STREAMS_EVENT_TYPE, DECODED_EVENT_TYPES2 as DECODED_EVENT_TYPES, DEFAULT_BTC_CONFIRMATIONS, Database, DatabaseError, DbPlane, DbReadRow, DbSplitStatus, DeadLetterEventsTable, DeadRow, DecodedEventType2 as DecodedEventType, DecodedEventsTable, DecoderCheckpointsTable, DeliveryRow, DeploySubgraphRequest, DeploySubgraphRequestSchema, DeploySubgraphResponse, EMPTY_RANGE_EVENT_INDEX_SENTINEL, Env, ErrorCode, ErrorCodes, Event, EventsArchiveTable, EventsTable, FailureClass, FailureUnit, FeedbackTicket, FeedbackTicketsTable, ForbiddenError, IndexColumn, IndexColumnType, IndexPrimaryKey, IndexProgress, IndexProgressTable, InsertAccount, InsertAccountBalanceAlerts, InsertAccountCredits, InsertAccountSpendCap, InsertApiFailedRequest, InsertApiKey, InsertApiRequestLogRow, InsertArchiveFetch, InsertBlock, InsertContactRequest, InsertContract, InsertEvent, InsertFeedbackTicket, InsertIndexProgress, InsertMagicLink, InsertMempoolTransaction, InsertSession, InsertStateWrite, InsertSubgraph, InsertSubgraphGap, InsertSubgraphHealthSnapshot, InsertSubgraphOperation, InsertTransaction, InsertUsageLedgerRow, InsertVmEvent, InsertWaitlistSignup, InsertWebhook, InsertWebhookDelivery, InsertWebhookOutbox, InstancesTable, KeyRotatedError, MagicLink, MagicLinksTable, MempoolTransaction, MempoolTransactionsTable, MigrationRole, NativeClock, NotFoundError, NumericAsText, ObserverJournalStatus, ObserverJournalTable, OutboxStatus, ParsedCreateWebhookRequest, ParsedReplayWebhookRequest, ParsedUpdateWebhookRequest, PaymentRequiredError, PendingForkBlocksTable, Pox4CallsTable, Pox4FunctionName, Pox5CycleSignersTable, Pox5CyclesTable, Pox5EventTopic, Pox5EventsTable, ProcessedStripeEventsTable, RUNE_EVENT_TYPES, RateLimitError, ReindexResponse, RepairMode, ReplayResult, ReplayWebhookRequest, ReplayWebhookRequestSchema, RetryState, RotateSecretResponse, RunStatus, RuneApplyDeliveryOf, RuneApplyEnvelope, RuneEventType, SOURCE_READ_COLUMNS, SOURCE_READ_PKS, SOURCE_READ_TYPES, STREAMS_DB_EVENT_TYPES, STREAMS_EVENT_TYPES, STREAMS_TO_DB_EVENT_TYPES, SbtcDepositEvent, SbtcEventTopic, SbtcEventsTable, SbtcSettlementsTable, SbtcTokenEventType, SbtcTokenEventsTable, SbtcWithdrawalEvent, SbtcWithdrawalSweptConfirmedEvent, SecondLayerError, SentinelAccount, SentinelAccountsTable, ServiceHeartbeatsTable, Session, SessionsTable, StageBlockReceiptsTable, StageFailuresTable, StageKind, StageRegistryTable, StageRunsTable, StateWrite, StateWritesArchiveTable, StateWritesTable, StreamsCursor, StreamsDbEventType, StreamsEventType, Subgraph, SubgraphAgentSchema, SubgraphAggregateParams, SubgraphAggregateResponse, SubgraphDetail, SubgraphGap, SubgraphGapEntry, SubgraphGapRange, SubgraphGapsResponse, SubgraphGapsTable, SubgraphHealthSnapshot, SubgraphHealthSnapshotsTable, SubgraphOperation, SubgraphOperationKind, SubgraphOperationStatus, SubgraphOperationsTable, SubgraphProcessingStatsTable, SubgraphQueryParams, SubgraphSpecFormat, SubgraphSpecOptions, SubgraphSummary, SubgraphSyncInfo, SubgraphVerification, SubgraphViolationsTable, SubgraphsTable, SyncScopesTable, TABLE_TO_DB, TenantSuspendedError, Transaction, TransactionsArchiveTable, TransactionsTable, TriggerEvaluatorState, TriggerEvaluatorStateTable, UpdateAccountBalanceAlerts, UpdateAccountCredits, UpdateAccountSpendCap, UpdateApiKey, UpdateArchiveFetch, UpdateBlock, UpdateContract, UpdateEvent, UpdateIndexProgress, UpdateSubgraph, UpdateSubgraphOperation, UpdateTransaction, UpdateUsageLedgerRow, UpdateVmEvent, UpdateWebhook, UpdateWebhookOutbox, UpdateWebhookRequest, UpdateWebhookRequestSchema, UsageLedgerRow, UsageLedgerTable, VM_EVENT_TYPES, VM_NODE_TO_STORED_TYPE2 as VM_NODE_TO_STORED_TYPE, VM_STORED_TO_NODE_TYPE, ValidationError, VersionConflictError, VmEvent, VmEventType, VmEventsArchiveTable, VmEventsTable, VmNodeEventType, WEBHOOK_FORMATS, WEBHOOK_STATUSES, Waitlist, WaitlistSignup, WaitlistSignupsTable, WaitlistsTable, Webhook, WebhookDeliveriesTable, WebhookDelivery, WebhookDetail, WebhookFormat, WebhookFormatSchema, WebhookKind, WebhookOutbox, WebhookOutboxTable, WebhookStatus, WebhookStatusSchema, WebhookSummary, WebhooksTable, applicationDatabaseUrl, assertDbSplit, billingPausedCode, blockEndCursor, closeDb, closeDbOrTimeout, committedHeight, compareStreamsCursor, exports_hmac as crypto, decodeStreamsCursor, describeDbUrl, exports_ed25519 as ed25519, encodeStreamsCursor, finalizedBurnHeight, formatWebhookSchemaErrors, generateSubgraphAgentSchema, generateSubgraphMarkdown, generateSubgraphOpenApi, generateSubgraphSpec, getDb, getDbSplitStatus, getEnv, getErrorMessage, getMigrationRole, getRawClient, getSourceDb, getTargetDb, isBnsDecoderEnabled, isEmptyRangeCursor, isPox4DecoderEnabled, isPox5DecoderEnabled, isSbtcDecoderEnabled, jsonb, logger, onChainPlane, onControlPlane, parseJsonb, resolveSourceUrl, resolveTargetUrl, setMigrationRole, sql };
|
|
3500
|
+
export { Account, AccountBalanceAlerts, AccountBalanceAlertsTable, AccountCredits, AccountCreditsTable, AccountSpendCap, AccountSpendCapsTable, AccountsTable, ApiFailedRequest, ApiFailedRequestsTable, ApiKey, ApiKeysTable, ApiRequestLogRow, ApiRequestLogTable, ArchiveFetch, ArchiveFetchesTable, AuthenticationError, AuthorizationError, BILLING_PAUSED_PREFIX, Block, BlocksTable, BnsMarketplaceAction, BnsMarketplaceEventsTable, BnsNameEventTopic, BnsNameEventsTable, BnsNamesTable, BnsNamespaceEventStatus, BnsNamespaceEventsTable, BnsNamespacesTable, BurnBlockRewardSlotsTable, BurnBlockRewardsTable, CHAIN_TRIGGER_FIELDS, CHAIN_TRIGGER_TYPES, CODE_TO_STATUS, ChainApplyDeliveryOf, ChainApplyEnvelope, ChainApplyEnvelopeOf, ChainEventEnvelope, ChainFtBurnData, ChainFtMintData, ChainFtTransferData, ChainNftBurnData, ChainNftMintData, ChainNftTransferData, ChainPrintEventData, ChainReadCacheTable, ChainReorgOrphanedEntry, ChainReorgRollbackDelivery, ChainReorgRollbackEnvelope, ChainReorgsTable, ChainStxBurnData, ChainStxLockData, ChainStxMintData, ChainStxTransferData, ChainTestDelivery, ChainTxLevelEvent, ChainWebhookDelivery, ChainWebhookEnvelope, ContactRequest, ContactRequestsTable, Contract, ContractsTable, CoverageSegmentsTable, CreateWebhookRequest, CreateWebhookRequestSchema, CreateWebhookResponse, DB_TO_STREAMS_EVENT_TYPE, DECODED_EVENT_TYPES2 as DECODED_EVENT_TYPES, DEFAULT_BTC_CONFIRMATIONS, Database, DatabaseError, DbPlane, DbReadRow, DbSplitStatus, DeadLetterEventsTable, DeadRow, DecodedEventType2 as DecodedEventType, DecodedEventsTable, DecoderCheckpointsTable, DeliveryRow, DeploySubgraphRequest, DeploySubgraphRequestSchema, DeploySubgraphResponse, EMPTY_RANGE_EVENT_INDEX_SENTINEL, Env, ErrorCode, ErrorCodes, Event, EventsArchiveTable, EventsTable, FailureClass, FailureUnit, FeedbackTicket, FeedbackTicketsTable, ForbiddenError, HealthHour, HealthSnapshotPoint, IndexColumn, IndexColumnType, IndexPrimaryKey, IndexProgress, IndexProgressTable, InsertAccount, InsertAccountBalanceAlerts, InsertAccountCredits, InsertAccountSpendCap, InsertApiFailedRequest, InsertApiKey, InsertApiRequestLogRow, InsertArchiveFetch, InsertBlock, InsertContactRequest, InsertContract, InsertEvent, InsertFeedbackTicket, InsertIndexProgress, InsertMagicLink, InsertMempoolTransaction, InsertSession, InsertStateWrite, InsertSubgraph, InsertSubgraphGap, InsertSubgraphHealthSnapshot, InsertSubgraphOperation, InsertTransaction, InsertUsageLedgerRow, InsertVmEvent, InsertWaitlistSignup, InsertWebhook, InsertWebhookDelivery, InsertWebhookOutbox, InstancesTable, KeyRotatedError, MagicLink, MagicLinksTable, MempoolTransaction, MempoolTransactionsTable, MigrationRole, NativeClock, NotFoundError, NumericAsText, ObserverJournalStatus, ObserverJournalTable, OutboxStatus, ParsedCreateWebhookRequest, ParsedReplayWebhookRequest, ParsedUpdateWebhookRequest, PaymentRequiredError, PendingForkBlocksTable, Pox4CallsTable, Pox4FunctionName, Pox5CycleSignersTable, Pox5CyclesTable, Pox5EventTopic, Pox5EventsTable, ProcessedStripeEventsTable, RUNE_EVENT_TYPES, RateLimitError, ReindexResponse, RepairMode, ReplayResult, ReplayWebhookRequest, ReplayWebhookRequestSchema, RetryState, RotateSecretResponse, RunStatus, RuneApplyDeliveryOf, RuneApplyEnvelope, RuneEventType, SOURCE_READ_COLUMNS, SOURCE_READ_PKS, SOURCE_READ_TYPES, STREAMS_DB_EVENT_TYPES, STREAMS_EVENT_TYPES, STREAMS_TO_DB_EVENT_TYPES, SbtcDepositEvent, SbtcEventTopic, SbtcEventsTable, SbtcSettlementsTable, SbtcTokenEventType, SbtcTokenEventsTable, SbtcWithdrawalEvent, SbtcWithdrawalSweptConfirmedEvent, SecondLayerError, SentinelAccount, SentinelAccountsTable, ServiceHeartbeatsTable, Session, SessionsTable, StageBlockReceiptsTable, StageFailuresTable, StageKind, StageRegistryTable, StageRunsTable, StateWrite, StateWritesArchiveTable, StateWritesTable, StreamsCursor, StreamsDbEventType, StreamsEventType, Subgraph, SubgraphAgentSchema, SubgraphAggregateParams, SubgraphAggregateResponse, SubgraphDetail, SubgraphErrorGroupsTable, SubgraphGap, SubgraphGapEntry, SubgraphGapRange, SubgraphGapsResponse, SubgraphGapsTable, SubgraphHealthSnapshot, SubgraphHealthSnapshotsTable, SubgraphOperation, SubgraphOperationKind, SubgraphOperationStatus, SubgraphOperationsTable, SubgraphProcessingStatsTable, SubgraphQueryParams, SubgraphSpecFormat, SubgraphSpecOptions, SubgraphSummary, SubgraphSyncInfo, SubgraphVerification, SubgraphViolationsTable, SubgraphsTable, SyncScopesTable, TABLE_TO_DB, TenantSuspendedError, Transaction, TransactionsArchiveTable, TransactionsTable, TriggerEvaluatorState, TriggerEvaluatorStateTable, UpdateAccountBalanceAlerts, UpdateAccountCredits, UpdateAccountSpendCap, UpdateApiKey, UpdateArchiveFetch, UpdateBlock, UpdateContract, UpdateEvent, UpdateIndexProgress, UpdateSubgraph, UpdateSubgraphOperation, UpdateTransaction, UpdateUsageLedgerRow, UpdateVmEvent, UpdateWebhook, UpdateWebhookOutbox, UpdateWebhookRequest, UpdateWebhookRequestSchema, UsageLedgerRow, UsageLedgerTable, VM_EVENT_TYPES, VM_NODE_TO_STORED_TYPE2 as VM_NODE_TO_STORED_TYPE, VM_STORED_TO_NODE_TYPE, ValidationError, VersionConflictError, VmEvent, VmEventType, VmEventsArchiveTable, VmEventsTable, VmNodeEventType, WEBHOOK_FORMATS, WEBHOOK_STATUSES, Waitlist, WaitlistSignup, WaitlistSignupsTable, WaitlistsTable, Webhook, WebhookDeliveriesTable, WebhookDelivery, WebhookDetail, WebhookFormat, WebhookFormatSchema, WebhookKind, WebhookOutbox, WebhookOutboxTable, WebhookStatus, WebhookStatusSchema, WebhookSummary, WebhooksTable, applicationDatabaseUrl, assertDbSplit, billingPausedCode, blockEndCursor, bucketHourly, closeDb, closeDbOrTimeout, committedHeight, compareStreamsCursor, exports_hmac as crypto, decodeStreamsCursor, describeDbUrl, exports_ed25519 as ed25519, encodeStreamsCursor, finalizedBurnHeight, formatWebhookSchemaErrors, generateSubgraphAgentSchema, generateSubgraphMarkdown, generateSubgraphOpenApi, generateSubgraphSpec, getDb, getDbSplitStatus, getEnv, getErrorMessage, getMigrationRole, getRawClient, getSourceDb, getTargetDb, isBnsDecoderEnabled, isEmptyRangeCursor, isPox4DecoderEnabled, isPox5DecoderEnabled, isSbtcDecoderEnabled, jsonb, logger, onChainPlane, onControlPlane, parseJsonb, resolveSourceUrl, resolveTargetUrl, setMigrationRole, sql };
|
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",
|
|
@@ -1997,6 +1998,61 @@ function generateSubgraphSpec(detail, format, options = {}) {
|
|
|
1997
1998
|
return generateSubgraphAgentSchema(detail, options);
|
|
1998
1999
|
return generateSubgraphMarkdown(detail, options);
|
|
1999
2000
|
}
|
|
2001
|
+
// src/subgraphs/health.ts
|
|
2002
|
+
var HOUR_MS = 3600000;
|
|
2003
|
+
function positiveDeltas(values) {
|
|
2004
|
+
let total = 0;
|
|
2005
|
+
let prev = null;
|
|
2006
|
+
for (const value of values) {
|
|
2007
|
+
if (value === null)
|
|
2008
|
+
continue;
|
|
2009
|
+
if (prev !== null && value > prev)
|
|
2010
|
+
total += value - prev;
|
|
2011
|
+
prev = value;
|
|
2012
|
+
}
|
|
2013
|
+
return total;
|
|
2014
|
+
}
|
|
2015
|
+
function toNumber(value) {
|
|
2016
|
+
if (value === null)
|
|
2017
|
+
return null;
|
|
2018
|
+
const n = Number(value);
|
|
2019
|
+
return Number.isFinite(n) ? n : null;
|
|
2020
|
+
}
|
|
2021
|
+
function bucketHourly(snapshots, hours, now = Date.now()) {
|
|
2022
|
+
const sorted = snapshots.map((s) => ({ ...s, at: new Date(s.captured_at).getTime() })).sort((a, b) => a.at - b.at);
|
|
2023
|
+
const currentHourStart = Math.floor(now / HOUR_MS) * HOUR_MS;
|
|
2024
|
+
const out = [];
|
|
2025
|
+
for (let i = hours - 1;i >= 0; i--) {
|
|
2026
|
+
const start = currentHourStart - i * HOUR_MS;
|
|
2027
|
+
const end = start + HOUR_MS;
|
|
2028
|
+
const inHour = sorted.filter((s) => s.at >= start && s.at < end);
|
|
2029
|
+
if (inHour.length === 0) {
|
|
2030
|
+
out.push({
|
|
2031
|
+
hour: new Date(start).toISOString(),
|
|
2032
|
+
lagBlocks: null,
|
|
2033
|
+
rowsWritten: 0,
|
|
2034
|
+
errors: 0,
|
|
2035
|
+
eventsHandled: 0
|
|
2036
|
+
});
|
|
2037
|
+
continue;
|
|
2038
|
+
}
|
|
2039
|
+
const before = sorted.filter((s) => s.at < start).at(-1);
|
|
2040
|
+
const series = before ? [before, ...inHour] : inHour;
|
|
2041
|
+
const lags = inHour.map((s) => {
|
|
2042
|
+
const tip = toNumber(s.chain_tip);
|
|
2043
|
+
const cursor = toNumber(s.last_processed_block);
|
|
2044
|
+
return tip === null || cursor === null ? null : Math.max(0, tip - cursor);
|
|
2045
|
+
}).filter((lag) => lag !== null);
|
|
2046
|
+
out.push({
|
|
2047
|
+
hour: new Date(start).toISOString(),
|
|
2048
|
+
lagBlocks: lags.length > 0 ? Math.max(...lags) : null,
|
|
2049
|
+
rowsWritten: positiveDeltas(series.map((s) => toNumber(s.rows_written_total))),
|
|
2050
|
+
errors: positiveDeltas(series.map((s) => toNumber(s.total_errors))),
|
|
2051
|
+
eventsHandled: positiveDeltas(series.map((s) => toNumber(s.total_processed)))
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
2054
|
+
return out;
|
|
2055
|
+
}
|
|
2000
2056
|
// src/crypto/hmac.ts
|
|
2001
2057
|
var exports_hmac = {};
|
|
2002
2058
|
__export(exports_hmac, {
|
|
@@ -2147,6 +2203,7 @@ export {
|
|
|
2147
2203
|
assertDbSplit,
|
|
2148
2204
|
billingPausedCode,
|
|
2149
2205
|
blockEndCursor,
|
|
2206
|
+
bucketHourly,
|
|
2150
2207
|
closeDb,
|
|
2151
2208
|
closeDbOrTimeout,
|
|
2152
2209
|
committedHeight,
|
|
@@ -2186,5 +2243,5 @@ export {
|
|
|
2186
2243
|
sql2 as sql
|
|
2187
2244
|
};
|
|
2188
2245
|
|
|
2189
|
-
//# debugId=
|
|
2246
|
+
//# debugId=E1550FF128BCB8A064756E2164756E21
|
|
2190
2247
|
//# sourceMappingURL=index.js.map
|