@fedify/fedify 2.4.0-dev.1417 → 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.
Files changed (104) hide show
  1. package/dist/{assert-OguE97r2.mjs → assert-DikXweDx.mjs} +1 -1
  2. package/dist/{assert_instance_of-DBC5X09g.mjs → assert_instance_of-C4Ri6VuN.mjs} +1 -1
  3. package/dist/{assert_not_equals-DkVK8oqV.mjs → assert_not_equals--wG9hV7u.mjs} +1 -1
  4. package/dist/{assert_rejects-DN60FHPX.mjs → assert_rejects-DQP-q39h.mjs} +2 -2
  5. package/dist/{assert_strict_equals-XEgZAlrj.mjs → assert_strict_equals-Dmjbg-bA.mjs} +1 -1
  6. package/dist/{assert_throws-BOkhLGYc.mjs → assert_throws-4NwKEy2q.mjs} +1 -1
  7. package/dist/{builder-CU98OOiD.mjs → builder-Gef_ZeDE.mjs} +23 -3
  8. package/dist/codec-Bf-rTqks.mjs +94 -0
  9. package/dist/compat/mod.d.cts +1 -1
  10. package/dist/compat/mod.d.ts +1 -1
  11. package/dist/compat/outgoing-jsonld.test.mjs +3 -3
  12. package/dist/compat/public-audience.test.mjs +3 -3
  13. package/dist/compat/transformers.test.mjs +5 -5
  14. package/dist/{context-DVoTs_wM.mjs → context-BrIOaBSs.mjs} +7 -1
  15. package/dist/{context-BBVLF7lx.d.cts → context-BuGH_Vft.d.cts} +286 -70
  16. package/dist/{context-BU6jSQdo.d.ts → context-CLtZxCu6.d.ts} +285 -70
  17. package/dist/{deno-Dhn909W6.mjs → deno-BmD7XRaO.mjs} +1 -1
  18. package/dist/{docloader-CX8Auxrr.mjs → docloader-B8AJowCx.mjs} +2 -2
  19. package/dist/federation/builder.test.mjs +5 -5
  20. package/dist/federation/circuit-breaker.test.mjs +5 -5
  21. package/dist/federation/collection.test.mjs +3 -3
  22. package/dist/federation/handler.test.mjs +13 -13
  23. package/dist/federation/idempotency.test.mjs +6 -6
  24. package/dist/federation/inbox.test.mjs +3 -3
  25. package/dist/federation/keycache.test.mjs +5 -5
  26. package/dist/federation/kv.test.mjs +3 -3
  27. package/dist/federation/metrics.test.mjs +4 -4
  28. package/dist/federation/middleware.test.mjs +200 -19
  29. package/dist/federation/mod.cjs +1 -1
  30. package/dist/federation/mod.d.cts +3 -3
  31. package/dist/federation/mod.d.ts +3 -3
  32. package/dist/federation/mod.js +1 -1
  33. package/dist/federation/mq.test.mjs +5 -260
  34. package/dist/federation/negotiation.test.mjs +4 -4
  35. package/dist/federation/retry.test.mjs +3 -3
  36. package/dist/federation/router.test.mjs +5 -5
  37. package/dist/federation/send.test.mjs +10 -10
  38. package/dist/federation/tasks/codec.test.d.mts +2 -0
  39. package/dist/federation/tasks/codec.test.mjs +292 -0
  40. package/dist/federation/tasks/tasks.test.d.mts +2 -0
  41. package/dist/federation/tasks/tasks.test.mjs +651 -0
  42. package/dist/federation/temporal.test.mjs +4 -4
  43. package/dist/federation/webfinger.test.mjs +6 -6
  44. package/dist/{http-CsSSDB5j.cjs → http-BCSQJ_gv.cjs} +1 -1
  45. package/dist/{http-DndWw3Rs.js → http-CJ0WNyqA.js} +1 -1
  46. package/dist/{http-iapcKTk-.mjs → http-GQoPA_YT.mjs} +4 -4
  47. package/dist/{key-b17Uu8wX.mjs → key-BLy_TeTg.mjs} +2 -2
  48. package/dist/{kv-cache-CLo3nRjl.js → kv-cache-CjEcb9qH.js} +1 -1
  49. package/dist/{kv-cache-BIngyLxt.cjs → kv-cache-DXwu7BtY.cjs} +1 -1
  50. package/dist/{kv-cache-DcsWACki.mjs → kv-cache-pw-kBdVz.mjs} +1 -1
  51. package/dist/{ld-B1503hdI.mjs → ld-CWgxPlZq.mjs} +3 -3
  52. package/dist/{metrics-DSV9HQUk.mjs → metrics-DUKoLd_E.mjs} +1 -1
  53. package/dist/{middleware-DT5sfJam.js → middleware-2Us0G3Iy.js} +277 -10
  54. package/dist/{middleware-DA8JjaXv.cjs → middleware-BiCk4wGY.cjs} +277 -10
  55. package/dist/{middleware-Bb9gR5Ro.mjs → middleware-Dq-HhJHd.mjs} +1 -1
  56. package/dist/{middleware-Dh1xDMbI.mjs → middleware-PZaroDUk.mjs} +182 -23
  57. package/dist/{mod-C0F6kvgS.d.cts → mod-DRokcHeU.d.cts} +1 -1
  58. package/dist/{mod-vPYVoa5n.d.ts → mod-r-1xOW_C.d.ts} +1 -1
  59. package/dist/mod.cjs +4 -4
  60. package/dist/mod.d.cts +4 -4
  61. package/dist/mod.d.ts +4 -4
  62. package/dist/mod.js +4 -4
  63. package/dist/mq-CvJAzRz5.mjs +260 -0
  64. package/dist/nodeinfo/client.test.mjs +3 -3
  65. package/dist/nodeinfo/handler.test.mjs +5 -5
  66. package/dist/nodeinfo/types.test.mjs +4 -4
  67. package/dist/otel/exporter.test.mjs +3 -3
  68. package/dist/{outgoing-jsonld-L_DbOaFe.mjs → outgoing-jsonld-BgFLCJQ_.mjs} +1 -1
  69. package/dist/{owner-PCw-OkL0.mjs → owner-U0Z8Ex6i.mjs} +2 -2
  70. package/dist/{proof-CJCLdaV3.cjs → proof-DA3hLGSO.cjs} +1 -1
  71. package/dist/{proof-BhbSD4bP.js → proof-f7K32nz7.js} +1 -1
  72. package/dist/{proof-Dacxh41h.mjs → proof-nb5tfciW.mjs} +5 -5
  73. package/dist/{send-Cdsbc_Vj.mjs → send-CLfW5Fdf.mjs} +3 -3
  74. package/dist/sig/accept.test.mjs +1 -1
  75. package/dist/sig/http.test.mjs +8 -8
  76. package/dist/sig/key.test.mjs +6 -6
  77. package/dist/sig/ld.test.mjs +7 -7
  78. package/dist/sig/mod.cjs +2 -2
  79. package/dist/sig/mod.js +2 -2
  80. package/dist/sig/owner.test.mjs +6 -6
  81. package/dist/sig/proof.test.mjs +8 -8
  82. package/dist/{std__assert-BBjXFNOb.mjs → std__assert-BTEgfoJo.mjs} +4 -4
  83. package/dist/{temporal-BMMqjhOp.mjs → temporal-2ry_jdCK.mjs} +1 -1
  84. package/dist/testing/mod.d.mts +378 -7
  85. package/dist/testing/mod.mjs +3 -2
  86. package/dist/testing-CjYPStvE.mjs +55 -0
  87. package/dist/utils/docloader.test.mjs +6 -6
  88. package/dist/utils/kv-cache.test.mjs +1 -1
  89. package/dist/utils/mod.cjs +1 -1
  90. package/dist/utils/mod.js +1 -1
  91. package/package.json +9 -7
  92. /package/dist/{accept-CPkZzmGN.mjs → accept-CceiKpCy.mjs} +0 -0
  93. /package/dist/{activity-listener-tztVvlNb.mjs → activity-listener-BeTGV3wc.mjs} +0 -0
  94. /package/dist/{assert_equals-C-ZRDbaf.mjs → assert_equals-Ew3jOFa3.mjs} +0 -0
  95. /package/dist/{circuit-breaker-CSWsyoef.mjs → circuit-breaker-hJBB6jwA.mjs} +0 -0
  96. /package/dist/{client-ByXmQhYD.mjs → client-B_A6mfn3.mjs} +0 -0
  97. /package/dist/{collection-Cc3DVAhE.mjs → collection-Dp5ky45w.mjs} +0 -0
  98. /package/dist/{keycache-BeU0LCII.mjs → keycache-CaOR6NYg.mjs} +0 -0
  99. /package/dist/{keys-DGu1NFwu.mjs → keys-C3kae-6B.mjs} +0 -0
  100. /package/dist/{kv-rV3vodCc.mjs → kv-x2IvBUyq.mjs} +0 -0
  101. /package/dist/{negotiation-DDstyBvc.mjs → negotiation-m_L2nyS3.mjs} +0 -0
  102. /package/dist/{public-audience-Cvbr2Gzt.mjs → public-audience-N3pyOx2p.mjs} +0 -0
  103. /package/dist/{retry-CXg_MBI-.mjs → retry-DI4O-zYl.mjs} +0 -0
  104. /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
