@fedify/fedify 2.4.0-dev.1508 → 2.4.0-dev.1531
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -4
- package/dist/{assert-DvVHoIZ0.mjs → assert-OguE97r2.mjs} +1 -1
- package/dist/{assert_instance_of-CxoC8bVq.mjs → assert_instance_of-DBC5X09g.mjs} +1 -1
- package/dist/{assert_not_equals-C8vcTTA3.mjs → assert_not_equals-DkVK8oqV.mjs} +1 -1
- package/dist/{assert_rejects-DAdaaIWM.mjs → assert_rejects-DN60FHPX.mjs} +2 -2
- package/dist/{assert_strict_equals-BzqyKuYL.mjs → assert_strict_equals-XEgZAlrj.mjs} +1 -1
- package/dist/{assert_throws-zN79lgIC.mjs → assert_throws-BOkhLGYc.mjs} +1 -1
- package/dist/{builder-DlWCek6Z.mjs → builder-CmQLlEE1.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-CYF8X0ft.d.cts → context-BBVLF7lx.d.cts} +272 -543
- package/dist/{context-BF5B4ZDk.d.ts → context-BU6jSQdo.d.ts} +272 -542
- package/dist/{context-BBRTgkrs.mjs → context-DVoTs_wM.mjs} +2 -8
- package/dist/{deno-nexucTAX.mjs → deno-bSDsva_4.mjs} +1 -1
- package/dist/{docloader-DAdEN549.mjs → docloader-DlmmTFJc.mjs} +3 -3
- 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 +259 -3
- package/dist/federation/mod.d.cts +4 -4
- package/dist/federation/mod.d.ts +4 -4
- package/dist/federation/mod.js +257 -1
- package/dist/federation/mq.test.mjs +261 -103
- 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-inQqS3yx.mjs → http-DwsK1LoE.mjs} +4 -4
- package/dist/{http-BCj9dlA_.cjs → http-bsrB-Tun.cjs} +1 -1
- package/dist/{http-Dv3147TL.js → http-yVXJ4RhY.js} +1 -1
- package/dist/{key-CGrr6-I2.mjs → key-C0aqQKRk.mjs} +2 -2
- package/dist/{kv-cache-C3qkFkbt.mjs → kv-cache-D3EQwzQ4.mjs} +1 -1
- package/dist/{kv-cache-c8X6svwE.cjs → kv-cache-Dv62PM2B.cjs} +1 -1
- package/dist/{kv-cache-C2oTEXyb.js → kv-cache-M2xxXg9M.js} +1 -1
- package/dist/{ld-fnWaNT8y.mjs → ld-CBIxjtov.mjs} +3 -3
- package/dist/{metrics-C5hMINAa.mjs → metrics-CwNvxtP6.mjs} +1 -1
- package/dist/{middleware-Dl2nyVgB.mjs → middleware-BWi34Ga3.mjs} +46 -306
- package/dist/{middleware-vQ_ZpgcX.js → middleware-BpMbjN9m.js} +31 -679
- package/dist/{middleware-DeVzbg1I.cjs → middleware-C27Pdo18.cjs} +30 -690
- package/dist/{middleware-CQlq6ykI.mjs → middleware-DiTi3jC5.mjs} +1 -1
- package/dist/{mod-BHEB3xhE.d.cts → mod-C0F6kvgS.d.cts} +1 -1
- package/dist/{mod-4WGAuR6X.d.ts → mod-vPYVoa5n.d.ts} +1 -1
- package/dist/mod.cjs +6 -6
- package/dist/mod.d.cts +5 -5
- package/dist/mod.d.ts +5 -5
- package/dist/mod.js +5 -5
- package/dist/{mq-DXMt_qCY.d.cts → mq-D-nlpY04.d.ts} +0 -34
- package/dist/{mq-B5_hohs7.d.ts → mq-D8uSFzxe.d.cts} +0 -34
- 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-BNL8AC14.mjs → outgoing-jsonld-L_DbOaFe.mjs} +1 -1
- package/dist/{owner-Bq2eZyO_.mjs → owner-SuWJf5wy.mjs} +2 -2
- package/dist/{proof-Buz7I8wj.cjs → proof-BclG-T7h.cjs} +1 -1
- package/dist/{proof-DZCjcFCd.mjs → proof-CZI5KQdk.mjs} +5 -5
- package/dist/{proof-CTG9azxN.js → proof-DMWr-n3N.js} +1 -1
- package/dist/{send-B253S5gN.mjs → send-1EADALaf.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 +6 -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-Dh6uLf_q.mjs → std__assert-BBjXFNOb.mjs} +4 -4
- package/dist/{temporal-d6TshGjq.mjs → temporal-GLaGoMUR.mjs} +1 -1
- package/dist/testing/mod.d.mts +8 -1037
- 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 +7 -9
- package/dist/codec-CmlPqjNX.mjs +0 -103
- package/dist/federation/tasks/codec.test.d.mts +0 -2
- package/dist/federation/tasks/codec.test.mjs +0 -292
- package/dist/federation/tasks/enqueue.test.d.mts +0 -2
- package/dist/federation/tasks/enqueue.test.mjs +0 -992
- package/dist/federation/tasks/tasks.test.d.mts +0 -2
- package/dist/federation/tasks/tasks.test.mjs +0 -555
- package/dist/mq-03vS-C9P.mjs +0 -276
- package/dist/testing-Dy-WhqpN.mjs +0 -77
- /package/dist/{accept-CgDcxvjV.mjs → accept-CPkZzmGN.mjs} +0 -0
- /package/dist/{activity-listener-BeTGV3wc.mjs → activity-listener-tztVvlNb.mjs} +0 -0
- /package/dist/{assert_equals-PBVKNMJd.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-CSYsOMFG.mjs → keys-DGu1NFwu.mjs} +0 -0
- /package/dist/{kv-CIvR3Non.mjs → kv-rV3vodCc.mjs} +0 -0
- /package/dist/{negotiation-m_L2nyS3.mjs → negotiation-DDstyBvc.mjs} +0 -0
- /package/dist/{public-audience-c9zmYKgA.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
package/dist/mq-03vS-C9P.mjs
DELETED
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
-
import "urlpattern-polyfill";
|
|
3
|
-
globalThis.addEventListener = () => {};
|
|
4
|
-
//#region src/federation/mq.ts
|
|
5
|
-
/**
|
|
6
|
-
* A message queue that processes messages in the same process.
|
|
7
|
-
* Do not use this in production as it does neither persist messages nor
|
|
8
|
-
* distribute them across multiple processes.
|
|
9
|
-
*
|
|
10
|
-
* @since 0.5.0
|
|
11
|
-
*/
|
|
12
|
-
var InProcessMessageQueue = class {
|
|
13
|
-
#messages;
|
|
14
|
-
#monitors;
|
|
15
|
-
#pollIntervalMs;
|
|
16
|
-
#delayedMessages;
|
|
17
|
-
/**
|
|
18
|
-
* Tracks which ordering keys are currently being processed to ensure
|
|
19
|
-
* sequential processing for messages with the same key.
|
|
20
|
-
*/
|
|
21
|
-
#processingKeys;
|
|
22
|
-
/**
|
|
23
|
-
* In-process message queue does not provide native retry mechanisms.
|
|
24
|
-
* @since 1.7.0
|
|
25
|
-
*/
|
|
26
|
-
nativeRetrial = false;
|
|
27
|
-
/**
|
|
28
|
-
* In-process message queue does not deduplicate messages natively.
|
|
29
|
-
* @since 2.4.0
|
|
30
|
-
*/
|
|
31
|
-
nativeDeduplication = false;
|
|
32
|
-
/**
|
|
33
|
-
* Constructs a new {@link InProcessMessageQueue} with the given options.
|
|
34
|
-
* @param options Additional options for the in-process message queue.
|
|
35
|
-
*/
|
|
36
|
-
constructor(options = {}) {
|
|
37
|
-
this.#messages = [];
|
|
38
|
-
this.#monitors = {};
|
|
39
|
-
this.#pollIntervalMs = Temporal.Duration.from(options.pollInterval ?? { seconds: 5 }).total("millisecond");
|
|
40
|
-
this.#delayedMessages = 0;
|
|
41
|
-
this.#processingKeys = /* @__PURE__ */ new Set();
|
|
42
|
-
}
|
|
43
|
-
enqueue(message, options) {
|
|
44
|
-
const delay = options?.delay == null ? 0 : Math.max(options.delay.total("millisecond"), 0);
|
|
45
|
-
if (delay > 0) {
|
|
46
|
-
this.#delayedMessages++;
|
|
47
|
-
setTimeout(() => {
|
|
48
|
-
this.#delayedMessages--;
|
|
49
|
-
this.#enqueueReady(message, options);
|
|
50
|
-
}, delay);
|
|
51
|
-
return Promise.resolve();
|
|
52
|
-
}
|
|
53
|
-
this.#enqueueReady(message, options);
|
|
54
|
-
return Promise.resolve();
|
|
55
|
-
}
|
|
56
|
-
#enqueueReady(message, options) {
|
|
57
|
-
const orderingKey = options?.orderingKey ?? null;
|
|
58
|
-
this.#messages.push({
|
|
59
|
-
message,
|
|
60
|
-
orderingKey
|
|
61
|
-
});
|
|
62
|
-
this.#notifyMonitors();
|
|
63
|
-
}
|
|
64
|
-
#notifyMonitors() {
|
|
65
|
-
for (const monitorId in this.#monitors) this.#monitors[monitorId]();
|
|
66
|
-
}
|
|
67
|
-
enqueueMany(messages, options) {
|
|
68
|
-
if (messages.length === 0) return Promise.resolve();
|
|
69
|
-
const delay = options?.delay == null ? 0 : Math.max(options.delay.total("millisecond"), 0);
|
|
70
|
-
if (delay > 0) {
|
|
71
|
-
const delayedCount = messages.length;
|
|
72
|
-
const deferredMessages = [...messages];
|
|
73
|
-
this.#delayedMessages += delayedCount;
|
|
74
|
-
setTimeout(() => {
|
|
75
|
-
this.#delayedMessages -= delayedCount;
|
|
76
|
-
this.#enqueueManyReady(deferredMessages, options);
|
|
77
|
-
}, delay);
|
|
78
|
-
return Promise.resolve();
|
|
79
|
-
}
|
|
80
|
-
this.#enqueueManyReady(messages, options);
|
|
81
|
-
return Promise.resolve();
|
|
82
|
-
}
|
|
83
|
-
#enqueueManyReady(messages, options) {
|
|
84
|
-
const orderingKey = options?.orderingKey ?? null;
|
|
85
|
-
for (const message of messages) this.#messages.push({
|
|
86
|
-
message,
|
|
87
|
-
orderingKey
|
|
88
|
-
});
|
|
89
|
-
this.#notifyMonitors();
|
|
90
|
-
}
|
|
91
|
-
async listen(handler, options = {}) {
|
|
92
|
-
const signal = options.signal;
|
|
93
|
-
while (signal == null || !signal.aborted) {
|
|
94
|
-
const idx = this.#messages.findIndex((m) => m.orderingKey == null || !this.#processingKeys.has(m.orderingKey));
|
|
95
|
-
if (idx >= 0) {
|
|
96
|
-
const { message, orderingKey } = this.#messages.splice(idx, 1)[0];
|
|
97
|
-
if (orderingKey != null) this.#processingKeys.add(orderingKey);
|
|
98
|
-
try {
|
|
99
|
-
await handler(message);
|
|
100
|
-
} finally {
|
|
101
|
-
if (orderingKey != null) this.#processingKeys.delete(orderingKey);
|
|
102
|
-
}
|
|
103
|
-
} else if (this.#messages.length === 0) await this.#wait(this.#pollIntervalMs, signal);
|
|
104
|
-
else await this.#wait(10, signal);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
getDepth() {
|
|
108
|
-
const ready = this.#messages.length;
|
|
109
|
-
const delayed = this.#delayedMessages;
|
|
110
|
-
return Promise.resolve({
|
|
111
|
-
queued: ready + delayed,
|
|
112
|
-
ready,
|
|
113
|
-
delayed
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
#wait(ms, signal) {
|
|
117
|
-
let timer = null;
|
|
118
|
-
return Promise.any([new Promise((resolve) => {
|
|
119
|
-
signal?.addEventListener("abort", () => {
|
|
120
|
-
if (timer != null) clearTimeout(timer);
|
|
121
|
-
resolve();
|
|
122
|
-
}, { once: true });
|
|
123
|
-
const monitorId = crypto.randomUUID();
|
|
124
|
-
this.#monitors[monitorId] = () => {
|
|
125
|
-
delete this.#monitors[monitorId];
|
|
126
|
-
if (timer != null) clearTimeout(timer);
|
|
127
|
-
resolve();
|
|
128
|
-
};
|
|
129
|
-
}), new Promise((resolve) => timer = setTimeout(resolve, ms))]);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* A message queue that processes messages in parallel. It takes another
|
|
134
|
-
* {@link MessageQueue}, and processes messages in parallel up to a certain
|
|
135
|
-
* number of workers.
|
|
136
|
-
*
|
|
137
|
-
* Actually, it's rather a decorator than a queue itself.
|
|
138
|
-
*
|
|
139
|
-
* Note that the workers do not run in truly parallel, in the sense that they
|
|
140
|
-
* are not running in separate threads or processes. They are running in the
|
|
141
|
-
* same process, but are scheduled to run in parallel. Hence, this is useful
|
|
142
|
-
* for I/O-bound tasks, but not for CPU-bound tasks, which is okay for Fedify's
|
|
143
|
-
* workloads.
|
|
144
|
-
*
|
|
145
|
-
* When using `ParallelMessageQueue`, the ordering guarantee is preserved
|
|
146
|
-
* *only if* the underlying queue implementation delivers messages in a wrapper
|
|
147
|
-
* format that includes the `__fedify_ordering_key__` property. Currently,
|
|
148
|
-
* only `DenoKvMessageQueue` and `WorkersMessageQueue` use this format.
|
|
149
|
-
* For other queue implementations (e.g., `InProcessMessageQueue`,
|
|
150
|
-
* `RedisMessageQueue`, `PostgresMessageQueue`, `SqliteMessageQueue`,
|
|
151
|
-
* `AmqpMessageQueue`), the ordering key cannot be detected by
|
|
152
|
-
* `ParallelMessageQueue`, so ordering guarantees are handled by those
|
|
153
|
-
* implementations directly rather than at the `ParallelMessageQueue` level.
|
|
154
|
-
*
|
|
155
|
-
* Messages with the same ordering key will never be processed concurrently
|
|
156
|
-
* by different workers, ensuring sequential processing within each key.
|
|
157
|
-
* Messages with different ordering keys (or no ordering key) can still be
|
|
158
|
-
* processed in parallel.
|
|
159
|
-
*
|
|
160
|
-
* @since 1.0.0
|
|
161
|
-
*/
|
|
162
|
-
var ParallelMessageQueue = class ParallelMessageQueue {
|
|
163
|
-
queue;
|
|
164
|
-
workers;
|
|
165
|
-
/**
|
|
166
|
-
* Inherits the native retry capability from the wrapped queue.
|
|
167
|
-
* @since 1.7.0
|
|
168
|
-
*/
|
|
169
|
-
nativeRetrial;
|
|
170
|
-
/**
|
|
171
|
-
* Inherits the native deduplication capability from the wrapped queue.
|
|
172
|
-
* @since 2.4.0
|
|
173
|
-
*/
|
|
174
|
-
nativeDeduplication;
|
|
175
|
-
getDepth;
|
|
176
|
-
/**
|
|
177
|
-
* Tracks which ordering keys are currently being processed to ensure
|
|
178
|
-
* sequential processing for messages with the same key.
|
|
179
|
-
*/
|
|
180
|
-
#processingKeys = /* @__PURE__ */ new Set();
|
|
181
|
-
/**
|
|
182
|
-
* Pending messages waiting for their ordering key to become available.
|
|
183
|
-
*/
|
|
184
|
-
#pendingMessages = [];
|
|
185
|
-
/**
|
|
186
|
-
* Constructs a new {@link ParallelMessageQueue} with the given queue and
|
|
187
|
-
* number of workers.
|
|
188
|
-
* @param queue The message queue to use under the hood. Note that
|
|
189
|
-
* {@link ParallelMessageQueue} cannot be nested.
|
|
190
|
-
* @param workers The number of workers to process messages in parallel.
|
|
191
|
-
* @throws {TypeError} If the given queue is an instance of
|
|
192
|
-
* {@link ParallelMessageQueue}.
|
|
193
|
-
*/
|
|
194
|
-
constructor(queue, workers) {
|
|
195
|
-
if (queue instanceof ParallelMessageQueue) throw new TypeError("Cannot nest ParallelMessageQueue.");
|
|
196
|
-
this.queue = queue;
|
|
197
|
-
this.workers = workers;
|
|
198
|
-
this.nativeRetrial = queue.nativeRetrial;
|
|
199
|
-
this.nativeDeduplication = queue.nativeDeduplication;
|
|
200
|
-
if (queue.getDepth != null) this.getDepth = () => queue.getDepth();
|
|
201
|
-
}
|
|
202
|
-
enqueue(message, options) {
|
|
203
|
-
return this.queue.enqueue(message, options);
|
|
204
|
-
}
|
|
205
|
-
async enqueueMany(messages, options) {
|
|
206
|
-
if (this.queue.enqueueMany == null) {
|
|
207
|
-
if (messages.length === 1) {
|
|
208
|
-
await this.queue.enqueue(messages[0], options);
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
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.");
|
|
212
|
-
const errors = (await Promise.allSettled(messages.map((message) => this.queue.enqueue(message, options)))).filter((r) => r.status === "rejected").map((r) => r.reason);
|
|
213
|
-
if (errors.length > 1) throw new AggregateError(errors, "Failed to enqueue messages.");
|
|
214
|
-
else if (errors.length === 1) throw errors[0];
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
await this.queue.enqueueMany(messages, options);
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Extracts ordering key from a message if present.
|
|
221
|
-
*
|
|
222
|
-
* This method only works for queue implementations that deliver messages
|
|
223
|
-
* in the wrapper format with `__fedify_ordering_key__` property. Currently,
|
|
224
|
-
* only `DenoKvMessageQueue` and `WorkersMessageQueue` use this format.
|
|
225
|
-
*
|
|
226
|
-
* For other queue implementations (`InProcessMessageQueue`,
|
|
227
|
-
* `RedisMessageQueue`, `PostgresMessageQueue`, `SqliteMessageQueue`,
|
|
228
|
-
* `AmqpMessageQueue`), messages are delivered as raw payloads without the
|
|
229
|
-
* wrapper, so the ordering key cannot be detected here. Those
|
|
230
|
-
* implementations handle ordering guarantees internally.
|
|
231
|
-
*/
|
|
232
|
-
#extractOrderingKey(message) {
|
|
233
|
-
if (message != null && typeof message === "object") {
|
|
234
|
-
if ("__fedify_ordering_key__" in message) return message.__fedify_ordering_key__;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
listen(handler, options = {}) {
|
|
238
|
-
const workers = /* @__PURE__ */ new Map();
|
|
239
|
-
return this.queue.listen(async (message) => {
|
|
240
|
-
while (workers.size >= this.workers) {
|
|
241
|
-
const consumedId = await Promise.any(workers.values());
|
|
242
|
-
workers.delete(consumedId);
|
|
243
|
-
}
|
|
244
|
-
const workerId = crypto.randomUUID();
|
|
245
|
-
const orderingKey = this.#extractOrderingKey(message);
|
|
246
|
-
if (orderingKey != null && this.#processingKeys.has(orderingKey)) await new Promise((resolve) => {
|
|
247
|
-
this.#pendingMessages.push({
|
|
248
|
-
message,
|
|
249
|
-
orderingKey,
|
|
250
|
-
resolve
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
if (orderingKey != null) this.#processingKeys.add(orderingKey);
|
|
254
|
-
const promise = this.#work(workerId, handler, message, orderingKey);
|
|
255
|
-
workers.set(workerId, promise);
|
|
256
|
-
}, options);
|
|
257
|
-
}
|
|
258
|
-
async #work(workerId, handler, message, orderingKey) {
|
|
259
|
-
await this.#sleep(0);
|
|
260
|
-
try {
|
|
261
|
-
await handler(message);
|
|
262
|
-
} finally {
|
|
263
|
-
if (orderingKey != null) {
|
|
264
|
-
this.#processingKeys.delete(orderingKey);
|
|
265
|
-
const pendingIdx = this.#pendingMessages.findIndex((p) => p.orderingKey === orderingKey);
|
|
266
|
-
if (pendingIdx >= 0) this.#pendingMessages.splice(pendingIdx, 1)[0].resolve();
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return workerId;
|
|
270
|
-
}
|
|
271
|
-
#sleep(ms) {
|
|
272
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
//#endregion
|
|
276
|
-
export { ParallelMessageQueue as n, InProcessMessageQueue as t };
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import "@js-temporal/polyfill";
|
|
2
|
-
import "urlpattern-polyfill";
|
|
3
|
-
globalThis.addEventListener = () => {};
|
|
4
|
-
import { i as mockDocumentLoader } from "./context-BBRTgkrs.mjs";
|
|
5
|
-
import { t as MemoryKvStore } from "./kv-CIvR3Non.mjs";
|
|
6
|
-
import { Note } from "@fedify/vocab";
|
|
7
|
-
//#region src/testing/tasks.ts
|
|
8
|
-
/**
|
|
9
|
-
* Test-only utilities shared by the task suites: the schema factory and stock
|
|
10
|
-
* schemas, the base federation options, and the recording {@link MockQueue}.
|
|
11
|
-
*
|
|
12
|
-
* These helpers live beside the suites that use them rather than in a shared
|
|
13
|
-
* package because {@link MockQueue} needs the package-internal
|
|
14
|
-
* {@link TaskMessage} type, and *deno.json*'s `publish.exclude` keeps this
|
|
15
|
-
* module out of the published sources.
|
|
16
|
-
*
|
|
17
|
-
* @module
|
|
18
|
-
*/
|
|
19
|
-
/** Federation options (sans `queue`) shared by the task suites. */
|
|
20
|
-
const baseOptions = {
|
|
21
|
-
kv: new MemoryKvStore(),
|
|
22
|
-
documentLoaderFactory: () => mockDocumentLoader,
|
|
23
|
-
contextLoaderFactory: () => mockDocumentLoader,
|
|
24
|
-
manuallyStartQueue: true
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Builds a minimal [Standard Schema](https://standardschema.dev/) from a type
|
|
28
|
-
* guard, for use as a task payload schema in tests.
|
|
29
|
-
*/
|
|
30
|
-
const makeSchema = (check) => ({ "~standard": {
|
|
31
|
-
version: 1,
|
|
32
|
-
vendor: "fedify-test",
|
|
33
|
-
validate: (value) => check(value) ? { value } : { issues: [{ message: "Invalid task data." }] }
|
|
34
|
-
} });
|
|
35
|
-
const stringSchema = makeSchema((d) => typeof d === "string");
|
|
36
|
-
const numberSchema = makeSchema((d) => typeof d === "number");
|
|
37
|
-
const envelopeSchema = makeSchema((data) => typeof data === "object" && data != null && data.note instanceof Note && typeof data.title === "string");
|
|
38
|
-
/**
|
|
39
|
-
* An in-memory {@link MessageQueue} that records task enqueues for assertions
|
|
40
|
-
* instead of delivering anything. Its {@link listen} resolves only when the
|
|
41
|
-
* abort signal fires.
|
|
42
|
-
*/
|
|
43
|
-
var MockQueue = class {
|
|
44
|
-
nativeRetrial;
|
|
45
|
-
nativeDeduplication;
|
|
46
|
-
enqueued = [];
|
|
47
|
-
enqueuedMany = [];
|
|
48
|
-
listenCount = 0;
|
|
49
|
-
enqueueMany;
|
|
50
|
-
constructor(options = {}) {
|
|
51
|
-
this.nativeRetrial = options.nativeRetrial ?? false;
|
|
52
|
-
this.nativeDeduplication = options.nativeDeduplication ?? false;
|
|
53
|
-
if (options.supportsEnqueueMany) this.enqueueMany = (messages, opts) => {
|
|
54
|
-
this.enqueuedMany.push({
|
|
55
|
-
messages,
|
|
56
|
-
options: opts
|
|
57
|
-
});
|
|
58
|
-
return Promise.resolve();
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
enqueue(message, options) {
|
|
62
|
-
this.enqueued.push({
|
|
63
|
-
message,
|
|
64
|
-
options
|
|
65
|
-
});
|
|
66
|
-
return Promise.resolve();
|
|
67
|
-
}
|
|
68
|
-
listen(_handler, options) {
|
|
69
|
-
this.listenCount++;
|
|
70
|
-
if (options?.signal?.aborted) return Promise.resolve();
|
|
71
|
-
return new Promise((resolve) => {
|
|
72
|
-
options?.signal?.addEventListener("abort", () => resolve(), { once: true });
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
//#endregion
|
|
77
|
-
export { numberSchema as a, makeSchema as i, baseOptions as n, stringSchema as o, envelopeSchema as r, MockQueue as t };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|