@nsnanocat/util 2.3.0 → 2.3.1

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/polyfill/KV.mjs +5 -27
package/package.json CHANGED
@@ -42,5 +42,5 @@
42
42
  "registry": "https://registry.npmjs.org/",
43
43
  "access": "public"
44
44
  },
45
- "version": "2.3.0"
45
+ "version": "2.3.1"
46
46
  }
package/polyfill/KV.mjs CHANGED
@@ -75,7 +75,7 @@ export class KV {
75
75
  default:
76
76
  switch ($app) {
77
77
  case "Worker":
78
- keyValue = await this.#getNamespace().get(keyName);
78
+ keyValue = await this.namespace.get(keyName);
79
79
  break;
80
80
  default:
81
81
  keyValue = Storage.getItem(keyName, defaultValue);
@@ -111,7 +111,7 @@ export class KV {
111
111
  default:
112
112
  switch ($app) {
113
113
  case "Worker":
114
- await this.#getNamespace().put(keyName, keyValue);
114
+ await this.namespace.put(keyName, keyValue);
115
115
  result = true;
116
116
  break;
117
117
  default:
@@ -145,7 +145,7 @@ export class KV {
145
145
  default:
146
146
  switch ($app) {
147
147
  case "Worker":
148
- await this.#getNamespace().delete(keyName);
148
+ await this.namespace.delete(keyName);
149
149
  result = true;
150
150
  break;
151
151
  default:
@@ -176,35 +176,13 @@ export class KV {
176
176
  */
177
177
  async list(options = {}) {
178
178
  switch ($app) {
179
- case "Worker": {
180
- const namespace = this.#getNamespace();
181
- if (typeof namespace.list !== "function") throw new TypeError("KV namespace binding with list() is required in Worker runtime.");
182
- return await namespace.list(options);
183
- }
179
+ case "Worker":
180
+ return await this.namespace.list(options);
184
181
  default:
185
182
  throw new TypeError("KV.list() is only supported in Worker runtime.");
186
183
  }
187
184
  }
188
185
 
189
- /**
190
- * 解析 Worker 所需的 namespace 绑定。
191
- * Resolve the namespace binding required by Workers.
192
- *
193
- * @private
194
- * @returns {{ get(key: string): Promise<string|null>; put(key: string, value: string): Promise<void>; delete(key: string): Promise<void>; list?(options?: { prefix?: string; limit?: number; cursor?: string }): Promise<{ keys: { name: string; expiration?: number; metadata?: object }[]; list_complete: boolean; cursor: string }> }}
195
- */
196
- #getNamespace() {
197
- if (
198
- !this.namespace ||
199
- typeof this.namespace.get !== "function" ||
200
- typeof this.namespace.put !== "function" ||
201
- typeof this.namespace.delete !== "function"
202
- ) {
203
- throw new TypeError("KV namespace binding is required in Worker runtime.");
204
- }
205
- return this.namespace;
206
- }
207
-
208
186
  /**
209
187
  * 尝试将字符串反序列化为原始值。
210
188
  * Try to deserialize a string into its original value.