@fedify/cfworkers 2.0.1 → 2.0.2-dev.407

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/dist/mod.d.ts +104 -102
  2. package/package.json +2 -2
package/dist/mod.d.ts CHANGED
@@ -4,40 +4,41 @@ import { KvKey, KvStore, KvStoreListEntry, KvStoreSetOptions, MessageQueue, Mess
4
4
  //#region src/mod.d.ts
5
5
 
6
6
  /**
7
- * Result from {@link WorkersMessageQueue.processMessage}.
8
- * @since 2.0.0
9
- */
7
+ * Result from {@link WorkersMessageQueue.processMessage}.
8
+ * @since 2.0.0
9
+ */
10
10
  interface ProcessMessageResult {
11
11
  /**
12
- * Whether the message should be processed. If `false`, the message has not
13
- * been processed (for example, because an ordering key lock is still held)
14
- * and the caller is responsible for re-enqueuing or retrying it when
15
- * appropriate.
16
- */
12
+ * Whether the message should be processed. If `false`, the message has not
13
+ * been processed (for example, because an ordering key lock is still held)
14
+ * and the caller is responsible for re-enqueuing or retrying it when
15
+ * appropriate.
16
+ */
17
17
  readonly shouldProcess: boolean;
18
18
  /**
19
- * The unwrapped message payload to process.
20
- * Only present when `shouldProcess` is `true`.
21
- */
19
+ * The unwrapped message payload to process.
20
+ * Only present when `shouldProcess` is `true`.
21
+ */
22
+ // deno-lint-ignore no-explicit-any
22
23
  readonly message?: any;
23
24
  /**
24
- * A cleanup function that must be called after processing the message.
25
- * This releases the ordering key lock. Only present when `shouldProcess`
26
- * is `true` and the message had an ordering key.
27
- */
25
+ * A cleanup function that must be called after processing the message.
26
+ * This releases the ordering key lock. Only present when `shouldProcess`
27
+ * is `true` and the message had an ordering key.
28
+ */
28
29
  readonly release?: () => Promise<void>;
29
30
  }
30
31
  /**
31
- * Implementation of the {@link KvStore} interface for Cloudflare Workers KV
32
- * binding. This class provides a wrapper around Cloudflare's KV namespace to
33
- * store and retrieve JSON-serializable values using structured keys.
34
- *
35
- * Note that this implementation does not support the {@link KvStore.cas}
36
- * operation, as Cloudflare Workers KV does not support atomic compare-and-swap
37
- * operations. If you need this functionality, consider using a different
38
- * key–value store that supports atomic operations.
39
- * @since 1.9.0
40
- */
32
+ * Implementation of the {@link KvStore} interface for Cloudflare Workers KV
33
+ * binding. This class provides a wrapper around Cloudflare's KV namespace to
34
+ * store and retrieve JSON-serializable values using structured keys.
35
+ *
36
+ * Note that this implementation does not support the {@link KvStore.cas}
37
+ * operation, as Cloudflare Workers KV does not support atomic compare-and-swap
38
+ * operations. If you need this functionality, consider using a different
39
+ * key–value store that supports atomic operations.
40
+ * @since 1.9.0
41
+ */
41
42
  declare class WorkersKvStore implements KvStore {
42
43
  #private;
43
44
  constructor(namespace: KVNamespace<string>);
@@ -45,103 +46,104 @@ declare class WorkersKvStore implements KvStore {
45
46
  set(key: KvKey, value: unknown, options?: KvStoreSetOptions): Promise<void>;
46
47
  delete(key: KvKey): Promise<void>;
47
48
  /**
48
- * {@inheritDoc KvStore.list}
49
- * @since 1.10.0
50
- */
49
+ * {@inheritDoc KvStore.list}
50
+ * @since 1.10.0
51
+ */
51
52
  list(prefix?: KvKey): AsyncIterable<KvStoreListEntry>;
52
53
  }
53
54
  /**
54
- * Options for {@link WorkersMessageQueue}.
55
- * @since 2.0.0
56
- */
55
+ * Options for {@link WorkersMessageQueue}.
56
+ * @since 2.0.0
57
+ */
57
58
  interface WorkersMessageQueueOptions {
58
59
  /**
59
- * The KV namespace to use for ordering key locks. If not provided, ordering
60
- * keys will not be supported.
61
- *
62
- * Note: Cloudflare Workers KV has eventual consistency, so ordering key
63
- * guarantees are best-effort. For strict ordering requirements, consider
64
- * using Durable Objects.
65
- */
60
+ * The KV namespace to use for ordering key locks. If not provided, ordering
61
+ * keys will not be supported.
62
+ *
63
+ * Note: Cloudflare Workers KV has eventual consistency, so ordering key
64
+ * guarantees are best-effort. For strict ordering requirements, consider
65
+ * using Durable Objects.
66
+ */
66
67
  readonly orderingKv?: KVNamespace<string>;
67
68
  /**
68
- * The prefix for ordering key lock keys. Defaults to `"__fedify_ordering_"`.
69
- * @default `"__fedify_ordering_"`
70
- */
69
+ * The prefix for ordering key lock keys. Defaults to `"__fedify_ordering_"`.
70
+ * @default `"__fedify_ordering_"`
71
+ */
71
72
  readonly orderingKeyPrefix?: string;
72
73
  /**
73
- * The TTL (time-to-live) for ordering key locks in seconds.
74
- * Defaults to 60 seconds. Must be at least 60 seconds due to
75
- * Cloudflare KV minimum TTL requirement.
76
- * @default 60
77
- */
74
+ * The TTL (time-to-live) for ordering key locks in seconds.
75
+ * Defaults to 60 seconds. Must be at least 60 seconds due to
76
+ * Cloudflare KV minimum TTL requirement.
77
+ * @default 60
78
+ */
78
79
  readonly orderingLockTtl?: number;
79
80
  }
80
81
  /**
81
- * Implementation of the {@link MessageQueue} interface for Cloudflare
82
- * Workers Queues binding. This class provides a wrapper around Cloudflare's
83
- * Queues to send messages to a queue.
84
- *
85
- * Note that this implementation does not support the `listen()` method,
86
- * as Cloudflare Workers Queues do not support message consumption in the same
87
- * way as other message queue systems. Instead, you should use
88
- * the {@link WorkersMessageQueue.processMessage} method to handle ordering key
89
- * locks before calling {@link Federation.processQueuedTask}.
90
- * @since 1.9.0
91
- */
82
+ * Implementation of the {@link MessageQueue} interface for Cloudflare
83
+ * Workers Queues binding. This class provides a wrapper around Cloudflare's
84
+ * Queues to send messages to a queue.
85
+ *
86
+ * Note that this implementation does not support the `listen()` method,
87
+ * as Cloudflare Workers Queues do not support message consumption in the same
88
+ * way as other message queue systems. Instead, you should use
89
+ * the {@link WorkersMessageQueue.processMessage} method to handle ordering key
90
+ * locks before calling {@link Federation.processQueuedTask}.
91
+ * @since 1.9.0
92
+ */
92
93
  declare class WorkersMessageQueue implements MessageQueue {
93
94
  #private;
94
95
  /**
95
- * Cloudflare Queues provide automatic retry with exponential backoff
96
- * and Dead Letter Queues.
97
- * @since 1.7.0
98
- */
99
- readonly nativeRetrial = true;
96
+ * Cloudflare Queues provide automatic retry with exponential backoff
97
+ * and Dead Letter Queues.
98
+ * @since 1.7.0
99
+ */
100
+ readonly nativeRetrial: true;
100
101
  /**
101
- * Constructs a new {@link WorkersMessageQueue} with the given queue and
102
- * optional ordering key configuration.
103
- * @param queue The Cloudflare Queue binding.
104
- * @param options Options for ordering key support.
105
- */
102
+ * Constructs a new {@link WorkersMessageQueue} with the given queue and
103
+ * optional ordering key configuration.
104
+ * @param queue The Cloudflare Queue binding.
105
+ * @param options Options for ordering key support.
106
+ */
106
107
  constructor(queue: Queue, options?: WorkersMessageQueueOptions);
107
108
  enqueue(message: any, options?: MessageQueueEnqueueOptions): Promise<void>;
108
109
  enqueueMany(messages: readonly any[], options?: MessageQueueEnqueueOptions): Promise<void>;
109
110
  /**
110
- * Processes a message from the queue, handling ordering key locks.
111
- * Call this method before {@link Federation.processQueuedTask} to ensure
112
- * ordering key semantics are respected.
113
- *
114
- * Example usage in a Cloudflare Worker queue handler:
115
- *
116
- * ```typescript ignore
117
- * export default {
118
- * async queue(batch, env, ctx) {
119
- * const queue = new WorkersMessageQueue(env.QUEUE, {
120
- * orderingKv: env.ORDERING_KV,
121
- * });
122
- * for (const msg of batch.messages) {
123
- * const result = await queue.processMessage(msg.body);
124
- * if (!result.shouldProcess) {
125
- * msg.retry(); // Re-enqueue to wait for lock
126
- * continue;
127
- * }
128
- * try {
129
- * await federation.processQueuedTask(ctx, result.message);
130
- * msg.ack();
131
- * } catch (e) {
132
- * msg.retry();
133
- * } finally {
134
- * await result.release?.();
135
- * }
136
- * }
137
- * }
138
- * };
139
- * ```
140
- *
141
- * @param rawMessage The raw message body from the queue.
142
- * @returns A result object indicating whether to process the message.
143
- * @since 2.0.0
144
- */
111
+ * Processes a message from the queue, handling ordering key locks.
112
+ * Call this method before {@link Federation.processQueuedTask} to ensure
113
+ * ordering key semantics are respected.
114
+ *
115
+ * Example usage in a Cloudflare Worker queue handler:
116
+ *
117
+ * ```typescript ignore
118
+ * export default {
119
+ * async queue(batch, env, ctx) {
120
+ * const queue = new WorkersMessageQueue(env.QUEUE, {
121
+ * orderingKv: env.ORDERING_KV,
122
+ * });
123
+ * for (const msg of batch.messages) {
124
+ * const result = await queue.processMessage(msg.body);
125
+ * if (!result.shouldProcess) {
126
+ * msg.retry(); // Re-enqueue to wait for lock
127
+ * continue;
128
+ * }
129
+ * try {
130
+ * await federation.processQueuedTask(ctx, result.message);
131
+ * msg.ack();
132
+ * } catch (e) {
133
+ * msg.retry();
134
+ * } finally {
135
+ * await result.release?.();
136
+ * }
137
+ * }
138
+ * }
139
+ * };
140
+ * ```
141
+ *
142
+ * @param rawMessage The raw message body from the queue.
143
+ * @returns A result object indicating whether to process the message.
144
+ * @since 2.0.0
145
+ */
146
+ // deno-lint-ignore no-explicit-any
145
147
  processMessage(rawMessage: any): Promise<ProcessMessageResult>;
146
148
  listen(_handler: (message: any) => Promise<void> | void, _options?: MessageQueueListenOptions): Promise<void>;
147
149
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/cfworkers",
3
- "version": "2.0.1",
3
+ "version": "2.0.2-dev.407+6f4b2e28",
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",
55
- "@fedify/fedify": "^2.0.1"
55
+ "@fedify/fedify": "^2.0.2-dev.407+6f4b2e28"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@cloudflare/vitest-pool-workers": "^0.8.31",