@fedify/fedify 2.4.0-dev.1634 → 2.4.0-pr.934.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +3 -0
  2. package/dist/{builder-DYAAegyy.mjs → builder-BBPwtB2v.mjs} +2 -2
  3. package/dist/compat/mod.d.cts +1 -1
  4. package/dist/compat/mod.d.ts +1 -1
  5. package/dist/compat/transformers.test.mjs +1 -1
  6. package/dist/{context-lxX6I7as.d.cts → context-C05Rgxmu.d.cts} +1 -1
  7. package/dist/{context-Zii1f5xS.d.ts → context-Cjnr0ig1.d.ts} +1 -1
  8. package/dist/{deno-C30u61BX.mjs → deno-D3c0o_N0.mjs} +1 -1
  9. package/dist/{docloader-C8JfZ3bD.mjs → docloader-BCecHIxU.mjs} +2 -2
  10. package/dist/federation/builder.test.mjs +1 -1
  11. package/dist/federation/handler.test.mjs +3 -5
  12. package/dist/federation/idempotency.test.mjs +2 -2
  13. package/dist/federation/metrics.test.mjs +1 -1
  14. package/dist/federation/middleware.test.mjs +7 -7
  15. package/dist/federation/mod.cjs +288 -9
  16. package/dist/federation/mod.d.cts +3 -3
  17. package/dist/federation/mod.d.ts +3 -3
  18. package/dist/federation/mod.js +279 -1
  19. package/dist/federation/mq.test.mjs +20 -1
  20. package/dist/federation/send.test.mjs +3 -3
  21. package/dist/federation/tasks/enqueue.test.mjs +39 -2
  22. package/dist/federation/tasks/tasks.test.mjs +3 -3
  23. package/dist/federation/temporal.test.mjs +1 -1
  24. package/dist/federation/webfinger.test.mjs +1 -1
  25. package/dist/{http-D_cl_PbN.js → http-Ctb_KhZ8.js} +1 -1
  26. package/dist/{http-DJEaNMSB.mjs → http-Dm0JAUa_.mjs} +3 -3
  27. package/dist/{http-DiMJDFtd.cjs → http-jr0TkgZe.cjs} +1 -1
  28. package/dist/{key-C1tsoBAW.mjs → key-C_gNKtxm.mjs} +2 -2
  29. package/dist/{kv-cache-D9Tia3Td.mjs → kv-cache-B7H7lZ84.mjs} +1 -1
  30. package/dist/{kv-cache-EL9jIFqA.js → kv-cache-BxUZRBC2.js} +1 -1
  31. package/dist/{kv-cache-BInLi0Ro.cjs → kv-cache-D-hbjJAD.cjs} +1 -1
  32. package/dist/{ld-CDBNQmZD.mjs → ld-DAPAVL_7.mjs} +3 -3
  33. package/dist/{metrics-De7b7Hgb.mjs → metrics-BMaatuZi.mjs} +1 -1
  34. package/dist/{metrics-CoUJLQhZ.d.cts → metrics-DN13mCAw.d.cts} +19 -1
  35. package/dist/{metrics-Dc4jR-IC.d.ts → metrics-v_e0n5GQ.d.ts} +19 -1
  36. package/dist/{middleware-BPHpdYl4.cjs → middleware-BW7WQltk.cjs} +40 -325
  37. package/dist/{middleware-8oyKaRYF.js → middleware-CfZR_riY.js} +6 -278
  38. package/dist/{middleware-DloBgcWp.mjs → middleware-DfPBAh9L.mjs} +1 -1
  39. package/dist/{middleware-CPlgpBML.mjs → middleware-O2LHXFEk.mjs} +14 -15
  40. package/dist/{mod-BtEaIEcD.d.cts → mod-BrpVsSfY.d.cts} +1 -1
  41. package/dist/{mod-DLc2Ot6f.d.ts → mod-BsCE5Ihq.d.ts} +1 -1
  42. package/dist/{mod-UMmveiO0.d.ts → mod-CNef4in0.d.ts} +1 -1
  43. package/dist/{mod-gOlPDuT8.d.cts → mod-DdONo-ep.d.cts} +1 -1
  44. package/dist/mod.cjs +6 -6
  45. package/dist/mod.d.cts +4 -4
  46. package/dist/mod.d.ts +4 -4
  47. package/dist/mod.js +5 -5
  48. package/dist/{mq-llHKivST.mjs → mq-Bo7Etgh6.mjs} +6 -0
  49. package/dist/nodeinfo/handler.test.mjs +1 -1
  50. package/dist/{owner-CB3dPva0.mjs → owner-Dcx-czqn.mjs} +2 -2
  51. package/dist/{proof-BqDtIxGz.mjs → proof-BkAxvrjt.mjs} +3 -3
  52. package/dist/{proof-DT5SgzkH.js → proof-D-H_PnJW.js} +1 -1
  53. package/dist/{proof-BI4Wn6Ur.cjs → proof-NY0D8Oux.cjs} +1 -1
  54. package/dist/{send-ClWims8x.mjs → send-D_j7E-oC.mjs} +3 -3
  55. package/dist/sig/http.test.mjs +2 -2
  56. package/dist/sig/key.test.mjs +1 -1
  57. package/dist/sig/ld.test.mjs +2 -2
  58. package/dist/sig/mod.cjs +2 -2
  59. package/dist/sig/mod.js +2 -2
  60. package/dist/sig/owner.test.mjs +1 -1
  61. package/dist/sig/proof.test.mjs +1 -1
  62. package/dist/{temporal-DyITEDcU.mjs → temporal-yE5EcfNX.mjs} +1 -1
  63. package/dist/testing/mod.d.mts +14 -1
  64. package/dist/utils/docloader.test.mjs +2 -2
  65. package/dist/utils/kv-cache.test.mjs +1 -1
  66. package/dist/utils/mod.cjs +1 -1
  67. package/dist/utils/mod.d.cts +1 -1
  68. package/dist/utils/mod.d.ts +1 -1
  69. package/dist/utils/mod.js +1 -1
  70. package/package.json +6 -6
  71. package/skills/fedify/SKILL.md +462 -0
