@openworkers/workers-types 0.1.6 → 0.1.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openworkers/workers-types",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
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
  }
@@ -18,10 +18,10 @@ declare global {
18
18
  interface BindingAssets {
19
19
  /**
20
20
  * 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.
23
23
  */
24
- fetch(path: string, options?: RequestInit): Promise<Response>;
24
+ fetch(input: Request | string | URL, init?: RequestInit): Promise<Response>;
25
25
  }
26
26
 
27
27
  /**
@@ -98,6 +98,13 @@ declare global {
98
98
  * Deletes a key.
99
99
  */
100
100
  delete(key: string): Promise<void>;
101
+
102
+ /**
103
+ * Fetches a static asset from the bundle (same as BindingAssets).
104
+ * @param input The asset path, URL, or request.
105
+ * @param init Optional request options.
106
+ */
107
+ fetch(input: Request | string | URL, init?: RequestInit): Promise<Response>;
101
108
  }
102
109
 
103
110
  /**
@@ -124,13 +131,7 @@ declare global {
124
131
  * Supports strings, numbers, booleans, null, arrays, and objects.
125
132
  * Note: Binary data (Uint8Array, ArrayBuffer) is not supported.
126
133
  */
127
- type JsonValue =
128
- | string
129
- | number
130
- | boolean
131
- | null
132
- | JsonValue[]
133
- | { [key: string]: JsonValue };
134
+ type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };
134
135
 
135
136
  /**
136
137
  * Key-Value storage binding for fast, low-latency data access.
@@ -217,9 +218,9 @@ declare global {
217
218
  interface BindingWorker {
218
219
  /**
219
220
  * Calls another worker with a request.
220
- * @param request The request to send.
221
- * @param init Optional request options (when using string URL).
221
+ * @param input The request, URL, or string URL to send.
222
+ * @param init Optional request options.
222
223
  */
223
- fetch(request: Request | string, init?: RequestInit): Promise<Response>;
224
+ fetch(input: Request | string | URL, init?: RequestInit): Promise<Response>;
224
225
  }
225
226
  }
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.
@@ -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?: "follow" | "error" | "manual";
78
+ redirect?: 'follow' | 'error' | 'manual';
86
79
 
87
80
  /** An AbortSignal to cancel the request. */
88
81
  signal?: AbortSignal;
@@ -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
  }
@@ -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>;
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]>;
@@ -71,11 +71,7 @@ declare global {
71
71
  * @param env Environment bindings.
72
72
  * @param ctx Execution context.
73
73
  */
74
- fetch?(
75
- request: Request,
76
- env: Env,
77
- ctx: ExecutionContext
78
- ): Response | Promise<Response>;
74
+ fetch?(request: Request, env: Env, ctx: ExecutionContext): Response | Promise<Response>;
79
75
 
80
76
  /**
81
77
  * Handles scheduled (cron) invocations.
@@ -83,11 +79,7 @@ declare global {
83
79
  * @param env Environment bindings.
84
80
  * @param ctx Execution context.
85
81
  */
86
- scheduled?(
87
- event: ScheduledEvent,
88
- env: Env,
89
- ctx: ExecutionContext
90
- ): void | Promise<void>;
82
+ scheduled?(event: ScheduledEvent, env: Env, ctx: ExecutionContext): void | Promise<void>;
91
83
  }
92
84
 
93
85
  // addEventListener pattern
@@ -133,16 +125,10 @@ declare global {
133
125
  /**
134
126
  * Registers a fetch event listener (Service Worker pattern).
135
127
  */
136
- function addEventListener(
137
- type: "fetch",
138
- listener: (event: FetchEvent) => void
139
- ): void;
128
+ function addEventListener(type: 'fetch', listener: (event: FetchEvent) => void): void;
140
129
 
141
130
  /**
142
131
  * Registers a scheduled event listener (Service Worker pattern).
143
132
  */
144
- function addEventListener(
145
- type: "scheduled",
146
- listener: ScheduledEventListener
147
- ): void;
133
+ function addEventListener(type: 'scheduled', listener: ScheduledEventListener): void;
148
134
  }