Execute oxfmt (#1166)

Ran
pnpm oxfmt .

This should get the web repo aligned so that we can better enforce oxfmt going forward.
This commit is contained in:
Austin
2026-06-16 20:30:08 -04:00
committed by GitHub
parent c5690d1edb
commit d2cb51d489
378 changed files with 5548 additions and 1974 deletions
+28 -28
View File
@@ -2,43 +2,20 @@
"name": "@meshtastic/transport-http",
"version": "1.0.0",
"description": "A transport layer for Meshtastic applications using HTTP.",
"exports": {
".": "./mod.ts"
},
"type": "module",
"license": "GPL-3.0-only",
"files": [
"package.json",
"README.md",
"LICENSE",
"dist"
],
"type": "module",
"main": "./dist/mod.js",
"module": "./dist/mod.js",
"types": "./dist/mod.d.ts",
"license": "GPL-3.0-only",
"tsdown": {
"entry": "mod.ts",
"target": "esnext",
"dts": true,
"format": [
"esm"
],
"splitting": false,
"sourcemap": false,
"minify": false,
"treeshake": true,
"report": false,
"clean": true
"exports": {
".": "./mod.ts"
},
"jsrInclude": [
"mod.ts",
"src",
"README.md",
"LICENSE"
],
"jsrExclude": [
"src/**/*.test.ts"
],
"scripts": {
"preinstall": "npx only-allow pnpm",
"prepack": "cp ../../LICENSE ./LICENSE",
@@ -50,5 +27,28 @@
},
"dependencies": {
"@meshtastic/sdk": "workspace:*"
}
},
"tsdown": {
"clean": true,
"dts": true,
"entry": "mod.ts",
"format": [
"esm"
],
"minify": false,
"report": false,
"sourcemap": false,
"splitting": false,
"target": "esnext",
"treeshake": true
},
"jsrExclude": [
"src/**/*.test.ts"
],
"jsrInclude": [
"mod.ts",
"src",
"README.md",
"LICENSE"
]
}
+24 -10
View File
@@ -1,14 +1,26 @@
import { afterEach, beforeEach, describe, expect, it, type MockInstance, vi } from "vitest";
import {
afterEach,
beforeEach,
describe,
expect,
it,
type MockInstance,
vi,
} from "vitest";
import { runTransportContract } from "../../../tests/utils/transportContract.ts";
import { TransportHTTP } from "./transport.ts";
let abortTimeoutSpy: MockInstance | undefined;
beforeEach(() => {
abortTimeoutSpy = vi
.spyOn(globalThis.AbortSignal as unknown as { timeout(ms: number): AbortSignal }, "timeout")
.spyOn(
globalThis.AbortSignal as unknown as { timeout(ms: number): AbortSignal },
"timeout",
)
.mockImplementation((ms: number) => {
const ctrl = new AbortController();
const abort = () => ctrl.abort(new DOMException("Timeout reached", "TimeoutError"));
const abort = () =>
ctrl.abort(new DOMException("Timeout reached", "TimeoutError"));
// Uses setTimeout so vi.useFakeTimers() can fast-forward it
setTimeout(abort, ms);
return ctrl.signal;
@@ -116,21 +128,23 @@ describe("TransportHTTP (contract)", () => {
vi.unstubAllGlobals();
},
create: async () => {
(globalThis as unknown as { __http: ReturnType<typeof stubFetch> }).__http = stubFetch();
(
globalThis as unknown as { __http: ReturnType<typeof stubFetch> }
).__http = stubFetch();
const transport = await TransportHTTP.create("127.0.0.1:80", false);
await tickNextTimer();
return transport;
},
pushIncoming: async (bytes) => {
(globalThis as unknown as { __http: ReturnType<typeof stubFetch> }).__http.pushIncoming(
bytes,
);
(
globalThis as unknown as { __http: ReturnType<typeof stubFetch> }
).__http.pushIncoming(bytes);
await tickNextTimer();
},
assertLastWritten: (bytes) => {
(globalThis as unknown as { __http: ReturnType<typeof stubFetch> }).__http.assertLastWritten(
bytes,
);
(
globalThis as unknown as { __http: ReturnType<typeof stubFetch> }
).__http.assertLastWritten(bytes);
},
triggerDisconnect: async () => {
(
+24 -7
View File
@@ -1,4 +1,8 @@
import { DeviceStatusEnum, type DeviceOutput, type Transport } from "@meshtastic/sdk";
import {
DeviceStatusEnum,
type DeviceOutput,
type Transport,
} from "@meshtastic/sdk";
const FETCH_INTERVAL_MS = 3000;
const READ_TIMEOUT_MS = 7000;
@@ -43,7 +47,10 @@ export class TransportHTTP implements Transport {
* @param address Hostname or IP address (with optional port).
* @param tls Use HTTPS if true, HTTP otherwise.
*/
public static async create(address: string, tls?: boolean): Promise<TransportHTTP> {
public static async create(
address: string,
tls?: boolean,
): Promise<TransportHTTP> {
const connectionUrl = `${tls ? "https" : "http"}://${address}`;
await fetch(`${connectionUrl}/api/v1/toradio`, {
method: "OPTIONS",
@@ -86,7 +93,10 @@ export class TransportHTTP implements Transport {
// Start polling immediately
void this.safePoll();
this.interval = setInterval(() => void this.safePoll(), this.fetchInterval);
this.interval = setInterval(
() => void this.safePoll(),
this.fetchInterval,
);
},
cancel: () => {
if (this.interval) {
@@ -105,7 +115,10 @@ export class TransportHTTP implements Transport {
const inflight = new AbortController();
this.inflightReadController = inflight;
const signal = AbortSignal.any([inflight.signal, AbortSignal.timeout(READ_TIMEOUT_MS)]);
const signal = AbortSignal.any([
inflight.signal,
AbortSignal.timeout(READ_TIMEOUT_MS),
]);
try {
const response = await fetch(
@@ -117,7 +130,9 @@ export class TransportHTTP implements Transport {
},
);
if (!response.ok) {
throw new Error(`fromradio ${response.status} ${response.statusText}`);
throw new Error(
`fromradio ${response.status} ${response.statusText}`,
);
}
this.emitStatus(DeviceStatusEnum.DeviceConnected);
@@ -205,8 +220,10 @@ export class TransportHTTP implements Transport {
private isTimeoutOrAbort(err: unknown): boolean {
return (
(err instanceof DOMException && (err.name === "AbortError" || err.name === "TimeoutError")) ||
(err instanceof Error && (err.name === "AbortError" || err.name === "TimeoutError"))
(err instanceof DOMException &&
(err.name === "AbortError" || err.name === "TimeoutError")) ||
(err instanceof Error &&
(err.name === "AbortError" || err.name === "TimeoutError"))
);
}