@fedify/fedify 1.8.1-pr.331.1178 → 1.8.1-pr.332.1179

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 (86) hide show
  1. package/dist/{actor-3n3a3mn9.js → actor-BxoA0YAS.js} +179 -179
  2. package/dist/{actor-FNzWBOLP.js → actor-XdgmhnS2.js} +1 -1
  3. package/dist/{authdocloader-GfBzg16C.js → authdocloader-BVZHcNUr.js} +3 -3
  4. package/dist/{authdocloader-Ca5hhhev.js → authdocloader-InqI_lXP.js} +3 -3
  5. package/dist/{builder-Clm8gcd0.js → builder--IjI02Ox.js} +43 -4
  6. package/dist/{client-Cn1v4IjU.js → client-Crj_oOVS.js} +1 -1
  7. package/dist/compat/mod.d.ts +2 -2
  8. package/dist/compat/transformers.test.js +16 -16
  9. package/dist/{context-B6mUZhs_.d.ts → context-72aRESIE.d.ts} +214 -1
  10. package/dist/{docloader-EkABD3kd.js → docloader-CHd_rHX1.js} +1 -1
  11. package/dist/{esm-DYas5DHL.js → esm-DnLA4gl4.js} +1 -1
  12. package/dist/federation/builder.test.js +5 -5
  13. package/dist/federation/collection.test.js +3 -3
  14. package/dist/federation/handler.test.js +327 -17
  15. package/dist/federation/inbox.test.js +4 -4
  16. package/dist/federation/keycache.test.js +4 -4
  17. package/dist/federation/kv.test.js +3 -3
  18. package/dist/federation/middleware.test.js +19 -18
  19. package/dist/federation/mod.d.ts +2 -2
  20. package/dist/federation/mod.js +10 -10
  21. package/dist/federation/mq.test.js +3 -3
  22. package/dist/federation/retry.test.js +3 -3
  23. package/dist/federation/router.test.js +3 -3
  24. package/dist/federation/send.test.js +10 -10
  25. package/dist/{http-BMoRES3C.js → http-BJEmgkaN.js} +2 -2
  26. package/dist/{http-BjAxnWIu.js → http-kTQne-Vy.js} +3 -3
  27. package/dist/{inbox-CSCse5JS.js → inbox-Cvy4NbLS.js} +1 -1
  28. package/dist/{key-CcIJJoyp.js → key-Bqd_lPUv.js} +2 -2
  29. package/dist/{key-DA72_KFf.js → key-CnAHzdUR.js} +4 -4
  30. package/dist/{key-DzT1bGXW.js → key-DH5TJ47Z.js} +3 -3
  31. package/dist/{key-B8Ddhi4l.js → key-fNDZsrw-.js} +2 -2
  32. package/dist/{keycache-B4X8zg2j.js → keycache-BmNxwMWl.js} +1 -1
  33. package/dist/{keys-Db8BUZdO.js → keys-BQv1XI0z.js} +1 -1
  34. package/dist/{ld-BwliTJit.js → ld-tVEgwW3c.js} +2 -2
  35. package/dist/{lookup-DSIbu5DQ.js → lookup-CzGCa7ll.js} +1 -1
  36. package/dist/{lookup-DYSWakdP.js → lookup-S2xtiVK9.js} +1 -1
  37. package/dist/{middleware-CGmmWG7J.js → middleware-B0SKbJiv.js} +555 -14
  38. package/dist/middleware-CcI2U-o7.js +26 -0
  39. package/dist/{middleware-B5NWowV0.js → middleware-DihQ_X9R.js} +590 -10
  40. package/dist/middleware-ksP_j6kc.js +17 -0
  41. package/dist/{mod-D9qE4iHP.d.ts → mod-OU0GgfW6.d.ts} +1 -1
  42. package/dist/mod.d.ts +3 -3
  43. package/dist/mod.js +10 -10
  44. package/dist/nodeinfo/client.test.js +5 -5
  45. package/dist/nodeinfo/handler.test.js +16 -16
  46. package/dist/nodeinfo/mod.js +2 -2
  47. package/dist/nodeinfo/semver.test.js +3 -3
  48. package/dist/nodeinfo/types.test.js +3 -3
  49. package/dist/{owner-CTaAKlYE.js → owner-DuPxPR5X.js} +2 -2
  50. package/dist/{proof-CaMDg5Wf.js → proof-DLGV7jUF.js} +3 -3
  51. package/dist/{proof-CqInNpez.js → proof-D_vMdizW.js} +2 -2
  52. package/dist/runtime/authdocloader.test.js +9 -9
  53. package/dist/runtime/docloader.test.js +4 -4
  54. package/dist/runtime/key.test.js +5 -5
  55. package/dist/runtime/langstr.test.js +3 -3
  56. package/dist/runtime/mod.js +6 -6
  57. package/dist/runtime/multibase/multibase.test.js +3 -3
  58. package/dist/runtime/url.test.js +3 -3
  59. package/dist/{send-CylRphpj.js → send--AIUpFOl.js} +2 -2
  60. package/dist/sig/http.test.js +8 -8
  61. package/dist/sig/key.test.js +6 -6
  62. package/dist/sig/ld.test.js +7 -7
  63. package/dist/sig/mod.js +6 -6
  64. package/dist/sig/owner.test.js +7 -7
  65. package/dist/sig/proof.test.js +7 -7
  66. package/dist/testing/docloader.test.js +3 -3
  67. package/dist/testing/mod.d.ts +212 -0
  68. package/dist/testing/mod.js +3 -3
  69. package/dist/{testing-BYK226ka.js → testing-dG4K85Rn.js} +4 -3
  70. package/dist/{type-6aat8vwp.js → type-Dn3B2sdm.js} +179 -179
  71. package/dist/{types-BaOxz8EG.js → types-WOQMaDxr.js} +1 -1
  72. package/dist/vocab/actor.test.js +5 -5
  73. package/dist/vocab/lookup.test.js +4 -4
  74. package/dist/vocab/mod.js +4 -4
  75. package/dist/vocab/type.test.js +3 -3
  76. package/dist/vocab/vocab.test.js +4 -4
  77. package/dist/{vocab-3WdS2ySQ.js → vocab-CjmKyqUK.js} +3 -3
  78. package/dist/webfinger/handler.test.js +16 -16
  79. package/dist/webfinger/lookup.test.js +4 -4
  80. package/dist/webfinger/mod.js +2 -2
  81. package/dist/x/cfworkers.test.js +3 -3
  82. package/dist/x/hono.d.ts +1 -1
  83. package/dist/x/sveltekit.d.ts +1 -1
  84. package/package.json +1 -1
  85. package/dist/middleware-7JYs-9eD.js +0 -26
  86. package/dist/middleware-CcZg36yb.js +0 -17
