@fedify/fedify 2.0.0-pr.467.1876 → 2.0.0-pr.469.1873
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/{actor-CsH6QBYT.js → actor-Bo3uuvwH.js} +185 -185
- package/dist/{actor-D1LkZWVU.js → actor-DhFfLv7K.js} +1 -1
- package/dist/{actor-9gjVpXgd.cjs → actor-DoaVs0vL.cjs} +185 -185
- package/dist/{builder-DCBCGtfN.js → builder-DFaO3_4-.js} +3 -3
- package/dist/compat/mod.d.cts +3 -2
- package/dist/compat/mod.d.ts +3 -2
- package/dist/compat/transformers.test.js +14 -14
- package/dist/{context-V-XS2_6O.d.ts → context-DG0huGW-.d.ts} +3 -140
- package/dist/{context-PxGADCsD.d.cts → context-DJ8aSy2Q.d.cts} +3 -140
- package/dist/denokv-CCssOzMJ.js +57 -0
- package/dist/{docloader-BaWIuRb2.js → docloader-B1AZ1LMA.js} +2 -2
- package/dist/{esm-uX3RtJS9.js → esm-CbckHird.js} +1 -1
- package/dist/federation/builder.test.js +4 -4
- package/dist/federation/collection.test.js +2 -2
- package/dist/federation/handler.test.js +15 -15
- package/dist/federation/idempotency.test.js +15 -15
- package/dist/federation/inbox.test.js +3 -3
- package/dist/federation/keycache.test.js +3 -3
- package/dist/federation/kv.test.js +2 -2
- package/dist/federation/middleware.test.js +16 -16
- package/dist/federation/mod.cjs +7 -7
- package/dist/federation/mod.d.cts +3 -2
- package/dist/federation/mod.d.ts +3 -2
- package/dist/federation/mod.js +7 -7
- package/dist/federation/mq.test.js +4 -6
- package/dist/federation/negotiation.test.js +2 -2
- package/dist/federation/retry.test.js +2 -2
- package/dist/federation/router.test.js +2 -2
- package/dist/federation/send.test.js +9 -9
- package/dist/{http-zanXjqHu.cjs → http-D27ZccIJ.cjs} +2 -2
- package/dist/{http-C5NpY8dE.js → http-D8SvAGVC.js} +2 -2
- package/dist/{http-Cw6Nfbii.js → http-nnaaa9xj.js} +2 -2
- package/dist/{inbox-Bu3THMpw.js → inbox-C5M1_a0k.js} +1 -1
- package/dist/{key-KT2Sua_C.js → key-bc3A8THw.js} +2 -2
- package/dist/{keycache-CH77mwdO.js → keycache-CpTjHRpy.js} +1 -1
- package/dist/{keys-DM8I6W_Z.js → keys-D6W2Pnoh.js} +1 -1
- package/dist/{kv-cache-DspkH6f2.js → kv-cache-B_RVzls5.js} +1 -1
- package/dist/{kv-cache-DxziE8JZ.cjs → kv-cache-CZcZLaEo.cjs} +1 -1
- package/dist/{ld-RF_UxhNp.js → ld-D5Vg307g.js} +2 -2
- package/dist/{lookup-D029Hgmr.js → lookup-BBrk-_5k.js} +191 -186
- package/dist/{lookup-EXeITSkB.js → lookup-BXY5QJif.js} +7 -2
- package/dist/{lookup-ZMUieFn0.cjs → lookup-DO7ZeFb2.cjs} +7 -2
- package/dist/middleware-BU2XnCCI.js +15 -0
- package/dist/{middleware-CI-4cLU9.js → middleware-CU0RJROn.js} +11 -11
- package/dist/middleware-D4qQ6MLq.cjs +15 -0
- package/dist/middleware-DEu9Xuza.js +26 -0
- package/dist/{middleware-CMT8W2oG.cjs → middleware-Dy7xPuu-.cjs} +7 -7
- package/dist/{middleware-C32-qFyf.js → middleware-RgDZByG7.js} +7 -7
- package/dist/{mod-Cdo6SYlJ.d.ts → mod-BoHnwOCs.d.ts} +1 -1
- package/dist/{mod-BoRKfJPE.d.cts → mod-DJcZDvjA.d.cts} +1 -1
- package/dist/mod.cjs +7 -7
- package/dist/mod.d.cts +6 -5
- package/dist/mod.d.ts +6 -5
- package/dist/mod.js +7 -7
- package/dist/mq-CUKlBw08.d.ts +143 -0
- package/dist/mq-DcJPkXD5.d.cts +140 -0
- package/dist/nodeinfo/client.test.js +3 -3
- package/dist/nodeinfo/handler.test.js +14 -14
- package/dist/nodeinfo/mod.d.cts +1 -1
- package/dist/nodeinfo/mod.d.ts +1 -1
- package/dist/nodeinfo/types.test.js +2 -2
- package/dist/{owner-6JbsaBQB.js → owner-DSDpCSms.js} +2 -2
- package/dist/{proof-D8SPvADT.js → proof-4L3D-iT4.js} +3 -3
- package/dist/{proof-gHlNO1tx.js → proof-Bvu8zaM1.js} +2 -2
- package/dist/{proof-CB7YKfl6.cjs → proof-C1-VSUNW.cjs} +3 -3
- package/dist/{send-CmpkYTnR.js → send-Cr3PSs0N.js} +2 -2
- package/dist/sig/http.test.js +7 -7
- package/dist/sig/key.test.js +5 -5
- package/dist/sig/ld.test.js +6 -6
- package/dist/sig/mod.cjs +4 -4
- package/dist/sig/mod.d.cts +1 -1
- package/dist/sig/mod.d.ts +1 -1
- package/dist/sig/mod.js +4 -4
- package/dist/sig/owner.test.js +6 -6
- package/dist/sig/proof.test.js +6 -6
- package/dist/testing/docloader.test.js +2 -2
- package/dist/testing/mod.js +2 -2
- package/dist/{testing-BJ493d9l.js → testing-Bw9AfLxQ.js} +1 -1
- package/dist/utils/docloader.test.js +8 -8
- package/dist/utils/kv-cache.test.js +2 -2
- package/dist/utils/mod.cjs +4 -4
- package/dist/utils/mod.d.cts +1 -1
- package/dist/utils/mod.d.ts +1 -1
- package/dist/utils/mod.js +4 -4
- package/dist/vocab/actor.test.js +4 -4
- package/dist/vocab/lookup.test.js +3 -3
- package/dist/vocab/mod.cjs +3 -3
- package/dist/vocab/mod.js +3 -3
- package/dist/vocab/type.test.js +2 -2
- package/dist/vocab/vocab.test.js +3 -3
- package/dist/{vocab-BY_op-IW.js → vocab-B74bq08l.js} +2 -2
- package/dist/{vocab-I0FskT0s.cjs → vocab-HJLl6-1F.cjs} +2 -2
- package/dist/webfinger/handler.test.js +14 -14
- package/dist/webfinger/lookup.test.js +3 -3
- package/dist/webfinger/mod.cjs +1 -1
- package/dist/webfinger/mod.js +1 -1
- package/dist/x/cfworkers.cjs +100 -0
- package/dist/x/cfworkers.d.cts +59 -0
- package/dist/x/cfworkers.d.ts +61 -0
- package/dist/x/cfworkers.js +98 -0
- package/dist/x/cfworkers.test.d.ts +3 -0
- package/dist/x/cfworkers.test.js +177 -0
- package/dist/x/hono.cjs +61 -0
- package/dist/x/hono.d.cts +53 -0
- package/dist/x/hono.d.ts +55 -0
- package/dist/x/hono.js +60 -0
- package/dist/x/sveltekit.cjs +69 -0
- package/dist/x/sveltekit.d.cts +45 -0
- package/dist/x/sveltekit.d.ts +47 -0
- package/dist/x/sveltekit.js +68 -0
- package/package.json +34 -3
- package/dist/middleware-BuhoXDtM.js +0 -15
- package/dist/middleware-C2X56NUR.cjs +0 -15
- package/dist/middleware-DWijkoj4.js +0 -26
- /package/dist/{mod-DMpuiKXi.d.cts → mod-0noXw66R.d.cts} +0 -0
- /package/dist/{mod-D5Z2tISD.d.ts → mod-B2iOw50L.d.ts} +0 -0
- /package/dist/{mod-aAE2wOWV.d.ts → mod-B9M-8jm2.d.ts} +0 -0
- /package/dist/{mod-CcDPcLJW.d.cts → mod-C2tOeRkN.d.cts} +0 -0
- /package/dist/{mod-DgxG-byT.d.cts → mod-DgdBYYa0.d.cts} +0 -0
- /package/dist/{mod-bjzj5QIb.d.ts → mod-xIj-IT58.d.ts} +0 -0
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
4
4
|
|
|
5
5
|
const require_chunk = require('./chunk-DqRYRqnO.cjs');
|
|
6
|
-
const require_lookup = require('./lookup-
|
|
7
|
-
const require_actor = require('./actor-
|
|
6
|
+
const require_lookup = require('./lookup-DO7ZeFb2.cjs');
|
|
7
|
+
const require_actor = require('./actor-DoaVs0vL.cjs');
|
|
8
8
|
const __logtape_logtape = require_chunk.__toESM(require("@logtape/logtape"));
|
|
9
9
|
const __opentelemetry_api = require_chunk.__toESM(require("@opentelemetry/api"));
|
|
10
10
|
const __fedify_vocab_runtime = require_chunk.__toESM(require("@fedify/vocab-runtime"));
|
|
@@ -3,30 +3,30 @@
|
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
|
4
4
|
globalThis.addEventListener = () => {};
|
|
5
5
|
|
|
6
|
-
import { Image, Link, Person } from "../lookup-
|
|
6
|
+
import { Image, Link, Person } from "../lookup-BBrk-_5k.js";
|
|
7
7
|
import { assertEquals } from "../assert_equals-DSbWqCm3.js";
|
|
8
8
|
import "../assert-MZs1qjMx.js";
|
|
9
9
|
import "../assert_instance_of-DHz7EHNU.js";
|
|
10
10
|
import { MemoryKvStore } from "../kv-CRZrzyXm.js";
|
|
11
|
-
import { createFederation, handleWebFinger } from "../middleware-
|
|
11
|
+
import { createFederation, handleWebFinger } from "../middleware-CU0RJROn.js";
|
|
12
12
|
import "../client-pY7-3icS.js";
|
|
13
13
|
import "../types-C2XVl6gj.js";
|
|
14
|
-
import "../actor-
|
|
15
|
-
import "../key-
|
|
16
|
-
import "../http-
|
|
17
|
-
import "../ld-
|
|
18
|
-
import "../owner-
|
|
19
|
-
import "../proof-
|
|
20
|
-
import "../docloader-
|
|
14
|
+
import "../actor-DhFfLv7K.js";
|
|
15
|
+
import "../key-bc3A8THw.js";
|
|
16
|
+
import "../http-D8SvAGVC.js";
|
|
17
|
+
import "../ld-D5Vg307g.js";
|
|
18
|
+
import "../owner-DSDpCSms.js";
|
|
19
|
+
import "../proof-Bvu8zaM1.js";
|
|
20
|
+
import "../docloader-B1AZ1LMA.js";
|
|
21
21
|
import "../kv-cache-DN9pfMBe.js";
|
|
22
|
-
import "../inbox-
|
|
23
|
-
import "../builder-
|
|
22
|
+
import "../inbox-C5M1_a0k.js";
|
|
23
|
+
import "../builder-DFaO3_4-.js";
|
|
24
24
|
import "../collection-BzWsN9pB.js";
|
|
25
|
-
import "../keycache-
|
|
25
|
+
import "../keycache-CpTjHRpy.js";
|
|
26
26
|
import "../negotiation-C4nFufNk.js";
|
|
27
27
|
import "../retry-CfF8Gn4d.js";
|
|
28
|
-
import "../send-
|
|
29
|
-
import { createRequestContext, test } from "../testing-
|
|
28
|
+
import "../send-Cr3PSs0N.js";
|
|
29
|
+
import { createRequestContext, test } from "../testing-Bw9AfLxQ.js";
|
|
30
30
|
import "../std__assert-DWivtrGR.js";
|
|
31
31
|
import "../assert_rejects-Ce45JcFg.js";
|
|
32
32
|
import "../assert_throws-BNXdRGWP.js";
|
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
|
4
4
|
globalThis.addEventListener = () => {};
|
|
5
5
|
|
|
6
|
-
import { lookupWebFinger } from "../lookup-
|
|
6
|
+
import { lookupWebFinger } from "../lookup-BBrk-_5k.js";
|
|
7
7
|
import { assertEquals } from "../assert_equals-DSbWqCm3.js";
|
|
8
8
|
import "../assert-MZs1qjMx.js";
|
|
9
9
|
import "../assert_instance_of-DHz7EHNU.js";
|
|
10
|
-
import { test } from "../testing-
|
|
10
|
+
import { test } from "../testing-Bw9AfLxQ.js";
|
|
11
11
|
import "../std__assert-DWivtrGR.js";
|
|
12
12
|
import "../assert_rejects-Ce45JcFg.js";
|
|
13
13
|
import "../assert_throws-BNXdRGWP.js";
|
|
14
14
|
import "../assert_not_equals-C80BG-_5.js";
|
|
15
|
-
import { esm_default } from "../esm-
|
|
15
|
+
import { esm_default } from "../esm-CbckHird.js";
|
|
16
16
|
import { withTimeout } from "es-toolkit";
|
|
17
17
|
|
|
18
18
|
//#region src/webfinger/lookup.test.ts
|
package/dist/webfinger/mod.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const { Temporal } = require("@js-temporal/polyfill");
|
|
3
3
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
4
4
|
|
|
5
|
-
const require_lookup = require('../lookup-
|
|
5
|
+
const require_lookup = require('../lookup-DO7ZeFb2.cjs');
|
|
6
6
|
require('../webfinger-vAtLmxOF.cjs');
|
|
7
7
|
|
|
8
8
|
exports.lookupWebFinger = require_lookup.lookupWebFinger;
|
package/dist/webfinger/mod.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Temporal } from "@js-temporal/polyfill";
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
|
4
4
|
|
|
5
|
-
import { lookupWebFinger } from "../lookup-
|
|
5
|
+
import { lookupWebFinger } from "../lookup-BXY5QJif.js";
|
|
6
6
|
import "../webfinger-C72Y8lrh.js";
|
|
7
7
|
|
|
8
8
|
export { lookupWebFinger };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
|
|
2
|
+
const { Temporal } = require("@js-temporal/polyfill");
|
|
3
|
+
const { URLPattern } = require("urlpattern-polyfill");
|
|
4
|
+
|
|
5
|
+
const require_chunk = require('../chunk-DqRYRqnO.cjs');
|
|
6
|
+
const __logtape_logtape = require_chunk.__toESM(require("@logtape/logtape"));
|
|
7
|
+
|
|
8
|
+
//#region src/x/cfworkers.ts
|
|
9
|
+
/**
|
|
10
|
+
* Implementation of the {@link KvStore} interface for Cloudflare Workers KV
|
|
11
|
+
* binding. This class provides a wrapper around Cloudflare's KV namespace to
|
|
12
|
+
* store and retrieve JSON-serializable values using structured keys.
|
|
13
|
+
*
|
|
14
|
+
* Note that this implementation does not support the {@link KvStore.cas}
|
|
15
|
+
* operation, as Cloudflare Workers KV does not support atomic compare-and-swap
|
|
16
|
+
* operations. If you need this functionality, consider using a different
|
|
17
|
+
* key–value store that supports atomic operations.
|
|
18
|
+
*
|
|
19
|
+
* @deprecated This class has been moved to `@fedify/cfworkers` package.
|
|
20
|
+
* Import `WorkersKvStore` from `@fedify/cfworkers` instead.
|
|
21
|
+
* This class will be removed in Fedify v2.0.
|
|
22
|
+
* @since 1.6.0
|
|
23
|
+
*/
|
|
24
|
+
var WorkersKvStore = class {
|
|
25
|
+
#namespace;
|
|
26
|
+
constructor(namespace) {
|
|
27
|
+
const logger = (0, __logtape_logtape.getLogger)(["fedify", "cfworkers"]);
|
|
28
|
+
logger.warn("The `@fedify/fedify/x/cfworkers` module is deprecated; use `WorkersKvStore` from `@fedify/cfworkers` package instead.");
|
|
29
|
+
this.#namespace = namespace;
|
|
30
|
+
}
|
|
31
|
+
#encodeKey(key) {
|
|
32
|
+
return JSON.stringify(key);
|
|
33
|
+
}
|
|
34
|
+
async get(key) {
|
|
35
|
+
const encodedKey = this.#encodeKey(key);
|
|
36
|
+
const { value, metadata } = await this.#namespace.getWithMetadata(encodedKey, "json");
|
|
37
|
+
return metadata == null || metadata.expires < Date.now() ? void 0 : value;
|
|
38
|
+
}
|
|
39
|
+
async set(key, value, options) {
|
|
40
|
+
const encodedKey = this.#encodeKey(key);
|
|
41
|
+
const metadata = options?.ttl == null ? {} : { expires: Date.now() + options.ttl.total("milliseconds") };
|
|
42
|
+
await this.#namespace.put(encodedKey, JSON.stringify(value), options?.ttl == null ? { metadata } : {
|
|
43
|
+
expirationTtl: Math.max(options.ttl.total("seconds"), 60),
|
|
44
|
+
metadata
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
delete(key) {
|
|
48
|
+
return this.#namespace.delete(this.#encodeKey(key));
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Implementation of the {@link MessageQueue} interface for Cloudflare
|
|
53
|
+
* Workers Queues binding. This class provides a wrapper around Cloudflare's
|
|
54
|
+
* Queues to send messages to a queue.
|
|
55
|
+
*
|
|
56
|
+
* Note that this implementation does not support the `listen()` method,
|
|
57
|
+
* as Cloudflare Workers Queues do not support message consumption in the same
|
|
58
|
+
* way as other message queue systems. Instead, you should use
|
|
59
|
+
* the {@link Federation.processQueuedTask} method to process messages
|
|
60
|
+
* passed to the queue.
|
|
61
|
+
*
|
|
62
|
+
* @deprecated This class has been moved to `@fedify/cfworkers` package.
|
|
63
|
+
* Import `WorkersMessageQueue` from `@fedify/cfworkers` instead.
|
|
64
|
+
* This class will be removed in Fedify v2.0.
|
|
65
|
+
* @since 1.6.0
|
|
66
|
+
*/
|
|
67
|
+
var WorkersMessageQueue = class {
|
|
68
|
+
#queue;
|
|
69
|
+
/**
|
|
70
|
+
* Cloudflare Queues provide automatic retry with exponential backoff
|
|
71
|
+
* and Dead Letter Queues.
|
|
72
|
+
* @since 1.7.0
|
|
73
|
+
*/
|
|
74
|
+
nativeRetrial = true;
|
|
75
|
+
constructor(queue) {
|
|
76
|
+
const logger = (0, __logtape_logtape.getLogger)(["fedify", "cfworkers"]);
|
|
77
|
+
logger.warn("The `@fedify/fedify/x/cfworkers` module is deprecated; use `WorkersMessageQueue` from `@fedify/cfworkers` package instead.");
|
|
78
|
+
this.#queue = queue;
|
|
79
|
+
}
|
|
80
|
+
enqueue(message, options) {
|
|
81
|
+
return this.#queue.send(message, {
|
|
82
|
+
contentType: "json",
|
|
83
|
+
delaySeconds: options?.delay?.total("seconds") ?? 0
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
enqueueMany(messages, options) {
|
|
87
|
+
const requests = messages.map((msg) => ({
|
|
88
|
+
body: msg,
|
|
89
|
+
contentType: "json"
|
|
90
|
+
}));
|
|
91
|
+
return this.#queue.sendBatch(requests, { delaySeconds: options?.delay?.total("seconds") ?? 0 });
|
|
92
|
+
}
|
|
93
|
+
listen(_handler, _options) {
|
|
94
|
+
throw new TypeError("WorkersMessageQueue does not support listen(). Use Federation.processQueuedTask() method instead.");
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
exports.WorkersKvStore = WorkersKvStore;
|
|
100
|
+
exports.WorkersMessageQueue = WorkersMessageQueue;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { KvKey, KvStore, KvStoreSetOptions } from "../kv-Bxr0Q87_.cjs";
|
|
2
|
+
import { MessageQueue, MessageQueueEnqueueOptions, MessageQueueListenOptions } from "../mq-DcJPkXD5.cjs";
|
|
3
|
+
import { KVNamespace, Queue } from "@cloudflare/workers-types/experimental";
|
|
4
|
+
|
|
5
|
+
//#region src/x/cfworkers.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Implementation of the {@link KvStore} interface for Cloudflare Workers KV
|
|
9
|
+
* binding. This class provides a wrapper around Cloudflare's KV namespace to
|
|
10
|
+
* store and retrieve JSON-serializable values using structured keys.
|
|
11
|
+
*
|
|
12
|
+
* Note that this implementation does not support the {@link KvStore.cas}
|
|
13
|
+
* operation, as Cloudflare Workers KV does not support atomic compare-and-swap
|
|
14
|
+
* operations. If you need this functionality, consider using a different
|
|
15
|
+
* key–value store that supports atomic operations.
|
|
16
|
+
*
|
|
17
|
+
* @deprecated This class has been moved to `@fedify/cfworkers` package.
|
|
18
|
+
* Import `WorkersKvStore` from `@fedify/cfworkers` instead.
|
|
19
|
+
* This class will be removed in Fedify v2.0.
|
|
20
|
+
* @since 1.6.0
|
|
21
|
+
*/
|
|
22
|
+
declare class WorkersKvStore implements KvStore {
|
|
23
|
+
#private;
|
|
24
|
+
constructor(namespace: KVNamespace<string>);
|
|
25
|
+
get<T = unknown>(key: KvKey): Promise<T | undefined>;
|
|
26
|
+
set(key: KvKey, value: unknown, options?: KvStoreSetOptions): Promise<void>;
|
|
27
|
+
delete(key: KvKey): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Implementation of the {@link MessageQueue} interface for Cloudflare
|
|
31
|
+
* Workers Queues binding. This class provides a wrapper around Cloudflare's
|
|
32
|
+
* Queues to send messages to a queue.
|
|
33
|
+
*
|
|
34
|
+
* Note that this implementation does not support the `listen()` method,
|
|
35
|
+
* as Cloudflare Workers Queues do not support message consumption in the same
|
|
36
|
+
* way as other message queue systems. Instead, you should use
|
|
37
|
+
* the {@link Federation.processQueuedTask} method to process messages
|
|
38
|
+
* passed to the queue.
|
|
39
|
+
*
|
|
40
|
+
* @deprecated This class has been moved to `@fedify/cfworkers` package.
|
|
41
|
+
* Import `WorkersMessageQueue` from `@fedify/cfworkers` instead.
|
|
42
|
+
* This class will be removed in Fedify v2.0.
|
|
43
|
+
* @since 1.6.0
|
|
44
|
+
*/
|
|
45
|
+
declare class WorkersMessageQueue implements MessageQueue {
|
|
46
|
+
#private;
|
|
47
|
+
/**
|
|
48
|
+
* Cloudflare Queues provide automatic retry with exponential backoff
|
|
49
|
+
* and Dead Letter Queues.
|
|
50
|
+
* @since 1.7.0
|
|
51
|
+
*/
|
|
52
|
+
readonly nativeRetrial = true;
|
|
53
|
+
constructor(queue: Queue);
|
|
54
|
+
enqueue(message: any, options?: MessageQueueEnqueueOptions): Promise<void>;
|
|
55
|
+
enqueueMany(messages: any[], options?: MessageQueueEnqueueOptions): Promise<void>;
|
|
56
|
+
listen(_handler: (message: any) => Promise<void> | void, _options?: MessageQueueListenOptions): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { WorkersKvStore, WorkersMessageQueue };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import { URLPattern } from "urlpattern-polyfill";
|
|
3
|
+
import { KvKey, KvStore, KvStoreSetOptions } from "../kv-BKNZ-Tb-.js";
|
|
4
|
+
import { MessageQueue, MessageQueueEnqueueOptions, MessageQueueListenOptions } from "../mq-CUKlBw08.js";
|
|
5
|
+
import { KVNamespace, Queue } from "@cloudflare/workers-types/experimental";
|
|
6
|
+
|
|
7
|
+
//#region src/x/cfworkers.d.ts
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Implementation of the {@link KvStore} interface for Cloudflare Workers KV
|
|
11
|
+
* binding. This class provides a wrapper around Cloudflare's KV namespace to
|
|
12
|
+
* store and retrieve JSON-serializable values using structured keys.
|
|
13
|
+
*
|
|
14
|
+
* Note that this implementation does not support the {@link KvStore.cas}
|
|
15
|
+
* operation, as Cloudflare Workers KV does not support atomic compare-and-swap
|
|
16
|
+
* operations. If you need this functionality, consider using a different
|
|
17
|
+
* key–value store that supports atomic operations.
|
|
18
|
+
*
|
|
19
|
+
* @deprecated This class has been moved to `@fedify/cfworkers` package.
|
|
20
|
+
* Import `WorkersKvStore` from `@fedify/cfworkers` instead.
|
|
21
|
+
* This class will be removed in Fedify v2.0.
|
|
22
|
+
* @since 1.6.0
|
|
23
|
+
*/
|
|
24
|
+
declare class WorkersKvStore implements KvStore {
|
|
25
|
+
#private;
|
|
26
|
+
constructor(namespace: KVNamespace<string>);
|
|
27
|
+
get<T = unknown>(key: KvKey): Promise<T | undefined>;
|
|
28
|
+
set(key: KvKey, value: unknown, options?: KvStoreSetOptions): Promise<void>;
|
|
29
|
+
delete(key: KvKey): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Implementation of the {@link MessageQueue} interface for Cloudflare
|
|
33
|
+
* Workers Queues binding. This class provides a wrapper around Cloudflare's
|
|
34
|
+
* Queues to send messages to a queue.
|
|
35
|
+
*
|
|
36
|
+
* Note that this implementation does not support the `listen()` method,
|
|
37
|
+
* as Cloudflare Workers Queues do not support message consumption in the same
|
|
38
|
+
* way as other message queue systems. Instead, you should use
|
|
39
|
+
* the {@link Federation.processQueuedTask} method to process messages
|
|
40
|
+
* passed to the queue.
|
|
41
|
+
*
|
|
42
|
+
* @deprecated This class has been moved to `@fedify/cfworkers` package.
|
|
43
|
+
* Import `WorkersMessageQueue` from `@fedify/cfworkers` instead.
|
|
44
|
+
* This class will be removed in Fedify v2.0.
|
|
45
|
+
* @since 1.6.0
|
|
46
|
+
*/
|
|
47
|
+
declare class WorkersMessageQueue implements MessageQueue {
|
|
48
|
+
#private;
|
|
49
|
+
/**
|
|
50
|
+
* Cloudflare Queues provide automatic retry with exponential backoff
|
|
51
|
+
* and Dead Letter Queues.
|
|
52
|
+
* @since 1.7.0
|
|
53
|
+
*/
|
|
54
|
+
readonly nativeRetrial = true;
|
|
55
|
+
constructor(queue: Queue);
|
|
56
|
+
enqueue(message: any, options?: MessageQueueEnqueueOptions): Promise<void>;
|
|
57
|
+
enqueueMany(messages: any[], options?: MessageQueueEnqueueOptions): Promise<void>;
|
|
58
|
+
listen(_handler: (message: any) => Promise<void> | void, _options?: MessageQueueListenOptions): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { WorkersKvStore, WorkersMessageQueue };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
import { URLPattern } from "urlpattern-polyfill";
|
|
4
|
+
|
|
5
|
+
import { getLogger } from "@logtape/logtape";
|
|
6
|
+
|
|
7
|
+
//#region src/x/cfworkers.ts
|
|
8
|
+
/**
|
|
9
|
+
* Implementation of the {@link KvStore} interface for Cloudflare Workers KV
|
|
10
|
+
* binding. This class provides a wrapper around Cloudflare's KV namespace to
|
|
11
|
+
* store and retrieve JSON-serializable values using structured keys.
|
|
12
|
+
*
|
|
13
|
+
* Note that this implementation does not support the {@link KvStore.cas}
|
|
14
|
+
* operation, as Cloudflare Workers KV does not support atomic compare-and-swap
|
|
15
|
+
* operations. If you need this functionality, consider using a different
|
|
16
|
+
* key–value store that supports atomic operations.
|
|
17
|
+
*
|
|
18
|
+
* @deprecated This class has been moved to `@fedify/cfworkers` package.
|
|
19
|
+
* Import `WorkersKvStore` from `@fedify/cfworkers` instead.
|
|
20
|
+
* This class will be removed in Fedify v2.0.
|
|
21
|
+
* @since 1.6.0
|
|
22
|
+
*/
|
|
23
|
+
var WorkersKvStore = class {
|
|
24
|
+
#namespace;
|
|
25
|
+
constructor(namespace) {
|
|
26
|
+
const logger = getLogger(["fedify", "cfworkers"]);
|
|
27
|
+
logger.warn("The `@fedify/fedify/x/cfworkers` module is deprecated; use `WorkersKvStore` from `@fedify/cfworkers` package instead.");
|
|
28
|
+
this.#namespace = namespace;
|
|
29
|
+
}
|
|
30
|
+
#encodeKey(key) {
|
|
31
|
+
return JSON.stringify(key);
|
|
32
|
+
}
|
|
33
|
+
async get(key) {
|
|
34
|
+
const encodedKey = this.#encodeKey(key);
|
|
35
|
+
const { value, metadata } = await this.#namespace.getWithMetadata(encodedKey, "json");
|
|
36
|
+
return metadata == null || metadata.expires < Date.now() ? void 0 : value;
|
|
37
|
+
}
|
|
38
|
+
async set(key, value, options) {
|
|
39
|
+
const encodedKey = this.#encodeKey(key);
|
|
40
|
+
const metadata = options?.ttl == null ? {} : { expires: Date.now() + options.ttl.total("milliseconds") };
|
|
41
|
+
await this.#namespace.put(encodedKey, JSON.stringify(value), options?.ttl == null ? { metadata } : {
|
|
42
|
+
expirationTtl: Math.max(options.ttl.total("seconds"), 60),
|
|
43
|
+
metadata
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
delete(key) {
|
|
47
|
+
return this.#namespace.delete(this.#encodeKey(key));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Implementation of the {@link MessageQueue} interface for Cloudflare
|
|
52
|
+
* Workers Queues binding. This class provides a wrapper around Cloudflare's
|
|
53
|
+
* Queues to send messages to a queue.
|
|
54
|
+
*
|
|
55
|
+
* Note that this implementation does not support the `listen()` method,
|
|
56
|
+
* as Cloudflare Workers Queues do not support message consumption in the same
|
|
57
|
+
* way as other message queue systems. Instead, you should use
|
|
58
|
+
* the {@link Federation.processQueuedTask} method to process messages
|
|
59
|
+
* passed to the queue.
|
|
60
|
+
*
|
|
61
|
+
* @deprecated This class has been moved to `@fedify/cfworkers` package.
|
|
62
|
+
* Import `WorkersMessageQueue` from `@fedify/cfworkers` instead.
|
|
63
|
+
* This class will be removed in Fedify v2.0.
|
|
64
|
+
* @since 1.6.0
|
|
65
|
+
*/
|
|
66
|
+
var WorkersMessageQueue = class {
|
|
67
|
+
#queue;
|
|
68
|
+
/**
|
|
69
|
+
* Cloudflare Queues provide automatic retry with exponential backoff
|
|
70
|
+
* and Dead Letter Queues.
|
|
71
|
+
* @since 1.7.0
|
|
72
|
+
*/
|
|
73
|
+
nativeRetrial = true;
|
|
74
|
+
constructor(queue) {
|
|
75
|
+
const logger = getLogger(["fedify", "cfworkers"]);
|
|
76
|
+
logger.warn("The `@fedify/fedify/x/cfworkers` module is deprecated; use `WorkersMessageQueue` from `@fedify/cfworkers` package instead.");
|
|
77
|
+
this.#queue = queue;
|
|
78
|
+
}
|
|
79
|
+
enqueue(message, options) {
|
|
80
|
+
return this.#queue.send(message, {
|
|
81
|
+
contentType: "json",
|
|
82
|
+
delaySeconds: options?.delay?.total("seconds") ?? 0
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
enqueueMany(messages, options) {
|
|
86
|
+
const requests = messages.map((msg) => ({
|
|
87
|
+
body: msg,
|
|
88
|
+
contentType: "json"
|
|
89
|
+
}));
|
|
90
|
+
return this.#queue.sendBatch(requests, { delaySeconds: options?.delay?.total("seconds") ?? 0 });
|
|
91
|
+
}
|
|
92
|
+
listen(_handler, _options) {
|
|
93
|
+
throw new TypeError("WorkersMessageQueue does not support listen(). Use Federation.processQueuedTask() method instead.");
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
export { WorkersKvStore, WorkersMessageQueue };
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
import { URLPattern } from "urlpattern-polyfill";
|
|
4
|
+
globalThis.addEventListener = () => {};
|
|
5
|
+
|
|
6
|
+
import "../lookup-BBrk-_5k.js";
|
|
7
|
+
import { assertEquals } from "../assert_equals-DSbWqCm3.js";
|
|
8
|
+
import "../assert-MZs1qjMx.js";
|
|
9
|
+
import "../assert_instance_of-DHz7EHNU.js";
|
|
10
|
+
import { test } from "../testing-Bw9AfLxQ.js";
|
|
11
|
+
import "../std__assert-DWivtrGR.js";
|
|
12
|
+
import "../assert_rejects-Ce45JcFg.js";
|
|
13
|
+
import "../assert_throws-BNXdRGWP.js";
|
|
14
|
+
import "../assert_not_equals-C80BG-_5.js";
|
|
15
|
+
import { delay } from "es-toolkit";
|
|
16
|
+
import { getLogger } from "@logtape/logtape";
|
|
17
|
+
|
|
18
|
+
//#region src/x/cfworkers.ts
|
|
19
|
+
/**
|
|
20
|
+
* Implementation of the {@link KvStore} interface for Cloudflare Workers KV
|
|
21
|
+
* binding. This class provides a wrapper around Cloudflare's KV namespace to
|
|
22
|
+
* store and retrieve JSON-serializable values using structured keys.
|
|
23
|
+
*
|
|
24
|
+
* Note that this implementation does not support the {@link KvStore.cas}
|
|
25
|
+
* operation, as Cloudflare Workers KV does not support atomic compare-and-swap
|
|
26
|
+
* operations. If you need this functionality, consider using a different
|
|
27
|
+
* key–value store that supports atomic operations.
|
|
28
|
+
*
|
|
29
|
+
* @deprecated This class has been moved to `@fedify/cfworkers` package.
|
|
30
|
+
* Import `WorkersKvStore` from `@fedify/cfworkers` instead.
|
|
31
|
+
* This class will be removed in Fedify v2.0.
|
|
32
|
+
* @since 1.6.0
|
|
33
|
+
*/
|
|
34
|
+
var WorkersKvStore = class {
|
|
35
|
+
#namespace;
|
|
36
|
+
constructor(namespace) {
|
|
37
|
+
const logger = getLogger(["fedify", "cfworkers"]);
|
|
38
|
+
logger.warn("The `@fedify/fedify/x/cfworkers` module is deprecated; use `WorkersKvStore` from `@fedify/cfworkers` package instead.");
|
|
39
|
+
this.#namespace = namespace;
|
|
40
|
+
}
|
|
41
|
+
#encodeKey(key) {
|
|
42
|
+
return JSON.stringify(key);
|
|
43
|
+
}
|
|
44
|
+
async get(key) {
|
|
45
|
+
const encodedKey = this.#encodeKey(key);
|
|
46
|
+
const { value, metadata } = await this.#namespace.getWithMetadata(encodedKey, "json");
|
|
47
|
+
return metadata == null || metadata.expires < Date.now() ? void 0 : value;
|
|
48
|
+
}
|
|
49
|
+
async set(key, value, options) {
|
|
50
|
+
const encodedKey = this.#encodeKey(key);
|
|
51
|
+
const metadata = options?.ttl == null ? {} : { expires: Date.now() + options.ttl.total("milliseconds") };
|
|
52
|
+
await this.#namespace.put(encodedKey, JSON.stringify(value), options?.ttl == null ? { metadata } : {
|
|
53
|
+
expirationTtl: Math.max(options.ttl.total("seconds"), 60),
|
|
54
|
+
metadata
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
delete(key) {
|
|
58
|
+
return this.#namespace.delete(this.#encodeKey(key));
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Implementation of the {@link MessageQueue} interface for Cloudflare
|
|
63
|
+
* Workers Queues binding. This class provides a wrapper around Cloudflare's
|
|
64
|
+
* Queues to send messages to a queue.
|
|
65
|
+
*
|
|
66
|
+
* Note that this implementation does not support the `listen()` method,
|
|
67
|
+
* as Cloudflare Workers Queues do not support message consumption in the same
|
|
68
|
+
* way as other message queue systems. Instead, you should use
|
|
69
|
+
* the {@link Federation.processQueuedTask} method to process messages
|
|
70
|
+
* passed to the queue.
|
|
71
|
+
*
|
|
72
|
+
* @deprecated This class has been moved to `@fedify/cfworkers` package.
|
|
73
|
+
* Import `WorkersMessageQueue` from `@fedify/cfworkers` instead.
|
|
74
|
+
* This class will be removed in Fedify v2.0.
|
|
75
|
+
* @since 1.6.0
|
|
76
|
+
*/
|
|
77
|
+
var WorkersMessageQueue = class {
|
|
78
|
+
#queue;
|
|
79
|
+
/**
|
|
80
|
+
* Cloudflare Queues provide automatic retry with exponential backoff
|
|
81
|
+
* and Dead Letter Queues.
|
|
82
|
+
* @since 1.7.0
|
|
83
|
+
*/
|
|
84
|
+
nativeRetrial = true;
|
|
85
|
+
constructor(queue) {
|
|
86
|
+
const logger = getLogger(["fedify", "cfworkers"]);
|
|
87
|
+
logger.warn("The `@fedify/fedify/x/cfworkers` module is deprecated; use `WorkersMessageQueue` from `@fedify/cfworkers` package instead.");
|
|
88
|
+
this.#queue = queue;
|
|
89
|
+
}
|
|
90
|
+
enqueue(message, options) {
|
|
91
|
+
return this.#queue.send(message, {
|
|
92
|
+
contentType: "json",
|
|
93
|
+
delaySeconds: options?.delay?.total("seconds") ?? 0
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
enqueueMany(messages, options) {
|
|
97
|
+
const requests = messages.map((msg) => ({
|
|
98
|
+
body: msg,
|
|
99
|
+
contentType: "json"
|
|
100
|
+
}));
|
|
101
|
+
return this.#queue.sendBatch(requests, { delaySeconds: options?.delay?.total("seconds") ?? 0 });
|
|
102
|
+
}
|
|
103
|
+
listen(_handler, _options) {
|
|
104
|
+
throw new TypeError("WorkersMessageQueue does not support listen(). Use Federation.processQueuedTask() method instead.");
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/x/cfworkers.test.ts
|
|
110
|
+
test({
|
|
111
|
+
name: "WorkersKvStore",
|
|
112
|
+
ignore: !("navigator" in globalThis && navigator.userAgent === "Cloudflare-Workers"),
|
|
113
|
+
async fn(t) {
|
|
114
|
+
const { env } = t;
|
|
115
|
+
const store = new WorkersKvStore(env.KV1);
|
|
116
|
+
await t.step("set() & get()", async () => {
|
|
117
|
+
await store.set(["foo", "bar"], {
|
|
118
|
+
foo: 1,
|
|
119
|
+
bar: 2
|
|
120
|
+
});
|
|
121
|
+
assertEquals(await store.get(["foo", "bar"]), {
|
|
122
|
+
foo: 1,
|
|
123
|
+
bar: 2
|
|
124
|
+
});
|
|
125
|
+
assertEquals(await store.get(["foo"]), void 0);
|
|
126
|
+
await store.set(["foo", "baz"], "baz", { ttl: Temporal.Duration.from({ seconds: 0 }) });
|
|
127
|
+
assertEquals(await store.get(["foo", "baz"]), void 0);
|
|
128
|
+
});
|
|
129
|
+
await t.step("delete()", async () => {
|
|
130
|
+
await store.delete(["foo", "bar"]);
|
|
131
|
+
assertEquals(await store.get(["foo", "bar"]), void 0);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
test({
|
|
136
|
+
name: "WorkersMessageQueue",
|
|
137
|
+
ignore: !("navigator" in globalThis && navigator.userAgent === "Cloudflare-Workers"),
|
|
138
|
+
async fn(t) {
|
|
139
|
+
const { env, messageBatches } = t;
|
|
140
|
+
const queue = new WorkersMessageQueue(env.Q1);
|
|
141
|
+
await queue.enqueue({
|
|
142
|
+
foo: 1,
|
|
143
|
+
bar: 2
|
|
144
|
+
});
|
|
145
|
+
await waitFor(() => messageBatches.length > 0, 5e3);
|
|
146
|
+
assertEquals(messageBatches.length, 1);
|
|
147
|
+
assertEquals(messageBatches[0].queue, "Q1");
|
|
148
|
+
assertEquals(messageBatches[0].messages.length, 1);
|
|
149
|
+
assertEquals(messageBatches[0].messages[0].body, {
|
|
150
|
+
foo: 1,
|
|
151
|
+
bar: 2
|
|
152
|
+
});
|
|
153
|
+
await queue.enqueue({
|
|
154
|
+
baz: 3,
|
|
155
|
+
qux: 4
|
|
156
|
+
}, { delay: Temporal.Duration.from({ seconds: 3 }) });
|
|
157
|
+
await delay(2e3);
|
|
158
|
+
assertEquals(messageBatches.length, 1);
|
|
159
|
+
await waitFor(() => messageBatches.length > 1, 6e3);
|
|
160
|
+
assertEquals(messageBatches[1].queue, "Q1");
|
|
161
|
+
assertEquals(messageBatches[1].messages.length, 1);
|
|
162
|
+
assertEquals(messageBatches[1].messages[0].body, {
|
|
163
|
+
baz: 3,
|
|
164
|
+
qux: 4
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
async function waitFor(predicate, timeoutMs) {
|
|
169
|
+
let delayed = 0;
|
|
170
|
+
while (!predicate()) {
|
|
171
|
+
await delay(500);
|
|
172
|
+
delayed += 500;
|
|
173
|
+
if (delayed > timeoutMs) throw new Error("Timeout");
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
//#endregion
|
package/dist/x/hono.cjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
|
|
2
|
+
const { Temporal } = require("@js-temporal/polyfill");
|
|
3
|
+
const { URLPattern } = require("urlpattern-polyfill");
|
|
4
|
+
|
|
5
|
+
const require_chunk = require('../chunk-DqRYRqnO.cjs');
|
|
6
|
+
const __logtape_logtape = require_chunk.__toESM(require("@logtape/logtape"));
|
|
7
|
+
|
|
8
|
+
//#region src/x/hono.ts
|
|
9
|
+
/**
|
|
10
|
+
* Create a Hono middleware to integrate with the {@link Federation} object.
|
|
11
|
+
*
|
|
12
|
+
* @deprecated This function has been moved to `@fedify/hono` package.
|
|
13
|
+
* Import `federation` from `@fedify/hono` instead.
|
|
14
|
+
* This function will be removed in Fedify v2.0.
|
|
15
|
+
*
|
|
16
|
+
* @template TContextData A type of the context data for the {@link Federation}
|
|
17
|
+
* object.
|
|
18
|
+
* @template THonoContext A type of the Hono context.
|
|
19
|
+
* @param federation A {@link Federation} object to integrate with Hono.
|
|
20
|
+
* @param contextDataFactory A function to create a context data for the
|
|
21
|
+
* {@link Federation} object.
|
|
22
|
+
* @returns A Hono middleware.
|
|
23
|
+
*/
|
|
24
|
+
function federation(federation$1, contextDataFactory) {
|
|
25
|
+
const logger = (0, __logtape_logtape.getLogger)([
|
|
26
|
+
"fedify",
|
|
27
|
+
"federation",
|
|
28
|
+
"hono"
|
|
29
|
+
]);
|
|
30
|
+
logger.warn("The `@fedify/fedify/x/hono` module is deprecated; use `federation` from `@fedify/hono` package instead.");
|
|
31
|
+
return async (ctx, next) => {
|
|
32
|
+
let contextData = contextDataFactory(ctx);
|
|
33
|
+
if (contextData instanceof Promise) contextData = await contextData;
|
|
34
|
+
return await federation$1.fetch(ctx.req.raw, {
|
|
35
|
+
contextData,
|
|
36
|
+
...integrateFetchOptions(ctx, next)
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function integrateFetchOptions(ctx, next) {
|
|
41
|
+
return {
|
|
42
|
+
async onNotFound(_req) {
|
|
43
|
+
await next();
|
|
44
|
+
return ctx.res;
|
|
45
|
+
},
|
|
46
|
+
async onNotAcceptable(_req) {
|
|
47
|
+
await next();
|
|
48
|
+
if (ctx.res.status !== 404) return ctx.res;
|
|
49
|
+
return new Response("Not acceptable", {
|
|
50
|
+
status: 406,
|
|
51
|
+
headers: {
|
|
52
|
+
"Content-Type": "text/plain",
|
|
53
|
+
Vary: "Accept"
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
exports.federation = federation;
|