@@ -10,6 +10,7 @@ import { MeterProvider, Span, Tracer, TracerProvider } from "@opentelemetry/api"
10
10
  import { AuthenticatedDocumentLoaderFactory, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions } from "@fedify/vocab-runtime";
11
11
  import { Link as Link$1, LookupWebFingerOptions, ResourceDescriptor } from "@fedify/webfinger";
12
12
  import { MeterProvider as MeterProvider$1, MetricReader } from "@opentelemetry/sdk-metrics";
13
+ import { StandardSchemaV1 } from "@standard-schema/spec";
13
14
 
14
15
  //#region src/compat/types.d.ts
15
16
  /**
@@ -610,6 +611,201 @@ declare function respondWithObject(object: Object$1, options?: RespondWithObject
610
611
  */
611
612
  declare function respondWithObjectIfAcceptable(object: Object$1, request: Request, options?: RespondWithObjectOptions): Promise<Response | null>;
612
613
  //#endregion
614
+ //#region src/federation/retry.d.ts
615
+ /**
616
+ * The context passed to a {@link RetryPolicy} callback.
617
+ * @since 0.12.0
618
+ */
619
+ interface RetryContext {
620
+ /**
621
+ * The elapsed time since the first attempt.
622
+ */
623
+ readonly elapsedTime: Temporal.Duration;
624
+ /**
625
+ * The number of attempts so far.
626
+ */
627
+ readonly attempts: number;
628
+ }
629
+ /**
630
+ * A policy that determines the delay before the next retry.
631
+ * @param context The retry context.
632
+ * @returns The delay before the next retry, or `null` to stop retrying.
633
+ * It must not negative.
634
+ * @since 0.12.0
635
+ */
636
+ type RetryPolicy = (context: RetryContext) => Temporal.Duration | null;
637
+ /**
638
+ * Options for {@link createExponentialBackoffPolicy} function.
639
+ * @since 0.12.0
640
+ */
641
+ interface CreateExponentialBackoffPolicyOptions {
642
+ /**
643
+ * The initial delay before the first retry. Defaults to 1 second.
644
+ */
645
+ readonly initialDelay?: Temporal.DurationLike;
646
+ /**
647
+ * The maximum delay between retries. Defaults to 12 hours.
648
+ */
649
+ readonly maxDelay?: Temporal.DurationLike;
650
+ /**
651
+ * The maximum number of attempts before giving up.
652
+ * Defaults to 10.
653
+ */
654
+ readonly maxAttempts?: number;
655
+ /**
656
+ * The factor to multiply the previous delay by for each retry.
657
+ * Defaults to 2.
658
+ */
659
+ readonly factor?: number;
660
+ /**
661
+ * Whether to add jitter to the delay to avoid synchronization.
662
+ * Turned on by default.
663
+ */
664
+ readonly jitter?: boolean;
665
+ }
666
+ /**
667
+ * Creates an exponential backoff retry policy. The delay between retries
668
+ * starts at the `initialDelay` and is multiplied by the `factor` for each
669
+ * subsequent retry, up to the `maxDelay`. The policy will give up after
670
+ * `maxAttempts` attempts. The actual delay is randomized to avoid
671
+ * synchronization (jitter).
672
+ * @param options The options for the policy.
673
+ * @returns The retry policy.
674
+ * @since 0.12.0
675
+ */
676
+ declare function createExponentialBackoffPolicy(options?: CreateExponentialBackoffPolicyOptions): RetryPolicy;
677
+ //#endregion
678
+ //#region src/federation/tasks/task.d.ts
679
+ /**
680
+ * A callback that processes a custom background task.
681
+ * @template TContextData The context data to pass to the {@link Context}.
682
+ * @template TData The type of the task payload, inferred from the task's
683
+ * schema.
684
+ * @param ctx The context for the worker processing the task.
685
+ * @param data The decoded and validated task payload.
686
+ * @since 2.x.x
687
+ */
688
+ type TaskHandler<TContextData, TData> = (ctx: Context<TContextData>, data: TData) => Promise<void> | void;
689
+ /**
690
+ * Options for {@link TaskRegistry.defineTask}.
691
+ * @template TContextData The context data to pass to the {@link Context}.
692
+ * @template TSchema The [Standard Schema](https://standardschema.dev/) that
693
+ * validates the task payload.
694
+ * @since 2.x.x
695
+ */
696
+ interface TaskDefinitionOptions<TContextData, TSchema extends StandardSchemaV1> {
697
+ /**
698
+ * The [Standard Schema](https://standardschema.dev/) that validates the
699
+ * task payload. The payload type is inferred from this schema.
700
+ *
701
+ * The payload is validated twice: once at enqueue time (fail fast) and
702
+ * once at dequeue time (drift protection against payloads enqueued by an
703
+ * older deployment). Because the same schema runs on both sides, its
704
+ * validation must be idempotent: the validated output must itself be
705
+ * a valid input. Transforming schemas (e.g., Zod's `.transform()`) whose
706
+ * output differs in shape from their input are not supported.
707
+ */
708
+ readonly schema: TSchema;
709
+ /**
710
+ * The callback that processes the task on a background worker.
711
+ */
712
+ readonly handler: TaskHandler<TContextData, StandardSchemaV1.InferOutput<TSchema>>;
713
+ /**
714
+ * The retry policy for this task. If omitted, the federation-wide
715
+ * task retry policy is used, which defaults to an exponential backoff
716
+ * policy.
717
+ */
718
+ readonly retryPolicy?: RetryPolicy;
719
+ /**
720
+ * A callback invoked when the {@link handler} throws an error, before
721
+ * a retry is scheduled.
722
+ * @param ctx The context for the worker processing the task.
723
+ * @param error The error thrown by the handler.
724
+ * @param data The decoded and validated task payload.
725
+ */
726
+ readonly onError?: (ctx: Context<TContextData>, error: unknown, data: StandardSchemaV1.InferOutput<TSchema>) => Promise<void> | void;
727
+ /**
728
+ * The message queue dedicated to this task. If omitted, the task is
729
+ * routed to the federation-wide task queue, falling back to the outbox
730
+ * queue (unless `taskQueueResolution: "strict"` is configured).
731
+ */
732
+ readonly queue?: MessageQueue;
733
+ }
734
+ /**
735
+ * Phantom key binding a {@link TaskDefinition} to its federation's context
736
+ * data type. Declared only—no value exists at runtime, and the symbol is
737
+ * not exported, so the marker stays out of user-facing completions.
738
+ */
739
+ declare const contextDataBrand: unique symbol;
740
+ /**
741
+ * The handle returned by {@link TaskRegistry.defineTask}. It carries the
742
+ * task name and schema so that {@link Context.enqueueTask} can validate the
743
+ * payload and infer its type at every call site.
744
+ * @template TContextData The context data to pass to the {@link Context}.
745
+ * @template TData The type of the task payload, inferred from the task's
746
+ * schema.
747
+ * @since 2.x.x
748
+ */
749
+ interface TaskDefinition<TContextData, TData> {
750
+ /**
751
+ * The unique name of the task.
752
+ */
753
+ readonly name: string;
754
+ /**
755
+ * The [Standard Schema](https://standardschema.dev/) that validates the
756
+ * task payload.
757
+ */
758
+ readonly schema: StandardSchemaV1<unknown, TData>;
759
+ /**
760
+ * @internal Phantom marker binding the handle to its federation.
761
+ */
762
+ readonly [contextDataBrand]?: TContextData;
763
+ }
764
+ /**
765
+ * Registration of custom background tasks. Both {@link Federation} and
766
+ * {@link FederationBuilder} implement this interface.
767
+ * @template TContextData The context data to pass to the {@link Context}.
768
+ * @since 2.x.x
769
+ */
770
+ interface TaskRegistry<TContextData> {
771
+ /**
772
+ * Defines a custom background task. The returned handle is passed to
773
+ * {@link Context.enqueueTask} to enqueue the task.
774
+ *
775
+ * @example
776
+ * ``` typescript
777
+ * const sendDigest = federation.defineTask("sendDigest", {
778
+ * schema: digestSchema,
779
+ * handler: async (ctx, data) => {
780
+ * // …process the payload on a background worker…
781
+ * },
782
+ * });
783
+ * ```
784
+ *
785
+ * @param name The unique name of the task.
786
+ * @param options The task definition options. The payload type is
787
+ * inferred from `options.schema`.
788
+ * @returns The handle to pass to {@link Context.enqueueTask}.
789
+ * @throws {TypeError} If a task with the same name is already defined.
790
+ */
791
+ defineTask<TSchema extends StandardSchemaV1>(name: string, options: TaskDefinitionOptions<TContextData, TSchema>): TaskDefinition<TContextData, StandardSchemaV1.InferOutput<TSchema>>;
792
+ }
793
+ /**
794
+ * Options for {@link Context.enqueueTask} and {@link Context.enqueueTaskMany}.
795
+ * @since 2.x.x
796
+ */
797
+ interface TaskEnqueueOptions {
798
+ /**
799
+ * The delay before the task is processed. No delay by default.
800
+ */
801
+ readonly delay?: Temporal.DurationLike;
802
+ /**
803
+ * An optional key that ensures tasks with the same ordering key are
804
+ * processed sequentially (one at a time).
805
+ */
806
+ readonly orderingKey?: string;
807
+ }
808
+ //#endregion
613
809
  //#region src/federation/builder.d.ts
