Skip to content
This repository was archived by the owner on May 17, 2025. It is now read-only.

Commit fdea945

Browse files
committed
Run chomp prettier on codebase
1 parent 7814cac commit fdea945

File tree

18 files changed

+323
-220
lines changed

18 files changed

+323
-220
lines changed

src/common/fetch-common.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@ export interface WrappedResponse {
99
export type FetchFn = (
1010
url: URL | string,
1111
...args: any[]
12-
) => Promise<WrappedResponse | globalThis.Response>
12+
) => Promise<WrappedResponse | globalThis.Response>;
1313

1414
export type WrappedFetch = ((
1515
url: URL | string,
1616
...args: any[]
17-
) => Promise<WrappedResponse | globalThis.Response>) & {
18-
arrayBuffer: (url: URL | string, ...args: any[]) => Promise<ArrayBuffer | null>,
19-
text: (url: URL | string, ...args: any[]) => Promise<string | null>
17+
) => Promise<WrappedResponse | globalThis.Response>) & {
18+
arrayBuffer: (
19+
url: URL | string,
20+
...args: any[]
21+
) => Promise<ArrayBuffer | null>;
22+
text: (url: URL | string, ...args: any[]) => Promise<string | null>;
2023
};
2124

22-
let retryCount = 5, poolSize = 100;
25+
let retryCount = 5,
26+
poolSize = 100;
2327

