@openworkers/workers-types 0.1.4 → 0.1.5
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 +1 -1
- package/types/bindings.d.ts +32 -10
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.
|