@fedify/fedify 2.3.0 → 2.4.0-dev.1422
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-OguE97r2.mjs → assert-DikXweDx.mjs} +1 -1
- package/dist/{assert_instance_of-DBC5X09g.mjs → assert_instance_of-C4Ri6VuN.mjs} +1 -1
- package/dist/{assert_not_equals-DkVK8oqV.mjs → assert_not_equals--wG9hV7u.mjs} +1 -1
- package/dist/{assert_rejects-DN60FHPX.mjs → assert_rejects-DQP-q39h.mjs} +2 -2
- package/dist/{assert_strict_equals-XEgZAlrj.mjs → assert_strict_equals-Dmjbg-bA.mjs} +1 -1
- package/dist/{assert_throws-BOkhLGYc.mjs → assert_throws-4NwKEy2q.mjs} +1 -1
- package/dist/{builder-DYXTKqvC.mjs → builder-Gef_ZeDE.mjs} +23 -3
- package/dist/codec-Bf-rTqks.mjs +94 -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-BrIOaBSs.mjs} +7 -1
- package/dist/{context-BBVLF7lx.d.cts → context-BuGH_Vft.d.cts} +286 -70
- package/dist/{context-BU6jSQdo.d.ts → context-CLtZxCu6.d.ts} +285 -70
- package/dist/{deno-ChfuM30K.mjs → deno-BmD7XRaO.mjs} +1 -1
- package/dist/{docloader-Bu-Oecom.mjs → docloader-B8AJowCx.mjs} +2 -2
- 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 +1 -1
- package/dist/federation/mod.d.cts +3 -3
- package/dist/federation/mod.d.ts +3 -3
- package/dist/federation/mod.js +1 -1
- package/dist/federation/mq.test.mjs +5 -260
- 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/tasks.test.d.mts +2 -0
- package/dist/federation/tasks/tasks.test.mjs +651 -0
- package/dist/federation/temporal.test.mjs +4 -4
- package/dist/federation/webfinger.test.mjs +6 -6
- package/dist/{http-Q2nW0DHO.cjs → http-BCSQJ_gv.cjs} +1 -1
- package/dist/{http-CiPBp7Ax.js → http-CJ0WNyqA.js} +1 -1
- package/dist/{http-Cm_e9dY7.mjs → http-GQoPA_YT.mjs} +4 -4
- package/dist/{key-nrqRBwjx.mjs → key-BLy_TeTg.mjs} +2 -2
- package/dist/{kv-cache-BQLjC1KN.js → kv-cache-CjEcb9qH.js} +1 -1
- package/dist/{kv-cache-QkLiue07.cjs → kv-cache-DXwu7BtY.cjs} +1 -1
- package/dist/{kv-cache-B3Na5DMI.mjs → kv-cache-pw-kBdVz.mjs} +1 -1
- package/dist/{ld-CaRoGhYH.mjs → ld-CWgxPlZq.mjs} +3 -3
- package/dist/{metrics-BSUZSyQU.mjs → metrics-DUKoLd_E.mjs} +1 -1
- package/dist/{middleware-BIj0BBxb.js → middleware-2Us0G3Iy.js} +277 -10
- package/dist/{middleware-DXLo-UOS.cjs → middleware-BiCk4wGY.cjs} +277 -10
- package/dist/{middleware-BIctkZ9S.mjs → middleware-Dq-HhJHd.mjs} +1 -1
- package/dist/{middleware-CwJv5KxX.mjs → middleware-PZaroDUk.mjs} +182 -23
- package/dist/{mod-C0F6kvgS.d.cts → mod-DRokcHeU.d.cts} +1 -1
- package/dist/{mod-vPYVoa5n.d.ts → mod-r-1xOW_C.d.ts} +1 -1
- package/dist/mod.cjs +4 -4
- package/dist/mod.d.cts +4 -4
- package/dist/mod.d.ts +4 -4
- package/dist/mod.js +4 -4
- package/dist/mq-CvJAzRz5.mjs +260 -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-BgFLCJQ_.mjs} +1 -1
- package/dist/{owner-CyK8YW7-.mjs → owner-U0Z8Ex6i.mjs} +2 -2
- package/dist/{proof-CIUSLcHg.cjs → proof-DA3hLGSO.cjs} +1 -1
- package/dist/{proof-Ba14ORbL.js → proof-f7K32nz7.js} +1 -1
- package/dist/{proof-DXHo4Yon.mjs → proof-nb5tfciW.mjs} +5 -5
- package/dist/{send-B4Ld91pX.mjs → send-CLfW5Fdf.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-BBjXFNOb.mjs → std__assert-BTEgfoJo.mjs} +4 -4
- package/dist/{temporal-E7cF2Hsh.mjs → temporal-2ry_jdCK.mjs} +1 -1
- package/dist/testing/mod.d.mts +378 -7
- package/dist/testing/mod.mjs +3 -2
- package/dist/testing-CjYPStvE.mjs +55 -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 +8 -6
- /package/dist/{accept-CPkZzmGN.mjs → accept-CceiKpCy.mjs} +0 -0
- /package/dist/{activity-listener-tztVvlNb.mjs → activity-listener-BeTGV3wc.mjs} +0 -0
- /package/dist/{assert_equals-C-ZRDbaf.mjs → assert_equals-Ew3jOFa3.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-C3kae-6B.mjs} +0 -0
- /package/dist/{kv-rV3vodCc.mjs → kv-x2IvBUyq.mjs} +0 -0
- /package/dist/{negotiation-DDstyBvc.mjs → negotiation-m_L2nyS3.mjs} +0 -0
- /package/dist/{public-audience-Cvbr2Gzt.mjs → public-audience-N3pyOx2p.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
|
@@ -8,6 +8,8 @@ import { Activity, Actor, Collection, CryptographicKey, Hashtag, Link, LookupObj
|
|
|
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.
|
|
@@ -607,6 +609,201 @@ 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.x.x
|
|
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.x.x
|
|
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.x.x
|
|
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.x.x
|
|
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.x.x
|
|
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
|
+
//#endregion
|
|
610
807
|
//#region src/federation/builder.d.ts
|
|
611
808
|
/**
|
|
612
809
|
* Creates a new {@link FederationBuilder} instance.
|
|
@@ -629,7 +826,7 @@ interface SenderKeyJwkPair {
|
|
|
629
826
|
* type.
|
|
630
827
|
* @since 1.6.0
|
|
631
828
|
*/
|
|
632
|
-
type Message = FanoutMessage | OutboxMessage | InboxMessage;
|
|
829
|
+
type Message = FanoutMessage | OutboxMessage | InboxMessage | TaskMessage;
|
|
633
830
|
interface FanoutMessage {
|
|
634
831
|
readonly type: "fanout";
|
|
635
832
|
readonly id: ReturnType<typeof crypto.randomUUID>;
|
|
@@ -683,6 +880,24 @@ interface OutboxMessage {
|
|
|
683
880
|
readonly circuitHeldSince?: string;
|
|
684
881
|
readonly traceContext: Readonly<Record<string, string>>;
|
|
685
882
|
}
|
|
883
|
+
/**
|
|
884
|
+
* A message that carries a custom background task. Every field is
|
|
885
|
+
* a string, number, or plain record so that the message survives both
|
|
886
|
+
* JSON serialization and structured clone on every queue backend.
|
|
887
|
+
* @since 2.x.x
|
|
888
|
+
*/
|
|
889
|
+
interface TaskMessage {
|
|
890
|
+
readonly type: "task";
|
|
891
|
+
readonly id: ReturnType<typeof crypto.randomUUID>;
|
|
892
|
+
readonly baseUrl: string;
|
|
893
|
+
readonly taskName: string;
|
|
894
|
+
/** devalue-encoded task data; vocab objects bridged to expanded JSON-LD. */
|
|
895
|
+
readonly data: string;
|
|
896
|
+
readonly started: string;
|
|
897
|
+
readonly attempt: number;
|
|
898
|
+
readonly orderingKey?: string;
|
|
899
|
+
readonly traceContext: Readonly<Record<string, string>>;
|
|
900
|
+
}
|
|
686
901
|
interface InboxMessage {
|
|
687
902
|
readonly type: "inbox";
|
|
688
903
|
readonly id: ReturnType<typeof crypto.randomUUID>;
|
|
@@ -730,70 +945,6 @@ interface InboxMessage {
|
|
|
730
945
|
readonly traceContext: Readonly<Record<string, string>>;
|
|
731
946
|
}
|
|
732
947
|
//#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
948
|
//#region src/federation/middleware.d.ts
|
|
798
949
|
/**
|
|
799
950
|
* Configures the task queues for sending and receiving activities.
|
|
@@ -817,6 +968,13 @@ interface FederationQueueOptions {
|
|
|
817
968
|
* {@link Context.sendActivity} calls.
|
|
818
969
|
*/
|
|
819
970
|
readonly fanout?: MessageQueue;
|
|
971
|
+
/**
|
|
972
|
+
* The message queue for custom background tasks. If not provided,
|
|
973
|
+
* tasks are routed to the outbox queue (unless
|
|
974
|
+
* {@link FederationOptions.taskQueueResolution} is `"strict"`).
|
|
975
|
+
* @since 2.x.x
|
|
976
|
+
*/
|
|
977
|
+
readonly task?: MessageQueue;
|
|
820
978
|
}
|
|
821
979
|
/**
|
|
822
980
|
* Prefixes for namespacing keys in the Deno KV store.
|
|
@@ -901,18 +1059,18 @@ interface FederationStartQueueOptions {
|
|
|
901
1059
|
signal?: AbortSignal;
|
|
902
1060
|
/**
|
|
903
1061
|
* 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
|
|
1062
|
+
* which is the default, the task worker starts for all four queues:
|
|
1063
|
+
* inbox, outbox, fanout, and task.
|
|
906
1064
|
* @since 1.3.0
|
|
907
1065
|
*/
|
|
908
|
-
queue?: "inbox" | "outbox" | "fanout";
|
|
1066
|
+
queue?: "inbox" | "outbox" | "fanout" | "task";
|
|
909
1067
|
}
|
|
910
1068
|
/**
|
|
911
1069
|
* A common interface between {@link Federation} and {@link FederationBuilder}.
|
|
912
1070
|
* @template TContextData The context data to pass to the {@link Context}.
|
|
913
1071
|
* @since 1.6.0
|
|
914
1072
|
*/
|
|
915
|
-
interface Federatable<TContextData> {
|
|
1073
|
+
interface Federatable<TContextData> extends TaskRegistry<TContextData> {
|
|
916
1074
|
/**
|
|
917
1075
|
* Registers a NodeInfo dispatcher.
|
|
918
1076
|
* @param path The URI path pattern for the NodeInfo dispatcher. The syntax
|
|
@@ -1619,6 +1777,26 @@ interface FederationOptions<TContextData> {
|
|
|
1619
1777
|
*/
|
|
1620
1778
|
inboxRetryPolicy?: RetryPolicy;
|
|
1621
1779
|
/**
|
|
1780
|
+
* The retry policy for processing custom background tasks. By default,
|
|
1781
|
+
* this uses an exponential backoff strategy with a maximum of 10 attempts
|
|
1782
|
+
* and a maximum delay of 12 hours. A per-task retry policy
|
|
1783
|
+
* ({@link TaskDefinitionOptions.retryPolicy}) overrides this.
|
|
1784
|
+
* @since 2.x.x
|
|
1785
|
+
*/
|
|
1786
|
+
taskRetryPolicy?: RetryPolicy;
|
|
1787
|
+
/**
|
|
1788
|
+
* How a queue is resolved for a custom background task when neither
|
|
1789
|
+
* a per-task queue ({@link TaskDefinitionOptions.queue}) nor a dedicated
|
|
1790
|
+
* task queue ({@link FederationQueueOptions.task}) is configured.
|
|
1791
|
+
*
|
|
1792
|
+
* - `"fallback"` (the default): the task is routed to the outbox queue.
|
|
1793
|
+
* - `"strict"`: no fallback; enqueuing the task throws instead of
|
|
1794
|
+
* silently sharing the outbox queue.
|
|
1795
|
+
* @default `"fallback"`
|
|
1796
|
+
* @since 2.x.x
|
|
1797
|
+
*/
|
|
1798
|
+
taskQueueResolution?: "fallback" | "strict";
|
|
1799
|
+
/**
|
|
1622
1800
|
* Activity transformers that are applied to outgoing activities. It is
|
|
1623
1801
|
* useful for adjusting outgoing activities to satisfy some ActivityPub
|
|
1624
1802
|
* implementations.
|
|
@@ -2371,6 +2549,44 @@ interface Context<TContextData> {
|
|
|
2371
2549
|
*/
|
|
2372
2550
|
routeActivity(recipient: string | null, activity: Activity, options?: RouteActivityOptions): Promise<boolean>;
|
|
2373
2551
|
/**
|
|
2552
|
+
* Enqueues a custom background task. The payload is validated against
|
|
2553
|
+
* the task's schema, serialized, and processed by the task's handler on
|
|
2554
|
+
* a background worker.
|
|
2555
|
+
*
|
|
2556
|
+
* @example
|
|
2557
|
+
* ``` typescript
|
|
2558
|
+
* await ctx.enqueueTask(sendDigest, { userId: "alice" });
|
|
2559
|
+
* ```
|
|
2560
|
+
*
|
|
2561
|
+
* @template TData The type of the task payload, inferred from the task's
|
|
2562
|
+
* schema.
|
|
2563
|
+
* @param task The handle returned by {@link TaskRegistry.defineTask}.
|
|
2564
|
+
* @param data The task payload. It is validated against the task's
|
|
2565
|
+
* schema before being enqueued.
|
|
2566
|
+
* @param options Options for enqueuing the task.
|
|
2567
|
+
* @throws {TypeError} If the task is not defined on this federation,
|
|
2568
|
+
* if no message queue is configured for tasks, or if
|
|
2569
|
+
* the payload fails schema validation.
|
|
2570
|
+
* @since 2.x.x
|
|
2571
|
+
*/
|
|
2572
|
+
enqueueTask<TData>(task: TaskDefinition<TContextData, TData>, data: TData, options?: TaskEnqueueOptions): Promise<void>;
|
|
2573
|
+
/**
|
|
2574
|
+
* Enqueues multiple payloads for a custom background task at once.
|
|
2575
|
+
* Uses the queue's bulk enqueue operation when available, falling back
|
|
2576
|
+
* to parallel single enqueues.
|
|
2577
|
+
* @template TData The type of the task payload, inferred from the task's
|
|
2578
|
+
* schema.
|
|
2579
|
+
* @param task The handle returned by {@link TaskRegistry.defineTask}.
|
|
2580
|
+
* @param payloads The task payloads. Each is validated against the
|
|
2581
|
+
* task's schema before being enqueued.
|
|
2582
|
+
* @param options Options for enqueuing the tasks.
|
|
2583
|
+
* @throws {TypeError} If the task is not defined on this federation,
|
|
2584
|
+
* if no message queue is configured for tasks, or if
|
|
2585
|
+
* a payload fails schema validation.
|
|
2586
|
+
* @since 2.x.x
|
|
2587
|
+
*/
|
|
2588
|
+
enqueueTaskMany<TData>(task: TaskDefinition<TContextData, TData>, payloads: readonly TData[], options?: TaskEnqueueOptions): Promise<void>;
|
|
2589
|
+
/**
|
|
2374
2590
|
* Builds the URI of a collection of objects with the given name and values.
|
|
2375
2591
|
* @param name The name of the collection, which can be a string or a symbol.
|
|
2376
2592
|
* @param values The values of the URI parameters.
|
|
@@ -2881,4 +3097,4 @@ interface ActorKeyPair extends CryptoKeyPair {
|
|
|
2881
3097
|
readonly multikey: Multikey;
|
|
2882
3098
|
}
|
|
2883
3099
|
//#endregion
|
|
2884
|
-
export {
|
|
3100
|
+
export { AuthorizePredicate as $, Rfc6570Expression as A, CircuitBreakerOptions as At, TaskHandler as B, FederationStartQueueOptions as C, digest as Ct, InboxListenerSetters as D, CircuitBreakerCreateOptions as Dt, InboxChallengePolicy as E, CircuitBreakerBeforeSendDecision as Et, Message as F, parseCircuitBreakerKvState 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, CircuitBreakerStateChange as Mt, FederationQueueOptions as N, NormalizedCircuitBreakerOptions as Nt, ObjectCallbackSetters as O, CircuitBreakerFailurePolicy as Ot, createFederation as P, normalizeCircuitBreakerOptions as Pt, ActorKeyPairsDispatcher as Q, TaskDefinitionOptions as R, FederationOptions as S, buildCollectionSynchronizationHeader as St, IdempotencyStrategy as T, CircuitBreakerActivityDrop as Tt, RetryContext as U, TaskRegistry as V, RetryPolicy as W, ActorDispatcher as X, ActorAliasMapper as Y, ActorHandleMapper as Z, Federatable as _, UnverifiedActivityReason as _t, GetSignedKeyOptions as a, CustomCollectionDispatcher as at, FederationBuilder as b, SenderKeyPair as bt, ParseUriResult as c, NodeInfoDispatcher as ct, SendActivityOptions as d, OutboxErrorHandler as dt, CollectionCounter as et, SendActivityOptionsForCollection as f, OutboxListener as ft, CustomCollectionCallbackSetters as g, UnverifiedActivityHandler as gt, ConstructorWithTypeId as h, SharedInboxKeyDispatcher as ht, GetActorOptions as i, CustomCollectionCursor as it, FederationKvPrefixes as j, CircuitBreakerState as jt, OutboxListenerSetters as k, CircuitBreakerKvState as kt, RequestContext as l, ObjectAuthorizePredicate as lt, CollectionCallbackSetters as m, OutboxPermanentFailureHandler as mt, Context as n, CollectionDispatcher as nt, InboxContext as o, InboxErrorHandler as ot, ActorCallbackSetters as p, OutboxListenerErrorHandler as pt, respondWithObject as q, ForwardActivityOptions as r, CustomCollectionCounter as rt, OutboxContext as s, InboxListener as st, ActorKeyPair as t, CollectionCursor as tt, RouteActivityOptions as u, ObjectDispatcher as ut, Federation as v, WebFingerLinksDispatcher as vt, IdempotencyKeyCallback as w, CircuitBreaker as wt, FederationFetchOptions as x, PageItems as xt, FederationBenchmarkOptions as y, SendActivityError as yt, TaskEnqueueOptions as z };
|