@fedify/cfworkers 2.0.0-dev.7 → 2.0.0-dev.85

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/dist/mod.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { KVNamespace, Queue } from "@cloudflare/workers-types/experimental";
2
- import { KvKey, KvStore, KvStoreSetOptions, MessageQueue, MessageQueueEnqueueOptions, MessageQueueListenOptions } from "@fedify/fedify/federation";
2
+ import { KvKey, KvStore, KvStoreListEntry, KvStoreSetOptions, MessageQueue, MessageQueueEnqueueOptions, MessageQueueListenOptions } from "@fedify/fedify/federation";
3
3
 
4
4
  //#region src/mod.d.ts
5
5
 
@@ -20,6 +20,11 @@ declare class WorkersKvStore implements KvStore {
20
20
  get<T = unknown>(key: KvKey): Promise<T | undefined>;
21
21
  set(key: KvKey, value: unknown, options?: KvStoreSetOptions): Promise<void>;
22
22
  delete(key: KvKey): Promise<void>;
23
+ /**
24
+ * {@inheritDoc KvStore.list}
25
+ * @since 1.10.0
26
+ */
27
+ list(prefix?: KvKey): AsyncIterable<KvStoreListEntry>;
23
28
  }
24
29
  /**
25
30
  * Implementation of the {@link MessageQueue} interface for Cloudflare
package/dist/mod.js CHANGED
@@ -34,6 +34,44 @@ var WorkersKvStore = class {
34
34
  delete(key) {
35
35
  return this.#namespace.delete(this.#encodeKey(key));
36
36
  }
37
+ /**
38
+ * {@inheritDoc KvStore.list}
39
+ * @since 1.10.0
40
+ */
41
+ async *list(prefix) {
42
+ let pattern;
43
+ let exactKey = null;
44
+ if (prefix == null || prefix.length === 0) pattern = "[";
45
+ else {
46
+ exactKey = this.#encodeKey(prefix);
47
+ pattern = JSON.stringify(prefix).slice(0, -1) + ",";
48
+ }
49
+ if (exactKey != null) {
50
+ const { value, metadata } = await this.#namespace.getWithMetadata(exactKey, "json");
51
+ if (value != null && (metadata == null || metadata.expires == null || metadata.expires >= Date.now())) yield {
52
+ key: prefix,
53
+ value
54
+ };
55
+ }
56
+ let cursor;
57
+ do {
58
+ const result = await this.#namespace.list({
59
+ prefix: pattern,
60
+ cursor
61
+ });
62
+ cursor = result.list_complete ? void 0 : result.cursor;
63
+ for (const keyInfo of result.keys) {
64
+ const metadata = keyInfo.metadata;
65
+ if (metadata?.expires != null && metadata.expires < Date.now()) continue;
66
+ const value = await this.#namespace.get(keyInfo.name, "json");
67
+ if (value == null) continue;
68
+ yield {
69
+ key: JSON.parse(keyInfo.name),
70
+ value
71
+ };
72
+ }
73
+ } while (cursor != null);
74
+ }
37
75
  };
38
76
  /**
39
77
  * Implementation of the {@link MessageQueue} interface for Cloudflare
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/cfworkers",
3
- "version": "2.0.0-dev.7+a392e496",
3
+ "version": "2.0.0-dev.85+a55c8362",
4
4
  "description": "Adapt Fedify with Cloudflare Workers",
5
5
  "keywords": [
6
6
  "Fedify",
@@ -51,16 +51,19 @@
51
51
  "package.json"
52
52
  ],
53
53
  "peerDependencies": {
54
- "@cloudflare/workers-types": "^4.20250529.0",
55
- "@fedify/fedify": "^2.0.0-dev.7+a392e496"
54
+ "@cloudflare/workers-types": "^4.20250906.0",
55
+ "@fedify/fedify": "^2.0.0-dev.85+a55c8362"
56
56
  },
57
57
  "devDependencies": {
58
+ "@cloudflare/vitest-pool-workers": "^0.8.31",
58
59
  "tsdown": "^0.12.9",
59
- "typescript": "^5.9.3"
60
+ "typescript": "^5.9.3",
61
+ "vitest": "~3.2.0",
62
+ "wrangler": "^4.21.1"
60
63
  },
61
64
  "scripts": {
62
65
  "build": "tsdown",
63
66
  "prepublish": "tsdown",
64
- "test": "deno task codegen && tsdown && cd dist/ && node --test"
67
+ "test": "vitest run"
65
68
  }
66
69
  }