@fedify/fedify 2.4.0-dev.1508 → 2.4.0-dev.1528
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/dist/{assert-DvVHoIZ0.mjs → assert-OguE97r2.mjs} +1 -1
- package/dist/{assert_instance_of-CxoC8bVq.mjs → assert_instance_of-DBC5X09g.mjs} +1 -1
- package/dist/{assert_not_equals-C8vcTTA3.mjs → assert_not_equals-DkVK8oqV.mjs} +1 -1
- package/dist/{assert_rejects-DAdaaIWM.mjs → assert_rejects-DN60FHPX.mjs} +2 -2
- package/dist/{assert_strict_equals-BzqyKuYL.mjs → assert_strict_equals-XEgZAlrj.mjs} +1 -1
- package/dist/{assert_throws-zN79lgIC.mjs → assert_throws-BOkhLGYc.mjs} +1 -1
- package/dist/{builder-DlWCek6Z.mjs → builder-B6myMguW.mjs} +3 -23
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/outgoing-jsonld.test.mjs +3 -3
- package/dist/compat/public-audience.test.mjs +3 -3
- package/dist/compat/transformers.test.mjs +5 -5
- package/dist/{context-CYF8X0ft.d.cts → context-BBVLF7lx.d.cts} +272 -543
- package/dist/{context-BF5B4ZDk.d.ts → context-BU6jSQdo.d.ts} +272 -542
- package/dist/{context-BBRTgkrs.mjs → context-DVoTs_wM.mjs} +2 -8
- package/dist/{deno-nexucTAX.mjs → deno-CVNsRJe9.mjs} +1 -1
- package/dist/{docloader-DAdEN549.mjs → docloader-CB8AGpw3.mjs} +3 -3
- package/dist/federation/builder.test.mjs +5 -5
- package/dist/federation/circuit-breaker.test.mjs +5 -5
- package/dist/federation/collection.test.mjs +3 -3
- package/dist/federation/handler.test.mjs +13 -13
- package/dist/federation/idempotency.test.mjs +6 -6
- package/dist/federation/inbox.test.mjs +3 -3
- package/dist/federation/keycache.test.mjs +5 -5
- package/dist/federation/kv.test.mjs +3 -3
- package/dist/federation/metrics.test.mjs +4 -4
- package/dist/federation/middleware.test.mjs +19 -200
- package/dist/federation/mod.cjs +259 -3
- package/dist/federation/mod.d.cts +4 -4
- package/dist/federation/mod.d.ts +4 -4
- package/dist/federation/mod.js +257 -1
- package/dist/federation/mq.test.mjs +261 -103
- package/dist/federation/negotiation.test.mjs +4 -4
- package/dist/federation/retry.test.mjs +3 -3
- package/dist/federation/router.test.mjs +5 -5
- package/dist/federation/send.test.mjs +10 -10
- package/dist/federation/temporal.test.mjs +4 -4
- package/dist/federation/webfinger.test.mjs +6 -6
- package/dist/{http-Dv3147TL.js → http-B0-9u_1F.js} +1 -1
- package/dist/{http-BCj9dlA_.cjs → http-EkV7OslM.cjs} +1 -1
- package/dist/{http-inQqS3yx.mjs → http-L7wqkbZR.mjs} +4 -4
- package/dist/{key-CGrr6-I2.mjs → key-Ct8zNgGk.mjs} +2 -2
- package/dist/{kv-cache-C3qkFkbt.mjs → kv-cache-CUT9OGpX.mjs} +1 -1
- package/dist/{kv-cache-c8X6svwE.cjs → kv-cache-CbB50co6.cjs} +1 -1
- package/dist/{kv-cache-C2oTEXyb.js → kv-cache-Dh8ZoQfC.js} +1 -1
- package/dist/{ld-fnWaNT8y.mjs → ld-D6I7H18J.mjs} +3 -3
- package/dist/{metrics-C5hMINAa.mjs → metrics-DvClPYaE.mjs} +1 -1
- package/dist/{middleware-DeVzbg1I.cjs → middleware-B0ujKP-0.cjs} +30 -690
- package/dist/{middleware-CQlq6ykI.mjs → middleware-CGqUj4XY.mjs} +1 -1
- package/dist/{middleware-vQ_ZpgcX.js → middleware-DX9Fd37u.js} +31 -679
- package/dist/{middleware-Dl2nyVgB.mjs → middleware-RxFBNV2C.mjs} +46 -306
- package/dist/{mod-BHEB3xhE.d.cts → mod-C0F6kvgS.d.cts} +1 -1
- package/dist/{mod-4WGAuR6X.d.ts → mod-vPYVoa5n.d.ts} +1 -1
- package/dist/mod.cjs +6 -6
- package/dist/mod.d.cts +5 -5
- package/dist/mod.d.ts +5 -5
- package/dist/mod.js +5 -5
- package/dist/{mq-DXMt_qCY.d.cts → mq-D-nlpY04.d.ts} +0 -34
- package/dist/{mq-B5_hohs7.d.ts → mq-D8uSFzxe.d.cts} +0 -34
- package/dist/nodeinfo/client.test.mjs +3 -3
- package/dist/nodeinfo/handler.test.mjs +5 -5
- package/dist/nodeinfo/types.test.mjs +4 -4
- package/dist/otel/exporter.test.mjs +3 -3
- package/dist/{outgoing-jsonld-BNL8AC14.mjs → outgoing-jsonld-L_DbOaFe.mjs} +1 -1
- package/dist/{owner-Bq2eZyO_.mjs → owner-BqPUA8Z6.mjs} +2 -2
- package/dist/{proof-DZCjcFCd.mjs → proof-BJKoRFBc.mjs} +5 -5
- package/dist/{proof-CTG9azxN.js → proof-DCCmmEuJ.js} +1 -1
- package/dist/{proof-Buz7I8wj.cjs → proof-eZme7HYR.cjs} +1 -1
- package/dist/{send-B253S5gN.mjs → send-DVtEjoJ6.mjs} +3 -3
- package/dist/sig/accept.test.mjs +1 -1
- package/dist/sig/http.test.mjs +8 -8
- package/dist/sig/key.test.mjs +6 -6
- package/dist/sig/ld.test.mjs +7 -7
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +6 -6
- package/dist/sig/proof.test.mjs +8 -8
- package/dist/{std__assert-Dh6uLf_q.mjs → std__assert-BBjXFNOb.mjs} +4 -4
- package/dist/{temporal-d6TshGjq.mjs → temporal-B06FcmVK.mjs} +1 -1
- package/dist/testing/mod.d.mts +8 -1037
- package/dist/testing/mod.mjs +2 -3
- package/dist/utils/docloader.test.mjs +6 -6
- package/dist/utils/kv-cache.test.mjs +1 -1
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +7 -9
- package/dist/codec-CmlPqjNX.mjs +0 -103
- package/dist/federation/tasks/codec.test.d.mts +0 -2
- package/dist/federation/tasks/codec.test.mjs +0 -292
- package/dist/federation/tasks/enqueue.test.d.mts +0 -2
- package/dist/federation/tasks/enqueue.test.mjs +0 -992
- package/dist/federation/tasks/tasks.test.d.mts +0 -2
- package/dist/federation/tasks/tasks.test.mjs +0 -555
- package/dist/mq-03vS-C9P.mjs +0 -276
- package/dist/testing-Dy-WhqpN.mjs +0 -77
- /package/dist/{accept-CgDcxvjV.mjs → accept-CPkZzmGN.mjs} +0 -0
- /package/dist/{activity-listener-BeTGV3wc.mjs → activity-listener-tztVvlNb.mjs} +0 -0
- /package/dist/{assert_equals-PBVKNMJd.mjs → assert_equals-C-ZRDbaf.mjs} +0 -0
- /package/dist/{circuit-breaker-hJBB6jwA.mjs → circuit-breaker-CSWsyoef.mjs} +0 -0
- /package/dist/{client-B_A6mfn3.mjs → client-ByXmQhYD.mjs} +0 -0
- /package/dist/{collection-Dp5ky45w.mjs → collection-Cc3DVAhE.mjs} +0 -0
- /package/dist/{keycache-CaOR6NYg.mjs → keycache-BeU0LCII.mjs} +0 -0
- /package/dist/{keys-CSYsOMFG.mjs → keys-DGu1NFwu.mjs} +0 -0
- /package/dist/{kv-CIvR3Non.mjs → kv-rV3vodCc.mjs} +0 -0
- /package/dist/{negotiation-m_L2nyS3.mjs → negotiation-DDstyBvc.mjs} +0 -0
- /package/dist/{public-audience-c9zmYKgA.mjs → public-audience-Cvbr2Gzt.mjs} +0 -0
- /package/dist/{retry-DI4O-zYl.mjs → retry-CXg_MBI-.mjs} +0 -0
- /package/dist/{types-BFowWFTT.mjs → types-J53Kw7so.mjs} +0 -0
|
@@ -3,13 +3,11 @@ 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-D8uSFzxe.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
|
-
|
|
13
11
|
//#region src/compat/types.d.ts
|
|
14
12
|
/**
|
|
15
13
|
* A function that transforms an activity object.
|
|
@@ -17,6 +15,177 @@ import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
|
17
15
|
*/
|
|
18
16
|
type ActivityTransformer<TContextData> = (activity: Activity, context: Context<TContextData>) => Activity;
|
|
19
17
|
//#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
|
|
20
189
|
//#region src/federation/collection.d.ts
|
|
21
190
|
/**
|
|
22
191
|
* A page of items.
|
|
@@ -369,213 +538,42 @@ type ObjectAuthorizePredicate<TContextData, TParam extends string> = (context: R
|
|
|
369
538
|
/**
|
|
370
539
|
* A callback that dispatches a custom collection.
|
|
371
540
|
*
|
|
372
|
-
* @template TItem The type of items in the collection.
|
|
373
|
-
* @template TParams The parameter names of the requested URL.
|
|
374
|
-
* @template TContext The type of the context. {@link Context} or
|
|
375
|
-
* {@link RequestContext}.
|
|
376
|
-
* @template TContextData The context data to pass to the `TContext`.
|
|
377
|
-
* @template TFilter The type of the filter, if any.
|
|
378
|
-
* @param context The context.
|
|
379
|
-
* @param values The parameters of the requested URL.
|
|
380
|
-
* @param cursor The cursor to start the collection from, or `null` to dispatch
|
|
381
|
-
* the entire collection without pagination.
|
|
382
|
-
* @since 1.8.0
|
|
383
|
-
*/
|
|
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>;
|
|
385
|
-
/**
|
|
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
|
-
}
|
|
541
|
+
* @template TItem The type of items in the collection.
|
|
542
|
+
* @template TParams The parameter names of the requested URL.
|
|
543
|
+
* @template TContext The type of the context. {@link Context} or
|
|
544
|
+
* {@link RequestContext}.
|
|
545
|
+
* @template TContextData The context data to pass to the `TContext`.
|
|
546
|
+
* @template TFilter The type of the filter, if any.
|
|
547
|
+
* @param context The context.
|
|
548
|
+
* @param values The parameters of the requested URL.
|
|
549
|
+
* @param cursor The cursor to start the collection from, or `null` to dispatch
|
|
550
|
+
* the entire collection without pagination.
|
|
551
|
+
* @since 1.8.0
|
|
552
|
+
*/
|
|
553
|
+
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>;
|
|
560
554
|
/**
|
|
561
|
-
*
|
|
562
|
-
* shape used while processing queued outbox deliveries.
|
|
555
|
+
* A callback that counts the number of items in a custom collection.
|
|
563
556
|
*
|
|
564
|
-
* @
|
|
565
|
-
* @
|
|
566
|
-
*
|
|
567
|
-
* @
|
|
568
|
-
* @
|
|
557
|
+
* @template TParams The parameter names of the requested URL.
|
|
558
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
|
559
|
+
* @param context The context.
|
|
560
|
+
* @param values The parameters of the requested URL.
|
|
561
|
+
* @since 1.8.0
|
|
569
562
|
*/
|
|
570
|
-
|
|
563
|
+
type CustomCollectionCounter<TParam extends string, TContextData> = (context: RequestContext<TContextData>, values: Record<TParam, string>) => number | bigint | null | Promise<number | bigint | null>;
|
|
571
564
|
/**
|
|
572
|
-
*
|
|
565
|
+
* A callback that returns a cursor for a custom collection.
|
|
573
566
|
*
|
|
574
|
-
* @
|
|
575
|
-
* @
|
|
576
|
-
*
|
|
567
|
+
* @template TParams The parameter names of the requested URL.
|
|
568
|
+
* @template TContext The type of the context. {@link Context} or
|
|
569
|
+
* {@link RequestContext}.
|
|
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
|
|
577
575
|
*/
|
|
578
|
-
|
|
576
|
+
type CustomCollectionCursor<TParam extends string, TContext extends Context<TContextData>, TContextData> = (context: TContext, values: Record<TParam, string>) => string | null | Promise<string | null>;
|
|
579
577
|
//#endregion
|
|
580
578
|
//#region src/federation/handler.d.ts
|
|
581
579
|
/**
|
|
@@ -609,220 +607,6 @@ declare function respondWithObject(object: Object$1, options?: RespondWithObject
|
|
|
609
607
|
*/
|
|
610
608
|
declare function respondWithObjectIfAcceptable(object: Object$1, request: Request, options?: RespondWithObjectOptions): Promise<Response | null>;
|
|
611
609
|
//#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
|
|
826
610
|
//#region src/federation/builder.d.ts
|
|
827
611
|
/**
|
|
828
612
|
* Creates a new {@link FederationBuilder} instance.
|
|
@@ -845,7 +629,7 @@ interface SenderKeyJwkPair {
|
|
|
845
629
|
* type.
|
|
846
630
|
* @since 1.6.0
|
|
847
631
|
*/
|
|
848
|
-
type Message = FanoutMessage | OutboxMessage | InboxMessage
|
|
632
|
+
type Message = FanoutMessage | OutboxMessage | InboxMessage;
|
|
849
633
|
interface FanoutMessage {
|
|
850
634
|
readonly type: "fanout";
|
|
851
635
|
readonly id: ReturnType<typeof crypto.randomUUID>;
|
|
@@ -899,24 +683,6 @@ interface OutboxMessage {
|
|
|
899
683
|
readonly circuitHeldSince?: string;
|
|
900
684
|
readonly traceContext: Readonly<Record<string, string>>;
|
|
901
685
|
}
|
|
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
|
-
}
|
|
920
686
|
interface InboxMessage {
|
|
921
687
|
readonly type: "inbox";
|
|
922
688
|
readonly id: ReturnType<typeof crypto.randomUUID>;
|
|
@@ -964,6 +730,70 @@ interface InboxMessage {
|
|
|
964
730
|
readonly traceContext: Readonly<Record<string, string>>;
|
|
965
731
|
}
|
|
966
732
|
//#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
|
|
967
797
|
//#region src/federation/middleware.d.ts
|
|
968
798
|
/**
|
|
969
799
|
* Configures the task queues for sending and receiving activities.
|
|
@@ -987,13 +817,6 @@ interface FederationQueueOptions {
|
|
|
987
817
|
* {@link Context.sendActivity} calls.
|
|
988
818
|
*/
|
|
989
819
|
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;
|
|
997
820
|
}
|
|
998
821
|
/**
|
|
999
822
|
* Prefixes for namespacing keys in the Deno KV store.
|
|
@@ -1037,14 +860,6 @@ interface FederationKvPrefixes {
|
|
|
1037
860
|
* @since 2.3.0
|
|
1038
861
|
*/
|
|
1039
862
|
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;
|
|
1048
863
|
}
|
|
1049
864
|
/**
|
|
1050
865
|
* Options for {@link FederationOptions.origin} when it is not a string.
|
|
@@ -1086,18 +901,18 @@ interface FederationStartQueueOptions {
|
|
|
1086
901
|
signal?: AbortSignal;
|
|
1087
902
|
/**
|
|
1088
903
|
* Starts the task worker only for the specified queue. If unspecified,
|
|
1089
|
-
* which is the default, the task worker starts for all
|
|
1090
|
-
* inbox, outbox,
|
|
904
|
+
* which is the default, the task worker starts for all three queues:
|
|
905
|
+
* inbox, outbox, and fanout.
|
|
1091
906
|
* @since 1.3.0
|
|
1092
907
|
*/
|
|
1093
|
-
queue?: "inbox" | "outbox" | "fanout"
|
|
908
|
+
queue?: "inbox" | "outbox" | "fanout";
|
|
1094
909
|
}
|
|
1095
910
|
/**
|
|
1096
911
|
* A common interface between {@link Federation} and {@link FederationBuilder}.
|
|
1097
912
|
* @template TContextData The context data to pass to the {@link Context}.
|
|
1098
913
|
* @since 1.6.0
|
|
1099
914
|
*/
|
|
1100
|
-
interface Federatable<TContextData>
|
|
915
|
+
interface Federatable<TContextData> {
|
|
1101
916
|
/**
|
|
1102
917
|
* Registers a NodeInfo dispatcher.
|
|
1103
918
|
* @param path The URI path pattern for the NodeInfo dispatcher. The syntax
|
|
@@ -1804,50 +1619,6 @@ interface FederationOptions<TContextData> {
|
|
|
1804
1619
|
*/
|
|
1805
1620
|
inboxRetryPolicy?: RetryPolicy;
|
|
1806
1621
|
/**
|
|
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
|
-
/**
|
|
1851
1622
|
* Activity transformers that are applied to outgoing activities. It is
|
|
1852
1623
|
* useful for adjusting outgoing activities to satisfy some ActivityPub
|
|
1853
1624
|
* implementations.
|
|
@@ -2600,48 +2371,6 @@ interface Context<TContextData> {
|
|
|
2600
2371
|
*/
|
|
2601
2372
|
routeActivity(recipient: string | null, activity: Activity, options?: RouteActivityOptions): Promise<boolean>;
|
|
2602
2373
|
/**
|
|
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
|
-
/**
|
|
2645
2374
|
* Builds the URI of a collection of objects with the given name and values.
|
|
2646
2375
|
* @param name The name of the collection, which can be a string or a symbol.
|
|
2647
2376
|
* @param values The values of the URI parameters.
|
|
@@ -3152,4 +2881,4 @@ interface ActorKeyPair extends CryptoKeyPair {
|
|
|
3152
2881
|
readonly multikey: Multikey;
|
|
3153
2882
|
}
|
|
3154
2883
|
//#endregion
|
|
3155
|
-
export {
|
|
2884
|
+
export { CustomCollectionCursor as $, Rfc6570Expression as A, parseCircuitBreakerKvState as At, createFederationBuilder as B, FederationStartQueueOptions as C, CircuitBreakerFailurePolicy as Ct, InboxListenerSetters as D, CircuitBreakerStateChange as Dt, InboxChallengePolicy as E, CircuitBreakerState as Et, CreateExponentialBackoffPolicyOptions as F, ActorDispatcher as G, respondWithObject as H, RetryContext as I, AuthorizePredicate as J, ActorHandleMapper as K, RetryPolicy as L, FederationOrigin as M, FederationQueueOptions as N, ObjectCallbackSetters as O, NormalizedCircuitBreakerOptions as Ot, createFederation as P, CustomCollectionCounter as Q, createExponentialBackoffPolicy as R, FederationOptions as S, CircuitBreakerCreateOptions as St, IdempotencyStrategy as T, CircuitBreakerOptions as Tt, respondWithObjectIfAcceptable as U, RespondWithObjectOptions as V, ActorAliasMapper as W, CollectionCursor as X, CollectionCounter as Y, CollectionDispatcher as Z, Federatable as _, buildCollectionSynchronizationHeader as _t, GetSignedKeyOptions as a, ObjectDispatcher as at, FederationBuilder as b, CircuitBreakerActivityDrop as bt, ParseUriResult as c, OutboxListenerErrorHandler as ct, SendActivityOptions as d, UnverifiedActivityHandler as dt, CustomCollectionDispatcher as et, SendActivityOptionsForCollection as f, UnverifiedActivityReason as ft, CustomCollectionCallbackSetters as g, PageItems as gt, ConstructorWithTypeId as h, SenderKeyPair as ht, GetActorOptions as i, ObjectAuthorizePredicate as it, FederationKvPrefixes as j, ActivityTransformer as jt, OutboxListenerSetters as k, normalizeCircuitBreakerOptions as kt, RequestContext as l, OutboxPermanentFailureHandler as lt, CollectionCallbackSetters as m, SendActivityError as mt, Context as n, InboxListener as nt, InboxContext as o, OutboxErrorHandler as ot, ActorCallbackSetters as p, WebFingerLinksDispatcher as pt, ActorKeyPairsDispatcher as q, ForwardActivityOptions as r, NodeInfoDispatcher as rt, OutboxContext as s, OutboxListener as st, ActorKeyPair as t, InboxErrorHandler as tt, RouteActivityOptions as u, SharedInboxKeyDispatcher as ut, Federation as v, digest as vt, IdempotencyKeyCallback as w, CircuitBreakerKvState as wt, FederationFetchOptions as x, CircuitBreakerBeforeSendDecision as xt, FederationBenchmarkOptions as y, CircuitBreaker as yt, Message as z };
|