@secondlayer/shared 7.11.2 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/src/archive/range-digest.d.ts +16 -169
  2. package/dist/src/archive/semantic-digest-builder.d.ts +16 -169
  3. package/dist/src/archive/status.js +11 -3
  4. package/dist/src/archive/status.js.map +3 -3
  5. package/dist/src/coverage/index.d.ts +15 -169
  6. package/dist/src/crypto/secrets.js +22 -3
  7. package/dist/src/crypto/secrets.js.map +3 -3
  8. package/dist/src/db/index.d.ts +18 -211
  9. package/dist/src/db/index.js +23 -16
  10. package/dist/src/db/index.js.map +4 -4
  11. package/dist/src/db/queries/chain-reorgs.d.ts +16 -169
  12. package/dist/src/db/queries/chain-reorgs.js +23 -16
  13. package/dist/src/db/queries/chain-reorgs.js.map +4 -4
  14. package/dist/src/db/queries/contracts.d.ts +16 -169
  15. package/dist/src/db/queries/instance.d.ts +16 -169
  16. package/dist/src/db/queries/integrity.d.ts +16 -169
  17. package/dist/src/db/queries/subgraph-gaps.d.ts +16 -169
  18. package/dist/src/db/queries/subgraph-operations.d.ts +17 -170
  19. package/dist/src/db/queries/subgraph-operations.js +1 -15
  20. package/dist/src/db/queries/subgraph-operations.js.map +3 -3
  21. package/dist/src/db/queries/subgraphs.d.ts +17 -191
  22. package/dist/src/db/queries/subgraphs.js +30 -1068
  23. package/dist/src/db/queries/subgraphs.js.map +5 -12
  24. package/dist/src/db/queries/subscriptions.d.ts +16 -169
  25. package/dist/src/db/queries/subscriptions.js +22 -3
  26. package/dist/src/db/queries/subscriptions.js.map +3 -3
  27. package/dist/src/db/queries/sync-scope.d.ts +1006 -0
  28. package/dist/src/db/queries/sync-scope.js +116 -0
  29. package/dist/src/db/queries/sync-scope.js.map +10 -0
  30. package/dist/src/db/schema.d.ts +17 -198
  31. package/dist/src/errors.d.ts +1 -22
  32. package/dist/src/errors.js +2 -4
  33. package/dist/src/errors.js.map +3 -3
  34. package/dist/src/index.d.ts +22 -256
  35. package/dist/src/index.js +24 -20
  36. package/dist/src/index.js.map +6 -6
  37. package/dist/src/mode.d.ts +16 -2
  38. package/dist/src/mode.js +25 -4
  39. package/dist/src/mode.js.map +3 -3
  40. package/dist/src/node/local-client.d.ts +16 -169
  41. package/dist/src/runtime/index.d.ts +137 -18
  42. package/dist/src/runtime/index.js +261 -41
  43. package/dist/src/runtime/index.js.map +9 -7
  44. package/dist/src/schemas/index.d.ts +5 -25
  45. package/dist/src/schemas/index.js +1 -2
  46. package/dist/src/schemas/index.js.map +3 -3
  47. package/dist/src/schemas/subgraphs.d.ts +5 -25
  48. package/dist/src/schemas/subgraphs.js +1 -2
  49. package/dist/src/schemas/subgraphs.js.map +3 -3
  50. package/dist/src/streams-rows/index.d.ts +399 -0
  51. package/dist/src/streams-rows/index.js +336 -0
  52. package/dist/src/streams-rows/index.js.map +17 -0
  53. package/dist/src/subgraphs/spec.d.ts +0 -9
  54. package/migrations/0118_drop_retired_control_tables.ts +53 -0
  55. package/migrations/0119_drop_accounts_plan.ts +29 -0
  56. package/migrations/0120_sync_scopes.ts +42 -0
  57. package/package.json +10 -6
  58. package/dist/src/x402.d.ts +0 -47
  59. package/dist/src/x402.js +0 -79
  60. package/dist/src/x402.js.map +0 -10