614
810
  /**
615
811
  * Creates a new {@link FederationBuilder} instance.
@@ -632,7 +828,7 @@ interface SenderKeyJwkPair {
632
828
  * type.
633
829
  * @since 1.6.0
634
830
  */
635
- type Message = FanoutMessage | OutboxMessage | InboxMessage;
831
+ type Message = FanoutMessage | OutboxMessage | InboxMessage | TaskMessage;
636
832
  interface FanoutMessage {
637
833
  readonly type: "fanout";
638
834
  readonly id: ReturnType<typeof crypto.randomUUID>;
@@ -686,6 +882,24 @@ interface OutboxMessage {
686
882
  readonly circuitHeldSince?: string;
687
883
  readonly traceContext: Readonly<Record<string, string>>;
688
884
  }
885
+ /**
886
+ * A message that carries a custom background task. Every field is
887
+ * a string, number, or plain record so that the message survives both
888
+ * JSON serialization and structured clone on every queue backend.
889
+ * @since 2.x.x
890
+ */
891
+ interface TaskMessage {
892
+ readonly type: "task";
893
+ readonly id: ReturnType<typeof crypto.randomUUID>;
894
+ readonly baseUrl: string;
895
+ readonly taskName: string;
896
+ /** devalue-encoded task data; vocab objects bridged to expanded JSON-LD. */
897
+ readonly data: string;
898
+ readonly started: string;
899
+ readonly attempt: number;
900
+ readonly orderingKey?: string;
901
+ readonly traceContext: Readonly<Record<string, string>>;
902
+ }
689
903
  interface InboxMessage {
690
904
  readonly type: "inbox";
691
905
  readonly id: ReturnType<typeof crypto.randomUUID>;
@@ -733,70 +947,6 @@ interface InboxMessage {
733
947
  readonly traceContext: Readonly<Record<string, string>>;
734
948
  }
735
949
  //#endregion
736
- //#region src/federation/retry.d.ts
737
- /**
738
- * The context passed to a {@link RetryPolicy} callback.
739
- * @since 0.12.0
740
- */
741
- interface RetryContext {
742
- /**
743
- * The elapsed time since the first attempt.
744
- */
745
- readonly elapsedTime: Temporal.Duration;
746
- /**
747
- * The number of attempts so far.
748
- */
749
- readonly attempts: number;
750
- }
751
- /**
752
- * A policy that determines the delay before the next retry.
753
- * @param context The retry context.
754
- * @returns The delay before the next retry, or `null` to stop retrying.
755
- * It must not negative.
756
- * @since 0.12.0
757
- */
758
- type RetryPolicy = (context: RetryContext) => Temporal.Duration | null;
759
- /**
760
- * Options for {@link createExponentialBackoffPolicy} function.
761
- * @since 0.12.0
762
- */
763
- interface CreateExponentialBackoffPolicyOptions {
764
- /**
765
- * The initial delay before the first retry. Defaults to 1 second.
766
- */
767
- readonly initialDelay?: Temporal.DurationLike;
768
- /**
769
- * The maximum delay between retries. Defaults to 12 hours.
770
- */
771
- readonly maxDelay?: Temporal.DurationLike;
772
- /**
773
- * The maximum number of attempts before giving up.
774
- * Defaults to 10.
775
- */
776
- readonly maxAttempts?: number;
777
- /**
778
- * The factor to multiply the previous delay by for each retry.
779
- * Defaults to 2.
780
- */
781
- readonly factor?: number;
782
- /**
783
- * Whether to add jitter to the delay to avoid synchronization.
784
- * Turned on by default.
785
- */
786
- readonly jitter?: boolean;
787
- }
788
- /**
789
- * Creates an exponential backoff retry policy. The delay between retries
790
- * starts at the `initialDelay` and is multiplied by the `factor` for each
791
- * subsequent retry, up to the `maxDelay`. The policy will give up after
792
- * `maxAttempts` attempts. The actual delay is randomized to avoid
793
- * synchronization (jitter).
794
- * @param options The options for the policy.
795
- * @returns The retry policy.
796
- * @since 0.12.0
797
- */
798
- declare function createExponentialBackoffPolicy(options?: CreateExponentialBackoffPolicyOptions): RetryPolicy;
799
- //#endregion
800
950
  //#region src/federation/middleware.d.ts
801
951
  /**
802
952
  * Configures the task queues for sending and receiving activities.
@@ -820,6 +970,13 @@ interface FederationQueueOptions {
820
970
  * {@link Context.sendActivity} calls.
821
971
  */
822
972
  readonly fanout?: MessageQueue;
973
+ /**
974
+ * The message queue for custom background tasks. If not provided,
975
+ * tasks are routed to the outbox queue (unless
976
+ * {@link FederationOptions.taskQueueResolution} is `"strict"`).
977
+ * @since 2.x.x
978
+ */
979
+ readonly task?: MessageQueue;
823
980
  }
824
981
  /**
825
982
  * Prefixes for namespacing keys in the Deno KV store.
@@ -904,18 +1061,18 @@ interface FederationStartQueueOptions {
904
1061
  signal?: AbortSignal;
905
1062
  /**
906
1063
  * Starts the task worker only for the specified queue. If unspecified,
907
- * which is the default, the task worker starts for all three queues:
908
- * inbox, outbox, and fanout.
1064
+ * which is the default, the task worker starts for all four queues:
1065
+ * inbox, outbox, fanout, and task.
909
1066
  * @since 1.3.0
910
1067
  */
911
- queue?: "inbox" | "outbox" | "fanout";
1068
+ queue?: "inbox" | "outbox" | "fanout" | "task";
912
1069
  }
