@fedify/fedify 2.4.0-dev.1488 → 2.4.0-dev.1504
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 +3 -4
- package/dist/{assert-OguE97r2.mjs → assert-DvVHoIZ0.mjs} +1 -1
- package/dist/{assert_instance_of-DBC5X09g.mjs → assert_instance_of-CxoC8bVq.mjs} +1 -1
- package/dist/{assert_not_equals-DkVK8oqV.mjs → assert_not_equals-C8vcTTA3.mjs} +1 -1
- package/dist/{assert_rejects-DN60FHPX.mjs → assert_rejects-DAdaaIWM.mjs} +2 -2
- package/dist/{assert_strict_equals-XEgZAlrj.mjs → assert_strict_equals-BzqyKuYL.mjs} +1 -1
- package/dist/{assert_throws-BOkhLGYc.mjs → assert_throws-zN79lgIC.mjs} +1 -1
- package/dist/{builder-Dcr6y6XD.mjs → builder-Ck0Fl_a5.mjs} +23 -3
- package/dist/codec-CmlPqjNX.mjs +103 -0
- 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-DVoTs_wM.mjs → context-BBRTgkrs.mjs} +8 -2
- package/dist/{context-BU6jSQdo.d.ts → context-BF5B4ZDk.d.ts} +529 -259
- package/dist/{context-BBVLF7lx.d.cts → context-CYF8X0ft.d.cts} +530 -259
- package/dist/{deno-BCFGf8NR.mjs → deno-D3gb4X9v.mjs} +1 -1
- package/dist/{docloader-DWEwaGqF.mjs → docloader-DUKu0GzG.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 +200 -19
- package/dist/federation/mod.cjs +3 -259
- package/dist/federation/mod.d.cts +4 -4
- package/dist/federation/mod.d.ts +4 -4
- package/dist/federation/mod.js +1 -257
- package/dist/federation/mq.test.mjs +103 -261
- 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/tasks/codec.test.d.mts +2 -0
- package/dist/federation/tasks/codec.test.mjs +292 -0
- package/dist/federation/tasks/enqueue.test.d.mts +2 -0
- package/dist/federation/tasks/enqueue.test.mjs +992 -0
- package/dist/federation/tasks/tasks.test.d.mts +2 -0
- package/dist/federation/tasks/tasks.test.mjs +555 -0
- package/dist/federation/temporal.test.mjs +4 -4
- package/dist/federation/webfinger.test.mjs +6 -6
- package/dist/{http-RriziGDE.mjs → http-BNFQkiEZ.mjs} +4 -4
- package/dist/{http-DaVoLyyA.js → http-CrZzUAtV.js} +7 -17
- package/dist/{http-DLqxhQg1.cjs → http-D9p2_d2X.cjs} +7 -17
- package/dist/{key-Bkg8Zg36.mjs → key-BM_SRwBV.mjs} +8 -18
- package/dist/{kv-cache-BR--9V4L.mjs → kv-cache-BE1QIPdL.mjs} +1 -1
- package/dist/{kv-cache-DxlFLMiU.js → kv-cache-Ch_Zv5Yq.js} +1 -1
- package/dist/{kv-cache-Fw-iwKjy.cjs → kv-cache-Cna211RR.cjs} +1 -1
- package/dist/{ld-BjsmbqO7.mjs → ld-ubkf03eb.mjs} +3 -3
- package/dist/{metrics-BLoa2pab.mjs → metrics-BXR36qzu.mjs} +1 -1
- package/dist/{middleware-V-r1QH5Z.cjs → middleware-DUNeIkXN.cjs} +694 -51
- package/dist/{middleware-D3kuDjvb.mjs → middleware-iP9VRMus.mjs} +310 -67
- package/dist/{middleware-_9t5HVBi.js → middleware-lB4vtShP.js} +683 -52
- package/dist/{middleware-DNR3YBCi.mjs → middleware-pzCP79He.mjs} +1 -1
- package/dist/{mod-vPYVoa5n.d.ts → mod-4WGAuR6X.d.ts} +1 -1
- package/dist/{mod-C0F6kvgS.d.cts → mod-BHEB3xhE.d.cts} +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-03vS-C9P.mjs +276 -0
- package/dist/{mq-D8uSFzxe.d.cts → mq-B5_hohs7.d.ts} +34 -0
- package/dist/{mq-D-nlpY04.d.ts → mq-DXMt_qCY.d.cts} +34 -0
- 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-L_DbOaFe.mjs → outgoing-jsonld-BNL8AC14.mjs} +1 -1
- package/dist/{owner-NK2p1ihR.mjs → owner-Bf1KkncT.mjs} +2 -2
- package/dist/{proof-D7WVwQzs.js → proof-BMcsi8q_.js} +1 -1
- package/dist/{proof-CRXqo703.mjs → proof-Q781Ks5q.mjs} +5 -5
- package/dist/{proof-2WI6mMbC.cjs → proof-yeAU1MyT.cjs} +1 -1
- package/dist/{send-CTaPzl8L.mjs → send-DFV0S_n9.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 -56
- 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-BBjXFNOb.mjs → std__assert-Dh6uLf_q.mjs} +4 -4
- package/dist/{temporal-C8M0Y7v9.mjs → temporal-CyOjsqPj.mjs} +1 -1
- package/dist/testing/mod.d.mts +1037 -8
- package/dist/testing/mod.mjs +3 -2
- package/dist/testing-Dy-WhqpN.mjs +77 -0
- 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 +13 -8
- /package/dist/{accept-CPkZzmGN.mjs → accept-CgDcxvjV.mjs} +0 -0
- /package/dist/{activity-listener-tztVvlNb.mjs → activity-listener-BeTGV3wc.mjs} +0 -0
- /package/dist/{assert_equals-C-ZRDbaf.mjs → assert_equals-PBVKNMJd.mjs} +0 -0
- /package/dist/{circuit-breaker-CSWsyoef.mjs → circuit-breaker-hJBB6jwA.mjs} +0 -0
- /package/dist/{client-ByXmQhYD.mjs → client-B_A6mfn3.mjs} +0 -0
- /package/dist/{collection-Cc3DVAhE.mjs → collection-Dp5ky45w.mjs} +0 -0
- /package/dist/{keycache-BeU0LCII.mjs → keycache-CaOR6NYg.mjs} +0 -0
- /package/dist/{keys-DGu1NFwu.mjs → keys-CSYsOMFG.mjs} +0 -0
- /package/dist/{kv-rV3vodCc.mjs → kv-CIvR3Non.mjs} +0 -0
- /package/dist/{negotiation-DDstyBvc.mjs → negotiation-m_L2nyS3.mjs} +0 -0
- /package/dist/{public-audience-Cvbr2Gzt.mjs → public-audience-c9zmYKgA.mjs} +0 -0
- /package/dist/{retry-CXg_MBI-.mjs → retry-DI4O-zYl.mjs} +0 -0
- /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
|
@@ -3,11 +3,13 @@ import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client
|
|
|
3
3
|
import { o as VerifyRequestFailureReason, t as HttpMessageSignaturesSpec } from "./http-VyDTd4G3.cjs";
|
|
4
4
|
import { n as GetKeyOwnerOptions } from "./owner-DEvZuyOE.cjs";
|
|
5
5
|
import { n as KvStore, t as KvKey } from "./kv-gJ8LYbxX.cjs";
|
|
6
|
-
import { r as MessageQueue } from "./mq-
|
|
6
|
+
import { r as MessageQueue } from "./mq-DXMt_qCY.cjs";
|
|
7
7
|
import { Activity, Actor, Collection, CryptographicKey, Hashtag, Link, LookupObjectOptions, Multikey, Object as Object$1, Recipient, Tombstone, TraverseCollectionOptions } from "@fedify/vocab";
|
|
8
8
|
import { AuthenticatedDocumentLoaderFactory, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions } from "@fedify/vocab-runtime";
|
|
9
9
|
import { Link as Link$1, LookupWebFingerOptions, ResourceDescriptor } from "@fedify/webfinger";
|
|
10
10
|
import { MeterProvider, Span, Tracer, TracerProvider } from "@opentelemetry/api";
|
|
11
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
12
|
+
|
|
11
13
|
//#region src/compat/types.d.ts
|
|
12
14
|
/**
|
|
13
15
|
* A function that transforms an activity object.
|
|
@@ -15,177 +17,6 @@ import { MeterProvider, Span, Tracer, TracerProvider } from "@opentelemetry/api"
|
|
|
15
17
|
*/
|
|
16
18
|
type ActivityTransformer<TContextData> = (activity: Activity, context: Context<TContextData>) => Activity;
|
|
17
19
|
//#endregion
|
|
18
|
-
//#region src/federation/circuit-breaker.d.ts
|
|
19
|
-
/**
|
|
20
|
-
* The state of a remote host circuit breaker.
|
|
21
|
-
* @since 2.3.0
|
|
22
|
-
*/
|
|
23
|
-
type CircuitBreakerState = "closed" | "open" | "half-open";
|
|
24
|
-
/**
|
|
25
|
-
* The JSON-serializable state stored in the configured {@link KvStore}.
|
|
26
|
-
* @since 2.3.0
|
|
27
|
-
*/
|
|
28
|
-
interface CircuitBreakerKvState {
|
|
29
|
-
readonly state: CircuitBreakerState;
|
|
30
|
-
readonly failures: readonly string[];
|
|
31
|
-
readonly opened?: string;
|
|
32
|
-
readonly halfOpened?: string;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Details passed to {@link CircuitBreakerOptions.onActivityDrop} when a held
|
|
36
|
-
* activity expires before the remote host recovers.
|
|
37
|
-
* @since 2.3.0
|
|
38
|
-
*/
|
|
39
|
-
interface CircuitBreakerActivityDrop {
|
|
40
|
-
/** The inbox URL that would have received the activity. */
|
|
41
|
-
readonly inbox: URL;
|
|
42
|
-
/** The activity that was dropped. */
|
|
43
|
-
readonly activity: Activity;
|
|
44
|
-
/** The activity ID, when known. */
|
|
45
|
-
readonly activityId?: string;
|
|
46
|
-
/** The activity type. */
|
|
47
|
-
readonly activityType: string;
|
|
48
|
-
/** The actor IDs represented by this inbox. */
|
|
49
|
-
readonly actorIds: readonly URL[];
|
|
50
|
-
/** The time when Fedify first held this activity. */
|
|
51
|
-
readonly heldSince: Temporal.Instant;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Configures how a remote host circuit opens after repeated delivery
|
|
55
|
-
* failures.
|
|
56
|
-
* @since 2.3.0
|
|
57
|
-
*/
|
|
58
|
-
type CircuitBreakerFailurePolicy = {
|
|
59
|
-
failure(timestamps: readonly Temporal.Instant[]): boolean;
|
|
60
|
-
readonly failureThreshold?: never;
|
|
61
|
-
readonly failureWindow?: never;
|
|
62
|
-
} | {
|
|
63
|
-
readonly failure?: never;
|
|
64
|
-
readonly failureThreshold?: number;
|
|
65
|
-
readonly failureWindow?: Temporal.Duration | Temporal.DurationLike;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Options for Fedify's outbound activity circuit breaker.
|
|
69
|
-
* @since 2.3.0
|
|
70
|
-
*/
|
|
71
|
-
type CircuitBreakerOptions = CircuitBreakerFailurePolicy & {
|
|
72
|
-
/**
|
|
73
|
-
* How long an open circuit waits before allowing a half-open recovery probe.
|
|
74
|
-
* @default `{ minutes: 30 }`
|
|
75
|
-
*/
|
|
76
|
-
readonly recoveryDelay?: Temporal.Duration | Temporal.DurationLike;
|
|
77
|
-
/**
|
|
78
|
-
* How long Fedify keeps requeueing activities held by an open circuit before
|
|
79
|
-
* dropping them.
|
|
80
|
-
* @default `{ days: 7 }`
|
|
81
|
-
*/
|
|
82
|
-
readonly heldActivityTtl?: Temporal.Duration | Temporal.DurationLike;
|
|
83
|
-
/**
|
|
84
|
-
* How often other held activities retry while a half-open probe is in
|
|
85
|
-
* flight. The probe is treated as stale after the recovery delay.
|
|
86
|
-
* @default `{ seconds: 1 }`
|
|
87
|
-
*/
|
|
88
|
-
readonly releaseInterval?: Temporal.Duration | Temporal.DurationLike;
|
|
89
|
-
/**
|
|
90
|
-
* Called whenever the circuit state changes.
|
|
91
|
-
*/
|
|
92
|
-
readonly onStateChange?: (remoteHost: string, previousState: CircuitBreakerState, newState: CircuitBreakerState) => void | Promise<void>;
|
|
93
|
-
/**
|
|
94
|
-
* Called when an activity held by the circuit breaker expires.
|
|
95
|
-
*/
|
|
96
|
-
readonly onActivityDrop?: (remoteHost: string, details: CircuitBreakerActivityDrop) => void | Promise<void>;
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Normalized circuit breaker options used internally by Fedify.
|
|
100
|
-
* @internal
|
|
101
|
-
*/
|
|
102
|
-
interface NormalizedCircuitBreakerOptions {
|
|
103
|
-
readonly failure: (timestamps: readonly Temporal.Instant[]) => boolean;
|
|
104
|
-
readonly pruneFailures: (timestamps: readonly Temporal.Instant[], now: Temporal.Instant) => readonly Temporal.Instant[];
|
|
105
|
-
readonly recoveryDelay: Temporal.Duration;
|
|
106
|
-
readonly heldActivityTtl: Temporal.Duration;
|
|
107
|
-
readonly releaseInterval: Temporal.Duration;
|
|
108
|
-
readonly onStateChange?: CircuitBreakerOptions["onStateChange"];
|
|
109
|
-
readonly onActivityDrop?: CircuitBreakerOptions["onActivityDrop"];
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Constructor options for {@link CircuitBreaker}.
|
|
113
|
-
* @internal
|
|
114
|
-
*/
|
|
115
|
-
interface CircuitBreakerCreateOptions {
|
|
116
|
-
readonly kv: KvStore;
|
|
117
|
-
readonly prefix: KvKey;
|
|
118
|
-
readonly options?: CircuitBreakerOptions;
|
|
119
|
-
readonly now?: () => Temporal.Instant;
|
|
120
|
-
/**
|
|
121
|
-
* Observes state changes after user callbacks have run.
|
|
122
|
-
* @internal
|
|
123
|
-
*/
|
|
124
|
-
readonly stateChangeObserver?: (remoteHost: string, previousState: CircuitBreakerState, newState: CircuitBreakerState) => void | Promise<void>;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* The delivery decision returned by {@link CircuitBreaker.beforeSend}.
|
|
128
|
-
* @internal
|
|
129
|
-
*/
|
|
130
|
-
type CircuitBreakerBeforeSendDecision = {
|
|
131
|
-
readonly type: "send";
|
|
132
|
-
readonly probe: boolean;
|
|
133
|
-
readonly stateChange?: CircuitBreakerStateChange;
|
|
134
|
-
} | {
|
|
135
|
-
readonly type: "hold";
|
|
136
|
-
readonly state: "open" | "half-open";
|
|
137
|
-
readonly delay: Temporal.Duration;
|
|
138
|
-
readonly heldSince: Temporal.Instant;
|
|
139
|
-
} | {
|
|
140
|
-
readonly type: "drop";
|
|
141
|
-
readonly heldSince: Temporal.Instant;
|
|
142
|
-
};
|
|
143
|
-
/**
|
|
144
|
-
* A circuit breaker state transition.
|
|
145
|
-
* @since 2.3.0
|
|
146
|
-
*/
|
|
147
|
-
interface CircuitBreakerStateChange {
|
|
148
|
-
readonly previousState: CircuitBreakerState;
|
|
149
|
-
readonly newState: CircuitBreakerState;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Tracks reachability state for remote outbox delivery hosts.
|
|
153
|
-
* @since 2.3.0
|
|
154
|
-
*/
|
|
155
|
-
declare class CircuitBreaker {
|
|
156
|
-
#private;
|
|
157
|
-
constructor(options: CircuitBreakerCreateOptions);
|
|
158
|
-
get options(): NormalizedCircuitBreakerOptions;
|
|
159
|
-
capHeldDelay(heldSince: Temporal.Instant, delay: Temporal.Duration): Temporal.Duration;
|
|
160
|
-
beforeSend(remoteHost: string, message: {
|
|
161
|
-
readonly circuitHeldSince?: string;
|
|
162
|
-
}): Promise<CircuitBreakerBeforeSendDecision>;
|
|
163
|
-
recordSuccess(remoteHost: string): Promise<CircuitBreakerStateChange | undefined>;
|
|
164
|
-
recordReachableFailure(remoteHost: string): Promise<CircuitBreakerStateChange | undefined>;
|
|
165
|
-
recordFailure(remoteHost: string): Promise<CircuitBreakerStateChange | undefined>;
|
|
166
|
-
dropActivity(remoteHost: string, details: CircuitBreakerActivityDrop): Promise<void>;
|
|
167
|
-
getState(remoteHost: string): Promise<CircuitBreakerKvState | undefined>;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Normalizes user-provided circuit breaker options into the internal policy
|
|
171
|
-
* shape used while processing queued outbox deliveries.
|
|
172
|
-
*
|
|
173
|
-
* @param options The public circuit breaker options supplied to Fedify.
|
|
174
|
-
* @returns The normalized failure predicate, failure pruning function,
|
|
175
|
-
* duration values, and optional callbacks with defaults applied.
|
|
176
|
-
* @throws {RangeError} If any configured duration is not positive.
|
|
177
|
-
* @throws {TypeError} If `failureThreshold` is not a positive integer.
|
|
178
|
-
*/
|
|
179
|
-
declare function normalizeCircuitBreakerOptions(options: CircuitBreakerOptions): NormalizedCircuitBreakerOptions;
|
|
180
|
-
/**
|
|
181
|
-
* Parses a value loaded from the circuit breaker KV store.
|
|
182
|
-
*
|
|
183
|
-
* @param value The raw KV value to validate.
|
|
184
|
-
* @returns A circuit breaker state when `value` has a recognized state and
|
|
185
|
-
* valid instant strings, or `undefined` when the stored value is malformed.
|
|
186
|
-
*/
|
|
187
|
-
declare function parseCircuitBreakerKvState(value: unknown): CircuitBreakerKvState | undefined;
|
|
188
|
-
//#endregion
|
|
189
20
|
//#region src/federation/collection.d.ts
|
|
190
21
|
/**
|
|
191
22
|
* A page of items.
|
|
@@ -552,28 +383,199 @@ type ObjectAuthorizePredicate<TContextData, TParam extends string> = (context: R
|
|
|
552
383
|
*/
|
|
553
384
|
type CustomCollectionDispatcher<TItem, TParam extends string, TContext extends Context<TContextData>, TContextData> = (context: TContext, values: Record<TParam, string>, cursor: string | null) => PageItems<TItem> | null | Promise<PageItems<TItem> | null>;
|
|
554
385
|
/**
|
|
555
|
-
* A callback that counts the number of items in a custom collection.
|
|
386
|
+
* A callback that counts the number of items in a custom collection.
|
|
387
|
+
*
|
|
388
|
+
* @template TParams The parameter names of the requested URL.
|
|
389
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
|
390
|
+
* @param context The context.
|
|
391
|
+
* @param values The parameters of the requested URL.
|
|
392
|
+
* @since 1.8.0
|
|
393
|
+
*/
|
|
394
|
+
type CustomCollectionCounter<TParam extends string, TContextData> = (context: RequestContext<TContextData>, values: Record<TParam, string>) => number | bigint | null | Promise<number | bigint | null>;
|
|
395
|
+
/**
|
|
396
|
+
* A callback that returns a cursor for a custom collection.
|
|
397
|
+
*
|
|
398
|
+
* @template TParams The parameter names of the requested URL.
|
|
399
|
+
* @template TContext The type of the context. {@link Context} or
|
|
400
|
+
* {@link RequestContext}.
|
|
401
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
|
402
|
+
* @template TFilter The type of the filter, if any.
|
|
403
|
+
* @param context The context.
|
|
404
|
+
* @param values The parameters of the requested URL.
|
|
405
|
+
* @since 1.8.0
|
|
406
|
+
*/
|
|
407
|
+
type CustomCollectionCursor<TParam extends string, TContext extends Context<TContextData>, TContextData> = (context: TContext, values: Record<TParam, string>) => string | null | Promise<string | null>;
|
|
408
|
+
//#endregion
|
|
409
|
+
//#region src/federation/circuit-breaker.d.ts
|
|
410
|
+
/**
|
|
411
|
+
* The state of a remote host circuit breaker.
|
|
412
|
+
* @since 2.3.0
|
|
413
|
+
*/
|
|
414
|
+
type CircuitBreakerState = "closed" | "open" | "half-open";
|
|
415
|
+
/**
|
|
416
|
+
* The JSON-serializable state stored in the configured {@link KvStore}.
|
|
417
|
+
* @since 2.3.0
|
|
418
|
+
*/
|
|
419
|
+
interface CircuitBreakerKvState {
|
|
420
|
+
readonly state: CircuitBreakerState;
|
|
421
|
+
readonly failures: readonly string[];
|
|
422
|
+
readonly opened?: string;
|
|
423
|
+
readonly halfOpened?: string;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Details passed to {@link CircuitBreakerOptions.onActivityDrop} when a held
|
|
427
|
+
* activity expires before the remote host recovers.
|
|
428
|
+
* @since 2.3.0
|
|
429
|
+
*/
|
|
430
|
+
interface CircuitBreakerActivityDrop {
|
|
431
|
+
/** The inbox URL that would have received the activity. */
|
|
432
|
+
readonly inbox: URL;
|
|
433
|
+
/** The activity that was dropped. */
|
|
434
|
+
readonly activity: Activity;
|
|
435
|
+
/** The activity ID, when known. */
|
|
436
|
+
readonly activityId?: string;
|
|
437
|
+
/** The activity type. */
|
|
438
|
+
readonly activityType: string;
|
|
439
|
+
/** The actor IDs represented by this inbox. */
|
|
440
|
+
readonly actorIds: readonly URL[];
|
|
441
|
+
/** The time when Fedify first held this activity. */
|
|
442
|
+
readonly heldSince: Temporal.Instant;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Configures how a remote host circuit opens after repeated delivery
|
|
446
|
+
* failures.
|
|
447
|
+
* @since 2.3.0
|
|
448
|
+
*/
|
|
449
|
+
type CircuitBreakerFailurePolicy = {
|
|
450
|
+
failure(timestamps: readonly Temporal.Instant[]): boolean;
|
|
451
|
+
readonly failureThreshold?: never;
|
|
452
|
+
readonly failureWindow?: never;
|
|
453
|
+
} | {
|
|
454
|
+
readonly failure?: never;
|
|
455
|
+
readonly failureThreshold?: number;
|
|
456
|
+
readonly failureWindow?: Temporal.Duration | Temporal.DurationLike;
|
|
457
|
+
};
|
|
458
|
+
/**
|
|
459
|
+
* Options for Fedify's outbound activity circuit breaker.
|
|
460
|
+
* @since 2.3.0
|
|
461
|
+
*/
|
|
462
|
+
type CircuitBreakerOptions = CircuitBreakerFailurePolicy & {
|
|
463
|
+
/**
|
|
464
|
+
* How long an open circuit waits before allowing a half-open recovery probe.
|
|
465
|
+
* @default `{ minutes: 30 }`
|
|
466
|
+
*/
|
|
467
|
+
readonly recoveryDelay?: Temporal.Duration | Temporal.DurationLike;
|
|
468
|
+
/**
|
|
469
|
+
* How long Fedify keeps requeueing activities held by an open circuit before
|
|
470
|
+
* dropping them.
|
|
471
|
+
* @default `{ days: 7 }`
|
|
472
|
+
*/
|
|
473
|
+
readonly heldActivityTtl?: Temporal.Duration | Temporal.DurationLike;
|
|
474
|
+
/**
|
|
475
|
+
* How often other held activities retry while a half-open probe is in
|
|
476
|
+
* flight. The probe is treated as stale after the recovery delay.
|
|
477
|
+
* @default `{ seconds: 1 }`
|
|
478
|
+
*/
|
|
479
|
+
readonly releaseInterval?: Temporal.Duration | Temporal.DurationLike;
|
|
480
|
+
/**
|
|
481
|
+
* Called whenever the circuit state changes.
|
|
482
|
+
*/
|
|
483
|
+
readonly onStateChange?: (remoteHost: string, previousState: CircuitBreakerState, newState: CircuitBreakerState) => void | Promise<void>;
|
|
484
|
+
/**
|
|
485
|
+
* Called when an activity held by the circuit breaker expires.
|
|
486
|
+
*/
|
|
487
|
+
readonly onActivityDrop?: (remoteHost: string, details: CircuitBreakerActivityDrop) => void | Promise<void>;
|
|
488
|
+
};
|
|
489
|
+
/**
|
|
490
|
+
* Normalized circuit breaker options used internally by Fedify.
|
|
491
|
+
* @internal
|
|
492
|
+
*/
|
|
493
|
+
interface NormalizedCircuitBreakerOptions {
|
|
494
|
+
readonly failure: (timestamps: readonly Temporal.Instant[]) => boolean;
|
|
495
|
+
readonly pruneFailures: (timestamps: readonly Temporal.Instant[], now: Temporal.Instant) => readonly Temporal.Instant[];
|
|
496
|
+
readonly recoveryDelay: Temporal.Duration;
|
|
497
|
+
readonly heldActivityTtl: Temporal.Duration;
|
|
498
|
+
readonly releaseInterval: Temporal.Duration;
|
|
499
|
+
readonly onStateChange?: CircuitBreakerOptions["onStateChange"];
|
|
500
|
+
readonly onActivityDrop?: CircuitBreakerOptions["onActivityDrop"];
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Constructor options for {@link CircuitBreaker}.
|
|
504
|
+
* @internal
|
|
505
|
+
*/
|
|
506
|
+
interface CircuitBreakerCreateOptions {
|
|
507
|
+
readonly kv: KvStore;
|
|
508
|
+
readonly prefix: KvKey;
|
|
509
|
+
readonly options?: CircuitBreakerOptions;
|
|
510
|
+
readonly now?: () => Temporal.Instant;
|
|
511
|
+
/**
|
|
512
|
+
* Observes state changes after user callbacks have run.
|
|
513
|
+
* @internal
|
|
514
|
+
*/
|
|
515
|
+
readonly stateChangeObserver?: (remoteHost: string, previousState: CircuitBreakerState, newState: CircuitBreakerState) => void | Promise<void>;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* The delivery decision returned by {@link CircuitBreaker.beforeSend}.
|
|
519
|
+
* @internal
|
|
520
|
+
*/
|
|
521
|
+
type CircuitBreakerBeforeSendDecision = {
|
|
522
|
+
readonly type: "send";
|
|
523
|
+
readonly probe: boolean;
|
|
524
|
+
readonly stateChange?: CircuitBreakerStateChange;
|
|
525
|
+
} | {
|
|
526
|
+
readonly type: "hold";
|
|
527
|
+
readonly state: "open" | "half-open";
|
|
528
|
+
readonly delay: Temporal.Duration;
|
|
529
|
+
readonly heldSince: Temporal.Instant;
|
|
530
|
+
} | {
|
|
531
|
+
readonly type: "drop";
|
|
532
|
+
readonly heldSince: Temporal.Instant;
|
|
533
|
+
};
|
|
534
|
+
/**
|
|
535
|
+
* A circuit breaker state transition.
|
|
536
|
+
* @since 2.3.0
|
|
537
|
+
*/
|
|
538
|
+
interface CircuitBreakerStateChange {
|
|
539
|
+
readonly previousState: CircuitBreakerState;
|
|
540
|
+
readonly newState: CircuitBreakerState;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Tracks reachability state for remote outbox delivery hosts.
|
|
544
|
+
* @since 2.3.0
|
|
545
|
+
*/
|
|
546
|
+
declare class CircuitBreaker {
|
|
547
|
+
#private;
|
|
548
|
+
constructor(options: CircuitBreakerCreateOptions);
|
|
549
|
+
get options(): NormalizedCircuitBreakerOptions;
|
|
550
|
+
capHeldDelay(heldSince: Temporal.Instant, delay: Temporal.Duration): Temporal.Duration;
|
|
551
|
+
beforeSend(remoteHost: string, message: {
|
|
552
|
+
readonly circuitHeldSince?: string;
|
|
553
|
+
}): Promise<CircuitBreakerBeforeSendDecision>;
|
|
554
|
+
recordSuccess(remoteHost: string): Promise<CircuitBreakerStateChange | undefined>;
|
|
555
|
+
recordReachableFailure(remoteHost: string): Promise<CircuitBreakerStateChange | undefined>;
|
|
556
|
+
recordFailure(remoteHost: string): Promise<CircuitBreakerStateChange | undefined>;
|
|
557
|
+
dropActivity(remoteHost: string, details: CircuitBreakerActivityDrop): Promise<void>;
|
|
558
|
+
getState(remoteHost: string): Promise<CircuitBreakerKvState | undefined>;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Normalizes user-provided circuit breaker options into the internal policy
|
|
562
|
+
* shape used while processing queued outbox deliveries.
|
|
556
563
|
*
|
|
557
|
-
* @
|
|
558
|
-
* @
|
|
559
|
-
*
|
|
560
|
-
* @
|
|
561
|
-
* @
|
|
564
|
+
* @param options The public circuit breaker options supplied to Fedify.
|
|
565
|
+
* @returns The normalized failure predicate, failure pruning function,
|
|
566
|
+
* duration values, and optional callbacks with defaults applied.
|
|
567
|
+
* @throws {RangeError} If any configured duration is not positive.
|
|
568
|
+
* @throws {TypeError} If `failureThreshold` is not a positive integer.
|
|
562
569
|
*/
|
|
563
|
-
|
|
570
|
+
declare function normalizeCircuitBreakerOptions(options: CircuitBreakerOptions): NormalizedCircuitBreakerOptions;
|
|
564
571
|
/**
|
|
565
|
-
*
|
|
572
|
+
* Parses a value loaded from the circuit breaker KV store.
|
|
566
573
|
*
|
|
567
|
-
* @
|
|
568
|
-
* @
|
|
569
|
-
*
|
|
570
|
-
* @template TContextData The context data to pass to the {@link Context}.
|
|
571
|
-
* @template TFilter The type of the filter, if any.
|
|
572
|
-
* @param context The context.
|
|
573
|
-
* @param values The parameters of the requested URL.
|
|
574
|
-
* @since 1.8.0
|
|
574
|
+
* @param value The raw KV value to validate.
|
|
575
|
+
* @returns A circuit breaker state when `value` has a recognized state and
|
|
576
|
+
* valid instant strings, or `undefined` when the stored value is malformed.
|
|
575
577
|
*/
|
|
576
|
-
|
|
578
|
+
declare function parseCircuitBreakerKvState(value: unknown): CircuitBreakerKvState | undefined;
|
|
577
579
|
//#endregion
|
|
578
580
|
//#region src/federation/handler.d.ts
|
|
579
581
|
/**
|
|
@@ -607,6 +609,220 @@ declare function respondWithObject(object: Object$1, options?: RespondWithObject
|
|
|
607
609
|
*/
|
|
608
610
|
declare function respondWithObjectIfAcceptable(object: Object$1, request: Request, options?: RespondWithObjectOptions): Promise<Response | null>;
|
|
609
611
|
//#endregion
|
|
612
|
+
//#region src/federation/retry.d.ts
|
|
613
|
+
/**
|
|
614
|
+
* The context passed to a {@link RetryPolicy} callback.
|
|
615
|
+
* @since 0.12.0
|
|
616
|
+
*/
|
|
617
|
+
interface RetryContext {
|
|
618
|
+
/**
|
|
619
|
+
* The elapsed time since the first attempt.
|
|
620
|
+
*/
|
|
621
|
+
readonly elapsedTime: Temporal.Duration;
|
|
622
|
+
/**
|
|
623
|
+
* The number of attempts so far.
|
|
624
|
+
*/
|
|
625
|
+
readonly attempts: number;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* A policy that determines the delay before the next retry.
|
|
629
|
+
* @param context The retry context.
|
|
630
|
+
* @returns The delay before the next retry, or `null` to stop retrying.
|
|
631
|
+
* It must not negative.
|
|
632
|
+
* @since 0.12.0
|
|
633
|
+
*/
|
|
634
|
+
type RetryPolicy = (context: RetryContext) => Temporal.Duration | null;
|
|
635
|
+
/**
|
|
636
|
+
* Options for {@link createExponentialBackoffPolicy} function.
|
|
637
|
+
* @since 0.12.0
|
|
638
|
+
*/
|
|
639
|
+
interface CreateExponentialBackoffPolicyOptions {
|
|
640
|
+
/**
|
|
641
|
+
* The initial delay before the first retry. Defaults to 1 second.
|
|
642
|
+
*/
|
|
643
|
+
readonly initialDelay?: Temporal.DurationLike;
|
|
644
|
+
/**
|
|
645
|
+
* The maximum delay between retries. Defaults to 12 hours.
|
|
646
|
+
*/
|
|
647
|
+
readonly maxDelay?: Temporal.DurationLike;
|
|
648
|
+
/**
|
|
649
|
+
* The maximum number of attempts before giving up.
|
|
650
|
+
* Defaults to 10.
|
|
651
|
+
*/
|
|
652
|
+
readonly maxAttempts?: number;
|
|
653
|
+
/**
|
|
654
|
+
* The factor to multiply the previous delay by for each retry.
|
|
655
|
+
* Defaults to 2.
|
|
656
|
+
*/
|
|
657
|
+
readonly factor?: number;
|
|
658
|
+
/**
|
|
659
|
+
* Whether to add jitter to the delay to avoid synchronization.
|
|
660
|
+
* Turned on by default.
|
|
661
|
+
*/
|
|
662
|
+
readonly jitter?: boolean;
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Creates an exponential backoff retry policy. The delay between retries
|
|
666
|
+
* starts at the `initialDelay` and is multiplied by the `factor` for each
|
|
667
|
+
* subsequent retry, up to the `maxDelay`. The policy will give up after
|
|
668
|
+
* `maxAttempts` attempts. The actual delay is randomized to avoid
|
|
669
|
+
* synchronization (jitter).
|
|
670
|
+
* @param options The options for the policy.
|
|
671
|
+
* @returns The retry policy.
|
|
672
|
+
* @since 0.12.0
|
|
673
|
+
*/
|
|
674
|
+
declare function createExponentialBackoffPolicy(options?: CreateExponentialBackoffPolicyOptions): RetryPolicy;
|
|
675
|
+
//#endregion
|
|
676
|
+
//#region src/federation/tasks/task.d.ts
|
|
677
|
+
/**
|
|
678
|
+
* A callback that processes a custom background task.
|
|
679
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
|
680
|
+
* @template TData The type of the task payload, inferred from the task's
|
|
681
|
+
* schema.
|
|
682
|
+
* @param ctx The context for the worker processing the task.
|
|
683
|
+
* @param data The decoded and validated task payload.
|
|
684
|
+
* @since 2.4.0
|
|
685
|
+
*/
|
|
686
|
+
type TaskHandler<TContextData, TData> = (ctx: Context<TContextData>, data: TData) => Promise<void> | void;
|
|
687
|
+
/**
|
|
688
|
+
* Options for {@link TaskRegistry.defineTask}.
|
|
689
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
|
690
|
+
* @template TSchema The [Standard Schema](https://standardschema.dev/) that
|
|
691
|
+
* validates the task payload.
|
|
692
|
+
* @since 2.4.0
|
|
693
|
+
*/
|
|
694
|
+
interface TaskDefinitionOptions<TContextData, TSchema extends StandardSchemaV1> {
|
|
695
|
+
/**
|
|
696
|
+
* The [Standard Schema](https://standardschema.dev/) that validates the
|
|
697
|
+
* task payload. The payload type is inferred from this schema.
|
|
698
|
+
*
|
|
699
|
+
* The payload is validated twice: once at enqueue time (fail fast) and
|
|
700
|
+
* once at dequeue time (drift protection against payloads enqueued by an
|
|
701
|
+
* older deployment). Because the same schema runs on both sides, its
|
|
702
|
+
* validation must be idempotent: the validated output must itself be
|
|
703
|
+
* a valid input. Transforming schemas (e.g., Zod's `.transform()`) whose
|
|
704
|
+
* output differs in shape from their input are not supported.
|
|
705
|
+
*/
|
|
706
|
+
readonly schema: TSchema;
|
|
707
|
+
/**
|
|
708
|
+
* The callback that processes the task on a background worker.
|
|
709
|
+
*/
|
|
710
|
+
readonly handler: TaskHandler<TContextData, StandardSchemaV1.InferOutput<TSchema>>;
|
|
711
|
+
/**
|
|
712
|
+
* The retry policy for this task. If omitted, the federation-wide
|
|
713
|
+
* task retry policy is used, which defaults to an exponential backoff
|
|
714
|
+
* policy.
|
|
715
|
+
*/
|
|
716
|
+
readonly retryPolicy?: RetryPolicy;
|
|
717
|
+
/**
|
|
718
|
+
* A callback invoked when the {@link handler} throws an error, before
|
|
719
|
+
* a retry is scheduled.
|
|
720
|
+
* @param ctx The context for the worker processing the task.
|
|
721
|
+
* @param error The error thrown by the handler.
|
|
722
|
+
* @param data The decoded and validated task payload.
|
|
723
|
+
*/
|
|
724
|
+
readonly onError?: (ctx: Context<TContextData>, error: unknown, data: StandardSchemaV1.InferOutput<TSchema>) => Promise<void> | void;
|
|
725
|
+
/**
|
|
726
|
+
* The message queue dedicated to this task. If omitted, the task is
|
|
727
|
+
* routed to the federation-wide task queue, falling back to the outbox
|
|
728
|
+
* queue (unless `taskQueueResolution: "strict"` is configured).
|
|
729
|
+
*/
|
|
730
|
+
readonly queue?: MessageQueue;
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Phantom key binding a {@link TaskDefinition} to its federation's context
|
|
734
|
+
* data type. Declared only—no value exists at runtime, and the symbol is
|
|
735
|
+
* not exported, so the marker stays out of user-facing completions.
|
|
736
|
+
*/
|
|
737
|
+
declare const contextDataBrand: unique symbol;
|
|
738
|
+
/**
|
|
739
|
+
* The handle returned by {@link TaskRegistry.defineTask}. It carries the
|
|
740
|
+
* task name and schema so that {@link Context.enqueueTask} can validate the
|
|
741
|
+
* payload and infer its type at every call site.
|
|
742
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
|
743
|
+
* @template TData The type of the task payload, inferred from the task's
|
|
744
|
+
* schema.
|
|
745
|
+
* @since 2.4.0
|
|
746
|
+
*/
|
|
747
|
+
interface TaskDefinition<TContextData, TData> {
|
|
748
|
+
/**
|
|
749
|
+
* The unique name of the task.
|
|
750
|
+
*/
|
|
751
|
+
readonly name: string;
|
|
752
|
+
/**
|
|
753
|
+
* The [Standard Schema](https://standardschema.dev/) that validates the
|
|
754
|
+
* task payload.
|
|
755
|
+
*/
|
|
756
|
+
readonly schema: StandardSchemaV1<unknown, TData>;
|
|
757
|
+
/**
|
|
758
|
+
* @internal Phantom marker binding the handle to its federation.
|
|
759
|
+
*/
|
|
760
|
+
readonly [contextDataBrand]?: TContextData;
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Registration of custom background tasks. Both {@link Federation} and
|
|
764
|
+
* {@link FederationBuilder} implement this interface.
|
|
765
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
|
766
|
+
* @since 2.4.0
|
|
767
|
+
*/
|
|
768
|
+
interface TaskRegistry<TContextData> {
|
|
769
|
+
/**
|
|
770
|
+
* Defines a custom background task. The returned handle is passed to
|
|
771
|
+
* {@link Context.enqueueTask} to enqueue the task.
|
|
772
|
+
*
|
|
773
|
+
* @example
|
|
774
|
+
* ``` typescript
|
|
775
|
+
* const sendDigest = federation.defineTask("sendDigest", {
|
|
776
|
+
* schema: digestSchema,
|
|
777
|
+
* handler: async (ctx, data) => {
|
|
778
|
+
* // …process the payload on a background worker…
|
|
779
|
+
* },
|
|
780
|
+
* });
|
|
781
|
+
* ```
|
|
782
|
+
*
|
|
783
|
+
* @param name The unique name of the task.
|
|
784
|
+
* @param options The task definition options. The payload type is
|
|
785
|
+
* inferred from `options.schema`.
|
|
786
|
+
* @returns The handle to pass to {@link Context.enqueueTask}.
|
|
787
|
+
* @throws {TypeError} If a task with the same name is already defined.
|
|
788
|
+
*/
|
|
789
|
+
defineTask<TSchema extends StandardSchemaV1>(name: string, options: TaskDefinitionOptions<TContextData, TSchema>): TaskDefinition<TContextData, StandardSchemaV1.InferOutput<TSchema>>;
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Options for {@link Context.enqueueTask} and {@link Context.enqueueTaskMany}.
|
|
793
|
+
* @since 2.4.0
|
|
794
|
+
*/
|
|
795
|
+
interface TaskEnqueueOptions {
|
|
796
|
+
/**
|
|
797
|
+
* The delay before the task is processed. No delay by default.
|
|
798
|
+
*/
|
|
799
|
+
readonly delay?: Temporal.DurationLike;
|
|
800
|
+
/**
|
|
801
|
+
* An optional key that ensures tasks with the same ordering key are
|
|
802
|
+
* processed sequentially (one at a time).
|
|
803
|
+
*/
|
|
804
|
+
readonly orderingKey?: string;
|
|
805
|
+
/**
|
|
806
|
+
* An optional key requesting at-most-once enqueue for tasks that share it.
|
|
807
|
+
*
|
|
808
|
+
* A queue with {@link MessageQueue.nativeDeduplication} `true` enforces it
|
|
809
|
+
* strictly; otherwise deduplication is best-effort via {@link KvStore.cas},
|
|
810
|
+
* and {@link FederationOptions.taskDeduplicationFallback} decides whether a
|
|
811
|
+
* missing `cas` proceeds without deduplication or throws.
|
|
812
|
+
*
|
|
813
|
+
* For {@link Context.enqueueTaskMany}, one key governs the whole batch. When
|
|
814
|
+
* deduplication is actually applied—a native queue, or the key–value
|
|
815
|
+
* fallback through {@link KvStore.cas}—a multi-item batch with a
|
|
816
|
+
* `deduplicationKey` requires the queue to implement
|
|
817
|
+
* {@link MessageQueue.enqueueMany} so it enqueues atomically, or the call
|
|
818
|
+
* throws a `TypeError`. Under the `"open"` fallback with no `cas`, no marker
|
|
819
|
+
* is taken, so such a batch instead fans out without deduplication.
|
|
820
|
+
*
|
|
821
|
+
* @since 2.4.0
|
|
822
|
+
*/
|
|
823
|
+
readonly deduplicationKey?: string;
|
|
824
|
+
}
|
|
825
|
+
//#endregion
|
|
610
826
|
//#region src/federation/builder.d.ts
|
|
611
827
|
/**
|
|
612
828
|
* Creates a new {@link FederationBuilder} instance.
|
|
@@ -629,7 +845,7 @@ interface SenderKeyJwkPair {
|
|
|
629
845
|
* type.
|
|
630
846
|
* @since 1.6.0
|
|
631
847
|
*/
|
|
632
|
-
type Message = FanoutMessage | OutboxMessage | InboxMessage;
|
|
848
|
+
type Message = FanoutMessage | OutboxMessage | InboxMessage | TaskMessage;
|
|
633
849
|
interface FanoutMessage {
|
|
634
850
|
readonly type: "fanout";
|
|
635
851
|
readonly id: ReturnType<typeof crypto.randomUUID>;
|
|
@@ -683,6 +899,24 @@ interface OutboxMessage {
|
|
|
683
899
|
readonly circuitHeldSince?: string;
|
|
684
900
|
readonly traceContext: Readonly<Record<string, string>>;
|
|
685
901
|
}
|
|
902
|
+
/**
|
|
903
|
+
* A message that carries a custom background task. Every field is
|
|
904
|
+
* a string, number, or plain record so that the message survives both
|
|
905
|
+
* JSON serialization and structured clone on every queue backend.
|
|
906
|
+
* @since 2.4.0
|
|
907
|
+
*/
|
|
908
|
+
interface TaskMessage {
|
|
909
|
+
readonly type: "task";
|
|
910
|
+
readonly id: ReturnType<typeof crypto.randomUUID>;
|
|
911
|
+
readonly baseUrl: string;
|
|
912
|
+
readonly taskName: string;
|
|
913
|
+
/** devalue-encoded task data; vocab objects bridged to expanded JSON-LD. */
|
|
914
|
+
readonly data: string;
|
|
915
|
+
readonly started: string;
|
|
916
|
+
readonly attempt: number;
|
|
917
|
+
readonly orderingKey?: string;
|
|
918
|
+
readonly traceContext: Readonly<Record<string, string>>;
|
|
919
|
+
}
|
|
686
920
|
interface InboxMessage {
|
|
687
921
|
readonly type: "inbox";
|
|
688
922
|
readonly id: ReturnType<typeof crypto.randomUUID>;
|
|
@@ -730,70 +964,6 @@ interface InboxMessage {
|
|
|
730
964
|
readonly traceContext: Readonly<Record<string, string>>;
|
|
731
965
|
}
|
|
732
966
|
//#endregion
|
|
733
|
-
//#region src/federation/retry.d.ts
|
|
734
|
-
/**
|
|
735
|
-
* The context passed to a {@link RetryPolicy} callback.
|
|
736
|
-
* @since 0.12.0
|
|
737
|
-
*/
|
|
738
|
-
interface RetryContext {
|
|
739
|
-
/**
|
|
740
|
-
* The elapsed time since the first attempt.
|
|
741
|
-
*/
|
|
742
|
-
readonly elapsedTime: Temporal.Duration;
|
|
743
|
-
/**
|
|
744
|
-
* The number of attempts so far.
|
|
745
|
-
*/
|
|
746
|
-
readonly attempts: number;
|
|
747
|
-
}
|
|
748
|
-
/**
|
|
749
|
-
* A policy that determines the delay before the next retry.
|
|
750
|
-
* @param context The retry context.
|
|
751
|
-
* @returns The delay before the next retry, or `null` to stop retrying.
|
|
752
|
-
* It must not negative.
|
|
753
|
-
* @since 0.12.0
|
|
754
|
-
*/
|
|
755
|
-
type RetryPolicy = (context: RetryContext) => Temporal.Duration | null;
|
|
756
|
-
/**
|
|
757
|
-
* Options for {@link createExponentialBackoffPolicy} function.
|
|
758
|
-
* @since 0.12.0
|
|
759
|
-
*/
|
|
760
|
-
interface CreateExponentialBackoffPolicyOptions {
|
|
761
|
-
/**
|
|
762
|
-
* The initial delay before the first retry. Defaults to 1 second.
|
|
763
|
-
*/
|
|
764
|
-
readonly initialDelay?: Temporal.DurationLike;
|
|
765
|
-
/**
|
|
766
|
-
* The maximum delay between retries. Defaults to 12 hours.
|
|
767
|
-
*/
|
|
768
|
-
readonly maxDelay?: Temporal.DurationLike;
|
|
769
|
-
/**
|
|
770
|
-
* The maximum number of attempts before giving up.
|
|
771
|
-
* Defaults to 10.
|
|
772
|
-
*/
|
|
773
|
-
readonly maxAttempts?: number;
|
|
774
|
-
/**
|
|
775
|
-
* The factor to multiply the previous delay by for each retry.
|
|
776
|
-
* Defaults to 2.
|
|
777
|
-
*/
|
|
778
|
-
readonly factor?: number;
|
|
779
|
-
/**
|
|
780
|
-
* Whether to add jitter to the delay to avoid synchronization.
|
|
781
|
-
* Turned on by default.
|
|
782
|
-
*/
|
|
783
|
-
readonly jitter?: boolean;
|
|
784
|
-
}
|
|
785
|
-
/**
|
|
786
|
-
* Creates an exponential backoff retry policy. The delay between retries
|
|
787
|
-
* starts at the `initialDelay` and is multiplied by the `factor` for each
|
|
788
|
-
* subsequent retry, up to the `maxDelay`. The policy will give up after
|
|
789
|
-
* `maxAttempts` attempts. The actual delay is randomized to avoid
|
|
790
|
-
* synchronization (jitter).
|
|
791
|
-
* @param options The options for the policy.
|
|
792
|
-
* @returns The retry policy.
|
|
793
|
-
* @since 0.12.0
|
|
794
|
-
*/
|
|
795
|
-
declare function createExponentialBackoffPolicy(options?: CreateExponentialBackoffPolicyOptions): RetryPolicy;
|
|
796
|
-
//#endregion
|
|
797
967
|
//#region src/federation/middleware.d.ts
|
|
798
968
|
/**
|
|
799
969
|
* Configures the task queues for sending and receiving activities.
|
|
@@ -817,6 +987,13 @@ interface FederationQueueOptions {
|
|
|
817
987
|
* {@link Context.sendActivity} calls.
|
|
818
988
|
*/
|
|
819
989
|
readonly fanout?: MessageQueue;
|
|
990
|
+
/**
|
|
991
|
+
* The message queue for custom background tasks. If not provided,
|
|
992
|
+
* tasks are routed to the outbox queue (unless
|
|
993
|
+
* {@link FederationOptions.taskQueueResolution} is `"strict"`).
|
|
994
|
+
* @since 2.4.0
|
|
995
|
+
*/
|
|
996
|
+
readonly task?: MessageQueue;
|
|
820
997
|
}
|
|
821
998
|
/**
|
|
822
999
|
* Prefixes for namespacing keys in the Deno KV store.
|
|
@@ -860,6 +1037,14 @@ interface FederationKvPrefixes {
|
|
|
860
1037
|
* @since 2.3.0
|
|
861
1038
|
*/
|
|
862
1039
|
readonly circuitBreaker: KvKey;
|
|
1040
|
+
/**
|
|
1041
|
+
* The key prefix used for storing custom background task deduplication
|
|
1042
|
+
* markers. Kept separate from {@link activityIdempotence} so the two key
|
|
1043
|
+
* spaces never collide.
|
|
1044
|
+
* @default `["_fedify", "taskDeduplication"]`
|
|
1045
|
+
* @since 2.4.0
|
|
1046
|
+
*/
|
|
1047
|
+
readonly taskDeduplication: KvKey;
|
|
863
1048
|
}
|
|
864
1049
|
/**
|
|
865
1050
|
* Options for {@link FederationOptions.origin} when it is not a string.
|
|
@@ -901,18 +1086,18 @@ interface FederationStartQueueOptions {
|
|
|
901
1086
|
signal?: AbortSignal;
|
|
902
1087
|
/**
|
|
903
1088
|
* Starts the task worker only for the specified queue. If unspecified,
|
|
904
|
-
* which is the default, the task worker starts for all
|
|
905
|
-
* inbox, outbox, and
|
|
1089
|
+
* which is the default, the task worker starts for all four queues:
|
|
1090
|
+
* inbox, outbox, fanout, and task.
|
|
906
1091
|
* @since 1.3.0
|
|
907
1092
|
*/
|
|
908
|
-
queue?: "inbox" | "outbox" | "fanout";
|
|
1093
|
+
queue?: "inbox" | "outbox" | "fanout" | "task";
|
|
909
1094
|
}
|
|
910
1095
|
/**
|
|
911
1096
|
* A common interface between {@link Federation} and {@link FederationBuilder}.
|
|
912
1097
|
* @template TContextData The context data to pass to the {@link Context}.
|
|
913
1098
|
* @since 1.6.0
|
|
914
1099
|
*/
|
|
915
|
-
interface Federatable<TContextData> {
|
|
1100
|
+
interface Federatable<TContextData> extends TaskRegistry<TContextData> {
|
|
916
1101
|
/**
|
|
917
1102
|
* Registers a NodeInfo dispatcher.
|
|
918
1103
|
* @param path The URI path pattern for the NodeInfo dispatcher. The syntax
|
|
@@ -1619,6 +1804,50 @@ interface FederationOptions<TContextData> {
|
|
|
1619
1804
|
*/
|
|
1620
1805
|
inboxRetryPolicy?: RetryPolicy;
|
|
1621
1806
|
/**
|
|
1807
|
+
* The retry policy for processing custom background tasks. By default,
|
|
1808
|
+
* this uses an exponential backoff strategy with a maximum of 10 attempts
|
|
1809
|
+
* and a maximum delay of 12 hours. A per-task retry policy
|
|
1810
|
+
* ({@link TaskDefinitionOptions.retryPolicy}) overrides this.
|
|
1811
|
+
* @since 2.4.0
|
|
1812
|
+
*/
|
|
1813
|
+
taskRetryPolicy?: RetryPolicy;
|
|
1814
|
+
/**
|
|
1815
|
+
* How a queue is resolved for a custom background task when neither
|
|
1816
|
+
* a per-task queue ({@link TaskDefinitionOptions.queue}) nor a dedicated
|
|
1817
|
+
* task queue ({@link FederationQueueOptions.task}) is configured.
|
|
1818
|
+
*
|
|
1819
|
+
* - `"fallback"` (the default): the task is routed to the outbox queue.
|
|
1820
|
+
* - `"strict"`: no fallback; enqueuing the task throws instead of
|
|
1821
|
+
* silently sharing the outbox queue.
|
|
1822
|
+
* @default `"fallback"`
|
|
1823
|
+
* @since 2.4.0
|
|
1824
|
+
*/
|
|
1825
|
+
taskQueueResolution?: "fallback" | "strict";
|
|
1826
|
+
/**
|
|
1827
|
+
* The time-to-live for a {@link TaskEnqueueOptions.deduplicationKey} marker
|
|
1828
|
+
* stored in the key–value deduplication fallback. A second enqueue with the
|
|
1829
|
+
* same key within this window is skipped; once it expires, the key may
|
|
1830
|
+
* enqueue again. Ignored when the task's queue declares
|
|
1831
|
+
* {@link MessageQueue.nativeDeduplication} (the backend owns the window).
|
|
1832
|
+
* @default `{ hours: 1 }`
|
|
1833
|
+
* @since 2.4.0
|
|
1834
|
+
*/
|
|
1835
|
+
taskDeduplicationTtl?: Temporal.DurationLike;
|
|
1836
|
+
/**
|
|
1837
|
+
* The behavior when a {@link TaskEnqueueOptions.deduplicationKey} is supplied
|
|
1838
|
+
* but the task's queue does not declare
|
|
1839
|
+
* {@link MessageQueue.nativeDeduplication} *and* the configured
|
|
1840
|
+
* {@link KvStore} exposes no `cas` (compare-and-swap) primitive:
|
|
1841
|
+
*
|
|
1842
|
+
* - `"open"` (the default): proceeds without deduplication after logging at
|
|
1843
|
+
* debug level.
|
|
1844
|
+
* - `"closed"`: rejects with a `TypeError` before enqueuing.
|
|
1845
|
+
*
|
|
1846
|
+
* @default `"open"`
|
|
1847
|
+
* @since 2.4.0
|
|
1848
|
+
*/
|
|
1849
|
+
taskDeduplicationFallback?: "open" | "closed";
|
|
1850
|
+
/**
|
|
1622
1851
|
* Activity transformers that are applied to outgoing activities. It is
|
|
1623
1852
|
* useful for adjusting outgoing activities to satisfy some ActivityPub
|
|
1624
1853
|
* implementations.
|
|
@@ -2371,6 +2600,48 @@ interface Context<TContextData> {
|
|
|
2371
2600
|
*/
|
|
2372
2601
|
routeActivity(recipient: string | null, activity: Activity, options?: RouteActivityOptions): Promise<boolean>;
|
|
2373
2602
|
/**
|
|
2603
|
+
* Enqueues a custom background task. The payload is validated against
|
|
2604
|
+
* the task's schema, serialized, and processed by the task's handler on
|
|
2605
|
+
* a background worker.
|
|
2606
|
+
*
|
|
2607
|
+
* @example
|
|
2608
|
+
* ``` typescript
|
|
2609
|
+
* await ctx.enqueueTask(sendDigest, { userId: "alice" });
|
|
2610
|
+
* ```
|
|
2611
|
+
*
|
|
2612
|
+
* @template TData The type of the task payload, inferred from the task's
|
|
2613
|
+
* schema.
|
|
2614
|
+
* @param task The handle returned by {@link TaskRegistry.defineTask}.
|
|
2615
|
+
* @param data The task payload. It is validated against the task's
|
|
2616
|
+
* schema before being enqueued.
|
|
2617
|
+
* @param options Options for enqueuing the task.
|
|
2618
|
+
* @throws {TypeError} If the task is not defined on this federation,
|
|
2619
|
+
* if no message queue is configured for tasks, or if
|
|
2620
|
+
* the payload fails schema validation.
|
|
2621
|
+
* @since 2.4.0
|
|
2622
|
+
*/
|
|
2623
|
+
enqueueTask<TData>(task: TaskDefinition<TContextData, TData>, data: TData, options?: TaskEnqueueOptions): Promise<void>;
|
|
2624
|
+
/**
|
|
2625
|
+
* Enqueues multiple payloads for a custom background task at once.
|
|
2626
|
+
* Uses the queue's bulk enqueue operation when available. Without
|
|
2627
|
+
* deduplication, it may fall back to parallel single enqueues when the
|
|
2628
|
+
* queue does not implement bulk enqueue.
|
|
2629
|
+
* @template TData The type of the task payload, inferred from the task's
|
|
2630
|
+
* schema.
|
|
2631
|
+
* @param task The handle returned by {@link TaskRegistry.defineTask}.
|
|
2632
|
+
* @param payloads The task payloads. Each is validated against the
|
|
2633
|
+
* task's schema before being enqueued.
|
|
2634
|
+
* @param options Options for enqueuing the tasks.
|
|
2635
|
+
* @throws {TypeError} If the task is not defined on this federation,
|
|
2636
|
+
* if no message queue is configured for tasks, if
|
|
2637
|
+
* a payload fails schema validation, or if a
|
|
2638
|
+
* deduplicated multi-item batch cannot be enqueued
|
|
2639
|
+
* atomically because the queue does not implement
|
|
2640
|
+
* bulk enqueue.
|
|
2641
|
+
* @since 2.4.0
|
|
2642
|
+
*/
|
|
2643
|
+
enqueueTaskMany<TData>(task: TaskDefinition<TContextData, TData>, payloads: readonly TData[], options?: TaskEnqueueOptions): Promise<void>;
|
|
2644
|
+
/**
|
|
2374
2645
|
* Builds the URI of a collection of objects with the given name and values.
|
|
2375
2646
|
* @param name The name of the collection, which can be a string or a symbol.
|
|
2376
2647
|
* @param values The values of the URI parameters.
|
|
@@ -2881,4 +3152,4 @@ interface ActorKeyPair extends CryptoKeyPair {
|
|
|
2881
3152
|
readonly multikey: Multikey;
|
|
2882
3153
|
}
|
|
2883
3154
|
//#endregion
|
|
2884
|
-
export {
|
|
3155
|
+
export { CircuitBreakerFailurePolicy as $, Rfc6570Expression as A, WebFingerLinksDispatcher as At, TaskHandler as B, FederationStartQueueOptions as C, OutboxErrorHandler as Ct, InboxListenerSetters as D, SharedInboxKeyDispatcher as Dt, InboxChallengePolicy as E, OutboxPermanentFailureHandler as Et, Message as F, digest as Ft, createExponentialBackoffPolicy as G, CreateExponentialBackoffPolicyOptions as H, createFederationBuilder as I, ActivityTransformer as It, respondWithObjectIfAcceptable as J, RespondWithObjectOptions as K, TaskDefinition as L, FederationOrigin as M, SenderKeyPair as Mt, FederationQueueOptions as N, PageItems as Nt, ObjectCallbackSetters as O, UnverifiedActivityHandler as Ot, createFederation as P, buildCollectionSynchronizationHeader as Pt, CircuitBreakerCreateOptions as Q, TaskDefinitionOptions as R, FederationOptions as S, ObjectDispatcher as St, IdempotencyStrategy as T, OutboxListenerErrorHandler as Tt, RetryContext as U, TaskRegistry as V, RetryPolicy as W, CircuitBreakerActivityDrop as X, CircuitBreaker as Y, CircuitBreakerBeforeSendDecision as Z, Federatable as _, CustomCollectionDispatcher as _t, GetSignedKeyOptions as a, normalizeCircuitBreakerOptions as at, FederationBuilder as b, NodeInfoDispatcher as bt, ParseUriResult as c, ActorDispatcher as ct, SendActivityOptions as d, AuthorizePredicate as dt, CircuitBreakerKvState as et, SendActivityOptionsForCollection as f, CollectionCounter as ft, CustomCollectionCallbackSetters as g, CustomCollectionCursor as gt, ConstructorWithTypeId as h, CustomCollectionCounter as ht, GetActorOptions as i, NormalizedCircuitBreakerOptions as it, FederationKvPrefixes as j, SendActivityError as jt, OutboxListenerSetters as k, UnverifiedActivityReason as kt, RequestContext as l, ActorHandleMapper as lt, CollectionCallbackSetters as m, CollectionDispatcher as mt, Context as n, CircuitBreakerState as nt, InboxContext as o, parseCircuitBreakerKvState as ot, ActorCallbackSetters as p, CollectionCursor as pt, respondWithObject as q, ForwardActivityOptions as r, CircuitBreakerStateChange as rt, OutboxContext as s, ActorAliasMapper as st, ActorKeyPair as t, CircuitBreakerOptions as tt, RouteActivityOptions as u, ActorKeyPairsDispatcher as ut, Federation as v, InboxErrorHandler as vt, IdempotencyKeyCallback as w, OutboxListener as wt, FederationFetchOptions as x, ObjectAuthorizePredicate as xt, FederationBenchmarkOptions as y, InboxListener as yt, TaskEnqueueOptions as z };
|