@secondlayer/shared 7.8.0 → 7.10.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 (52) hide show
  1. package/dist/src/archive/derived-stage-report.d.ts +99 -0
  2. package/dist/src/archive/derived-stage-report.js +64 -0
  3. package/dist/src/archive/derived-stage-report.js.map +10 -0
  4. package/dist/src/archive/disk-guard.d.ts +46 -0
  5. package/dist/src/archive/disk-guard.js +69 -0
  6. package/dist/src/archive/disk-guard.js.map +10 -0
  7. package/dist/src/archive/per-height-digest.d.ts +99 -0
  8. package/dist/src/archive/per-height-digest.js +194 -0
  9. package/dist/src/archive/per-height-digest.js.map +11 -0
  10. package/dist/src/archive/range-digest.d.ts +96 -0
  11. package/dist/src/archive/semantic-digest-builder.d.ts +1183 -0
  12. package/dist/src/archive/semantic-digest-builder.js +302 -0
  13. package/dist/src/archive/semantic-digest-builder.js.map +11 -0
  14. package/dist/src/archive/semantic-digest.d.ts +131 -0
  15. package/dist/src/archive/semantic-digest.js +143 -0
  16. package/dist/src/archive/semantic-digest.js.map +10 -0
  17. package/dist/src/coverage/index.d.ts +1670 -0
  18. package/dist/src/coverage/index.js +1483 -0
  19. package/dist/src/coverage/index.js.map +23 -0
  20. package/dist/src/db/index.d.ts +105 -1
  21. package/dist/src/db/index.js +31 -1
  22. package/dist/src/db/index.js.map +6 -5
  23. package/dist/src/db/queries/chain-reorgs.d.ts +96 -0
  24. package/dist/src/db/queries/chain-reorgs.js +30 -1
  25. package/dist/src/db/queries/chain-reorgs.js.map +6 -5
  26. package/dist/src/db/queries/contracts.d.ts +96 -0
  27. package/dist/src/db/queries/instance.d.ts +1127 -0
  28. package/dist/src/db/queries/instance.js +92 -0
  29. package/dist/src/db/queries/instance.js.map +10 -0
  30. package/dist/src/db/queries/integrity.d.ts +96 -0
  31. package/dist/src/db/queries/subgraph-gaps.d.ts +96 -0
  32. package/dist/src/db/queries/subgraph-operations.d.ts +96 -0
  33. package/dist/src/db/queries/subgraphs.d.ts +99 -1
  34. package/dist/src/db/queries/subgraphs.js +52 -23
  35. package/dist/src/db/queries/subgraphs.js.map +7 -7
  36. package/dist/src/db/queries/subscriptions.d.ts +96 -0
  37. package/dist/src/db/queries/subscriptions.js +47 -31
  38. package/dist/src/db/queries/subscriptions.js.map +5 -5
  39. package/dist/src/db/schema.d.ts +97 -1
  40. package/dist/src/index.d.ts +109 -1
  41. package/dist/src/index.js +52 -1
  42. package/dist/src/index.js.map +7 -6
  43. package/dist/src/node/client.d.ts +11 -1
  44. package/dist/src/node/client.js +42 -4
  45. package/dist/src/node/client.js.map +3 -3
  46. package/dist/src/node/local-client.d.ts +96 -0
  47. package/dist/src/node/nakamoto.d.ts +22 -7
  48. package/dist/src/node/nakamoto.js +46 -5
  49. package/dist/src/node/nakamoto.js.map +3 -3
  50. package/migrations/0115_instances.ts +33 -0
  51. package/migrations/0116_coverage_schema.ts +163 -0
  52. package/package.json +29 -1
@@ -1,4 +1,22 @@
1
1
  import { ColumnType, Generated, Insertable, Selectable, Updateable } from "kysely";
