Skip to content

Commit

Permalink
Update dispatcher & listener setters to use type-safe path format
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Apr 22, 2024
1 parent 8cb8c8e commit 1d26571
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ To be released.

- Activity Vocabulary classes now have `typeId` static property.

- Dispatcher setters and inbox listener setters in `Federation` now take
a path as <code>`${string}{handle}${string}`</code> instead of `string`
so that it is more type-safe.

[public addressing]: https://www.w3.org/TR/activitypub/#public-addressing
[authorized fetch]: https://swicg.github.io/activitypub-http-signature/#authorized-fetch
[LogTape]: https://github.com/dahlia/logtape
Expand Down
10 changes: 5 additions & 5 deletions federation/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ export class Federation<TContextData> {
* @throws {RouterError} Thrown if the path pattern is invalid.
*/
setActorDispatcher(
path: string,
path: `${string}{handle}${string}`,
dispatcher: ActorDispatcher<TContextData>,
): ActorCallbackSetters<TContextData> {
if (this.#router.has("actor")) {
Expand Down Expand Up @@ -574,7 +574,7 @@ export class Federation<TContextData> {
* @throws {@link RouterError} Thrown if the path pattern is invalid.
*/
setOutboxDispatcher(
path: string,
path: `${string}{handle}${string}`,
dispatcher: CollectionDispatcher<Activity, TContextData>,
): CollectionCallbackSetters<TContextData> {
if (this.#router.has("outbox")) {
Expand Down Expand Up @@ -623,7 +623,7 @@ export class Federation<TContextData> {
* @throws {RouterError} Thrown if the path pattern is invalid.
*/
setFollowingDispatcher(
path: string,
path: `${string}{handle}${string}`,
dispatcher: CollectionDispatcher<Actor | URL, TContextData>,
): CollectionCallbackSetters<TContextData> {
if (this.#router.has("following")) {
Expand Down Expand Up @@ -672,7 +672,7 @@ export class Federation<TContextData> {
* @throws {@link RouterError} Thrown if the path pattern is invalid.
*/
setFollowersDispatcher(
path: string,
path: `${string}{handle}${string}`,
dispatcher: CollectionDispatcher<Actor | URL, TContextData>,
): CollectionCallbackSetters<TContextData> {
if (this.#router.has("followers")) {
Expand Down Expand Up @@ -739,7 +739,7 @@ export class Federation<TContextData> {
* @throws {RouteError} Thrown if the path pattern is invalid.
*/
setInboxListeners(
inboxPath: string,
inboxPath: `${string}{handle}${string}`,
sharedInboxPath?: string,
): InboxListenerSetter<TContextData> {
if (this.#router.has("inbox")) {
Expand Down

0 comments on commit 1d26571

Please sign in to comment.