2428
export function setRetryCount(count: number) {
2529
retryCount = count;
@@ -58,8 +62,7 @@ export function wrappedFetch(fetch: FetchFn): WrappedFetch {
5862
try {
5963
var res = await fetch(url, ...args);
6064
} catch (e) {
61-
if (retries++ >= retryCount)
62-
throw e;
65+
if (retries++ >= retryCount) throw e;
6366
continue;
6467
}
6568
switch (res.status) {
@@ -75,12 +78,12 @@ export function wrappedFetch(fetch: FetchFn): WrappedFetch {
7578
try {
7679
return await res.arrayBuffer();
7780
} catch (e) {
78-
if (retries++ >= retryCount &&
79-
e.code === "ERR_SOCKET_TIMEOUT" ||
80-
e.code === "ETIMEOUT" ||
81-
e.code === "ECONNRESET" ||
82-
e.code === 'FETCH_ERROR') {
83-
81+
if (
82+
(retries++ >= retryCount && e.code === "ERR_SOCKET_TIMEOUT") ||
83+
e.code === "ETIMEOUT" ||
84+
e.code === "ECONNRESET" ||
85+
e.code === "FETCH_ERROR"
86+
) {
8487
}
8588
}
8689
}
@@ -90,8 +93,7 @@ export function wrappedFetch(fetch: FetchFn): WrappedFetch {
9093
};
9194
wrappedFetch.text = async function (url, ...args) {
9295
const arrayBuffer = await this.arrayBuffer(url, ...args);
93-
if (!arrayBuffer)
94-
return null;
96+
if (!arrayBuffer) return null;
9597
return new TextDecoder().decode(arrayBuffer);
9698
};
9799
return wrappedFetch;
@@ -100,12 +102,10 @@ export function wrappedFetch(fetch: FetchFn): WrappedFetch {
100102
// restrict in-flight fetches to a pool of 100
101103
let p = [];
102104
let c = 0;
103-
function pushFetchPool () {
104-
if (++c > poolSize)
105-
return new Promise(r => p.push(r));
105+
function pushFetchPool() {
106+
if (++c > poolSize) return new Promise((r) => p.push(r));
106107
}
107-
function popFetchPool () {
108+
function popFetchPool() {
108109
c--;
109-
if (p.length)
110-
p.shift()();
110+
if (p.length) p.shift()();
111111
}

src/common/fetch.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-ignore
2-
import { fetch as fetchImpl, clearCache } from '#fetch';
2+
import { fetch as fetchImpl, clearCache } from "#fetch";
33

44
export interface WrappedResponse {
55
url: string;
@@ -15,17 +15,21 @@ export interface WrappedResponse {
1515
export type FetchFn = (
1616
url: URL | string,
1717
...args: any[]
18-
) => Promise<WrappedResponse | globalThis.Response>
18+
) => Promise<WrappedResponse | globalThis.Response>;
1919

2020
export type WrappedFetch = ((
2121
url: URL | string,
2222
...args: any[]
23-
) => Promise<WrappedResponse | globalThis.Response>) & {
24-
arrayBuffer: (url: URL | string, ...args: any[]) => Promise<ArrayBuffer | null>,
25-
text: (url: URL | string, ...args: any[]) => Promise<string | null>
23+
) => Promise<WrappedResponse | globalThis.Response>) & {
24+
arrayBuffer: (
25+
url: URL | string,
26+
...args: any[]
27+
) => Promise<ArrayBuffer | null>;
28+
text: (url: URL | string, ...args: any[]) => Promise<string | null>;
2629
};
2730

28-
let retryCount = 5, poolSize = 100;
31+
let retryCount = 5,
32+
poolSize = 100;
2933

3034
export function setRetryCount(count: number) {
3135
retryCount = count;
@@ -44,7 +48,7 @@ export function setFetch(fetch: typeof globalThis.fetch | WrappedFetch) {
4448
_fetch = fetch as WrappedFetch;
4549
}
4650

47-
export { clearCache, _fetch as fetch }
51+
export { clearCache, _fetch as fetch };
4852

4953
/**
5054
* Wraps a fetch request with pooling, and retry logic on exceptions (emfile / network errors).
@@ -75,8 +79,7 @@ function wrappedFetch(fetch: FetchFn): WrappedFetch {
7579
try {
7680
var res = await fetch(url, ...args);
7781
} catch (e) {
78-
if (retries++ >= retryCount)
79-
throw e;
82+
if (retries++ >= retryCount) throw e;
8083
continue;
8184
}
8285
switch (res.status) {
@@ -92,12 +95,12 @@ function wrappedFetch(fetch: FetchFn): WrappedFetch {
9295
try {
9396
return await res.arrayBuffer();
9497
} catch (e) {
95-
if (retries++ >= retryCount &&
96-
e.code === "ERR_SOCKET_TIMEOUT" ||
97-
e.code === "ETIMEOUT" ||
98-
e.code === "ECONNRESET" ||
99-
e.code === 'FETCH_ERROR') {
100-
98+
if (
99+
(retries++ >= retryCount && e.code === "ERR_SOCKET_TIMEOUT") ||
100+
e.code === "ETIMEOUT" ||
101+
e.code === "ECONNRESET" ||
102+
e.code === "FETCH_ERROR"
103+
) {
101104
}
102105
}
103106
}
@@ -107,8 +110,7 @@ function wrappedFetch(fetch: FetchFn): WrappedFetch {
107110
};
108111
wrappedFetch.text = async function (url, ...args) {
109112
const arrayBuffer = await this.arrayBuffer(url, ...args);
110-
if (!arrayBuffer)
111-
return null;
113+
if (!arrayBuffer) return null;
112114
return new TextDecoder().decode(arrayBuffer);
113115
};
114116
return wrappedFetch;
@@ -117,12 +119,10 @@ function wrappedFetch(fetch: FetchFn): WrappedFetch {
117119
// restrict in-flight fetches to a pool of 100
118120
let p = [];
119121
let c = 0;
120-
function pushFetchPool () {
121-
if (++c > poolSize)
122-
return new Promise(r => p.push(r));
122+
function pushFetchPool() {
123+
if (++c > poolSize) return new Promise((r) => p.push(r));
123124
}
124-
function popFetchPool () {
125+
function popFetchPool() {
125126
c--;
126-
if (p.length)
127-
p.shift()();
127+
if (p.length) p.shift()();
128128
}

src/common/integrity.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
let _nodeCrypto;
22

3-
export async function getIntegrityNodeLegacy(buf: Uint8Array | string): Promise<`sha384-${string}`> {
4-
const hash = (_nodeCrypto || (_nodeCrypto = (await (0, eval)('import("node:crypto")')))).createHash("sha384");
3+
export async function getIntegrityNodeLegacy(
4+
buf: Uint8Array | string
5+
): Promise<`sha384-${string}`> {
6+
const hash = (
7+
_nodeCrypto || (_nodeCrypto = await (0, eval)('import("node:crypto")'))
8+
).createHash("sha384");
59
hash.update(buf);
610
return `sha384-${hash.digest("base64")}`;
711
}
812

9-
export let getIntegrity = async function getIntegrity(buf: Uint8Array | string): Promise<`sha384-${string}`> {
13+
export let getIntegrity = async function getIntegrity(
14+
buf: Uint8Array | string
15+
): Promise<`sha384-${string}`> {
1016
const data = typeof buf === "string" ? new TextEncoder().encode(buf) : buf;
1117
const hashBuffer = await crypto.subtle.digest("SHA-384", data);
1218
const hashArray = Array.from(new Uint8Array(hashBuffer));
1319
const hashBase64 = btoa(String.fromCharCode(...hashArray));
1420
return `sha384-${hashBase64}`;
15-
}
21+
};
1622

17-
if (typeof crypto === 'undefined')
18-
getIntegrity = getIntegrityNodeLegacy;
23+
if (typeof crypto === "undefined") getIntegrity = getIntegrityNodeLegacy;

0 commit comments

Comments
 (0)