@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.
@@ -0,0 +1,532 @@
1
+ import { ColumnType, Generated } from "kysely";
2
+ interface BlocksTable {
3
+ height: number;
4
+ hash: string;
5
+ parent_hash: string;
6
+ burn_block_height: number;
7
+ burn_block_hash: ColumnType<string | null, string | null | undefined, string | null>;
8
+ timestamp: number;
9
+ canonical: Generated<boolean>;
10
+ created_at: Generated<Date>;
11
+ }
12
+ interface TransactionsTable {
13
+ tx_id: string;
14
+ block_height: number;
15
+ tx_index: Generated<number>;
16
+ type: string;
17
+ sender: string;
18
+ status: string;
19
+ contract_id: string | null;
20
+ function_name: string | null;
21
+ function_args: Generated<unknown | null>;
22
+ raw_result: Generated<string | null>;
23
+ raw_tx: string;
24
+ created_at: Generated<Date>;
25
+ }
26
+ interface EventsTable {
27
+ id: Generated<string>;
28
+ tx_id: string;
29
+ block_height: number;
30
+ event_index: number;
31
+ type: string;
32
+ data: unknown;
33
+ created_at: Generated<Date>;
34
+ }
35
+ interface IndexProgressTable {
36
+ network: string;
37
+ last_indexed_block: Generated<number>;
38
+ last_contiguous_block: Generated<number>;
39
+ highest_seen_block: Generated<number>;
40
+ updated_at: Generated<Date>;
41
+ }
42
+ interface SubgraphsTable {
43
+ id: Generated<string>;
44
+ name: string;
45
+ version: Generated<string>;
46
+ status: Generated<string>;
47
+ definition: Record<string, unknown>;
48
+ schema_hash: string;
49
+ handler_path: string;
50
+ schema_name: string | null;
51
+ start_block: Generated<number>;
52
+ last_processed_block: Generated<number>;
53
+ reindex_from_block: number | null;
54
+ reindex_to_block: number | null;
55
+ last_error: string | null;
56
+ last_error_at: Date | null;
57
+ total_processed: Generated<number>;
58
+ total_errors: Generated<number>;
59
+ account_id: string;
60
+ handler_code: string | null;
61
+ source_code: string | null;
62
+ project_id: string | null;
63
+ created_at: Generated<Date>;
64
+ updated_at: Generated<Date>;
65
+ }
66
+ interface SubgraphGapsTable {
67
+ id: Generated<string>;
68
+ subgraph_id: string;
69
+ subgraph_name: string;
70
+ gap_start: number;
71
+ gap_end: number;
72
+ reason: string;
73
+ detected_at: Generated<Date>;
74
+ resolved_at: Date | null;
75
+ }
76
+ type SubgraphOperationKind = "reindex" | "backfill";
77
+ type SubgraphOperationStatus = "queued" | "running" | "completed" | "failed" | "cancelled";
78
+ interface SubgraphOperationsTable {
79
+ id: Generated<string>;
80
+ subgraph_id: string;
81
+ subgraph_name: string;
82
+ account_id: string | null;
83
+ kind: ColumnType<SubgraphOperationKind, SubgraphOperationKind, SubgraphOperationKind>;
84
+ status: ColumnType<SubgraphOperationStatus, SubgraphOperationStatus | undefined, SubgraphOperationStatus>;
85
+ from_block: number | null;
86
+ to_block: number | null;
87
+ cancel_requested: Generated<boolean>;
88
+ locked_by: string | null;
89
+ locked_until: Date | null;
90
+ started_at: Date | null;
91
+ finished_at: Date | null;
92
+ processed_blocks: number | null;
93
+ error: string | null;
94
+ created_at: Generated<Date>;
95
+ updated_at: Generated<Date>;
96
+ }
97
+ interface ApiKeysTable {
98
+ id: Generated<string>;
99
+ key_hash: string;
100
+ key_prefix: string;
101
+ name: string | null;
102
+ status: Generated<string>;
103
+ rate_limit: Generated<number>;
104
+ ip_address: string;
105
+ account_id: string;
106
+ last_used_at: Date | null;
107
+ revoked_at: Date | null;
108
+ created_at: Generated<Date>;
109
+ }
110
+ interface AccountsTable {
111
+ id: Generated<string>;
112
+ email: string;
113
+ plan: Generated<string>;
114
+ display_name: string | null;
115
+ bio: string | null;
116
+ avatar_url: string | null;
117
+ slug: string | null;
118
+ stripe_customer_id: string | null;
119
+ created_at: Generated<Date>;
120
+ }
121
+ interface SessionsTable {
122
+ id: Generated<string>;
123
+ token_hash: string;
124
+ token_prefix: string;
125
+ account_id: string;
126
+ ip_address: string;
127
+ expires_at: Generated<Date>;
128
+ revoked_at: Date | null;
129
+ last_used_at: Date | null;
130
+ created_at: Generated<Date>;
131
+ }
132
+ interface MagicLinksTable {
133
+ id: Generated<string>;
134
+ email: string;
135
+ token: string;
136
+ code: string | null;
137
+ expires_at: Date;
138
+ used_at: Date | null;
139
+ failed_attempts: Generated<number>;
140
+ created_at: Generated<Date>;
141
+ }
142
+ interface UsageDailyTable {
143
+ account_id: string;
144
+ tenant_id: string | null;
145
+ date: string;
146
+ api_requests: Generated<number>;
147
+ deliveries: Generated<number>;
148
+ streams_events_returned: Generated<number>;
149
+ index_decoded_events_returned: Generated<number>;
150
+ }
151
+ interface UsageSnapshotsTable {
152
+ id: Generated<string>;
153
+ account_id: string;
154
+ measured_at: Generated<Date>;
155
+ storage_bytes: Generated<number>;
156
+ }
157
+ interface WaitlistTable {
158
+ id: Generated<string>;
159
+ email: string;
160
+ source: Generated<string>;
161
+ status: Generated<string>;
162
+ created_at: Generated<Date>;
163
+ }
164
+ interface AccountInsightsTable {
165
+ id: Generated<string>;
166
+ account_id: string;
167
+ category: string;
168
+ insight_type: string;
169
+ resource_id: string | null;
170
+ severity: string;
171
+ title: string;
172
+ body: string;
173
+ data: unknown;
174
+ dismissed_at: Date | null;
175
+ expires_at: Date | null;
176
+ created_at: Generated<Date>;
177
+ }
178
+ interface AccountAgentRunsTable {
179
+ id: Generated<string>;
180
+ account_id: string;
181
+ started_at: Generated<Date>;
182
+ completed_at: Date | null;
183
+ status: Generated<string>;
184
+ input_tokens: Generated<number>;
185
+ output_tokens: Generated<number>;
186
+ cost_usd: Generated<number>;
187
+ insights_created: Generated<number>;
188
+ error: string | null;
189
+ }
190
+ interface SubgraphProcessingStatsTable {
191
+ id: Generated<string>;
192
+ subgraph_name: string;
193
+ api_key_id: string | null;
194
+ bucket_start: Date | null;
195
+ bucket_end: Date | null;
196
+ blocks_processed: number | null;
197
+ total_time_ms: number | null;
198
+ handler_time_ms: number | null;
199
+ flush_time_ms: number | null;
200
+ max_block_time_ms: number | null;
201
+ max_handler_time_ms: number | null;
202
+ avg_ops_per_block: number | null;
203
+ is_catchup: Generated<boolean>;
204
+ created_at: Generated<Date>;
205
+ }
206
+ interface SubgraphTableSnapshotsTable {
207
+ id: Generated<string>;
208
+ subgraph_name: string;
209
+ api_key_id: string | null;
210
+ table_name: string;
211
+ row_count: number | null;
212
+ created_at: Generated<Date>;
213
+ }
214
+ interface SubgraphHealthSnapshotsTable {
215
+ id: Generated<string>;
216
+ subgraph_id: string;
217
+ total_processed: number;
218
+ total_errors: number;
219
+ last_processed_block: number | null;
220
+ captured_at: Generated<Date>;
221
+ }
222
+ interface SubgraphUsageDailyTable {
223
+ subgraph_id: string;
224
+ date: string;
225
+ query_count: Generated<number>;
226
+ }
227
+ interface ProjectsTable {
228
+ id: Generated<string>;
229
+ name: string;
230
+ slug: string;
231
+ account_id: string;
232
+ settings: Generated<Record<string, unknown>>;
233
+ network: Generated<string>;
234
+ node_rpc: string | null;
235
+ created_at: Generated<Date>;
236
+ updated_at: Generated<Date>;
237
+ }
238
+ interface TeamMembersTable {
239
+ id: Generated<string>;
240
+ project_id: string;
241
+ account_id: string;
242
+ role: Generated<string>;
243
+ invited_by: string | null;
244
+ created_at: Generated<Date>;
245
+ }
246
+ interface TeamInvitationsTable {
247
+ id: Generated<string>;
248
+ project_id: string;
249
+ email: string;
250
+ role: Generated<string>;
251
+ token: string;
252
+ invited_by: string | null;
253
+ expires_at: Date;
254
+ accepted_at: Date | null;
255
+ created_at: Generated<Date>;
256
+ }
257
+ interface ChatSessionsTable {
258
+ id: Generated<string>;
259
+ account_id: string;
260
+ title: string | null;
261
+ summary: unknown | null;
262
+ created_at: Generated<Date>;
263
+ updated_at: Generated<Date>;
264
+ }
265
+ interface ChatMessagesTable {
266
+ id: Generated<string>;
267
+ chat_session_id: string;
268
+ role: string;
269
+ parts: unknown;
270
+ metadata: unknown | null;
271
+ created_at: Generated<Date>;
272
+ }
273
+ interface ProcessedStripeEventsTable {
274
+ event_id: string;
275
+ event_type: string;
276
+ processed_at: Generated<Date>;
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
+ }
316
+ interface Database {
317
+ blocks: BlocksTable;
318
+ transactions: TransactionsTable;
319
+ events: EventsTable;
320
+ index_progress: IndexProgressTable;
321
+ subgraphs: SubgraphsTable;
322
+ api_keys: ApiKeysTable;
323
+ accounts: AccountsTable;
324
+ sessions: SessionsTable;
325
+ magic_links: MagicLinksTable;
326
+ usage_daily: UsageDailyTable;
327
+ usage_snapshots: UsageSnapshotsTable;
328
+ waitlist: WaitlistTable;
329
+ account_insights: AccountInsightsTable;
330
+ account_agent_runs: AccountAgentRunsTable;
331
+ subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
332
+ subgraph_processing_stats: SubgraphProcessingStatsTable;
333
+ subgraph_table_snapshots: SubgraphTableSnapshotsTable;
334
+ subgraph_gaps: SubgraphGapsTable;
335
+ subgraph_operations: SubgraphOperationsTable;
336
+ subgraph_usage_daily: SubgraphUsageDailyTable;
337
+ projects: ProjectsTable;
338
+ team_members: TeamMembersTable;
339
+ team_invitations: TeamInvitationsTable;
340
+ chat_sessions: ChatSessionsTable;
341
+ chat_messages: ChatMessagesTable;
342
+ processed_stripe_events: ProcessedStripeEventsTable;
343
+ tenants: TenantsTable;
344
+ tenant_usage_monthly: TenantUsageMonthlyTable;
345
+ tenant_compute_addons: TenantComputeAddonsTable;
346
+ account_spend_caps: AccountSpendCapsTable;
347
+ provisioning_audit_log: ProvisioningAuditLogTable;
348
+ subscriptions: SubscriptionsTable;
349
+ subscription_outbox: SubscriptionOutboxTable;
350
+ subscription_deliveries: SubscriptionDeliveriesTable;
351
+ decoded_events: DecodedEventsTable;
352
+ l2_decoder_checkpoints: L2DecoderCheckpointsTable;
353
+ chain_reorgs: ChainReorgsTable;
354
+ }
355
+ type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
356
+ interface TenantsTable {
357
+ id: Generated<string>;
358
+ account_id: string;
359
+ slug: string;
360
+ status: ColumnType<TenantStatus, TenantStatus | undefined, TenantStatus>;
361
+ plan: string;
362
+ cpus: ColumnType<number, number | string, number | string>;
363
+ memory_mb: number;
364
+ storage_limit_mb: number;
365
+ storage_used_mb: number | null;
366
+ pg_container_id: string | null;
367
+ api_container_id: string | null;
368
+ processor_container_id: string | null;
369
+ target_database_url_enc: Buffer;
370
+ tenant_jwt_secret_enc: Buffer;
371
+ anon_key_enc: Buffer;
372
+ service_key_enc: Buffer;
373
+ api_url_internal: string;
374
+ api_url_public: string;
375
+ suspended_at: Date | null;
376
+ last_health_check_at: Date | null;
377
+ last_active_at: Generated<Date>;
378
+ service_gen: Generated<number>;
379
+ anon_gen: Generated<number>;
380
+ project_id: string | null;
381
+ created_at: Generated<Date>;
382
+ updated_at: Generated<Date>;
383
+ }
384
+ interface TenantUsageMonthlyTable {
385
+ id: Generated<string>;
386
+ tenant_id: string;
387
+ period_month: Date;
388
+ storage_peak_mb: Generated<number>;
389
+ storage_avg_mb: Generated<number>;
390
+ storage_last_mb: Generated<number>;
391
+ measurements: Generated<number>;
392
+ first_at: Generated<Date>;
393
+ last_at: Generated<Date>;
394
+ }
395
+ interface TenantComputeAddonsTable {
396
+ id: Generated<string>;
397
+ tenant_id: string;
398
+ memory_mb_delta: Generated<number>;
399
+ cpu_delta: Generated<number | string>;
400
+ storage_mb_delta: Generated<number>;
401
+ effective_from: Generated<Date>;
402
+ effective_until: Date | null;
403
+ stripe_subscription_item_id: string | null;
404
+ created_at: Generated<Date>;
405
+ }
406
+ interface AccountSpendCapsTable {
407
+ account_id: string;
408
+ monthly_cap_cents: number | null;
409
+ compute_cap_cents: number | null;
410
+ storage_cap_cents: number | null;
411
+ alert_threshold_pct: Generated<number>;
412
+ alert_sent_at: Date | null;
413
+ frozen_at: Date | null;
414
+ updated_at: Generated<Date>;
415
+ }
416
+ type ProvisioningAuditEvent = "provision.start" | "provision.success" | "provision.failure" | "suspend" | "resume" | "resize" | "keys.rotate" | "bastion.key.upload" | "bastion.key.revoke" | "teardown";
417
+ type ProvisioningAuditStatus = "ok" | "error";
418
+ interface ProvisioningAuditLogTable {
419
+ id: Generated<string>;
420
+ tenant_id: string | null;
421
+ tenant_slug: string | null;
422
+ account_id: string | null;
423
+ actor: string;
424
+ event: ProvisioningAuditEvent;
425
+ status: ProvisioningAuditStatus;
426
+ detail: unknown | null;
427
+ error: string | null;
428
+ created_at: Generated<Date>;
429
+ }
430
+ type SubscriptionStatus = "active" | "paused" | "error";
431
+ type SubscriptionFormat = "standard-webhooks" | "inngest" | "trigger" | "cloudflare" | "cloudevents" | "raw";
432
+ type SubscriptionRuntime = "inngest" | "trigger" | "cloudflare" | "node";
433
+ interface SubscriptionsTable {
434
+ id: Generated<string>;
435
+ account_id: string;
436
+ project_id: string | null;
437
+ name: string;
438
+ status: ColumnType<SubscriptionStatus, SubscriptionStatus | undefined, SubscriptionStatus>;
439
+ subgraph_name: string;
440
+ table_name: string;
441
+ filter: Generated<unknown>;
442
+ format: ColumnType<SubscriptionFormat, SubscriptionFormat | undefined, SubscriptionFormat>;
443
+ runtime: SubscriptionRuntime | null;
444
+ url: string;
445
+ signing_secret_enc: Buffer;
446
+ auth_config: Generated<unknown>;
447
+ max_retries: Generated<number>;
448
+ timeout_ms: Generated<number>;
449
+ concurrency: Generated<number>;
450
+ circuit_failures: Generated<number>;
451
+ circuit_opened_at: Date | null;
452
+ last_delivery_at: Date | null;
453
+ last_success_at: Date | null;
454
+ last_error: string | null;
455
+ created_at: Generated<Date>;
456
+ updated_at: Generated<Date>;
457
+ }
458
+ type OutboxStatus = "pending" | "delivered" | "dead";
459
+ interface SubscriptionOutboxTable {
460
+ id: Generated<string>;
461
+ subscription_id: string;
462
+ subgraph_name: string;
463
+ table_name: string;
464
+ block_height: number | bigint;
465
+ tx_id: string | null;
466
+ row_pk: unknown;
467
+ event_type: string;
468
+ payload: unknown;
469
+ dedup_key: string;
470
+ attempt: Generated<number>;
471
+ next_attempt_at: Generated<Date>;
472
+ status: ColumnType<OutboxStatus, OutboxStatus | undefined, OutboxStatus>;
473
+ is_replay: Generated<boolean>;
474
+ delivered_at: Date | null;
475
+ failed_at: Date | null;
476
+ locked_by: string | null;
477
+ locked_until: Date | null;
478
+ created_at: Generated<Date>;
479
+ }
480
+ interface SubscriptionDeliveriesTable {
481
+ id: Generated<string>;
482
+ outbox_id: string;
483
+ subscription_id: string;
484
+ attempt: number;
485
+ status_code: number | null;
486
+ response_headers: unknown | null;
487
+ response_body: string | null;
488
+ error_message: string | null;
489
+ duration_ms: number | null;
490
+ dispatched_at: Generated<Date>;
491
+ }
492
+ import { Kysely, Transaction as Transaction2 } from "kysely";
493
+ type ChainReorgCursor = {
494
+ block_height: number
495
+ event_index: number
496
+ };
497
+ type ChainReorgRecord = {
498
+ id: string
499
+ detected_at: string
500
+ fork_point_height: number
501
+ old_index_block_hash: string | null
502
+ new_index_block_hash: string | null
503
+ orphaned_range: {
504
+ from: string
505
+ to: string
506
+ }
507
+ new_canonical_tip: string
508
+ };
509
+ type InsertChainReorgParams = {
510
+ forkPointHeight: number
511
+ oldIndexBlockHash?: string | null
512
+ newIndexBlockHash?: string | null
513
+ orphanedFrom: ChainReorgCursor
514
+ orphanedTo: ChainReorgCursor
515
+ newCanonicalTip: ChainReorgCursor
516
+ db?: Kysely<Database> | Transaction2<Database>
517
+ };
518
+ type ReadChainReorgsSinceParams = {
519
+ since: Date | ChainReorgCursor
520
+ limit: number
521
+ db?: Kysely<Database>
522
+ };
523
+ type ReadChainReorgsForRangeParams = {
524
+ from: ChainReorgCursor
525
+ to: ChainReorgCursor
526
+ db?: Kysely<Database>
527
+ };
528
+ declare function encodeChainReorgCursor(cursor: ChainReorgCursor): string;
529
+ declare function insertChainReorg(params: InsertChainReorgParams): Promise<ChainReorgRecord>;
530
+ declare function readChainReorgsSince(params: ReadChainReorgsSinceParams): Promise<ChainReorgRecord[]>;
531
+ declare function readChainReorgsForRange(params: ReadChainReorgsForRangeParams): Promise<ChainReorgRecord[]>;
532
+ export { readChainReorgsSince, readChainReorgsForRange, insertChainReorg, encodeChainReorgCursor, ReadChainReorgsSinceParams, ReadChainReorgsForRangeParams, InsertChainReorgParams, ChainReorgRecord, ChainReorgCursor };