Skip to content

Commit 16d36ce

Browse files
committed
Unify fetch inputs & add format script
1 parent 82be00e commit 16d36ce

12 files changed

Lines changed: 51 additions & 115 deletions

.prettierrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"tabWidth": 2,
3+
"useTabs": false,
4+
"singleQuote": true,
5+
"trailingComma": "none",
6+
"endOfLine": "lf",
7+
"arrowParens": "always",
8+
"printWidth": 120
9+
}

bun.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openworkers/workers-types",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"description": "TypeScript types for the OpenWorkers runtime",
55
"license": "MIT",
66
"repository": {
@@ -18,12 +18,18 @@
1818
"index.d.ts",
1919
"types/*.d.ts"
2020
],
21+
"scripts": {
22+
"format": "prettier --write ."
23+
},
2124
"peerDependencies": {
2225
"typescript": "^5"
2326
},
2427
"publishConfig": {
2528
"access": "public",
2629
"registry": "https://registry.npmjs.org/",
2730
"provenance": true
31+
},
32+
"devDependencies": {
33+
"prettier": "^3.8.1"
2834
}
2935
}

types/bindings.d.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ declare global {
1818
interface BindingAssets {
1919
/**
2020
* Fetches a static asset from the bundle.
21-
* @param path The asset path (e.g., "/index.html").
22-
* @param options Optional request options.
21+
* @param input The asset path, URL, or request.
22+
* @param init Optional request options.
2323
*/
24-
fetch(path: string, options?: RequestInit): Promise<Response>;
24+
fetch(input: Request | string | URL, init?: RequestInit): Promise<Response>;
2525
}
2626

2727
/**
@@ -124,13 +124,7 @@ declare global {
124124
* Supports strings, numbers, booleans, null, arrays, and objects.
125125
* Note: Binary data (Uint8Array, ArrayBuffer) is not supported.
126126
*/
127-
type JsonValue =
128-
| string
129-
| number
130-
| boolean
131-
| null
132-
| JsonValue[]
133-
| { [key: string]: JsonValue };
127+
type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };
134128

135129
/**
136130
* Key-Value storage binding for fast, low-latency data access.
@@ -217,9 +211,9 @@ declare global {
217211
interface BindingWorker {
218212
/**
219213
* Calls another worker with a request.
220-
* @param request The request to send.
221-
* @param init Optional request options (when using string URL).
214+
* @param input The request, URL, or string URL to send.
215+
* @param init Optional request options.
222216
*/
223-
fetch(request: Request | string, init?: RequestInit): Promise<Response>;
217+
fetch(input: Request | string | URL, init?: RequestInit): Promise<Response>;
224218
}
225219
}