2
+ /**
3
+ * Coverage-kernel constraints. SQL CHECKs in migration 0116 must stay
4
+ * identical — property tests treat this file as the spec.
5
+ */
6
+ declare const STAGE_KINDS: readonly ["raw", "decode", "subgraph", "queue"];
7
+ type StageKind = (typeof STAGE_KINDS)[number];
8
+ declare const NATIVE_CLOCKS: readonly ["block", "cursor", "queue"];
9
+ type NativeClock = (typeof NATIVE_CLOCKS)[number];
10
+ declare const REPAIR_MODES: readonly ["range_safe", "full_reindex", "archive_replay", "none"];
11
+ type RepairMode = (typeof REPAIR_MODES)[number];
12
+ declare const RUN_STATUSES: readonly ["pending", "running", "complete", "syncing", "lagging", "gap", "stale", "failed", "unverified_import", "unanchored", "source_unavailable", "out_of_scope", "disabled", "halted"];
13
+ type RunStatus = (typeof RUN_STATUSES)[number];
14
+ declare const FAILURE_UNITS: readonly ["block", "range", "cursor", "queue"];
15
+ type FailureUnit = (typeof FAILURE_UNITS)[number];
16
+ declare const FAILURE_CLASSES: readonly ["omission", "version", "digest_mismatch", "crash", "reorg", "source_gap", "handler", "timeout", "unknown"];
17
+ type FailureClass = (typeof FAILURE_CLASSES)[number];
18
+ declare const RETRY_STATES: readonly ["open", "retrying", "halted", "resolved"];
19
+ type RetryState = (typeof RETRY_STATES)[number];
2
20
  interface BlocksTable {
3
21
  height: number;
4
22
  hash: string;
@@ -190,6 +208,12 @@ interface ApiKeysTable {
190
208
  revoked_at: Date | null;
191
209
  created_at: Generated<Date>;
192
210
  }
211
+ /** Singleton self-host / publisher identity. Network is immutable. */
212
+ interface InstancesTable {
213
+ id: Generated<string>;
214
+ network: string;
215
+ created_at: Generated<Date>;
216
+ }
193
217
  interface AccountsTable {
194
218
  id: Generated<string>;
195
219
  /** NULL for unclaimed ghost accounts (anonymous self-serve keys). */
@@ -720,6 +744,72 @@ interface ObserverJournalTable {
720
744
  error: string | null;
721
745
  processed_at: Date | null;
722
746
  }
747
+ /** Declared coverage stage. Identity is the `id` string (`raw`, `decode:stx`, …). */
748
+ interface StageRegistryTable {
749
+ id: string;
750
+ kind: StageKind;
751
+ depends_on: string | null;
752
+ native_clock: NativeClock;
753
+ producer_version: string;
754
+ repair_mode: RepairMode;
755
+ enabled: Generated<boolean>;
756
+ created_at: Generated<Date>;
757
+ }
758
+ /** One versioned sweep of a stage. */
759
+ interface StageRunsTable {
760
+ id: Generated<string>;
761
+ stage_id: string;
762
+ code_hash: string;
763
+ config_hash: string;
764
+ handler_hash: string | null;
765
+ target_height: number | null;
766
+ target_cursor: string | null;
767
+ status: RunStatus;
768
+ complete_through: number | null;
769
+ started_at: Generated<Date>;
770
+ finished_at: Date | null;
771
+ }
772
+ /** Per-block acknowledgement. Unique on (stage, height, hash). */
773
+ interface StageBlockReceiptsTable {
774
+ id: Generated<string>;
775
+ stage_id: string;
776
+ run_id: string | null;
777
+ block_height: number;
778
+ block_hash: string;
779
+ input_count: number;
780
+ input_digest: string;
781
+ effect_digest: string;
782
+ finalized: Generated<boolean>;
783
+ compacted_at: Date | null;
784
+ created_at: Generated<Date>;
785
+ }
786
+ /** Compacted finalized range. Only sealed after receipts in the range finalize. */
787
+ interface CoverageSegmentsTable {
788
+ id: Generated<string>;
789
+ stage_id: string;
790
+ from_height: number;
791
+ to_height: number;
792
+ chain_digest: string;
793
+ input_digest: string;
794
+ output_digest: string;
795
+ sealed_at: Generated<Date>;
796
+ }
797
+ /** Exact unit or range that failed, plus retry/retention state. */
798
+ interface StageFailuresTable {
799
+ id: Generated<string>;
800
+ stage_id: string;
801
+ run_id: string | null;
802
+ unit_kind: FailureUnit;
803
+ from_height: number | null;
804
+ to_height: number | null;
805
+ class: FailureClass;
806
+ retry_state: RetryState;
807
+ retry_count: Generated<number>;
808
+ last_error: string | null;
809
+ created_at: Generated<Date>;
810
+ resolved_at: Date | null;
811
+ retain_until: Generated<Date>;
812
+ }
723
813
  interface Database {
724
814
  blocks: BlocksTable;
725
815
  transactions: TransactionsTable;
@@ -732,6 +822,7 @@ interface Database {
732
822
  contracts: ContractsTable;
733
823
  subgraphs: SubgraphsTable;
734
824
  api_keys: ApiKeysTable;
825
+ instances: InstancesTable;
735
826
  accounts: AccountsTable;
736
827
  sessions: SessionsTable;
737
828
  magic_links: MagicLinksTable;
@@ -784,6 +875,11 @@ interface Database {
784
875
  chain_read_cache: ChainReadCacheTable;
785
876
  pending_fork_blocks: PendingForkBlocksTable;
786
877
  observer_journal: ObserverJournalTable;
878
+ stage_registry: StageRegistryTable;
879
+ stage_runs: StageRunsTable;
880
+ stage_block_receipts: StageBlockReceiptsTable;
881
+ coverage_segments: CoverageSegmentsTable;
882
+ stage_failures: StageFailuresTable;
787
883
  }
788
884
  /** Prepaid x402 credit — one running USD-micros balance per payer principal. */
789
885
  interface X402BalancesTable {
@@ -2025,6 +2121,11 @@ declare const TABLE_TO_DB: {
2025
2121
  chain_read_cache: string
2026
2122
  pending_fork_blocks: string
2027
2123
  observer_journal: string
2124
+ stage_registry: string
2125
+ stage_runs: string
2126
+ stage_block_receipts: string
2127
+ coverage_segments: string
2128
+ stage_failures: string
2028
2129
  decoded_events: string
2029
2130
  decoder_checkpoints: string
2030
2131
  pox4_calls: string
@@ -2042,6 +2143,7 @@ declare const TABLE_TO_DB: {
2042
2143
  bns_marketplace_events: string
2043
2144
  bns_names: string
2044
2145
  bns_namespaces: string
2146
+ instances: string
2045
2147
  accounts: string
2046
2148
  api_keys: string
2047
2149
  sessions: string
@@ -2076,6 +2178,8 @@ declare const TABLE_TO_DB: {
2076
2178
  account_credits: string
2077
2179
  service_heartbeats: string
2078
2180
  };
2181
+ /** OSS: one application URL. SOURCE_/TARGET_ are hosted split only. */
2182
+ declare function applicationDatabaseUrl(): string;
2079
2183
  interface DbSplitStatus {
2080
2184
  /** "split" when source/target resolve to different DBs, else "single". */
2081
2185
  mode: "split" | "single";
@@ -2883,6 +2987,10 @@ type StreamsCursor = {
2883
2987
  declare const EMPTY_RANGE_EVENT_INDEX_SENTINEL = 2147483647;
2884
2988
  declare function encodeStreamsCursor(cursor: StreamsCursor): string;
2885
2989
  declare function decodeStreamsCursor(cursor: string): StreamsCursor;
2990
+ declare function compareStreamsCursor(a: StreamsCursor, b: StreamsCursor): number;
2991
+ declare function isEmptyRangeCursor(cursor: StreamsCursor): boolean;
2992
+ /** Exclusive end of every event that can live in `height`. */
2993
+ declare function blockEndCursor(height: number): StreamsCursor;
2886
2994
  /**
2887
2995
  * Payload for `sbtc_deposit` (topic: completed-deposit).
2888
2996
  * `sender` is the Stacks address that initiated the deposit and receives the sBTC.
@@ -3142,4 +3250,4 @@ interface ChainTestDelivery {
3142
3250
  * "Chain subscription webhook payloads" doc.
3143
3251
  */
3144
3252
  type ChainWebhookDelivery = ChainApplyDeliveryOf<"stx_transfer", ChainEventEnvelope<"stx_transfer_event", ChainStxTransferData>> | ChainApplyDeliveryOf<"stx_mint", ChainEventEnvelope<"stx_mint_event", ChainStxMintData>> | ChainApplyDeliveryOf<"stx_burn", ChainEventEnvelope<"stx_burn_event", ChainStxBurnData>> | ChainApplyDeliveryOf<"stx_lock", ChainEventEnvelope<"stx_lock_event", ChainStxLockData>> | ChainApplyDeliveryOf<"ft_transfer", ChainEventEnvelope<"ft_transfer_event", ChainFtTransferData>> | ChainApplyDeliveryOf<"ft_mint", ChainEventEnvelope<"ft_mint_event", ChainFtMintData>> | ChainApplyDeliveryOf<"ft_burn", ChainEventEnvelope<"ft_burn_event", ChainFtBurnData>> | ChainApplyDeliveryOf<"nft_transfer", ChainEventEnvelope<"nft_transfer_event", ChainNftTransferData>> | ChainApplyDeliveryOf<"nft_mint", ChainEventEnvelope<"nft_mint_event", ChainNftMintData>> | ChainApplyDeliveryOf<"nft_burn", ChainEventEnvelope<"nft_burn_event", ChainNftBurnData>> | ChainApplyDeliveryOf<"print_event", ChainEventEnvelope<"contract_event", ChainPrintEventData>> | ChainApplyDeliveryOf<"contract_call", ChainTxLevelEvent> | ChainApplyDeliveryOf<"contract_deploy", ChainTxLevelEvent> | ChainApplyDeliveryOf<"sbtc_deposit", SbtcDepositEvent> | ChainApplyDeliveryOf<"sbtc_withdrawal_create", SbtcWithdrawalEvent> | ChainApplyDeliveryOf<"sbtc_withdrawal_accept", SbtcWithdrawalEvent> | ChainApplyDeliveryOf<"sbtc_withdrawal_reject", SbtcWithdrawalEvent> | ChainApplyDeliveryOf<"sbtc_withdrawal_swept_confirmed", SbtcWithdrawalSweptConfirmedEvent> | ChainReorgRollbackDelivery | ChainTestDelivery;
3145
- export { validateSubscriptionFilterForTable, sql, setMigrationRole, parseJsonb, onControlPlane, onChainPlane, logger, jsonb, isPox5DecoderEnabled, isPox4DecoderEnabled, getTargetDb, getSourceDb, getRawClientFor, getRawClient, getMigrationRole, getErrorMessage, getEnv, getDbSplitStatus, getDb, generateSubgraphSpec, generateSubgraphOpenApi, generateSubgraphMarkdown, generateSubgraphAgentSchema, formatSubscriptionSchemaErrors, finalizedBurnHeight, encodeStreamsCursor, exports_ed25519 as ed25519, decodeStreamsCursor, exports_hmac as crypto, closeDb, assertDbSplit, X402PaymentsTable, X402BalancesTable, VersionConflictError, ValidationError, UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateTransaction, UpdateTenantUsageMonthly, UpdateTenantComputeAddon, UpdateTenant, UpdateSubscriptionRequestSchema, UpdateSubscriptionRequest, UpdateSubscriptionOutbox, UpdateSubscription, UpdateSubgraphOperation, UpdateSubgraph, UpdateProject, UpdateIndexProgress, UpdateEvent, UpdateContract, UpdateBlock, UpdateApiKey, UpdateAccountSpendCap, UpdateAccountCredits, TriggerEvaluatorStateTable, TriggerEvaluatorState, TransactionsTable, TransactionsArchiveTable, Transaction, TenantsTable, TenantUsageMonthlyTable, TenantUsageMonthly, TenantSuspendedError, TenantStatus, TenantComputeAddonsTable, TenantComputeAddon, Tenant, TeamMembersTable, TeamMember, TeamInvitationsTable, TeamInvitation, TABLE_TO_DB, SubscriptionsTable, SubscriptionSummary, SubscriptionStatusSchema, SubscriptionStatus, SubscriptionSchemaTables, SubscriptionSchemaTable, SubscriptionSchemaColumn, SubscriptionRuntimeSchema, SubscriptionRuntime, SubscriptionOutboxTable, SubscriptionOutbox, SubscriptionKind, SubscriptionFormatSchema, SubscriptionFormat, SubscriptionFilterSchema, SubscriptionFilterPrimitiveSchema, SubscriptionFilterPrimitive, SubscriptionFilterOperatorSchema, SubscriptionFilterOperator, SubscriptionFilterClauseSchema, SubscriptionFilterClause, SubscriptionFilter, SubscriptionDetail, SubscriptionDelivery, SubscriptionDeliveriesTable, Subscription, SubgraphsTable, SubgraphUsageDailyTable, SubgraphUsageDaily, SubgraphTableSnapshotsTable, SubgraphSyncInfo, SubgraphSummary, SubgraphSpecOptions, SubgraphSpecFormat, SubgraphResourceWarning, SubgraphQueryParams, SubgraphProcessingStatsTable, SubgraphOperationsTable, SubgraphOperationStatus, SubgraphOperationKind, SubgraphOperation, SubgraphHealthSnapshotsTable, SubgraphHealthSnapshot, SubgraphGapsTable, SubgraphGapsResponse, SubgraphGapRange, SubgraphGapEntry, SubgraphGap, SubgraphDetail, SubgraphAggregateResponse, SubgraphAggregateParams, SubgraphAgentSchema, Subgraph, StreamsEventType, StreamsDbEventType, StreamsCursor, SessionsTable, Session, ServiceHeartbeatsTable, SecondLayerError, SbtcWithdrawalSweptConfirmedEvent, SbtcWithdrawalEvent, SbtcTokenEventsTable, SbtcTokenEventType, SbtcSupplySnapshotsTable, SbtcSettlementsTable, SbtcEventsTable, SbtcEventTopic, SbtcDepositEvent, SUBSCRIPTION_STATUSES, SUBSCRIPTION_RUNTIMES, SUBSCRIPTION_FORMATS, SUBSCRIPTION_FILTER_OPERATORS, STREAMS_TO_DB_EVENT_TYPES, STREAMS_EVENT_TYPES, STREAMS_DB_EVENT_TYPES, SOURCE_READ_TYPES, SOURCE_READ_PKS, SOURCE_READ_COLUMNS, RotateSecretResponse, ReplaySubscriptionRequestSchema, ReplaySubscriptionRequest, ReplayResult, ReindexResponse, RateLimitError, ProvisioningAuditStatus, ProvisioningAuditLogTable, ProvisioningAuditLog, ProvisioningAuditEvent, ProjectsTable, Project, ProcessedStripeEventsTable, Pox5EventsTable, Pox5EventTopic, Pox4SignersDailyTable, Pox4FunctionName, Pox4CyclesDailyTable, Pox4CallsTable, PendingForkBlocksTable, PaymentRequiredError, ParsedUpdateSubscriptionRequest, ParsedReplaySubscriptionRequest, ParsedCreateSubscriptionRequest, OutboxStatus, ObserverJournalTable, ObserverJournalStatus, NumericAsText, NotFoundError, MigrationRole, MempoolTransactionsTable, MempoolTransaction, MagicLinksTable, MagicLink, KeyRotatedError, InsertTransaction, InsertTenantUsageMonthly, InsertTenantComputeAddon, InsertTenant, InsertTeamMember, InsertTeamInvitation, InsertSubscriptionOutbox, InsertSubscriptionDelivery, InsertSubscription, InsertSubgraphUsageDaily, InsertSubgraphOperation, InsertSubgraphHealthSnapshot, InsertSubgraphGap, InsertSubgraph, InsertSession, InsertProvisioningAuditLog, InsertProject, InsertMempoolTransaction, InsertMagicLink, InsertIndexProgress, InsertEvent, InsertContract, InsertClaimToken, InsertBlock, InsertApiKey, InsertAccountSpendCap, InsertAccountInsight, InsertAccountCredits, InsertAccountAgentRun, InsertAccount, IndexProgressTable, IndexProgress, IndexPrimaryKey, IndexColumnType, IndexColumn, ForbiddenError, EventsTable, EventsArchiveTable, Event, ErrorCodes, ErrorCode, Env, EMPTY_RANGE_EVENT_INDEX_SENTINEL, DeploySubgraphResponse, DeploySubgraphRequestSchema, DeploySubgraphRequest, DeliveryRow, DecoderCheckpointsTable, DecodedEventsTable, DecodedEventType2 as DecodedEventType, DeadRow, DeadLetterEventsTable, DbSplitStatus, DbReadRow, DbPlane, DatabaseError, Database, DEFAULT_BTC_CONFIRMATIONS, DECODED_EVENT_TYPES2 as DECODED_EVENT_TYPES, DB_TO_STREAMS_EVENT_TYPE, CreateSubscriptionResponse, CreateSubscriptionRequestSchema, CreateSubscriptionRequest, ContractsTable, Contract, ClaimTokensTable, ClaimToken, ChainWebhookEnvelope, ChainWebhookDelivery, ChainTxLevelEvent, ChainTestDelivery, ChainStxTransferData, ChainStxMintData, ChainStxLockData, ChainStxBurnData, ChainReorgsTable, ChainReorgRollbackEnvelope, ChainReorgRollbackDelivery, ChainReorgOrphanedEntry, ChainReadCacheTable, ChainPrintEventData, ChainNftTransferData, ChainNftMintData, ChainNftBurnData, ChainFtTransferData, ChainFtMintData, ChainFtBurnData, ChainEventEnvelope, ChainApplyEnvelopeOf, ChainApplyEnvelope, ChainApplyDeliveryOf, CODE_TO_STATUS, CHAIN_TRIGGER_TYPES, CHAIN_TRIGGER_FIELDS, ByoBreakingChangeDetails, BurnBlockRewardsTable, BurnBlockRewardSlotsTable, BnsNamespacesTable, BnsNamespaceEventsTable, BnsNamespaceEventStatus, BnsNamesTable, BnsNameEventsTable, BnsNameEventTopic, BnsMarketplaceEventsTable, BnsMarketplaceAction, BlocksTable, Block, AuthorizationError, AuthenticationError, ApiKeysTable, ApiKey, AccountsTable, AccountSpendCapsTable, AccountSpendCap, AccountInsightsTable, AccountInsight, AccountCreditsTable, AccountCredits, AccountAgentRunsTable, AccountAgentRun, Account };
3253
+ export { validateSubscriptionFilterForTable, sql, setMigrationRole, parseJsonb, onControlPlane, onChainPlane, logger, jsonb, isPox5DecoderEnabled, isPox4DecoderEnabled, isEmptyRangeCursor, getTargetDb, getSourceDb, getRawClientFor, getRawClient, getMigrationRole, getErrorMessage, getEnv, getDbSplitStatus, getDb, generateSubgraphSpec, generateSubgraphOpenApi, generateSubgraphMarkdown, generateSubgraphAgentSchema, formatSubscriptionSchemaErrors, finalizedBurnHeight, encodeStreamsCursor, exports_ed25519 as ed25519, decodeStreamsCursor, exports_hmac as crypto, compareStreamsCursor, closeDb, blockEndCursor, assertDbSplit, applicationDatabaseUrl, X402PaymentsTable, X402BalancesTable, VersionConflictError, ValidationError, UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateTransaction, UpdateTenantUsageMonthly, UpdateTenantComputeAddon, UpdateTenant, UpdateSubscriptionRequestSchema, UpdateSubscriptionRequest, UpdateSubscriptionOutbox, UpdateSubscription, UpdateSubgraphOperation, UpdateSubgraph, UpdateProject, UpdateIndexProgress, UpdateEvent, UpdateContract, UpdateBlock, UpdateApiKey, UpdateAccountSpendCap, UpdateAccountCredits, TriggerEvaluatorStateTable, TriggerEvaluatorState, TransactionsTable, TransactionsArchiveTable, Transaction, TenantsTable, TenantUsageMonthlyTable, TenantUsageMonthly, TenantSuspendedError, TenantStatus, TenantComputeAddonsTable, TenantComputeAddon, Tenant, TeamMembersTable, TeamMember, TeamInvitationsTable, TeamInvitation, TABLE_TO_DB, SubscriptionsTable, SubscriptionSummary, SubscriptionStatusSchema, SubscriptionStatus, SubscriptionSchemaTables, SubscriptionSchemaTable, SubscriptionSchemaColumn, SubscriptionRuntimeSchema, SubscriptionRuntime, SubscriptionOutboxTable, SubscriptionOutbox, SubscriptionKind, SubscriptionFormatSchema, SubscriptionFormat, SubscriptionFilterSchema, SubscriptionFilterPrimitiveSchema, SubscriptionFilterPrimitive, SubscriptionFilterOperatorSchema, SubscriptionFilterOperator, SubscriptionFilterClauseSchema, SubscriptionFilterClause, SubscriptionFilter, SubscriptionDetail, SubscriptionDelivery, SubscriptionDeliveriesTable, Subscription, SubgraphsTable, SubgraphUsageDailyTable, SubgraphUsageDaily, SubgraphTableSnapshotsTable, SubgraphSyncInfo, SubgraphSummary, SubgraphSpecOptions, SubgraphSpecFormat, SubgraphResourceWarning, SubgraphQueryParams, SubgraphProcessingStatsTable, SubgraphOperationsTable, SubgraphOperationStatus, SubgraphOperationKind, SubgraphOperation, SubgraphHealthSnapshotsTable, SubgraphHealthSnapshot, SubgraphGapsTable, SubgraphGapsResponse, SubgraphGapRange, SubgraphGapEntry, SubgraphGap, SubgraphDetail, SubgraphAggregateResponse, SubgraphAggregateParams, SubgraphAgentSchema, Subgraph, StreamsEventType, StreamsDbEventType, StreamsCursor, StageRunsTable, StageRegistryTable, StageKind, StageFailuresTable, StageBlockReceiptsTable, SessionsTable, Session, ServiceHeartbeatsTable, SecondLayerError, SbtcWithdrawalSweptConfirmedEvent, SbtcWithdrawalEvent, SbtcTokenEventsTable, SbtcTokenEventType, SbtcSupplySnapshotsTable, SbtcSettlementsTable, SbtcEventsTable, SbtcEventTopic, SbtcDepositEvent, SUBSCRIPTION_STATUSES, SUBSCRIPTION_RUNTIMES, SUBSCRIPTION_FORMATS, SUBSCRIPTION_FILTER_OPERATORS, STREAMS_TO_DB_EVENT_TYPES, STREAMS_EVENT_TYPES, STREAMS_DB_EVENT_TYPES, SOURCE_READ_TYPES, SOURCE_READ_PKS, SOURCE_READ_COLUMNS, RunStatus, RotateSecretResponse, RetryState, ReplaySubscriptionRequestSchema, ReplaySubscriptionRequest, ReplayResult, RepairMode, ReindexResponse, RateLimitError, ProvisioningAuditStatus, ProvisioningAuditLogTable, ProvisioningAuditLog, ProvisioningAuditEvent, ProjectsTable, Project, ProcessedStripeEventsTable, Pox5EventsTable, Pox5EventTopic, Pox4SignersDailyTable, Pox4FunctionName, Pox4CyclesDailyTable, Pox4CallsTable, PendingForkBlocksTable, PaymentRequiredError, ParsedUpdateSubscriptionRequest, ParsedReplaySubscriptionRequest, ParsedCreateSubscriptionRequest, OutboxStatus, ObserverJournalTable, ObserverJournalStatus, NumericAsText, NotFoundError, NativeClock, MigrationRole, MempoolTransactionsTable, MempoolTransaction, MagicLinksTable, MagicLink, KeyRotatedError, InstancesTable, InsertTransaction, InsertTenantUsageMonthly, InsertTenantComputeAddon, InsertTenant, InsertTeamMember, InsertTeamInvitation, InsertSubscriptionOutbox, InsertSubscriptionDelivery, InsertSubscription, InsertSubgraphUsageDaily, InsertSubgraphOperation, InsertSubgraphHealthSnapshot, InsertSubgraphGap, InsertSubgraph, InsertSession, InsertProvisioningAuditLog, InsertProject, InsertMempoolTransaction, InsertMagicLink, InsertIndexProgress, InsertEvent, InsertContract, InsertClaimToken, InsertBlock, InsertApiKey, InsertAccountSpendCap, InsertAccountInsight, InsertAccountCredits, InsertAccountAgentRun, InsertAccount, IndexProgressTable, IndexProgress, IndexPrimaryKey, IndexColumnType, IndexColumn, ForbiddenError, FailureUnit, FailureClass, EventsTable, EventsArchiveTable, Event, ErrorCodes, ErrorCode, Env, EMPTY_RANGE_EVENT_INDEX_SENTINEL, DeploySubgraphResponse, DeploySubgraphRequestSchema, DeploySubgraphRequest, DeliveryRow, DecoderCheckpointsTable, DecodedEventsTable, DecodedEventType2 as DecodedEventType, DeadRow, DeadLetterEventsTable, DbSplitStatus, DbReadRow, DbPlane, DatabaseError, Database, DEFAULT_BTC_CONFIRMATIONS, DECODED_EVENT_TYPES2 as DECODED_EVENT_TYPES, DB_TO_STREAMS_EVENT_TYPE, CreateSubscriptionResponse, CreateSubscriptionRequestSchema, CreateSubscriptionRequest, CoverageSegmentsTable, ContractsTable, Contract, ClaimTokensTable, ClaimToken, ChainWebhookEnvelope, ChainWebhookDelivery, ChainTxLevelEvent, ChainTestDelivery, ChainStxTransferData, ChainStxMintData, ChainStxLockData, ChainStxBurnData, ChainReorgsTable, ChainReorgRollbackEnvelope, ChainReorgRollbackDelivery, ChainReorgOrphanedEntry, ChainReadCacheTable, ChainPrintEventData, ChainNftTransferData, ChainNftMintData, ChainNftBurnData, ChainFtTransferData, ChainFtMintData, ChainFtBurnData, ChainEventEnvelope, ChainApplyEnvelopeOf, ChainApplyEnvelope, ChainApplyDeliveryOf, CODE_TO_STATUS, CHAIN_TRIGGER_TYPES, CHAIN_TRIGGER_FIELDS, ByoBreakingChangeDetails, BurnBlockRewardsTable, BurnBlockRewardSlotsTable, BnsNamespacesTable, BnsNamespaceEventsTable, BnsNamespaceEventStatus, BnsNamesTable, BnsNameEventsTable, BnsNameEventTopic, BnsMarketplaceEventsTable, BnsMarketplaceAction, BlocksTable, Block, AuthorizationError, AuthenticationError, ApiKeysTable, ApiKey, AccountsTable, AccountSpendCapsTable, AccountSpendCap, AccountInsightsTable, AccountInsight, AccountCreditsTable, AccountCredits, AccountAgentRunsTable, AccountAgentRun, Account };
package/dist/src/index.js CHANGED
@@ -137,6 +137,22 @@ class Logger {
137
137
  }
138
138
  var logger = new Logger;
139
139
 
140
+ // src/mode.ts
141
+ var VALID_MODES = ["oss", "platform"];
142
+ function getInstanceMode() {
143
+ const raw = process.env.INSTANCE_MODE?.trim().toLowerCase();
144
+ if (raw && VALID_MODES.includes(raw)) {
145
+ return raw;
146
+ }
147
+ return "oss";
148
+ }
149
+ function isPlatformMode() {
150
+ return getInstanceMode() === "platform";
151
+ }
152
+ function isOssMode() {
153
+ return getInstanceMode() === "oss";
154
+ }
155
+
140
156
  // src/db/jsonb.ts
141
157
  import { sql } from "kysely";
142
158
  function jsonb(value) {
@@ -705,6 +721,11 @@ var TABLE_TO_DB = {
705
721
  chain_read_cache: "source",
706
722
  pending_fork_blocks: "source",
707
723
  observer_journal: "source",
724
+ stage_registry: "source",
725
+ stage_runs: "source",
726
+ stage_block_receipts: "source",
727
+ coverage_segments: "source",
728
+ stage_failures: "source",
708
729
  decoded_events: "source",
709
730
  decoder_checkpoints: "source",
710
731
  pox4_calls: "source",
@@ -722,6 +743,7 @@ var TABLE_TO_DB = {
722
743
  bns_marketplace_events: "source",
723
744
  bns_names: "source",
724
745
  bns_namespaces: "source",
746
+ instances: "target",
725
747
  accounts: "target",
726
748
  api_keys: "target",
727
749
  sessions: "target",
@@ -784,10 +806,17 @@ function evictIfNeeded() {
784
806
  const evicted = lruEntry;
785
807
  evicted.db.destroy().catch(() => {}).then(() => evicted.rawClient.end({ timeout: 5 })).catch(() => {});
786
808
  }
809
+ function applicationDatabaseUrl() {
810
+ return process.env.DATABASE_URL || DEFAULT_URL;
811
+ }
787
812
  function resolveSourceUrl() {
813
+ if (!isPlatformMode())
814
+ return applicationDatabaseUrl();
788
815
  return process.env.SOURCE_DATABASE_URL || process.env.DATABASE_URL || DEFAULT_URL;
789
816
  }
790
817
  function resolveTargetUrl() {
818
+ if (!isPlatformMode())
819
+ return applicationDatabaseUrl();
791
820
  return process.env.TARGET_DATABASE_URL || process.env.DATABASE_URL || DEFAULT_URL;
792
821
  }
793
822
  function describeDbUrl(url) {
@@ -2016,6 +2045,24 @@ function decodeStreamsCursor(cursor) {
2016
2045
  }
2017
2046
  return decoded;
2018
2047
  }
2048
+ function compareStreamsCursor(a, b) {
2049
+ if (a.block_height !== b.block_height) {
2050
+ return a.block_height < b.block_height ? -1 : 1;
2051
+ }
2052
+ if (a.event_index !== b.event_index) {
2053
+ return a.event_index < b.event_index ? -1 : 1;
2054
+ }
2055
+ return 0;
2056
+ }
2057
+ function isEmptyRangeCursor(cursor) {
2058
+ return cursor.event_index === EMPTY_RANGE_EVENT_INDEX_SENTINEL;
2059
+ }
2060
+ function blockEndCursor(height) {
2061
+ return {
2062
+ block_height: height,
2063
+ event_index: EMPTY_RANGE_EVENT_INDEX_SENTINEL
2064
+ };
2065
+ }
2019
2066
  export {
2020
2067
  validateSubscriptionFilterForTable,
2021
2068
  sql2 as sql,
@@ -2027,6 +2074,7 @@ export {
2027
2074
  jsonb,
2028
2075
  isPox5DecoderEnabled,
2029
2076
  isPox4DecoderEnabled,
2077
+ isEmptyRangeCursor,
2030
2078
  getTargetDb,
2031
2079
  getSourceDb,
2032
2080
  getRawClientFor,
@@ -2046,8 +2094,11 @@ export {
2046
2094
  exports_ed25519 as ed25519,
2047
2095
  decodeStreamsCursor,
2048
2096
  exports_hmac as crypto,
2097
+ compareStreamsCursor,
2049
2098
  closeDb,
2099
+ blockEndCursor,
2050
2100
  assertDbSplit,
2101
+ applicationDatabaseUrl,
2051
2102
  VersionConflictError,
2052
2103
  ValidationError,
2053
2104
  UpdateSubscriptionRequestSchema,
@@ -2092,5 +2143,5 @@ export {
2092
2143
  AuthenticationError
2093
2144
  };
2094
2145
 
2095
- //# debugId=34191DAB67D9160664756E2164756E21
2146
+ //# debugId=231D0EA60821FC7764756E2164756E21
2096
2147
  //# sourceMappingURL=index.js.map