@fedify/fedify 2.1.1 → 2.1.3

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 (207) hide show
  1. package/dist/{accept-D7sAxyNa.js → accept-Dd__NiUL.mjs} +10 -8
  2. package/dist/{assert-MZs1qjMx.js → assert-ddO5KLpe.mjs} +5 -9
  3. package/dist/{assert_equals-DSbWqCm3.js → assert_equals-Ew3jOFa3.mjs} +55 -69
  4. package/dist/{assert_instance_of-DHz7EHNU.js → assert_instance_of-C4Ri6VuN.mjs} +5 -9
  5. package/dist/{assert_not_equals-f3m3epl3.js → assert_not_equals--wG9hV7u.mjs} +6 -13
  6. package/dist/{assert_rejects-0h7I2Esa.js → assert_rejects-B-qJtC9Z.mjs} +6 -11
  7. package/dist/{assert_throws-rjdMBf31.js → assert_throws-4NwKEy2q.mjs} +5 -10
  8. package/dist/{builder-DbKYZdSy.js → builder-BKo51w-F.mjs} +32 -41
  9. package/dist/{chunk-CGaQZ11T.cjs → chunk-DDcVe30Y.cjs} +23 -24
  10. package/dist/{chunk-DJNbSFdH.js → chunk-nlSIicah.js} +8 -8
  11. package/dist/{client-BxMZiQaD.d.ts → client-AtlibPOU.d.ts} +1 -1
  12. package/dist/{client-CoCIaTNO.js → client-DEpOVgY1.mjs} +9 -13
  13. package/dist/{client-C97KOq3x.d.cts → client-z-8dc-e1.d.cts} +1 -1
  14. package/dist/{collection-CSzG2j1P.js → collection-BD6-SZ6O.mjs} +7 -12
  15. package/dist/compat/mod.cjs +5 -8
  16. package/dist/compat/mod.d.cts +78 -6
  17. package/dist/compat/mod.d.ts +78 -6
  18. package/dist/compat/mod.js +4 -8
  19. package/dist/compat/transformers.test.mjs +62 -0
  20. package/dist/{context-DyJjQQ_H.d.ts → context-BOiMZBu5.d.ts} +9 -18
  21. package/dist/{context-BcqA-0BL.d.cts → context-BhZVy7RB.d.cts} +9 -18
  22. package/dist/{context-Aqenou7c.js → context-Juj6bdHC.mjs} +7 -11
  23. package/dist/deno-D5r_9RvZ.mjs +8 -0
  24. package/dist/{docloader-Ck0SCLXX.js → docloader-B9CXCw8i.mjs} +8 -14
  25. package/dist/{esm-nLm00z9V.js → esm-DVILvP5e.mjs} +50 -89
  26. package/dist/federation/builder.test.d.mts +2 -0
  27. package/dist/federation/{builder.test.js → builder.test.mjs} +21 -44
  28. package/dist/federation/collection.test.d.mts +2 -0
  29. package/dist/federation/collection.test.mjs +21 -0
  30. package/dist/federation/handler.test.d.mts +2 -0
  31. package/dist/federation/{handler.test.js → handler.test.mjs} +69 -131
  32. package/dist/federation/idempotency.test.d.mts +2 -0
  33. package/dist/federation/{idempotency.test.js → idempotency.test.mjs} +31 -63
  34. package/dist/federation/inbox.test.d.mts +2 -0
  35. package/dist/federation/{inbox.test.js → inbox.test.mjs} +8 -12
  36. package/dist/federation/keycache.test.d.mts +2 -0
  37. package/dist/federation/{keycache.test.js → keycache.test.mjs} +13 -19
  38. package/dist/federation/kv.test.d.mts +2 -0
  39. package/dist/federation/{kv.test.js → kv.test.mjs} +11 -22
  40. package/dist/federation/middleware.test.d.mts +2 -0
  41. package/dist/federation/{middleware.test.js → middleware.test.mjs} +173 -262
  42. package/dist/federation/mod.cjs +327 -16
  43. package/dist/federation/mod.d.cts +3 -6
  44. package/dist/federation/mod.d.ts +3 -6
  45. package/dist/federation/mod.js +322 -13
  46. package/dist/federation/mq.test.d.mts +2 -0
  47. package/dist/federation/{mq.test.js → mq.test.mjs} +21 -35
  48. package/dist/federation/negotiation.test.d.mts +2 -0
  49. package/dist/federation/{negotiation.test.js → negotiation.test.mjs} +9 -16
  50. package/dist/federation/retry.test.d.mts +2 -0
  51. package/dist/federation/{retry.test.js → retry.test.mjs} +8 -11
  52. package/dist/federation/router.test.d.mts +2 -0
  53. package/dist/federation/{router.test.js → router.test.mjs} +11 -16
  54. package/dist/federation/send.test.d.mts +2 -0
  55. package/dist/federation/{send.test.js → send.test.mjs} +22 -30
  56. package/dist/federation/webfinger.test.d.mts +2 -0
  57. package/dist/federation/{webfinger.test.js → webfinger.test.mjs} +22 -56
  58. package/dist/{http-DFzT4YFG.js → http-B53alCGi.mjs} +23 -43
  59. package/dist/{http-ca2xny58.cjs → http-BngkmEhl.cjs} +177 -302
  60. package/dist/{http-BudnHZE2.d.cts → http-CrGuipxe.d.cts} +1 -6
  61. package/dist/{http-EUQ6crVa.js → http-PS3wuU8D.js} +53 -184
  62. package/dist/{http-Dax_FIBo.d.ts → http-aQzN9Ayi.d.ts} +1 -6
  63. package/dist/{inbox-BMLz_-pL.js → inbox-CHsLu5ai.mjs} +18 -26
  64. package/dist/{key-CypuWa94.js → key-D9Np_ZXl.mjs} +29 -37
  65. package/dist/{keycache-CpGWAUbj.js → keycache-CCSwkQcY.mjs} +5 -10
  66. package/dist/{keys-BFve7QQv.js → keys-BAK-tUlf.mjs} +5 -9
  67. package/dist/{kv-BL4nlICN.d.cts → kv-CbLNp3zQ.d.cts} +1 -1
  68. package/dist/{kv-DXEUEP6z.d.ts → kv-GFYnFoOl.d.ts} +1 -1
  69. package/dist/{kv-cache-Bw2F2ABq.js → kv-cache-B01V7s3h.mjs} +4 -8
  70. package/dist/{kv-cache-SKgbvvu4.js → kv-cache-B2Qi5MGv.js} +6 -13
  71. package/dist/{kv-cache-BBJFLMW5.cjs → kv-cache-YCtINZK4.cjs} +27 -34
  72. package/dist/{kv-QzKcOQgP.js → kv-tL2TOE9X.mjs} +6 -10
  73. package/dist/{ld-CXLtTc0G.js → ld-BaxRFhDd.mjs} +17 -31
  74. package/dist/{middleware-CL6XaAFy.cjs → middleware-Bsv-7iX7.cjs} +532 -587
  75. package/dist/middleware-C37OmOz_.mjs +5 -0
  76. package/dist/middleware-CelV2xrI.cjs +4 -0
  77. package/dist/{middleware-CvS6hWm3.js → middleware-Dn1kk96N.js} +335 -382
  78. package/dist/{middleware-BHJ0xm0L.js → middleware-dFn6ozt5.mjs} +282 -317
  79. package/dist/{mod-Bx9jcLB8.d.cts → mod-B505FZBC.d.cts} +3 -3
  80. package/dist/{mod-em2Il1eD.d.cts → mod-Bp_CzKd4.d.cts} +2 -2
  81. package/dist/{mod-Cs2dYEwI.d.ts → mod-D7PAuO6k.d.ts} +3 -3
  82. package/dist/{mod-D6MdymW7.d.ts → mod-DKOAow7a.d.ts} +2 -2
  83. package/dist/{mod-Coe7KEgX.d.cts → mod-DoJBjjnO.d.cts} +2 -2
  84. package/dist/{mod-D6dOd--H.d.ts → mod-DvxszxXC.d.ts} +2 -2
  85. package/dist/mod.cjs +29 -74
  86. package/dist/mod.d.cts +11 -14
  87. package/dist/mod.d.ts +11 -15
  88. package/dist/mod.js +17 -71
  89. package/dist/{negotiation-BlAuS_nr.js → negotiation-DnsfFF8I.mjs} +7 -11
  90. package/dist/nodeinfo/client.test.d.mts +2 -0
  91. package/dist/nodeinfo/{client.test.js → client.test.mjs} +22 -40
  92. package/dist/nodeinfo/handler.test.d.mts +2 -0
  93. package/dist/nodeinfo/{handler.test.js → handler.test.mjs} +13 -43
  94. package/dist/nodeinfo/mod.cjs +5 -8
  95. package/dist/nodeinfo/mod.d.cts +2 -3
  96. package/dist/nodeinfo/mod.d.ts +2 -3
  97. package/dist/nodeinfo/mod.js +4 -8
  98. package/dist/nodeinfo/types.test.d.mts +2 -0
  99. package/dist/nodeinfo/{types.test.js → types.test.mjs} +9 -16
  100. package/dist/otel/exporter.test.d.mts +2 -0
  101. package/dist/otel/{exporter.test.js → exporter.test.mjs} +124 -178
  102. package/dist/otel/mod.cjs +15 -20
  103. package/dist/otel/mod.d.cts +2 -2
  104. package/dist/otel/mod.d.ts +2 -2
  105. package/dist/otel/mod.js +8 -14
  106. package/dist/{owner-gd0Q9FuU.d.ts → owner-74ARJ5TL.d.ts} +1 -1
  107. package/dist/{owner-1AbPBOOZ.d.cts → owner-CptqhsOy.d.cts} +1 -1
  108. package/dist/{owner-CwMai3jn.js → owner-dxM51u36.mjs} +11 -16
  109. package/dist/{proof-ZuJBOUoi.js → proof-CH5U0k7G.mjs} +21 -33
  110. package/dist/{proof-sCID81Ua.cjs → proof-D39qiki3.cjs} +133 -157
  111. package/dist/{proof-6Zw1FW7t.js → proof-Dpgqx9RS.js} +32 -58
  112. package/dist/{retry-mqLf4b-R.js → retry-B_E3V_Dx.mjs} +4 -7
  113. package/dist/{router-D9eI0s4b.js → router-CrMLXoOr.mjs} +4 -8
  114. package/dist/runtime/mod.cjs +11 -13
  115. package/dist/runtime/mod.d.cts +6 -2
  116. package/dist/runtime/mod.d.ts +0 -1
  117. package/dist/runtime/mod.js +4 -7
  118. package/dist/{send-BW73dy6Q.js → send-D1-4ZnQq.mjs} +8 -13
  119. package/dist/sig/accept.test.d.mts +2 -0
  120. package/dist/sig/{accept.test.js → accept.test.mjs} +35 -70
  121. package/dist/sig/http.test.d.mts +2 -0
  122. package/dist/sig/{http.test.js → http.test.mjs} +166 -280
  123. package/dist/sig/key.test.d.mts +2 -0
  124. package/dist/sig/{key.test.js → key.test.mjs} +11 -18
  125. package/dist/sig/ld.test.d.mts +2 -0
  126. package/dist/sig/{ld.test.js → ld.test.mjs} +22 -35
  127. package/dist/sig/mod.cjs +6 -9
  128. package/dist/sig/mod.d.cts +3 -3
  129. package/dist/sig/mod.d.ts +3 -3
  130. package/dist/sig/mod.js +5 -9
  131. package/dist/sig/owner.test.d.mts +2 -0
  132. package/dist/sig/{owner.test.js → owner.test.mjs} +19 -34
  133. package/dist/sig/proof.test.d.mts +2 -0
  134. package/dist/sig/{proof.test.js → proof.test.mjs} +16 -27
  135. package/dist/{std__assert-X-_kMxKM.js → std__assert-Duiq_YC9.mjs} +12 -24
  136. package/dist/testing/{mod.d.ts → mod.d.mts} +26 -90
  137. package/dist/testing/mod.mjs +6 -0
  138. package/dist/{transformers-3g8GZwkZ.cjs → transformers-NeAONrAq.cjs} +20 -25
  139. package/dist/{transformers-C3FLHUd6.js → transformers-ve6e2xcg.js} +3 -7
  140. package/dist/{types-CPz01LGH.js → types-DCP0WLdt.mjs} +4 -7
  141. package/dist/{types-Cd_hszr_.cjs → types-KC4QAoxe.cjs} +29 -34
  142. package/dist/{types-C93Ob9cU.js → types-hvL8ElAs.js} +8 -13
  143. package/dist/utils/docloader.test.d.mts +2 -0
  144. package/dist/utils/{docloader.test.js → docloader.test.mjs} +14 -25
  145. package/dist/utils/kv-cache.test.d.mts +2 -0
  146. package/dist/utils/{kv-cache.test.js → kv-cache.test.mjs} +25 -40
  147. package/dist/utils/mod.cjs +5 -9
  148. package/dist/utils/mod.d.cts +1 -3
  149. package/dist/utils/mod.d.ts +1 -3
  150. package/dist/utils/mod.js +4 -9
  151. package/dist/vocab/cjs.test.d.mts +2 -0
  152. package/dist/vocab/cjs.test.mjs +14 -0
  153. package/dist/vocab/mod.cjs +10 -12
  154. package/dist/vocab/mod.js +3 -5
  155. package/package.json +8 -8
  156. package/dist/compat/transformers.test.d.ts +0 -3
  157. package/dist/compat/transformers.test.js +0 -88
  158. package/dist/compat-Bb4NuTUO.js +0 -4
  159. package/dist/compat-DmDDELst.cjs +0 -4
  160. package/dist/deno-DH972JvX.js +0 -121
  161. package/dist/federation/builder.test.d.ts +0 -3
  162. package/dist/federation/collection.test.d.ts +0 -3
  163. package/dist/federation/collection.test.js +0 -32
  164. package/dist/federation/handler.test.d.ts +0 -3
  165. package/dist/federation/idempotency.test.d.ts +0 -3
  166. package/dist/federation/inbox.test.d.ts +0 -3
  167. package/dist/federation/keycache.test.d.ts +0 -3
  168. package/dist/federation/kv.test.d.ts +0 -3
  169. package/dist/federation/middleware.test.d.ts +0 -3
  170. package/dist/federation/mq.test.d.ts +0 -3
  171. package/dist/federation/negotiation.test.d.ts +0 -3
  172. package/dist/federation/retry.test.d.ts +0 -3
  173. package/dist/federation/router.test.d.ts +0 -3
  174. package/dist/federation/send.test.d.ts +0 -3
  175. package/dist/federation/webfinger.test.d.ts +0 -3
  176. package/dist/federation-Bp3HI26G.cjs +0 -350
  177. package/dist/federation-DaMfqRm4.js +0 -332
  178. package/dist/middleware-B8FJuMM0.js +0 -27
  179. package/dist/middleware-BVp930fR.js +0 -12
  180. package/dist/middleware-BvGP-uXy.cjs +0 -12
  181. package/dist/mod-B7QkWzrL.d.cts +0 -80
  182. package/dist/mod-Bh8mqlYw.d.cts +0 -9
  183. package/dist/mod-D6HodEq7.d.ts +0 -7
  184. package/dist/mod-SMHOMNpZ.d.ts +0 -82
  185. package/dist/mod-gq_Xfdz8.d.cts +0 -1
  186. package/dist/nodeinfo/client.test.d.ts +0 -3
  187. package/dist/nodeinfo/handler.test.d.ts +0 -3
  188. package/dist/nodeinfo/types.test.d.ts +0 -3
  189. package/dist/nodeinfo-DoESQxq5.js +0 -4
  190. package/dist/nodeinfo-DuMYTpbZ.cjs +0 -4
  191. package/dist/otel/exporter.test.d.ts +0 -3
  192. package/dist/runtime-c2Njxsry.cjs +0 -17
  193. package/dist/runtime-poamPCMb.js +0 -13
  194. package/dist/sig/accept.test.d.ts +0 -3
  195. package/dist/sig/http.test.d.ts +0 -3
  196. package/dist/sig/key.test.d.ts +0 -3
  197. package/dist/sig/ld.test.d.ts +0 -3
  198. package/dist/sig/owner.test.d.ts +0 -3
  199. package/dist/sig/proof.test.d.ts +0 -3
  200. package/dist/sig-BNhspNOf.js +0 -4
  201. package/dist/sig-vX39WyWI.cjs +0 -4
  202. package/dist/testing/mod.js +0 -10
  203. package/dist/utils/docloader.test.d.ts +0 -3
  204. package/dist/utils/kv-cache.test.d.ts +0 -3
  205. package/dist/utils-BQ9KqEK9.cjs +0 -4
  206. package/dist/utils-Dn5OPdSW.js +0 -4
  207. /package/dist/{mod-AGjRfPjT.d.ts → compat/transformers.test.d.mts} +0 -0
