fix: resolve biome lint issues (format, imports, parameter property, complexity)
This commit is contained in:
@@ -12,8 +12,8 @@ import {
|
||||
listWorkflowsViaDaemon,
|
||||
triggerWorkflowViaDaemon,
|
||||
} from "../daemon-client.js";
|
||||
import { loadDaemonModule } from "../workspace-daemon.js";
|
||||
import { formatRowsAsAlignedTable } from "../sense-sqlite.js";
|
||||
import { loadDaemonModule } from "../workspace-daemon.js";
|
||||
import { getNerveRoot, getSocketPath, isRunning } from "../workspace.js";
|
||||
|
||||
export const DEFAULT_PAGE_SIZE = 20;
|
||||
|
||||
@@ -191,13 +191,14 @@ function sendAndReceive<T>(
|
||||
|
||||
/** Unix-socket implementation of {@link DaemonTransport} (local daemon). */
|
||||
export class UnixTransport implements DaemonTransport {
|
||||
constructor(private readonly socketPath: string) {}
|
||||
readonly socketPath: string;
|
||||
constructor(socketPath: string) {
|
||||
this.socketPath = socketPath;
|
||||
}
|
||||
|
||||
async health(): Promise<HealthInfo> {
|
||||
const parsed = await sendAndReceive(
|
||||
this.socketPath,
|
||||
{ type: "health" },
|
||||
(line) => parseHealthResponse(line),
|
||||
const parsed = await sendAndReceive(this.socketPath, { type: "health" }, (line) =>
|
||||
parseHealthResponse(line),
|
||||
);
|
||||
if (parsed === null) {
|
||||
throw new Error("Unexpected daemon response for health");
|
||||
@@ -206,7 +207,11 @@ export class UnixTransport implements DaemonTransport {
|
||||
}
|
||||
|
||||
async listSenses(): Promise<SenseInfo[]> {
|
||||
const r = await sendAndReceive(this.socketPath, { type: "list-senses" }, parseListSensesResponse);
|
||||
const r = await sendAndReceive(
|
||||
this.socketPath,
|
||||
{ type: "list-senses" },
|
||||
parseListSensesResponse,
|
||||
);
|
||||
if (!r.ok) {
|
||||
throw new Error(r.error);
|
||||
}
|
||||
@@ -226,7 +231,11 @@ export class UnixTransport implements DaemonTransport {
|
||||
}
|
||||
|
||||
async triggerSense(name: string): Promise<DaemonTransportTriggerResult> {
|
||||
return sendAndReceive(this.socketPath, { type: "trigger-sense", sense: name }, parseDaemonResponse);
|
||||
return sendAndReceive(
|
||||
this.socketPath,
|
||||
{ type: "trigger-sense", sense: name },
|
||||
parseDaemonResponse,
|
||||
);
|
||||
}
|
||||
|
||||
async triggerWorkflow(name: string): Promise<DaemonTransportTriggerResult> {
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { parse } from "yaml";
|
||||
|
||||
import type { NerveApiConfig, NerveConfig, ReflexConfig, SenseConfig, WorkflowConfig } from "./config.js";
|
||||
import type {
|
||||
NerveApiConfig,
|
||||
NerveConfig,
|
||||
ReflexConfig,
|
||||
SenseConfig,
|
||||
WorkflowConfig,
|
||||
} from "./config.js";
|
||||
import { isPlainRecord } from "./is-plain-record.js";
|
||||
import type { Result } from "./result.js";
|
||||
import { err, ok } from "./result.js";
|
||||
@@ -256,7 +262,12 @@ function parseApiConfig(obj: Record<string, unknown>): Result<NerveApiConfig> {
|
||||
if (api.port === undefined || api.port === null) {
|
||||
return ok({ port: null });
|
||||
}
|
||||
if (typeof api.port !== "number" || !Number.isInteger(api.port) || api.port < 1 || api.port > 65_535) {
|
||||
if (
|
||||
typeof api.port !== "number" ||
|
||||
!Number.isInteger(api.port) ||
|
||||
api.port < 1 ||
|
||||
api.port > 65_535
|
||||
) {
|
||||
return err(new Error("api.port: must be an integer between 1 and 65535 if provided"));
|
||||
}
|
||||
return ok({ port: api.port });
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Uses only `node:http`; shares handler logic with Unix IPC via {@link createDaemonHandlers}.
|
||||
*/
|
||||
|
||||
import { createServer, type IncomingMessage, type Server, type ServerResponse } from "node:http";
|
||||
import { type IncomingMessage, type Server, type ServerResponse, createServer } from "node:http";
|
||||
|
||||
import { isPlainRecord } from "@uncaged/nerve-core";
|
||||
|
||||
@@ -55,6 +55,7 @@ function parseJsonBody(raw: string): unknown | null {
|
||||
}
|
||||
|
||||
export function createHttpApiServer(port: number, handlers: DaemonHandlerBundle): HttpApiServer {
|
||||
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: HTTP router dispatches multiple routes in one handler
|
||||
const server: Server = createServer(async (req, res) => {
|
||||
if (req.method === "OPTIONS") {
|
||||
setJsonHeaders(res, 204);
|
||||
@@ -85,7 +86,7 @@ export function createHttpApiServer(port: number, handlers: DaemonHandlerBundle)
|
||||
const raw = await readRequestBody(req);
|
||||
const body = parseJsonBody(raw);
|
||||
if (!isPlainRecord(body) || typeof body.name !== "string" || body.name.length === 0) {
|
||||
sendJson(res, 400, { ok: false, error: "Expected JSON body: { \"name\": string }" });
|
||||
sendJson(res, 400, { ok: false, error: 'Expected JSON body: { "name": string }' });
|
||||
return;
|
||||
}
|
||||
const result = handlers.triggerSense(body.name);
|
||||
@@ -97,7 +98,7 @@ export function createHttpApiServer(port: number, handlers: DaemonHandlerBundle)
|
||||
const raw = await readRequestBody(req);
|
||||
const body = parseJsonBody(raw);
|
||||
if (!isPlainRecord(body) || typeof body.name !== "string" || body.name.length === 0) {
|
||||
sendJson(res, 400, { ok: false, error: "Expected JSON body: { \"name\": string }" });
|
||||
sendJson(res, 400, { ok: false, error: 'Expected JSON body: { "name": string }' });
|
||||
return;
|
||||
}
|
||||
const result = handlers.triggerWorkflow(body.name, {
|
||||
@@ -121,7 +122,7 @@ export function createHttpApiServer(port: number, handlers: DaemonHandlerBundle)
|
||||
) {
|
||||
sendJson(res, 400, {
|
||||
ok: false,
|
||||
error: "Expected JSON body: { \"name\": string, \"threadId\": string }",
|
||||
error: 'Expected JSON body: { "name": string, "threadId": string }',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ import type { LogStore } from "@uncaged/nerve-store";
|
||||
import { createDaemonHandlers } from "./daemon-handlers.js";
|
||||
import { createDaemonIpcServer } from "./daemon-ipc.js";
|
||||
import type { DaemonIpcServer } from "./daemon-ipc.js";
|
||||
import { createHttpApiServer } from "./http-api.js";
|
||||
import type { HttpApiServer } from "./http-api.js";
|
||||
import { createFileWatcher } from "./file-watcher.js";
|
||||
import type { FileWatcher } from "./file-watcher.js";
|
||||
import { createHttpApiServer } from "./http-api.js";
|
||||
import type { HttpApiServer } from "./http-api.js";
|
||||
import { parseWorkerMessage } from "./ipc.js";
|
||||
import { createKernelFileWatchHandlers } from "./kernel-file-watch.js";
|
||||
import {
|
||||
@@ -85,7 +85,12 @@ function readDaemonPackageVersion(): string {
|
||||
const pkgPath = join(dirname(here), "..", "package.json");
|
||||
const raw = readFileSync(pkgPath, "utf8");
|
||||
const o: unknown = JSON.parse(raw);
|
||||
if (typeof o === "object" && o !== null && "version" in o && typeof (o as { version: unknown }).version === "string") {
|
||||
if (
|
||||
typeof o === "object" &&
|
||||
o !== null &&
|
||||
"version" in o &&
|
||||
typeof (o as { version: unknown }).version === "string"
|
||||
) {
|
||||
return (o as { version: string }).version;
|
||||
}
|
||||
return "0.0.0";
|
||||
|
||||
@@ -11,7 +11,12 @@ import type { ChildProcess } from "node:child_process";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import type { NerveConfig, WorkflowConfig, WorkflowMessage, WorkflowStatus } from "@uncaged/nerve-core";
|
||||
import type {
|
||||
NerveConfig,
|
||||
WorkflowConfig,
|
||||
WorkflowMessage,
|
||||
WorkflowStatus,
|
||||
} from "@uncaged/nerve-core";
|
||||
import { START, isPlainRecord } from "@uncaged/nerve-core";
|
||||
|
||||
import type { LogStore, WorkflowRunStatus } from "@uncaged/nerve-store";
|
||||
|
||||
Reference in New Issue
Block a user