@oh-my-pi/pi-utils 15.10.7 → 15.10.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types/index.d.ts +0 -1
- package/package.json +2 -2
- package/src/index.ts +0 -1
- package/dist/types/hook-fetch.d.ts +0 -16
- package/src/hook-fetch.ts +0 -30
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@oh-my-pi/pi-utils",
|
|
4
|
-
"version": "15.10.
|
|
4
|
+
"version": "15.10.9",
|
|
5
5
|
"description": "Shared utilities for pi packages",
|
|
6
6
|
"homepage": "https://omp.sh",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"fmt": "biome format --write ."
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@oh-my-pi/pi-natives": "15.10.
|
|
34
|
+
"@oh-my-pi/pi-natives": "15.10.9",
|
|
35
35
|
"beautiful-mermaid": "^1.1.3",
|
|
36
36
|
"handlebars": "^4.7.9",
|
|
37
37
|
"winston": "^3.19.0",
|
package/src/index.ts
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Intercept `globalThis.fetch` with a middleware-style handler.
|
|
3
|
-
*
|
|
4
|
-
* Returns a `Disposable` so callers can use `using` for automatic cleanup:
|
|
5
|
-
*
|
|
6
|
-
* ```ts
|
|
7
|
-
* using _hook = hookFetch((input, init, next) => {
|
|
8
|
-
* if (shouldIntercept(input)) {
|
|
9
|
-
* return new Response("mocked");
|
|
10
|
-
* }
|
|
11
|
-
* return next(input, init);
|
|
12
|
-
* });
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export type FetchHandler = (input: string | URL | Request, init: RequestInit | undefined, next: typeof fetch) => Response | Promise<Response>;
|
|
16
|
-
export declare function hookFetch(handler: FetchHandler): Disposable;
|
package/src/hook-fetch.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Intercept `globalThis.fetch` with a middleware-style handler.
|
|
3
|
-
*
|
|
4
|
-
* Returns a `Disposable` so callers can use `using` for automatic cleanup:
|
|
5
|
-
*
|
|
6
|
-
* ```ts
|
|
7
|
-
* using _hook = hookFetch((input, init, next) => {
|
|
8
|
-
* if (shouldIntercept(input)) {
|
|
9
|
-
* return new Response("mocked");
|
|
10
|
-
* }
|
|
11
|
-
* return next(input, init);
|
|
12
|
-
* });
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export type FetchHandler = (
|
|
16
|
-
input: string | URL | Request,
|
|
17
|
-
init: RequestInit | undefined,
|
|
18
|
-
next: typeof fetch,
|
|
19
|
-
) => Response | Promise<Response>;
|
|
20
|
-
|
|
21
|
-
export function hookFetch(handler: FetchHandler): Disposable {
|
|
22
|
-
const original = globalThis.fetch;
|
|
23
|
-
globalThis.fetch = ((input: string | URL | Request, init?: RequestInit) =>
|
|
24
|
-
handler(input, init, original)) as typeof fetch;
|
|
25
|
-
return {
|
|
26
|
-
[Symbol.dispose]() {
|
|
27
|
-
globalThis.fetch = original;
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
}
|