@secondlayer/shared 6.0.0 → 6.2.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/queries/account-spend-caps.d.ts +46 -0
- package/dist/src/db/queries/account-usage.d.ts +46 -0
- package/dist/src/db/queries/accounts.d.ts +46 -0
- package/dist/src/db/queries/chain-reorgs.d.ts +534 -0
- package/dist/src/db/queries/chain-reorgs.js +322 -0
- package/dist/src/db/queries/chain-reorgs.js.map +14 -0
- package/dist/src/db/queries/integrity.d.ts +46 -0
- package/dist/src/db/queries/projects.d.ts +46 -0
- package/dist/src/db/queries/provisioning-audit.d.ts +46 -0
- package/dist/src/db/queries/subgraph-gaps.d.ts +46 -0
- package/dist/src/db/queries/subgraph-operations.d.ts +46 -0
- package/dist/src/db/queries/subgraphs.d.ts +46 -0
- package/dist/src/db/queries/subscriptions.d.ts +46 -0
- package/dist/src/db/queries/tenant-compute-addons.d.ts +46 -0
- package/dist/src/db/queries/tenants.d.ts +46 -0
- package/dist/src/db/queries/usage.d.ts +57 -1
- package/dist/src/db/queries/usage.js +37 -2
- package/dist/src/db/queries/usage.js.map +3 -3
- package/dist/src/db/schema.d.ts +47 -1
- package/dist/src/index.d.ts +47 -1
- package/dist/src/node/local-client.d.ts +46 -0
- package/dist/src/types.d.ts +2 -1
- package/migrations/0065_l2_decoded_events.ts +50 -0
- package/migrations/0066_public_l2_decoded_events.ts +83 -0
- package/migrations/0067_product_usage_counters.ts +18 -0
- package/migrations/0068_chain_reorgs_and_burn_block_hash.ts +48 -0
- package/migrations/0069_api_keys_product_tier.ts +43 -0
- package/package.json +5 -1
|
@@ -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>;
|
|
@@ -103,6 +104,8 @@ interface ApiKeysTable {
|
|
|
103
104
|
rate_limit: Generated<number>;
|
|
104
105
|
ip_address: string;
|
|
105
106
|
account_id: string;
|
|
107
|
+
product: Generated<"account" | "streams" | "index">;
|
|
108
|
+
tier: "free" | "build" | "scale" | "enterprise" | null;
|
|
106
109
|
last_used_at: Date | null;
|
|
107
110
|
revoked_at: Date | null;
|
|
108
111
|
created_at: Generated<Date>;
|
|
@@ -145,6 +148,8 @@ interface UsageDailyTable {
|
|
|
145
148
|
date: string;
|
|
146
149
|
api_requests: Generated<number>;
|
|
147
150
|
deliveries: Generated<number>;
|
|
151
|
+
streams_events_returned: Generated<number>;
|
|
152
|
+
index_decoded_events_returned: Generated<number>;
|
|
148
153
|
}
|
|
149
154
|
interface UsageSnapshotsTable {
|
|
150
155
|
id: Generated<string>;
|
|
@@ -273,6 +278,44 @@ interface ProcessedStripeEventsTable {
|
|
|
273
278
|
event_type: string;
|
|
274
279
|
processed_at: Generated<Date>;
|
|
275
280
|
}
|
|
281
|
+
interface DecodedEventsTable {
|
|
282
|
+
cursor: string;
|
|
283
|
+
block_height: number;
|
|
284
|
+
tx_id: string;
|
|
285
|
+
tx_index: number;
|
|
286
|
+
event_index: number;
|
|
287
|
+
event_type: string;
|
|
288
|
+
microblock_hash: string | null;
|
|
289
|
+
canonical: Generated<boolean>;
|
|
290
|
+
contract_id: string | null;
|
|
291
|
+
sender: string | null;
|
|
292
|
+
recipient: string | null;
|
|
293
|
+
amount: string | null;
|
|
294
|
+
asset_identifier: string | null;
|
|
295
|
+
value: string | null;
|
|
296
|
+
memo: string | null;
|
|
297
|
+
source_cursor: string;
|
|
298
|
+
created_at: Generated<Date>;
|
|
299
|
+
}
|
|
300
|
+
interface L2DecoderCheckpointsTable {
|
|
301
|
+
decoder_name: string;
|
|
302
|
+
last_cursor: string | null;
|
|
303
|
+
updated_at: Generated<Date>;
|
|
304
|
+
}
|
|
305
|
+
interface ChainReorgsTable {
|
|
306
|
+
id: Generated<string>;
|
|
307
|
+
detected_at: Generated<Date>;
|
|
308
|
+
fork_point_height: number;
|
|
309
|
+
old_index_block_hash: string | null;
|
|
310
|
+
new_index_block_hash: string | null;
|
|
311
|
+
orphaned_from_height: number;
|
|
312
|
+
orphaned_from_event_index: number;
|
|
313
|
+
orphaned_to_height: number;
|
|
314
|
+
orphaned_to_event_index: number;
|
|
315
|
+
new_canonical_height: number;
|
|
316
|
+
new_canonical_event_index: number;
|
|
317
|
+
created_at: Generated<Date>;
|
|
318
|
+
}
|
|
276
319
|
interface Database {
|
|
277
320
|
blocks: BlocksTable;
|
|
278
321
|
transactions: TransactionsTable;
|
|
@@ -308,6 +351,9 @@ interface Database {
|
|
|
308
351
|
subscriptions: SubscriptionsTable;
|
|
309
352
|
subscription_outbox: SubscriptionOutboxTable;
|
|
310
353
|
subscription_deliveries: SubscriptionDeliveriesTable;
|
|
354
|
+
decoded_events: DecodedEventsTable;
|
|
355
|
+
l2_decoder_checkpoints: L2DecoderCheckpointsTable;
|
|
356
|
+
chain_reorgs: ChainReorgsTable;
|
|
311
357
|
}
|
|
312
358
|
type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
|
|
313
359
|
interface TenantsTable {
|
|
@@ -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>;
|
|
@@ -103,6 +104,8 @@ interface ApiKeysTable {
|
|
|
103
104
|
rate_limit: Generated<number>;
|
|
104
105
|
ip_address: string;
|
|
105
106
|
account_id: string;
|
|
107
|
+
product: Generated<"account" | "streams" | "index">;
|
|
108
|
+
tier: "free" | "build" | "scale" | "enterprise" | null;
|
|
106
109
|
last_used_at: Date | null;
|
|
107
110
|
revoked_at: Date | null;
|
|
108
111
|
created_at: Generated<Date>;
|
|
@@ -145,6 +148,8 @@ interface UsageDailyTable {
|
|
|
145
148
|
date: string;
|
|
146
149
|
api_requests: Generated<number>;
|
|
147
150
|
deliveries: Generated<number>;
|
|
151
|
+
streams_events_returned: Generated<number>;
|
|
152
|
+
index_decoded_events_returned: Generated<number>;
|
|
148
153
|
}
|
|
149
154
|
interface UsageSnapshotsTable {
|
|
150
155
|
id: Generated<string>;
|
|
@@ -273,6 +278,44 @@ interface ProcessedStripeEventsTable {
|
|
|
273
278
|
event_type: string;
|
|
274
279
|
processed_at: Generated<Date>;
|
|
275
280
|
}
|
|
281
|
+
interface DecodedEventsTable {
|
|
282
|
+
cursor: string;
|
|
283
|
+
block_height: number;
|
|
284
|
+
tx_id: string;
|
|
285
|
+
tx_index: number;
|
|
286
|
+
event_index: number;
|
|
287
|
+
event_type: string;
|
|
288
|
+
microblock_hash: string | null;
|
|
289
|
+
canonical: Generated<boolean>;
|
|
290
|
+
contract_id: string | null;
|
|
291
|
+
sender: string | null;
|
|
292
|
+
recipient: string | null;
|
|
293
|
+
amount: string | null;
|
|
294
|
+
asset_identifier: string | null;
|
|
295
|
+
value: string | null;
|
|
296
|
+
memo: string | null;
|
|
297
|
+
source_cursor: string;
|
|
298
|
+
created_at: Generated<Date>;
|
|
299
|
+
}
|
|
300
|
+
interface L2DecoderCheckpointsTable {
|
|
301
|
+
decoder_name: string;
|
|
302
|
+
last_cursor: string | null;
|
|
303
|
+
updated_at: Generated<Date>;
|
|
304
|
+
}
|
|
305
|
+
interface ChainReorgsTable {
|
|
306
|
+
id: Generated<string>;
|
|
307
|
+
detected_at: Generated<Date>;
|
|
308
|
+
fork_point_height: number;
|
|
309
|
+
old_index_block_hash: string | null;
|
|
310
|
+
new_index_block_hash: string | null;
|
|
311
|
+
orphaned_from_height: number;
|
|
312
|
+
orphaned_from_event_index: number;
|
|
313
|
+
orphaned_to_height: number;
|
|
314
|
+
orphaned_to_event_index: number;
|
|
315
|
+
new_canonical_height: number;
|
|
316
|
+
new_canonical_event_index: number;
|
|
317
|
+
created_at: Generated<Date>;
|
|
318
|
+
}
|
|
276
319
|
interface Database {
|
|
277
320
|
blocks: BlocksTable;
|
|
278
321
|
transactions: TransactionsTable;
|
|
@@ -308,6 +351,9 @@ interface Database {
|
|
|
308
351
|
subscriptions: SubscriptionsTable;
|
|
309
352
|
subscription_outbox: SubscriptionOutboxTable;
|
|
310
353
|
subscription_deliveries: SubscriptionDeliveriesTable;
|
|
354
|
+
decoded_events: DecodedEventsTable;
|
|
355
|
+
l2_decoder_checkpoints: L2DecoderCheckpointsTable;
|
|
356
|
+
chain_reorgs: ChainReorgsTable;
|
|
311
357
|
}
|
|
312
358
|
type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
|
|
313
359
|
interface TenantsTable {
|
|
@@ -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>;
|
|
@@ -103,6 +104,8 @@ interface ApiKeysTable {
|
|
|
103
104
|
rate_limit: Generated<number>;
|
|
104
105
|
ip_address: string;
|
|
105
106
|
account_id: string;
|
|
107
|
+
product: Generated<"account" | "streams" | "index">;
|
|
108
|
+
tier: "free" | "build" | "scale" | "enterprise" | null;
|
|
106
109
|
last_used_at: Date | null;
|
|
107
110
|
revoked_at: Date | null;
|
|
108
111
|
created_at: Generated<Date>;
|
|
@@ -145,6 +148,8 @@ interface UsageDailyTable {
|
|
|
145
148
|
date: string;
|
|
146
149
|
api_requests: Generated<number>;
|
|
147
150
|
deliveries: Generated<number>;
|
|
151
|
+
streams_events_returned: Generated<number>;
|
|
152
|
+
index_decoded_events_returned: Generated<number>;
|
|
148
153
|
}
|
|
149
154
|
interface UsageSnapshotsTable {
|
|
150
155
|
id: Generated<string>;
|
|
@@ -273,6 +278,44 @@ interface ProcessedStripeEventsTable {
|
|
|
273
278
|
event_type: string;
|
|
274
279
|
processed_at: Generated<Date>;
|
|
275
280
|
}
|
|
281
|
+
interface DecodedEventsTable {
|
|
282
|
+
cursor: string;
|
|
283
|
+
block_height: number;
|
|
284
|
+
tx_id: string;
|
|
285
|
+
tx_index: number;
|
|
286
|
+
event_index: number;
|
|
287
|
+
event_type: string;
|
|
288
|
+
microblock_hash: string | null;
|
|
289
|
+
canonical: Generated<boolean>;
|
|
290
|
+
contract_id: string | null;
|
|
291
|
+
sender: string | null;
|
|
292
|
+
recipient: string | null;
|
|
293
|
+
amount: string | null;
|
|
294
|
+
asset_identifier: string | null;
|
|
295
|
+
value: string | null;
|
|
296
|
+
memo: string | null;
|
|
297
|
+
source_cursor: string;
|
|
298
|
+
created_at: Generated<Date>;
|
|
299
|
+
}
|
|
300
|
+
interface L2DecoderCheckpointsTable {
|
|
301
|
+
decoder_name: string;
|
|
302
|
+
last_cursor: string | null;
|
|
303
|
+
updated_at: Generated<Date>;
|
|
304
|
+
}
|
|
305
|
+
interface ChainReorgsTable {
|
|
306
|
+
id: Generated<string>;
|
|
307
|
+
detected_at: Generated<Date>;
|
|
308
|
+
fork_point_height: number;
|
|
309
|
+
old_index_block_hash: string | null;
|
|
310
|
+
new_index_block_hash: string | null;
|
|
311
|
+
orphaned_from_height: number;
|
|
312
|
+
orphaned_from_event_index: number;
|
|
313
|
+
orphaned_to_height: number;
|
|
314
|
+
orphaned_to_event_index: number;
|
|
315
|
+
new_canonical_height: number;
|
|
316
|
+
new_canonical_event_index: number;
|
|
317
|
+
created_at: Generated<Date>;
|
|
318
|
+
}
|
|
276
319
|
interface Database {
|
|
277
320
|
blocks: BlocksTable;
|
|
278
321
|
transactions: TransactionsTable;
|
|
@@ -308,6 +351,9 @@ interface Database {
|
|
|
308
351
|
subscriptions: SubscriptionsTable;
|
|
309
352
|
subscription_outbox: SubscriptionOutboxTable;
|
|
310
353
|
subscription_deliveries: SubscriptionDeliveriesTable;
|
|
354
|
+
decoded_events: DecodedEventsTable;
|
|
355
|
+
l2_decoder_checkpoints: L2DecoderCheckpointsTable;
|
|
356
|
+
chain_reorgs: ChainReorgsTable;
|
|
311
357
|
}
|
|
312
358
|
type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
|
|
313
359
|
interface TenantsTable {
|
|
@@ -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>;
|
|
@@ -103,6 +104,8 @@ interface ApiKeysTable {
|
|
|
103
104
|
rate_limit: Generated<number>;
|
|
104
105
|
ip_address: string;
|
|
105
106
|
account_id: string;
|
|
107
|
+
product: Generated<"account" | "streams" | "index">;
|
|
108
|
+
tier: "free" | "build" | "scale" | "enterprise" | null;
|
|
106
109
|
last_used_at: Date | null;
|
|
107
110
|
revoked_at: Date | null;
|
|
108
111
|
created_at: Generated<Date>;
|
|
@@ -145,6 +148,8 @@ interface UsageDailyTable {
|
|
|
145
148
|
date: string;
|
|
146
149
|
api_requests: Generated<number>;
|
|
147
150
|
deliveries: Generated<number>;
|
|
151
|
+
streams_events_returned: Generated<number>;
|
|
152
|
+
index_decoded_events_returned: Generated<number>;
|
|
148
153
|
}
|
|
149
154
|
interface UsageSnapshotsTable {
|
|
150
155
|
id: Generated<string>;
|
|
@@ -273,6 +278,44 @@ interface ProcessedStripeEventsTable {
|
|
|
273
278
|
event_type: string;
|
|
274
279
|
processed_at: Generated<Date>;
|
|
275
280
|
}
|
|
281
|
+
interface DecodedEventsTable {
|
|
282
|
+
cursor: string;
|
|
283
|
+
block_height: number;
|
|
284
|
+
tx_id: string;
|
|
285
|
+
tx_index: number;
|
|
286
|
+
event_index: number;
|
|
287
|
+
event_type: string;
|
|
288
|
+
microblock_hash: string | null;
|
|
289
|
+
canonical: Generated<boolean>;
|
|
290
|
+
contract_id: string | null;
|
|
291
|
+
sender: string | null;
|
|
292
|
+
recipient: string | null;
|
|
293
|
+
amount: string | null;
|
|
294
|
+
asset_identifier: string | null;
|
|
295
|
+
value: string | null;
|
|
296
|
+
memo: string | null;
|
|
297
|
+
source_cursor: string;
|
|
298
|
+
created_at: Generated<Date>;
|
|
299
|
+
}
|
|
300
|
+
interface L2DecoderCheckpointsTable {
|
|
301
|
+
decoder_name: string;
|
|
302
|
+
last_cursor: string | null;
|
|
303
|
+
updated_at: Generated<Date>;
|
|
304
|
+
}
|
|
305
|
+
interface ChainReorgsTable {
|
|
306
|
+
id: Generated<string>;
|
|
307
|
+
detected_at: Generated<Date>;
|
|
308
|
+
fork_point_height: number;
|
|
309
|
+
old_index_block_hash: string | null;
|
|
310
|
+
new_index_block_hash: string | null;
|
|
311
|
+
orphaned_from_height: number;
|
|
312
|
+
orphaned_from_event_index: number;
|
|
313
|
+
orphaned_to_height: number;
|
|
314
|
+
orphaned_to_event_index: number;
|
|
315
|
+
new_canonical_height: number;
|
|
316
|
+
new_canonical_event_index: number;
|
|
317
|
+
created_at: Generated<Date>;
|
|
318
|
+
}
|
|
276
319
|
interface Database {
|
|
277
320
|
blocks: BlocksTable;
|
|
278
321
|
transactions: TransactionsTable;
|
|
@@ -308,6 +351,9 @@ interface Database {
|
|
|
308
351
|
subscriptions: SubscriptionsTable;
|
|
309
352
|
subscription_outbox: SubscriptionOutboxTable;
|
|
310
353
|
subscription_deliveries: SubscriptionDeliveriesTable;
|
|
354
|
+
decoded_events: DecodedEventsTable;
|
|
355
|
+
l2_decoder_checkpoints: L2DecoderCheckpointsTable;
|
|
356
|
+
chain_reorgs: ChainReorgsTable;
|
|
311
357
|
}
|
|
312
358
|
type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
|
|
313
359
|
interface TenantsTable {
|
|
@@ -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>;
|
|
@@ -103,6 +104,8 @@ interface ApiKeysTable {
|
|
|
103
104
|
rate_limit: Generated<number>;
|
|
104
105
|
ip_address: string;
|
|
105
106
|
account_id: string;
|
|
107
|
+
product: Generated<"account" | "streams" | "index">;
|
|
108
|
+
tier: "free" | "build" | "scale" | "enterprise" | null;
|
|
106
109
|
last_used_at: Date | null;
|
|
107
110
|
revoked_at: Date | null;
|
|
108
111
|
created_at: Generated<Date>;
|
|
@@ -145,6 +148,8 @@ interface UsageDailyTable {
|
|
|
145
148
|
date: string;
|
|
146
149
|
api_requests: Generated<number>;
|
|
147
150
|
deliveries: Generated<number>;
|
|
151
|
+
streams_events_returned: Generated<number>;
|
|
152
|
+
index_decoded_events_returned: Generated<number>;
|
|
148
153
|
}
|
|
149
154
|
interface UsageSnapshotsTable {
|
|
150
155
|
id: Generated<string>;
|
|
@@ -273,6 +278,44 @@ interface ProcessedStripeEventsTable {
|
|
|
273
278
|
event_type: string;
|
|
274
279
|
processed_at: Generated<Date>;
|
|
275
280
|
}
|
|
281
|
+
interface DecodedEventsTable {
|
|
282
|
+
cursor: string;
|
|
283
|
+
block_height: number;
|
|
284
|
+
tx_id: string;
|
|
285
|
+
tx_index: number;
|
|
286
|
+
event_index: number;
|
|
287
|
+
event_type: string;
|
|
288
|
+
microblock_hash: string | null;
|
|
289
|
+
canonical: Generated<boolean>;
|
|
290
|
+
contract_id: string | null;
|
|
291
|
+
sender: string | null;
|
|
292
|
+
recipient: string | null;
|
|
293
|
+
amount: string | null;
|
|
294
|
+
asset_identifier: string | null;
|
|
295
|
+
value: string | null;
|
|
296
|
+
memo: string | null;
|
|
297
|
+
source_cursor: string;
|
|
298
|
+
created_at: Generated<Date>;
|
|
299
|
+
}
|
|
300
|
+
interface L2DecoderCheckpointsTable {
|
|
301
|
+
decoder_name: string;
|
|
302
|
+
last_cursor: string | null;
|
|
303
|
+
updated_at: Generated<Date>;
|
|
304
|
+
}
|
|
305
|
+
interface ChainReorgsTable {
|
|
306
|
+
id: Generated<string>;
|
|
307
|
+
detected_at: Generated<Date>;
|
|
308
|
+
fork_point_height: number;
|
|
309
|
+
old_index_block_hash: string | null;
|
|
310
|
+
new_index_block_hash: string | null;
|
|
311
|
+
orphaned_from_height: number;
|
|
312
|
+
orphaned_from_event_index: number;
|
|
313
|
+
orphaned_to_height: number;
|
|
314
|
+
orphaned_to_event_index: number;
|
|
315
|
+
new_canonical_height: number;
|
|
316
|
+
new_canonical_event_index: number;
|
|
317
|
+
created_at: Generated<Date>;
|
|
318
|
+
}
|
|
276
319
|
interface Database {
|
|
277
320
|
blocks: BlocksTable;
|
|
278
321
|
transactions: TransactionsTable;
|
|
@@ -308,6 +351,9 @@ interface Database {
|
|
|
308
351
|
subscriptions: SubscriptionsTable;
|
|
309
352
|
subscription_outbox: SubscriptionOutboxTable;
|
|
310
353
|
subscription_deliveries: SubscriptionDeliveriesTable;
|
|
354
|
+
decoded_events: DecodedEventsTable;
|
|
355
|
+
l2_decoder_checkpoints: L2DecoderCheckpointsTable;
|
|
356
|
+
chain_reorgs: ChainReorgsTable;
|
|
311
357
|
}
|
|
312
358
|
type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
|
|
313
359
|
interface TenantsTable {
|
|
@@ -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>;
|
|
@@ -103,6 +104,8 @@ interface ApiKeysTable {
|
|
|
103
104
|
rate_limit: Generated<number>;
|
|
104
105
|
ip_address: string;
|
|
105
106
|
account_id: string;
|
|
107
|
+
product: Generated<"account" | "streams" | "index">;
|
|
108
|
+
tier: "free" | "build" | "scale" | "enterprise" | null;
|
|
106
109
|
last_used_at: Date | null;
|
|
107
110
|
revoked_at: Date | null;
|
|
108
111
|
created_at: Generated<Date>;
|
|
@@ -145,6 +148,8 @@ interface UsageDailyTable {
|
|
|
145
148
|
date: string;
|
|
146
149
|
api_requests: Generated<number>;
|
|
147
150
|
deliveries: Generated<number>;
|
|
151
|
+
streams_events_returned: Generated<number>;
|
|
152
|
+
index_decoded_events_returned: Generated<number>;
|
|
148
153
|
}
|
|
149
154
|
interface UsageSnapshotsTable {
|
|
150
155
|
id: Generated<string>;
|
|
@@ -273,6 +278,44 @@ interface ProcessedStripeEventsTable {
|
|
|
273
278
|
event_type: string;
|
|
274
279
|
processed_at: Generated<Date>;
|
|
275
280
|
}
|
|
281
|
+
interface DecodedEventsTable {
|
|
282
|
+
cursor: string;
|
|
283
|
+
block_height: number;
|
|
284
|
+
tx_id: string;
|
|
285
|
+
tx_index: number;
|
|
286
|
+
event_index: number;
|
|
287
|
+
event_type: string;
|
|
288
|
+
microblock_hash: string | null;
|
|
289
|
+
canonical: Generated<boolean>;
|
|
290
|
+
contract_id: string | null;
|
|
291
|
+
sender: string | null;
|
|
292
|
+
recipient: string | null;
|
|
293
|
+
amount: string | null;
|
|
294
|
+
asset_identifier: string | null;
|
|
295
|
+
value: string | null;
|
|
296
|
+
memo: string | null;
|
|
297
|
+
source_cursor: string;
|
|
298
|
+
created_at: Generated<Date>;
|
|
299
|
+
}
|
|
300
|
+
interface L2DecoderCheckpointsTable {
|
|
301
|
+
decoder_name: string;
|
|
302
|
+
last_cursor: string | null;
|
|
303
|
+
updated_at: Generated<Date>;
|
|
304
|
+
}
|
|
305
|
+
interface ChainReorgsTable {
|
|
306
|
+
id: Generated<string>;
|
|
307
|
+
detected_at: Generated<Date>;
|
|
308
|
+
fork_point_height: number;
|
|
309
|
+
old_index_block_hash: string | null;
|
|
310
|
+
new_index_block_hash: string | null;
|
|
311
|
+
orphaned_from_height: number;
|
|
312
|
+
orphaned_from_event_index: number;
|
|
313
|
+
orphaned_to_height: number;
|
|
314
|
+
orphaned_to_event_index: number;
|
|
315
|
+
new_canonical_height: number;
|
|
316
|
+
new_canonical_event_index: number;
|
|
317
|
+
created_at: Generated<Date>;
|
|
318
|
+
}
|
|
276
319
|
interface Database {
|
|
277
320
|
blocks: BlocksTable;
|
|
278
321
|
transactions: TransactionsTable;
|
|
@@ -308,6 +351,9 @@ interface Database {
|
|
|
308
351
|
subscriptions: SubscriptionsTable;
|
|
309
352
|
subscription_outbox: SubscriptionOutboxTable;
|
|
310
353
|
subscription_deliveries: SubscriptionDeliveriesTable;
|
|
354
|
+
decoded_events: DecodedEventsTable;
|
|
355
|
+
l2_decoder_checkpoints: L2DecoderCheckpointsTable;
|
|
356
|
+
chain_reorgs: ChainReorgsTable;
|
|
311
357
|
}
|
|
312
358
|
type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
|
|
313
359
|
interface TenantsTable {
|
|
@@ -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>;
|
|
@@ -103,6 +104,8 @@ interface ApiKeysTable {
|
|
|
103
104
|
rate_limit: Generated<number>;
|
|
104
105
|
ip_address: string;
|
|
105
106
|
account_id: string;
|
|
107
|
+
product: Generated<"account" | "streams" | "index">;
|
|
108
|
+
tier: "free" | "build" | "scale" | "enterprise" | null;
|
|
106
109
|
last_used_at: Date | null;
|
|
107
110
|
revoked_at: Date | null;
|
|
108
111
|
created_at: Generated<Date>;
|
|
@@ -145,6 +148,8 @@ interface UsageDailyTable {
|
|
|
145
148
|
date: string;
|
|
146
149
|
api_requests: Generated<number>;
|
|
147
150
|
deliveries: Generated<number>;
|
|
151
|
+
streams_events_returned: Generated<number>;
|
|
152
|
+
index_decoded_events_returned: Generated<number>;
|
|
148
153
|
}
|
|
149
154
|
interface UsageSnapshotsTable {
|
|
150
155
|
id: Generated<string>;
|
|
@@ -273,6 +278,44 @@ interface ProcessedStripeEventsTable {
|
|
|
273
278
|
event_type: string;
|
|
274
279
|
processed_at: Generated<Date>;
|
|
275
280
|
}
|
|
281
|
+
interface DecodedEventsTable {
|
|
282
|
+
cursor: string;
|
|
283
|
+
block_height: number;
|
|
284
|
+
tx_id: string;
|
|
285
|
+
tx_index: number;
|
|
286
|
+
event_index: number;
|
|
287
|
+
event_type: string;
|
|
288
|
+
microblock_hash: string | null;
|
|
289
|
+
canonical: Generated<boolean>;
|
|
290
|
+
contract_id: string | null;
|
|
291
|
+
sender: string | null;
|
|
292
|
+
recipient: string | null;
|
|
293
|
+
amount: string | null;
|
|
294
|
+
asset_identifier: string | null;
|
|
295
|
+
value: string | null;
|
|
296
|
+
memo: string | null;
|
|
297
|
+
source_cursor: string;
|
|
298
|
+
created_at: Generated<Date>;
|
|
299
|
+
}
|
|
300
|
+
interface L2DecoderCheckpointsTable {
|
|
301
|
+
decoder_name: string;
|
|
302
|
+
last_cursor: string | null;
|
|
303
|
+
updated_at: Generated<Date>;
|
|
304
|
+
}
|
|
305
|
+
interface ChainReorgsTable {
|
|
306
|
+
id: Generated<string>;
|
|
307
|
+
detected_at: Generated<Date>;
|
|
308
|
+
fork_point_height: number;
|
|
309
|
+
old_index_block_hash: string | null;
|
|
310
|
+
new_index_block_hash: string | null;
|
|
311
|
+
orphaned_from_height: number;
|
|
312
|
+
orphaned_from_event_index: number;
|
|
313
|
+
orphaned_to_height: number;
|
|
314
|
+
orphaned_to_event_index: number;
|
|
315
|
+
new_canonical_height: number;
|
|
316
|
+
new_canonical_event_index: number;
|
|
317
|
+
created_at: Generated<Date>;
|
|
318
|
+
}
|
|
276
319
|
interface Database {
|
|
277
320
|
blocks: BlocksTable;
|
|
278
321
|
transactions: TransactionsTable;
|
|
@@ -308,6 +351,9 @@ interface Database {
|
|
|
308
351
|
subscriptions: SubscriptionsTable;
|
|
309
352
|
subscription_outbox: SubscriptionOutboxTable;
|
|
310
353
|
subscription_deliveries: SubscriptionDeliveriesTable;
|
|
354
|
+
decoded_events: DecodedEventsTable;
|
|
355
|
+
l2_decoder_checkpoints: L2DecoderCheckpointsTable;
|
|
356
|
+
chain_reorgs: ChainReorgsTable;
|
|
311
357
|
}
|
|
312
358
|
type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
|
|
313
359
|
interface TenantsTable {
|
|
@@ -448,6 +494,8 @@ interface SubscriptionDeliveriesTable {
|
|
|
448
494
|
}
|
|
449
495
|
/** Increment API request counter for today. Fire-and-forget safe. */
|
|
450
496
|
declare function incrementApiRequests(db: Kysely<Database>, accountId: string): Promise<void>;
|
|
497
|
+
declare function incrementStreamsEventsReturned(db: Kysely<Database>, accountId: string, quantity: number): Promise<void>;
|
|
498
|
+
declare function incrementIndexDecodedEventsReturned(db: Kysely<Database>, accountId: string, quantity: number): Promise<void>;
|
|
451
499
|
interface UsageSummary {
|
|
452
500
|
apiRequestsToday: number;
|
|
453
501
|
deliveriesThisMonth: number;
|
|
@@ -455,9 +503,17 @@ interface UsageSummary {
|
|
|
455
503
|
}
|
|
456
504
|
/** Get current usage for an account. */
|
|
457
505
|
declare function getUsage(db: Kysely<Database>, accountId: string): Promise<UsageSummary>;
|
|
506
|
+
interface ProductUsageBreakdown {
|
|
507
|
+
streamsEventsToday: number;
|
|
508
|
+
streamsEventsThisMonth: number;
|
|
509
|
+
indexDecodedEventsToday: number;
|
|
510
|
+
indexDecodedEventsThisMonth: number;
|
|
511
|
+
}
|
|
512
|
+
/** Get per-product event counts (today + this month) for an account. */
|
|
513
|
+
declare function getProductUsage(db: Kysely<Database>, accountId: string): Promise<ProductUsageBreakdown>;
|
|
458
514
|
/**
|
|
459
515
|
* Measure storage for all accounts by querying pg_total_relation_size
|
|
460
516
|
* for each tenant's subgraph schemas.
|
|
461
517
|
*/
|
|
462
518
|
declare function measureStorage(db: Kysely<Database>): Promise<void>;
|
|
463
|
-
export { measureStorage, incrementApiRequests, getUsage, UsageSummary };
|
|
519
|
+
export { measureStorage, incrementStreamsEventsReturned, incrementIndexDecodedEventsReturned, incrementApiRequests, getUsage, getProductUsage, UsageSummary, ProductUsageBreakdown };
|
|
@@ -25,6 +25,23 @@ async function incrementApiRequests(db, accountId) {
|
|
|
25
25
|
DO UPDATE SET api_requests = usage_daily.api_requests + 1
|
|
26
26
|
`.execute(db);
|
|
27
27
|
}
|
|
28
|
+
async function incrementAccountDailyCounter(db, accountId, column, quantity) {
|
|
29
|
+
if (quantity <= 0)
|
|
30
|
+
return;
|
|
31
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
32
|
+
await sql`
|
|
33
|
+
INSERT INTO usage_daily (account_id, tenant_id, date, api_requests, deliveries, ${sql.raw(column)})
|
|
34
|
+
VALUES (${accountId}, NULL, ${today}, 0, 0, ${quantity})
|
|
35
|
+
ON CONFLICT (account_id, date) WHERE tenant_id IS NULL
|
|
36
|
+
DO UPDATE SET ${sql.raw(column)} = usage_daily.${sql.raw(column)} + ${quantity}
|
|
37
|
+
`.execute(db);
|
|
38
|
+
}
|
|
39
|
+
async function incrementStreamsEventsReturned(db, accountId, quantity) {
|
|
40
|
+
await incrementAccountDailyCounter(db, accountId, "streams_events_returned", quantity);
|
|
41
|
+
}
|
|
42
|
+
async function incrementIndexDecodedEventsReturned(db, accountId, quantity) {
|
|
43
|
+
await incrementAccountDailyCounter(db, accountId, "index_decoded_events_returned", quantity);
|
|
44
|
+
}
|
|
28
45
|
async function getUsage(db, accountId) {
|
|
29
46
|
const today = new Date().toISOString().slice(0, 10);
|
|
30
47
|
const monthStart = `${today.slice(0, 7)}-01`;
|
|
@@ -37,6 +54,21 @@ async function getUsage(db, accountId) {
|
|
|
37
54
|
storageBytes: Number(storageRow?.storage_bytes ?? 0)
|
|
38
55
|
};
|
|
39
56
|
}
|
|
57
|
+
async function getProductUsage(db, accountId) {
|
|
58
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
59
|
+
const monthStart = `${today.slice(0, 7)}-01`;
|
|
60
|
+
const dailyRow = await db.selectFrom("usage_daily").select(["streams_events_returned", "index_decoded_events_returned"]).where("account_id", "=", accountId).where("date", "=", today).executeTakeFirst();
|
|
61
|
+
const monthlyRow = await db.selectFrom("usage_daily").select([
|
|
62
|
+
sql`COALESCE(SUM(streams_events_returned), 0)`.as("streams_total"),
|
|
63
|
+
sql`COALESCE(SUM(index_decoded_events_returned), 0)`.as("index_total")
|
|
64
|
+
]).where("account_id", "=", accountId).where("date", ">=", monthStart).executeTakeFirst();
|
|
65
|
+
return {
|
|
66
|
+
streamsEventsToday: Number(dailyRow?.streams_events_returned ?? 0),
|
|
67
|
+
streamsEventsThisMonth: Number(monthlyRow?.streams_total ?? 0),
|
|
68
|
+
indexDecodedEventsToday: Number(dailyRow?.index_decoded_events_returned ?? 0),
|
|
69
|
+
indexDecodedEventsThisMonth: Number(monthlyRow?.index_total ?? 0)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
40
72
|
async function measureStorage(db) {
|
|
41
73
|
const accountSubgraphs = await db.selectFrom("subgraphs").select(["account_id", "schema_name"]).where("schema_name", "is not", null).execute();
|
|
42
74
|
const byAccount = new Map;
|
|
@@ -66,9 +98,12 @@ async function measureStorage(db) {
|
|
|
66
98
|
}
|
|
67
99
|
export {
|
|
68
100
|
measureStorage,
|
|
101
|
+
incrementStreamsEventsReturned,
|
|
102
|
+
incrementIndexDecodedEventsReturned,
|
|
69
103
|
incrementApiRequests,
|
|
70
|
-
getUsage
|
|
104
|
+
getUsage,
|
|
105
|
+
getProductUsage
|
|
71
106
|
};
|
|
72
107
|
|
|
73
|
-
//# debugId=
|
|
108
|
+
//# debugId=4876492CE8C84D6164756E2164756E21
|
|
74
109
|
//# sourceMappingURL=usage.js.map
|