Commit 2ee65565 authored by Jiwon Kwon's avatar Jiwon Kwon
Browse files

Add setCollectionDipatchers and setOrderdCollectionsDispatchers

- Each dispatcher supports params up to 5
parent fa77bff1
Loading
Loading
Loading
Loading
+246 −24
Original line number Diff line number Diff line
@@ -1211,17 +1211,130 @@ export class FederationBuilderImpl<TContextData>
    TParam extends string,
  >(
    name: string | symbol,
    ...args: [
    // deno-lint-ignore no-explicit-any
      (new (...args: any[]) => TObject) & { typeId: URL },
      `${string}${Rfc6570Expression<TParam>}${string}`,
      CustomCollectionDispatcher<
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;
  setCollectionDispatcher<
    TObject extends Object,
    TParam extends string,
  >(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<
      TParam
    >}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;
  setCollectionDispatcher<
    TObject extends Object,
    TParam extends string,
  >(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<
      TParam
    >}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;
  setCollectionDispatcher<
    TObject extends Object,
    TParam extends string,
  >(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;
  setCollectionDispatcher<
    TObject extends Object,
    TParam extends string,
  >(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<TParam>}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;
  setCollectionDispatcher<
    TObject extends Object,
    TParam extends string,
  >(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: string,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
    ]
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
@@ -1230,7 +1343,9 @@ export class FederationBuilderImpl<TContextData>
    return this.#setCustomCollectionDispatcher(
      name,
      "collection",
      ...args,
      itemType,
      path as `${string}${Rfc6570Expression<TParam>}${string}`,
      dispatcher,
    );
  }

@@ -1239,17 +1354,122 @@ export class FederationBuilderImpl<TContextData>
    TParam extends string,
  >(
    name: string | symbol,
    ...args: [
    // deno-lint-ignore no-explicit-any
      (new (...args: any[]) => TObject) & { typeId: URL },
      `${string}${Rfc6570Expression<TParam>}${string}`,
      CustomCollectionDispatcher<
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<TParam>}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;
  setOrderedCollectionDispatcher<
    TObject extends Object,
    TParam extends string,
  >(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;
  setOrderedCollectionDispatcher<
    TObject extends Object,
    TParam extends string,
  >(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<TParam>}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;
  setOrderedCollectionDispatcher<
    TObject extends Object,
    TParam extends string,
  >(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;
  setOrderedCollectionDispatcher<
    TObject extends Object,
    TParam extends string,
  >(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<TParam>}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;
  setOrderedCollectionDispatcher<
    TObject extends Object,
    TParam extends string,
  >(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: string,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
    ]
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
@@ -1258,7 +1478,9 @@ export class FederationBuilderImpl<TContextData>
    return this.#setCustomCollectionDispatcher(
      name,
      "orderedCollection",
      ...args,
      itemType,
      path as `${string}${Rfc6570Expression<TParam>}${string}`,
      dispatcher,
    );
  }

+294 −1
Original line number Diff line number Diff line
@@ -457,7 +457,152 @@ export interface Federatable<TContextData> {
    inboxPath: `${string}{identifier}${string}` | `${string}{handle}${string}`,
    sharedInboxPath?: string,
  ): InboxListenerSetters<TContextData>;
  /** ß

  /**
   * Registers a collection of objects dispatcher.
   *
   * @template TContextData The context data to pass to the {@link Context}.
   * @template TObject The type of objects to dispatch.
   * @template TParam The parameter names of the requested URL.
   * @param name A unique name for the collection dispatcher.
   * @param itemType The Activity Vocabulary class of the object to dispatch.
   * @param path The URI path pattern for the collection dispatcher.
   *             The syntax is based on URI Template
   *             ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
   *             The path must have one or more variables.
   * @param dispatcher A collection dispatcher callback to register.
   */
  setCollectionDispatcher<TObject extends Object, TParam extends string>(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;

  /**
   * Registers a collection of objects dispatcher.
   *
   * @template TContextData The context data to pass to the {@link Context}.
   * @template TObject The type of objects to dispatch.
   * @template TParam The parameter names of the requested URL.
   * @param name A unique name for the collection dispatcher.
   * @param itemType The Activity Vocabulary class of the object to dispatch.
   * @param path The URI path pattern for the collection dispatcher.
   *             The syntax is based on URI Template
   *             ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
   *             The path must have one or more variables.
   * @param dispatcher A collection dispatcher callback to register.
   */
  setCollectionDispatcher<TObject extends Object, TParam extends string>(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<
      TParam
    >}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;

  /**
   * Registers a collection of objects dispatcher.
   *
   * @template TContextData The context data to pass to the {@link Context}.
   * @template TObject The type of objects to dispatch.
   * @template TParam The parameter names of the requested URL.
   * @param name A unique name for the collection dispatcher.
   * @param itemType The Activity Vocabulary class of the object to dispatch.
   * @param path The URI path pattern for the collection dispatcher.
   *             The syntax is based on URI Template
   *             ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
   *             The path must have one or more variables.
   * @param dispatcher A collection dispatcher callback to register.
   */
  setCollectionDispatcher<TObject extends Object, TParam extends string>(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<
      TParam
    >}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;

  /**
   * Registers a collection of objects dispatcher.
   *
   * @template TContextData The context data to pass to the {@link Context}.
   * @template TObject The type of objects to dispatch.
   * @template TParam The parameter names of the requested URL.
   * @param name A unique name for the collection dispatcher.
   * @param itemType The Activity Vocabulary class of the object to dispatch.
   * @param path The URI path pattern for the collection dispatcher.
   *             The syntax is based on URI Template
   *             ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
   *             The path must have one or more variables.
   * @param dispatcher A collection dispatcher callback to register.
   */
  setCollectionDispatcher<TObject extends Object, TParam extends string>(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;

  /**
   * Registers a collection of objects dispatcher.
   *
   * @template TContextData The context data to pass to the {@link Context}.
@@ -488,6 +633,154 @@ export interface Federatable<TContextData> {
    TContextData
  >;

  /**
   * Registers an ordered collection of objects dispatcher.
   *
   * @template TContextData The context data to pass to the {@link Context}.
   * @template TObject The type of objects to dispatch.
   * @template TParam The parameter names of the requested URL.
   * @param name A unique name for the collection dispatcher.
   * @param itemType The Activity Vocabulary class of the object to dispatch.
   * @param path The URI path pattern for the collection dispatcher.
   *             The syntax is based on URI Template
   *             ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
   *             The path must have one or more variables.
   * @param dispatcher A collection dispatcher callback to register.
   */
  setOrderedCollectionDispatcher<
    TObject extends Object,
    TParam extends string,
  >(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<TParam>}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;

  /**
   * Registers an ordered collection of objects dispatcher.
   *
   * @template TContextData The context data to pass to the {@link Context}.
   * @template TObject The type of objects to dispatch.
   * @template TParam The parameter names of the requested URL.
   * @param name A unique name for the collection dispatcher.
   * @param itemType The Activity Vocabulary class of the object to dispatch.
   * @param path The URI path pattern for the collection dispatcher.
   *             The syntax is based on URI Template
   *             ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
   *             The path must have one or more variables.
   * @param dispatcher A collection dispatcher callback to register.
   */
  setOrderedCollectionDispatcher<
    TObject extends Object,
    TParam extends string,
  >(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;

  /**
   * Registers an ordered collection of objects dispatcher.
   *
   * @template TContextData The context data to pass to the {@link Context}.
   * @template TObject The type of objects to dispatch.
   * @template TParam The parameter names of the requested URL.
   * @param name A unique name for the collection dispatcher.
   * @param itemType The Activity Vocabulary class of the object to dispatch.
   * @param path The URI path pattern for the collection dispatcher.
   *             The syntax is based on URI Template
   *             ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
   *             The path must have one or more variables.
   * @param dispatcher A collection dispatcher callback to register.
   */
  setOrderedCollectionDispatcher<
    TObject extends Object,
    TParam extends string,
  >(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}${Rfc6570Expression<TParam>}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;

  /**
   * Registers an ordered collection of objects dispatcher.
   *
   * @template TContextData The context data to pass to the {@link Context}.
   * @template TObject The type of objects to dispatch.
   * @template TParam The parameter names of the requested URL.
   * @param name A unique name for the collection dispatcher.
   * @param itemType The Activity Vocabulary class of the object to dispatch.
   * @param path The URI path pattern for the collection dispatcher.
   *             The syntax is based on URI Template
   *             ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
   *             The path must have one or more variables.
   * @param dispatcher A collection dispatcher callback to register.
   */
  setOrderedCollectionDispatcher<
    TObject extends Object,
    TParam extends string,
  >(
    name: string | symbol,
    // deno-lint-ignore no-explicit-any
    itemType: (new (...args: any[]) => TObject) & { typeId: URL },
    path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
      TParam
    >}${string}`,
    dispatcher: CustomCollectionDispatcher<
      TObject,
      TParam,
      RequestContext<TContextData>,
      TContextData
    >,
  ): CustomCollectionCallbackSetters<
    TParam,
    RequestContext<TContextData>,
    TContextData
  >;

  /**
   * Registers an ordered collection of objects dispatcher.
   *