@@ -1,6 +1,6 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
- import { a as ParallelMessageQueue, c as respondWithObject, d as digest, f as CircuitBreaker, h as createFederationBuilder, i as InProcessMessageQueue, l as respondWithObjectIfAcceptable, m as parseCircuitBreakerKvState, o as createExponentialBackoffPolicy, p as normalizeCircuitBreakerOptions, r as handleWebFinger, s as SendActivityError, t as createFederation, u as buildCollectionSynchronizationHeader } from "../middleware-8oyKaRYF.js";
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-CfZR_riY.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";
@@ -91,6 +91,284 @@ var MemoryKvStore = class {
91
91
  }
92
92
  };
93
93
  //#endregion
94
+ //#region src/federation/mq.ts
95
+ /**
96
+ * A message queue that processes messages in the same process.
97
+ * Do not use this in production as it does neither persist messages nor
98
+ * distribute them across multiple processes.
99
+ *
100
+ * @since 0.5.0
101
+ */
102
+ var InProcessMessageQueue = class {
103
+ #messages;
104
+ #monitors;
105
+ #pollIntervalMs;
106
+ #delayedMessages;
107
+ /**
108
+ * Tracks which ordering keys are currently being processed to ensure
109
+ * sequential processing for messages with the same key.
110
+ */
111
+ #processingKeys;
112
+ /**
113
+ * In-process message queue does not provide native retry mechanisms.
114
+ * @since 1.7.0
115
+ */
116
+ nativeRetrial = false;
117
+ /**
118
+ * In-process message queue does not deduplicate messages natively.
119
+ * @since 2.4.0
120
+ */
121
+ nativeDeduplication = false;
122
+ /**
123
+ * Constructs a new {@link InProcessMessageQueue} with the given options.
124
+ * @param options Additional options for the in-process message queue.
125
+ */
126
+ constructor(options = {}) {
127
+ this.#messages = [];
128
+ this.#monitors = {};
129
+ this.#pollIntervalMs = Temporal.Duration.from(options.pollInterval ?? { seconds: 5 }).total("millisecond");
130
+ this.#delayedMessages = 0;
131
+ this.#processingKeys = /* @__PURE__ */ new Set();
132
+ }
133
+ enqueue(message, options) {
134
+ const delay = options?.delay == null ? 0 : Math.max(options.delay.total("millisecond"), 0);
135
+ if (delay > 0) {
136
+ this.#delayedMessages++;
137
+ setTimeout(() => {
138
+ this.#delayedMessages--;
139
+ this.#enqueueReady(message, options);
140
+ }, delay);
141
+ return Promise.resolve();
142
+ }
143
+ this.#enqueueReady(message, options);
144
+ return Promise.resolve();
145
+ }
146
+ #enqueueReady(message, options) {
147
+ const orderingKey = options?.orderingKey ?? null;
148
+ this.#messages.push({
149
+ message,
150
+ orderingKey
151
+ });
152
+ this.#notifyMonitors();
153
+ }
154
+ #notifyMonitors() {
155
+ for (const monitorId in this.#monitors) this.#monitors[monitorId]();
156
+ }
157
+ enqueueMany(messages, options) {
158
+ if (messages.length === 0) return Promise.resolve();
159
+ const delay = options?.delay == null ? 0 : Math.max(options.delay.total("millisecond"), 0);
160
+ if (delay > 0) {
161
+ const delayedCount = messages.length;
162
+ const deferredMessages = [...messages];
163
+ this.#delayedMessages += delayedCount;
164
+ setTimeout(() => {
165
+ this.#delayedMessages -= delayedCount;
166
+ this.#enqueueManyReady(deferredMessages, options);
167
+ }, delay);
168
+ return Promise.resolve();
169
+ }
170
+ this.#enqueueManyReady(messages, options);
171
+ return Promise.resolve();
172
+ }
173
+ #enqueueManyReady(messages, options) {
174
+ const orderingKey = options?.orderingKey ?? null;
175
+ for (const message of messages) this.#messages.push({
176
+ message,
177
+ orderingKey
178
+ });
179
+ this.#notifyMonitors();
180
+ }
181
+ async listen(handler, options = {}) {
182
+ const signal = options.signal;
183
+ while (signal == null || !signal.aborted) {
184
+ const idx = this.#messages.findIndex((m) => m.orderingKey == null || !this.#processingKeys.has(m.orderingKey));
185
+ if (idx >= 0) {
186
+ const { message, orderingKey } = this.#messages.splice(idx, 1)[0];
187
+ if (orderingKey != null) this.#processingKeys.add(orderingKey);
188
+ try {
189
+ await handler(message);
190
+ } finally {
191
+ if (orderingKey != null) this.#processingKeys.delete(orderingKey);
192
+ }
193
+ } else if (this.#messages.length === 0) await this.#wait(this.#pollIntervalMs, signal);
194
+ else await this.#wait(10, signal);
195
+ }
196
+ }
197
+ getDepth() {
198
+ const ready = this.#messages.length;
199
+ const delayed = this.#delayedMessages;
200
+ return Promise.resolve({
201
+ queued: ready + delayed,
202
+ ready,
203
+ delayed
204
+ });
205
+ }
206
+ #wait(ms, signal) {
207
+ let timer = null;
208
+ return Promise.any([new Promise((resolve) => {
209
+ signal?.addEventListener("abort", () => {
210
+ if (timer != null) clearTimeout(timer);
211
+ resolve();
212
+ }, { once: true });
213
+ const monitorId = crypto.randomUUID();
214
+ this.#monitors[monitorId] = () => {
215
+ delete this.#monitors[monitorId];
216
+ if (timer != null) clearTimeout(timer);
217
+ resolve();
218
+ };
219
+ }), new Promise((resolve) => timer = setTimeout(resolve, ms))]);
220
+ }
221
+ };
222
+ /**
223
+ * A message queue that processes messages in parallel. It takes another
224
+ * {@link MessageQueue}, and processes messages in parallel up to a certain
225
+ * number of workers.
226
+ *
227
+ * Actually, it's rather a decorator than a queue itself.
228
+ *
229
+ * Note that the workers do not run in truly parallel, in the sense that they
230
+ * are not running in separate threads or processes. They are running in the
231
+ * same process, but are scheduled to run in parallel. Hence, this is useful
232
+ * for I/O-bound tasks, but not for CPU-bound tasks, which is okay for Fedify's
233
+ * workloads.
234
+ *
235
+ * When using `ParallelMessageQueue`, the ordering guarantee is preserved
236
+ * *only if* the underlying queue implementation delivers messages in a wrapper
237
+ * format that includes the `__fedify_ordering_key__` property. Currently,
238
+ * only `DenoKvMessageQueue` and `WorkersMessageQueue` use this format.
239
+ * For other queue implementations (e.g., `InProcessMessageQueue`,
240
+ * `RedisMessageQueue`, `PostgresMessageQueue`, `SqliteMessageQueue`,
241
+ * `AmqpMessageQueue`), the ordering key cannot be detected by
242
+ * `ParallelMessageQueue`, so ordering guarantees are handled by those
243
+ * implementations directly rather than at the `ParallelMessageQueue` level.
244
+ *
245
+ * Messages with the same ordering key will never be processed concurrently
246
+ * by different workers, ensuring sequential processing within each key.
247
+ * Messages with different ordering keys (or no ordering key) can still be
248
+ * processed in parallel.
249
+ *
250
+ * @since 1.0.0
251
+ */
252
+ var ParallelMessageQueue = class ParallelMessageQueue {
253
+ queue;
254
+ workers;
255
+ /**
256
+ * Inherits the native retry capability from the wrapped queue.
257
+ * @since 1.7.0
258
+ */
259
+ nativeRetrial;
260
+ /**
261
+ * Inherits the native deduplication capability from the wrapped queue.
262
+ * @since 2.4.0
263
+ */
264
+ nativeDeduplication;
265
+ /**
266
+ * Inherits the atomic batch capability from the wrapped queue.
267
+ * @since 2.4.0
268
+ */
269
+ atomicEnqueueMany;
270
+ getDepth;
271
+ /**
272
+ * Tracks which ordering keys are currently being processed to ensure
273
+ * sequential processing for messages with the same key.
274
+ */
275
+ #processingKeys = /* @__PURE__ */ new Set();
276
+ /**
277
+ * Pending messages waiting for their ordering key to become available.
278
+ */
279
+ #pendingMessages = [];
280
+ /**
281
+ * Constructs a new {@link ParallelMessageQueue} with the given queue and
282
+ * number of workers.
283
+ * @param queue The message queue to use under the hood. Note that
284
+ * {@link ParallelMessageQueue} cannot be nested.
285
+ * @param workers The number of workers to process messages in parallel.
286
+ * @throws {TypeError} If the given queue is an instance of
287
+ * {@link ParallelMessageQueue}.
288
+ */
289
+ constructor(queue, workers) {
290
+ if (queue instanceof ParallelMessageQueue) throw new TypeError("Cannot nest ParallelMessageQueue.");
291
+ this.queue = queue;
292
+ this.workers = workers;
293
+ this.nativeRetrial = queue.nativeRetrial;
294
+ this.nativeDeduplication = queue.nativeDeduplication;
295
+ this.atomicEnqueueMany = queue.enqueueMany == null ? false : queue.atomicEnqueueMany;
296
+ if (queue.getDepth != null) this.getDepth = () => queue.getDepth();
297
+ }
298
+ enqueue(message, options) {
299
+ return this.queue.enqueue(message, options);
300
+ }
301
+ async enqueueMany(messages, options) {
302
+ if (this.queue.enqueueMany == null) {
303
+ if (messages.length === 1) {
304
+ await this.queue.enqueue(messages[0], options);
305
+ return;
306
+ }
307
+ if (options?.deduplicationKey != null) throw new TypeError("Cannot enqueue a batch with a deduplicationKey: the wrapped queue does not implement enqueueMany, so ParallelMessageQueue would have to fan out to individual enqueue() calls that cannot share one deduplicationKey atomically. Wrap a queue that implements enqueueMany instead.");
308
+ const errors = (await Promise.allSettled(messages.map((message) => this.queue.enqueue(message, options)))).filter((r) => r.status === "rejected").map((r) => r.reason);
309
+ if (errors.length > 1) throw new AggregateError(errors, "Failed to enqueue messages.");
310
+ else if (errors.length === 1) throw errors[0];
311
+ return;
312
+ }
313
+ await this.queue.enqueueMany(messages, options);
314
+ }
315
+ /**
316
+ * Extracts ordering key from a message if present.
317
+ *
318
+ * This method only works for queue implementations that deliver messages
319
+ * in the wrapper format with `__fedify_ordering_key__` property. Currently,
320
+ * only `DenoKvMessageQueue` and `WorkersMessageQueue` use this format.
321
+ *
322
+ * For other queue implementations (`InProcessMessageQueue`,
323
+ * `RedisMessageQueue`, `PostgresMessageQueue`, `SqliteMessageQueue`,
324
+ * `AmqpMessageQueue`), messages are delivered as raw payloads without the
325
+ * wrapper, so the ordering key cannot be detected here. Those
326
+ * implementations handle ordering guarantees internally.
327
+ */
328
+ #extractOrderingKey(message) {
329
+ if (message != null && typeof message === "object") {
330
+ if ("__fedify_ordering_key__" in message) return message.__fedify_ordering_key__;
331
+ }
332
+ }
333
+ listen(handler, options = {}) {
334
+ const workers = /* @__PURE__ */ new Map();
335
+ return this.queue.listen(async (message) => {
336
+ while (workers.size >= this.workers) {
337
+ const consumedId = await Promise.any(workers.values());
338
+ workers.delete(consumedId);
339
+ }
340
+ const workerId = crypto.randomUUID();
341
+ const orderingKey = this.#extractOrderingKey(message);
342
+ if (orderingKey != null && this.#processingKeys.has(orderingKey)) await new Promise((resolve) => {
343
+ this.#pendingMessages.push({
344
+ message,
345
+ orderingKey,
346
+ resolve
347
+ });
348
+ });
349
+ if (orderingKey != null) this.#processingKeys.add(orderingKey);
350
+ const promise = this.#work(workerId, handler, message, orderingKey);
351
+ workers.set(workerId, promise);
352
+ }, options);
353
+ }
354
+ async #work(workerId, handler, message, orderingKey) {
355
+ await this.#sleep(0);
356
+ try {
357
+ await handler(message);
358
+ } finally {
359
+ if (orderingKey != null) {
360
+ this.#processingKeys.delete(orderingKey);
361
+ const pendingIdx = this.#pendingMessages.findIndex((p) => p.orderingKey === orderingKey);
362
+ if (pendingIdx >= 0) this.#pendingMessages.splice(pendingIdx, 1)[0].resolve();
363
+ }
364
+ }
365
+ return workerId;
366
+ }
367
+ #sleep(ms) {
368
+ return new Promise((resolve) => setTimeout(resolve, ms));
369
+ }
370
+ };
371
+ //#endregion
94
372
  //#region src/federation/router.ts
