@secondlayer/shared 6.4.2 → 6.4.4
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 +1 -9
- package/dist/src/db/queries/account-spend-caps.d.ts +0 -8
- package/dist/src/db/queries/account-usage.d.ts +0 -8
- package/dist/src/db/queries/accounts.d.ts +1 -19
- package/dist/src/db/queries/accounts.js +2 -37
- package/dist/src/db/queries/accounts.js.map +3 -3
- package/dist/src/db/queries/chain-reorgs.d.ts +0 -8
- package/dist/src/db/queries/integrity.d.ts +0 -8
- package/dist/src/db/queries/projects.d.ts +0 -8
- package/dist/src/db/queries/provisioning-audit.d.ts +0 -8
- package/dist/src/db/queries/subgraph-gaps.d.ts +0 -8
- package/dist/src/db/queries/subgraph-operations.d.ts +0 -8
- package/dist/src/db/queries/subgraph-operations.js +16 -9
- package/dist/src/db/queries/subgraph-operations.js.map +3 -3
- package/dist/src/db/queries/subgraphs.d.ts +0 -8
- package/dist/src/db/queries/subscriptions.d.ts +0 -8
- package/dist/src/db/queries/tenant-compute-addons.d.ts +0 -8
- package/dist/src/db/queries/usage.d.ts +0 -8
- package/dist/src/db/schema.d.ts +1 -9
- package/dist/src/index.d.ts +1 -9
- package/dist/src/node/local-client.d.ts +0 -8
- package/migrations/0078_drop_waitlist.ts +25 -0
- package/package.json +1 -1
package/dist/src/db/index.d.ts
CHANGED
|
@@ -175,13 +175,6 @@ interface UsageSnapshotsTable {
|
|
|
175
175
|
measured_at: Generated<Date>;
|
|
176
176
|
storage_bytes: Generated<number>;
|
|
177
177
|
}
|
|
178
|
-
interface WaitlistTable {
|
|
179
|
-
id: Generated<string>;
|
|
180
|
-
email: string;
|
|
181
|
-
source: Generated<string>;
|
|
182
|
-
status: Generated<string>;
|
|
183
|
-
created_at: Generated<Date>;
|
|
184
|
-
}
|
|
185
178
|
interface AccountInsightsTable {
|
|
186
179
|
id: Generated<string>;
|
|
187
180
|
account_id: string;
|
|
@@ -548,7 +541,6 @@ interface Database {
|
|
|
548
541
|
magic_links: MagicLinksTable;
|
|
549
542
|
usage_daily: UsageDailyTable;
|
|
550
543
|
usage_snapshots: UsageSnapshotsTable;
|
|
551
|
-
waitlist: WaitlistTable;
|
|
552
544
|
account_insights: AccountInsightsTable;
|
|
553
545
|
account_agent_runs: AccountAgentRunsTable;
|
|
554
546
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
@@ -828,4 +820,4 @@ declare function getDb(connectionString?: string): Kysely<Database>;
|
|
|
828
820
|
declare function getRawClient(role?: "source" | "target"): ReturnType<typeof postgres>;
|
|
829
821
|
/** Close all DB connection pools. Call in CLI commands to allow process exit. */
|
|
830
822
|
declare function closeDb(): Promise<void>;
|
|
831
|
-
export { sql, parseJsonb, jsonb, getTargetDb, getSourceDb, getRawClient, getDb, closeDb,
|
|
823
|
+
export { sql, parseJsonb, jsonb, getTargetDb, getSourceDb, getRawClient, getDb, closeDb, UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateTransaction, UpdateTenantUsageMonthly, UpdateTenantComputeAddon, UpdateTenant, UpdateSubscriptionOutbox, UpdateSubscription, UpdateSubgraphOperation, UpdateSubgraph, UpdateProject, UpdateIndexProgress, UpdateEvent, UpdateChatSession, UpdateBlock, UpdateApiKey, UpdateAccountSpendCap, TransactionsTable, Transaction, TenantsTable, TenantUsageMonthlyTable, TenantUsageMonthly, TenantStatus, TenantComputeAddonsTable, TenantComputeAddon, Tenant, TeamMembersTable, TeamMember, TeamInvitationsTable, TeamInvitation, SubscriptionsTable, SubscriptionStatus, SubscriptionRuntime, SubscriptionOutboxTable, SubscriptionOutbox, SubscriptionFormat, SubscriptionDelivery, SubscriptionDeliveriesTable, Subscription, SubgraphsTable, SubgraphUsageDailyTable, SubgraphUsageDaily, SubgraphTableSnapshotsTable, SubgraphProcessingStatsTable, SubgraphOperationsTable, SubgraphOperationStatus, SubgraphOperationKind, SubgraphOperation, SubgraphHealthSnapshotsTable, SubgraphHealthSnapshot, SubgraphGapsTable, SubgraphGap, Subgraph, SessionsTable, Session, ServiceHeartbeatsTable, SbtcTokenEventsTable, SbtcTokenEventType, SbtcSupplySnapshotsTable, SbtcEventsTable, SbtcEventTopic, ProvisioningAuditStatus, ProvisioningAuditLogTable, ProvisioningAuditLog, ProvisioningAuditEvent, ProjectsTable, Project, ProcessedStripeEventsTable, Pox4SignersDailyTable, Pox4FunctionName, Pox4CyclesDailyTable, Pox4CallsTable, OutboxStatus, MagicLinksTable, MagicLink, L2DecoderCheckpointsTable, InsertTransaction, InsertTenantUsageMonthly, InsertTenantComputeAddon, InsertTenant, InsertTeamMember, InsertTeamInvitation, InsertSubscriptionOutbox, InsertSubscriptionDelivery, InsertSubscription, InsertSubgraphUsageDaily, InsertSubgraphOperation, InsertSubgraphHealthSnapshot, InsertSubgraphGap, InsertSubgraph, InsertSession, InsertProvisioningAuditLog, InsertProject, InsertMagicLink, InsertIndexProgress, InsertEvent, InsertChatSession, InsertChatMessage, InsertBlock, InsertApiKey, InsertAccountSpendCap, InsertAccountInsight, InsertAccountAgentRun, InsertAccount, IndexProgressTable, IndexProgress, EventsTable, Event, DecodedEventsTable, Database, ChatSessionsTable, ChatSession, ChatMessagesTable, ChatMessage, ChainReorgsTable, BnsNamespacesTable, BnsNamespaceEventsTable, BnsNamespaceEventStatus, BnsNamesTable, BnsNameEventsTable, BnsNameEventTopic, BnsMarketplaceEventsTable, BnsMarketplaceAction, BlocksTable, Block, ApiKeysTable, ApiKey, AccountsTable, AccountSpendCapsTable, AccountSpendCap, AccountInsightsTable, AccountInsight, AccountAgentRunsTable, AccountAgentRun, Account };
|
|
@@ -157,13 +157,6 @@ interface UsageSnapshotsTable {
|
|
|
157
157
|
measured_at: Generated<Date>;
|
|
158
158
|
storage_bytes: Generated<number>;
|
|
159
159
|
}
|
|
160
|
-
interface WaitlistTable {
|
|
161
|
-
id: Generated<string>;
|
|
162
|
-
email: string;
|
|
163
|
-
source: Generated<string>;
|
|
164
|
-
status: Generated<string>;
|
|
165
|
-
created_at: Generated<Date>;
|
|
166
|
-
}
|
|
167
160
|
interface AccountInsightsTable {
|
|
168
161
|
id: Generated<string>;
|
|
169
162
|
account_id: string;
|
|
@@ -530,7 +523,6 @@ interface Database {
|
|
|
530
523
|
magic_links: MagicLinksTable;
|
|
531
524
|
usage_daily: UsageDailyTable;
|
|
532
525
|
usage_snapshots: UsageSnapshotsTable;
|
|
533
|
-
waitlist: WaitlistTable;
|
|
534
526
|
account_insights: AccountInsightsTable;
|
|
535
527
|
account_agent_runs: AccountAgentRunsTable;
|
|
536
528
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
@@ -157,13 +157,6 @@ interface UsageSnapshotsTable {
|
|
|
157
157
|
measured_at: Generated<Date>;
|
|
158
158
|
storage_bytes: Generated<number>;
|
|
159
159
|
}
|
|
160
|
-
interface WaitlistTable {
|
|
161
|
-
id: Generated<string>;
|
|
162
|
-
email: string;
|
|
163
|
-
source: Generated<string>;
|
|
164
|
-
status: Generated<string>;
|
|
165
|
-
created_at: Generated<Date>;
|
|
166
|
-
}
|
|
167
160
|
interface AccountInsightsTable {
|
|
168
161
|
id: Generated<string>;
|
|
169
162
|
account_id: string;
|
|
@@ -530,7 +523,6 @@ interface Database {
|
|
|
530
523
|
magic_links: MagicLinksTable;
|
|
531
524
|
usage_daily: UsageDailyTable;
|
|
532
525
|
usage_snapshots: UsageSnapshotsTable;
|
|
533
|
-
waitlist: WaitlistTable;
|
|
534
526
|
account_insights: AccountInsightsTable;
|
|
535
527
|
account_agent_runs: AccountAgentRunsTable;
|
|
536
528
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Kysely } from "kysely";
|
|
2
|
-
import { Selectable as Selectable2 } from "kysely";
|
|
3
2
|
import { ColumnType, Generated, Selectable } from "kysely";
|
|
4
3
|
interface BlocksTable {
|
|
5
4
|
height: number;
|
|
@@ -158,13 +157,6 @@ interface UsageSnapshotsTable {
|
|
|
158
157
|
measured_at: Generated<Date>;
|
|
159
158
|
storage_bytes: Generated<number>;
|
|
160
159
|
}
|
|
161
|
-
interface WaitlistTable {
|
|
162
|
-
id: Generated<string>;
|
|
163
|
-
email: string;
|
|
164
|
-
source: Generated<string>;
|
|
165
|
-
status: Generated<string>;
|
|
166
|
-
created_at: Generated<Date>;
|
|
167
|
-
}
|
|
168
160
|
interface AccountInsightsTable {
|
|
169
161
|
id: Generated<string>;
|
|
170
162
|
account_id: string;
|
|
@@ -531,7 +523,6 @@ interface Database {
|
|
|
531
523
|
magic_links: MagicLinksTable;
|
|
532
524
|
usage_daily: UsageDailyTable;
|
|
533
525
|
usage_snapshots: UsageSnapshotsTable;
|
|
534
|
-
waitlist: WaitlistTable;
|
|
535
526
|
account_insights: AccountInsightsTable;
|
|
536
527
|
account_agent_runs: AccountAgentRunsTable;
|
|
537
528
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
@@ -735,7 +726,6 @@ declare function getAccountByStripeCustomerId(db: Kysely<Database>, stripeCustom
|
|
|
735
726
|
id: string
|
|
736
727
|
} | null>;
|
|
737
728
|
declare function isSlugTaken(db: Kysely<Database>, slug: string, excludeAccountId: string): Promise<boolean>;
|
|
738
|
-
declare function isEmailAllowed(db: Kysely<Database>, email: string): Promise<boolean>;
|
|
739
729
|
declare function createMagicLink(db: Kysely<Database>, email: string, token: string, code: string, expiresInMs?: number): Promise<void>;
|
|
740
730
|
/**
|
|
741
731
|
* Verify a magic link token. Returns the email if valid, null otherwise.
|
|
@@ -748,12 +738,4 @@ declare function verifyMagicLink(db: Kysely<Database>, token: string): Promise<s
|
|
|
748
738
|
* active codes for this email on failure (prevents parallel brute-force).
|
|
749
739
|
*/
|
|
750
740
|
declare function verifyMagicLinkByCode(db: Kysely<Database>, email: string, code: string): Promise<string | null>;
|
|
751
|
-
|
|
752
|
-
declare function listWaitlist(db: Kysely<Database>, status?: string): Promise<WaitlistEntry[]>;
|
|
753
|
-
declare function getWaitlistById(db: Kysely<Database>, id: string): Promise<WaitlistEntry | null>;
|
|
754
|
-
declare function approveWaitlistEntry(db: Kysely<Database>, email: string): Promise<{
|
|
755
|
-
token: string
|
|
756
|
-
code: string
|
|
757
|
-
status: "approved" | "already_approved" | "not_found"
|
|
758
|
-
}>;
|
|
759
|
-
export { verifyMagicLinkByCode, verifyMagicLink, upsertAccount, updateAccountProfile, setStripeCustomerId, setAccountPlan, listWaitlist, isSlugTaken, isEmailAllowed, getWaitlistById, getAccountByStripeCustomerId, getAccountById, createMagicLink, approveWaitlistEntry, WaitlistEntry };
|
|
741
|
+
export { verifyMagicLinkByCode, verifyMagicLink, upsertAccount, updateAccountProfile, setStripeCustomerId, setAccountPlan, isSlugTaken, getAccountByStripeCustomerId, getAccountById, createMagicLink };
|
|
@@ -47,15 +47,6 @@ async function isSlugTaken(db, slug, excludeAccountId) {
|
|
|
47
47
|
const row = await db.selectFrom("accounts").select("id").where("slug", "=", slug).where("id", "!=", excludeAccountId).executeTakeFirst();
|
|
48
48
|
return !!row;
|
|
49
49
|
}
|
|
50
|
-
async function isEmailAllowed(db, email) {
|
|
51
|
-
const result = await sql`
|
|
52
|
-
SELECT 1 AS found FROM accounts WHERE email = ${email}
|
|
53
|
-
UNION ALL
|
|
54
|
-
SELECT 1 AS found FROM waitlist WHERE email = ${email} AND status = 'approved'
|
|
55
|
-
LIMIT 1
|
|
56
|
-
`.execute(db);
|
|
57
|
-
return result.rows.length > 0;
|
|
58
|
-
}
|
|
59
50
|
async function createMagicLink(db, email, token, code, expiresInMs = 15 * 60 * 1000) {
|
|
60
51
|
await db.insertInto("magic_links").values({
|
|
61
52
|
email,
|
|
@@ -78,28 +69,6 @@ async function verifyMagicLinkByCode(db, email, code) {
|
|
|
78
69
|
await db.updateTable("magic_links").set({ failed_attempts: sql`failed_attempts + 1` }).where("email", "=", email).where("used_at", "is", null).where("expires_at", ">", new Date).execute();
|
|
79
70
|
return null;
|
|
80
71
|
}
|
|
81
|
-
async function listWaitlist(db, status) {
|
|
82
|
-
let query = db.selectFrom("waitlist").selectAll().orderBy("created_at", "desc");
|
|
83
|
-
if (status) {
|
|
84
|
-
query = query.where("status", "=", status);
|
|
85
|
-
}
|
|
86
|
-
return query.execute();
|
|
87
|
-
}
|
|
88
|
-
async function getWaitlistById(db, id) {
|
|
89
|
-
return await db.selectFrom("waitlist").selectAll().where("id", "=", id).executeTakeFirst() ?? null;
|
|
90
|
-
}
|
|
91
|
-
async function approveWaitlistEntry(db, email) {
|
|
92
|
-
const row = await db.selectFrom("waitlist").select("status").where("email", "=", email).executeTakeFirst();
|
|
93
|
-
if (!row)
|
|
94
|
-
return { token: "", code: "", status: "not_found" };
|
|
95
|
-
if (row.status !== "pending")
|
|
96
|
-
return { token: "", code: "", status: "already_approved" };
|
|
97
|
-
await db.updateTable("waitlist").set({ status: "approved" }).where("email", "=", email).execute();
|
|
98
|
-
const token = Math.floor(1e5 + Math.random() * 900000).toString();
|
|
99
|
-
const code = String(Math.floor(Math.random() * 1e6)).padStart(6, "0");
|
|
100
|
-
await createMagicLink(db, email, token, code, 7 * 24 * 60 * 60 * 1000);
|
|
101
|
-
return { token, code, status: "approved" };
|
|
102
|
-
}
|
|
103
72
|
export {
|
|
104
73
|
verifyMagicLinkByCode,
|
|
105
74
|
verifyMagicLink,
|
|
@@ -107,15 +76,11 @@ export {
|
|
|
107
76
|
updateAccountProfile,
|
|
108
77
|
setStripeCustomerId,
|
|
109
78
|
setAccountPlan,
|
|
110
|
-
listWaitlist,
|
|
111
79
|
isSlugTaken,
|
|
112
|
-
isEmailAllowed,
|
|
113
|
-
getWaitlistById,
|
|
114
80
|
getAccountByStripeCustomerId,
|
|
115
81
|
getAccountById,
|
|
116
|
-
createMagicLink
|
|
117
|
-
approveWaitlistEntry
|
|
82
|
+
createMagicLink
|
|
118
83
|
};
|
|
119
84
|
|
|
120
|
-
//# debugId=
|
|
85
|
+
//# debugId=3F16B7D5288E440E64756E2164756E21
|
|
121
86
|
//# sourceMappingURL=accounts.js.map
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/db/queries/accounts.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { type Kysely, sql } from \"kysely\";\nimport type {
|
|
5
|
+
"import { type Kysely, sql } from \"kysely\";\nimport type { Account, Database } from \"../types.ts\";\n\nexport async function upsertAccount(\n\tdb: Kysely<Database>,\n\temail: string,\n): Promise<Account> {\n\treturn await db\n\t\t.insertInto(\"accounts\")\n\t\t.values({ email })\n\t\t.onConflict(\n\t\t\t(oc) => oc.column(\"email\").doUpdateSet({ email }), // no-op update to return existing\n\t\t)\n\t\t.returningAll()\n\t\t.executeTakeFirstOrThrow();\n}\n\nexport async function getAccountById(\n\tdb: Kysely<Database>,\n\tid: string,\n): Promise<Account | null> {\n\treturn (\n\t\t(await db\n\t\t\t.selectFrom(\"accounts\")\n\t\t\t.selectAll()\n\t\t\t.where(\"id\", \"=\", id)\n\t\t\t.executeTakeFirst()) ?? null\n\t);\n}\n\nexport async function updateAccountProfile(\n\tdb: Kysely<Database>,\n\tid: string,\n\tdata: {\n\t\tdisplay_name?: string;\n\t\tbio?: string;\n\t\tslug?: string;\n\t},\n): Promise<Account> {\n\tconst set: Record<string, unknown> = {};\n\tif (data.display_name !== undefined) set.display_name = data.display_name;\n\tif (data.bio !== undefined) set.bio = data.bio;\n\tif (data.slug !== undefined) set.slug = data.slug;\n\n\treturn db\n\t\t.updateTable(\"accounts\")\n\t\t.set(set)\n\t\t.where(\"id\", \"=\", id)\n\t\t.returningAll()\n\t\t.executeTakeFirstOrThrow();\n}\n\n/** Persist the Stripe customer id on first upgrade (lazy customer model). */\nexport async function setStripeCustomerId(\n\tdb: Kysely<Database>,\n\taccountId: string,\n\tstripeCustomerId: string,\n): Promise<void> {\n\tawait db\n\t\t.updateTable(\"accounts\")\n\t\t.set({ stripe_customer_id: stripeCustomerId })\n\t\t.where(\"id\", \"=\", accountId)\n\t\t.execute();\n}\n\n/**\n * Set the plan tier on an account. Called by the Stripe webhook on\n * subscription lifecycle events + by the billing page's fast-resolve\n * after a successful Checkout redirect. Returns true if a row was\n * updated (account exists).\n */\nexport async function setAccountPlan(\n\tdb: Kysely<Database>,\n\taccountId: string,\n\tplan: string,\n): Promise<boolean> {\n\tconst result = await db\n\t\t.updateTable(\"accounts\")\n\t\t.set({ plan })\n\t\t.where(\"id\", \"=\", accountId)\n\t\t.executeTakeFirst();\n\treturn (result.numUpdatedRows ?? 0n) > 0n;\n}\n\n/** Resolve an account by its Stripe customer id. Null if no match. */\nexport async function getAccountByStripeCustomerId(\n\tdb: Kysely<Database>,\n\tstripeCustomerId: string,\n): Promise<{ id: string } | null> {\n\tconst row = await db\n\t\t.selectFrom(\"accounts\")\n\t\t.select(\"id\")\n\t\t.where(\"stripe_customer_id\", \"=\", stripeCustomerId)\n\t\t.executeTakeFirst();\n\treturn row ?? null;\n}\n\nexport async function isSlugTaken(\n\tdb: Kysely<Database>,\n\tslug: string,\n\texcludeAccountId: string,\n): Promise<boolean> {\n\tconst row = await db\n\t\t.selectFrom(\"accounts\")\n\t\t.select(\"id\")\n\t\t.where(\"slug\", \"=\", slug)\n\t\t.where(\"id\", \"!=\", excludeAccountId)\n\t\t.executeTakeFirst();\n\treturn !!row;\n}\n\nexport async function createMagicLink(\n\tdb: Kysely<Database>,\n\temail: string,\n\ttoken: string,\n\tcode: string,\n\texpiresInMs: number = 15 * 60 * 1000,\n): Promise<void> {\n\tawait db\n\t\t.insertInto(\"magic_links\")\n\t\t.values({\n\t\t\temail,\n\t\t\ttoken,\n\t\t\tcode,\n\t\t\texpires_at: new Date(Date.now() + expiresInMs),\n\t\t})\n\t\t.execute();\n}\n\n/**\n * Verify a magic link token. Returns the email if valid, null otherwise.\n * Marks the token as used atomically. Rejects after 3 failed attempts.\n */\nexport async function verifyMagicLink(\n\tdb: Kysely<Database>,\n\ttoken: string,\n): Promise<string | null> {\n\tconst result = await db\n\t\t.updateTable(\"magic_links\")\n\t\t.set({ used_at: new Date() })\n\t\t.where(\"token\", \"=\", token)\n\t\t.where(\"used_at\", \"is\", null)\n\t\t.where(\"expires_at\", \">\", new Date())\n\t\t.where(\"failed_attempts\", \"<\", 3)\n\t\t.returning(\"email\")\n\t\t.executeTakeFirst();\n\n\tif (result?.email) return result.email;\n\n\t// Increment failed attempts if token exists but didn't verify\n\tawait db\n\t\t.updateTable(\"magic_links\")\n\t\t.set({ failed_attempts: sql`failed_attempts + 1` })\n\t\t.where(\"token\", \"=\", token)\n\t\t.where(\"used_at\", \"is\", null)\n\t\t.where(\"expires_at\", \">\", new Date())\n\t\t.execute();\n\n\treturn null;\n}\n\n/**\n * Verify by 6-digit code + email. Same atomic pattern as verifyMagicLink.\n * Rejects after 3 failed attempts. Increments failed_attempts on all\n * active codes for this email on failure (prevents parallel brute-force).\n */\nexport async function verifyMagicLinkByCode(\n\tdb: Kysely<Database>,\n\temail: string,\n\tcode: string,\n): Promise<string | null> {\n\tconst result = await db\n\t\t.updateTable(\"magic_links\")\n\t\t.set({ used_at: new Date() })\n\t\t.where(\"email\", \"=\", email)\n\t\t.where(\"code\", \"=\", code)\n\t\t.where(\"used_at\", \"is\", null)\n\t\t.where(\"expires_at\", \">\", new Date())\n\t\t.where(\"failed_attempts\", \"<\", 3)\n\t\t.returning(\"email\")\n\t\t.executeTakeFirst();\n\n\tif (result?.email) return result.email;\n\n\t// Increment failed attempts on all active codes for this email\n\tawait db\n\t\t.updateTable(\"magic_links\")\n\t\t.set({ failed_attempts: sql`failed_attempts + 1` })\n\t\t.where(\"email\", \"=\", email)\n\t\t.where(\"used_at\", \"is\", null)\n\t\t.where(\"expires_at\", \">\", new Date())\n\t\t.execute();\n\n\treturn null;\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAGA,eA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SAAS,KAAK,KAAK,EACzB,MAAM,QAAQ,KAAK,IAAI,EACvB,MAAM,WAAW,MAAM,IAAI,EAC3B,MAAM,cAAc,KAAK,IAAI,IAAM,EACnC,MAAM,mBAAmB,KAAK,CAAC,EAC/B,UAAU,OAAO,EACjB,iBAAiB;AAAA,EAEnB,IAAI,QAAQ;AAAA,IAAO,OAAO,OAAO;AAAA,EAGjC,MAAM,GACJ,YAAY,aAAa,EACzB,IAAI,EAAE,iBAAiB,yBAAyB,CAAC,EACjD,MAAM,SAAS,KAAK,KAAK,EACzB,MAAM,WAAW,MAAM,IAAI,EAC3B,MAAM,cAAc,KAAK,IAAI,IAAM,EACnC,QAAQ;AAAA,EAEV,OAAO;AAAA;",
|
|
8
|
+
"debugId": "3F16B7D5288E440E64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -156,13 +156,6 @@ interface UsageSnapshotsTable {
|
|
|
156
156
|
measured_at: Generated<Date>;
|
|
157
157
|
storage_bytes: Generated<number>;
|
|
158
158
|
}
|
|
159
|
-
interface WaitlistTable {
|
|
160
|
-
id: Generated<string>;
|
|
161
|
-
email: string;
|
|
162
|
-
source: Generated<string>;
|
|
163
|
-
status: Generated<string>;
|
|
164
|
-
created_at: Generated<Date>;
|
|
165
|
-
}
|
|
166
159
|
interface AccountInsightsTable {
|
|
167
160
|
id: Generated<string>;
|
|
168
161
|
account_id: string;
|
|
@@ -529,7 +522,6 @@ interface Database {
|
|
|
529
522
|
magic_links: MagicLinksTable;
|
|
530
523
|
usage_daily: UsageDailyTable;
|
|
531
524
|
usage_snapshots: UsageSnapshotsTable;
|
|
532
|
-
waitlist: WaitlistTable;
|
|
533
525
|
account_insights: AccountInsightsTable;
|
|
534
526
|
account_agent_runs: AccountAgentRunsTable;
|
|
535
527
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
@@ -157,13 +157,6 @@ interface UsageSnapshotsTable {
|
|
|
157
157
|
measured_at: Generated<Date>;
|
|
158
158
|
storage_bytes: Generated<number>;
|
|
159
159
|
}
|
|
160
|
-
interface WaitlistTable {
|
|
161
|
-
id: Generated<string>;
|
|
162
|
-
email: string;
|
|
163
|
-
source: Generated<string>;
|
|
164
|
-
status: Generated<string>;
|
|
165
|
-
created_at: Generated<Date>;
|
|
166
|
-
}
|
|
167
160
|
interface AccountInsightsTable {
|
|
168
161
|
id: Generated<string>;
|
|
169
162
|
account_id: string;
|
|
@@ -530,7 +523,6 @@ interface Database {
|
|
|
530
523
|
magic_links: MagicLinksTable;
|
|
531
524
|
usage_daily: UsageDailyTable;
|
|
532
525
|
usage_snapshots: UsageSnapshotsTable;
|
|
533
|
-
waitlist: WaitlistTable;
|
|
534
526
|
account_insights: AccountInsightsTable;
|
|
535
527
|
account_agent_runs: AccountAgentRunsTable;
|
|
536
528
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
@@ -157,13 +157,6 @@ interface UsageSnapshotsTable {
|
|
|
157
157
|
measured_at: Generated<Date>;
|
|
158
158
|
storage_bytes: Generated<number>;
|
|
159
159
|
}
|
|
160
|
-
interface WaitlistTable {
|
|
161
|
-
id: Generated<string>;
|
|
162
|
-
email: string;
|
|
163
|
-
source: Generated<string>;
|
|
164
|
-
status: Generated<string>;
|
|
165
|
-
created_at: Generated<Date>;
|
|
166
|
-
}
|
|
167
160
|
interface AccountInsightsTable {
|
|
168
161
|
id: Generated<string>;
|
|
169
162
|
account_id: string;
|
|
@@ -530,7 +523,6 @@ interface Database {
|
|
|
530
523
|
magic_links: MagicLinksTable;
|
|
531
524
|
usage_daily: UsageDailyTable;
|
|
532
525
|
usage_snapshots: UsageSnapshotsTable;
|
|
533
|
-
waitlist: WaitlistTable;
|
|
534
526
|
account_insights: AccountInsightsTable;
|
|
535
527
|
account_agent_runs: AccountAgentRunsTable;
|
|
536
528
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
@@ -157,13 +157,6 @@ interface UsageSnapshotsTable {
|
|
|
157
157
|
measured_at: Generated<Date>;
|
|
158
158
|
storage_bytes: Generated<number>;
|
|
159
159
|
}
|
|
160
|
-
interface WaitlistTable {
|
|
161
|
-
id: Generated<string>;
|
|
162
|
-
email: string;
|
|
163
|
-
source: Generated<string>;
|
|
164
|
-
status: Generated<string>;
|
|
165
|
-
created_at: Generated<Date>;
|
|
166
|
-
}
|
|
167
160
|
interface AccountInsightsTable {
|
|
168
161
|
id: Generated<string>;
|
|
169
162
|
account_id: string;
|
|
@@ -530,7 +523,6 @@ interface Database {
|
|
|
530
523
|
magic_links: MagicLinksTable;
|
|
531
524
|
usage_daily: UsageDailyTable;
|
|
532
525
|
usage_snapshots: UsageSnapshotsTable;
|
|
533
|
-
waitlist: WaitlistTable;
|
|
534
526
|
account_insights: AccountInsightsTable;
|
|
535
527
|
account_agent_runs: AccountAgentRunsTable;
|
|
536
528
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
@@ -157,13 +157,6 @@ interface UsageSnapshotsTable {
|
|
|
157
157
|
measured_at: Generated<Date>;
|
|
158
158
|
storage_bytes: Generated<number>;
|
|
159
159
|
}
|
|
160
|
-
interface WaitlistTable {
|
|
161
|
-
id: Generated<string>;
|
|
162
|
-
email: string;
|
|
163
|
-
source: Generated<string>;
|
|
164
|
-
status: Generated<string>;
|
|
165
|
-
created_at: Generated<Date>;
|
|
166
|
-
}
|
|
167
160
|
interface AccountInsightsTable {
|
|
168
161
|
id: Generated<string>;
|
|
169
162
|
account_id: string;
|
|
@@ -530,7 +523,6 @@ interface Database {
|
|
|
530
523
|
magic_links: MagicLinksTable;
|
|
531
524
|
usage_daily: UsageDailyTable;
|
|
532
525
|
usage_snapshots: UsageSnapshotsTable;
|
|
533
|
-
waitlist: WaitlistTable;
|
|
534
526
|
account_insights: AccountInsightsTable;
|
|
535
527
|
account_agent_runs: AccountAgentRunsTable;
|
|
536
528
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
@@ -157,13 +157,6 @@ interface UsageSnapshotsTable {
|
|
|
157
157
|
measured_at: Generated<Date>;
|
|
158
158
|
storage_bytes: Generated<number>;
|
|
159
159
|
}
|
|
160
|
-
interface WaitlistTable {
|
|
161
|
-
id: Generated<string>;
|
|
162
|
-
email: string;
|
|
163
|
-
source: Generated<string>;
|
|
164
|
-
status: Generated<string>;
|
|
165
|
-
created_at: Generated<Date>;
|
|
166
|
-
}
|
|
167
160
|
interface AccountInsightsTable {
|
|
168
161
|
id: Generated<string>;
|
|
169
162
|
account_id: string;
|
|
@@ -530,7 +523,6 @@ interface Database {
|
|
|
530
523
|
magic_links: MagicLinksTable;
|
|
531
524
|
usage_daily: UsageDailyTable;
|
|
532
525
|
usage_snapshots: UsageSnapshotsTable;
|
|
533
|
-
waitlist: WaitlistTable;
|
|
534
526
|
account_insights: AccountInsightsTable;
|
|
535
527
|
account_agent_runs: AccountAgentRunsTable;
|
|
536
528
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
@@ -64,18 +64,25 @@ async function claimSubgraphOperation(db, lockedBy) {
|
|
|
64
64
|
started_at = COALESCE(started_at, now()),
|
|
65
65
|
updated_at = now()
|
|
66
66
|
WHERE id = (
|
|
67
|
-
SELECT id
|
|
68
|
-
FROM subgraph_operations
|
|
67
|
+
SELECT so.id
|
|
68
|
+
FROM subgraph_operations so
|
|
69
|
+
LEFT JOIN (
|
|
70
|
+
SELECT account_id, COUNT(*) AS cnt
|
|
71
|
+
FROM subgraph_operations
|
|
72
|
+
WHERE status = 'running'
|
|
73
|
+
GROUP BY account_id
|
|
74
|
+
) rc ON so.account_id = rc.account_id
|
|
69
75
|
WHERE
|
|
70
|
-
status = 'queued'
|
|
76
|
+
so.status = 'queued'
|
|
71
77
|
OR (
|
|
72
|
-
status = 'running'
|
|
73
|
-
AND (locked_until IS NULL OR locked_until < now())
|
|
78
|
+
so.status = 'running'
|
|
79
|
+
AND (so.locked_until IS NULL OR so.locked_until < now())
|
|
74
80
|
)
|
|
75
81
|
ORDER BY
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
COALESCE(rc.cnt, 0) ASC,
|
|
83
|
+
CASE WHEN so.status = 'queued' THEN 0 ELSE 1 END,
|
|
84
|
+
so.created_at ASC
|
|
85
|
+
FOR UPDATE OF so SKIP LOCKED
|
|
79
86
|
LIMIT 1
|
|
80
87
|
)
|
|
81
88
|
RETURNING *
|
|
@@ -137,5 +144,5 @@ export {
|
|
|
137
144
|
cancelSubgraphOperation
|
|
138
145
|
};
|
|
139
146
|
|
|
140
|
-
//# debugId=
|
|
147
|
+
//# debugId=E70EFC240746415E64756E2164756E21
|
|
141
148
|
//# sourceMappingURL=subgraph-operations.js.map
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/db/queries/subgraph-operations.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { type Kysely, sql } from \"kysely\";\nimport type {\n\tDatabase,\n\tSubgraphOperation,\n\tSubgraphOperationKind,\n\tSubgraphOperationStatus,\n} from \"../types.ts\";\n\nconst ACTIVE_STATUSES: SubgraphOperationStatus[] = [\"queued\", \"running\"];\n\nexport function isActiveSubgraphOperationConflict(err: unknown): boolean {\n\tif (!(err instanceof Error)) return false;\n\tconst candidate = err as Error & {\n\t\tcode?: string;\n\t\tconstraint?: string;\n\t\tconstraint_name?: string;\n\t};\n\treturn (\n\t\tcandidate.code === \"23505\" &&\n\t\t(candidate.constraint === \"subgraph_operations_active_unique\" ||\n\t\t\tcandidate.constraint_name === \"subgraph_operations_active_unique\")\n\t);\n}\n\nexport async function createSubgraphOperation(\n\tdb: Kysely<Database>,\n\tdata: {\n\t\tsubgraphId: string;\n\t\tsubgraphName: string;\n\t\taccountId?: string | null;\n\t\tkind: SubgraphOperationKind;\n\t\tfromBlock?: number;\n\t\ttoBlock?: number;\n\t},\n): Promise<SubgraphOperation> {\n\treturn await db\n\t\t.insertInto(\"subgraph_operations\")\n\t\t.values({\n\t\t\tsubgraph_id: data.subgraphId,\n\t\t\tsubgraph_name: data.subgraphName,\n\t\t\taccount_id: data.accountId ?? null,\n\t\t\tkind: data.kind,\n\t\t\tfrom_block: data.fromBlock ?? null,\n\t\t\tto_block: data.toBlock ?? null,\n\t\t})\n\t\t.returningAll()\n\t\t.executeTakeFirstOrThrow();\n}\n\nexport async function findActiveSubgraphOperation(\n\tdb: Kysely<Database>,\n\tsubgraphId: string,\n): Promise<SubgraphOperation | null> {\n\treturn (\n\t\t(await db\n\t\t\t.selectFrom(\"subgraph_operations\")\n\t\t\t.selectAll()\n\t\t\t.where(\"subgraph_id\", \"=\", subgraphId)\n\t\t\t.where(\"status\", \"in\", ACTIVE_STATUSES)\n\t\t\t.orderBy(\"created_at\", \"asc\")\n\t\t\t.executeTakeFirst()) ?? null\n\t);\n}\n\nexport async function requestSubgraphOperationCancel(\n\tdb: Kysely<Database>,\n\tsubgraphId: string,\n): Promise<SubgraphOperation | null> {\n\treturn (\n\t\t(await db\n\t\t\t.updateTable(\"subgraph_operations\")\n\t\t\t.set({ cancel_requested: true, updated_at: new Date() })\n\t\t\t.where(\"subgraph_id\", \"=\", subgraphId)\n\t\t\t.where(\"status\", \"in\", ACTIVE_STATUSES)\n\t\t\t.returningAll()\n\t\t\t.executeTakeFirst()) ?? null\n\t);\n}\n\nexport async function requestSubgraphOperationsCancelForDelete(\n\tdb: Kysely<Database>,\n\tsubgraphId: string,\n): Promise<SubgraphOperation[]> {\n\treturn await db\n\t\t.updateTable(\"subgraph_operations\")\n\t\t.set({ cancel_requested: true, updated_at: new Date() })\n\t\t.where(\"subgraph_id\", \"=\", subgraphId)\n\t\t.where(\"status\", \"in\", ACTIVE_STATUSES)\n\t\t.returningAll()\n\t\t.execute();\n}\n\n/**\n * Poll until no active subgraph operations remain for the subgraph or until\n * `timeoutMs` elapses. Returns true if all active operations cleared, false\n * if we timed out. Callers should use this before `DROP SCHEMA` so the active\n * processor has a chance to observe `cancel_requested` and release its row /\n * advisory locks. Without this, the DROP blocks behind the live transaction\n * and the API socket times out before the lock releases.\n */\nexport async function waitForSubgraphOperationsClear(\n\tdb: Kysely<Database>,\n\tsubgraphId: string,\n\topts?: { timeoutMs?: number; pollMs?: number },\n): Promise<boolean> {\n\tconst timeoutMs = opts?.timeoutMs ?? 30_000;\n\tconst pollMs = opts?.pollMs ?? 500;\n\tconst deadline = Date.now() + timeoutMs;\n\twhile (Date.now() < deadline) {\n\t\tconst active = await db\n\t\t\t.selectFrom(\"subgraph_operations\")\n\t\t\t.select(\"id\")\n\t\t\t.where(\"subgraph_id\", \"=\", subgraphId)\n\t\t\t.where(\"status\", \"in\", ACTIVE_STATUSES)\n\t\t\t.limit(1)\n\t\t\t.executeTakeFirst();\n\t\tif (!active) return true;\n\t\tawait new Promise((r) => setTimeout(r, pollMs));\n\t}\n\treturn false;\n}\n\nexport async function claimSubgraphOperation(\n\tdb: Kysely<Database>,\n\tlockedBy: string,\n): Promise<SubgraphOperation | null> {\n\tconst result = await sql<SubgraphOperation>`\n\t\tUPDATE subgraph_operations\n\t\tSET\n\t\t\tstatus = 'running',\n\t\t\tlocked_by = ${lockedBy},\n\t\t\tlocked_until = now() + interval '60 seconds',\n\t\t\tstarted_at = COALESCE(started_at, now()),\n\t\t\tupdated_at = now()\n\t\tWHERE id = (\n\t\t\tSELECT id\n\t\t\tFROM subgraph_operations\n\t\t\tWHERE\n\t\t\t\
|
|
5
|
+
"import { type Kysely, sql } from \"kysely\";\nimport type {\n\tDatabase,\n\tSubgraphOperation,\n\tSubgraphOperationKind,\n\tSubgraphOperationStatus,\n} from \"../types.ts\";\n\nconst ACTIVE_STATUSES: SubgraphOperationStatus[] = [\"queued\", \"running\"];\n\nexport function isActiveSubgraphOperationConflict(err: unknown): boolean {\n\tif (!(err instanceof Error)) return false;\n\tconst candidate = err as Error & {\n\t\tcode?: string;\n\t\tconstraint?: string;\n\t\tconstraint_name?: string;\n\t};\n\treturn (\n\t\tcandidate.code === \"23505\" &&\n\t\t(candidate.constraint === \"subgraph_operations_active_unique\" ||\n\t\t\tcandidate.constraint_name === \"subgraph_operations_active_unique\")\n\t);\n}\n\nexport async function createSubgraphOperation(\n\tdb: Kysely<Database>,\n\tdata: {\n\t\tsubgraphId: string;\n\t\tsubgraphName: string;\n\t\taccountId?: string | null;\n\t\tkind: SubgraphOperationKind;\n\t\tfromBlock?: number;\n\t\ttoBlock?: number;\n\t},\n): Promise<SubgraphOperation> {\n\treturn await db\n\t\t.insertInto(\"subgraph_operations\")\n\t\t.values({\n\t\t\tsubgraph_id: data.subgraphId,\n\t\t\tsubgraph_name: data.subgraphName,\n\t\t\taccount_id: data.accountId ?? null,\n\t\t\tkind: data.kind,\n\t\t\tfrom_block: data.fromBlock ?? null,\n\t\t\tto_block: data.toBlock ?? null,\n\t\t})\n\t\t.returningAll()\n\t\t.executeTakeFirstOrThrow();\n}\n\nexport async function findActiveSubgraphOperation(\n\tdb: Kysely<Database>,\n\tsubgraphId: string,\n): Promise<SubgraphOperation | null> {\n\treturn (\n\t\t(await db\n\t\t\t.selectFrom(\"subgraph_operations\")\n\t\t\t.selectAll()\n\t\t\t.where(\"subgraph_id\", \"=\", subgraphId)\n\t\t\t.where(\"status\", \"in\", ACTIVE_STATUSES)\n\t\t\t.orderBy(\"created_at\", \"asc\")\n\t\t\t.executeTakeFirst()) ?? null\n\t);\n}\n\nexport async function requestSubgraphOperationCancel(\n\tdb: Kysely<Database>,\n\tsubgraphId: string,\n): Promise<SubgraphOperation | null> {\n\treturn (\n\t\t(await db\n\t\t\t.updateTable(\"subgraph_operations\")\n\t\t\t.set({ cancel_requested: true, updated_at: new Date() })\n\t\t\t.where(\"subgraph_id\", \"=\", subgraphId)\n\t\t\t.where(\"status\", \"in\", ACTIVE_STATUSES)\n\t\t\t.returningAll()\n\t\t\t.executeTakeFirst()) ?? null\n\t);\n}\n\nexport async function requestSubgraphOperationsCancelForDelete(\n\tdb: Kysely<Database>,\n\tsubgraphId: string,\n): Promise<SubgraphOperation[]> {\n\treturn await db\n\t\t.updateTable(\"subgraph_operations\")\n\t\t.set({ cancel_requested: true, updated_at: new Date() })\n\t\t.where(\"subgraph_id\", \"=\", subgraphId)\n\t\t.where(\"status\", \"in\", ACTIVE_STATUSES)\n\t\t.returningAll()\n\t\t.execute();\n}\n\n/**\n * Poll until no active subgraph operations remain for the subgraph or until\n * `timeoutMs` elapses. Returns true if all active operations cleared, false\n * if we timed out. Callers should use this before `DROP SCHEMA` so the active\n * processor has a chance to observe `cancel_requested` and release its row /\n * advisory locks. Without this, the DROP blocks behind the live transaction\n * and the API socket times out before the lock releases.\n */\nexport async function waitForSubgraphOperationsClear(\n\tdb: Kysely<Database>,\n\tsubgraphId: string,\n\topts?: { timeoutMs?: number; pollMs?: number },\n): Promise<boolean> {\n\tconst timeoutMs = opts?.timeoutMs ?? 30_000;\n\tconst pollMs = opts?.pollMs ?? 500;\n\tconst deadline = Date.now() + timeoutMs;\n\twhile (Date.now() < deadline) {\n\t\tconst active = await db\n\t\t\t.selectFrom(\"subgraph_operations\")\n\t\t\t.select(\"id\")\n\t\t\t.where(\"subgraph_id\", \"=\", subgraphId)\n\t\t\t.where(\"status\", \"in\", ACTIVE_STATUSES)\n\t\t\t.limit(1)\n\t\t\t.executeTakeFirst();\n\t\tif (!active) return true;\n\t\tawait new Promise((r) => setTimeout(r, pollMs));\n\t}\n\treturn false;\n}\n\nexport async function claimSubgraphOperation(\n\tdb: Kysely<Database>,\n\tlockedBy: string,\n): Promise<SubgraphOperation | null> {\n\t// Fair queue: accounts with fewer currently-running operations are served first,\n\t// breaking ties by creation time. Prevents one user's long reindex from\n\t// starving other accounts when SUBGRAPH_OPERATION_CONCURRENCY > 1.\n\tconst result = await sql<SubgraphOperation>`\n\t\tUPDATE subgraph_operations\n\t\tSET\n\t\t\tstatus = 'running',\n\t\t\tlocked_by = ${lockedBy},\n\t\t\tlocked_until = now() + interval '60 seconds',\n\t\t\tstarted_at = COALESCE(started_at, now()),\n\t\t\tupdated_at = now()\n\t\tWHERE id = (\n\t\t\tSELECT so.id\n\t\t\tFROM subgraph_operations so\n\t\t\tLEFT JOIN (\n\t\t\t\tSELECT account_id, COUNT(*) AS cnt\n\t\t\t\tFROM subgraph_operations\n\t\t\t\tWHERE status = 'running'\n\t\t\t\tGROUP BY account_id\n\t\t\t) rc ON so.account_id = rc.account_id\n\t\t\tWHERE\n\t\t\t\tso.status = 'queued'\n\t\t\t\tOR (\n\t\t\t\t\tso.status = 'running'\n\t\t\t\t\tAND (so.locked_until IS NULL OR so.locked_until < now())\n\t\t\t\t)\n\t\t\tORDER BY\n\t\t\t\tCOALESCE(rc.cnt, 0) ASC,\n\t\t\t\tCASE WHEN so.status = 'queued' THEN 0 ELSE 1 END,\n\t\t\t\tso.created_at ASC\n\t\t\tFOR UPDATE OF so SKIP LOCKED\n\t\t\tLIMIT 1\n\t\t)\n\t\tRETURNING *\n\t`.execute(db);\n\treturn result.rows[0] ?? null;\n}\n\nexport async function heartbeatSubgraphOperation(\n\tdb: Kysely<Database>,\n\toperationId: string,\n\tlockedBy: string,\n): Promise<void> {\n\tawait db\n\t\t.updateTable(\"subgraph_operations\")\n\t\t.set({\n\t\t\tlocked_until: sql<Date>`now() + interval '60 seconds'`,\n\t\t\tupdated_at: new Date(),\n\t\t})\n\t\t.where(\"id\", \"=\", operationId)\n\t\t.where(\"status\", \"=\", \"running\")\n\t\t.where(\"locked_by\", \"=\", lockedBy)\n\t\t.execute();\n}\n\nexport async function getSubgraphOperation(\n\tdb: Kysely<Database>,\n\toperationId: string,\n): Promise<SubgraphOperation | null> {\n\treturn (\n\t\t(await db\n\t\t\t.selectFrom(\"subgraph_operations\")\n\t\t\t.selectAll()\n\t\t\t.where(\"id\", \"=\", operationId)\n\t\t\t.executeTakeFirst()) ?? null\n\t);\n}\n\nexport async function completeSubgraphOperation(\n\tdb: Kysely<Database>,\n\toperationId: string,\n\tlockedBy: string,\n\tprocessedBlocks: number,\n): Promise<void> {\n\tawait db\n\t\t.updateTable(\"subgraph_operations\")\n\t\t.set({\n\t\t\tstatus: \"completed\",\n\t\t\tfinished_at: new Date(),\n\t\t\tprocessed_blocks: processedBlocks,\n\t\t\tlocked_by: null,\n\t\t\tlocked_until: null,\n\t\t\tupdated_at: new Date(),\n\t\t})\n\t\t.where(\"id\", \"=\", operationId)\n\t\t.where(\"locked_by\", \"=\", lockedBy)\n\t\t.execute();\n}\n\nexport async function cancelSubgraphOperation(\n\tdb: Kysely<Database>,\n\toperationId: string,\n\tlockedBy: string,\n\tprocessedBlocks: number,\n): Promise<void> {\n\tawait db\n\t\t.updateTable(\"subgraph_operations\")\n\t\t.set({\n\t\t\tstatus: \"cancelled\",\n\t\t\tfinished_at: new Date(),\n\t\t\tprocessed_blocks: processedBlocks,\n\t\t\tlocked_by: null,\n\t\t\tlocked_until: null,\n\t\t\tupdated_at: new Date(),\n\t\t})\n\t\t.where(\"id\", \"=\", operationId)\n\t\t.where(\"locked_by\", \"=\", lockedBy)\n\t\t.execute();\n}\n\nexport async function failSubgraphOperation(\n\tdb: Kysely<Database>,\n\toperationId: string,\n\tlockedBy: string,\n\terror: string,\n\tprocessedBlocks?: number,\n): Promise<void> {\n\tawait db\n\t\t.updateTable(\"subgraph_operations\")\n\t\t.set({\n\t\t\tstatus: \"failed\",\n\t\t\tfinished_at: new Date(),\n\t\t\tprocessed_blocks: processedBlocks ?? null,\n\t\t\terror,\n\t\t\tlocked_by: null,\n\t\t\tlocked_until: null,\n\t\t\tupdated_at: new Date(),\n\t\t})\n\t\t.where(\"id\", \"=\", operationId)\n\t\t.where(\"locked_by\", \"=\", lockedBy)\n\t\t.execute();\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAQA,IAAM,kBAA6C,CAAC,UAAU,SAAS;AAEhE,SAAS,iCAAiC,CAAC,KAAuB;AAAA,EACxE,IAAI,EAAE,eAAe;AAAA,IAAQ,OAAO;AAAA,EACpC,MAAM,YAAY;AAAA,EAKlB,OACC,UAAU,SAAS,YAClB,UAAU,eAAe,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;AAAA,IACA,WAAW;AAAA,IACX,cAAc;AAAA,IACd,YAAY,IAAI;AAAA,EACjB,CAAC,EACA,MAAM,MAAM,KAAK,WAAW,EAC5B,MAAM,aAAa,KAAK,QAAQ,EAChC,QAAQ;AAAA;",
|
|
8
|
+
"debugId": "E70EFC240746415E64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -157,13 +157,6 @@ interface UsageSnapshotsTable {
|
|
|
157
157
|
measured_at: Generated<Date>;
|
|
158
158
|
storage_bytes: Generated<number>;
|
|
159
159
|
}
|
|
160
|
-
interface WaitlistTable {
|
|
161
|
-
id: Generated<string>;
|
|
162
|
-
email: string;
|
|
163
|
-
source: Generated<string>;
|
|
164
|
-
status: Generated<string>;
|
|
165
|
-
created_at: Generated<Date>;
|
|
166
|
-
}
|
|
167
160
|
interface AccountInsightsTable {
|
|
168
161
|
id: Generated<string>;
|
|
169
162
|
account_id: string;
|
|
@@ -530,7 +523,6 @@ interface Database {
|
|
|
530
523
|
magic_links: MagicLinksTable;
|
|
531
524
|
usage_daily: UsageDailyTable;
|
|
532
525
|
usage_snapshots: UsageSnapshotsTable;
|
|
533
|
-
waitlist: WaitlistTable;
|
|
534
526
|
account_insights: AccountInsightsTable;
|
|
535
527
|
account_agent_runs: AccountAgentRunsTable;
|
|
536
528
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
@@ -157,13 +157,6 @@ interface UsageSnapshotsTable {
|
|
|
157
157
|
measured_at: Generated<Date>;
|
|
158
158
|
storage_bytes: Generated<number>;
|
|
159
159
|
}
|
|
160
|
-
interface WaitlistTable {
|
|
161
|
-
id: Generated<string>;
|
|
162
|
-
email: string;
|
|
163
|
-
source: Generated<string>;
|
|
164
|
-
status: Generated<string>;
|
|
165
|
-
created_at: Generated<Date>;
|
|
166
|
-
}
|
|
167
160
|
interface AccountInsightsTable {
|
|
168
161
|
id: Generated<string>;
|
|
169
162
|
account_id: string;
|
|
@@ -530,7 +523,6 @@ interface Database {
|
|
|
530
523
|
magic_links: MagicLinksTable;
|
|
531
524
|
usage_daily: UsageDailyTable;
|
|
532
525
|
usage_snapshots: UsageSnapshotsTable;
|
|
533
|
-
waitlist: WaitlistTable;
|
|
534
526
|
account_insights: AccountInsightsTable;
|
|
535
527
|
account_agent_runs: AccountAgentRunsTable;
|
|
536
528
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
@@ -157,13 +157,6 @@ interface UsageSnapshotsTable {
|
|
|
157
157
|
measured_at: Generated<Date>;
|
|
158
158
|
storage_bytes: Generated<number>;
|
|
159
159
|
}
|
|
160
|
-
interface WaitlistTable {
|
|
161
|
-
id: Generated<string>;
|
|
162
|
-
email: string;
|
|
163
|
-
source: Generated<string>;
|
|
164
|
-
status: Generated<string>;
|
|
165
|
-
created_at: Generated<Date>;
|
|
166
|
-
}
|
|
167
160
|
interface AccountInsightsTable {
|
|
168
161
|
id: Generated<string>;
|
|
169
162
|
account_id: string;
|
|
@@ -530,7 +523,6 @@ interface Database {
|
|
|
530
523
|
magic_links: MagicLinksTable;
|
|
531
524
|
usage_daily: UsageDailyTable;
|
|
532
525
|
usage_snapshots: UsageSnapshotsTable;
|
|
533
|
-
waitlist: WaitlistTable;
|
|
534
526
|
account_insights: AccountInsightsTable;
|
|
535
527
|
account_agent_runs: AccountAgentRunsTable;
|
|
536
528
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
@@ -157,13 +157,6 @@ interface UsageSnapshotsTable {
|
|
|
157
157
|
measured_at: Generated<Date>;
|
|
158
158
|
storage_bytes: Generated<number>;
|
|
159
159
|
}
|
|
160
|
-
interface WaitlistTable {
|
|
161
|
-
id: Generated<string>;
|
|
162
|
-
email: string;
|
|
163
|
-
source: Generated<string>;
|
|
164
|
-
status: Generated<string>;
|
|
165
|
-
created_at: Generated<Date>;
|
|
166
|
-
}
|
|
167
160
|
interface AccountInsightsTable {
|
|
168
161
|
id: Generated<string>;
|
|
169
162
|
account_id: string;
|
|
@@ -530,7 +523,6 @@ interface Database {
|
|
|
530
523
|
magic_links: MagicLinksTable;
|
|
531
524
|
usage_daily: UsageDailyTable;
|
|
532
525
|
usage_snapshots: UsageSnapshotsTable;
|
|
533
|
-
waitlist: WaitlistTable;
|
|
534
526
|
account_insights: AccountInsightsTable;
|
|
535
527
|
account_agent_runs: AccountAgentRunsTable;
|
|
536
528
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
package/dist/src/db/schema.d.ts
CHANGED
|
@@ -156,13 +156,6 @@ interface UsageSnapshotsTable {
|
|
|
156
156
|
measured_at: Generated<Date>;
|
|
157
157
|
storage_bytes: Generated<number>;
|
|
158
158
|
}
|
|
159
|
-
interface WaitlistTable {
|
|
160
|
-
id: Generated<string>;
|
|
161
|
-
email: string;
|
|
162
|
-
source: Generated<string>;
|
|
163
|
-
status: Generated<string>;
|
|
164
|
-
created_at: Generated<Date>;
|
|
165
|
-
}
|
|
166
159
|
interface AccountInsightsTable {
|
|
167
160
|
id: Generated<string>;
|
|
168
161
|
account_id: string;
|
|
@@ -529,7 +522,6 @@ interface Database {
|
|
|
529
522
|
magic_links: MagicLinksTable;
|
|
530
523
|
usage_daily: UsageDailyTable;
|
|
531
524
|
usage_snapshots: UsageSnapshotsTable;
|
|
532
|
-
waitlist: WaitlistTable;
|
|
533
525
|
account_insights: AccountInsightsTable;
|
|
534
526
|
account_agent_runs: AccountAgentRunsTable;
|
|
535
527
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
@@ -784,4 +776,4 @@ interface SubscriptionDeliveriesTable {
|
|
|
784
776
|
}
|
|
785
777
|
type SubscriptionDelivery = Selectable<SubscriptionDeliveriesTable>;
|
|
786
778
|
type InsertSubscriptionDelivery = Insertable<SubscriptionDeliveriesTable>;
|
|
787
|
-
export {
|
|
779
|
+
export { UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateTransaction, UpdateTenantUsageMonthly, UpdateTenantComputeAddon, UpdateTenant, UpdateSubscriptionOutbox, UpdateSubscription, UpdateSubgraphOperation, UpdateSubgraph, UpdateProject, UpdateIndexProgress, UpdateEvent, UpdateChatSession, UpdateBlock, UpdateApiKey, UpdateAccountSpendCap, TransactionsTable, Transaction, TenantsTable, TenantUsageMonthlyTable, TenantUsageMonthly, TenantStatus, TenantComputeAddonsTable, TenantComputeAddon, Tenant, TeamMembersTable, TeamMember, TeamInvitationsTable, TeamInvitation, SubscriptionsTable, SubscriptionStatus, SubscriptionRuntime, SubscriptionOutboxTable, SubscriptionOutbox, SubscriptionFormat, SubscriptionDelivery, SubscriptionDeliveriesTable, Subscription, SubgraphsTable, SubgraphUsageDailyTable, SubgraphUsageDaily, SubgraphTableSnapshotsTable, SubgraphProcessingStatsTable, SubgraphOperationsTable, SubgraphOperationStatus, SubgraphOperationKind, SubgraphOperation, SubgraphHealthSnapshotsTable, SubgraphHealthSnapshot, SubgraphGapsTable, SubgraphGap, Subgraph, SessionsTable, Session, ServiceHeartbeatsTable, SbtcTokenEventsTable, SbtcTokenEventType, SbtcSupplySnapshotsTable, SbtcEventsTable, SbtcEventTopic, ProvisioningAuditStatus, ProvisioningAuditLogTable, ProvisioningAuditLog, ProvisioningAuditEvent, ProjectsTable, Project, ProcessedStripeEventsTable, Pox4SignersDailyTable, Pox4FunctionName, Pox4CyclesDailyTable, Pox4CallsTable, OutboxStatus, MagicLinksTable, MagicLink, L2DecoderCheckpointsTable, InsertTransaction, InsertTenantUsageMonthly, InsertTenantComputeAddon, InsertTenant, InsertTeamMember, InsertTeamInvitation, InsertSubscriptionOutbox, InsertSubscriptionDelivery, InsertSubscription, InsertSubgraphUsageDaily, InsertSubgraphOperation, InsertSubgraphHealthSnapshot, InsertSubgraphGap, InsertSubgraph, InsertSession, InsertProvisioningAuditLog, InsertProject, InsertMagicLink, InsertIndexProgress, InsertEvent, InsertChatSession, InsertChatMessage, InsertBlock, InsertApiKey, InsertAccountSpendCap, InsertAccountInsight, InsertAccountAgentRun, InsertAccount, IndexProgressTable, IndexProgress, EventsTable, Event, DecodedEventsTable, Database, ChatSessionsTable, ChatSession, ChatMessagesTable, ChatMessage, ChainReorgsTable, BnsNamespacesTable, BnsNamespaceEventsTable, BnsNamespaceEventStatus, BnsNamesTable, BnsNameEventsTable, BnsNameEventTopic, BnsMarketplaceEventsTable, BnsMarketplaceAction, BlocksTable, Block, ApiKeysTable, ApiKey, AccountsTable, AccountSpendCapsTable, AccountSpendCap, AccountInsightsTable, AccountInsight, AccountAgentRunsTable, AccountAgentRun, Account };
|
package/dist/src/index.d.ts
CHANGED
|
@@ -156,13 +156,6 @@ interface UsageSnapshotsTable {
|
|
|
156
156
|
measured_at: Generated<Date>;
|
|
157
157
|
storage_bytes: Generated<number>;
|
|
158
158
|
}
|
|
159
|
-
interface WaitlistTable {
|
|
160
|
-
id: Generated<string>;
|
|
161
|
-
email: string;
|
|
162
|
-
source: Generated<string>;
|
|
163
|
-
status: Generated<string>;
|
|
164
|
-
created_at: Generated<Date>;
|
|
165
|
-
}
|
|
166
159
|
interface AccountInsightsTable {
|
|
167
160
|
id: Generated<string>;
|
|
168
161
|
account_id: string;
|
|
@@ -529,7 +522,6 @@ interface Database {
|
|
|
529
522
|
magic_links: MagicLinksTable;
|
|
530
523
|
usage_daily: UsageDailyTable;
|
|
531
524
|
usage_snapshots: UsageSnapshotsTable;
|
|
532
|
-
waitlist: WaitlistTable;
|
|
533
525
|
account_insights: AccountInsightsTable;
|
|
534
526
|
account_agent_runs: AccountAgentRunsTable;
|
|
535
527
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
@@ -1394,4 +1386,4 @@ declare function createSignatureHeader(payload: string, secret: string, timestam
|
|
|
1394
1386
|
* Returns true if valid, false otherwise
|
|
1395
1387
|
*/
|
|
1396
1388
|
declare function verifySignatureHeader(payload: string, header: string, secret: string, toleranceSeconds?: number): boolean;
|
|
1397
|
-
export { validateSubscriptionFilterForTable, sql, parseJsonb, logger, jsonb, getTargetDb, getSourceDb, getRawClient, getErrorMessage, getEnv, getDb, generateSubgraphSpec, generateSubgraphOpenApi, generateSubgraphMarkdown, generateSubgraphAgentSchema, formatSubscriptionSchemaErrors, exports_hmac as crypto, closeDb,
|
|
1389
|
+
export { validateSubscriptionFilterForTable, sql, parseJsonb, logger, jsonb, getTargetDb, getSourceDb, getRawClient, getErrorMessage, getEnv, getDb, generateSubgraphSpec, generateSubgraphOpenApi, generateSubgraphMarkdown, generateSubgraphAgentSchema, formatSubscriptionSchemaErrors, exports_hmac as crypto, closeDb, VersionConflictError, ValidationError, UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateTransaction, UpdateTenantUsageMonthly, UpdateTenantComputeAddon, UpdateTenant, UpdateSubscriptionRequestSchema, UpdateSubscriptionRequest, UpdateSubscriptionOutbox, UpdateSubscription, UpdateSubgraphOperation, UpdateSubgraph, UpdateProject, 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, ServiceHeartbeatsTable, SecondLayerError, SbtcTokenEventsTable, SbtcTokenEventType, SbtcSupplySnapshotsTable, SbtcEventsTable, SbtcEventTopic, SUBSCRIPTION_STATUSES, SUBSCRIPTION_RUNTIMES, SUBSCRIPTION_FORMATS, SUBSCRIPTION_FILTER_OPERATORS, RotateSecretResponse, ReplaySubscriptionRequestSchema, ReplaySubscriptionRequest, ReplayResult, ReindexResponse, RateLimitError, ProvisioningAuditStatus, ProvisioningAuditLogTable, ProvisioningAuditLog, ProvisioningAuditEvent, ProjectsTable, Project, ProcessedStripeEventsTable, PrintEventFilterSchema, PrintEventFilter, Pox4SignersDailyTable, Pox4FunctionName, Pox4CyclesDailyTable, Pox4CallsTable, ParsedUpdateSubscriptionRequest, ParsedReplaySubscriptionRequest, ParsedCreateSubscriptionRequest, OutboxStatus, NotFoundError, NftTransferFilterSchema, NftTransferFilter, NftMintFilterSchema, NftMintFilter, NftBurnFilterSchema, NftBurnFilter, MagicLinksTable, MagicLink, L2DecoderCheckpointsTable, KeyRotatedError, InsertTransaction, InsertTenantUsageMonthly, InsertTenantComputeAddon, InsertTenant, InsertTeamMember, InsertTeamInvitation, InsertSubscriptionOutbox, InsertSubscriptionDelivery, InsertSubscription, InsertSubgraphUsageDaily, InsertSubgraphOperation, InsertSubgraphHealthSnapshot, InsertSubgraphGap, InsertSubgraph, InsertSession, InsertProvisioningAuditLog, InsertProject, InsertMagicLink, InsertIndexProgress, InsertEvent, InsertChatSession, InsertChatMessage, InsertBlock, InsertApiKey, InsertAccountSpendCap, InsertAccountInsight, InsertAccountAgentRun, InsertAccount, IndexProgressTable, IndexProgress, FtTransferFilterSchema, FtTransferFilter, FtMintFilterSchema, FtMintFilter, FtBurnFilterSchema, FtBurnFilter, ForbiddenError, EventsTable, EventFilterSchema, EventFilter, Event, ErrorCodes, ErrorCode, Env, DeploySubgraphResponse, DeploySubgraphRequestSchema, DeploySubgraphRequest, DeliveryRow, DecodedEventsTable, DeadRow, DatabaseError, Database, CreateSubscriptionResponse, CreateSubscriptionRequestSchema, CreateSubscriptionRequest, ContractDeployFilterSchema, ContractDeployFilter, ContractCallFilterSchema, ContractCallFilter, ChatSessionsTable, ChatSession, ChatMessagesTable, ChatMessage, ChainReorgsTable, CODE_TO_STATUS, BnsNamespacesTable, BnsNamespaceEventsTable, BnsNamespaceEventStatus, BnsNamesTable, BnsNameEventsTable, BnsNameEventTopic, BnsMarketplaceEventsTable, BnsMarketplaceAction, BlocksTable, Block, AuthorizationError, AuthenticationError, ApiKeysTable, ApiKey, AccountsTable, AccountSpendCapsTable, AccountSpendCap, AccountInsightsTable, AccountInsight, AccountAgentRunsTable, AccountAgentRun, Account };
|
|
@@ -157,13 +157,6 @@ interface UsageSnapshotsTable {
|
|
|
157
157
|
measured_at: Generated<Date>;
|
|
158
158
|
storage_bytes: Generated<number>;
|
|
159
159
|
}
|
|
160
|
-
interface WaitlistTable {
|
|
161
|
-
id: Generated<string>;
|
|
162
|
-
email: string;
|
|
163
|
-
source: Generated<string>;
|
|
164
|
-
status: Generated<string>;
|
|
165
|
-
created_at: Generated<Date>;
|
|
166
|
-
}
|
|
167
160
|
interface AccountInsightsTable {
|
|
168
161
|
id: Generated<string>;
|
|
169
162
|
account_id: string;
|
|
@@ -530,7 +523,6 @@ interface Database {
|
|
|
530
523
|
magic_links: MagicLinksTable;
|
|
531
524
|
usage_daily: UsageDailyTable;
|
|
532
525
|
usage_snapshots: UsageSnapshotsTable;
|
|
533
|
-
waitlist: WaitlistTable;
|
|
534
526
|
account_insights: AccountInsightsTable;
|
|
535
527
|
account_agent_runs: AccountAgentRunsTable;
|
|
536
528
|
subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
|
|
3
|
+
// Open signup replaced the waitlist gate — the table is no longer read or written.
|
|
4
|
+
|
|
5
|
+
// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety
|
|
6
|
+
export async function up(db: Kysely<any>): Promise<void> {
|
|
7
|
+
await db.schema.dropTable("waitlist").ifExists().execute();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Recreates the table as it stood after 0009 + 0010 (no data).
|
|
11
|
+
// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety
|
|
12
|
+
export async function down(db: Kysely<any>): Promise<void> {
|
|
13
|
+
await db.schema
|
|
14
|
+
.createTable("waitlist")
|
|
15
|
+
.addColumn("id", "uuid", (col) =>
|
|
16
|
+
col.primaryKey().defaultTo(db.fn("gen_random_uuid")),
|
|
17
|
+
)
|
|
18
|
+
.addColumn("email", "text", (col) => col.notNull().unique())
|
|
19
|
+
.addColumn("source", "text", (col) => col.defaultTo("website"))
|
|
20
|
+
.addColumn("created_at", "timestamptz", (col) =>
|
|
21
|
+
col.notNull().defaultTo(db.fn("now")),
|
|
22
|
+
)
|
|
23
|
+
.addColumn("status", "text", (col) => col.notNull().defaultTo("pending"))
|
|
24
|
+
.execute();
|
|
25
|
+
}
|