@secondlayer/shared 6.0.0 → 6.1.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.
@@ -4,6 +4,7 @@ interface BlocksTable {
4
4
  hash: string;
5
5
  parent_hash: string;
6
6
  burn_block_height: number;
7
+ burn_block_hash: ColumnType<string | null, string | null | undefined, string | null>;
7
8
  timestamp: number;
8
9
  canonical: Generated<boolean>;
9
10
  created_at: Generated<Date>;
@@ -144,6 +145,8 @@ interface UsageDailyTable {
144
145
  date: string;
145
146
  api_requests: Generated<number>;
146
147
  deliveries: Generated<number>;
148
+ streams_events_returned: Generated<number>;
149
+ index_decoded_events_returned: Generated<number>;
147
150
  }
148
151
  interface UsageSnapshotsTable {
149
152
  id: Generated<string>;
@@ -272,6 +275,44 @@ interface ProcessedStripeEventsTable {
272
275
  event_type: string;
273
276
  processed_at: Generated<Date>;
274
277
  }
278
+ interface DecodedEventsTable {
279
+ cursor: string;
280
+ block_height: number;
281
+ tx_id: string;
282
+ tx_index: number;
283
+ event_index: number;
284
+ event_type: string;
285
+ microblock_hash: string | null;
286
+ canonical: Generated<boolean>;
287
+ contract_id: string | null;
288
+ sender: string | null;
289
+ recipient: string | null;
290
+ amount: string | null;
291
+ asset_identifier: string | null;
292
+ value: string | null;
293
+ memo: string | null;
294
+ source_cursor: string;
295
+ created_at: Generated<Date>;
296
+ }
297
+ interface L2DecoderCheckpointsTable {
298
+ decoder_name: string;
299
+ last_cursor: string | null;
300
+ updated_at: Generated<Date>;
301
+ }
302
+ interface ChainReorgsTable {
303
+ id: Generated<string>;
304
+ detected_at: Generated<Date>;
305
+ fork_point_height: number;
306
+ old_index_block_hash: string | null;
307
+ new_index_block_hash: string | null;
308
+ orphaned_from_height: number;
309
+ orphaned_from_event_index: number;
310
+ orphaned_to_height: number;
311
+ orphaned_to_event_index: number;
312
+ new_canonical_height: number;
313
+ new_canonical_event_index: number;
314
+ created_at: Generated<Date>;
315
+ }
275
316
  interface Database {
276
317
  blocks: BlocksTable;
277
318
  transactions: TransactionsTable;
@@ -307,6 +348,9 @@ interface Database {
307
348
  subscriptions: SubscriptionsTable;
308
349
  subscription_outbox: SubscriptionOutboxTable;
309
350
  subscription_deliveries: SubscriptionDeliveriesTable;
351
+ decoded_events: DecodedEventsTable;
352
+ l2_decoder_checkpoints: L2DecoderCheckpointsTable;
353
+ chain_reorgs: ChainReorgsTable;
310
354
  }
311
355
  type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
312
356
  interface TenantsTable {
@@ -1128,4 +1172,4 @@ declare function createSignatureHeader(payload: string, secret: string, timestam
1128
1172
  * Returns true if valid, false otherwise
1129
1173
  */
1130
1174
  declare function verifySignatureHeader(payload: string, header: string, secret: string, toleranceSeconds?: number): boolean;
1131
- export { validateSubscriptionFilterForTable, sql, parseJsonb, logger, jsonb, getTargetDb, getSourceDb, getRawClient, getErrorMessage, getEnv, getDb, generateSubgraphSpec, generateSubgraphOpenApi, generateSubgraphMarkdown, generateSubgraphAgentSchema, formatSubscriptionSchemaErrors, exports_hmac as crypto, closeDb, WaitlistTable, VersionConflictError, ValidationError, UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateTransaction, UpdateTenantUsageMonthly, UpdateTenantComputeAddon, UpdateTenant, UpdateSubscriptionRequestSchema, UpdateSubscriptionRequest, UpdateSubscriptionOutbox, UpdateSubscription, UpdateSubgraphOperation, UpdateSubgraph, UpdateProject, UpdateProfileRequestSchema, UpdateProfileRequest, 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, SecondLayerError, SUBSCRIPTION_STATUSES, SUBSCRIPTION_RUNTIMES, SUBSCRIPTION_FORMATS, SUBSCRIPTION_FILTER_OPERATORS, RotateSecretResponse, ReplaySubscriptionRequestSchema, ReplaySubscriptionRequest, ReplayResult, ReindexResponse, RateLimitError, ProvisioningAuditStatus, ProvisioningAuditLogTable, ProvisioningAuditLog, ProvisioningAuditEvent, ProjectsTable, Project, ProcessedStripeEventsTable, PrintEventFilterSchema, PrintEventFilter, ParsedUpdateSubscriptionRequest, ParsedReplaySubscriptionRequest, ParsedCreateSubscriptionRequest, OutboxStatus, NotFoundError, NftTransferFilterSchema, NftTransferFilter, NftMintFilterSchema, NftMintFilter, NftBurnFilterSchema, NftBurnFilter, MagicLinksTable, MagicLink, 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, DeadRow, DatabaseError, Database, CreateSubscriptionResponse, CreateSubscriptionRequestSchema, CreateSubscriptionRequest, ContractDeployFilterSchema, ContractDeployFilter, ContractCallFilterSchema, ContractCallFilter, ChatSessionsTable, ChatSession, ChatMessagesTable, ChatMessage, CODE_TO_STATUS, BlocksTable, Block, AuthorizationError, AuthenticationError, ApiKeysTable, ApiKey, AccountsTable, AccountSpendCapsTable, AccountSpendCap, AccountInsightsTable, AccountInsight, AccountAgentRunsTable, AccountAgentRun, Account };
1175
+ export { validateSubscriptionFilterForTable, sql, parseJsonb, logger, jsonb, getTargetDb, getSourceDb, getRawClient, getErrorMessage, getEnv, getDb, generateSubgraphSpec, generateSubgraphOpenApi, generateSubgraphMarkdown, generateSubgraphAgentSchema, formatSubscriptionSchemaErrors, exports_hmac as crypto, closeDb, WaitlistTable, VersionConflictError, ValidationError, UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateTransaction, UpdateTenantUsageMonthly, UpdateTenantComputeAddon, UpdateTenant, UpdateSubscriptionRequestSchema, UpdateSubscriptionRequest, UpdateSubscriptionOutbox, UpdateSubscription, UpdateSubgraphOperation, UpdateSubgraph, UpdateProject, UpdateProfileRequestSchema, UpdateProfileRequest, 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, SecondLayerError, SUBSCRIPTION_STATUSES, SUBSCRIPTION_RUNTIMES, SUBSCRIPTION_FORMATS, SUBSCRIPTION_FILTER_OPERATORS, RotateSecretResponse, ReplaySubscriptionRequestSchema, ReplaySubscriptionRequest, ReplayResult, ReindexResponse, RateLimitError, ProvisioningAuditStatus, ProvisioningAuditLogTable, ProvisioningAuditLog, ProvisioningAuditEvent, ProjectsTable, Project, ProcessedStripeEventsTable, PrintEventFilterSchema, PrintEventFilter, 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, BlocksTable, Block, AuthorizationError, AuthenticationError, ApiKeysTable, ApiKey, AccountsTable, AccountSpendCapsTable, AccountSpendCap, AccountInsightsTable, AccountInsight, AccountAgentRunsTable, AccountAgentRun, Account };
@@ -5,6 +5,7 @@ interface BlocksTable {
5
5
  hash: string;
6
6
  parent_hash: string;
7
7
  burn_block_height: number;
8
+ burn_block_hash: ColumnType<string | null, string | null | undefined, string | null>;
8
9
  timestamp: number;
9
10
  canonical: Generated<boolean>;
10
11
  created_at: Generated<Date>;
@@ -145,6 +146,8 @@ interface UsageDailyTable {
145
146
  date: string;
146
147
  api_requests: Generated<number>;
147
148
  deliveries: Generated<number>;
149
+ streams_events_returned: Generated<number>;
150
+ index_decoded_events_returned: Generated<number>;
148
151
  }
149
152
  interface UsageSnapshotsTable {
150
153
  id: Generated<string>;
@@ -273,6 +276,44 @@ interface ProcessedStripeEventsTable {
273
276
  event_type: string;
274
277
  processed_at: Generated<Date>;
275
278
  }
279
+ interface DecodedEventsTable {
280
+ cursor: string;
281
+ block_height: number;
282
+ tx_id: string;
283
+ tx_index: number;
284
+ event_index: number;
285
+ event_type: string;
286
+ microblock_hash: string | null;
287
+ canonical: Generated<boolean>;
288
+ contract_id: string | null;
289
+ sender: string | null;
290
+ recipient: string | null;
291
+ amount: string | null;
292
+ asset_identifier: string | null;
293
+ value: string | null;
294
+ memo: string | null;
295
+ source_cursor: string;
296
+ created_at: Generated<Date>;
297
+ }
298
+ interface L2DecoderCheckpointsTable {
299
+ decoder_name: string;
300
+ last_cursor: string | null;
301
+ updated_at: Generated<Date>;
302
+ }
303
+ interface ChainReorgsTable {
304
+ id: Generated<string>;
305
+ detected_at: Generated<Date>;
306
+ fork_point_height: number;
307
+ old_index_block_hash: string | null;
308
+ new_index_block_hash: string | null;
309
+ orphaned_from_height: number;
310
+ orphaned_from_event_index: number;
311
+ orphaned_to_height: number;
312
+ orphaned_to_event_index: number;
313
+ new_canonical_height: number;
314
+ new_canonical_event_index: number;
315
+ created_at: Generated<Date>;
316
+ }
276
317
  interface Database {
277
318
  blocks: BlocksTable;
278
319
  transactions: TransactionsTable;
@@ -308,6 +349,9 @@ interface Database {
308
349
  subscriptions: SubscriptionsTable;
309
350
  subscription_outbox: SubscriptionOutboxTable;
310
351
  subscription_deliveries: SubscriptionDeliveriesTable;
352
+ decoded_events: DecodedEventsTable;
353
+ l2_decoder_checkpoints: L2DecoderCheckpointsTable;
354
+ chain_reorgs: ChainReorgsTable;
311
355
  }
312
356
  type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
313
357
  interface TenantsTable {
@@ -1,9 +1,10 @@
1
- import { Generated, Insertable, Selectable } from "kysely";
1
+ import { ColumnType, Generated, Insertable, Selectable } from "kysely";
2
2
  interface BlocksTable {
3
3
  height: number;
4
4
  hash: string;
5
5
  parent_hash: string;
6
6
  burn_block_height: number;
7
+ burn_block_hash: ColumnType<string | null, string | null | undefined, string | null>;
7
8
  timestamp: number;
8
9
  canonical: Generated<boolean>;
9
10
  created_at: Generated<Date>;
@@ -0,0 +1,50 @@
1
+ import { type Kysely, sql } from "kysely";
2
+
3
+ // biome-ignore lint/suspicious/noExplicitAny: migration DDL is intentionally schema-dynamic
4
+ export async function up(db: Kysely<any>): Promise<void> {
5
+ await db.schema
6
+ .createTable("decoded_events")
7
+ .addColumn("cursor", "text", (c) => c.primaryKey())
8
+ .addColumn("block_height", "bigint", (c) => c.notNull())
9
+ .addColumn("tx_id", "text", (c) => c.notNull())
10
+ .addColumn("tx_index", "integer", (c) => c.notNull())
11
+ .addColumn("event_index", "integer", (c) => c.notNull())
12
+ .addColumn("event_type", "text", (c) => c.notNull())
13
+ .addColumn("decoded_payload", "jsonb", (c) => c.notNull())
14
+ .addColumn("source_cursor", "text", (c) => c.notNull())
15
+ .addColumn("created_at", "timestamp", (c) =>
16
+ c.notNull().defaultTo(sql`now()`),
17
+ )
18
+ .execute();
19
+
20
+ await db.schema
21
+ .createIndex("decoded_events_block_height_idx")
22
+ .on("decoded_events")
23
+ .column("block_height")
24
+ .execute();
25
+ await db.schema
26
+ .createIndex("decoded_events_event_type_idx")
27
+ .on("decoded_events")
28
+ .column("event_type")
29
+ .execute();
30
+ await db.schema
31
+ .createIndex("decoded_events_tx_id_event_index_idx")
32
+ .on("decoded_events")
33
+ .columns(["tx_id", "event_index"])
34
+ .execute();
35
+
36
+ await db.schema
37
+ .createTable("l2_decoder_checkpoints")
38
+ .addColumn("decoder_name", "text", (c) => c.primaryKey())
39
+ .addColumn("last_cursor", "text")
40
+ .addColumn("updated_at", "timestamp", (c) =>
41
+ c.notNull().defaultTo(sql`now()`),
42
+ )
43
+ .execute();
44
+ }
45
+
46
+ // biome-ignore lint/suspicious/noExplicitAny: migration DDL is intentionally schema-dynamic
47
+ export async function down(db: Kysely<any>): Promise<void> {
48
+ await db.schema.dropTable("l2_decoder_checkpoints").ifExists().execute();
49
+ await db.schema.dropTable("decoded_events").ifExists().execute();
50
+ }
@@ -0,0 +1,83 @@
1
+ import { type Kysely, sql } from "kysely";
2
+
3
+ export async function up(db: Kysely<unknown>): Promise<void> {
4
+ await sql`
5
+ ALTER TABLE decoded_events
6
+ ADD COLUMN microblock_hash TEXT,
7
+ ADD COLUMN canonical BOOLEAN NOT NULL DEFAULT true,
8
+ ADD COLUMN contract_id TEXT,
9
+ ADD COLUMN sender TEXT,
10
+ ADD COLUMN recipient TEXT,
11
+ ADD COLUMN amount TEXT,
12
+ ADD COLUMN asset_identifier TEXT,
13
+ ADD COLUMN value TEXT,
14
+ ADD COLUMN memo TEXT
15
+ `.execute(db);
16
+
17
+ await sql`
18
+ UPDATE decoded_events
19
+ SET
20
+ contract_id = decoded_payload->>'contract_id',
21
+ sender = decoded_payload->>'sender',
22
+ recipient = decoded_payload->>'recipient',
23
+ amount = decoded_payload->>'amount',
24
+ asset_identifier = decoded_payload->>'asset_identifier'
25
+ WHERE event_type = 'ft_transfer'
26
+ `.execute(db);
27
+
28
+ await sql`ALTER TABLE decoded_events DROP COLUMN decoded_payload`.execute(db);
29
+
30
+ await sql`
31
+ CREATE INDEX decoded_events_contract_height_event_idx
32
+ ON decoded_events (contract_id, block_height, event_index)
33
+ `.execute(db);
34
+ await sql`
35
+ CREATE INDEX decoded_events_sender_height_event_idx
36
+ ON decoded_events (sender, block_height, event_index)
37
+ `.execute(db);
38
+ await sql`
39
+ CREATE INDEX decoded_events_recipient_height_event_idx
40
+ ON decoded_events (recipient, block_height, event_index)
41
+ `.execute(db);
42
+ }
43
+
44
+ export async function down(db: Kysely<unknown>): Promise<void> {
45
+ await sql`DROP INDEX IF EXISTS decoded_events_recipient_height_event_idx`.execute(
46
+ db,
47
+ );
48
+ await sql`DROP INDEX IF EXISTS decoded_events_sender_height_event_idx`.execute(
49
+ db,
50
+ );
51
+ await sql`DROP INDEX IF EXISTS decoded_events_contract_height_event_idx`.execute(
52
+ db,
53
+ );
54
+
55
+ await sql`ALTER TABLE decoded_events ADD COLUMN decoded_payload JSONB`.execute(
56
+ db,
57
+ );
58
+ await sql`
59
+ UPDATE decoded_events
60
+ SET decoded_payload = jsonb_strip_nulls(jsonb_build_object(
61
+ 'contract_id', contract_id,
62
+ 'sender', sender,
63
+ 'recipient', recipient,
64
+ 'amount', amount,
65
+ 'asset_identifier', asset_identifier,
66
+ 'value', value,
67
+ 'memo', memo
68
+ ))
69
+ `.execute(db);
70
+ await sql`
71
+ ALTER TABLE decoded_events
72
+ ALTER COLUMN decoded_payload SET NOT NULL,
73
+ DROP COLUMN memo,
74
+ DROP COLUMN value,
75
+ DROP COLUMN asset_identifier,
76
+ DROP COLUMN amount,
77
+ DROP COLUMN recipient,
78
+ DROP COLUMN sender,
79
+ DROP COLUMN contract_id,
80
+ DROP COLUMN canonical,
81
+ DROP COLUMN microblock_hash
82
+ `.execute(db);
83
+ }
@@ -0,0 +1,18 @@
1
+ import { type Kysely, sql } from "kysely";
2
+
3
+ export async function up(db: Kysely<unknown>): Promise<void> {
4
+ await sql`SET lock_timeout = '30s'`.execute(db);
5
+ await sql`
6
+ ALTER TABLE usage_daily
7
+ ADD COLUMN IF NOT EXISTS streams_events_returned integer NOT NULL DEFAULT 0,
8
+ ADD COLUMN IF NOT EXISTS index_decoded_events_returned integer NOT NULL DEFAULT 0
9
+ `.execute(db);
10
+ }
11
+
12
+ export async function down(db: Kysely<unknown>): Promise<void> {
13
+ await sql`
14
+ ALTER TABLE usage_daily
15
+ DROP COLUMN IF EXISTS index_decoded_events_returned,
16
+ DROP COLUMN IF EXISTS streams_events_returned
17
+ `.execute(db);
18
+ }
@@ -0,0 +1,48 @@
1
+ import { type Kysely, sql } from "kysely";
2
+
3
+ export async function up(db: Kysely<unknown>): Promise<void> {
4
+ await sql`SET lock_timeout = '30s'`.execute(db);
5
+ await sql`
6
+ ALTER TABLE blocks
7
+ ADD COLUMN IF NOT EXISTS burn_block_hash text
8
+ `.execute(db);
9
+
10
+ await sql`
11
+ CREATE TABLE IF NOT EXISTS chain_reorgs (
12
+ id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
13
+ detected_at timestamptz NOT NULL DEFAULT now(),
14
+ fork_point_height bigint NOT NULL,
15
+ old_index_block_hash text,
16
+ new_index_block_hash text,
17
+ orphaned_from_height bigint NOT NULL,
18
+ orphaned_from_event_index integer NOT NULL,
19
+ orphaned_to_height bigint NOT NULL,
20
+ orphaned_to_event_index integer NOT NULL,
21
+ new_canonical_height bigint NOT NULL,
22
+ new_canonical_event_index integer NOT NULL,
23
+ created_at timestamptz NOT NULL DEFAULT now()
24
+ )
25
+ `.execute(db);
26
+
27
+ await sql`
28
+ CREATE INDEX IF NOT EXISTS chain_reorgs_detected_at_idx
29
+ ON chain_reorgs (detected_at)
30
+ `.execute(db);
31
+ await sql`
32
+ CREATE INDEX IF NOT EXISTS chain_reorgs_orphaned_range_idx
33
+ ON chain_reorgs (
34
+ orphaned_from_height,
35
+ orphaned_from_event_index,
36
+ orphaned_to_height,
37
+ orphaned_to_event_index
38
+ )
39
+ `.execute(db);
40
+ }
41
+
42
+ export async function down(db: Kysely<unknown>): Promise<void> {
43
+ await sql`DROP TABLE IF EXISTS chain_reorgs`.execute(db);
44
+ await sql`
45
+ ALTER TABLE blocks
46
+ DROP COLUMN IF EXISTS burn_block_hash
47
+ `.execute(db);
48
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secondlayer/shared",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
4
4
  "type": "module",
5
5
  "main": "./dist/src/index.js",
6
6
  "types": "./dist/src/index.d.ts",
@@ -25,6 +25,10 @@
25
25
  "types": "./dist/src/db/queries/usage.d.ts",
26
26
  "import": "./dist/src/db/queries/usage.js"
27
27
  },
28
+ "./db/queries/chain-reorgs": {
29
+ "types": "./dist/src/db/queries/chain-reorgs.d.ts",
30
+ "import": "./dist/src/db/queries/chain-reorgs.js"
31
+ },
28
32
  "./db/queries/subgraphs": {
29
33
  "types": "./dist/src/db/queries/subgraphs.d.ts",
30
34
  "import": "./dist/src/db/queries/subgraphs.js"