@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/types/bindings.d.ts +32 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openworkers/workers-types",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "TypeScript types for the OpenWorkers runtime",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -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
- * Ideal for configuration, sessions, and small data.
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 with expiration
129
- * await env.KV.put('session:abc', userData, { expiresIn: 3600 });
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
- * // Retrieve
132
- * const session = await env.KV.get('session:abc');
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
- * @returns The value as a string, or null if not found.
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<string | null>;
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: string, options?: KVPutOptions): Promise<void>;
170
+ put(key: string, value: JsonValue, options?: KVPutOptions): Promise<void>;
149
171
 
150
172
  /**
151
173
  * Deletes a key.