@@ -7062,6 +7062,45 @@ type AuthorizePredicate<TContextData> = (context: RequestContext<TContextData>,
7062
7062
  * @since 0.7.0
7063
7063
  */
7064
7064
  type ObjectAuthorizePredicate<TContextData, TParam extends string> = (context: RequestContext<TContextData>, values: Record<TParam, string>, signedKey: CryptographicKey | null, signedKeyOwner: Actor | null) => boolean | Promise<boolean>;
7065
+ /**
7066
+ * A callback that dispatches a custom collection.
7067
+ *
7068
+ * @typeParam TItem The type of items in the collection.
7069
+ * @typeParam TParams The parameter names of the requested URL.
7070
+ * @typeParam TContext The type of the context. {@link Context} or
7071
+ * {@link RequestContext}.
7072
+ * @typeParam TContextData The context data to pass to the `TContext`.
7073
+ * @typeParam TFilter The type of the filter, if any.
7074
+ * @param context The context.
7075
+ * @param values The parameters of the requested URL.
7076
+ * @param cursor The cursor to start the collection from, or `null` to dispatch
7077
+ * the entire collection without pagination.
7078
+ * @since 1.8.0
7079
+ */
7080
+ type CustomCollectionDispatcher<TItem, TParams extends Record<string, string>, TContext extends Context<TContextData>, TContextData> = (context: TContext, values: TParams, cursor: string | null) => PageItems<TItem> | null | Promise<PageItems<TItem> | null>;
7081
+ /**
7082
+ * A callback that counts the number of items in a custom collection.
7083
+ *
7084
+ * @typeParam TParams The parameter names of the requested URL.
7085
+ * @typeParam TContextData The context data to pass to the {@link Context}.
7086
+ * @param context The context.
7087
+ * @param values The parameters of the requested URL.
7088
+ * @since 1.8.0
7089
+ */
7090
+ type CustomCollectionCounter<TParams extends Record<string, string>, TContextData> = (context: RequestContext<TContextData>, values: TParams) => number | bigint | null | Promise<number | bigint | null>;
7091
+ /**
7092
+ * A callback that returns a cursor for a custom collection.
7093
+ *
7094
+ * @typeParam TParams The parameter names of the requested URL.
7095
+ * @typeParam TContext The type of the context. {@link Context} or
7096
+ * {@link RequestContext}.
7097
+ * @typeParam TContextData The context data to pass to the {@link Context}.
7098
+ * @typeParam TFilter The type of the filter, if any.
7099
+ * @param context The context.
7100
+ * @param values The parameters of the requested URL.
7101
+ * @since 1.8.0
7102
+ */
7103
+ type CustomCollectionCursor<TParams extends Record<string, string>, TContext extends Context<TContextData>, TContextData> = (context: TContext, values: TParams) => string | null | Promise<string | null>;
7065
7104
  //#endregion
7066
7105
  //#region federation/queue.d.ts
7067
7106
  interface SenderKeyJwkPair {
@@ -7400,6 +7439,36 @@ interface Federatable<TContextData> {
7400
7439
  * @throws {RouteError} Thrown if the path pattern is invalid.
7401
7440
  */
7402
7441
  setInboxListeners(inboxPath: `${string}{identifier}${string}` | `${string}{handle}${string}`, sharedInboxPath?: string): InboxListenerSetters<TContextData>;
7442
+ /**
7443
+ * Registers a collection of objects dispatcher.
7444
+ *
7445
+ * @typeParam TContextData The context data to pass to the {@link Context}.
7446
+ * @typeParam TObject The type of objects to dispatch.
7447
+ * @typeParam TParam The parameter names of the requested URL.
7448
+ * @param name A unique name for the collection dispatcher.
7449
+ * @param itemType The Activity Vocabulary class of the object to dispatch.
7450
+ * @param path The URI path pattern for the collection dispatcher.
7451
+ * The syntax is based on URI Template
7452
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
7453
+ * The path must have one or more variables.
7454
+ * @param dispatcher A collection dispatcher callback to register.
7455
+ */
7456
+ setCollectionDispatcher<TObject extends Object$1, TParams extends Record<string, string>>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: ParamsKeyPath<TParams>, dispatcher: CustomCollectionDispatcher<TObject, TParams, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParams, RequestContext<TContextData>, TContextData>;
7457
+ /**
7458
+ * Registers an ordered collection of objects dispatcher.
7459
+ *
7460
+ * @typeParam TContextData The context data to pass to the {@link Context}.
7461
+ * @typeParam TObject The type of objects to dispatch.
7462
+ * @typeParam TParam The parameter names of the requested URL.
7463
+ * @param name A unique name for the collection dispatcher.
7464
+ * @param itemType The Activity Vocabulary class of the object to dispatch.
7465
+ * @param path The URI path pattern for the collection dispatcher.
7466
+ * The syntax is based on URI Template
7467
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
7468
+ * The path must have one or more variables.
7469
+ * @param dispatcher A collection dispatcher callback to register.
7470
+ */
7471
+ setOrderedCollectionDispatcher<TObject extends Object$1, TParams extends Record<string, string>>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: ParamsKeyPath<TParams>, dispatcher: CustomCollectionDispatcher<TObject, TParams, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParams, RequestContext<TContextData>, TContextData>;
7403
7472
  }
7404
7473
  /**
7405
7474
  * An object that registers federation-related business logic and dispatches
@@ -7635,6 +7704,119 @@ interface FederationFetchOptions<TContextData> {
7635
7704
  */
7636
7705
  onUnauthorized?: (request: Request) => Response | Promise<Response>;
7637
7706
  }
7707
+ /**
7708
+ * Additional settings for a custom collection dispatcher.
7709
+ *
7710
+ * @typeParam TParams The type of the parameters in the URL path.
7711
+ * @typeParam TContext The type of the context. {@link Context} or
7712
+ * {@link RequestContext}.
7713
+ * @typeParam TContextData The context data to pass to the {@link Context}.
7714
+ * @typeParam TFilter The type of filter for the collection.
7715
+ */
7716
+ interface CustomCollectionCallbackSetters<TParams extends Record<string, string>, TContext extends Context<TContextData>, TContextData> {
7717
+ /**
7718
+ * Sets the counter for the custom collection.
7719
+ * @param counter A callback that returns the number of items in the custom collection.
7720
+ * @returns The setters object so that settings can be chained.
7721
+ */
7722
+ setCounter(counter: CustomCollectionCounter<TParams, TContextData>): CustomCollectionCallbackSetters<TParams, TContext, TContextData>;
7723
+ /**
7724
+ * Sets the first cursor for the custom collection.
7725
+ * @param cursor The cursor for the first item in the custom collection.
7726
+ * @returns The setters object so that settings can be chained.
7727
+ */
7728
+ setFirstCursor(cursor: CustomCollectionCursor<TParams, TContext, TContextData>): CustomCollectionCallbackSetters<TParams, TContext, TContextData>;
7729
+ /**
7730
+ * Sets the last cursor for the custom collection.
7731
+ * @param cursor The cursor for the last item in the custom collection.
7732
+ * @returns The setters object so that settings can be chained.
7733
+ */
7734
+ setLastCursor(cursor: CustomCollectionCursor<TParams, TContext, TContextData>): CustomCollectionCallbackSetters<TParams, TContext, TContextData>;
7735
+ /**
7736
+ * Specifies the conditions under which requests are authorized.
7737
+ * @param predicate A callback that returns whether a request is authorized.
7738
+ * @returns The setters object so that settings can be chained.
7739
+ * @since 0.7.0
7740
+ */
7741
+ authorize(predicate: ObjectAuthorizePredicate<TContextData, string>): CustomCollectionCallbackSetters<TParams, TContext, TContextData>;
7742
+ }
7743
+ /**
7744
+ * Represents an object with a type ID, which is either a constructor or an
7745
+ * instance of the object.
7746
+ *
7747
+ * @typeParam TObject The type of the object.
7748
+ */
7749
+ type ConstructorWithTypeId<TObject extends Object$1> = (new (...args: any[]) => TObject) & {
7750
+ typeId: URL;
7751
+ };
7752
+ /**
7753
+ * Represents a path from the key of parameter objects.
7754
+ * @param Params - A record of parameters where keys are parameter names and
7755
+ * values are their string representations.
7756
+ * @returns A string representing the path with all parameters.
7757
+ * @example
7758
+ * ```ts
7759
+ * type UserPostPath = ParamsKeyPath<{ userId: string; postId: string }>;
7760
+ * let userPostPath: UserPostPath;
7761
+ * // userPostPath = "/posts/{postId}"; // invalid - does not contain `{userId}`
7762
+ * // userPostPath = "/users/{userId}"; // invalid - does not contain `{postId}`
7763
+ * userPostPath = "/users/{userId}/posts/{postId}"; // valid
7764
+ * userPostPath = "/posts/{postId}/users/{userId}"; // valid
7765
+ * ```
7766
+ */
7767
+ type ParamsKeyPath<Params extends Record<string, string>> = ParamsPath<Extract<keyof Params, string>> & string;
7768
+ /**
7769
+ * Represents a path with multiple parameters.
7770
+ * All permutations of the parameters are included in the union type.
7771
+ * The path must have all parameters in the form of `{paramName}`.
7772
+ * @param Params - A union of parameter names.
7773
+ * @returns A string representing the path with all parameters.
7774
+ * @example
7775
+ * ```ts
7776
+ * type UserPostPath = ParamsPath<"userId" | "postId">;
7777
+ * // = `${string}{userId}${string}` & `${string}{postId}${string}`
7778
+ * // =
7779
+ * // | `${string}{userId}${string}{postId}${string}`
7780
+ * // | `${string}{postId}${string}{userId}${string}`
7781
+ * let userPostPath: UserPostPath;
7782
+ * userPostPath = "/users/posts"; // ❌ invalid
7783
+ * userPostPath = "/users/{userId}"; // ❌ invalid
7784
+ * userPostPath = "/posts/{postId}"; // ❌ invalid
7785
+ * userPostPath = "/users/{userId}/posts/{postId}"; // ✅ valid
7786
+ * userPostPath = "/posts/{postId}/users/{userId}"; // ✅ valid
7787
+ */
7788
+ type ParamsPath<Params extends string> = UnionToIntersection<ParamPath<Params>>;
7789
+ /**
7790
+ * Represents a path with a single parameter.
7791
+ * The path must have at least one of the parameters in the form of `{paramName}`.
7792
+ * @param Param - The name of the parameter.
7793
+ * @returns A string representing the path with the parameter.
7794
+ * @example
7795
+ * ```ts
7796
+ * type UserPostPath = ParamPath<"userId" | "postId">;
7797
+ * // = `${string}{userId}${string}` | `${string}{postId}${string}`
7798
+ * let userPostPath: UserPostPath;
7799
+ * userPostPath = "/users/posts"; // ❌ invalid
7800
+ * userPostPath = "/users/{userId}"; // ✅ valid
7801
+ * userPostPath = "/posts/{postId}"; // ✅ valid
7802
+ * userPostPath = "/users/{userId}/posts/{postId}"; // ✅ valid
7803
+ * userPostPath = "/posts/{postId}/users/{userId}"; // ✅ valid
7804
+ */
7805
+ type ParamPath<Param extends string> = `${string}{${Param}}${string}`;
7806
+ /**
7807
+ * Converts union types to intersection types.
7808
+ *
7809
+ * @typeParam U - The union type to convert.
7810
+ * @returns The intersection type of the union.
7811
+ * @example
7812
+ * ```ts
7813
+ * type A = { a: string };
7814
+ * type B = { b: number };
7815
+ * type AorB = A | B;
7816
+ * type AandB = UnionToIntersection<AorB>;
7817
+ * // AandB = { a: string; b: number }
7818
+ */
7819
+ type UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
7638
7820
  //#endregion
7639
7821
  //#region federation/context.d.ts
7640
7822
  /**
@@ -7989,6 +8171,16 @@ interface Context<TContextData> {
7989
8171
  * @since 1.3.0
7990
8172
  */
7991
8173
  routeActivity(recipient: string | null, activity: Activity, options?: RouteActivityOptions): Promise<boolean>;
8174
+ /**
8175
+ * Builds the URI of a collection of objects with the given name and values.
8176
+ * @param name The name of the collection, which can be a string or a symbol.
8177
+ * @param values The values of the URI parameters.
8178
+ * @return The URI of the collection.
8179
+ * @throws {RouteError} If no object dispatcher is available for the name.
8180
+ * @throws {TypeError} If values are invalid.
8181
+ * @since 1.8.0
8182
+ */
8183
+ getCollectionUri<TParam extends Record<string, string>>(name: string | symbol, values: TParam): URL;
7992
8184
  }