@@ -1,350 +0,0 @@
1
-
2
- const { Temporal } = require("@js-temporal/polyfill");
3
- const { URLPattern } = require("urlpattern-polyfill");
4
-
5
- const require_chunk = require('./chunk-CGaQZ11T.cjs');
6
- const es_toolkit = require_chunk.__toESM(require("es-toolkit"));
7
-
8
- //#region src/federation/kv.ts
9
- /**
10
- * A key–value store that stores values in memory.
11
- * Do not use this in production as it does not persist values.
12
- *
13
- * @since 0.5.0
14
- */
15
- var MemoryKvStore = class {
16
- #values = {};
17
- #encodeKey(key) {
18
- return JSON.stringify(key);
19
- }
20
- /**
21
- * {@inheritDoc KvStore.get}
22
- */
23
- get(key) {
24
- const encodedKey = this.#encodeKey(key);
25
- const entry = this.#values[encodedKey];
26
- if (entry == null) return Promise.resolve(void 0);
27
- const [value, expiration] = entry;
28
- if (expiration != null && Temporal.Now.instant().until(expiration).sign < 0) {
29
- delete this.#values[encodedKey];
30
- return Promise.resolve(void 0);
31
- }
32
- return Promise.resolve(value);
33
- }
34
- /**
35
- * {@inheritDoc KvStore.set}
36
- */
37
- set(key, value, options) {
38
- const encodedKey = this.#encodeKey(key);
39
- const expiration = options?.ttl == null ? null : Temporal.Now.instant().add(options.ttl.round({ largestUnit: "hour" }));
40
- this.#values[encodedKey] = [value, expiration];
41
- return Promise.resolve();
42
- }
43
- /**
44
- * {@inheritDoc KvStore.delete}
45
- */
46
- delete(key) {
47
- const encodedKey = this.#encodeKey(key);
48
- delete this.#values[encodedKey];
49
- return Promise.resolve();
50
- }
51
- /**
52
- * {@inheritDoc KvStore.cas}
53
- */
54
- cas(key, expectedValue, newValue, options) {
55
- const encodedKey = this.#encodeKey(key);
56
- const entry = this.#values[encodedKey];
57
- let currentValue;
58
- if (entry == null) currentValue = void 0;
59
- else {
60
- const [value, expiration$1] = entry;
61
- if (expiration$1 != null && Temporal.Now.instant().until(expiration$1).sign < 0) {
62
- delete this.#values[encodedKey];
63
- currentValue = void 0;
64
- } else currentValue = value;
65
- }
66
- if (!(0, es_toolkit.isEqual)(currentValue, expectedValue)) return Promise.resolve(false);
67
- const expiration = options?.ttl == null ? null : Temporal.Now.instant().add(options.ttl.round({ largestUnit: "hour" }));
68
- this.#values[encodedKey] = [newValue, expiration];
69
- return Promise.resolve(true);
70
- }
71
- /**
72
- * {@inheritDoc KvStore.list}
73
- */
74
- async *list(prefix) {
75
- const now = Temporal.Now.instant();
76
- for (const [encodedKey, entry] of Object.entries(this.#values)) {
77
- const key = JSON.parse(encodedKey);
78
- if (prefix != null) {
79
- if (key.length < prefix.length) continue;
80
- if (!prefix.every((p, i) => key[i] === p)) continue;
81
- }
82
- const [value, expiration] = entry;
83
- if (expiration != null && now.until(expiration).sign < 0) {
84
- delete this.#values[encodedKey];
85
- continue;
86
- }
87
- yield {
88
- key,
89
- value
90
- };
91
- }
92
- }
93
- };
94
-
95
- //#endregion
96
- //#region src/federation/mq.ts
97
- /**
98
- * A message queue that processes messages in the same process.
99
- * Do not use this in production as it does neither persist messages nor
100
- * distribute them across multiple processes.
101
- *
102
- * @since 0.5.0
103
- */
104
- var InProcessMessageQueue = class {
105
- #messages;
106
- #monitors;
107
- #pollIntervalMs;
108
- /**
109
- * Tracks which ordering keys are currently being processed to ensure
110
- * sequential processing for messages with the same key.
111
- */
112
- #processingKeys;
113
- /**
114
- * In-process message queue does not provide native retry mechanisms.
115
- * @since 1.7.0
116
- */
117
- nativeRetrial = false;
118
- /**
119
- * Constructs a new {@link InProcessMessageQueue} with the given options.
120
- * @param options Additional options for the in-process message queue.
121
- */
122
- constructor(options = {}) {
123
- this.#messages = [];
124
- this.#monitors = {};
125
- this.#pollIntervalMs = Temporal.Duration.from(options.pollInterval ?? { seconds: 5 }).total("millisecond");
126
- this.#processingKeys = /* @__PURE__ */ new Set();
127
- }
128
- enqueue(message, options) {
129
- const delay = options?.delay == null ? 0 : Math.max(options.delay.total("millisecond"), 0);
130
- if (delay > 0) {
131
- setTimeout(() => this.enqueue(message, {
132
- ...options,
133
- delay: void 0
134
- }), delay);
135
- return Promise.resolve();
136
- }
137
- const orderingKey = options?.orderingKey ?? null;
138
- this.#messages.push({
139
- message,
140
- orderingKey
141
- });
142
- for (const monitorId in this.#monitors) this.#monitors[monitorId]();
143
- return Promise.resolve();
144
- }
145
- enqueueMany(messages, options) {
146
- if (messages.length === 0) return Promise.resolve();
147
- const delay = options?.delay == null ? 0 : Math.max(options.delay.total("millisecond"), 0);
148
- if (delay > 0) {
149
- setTimeout(() => this.enqueueMany(messages, {
150
- ...options,
151
- delay: void 0
152
- }), delay);
153
- return Promise.resolve();
154
- }
155
- const orderingKey = options?.orderingKey ?? null;
156
- for (const message of messages) this.#messages.push({
157
- message,
158
- orderingKey
159
- });
160
- for (const monitorId in this.#monitors) this.#monitors[monitorId]();
161
- return Promise.resolve();
162
- }
163
- async listen(handler, options = {}) {
164
- const signal = options.signal;
165
- while (signal == null || !signal.aborted) {
166
- const idx = this.#messages.findIndex((m) => m.orderingKey == null || !this.#processingKeys.has(m.orderingKey));
167
- if (idx >= 0) {
168
- const queued = this.#messages.splice(idx, 1)[0];
169
- const { message, orderingKey } = queued;
170
- if (orderingKey != null) this.#processingKeys.add(orderingKey);
171
- try {
172
- await handler(message);
173
- } finally {
174
- if (orderingKey != null) this.#processingKeys.delete(orderingKey);
175
- }
176
- } else if (this.#messages.length === 0) await this.#wait(this.#pollIntervalMs, signal);
177
- else await this.#wait(10, signal);
178
- }
179
- }
180
- #wait(ms, signal) {
181
- let timer = null;
182
- return Promise.any([new Promise((resolve) => {
183
- signal?.addEventListener("abort", () => {
184
- if (timer != null) clearTimeout(timer);
185
- resolve();
186
- }, { once: true });
187
- const monitorId = crypto.randomUUID();
188
- this.#monitors[monitorId] = () => {
189
- delete this.#monitors[monitorId];
190
- if (timer != null) clearTimeout(timer);
191
- resolve();
192
- };
193
- }), new Promise((resolve) => timer = setTimeout(resolve, ms))]);
194
- }
195
- };
196
- /**
197
- * A message queue that processes messages in parallel. It takes another
198
- * {@link MessageQueue}, and processes messages in parallel up to a certain
199
- * number of workers.
200
- *
201
- * Actually, it's rather a decorator than a queue itself.
202
- *
203
- * Note that the workers do not run in truly parallel, in the sense that they
204
- * are not running in separate threads or processes. They are running in the
205
- * same process, but are scheduled to run in parallel. Hence, this is useful
206
- * for I/O-bound tasks, but not for CPU-bound tasks, which is okay for Fedify's
207
- * workloads.
208
- *
209
- * When using `ParallelMessageQueue`, the ordering guarantee is preserved
210
- * *only if* the underlying queue implementation delivers messages in a wrapper
211
- * format that includes the `__fedify_ordering_key__` property. Currently,
212
- * only `DenoKvMessageQueue` and `WorkersMessageQueue` use this format.
213
- * For other queue implementations (e.g., `InProcessMessageQueue`,
214
- * `RedisMessageQueue`, `PostgresMessageQueue`, `SqliteMessageQueue`,
215
- * `AmqpMessageQueue`), the ordering key cannot be detected by
216
- * `ParallelMessageQueue`, so ordering guarantees are handled by those
217
- * implementations directly rather than at the `ParallelMessageQueue` level.
218
- *
219
- * Messages with the same ordering key will never be processed concurrently
220
- * by different workers, ensuring sequential processing within each key.
221
- * Messages with different ordering keys (or no ordering key) can still be
222
- * processed in parallel.
223
- *
224
- * @since 1.0.0
225
- */
226
- var ParallelMessageQueue = class ParallelMessageQueue {
227
- queue;
228
- workers;
229
- /**
230
- * Inherits the native retry capability from the wrapped queue.
231
- * @since 1.7.0
232
- */
233
- nativeRetrial;
234
- /**
235
- * Tracks which ordering keys are currently being processed to ensure
236
- * sequential processing for messages with the same key.
237
- */
238
- #processingKeys = /* @__PURE__ */ new Set();
239
- /**
240
- * Pending messages waiting for their ordering key to become available.
241
- */
242
- #pendingMessages = [];
243
- /**
244
- * Constructs a new {@link ParallelMessageQueue} with the given queue and
245
- * number of workers.
246
- * @param queue The message queue to use under the hood. Note that
247
- * {@link ParallelMessageQueue} cannot be nested.
248
- * @param workers The number of workers to process messages in parallel.
249
- * @throws {TypeError} If the given queue is an instance of
250
- * {@link ParallelMessageQueue}.
251
- */
252
- constructor(queue, workers) {
253
- if (queue instanceof ParallelMessageQueue) throw new TypeError("Cannot nest ParallelMessageQueue.");
254
- this.queue = queue;
255
- this.workers = workers;
256
- this.nativeRetrial = queue.nativeRetrial;
257
- }
258
- enqueue(message, options) {
259
- return this.queue.enqueue(message, options);
260
- }
261
- async enqueueMany(messages, options) {
262
- if (this.queue.enqueueMany == null) {
263
- const results = await Promise.allSettled(messages.map((message) => this.queue.enqueue(message, options)));
264
- const errors = results.filter((r) => r.status === "rejected").map((r) => r.reason);
265
- if (errors.length > 1) throw new AggregateError(errors, "Failed to enqueue messages.");
266
- else if (errors.length === 1) throw errors[0];
267
- return;
268
- }
269
- await this.queue.enqueueMany(messages, options);
270
- }
271
- /**
272
- * Extracts ordering key from a message if present.
273
- *
274
- * This method only works for queue implementations that deliver messages
275
- * in the wrapper format with `__fedify_ordering_key__` property. Currently,
276
- * only `DenoKvMessageQueue` and `WorkersMessageQueue` use this format.
277
- *
278
- * For other queue implementations (`InProcessMessageQueue`,
279
- * `RedisMessageQueue`, `PostgresMessageQueue`, `SqliteMessageQueue`,
280
- * `AmqpMessageQueue`), messages are delivered as raw payloads without the
281
- * wrapper, so the ordering key cannot be detected here. Those
282
- * implementations handle ordering guarantees internally.
283
- */
284
- #extractOrderingKey(message) {
285
- if (message != null && typeof message === "object") {
286
- if ("__fedify_ordering_key__" in message) return message.__fedify_ordering_key__;
287
- }
288
- return void 0;
289
- }
290
- listen(handler, options = {}) {
291
- const workers = /* @__PURE__ */ new Map();
292
- return this.queue.listen(async (message) => {
293
- while (workers.size >= this.workers) {
294
- const consumedId = await Promise.any(workers.values());
295
- workers.delete(consumedId);
296
- }
297
- const workerId = crypto.randomUUID();
298
- const orderingKey = this.#extractOrderingKey(message);
299
- if (orderingKey != null && this.#processingKeys.has(orderingKey)) await new Promise((resolve) => {
300
- this.#pendingMessages.push({
301
- message,
302
- orderingKey,
303
- resolve
304
- });
305
- });
306
- if (orderingKey != null) this.#processingKeys.add(orderingKey);
307
- const promise = this.#work(workerId, handler, message, orderingKey);
308
- workers.set(workerId, promise);
309
- }, options);
310
- }
311
- async #work(workerId, handler, message, orderingKey) {
312
- await this.#sleep(0);
313
- try {
314
- await handler(message);
315
- } finally {
316
- if (orderingKey != null) {
317
- this.#processingKeys.delete(orderingKey);
318
- const pendingIdx = this.#pendingMessages.findIndex((p) => p.orderingKey === orderingKey);
319
- if (pendingIdx >= 0) {
320
- const pending = this.#pendingMessages.splice(pendingIdx, 1)[0];
321
- pending.resolve();
322
- }
323
- }
324
- }
325
- return workerId;
326
- }
327
- #sleep(ms) {
328
- return new Promise((resolve) => setTimeout(resolve, ms));
329
- }
330
- };
331
-
332
- //#endregion
333
- Object.defineProperty(exports, 'InProcessMessageQueue', {
334
- enumerable: true,
335
- get: function () {
336
- return InProcessMessageQueue;
337
- }
338
- });
339
- Object.defineProperty(exports, 'MemoryKvStore', {
340
- enumerable: true,
341
- get: function () {
342
- return MemoryKvStore;
343
- }
344
- });
345
- Object.defineProperty(exports, 'ParallelMessageQueue', {
346
- enumerable: true,
347
- get: function () {
348
- return ParallelMessageQueue;
349
- }
350
- });
@@ -1,332 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
5
- import { isEqual } from "es-toolkit";
6
-
7
- //#region src/federation/kv.ts
8
- /**
9
- * A key–value store that stores values in memory.
10
- * Do not use this in production as it does not persist values.
11
- *
12
- * @since 0.5.0
13
- */
14
- var MemoryKvStore = class {
15
- #values = {};
16
- #encodeKey(key) {
17
- return JSON.stringify(key);
18
- }
19
- /**
20
- * {@inheritDoc KvStore.get}
21
- */
22
- get(key) {
23
- const encodedKey = this.#encodeKey(key);
24
- const entry = this.#values[encodedKey];
25
- if (entry == null) return Promise.resolve(void 0);
26
- const [value, expiration] = entry;
27
- if (expiration != null && Temporal.Now.instant().until(expiration).sign < 0) {
28
- delete this.#values[encodedKey];
29
- return Promise.resolve(void 0);
30
- }
31
- return Promise.resolve(value);
32
- }
33
- /**
34
- * {@inheritDoc KvStore.set}
35
- */
36
- set(key, value, options) {
37
- const encodedKey = this.#encodeKey(key);
38
- const expiration = options?.ttl == null ? null : Temporal.Now.instant().add(options.ttl.round({ largestUnit: "hour" }));
39
- this.#values[encodedKey] = [value, expiration];
40
- return Promise.resolve();
41
- }
42
- /**
43
- * {@inheritDoc KvStore.delete}
44
- */
45
- delete(key) {
46
- const encodedKey = this.#encodeKey(key);
47
- delete this.#values[encodedKey];
48
- return Promise.resolve();
49
- }
50
- /**
51
- * {@inheritDoc KvStore.cas}
52
- */
53
- cas(key, expectedValue, newValue, options) {
54
- const encodedKey = this.#encodeKey(key);
55
- const entry = this.#values[encodedKey];
56
- let currentValue;
57
- if (entry == null) currentValue = void 0;
58
- else {
59
- const [value, expiration$1] = entry;
60
- if (expiration$1 != null && Temporal.Now.instant().until(expiration$1).sign < 0) {
61
- delete this.#values[encodedKey];
62
- currentValue = void 0;
63
- } else currentValue = value;
64
- }
65
- if (!isEqual(currentValue, expectedValue)) return Promise.resolve(false);
66
- const expiration = options?.ttl == null ? null : Temporal.Now.instant().add(options.ttl.round({ largestUnit: "hour" }));
67
- this.#values[encodedKey] = [newValue, expiration];
68
- return Promise.resolve(true);
69
- }
70
- /**
71
- * {@inheritDoc KvStore.list}
72
- */
73
- async *list(prefix) {
74
- const now = Temporal.Now.instant();
75
- for (const [encodedKey, entry] of Object.entries(this.#values)) {
76
- const key = JSON.parse(encodedKey);
77
- if (prefix != null) {
78
- if (key.length < prefix.length) continue;
79
- if (!prefix.every((p, i) => key[i] === p)) continue;
80
- }
81
- const [value, expiration] = entry;
82
- if (expiration != null && now.until(expiration).sign < 0) {
83
- delete this.#values[encodedKey];
84
- continue;
85
- }
86
- yield {
87
- key,
88
- value
89
- };
90
- }
91
- }
92
- };
93
-
94
- //#endregion
95
- //#region src/federation/mq.ts
96
- /**
97
- * A message queue that processes messages in the same process.
98
- * Do not use this in production as it does neither persist messages nor
99
- * distribute them across multiple processes.
100
- *
101
- * @since 0.5.0
102
- */
103
- var InProcessMessageQueue = class {
104
- #messages;
105
- #monitors;
106
- #pollIntervalMs;
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
- * Constructs a new {@link InProcessMessageQueue} with the given options.
119
- * @param options Additional options for the in-process message queue.
120
- */
121
- constructor(options = {}) {
122
- this.#messages = [];
123
- this.#monitors = {};
124
- this.#pollIntervalMs = Temporal.Duration.from(options.pollInterval ?? { seconds: 5 }).total("millisecond");
125
- this.#processingKeys = /* @__PURE__ */ new Set();
126
- }
127
- enqueue(message, options) {
128
- const delay = options?.delay == null ? 0 : Math.max(options.delay.total("millisecond"), 0);
129
- if (delay > 0) {
130
- setTimeout(() => this.enqueue(message, {
131
- ...options,
132
- delay: void 0
133
- }), delay);
134
- return Promise.resolve();
135
- }
136
- const orderingKey = options?.orderingKey ?? null;
137
- this.#messages.push({
138
- message,
139
- orderingKey
140
- });
141
- for (const monitorId in this.#monitors) this.#monitors[monitorId]();
142
- return Promise.resolve();
143
- }
144
- enqueueMany(messages, options) {
145
- if (messages.length === 0) return Promise.resolve();
146
- const delay = options?.delay == null ? 0 : Math.max(options.delay.total("millisecond"), 0);
147
- if (delay > 0) {
148
- setTimeout(() => this.enqueueMany(messages, {
149
- ...options,
150
- delay: void 0
151
- }), delay);
152
- return Promise.resolve();
153
- }
154
- const orderingKey = options?.orderingKey ?? null;
155
- for (const message of messages) this.#messages.push({
156
- message,
157
- orderingKey
158
- });
159
- for (const monitorId in this.#monitors) this.#monitors[monitorId]();
160
- return Promise.resolve();
161
- }
162
- async listen(handler, options = {}) {
163
- const signal = options.signal;
164
- while (signal == null || !signal.aborted) {
165
- const idx = this.#messages.findIndex((m) => m.orderingKey == null || !this.#processingKeys.has(m.orderingKey));
166
- if (idx >= 0) {
167
- const queued = this.#messages.splice(idx, 1)[0];
168
- const { message, orderingKey } = queued;
169
- if (orderingKey != null) this.#processingKeys.add(orderingKey);
170
- try {
171
- await handler(message);
172
- } finally {
173
- if (orderingKey != null) this.#processingKeys.delete(orderingKey);
174
- }
175
- } else if (this.#messages.length === 0) await this.#wait(this.#pollIntervalMs, signal);
176
- else await this.#wait(10, signal);
177
- }
178
- }
179
- #wait(ms, signal) {
180
- let timer = null;
181
- return Promise.any([new Promise((resolve) => {
182
- signal?.addEventListener("abort", () => {
183
- if (timer != null) clearTimeout(timer);
184
- resolve();
185
- }, { once: true });
186
- const monitorId = crypto.randomUUID();
187
- this.#monitors[monitorId] = () => {
188
- delete this.#monitors[monitorId];
189
- if (timer != null) clearTimeout(timer);
190
- resolve();
191
- };
192
- }), new Promise((resolve) => timer = setTimeout(resolve, ms))]);
193
- }
194
- };
195
- /**
196
- * A message queue that processes messages in parallel. It takes another
197
- * {@link MessageQueue}, and processes messages in parallel up to a certain
198
- * number of workers.
199
- *
200
- * Actually, it's rather a decorator than a queue itself.
201
- *
202
- * Note that the workers do not run in truly parallel, in the sense that they
203
- * are not running in separate threads or processes. They are running in the
204
- * same process, but are scheduled to run in parallel. Hence, this is useful
205
- * for I/O-bound tasks, but not for CPU-bound tasks, which is okay for Fedify's
206
- * workloads.
207
- *
208
- * When using `ParallelMessageQueue`, the ordering guarantee is preserved
209
- * *only if* the underlying queue implementation delivers messages in a wrapper
210
- * format that includes the `__fedify_ordering_key__` property. Currently,
211
- * only `DenoKvMessageQueue` and `WorkersMessageQueue` use this format.
212
- * For other queue implementations (e.g., `InProcessMessageQueue`,
213
- * `RedisMessageQueue`, `PostgresMessageQueue`, `SqliteMessageQueue`,
214
- * `AmqpMessageQueue`), the ordering key cannot be detected by
215
- * `ParallelMessageQueue`, so ordering guarantees are handled by those
216
- * implementations directly rather than at the `ParallelMessageQueue` level.
217
- *
218
- * Messages with the same ordering key will never be processed concurrently
219
- * by different workers, ensuring sequential processing within each key.
220
- * Messages with different ordering keys (or no ordering key) can still be
221
- * processed in parallel.
222
- *
223
- * @since 1.0.0
224
- */
225
- var ParallelMessageQueue = class ParallelMessageQueue {
226
- queue;
227
- workers;
228
- /**
229
- * Inherits the native retry capability from the wrapped queue.
230
- * @since 1.7.0
231
- */
232
- nativeRetrial;
233
- /**
234
- * Tracks which ordering keys are currently being processed to ensure
235
- * sequential processing for messages with the same key.
236
- */
237
- #processingKeys = /* @__PURE__ */ new Set();
238
- /**
239
- * Pending messages waiting for their ordering key to become available.
240
- */
241
- #pendingMessages = [];
242
- /**
243
- * Constructs a new {@link ParallelMessageQueue} with the given queue and
244
- * number of workers.
245
- * @param queue The message queue to use under the hood. Note that
246
- * {@link ParallelMessageQueue} cannot be nested.
247
- * @param workers The number of workers to process messages in parallel.
248
- * @throws {TypeError} If the given queue is an instance of
249
- * {@link ParallelMessageQueue}.
250
- */
251
- constructor(queue, workers) {
252
- if (queue instanceof ParallelMessageQueue) throw new TypeError("Cannot nest ParallelMessageQueue.");
253
- this.queue = queue;
254
- this.workers = workers;
255
- this.nativeRetrial = queue.nativeRetrial;
256
- }
257
- enqueue(message, options) {
258
- return this.queue.enqueue(message, options);
259
- }
260
- async enqueueMany(messages, options) {
261
- if (this.queue.enqueueMany == null) {
262
- const results = await Promise.allSettled(messages.map((message) => this.queue.enqueue(message, options)));
263
- const errors = results.filter((r) => r.status === "rejected").map((r) => r.reason);
264
- if (errors.length > 1) throw new AggregateError(errors, "Failed to enqueue messages.");
265
- else if (errors.length === 1) throw errors[0];
266
- return;
267
- }
268
- await this.queue.enqueueMany(messages, options);
269
- }
270
- /**
271
- * Extracts ordering key from a message if present.
272
- *
273
- * This method only works for queue implementations that deliver messages
274
- * in the wrapper format with `__fedify_ordering_key__` property. Currently,
275
- * only `DenoKvMessageQueue` and `WorkersMessageQueue` use this format.
276
- *
277
- * For other queue implementations (`InProcessMessageQueue`,
278
- * `RedisMessageQueue`, `PostgresMessageQueue`, `SqliteMessageQueue`,
279
- * `AmqpMessageQueue`), messages are delivered as raw payloads without the
280
- * wrapper, so the ordering key cannot be detected here. Those
281
- * implementations handle ordering guarantees internally.
282
- */
283
- #extractOrderingKey(message) {
284
- if (message != null && typeof message === "object") {
285
- if ("__fedify_ordering_key__" in message) return message.__fedify_ordering_key__;
286
- }
287
- return void 0;
288
- }
289
- listen(handler, options = {}) {
290
- const workers = /* @__PURE__ */ new Map();
291
- return this.queue.listen(async (message) => {
292
- while (workers.size >= this.workers) {
293
- const consumedId = await Promise.any(workers.values());
294
- workers.delete(consumedId);
295
- }
296
- const workerId = crypto.randomUUID();
297
- const orderingKey = this.#extractOrderingKey(message);
298
- if (orderingKey != null && this.#processingKeys.has(orderingKey)) await new Promise((resolve) => {
299
- this.#pendingMessages.push({
300
- message,
301
- orderingKey,
302
- resolve
303
- });
304
- });
305
- if (orderingKey != null) this.#processingKeys.add(orderingKey);
306
- const promise = this.#work(workerId, handler, message, orderingKey);
307
- workers.set(workerId, promise);
308
- }, options);
309
- }
310
- async #work(workerId, handler, message, orderingKey) {
311
- await this.#sleep(0);
312
- try {
313
- await handler(message);
314
- } finally {
315
- if (orderingKey != null) {
316
- this.#processingKeys.delete(orderingKey);
317
- const pendingIdx = this.#pendingMessages.findIndex((p) => p.orderingKey === orderingKey);
318
- if (pendingIdx >= 0) {
319
- const pending = this.#pendingMessages.splice(pendingIdx, 1)[0];
320
- pending.resolve();
321
- }
322
- }
323
- }
324
- return workerId;
325
- }
326
- #sleep(ms) {
327
- return new Promise((resolve) => setTimeout(resolve, ms));
328
- }
329
- };
330
-
331
- //#endregion
332
- export { InProcessMessageQueue, MemoryKvStore, ParallelMessageQueue };
@@ -1,27 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
-
6
- import "./deno-DH972JvX.js";
7
- import { ContextImpl, FederationImpl, InboxContextImpl, KvSpecDeterminer, createFederation } from "./middleware-BHJ0xm0L.js";
8
- import "./client-CoCIaTNO.js";
9
- import "./router-D9eI0s4b.js";
10
- import "./types-CPz01LGH.js";
11
- import "./accept-D7sAxyNa.js";
12
- import "./key-CypuWa94.js";
13
- import "./http-DFzT4YFG.js";
14
- import "./ld-CXLtTc0G.js";
15
- import "./owner-CwMai3jn.js";
16
- import "./proof-ZuJBOUoi.js";
17
- import "./docloader-Ck0SCLXX.js";
18
- import "./kv-cache-Bw2F2ABq.js";
19
- import "./inbox-BMLz_-pL.js";
20
- import "./builder-DbKYZdSy.js";
21
- import "./collection-CSzG2j1P.js";
22
- import "./keycache-CpGWAUbj.js";
23
- import "./negotiation-BlAuS_nr.js";
24
- import "./retry-mqLf4b-R.js";
25
- import "./send-BW73dy6Q.js";
26
-
27
- export { FederationImpl };