build(typescript): Phase 2 completion — convert data-api.mjs to .ts - #7856
Conversation
Converts workers/data-api.mjs (8940 lines, the Postgres-serving Worker and the last remaining Phase 2 file) and its test file tests/data-api.test.mjs (8570 lines) to .ts, updating the 5 files with data-api.mjs import specifiers (3 route test files, workers/data-api.sentry.ts — again the live deploy entry point, same dangling-specifier class #7837 fixed for api.sentry.ts). postgres.js typing: transaction-scoped helpers (savepoint callers, the read dispatcher, batchedUpsert) take postgres.TransactionSql; the raw per-request connections stay postgres.Sql. Ten runtime-only sync-route secrets (NEURONS_SYNC_SECRET, SUBNET_LOCKS_SYNC_SECRET, etc.) added to workers/env-extra.d.ts — set via wrangler secret put, invisible to `wrangler types` by design. Root-level type corrections in shared src/ modules, each verified behavior-preserving against the implementation: - src/cursor.ts: encodeCursor accepts null parts — cursorPart() already normalized them to a null token (no next_cursor); the declared type was just narrower than the real contract every caller relies on. - src/unkey-client.ts: createUnkeyKey/verifyUnkeyKey returned `Row | UnkeyFetchFailure`, which cannot discriminate on .ok (Row also admits an ok key) — introduced UnkeyMintSuccess/UnkeyVerifySuccess so callers' existing `if (!result.ok)` guards actually narrow. - src/metagraph-neurons.ts + src/subnet-conviction.ts: widened immunityPeriod/now/unlockRate/maturityRate options to `| null` — their paired Postgres/RPC loaders return null by design and the builders already coalesce with ?? internally.
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
metagraphed-registry-sync-api | 09167bc | Jul 24 2026, 02:05 AM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
metagraphed-data-api | 09167bc | Jul 24 2026, 02:05 AM |
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7856 +/- ##
==========================================
- Coverage 97.58% 97.57% -0.01%
==========================================
Files 203 203
Lines 26283 26290 +7
Branches 10414 10420 +6
==========================================
+ Hits 25647 25652 +5
Misses 150 150
- Partials 486 488 +2
🚀 New features to boost your workflow:
|
|
Caution 🛑 LoopOver review result - fixes requiredReview updated: 2026-07-24 11:22:34 UTC
Review summary Nits — 2 non-blocking
Why this is blocked
📋 Copy for AI agents — paste into your coding agentCI checks failing
Decision drivers
Context & advisory signals — never blocks the verdict
Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://loopover.ai/docs/loopover-commands 🧪 Experimental — new and may change. 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
Summary
Part of the TS migration epic (#7510). Completes Phase 2 (#7513,
workers/): convertsworkers/data-api.mjs(8940 lines, the Postgres-serving Worker) andtests/data-api.test.mjs(8570 lines) to.ts, updating the 5 files that import by the.mjsspecifier — includingworkers/data-api.sentry.ts, the livewrangler.data.jsoncdeploy entry point, which would have broken on the next deploy exactly like theapi.sentry.tscase fixed in #7837.Every
workers/**runtime file is now TypeScript.postgres.js typing: transaction-scoped helpers (savepoint-calling loaders, the read-route dispatcher,
batchedUpsert) takepostgres.TransactionSql; raw per-request connections staypostgres.Sql. Ten runtime-only sync-route secrets (NEURONS_SYNC_SECRET,SUBNET_LOCKS_SYNC_SECRET,WALLET_SESSION_SECRET, etc.) are added toworkers/env-extra.d.ts— they're set viawrangler secret putand invisible towrangler typesby design.Root-level type corrections in shared src/ modules
Each verified behavior-preserving against the implementation (not just cast around):
src/cursor.ts:encodeCursornow accepts null parts —cursorPart()already normalized them to a null token (nonext_cursor); the declared type was narrower than the real contract its callers rely on.src/unkey-client.ts:createUnkeyKey/verifyUnkeyKeyreturnedRow | UnkeyFetchFailure, which cannot discriminate on.ok(Rowalso admits anokkey) — introducedUnkeyMintSuccess/UnkeyVerifySuccessso callers' existingif (!result.ok)guards actually narrow.src/metagraph-neurons.ts+src/subnet-conviction.ts: widenedimmunityPeriod/now/unlockRate/maturityRateoptions to| null— their paired Postgres/RPC loaders return null by design and the builders already coalesce internally.Test plan
npx tsc --noEmitclean (repo-wide)npx eslint+prettier --checkclean on all touched filesnpx vitest runon the 5 directly-affected test files: 665/665 passing (incl. the full 8570-line data-api suite)