@fedify/cfworkers 2.2.0-dev.671 → 2.2.0-dev.681
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/README.md +18 -7
- package/dist/mod.d.ts +43 -4
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ implementations for [Cloudflare Workers]:
|
|
|
16
16
|
- [`WorkersMessageQueue`]
|
|
17
17
|
|
|
18
18
|
~~~~ typescript
|
|
19
|
-
import type
|
|
19
|
+
import { createFederation, type Message } from "@fedify/fedify";
|
|
20
20
|
import { WorkersKvStore, WorkersMessageQueue } from "@fedify/cfworkers";
|
|
21
21
|
|
|
22
22
|
export default {
|
|
@@ -26,22 +26,25 @@ export default {
|
|
|
26
26
|
queue: new WorkersMessageQueue(env.QUEUE_BINDING),
|
|
27
27
|
// ... other options
|
|
28
28
|
});
|
|
29
|
-
|
|
30
|
-
return federation.
|
|
29
|
+
|
|
30
|
+
return federation.fetch(request, { contextData: env });
|
|
31
31
|
},
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
async queue(batch, env, ctx) {
|
|
34
34
|
const federation = createFederation({
|
|
35
35
|
kv: new WorkersKvStore(env.KV_BINDING),
|
|
36
36
|
queue: new WorkersMessageQueue(env.QUEUE_BINDING),
|
|
37
37
|
// ... other options
|
|
38
38
|
});
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
for (const message of batch.messages) {
|
|
41
|
-
await federation.processQueuedTask(
|
|
41
|
+
await federation.processQueuedTask(
|
|
42
|
+
env,
|
|
43
|
+
message.body as unknown as Message,
|
|
44
|
+
);
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
|
-
} satisfies ExportedHandler<{
|
|
47
|
+
} satisfies ExportedHandler<{
|
|
45
48
|
KV_BINDING: KVNamespace<string>;
|
|
46
49
|
QUEUE_BINDING: Queue;
|
|
47
50
|
}>;
|
|
@@ -101,6 +104,14 @@ management.
|
|
|
101
104
|
> process the messages. The `queue()` method is the only way to consume
|
|
102
105
|
> messages from the queue in Cloudflare Workers.
|
|
103
106
|
|
|
107
|
+
> [!NOTE]
|
|
108
|
+
> If you use `orderingKey` when enqueueing messages, construct
|
|
109
|
+
> `WorkersMessageQueue` with an `orderingKv` namespace and pass each raw queue
|
|
110
|
+
> message through `WorkersMessageQueue.processMessage()` before calling
|
|
111
|
+
> `Federation.processQueuedTask()`. This acquires and releases the best-effort
|
|
112
|
+
> ordering lock for that key. You can also customize the lock behavior with
|
|
113
|
+
> the `orderingKeyPrefix` and `orderingLockTtl` options.
|
|
114
|
+
|
|
104
115
|
[Cloudflare Queues]: https://developers.cloudflare.com/queues/
|
|
105
116
|
|
|
106
117
|
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,7 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Queue } from "@cloudflare/workers-types";
|
|
2
2
|
import { KvKey, KvStore, KvStoreListEntry, KvStoreSetOptions, MessageQueue, MessageQueueEnqueueOptions, MessageQueueListenOptions } from "@fedify/fedify/federation";
|
|
3
3
|
|
|
4
4
|
//#region src/mod.d.ts
|
|
5
|
+
interface WorkersKvNamespaceGetWithMetadataResult<Value, Metadata> {
|
|
6
|
+
readonly value: Value | null;
|
|
7
|
+
readonly metadata: Metadata | null;
|
|
8
|
+
}
|
|
9
|
+
interface WorkersKvNamespaceListKey<Metadata, Key extends string = string> {
|
|
10
|
+
readonly name: Key;
|
|
11
|
+
readonly expiration?: number;
|
|
12
|
+
readonly metadata?: Metadata;
|
|
13
|
+
}
|
|
14
|
+
interface WorkersKvNamespaceListResult<Metadata, Key extends string = string> {
|
|
15
|
+
readonly list_complete: boolean;
|
|
16
|
+
readonly keys: readonly WorkersKvNamespaceListKey<Metadata, Key>[];
|
|
17
|
+
readonly cursor?: string;
|
|
18
|
+
}
|
|
19
|
+
interface WorkersKvNamespaceListOptions {
|
|
20
|
+
readonly limit?: number;
|
|
21
|
+
readonly prefix?: string | null;
|
|
22
|
+
readonly cursor?: string | null;
|
|
23
|
+
}
|
|
24
|
+
interface WorkersKvNamespacePutOptions {
|
|
25
|
+
readonly expiration?: number;
|
|
26
|
+
readonly expirationTtl?: number;
|
|
27
|
+
readonly metadata?: unknown;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Minimal Cloudflare Workers KV binding shape used by this package.
|
|
31
|
+
* Compatible with both `@cloudflare/workers-types` and `wrangler types`
|
|
32
|
+
* generated declarations.
|
|
33
|
+
* @since 2.0.12
|
|
34
|
+
*/
|
|
35
|
+
interface WorkersKvNamespaceLike<Key extends string = string> {
|
|
36
|
+
get(key: Key): Promise<string | null>;
|
|
37
|
+
get<ExpectedValue = unknown>(key: Key, type: "json"): Promise<ExpectedValue | null>;
|
|
38
|
+
getWithMetadata<Metadata = unknown>(key: Key): Promise<WorkersKvNamespaceGetWithMetadataResult<string, Metadata>>;
|
|
39
|
+
getWithMetadata<ExpectedValue = unknown, Metadata = unknown>(key: Key, type: "json"): Promise<WorkersKvNamespaceGetWithMetadataResult<ExpectedValue, Metadata>>;
|
|
40
|
+
put(key: Key, value: string, options?: WorkersKvNamespacePutOptions): Promise<void>;
|
|
41
|
+
delete(key: Key): Promise<void>;
|
|
42
|
+
list<Metadata = unknown>(options?: WorkersKvNamespaceListOptions): Promise<WorkersKvNamespaceListResult<Metadata, Key>>;
|
|
43
|
+
}
|
|
5
44
|
/**
|
|
6
45
|
* Result from {@link WorkersMessageQueue.processMessage}.
|
|
7
46
|
* @since 2.0.0
|
|
@@ -39,7 +78,7 @@ interface ProcessMessageResult {
|
|
|
39
78
|
*/
|
|
40
79
|
declare class WorkersKvStore implements KvStore {
|
|
41
80
|
#private;
|
|
42
|
-
constructor(namespace:
|
|
81
|
+
constructor(namespace: WorkersKvNamespaceLike<string>);
|
|
43
82
|
get<T = unknown>(key: KvKey): Promise<T | undefined>;
|
|
44
83
|
set(key: KvKey, value: unknown, options?: KvStoreSetOptions): Promise<void>;
|
|
45
84
|
delete(key: KvKey): Promise<void>;
|
|
@@ -62,7 +101,7 @@ interface WorkersMessageQueueOptions {
|
|
|
62
101
|
* guarantees are best-effort. For strict ordering requirements, consider
|
|
63
102
|
* using Durable Objects.
|
|
64
103
|
*/
|
|
65
|
-
readonly orderingKv?:
|
|
104
|
+
readonly orderingKv?: WorkersKvNamespaceLike<string>;
|
|
66
105
|
/**
|
|
67
106
|
* The prefix for ordering key lock keys. Defaults to `"__fedify_ordering_"`.
|
|
68
107
|
* @default `"__fedify_ordering_"`
|
|
@@ -145,4 +184,4 @@ declare class WorkersMessageQueue implements MessageQueue {
|
|
|
145
184
|
listen(_handler: (message: any) => Promise<void> | void, _options?: MessageQueueListenOptions): Promise<void>;
|
|
146
185
|
}
|
|
147
186
|
//#endregion
|
|
148
|
-
export { ProcessMessageResult, WorkersKvStore, WorkersMessageQueue, WorkersMessageQueueOptions };
|
|
187
|
+
export { ProcessMessageResult, WorkersKvNamespaceLike, WorkersKvStore, WorkersMessageQueue, WorkersMessageQueueOptions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/cfworkers",
|
|
3
|
-
"version": "2.2.0-dev.
|
|
3
|
+
"version": "2.2.0-dev.681+db2766de",
|
|
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.2.0-dev.
|
|
55
|
+
"@fedify/fedify": "^2.2.0-dev.681+db2766de"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@cloudflare/vitest-pool-workers": "^0.8.31",
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"build:self": "tsdown",
|
|
66
66
|
"build": "pnpm --filter @fedify/cfworkers... run build:self",
|
|
67
67
|
"prepublish": "pnpm build",
|
|
68
|
-
"
|
|
68
|
+
"pretest": "pnpm build",
|
|
69
|
+
"test": "tsc -p test/typecheck/tsconfig.json --noEmit && vitest run"
|
|
69
70
|
}
|
|
70
71
|
}
|