@openworkers/workers-types 0.1.4 → 0.1.6
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 +1 -1
- package/types/bindings.d.ts +32 -10
- package/types/fetch.d.ts +2 -2
- package/types/streams.d.ts +6 -0
- package/types/workers.d.ts +7 -0
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
package/types/bindings.d.ts
CHANGED
|
@@ -119,33 +119,55 @@ declare global {
|
|
|
119
119
|
limit?: number;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
/**
|
|
123
|
+
* JSON-serializable value type.
|
|
124
|
+
* Supports strings, numbers, booleans, null, arrays, and objects.
|
|
125
|
+
* Note: Binary data (Uint8Array, ArrayBuffer) is not supported.
|
|
126
|
+
*/
|
|
127
|
+
type JsonValue =
|
|
128
|
+
| string
|
|
129
|
+
| number
|
|
130
|
+
| boolean
|
|
131
|
+
| null
|
|
132
|
+
| JsonValue[]
|
|
133
|
+
| { [key: string]: JsonValue };
|
|
134
|
+
|
|
122
135
|
/**
|
|
123
136
|
* Key-Value storage binding for fast, low-latency data access.
|
|
124
|
-
*
|
|
137
|
+
* Stores values as JSON, supporting strings, numbers, booleans, objects, and arrays.
|
|
138
|
+
* Ideal for configuration, sessions, and structured data.
|
|
125
139
|
*
|
|
126
140
|
* @example
|
|
127
141
|
* ```ts
|
|
128
|
-
* // Store
|
|
129
|
-
* await env.KV.put('
|
|
142
|
+
* // Store a string
|
|
143
|
+
* await env.KV.put('greeting', 'Hello, World!');
|
|
144
|
+
*
|
|
145
|
+
* // Store a number
|
|
146
|
+
* await env.KV.put('count', 42);
|
|
130
147
|
*
|
|
131
|
-
* //
|
|
132
|
-
*
|
|
148
|
+
* // Store an object with expiration
|
|
149
|
+
* await env.KV.put('session:abc', { userId: 123, role: 'admin' }, { expiresIn: 3600 });
|
|
150
|
+
*
|
|
151
|
+
* // Retrieve with type inference
|
|
152
|
+
* const session = await env.KV.get<{ userId: number; role: string }>('session:abc');
|
|
133
153
|
* ```
|
|
134
154
|
*/
|
|
135
155
|
interface BindingKV {
|
|
136
156
|
/**
|
|
137
157
|
* Retrieves a value by key.
|
|
138
|
-
* @
|
|
158
|
+
* @typeParam T The expected value type (defaults to unknown).
|
|
159
|
+
* @returns The value, or null if not found or expired.
|
|
139
160
|
*/
|
|
140
|
-
get(key: string): Promise<
|
|
161
|
+
get<T = unknown>(key: string): Promise<T | null>;
|
|
141
162
|
|
|
142
163
|
/**
|
|
143
|
-
* Stores a value with optional expiration.
|
|
164
|
+
* Stores a JSON-serializable value with optional expiration.
|
|
165
|
+
* Maximum value size: 100KB.
|
|
144
166
|
* @param key The storage key.
|
|
145
|
-
* @param value The value to store.
|
|
167
|
+
* @param value The value to store (must be JSON-serializable).
|
|
146
168
|
* @param options Optional settings like TTL.
|
|
147
169
|
*/
|
|
148
|
-
put(key: string, value:
|
|
170
|
+
put(key: string, value: JsonValue, options?: KVPutOptions): Promise<void>;
|
|
149
171
|
|
|
150
172
|
/**
|
|
151
173
|
* Deletes a key.
|
package/types/fetch.d.ts
CHANGED
|
@@ -136,7 +136,7 @@ declare global {
|
|
|
136
136
|
formData(): Promise<FormData>;
|
|
137
137
|
|
|
138
138
|
/** Reads the body as JSON. */
|
|
139
|
-
json(): Promise<
|
|
139
|
+
json<T = unknown>(): Promise<T>;
|
|
140
140
|
|
|
141
141
|
/** Reads the body as text. */
|
|
142
142
|
text(): Promise<string>;
|
|
@@ -227,7 +227,7 @@ declare global {
|
|
|
227
227
|
formData(): Promise<FormData>;
|
|
228
228
|
|
|
229
229
|
/** Reads the body as JSON. */
|
|
230
|
-
json(): Promise<
|
|
230
|
+
json<T = unknown>(): Promise<T>;
|
|
231
231
|
|
|
232
232
|
/** Reads the body as text. */
|
|
233
233
|
text(): Promise<string>;
|
package/types/streams.d.ts
CHANGED
|
@@ -73,6 +73,12 @@ declare global {
|
|
|
73
73
|
/** The amount of data the consumer wants, or null if the stream is closed. */
|
|
74
74
|
readonly desiredSize: number | null;
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* An AbortSignal that is aborted when the stream consumer cancels/disconnects.
|
|
78
|
+
* Use this to detect client disconnection and stop producing data.
|
|
79
|
+
*/
|
|
80
|
+
readonly signal?: AbortSignal;
|
|
81
|
+
|
|
76
82
|
/** Closes the stream. No more chunks can be enqueued after this. */
|
|
77
83
|
close(): void;
|
|
78
84
|
|
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
|
/**
|