@secondlayer/shared 6.8.1 → 6.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.
- package/dist/src/db/index.d.ts +47 -1
- package/dist/src/db/index.js +42 -3
- package/dist/src/db/index.js.map +3 -3
- package/dist/src/db/queries/chain-reorgs.d.ts +36 -0
- package/dist/src/db/queries/chain-reorgs.js +41 -3
- package/dist/src/db/queries/chain-reorgs.js.map +3 -3
- package/dist/src/db/queries/contracts.d.ts +783 -0
- package/dist/src/db/queries/contracts.js +90 -0
- package/dist/src/db/queries/contracts.js.map +11 -0
- package/dist/src/db/queries/integrity.d.ts +36 -0
- package/dist/src/db/queries/subgraph-gaps.d.ts +36 -0
- package/dist/src/db/queries/subgraph-operations.d.ts +36 -0
- package/dist/src/db/queries/subgraphs.d.ts +58 -1
- package/dist/src/db/queries/subgraphs.js +390 -6
- package/dist/src/db/queries/subgraphs.js.map +9 -4
- package/dist/src/db/queries/subscriptions.d.ts +36 -0
- package/dist/src/db/schema.d.ts +40 -1
- package/dist/src/index.d.ts +55 -1
- package/dist/src/index.js +45 -4
- package/dist/src/index.js.map +4 -4
- package/dist/src/node/client.d.ts +2 -0
- package/dist/src/node/client.js +11 -1
- package/dist/src/node/client.js.map +3 -3
- package/dist/src/node/local-client.d.ts +36 -0
- package/dist/src/schemas/index.d.ts +8 -0
- package/dist/src/schemas/index.js +4 -2
- package/dist/src/schemas/index.js.map +3 -3
- package/dist/src/schemas/subgraphs.d.ts +8 -0
- package/dist/src/schemas/subgraphs.js +4 -2
- package/dist/src/schemas/subgraphs.js.map +3 -3
- package/migrations/0066_public_l2_decoded_events.ts +4 -2
- package/migrations/0067_product_usage_counters.ts +4 -2
- package/migrations/0081_subgraphs_database_url_enc.ts +16 -0
- package/migrations/0082_contracts_registry.ts +44 -0
- package/migrations/0083_burnchain_rewards.ts +63 -0
- package/package.json +6 -2
|
@@ -61,9 +61,22 @@ interface SubgraphsTable {
|
|
|
61
61
|
handler_code: string | null;
|
|
62
62
|
source_code: string | null;
|
|
63
63
|
project_id: string | null;
|
|
64
|
+
database_url_enc: ColumnType<Buffer | null, Buffer | null | undefined, Buffer | null>;
|
|
64
65
|
created_at: Generated<Date>;
|
|
65
66
|
updated_at: Generated<Date>;
|
|
66
67
|
}
|
|
68
|
+
interface ContractsTable {
|
|
69
|
+
contract_id: string;
|
|
70
|
+
deployer: string;
|
|
71
|
+
block_height: number;
|
|
72
|
+
canonical: Generated<boolean>;
|
|
73
|
+
abi: unknown | null;
|
|
74
|
+
declared_traits: Generated<string[]>;
|
|
75
|
+
inferred_standards: Generated<string[]>;
|
|
76
|
+
abi_status: Generated<string>;
|
|
77
|
+
abi_fetched_at: Date | null;
|
|
78
|
+
created_at: Generated<Date>;
|
|
79
|
+
}
|
|
67
80
|
interface SubgraphGapsTable {
|
|
68
81
|
id: Generated<string>;
|
|
69
82
|
subgraph_id: string;
|
|
@@ -367,6 +380,26 @@ interface Pox4SignersDailyTable {
|
|
|
367
380
|
aggregation_calls: Generated<number>;
|
|
368
381
|
updated_at: Generated<Date>;
|
|
369
382
|
}
|
|
383
|
+
interface BurnBlockRewardsTable {
|
|
384
|
+
cursor: string;
|
|
385
|
+
burn_block_height: number;
|
|
386
|
+
burn_block_hash: string;
|
|
387
|
+
reward_index: number;
|
|
388
|
+
recipient_btc: string;
|
|
389
|
+
amount_sats: string;
|
|
390
|
+
burn_amount: Generated<string>;
|
|
391
|
+
canonical: Generated<boolean>;
|
|
392
|
+
created_at: Generated<Date>;
|
|
393
|
+
}
|
|
394
|
+
interface BurnBlockRewardSlotsTable {
|
|
395
|
+
cursor: string;
|
|
396
|
+
burn_block_height: number;
|
|
397
|
+
burn_block_hash: string;
|
|
398
|
+
slot_index: number;
|
|
399
|
+
holder_btc: string;
|
|
400
|
+
canonical: Generated<boolean>;
|
|
401
|
+
created_at: Generated<Date>;
|
|
402
|
+
}
|
|
370
403
|
type SbtcEventTopic = "completed-deposit" | "withdrawal-create" | "withdrawal-accept" | "withdrawal-reject" | "key-rotation" | "update-protocol-contract";
|
|
371
404
|
interface SbtcEventsTable {
|
|
372
405
|
cursor: string;
|
|
@@ -519,6 +552,7 @@ interface Database {
|
|
|
519
552
|
transactions: TransactionsTable;
|
|
520
553
|
events: EventsTable;
|
|
521
554
|
index_progress: IndexProgressTable;
|
|
555
|
+
contracts: ContractsTable;
|
|
522
556
|
subgraphs: SubgraphsTable;
|
|
523
557
|
api_keys: ApiKeysTable;
|
|
524
558
|
accounts: AccountsTable;
|
|
@@ -554,6 +588,8 @@ interface Database {
|
|
|
554
588
|
pox4_calls: Pox4CallsTable;
|
|
555
589
|
pox4_cycles_daily: Pox4CyclesDailyTable;
|
|
556
590
|
pox4_signers_daily: Pox4SignersDailyTable;
|
|
591
|
+
burn_block_rewards: BurnBlockRewardsTable;
|
|
592
|
+
burn_block_reward_slots: BurnBlockRewardSlotsTable;
|
|
557
593
|
sbtc_events: SbtcEventsTable;
|
|
558
594
|
sbtc_token_events: SbtcTokenEventsTable;
|
|
559
595
|
sbtc_supply_snapshots: SbtcSupplySnapshotsTable;
|
package/dist/src/db/schema.d.ts
CHANGED
|
@@ -60,9 +60,22 @@ interface SubgraphsTable {
|
|
|
60
60
|
handler_code: string | null;
|
|
61
61
|
source_code: string | null;
|
|
62
62
|
project_id: string | null;
|
|
63
|
+
database_url_enc: ColumnType<Buffer | null, Buffer | null | undefined, Buffer | null>;
|
|
63
64
|
created_at: Generated<Date>;
|
|
64
65
|
updated_at: Generated<Date>;
|
|
65
66
|
}
|
|
67
|
+
interface ContractsTable {
|
|
68
|
+
contract_id: string;
|
|
69
|
+
deployer: string;
|
|
70
|
+
block_height: number;
|
|
71
|
+
canonical: Generated<boolean>;
|
|
72
|
+
abi: unknown | null;
|
|
73
|
+
declared_traits: Generated<string[]>;
|
|
74
|
+
inferred_standards: Generated<string[]>;
|
|
75
|
+
abi_status: Generated<string>;
|
|
76
|
+
abi_fetched_at: Date | null;
|
|
77
|
+
created_at: Generated<Date>;
|
|
78
|
+
}
|
|
66
79
|
interface SubgraphGapsTable {
|
|
67
80
|
id: Generated<string>;
|
|
68
81
|
subgraph_id: string;
|
|
@@ -366,6 +379,26 @@ interface Pox4SignersDailyTable {
|
|
|
366
379
|
aggregation_calls: Generated<number>;
|
|
367
380
|
updated_at: Generated<Date>;
|
|
368
381
|
}
|
|
382
|
+
interface BurnBlockRewardsTable {
|
|
383
|
+
cursor: string;
|
|
384
|
+
burn_block_height: number;
|
|
385
|
+
burn_block_hash: string;
|
|
386
|
+
reward_index: number;
|
|
387
|
+
recipient_btc: string;
|
|
388
|
+
amount_sats: string;
|
|
389
|
+
burn_amount: Generated<string>;
|
|
390
|
+
canonical: Generated<boolean>;
|
|
391
|
+
created_at: Generated<Date>;
|
|
392
|
+
}
|
|
393
|
+
interface BurnBlockRewardSlotsTable {
|
|
394
|
+
cursor: string;
|
|
395
|
+
burn_block_height: number;
|
|
396
|
+
burn_block_hash: string;
|
|
397
|
+
slot_index: number;
|
|
398
|
+
holder_btc: string;
|
|
399
|
+
canonical: Generated<boolean>;
|
|
400
|
+
created_at: Generated<Date>;
|
|
401
|
+
}
|
|
369
402
|
type SbtcEventTopic = "completed-deposit" | "withdrawal-create" | "withdrawal-accept" | "withdrawal-reject" | "key-rotation" | "update-protocol-contract";
|
|
370
403
|
interface SbtcEventsTable {
|
|
371
404
|
cursor: string;
|
|
@@ -518,6 +551,7 @@ interface Database {
|
|
|
518
551
|
transactions: TransactionsTable;
|
|
519
552
|
events: EventsTable;
|
|
520
553
|
index_progress: IndexProgressTable;
|
|
554
|
+
contracts: ContractsTable;
|
|
521
555
|
subgraphs: SubgraphsTable;
|
|
522
556
|
api_keys: ApiKeysTable;
|
|
523
557
|
accounts: AccountsTable;
|
|
@@ -553,6 +587,8 @@ interface Database {
|
|
|
553
587
|
pox4_calls: Pox4CallsTable;
|
|
554
588
|
pox4_cycles_daily: Pox4CyclesDailyTable;
|
|
555
589
|
pox4_signers_daily: Pox4SignersDailyTable;
|
|
590
|
+
burn_block_rewards: BurnBlockRewardsTable;
|
|
591
|
+
burn_block_reward_slots: BurnBlockRewardSlotsTable;
|
|
556
592
|
sbtc_events: SbtcEventsTable;
|
|
557
593
|
sbtc_token_events: SbtcTokenEventsTable;
|
|
558
594
|
sbtc_supply_snapshots: SbtcSupplySnapshotsTable;
|
|
@@ -671,6 +707,9 @@ type UpdateIndexProgress = Updateable<IndexProgressTable>;
|
|
|
671
707
|
type Subgraph = Selectable<SubgraphsTable>;
|
|
672
708
|
type InsertSubgraph = Insertable<SubgraphsTable>;
|
|
673
709
|
type UpdateSubgraph = Updateable<SubgraphsTable>;
|
|
710
|
+
type Contract = Selectable<ContractsTable>;
|
|
711
|
+
type InsertContract = Insertable<ContractsTable>;
|
|
712
|
+
type UpdateContract = Updateable<ContractsTable>;
|
|
674
713
|
type SubgraphOperation = Selectable<SubgraphOperationsTable>;
|
|
675
714
|
type InsertSubgraphOperation = Insertable<SubgraphOperationsTable>;
|
|
676
715
|
type UpdateSubgraphOperation = Updateable<SubgraphOperationsTable>;
|
|
@@ -779,4 +818,4 @@ interface SubscriptionDeliveriesTable {
|
|
|
779
818
|
}
|
|
780
819
|
type SubscriptionDelivery = Selectable<SubscriptionDeliveriesTable>;
|
|
781
820
|
type InsertSubscriptionDelivery = Insertable<SubscriptionDeliveriesTable>;
|
|
782
|
-
export { UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateTransaction, UpdateTenantUsageMonthly, UpdateTenantComputeAddon, UpdateTenant, UpdateSubscriptionOutbox, UpdateSubscription, UpdateSubgraphOperation, UpdateSubgraph, UpdateProject, UpdateIndexProgress, UpdateEvent, UpdateChatSession, UpdateBlock, UpdateApiKey, UpdateAccountSpendCap, TransactionsTable, Transaction, TenantsTable, TenantUsageMonthlyTable, TenantUsageMonthly, TenantStatus, TenantComputeAddonsTable, TenantComputeAddon, Tenant, TeamMembersTable, TeamMember, TeamInvitationsTable, TeamInvitation, SubscriptionsTable, SubscriptionStatus, SubscriptionRuntime, SubscriptionOutboxTable, SubscriptionOutbox, SubscriptionFormat, SubscriptionDelivery, SubscriptionDeliveriesTable, Subscription, SubgraphsTable, SubgraphUsageDailyTable, SubgraphUsageDaily, SubgraphTableSnapshotsTable, SubgraphProcessingStatsTable, SubgraphOperationsTable, SubgraphOperationStatus, SubgraphOperationKind, SubgraphOperation, SubgraphHealthSnapshotsTable, SubgraphHealthSnapshot, SubgraphGapsTable, SubgraphGap, Subgraph, SessionsTable, Session, ServiceHeartbeatsTable, SbtcTokenEventsTable, SbtcTokenEventType, SbtcSupplySnapshotsTable, SbtcEventsTable, SbtcEventTopic, ProvisioningAuditStatus, ProvisioningAuditLogTable, ProvisioningAuditLog, ProvisioningAuditEvent, ProjectsTable, Project, ProcessedStripeEventsTable, Pox4SignersDailyTable, Pox4FunctionName, Pox4CyclesDailyTable, Pox4CallsTable, OutboxStatus, MagicLinksTable, MagicLink, L2DecoderCheckpointsTable, InsertTransaction, InsertTenantUsageMonthly, InsertTenantComputeAddon, InsertTenant, InsertTeamMember, InsertTeamInvitation, InsertSubscriptionOutbox, InsertSubscriptionDelivery, InsertSubscription, InsertSubgraphUsageDaily, InsertSubgraphOperation, InsertSubgraphHealthSnapshot, InsertSubgraphGap, InsertSubgraph, InsertSession, InsertProvisioningAuditLog, InsertProject, InsertMagicLink, InsertIndexProgress, InsertEvent, InsertChatSession, InsertChatMessage, InsertBlock, InsertApiKey, InsertAccountSpendCap, InsertAccountInsight, InsertAccountAgentRun, InsertAccount, IndexProgressTable, IndexProgress, EventsTable, Event, DecodedEventsTable, Database, ChatSessionsTable, ChatSession, ChatMessagesTable, ChatMessage, ChainReorgsTable, BnsNamespacesTable, BnsNamespaceEventsTable, BnsNamespaceEventStatus, BnsNamesTable, BnsNameEventsTable, BnsNameEventTopic, BnsMarketplaceEventsTable, BnsMarketplaceAction, BlocksTable, Block, ApiKeysTable, ApiKey, AccountsTable, AccountSpendCapsTable, AccountSpendCap, AccountInsightsTable, AccountInsight, AccountAgentRunsTable, AccountAgentRun, Account };
|
|
821
|
+
export { UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateTransaction, UpdateTenantUsageMonthly, UpdateTenantComputeAddon, UpdateTenant, UpdateSubscriptionOutbox, UpdateSubscription, UpdateSubgraphOperation, UpdateSubgraph, UpdateProject, UpdateIndexProgress, UpdateEvent, UpdateContract, UpdateChatSession, UpdateBlock, UpdateApiKey, UpdateAccountSpendCap, TransactionsTable, Transaction, TenantsTable, TenantUsageMonthlyTable, TenantUsageMonthly, TenantStatus, TenantComputeAddonsTable, TenantComputeAddon, Tenant, TeamMembersTable, TeamMember, TeamInvitationsTable, TeamInvitation, SubscriptionsTable, SubscriptionStatus, SubscriptionRuntime, SubscriptionOutboxTable, SubscriptionOutbox, SubscriptionFormat, SubscriptionDelivery, SubscriptionDeliveriesTable, Subscription, SubgraphsTable, SubgraphUsageDailyTable, SubgraphUsageDaily, SubgraphTableSnapshotsTable, SubgraphProcessingStatsTable, SubgraphOperationsTable, SubgraphOperationStatus, SubgraphOperationKind, SubgraphOperation, SubgraphHealthSnapshotsTable, SubgraphHealthSnapshot, SubgraphGapsTable, SubgraphGap, Subgraph, SessionsTable, Session, ServiceHeartbeatsTable, SbtcTokenEventsTable, SbtcTokenEventType, SbtcSupplySnapshotsTable, SbtcEventsTable, SbtcEventTopic, ProvisioningAuditStatus, ProvisioningAuditLogTable, ProvisioningAuditLog, ProvisioningAuditEvent, ProjectsTable, Project, ProcessedStripeEventsTable, Pox4SignersDailyTable, Pox4FunctionName, Pox4CyclesDailyTable, Pox4CallsTable, OutboxStatus, MagicLinksTable, MagicLink, L2DecoderCheckpointsTable, InsertTransaction, InsertTenantUsageMonthly, InsertTenantComputeAddon, InsertTenant, InsertTeamMember, InsertTeamInvitation, InsertSubscriptionOutbox, InsertSubscriptionDelivery, InsertSubscription, InsertSubgraphUsageDaily, InsertSubgraphOperation, InsertSubgraphHealthSnapshot, InsertSubgraphGap, InsertSubgraph, InsertSession, InsertProvisioningAuditLog, InsertProject, InsertMagicLink, InsertIndexProgress, InsertEvent, InsertContract, InsertChatSession, InsertChatMessage, InsertBlock, InsertApiKey, InsertAccountSpendCap, InsertAccountInsight, InsertAccountAgentRun, InsertAccount, IndexProgressTable, IndexProgress, EventsTable, Event, DecodedEventsTable, Database, ContractsTable, Contract, ChatSessionsTable, ChatSession, ChatMessagesTable, ChatMessage, ChainReorgsTable, BurnBlockRewardsTable, BurnBlockRewardSlotsTable, BnsNamespacesTable, BnsNamespaceEventsTable, BnsNamespaceEventStatus, BnsNamesTable, BnsNameEventsTable, BnsNameEventTopic, BnsMarketplaceEventsTable, BnsMarketplaceAction, BlocksTable, Block, ApiKeysTable, ApiKey, AccountsTable, AccountSpendCapsTable, AccountSpendCap, AccountInsightsTable, AccountInsight, AccountAgentRunsTable, AccountAgentRun, Account };
|
package/dist/src/index.d.ts
CHANGED
|
@@ -60,9 +60,22 @@ interface SubgraphsTable {
|
|
|
60
60
|
handler_code: string | null;
|
|
61
61
|
source_code: string | null;
|
|
62
62
|
project_id: string | null;
|
|
63
|
+
database_url_enc: ColumnType<Buffer | null, Buffer | null | undefined, Buffer | null>;
|
|
63
64
|
created_at: Generated<Date>;
|
|
64
65
|
updated_at: Generated<Date>;
|
|
65
66
|
}
|
|
67
|
+
interface ContractsTable {
|
|
68
|
+
contract_id: string;
|
|
69
|
+
deployer: string;
|
|
70
|
+
block_height: number;
|
|
71
|
+
canonical: Generated<boolean>;
|
|
72
|
+
abi: unknown | null;
|
|
73
|
+
declared_traits: Generated<string[]>;
|
|
74
|
+
inferred_standards: Generated<string[]>;
|
|
75
|
+
abi_status: Generated<string>;
|
|
76
|
+
abi_fetched_at: Date | null;
|
|
77
|
+
created_at: Generated<Date>;
|
|
78
|
+
}
|
|
66
79
|
interface SubgraphGapsTable {
|
|
67
80
|
id: Generated<string>;
|
|
68
81
|
subgraph_id: string;
|
|
@@ -366,6 +379,26 @@ interface Pox4SignersDailyTable {
|
|
|
366
379
|
aggregation_calls: Generated<number>;
|
|
367
380
|
updated_at: Generated<Date>;
|
|
368
381
|
}
|
|
382
|
+
interface BurnBlockRewardsTable {
|
|
383
|
+
cursor: string;
|
|
384
|
+
burn_block_height: number;
|
|
385
|
+
burn_block_hash: string;
|
|
386
|
+
reward_index: number;
|
|
387
|
+
recipient_btc: string;
|
|
388
|
+
amount_sats: string;
|
|
389
|
+
burn_amount: Generated<string>;
|
|
390
|
+
canonical: Generated<boolean>;
|
|
391
|
+
created_at: Generated<Date>;
|
|
392
|
+
}
|
|
393
|
+
interface BurnBlockRewardSlotsTable {
|
|
394
|
+
cursor: string;
|
|
395
|
+
burn_block_height: number;
|
|
396
|
+
burn_block_hash: string;
|
|
397
|
+
slot_index: number;
|
|
398
|
+
holder_btc: string;
|
|
399
|
+
canonical: Generated<boolean>;
|
|
400
|
+
created_at: Generated<Date>;
|
|
401
|
+
}
|
|
369
402
|
type SbtcEventTopic = "completed-deposit" | "withdrawal-create" | "withdrawal-accept" | "withdrawal-reject" | "key-rotation" | "update-protocol-contract";
|
|
370
403
|
interface SbtcEventsTable {
|
|
371
404
|
cursor: string;
|
|
@@ -518,6 +551,7 @@ interface Database {
|
|
|
518
551
|
transactions: TransactionsTable;
|
|
519
552
|
events: EventsTable;
|
|
520
553
|
index_progress: IndexProgressTable;
|
|
554
|
+
contracts: ContractsTable;
|
|
521
555
|
subgraphs: SubgraphsTable;
|
|
522
556
|
api_keys: ApiKeysTable;
|
|
523
557
|
accounts: AccountsTable;
|
|
@@ -553,6 +587,8 @@ interface Database {
|
|
|
553
587
|
pox4_calls: Pox4CallsTable;
|
|
554
588
|
pox4_cycles_daily: Pox4CyclesDailyTable;
|
|
555
589
|
pox4_signers_daily: Pox4SignersDailyTable;
|
|
590
|
+
burn_block_rewards: BurnBlockRewardsTable;
|
|
591
|
+
burn_block_reward_slots: BurnBlockRewardSlotsTable;
|
|
556
592
|
sbtc_events: SbtcEventsTable;
|
|
557
593
|
sbtc_token_events: SbtcTokenEventsTable;
|
|
558
594
|
sbtc_supply_snapshots: SbtcSupplySnapshotsTable;
|
|
@@ -671,6 +707,9 @@ type UpdateIndexProgress = Updateable<IndexProgressTable>;
|
|
|
671
707
|
type Subgraph = Selectable<SubgraphsTable>;
|
|
672
708
|
type InsertSubgraph = Insertable<SubgraphsTable>;
|
|
673
709
|
type UpdateSubgraph = Updateable<SubgraphsTable>;
|
|
710
|
+
type Contract = Selectable<ContractsTable>;
|
|
711
|
+
type InsertContract = Insertable<ContractsTable>;
|
|
712
|
+
type UpdateContract = Updateable<ContractsTable>;
|
|
674
713
|
type SubgraphOperation = Selectable<SubgraphOperationsTable>;
|
|
675
714
|
type InsertSubgraphOperation = Insertable<SubgraphOperationsTable>;
|
|
676
715
|
type UpdateSubgraphOperation = Updateable<SubgraphOperationsTable>;
|
|
@@ -842,6 +881,13 @@ declare function getDb(connectionString?: string): Kysely<Database>;
|
|
|
842
881
|
* Defaults to the target role (tenant schemas live in the target DB).
|
|
843
882
|
*/
|
|
844
883
|
declare function getRawClient(role?: "source" | "target"): ReturnType<typeof postgres>;
|
|
884
|
+
/**
|
|
885
|
+
* Raw postgres.js client for an arbitrary connection string (cached by URL).
|
|
886
|
+
* Used by the BYO data plane to run DDL / serving queries against a
|
|
887
|
+
* user-owned Postgres. Distinct from {@link getRawClient}, which only knows the
|
|
888
|
+
* source/target roles resolved from env.
|
|
889
|
+
*/
|
|
890
|
+
declare function getRawClientFor(url: string): ReturnType<typeof postgres>;
|
|
845
891
|
/** Close all DB connection pools. Call in CLI commands to allow process exit. */
|
|
846
892
|
declare function closeDb(): Promise<void>;
|
|
847
893
|
declare const ErrorCodes: {
|
|
@@ -1028,6 +1074,14 @@ interface DeploySubgraphRequest {
|
|
|
1028
1074
|
startBlock?: number;
|
|
1029
1075
|
/** Original TypeScript source, persisted so chat can read/diff/edit later. */
|
|
1030
1076
|
sourceCode?: string;
|
|
1077
|
+
/**
|
|
1078
|
+
* BYO data plane: a user-owned Postgres connection string. When set, the
|
|
1079
|
+
* subgraph's schema, handler writes, and serving reads live in this DB instead
|
|
1080
|
+
* of the managed one. Stored encrypted at rest, never returned.
|
|
1081
|
+
*/
|
|
1082
|
+
databaseUrl?: string;
|
|
1083
|
+
/** Validate the connection + print the DDL/grant plan without deploying. */
|
|
1084
|
+
dryRun?: boolean;
|
|
1031
1085
|
}
|
|
1032
1086
|
declare const DeploySubgraphRequestSchema: z3.ZodType<DeploySubgraphRequest>;
|
|
1033
1087
|
interface DeploySubgraphResponse {
|
|
@@ -1376,4 +1430,4 @@ declare function createSignatureHeader(payload: string, secret: string, timestam
|
|
|
1376
1430
|
* Returns true if valid, false otherwise
|
|
1377
1431
|
*/
|
|
1378
1432
|
declare function verifySignatureHeader(payload: string, header: string, secret: string, toleranceSeconds?: number): boolean;
|
|
1379
|
-
export { validateSubscriptionFilterForTable, sql, parseJsonb, logger, jsonb, getTargetDb, getSourceDb, getRawClient, getErrorMessage, getEnv, getDb, generateSubgraphSpec, generateSubgraphOpenApi, generateSubgraphMarkdown, generateSubgraphAgentSchema, formatSubscriptionSchemaErrors, exports_hmac as crypto, closeDb, VersionConflictError, ValidationError, UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateTransaction, UpdateTenantUsageMonthly, UpdateTenantComputeAddon, UpdateTenant, UpdateSubscriptionRequestSchema, UpdateSubscriptionRequest, UpdateSubscriptionOutbox, UpdateSubscription, UpdateSubgraphOperation, UpdateSubgraph, UpdateProject, UpdateIndexProgress, UpdateEvent, UpdateChatSession, UpdateBlock, UpdateApiKey, UpdateAccountSpendCap, TransactionsTable, Transaction, TenantsTable, TenantUsageMonthlyTable, TenantUsageMonthly, TenantSuspendedError, TenantStatus, TenantComputeAddonsTable, TenantComputeAddon, Tenant, TeamMembersTable, TeamMember, TeamInvitationsTable, TeamInvitation, SubscriptionsTable, SubscriptionSummary, SubscriptionStatusSchema, SubscriptionStatus, SubscriptionSchemaTables, SubscriptionSchemaTable, SubscriptionSchemaColumn, SubscriptionRuntimeSchema, SubscriptionRuntime, SubscriptionOutboxTable, SubscriptionOutbox, 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, SubgraphAgentSchema, Subgraph, StxTransferFilterSchema, StxTransferFilter, StxMintFilterSchema, StxMintFilter, StxLockFilterSchema, StxLockFilter, StxBurnFilterSchema, StxBurnFilter, SessionsTable, Session, ServiceHeartbeatsTable, SecondLayerError, SbtcTokenEventsTable, SbtcTokenEventType, SbtcSupplySnapshotsTable, SbtcEventsTable, SbtcEventTopic, SUBSCRIPTION_STATUSES, SUBSCRIPTION_RUNTIMES, SUBSCRIPTION_FORMATS, SUBSCRIPTION_FILTER_OPERATORS, RotateSecretResponse, ReplaySubscriptionRequestSchema, ReplaySubscriptionRequest, ReplayResult, ReindexResponse, RateLimitError, ProvisioningAuditStatus, ProvisioningAuditLogTable, ProvisioningAuditLog, ProvisioningAuditEvent, ProjectsTable, Project, ProcessedStripeEventsTable, PrintEventFilterSchema, PrintEventFilter, Pox4SignersDailyTable, Pox4FunctionName, Pox4CyclesDailyTable, Pox4CallsTable, ParsedUpdateSubscriptionRequest, ParsedReplaySubscriptionRequest, ParsedCreateSubscriptionRequest, OutboxStatus, NotFoundError, NftTransferFilterSchema, NftTransferFilter, NftMintFilterSchema, NftMintFilter, NftBurnFilterSchema, NftBurnFilter, MagicLinksTable, MagicLink, L2DecoderCheckpointsTable, KeyRotatedError, InsertTransaction, InsertTenantUsageMonthly, InsertTenantComputeAddon, InsertTenant, InsertTeamMember, InsertTeamInvitation, InsertSubscriptionOutbox, InsertSubscriptionDelivery, InsertSubscription, InsertSubgraphUsageDaily, InsertSubgraphOperation, InsertSubgraphHealthSnapshot, InsertSubgraphGap, InsertSubgraph, InsertSession, InsertProvisioningAuditLog, InsertProject, InsertMagicLink, InsertIndexProgress, InsertEvent, InsertChatSession, InsertChatMessage, InsertBlock, InsertApiKey, InsertAccountSpendCap, InsertAccountInsight, InsertAccountAgentRun, InsertAccount, IndexProgressTable, IndexProgress, FtTransferFilterSchema, FtTransferFilter, FtMintFilterSchema, FtMintFilter, FtBurnFilterSchema, FtBurnFilter, ForbiddenError, EventsTable, EventFilterSchema, EventFilter, Event, ErrorCodes, ErrorCode, Env, DeploySubgraphResponse, DeploySubgraphRequestSchema, DeploySubgraphRequest, DeliveryRow, DecodedEventsTable, DeadRow, DatabaseError, Database, CreateSubscriptionResponse, CreateSubscriptionRequestSchema, CreateSubscriptionRequest, ContractDeployFilterSchema, ContractDeployFilter, ContractCallFilterSchema, ContractCallFilter, ChatSessionsTable, ChatSession, ChatMessagesTable, ChatMessage, ChainReorgsTable, CODE_TO_STATUS, BnsNamespacesTable, BnsNamespaceEventsTable, BnsNamespaceEventStatus, BnsNamesTable, BnsNameEventsTable, BnsNameEventTopic, BnsMarketplaceEventsTable, BnsMarketplaceAction, BlocksTable, Block, AuthorizationError, AuthenticationError, ApiKeysTable, ApiKey, AccountsTable, AccountSpendCapsTable, AccountSpendCap, AccountInsightsTable, AccountInsight, AccountAgentRunsTable, AccountAgentRun, Account };
|
|
1433
|
+
export { validateSubscriptionFilterForTable, sql, parseJsonb, logger, jsonb, getTargetDb, getSourceDb, getRawClientFor, getRawClient, getErrorMessage, getEnv, getDb, generateSubgraphSpec, generateSubgraphOpenApi, generateSubgraphMarkdown, generateSubgraphAgentSchema, formatSubscriptionSchemaErrors, exports_hmac as crypto, closeDb, VersionConflictError, ValidationError, UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateTransaction, UpdateTenantUsageMonthly, UpdateTenantComputeAddon, UpdateTenant, UpdateSubscriptionRequestSchema, UpdateSubscriptionRequest, UpdateSubscriptionOutbox, UpdateSubscription, UpdateSubgraphOperation, UpdateSubgraph, UpdateProject, UpdateIndexProgress, UpdateEvent, UpdateContract, UpdateChatSession, UpdateBlock, UpdateApiKey, UpdateAccountSpendCap, TransactionsTable, Transaction, TenantsTable, TenantUsageMonthlyTable, TenantUsageMonthly, TenantSuspendedError, TenantStatus, TenantComputeAddonsTable, TenantComputeAddon, Tenant, TeamMembersTable, TeamMember, TeamInvitationsTable, TeamInvitation, SubscriptionsTable, SubscriptionSummary, SubscriptionStatusSchema, SubscriptionStatus, SubscriptionSchemaTables, SubscriptionSchemaTable, SubscriptionSchemaColumn, SubscriptionRuntimeSchema, SubscriptionRuntime, SubscriptionOutboxTable, SubscriptionOutbox, 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, SubgraphAgentSchema, Subgraph, StxTransferFilterSchema, StxTransferFilter, StxMintFilterSchema, StxMintFilter, StxLockFilterSchema, StxLockFilter, StxBurnFilterSchema, StxBurnFilter, SessionsTable, Session, ServiceHeartbeatsTable, SecondLayerError, SbtcTokenEventsTable, SbtcTokenEventType, SbtcSupplySnapshotsTable, SbtcEventsTable, SbtcEventTopic, SUBSCRIPTION_STATUSES, SUBSCRIPTION_RUNTIMES, SUBSCRIPTION_FORMATS, SUBSCRIPTION_FILTER_OPERATORS, RotateSecretResponse, ReplaySubscriptionRequestSchema, ReplaySubscriptionRequest, ReplayResult, ReindexResponse, RateLimitError, ProvisioningAuditStatus, ProvisioningAuditLogTable, ProvisioningAuditLog, ProvisioningAuditEvent, ProjectsTable, Project, ProcessedStripeEventsTable, PrintEventFilterSchema, PrintEventFilter, Pox4SignersDailyTable, Pox4FunctionName, Pox4CyclesDailyTable, Pox4CallsTable, ParsedUpdateSubscriptionRequest, ParsedReplaySubscriptionRequest, ParsedCreateSubscriptionRequest, OutboxStatus, NotFoundError, NftTransferFilterSchema, NftTransferFilter, NftMintFilterSchema, NftMintFilter, NftBurnFilterSchema, NftBurnFilter, MagicLinksTable, MagicLink, L2DecoderCheckpointsTable, KeyRotatedError, InsertTransaction, InsertTenantUsageMonthly, InsertTenantComputeAddon, InsertTenant, InsertTeamMember, InsertTeamInvitation, InsertSubscriptionOutbox, InsertSubscriptionDelivery, InsertSubscription, InsertSubgraphUsageDaily, InsertSubgraphOperation, InsertSubgraphHealthSnapshot, InsertSubgraphGap, InsertSubgraph, InsertSession, InsertProvisioningAuditLog, InsertProject, InsertMagicLink, InsertIndexProgress, InsertEvent, InsertContract, InsertChatSession, InsertChatMessage, InsertBlock, InsertApiKey, InsertAccountSpendCap, InsertAccountInsight, InsertAccountAgentRun, InsertAccount, IndexProgressTable, IndexProgress, FtTransferFilterSchema, FtTransferFilter, FtMintFilterSchema, FtMintFilter, FtBurnFilterSchema, FtBurnFilter, ForbiddenError, EventsTable, EventFilterSchema, EventFilter, Event, ErrorCodes, ErrorCode, Env, DeploySubgraphResponse, DeploySubgraphRequestSchema, DeploySubgraphRequest, DeliveryRow, DecodedEventsTable, DeadRow, DatabaseError, Database, CreateSubscriptionResponse, CreateSubscriptionRequestSchema, CreateSubscriptionRequest, ContractsTable, ContractDeployFilterSchema, ContractDeployFilter, ContractCallFilterSchema, ContractCallFilter, Contract, ChatSessionsTable, ChatSession, ChatMessagesTable, ChatMessage, ChainReorgsTable, CODE_TO_STATUS, BurnBlockRewardsTable, BurnBlockRewardSlotsTable, BnsNamespacesTable, BnsNamespaceEventsTable, BnsNamespaceEventStatus, BnsNamesTable, BnsNameEventsTable, BnsNameEventTopic, BnsMarketplaceEventsTable, BnsMarketplaceAction, BlocksTable, Block, AuthorizationError, AuthenticationError, ApiKeysTable, ApiKey, AccountsTable, AccountSpendCapsTable, AccountSpendCap, AccountInsightsTable, AccountInsight, AccountAgentRunsTable, AccountAgentRun, Account };
|
package/dist/src/index.js
CHANGED
|
@@ -152,6 +152,30 @@ import postgres from "postgres";
|
|
|
152
152
|
import { sql as sql2 } from "kysely";
|
|
153
153
|
var DEFAULT_URL = "postgres://postgres:postgres@localhost:5432/secondlayer_dev";
|
|
154
154
|
var pools = new Map;
|
|
155
|
+
var poolSeq = 0;
|
|
156
|
+
function maxPools() {
|
|
157
|
+
return Number.parseInt(process.env.DATABASE_MAX_POOLS ?? "25", 10);
|
|
158
|
+
}
|
|
159
|
+
function evictIfNeeded() {
|
|
160
|
+
if (pools.size <= maxPools())
|
|
161
|
+
return;
|
|
162
|
+
const protectedUrls = new Set([resolveSourceUrl(), resolveTargetUrl()]);
|
|
163
|
+
let lruUrl;
|
|
164
|
+
let lruEntry;
|
|
165
|
+
for (const [url, entry] of pools) {
|
|
166
|
+
if (protectedUrls.has(url))
|
|
167
|
+
continue;
|
|
168
|
+
if (!lruEntry || entry.lastUsed < lruEntry.lastUsed || entry.lastUsed === lruEntry.lastUsed && entry.seq < lruEntry.seq) {
|
|
169
|
+
lruUrl = url;
|
|
170
|
+
lruEntry = entry;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (!lruUrl || !lruEntry)
|
|
174
|
+
return;
|
|
175
|
+
pools.delete(lruUrl);
|
|
176
|
+
const evicted = lruEntry;
|
|
177
|
+
evicted.db.destroy().catch(() => {}).then(() => evicted.rawClient.end({ timeout: 5 })).catch(() => {});
|
|
178
|
+
}
|
|
155
179
|
function resolveSourceUrl() {
|
|
156
180
|
return process.env.SOURCE_DATABASE_URL || process.env.DATABASE_URL || DEFAULT_URL;
|
|
157
181
|
}
|
|
@@ -160,8 +184,11 @@ function resolveTargetUrl() {
|
|
|
160
184
|
}
|
|
161
185
|
function getOrCreatePool(url) {
|
|
162
186
|
const existing = pools.get(url);
|
|
163
|
-
if (existing)
|
|
187
|
+
if (existing) {
|
|
188
|
+
existing.lastUsed = Date.now();
|
|
189
|
+
existing.seq = poolSeq++;
|
|
164
190
|
return existing;
|
|
191
|
+
}
|
|
165
192
|
const host = (() => {
|
|
166
193
|
try {
|
|
167
194
|
return new URL(url).hostname;
|
|
@@ -171,8 +198,10 @@ function getOrCreatePool(url) {
|
|
|
171
198
|
})();
|
|
172
199
|
const isLocal = host === "localhost" || host === "127.0.0.1" || !host.includes(".");
|
|
173
200
|
const poolMax = Number.parseInt(process.env.DATABASE_POOL_MAX ?? "20", 10);
|
|
201
|
+
const idleTimeout = Number.parseInt(process.env.DATABASE_IDLE_TIMEOUT ?? "300", 10);
|
|
174
202
|
const rawClient = postgres(url, {
|
|
175
203
|
max: poolMax,
|
|
204
|
+
idle_timeout: idleTimeout,
|
|
176
205
|
ssl: isLocal ? undefined : {
|
|
177
206
|
rejectUnauthorized: process.env.NODE_TLS_REJECT_UNAUTHORIZED !== "0"
|
|
178
207
|
}
|
|
@@ -193,8 +222,14 @@ function getOrCreatePool(url) {
|
|
|
193
222
|
});
|
|
194
223
|
}
|
|
195
224
|
});
|
|
196
|
-
const entry = {
|
|
225
|
+
const entry = {
|
|
226
|
+
db,
|
|
227
|
+
rawClient,
|
|
228
|
+
lastUsed: Date.now(),
|
|
229
|
+
seq: poolSeq++
|
|
230
|
+
};
|
|
197
231
|
pools.set(url, entry);
|
|
232
|
+
evictIfNeeded();
|
|
198
233
|
return entry;
|
|
199
234
|
}
|
|
200
235
|
function getSourceDb() {
|
|
@@ -212,6 +247,9 @@ function getRawClient(role = "target") {
|
|
|
212
247
|
const url = role === "source" ? resolveSourceUrl() : resolveTargetUrl();
|
|
213
248
|
return getOrCreatePool(url).rawClient;
|
|
214
249
|
}
|
|
250
|
+
function getRawClientFor(url) {
|
|
251
|
+
return getOrCreatePool(url).rawClient;
|
|
252
|
+
}
|
|
215
253
|
async function closeDb() {
|
|
216
254
|
for (const entry of pools.values()) {
|
|
217
255
|
await entry.db.destroy();
|
|
@@ -450,7 +488,9 @@ var DeploySubgraphRequestSchema = z3.object({
|
|
|
450
488
|
schema: z3.record(z3.string(), z3.unknown()),
|
|
451
489
|
handlerCode: z3.string().max(1048576, "handler code exceeds 1MB limit"),
|
|
452
490
|
startBlock: z3.number().int().nonnegative().optional(),
|
|
453
|
-
sourceCode: z3.string().max(1048576, "source code exceeds 1MB limit").optional()
|
|
491
|
+
sourceCode: z3.string().max(1048576, "source code exceeds 1MB limit").optional(),
|
|
492
|
+
databaseUrl: z3.string().url().refine((u) => u.startsWith("postgres://") || u.startsWith("postgresql://"), "must be a postgres:// connection string").optional(),
|
|
493
|
+
dryRun: z3.boolean().optional()
|
|
454
494
|
});
|
|
455
495
|
|
|
456
496
|
// src/schemas/subscriptions.ts
|
|
@@ -992,6 +1032,7 @@ export {
|
|
|
992
1032
|
jsonb,
|
|
993
1033
|
getTargetDb,
|
|
994
1034
|
getSourceDb,
|
|
1035
|
+
getRawClientFor,
|
|
995
1036
|
getRawClient,
|
|
996
1037
|
getErrorMessage,
|
|
997
1038
|
getEnv,
|
|
@@ -1047,5 +1088,5 @@ export {
|
|
|
1047
1088
|
AuthenticationError
|
|
1048
1089
|
};
|
|
1049
1090
|
|
|
1050
|
-
//# debugId=
|
|
1091
|
+
//# debugId=40BA68E1C44D67FE64756E2164756E21
|
|
1051
1092
|
//# sourceMappingURL=index.js.map
|