types/blob.d.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ declare global {
1919
* @param blobParts Array of data to include in the blob.
2020
* @param options Optional settings like MIME type.
2121
*/
22-
constructor(
23-
blobParts?: (ArrayBuffer | Uint8Array | Blob | string)[],
24-
options?: { type?: string }
25-
);
22+
constructor(blobParts?: (ArrayBuffer | Uint8Array | Blob | string)[], options?: { type?: string });
2623

2724
/** The size of the blob in bytes. */
2825
readonly size: number;
@@ -104,9 +101,7 @@ declare global {
104101
set(name: string, value: string | Blob, filename?: string): void;
105102

106103
/** Executes a callback for each key/value pair. */
107-
forEach(
108-
callback: (value: string | File, key: string, parent: FormData) => void
109-
): void;
104+
forEach(callback: (value: string | File, key: string, parent: FormData) => void): void;
110105

111106
/** Returns an iterator of all key/value pairs. */
112107
entries(): IterableIterator<[string, string | File]>;

types/crypto.d.ts

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,31 @@ declare global {
1818
* const hash = await crypto.subtle.digest('SHA-256', new TextEncoder().encode('hello'));
1919
* ```
2020
*/
21-
digest(
22-
algorithm: string | { name: string },
23-
data: BufferSource
24-
): Promise<ArrayBuffer>;
21+
digest(algorithm: string | { name: string }, data: BufferSource): Promise<ArrayBuffer>;
2522

2623
/**
2724
* Encrypts data using a key.
2825
* @param algorithm The encryption algorithm and parameters.
2926
* @param key The encryption key.
3027
* @param data The data to encrypt.
3128
*/
32-
encrypt(
33-
algorithm: unknown,
34-
key: CryptoKey,
35-
data: BufferSource
36-
): Promise<ArrayBuffer>;
29+
encrypt(algorithm: unknown, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>;
3730

3831
/**
3932
* Decrypts data using a key.
4033
* @param algorithm The encryption algorithm and parameters.
4134
* @param key The decryption key.
4235
* @param data The data to decrypt.
4336
*/
44-
decrypt(
45-
algorithm: unknown,
46-
key: CryptoKey,
47-
data: BufferSource
48-
): Promise<ArrayBuffer>;
37+
decrypt(algorithm: unknown, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>;
4938

5039
/**
5140
* Signs data using a private key.
5241
* @param algorithm The signing algorithm and parameters.
5342
* @param key The private key.
5443
* @param data The data to sign.
5544
*/
56-
sign(
57-
algorithm: unknown,
58-
key: CryptoKey,
59-
data: BufferSource
60-
): Promise<ArrayBuffer>;
45+
sign(algorithm: unknown, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>;
6146

6247
/**
6348
* Verifies a signature using a public key.
@@ -67,24 +52,15 @@ declare global {
6752
* @param data The original data.
6853
* @returns True if the signature is valid.
6954
*/
70-
verify(
71-
algorithm: unknown,
72-
key: CryptoKey,
73-
signature: BufferSource,
74-
data: BufferSource
75-
): Promise<boolean>;
55+
verify(algorithm: unknown, key: CryptoKey, signature: BufferSource, data: BufferSource): Promise<boolean>;
7656

7757
/**
7858
* Generates a new cryptographic key or key pair.
7959
* @param algorithm The algorithm and parameters.
8060
* @param extractable Whether the key can be exported.
8161
* @param keyUsages The allowed operations for this key.
8262
*/
83-
generateKey(
84-
algorithm: unknown,
85-
extractable: boolean,
86-
keyUsages: string[]
87-
): Promise<CryptoKey | CryptoKeyPair>;
63+
generateKey(algorithm: unknown, extractable: boolean, keyUsages: string[]): Promise<CryptoKey | CryptoKeyPair>;
8864

8965
/**
9066
* Imports a key from external format.
@@ -107,22 +83,15 @@ declare global {
10783
* @param format The key format ("raw", "pkcs8", "spki", "jwk").
10884
* @param key The key to export.
10985
*/
110-
exportKey(
111-
format: string,
112-
key: CryptoKey
113-
): Promise<ArrayBuffer | JsonWebKey>;
86+
exportKey(format: string, key: CryptoKey): Promise<ArrayBuffer | JsonWebKey>;
11487

11588
/**
11689
* Derives bits from a base key.
11790
* @param algorithm The derivation algorithm and parameters.
11891
* @param baseKey The base key.
11992
* @param length The number of bits to derive.
12093
*/
121-
deriveBits(
122-
algorithm: unknown,
123-
baseKey: CryptoKey,
124-
length: number
125-
): Promise<ArrayBuffer>;
94+
deriveBits(algorithm: unknown, baseKey: CryptoKey, length: number): Promise<ArrayBuffer>;
12695

12796
/**
12897
* Derives a new key from a base key.

types/encoding.d.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ declare global {
3636
* @param destination The buffer to write into.
3737
* @returns An object with `read` (chars read) and `written` (bytes written).
3838
*/
39-
encodeInto(
40-
source: string,
41-
destination: Uint8Array
42-
): { read: number; written: number };
39+
encodeInto(source: string, destination: Uint8Array): { read: number; written: number };
4340
}
4441

4542
/**

types/fetch.d.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@ export {};
55
/**
66
* Valid types for a request or response body.
77
*/
8-
type BodyInit =
9-
| ReadableStream
10-
| Blob
11-
| ArrayBuffer
12-
| Uint8Array
13-
| FormData
14-
| URLSearchParams
15-
| string;
8+
type BodyInit = ReadableStream | Blob | ArrayBuffer | Uint8Array | FormData | URLSearchParams | string;
169

1710
/**
1811
* Valid types for initializing Headers.
@@ -82,7 +75,7 @@ declare global {
8275
body?: BodyInit | null;
8376

8477
/** How to handle redirects: "follow", "error", or "manual". */
85-
redirect?: "follow" | "error" | "manual";
78+
redirect?: 'follow' | 'error' | 'manual';
8679

8780
/** An AbortSignal to cancel the request. */
8881
signal?: AbortSignal;
@@ -246,8 +239,5 @@ declare global {
246239
* const data = await response.json();
247240
* ```
248241
*/
249-
function fetch(
250-
input: Request | string | URL,
251-
init?: RequestInit
252-
): Promise<Response>;
242+
function fetch(input: Request | string | URL, init?: RequestInit): Promise<Response>;
253243
}

types/streams.d.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ declare global {
5353
* Pipes this stream through a transform stream, returning the readable side.
5454
* @param transform An object with `writable` and `readable` properties.
5555
*/
56-
pipeThrough<T>(transform: {
57-
writable: WritableStream<R>;
58-
readable: ReadableStream<T>;
59-
}): ReadableStream<T>;
56+
pipeThrough<T>(transform: { writable: WritableStream<R>; readable: ReadableStream<T> }): ReadableStream<T>;
6057

6158
/** Pipes this stream to a writable stream. */
6259
pipeTo(dest: WritableStream<R>): Promise<void>;

types/timers.d.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ declare global {
1717
* clearTimeout(id); // Cancel before it runs
1818
* ```
1919
*/
20-
function setTimeout(
21-
callback: (...args: unknown[]) => void,
22-
ms?: number,
23-
...args: unknown[]
24-
): number;
20+
function setTimeout(callback: (...args: unknown[]) => void, ms?: number, ...args: unknown[]): number;
2521

2622
/**
2723
* Cancels a timeout previously scheduled with setTimeout().
@@ -46,11 +42,7 @@ declare global {
4642
* }, 1000);
4743
* ```
4844
*/
49-
function setInterval(
50-
callback: (...args: unknown[]) => void,
51-
ms?: number,
52-
...args: unknown[]
53-
): number;
45+
function setInterval(callback: (...args: unknown[]) => void, ms?: number, ...args: unknown[]): number;
5446

5547
/**
5648
* Cancels an interval previously scheduled with setInterval().

0 commit comments

Comments
 (0)