913
1070
  /**
914
1071
  * A common interface between {@link Federation} and {@link FederationBuilder}.
915
1072
  * @template TContextData The context data to pass to the {@link Context}.
916
1073
  * @since 1.6.0
917
1074
  */
918
- interface Federatable<TContextData> {
1075
+ interface Federatable<TContextData> extends TaskRegistry<TContextData> {
919
1076
  /**
920
1077
  * Registers a NodeInfo dispatcher.
921
1078
  * @param path The URI path pattern for the NodeInfo dispatcher. The syntax
@@ -1622,6 +1779,26 @@ interface FederationOptions<TContextData> {
1622
1779
  */
1623
1780
  inboxRetryPolicy?: RetryPolicy;
1624
1781
  /**
1782
+ * The retry policy for processing custom background tasks. By default,
1783
+ * this uses an exponential backoff strategy with a maximum of 10 attempts
1784
+ * and a maximum delay of 12 hours. A per-task retry policy
1785
+ * ({@link TaskDefinitionOptions.retryPolicy}) overrides this.
1786
+ * @since 2.x.x
1787
+ */
1788
+ taskRetryPolicy?: RetryPolicy;
1789
+ /**
1790
+ * How a queue is resolved for a custom background task when neither
1791
+ * a per-task queue ({@link TaskDefinitionOptions.queue}) nor a dedicated
1792
+ * task queue ({@link FederationQueueOptions.task}) is configured.
1793
+ *
1794
+ * - `"fallback"` (the default): the task is routed to the outbox queue.
1795
+ * - `"strict"`: no fallback; enqueuing the task throws instead of
1796
+ * silently sharing the outbox queue.
1797
+ * @default `"fallback"`
1798
+ * @since 2.x.x
1799
+ */
1800
+ taskQueueResolution?: "fallback" | "strict";
1801
+ /**
1625
1802
  * Activity transformers that are applied to outgoing activities. It is
1626
1803
  * useful for adjusting outgoing activities to satisfy some ActivityPub
1627
1804
  * implementations.
@@ -2374,6 +2551,44 @@ interface Context<TContextData> {
2374
2551
  */
2375
2552
  routeActivity(recipient: string | null, activity: Activity, options?: RouteActivityOptions): Promise<boolean>;
2376
2553
  /**
2554
+ * Enqueues a custom background task. The payload is validated against
2555
+ * the task's schema, serialized, and processed by the task's handler on
2556
+ * a background worker.
2557
+ *
2558
+ * @example
2559
+ * ``` typescript
2560
+ * await ctx.enqueueTask(sendDigest, { userId: "alice" });
2561
+ * ```
2562
+ *
2563
+ * @template TData The type of the task payload, inferred from the task's
2564
+ * schema.
2565
+ * @param task The handle returned by {@link TaskRegistry.defineTask}.
2566
+ * @param data The task payload. It is validated against the task's
2567
+ * schema before being enqueued.
2568
+ * @param options Options for enqueuing the task.
2569
+ * @throws {TypeError} If the task is not defined on this federation,
2570
+ * if no message queue is configured for tasks, or if
2571
+ * the payload fails schema validation.
2572
+ * @since 2.x.x
2573
+ */
2574
+ enqueueTask<TData>(task: TaskDefinition<TContextData, TData>, data: TData, options?: TaskEnqueueOptions): Promise<void>;
2575
+ /**
2576
+ * Enqueues multiple payloads for a custom background task at once.
2577
+ * Uses the queue's bulk enqueue operation when available, falling back
2578
+ * to parallel single enqueues.
2579
+ * @template TData The type of the task payload, inferred from the task's
2580
+ * schema.
2581
+ * @param task The handle returned by {@link TaskRegistry.defineTask}.
2582
+ * @param payloads The task payloads. Each is validated against the
2583
+ * task's schema before being enqueued.
2584
+ * @param options Options for enqueuing the tasks.
2585
+ * @throws {TypeError} If the task is not defined on this federation,
2586
+ * if no message queue is configured for tasks, or if
2587
+ * a payload fails schema validation.
2588
+ * @since 2.x.x
2589
+ */
2590
+ enqueueTaskMany<TData>(task: TaskDefinition<TContextData, TData>, payloads: readonly TData[], options?: TaskEnqueueOptions): Promise<void>;
2591
+ /**
2377
2592
  * Builds the URI of a collection of objects with the given name and values.
2378
2593
  * @param name The name of the collection, which can be a string or a symbol.
2379
2594
  * @param values The values of the URI parameters.
@@ -2884,4 +3099,4 @@ interface ActorKeyPair extends CryptoKeyPair {
2884
3099
  readonly multikey: Multikey;
2885
3100
  }
2886
3101
  //#endregion
2887
- 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 };
3102
+ 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 };
@@ -3,6 +3,6 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  //#region deno.json
5
5
  var name = "@fedify/fedify";
6
- var version = "2.4.0-dev.1417+43d75b89";
6
+ var version = "2.4.0-dev.1422+7668da16";
7
7
  //#endregion
8
8
  export { version as n, name as t };
@@ -1,8 +1,8 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { o as validateCryptoKey } from "./key-b17Uu8wX.mjs";
5
- import { n as doubleKnock } from "./http-iapcKTk-.mjs";
4
+ import { o as validateCryptoKey } from "./key-BLy_TeTg.mjs";
5
+ import { n as doubleKnock } from "./http-GQoPA_YT.mjs";
6
6
  import { getLogger } from "@logtape/logtape";
7
7
  import { UrlError, createActivityPubRequest, getRemoteDocument, logRequest, validatePublicUrl } from "@fedify/vocab-runtime";
8
8
  import { curry } from "es-toolkit";
@@ -1,11 +1,11 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
- import { r as assertExists } from "../std__assert-BBjXFNOb.mjs";
6
- import { t as assertThrows } from "../assert_throws-BOkhLGYc.mjs";
7
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
8
- import { r as createFederationBuilder } from "../builder-CU98OOiD.mjs";
4
+ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
+ import { r as assertExists } from "../std__assert-BTEgfoJo.mjs";
6
+ import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
7
+ import { t as MemoryKvStore } from "../kv-x2IvBUyq.mjs";
8
+ import { r as createFederationBuilder } from "../builder-Gef_ZeDE.mjs";
9
9
  import { DisallowedOperatorError, DisallowedVarSpecModifierError, DuplicateRouteVariableError, RouteTemplateOptionsNotMatchedError, RouterError } from "@fedify/uri-template";
10
10
  import { Activity, Note, Person } from "@fedify/vocab";
11
11
  import { test } from "@fedify/fixture";
@@ -1,11 +1,11 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
- import "../std__assert-BBjXFNOb.mjs";
6
- import { t as assertThrows } from "../assert_throws-BOkhLGYc.mjs";
7
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
8
- import { n as normalizeCircuitBreakerOptions, r as parseCircuitBreakerKvState, t as CircuitBreaker } from "../circuit-breaker-CSWsyoef.mjs";
4
+ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
+ import "../std__assert-BTEgfoJo.mjs";
6
+ import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
7
+ import { t as MemoryKvStore } from "../kv-x2IvBUyq.mjs";
8
+ import { n as normalizeCircuitBreakerOptions, r as parseCircuitBreakerKvState, t as CircuitBreaker } from "../circuit-breaker-hJBB6jwA.mjs";
9
9
  import { test } from "@fedify/fixture";
10
10
  //#region src/federation/circuit-breaker.test.ts
11
11
  var AlwaysConflictingKvStore = class extends MemoryKvStore {
@@ -1,9 +1,9 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
- import "../std__assert-BBjXFNOb.mjs";
6
- import { n as digest, t as buildCollectionSynchronizationHeader } from "../collection-Cc3DVAhE.mjs";
4
+ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
+ import "../std__assert-BTEgfoJo.mjs";
6
+ import { n as digest, t as buildCollectionSynchronizationHeader } from "../collection-Dp5ky45w.mjs";
7
7
  import { test } from "@fedify/fixture";
8
8
  import { decodeHex } from "byte-encodings/hex";
9
9
  //#region src/federation/collection.test.ts
@@ -1,19 +1,19 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as createOutboxContext, r as createRequestContext, t as createInboxContext } from "../context-DVoTs_wM.mjs";
5
- import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
6
- import "../std__assert-BBjXFNOb.mjs";
7
- import { n as assertGreaterOrEqual, t as assertRejects } from "../assert_rejects-DN60FHPX.mjs";
8
- import { t as assertInstanceOf } from "../assert_instance_of-DBC5X09g.mjs";
9
- import { t as assert } from "../assert-OguE97r2.mjs";
10
- import { r as parseAcceptSignature } from "../accept-CPkZzmGN.mjs";
11
- import { s as signRequest } from "../http-iapcKTk-.mjs";
12
- import { a as rsaPrivateKey3, c as rsaPublicKey3, s as rsaPublicKey2 } from "../keys-DGu1NFwu.mjs";
13
- import { a as compactJsonLd, p as signJsonLd } from "../ld-B1503hdI.mjs";
14
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
15
- import { c as handleActor, d as handleInbox, f as handleObject, h as respondWithObjectIfAcceptable, l as handleCollection, m as respondWithObject, o as createFederation, p as handleOutbox, u as handleCustomCollection } from "../middleware-Dh1xDMbI.mjs";
16
- import { t as ActivityListenerSet } from "../activity-listener-tztVvlNb.mjs";
4
+ import { n as createOutboxContext, r as createRequestContext, t as createInboxContext } from "../context-BrIOaBSs.mjs";
5
+ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
+ import "../std__assert-BTEgfoJo.mjs";
7
+ import { n as assertGreaterOrEqual, t as assertRejects } from "../assert_rejects-DQP-q39h.mjs";
8
+ import { t as assertInstanceOf } from "../assert_instance_of-C4Ri6VuN.mjs";
9
+ import { t as assert } from "../assert-DikXweDx.mjs";
10
+ import { r as parseAcceptSignature } from "../accept-CceiKpCy.mjs";
11
+ import { s as signRequest } from "../http-GQoPA_YT.mjs";
12
+ import { a as rsaPrivateKey3, c as rsaPublicKey3, s as rsaPublicKey2 } from "../keys-C3kae-6B.mjs";
13
+ import { a as compactJsonLd, p as signJsonLd } from "../ld-CWgxPlZq.mjs";
14
+ import { t as MemoryKvStore } from "../kv-x2IvBUyq.mjs";
15
+ import { c as handleActor, d as handleInbox, f as handleObject, h as respondWithObjectIfAcceptable, l as handleCollection, m as respondWithObject, o as createFederation, p as handleOutbox, u as handleCustomCollection } from "../middleware-PZaroDUk.mjs";
16
+ import { t as ActivityListenerSet } from "../activity-listener-BeTGV3wc.mjs";
17
17
  import { Activity, Create, Note, Person, Tombstone } from "@fedify/vocab";
18
18
  import { createTestMeterProvider, createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
19
19
  import { FetchError } from "@fedify/vocab-runtime";
@@ -1,12 +1,12 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
- import "../std__assert-BBjXFNOb.mjs";
6
- import { n as ed25519PrivateKey, r as ed25519PublicKey, t as ed25519Multikey } from "../keys-DGu1NFwu.mjs";
7
- import { r as signObject } from "../proof-Dacxh41h.mjs";
8
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
9
- import { o as createFederation } from "../middleware-Dh1xDMbI.mjs";
4
+ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
+ import "../std__assert-BTEgfoJo.mjs";
6
+ import { n as ed25519PrivateKey, r as ed25519PublicKey, t as ed25519Multikey } from "../keys-C3kae-6B.mjs";
7
+ import { r as signObject } from "../proof-nb5tfciW.mjs";
8
+ import { t as MemoryKvStore } from "../kv-x2IvBUyq.mjs";
9
+ import { o as createFederation } from "../middleware-PZaroDUk.mjs";
10
10
  import { Create, Follow, Person } from "@fedify/vocab";
11
11
  import { mockDocumentLoader, test } from "@fedify/fixture";
12
12
  //#region src/federation/idempotency.test.ts
@@ -1,9 +1,9 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
- import { t as assertThrows } from "../assert_throws-BOkhLGYc.mjs";
6
- import { t as ActivityListenerSet } from "../activity-listener-tztVvlNb.mjs";
4
+ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
+ import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
6
+ import { t as ActivityListenerSet } from "../activity-listener-BeTGV3wc.mjs";
7
7
  import { Activity, Create, Invite, Offer, Update } from "@fedify/vocab";
8
8
  import { test } from "@fedify/fixture";
9
9
  //#region src/federation/inbox.test.ts
@@ -1,11 +1,11 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
- import { t as assertInstanceOf } from "../assert_instance_of-DBC5X09g.mjs";
6
- import { t as assert } from "../assert-OguE97r2.mjs";
7
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
8
- import { t as KvKeyCache } from "../keycache-BeU0LCII.mjs";
4
+ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
+ import { t as assertInstanceOf } from "../assert_instance_of-C4Ri6VuN.mjs";
6
+ import { t as assert } from "../assert-DikXweDx.mjs";
7
+ import { t as MemoryKvStore } from "../kv-x2IvBUyq.mjs";
8
+ import { t as KvKeyCache } from "../keycache-CaOR6NYg.mjs";
9
9
  import { CryptographicKey, Multikey } from "@fedify/vocab";
10
10
  import { test } from "@fedify/fixture";
11
11
  //#region src/federation/keycache.test.ts
@@ -1,9 +1,9 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
- import "../std__assert-BBjXFNOb.mjs";
6
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
4
+ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
+ import "../std__assert-BTEgfoJo.mjs";
6
+ import { t as MemoryKvStore } from "../kv-x2IvBUyq.mjs";
7
7
  import { test } from "@fedify/fixture";
8
8
  //#region src/federation/kv.test.ts
9
9
  test("MemoryKvStore", async (t) => {
@@ -1,10 +1,10 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
- import "../std__assert-BBjXFNOb.mjs";
6
- import { t as assertRejects } from "../assert_rejects-DN60FHPX.mjs";
7
- import { _ as recordKeyLookup, a as instrumentDocumentLoader, b as recordWebFingerHandle, c as recordCircuitBreakerStateChange, d as recordCollectionRequest, f as recordCollectionTotalItems, g as recordInboxActivity, h as recordFanoutRecipients, i as getRemoteHost, l as recordCollectionDispatchDuration, m as recordDocumentFetch, p as recordDocumentCache, r as getFederationMetrics, t as classifyFetchError, u as recordCollectionPageItems, v as recordOutboxActivity, x as registerQueueDepthGauge, y as recordOutboxEnqueue } from "../metrics-DSV9HQUk.mjs";
4
+ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
+ import "../std__assert-BTEgfoJo.mjs";
6
+ import { t as assertRejects } from "../assert_rejects-DQP-q39h.mjs";
7
+ import { _ as recordKeyLookup, a as instrumentDocumentLoader, b as recordWebFingerHandle, c as recordCircuitBreakerStateChange, d as recordCollectionRequest, f as recordCollectionTotalItems, g as recordInboxActivity, h as recordFanoutRecipients, i as getRemoteHost, l as recordCollectionDispatchDuration, m as recordDocumentFetch, p as recordDocumentCache, r as getFederationMetrics, t as classifyFetchError, u as recordCollectionPageItems, v as recordOutboxActivity, x as registerQueueDepthGauge, y as recordOutboxEnqueue } from "../metrics-DUKoLd_E.mjs";
8
8
  import { createTestMeterProvider, test } from "@fedify/fixture";
9
9
  import { FetchError } from "@fedify/vocab-runtime";
10
10
  import { DataPointType, MeterProvider, MetricReader } from "@opentelemetry/sdk-metrics";