@fedify/fedify 2.3.0-dev.994 → 2.3.0-pr.809.36
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 +16 -7
- 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-B-qJtC9Z.mjs → assert_rejects-DN60FHPX.mjs} +28 -3
- 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-yAlpiIqP.mjs → builder-DSZ7FZmg.mjs} +96 -42
- package/dist/{chunk-nlSIicah.js → chunk-CRNNMoPX.js} +2 -2
- package/dist/circuit-breaker-CSWsyoef.mjs +337 -0
- package/dist/{client-z-8dc-e1.d.cts → client-CAM_bQXx.d.cts} +1 -0
- package/dist/{client-AtlibPOU.d.ts → client-CSddvgWN.d.ts} +1 -2
- package/dist/compat/mod.d.cts +2 -1
- package/dist/compat/mod.d.ts +2 -3
- package/dist/compat/mod.js +3 -3
- package/dist/compat/outgoing-jsonld.test.mjs +4 -4
- package/dist/compat/public-audience.test.mjs +4 -4
- package/dist/compat/transformers.test.mjs +5 -5
- package/dist/{context-BzH2-ajs.d.ts → context-BBVLF7lx.d.cts} +342 -269
- package/dist/{context-DJGagtNd.d.cts → context-BU6jSQdo.d.ts} +344 -266
- package/dist/{context-Dk_tacqz.mjs → context-DVoTs_wM.mjs} +64 -5
- package/dist/{deno-XBVlKnOX.mjs → deno-DCdM7d93.mjs} +1 -1
- package/dist/{docloader-DPp-X6gk.mjs → docloader-B7mVwA5_.mjs} +4 -4
- package/dist/{esm-DVILvP5e.mjs → esm-vrlUxr60.mjs} +4 -7
- package/dist/federation/builder.test.mjs +163 -11
- package/dist/federation/circuit-breaker.test.d.mts +2 -0
- package/dist/federation/circuit-breaker.test.mjs +446 -0
- package/dist/federation/collection.test.mjs +3 -3
- package/dist/federation/handler.test.mjs +1770 -29
- package/dist/federation/idempotency.test.mjs +5 -5
- package/dist/federation/inbox.test.mjs +4 -4
- package/dist/federation/keycache.test.mjs +5 -5
- package/dist/federation/kv.test.mjs +2 -2
- package/dist/federation/metrics.test.d.mts +2 -0
- package/dist/federation/metrics.test.mjs +634 -0
- package/dist/federation/middleware.test.mjs +4036 -146
- package/dist/federation/mod.cjs +195 -14
- package/dist/federation/mod.d.cts +6 -4
- package/dist/federation/mod.d.ts +6 -6
- package/dist/federation/mod.js +192 -14
- package/dist/federation/mq.test.mjs +176 -15
- package/dist/federation/negotiation.test.mjs +4 -4
- package/dist/federation/retry.test.mjs +3 -3
- package/dist/federation/router.test.mjs +190 -9
- package/dist/federation/send.test.mjs +153 -15
- package/dist/federation/temporal.test.d.mts +2 -0
- package/dist/federation/temporal.test.mjs +71 -0
- package/dist/federation/webfinger.test.mjs +150 -5
- package/dist/{http-CSlLA54v.mjs → http-BufbkLuW.mjs} +146 -47
- package/dist/{http-B4rrzxtg.js → http-Dh18nwJg.js} +994 -64
- package/dist/{http-aQzN9Ayi.d.ts → http-VyDTd4G3.d.cts} +15 -3
- package/dist/{http-BrGqJDXL.cjs → http-gOiudB3g.cjs} +1099 -61
- package/dist/{http-CrGuipxe.d.cts → http-lf8Hsd91.d.ts} +15 -1
- package/dist/{key-Bzx--sHD.mjs → key-DZdKLJXT.mjs} +43 -18
- package/dist/{kv-CbLNp3zQ.d.cts → kv-D6hNiMTK.d.ts} +1 -0
- package/dist/{kv-cache-DI-Sk7-I.cjs → kv-cache-BuK_nlpY.cjs} +20 -3
- package/dist/{kv-cache-U__xU4qR.mjs → kv-cache-C7SQnkGI.mjs} +21 -3
- package/dist/{kv-cache-EMIqoIuB.js → kv-cache-DNDSb6Po.js} +20 -3
- package/dist/{kv-GFYnFoOl.d.ts → kv-gJ8LYbxX.d.cts} +1 -3
- package/dist/ld-0Lsznacf.mjs +626 -0
- package/dist/metrics-BHeWd24f.mjs +815 -0
- package/dist/{middleware-zjZ6AFCW.mjs → middleware-BNANvDh2.mjs} +1 -1
- package/dist/{middleware-nidH7VZH.js → middleware-BgzRkDcm.js} +2260 -556
- package/dist/{middleware-An4DjES4.cjs → middleware-D-iES1nQ.cjs} +2318 -623
- package/dist/{middleware-K1g6bEkV.mjs → middleware-EV6J_eAc.mjs} +1639 -373
- package/dist/{mod-CR8soWa9.d.ts → mod-B0hW12_O.d.cts} +26 -4
- package/dist/mod-C0F6kvgS.d.cts +182 -0
- package/dist/{mod-Cr3f-ACa.d.cts → mod-COIAjwRS.d.ts} +26 -2
- package/dist/{mod-CMEbIaNh.d.cts → mod-DFvNJcNb.d.ts} +56 -4
- package/dist/mod-vPYVoa5n.d.ts +182 -0
- package/dist/{mod-CLgIXe9w.d.ts → mod-yvIXFAEi.d.cts} +56 -6
- package/dist/mod.cjs +9 -6
- package/dist/mod.d.cts +12 -10
- package/dist/mod.d.ts +12 -12
- package/dist/mod.js +11 -11
- package/dist/mq-D-nlpY04.d.ts +208 -0
- package/dist/mq-D8uSFzxe.d.cts +208 -0
- package/dist/{negotiation-SQvQgUqe.mjs → negotiation-DDstyBvc.mjs} +29 -0
- package/dist/nodeinfo/client.test.mjs +4 -4
- package/dist/nodeinfo/handler.test.mjs +4 -4
- package/dist/nodeinfo/mod.d.cts +2 -1
- package/dist/nodeinfo/mod.d.ts +2 -3
- package/dist/nodeinfo/mod.js +3 -3
- package/dist/nodeinfo/types.test.mjs +3 -3
- package/dist/otel/exporter.test.mjs +28 -25
- package/dist/otel/mod.cjs +6 -5
- package/dist/otel/mod.d.cts +5 -3
- package/dist/otel/mod.d.ts +5 -5
- package/dist/otel/mod.js +8 -7
- package/dist/{outgoing-jsonld-CNmZLixq.mjs → outgoing-jsonld-L_DbOaFe.mjs} +2 -2
- package/dist/{owner-C-tqfvxn.mjs → owner-Cl-1cAR8.mjs} +2 -2
- package/dist/{owner-CptqhsOy.d.cts → owner-CnngXDNJ.d.ts} +2 -1
- package/dist/{owner-74ARJ5TL.d.ts → owner-DEvZuyOE.d.cts} +2 -3
- package/dist/{proof-Bbbwf8_x.js → proof-CyXndf6-.js} +378 -15
- package/dist/{proof-BlmRPzrK.mjs → proof-Dnz8jtiQ.mjs} +26 -8
- package/dist/{proof-BW89QMVB.cjs → proof-tz35unOj.cjs} +432 -15
- package/dist/runtime/mod.d.cts +1 -0
- package/dist/runtime/mod.d.ts +1 -2
- package/dist/runtime/mod.js +3 -3
- package/dist/{send-05pJLcb6.mjs → send-DIbBYN5P.mjs} +72 -26
- package/dist/sig/http.test.mjs +356 -33
- package/dist/sig/key.test.mjs +103 -6
- package/dist/sig/ld.test.mjs +696 -7
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.d.cts +4 -3
- package/dist/sig/mod.d.ts +4 -5
- package/dist/sig/mod.js +4 -4
- package/dist/sig/owner.test.mjs +6 -6
- package/dist/sig/proof.test.mjs +169 -8
- package/dist/{std__assert-CRDpx_HF.mjs → std__assert-BBjXFNOb.mjs} +5 -30
- package/dist/temporal-BEwob1Vg.mjs +95 -0
- package/dist/testing/mod.d.mts +110 -10
- package/dist/testing/mod.mjs +1 -2
- package/dist/{transformers-ve6e2xcg.js → transformers-BGMIq1cs.js} +2 -2
- package/dist/{types-hvL8ElAs.js → types-CAY3OdLq.js} +2 -2
- package/dist/utils/docloader.test.mjs +6 -6
- package/dist/utils/kv-cache.test.mjs +67 -2
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.d.cts +2 -1
- package/dist/utils/mod.d.ts +2 -3
- package/dist/utils/mod.js +3 -3
- package/dist/vocab/cjs.test.mjs +1 -1
- package/dist/vocab/mod.d.cts +1 -0
- package/dist/vocab/mod.d.ts +1 -2
- package/dist/vocab/mod.js +2 -2
- package/package.json +16 -16
- package/dist/ld-DR78beiv.mjs +0 -279
- package/dist/middleware-BFBaR0mF.cjs +0 -4
- package/dist/mod-2d12ffz3.d.ts +0 -64
- package/dist/mod-D35TRn09.d.cts +0 -62
- package/dist/router-CrMLXoOr.mjs +0 -114
- package/dist/{activity-listener-ell7W1s9.mjs → activity-listener-tztVvlNb.mjs} +0 -0
- package/dist/{assert_equals-Ew3jOFa3.mjs → assert_equals-C-ZRDbaf.mjs} +0 -0
- package/dist/{client-D_1QpnWt.mjs → client-ByXmQhYD.mjs} +1 -1
- package/dist/{collection-D-HqUuA2.mjs → collection-Cc3DVAhE.mjs} +0 -0
- package/dist/{keycache-EGATflN-.mjs → keycache-BeU0LCII.mjs} +0 -0
- package/dist/{public-audience-DYFHzm_c.mjs → public-audience-Cvbr2Gzt.mjs} +1 -1
- /package/dist/{retry-bMXBL97A.mjs → retry-CXg_MBI-.mjs} +0 -0
package/dist/federation/mod.cjs
CHANGED
|
@@ -2,7 +2,9 @@ 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-D-iES1nQ.cjs");
|
|
6
|
+
let _logtape_logtape = require("@logtape/logtape");
|
|
7
|
+
let _fedify_uri_template = require("@fedify/uri-template");
|
|
6
8
|
let es_toolkit = require("es-toolkit");
|
|
7
9
|
//#region src/federation/kv.ts
|
|
8
10
|
/**
|
|
@@ -103,6 +105,7 @@ var InProcessMessageQueue = class {
|
|
|
103
105
|
#messages;
|
|
104
106
|
#monitors;
|
|
105
107
|
#pollIntervalMs;
|
|
108
|
+
#delayedMessages;
|
|
106
109
|
/**
|
|
107
110
|
* Tracks which ordering keys are currently being processed to ensure
|
|
108
111
|
* sequential processing for messages with the same key.
|
|
@@ -121,42 +124,56 @@ var InProcessMessageQueue = class {
|
|
|
121
124
|
this.#messages = [];
|
|
122
125
|
this.#monitors = {};
|
|
123
126
|
this.#pollIntervalMs = Temporal.Duration.from(options.pollInterval ?? { seconds: 5 }).total("millisecond");
|
|
127
|
+
this.#delayedMessages = 0;
|
|
124
128
|
this.#processingKeys = /* @__PURE__ */ new Set();
|
|
125
129
|
}
|
|
126
130
|
enqueue(message, options) {
|
|
127
131
|
const delay = options?.delay == null ? 0 : Math.max(options.delay.total("millisecond"), 0);
|
|
128
132
|
if (delay > 0) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
this.#delayedMessages++;
|
|
134
|
+
setTimeout(() => {
|
|
135
|
+
this.#delayedMessages--;
|
|
136
|
+
this.#enqueueReady(message, options);
|
|
137
|
+
}, delay);
|
|
133
138
|
return Promise.resolve();
|
|
134
139
|
}
|
|
140
|
+
this.#enqueueReady(message, options);
|
|
141
|
+
return Promise.resolve();
|
|
142
|
+
}
|
|
143
|
+
#enqueueReady(message, options) {
|
|
135
144
|
const orderingKey = options?.orderingKey ?? null;
|
|
136
145
|
this.#messages.push({
|
|
137
146
|
message,
|
|
138
147
|
orderingKey
|
|
139
148
|
});
|
|
149
|
+
this.#notifyMonitors();
|
|
150
|
+
}
|
|
151
|
+
#notifyMonitors() {
|
|
140
152
|
for (const monitorId in this.#monitors) this.#monitors[monitorId]();
|
|
141
|
-
return Promise.resolve();
|
|
142
153
|
}
|
|
143
154
|
enqueueMany(messages, options) {
|
|
144
155
|
if (messages.length === 0) return Promise.resolve();
|
|
145
156
|
const delay = options?.delay == null ? 0 : Math.max(options.delay.total("millisecond"), 0);
|
|
146
157
|
if (delay > 0) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
158
|
+
const delayedCount = messages.length;
|
|
159
|
+
const deferredMessages = [...messages];
|
|
160
|
+
this.#delayedMessages += delayedCount;
|
|
161
|
+
setTimeout(() => {
|
|
162
|
+
this.#delayedMessages -= delayedCount;
|
|
163
|
+
this.#enqueueManyReady(deferredMessages, options);
|
|
164
|
+
}, delay);
|
|
151
165
|
return Promise.resolve();
|
|
152
166
|
}
|
|
167
|
+
this.#enqueueManyReady(messages, options);
|
|
168
|
+
return Promise.resolve();
|
|
169
|
+
}
|
|
170
|
+
#enqueueManyReady(messages, options) {
|
|
153
171
|
const orderingKey = options?.orderingKey ?? null;
|
|
154
172
|
for (const message of messages) this.#messages.push({
|
|
155
173
|
message,
|
|
156
174
|
orderingKey
|
|
157
175
|
});
|
|
158
|
-
|
|
159
|
-
return Promise.resolve();
|
|
176
|
+
this.#notifyMonitors();
|
|
160
177
|
}
|
|
161
178
|
async listen(handler, options = {}) {
|
|
162
179
|
const signal = options.signal;
|
|
@@ -174,6 +191,15 @@ var InProcessMessageQueue = class {
|
|
|
174
191
|
else await this.#wait(10, signal);
|
|
175
192
|
}
|
|
176
193
|
}
|
|
194
|
+
getDepth() {
|
|
195
|
+
const ready = this.#messages.length;
|
|
196
|
+
const delayed = this.#delayedMessages;
|
|
197
|
+
return Promise.resolve({
|
|
198
|
+
queued: ready + delayed,
|
|
199
|
+
ready,
|
|
200
|
+
delayed
|
|
201
|
+
});
|
|
202
|
+
}
|
|
177
203
|
#wait(ms, signal) {
|
|
178
204
|
let timer = null;
|
|
179
205
|
return Promise.any([new Promise((resolve) => {
|
|
@@ -228,6 +254,7 @@ var ParallelMessageQueue = class ParallelMessageQueue {
|
|
|
228
254
|
* @since 1.7.0
|
|
229
255
|
*/
|
|
230
256
|
nativeRetrial;
|
|
257
|
+
getDepth;
|
|
231
258
|
/**
|
|
232
259
|
* Tracks which ordering keys are currently being processed to ensure
|
|
233
260
|
* sequential processing for messages with the same key.
|
|
@@ -251,6 +278,7 @@ var ParallelMessageQueue = class ParallelMessageQueue {
|
|
|
251
278
|
this.queue = queue;
|
|
252
279
|
this.workers = workers;
|
|
253
280
|
this.nativeRetrial = queue.nativeRetrial;
|
|
281
|
+
if (queue.getDepth != null) this.getDepth = () => queue.getDepth();
|
|
254
282
|
}
|
|
255
283
|
enqueue(message, options) {
|
|
256
284
|
return this.queue.enqueue(message, options);
|
|
@@ -321,11 +349,162 @@ var ParallelMessageQueue = class ParallelMessageQueue {
|
|
|
321
349
|
}
|
|
322
350
|
};
|
|
323
351
|
//#endregion
|
|
352
|
+
//#region src/federation/router.ts
|
|
353
|
+
const logger = (0, _logtape_logtape.getLogger)([
|
|
354
|
+
"fedify",
|
|
355
|
+
"federation",
|
|
356
|
+
"router",
|
|
357
|
+
"deprecated"
|
|
358
|
+
]);
|
|
359
|
+
let deprecationWarned = false;
|
|
360
|
+
function warnDeprecated() {
|
|
361
|
+
if (deprecationWarned) return;
|
|
362
|
+
deprecationWarned = true;
|
|
363
|
+
logger.warn("The `Router` and `RouterError` classes from `@fedify/fedify` are deprecated. Please use `Router` from `@fedify/uri-template` instead.");
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* URL router and constructor based on URI Template
|
|
367
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
|
|
368
|
+
*
|
|
369
|
+
* @deprecated Import `Router` from `@fedify/uri-template` instead. This class
|
|
370
|
+
* remains only for compatibility with older Fedify code. The
|
|
371
|
+
* `@fedify/uri-template` router is the replacement implementation
|
|
372
|
+
* and should be used directly in new code.
|
|
373
|
+
*/
|
|
374
|
+
var Router = class Router {
|
|
375
|
+
#router;
|
|
376
|
+
/**
|
|
377
|
+
* Create a new {@link Router}.
|
|
378
|
+
* @param options Options for the router.
|
|
379
|
+
* @deprecated Use `new Router(options)` from `@fedify/uri-template`
|
|
380
|
+
* instead.
|
|
381
|
+
*/
|
|
382
|
+
constructor(options) {
|
|
383
|
+
this.#router = convertRouterError(() => new _fedify_uri_template.Router(options));
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Whether to ignore trailing slashes when matching paths.
|
|
387
|
+
* @deprecated Use `Router` from `@fedify/uri-template` instead. This
|
|
388
|
+
* accessor forwards to the underlying `@fedify/uri-template`
|
|
389
|
+
* router so that post-construction mutation keeps working as
|
|
390
|
+
* in older Fedify code.
|
|
391
|
+
*/
|
|
392
|
+
get trailingSlashInsensitive() {
|
|
393
|
+
return this.#router.trailingSlashInsensitive;
|
|
394
|
+
}
|
|
395
|
+
set trailingSlashInsensitive(value) {
|
|
396
|
+
this.#router.trailingSlashInsensitive = value;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Clones this router.
|
|
400
|
+
* @deprecated Use `Router` from `@fedify/uri-template` instead.
|
|
401
|
+
*/
|
|
402
|
+
clone() {
|
|
403
|
+
return convertRouterError(() => {
|
|
404
|
+
const clone = new Router();
|
|
405
|
+
clone.#router = this.#router.clone();
|
|
406
|
+
return clone;
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Checks if a path name exists in the router.
|
|
411
|
+
* @param name The name of the path.
|
|
412
|
+
* @returns `true` if the path name exists, otherwise `false`.
|
|
413
|
+
* @deprecated Use `Router` from `@fedify/uri-template` instead.
|
|
414
|
+
*/
|
|
415
|
+
has(name) {
|
|
416
|
+
return convertRouterError(() => this.#router.has(name));
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Adds a new path rule to the router.
|
|
420
|
+
* @param template The path pattern.
|
|
421
|
+
* @param name The name of the path.
|
|
422
|
+
* @returns The names of the variables in the path pattern.
|
|
423
|
+
* @deprecated Use `Router` from `@fedify/uri-template` instead. In this
|
|
424
|
+
* compatibility class, `add()` both registers the route and
|
|
425
|
+
* returns the variables in the path pattern. In
|
|
426
|
+
* `@fedify/uri-template`, these two responsibilities are split:
|
|
427
|
+
* `router.add(template, name)` registers the route and returns
|
|
428
|
+
* `void`, while the pure static method
|
|
429
|
+
* `Router.variables(template)` returns the variable names. To
|
|
430
|
+
* migrate, call `Router.variables(template)` when variables are
|
|
431
|
+
* needed, then call `router.add(template, name)` to register the
|
|
432
|
+
* route.
|
|
433
|
+
*/
|
|
434
|
+
add(template, name) {
|
|
435
|
+
return convertRouterError(() => {
|
|
436
|
+
(0, _fedify_uri_template.assertPath)(template);
|
|
437
|
+
this.#router.add(template, name);
|
|
438
|
+
return _fedify_uri_template.Router.variables(template);
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Resolves a path name and values from a URL, if any match.
|
|
443
|
+
* @param url The URL to resolve.
|
|
444
|
+
* @returns The name of the path and its values, if any match. Otherwise,
|
|
445
|
+
* `null`.
|
|
446
|
+
* @deprecated Use `Router` from `@fedify/uri-template` instead. Unlike the
|
|
447
|
+
* stricter `@fedify/uri-template` router, this compatibility
|
|
448
|
+
* method keeps the old Fedify 2.x contract of returning `null`
|
|
449
|
+
* (rather than throwing) for inputs that are not router paths.
|
|
450
|
+
*/
|
|
451
|
+
route(url) {
|
|
452
|
+
return convertRouterError(() => {
|
|
453
|
+
if (!(0, _fedify_uri_template.isPath)(url)) return null;
|
|
454
|
+
return this.#router.route(url);
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Constructs a URL/path from a path name and values.
|
|
459
|
+
* @param name The name of the path.
|
|
460
|
+
* @param values The values to expand the path with.
|
|
461
|
+
* @returns The URL/path, if the name exists. Otherwise, `null`.
|
|
462
|
+
* @deprecated Use `Router` from `@fedify/uri-template` instead.
|
|
463
|
+
*/
|
|
464
|
+
build(name, values) {
|
|
465
|
+
return convertRouterError(() => this.#router.build(name, values));
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
/**
|
|
469
|
+
* An error thrown by the {@link Router}.
|
|
470
|
+
* @deprecated Import `RouterError` from `@fedify/uri-template` instead.
|
|
471
|
+
*/
|
|
472
|
+
var RouterError = class extends _fedify_uri_template.RouterError {
|
|
473
|
+
/**
|
|
474
|
+
* Treats every `RouterError` from `@fedify/uri-template` as an instance of
|
|
475
|
+
* this deprecated class.
|
|
476
|
+
*
|
|
477
|
+
* @deprecated Import `RouterError` from `@fedify/uri-template` instead.
|
|
478
|
+
*/
|
|
479
|
+
static [Symbol.hasInstance](instance) {
|
|
480
|
+
return instance instanceof _fedify_uri_template.RouterError;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Create a new {@link RouterError}.
|
|
484
|
+
* @param message The error message.
|
|
485
|
+
* @deprecated Import `RouterError` from `@fedify/uri-template` instead.
|
|
486
|
+
*/
|
|
487
|
+
constructor(message) {
|
|
488
|
+
super(message);
|
|
489
|
+
warnDeprecated();
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
function convertRouterError(func) {
|
|
493
|
+
try {
|
|
494
|
+
warnDeprecated();
|
|
495
|
+
return func();
|
|
496
|
+
} catch (error) {
|
|
497
|
+
if (error instanceof _fedify_uri_template.RouterError) throw new RouterError(error.message);
|
|
498
|
+
throw error;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
//#endregion
|
|
502
|
+
exports.CircuitBreaker = require_middleware.CircuitBreaker;
|
|
324
503
|
exports.InProcessMessageQueue = InProcessMessageQueue;
|
|
325
504
|
exports.MemoryKvStore = MemoryKvStore;
|
|
326
505
|
exports.ParallelMessageQueue = ParallelMessageQueue;
|
|
327
|
-
exports.Router =
|
|
328
|
-
exports.RouterError =
|
|
506
|
+
exports.Router = Router;
|
|
507
|
+
exports.RouterError = RouterError;
|
|
329
508
|
exports.SendActivityError = require_middleware.SendActivityError;
|
|
330
509
|
exports.buildCollectionSynchronizationHeader = require_middleware.buildCollectionSynchronizationHeader;
|
|
331
510
|
exports.createExponentialBackoffPolicy = require_middleware.createExponentialBackoffPolicy;
|
|
@@ -333,5 +512,7 @@ exports.createFederation = require_middleware.createFederation;
|
|
|
333
512
|
exports.createFederationBuilder = require_middleware.createFederationBuilder;
|
|
334
513
|
exports.digest = require_middleware.digest;
|
|
335
514
|
exports.handleWebFinger = require_middleware.handleWebFinger;
|
|
515
|
+
exports.normalizeCircuitBreakerOptions = require_middleware.normalizeCircuitBreakerOptions;
|
|
516
|
+
exports.parseCircuitBreakerKvState = require_middleware.parseCircuitBreakerKvState;
|
|
336
517
|
exports.respondWithObject = require_middleware.respondWithObject;
|
|
337
518
|
exports.respondWithObjectIfAcceptable = require_middleware.respondWithObjectIfAcceptable;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { a as
|
|
3
|
-
import { n as
|
|
4
|
-
|
|
1
|
+
/// <reference lib="esnext.temporal" />
|
|
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
|
+
import { a as MemoryKvStore, i as KvStoreSetOptions, n as KvStore, r as KvStoreListEntry, t as KvKey } from "../kv-gJ8LYbxX.cjs";
|
|
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-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
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
5
|
-
import { n as handleWebFinger, t as WebFingerHandlerParameters } from "../mod-
|
|
6
|
-
export { ActorAliasMapper, ActorCallbackSetters, ActorDispatcher, ActorHandleMapper, ActorKeyPair, ActorKeyPairsDispatcher, AuthorizePredicate, CollectionCallbackSetters, CollectionCounter, CollectionCursor, CollectionDispatcher, ConstructorWithTypeId, Context, CreateExponentialBackoffPolicyOptions, CustomCollectionCallbackSetters, CustomCollectionCounter, CustomCollectionCursor, CustomCollectionDispatcher, Federatable, Federation, 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, MessageQueueEnqueueOptions, MessageQueueListenOptions, NodeInfoDispatcher, 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, respondWithObject, respondWithObjectIfAcceptable };
|
|
1
|
+
/// <reference lib="esnext.temporal" />
|
|
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
|
+
import { a as MemoryKvStore, i as KvStoreSetOptions, n as KvStore, r as KvStoreListEntry, t as KvKey } from "../kv-D6hNiMTK.js";
|
|
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-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,8 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
-
import "urlpattern-polyfill";
|
|
3
|
-
import { a as
|
|
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-BgzRkDcm.js";
|
|
4
|
+
import { getLogger } from "@logtape/logtape";
|
|
5
|
+
import { Router as Router$1, RouterError as RouterError$1, assertPath, isPath } from "@fedify/uri-template";
|
|
4
6
|
import { isEqual } from "es-toolkit";
|
|
5
7
|
//#region src/federation/kv.ts
|
|
6
8
|
/**
|
|
@@ -101,6 +103,7 @@ var InProcessMessageQueue = class {
|
|
|
101
103
|
#messages;
|
|
102
104
|
#monitors;
|
|
103
105
|
#pollIntervalMs;
|
|
106
|
+
#delayedMessages;
|
|
104
107
|
/**
|
|
105
108
|
* Tracks which ordering keys are currently being processed to ensure
|
|
106
109
|
* sequential processing for messages with the same key.
|
|
@@ -119,42 +122,56 @@ var InProcessMessageQueue = class {
|
|
|
119
122
|
this.#messages = [];
|
|
120
123
|
this.#monitors = {};
|
|
121
124
|
this.#pollIntervalMs = Temporal.Duration.from(options.pollInterval ?? { seconds: 5 }).total("millisecond");
|
|
125
|
+
this.#delayedMessages = 0;
|
|
122
126
|
this.#processingKeys = /* @__PURE__ */ new Set();
|
|
123
127
|
}
|
|
124
128
|
enqueue(message, options) {
|
|
125
129
|
const delay = options?.delay == null ? 0 : Math.max(options.delay.total("millisecond"), 0);
|
|
126
130
|
if (delay > 0) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
+
this.#delayedMessages++;
|
|
132
|
+
setTimeout(() => {
|
|
133
|
+
this.#delayedMessages--;
|
|
134
|
+
this.#enqueueReady(message, options);
|
|
135
|
+
}, delay);
|
|
131
136
|
return Promise.resolve();
|
|
132
137
|
}
|
|
138
|
+
this.#enqueueReady(message, options);
|
|
139
|
+
return Promise.resolve();
|
|
140
|
+
}
|
|
141
|
+
#enqueueReady(message, options) {
|
|
133
142
|
const orderingKey = options?.orderingKey ?? null;
|
|
134
143
|
this.#messages.push({
|
|
135
144
|
message,
|
|
136
145
|
orderingKey
|
|
137
146
|
});
|
|
147
|
+
this.#notifyMonitors();
|
|
148
|
+
}
|
|
149
|
+
#notifyMonitors() {
|
|
138
150
|
for (const monitorId in this.#monitors) this.#monitors[monitorId]();
|
|
139
|
-
return Promise.resolve();
|
|
140
151
|
}
|
|
141
152
|
enqueueMany(messages, options) {
|
|
142
153
|
if (messages.length === 0) return Promise.resolve();
|
|
143
154
|
const delay = options?.delay == null ? 0 : Math.max(options.delay.total("millisecond"), 0);
|
|
144
155
|
if (delay > 0) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
156
|
+
const delayedCount = messages.length;
|
|
157
|
+
const deferredMessages = [...messages];
|
|
158
|
+
this.#delayedMessages += delayedCount;
|
|
159
|
+
setTimeout(() => {
|
|
160
|
+
this.#delayedMessages -= delayedCount;
|
|
161
|
+
this.#enqueueManyReady(deferredMessages, options);
|
|
162
|
+
}, delay);
|
|
149
163
|
return Promise.resolve();
|
|
150
164
|
}
|
|
165
|
+
this.#enqueueManyReady(messages, options);
|
|
166
|
+
return Promise.resolve();
|
|
167
|
+
}
|
|
168
|
+
#enqueueManyReady(messages, options) {
|
|
151
169
|
const orderingKey = options?.orderingKey ?? null;
|
|
152
170
|
for (const message of messages) this.#messages.push({
|
|
153
171
|
message,
|
|
154
172
|
orderingKey
|
|
155
173
|
});
|
|
156
|
-
|
|
157
|
-
return Promise.resolve();
|
|
174
|
+
this.#notifyMonitors();
|
|
158
175
|
}
|
|
159
176
|
async listen(handler, options = {}) {
|
|
160
177
|
const signal = options.signal;
|
|
@@ -172,6 +189,15 @@ var InProcessMessageQueue = class {
|
|
|
172
189
|
else await this.#wait(10, signal);
|
|
173
190
|
}
|
|
174
191
|
}
|
|
192
|
+
getDepth() {
|
|
193
|
+
const ready = this.#messages.length;
|
|
194
|
+
const delayed = this.#delayedMessages;
|
|
195
|
+
return Promise.resolve({
|
|
196
|
+
queued: ready + delayed,
|
|
197
|
+
ready,
|
|
198
|
+
delayed
|
|
199
|
+
});
|
|
200
|
+
}
|
|
175
201
|
#wait(ms, signal) {
|
|
176
202
|
let timer = null;
|
|
177
203
|
return Promise.any([new Promise((resolve) => {
|
|
@@ -226,6 +252,7 @@ var ParallelMessageQueue = class ParallelMessageQueue {
|
|
|
226
252
|
* @since 1.7.0
|
|
227
253
|
*/
|
|
228
254
|
nativeRetrial;
|
|
255
|
+
getDepth;
|
|
229
256
|
/**
|
|
230
257
|
* Tracks which ordering keys are currently being processed to ensure
|
|
231
258
|
* sequential processing for messages with the same key.
|
|
@@ -249,6 +276,7 @@ var ParallelMessageQueue = class ParallelMessageQueue {
|
|
|
249
276
|
this.queue = queue;
|
|
250
277
|
this.workers = workers;
|
|
251
278
|
this.nativeRetrial = queue.nativeRetrial;
|
|
279
|
+
if (queue.getDepth != null) this.getDepth = () => queue.getDepth();
|
|
252
280
|
}
|
|
253
281
|
enqueue(message, options) {
|
|
254
282
|
return this.queue.enqueue(message, options);
|
|
@@ -319,4 +347,154 @@ var ParallelMessageQueue = class ParallelMessageQueue {
|
|
|
319
347
|
}
|
|
320
348
|
};
|
|
321
349
|
//#endregion
|
|
322
|
-
|
|
350
|
+
//#region src/federation/router.ts
|
|
351
|
+
const logger = getLogger([
|
|
352
|
+
"fedify",
|
|
353
|
+
"federation",
|
|
354
|
+
"router",
|
|
355
|
+
"deprecated"
|
|
356
|
+
]);
|
|
357
|
+
let deprecationWarned = false;
|
|
358
|
+
function warnDeprecated() {
|
|
359
|
+
if (deprecationWarned) return;
|
|
360
|
+
deprecationWarned = true;
|
|
361
|
+
logger.warn("The `Router` and `RouterError` classes from `@fedify/fedify` are deprecated. Please use `Router` from `@fedify/uri-template` instead.");
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* URL router and constructor based on URI Template
|
|
365
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
|
|
366
|
+
*
|
|
367
|
+
* @deprecated Import `Router` from `@fedify/uri-template` instead. This class
|
|
368
|
+
* remains only for compatibility with older Fedify code. The
|
|
369
|
+
* `@fedify/uri-template` router is the replacement implementation
|
|
370
|
+
* and should be used directly in new code.
|
|
371
|
+
*/
|
|
372
|
+
var Router = class Router {
|
|
373
|
+
#router;
|
|
374
|
+
/**
|
|
375
|
+
* Create a new {@link Router}.
|
|
376
|
+
* @param options Options for the router.
|
|
377
|
+
* @deprecated Use `new Router(options)` from `@fedify/uri-template`
|
|
378
|
+
* instead.
|
|
379
|
+
*/
|
|
380
|
+
constructor(options) {
|
|
381
|
+
this.#router = convertRouterError(() => new Router$1(options));
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Whether to ignore trailing slashes when matching paths.
|
|
385
|
+
* @deprecated Use `Router` from `@fedify/uri-template` instead. This
|
|
386
|
+
* accessor forwards to the underlying `@fedify/uri-template`
|
|
387
|
+
* router so that post-construction mutation keeps working as
|
|
388
|
+
* in older Fedify code.
|
|
389
|
+
*/
|
|
390
|
+
get trailingSlashInsensitive() {
|
|
391
|
+
return this.#router.trailingSlashInsensitive;
|
|
392
|
+
}
|
|
393
|
+
set trailingSlashInsensitive(value) {
|
|
394
|
+
this.#router.trailingSlashInsensitive = value;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Clones this router.
|
|
398
|
+
* @deprecated Use `Router` from `@fedify/uri-template` instead.
|
|
399
|
+
*/
|
|
400
|
+
clone() {
|
|
401
|
+
return convertRouterError(() => {
|
|
402
|
+
const clone = new Router();
|
|
403
|
+
clone.#router = this.#router.clone();
|
|
404
|
+
return clone;
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Checks if a path name exists in the router.
|
|
409
|
+
* @param name The name of the path.
|
|
410
|
+
* @returns `true` if the path name exists, otherwise `false`.
|
|
411
|
+
* @deprecated Use `Router` from `@fedify/uri-template` instead.
|
|
412
|
+
*/
|
|
413
|
+
has(name) {
|
|
414
|
+
return convertRouterError(() => this.#router.has(name));
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Adds a new path rule to the router.
|
|
418
|
+
* @param template The path pattern.
|
|
419
|
+
* @param name The name of the path.
|
|
420
|
+
* @returns The names of the variables in the path pattern.
|
|
421
|
+
* @deprecated Use `Router` from `@fedify/uri-template` instead. In this
|
|
422
|
+
* compatibility class, `add()` both registers the route and
|
|
423
|
+
* returns the variables in the path pattern. In
|
|
424
|
+
* `@fedify/uri-template`, these two responsibilities are split:
|
|
425
|
+
* `router.add(template, name)` registers the route and returns
|
|
426
|
+
* `void`, while the pure static method
|
|
427
|
+
* `Router.variables(template)` returns the variable names. To
|
|
428
|
+
* migrate, call `Router.variables(template)` when variables are
|
|
429
|
+
* needed, then call `router.add(template, name)` to register the
|
|
430
|
+
* route.
|
|
431
|
+
*/
|
|
432
|
+
add(template, name) {
|
|
433
|
+
return convertRouterError(() => {
|
|
434
|
+
assertPath(template);
|
|
435
|
+
this.#router.add(template, name);
|
|
436
|
+
return Router$1.variables(template);
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Resolves a path name and values from a URL, if any match.
|
|
441
|
+
* @param url The URL to resolve.
|
|
442
|
+
* @returns The name of the path and its values, if any match. Otherwise,
|
|
443
|
+
* `null`.
|
|
444
|
+
* @deprecated Use `Router` from `@fedify/uri-template` instead. Unlike the
|
|
445
|
+
* stricter `@fedify/uri-template` router, this compatibility
|
|
446
|
+
* method keeps the old Fedify 2.x contract of returning `null`
|
|
447
|
+
* (rather than throwing) for inputs that are not router paths.
|
|
448
|
+
*/
|
|
449
|
+
route(url) {
|
|
450
|
+
return convertRouterError(() => {
|
|
451
|
+
if (!isPath(url)) return null;
|
|
452
|
+
return this.#router.route(url);
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Constructs a URL/path from a path name and values.
|
|
457
|
+
* @param name The name of the path.
|
|
458
|
+
* @param values The values to expand the path with.
|
|
459
|
+
* @returns The URL/path, if the name exists. Otherwise, `null`.
|
|
460
|
+
* @deprecated Use `Router` from `@fedify/uri-template` instead.
|
|
461
|
+
*/
|
|
462
|
+
build(name, values) {
|
|
463
|
+
return convertRouterError(() => this.#router.build(name, values));
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
/**
|
|
467
|
+
* An error thrown by the {@link Router}.
|
|
468
|
+
* @deprecated Import `RouterError` from `@fedify/uri-template` instead.
|
|
469
|
+
*/
|
|
470
|
+
var RouterError = class extends RouterError$1 {
|
|
471
|
+
/**
|
|
472
|
+
* Treats every `RouterError` from `@fedify/uri-template` as an instance of
|
|
473
|
+
* this deprecated class.
|
|
474
|
+
*
|
|
475
|
+
* @deprecated Import `RouterError` from `@fedify/uri-template` instead.
|
|
476
|
+
*/
|
|
477
|
+
static [Symbol.hasInstance](instance) {
|
|
478
|
+
return instance instanceof RouterError$1;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Create a new {@link RouterError}.
|
|
482
|
+
* @param message The error message.
|
|
483
|
+
* @deprecated Import `RouterError` from `@fedify/uri-template` instead.
|
|
484
|
+
*/
|
|
485
|
+
constructor(message) {
|
|
486
|
+
super(message);
|
|
487
|
+
warnDeprecated();
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
function convertRouterError(func) {
|
|
491
|
+
try {
|
|
492
|
+
warnDeprecated();
|
|
493
|
+
return func();
|
|
494
|
+
} catch (error) {
|
|
495
|
+
if (error instanceof RouterError$1) throw new RouterError(error.message);
|
|
496
|
+
throw error;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
//#endregion
|
|
500
|
+
export { CircuitBreaker, InProcessMessageQueue, MemoryKvStore, ParallelMessageQueue, Router, RouterError, SendActivityError, buildCollectionSynchronizationHeader, createExponentialBackoffPolicy, createFederation, createFederationBuilder, digest, handleWebFinger, normalizeCircuitBreakerOptions, parseCircuitBreakerKvState, respondWithObject, respondWithObjectIfAcceptable };
|