7993
8185
  /**
7994
8186
  * A context for a request.
@@ -8239,6 +8431,26 @@ type ParseUriResult =
8239
8431
  readonly type: "featuredTags";
8240
8432
  readonly identifier: string;
8241
8433
  readonly handle: string;
8434
+ }
8435
+ /**
8436
+ * The case of a custom collection URI.
8437
+ * @since 1.8.0
8438
+ */ | {
8439
+ readonly type: "collection";
8440
+ readonly name: string | symbol;
8441
+ readonly class: ConstructorWithTypeId<Object$1>;
8442
+ readonly typeId: URL;
8443
+ readonly values: Record<string, string>;
8444
+ }
8445
+ /**
8446
+ * The case of a custom ordered collection URI.
8447
+ * @since 1.8.0
8448
+ */ | {
8449
+ readonly type: "orderedCollection";
8450
+ readonly name: string | symbol;
8451
+ readonly class: ConstructorWithTypeId<Object$1>;
8452
+ readonly typeId: URL;
8453
+ readonly values: Record<string, string>;
8242
8454
  };
8243
8455
  /**
8244
8456
  * Options for {@link Context.sendActivity} method.
@@ -3,8 +3,8 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import "../type-6aat8vwp.js";
7
- import "../lookup-DYSWakdP.js";
8
- import { createInboxContext, createRequestContext, test, testDefinitions } from "../testing-BYK226ka.js";
6
+ import "../type-Dn3B2sdm.js";
7
+ import "../lookup-S2xtiVK9.js";
8
+ import { createInboxContext, createRequestContext, test, testDefinitions } from "../testing-dG4K85Rn.js";
9
9
 
10
10
  export { createInboxContext, createRequestContext, test, testDefinitions };
@@ -3,8 +3,8 @@
3
3
  import { URLPattern } from "urlpattern-polyfill";
4
4
  globalThis.addEventListener = () => {};
5
5
 
6
- import { __require, lookupWebFinger } from "./type-6aat8vwp.js";
7
- import { RouterError, lookupObject, traverseCollection } from "./lookup-DYSWakdP.js";
6
+ import { __require, lookupWebFinger } from "./type-Dn3B2sdm.js";
7
+ import { RouterError, lookupObject, traverseCollection } from "./lookup-S2xtiVK9.js";
8
8
  import { configure, getConsoleSink, getLogger, reset } from "@logtape/logtape";
9
9
  import { trace } from "@opentelemetry/api";
10
10
 
@@ -70,7 +70,7 @@ async function mockDocumentLoader(resource) {
70
70
  //#endregion
71
71
  //#region testing/context.ts
72
72
  function createContext(values) {
73
- const { federation, url = new URL("http://example.com/"), canonicalOrigin, data, documentLoader, contextLoader, tracerProvider, clone, getNodeInfoUri, getActorUri, getObjectUri, getOutboxUri, getInboxUri, getFollowingUri, getFollowersUri, getLikedUri, getFeaturedUri, getFeaturedTagsUri, parseUri, getActorKeyPairs, getDocumentLoader, lookupObject: lookupObject$1, traverseCollection: traverseCollection$1, lookupNodeInfo, lookupWebFinger: lookupWebFinger$1, sendActivity, routeActivity } = values;
73
+ const { federation, url = new URL("http://example.com/"), canonicalOrigin, data, documentLoader, contextLoader, tracerProvider, clone, getNodeInfoUri, getActorUri, getObjectUri, getCollectionUri, getOutboxUri, getInboxUri, getFollowingUri, getFollowersUri, getLikedUri, getFeaturedUri, getFeaturedTagsUri, parseUri, getActorKeyPairs, getDocumentLoader, lookupObject: lookupObject$1, traverseCollection: traverseCollection$1, lookupNodeInfo, lookupWebFinger: lookupWebFinger$1, sendActivity, routeActivity } = values;
74
74
  function throwRouteError() {
75
75
  throw new RouterError("Not implemented");
76
76
  }
@@ -91,6 +91,7 @@ function createContext(values) {
91
91
  getNodeInfoUri: getNodeInfoUri ?? throwRouteError,
92
92
  getActorUri: getActorUri ?? throwRouteError,
93
93
  getObjectUri: getObjectUri ?? throwRouteError,
94
+ getCollectionUri: getCollectionUri ?? throwRouteError,
94
95
  getOutboxUri: getOutboxUri ?? throwRouteError,
95
96
  getInboxUri: getInboxUri ?? throwRouteError,
96
97
  getFollowingUri: getFollowingUri ?? throwRouteError,