@fedify/fedify 2.4.0-dev.1422 → 2.4.0-dev.1431
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/{assert-DikXweDx.mjs → assert-OguE97r2.mjs} +1 -1
- package/dist/{assert_instance_of-C4Ri6VuN.mjs → assert_instance_of-DBC5X09g.mjs} +1 -1
- package/dist/{assert_not_equals--wG9hV7u.mjs → assert_not_equals-DkVK8oqV.mjs} +1 -1
- package/dist/{assert_rejects-DQP-q39h.mjs → assert_rejects-DN60FHPX.mjs} +2 -2
- package/dist/{assert_strict_equals-Dmjbg-bA.mjs → assert_strict_equals-XEgZAlrj.mjs} +1 -1
- package/dist/{assert_throws-4NwKEy2q.mjs → assert_throws-BOkhLGYc.mjs} +1 -1
- package/dist/{builder-Gef_ZeDE.mjs → builder-CZR-efLj.mjs} +3 -23
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/outgoing-jsonld.test.mjs +3 -3
- package/dist/compat/public-audience.test.mjs +3 -3
- package/dist/compat/transformers.test.mjs +5 -5
- package/dist/{context-BuGH_Vft.d.cts → context-BBVLF7lx.d.cts} +70 -286
- package/dist/{context-CLtZxCu6.d.ts → context-BU6jSQdo.d.ts} +70 -285
- package/dist/{context-BrIOaBSs.mjs → context-DVoTs_wM.mjs} +1 -7
- package/dist/{deno-BmD7XRaO.mjs → deno-DTMxScEV.mjs} +1 -1
- package/dist/{docloader-B8AJowCx.mjs → docloader-BfWi9rXZ.mjs} +2 -2
- package/dist/federation/builder.test.mjs +5 -5
- package/dist/federation/circuit-breaker.test.mjs +5 -5
- package/dist/federation/collection.test.mjs +3 -3
- package/dist/federation/handler.test.mjs +13 -13
- package/dist/federation/idempotency.test.mjs +6 -6
- package/dist/federation/inbox.test.mjs +3 -3
- package/dist/federation/keycache.test.mjs +5 -5
- package/dist/federation/kv.test.mjs +3 -3
- package/dist/federation/metrics.test.mjs +4 -4
- package/dist/federation/middleware.test.mjs +19 -200
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +3 -3
- package/dist/federation/mod.d.ts +3 -3
- package/dist/federation/mod.js +1 -1
- package/dist/federation/mq.test.mjs +260 -5
- package/dist/federation/negotiation.test.mjs +4 -4
- package/dist/federation/retry.test.mjs +3 -3
- package/dist/federation/router.test.mjs +5 -5
- package/dist/federation/send.test.mjs +10 -10
- package/dist/federation/temporal.test.mjs +4 -4
- package/dist/federation/webfinger.test.mjs +6 -6
- package/dist/{http-GQoPA_YT.mjs → http-BCpKHsqy.mjs} +4 -4
- package/dist/{http-BCSQJ_gv.cjs → http-CIwbPzeL.cjs} +17 -7
- package/dist/{http-CJ0WNyqA.js → http-D07vE9PZ.js} +17 -7
- package/dist/{key-BLy_TeTg.mjs → key-BjyR4b3H.mjs} +18 -8
- package/dist/{kv-cache-DXwu7BtY.cjs → kv-cache-CXj8cbEx.cjs} +1 -1
- package/dist/{kv-cache-pw-kBdVz.mjs → kv-cache-IEJVfSBn.mjs} +1 -1
- package/dist/{kv-cache-CjEcb9qH.js → kv-cache-LdHRMYlC.js} +1 -1
- package/dist/{ld-CWgxPlZq.mjs → ld-xrOJDs7P.mjs} +3 -3
- package/dist/{metrics-DUKoLd_E.mjs → metrics-BAQhI4a7.mjs} +1 -1
- package/dist/{middleware-BiCk4wGY.cjs → middleware-B1l3sgj_.cjs} +31 -281
- package/dist/{middleware-Dq-HhJHd.mjs → middleware-BQ8dje7a.mjs} +1 -1
- package/dist/{middleware-2Us0G3Iy.js → middleware-BgK5j6TR.js} +31 -281
- package/dist/{middleware-PZaroDUk.mjs → middleware-CvPc_n0b.mjs} +44 -186
- package/dist/{mod-DRokcHeU.d.cts → mod-C0F6kvgS.d.cts} +1 -1
- package/dist/{mod-r-1xOW_C.d.ts → mod-vPYVoa5n.d.ts} +1 -1
- package/dist/mod.cjs +4 -4
- package/dist/mod.d.cts +4 -4
- package/dist/mod.d.ts +4 -4
- package/dist/mod.js +4 -4
- package/dist/nodeinfo/client.test.mjs +3 -3
- package/dist/nodeinfo/handler.test.mjs +5 -5
- package/dist/nodeinfo/types.test.mjs +4 -4
- package/dist/otel/exporter.test.mjs +3 -3
- package/dist/{outgoing-jsonld-BgFLCJQ_.mjs → outgoing-jsonld-L_DbOaFe.mjs} +1 -1
- package/dist/{owner-U0Z8Ex6i.mjs → owner-CHvv4iAW.mjs} +2 -2
- package/dist/{proof-f7K32nz7.js → proof-C9nqy_mp.js} +1 -1
- package/dist/{proof-nb5tfciW.mjs → proof-DOIrkqW_.mjs} +5 -5
- package/dist/{proof-DA3hLGSO.cjs → proof-pmMnJMQe.cjs} +1 -1
- package/dist/{send-CLfW5Fdf.mjs → send-CC8034Mb.mjs} +3 -3
- package/dist/sig/accept.test.mjs +1 -1
- package/dist/sig/http.test.mjs +8 -8
- package/dist/sig/key.test.mjs +56 -6
- package/dist/sig/ld.test.mjs +7 -7
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +6 -6
- package/dist/sig/proof.test.mjs +8 -8
- package/dist/{std__assert-BTEgfoJo.mjs → std__assert-BBjXFNOb.mjs} +4 -4
- package/dist/{temporal-2ry_jdCK.mjs → temporal-CJdpFg8A.mjs} +1 -1
- package/dist/testing/mod.d.mts +7 -378
- package/dist/testing/mod.mjs +2 -3
- package/dist/utils/docloader.test.mjs +6 -6
- package/dist/utils/kv-cache.test.mjs +1 -1
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +6 -8
- package/dist/codec-Bf-rTqks.mjs +0 -94
- package/dist/federation/tasks/codec.test.d.mts +0 -2
- package/dist/federation/tasks/codec.test.mjs +0 -292
- package/dist/federation/tasks/tasks.test.d.mts +0 -2
- package/dist/federation/tasks/tasks.test.mjs +0 -651
- package/dist/mq-CvJAzRz5.mjs +0 -260
- package/dist/testing-CjYPStvE.mjs +0 -55
- /package/dist/{accept-CceiKpCy.mjs → accept-CPkZzmGN.mjs} +0 -0
- /package/dist/{activity-listener-BeTGV3wc.mjs → activity-listener-tztVvlNb.mjs} +0 -0
- /package/dist/{assert_equals-Ew3jOFa3.mjs → assert_equals-C-ZRDbaf.mjs} +0 -0
- /package/dist/{circuit-breaker-hJBB6jwA.mjs → circuit-breaker-CSWsyoef.mjs} +0 -0
- /package/dist/{client-B_A6mfn3.mjs → client-ByXmQhYD.mjs} +0 -0
- /package/dist/{collection-Dp5ky45w.mjs → collection-Cc3DVAhE.mjs} +0 -0
- /package/dist/{keycache-CaOR6NYg.mjs → keycache-BeU0LCII.mjs} +0 -0
- /package/dist/{keys-C3kae-6B.mjs → keys-DGu1NFwu.mjs} +0 -0
- /package/dist/{kv-x2IvBUyq.mjs → kv-rV3vodCc.mjs} +0 -0
- /package/dist/{negotiation-m_L2nyS3.mjs → negotiation-DDstyBvc.mjs} +0 -0
- /package/dist/{public-audience-N3pyOx2p.mjs → public-audience-Cvbr2Gzt.mjs} +0 -0
- /package/dist/{retry-DI4O-zYl.mjs → retry-CXg_MBI-.mjs} +0 -0
- /package/dist/{types-BFowWFTT.mjs → types-J53Kw7so.mjs} +0 -0
|
@@ -2,34 +2,31 @@ import { Temporal } from "@js-temporal/polyfill";
|
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { t as esm_default } from "../esm-vrlUxr60.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { r as
|
|
8
|
-
import {
|
|
9
|
-
import { t as
|
|
10
|
-
import { t as
|
|
11
|
-
import { t as
|
|
12
|
-
import { t as
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import { t as
|
|
22
|
-
import {
|
|
23
|
-
import { t as CircuitBreaker } from "../circuit-breaker-hJBB6jwA.mjs";
|
|
24
|
-
import { t as TaskCodec } from "../codec-Bf-rTqks.mjs";
|
|
5
|
+
import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
|
|
6
|
+
import { r as assertExists } from "../std__assert-BBjXFNOb.mjs";
|
|
7
|
+
import { r as assertFalse, t as assertRejects } from "../assert_rejects-DN60FHPX.mjs";
|
|
8
|
+
import { t as assertInstanceOf } from "../assert_instance_of-DBC5X09g.mjs";
|
|
9
|
+
import { t as assertThrows } from "../assert_throws-BOkhLGYc.mjs";
|
|
10
|
+
import { t as assertNotEquals } from "../assert_not_equals-DkVK8oqV.mjs";
|
|
11
|
+
import { t as assertStrictEquals } from "../assert_strict_equals-XEgZAlrj.mjs";
|
|
12
|
+
import { t as assert } from "../assert-OguE97r2.mjs";
|
|
13
|
+
import { g as recordInboxActivity } from "../metrics-BAQhI4a7.mjs";
|
|
14
|
+
import { l as verifyRequest, s as signRequest } from "../http-BCpKHsqy.mjs";
|
|
15
|
+
import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-DGu1NFwu.mjs";
|
|
16
|
+
import { t as getAuthenticatedDocumentLoader } from "../docloader-BfWi9rXZ.mjs";
|
|
17
|
+
import { a as compactJsonLd, h as verifyJsonLd, p as signJsonLd, s as detachSignature } from "../ld-xrOJDs7P.mjs";
|
|
18
|
+
import { t as doesActorOwnKey } from "../owner-CHvv4iAW.mjs";
|
|
19
|
+
import { i as verifyObject, r as signObject } from "../proof-DOIrkqW_.mjs";
|
|
20
|
+
import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
|
|
21
|
+
import { g as handleBenchmarkTrigger, i as KvSpecDeterminer, n as FederationImpl, o as createFederation, r as InboxContextImpl, t as ContextImpl } from "../middleware-CvPc_n0b.mjs";
|
|
22
|
+
import { t as CircuitBreaker } from "../circuit-breaker-CSWsyoef.mjs";
|
|
25
23
|
import { configure, reset } from "@logtape/logtape";
|
|
26
24
|
import { RouterError } from "@fedify/uri-template";
|
|
27
25
|
import * as vocab from "@fedify/vocab";
|
|
28
|
-
import { Create,
|
|
26
|
+
import { Create, Offer, Person, getTypeId, lookupObject } from "@fedify/vocab";
|
|
29
27
|
import { SpanStatusCode, metrics } from "@opentelemetry/api";
|
|
30
28
|
import { createTestMeterProvider, createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
|
|
31
29
|
import { FetchError, getDocumentLoader } from "@fedify/vocab-runtime";
|
|
32
|
-
import { deepStrictEqual, ok, rejects, strictEqual } from "node:assert/strict";
|
|
33
30
|
import serialize from "json-canon";
|
|
34
31
|
import { DataPointType, MeterProvider as MeterProvider$1, MetricReader } from "@opentelemetry/sdk-metrics";
|
|
35
32
|
//#region ../fixture/src/fixtures/example.com/create.json
|
|
@@ -6959,183 +6956,5 @@ test("createFederation() omits instrumentation when no meterProvider is set", ()
|
|
|
6959
6956
|
assertStrictEquals(ctx.documentLoader, mockDocumentLoader);
|
|
6960
6957
|
assertStrictEquals(ctx.contextLoader, mockDocumentLoader);
|
|
6961
6958
|
});
|
|
6962
|
-
const taskCodec = new TaskCodec({ contextLoader: mockDocumentLoader });
|
|
6963
|
-
const decodeEnvelope = (message) => taskCodec.decode(envelopeSchema, message.data);
|
|
6964
|
-
const envelope = (title) => ({
|
|
6965
|
-
note: new Note({ content: title }),
|
|
6966
|
-
title
|
|
6967
|
-
});
|
|
6968
|
-
var RendezvousQueue = class {
|
|
6969
|
-
expected;
|
|
6970
|
-
enqueued = [];
|
|
6971
|
-
#count = 0;
|
|
6972
|
-
#markDispatched;
|
|
6973
|
-
#openGate;
|
|
6974
|
-
dispatched;
|
|
6975
|
-
#gate;
|
|
6976
|
-
constructor(expected) {
|
|
6977
|
-
this.expected = expected;
|
|
6978
|
-
this.dispatched = new Promise((resolve) => {
|
|
6979
|
-
this.#markDispatched = resolve;
|
|
6980
|
-
});
|
|
6981
|
-
this.#gate = new Promise((resolve) => {
|
|
6982
|
-
this.#openGate = resolve;
|
|
6983
|
-
});
|
|
6984
|
-
}
|
|
6985
|
-
release() {
|
|
6986
|
-
this.#openGate();
|
|
6987
|
-
}
|
|
6988
|
-
enqueue(message, options) {
|
|
6989
|
-
this.enqueued.push({
|
|
6990
|
-
message,
|
|
6991
|
-
options
|
|
6992
|
-
});
|
|
6993
|
-
if (++this.#count >= this.expected) this.#markDispatched();
|
|
6994
|
-
return this.#gate;
|
|
6995
|
-
}
|
|
6996
|
-
listen(_handler, _options) {
|
|
6997
|
-
return new Promise(() => {});
|
|
6998
|
-
}
|
|
6999
|
-
};
|
|
7000
|
-
const withTimeout = (promise, ms, message) => {
|
|
7001
|
-
let timer;
|
|
7002
|
-
const timeout = new Promise((_, reject) => {
|
|
7003
|
-
timer = setTimeout(() => reject(new Error(message)), ms);
|
|
7004
|
-
});
|
|
7005
|
-
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
|
|
7006
|
-
};
|
|
7007
|
-
const taskFederationOptions = {
|
|
7008
|
-
kv: new MemoryKvStore(),
|
|
7009
|
-
documentLoaderFactory: () => mockDocumentLoader,
|
|
7010
|
-
contextLoaderFactory: () => mockDocumentLoader,
|
|
7011
|
-
manuallyStartQueue: true
|
|
7012
|
-
};
|
|
7013
|
-
test("ContextImpl.enqueueTask()", async (t) => {
|
|
7014
|
-
await t.step("builds the task message envelope and round-trips a vocab payload", async () => {
|
|
7015
|
-
const queue = new MockQueue({ supportsEnqueueMany: true });
|
|
7016
|
-
const federation = createFederation({
|
|
7017
|
-
...taskFederationOptions,
|
|
7018
|
-
queue: { task: queue }
|
|
7019
|
-
});
|
|
7020
|
-
const task = federation.defineTask("greet", {
|
|
7021
|
-
schema: envelopeSchema,
|
|
7022
|
-
handler: () => {}
|
|
7023
|
-
});
|
|
7024
|
-
const ctx = federation.createContext(new URL("https://example.com/"), void 0);
|
|
7025
|
-
ok(ctx instanceof ContextImpl);
|
|
7026
|
-
await ctx.enqueueTask(task, envelope("greeting"));
|
|
7027
|
-
strictEqual(queue.enqueuedMany.length, 0);
|
|
7028
|
-
strictEqual(queue.enqueued.length, 1);
|
|
7029
|
-
const { message } = queue.enqueued[0];
|
|
7030
|
-
strictEqual(message.type, "task");
|
|
7031
|
-
strictEqual(message.taskName, "greet");
|
|
7032
|
-
strictEqual(message.baseUrl, "https://example.com");
|
|
7033
|
-
strictEqual(message.attempt, 0);
|
|
7034
|
-
ok(/^[0-9a-f-]{36}$/i.test(message.id));
|
|
7035
|
-
ok(Temporal.Instant.from(message.started) instanceof Temporal.Instant);
|
|
7036
|
-
strictEqual(typeof message.traceContext, "object");
|
|
7037
|
-
ok(message.traceContext != null);
|
|
7038
|
-
const decoded = await decodeEnvelope(message);
|
|
7039
|
-
ok(decoded.note instanceof Note);
|
|
7040
|
-
strictEqual(decoded.note.content?.toString(), "greeting");
|
|
7041
|
-
strictEqual(decoded.title, "greeting");
|
|
7042
|
-
});
|
|
7043
|
-
});
|
|
7044
|
-
test("ContextImpl.enqueueTaskMany()", async (t) => {
|
|
7045
|
-
await t.step("round-trips every payload through enqueueMany in order, forwarding options", async () => {
|
|
7046
|
-
const queue = new MockQueue({ supportsEnqueueMany: true });
|
|
7047
|
-
const federation = createFederation({
|
|
7048
|
-
...taskFederationOptions,
|
|
7049
|
-
queue: { task: queue }
|
|
7050
|
-
});
|
|
7051
|
-
const task = federation.defineTask("bulk", {
|
|
7052
|
-
schema: envelopeSchema,
|
|
7053
|
-
handler: () => {}
|
|
7054
|
-
});
|
|
7055
|
-
const ctx = federation.createContext(new URL("https://example.com/"), void 0);
|
|
7056
|
-
const payloads = [
|
|
7057
|
-
envelope("a"),
|
|
7058
|
-
envelope("b"),
|
|
7059
|
-
envelope("c")
|
|
7060
|
-
];
|
|
7061
|
-
await ctx.enqueueTaskMany(task, payloads, {
|
|
7062
|
-
delay: { seconds: 30 },
|
|
7063
|
-
orderingKey: "batch"
|
|
7064
|
-
});
|
|
7065
|
-
strictEqual(queue.enqueued.length, 0);
|
|
7066
|
-
strictEqual(queue.enqueuedMany.length, 1);
|
|
7067
|
-
const { messages, options } = queue.enqueuedMany[0];
|
|
7068
|
-
ok(options?.delay instanceof Temporal.Duration);
|
|
7069
|
-
strictEqual(options.delay.total("second"), 30);
|
|
7070
|
-
strictEqual(options.orderingKey, "batch");
|
|
7071
|
-
deepStrictEqual((await Promise.all(messages.map(decodeEnvelope))).map((d) => d.title), [
|
|
7072
|
-
"a",
|
|
7073
|
-
"b",
|
|
7074
|
-
"c"
|
|
7075
|
-
]);
|
|
7076
|
-
for (const message of messages) strictEqual(message.orderingKey, "batch");
|
|
7077
|
-
});
|
|
7078
|
-
await t.step("with a single payload uses enqueue() instead of enqueueMany", async () => {
|
|
7079
|
-
const queue = new MockQueue({ supportsEnqueueMany: true });
|
|
7080
|
-
const federation = createFederation({
|
|
7081
|
-
...taskFederationOptions,
|
|
7082
|
-
queue: { task: queue }
|
|
7083
|
-
});
|
|
7084
|
-
const task = federation.defineTask("bulk-single", {
|
|
7085
|
-
schema: envelopeSchema,
|
|
7086
|
-
handler: () => {}
|
|
7087
|
-
});
|
|
7088
|
-
await federation.createContext(new URL("https://example.com/"), void 0).enqueueTaskMany(task, [envelope("solo")]);
|
|
7089
|
-
strictEqual(queue.enqueuedMany.length, 0);
|
|
7090
|
-
strictEqual(queue.enqueued.length, 1);
|
|
7091
|
-
});
|
|
7092
|
-
await t.step("falls back to concurrent single enqueues, preserving order and options", async () => {
|
|
7093
|
-
const queue = new RendezvousQueue(2);
|
|
7094
|
-
const federation = createFederation({
|
|
7095
|
-
...taskFederationOptions,
|
|
7096
|
-
queue: { task: queue }
|
|
7097
|
-
});
|
|
7098
|
-
const task = federation.defineTask("bulk-fallback", {
|
|
7099
|
-
schema: envelopeSchema,
|
|
7100
|
-
handler: () => {}
|
|
7101
|
-
});
|
|
7102
|
-
const ctx = federation.createContext(new URL("https://example.com/"), void 0);
|
|
7103
|
-
const payloads = [envelope("x"), envelope("y")];
|
|
7104
|
-
const pending = ctx.enqueueTaskMany(task, payloads, { orderingKey: "batch" });
|
|
7105
|
-
try {
|
|
7106
|
-
await withTimeout(queue.dispatched, 2e3, "fallback did not dispatch enqueues concurrently");
|
|
7107
|
-
strictEqual(queue.enqueued.length, 2);
|
|
7108
|
-
} finally {
|
|
7109
|
-
queue.release();
|
|
7110
|
-
await pending;
|
|
7111
|
-
}
|
|
7112
|
-
deepStrictEqual((await Promise.all(queue.enqueued.map(({ message }) => decodeEnvelope(message)))).map((d) => d.title), ["x", "y"]);
|
|
7113
|
-
for (const { message, options } of queue.enqueued) {
|
|
7114
|
-
strictEqual(message.orderingKey, "batch");
|
|
7115
|
-
strictEqual(options?.orderingKey, "batch");
|
|
7116
|
-
}
|
|
7117
|
-
});
|
|
7118
|
-
await t.step("fallback path aborts the whole batch when one payload is invalid", async () => {
|
|
7119
|
-
const queue = new MockQueue();
|
|
7120
|
-
const federation = createFederation({
|
|
7121
|
-
...taskFederationOptions,
|
|
7122
|
-
queue: { task: queue }
|
|
7123
|
-
});
|
|
7124
|
-
const task = federation.defineTask("bulk-typed", {
|
|
7125
|
-
schema: numberSchema,
|
|
7126
|
-
handler: () => {}
|
|
7127
|
-
});
|
|
7128
|
-
const ctx = federation.createContext(new URL("https://example.com/"), void 0);
|
|
7129
|
-
await rejects(() => ctx.enqueueTaskMany(task, [
|
|
7130
|
-
1,
|
|
7131
|
-
"two",
|
|
7132
|
-
3
|
|
7133
|
-
]), {
|
|
7134
|
-
name: "TypeError",
|
|
7135
|
-
message: /Task data failed schema validation/
|
|
7136
|
-
});
|
|
7137
|
-
strictEqual(queue.enqueued.length, 0);
|
|
7138
|
-
});
|
|
7139
|
-
});
|
|
7140
6959
|
//#endregion
|
|
7141
6960
|
export {};
|
package/dist/federation/mod.cjs
CHANGED
|
@@ -2,7 +2,7 @@ const { Temporal } = require("@js-temporal/polyfill");
|
|
|
2
2
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
4
|
require("../chunk-DDcVe30Y.cjs");
|
|
5
|
-
const require_middleware = require("../middleware-
|
|
5
|
+
const require_middleware = require("../middleware-B1l3sgj_.cjs");
|
|
6
6
|
let _logtape_logtape = require("@logtape/logtape");
|
|
7
7
|
let _fedify_uri_template = require("@fedify/uri-template");
|
|
8
8
|
let es_toolkit = require("es-toolkit");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { $ as
|
|
2
|
+
import { $ as CustomCollectionCursor, A as Rfc6570Expression, At as parseCircuitBreakerKvState, B as createFederationBuilder, C as FederationStartQueueOptions, Ct as CircuitBreakerFailurePolicy, D as InboxListenerSetters, Dt as CircuitBreakerStateChange, E as InboxChallengePolicy, Et as CircuitBreakerState, F as CreateExponentialBackoffPolicyOptions, G as ActorDispatcher, H as respondWithObject, I as RetryContext, J as AuthorizePredicate, K as ActorHandleMapper, L as RetryPolicy, M as FederationOrigin, N as FederationQueueOptions, O as ObjectCallbackSetters, Ot as NormalizedCircuitBreakerOptions, P as createFederation, Q as CustomCollectionCounter, R as createExponentialBackoffPolicy, S as FederationOptions, St as CircuitBreakerCreateOptions, T as IdempotencyStrategy, Tt as CircuitBreakerOptions, U as respondWithObjectIfAcceptable, V as RespondWithObjectOptions, W as ActorAliasMapper, X as CollectionCursor, Y as CollectionCounter, Z as CollectionDispatcher, _ as Federatable, _t as buildCollectionSynchronizationHeader, a as GetSignedKeyOptions, at as ObjectDispatcher, b as FederationBuilder, bt as CircuitBreakerActivityDrop, c as ParseUriResult, ct as OutboxListenerErrorHandler, d as SendActivityOptions, dt as UnverifiedActivityHandler, et as CustomCollectionDispatcher, f as SendActivityOptionsForCollection, ft as UnverifiedActivityReason, g as CustomCollectionCallbackSetters, gt as PageItems, h as ConstructorWithTypeId, ht as SenderKeyPair, i as GetActorOptions, it as ObjectAuthorizePredicate, j as FederationKvPrefixes, k as OutboxListenerSetters, kt as normalizeCircuitBreakerOptions, l as RequestContext, lt as OutboxPermanentFailureHandler, m as CollectionCallbackSetters, mt as SendActivityError, n as Context, nt as InboxListener, o as InboxContext, ot as OutboxErrorHandler, p as ActorCallbackSetters, pt as WebFingerLinksDispatcher, q as ActorKeyPairsDispatcher, r as ForwardActivityOptions, rt as NodeInfoDispatcher, s as OutboxContext, st as OutboxListener, t as ActorKeyPair, tt as InboxErrorHandler, u as RouteActivityOptions, ut as SharedInboxKeyDispatcher, v as Federation, vt as digest, w as IdempotencyKeyCallback, wt as CircuitBreakerKvState, x as FederationFetchOptions, xt as CircuitBreakerBeforeSendDecision, y as FederationBenchmarkOptions, yt as CircuitBreaker, z as Message } from "../context-BBVLF7lx.cjs";
|
|
3
3
|
import { a as MemoryKvStore, i as KvStoreSetOptions, n as KvStore, r as KvStoreListEntry, t as KvKey } from "../kv-gJ8LYbxX.cjs";
|
|
4
4
|
import { a as MessageQueueEnqueueOptions, i as MessageQueueDepth, n as InProcessMessageQueueOptions, o as MessageQueueListenOptions, r as MessageQueue, s as ParallelMessageQueue, t as InProcessMessageQueue } from "../mq-D8uSFzxe.cjs";
|
|
5
|
-
import { a as RouterOptions, i as RouterError, n as handleWebFinger, o as RouterRouteResult, r as Router, t as WebFingerHandlerParameters } from "../mod-
|
|
6
|
-
export { ActorAliasMapper, ActorCallbackSetters, ActorDispatcher, ActorHandleMapper, ActorKeyPair, ActorKeyPairsDispatcher, AuthorizePredicate, CircuitBreaker, CircuitBreakerActivityDrop, CircuitBreakerBeforeSendDecision, CircuitBreakerCreateOptions, CircuitBreakerFailurePolicy, CircuitBreakerKvState, CircuitBreakerOptions, CircuitBreakerState, CircuitBreakerStateChange, CollectionCallbackSetters, CollectionCounter, CollectionCursor, CollectionDispatcher, ConstructorWithTypeId, Context, CreateExponentialBackoffPolicyOptions, CustomCollectionCallbackSetters, CustomCollectionCounter, CustomCollectionCursor, CustomCollectionDispatcher, Federatable, Federation, FederationBenchmarkOptions, FederationBuilder, FederationFetchOptions, FederationKvPrefixes, FederationOptions, FederationOrigin, FederationQueueOptions, FederationStartQueueOptions, ForwardActivityOptions, GetActorOptions, GetSignedKeyOptions, IdempotencyKeyCallback, IdempotencyStrategy, InProcessMessageQueue, InProcessMessageQueueOptions, InboxChallengePolicy, InboxContext, InboxErrorHandler, InboxListener, InboxListenerSetters, KvKey, KvStore, KvStoreListEntry, KvStoreSetOptions, MemoryKvStore, Message, MessageQueue, MessageQueueDepth, MessageQueueEnqueueOptions, MessageQueueListenOptions, NodeInfoDispatcher, NormalizedCircuitBreakerOptions, ObjectAuthorizePredicate, ObjectCallbackSetters, ObjectDispatcher, OutboxContext, OutboxErrorHandler, OutboxListener, OutboxListenerErrorHandler, OutboxListenerSetters, OutboxPermanentFailureHandler, PageItems, ParallelMessageQueue, ParseUriResult, RequestContext, RespondWithObjectOptions, RetryContext, RetryPolicy, Rfc6570Expression, RouteActivityOptions, Router, RouterError, RouterOptions, RouterRouteResult, SendActivityError, SendActivityOptions, SendActivityOptionsForCollection, SenderKeyPair, SharedInboxKeyDispatcher,
|
|
5
|
+
import { a as RouterOptions, i as RouterError, n as handleWebFinger, o as RouterRouteResult, r as Router, t as WebFingerHandlerParameters } from "../mod-C0F6kvgS.cjs";
|
|
6
|
+
export { ActorAliasMapper, ActorCallbackSetters, ActorDispatcher, ActorHandleMapper, ActorKeyPair, ActorKeyPairsDispatcher, AuthorizePredicate, CircuitBreaker, CircuitBreakerActivityDrop, CircuitBreakerBeforeSendDecision, CircuitBreakerCreateOptions, CircuitBreakerFailurePolicy, CircuitBreakerKvState, CircuitBreakerOptions, CircuitBreakerState, CircuitBreakerStateChange, CollectionCallbackSetters, CollectionCounter, CollectionCursor, CollectionDispatcher, ConstructorWithTypeId, Context, CreateExponentialBackoffPolicyOptions, CustomCollectionCallbackSetters, CustomCollectionCounter, CustomCollectionCursor, CustomCollectionDispatcher, Federatable, Federation, FederationBenchmarkOptions, FederationBuilder, FederationFetchOptions, FederationKvPrefixes, FederationOptions, FederationOrigin, FederationQueueOptions, FederationStartQueueOptions, ForwardActivityOptions, GetActorOptions, GetSignedKeyOptions, IdempotencyKeyCallback, IdempotencyStrategy, InProcessMessageQueue, InProcessMessageQueueOptions, InboxChallengePolicy, InboxContext, InboxErrorHandler, InboxListener, InboxListenerSetters, KvKey, KvStore, KvStoreListEntry, KvStoreSetOptions, MemoryKvStore, Message, MessageQueue, MessageQueueDepth, MessageQueueEnqueueOptions, MessageQueueListenOptions, NodeInfoDispatcher, NormalizedCircuitBreakerOptions, ObjectAuthorizePredicate, ObjectCallbackSetters, ObjectDispatcher, OutboxContext, OutboxErrorHandler, OutboxListener, OutboxListenerErrorHandler, OutboxListenerSetters, OutboxPermanentFailureHandler, PageItems, ParallelMessageQueue, ParseUriResult, RequestContext, RespondWithObjectOptions, RetryContext, RetryPolicy, Rfc6570Expression, RouteActivityOptions, Router, RouterError, RouterOptions, RouterRouteResult, SendActivityError, SendActivityOptions, SendActivityOptionsForCollection, SenderKeyPair, SharedInboxKeyDispatcher, UnverifiedActivityHandler, UnverifiedActivityReason, WebFingerHandlerParameters, WebFingerLinksDispatcher, buildCollectionSynchronizationHeader, createExponentialBackoffPolicy, createFederation, createFederationBuilder, digest, handleWebFinger, normalizeCircuitBreakerOptions, parseCircuitBreakerKvState, respondWithObject, respondWithObjectIfAcceptable };
|
package/dist/federation/mod.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { $ as
|
|
2
|
+
import { $ as CustomCollectionCursor, A as Rfc6570Expression, At as parseCircuitBreakerKvState, B as createFederationBuilder, C as FederationStartQueueOptions, Ct as CircuitBreakerFailurePolicy, D as InboxListenerSetters, Dt as CircuitBreakerStateChange, E as InboxChallengePolicy, Et as CircuitBreakerState, F as CreateExponentialBackoffPolicyOptions, G as ActorDispatcher, H as respondWithObject, I as RetryContext, J as AuthorizePredicate, K as ActorHandleMapper, L as RetryPolicy, M as FederationOrigin, N as FederationQueueOptions, O as ObjectCallbackSetters, Ot as NormalizedCircuitBreakerOptions, P as createFederation, Q as CustomCollectionCounter, R as createExponentialBackoffPolicy, S as FederationOptions, St as CircuitBreakerCreateOptions, T as IdempotencyStrategy, Tt as CircuitBreakerOptions, U as respondWithObjectIfAcceptable, V as RespondWithObjectOptions, W as ActorAliasMapper, X as CollectionCursor, Y as CollectionCounter, Z as CollectionDispatcher, _ as Federatable, _t as buildCollectionSynchronizationHeader, a as GetSignedKeyOptions, at as ObjectDispatcher, b as FederationBuilder, bt as CircuitBreakerActivityDrop, c as ParseUriResult, ct as OutboxListenerErrorHandler, d as SendActivityOptions, dt as UnverifiedActivityHandler, et as CustomCollectionDispatcher, f as SendActivityOptionsForCollection, ft as UnverifiedActivityReason, g as CustomCollectionCallbackSetters, gt as PageItems, h as ConstructorWithTypeId, ht as SenderKeyPair, i as GetActorOptions, it as ObjectAuthorizePredicate, j as FederationKvPrefixes, k as OutboxListenerSetters, kt as normalizeCircuitBreakerOptions, l as RequestContext, lt as OutboxPermanentFailureHandler, m as CollectionCallbackSetters, mt as SendActivityError, n as Context, nt as InboxListener, o as InboxContext, ot as OutboxErrorHandler, p as ActorCallbackSetters, pt as WebFingerLinksDispatcher, q as ActorKeyPairsDispatcher, r as ForwardActivityOptions, rt as NodeInfoDispatcher, s as OutboxContext, st as OutboxListener, t as ActorKeyPair, tt as InboxErrorHandler, u as RouteActivityOptions, ut as SharedInboxKeyDispatcher, v as Federation, vt as digest, w as IdempotencyKeyCallback, wt as CircuitBreakerKvState, x as FederationFetchOptions, xt as CircuitBreakerBeforeSendDecision, y as FederationBenchmarkOptions, yt as CircuitBreaker, z as Message } from "../context-BU6jSQdo.js";
|
|
3
3
|
import { a as MemoryKvStore, i as KvStoreSetOptions, n as KvStore, r as KvStoreListEntry, t as KvKey } from "../kv-D6hNiMTK.js";
|
|
4
4
|
import { a as MessageQueueEnqueueOptions, i as MessageQueueDepth, n as InProcessMessageQueueOptions, o as MessageQueueListenOptions, r as MessageQueue, s as ParallelMessageQueue, t as InProcessMessageQueue } from "../mq-D-nlpY04.js";
|
|
5
|
-
import { a as RouterOptions, i as RouterError, n as handleWebFinger, o as RouterRouteResult, r as Router, t as WebFingerHandlerParameters } from "../mod-
|
|
6
|
-
export { ActorAliasMapper, ActorCallbackSetters, ActorDispatcher, ActorHandleMapper, ActorKeyPair, ActorKeyPairsDispatcher, AuthorizePredicate, CircuitBreaker, CircuitBreakerActivityDrop, CircuitBreakerBeforeSendDecision, CircuitBreakerCreateOptions, CircuitBreakerFailurePolicy, CircuitBreakerKvState, CircuitBreakerOptions, CircuitBreakerState, CircuitBreakerStateChange, CollectionCallbackSetters, CollectionCounter, CollectionCursor, CollectionDispatcher, ConstructorWithTypeId, Context, CreateExponentialBackoffPolicyOptions, CustomCollectionCallbackSetters, CustomCollectionCounter, CustomCollectionCursor, CustomCollectionDispatcher, Federatable, Federation, FederationBenchmarkOptions, FederationBuilder, FederationFetchOptions, FederationKvPrefixes, FederationOptions, FederationOrigin, FederationQueueOptions, FederationStartQueueOptions, ForwardActivityOptions, GetActorOptions, GetSignedKeyOptions, IdempotencyKeyCallback, IdempotencyStrategy, InProcessMessageQueue, InProcessMessageQueueOptions, InboxChallengePolicy, InboxContext, InboxErrorHandler, InboxListener, InboxListenerSetters, KvKey, KvStore, KvStoreListEntry, KvStoreSetOptions, MemoryKvStore, Message, MessageQueue, MessageQueueDepth, MessageQueueEnqueueOptions, MessageQueueListenOptions, NodeInfoDispatcher, NormalizedCircuitBreakerOptions, ObjectAuthorizePredicate, ObjectCallbackSetters, ObjectDispatcher, OutboxContext, OutboxErrorHandler, OutboxListener, OutboxListenerErrorHandler, OutboxListenerSetters, OutboxPermanentFailureHandler, PageItems, ParallelMessageQueue, ParseUriResult, RequestContext, RespondWithObjectOptions, RetryContext, RetryPolicy, Rfc6570Expression, RouteActivityOptions, Router, RouterError, RouterOptions, RouterRouteResult, SendActivityError, SendActivityOptions, SendActivityOptionsForCollection, SenderKeyPair, SharedInboxKeyDispatcher,
|
|
5
|
+
import { a as RouterOptions, i as RouterError, n as handleWebFinger, o as RouterRouteResult, r as Router, t as WebFingerHandlerParameters } from "../mod-vPYVoa5n.js";
|
|
6
|
+
export { ActorAliasMapper, ActorCallbackSetters, ActorDispatcher, ActorHandleMapper, ActorKeyPair, ActorKeyPairsDispatcher, AuthorizePredicate, CircuitBreaker, CircuitBreakerActivityDrop, CircuitBreakerBeforeSendDecision, CircuitBreakerCreateOptions, CircuitBreakerFailurePolicy, CircuitBreakerKvState, CircuitBreakerOptions, CircuitBreakerState, CircuitBreakerStateChange, CollectionCallbackSetters, CollectionCounter, CollectionCursor, CollectionDispatcher, ConstructorWithTypeId, Context, CreateExponentialBackoffPolicyOptions, CustomCollectionCallbackSetters, CustomCollectionCounter, CustomCollectionCursor, CustomCollectionDispatcher, Federatable, Federation, FederationBenchmarkOptions, FederationBuilder, FederationFetchOptions, FederationKvPrefixes, FederationOptions, FederationOrigin, FederationQueueOptions, FederationStartQueueOptions, ForwardActivityOptions, GetActorOptions, GetSignedKeyOptions, IdempotencyKeyCallback, IdempotencyStrategy, InProcessMessageQueue, InProcessMessageQueueOptions, InboxChallengePolicy, InboxContext, InboxErrorHandler, InboxListener, InboxListenerSetters, KvKey, KvStore, KvStoreListEntry, KvStoreSetOptions, MemoryKvStore, Message, MessageQueue, MessageQueueDepth, MessageQueueEnqueueOptions, MessageQueueListenOptions, NodeInfoDispatcher, NormalizedCircuitBreakerOptions, ObjectAuthorizePredicate, ObjectCallbackSetters, ObjectDispatcher, OutboxContext, OutboxErrorHandler, OutboxListener, OutboxListenerErrorHandler, OutboxListenerSetters, OutboxPermanentFailureHandler, PageItems, ParallelMessageQueue, ParseUriResult, RequestContext, RespondWithObjectOptions, RetryContext, RetryPolicy, Rfc6570Expression, RouteActivityOptions, Router, RouterError, RouterOptions, RouterRouteResult, SendActivityError, SendActivityOptions, SendActivityOptionsForCollection, SenderKeyPair, SharedInboxKeyDispatcher, UnverifiedActivityHandler, UnverifiedActivityReason, WebFingerHandlerParameters, WebFingerLinksDispatcher, buildCollectionSynchronizationHeader, createExponentialBackoffPolicy, createFederation, createFederationBuilder, digest, handleWebFinger, normalizeCircuitBreakerOptions, parseCircuitBreakerKvState, respondWithObject, respondWithObjectIfAcceptable };
|
package/dist/federation/mod.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
|
-
import { a as SendActivityError, c as buildCollectionSynchronizationHeader, d as normalizeCircuitBreakerOptions, f as parseCircuitBreakerKvState, i as createExponentialBackoffPolicy, l as digest, o as respondWithObject, p as createFederationBuilder, r as handleWebFinger, s as respondWithObjectIfAcceptable, t as createFederation, u as CircuitBreaker } from "../middleware-
|
|
3
|
+
import { a as SendActivityError, c as buildCollectionSynchronizationHeader, d as normalizeCircuitBreakerOptions, f as parseCircuitBreakerKvState, i as createExponentialBackoffPolicy, l as digest, o as respondWithObject, p as createFederationBuilder, r as handleWebFinger, s as respondWithObjectIfAcceptable, t as createFederation, u as CircuitBreaker } from "../middleware-BgK5j6TR.js";
|
|
4
4
|
import { getLogger } from "@logtape/logtape";
|
|
5
5
|
import { Router as Router$1, RouterError as RouterError$1, assertPath, isPath } from "@fedify/uri-template";
|
|
6
6
|
import { isEqual } from "es-toolkit";
|
|
@@ -1,13 +1,268 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { t as assertEquals } from "../assert_equals-
|
|
5
|
-
import { n as assertGreater } from "../std__assert-
|
|
6
|
-
import { n as assertGreaterOrEqual, r as assertFalse } from "../assert_rejects-
|
|
7
|
-
import { t as assert } from "../assert-
|
|
8
|
-
import { n as ParallelMessageQueue, t as InProcessMessageQueue } from "../mq-CvJAzRz5.mjs";
|
|
4
|
+
import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
|
|
5
|
+
import { n as assertGreater } from "../std__assert-BBjXFNOb.mjs";
|
|
6
|
+
import { n as assertGreaterOrEqual, r as assertFalse } from "../assert_rejects-DN60FHPX.mjs";
|
|
7
|
+
import { t as assert } from "../assert-OguE97r2.mjs";
|
|
9
8
|
import { test } from "@fedify/fixture";
|
|
10
9
|
import { delay } from "es-toolkit";
|
|
10
|
+
//#region src/federation/mq.ts
|
|
11
|
+
/**
|
|
12
|
+
* A message queue that processes messages in the same process.
|
|
13
|
+
* Do not use this in production as it does neither persist messages nor
|
|
14
|
+
* distribute them across multiple processes.
|
|
15
|
+
*
|
|
16
|
+
* @since 0.5.0
|
|
17
|
+
*/
|
|
18
|
+
var InProcessMessageQueue = class {
|
|
19
|
+
#messages;
|
|
20
|
+
#monitors;
|
|
21
|
+
#pollIntervalMs;
|
|
22
|
+
#delayedMessages;
|
|
23
|
+
/**
|
|
24
|
+
* Tracks which ordering keys are currently being processed to ensure
|
|
25
|
+
* sequential processing for messages with the same key.
|
|
26
|
+
*/
|
|
27
|
+
#processingKeys;
|
|
28
|
+
/**
|
|
29
|
+
* In-process message queue does not provide native retry mechanisms.
|
|
30
|
+
* @since 1.7.0
|
|
31
|
+
*/
|
|
32
|
+
nativeRetrial = false;
|
|
33
|
+
/**
|
|
34
|
+
* Constructs a new {@link InProcessMessageQueue} with the given options.
|
|
35
|
+
* @param options Additional options for the in-process message queue.
|
|
36
|
+
*/
|
|
37
|
+
constructor(options = {}) {
|
|
38
|
+
this.#messages = [];
|
|
39
|
+
this.#monitors = {};
|
|
40
|
+
this.#pollIntervalMs = Temporal.Duration.from(options.pollInterval ?? { seconds: 5 }).total("millisecond");
|
|
41
|
+
this.#delayedMessages = 0;
|
|
42
|
+
this.#processingKeys = /* @__PURE__ */ new Set();
|
|
43
|
+
}
|
|
44
|
+
enqueue(message, options) {
|
|
45
|
+
const delay = options?.delay == null ? 0 : Math.max(options.delay.total("millisecond"), 0);
|
|
46
|
+
if (delay > 0) {
|
|
47
|
+
this.#delayedMessages++;
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
this.#delayedMessages--;
|
|
50
|
+
this.#enqueueReady(message, options);
|
|
51
|
+
}, delay);
|
|
52
|
+
return Promise.resolve();
|
|
53
|
+
}
|
|
54
|
+
this.#enqueueReady(message, options);
|
|
55
|
+
return Promise.resolve();
|
|
56
|
+
}
|
|
57
|
+
#enqueueReady(message, options) {
|
|
58
|
+
const orderingKey = options?.orderingKey ?? null;
|
|
59
|
+
this.#messages.push({
|
|
60
|
+
message,
|
|
61
|
+
orderingKey
|
|
62
|
+
});
|
|
63
|
+
this.#notifyMonitors();
|
|
64
|
+
}
|
|
65
|
+
#notifyMonitors() {
|
|
66
|
+
for (const monitorId in this.#monitors) this.#monitors[monitorId]();
|
|
67
|
+
}
|
|
68
|
+
enqueueMany(messages, options) {
|
|
69
|
+
if (messages.length === 0) return Promise.resolve();
|
|
70
|
+
const delay = options?.delay == null ? 0 : Math.max(options.delay.total("millisecond"), 0);
|
|
71
|
+
if (delay > 0) {
|
|
72
|
+
const delayedCount = messages.length;
|
|
73
|
+
const deferredMessages = [...messages];
|
|
74
|
+
this.#delayedMessages += delayedCount;
|
|
75
|
+
setTimeout(() => {
|
|
76
|
+
this.#delayedMessages -= delayedCount;
|
|
77
|
+
this.#enqueueManyReady(deferredMessages, options);
|
|
78
|
+
}, delay);
|
|
79
|
+
return Promise.resolve();
|
|
80
|
+
}
|
|
81
|
+
this.#enqueueManyReady(messages, options);
|
|
82
|
+
return Promise.resolve();
|
|
83
|
+
}
|
|
84
|
+
#enqueueManyReady(messages, options) {
|
|
85
|
+
const orderingKey = options?.orderingKey ?? null;
|
|
86
|
+
for (const message of messages) this.#messages.push({
|
|
87
|
+
message,
|
|
88
|
+
orderingKey
|
|
89
|
+
});
|
|
90
|
+
this.#notifyMonitors();
|
|
91
|
+
}
|
|
92
|
+
async listen(handler, options = {}) {
|
|
93
|
+
const signal = options.signal;
|
|
94
|
+
while (signal == null || !signal.aborted) {
|
|
95
|
+
const idx = this.#messages.findIndex((m) => m.orderingKey == null || !this.#processingKeys.has(m.orderingKey));
|
|
96
|
+
if (idx >= 0) {
|
|
97
|
+
const { message, orderingKey } = this.#messages.splice(idx, 1)[0];
|
|
98
|
+
if (orderingKey != null) this.#processingKeys.add(orderingKey);
|
|
99
|
+
try {
|
|
100
|
+
await handler(message);
|
|
101
|
+
} finally {
|
|
102
|
+
if (orderingKey != null) this.#processingKeys.delete(orderingKey);
|
|
103
|
+
}
|
|
104
|
+
} else if (this.#messages.length === 0) await this.#wait(this.#pollIntervalMs, signal);
|
|
105
|
+
else await this.#wait(10, signal);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
getDepth() {
|
|
109
|
+
const ready = this.#messages.length;
|
|
110
|
+
const delayed = this.#delayedMessages;
|
|
111
|
+
return Promise.resolve({
|
|
112
|
+
queued: ready + delayed,
|
|
113
|
+
ready,
|
|
114
|
+
delayed
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
#wait(ms, signal) {
|
|
118
|
+
let timer = null;
|
|
119
|
+
return Promise.any([new Promise((resolve) => {
|
|
120
|
+
signal?.addEventListener("abort", () => {
|
|
121
|
+
if (timer != null) clearTimeout(timer);
|
|
122
|
+
resolve();
|
|
123
|
+
}, { once: true });
|
|
124
|
+
const monitorId = crypto.randomUUID();
|
|
125
|
+
this.#monitors[monitorId] = () => {
|
|
126
|
+
delete this.#monitors[monitorId];
|
|
127
|
+
if (timer != null) clearTimeout(timer);
|
|
128
|
+
resolve();
|
|
129
|
+
};
|
|
130
|
+
}), new Promise((resolve) => timer = setTimeout(resolve, ms))]);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* A message queue that processes messages in parallel. It takes another
|
|
135
|
+
* {@link MessageQueue}, and processes messages in parallel up to a certain
|
|
136
|
+
* number of workers.
|
|
137
|
+
*
|
|
138
|
+
* Actually, it's rather a decorator than a queue itself.
|
|
139
|
+
*
|
|
140
|
+
* Note that the workers do not run in truly parallel, in the sense that they
|
|
141
|
+
* are not running in separate threads or processes. They are running in the
|
|
142
|
+
* same process, but are scheduled to run in parallel. Hence, this is useful
|
|
143
|
+
* for I/O-bound tasks, but not for CPU-bound tasks, which is okay for Fedify's
|
|
144
|
+
* workloads.
|
|
145
|
+
*
|
|
146
|
+
* When using `ParallelMessageQueue`, the ordering guarantee is preserved
|
|
147
|
+
* *only if* the underlying queue implementation delivers messages in a wrapper
|
|
148
|
+
* format that includes the `__fedify_ordering_key__` property. Currently,
|
|
149
|
+
* only `DenoKvMessageQueue` and `WorkersMessageQueue` use this format.
|
|
150
|
+
* For other queue implementations (e.g., `InProcessMessageQueue`,
|
|
151
|
+
* `RedisMessageQueue`, `PostgresMessageQueue`, `SqliteMessageQueue`,
|
|
152
|
+
* `AmqpMessageQueue`), the ordering key cannot be detected by
|
|
153
|
+
* `ParallelMessageQueue`, so ordering guarantees are handled by those
|
|
154
|
+
* implementations directly rather than at the `ParallelMessageQueue` level.
|
|
155
|
+
*
|
|
156
|
+
* Messages with the same ordering key will never be processed concurrently
|
|
157
|
+
* by different workers, ensuring sequential processing within each key.
|
|
158
|
+
* Messages with different ordering keys (or no ordering key) can still be
|
|
159
|
+
* processed in parallel.
|
|
160
|
+
*
|
|
161
|
+
* @since 1.0.0
|
|
162
|
+
*/
|
|
163
|
+
var ParallelMessageQueue = class ParallelMessageQueue {
|
|
164
|
+
queue;
|
|
165
|
+
workers;
|
|
166
|
+
/**
|
|
167
|
+
* Inherits the native retry capability from the wrapped queue.
|
|
168
|
+
* @since 1.7.0
|
|
169
|
+
*/
|
|
170
|
+
nativeRetrial;
|
|
171
|
+
getDepth;
|
|
172
|
+
/**
|
|
173
|
+
* Tracks which ordering keys are currently being processed to ensure
|
|
174
|
+
* sequential processing for messages with the same key.
|
|
175
|
+
*/
|
|
176
|
+
#processingKeys = /* @__PURE__ */ new Set();
|
|
177
|
+
/**
|
|
178
|
+
* Pending messages waiting for their ordering key to become available.
|
|
179
|
+
*/
|
|
180
|
+
#pendingMessages = [];
|
|
181
|
+
/**
|
|
182
|
+
* Constructs a new {@link ParallelMessageQueue} with the given queue and
|
|
183
|
+
* number of workers.
|
|
184
|
+
* @param queue The message queue to use under the hood. Note that
|
|
185
|
+
* {@link ParallelMessageQueue} cannot be nested.
|
|
186
|
+
* @param workers The number of workers to process messages in parallel.
|
|
187
|
+
* @throws {TypeError} If the given queue is an instance of
|
|
188
|
+
* {@link ParallelMessageQueue}.
|
|
189
|
+
*/
|
|
190
|
+
constructor(queue, workers) {
|
|
191
|
+
if (queue instanceof ParallelMessageQueue) throw new TypeError("Cannot nest ParallelMessageQueue.");
|
|
192
|
+
this.queue = queue;
|
|
193
|
+
this.workers = workers;
|
|
194
|
+
this.nativeRetrial = queue.nativeRetrial;
|
|
195
|
+
if (queue.getDepth != null) this.getDepth = () => queue.getDepth();
|
|
196
|
+
}
|
|
197
|
+
enqueue(message, options) {
|
|
198
|
+
return this.queue.enqueue(message, options);
|
|
199
|
+
}
|
|
200
|
+
async enqueueMany(messages, options) {
|
|
201
|
+
if (this.queue.enqueueMany == null) {
|
|
202
|
+
const errors = (await Promise.allSettled(messages.map((message) => this.queue.enqueue(message, options)))).filter((r) => r.status === "rejected").map((r) => r.reason);
|
|
203
|
+
if (errors.length > 1) throw new AggregateError(errors, "Failed to enqueue messages.");
|
|
204
|
+
else if (errors.length === 1) throw errors[0];
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
await this.queue.enqueueMany(messages, options);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Extracts ordering key from a message if present.
|
|
211
|
+
*
|
|
212
|
+
* This method only works for queue implementations that deliver messages
|
|
213
|
+
* in the wrapper format with `__fedify_ordering_key__` property. Currently,
|
|
214
|
+
* only `DenoKvMessageQueue` and `WorkersMessageQueue` use this format.
|
|
215
|
+
*
|
|
216
|
+
* For other queue implementations (`InProcessMessageQueue`,
|
|
217
|
+
* `RedisMessageQueue`, `PostgresMessageQueue`, `SqliteMessageQueue`,
|
|
218
|
+
* `AmqpMessageQueue`), messages are delivered as raw payloads without the
|
|
219
|
+
* wrapper, so the ordering key cannot be detected here. Those
|
|
220
|
+
* implementations handle ordering guarantees internally.
|
|
221
|
+
*/
|
|
222
|
+
#extractOrderingKey(message) {
|
|
223
|
+
if (message != null && typeof message === "object") {
|
|
224
|
+
if ("__fedify_ordering_key__" in message) return message.__fedify_ordering_key__;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
listen(handler, options = {}) {
|
|
228
|
+
const workers = /* @__PURE__ */ new Map();
|
|
229
|
+
return this.queue.listen(async (message) => {
|
|
230
|
+
while (workers.size >= this.workers) {
|
|
231
|
+
const consumedId = await Promise.any(workers.values());
|
|
232
|
+
workers.delete(consumedId);
|
|
233
|
+
}
|
|
234
|
+
const workerId = crypto.randomUUID();
|
|
235
|
+
const orderingKey = this.#extractOrderingKey(message);
|
|
236
|
+
if (orderingKey != null && this.#processingKeys.has(orderingKey)) await new Promise((resolve) => {
|
|
237
|
+
this.#pendingMessages.push({
|
|
238
|
+
message,
|
|
239
|
+
orderingKey,
|
|
240
|
+
resolve
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
if (orderingKey != null) this.#processingKeys.add(orderingKey);
|
|
244
|
+
const promise = this.#work(workerId, handler, message, orderingKey);
|
|
245
|
+
workers.set(workerId, promise);
|
|
246
|
+
}, options);
|
|
247
|
+
}
|
|
248
|
+
async #work(workerId, handler, message, orderingKey) {
|
|
249
|
+
await this.#sleep(0);
|
|
250
|
+
try {
|
|
251
|
+
await handler(message);
|
|
252
|
+
} finally {
|
|
253
|
+
if (orderingKey != null) {
|
|
254
|
+
this.#processingKeys.delete(orderingKey);
|
|
255
|
+
const pendingIdx = this.#pendingMessages.findIndex((p) => p.orderingKey === orderingKey);
|
|
256
|
+
if (pendingIdx >= 0) this.#pendingMessages.splice(pendingIdx, 1)[0].resolve();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return workerId;
|
|
260
|
+
}
|
|
261
|
+
#sleep(ms) {
|
|
262
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
//#endregion
|
|
11
266
|
//#region src/federation/mq.test.ts
|
|
12
267
|
async function disposeMessageQueue(mq) {
|
|
13
268
|
if (Symbol.asyncDispose in mq) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import "../std__assert-
|
|
5
|
-
import { r as assertFalse } from "../assert_rejects-
|
|
6
|
-
import { t as assert } from "../assert-
|
|
7
|
-
import { t as acceptsJsonLd } from "../negotiation-
|
|
4
|
+
import "../std__assert-BBjXFNOb.mjs";
|
|
5
|
+
import { r as assertFalse } from "../assert_rejects-DN60FHPX.mjs";
|
|
6
|
+
import { t as assert } from "../assert-OguE97r2.mjs";
|
|
7
|
+
import { t as acceptsJsonLd } from "../negotiation-DDstyBvc.mjs";
|
|
8
8
|
import { test } from "@fedify/fixture";
|
|
9
9
|
//#region src/federation/negotiation.test.ts
|
|
10
10
|
test("acceptsJsonLd()", () => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { l as AssertionError, t as assertEquals } from "../assert_equals-
|
|
5
|
-
import { t as assertNotEquals } from "../assert_not_equals
|
|
6
|
-
import { t as createExponentialBackoffPolicy } from "../retry-
|
|
4
|
+
import { l as AssertionError, t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
|
|
5
|
+
import { t as assertNotEquals } from "../assert_not_equals-DkVK8oqV.mjs";
|
|
6
|
+
import { t as createExponentialBackoffPolicy } from "../retry-CXg_MBI-.mjs";
|
|
7
7
|
import { test } from "@fedify/fixture";
|
|
8
8
|
//#region src/federation/retry.test.ts
|
|
9
9
|
test("createExponentialBackoffPolicy()", () => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { t as assertEquals } from "../assert_equals-
|
|
5
|
-
import "../std__assert-
|
|
6
|
-
import { r as assertFalse } from "../assert_rejects-
|
|
7
|
-
import { t as assertThrows } from "../assert_throws-
|
|
8
|
-
import { t as assert } from "../assert-
|
|
4
|
+
import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
|
|
5
|
+
import "../std__assert-BBjXFNOb.mjs";
|
|
6
|
+
import { r as assertFalse } from "../assert_rejects-DN60FHPX.mjs";
|
|
7
|
+
import { t as assertThrows } from "../assert_throws-BOkhLGYc.mjs";
|
|
8
|
+
import { t as assert } from "../assert-OguE97r2.mjs";
|
|
9
9
|
import { getLogger } from "@logtape/logtape";
|
|
10
10
|
import { Router, RouterError, assertPath, isPath } from "@fedify/uri-template";
|
|
11
11
|
import { test } from "@fedify/fixture";
|