@@ -18,6 +18,7 @@ declare const FAILURE_CLASSES: readonly ["omission", "version", "digest_mismatch
18
18
  type FailureClass = (typeof FAILURE_CLASSES)[number];
19
19
  declare const RETRY_STATES: readonly ["open", "retrying", "halted", "resolved"];
20
20
  type RetryState = (typeof RETRY_STATES)[number];
21
+ type BootstrapSource = "archive" | "genesis" | "import";
21
22
  interface BlocksTable {
22
23
  height: number;
23
24
  hash: string;
@@ -223,11 +224,9 @@ interface AccountsTable {
223
224
  ghost: Generated<boolean>;
224
225
  /** Stacks principal owning a wallet-ghost account (x402-paid deploys). */
225
226
  wallet_principal: string | null;
226
- plan: Generated<string>;
227
227
  display_name: string | null;
228
228
  bio: string | null;
229
229
  avatar_url: string | null;
230
- slug: string | null;
231
230
  stripe_customer_id: string | null;
232
231
  /** Opt-out toggle for the subgraph reindex-completion email. Defaults true. */
233
232
  notify_reindex_complete: Generated<boolean>;
@@ -244,19 +243,6 @@ interface SessionsTable {
244
243
  last_used_at: Date | null;
245
244
  created_at: Generated<Date>;
246
245
  }
247
- /**
248
- * One-time claim tokens for ghost accounts. The raw token only ever appears in
249
- * the claim URL returned at mint time; we store its sha256. A used token marks
250
- * the account as claimed (or merged into an existing account).
251
- */
252
- interface ClaimTokensTable {
253
- id: Generated<string>;
254
- account_id: string;
255
- token_hash: string;
256
- created_at: Generated<Date>;
257
- expires_at: Date;
258
- used_at: Date | null;
259
- }
260
246
  interface MagicLinksTable {
261
247
  id: Generated<string>;
262
248
  email: string;
@@ -267,47 +253,6 @@ interface MagicLinksTable {
267
253
  failed_attempts: Generated<number>;
268
254
  created_at: Generated<Date>;
269
255
  }
270
- interface UsageDailyTable {
271
- account_id: string;
272
- tenant_id: string | null;
273
- date: string;
274
- api_requests: Generated<number>;
275
- deliveries: Generated<number>;
276
- streams_events_returned: Generated<number>;
277
- index_decoded_events_returned: Generated<number>;
278
- }
279
- interface UsageSnapshotsTable {
280
- id: Generated<string>;
281
- account_id: string;
282
- measured_at: Generated<Date>;
283
- storage_bytes: Generated<number>;
284
- }
285
- interface AccountInsightsTable {
286
- id: Generated<string>;
287
- account_id: string;
288
- category: string;
289
- insight_type: string;
290
- resource_id: string | null;
291
- severity: string;
292
- title: string;
293
- body: string;
294
- data: unknown;
295
- dismissed_at: Date | null;
296
- expires_at: Date | null;
297
- created_at: Generated<Date>;
298
- }
299
- interface AccountAgentRunsTable {
300
- id: Generated<string>;
301
- account_id: string;
302
- started_at: Generated<Date>;
303
- completed_at: Date | null;
304
- status: Generated<string>;
305
- input_tokens: Generated<number>;
306
- output_tokens: Generated<number>;
307
- cost_usd: Generated<number>;
308
- insights_created: Generated<number>;
309
- error: string | null;
310
- }
311
256
  interface SubgraphProcessingStatsTable {
312
257
  id: Generated<string>;
313
258
  subgraph_name: string;
@@ -340,41 +285,6 @@ interface SubgraphHealthSnapshotsTable {
340
285
  last_processed_block: number | null;
341
286
  captured_at: Generated<Date>;
342
287
  }
343
- interface SubgraphUsageDailyTable {
344
- subgraph_id: string;
345
- date: string;
346
- query_count: Generated<number>;
347
- }
348
- interface ProjectsTable {
349
- id: Generated<string>;
350
- name: string;
351
- slug: string;
352
- account_id: string;
353
- settings: Generated<Record<string, unknown>>;
354
- network: Generated<string>;
355
- node_rpc: string | null;
356
- created_at: Generated<Date>;
357
- updated_at: Generated<Date>;
358
- }
359
- interface TeamMembersTable {
360
- id: Generated<string>;
361
- project_id: string;
362
- account_id: string;
363
- role: Generated<string>;
364
- invited_by: string | null;
365
- created_at: Generated<Date>;
366
- }
367
- interface TeamInvitationsTable {
368
- id: Generated<string>;
369
- project_id: string;
370
- email: string;
371
- role: Generated<string>;
372
- token: string;
373
- invited_by: string | null;
374
- expires_at: Date;
375
- accepted_at: Date | null;
376
- created_at: Generated<Date>;
377
- }
378
288
  interface ProcessedStripeEventsTable {
379
289
  event_id: string;
380
290
  event_type: string;
@@ -811,6 +721,20 @@ interface StageFailuresTable {
811
721
  resolved_at: Date | null;
812
722
  retain_until: Generated<Date>;
813
723
  }
724
+ /**
725
+ * The instance's declared scope — one row per network. `start_height` is what
726
+ * makes missing history below it deliberate rather than a gap.
727
+ */
728
+ interface SyncScopesTable {
729
+ network: string;
730
+ start_height: number;
731
+ target_height: number | null;
732
+ bootstrap_source: BootstrapSource;
733
+ bootstrap_manifest_digest: string | null;
734
+ genesis_hash: string | null;
735
+ created_at: Generated<Date>;
736
+ updated_at: Generated<Date>;
737
+ }
814
738
  interface Database {
815
739
  blocks: BlocksTable;
816
740
  transactions: TransactionsTable;
@@ -827,27 +751,14 @@ interface Database {
827
751
  accounts: AccountsTable;
828
752
  sessions: SessionsTable;
829
753
  magic_links: MagicLinksTable;
830
- claim_tokens: ClaimTokensTable;
831
- usage_daily: UsageDailyTable;
832
- usage_snapshots: UsageSnapshotsTable;
833
- account_insights: AccountInsightsTable;
834
- account_agent_runs: AccountAgentRunsTable;
835
754
  subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
836
755
  subgraph_processing_stats: SubgraphProcessingStatsTable;
837
756
  subgraph_table_snapshots: SubgraphTableSnapshotsTable;
838
757
  subgraph_gaps: SubgraphGapsTable;
839
758
  subgraph_operations: SubgraphOperationsTable;
840
- subgraph_usage_daily: SubgraphUsageDailyTable;
841
- projects: ProjectsTable;
842
- team_members: TeamMembersTable;
843
- team_invitations: TeamInvitationsTable;
844
759
  processed_stripe_events: ProcessedStripeEventsTable;
845
- tenants: TenantsTable;
846
- tenant_usage_monthly: TenantUsageMonthlyTable;
847
- tenant_compute_addons: TenantComputeAddonsTable;
848
760
  account_spend_caps: AccountSpendCapsTable;
849
761
  account_credits: AccountCreditsTable;
850
- provisioning_audit_log: ProvisioningAuditLogTable;
851
762
  subscriptions: SubscriptionsTable;
852
763
  subscription_outbox: SubscriptionOutboxTable;
853
764
  subscription_deliveries: SubscriptionDeliveriesTable;
@@ -876,6 +787,7 @@ interface Database {
876
787
  chain_read_cache: ChainReadCacheTable;
877
788
  pending_fork_blocks: PendingForkBlocksTable;
878
789
  observer_journal: ObserverJournalTable;
790
+ sync_scopes: SyncScopesTable;
879
791
  stage_registry: StageRegistryTable;
880
792
  stage_runs: StageRunsTable;
881
793
  stage_block_receipts: StageBlockReceiptsTable;
@@ -922,57 +834,6 @@ interface X402PaymentsTable {
922
834
  * reconciler's heal path can never double-credit them. */
923
835
  credited_at: Generated<Date> | null;
924
836
  }
925
- type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
926
- interface TenantsTable {
927
- id: Generated<string>;
928
- account_id: string;
929
- slug: string;
930
- status: ColumnType<TenantStatus, TenantStatus | undefined, TenantStatus>;
931
- plan: string;
932
- cpus: ColumnType<number, number | string, number | string>;
933
- memory_mb: number;
934
- storage_limit_mb: number;
935
- storage_used_mb: number | null;
936
- pg_container_id: string | null;
937
- api_container_id: string | null;
938
- processor_container_id: string | null;
939
- target_database_url_enc: Buffer;
940
- tenant_jwt_secret_enc: Buffer;
941
- anon_key_enc: Buffer;
942
- service_key_enc: Buffer;
943
- api_url_internal: string;
944
- api_url_public: string;
945
- suspended_at: Date | null;
946
- last_health_check_at: Date | null;
947
- last_active_at: Generated<Date>;
948
- service_gen: Generated<number>;
949
- anon_gen: Generated<number>;
950
- project_id: string | null;
951
- created_at: Generated<Date>;
952
- updated_at: Generated<Date>;
953
- }
954
- interface TenantUsageMonthlyTable {
955
- id: Generated<string>;
956
- tenant_id: string;
957
- period_month: Date;
958
- storage_peak_mb: Generated<number>;
959
- storage_avg_mb: Generated<number>;
960
- storage_last_mb: Generated<number>;
961
- measurements: Generated<number>;
962
- first_at: Generated<Date>;
963
- last_at: Generated<Date>;
964
- }
965
- interface TenantComputeAddonsTable {
966
- id: Generated<string>;
967
- tenant_id: string;
968
- memory_mb_delta: Generated<number>;
969
- cpu_delta: Generated<number | string>;
970
- storage_mb_delta: Generated<number>;
971
- effective_from: Generated<Date>;
972
- effective_until: Date | null;
973
- stripe_subscription_item_id: string | null;
974
- created_at: Generated<Date>;
975
- }
976
837
  interface AccountSpendCapsTable {
977
838
  account_id: string;
978
839
  monthly_cap_cents: number | null;
@@ -996,20 +857,6 @@ interface AccountCreditsTable {
996
857
  refill_last_at: Date | null;
997
858
  updated_at: Generated<Date>;
998
859
  }
999
- type ProvisioningAuditEvent = "provision.start" | "provision.success" | "provision.failure" | "suspend" | "resume" | "resize" | "keys.rotate" | "bastion.key.upload" | "bastion.key.revoke" | "teardown";
1000
- type ProvisioningAuditStatus = "ok" | "error";
1001
- interface ProvisioningAuditLogTable {
1002
- id: Generated<string>;
1003
- tenant_id: string | null;
1004
- tenant_slug: string | null;
1005
- account_id: string | null;
1006
- actor: string;
1007
- event: ProvisioningAuditEvent;
1008
- status: ProvisioningAuditStatus;
1009
- detail: unknown | null;
1010
- error: string | null;
1011
- created_at: Generated<Date>;
1012
- }
1013
860
  type SubscriptionStatus = "active" | "paused" | "error";
1014
861
  /** Polymorphic subscription mode: `subgraph` reacts to processed table rows;
1015
862
  * `chain` reacts to raw chain events matched directly off the Index/Streams
@@ -18,6 +18,7 @@ declare const FAILURE_CLASSES: readonly ["omission", "version", "digest_mismatch
18
18
  type FailureClass = (typeof FAILURE_CLASSES)[number];
19
19
  declare const RETRY_STATES: readonly ["open", "retrying", "halted", "resolved"];
20
20
  type RetryState = (typeof RETRY_STATES)[number];
21
+ type BootstrapSource = "archive" | "genesis" | "import";
21
22
  interface BlocksTable {
22
23
  height: number;
23
24
  hash: string;
@@ -223,11 +224,9 @@ interface AccountsTable {
223
224
  ghost: Generated<boolean>;
224
225
  /** Stacks principal owning a wallet-ghost account (x402-paid deploys). */
225
226
  wallet_principal: string | null;
226
- plan: Generated<string>;
227
227
  display_name: string | null;
228
228
  bio: string | null;
229
229
  avatar_url: string | null;
230
- slug: string | null;
231
230
  stripe_customer_id: string | null;
232
231
  /** Opt-out toggle for the subgraph reindex-completion email. Defaults true. */
233
232
  notify_reindex_complete: Generated<boolean>;
@@ -244,19 +243,6 @@ interface SessionsTable {
244
243
  last_used_at: Date | null;
245
244
  created_at: Generated<Date>;
246
245
  }
247
- /**
248
- * One-time claim tokens for ghost accounts. The raw token only ever appears in
249
- * the claim URL returned at mint time; we store its sha256. A used token marks
250
- * the account as claimed (or merged into an existing account).
251
- */
252
- interface ClaimTokensTable {
253
- id: Generated<string>;
254
- account_id: string;
255
- token_hash: string;
256
- created_at: Generated<Date>;
257
- expires_at: Date;
258
- used_at: Date | null;
259
- }
260
246
  interface MagicLinksTable {
261
247
  id: Generated<string>;
262
248
  email: string;
@@ -267,47 +253,6 @@ interface MagicLinksTable {
267
253
  failed_attempts: Generated<number>;
268
254
  created_at: Generated<Date>;
269
255
  }
270
- interface UsageDailyTable {
271
- account_id: string;
272
- tenant_id: string | null;
273
- date: string;
274
- api_requests: Generated<number>;
275
- deliveries: Generated<number>;
276
- streams_events_returned: Generated<number>;
277
- index_decoded_events_returned: Generated<number>;
278
- }
279
- interface UsageSnapshotsTable {
280
- id: Generated<string>;
281
- account_id: string;
282
- measured_at: Generated<Date>;
283
- storage_bytes: Generated<number>;
284
- }
285
- interface AccountInsightsTable {
286
- id: Generated<string>;
287
- account_id: string;
288
- category: string;
289
- insight_type: string;
290
- resource_id: string | null;
291
- severity: string;
292
- title: string;
293
- body: string;
294
- data: unknown;
295
- dismissed_at: Date | null;
296
- expires_at: Date | null;
297
- created_at: Generated<Date>;
298
- }
299
- interface AccountAgentRunsTable {
300
- id: Generated<string>;
301
- account_id: string;
302
- started_at: Generated<Date>;
303
- completed_at: Date | null;
304
- status: Generated<string>;
305
- input_tokens: Generated<number>;
306
- output_tokens: Generated<number>;
307
- cost_usd: Generated<number>;
308
- insights_created: Generated<number>;
309
- error: string | null;
310
- }
311
256
  interface SubgraphProcessingStatsTable {
312
257
  id: Generated<string>;
313
258
  subgraph_name: string;
@@ -340,41 +285,6 @@ interface SubgraphHealthSnapshotsTable {
340
285
  last_processed_block: number | null;
341
286
  captured_at: Generated<Date>;
342
287
  }
343
- interface SubgraphUsageDailyTable {
344
- subgraph_id: string;
345
- date: string;
346
- query_count: Generated<number>;
347
- }
348
- interface ProjectsTable {
349
- id: Generated<string>;
350
- name: string;
351
- slug: string;
352
- account_id: string;
353
- settings: Generated<Record<string, unknown>>;
354
- network: Generated<string>;
355
- node_rpc: string | null;
356
- created_at: Generated<Date>;
357
- updated_at: Generated<Date>;
358
- }
359
- interface TeamMembersTable {
360
- id: Generated<string>;
361
- project_id: string;
362
- account_id: string;
363
- role: Generated<string>;
364
- invited_by: string | null;
365
- created_at: Generated<Date>;
366
- }
367
- interface TeamInvitationsTable {
368
- id: Generated<string>;
369
- project_id: string;
370
- email: string;
371
- role: Generated<string>;
372
- token: string;
373
- invited_by: string | null;
374
- expires_at: Date;
375
- accepted_at: Date | null;
376
- created_at: Generated<Date>;
377
- }
378
288
  interface ProcessedStripeEventsTable {
379
289
  event_id: string;
380
290
  event_type: string;
@@ -811,6 +721,20 @@ interface StageFailuresTable {
811
721
  resolved_at: Date | null;
812
722
  retain_until: Generated<Date>;
813
723
  }
724
+ /**
725
+ * The instance's declared scope — one row per network. `start_height` is what
726
+ * makes missing history below it deliberate rather than a gap.
727
+ */
728
+ interface SyncScopesTable {
729
+ network: string;
730
+ start_height: number;
731
+ target_height: number | null;
732
+ bootstrap_source: BootstrapSource;
733
+ bootstrap_manifest_digest: string | null;
734
+ genesis_hash: string | null;
735
+ created_at: Generated<Date>;
736
+ updated_at: Generated<Date>;
737
+ }
814
738
  interface Database {
815
739
  blocks: BlocksTable;
816
740
  transactions: TransactionsTable;
@@ -827,27 +751,14 @@ interface Database {
827
751
  accounts: AccountsTable;
828
752
  sessions: SessionsTable;
829
753
  magic_links: MagicLinksTable;
830
- claim_tokens: ClaimTokensTable;
831
- usage_daily: UsageDailyTable;
832
- usage_snapshots: UsageSnapshotsTable;
833
- account_insights: AccountInsightsTable;
834
- account_agent_runs: AccountAgentRunsTable;
835
754
  subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
836
755
  subgraph_processing_stats: SubgraphProcessingStatsTable;
837
756
  subgraph_table_snapshots: SubgraphTableSnapshotsTable;
838
757
  subgraph_gaps: SubgraphGapsTable;
839
758
  subgraph_operations: SubgraphOperationsTable;
840
- subgraph_usage_daily: SubgraphUsageDailyTable;
841
- projects: ProjectsTable;
842
- team_members: TeamMembersTable;
843
- team_invitations: TeamInvitationsTable;
844
759
  processed_stripe_events: ProcessedStripeEventsTable;
845
- tenants: TenantsTable;
846
- tenant_usage_monthly: TenantUsageMonthlyTable;
847
- tenant_compute_addons: TenantComputeAddonsTable;
848
760
  account_spend_caps: AccountSpendCapsTable;
849
761
  account_credits: AccountCreditsTable;
850
- provisioning_audit_log: ProvisioningAuditLogTable;
851
762
  subscriptions: SubscriptionsTable;
852
763
  subscription_outbox: SubscriptionOutboxTable;
853
764
  subscription_deliveries: SubscriptionDeliveriesTable;
@@ -876,6 +787,7 @@ interface Database {
876
787
  chain_read_cache: ChainReadCacheTable;
877
788
  pending_fork_blocks: PendingForkBlocksTable;
878
789
  observer_journal: ObserverJournalTable;
790
+ sync_scopes: SyncScopesTable;
879
791
  stage_registry: StageRegistryTable;
880
792
  stage_runs: StageRunsTable;
881
793
  stage_block_receipts: StageBlockReceiptsTable;
@@ -922,57 +834,6 @@ interface X402PaymentsTable {
922
834
  * reconciler's heal path can never double-credit them. */
923
835
  credited_at: Generated<Date> | null;
924
836
  }
925
- type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
926
- interface TenantsTable {
927
- id: Generated<string>;
928
- account_id: string;
929
- slug: string;
930
- status: ColumnType<TenantStatus, TenantStatus | undefined, TenantStatus>;
931
- plan: string;
932
- cpus: ColumnType<number, number | string, number | string>;
933
- memory_mb: number;
934
- storage_limit_mb: number;
935
- storage_used_mb: number | null;
936
- pg_container_id: string | null;
937
- api_container_id: string | null;
938
- processor_container_id: string | null;
939
- target_database_url_enc: Buffer;
940
- tenant_jwt_secret_enc: Buffer;
941
- anon_key_enc: Buffer;
942
- service_key_enc: Buffer;
943
- api_url_internal: string;
944
- api_url_public: string;
945
- suspended_at: Date | null;
946
- last_health_check_at: Date | null;
947
- last_active_at: Generated<Date>;
948
- service_gen: Generated<number>;
949
- anon_gen: Generated<number>;
950
- project_id: string | null;
951
- created_at: Generated<Date>;
952
- updated_at: Generated<Date>;
953
- }
954
- interface TenantUsageMonthlyTable {
955
- id: Generated<string>;
956
- tenant_id: string;
957
- period_month: Date;
958
- storage_peak_mb: Generated<number>;
959
- storage_avg_mb: Generated<number>;
960
- storage_last_mb: Generated<number>;
961
- measurements: Generated<number>;
962
- first_at: Generated<Date>;
963
- last_at: Generated<Date>;
964
- }
965
- interface TenantComputeAddonsTable {
966
- id: Generated<string>;
967
- tenant_id: string;
968
- memory_mb_delta: Generated<number>;
969
- cpu_delta: Generated<number | string>;
970
- storage_mb_delta: Generated<number>;
971
- effective_from: Generated<Date>;
972
- effective_until: Date | null;
973
- stripe_subscription_item_id: string | null;
974
- created_at: Generated<Date>;
975
- }
976
837
  interface AccountSpendCapsTable {
977
838
  account_id: string;
978
839
  monthly_cap_cents: number | null;
@@ -996,20 +857,6 @@ interface AccountCreditsTable {
996
857
  refill_last_at: Date | null;
997
858
  updated_at: Generated<Date>;
998
859
  }
999
- type ProvisioningAuditEvent = "provision.start" | "provision.success" | "provision.failure" | "suspend" | "resume" | "resize" | "keys.rotate" | "bastion.key.upload" | "bastion.key.revoke" | "teardown";
1000
- type ProvisioningAuditStatus = "ok" | "error";
1001
- interface ProvisioningAuditLogTable {
1002
- id: Generated<string>;
1003
- tenant_id: string | null;
1004
- tenant_slug: string | null;
1005
- account_id: string | null;
1006
- actor: string;
1007
- event: ProvisioningAuditEvent;
1008
- status: ProvisioningAuditStatus;
1009
- detail: unknown | null;
1010
- error: string | null;
1011
- created_at: Generated<Date>;
1012
- }
1013
860
  type SubgraphOperation = Selectable<SubgraphOperationsTable>;
1014
861
  type SubscriptionStatus = "active" | "paused" | "error";
1015
862
  /** Polymorphic subscription mode: `subgraph` reacts to processed table rows;
@@ -1134,7 +981,7 @@ declare function listSubgraphOperations(db: Kysely<Database>, subgraphId: string
1134
981
  declare function completeSubgraphOperation(db: Kysely<Database>, operationId: string, lockedBy: string, processedBlocks: number): Promise<void>;
1135
982
  declare function cancelSubgraphOperation(db: Kysely<Database>, operationId: string, lockedBy: string, processedBlocks: number): Promise<void>;
1136
983
  declare function failSubgraphOperation(db: Kysely<Database>, operationId: string, lockedBy: string, error: string, processedBlocks?: number): Promise<void>;
1137
- /**\\n* 1-based position of a queued operation under the claim ordering (fairness →\\n* plan rank → queued-first → FIFO). The heavy-budget admission filter is NOT\\n* applied — a heavy op's eligibility depends on runtime budget state — so the\\n* position is approximate; render it as "~N". Returns null unless queued.\\n*/
984
+ /**\\n* 1-based position of a queued operation under the claim ordering (fairness →\\n* queued-first → FIFO). The heavy-budget admission filter is NOT applied — a\\n* heavy op's eligibility depends on runtime budget state — so the position is\\n* approximate; render it as "~N". Returns null unless queued.\\n*/
1138
985
  declare function getOperationQueuePosition(db: Kysely<Database>, operationId: string): Promise<number | null>;
1139
986
  /** Median duration (seconds) of the last 20 completed ops of a weight class —
1140
987
  * the "est. start" multiplier for queued positions. Null with no history. */
@@ -85,7 +85,6 @@ async function claimSubgraphOperation(db, lockedBy) {
85
85
  WHERE status = 'running'
86
86
  GROUP BY account_id
87
87
  ) rc ON so.account_id = rc.account_id
88
- LEFT JOIN accounts a ON a.id::text = so.account_id
89
88
  WHERE
90
89
  (
91
90
  so.status = 'queued'
@@ -113,12 +112,6 @@ async function claimSubgraphOperation(db, lockedBy) {
113
112
  )
114
113
  ORDER BY
115
114
  COALESCE(rc.cnt, 0) ASC,
116
- CASE COALESCE(a.plan, 'none')
117
- WHEN 'enterprise' THEN 0
118
- WHEN 'scale' THEN 1
119
- WHEN 'launch' THEN 2
120
- ELSE 3
121
- END,
122
115
  CASE WHEN so.status = 'queued' THEN 0 ELSE 1 END,
123
116
  so.created_at ASC
124
117
  FOR UPDATE OF so SKIP LOCKED
@@ -179,12 +172,6 @@ async function getOperationQueuePosition(db, operationId) {
179
172
  ROW_NUMBER() OVER (
180
173
  ORDER BY
181
174
  COALESCE(rc.cnt, 0) ASC,
182
- CASE COALESCE(a.plan, 'none')
183
- WHEN 'enterprise' THEN 0
184
- WHEN 'scale' THEN 1
185
- WHEN 'launch' THEN 2
186
- ELSE 3
187
- END,
188
175
  CASE WHEN so.status = 'queued' THEN 0 ELSE 1 END,
189
176
  so.created_at ASC
190
177
  ) AS rn
@@ -195,7 +182,6 @@ async function getOperationQueuePosition(db, operationId) {
195
182
  WHERE status = 'running'
196
183
  GROUP BY account_id
197
184
  ) rc ON so.account_id = rc.account_id
198
- LEFT JOIN accounts a ON a.id::text = so.account_id
199
185
  WHERE so.status = 'queued'
200
186
  )
201
187
  SELECT rn FROM candidates WHERE id = ${operationId}
@@ -255,5 +241,5 @@ export {
255
241
  advanceOperationCursor
256
242
  };
257
243
 
258
- //# debugId=7C6D7169EDA84D0F64756E2164756E21
244
+ //# debugId=774B93C0E098748E64756E2164756E21
259
245
  //# sourceMappingURL=subgraph-operations.js.map