@fedify/cfworkers 2.0.36-dev.2551 → 2.0.36-dev.2637

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/README.md +27 -16
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -16,35 +16,44 @@ implementations for [Cloudflare Workers]:
16
16
  - [`WorkersMessageQueue`]
17
17
 
18
18
  ~~~~ typescript
19
- import type { Federation } from "@fedify/fedify";
19
+ import { createFederation, type Message } from "@fedify/fedify";
20
20
  import { WorkersKvStore, WorkersMessageQueue } from "@fedify/cfworkers";
21
21
 
22
+ type Env = {
23
+ KV_BINDING: KVNamespace<string>;
24
+ QUEUE_BINDING: Queue;
25
+ };
26
+
22
27
  export default {
23
- async fetch(request, env, ctx) {
24
- const federation = createFederation({
28
+ async fetch(request: Request, env: Env): Promise<Response> {
29
+ const federation = createFederation<Env>({
25
30
  kv: new WorkersKvStore(env.KV_BINDING),
26
31
  queue: new WorkersMessageQueue(env.QUEUE_BINDING),
32
+ // Cloudflare Queues cannot be polled, so the queue() handler below
33
+ // consumes the messages instead of Federation.startQueue():
34
+ manuallyStartQueue: true,
27
35
  // ... other options
28
36
  });
29
-
30
- return federation.handle(request, { contextData: env });
37
+
38
+ return await federation.fetch(request, { contextData: env });
31
39
  },
32
-
33
- async queue(batch, env, ctx) {
34
- const federation = createFederation({
40
+
41
+ async queue(batch: MessageBatch<unknown>, env: Env): Promise<void> {
42
+ const federation = createFederation<Env>({
35
43
  kv: new WorkersKvStore(env.KV_BINDING),
36
44
  queue: new WorkersMessageQueue(env.QUEUE_BINDING),
45
+ // Inbox listeners run inside processQueuedTask() and may call
46
+ // ctx.sendActivity(), which would otherwise start the queue workers
47
+ // automatically:
48
+ manuallyStartQueue: true,
37
49
  // ... other options
38
50
  });
39
-
51
+
40
52
  for (const message of batch.messages) {
41
- await federation.processQueuedTask(message.body);
53
+ await federation.processQueuedTask(env, message.body as Message);
42
54
  }
43
- }
44
- } satisfies ExportedHandler<{
45
- KV_BINDING: KVNamespace<string>;
46
- QUEUE_BINDING: Queue;
47
- }>;
55
+ },
56
+ } satisfies ExportedHandler<Env>;
48
57
  ~~~~
49
58
 
50
59
  [JSR badge]: https://jsr.io/badges/@fedify/cfworkers
@@ -99,7 +108,9 @@ management.
99
108
  > API when new messages are available in the queue. Inside the `queue()`
100
109
  > method, you need to call `Federation.processQueuedTask()` method to manually
101
110
  > process the messages. The `queue()` method is the only way to consume
102
- > messages from the queue in Cloudflare Workers.
111
+ > messages from the queue in Cloudflare Workers. Set `manuallyStartQueue` to
112
+ > `true` as well; otherwise Fedify tries to start the workers automatically,
113
+ > and since `listen()` throws, it logs a warning that they could not be started.
103
114
 
104
115
  [Cloudflare Queues]: https://developers.cloudflare.com/queues/
105
116
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/cfworkers",
3
- "version": "2.0.36-dev.2551+8b012df4",
3
+ "version": "2.0.36-dev.2637+cc2cd6fb",
4
4
  "description": "Adapt Fedify with Cloudflare Workers",
5
5
  "keywords": [
6
6
  "Fedify",
@@ -52,7 +52,7 @@
52
52
  ],
53
53
  "peerDependencies": {
54
54
  "@cloudflare/workers-types": "^4.20250906.0 || ^5.0.0",
55
- "@fedify/fedify": "^2.0.36-dev.2551+8b012df4"
55
+ "@fedify/fedify": "^2.0.36-dev.2637+cc2cd6fb"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@cloudflare/vitest-pool-workers": "^0.8.31",