@fedify/cfworkers 2.0.0-dev.1690 → 2.0.0-dev.170
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/LICENSE +1 -1
- package/README.md +25 -19
- package/dist/mod.d.ts +7 -2
- package/dist/mod.js +38 -0
- package/package.json +8 -5
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!-- deno-fmt-ignore-file -->
|
|
2
2
|
|
|
3
3
|
@fedify/cfworkers: Adapt Fedify with Cloudflare Workers
|
|
4
|
-
|
|
4
|
+
=======================================================
|
|
5
5
|
|
|
6
6
|
[![JSR][JSR badge]][JSR]
|
|
7
7
|
[![npm][npm badge]][npm]
|
|
@@ -47,6 +47,20 @@ export default {
|
|
|
47
47
|
}>;
|
|
48
48
|
~~~~
|
|
49
49
|
|
|
50
|
+
[JSR badge]: https://jsr.io/badges/@fedify/cfworkers
|
|
51
|
+
[JSR]: https://jsr.io/@fedify/cfworkers
|
|
52
|
+
[npm badge]: https://img.shields.io/npm/v/@fedify/cfworkers?logo=npm
|
|
53
|
+
[npm]: https://www.npmjs.com/package/@fedify/cfworkers
|
|
54
|
+
[@fedify@hollo.social badge]: https://fedi-badge.deno.dev/@fedify@hollo.social/followers.svg
|
|
55
|
+
[@fedify@hollo.social]: https://hollo.social/@fedify
|
|
56
|
+
[Fedify]: https://fedify.dev/
|
|
57
|
+
[`KvStore`]: https://jsr.io/@fedify/fedify/doc/federation/~/KvStore
|
|
58
|
+
[`MessageQueue`]: https://jsr.io/@fedify/fedify/doc/federation/~/MessageQueue
|
|
59
|
+
[Cloudflare Workers]: https://workers.cloudflare.com/
|
|
60
|
+
[`WorkersKvStore`]: https://jsr.io/@fedify/cfworkers/doc/~/WorkersKvStore
|
|
61
|
+
[`WorkersMessageQueue`]: https://jsr.io/@fedify/cfworkers/doc/~/WorkersMessageQueue
|
|
62
|
+
|
|
63
|
+
|
|
50
64
|
`WorkersKvStore`
|
|
51
65
|
----------------
|
|
52
66
|
|
|
@@ -55,6 +69,9 @@ that uses Cloudflare's built-in [Cloudflare Workers KV] API. It provides
|
|
|
55
69
|
persistent storage and good performance for Cloudflare Workers environments.
|
|
56
70
|
It's suitable for production use in Cloudflare Workers applications.
|
|
57
71
|
|
|
72
|
+
[Cloudflare Workers KV]: https://developers.cloudflare.com/kv/
|
|
73
|
+
|
|
74
|
+
|
|
58
75
|
`WorkersMessageQueue`
|
|
59
76
|
---------------------
|
|
60
77
|
|
|
@@ -65,9 +82,10 @@ Cloudflare Workers environments. It requires a Cloudflare Queues setup and
|
|
|
65
82
|
management.
|
|
66
83
|
|
|
67
84
|
> [!NOTE]
|
|
68
|
-
> Since your `KVNamespace` and `Queue` are not bound to global variables, but
|
|
69
|
-
> passed as arguments to the `fetch()` and `queue()` methods, you need
|
|
70
|
-
> your `Federation` object inside these methods, rather than at
|
|
85
|
+
> Since your `KVNamespace` and `Queue` are not bound to global variables, but
|
|
86
|
+
> rather passed as arguments to the `fetch()` and `queue()` methods, you need
|
|
87
|
+
> to instantiate your `Federation` object inside these methods, rather than at
|
|
88
|
+
> the top level.
|
|
71
89
|
>
|
|
72
90
|
> For better organization, you probably want to use a builder pattern to
|
|
73
91
|
> register your dispatchers and listeners before instantiating the `Federation`
|
|
@@ -83,6 +101,9 @@ management.
|
|
|
83
101
|
> process the messages. The `queue()` method is the only way to consume
|
|
84
102
|
> messages from the queue in Cloudflare Workers.
|
|
85
103
|
|
|
104
|
+
[Cloudflare Queues]: https://developers.cloudflare.com/queues/
|
|
105
|
+
|
|
106
|
+
|
|
86
107
|
Installation
|
|
87
108
|
------------
|
|
88
109
|
|
|
@@ -93,18 +114,3 @@ pnpm add @fedify/cfworkers # pnpm
|
|
|
93
114
|
yarn add @fedify/cfworkers # Yarn
|
|
94
115
|
bun add @fedify/cfworkers # Bun
|
|
95
116
|
~~~~
|
|
96
|
-
|
|
97
|
-
[JSR]: https://jsr.io/@fedify/cfworkers
|
|
98
|
-
[JSR badge]: https://jsr.io/badges/@fedify/cfworkers
|
|
99
|
-
[npm]: https://www.npmjs.com/package/@fedify/cfworkers
|
|
100
|
-
[npm badge]: https://img.shields.io/npm/v/@fedify/cfworkers?logo=npm
|
|
101
|
-
[@fedify@hollo.social badge]: https://fedi-badge.deno.dev/@fedify@hollo.social/followers.svg
|
|
102
|
-
[@fedify@hollo.social]: https://hollo.social/@fedify
|
|
103
|
-
[Fedify]: https://fedify.dev/
|
|
104
|
-
[`KvStore`]: https://jsr.io/@fedify/fedify/doc/federation/~/KvStore
|
|
105
|
-
[`MessageQueue`]: https://jsr.io/@fedify/fedify/doc/federation/~/MessageQueue
|
|
106
|
-
[`WorkersKvStore`]: https://jsr.io/@fedify/cfworkers/doc/~/WorkersKvStore
|
|
107
|
-
[`WorkersMessageQueue`]: https://jsr.io/@fedify/cfworkers/doc/~/WorkersMessageQueue
|
|
108
|
-
[Cloudflare Workers]: https://workers.cloudflare.com/
|
|
109
|
-
[Cloudflare Workers KV]: https://developers.cloudflare.com/kv/
|
|
110
|
-
[Cloudflare Queues]: https://developers.cloudflare.com/queues/
|
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
|
|
@@ -43,7 +48,7 @@ declare class WorkersMessageQueue implements MessageQueue {
|
|
|
43
48
|
readonly nativeRetrial = true;
|
|
44
49
|
constructor(queue: Queue);
|
|
45
50
|
enqueue(message: any, options?: MessageQueueEnqueueOptions): Promise<void>;
|
|
46
|
-
enqueueMany(messages: any[], options?: MessageQueueEnqueueOptions): Promise<void>;
|
|
51
|
+
enqueueMany(messages: readonly any[], options?: MessageQueueEnqueueOptions): Promise<void>;
|
|
47
52
|
listen(_handler: (message: any) => Promise<void> | void, _options?: MessageQueueListenOptions): Promise<void>;
|
|
48
53
|
}
|
|
49
54
|
//#endregion
|
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.
|
|
3
|
+
"version": "2.0.0-dev.170+a03fedcd",
|
|
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.
|
|
55
|
-
"@fedify/fedify": "^2.0.0-dev.
|
|
54
|
+
"@cloudflare/workers-types": "^4.20250906.0",
|
|
55
|
+
"@fedify/fedify": "^2.0.0-dev.170+a03fedcd"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
+
"@cloudflare/vitest-pool-workers": "^0.8.31",
|
|
58
59
|
"tsdown": "^0.12.9",
|
|
59
|
-
"typescript": "^5.9.
|
|
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": "
|
|
67
|
+
"test": "vitest run"
|
|
65
68
|
}
|
|
66
69
|
}
|