Skip to content

Commit cff9bad

Browse files
phasenullclaude
andauthored
backend setup --analytics basin|duckdb, --ingest, backend migrate (plans/35, 0.19.0) (#44)
* WIP: backend setup --analytics basin|duckdb, --ingest, backend migrate (plans/35) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * backend setup --analytics basin|duckdb keeps a Basin sink, --ingest, backend migrate; 0.19.0 (plans/35) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * backend setup: a kept ingest address that changed meanwhile is refused, not written unchecked Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 84e73d8 commit cff9bad

12 files changed

Lines changed: 1528 additions & 59 deletions

File tree

‎README.md‎

Lines changed: 67 additions & 10 deletions
Large diffs are not rendered by default.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typetorch/cli",
3-
"version": "0.18.1",
3+
"version": "0.19.0",
44
"description": "TypeTorch CLI: build, upload and hot-swap roblox-ts game code on live Roblox servers, roll back, and list deployments.",
55
"license": "MIT",
66
"repository": {

‎src/backend.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,12 @@ export interface BackendRequestOptions {
146146
adminToken: string;
147147
fetch?: typeof fetch;
148148
timeoutMs?: number;
149+
/** Ends the request early (Ctrl+C in a --watch loop), on top of the timeout. */
150+
signal?: AbortSignal;
149151
}
150152

151-
async function adminRequest(options: BackendRequestOptions, method: "GET" | "PUT" | "POST" | "PATCH" | "DELETE", path: string, body?: unknown, maxText = 4000): Promise<{ status: number; json?: Record<string, unknown>; text: string }> {
153+
/** One admin call (the admin token as a bearer, no redirects, the timeout). 401/403 and 3xx throw; other statuses return. */
154+
export async function adminRequest(options: BackendRequestOptions, method: "GET" | "PUT" | "POST" | "PATCH" | "DELETE", path: string, body?: unknown, maxText = 4000): Promise<{ status: number; json?: Record<string, unknown>; text: string }> {
152155
const base = options.url.replace(/\/+$/, "");
153156
const host = new URL(base).host;
154157
let response: Response;
@@ -159,9 +162,10 @@ async function adminRequest(options: BackendRequestOptions, method: "GET" | "PUT
159162
...(body !== undefined ? { body: JSON.stringify(body) } : {}),
160163
// A redirect would carry the admin token to wherever it points.
161164
redirect: "manual",
162-
signal: AbortSignal.timeout(options.timeoutMs ?? 10_000),
165+
signal: options.signal ? AbortSignal.any([options.signal, AbortSignal.timeout(options.timeoutMs ?? 10_000)]) : AbortSignal.timeout(options.timeoutMs ?? 10_000),
163166
});
164167
} catch (error) {
168+
if ((error as Error).name === "TimeoutError") throw new BackendError(`the backend at ${host} didn't answer within ${Math.round((options.timeoutMs ?? 10_000) / 1000)} s`);
165169
throw new BackendError(fleetNetworkHint(error as Error, host) ?? `the backend at ${host} didn't answer: ${(error as Error).message}`);
166170
}
167171
const text = (await response.text()).slice(0, maxText);

‎src/commands/backend.ts‎

Lines changed: 150 additions & 21 deletions
Large diffs are not rendered by default.

‎src/commands/doctor.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import { ADMIN_TOKEN_VAR, API_KEY_VARS, BACKEND_KEY_VAR, NOTIFY_KEY_VAR, CHILD_E
5151
import { gitInfo } from "../git.ts";
5252
import { bold, dim, emitJson, green, info, isJson, red, yellow } from "../log.ts";
5353
import { OpenCloud } from "../opencloud.ts";
54-
import { checkAnalyticsEndpoint, checkBackendEndpoint, checkFleetEndpoint, type EndpointOptions, type EndpointReport } from "../endpoints.ts";
54+
import { checkAnalyticsEndpoint, checkBackendEndpoint, checkFleetEndpoint, checkIngestEndpoint, type EndpointOptions, type EndpointReport, type Part } from "../endpoints.ts";
5555
import { backendCredentials, backendUrl, getAccessList, ownersOf, type BackendCredentials } from "../backend.ts";
5656
import { httpFleetClient } from "../fleet.ts";
5757
import { safeText } from "../httphints.ts";
@@ -63,7 +63,7 @@ import { hasZstd, isBun, runtimeName } from "../runtime.ts";
6363
import { rojoBinary } from "../build.ts";
6464
import { COMPILER_VAR, compilerVersion, GOBLOX_INSTALL, pluginsIgnoredByGoblox, resolveCompiler, type ResolveOptions } from "../compiler.ts";
6565
import { readTsconfig } from "../debug-macros.ts";
66-
import { describeFields, readSettings, verifySettingsRecord, type SettingsBody, type SettingsRead } from "../settings.ts";
66+
import { basinSinkOf, describeFields, readSettings, verifySettingsRecord, type SettingsBody, type SettingsRead } from "../settings.ts";
6767
import { DS_READ_SCOPE, DS_WRITE_SCOPES, HEADS_KEY, readSharedSeq, SEQ_DATASTORE } from "../seqstore.ts";
6868
import { defaultBranchHead, liveServerChecks, versionBeforeKernel } from "../livecheck.ts";
6969
import { branchCapWarning, HEADS_MAX_BRANCHES } from "../branches.ts";
@@ -155,8 +155,10 @@ export async function backendChecks(input: BackendCheckInput): Promise<Check[]>
155155
const { creds, body, configUrl } = input;
156156
const checks: Check[] = [];
157157
let adminOk = false;
158+
// A Basin analytics sink (plans/35 B): the backend serves only the fleet API, so a fleet-only one is right.
159+
const parts: Part[] | undefined = body && basinSinkOf(body) ? ["fleet"] : undefined;
158160
if (configUrl) {
159-
const report = await checkBackendEndpoint({ url: configUrl, key: creds.key?.value, admin: creds.admin?.value, requireKey: false, kernelRules: false, ...options });
161+
const report = await checkBackendEndpoint({ url: configUrl, key: creds.key?.value, admin: creds.admin?.value, requireKey: false, kernelRules: false, parts, ...options });
160162
for (const check of reportChecks(report, "backend")) {
161163
if (check.name === "backend key" && !creds.key) check.detail = `no ${BACKEND_KEY_VAR}${creds.refused ? ` (${creds.refused})` : ""}: the CLI posts no alerts (auto_rollback, server_stuck) and backend setup can't run`;
162164
if (check.name === "backend admin" && !creds.admin) {
@@ -187,13 +189,17 @@ export async function backendChecks(input: BackendCheckInput): Promise<Check[]>
187189
checks.push({ name: "record backend", status: "ok", detail: `the settings record's backend is typetorch.json backend.url with your ${BACKEND_KEY_VAR} (checked above)` });
188190
} else {
189191
// Its own address and key, with the kernel's rules (game servers use these); no admin token goes there.
190-
const report = await checkBackendEndpoint({ url: record.url, key: record.key, requireAdmin: false, kernelRules: true, ...options });
192+
const report = await checkBackendEndpoint({ url: record.url, key: record.key, requireAdmin: false, kernelRules: true, parts, ...options });
191193
checks.push(...reportChecks(report, "record backend").filter((check) => check.name !== "record backend admin"));
192194
if (configUrl && !sameAddress) {
193195
checks.push({ name: "record backend url", status: "warn", detail: `typetorch.json backend.url (${hostOf(configUrl)}) differs from the settings record's (${hostOf(record.url)}): game servers use the record's, the CLI the file's. Run typetorch backend setup --url <the right one>` });
194196
}
195197
if (creds.key && !sameKey) checks.push({ name: "record backend key", status: "warn", detail: `the settings record's backend key differs from your ${BACKEND_KEY_VAR}: run typetorch backend setup` });
196198
}
199+
// Separate ingest servers (plans/35 C): game servers post events there with the record's key.
200+
if (record.ingest) checks.push(...reportChecks(await checkIngestEndpoint({ url: record.ingest, key: record.key, ...options }), "record ingest"));
201+
// A Basin sink: its streams answer and the token isn't refused.
202+
if (parts) checks.push(...reportChecks(await checkAnalyticsEndpoint(body.analytics, options), "record analytics"));
197203
if (!body.fleet || body.fleet.url !== record.url || body.fleet.token !== record.key) {
198204
checks.push({ name: "record fleet", status: "warn", detail: "the record's fleet section (what kernels before 0.4 read) doesn't match its backend section: run typetorch backend setup" });
199205
}

0 commit comments

Comments
 (0)