95
373
  const logger = getLogger([
96
374
  "fedify",
@@ -5,7 +5,7 @@ import { t as assertEquals } from "../assert_equals-BV7oLMxm.mjs";
5
5
  import { n as assertGreater } from "../std__assert-B2NnY9bq.mjs";
6
6
  import { n as assertGreaterOrEqual, r as assertFalse, t as assertRejects } from "../assert_rejects-EgstcQy5.mjs";
7
7
  import { t as assert } from "../assert-CJ1KXcvv.mjs";
8
- import { n as ParallelMessageQueue, t as InProcessMessageQueue } from "../mq-llHKivST.mjs";
8
+ import { n as ParallelMessageQueue, t as InProcessMessageQueue } from "../mq-Bo7Etgh6.mjs";
9
9
  import { delay } from "es-toolkit";
10
10
  import { test } from "@fedify/fixture";
11
11
  //#region src/federation/mq.test.ts
@@ -327,6 +327,21 @@ test("ParallelMessageQueue inherits nativeDeduplication", () => {
327
327
  }
328
328
  assert(new ParallelMessageQueue(new NativeDeduplicationQueue(), 5).nativeDeduplication);
329
329
  });
330
+ test("ParallelMessageQueue inherits atomicEnqueueMany", () => {
331
+ class NonAtomicBatchQueue {
332
+ atomicEnqueueMany = false;
333
+ enqueue() {
334
+ return Promise.resolve();
335
+ }
336
+ enqueueMany() {
337
+ return Promise.resolve();
338
+ }
339
+ listen() {
340
+ return Promise.resolve();
341
+ }
342
+ }
343
+ assertFalse(new ParallelMessageQueue(new NonAtomicBatchQueue(), 5).atomicEnqueueMany);
344
+ });
330
345
  test("ParallelMessageQueue forwards deduplicationKey to the wrapped queue", async () => {
331
346
  class RecordingQueue {
332
347
  nativeDeduplication = true;
@@ -365,6 +380,7 @@ test("ParallelMessageQueue rejects a deduplicated batch when the wrapped queue l
365
380
  }
366
381
  const inner = new NoBulkQueue();
367
382
  const workers = new ParallelMessageQueue(inner, 5);
383
+ assertFalse(workers.atomicEnqueueMany);
368
384
  await assertRejects(() => workers.enqueueMany([{ x: 1 }, { x: 2 }], { deduplicationKey: "k" }), TypeError, "enqueueMany");
369
385
  assertEquals(inner.enqueued.length, 0);
370
386
  });
@@ -424,6 +440,9 @@ for (const mqName in queues) test({
424
440
  await t.step("nativeDeduplication property inheritance", () => {
425
441
  assertEquals(workers.nativeDeduplication, mq.nativeDeduplication);
426
442
  });
443
+ await t.step("atomicEnqueueMany capability propagation", () => {
444
+ assertEquals(workers.atomicEnqueueMany, mq.enqueueMany == null ? false : mq.atomicEnqueueMany);
445
+ });
427
446
  await t.step("getDepth() delegation", async () => {
428
447
  if (mq.getDepth == null) assertEquals(workers.getDepth, void 0);
429
448
  else assertEquals(await workers.getDepth?.(), await mq.getDepth());
@@ -8,10 +8,10 @@ import { n as assertGreaterOrEqual, r as assertFalse, t as assertRejects } from
8
8
  import { t as assertInstanceOf } from "../assert_instance_of-Q9KTBnrf.mjs";
9
9
  import { t as assertNotEquals } from "../assert_not_equals-EPJPoxuf.mjs";
10
10
  import { t as assert } from "../assert-CJ1KXcvv.mjs";
11
- import { l as verifyRequest } from "../http-DJEaNMSB.mjs";
11
+ import { l as verifyRequest } from "../http-Dm0JAUa_.mjs";
12
12
  import { i as rsaPrivateKey2, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-Dbyd7bhl.mjs";
13
- import { t as doesActorOwnKey } from "../owner-CB3dPva0.mjs";
14
- import { n as extractInboxes, r as sendActivity, t as SendActivityError } from "../send-ClWims8x.mjs";
13
+ import { t as doesActorOwnKey } from "../owner-Dcx-czqn.mjs";
14
+ import { n as extractInboxes, r as sendActivity, t as SendActivityError } from "../send-D_j7E-oC.mjs";
15
15
  import { Activity, Application, Endpoints, Group, Person, Service } from "@fedify/vocab";
16
16
  import { createTestMeterProvider, createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
17
17
  import { FetchError } from "@fedify/vocab-runtime";
@@ -3,8 +3,8 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as MemoryKvStore } from "../../kv-CXBAok3k.mjs";
5
5
  import { a as numberSchema, i as makeSchema, n as baseOptions, o as stringSchema, t as MockQueue } from "../../testing-CO7ftO8A.mjs";
6
- import { o as createFederation } from "../../middleware-CPlgpBML.mjs";
7
- import { n as ParallelMessageQueue } from "../../mq-llHKivST.mjs";
6
+ import { o as createFederation } from "../../middleware-O2LHXFEk.mjs";
7
+ import { n as ParallelMessageQueue } from "../../mq-Bo7Etgh6.mjs";
8
8
  import { configure, reset } from "@logtape/logtape";
9
9
  import { delay } from "es-toolkit";
10
10
  import { createTestMeterProvider, test } from "@fedify/fixture";
@@ -760,6 +760,43 @@ test("a multi-item batch dedup without enqueueMany is rejected on the cas path",
760
760
  await ctx.enqueueTaskMany(task, ["single"], { deduplicationKey: "single" });
761
761
  strictEqual(queue.enqueued.length, 1);
762
762
  });
763
+ test("a non-atomic enqueueMany is rejected for batch deduplication", async () => {
764
+ class NonAtomicBatchQueue extends MockQueue {
765
+ atomicEnqueueMany = false;
766
+ constructor() {
767
+ super({ supportsEnqueueMany: true });
768
+ }
769
+ }
770
+ const queue = new NonAtomicBatchQueue();
771
+ const kv = new MemoryKvStore();
772
+ const federation = createFederation({
773
+ ...baseOptions,
774
+ kv,
775
+ queue: { task: queue }
776
+ });
777
+ const task = federation.defineTask("cas-non-atomic-batch", {
778
+ schema: stringSchema,
779
+ handler: () => {}
780
+ });
781
+ const ctx = federation.createContext(new URL("https://example.com/"), void 0);
782
+ await rejects(() => ctx.enqueueTaskMany(task, [
783
+ "a",
784
+ "b",
785
+ "c"
786
+ ], { deduplicationKey: "batch" }), {
787
+ name: "TypeError",
788
+ message: /atomically/
789
+ });
790
+ strictEqual(queue.enqueued.length, 0);
791
+ strictEqual(queue.enqueuedMany.length, 0);
792
+ deepStrictEqual(await collectKeys(kv, TASK_DEDUP_PREFIX), []);
793
+ await ctx.enqueueTaskMany(task, [
794
+ "a",
795
+ "b",
796
+ "c"
797
+ ]);
798
+ strictEqual(queue.enqueuedMany.length, 1);
799
+ });
763
800
  test("a failed rollback is swallowed; the original enqueue error reaches the caller", async () => {
764
801
  class ClearFailingKvStore {
765
802
  inner = new MemoryKvStore();
@@ -3,10 +3,10 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as MemoryKvStore } from "../../kv-CXBAok3k.mjs";
5
5
  import { a as numberSchema, i as makeSchema, n as baseOptions, o as stringSchema, t as MockQueue } from "../../testing-CO7ftO8A.mjs";
6
- import { o as createFederation } from "../../middleware-CPlgpBML.mjs";
7
- import { r as createFederationBuilder } from "../../builder-DYAAegyy.mjs";
6
+ import { o as createFederation } from "../../middleware-O2LHXFEk.mjs";
7
+ import { r as createFederationBuilder } from "../../builder-BBPwtB2v.mjs";
8
8
  import { t as TaskCodec } from "../../codec-BBga-FWI.mjs";
9
- import { t as InProcessMessageQueue } from "../../mq-llHKivST.mjs";
9
+ import { t as InProcessMessageQueue } from "../../mq-Bo7Etgh6.mjs";
10
10
  import { W3CTraceContextPropagator } from "@opentelemetry/core";
11
11
  import { Note } from "@fedify/vocab";
12
12
  import { SpanStatusCode, propagation } from "@opentelemetry/api";
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
4
4
  import "../std__assert-B2NnY9bq.mjs";
5
5
  import { r as assertFalse } from "../assert_rejects-EgstcQy5.mjs";
6
6
  import { t as assert } from "../assert-CJ1KXcvv.mjs";
7
- import { t as hasMalformedKnownTemporalLiteral } from "../temporal-DyITEDcU.mjs";
7
+ import { t as hasMalformedKnownTemporalLiteral } from "../temporal-yE5EcfNX.mjs";
8
8
  import { test } from "@fedify/fixture";
9
9
  //#region src/federation/temporal.test.ts
10
10
  test("hasMalformedKnownTemporalLiteral() detects expanded proof timestamps", async () => {
@@ -6,7 +6,7 @@ import { t as MemoryKvStore } from "../kv-CXBAok3k.mjs";
6
6
  import { t as assertEquals } from "../assert_equals-BV7oLMxm.mjs";
7
7
  import "../std__assert-B2NnY9bq.mjs";
8
8
  import { t as assertNotEquals } from "../assert_not_equals-EPJPoxuf.mjs";
9
- import { o as createFederation, s as handleWebFinger } from "../middleware-CPlgpBML.mjs";
9
+ import { o as createFederation, s as handleWebFinger } from "../middleware-O2LHXFEk.mjs";
10
10
  import { Image, Link, Person, Tombstone } from "@fedify/vocab";
11
11
  import { createTestMeterProvider, test } from "@fedify/fixture";
12
12
  //#region src/federation/webfinger.test.ts
@@ -10,7 +10,7 @@ import { ATTR_HTTP_REQUEST_HEADER, ATTR_HTTP_REQUEST_METHOD, ATTR_URL_FULL } fro
10
10
  import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
11
11
  //#region deno.json
12
12
  var name = "@fedify/fedify";
13
- var version = "2.4.0-dev.1634+3b4bfbb6";
13
+ var version = "2.4.0-pr.934.40+3331d302";
14
14
  //#endregion
15
15
  //#region src/sig/accept.ts
16
16
  /**
@@ -1,10 +1,10 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-C30u61BX.mjs";
5
- import { n as getDurationMs, r as getFederationMetrics, s as measureSignatureKeyFetch } from "./metrics-De7b7Hgb.mjs";
4
+ import { n as version, t as name } from "./deno-D3c0o_N0.mjs";
5
+ import { n as getDurationMs, r as getFederationMetrics, s as measureSignatureKeyFetch } from "./metrics-BMaatuZi.mjs";
6
6
  import { i as validateAcceptSignature, n as fulfillAcceptSignature, r as parseAcceptSignature } from "./accept-8PiolDP7.mjs";
7
- import { o as validateCryptoKey, r as fetchKeyDetailed } from "./key-C1tsoBAW.mjs";
7
+ import { o as validateCryptoKey, r as fetchKeyDetailed } from "./key-C_gNKtxm.mjs";
8
8
  import { getLogger } from "@logtape/logtape";
9
9
  import { CryptographicKey } from "@fedify/vocab";
10
10
  import { SpanStatusCode, trace } from "@opentelemetry/api";
@@ -11,7 +11,7 @@ let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conve
11
11
  let byte_encodings_base64 = require("byte-encodings/base64");
12
12
  //#region deno.json
13
13
  var name = "@fedify/fedify";
14
- var version = "2.4.0-dev.1634+3b4bfbb6";
14
+ var version = "2.4.0-pr.934.40+3331d302";
15
15
  //#endregion
16
16
  //#region src/sig/accept.ts
17
17
  /**
@@ -1,8 +1,8 @@
1
1
  import "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-C30u61BX.mjs";
5
- import { _ as recordKeyLookup, n as getDurationMs, t as classifyFetchError } from "./metrics-De7b7Hgb.mjs";
4
+ import { n as version, t as name } from "./deno-D3c0o_N0.mjs";
5
+ import { _ as recordKeyLookup, n as getDurationMs, t as classifyFetchError } from "./metrics-BMaatuZi.mjs";
6
6
  import { getLogger } from "@logtape/logtape";
7
7
  import { CryptographicKey, Multikey, Object as Object$1, isActor } from "@fedify/vocab";
8
8
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
@@ -1,7 +1,7 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { p as recordDocumentCache } from "./metrics-De7b7Hgb.mjs";
4
+ import { p as recordDocumentCache } from "./metrics-BMaatuZi.mjs";
5
5
  import { getLogger } from "@logtape/logtape";
6
6
  import { preloadedContexts } from "@fedify/vocab-runtime";
7
7
  //#region src/utils/kv-cache.ts
@@ -1,6 +1,6 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
- import { C as recordDocumentCache, d as validateCryptoKey, t as doubleKnock } from "./http-D_cl_PbN.js";
3
+ import { C as recordDocumentCache, d as validateCryptoKey, t as doubleKnock } from "./http-Ctb_KhZ8.js";
4
4
  import { getLogger } from "@logtape/logtape";
5
5
  import { curry } from "es-toolkit";
6
6
  import { UrlError, createActivityPubRequest, getRemoteDocument, logRequest, preloadedContexts, validatePublicUrl } from "@fedify/vocab-runtime";
@@ -1,6 +1,6 @@
1
1
  const { URLPattern } = require("urlpattern-polyfill");
2
2
  require("./chunk-Czpeue4M.cjs");
3
- const require_http = require("./http-DiMJDFtd.cjs");
3
+ const require_http = require("./http-jr0TkgZe.cjs");
4
4
  const require_temporal_polyfill = require("./temporal-polyfill-BCdTHexd.cjs");
5
5
  let _logtape_logtape = require("@logtape/logtape");
6
6
  let es_toolkit = require("es-toolkit");
@@ -1,9 +1,9 @@
1
1
  import "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-C30u61BX.mjs";
5
- import { n as getDurationMs, r as getFederationMetrics, s as measureSignatureKeyFetch } from "./metrics-De7b7Hgb.mjs";
6
- import { n as fetchKey, o as validateCryptoKey } from "./key-C1tsoBAW.mjs";
4
+ import { n as version, t as name } from "./deno-D3c0o_N0.mjs";
5
+ import { n as getDurationMs, r as getFederationMetrics, s as measureSignatureKeyFetch } from "./metrics-BMaatuZi.mjs";
6
+ import { n as fetchKey, o as validateCryptoKey } from "./key-C_gNKtxm.mjs";
7
7
  import { getLogger } from "@logtape/logtape";
8
8
  import { Activity, CryptographicKey, Object as Object$1, getTypeId } from "@fedify/vocab";
9
9
  import { SpanStatusCode, trace } from "@opentelemetry/api";
@@ -1,7 +1,7 @@
1
1
  import "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-C30u61BX.mjs";
4
+ import { n as version, t as name } from "./deno-D3c0o_N0.mjs";
5
5
  import { metrics } from "@opentelemetry/api";
6
6
  import { FetchError } from "@fedify/vocab-runtime";
7
7
  //#region src/federation/metrics.ts
@@ -108,6 +108,17 @@ interface MessageQueue {
108
108
  */
109
109
  readonly nativeDeduplication?: boolean;
110
110
  /**
111
+ * Whether {@link enqueueMany} accepts either every message or no messages.
112
+ * Backends that implement `enqueueMany()` by sending messages individually
113
+ * must set this to `false`, so Fedify does not use that method for a batch
114
+ * governed by one `deduplicationKey`. `true` by default when `enqueueMany`
115
+ * is implemented.
116
+ *
117
+ * @default `true`
118
+ * @since 2.4.0
119
+ */
120
+ readonly atomicEnqueueMany?: boolean;
121
+ /**
111
122
  * Enqueues a message in the queue.
112
123
  * @param message The message to enqueue.
113
124
  * @param options Additional options for enqueuing the message.
@@ -116,7 +127,9 @@ interface MessageQueue {
116
127
  /**
117
128
  * Enqueues multiple messages in the queue. This operation is optional,
118
129
  * and may not be supported by all implementations. If not supported,
119
- * Fedify will invoke {@link enqueue} for each message.
130
+ * Fedify will invoke {@link enqueue} for each message. An implementation
131
+ * that may accept only part of a batch before rejecting must declare
132
+ * {@link atomicEnqueueMany} `false`.
120
133
  *
121
134
  * @param messages The messages to enqueue.
122
135
  * @param options Additional options for enqueuing the messages.
@@ -226,6 +239,11 @@ declare class ParallelMessageQueue implements MessageQueue {
226
239
  * @since 2.4.0
227
240
  */
228
241
  readonly nativeDeduplication?: boolean;
242
+ /**
243
+ * Inherits the atomic batch capability from the wrapped queue.
244
+ * @since 2.4.0
245
+ */
246
+ readonly atomicEnqueueMany?: boolean;
229
247
  readonly getDepth?: () => Promise<MessageQueueDepth>;
230
248
  /**
231
249
  * Constructs a new {@link ParallelMessageQueue} with the given queue and
@@ -108,6 +108,17 @@ interface MessageQueue {
108
108
  */
109
109
  readonly nativeDeduplication?: boolean;
110
110
  /**
111
+ * Whether {@link enqueueMany} accepts either every message or no messages.
112
+ * Backends that implement `enqueueMany()` by sending messages individually
113
+ * must set this to `false`, so Fedify does not use that method for a batch
114
+ * governed by one `deduplicationKey`. `true` by default when `enqueueMany`
115
+ * is implemented.
116
+ *
117
+ * @default `true`
118
+ * @since 2.4.0
119
+ */
120
+ readonly atomicEnqueueMany?: boolean;
121
+ /**
111
122
  * Enqueues a message in the queue.
112
123
  * @param message The message to enqueue.
113
124
  * @param options Additional options for enqueuing the message.
@@ -116,7 +127,9 @@ interface MessageQueue {
116
127
  /**
117
128
  * Enqueues multiple messages in the queue. This operation is optional,
118
129
  * and may not be supported by all implementations. If not supported,
119
- * Fedify will invoke {@link enqueue} for each message.
130
+ * Fedify will invoke {@link enqueue} for each message. An implementation
131
+ * that may accept only part of a batch before rejecting must declare
132
+ * {@link atomicEnqueueMany} `false`.
120
133
  *
121
134
  * @param messages The messages to enqueue.
122
135
  * @param options Additional options for enqueuing the messages.
@@ -226,6 +239,11 @@ declare class ParallelMessageQueue implements MessageQueue {
226
239
  * @since 2.4.0
227
240
  */
228
241
  readonly nativeDeduplication?: boolean;
242
+ /**
243
+ * Inherits the atomic batch capability from the wrapped queue.
244
+ * @since 2.4.0
245
+ */
246
+ readonly atomicEnqueueMany?: boolean;
229
247
  readonly getDepth?: () => Promise<MessageQueueDepth>;
230
248
  /**
231
249
  * Constructs a new {@link ParallelMessageQueue} with the given queue and