@openworkers/workers-types 0.1.5 → 0.1.7
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/LICENSE +21 -0
- package/package.json +7 -1
- package/types/bindings.d.ts +7 -13
- package/types/blob.d.ts +2 -7
- package/types/crypto.d.ts +8 -39
- package/types/encoding.d.ts +1 -4
- package/types/fetch.d.ts +5 -15
- package/types/streams.d.ts +7 -4
- package/types/timers.d.ts +2 -10
- package/types/url.d.ts +2 -6
- package/types/workers.d.ts +11 -18
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OpenWorkers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openworkers/workers-types",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "TypeScript types for the OpenWorkers runtime",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
"index.d.ts",
|
|
19
19
|
"types/*.d.ts"
|
|
20
20
|
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"format": "prettier --write ."
|
|
23
|
+
},
|
|
21
24
|
"peerDependencies": {
|
|
22
25
|
"typescript": "^5"
|
|
23
26
|
},
|
|
@@ -25,5 +28,8 @@
|
|
|
25
28
|
"access": "public",
|
|
26
29
|
"registry": "https://registry.npmjs.org/",
|
|
27
30
|
"provenance": true
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"prettier": "^3.8.1"
|
|
28
34
|
}
|
|
29
35
|
}
|
package/types/bindings.d.ts
CHANGED
|
@@ -18,10 +18,10 @@ declare global {
|
|
|
18
18
|
interface BindingAssets {
|
|
19
19
|
/**
|
|
20
20
|
* Fetches a static asset from the bundle.
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
21
|
+
* @param input The asset path, URL, or request.
|
|
22
|
+
* @param init Optional request options.
|
|
23
23
|
*/
|
|
24
|
-
fetch(
|
|
24
|
+
fetch(input: Request | string | URL, init?: RequestInit): Promise<Response>;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -124,13 +124,7 @@ declare global {
|
|
|
124
124
|
* Supports strings, numbers, booleans, null, arrays, and objects.
|
|
125
125
|
* Note: Binary data (Uint8Array, ArrayBuffer) is not supported.
|
|
126
126
|
*/
|
|
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 };
|
|
134
128
|
|
|
135
129
|
/**
|
|
136
130
|
* Key-Value storage binding for fast, low-latency data access.
|
|
@@ -217,9 +211,9 @@ declare global {
|
|
|
217
211
|
interface BindingWorker {
|
|
218
212
|
/**
|
|
219
213
|
* Calls another worker with a request.
|
|
220
|
-
* @param
|
|
221
|
-
* @param init Optional request options
|
|
214
|
+
* @param input The request, URL, or string URL to send.
|
|
215
|
+
* @param init Optional request options.
|
|
222
216
|
*/
|
|
223
|
-
fetch(
|
|
217
|
+
fetch(input: Request | string | URL, init?: RequestInit): Promise<Response>;
|
|
224
218
|
}
|
|
225
219
|
}
|
package/types/blob.d.ts
CHANGED
|
@@ -19,10 +19,7 @@ declare global {
|
|
|
19
19
|
* @param blobParts Array of data to include in the blob.
|
|
20
20
|
* @param options Optional settings like MIME type.
|
|
21
21
|
*/
|
|
22
|
-
constructor(
|
|
23
|
-
blobParts?: (ArrayBuffer | Uint8Array | Blob | string)[],
|
|
24
|
-
options?: { type?: string }
|
|
25
|
-
);
|
|
22
|
+
constructor(blobParts?: (ArrayBuffer | Uint8Array | Blob | string)[], options?: { type?: string });
|
|
26
23
|
|
|
27
24
|
/** The size of the blob in bytes. */
|
|
28
25
|
readonly size: number;
|
|
@@ -104,9 +101,7 @@ declare global {
|
|
|
104
101
|
set(name: string, value: string | Blob, filename?: string): void;
|
|
105
102
|
|
|
106
103
|
/** 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;
|
|
110
105
|
|
|
111
106
|
/** Returns an iterator of all key/value pairs. */
|
|
112
107
|
entries(): IterableIterator<[string, string | File]>;
|
package/types/crypto.d.ts
CHANGED
|
@@ -18,10 +18,7 @@ declare global {
|
|
|
18
18
|
* const hash = await crypto.subtle.digest('SHA-256', new TextEncoder().encode('hello'));
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
|
-
digest(
|
|
22
|
-
algorithm: string | { name: string },
|
|
23
|
-
data: BufferSource
|
|
24
|
-
): Promise<ArrayBuffer>;
|
|
21
|
+
digest(algorithm: string | { name: string }, data: BufferSource): Promise<ArrayBuffer>;
|
|
25
22
|
|
|
26
23
|
/**
|
|
27
24
|
* Encrypts data using a key.
|
|
@@ -29,11 +26,7 @@ declare global {
|
|
|
29
26
|
* @param key The encryption key.
|
|
30
27
|
* @param data The data to encrypt.
|
|
31
28
|
*/
|
|
32
|
-
encrypt(
|
|
33
|
-
algorithm: unknown,
|
|
34
|
-
key: CryptoKey,
|
|
35
|
-
data: BufferSource
|
|
36
|
-
): Promise<ArrayBuffer>;
|
|
29
|
+
encrypt(algorithm: unknown, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>;
|
|
37
30
|
|
|
38
31
|
/**
|
|
39
32
|
* Decrypts data using a key.
|
|
@@ -41,11 +34,7 @@ declare global {
|
|
|
41
34
|
* @param key The decryption key.
|
|
42
35
|
* @param data The data to decrypt.
|
|
43
36
|
*/
|
|
44
|
-
decrypt(
|
|
45
|
-
algorithm: unknown,
|
|
46
|
-
key: CryptoKey,
|
|
47
|
-
data: BufferSource
|
|
48
|
-
): Promise<ArrayBuffer>;
|
|
37
|
+
decrypt(algorithm: unknown, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>;
|
|
49
38
|
|
|
50
39
|
/**
|
|
51
40
|
* Signs data using a private key.
|
|
@@ -53,11 +42,7 @@ declare global {
|
|
|
53
42
|
* @param key The private key.
|
|
54
43
|
* @param data The data to sign.
|
|
55
44
|
*/
|
|
56
|
-
sign(
|
|
57
|
-
algorithm: unknown,
|
|
58
|
-
key: CryptoKey,
|
|
59
|
-
data: BufferSource
|
|
60
|
-
): Promise<ArrayBuffer>;
|
|
45
|
+
sign(algorithm: unknown, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>;
|
|
61
46
|
|
|
62
47
|
/**
|
|
63
48
|
* Verifies a signature using a public key.
|
|
@@ -67,12 +52,7 @@ declare global {
|
|
|
67
52
|
* @param data The original data.
|
|
68
53
|
* @returns True if the signature is valid.
|
|
69
54
|
*/
|
|
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>;
|
|
76
56
|
|
|
77
57
|
/**
|
|
78
58
|
* Generates a new cryptographic key or key pair.
|
|
@@ -80,11 +60,7 @@ declare global {
|
|
|
80
60
|
* @param extractable Whether the key can be exported.
|
|
81
61
|
* @param keyUsages The allowed operations for this key.
|
|
82
62
|
*/
|
|
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>;
|
|
88
64
|
|
|
89
65
|
/**
|
|
90
66
|
* Imports a key from external format.
|
|
@@ -107,10 +83,7 @@ declare global {
|
|
|
107
83
|
* @param format The key format ("raw", "pkcs8", "spki", "jwk").
|
|
108
84
|
* @param key The key to export.
|
|
109
85
|
*/
|
|
110
|
-
exportKey(
|
|
111
|
-
format: string,
|
|
112
|
-
key: CryptoKey
|
|
113
|
-
): Promise<ArrayBuffer | JsonWebKey>;
|
|
86
|
+
exportKey(format: string, key: CryptoKey): Promise<ArrayBuffer | JsonWebKey>;
|
|
114
87
|
|
|
115
88
|
/**
|
|
116
89
|
* Derives bits from a base key.
|
|
@@ -118,11 +91,7 @@ declare global {
|
|
|
118
91
|
* @param baseKey The base key.
|
|
119
92
|
* @param length The number of bits to derive.
|
|
120
93
|
*/
|
|
121
|
-
deriveBits(
|
|
122
|
-
algorithm: unknown,
|
|
123
|
-
baseKey: CryptoKey,
|
|
124
|
-
length: number
|
|
125
|
-
): Promise<ArrayBuffer>;
|
|
94
|
+
deriveBits(algorithm: unknown, baseKey: CryptoKey, length: number): Promise<ArrayBuffer>;
|
|
126
95
|
|
|
127
96
|
/**
|
|
128
97
|
* Derives a new key from a base key.
|
package/types/encoding.d.ts
CHANGED
|
@@ -36,10 +36,7 @@ declare global {
|
|
|
36
36
|
* @param destination The buffer to write into.
|
|
37
37
|
* @returns An object with `read` (chars read) and `written` (bytes written).
|
|
38
38
|
*/
|
|
39
|
-
encodeInto(
|
|
40
|
-
source: string,
|
|
41
|
-
destination: Uint8Array
|
|
42
|
-
): { read: number; written: number };
|
|
39
|
+
encodeInto(source: string, destination: Uint8Array): { read: number; written: number };
|
|
43
40
|
}
|
|
44
41
|
|
|
45
42
|
/**
|
package/types/fetch.d.ts
CHANGED
|
@@ -5,14 +5,7 @@ export {};
|
|
|
5
5
|
/**
|
|
6
6
|
* Valid types for a request or response body.
|
|
7
7
|
*/
|
|
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;
|
|
16
9
|
|
|
17
10
|
/**
|
|
18
11
|
* Valid types for initializing Headers.
|
|
@@ -82,7 +75,7 @@ declare global {
|
|
|
82
75
|
body?: BodyInit | null;
|
|
83
76
|
|
|
84
77
|
/** How to handle redirects: "follow", "error", or "manual". */
|
|
85
|
-
redirect?:
|
|
78
|
+
redirect?: 'follow' | 'error' | 'manual';
|
|
86
79
|
|
|
87
80
|
/** An AbortSignal to cancel the request. */
|
|
88
81
|
signal?: AbortSignal;
|
|
@@ -136,7 +129,7 @@ declare global {
|
|
|
136
129
|
formData(): Promise<FormData>;
|
|
137
130
|
|
|
138
131
|
/** Reads the body as JSON. */
|
|
139
|
-
json(): Promise<
|
|
132
|
+
json<T = unknown>(): Promise<T>;
|
|
140
133
|
|
|
141
134
|
/** Reads the body as text. */
|
|
142
135
|
text(): Promise<string>;
|
|
@@ -227,7 +220,7 @@ declare global {
|
|
|
227
220
|
formData(): Promise<FormData>;
|
|
228
221
|
|
|
229
222
|
/** Reads the body as JSON. */
|
|
230
|
-
json(): Promise<
|
|
223
|
+
json<T = unknown>(): Promise<T>;
|
|
231
224
|
|
|
232
225
|
/** Reads the body as text. */
|
|
233
226
|
text(): Promise<string>;
|
|
@@ -246,8 +239,5 @@ declare global {
|
|
|
246
239
|
* const data = await response.json();
|
|
247
240
|
* ```
|
|
248
241
|
*/
|
|
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>;
|
|
253
243
|
}
|
package/types/streams.d.ts
CHANGED
|
@@ -53,10 +53,7 @@ declare global {
|
|
|
53
53
|
* Pipes this stream through a transform stream, returning the readable side.
|
|
54
54
|
* @param transform An object with `writable` and `readable` properties.
|
|
55
55
|
*/
|
|
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>;
|
|
60
57
|
|
|
61
58
|
/** Pipes this stream to a writable stream. */
|
|
62
59
|
pipeTo(dest: WritableStream<R>): Promise<void>;
|
|
@@ -73,6 +70,12 @@ declare global {
|
|
|
73
70
|
/** The amount of data the consumer wants, or null if the stream is closed. */
|
|
74
71
|
readonly desiredSize: number | null;
|
|
75
72
|
|
|
73
|
+
/**
|
|
74
|
+
* An AbortSignal that is aborted when the stream consumer cancels/disconnects.
|
|
75
|
+
* Use this to detect client disconnection and stop producing data.
|
|
76
|
+
*/
|
|
77
|
+
readonly signal?: AbortSignal;
|
|
78
|
+
|
|
76
79
|
/** Closes the stream. No more chunks can be enqueued after this. */
|
|
77
80
|
close(): void;
|
|
78
81
|
|
package/types/timers.d.ts
CHANGED
|
@@ -17,11 +17,7 @@ declare global {
|
|
|
17
17
|
* clearTimeout(id); // Cancel before it runs
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
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;
|
|
25
21
|
|
|
26
22
|
/**
|
|
27
23
|
* Cancels a timeout previously scheduled with setTimeout().
|
|
@@ -46,11 +42,7 @@ declare global {
|
|
|
46
42
|
* }, 1000);
|
|
47
43
|
* ```
|
|
48
44
|
*/
|
|
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;
|
|
54
46
|
|
|
55
47
|
/**
|
|
56
48
|
* Cancels an interval previously scheduled with setInterval().
|
package/types/url.d.ts
CHANGED
|
@@ -85,9 +85,7 @@ declare global {
|
|
|
85
85
|
* Creates a new URLSearchParams.
|
|
86
86
|
* @param init Initial parameters as string, object, or array of pairs.
|
|
87
87
|
*/
|
|
88
|
-
constructor(
|
|
89
|
-
init?: string | URLSearchParams | Record<string, string> | [string, string][]
|
|
90
|
-
);
|
|
88
|
+
constructor(init?: string | URLSearchParams | Record<string, string> | [string, string][]);
|
|
91
89
|
|
|
92
90
|
/** Appends a new key/value pair. */
|
|
93
91
|
append(name: string, value: string): void;
|
|
@@ -114,9 +112,7 @@ declare global {
|
|
|
114
112
|
toString(): string;
|
|
115
113
|
|
|
116
114
|
/** Executes a callback for each key/value pair. */
|
|
117
|
-
forEach(
|
|
118
|
-
callback: (value: string, key: string, parent: URLSearchParams) => void
|
|
119
|
-
): void;
|
|
115
|
+
forEach(callback: (value: string, key: string, parent: URLSearchParams) => void): void;
|
|
120
116
|
|
|
121
117
|
/** Returns an iterator of all key/value pairs. */
|
|
122
118
|
entries(): IterableIterator<[string, string]>;
|
package/types/workers.d.ts
CHANGED
|
@@ -42,6 +42,13 @@ declare global {
|
|
|
42
42
|
* Must be called before any response is sent.
|
|
43
43
|
*/
|
|
44
44
|
passThroughOnException(): void;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Properties passed to the worker.
|
|
48
|
+
* For Hono/Cloudflare Workers compatibility.
|
|
49
|
+
* @deprecated Not implemented in OpenWorkers
|
|
50
|
+
*/
|
|
51
|
+
props: never;
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
/**
|
|
@@ -64,11 +71,7 @@ declare global {
|
|
|
64
71
|
* @param env Environment bindings.
|
|
65
72
|
* @param ctx Execution context.
|
|
66
73
|
*/
|
|
67
|
-
fetch?(
|
|
68
|
-
request: Request,
|
|
69
|
-
env: Env,
|
|
70
|
-
ctx: ExecutionContext
|
|
71
|
-
): Response | Promise<Response>;
|
|
74
|
+
fetch?(request: Request, env: Env, ctx: ExecutionContext): Response | Promise<Response>;
|
|
72
75
|
|
|
73
76
|
/**
|
|
74
77
|
* Handles scheduled (cron) invocations.
|
|
@@ -76,11 +79,7 @@ declare global {
|
|
|
76
79
|
* @param env Environment bindings.
|
|
77
80
|
* @param ctx Execution context.
|
|
78
81
|
*/
|
|
79
|
-
scheduled?(
|
|
80
|
-
event: ScheduledEvent,
|
|
81
|
-
env: Env,
|
|
82
|
-
ctx: ExecutionContext
|
|
83
|
-
): void | Promise<void>;
|
|
82
|
+
scheduled?(event: ScheduledEvent, env: Env, ctx: ExecutionContext): void | Promise<void>;
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
// addEventListener pattern
|
|
@@ -126,16 +125,10 @@ declare global {
|
|
|
126
125
|
/**
|
|
127
126
|
* Registers a fetch event listener (Service Worker pattern).
|
|
128
127
|
*/
|
|
129
|
-
function addEventListener(
|
|
130
|
-
type: "fetch",
|
|
131
|
-
listener: (event: FetchEvent) => void
|
|
132
|
-
): void;
|
|
128
|
+
function addEventListener(type: 'fetch', listener: (event: FetchEvent) => void): void;
|
|
133
129
|
|
|
134
130
|
/**
|
|
135
131
|
* Registers a scheduled event listener (Service Worker pattern).
|
|
136
132
|
*/
|
|
137
|
-
function addEventListener(
|
|
138
|
-
type: "scheduled",
|
|
139
|
-
listener: ScheduledEventListener
|
|
140
|
-
): void;
|
|
133
|
+
function addEventListener(type: 'scheduled', listener: ScheduledEventListener): void;
|
|
141
134
|
}
|