generated from sapphiredev/sapphire-template
-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(route)!: change method handling
Added support for specifying a route's supported methods in the options Added support for specifying a route's method in the file name Added `MediaParser.Request` and `MediaParser.Response` type aliases Added `Middleware.Request` and `Middleware.Response` type aliases Hardened the `onLoad` and `onUnload` hooks from the `Route` class BREAKING CHANGE: The headers middleware now uses the supported HTTP methods from the route or the store instead of sending all supported methods BREAKING CHANGE: Changed the method handling in the `Route` class to not be keyed by the method name, sending all requests to the `run` method. This allows for more flexibility in the route handling BREAKING CHANGE: Writing the name of a file as `<name>.<method>.ts` will now set `<method>` as a method for the route
- Loading branch information
Showing
21 changed files
with
198 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { LoaderStrategy } from '@sapphire/pieces'; | ||
import { Collection } from 'discord.js'; | ||
import type { Route } from './Route'; | ||
import type { RouteStore } from './RouteStore'; | ||
|
||
export class RouteLoaderStrategy extends LoaderStrategy<Route> { | ||
public override onLoad(store: RouteStore, piece: Route): void { | ||
for (const method of piece.methods) { | ||
store.methods.ensure(method, () => new Collection()).set(piece, piece.router); | ||
} | ||
} | ||
|
||
public override onUnload(store: RouteStore, piece: Route): void { | ||
for (const method of piece.methods) { | ||
const methods = store.methods.get(method); | ||
if (typeof methods === 'undefined') continue; | ||
|
||
methods.delete(piece); | ||
if (methods.size === 0) store.methods.delete(method); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.