@fedify/relay 2.0.36-dev.2842 → 2.0.36-dev.2843

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.
@@ -1,7 +1,7 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as exportSpki, r as getDocumentLoader, t as isRelayFollowerData } from "./types-Iq8eecec.js";
4
+ import { n as exportSpki, r as getDocumentLoader, t as isRelayFollowerData } from "./types-DPFuHaOn.js";
5
5
  import { MemoryKvStore, signRequest } from "@fedify/fedify";
6
6
  import { createRelay } from "@fedify/relay";
7
7
  import { Accept, Announce, Create, Delete, Follow, Move, Note, Person, Undo, Update } from "@fedify/vocab";
@@ -1,7 +1,7 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as exportSpki, r as getDocumentLoader, t as isRelayFollowerData } from "./types-Iq8eecec.js";
4
+ import { n as exportSpki, r as getDocumentLoader, t as isRelayFollowerData } from "./types-DPFuHaOn.js";
5
5
  import { MemoryKvStore, signRequest } from "@fedify/fedify";
6
6
  import { createRelay } from "@fedify/relay";
7
7
  import { Create, Delete, Follow, Move, Note, Person, Undo, Update } from "@fedify/vocab";
@@ -6,7 +6,7 @@ import { getLogger } from "@logtape/logtape";
6
6
  import dns from "node:dns/promises";
7
7
  import { isIP } from "node:net";
8
8
  import process$1 from "node:process";
9
- //#region ../vocab-runtime/dist/crypto-key-BoTl83Lh.js
9
+ //#region ../vocab-runtime/dist/crypto-key-BR2FO0pB.js
10
10
  const grants = /* @__PURE__ */ new WeakMap();
11
11
  /**
12
12
  * Issues a grant for the given URL's origin and addresses. This does not
@@ -80,6 +80,81 @@ function lookupAllAddresses(hostname) {
80
80
  return dns.lookup(hostname, { all: true });
81
81
  }
82
82
  /**
83
+ * Limits concurrent lookups started by the returned function. A pending
84
+ * caller can abort before its lookup starts. Once `dns.lookup()` has started,
85
+ * it cannot be cancelled, so its slot remains occupied until the underlying
86
+ * lookup settles, even if its caller aborts. This bounds the number of
87
+ * outstanding getaddrinfo calls made by users of this function.
88
+ * @internal
89
+ */
90
+ function createBoundedLookup(lookup, maxConcurrent = 1) {
91
+ if (!Number.isInteger(maxConcurrent) || maxConcurrent < 1) throw new RangeError("maxConcurrent must be a positive integer");
92
+ let active = 0;
93
+ const waiting = /* @__PURE__ */ new Set();
94
+ function release() {
95
+ active--;
96
+ while (waiting.size > 0) {
97
+ const next = waiting.values().next().value;
98
+ waiting.delete(next);
99
+ next.signal?.removeEventListener("abort", next.onAbort);
100
+ if (next.signal?.aborted) {
101
+ next.reject(next.signal.reason);
102
+ continue;
103
+ }
104
+ active++;
105
+ next.resolve();
106
+ break;
107
+ }
108
+ }
109
+ function acquire(signal) {
110
+ signal?.throwIfAborted();
111
+ if (active < maxConcurrent) {
112
+ active++;
113
+ return Promise.resolve();
114
+ }
115
+ return new Promise((resolve, reject) => {
116
+ const entry = {
117
+ signal,
118
+ resolve,
119
+ reject,
120
+ onAbort() {
121
+ if (!waiting.delete(entry)) return;
122
+ signal?.removeEventListener("abort", entry.onAbort);
123
+ reject(signal?.reason);
124
+ }
125
+ };
126
+ waiting.add(entry);
127
+ signal?.addEventListener("abort", entry.onAbort, { once: true });
128
+ if (signal?.aborted) entry.onAbort();
129
+ });
130
+ }
131
+ return async (hostname, signal) => {
132
+ await acquire(signal);
133
+ let started = false;
134
+ try {
135
+ signal?.throwIfAborted();
136
+ const pending = lookup(hostname);
137
+ started = true;
138
+ pending.then(release, release);
139
+ if (signal == null) return await pending;
140
+ let onAbort;
141
+ const aborted = new Promise((_, reject) => {
142
+ onAbort = () => reject(signal.reason);
143
+ signal.addEventListener("abort", onAbort, { once: true });
144
+ if (signal.aborted) onAbort();
145
+ });
146
+ try {
147
+ return await Promise.race([pending, aborted]);
148
+ } finally {
149
+ if (onAbort != null) signal.removeEventListener("abort", onAbort);
150
+ }
151
+ } finally {
152
+ if (!started) release();
153
+ }
154
+ };
155
+ }
156
+ createBoundedLookup(lookupAllAddresses, 2);
157
+ /**
83
158
  * Checks the parts of a URL that can be validated without resolving it:
84
159
  * the protocol, the `localhost` hostname, and IP literal hostnames.
85
160
  * @throws {UrlError} If the URL is not allowed.
@@ -26423,7 +26498,7 @@ const preloadedContexts = {
26423
26498
  "https://purl.archive.org/miscellany": miscellany_default
26424
26499
  };
26425
26500
  var name = "@fedify/vocab-runtime";
26426
- var version = "2.0.36-dev.2842+d35af543";
26501
+ var version = "2.0.36-dev.2843+780589e4";
26427
26502
  /**
26428
26503
  * Error thrown when fetching a JSON-LD document failed.
26429
26504
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/relay",
3
- "version": "2.0.36-dev.2842+d35af543",
3
+ "version": "2.0.36-dev.2843+780589e4",
4
4
  "description": "ActivityPub relay support for Fedify",
5
5
  "keywords": [
6
6
  "Fedify",
@@ -50,14 +50,14 @@
50
50
  "dependencies": {
51
51
  "@js-temporal/polyfill": "^0.5.1",
52
52
  "@logtape/logtape": "^2.0.0",
53
- "@fedify/vocab": "2.0.36-dev.2842+d35af543",
54
- "@fedify/fedify": "^2.0.36-dev.2842+d35af543"
53
+ "@fedify/fedify": "^2.0.36-dev.2843+780589e4",
54
+ "@fedify/vocab": "2.0.36-dev.2843+780589e4"
55
55
  },
56
56
  "devDependencies": {
57
57
  "tsdown": "^0.21.6",
58
58
  "typescript": "^6.0.0",
59
59
  "urlpattern-polyfill": "^10.1.0",
60
- "@fedify/vocab-runtime": "^2.0.36-dev.2842+d35af543"
60
+ "@fedify/vocab-runtime": "^2.0.36-dev.2843+780589e4"
61
61
  },
62
62
  "scripts": {
63
63
  "build:self": "tsdown",