fixed comments and added default generic arg name
This commit is contained in:
parent
56b756e16b
commit
47d5ea3ce2
11
CHANGELOG.md
11
CHANGELOG.md
|
@ -1,3 +1,14 @@
|
||||||
|
## v0.23.0-rc6 (WIP)
|
||||||
|
|
||||||
|
> [!CAUTION]
|
||||||
|
> **This is a prerelease intended for test and experimental purposes only!**
|
||||||
|
|
||||||
|
- Fixed the auto OAuth2 avatar mapped field assignment when the OAuth2 provider doesn't return an avatar URL ([#5673](https://github.com/pocketbase/pocketbase/pull/5673)).
|
||||||
|
_In case the image retrieval fails and the mapped record field is not required, the error is silenced and only logged with WARN level._
|
||||||
|
|
||||||
|
- Added `Router.SEARCH()` helper method.
|
||||||
|
|
||||||
|
|
||||||
## v0.23.0-rc5
|
## v0.23.0-rc5
|
||||||
|
|
||||||
> [!CAUTION]
|
> [!CAUTION]
|
||||||
|
|
|
@ -20,9 +20,6 @@ const (
|
||||||
|
|
||||||
// BodyLimit returns a middleware function that changes the default request body size limit.
|
// BodyLimit returns a middleware function that changes the default request body size limit.
|
||||||
//
|
//
|
||||||
// Note that in order to have effect this middleware should be registered
|
|
||||||
// before other middlewares that reads the request body.
|
|
||||||
//
|
|
||||||
// If limitBytes <= 0, no limit is applied.
|
// If limitBytes <= 0, no limit is applied.
|
||||||
//
|
//
|
||||||
// Otherwise, if the request body size exceeds the configured limitBytes,
|
// Otherwise, if the request body size exceeds the configured limitBytes,
|
||||||
|
|
|
@ -45,7 +45,7 @@ type GzipConfig struct {
|
||||||
MinLength int
|
MinLength int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gzip returns a middleware which compresses HTTP response using gzip compression scheme.
|
// Gzip returns a middleware which compresses HTTP response using Gzip compression scheme.
|
||||||
func Gzip() func(*core.RequestEvent) error {
|
func Gzip() func(*core.RequestEvent) error {
|
||||||
return GzipWithConfig(GzipConfig{})
|
return GzipWithConfig(GzipConfig{})
|
||||||
}
|
}
|
||||||
|
|
|
@ -335,13 +335,13 @@ func (app *BaseApp) initHooks() {
|
||||||
app.onBatchRequest = &hook.Hook[*BatchRequestEvent]{}
|
app.onBatchRequest = &hook.Hook[*BatchRequestEvent]{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @todo consider caching the created instance?
|
|
||||||
//
|
|
||||||
// UnsafeWithoutHooks returns a shallow copy of the current app WITHOUT any registered hooks.
|
// UnsafeWithoutHooks returns a shallow copy of the current app WITHOUT any registered hooks.
|
||||||
//
|
//
|
||||||
// NB! Note that using the returned app instance may cause data integrity errors
|
// NB! Note that using the returned app instance may cause data integrity errors
|
||||||
// since the Record validations and data normalizations (including files uploads)
|
// since the Record validations and data normalizations (including files uploads)
|
||||||
// rely on the app hooks to work.
|
// rely on the app hooks to work.
|
||||||
|
//
|
||||||
|
// @todo consider caching the created instance?
|
||||||
func (app *BaseApp) UnsafeWithoutHooks() App {
|
func (app *BaseApp) UnsafeWithoutHooks() App {
|
||||||
clone := *app
|
clone := *app
|
||||||
|
|
||||||
|
|
|
@ -922,7 +922,7 @@ declare namespace $os {
|
||||||
* const cmd = $os.cmd('ls', '-sl')
|
* const cmd = $os.cmd('ls', '-sl')
|
||||||
*
|
*
|
||||||
* // execute the command and return its standard output as string
|
* // execute the command and return its standard output as string
|
||||||
* const output = String.fromCharCode(...cmd.output());
|
* const output = toString(cmd.output());
|
||||||
* ` + "```" + `
|
* ` + "```" + `
|
||||||
*/
|
*/
|
||||||
export let cmd: exec.command
|
export let cmd: exec.command
|
||||||
|
|
|
@ -45,8 +45,8 @@ func (group *RouterGroup[T]) Group(prefix string) *RouterGroup[T] {
|
||||||
// aka. executes in the order they were registered.
|
// aka. executes in the order they were registered.
|
||||||
//
|
//
|
||||||
// If you need to specify a named middleware (ex. so that it can be removed)
|
// If you need to specify a named middleware (ex. so that it can be removed)
|
||||||
// or middleware with custom exec prirority, use [Group.Bind] method.
|
// or middleware with custom exec prirority, use [RouterGroup.Bind] method.
|
||||||
func (group *RouterGroup[T]) BindFunc(middlewareFuncs ...func(T) error) *RouterGroup[T] {
|
func (group *RouterGroup[T]) BindFunc(middlewareFuncs ...func(e T) error) *RouterGroup[T] {
|
||||||
for _, m := range middlewareFuncs {
|
for _, m := range middlewareFuncs {
|
||||||
group.Middlewares = append(group.Middlewares, &hook.Handler[T]{Func: m})
|
group.Middlewares = append(group.Middlewares, &hook.Handler[T]{Func: m})
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ func (group *RouterGroup[T]) Unbind(middlewareIds ...string) *RouterGroup[T] {
|
||||||
// meaning that only a top level group route could have HOST as part of the prefix.
|
// meaning that only a top level group route could have HOST as part of the prefix.
|
||||||
//
|
//
|
||||||
// Returns the newly created route to allow attaching route-only middlewares.
|
// Returns the newly created route to allow attaching route-only middlewares.
|
||||||
func (group *RouterGroup[T]) Route(method string, path string, action func(T) error) *Route[T] {
|
func (group *RouterGroup[T]) Route(method string, path string, action func(e T) error) *Route[T] {
|
||||||
route := &Route[T]{
|
route := &Route[T]{
|
||||||
Method: method,
|
Method: method,
|
||||||
Path: path,
|
Path: path,
|
||||||
|
@ -127,48 +127,48 @@ func (group *RouterGroup[T]) Route(method string, path string, action func(T) er
|
||||||
return route
|
return route
|
||||||
}
|
}
|
||||||
|
|
||||||
// Any is a shorthand for [Group.AddRoute] with "" as route method (aka. matches any method).
|
// Any is a shorthand for [RouterGroup.AddRoute] with "" as route method (aka. matches any method).
|
||||||
func (group *RouterGroup[T]) Any(path string, action func(T) error) *Route[T] {
|
func (group *RouterGroup[T]) Any(path string, action func(e T) error) *Route[T] {
|
||||||
return group.Route("", path, action)
|
return group.Route("", path, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET is a shorthand for [Group.AddRoute] with GET as route method.
|
// GET is a shorthand for [RouterGroup.AddRoute] with GET as route method.
|
||||||
func (group *RouterGroup[T]) GET(path string, action func(T) error) *Route[T] {
|
func (group *RouterGroup[T]) GET(path string, action func(e T) error) *Route[T] {
|
||||||
return group.Route(http.MethodGet, path, action)
|
return group.Route(http.MethodGet, path, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SEARCH is a shorthand for [Group.AddRoute] with SEARCH as route method.
|
// SEARCH is a shorthand for [RouterGroup.AddRoute] with SEARCH as route method.
|
||||||
func (group *RouterGroup[T]) SEARCH(path string, action func(T) error) *Route[T] {
|
func (group *RouterGroup[T]) SEARCH(path string, action func(e T) error) *Route[T] {
|
||||||
return group.Route("SEARCH", path, action)
|
return group.Route("SEARCH", path, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST is a shorthand for [Group.AddRoute] with POST as route method.
|
// POST is a shorthand for [RouterGroup.AddRoute] with POST as route method.
|
||||||
func (group *RouterGroup[T]) POST(path string, action func(T) error) *Route[T] {
|
func (group *RouterGroup[T]) POST(path string, action func(e T) error) *Route[T] {
|
||||||
return group.Route(http.MethodPost, path, action)
|
return group.Route(http.MethodPost, path, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE is a shorthand for [Group.AddRoute] with DELETE as route method.
|
// DELETE is a shorthand for [RouterGroup.AddRoute] with DELETE as route method.
|
||||||
func (group *RouterGroup[T]) DELETE(path string, action func(T) error) *Route[T] {
|
func (group *RouterGroup[T]) DELETE(path string, action func(e T) error) *Route[T] {
|
||||||
return group.Route(http.MethodDelete, path, action)
|
return group.Route(http.MethodDelete, path, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PATCH is a shorthand for [Group.AddRoute] with PATCH as route method.
|
// PATCH is a shorthand for [RouterGroup.AddRoute] with PATCH as route method.
|
||||||
func (group *RouterGroup[T]) PATCH(path string, action func(T) error) *Route[T] {
|
func (group *RouterGroup[T]) PATCH(path string, action func(e T) error) *Route[T] {
|
||||||
return group.Route(http.MethodPatch, path, action)
|
return group.Route(http.MethodPatch, path, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT is a shorthand for [Group.AddRoute] with PUT as route method.
|
// PUT is a shorthand for [RouterGroup.AddRoute] with PUT as route method.
|
||||||
func (group *RouterGroup[T]) PUT(path string, action func(T) error) *Route[T] {
|
func (group *RouterGroup[T]) PUT(path string, action func(e T) error) *Route[T] {
|
||||||
return group.Route(http.MethodPut, path, action)
|
return group.Route(http.MethodPut, path, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HEAD is a shorthand for [Group.AddRoute] with HEAD as route method.
|
// HEAD is a shorthand for [RouterGroup.AddRoute] with HEAD as route method.
|
||||||
func (group *RouterGroup[T]) HEAD(path string, action func(T) error) *Route[T] {
|
func (group *RouterGroup[T]) HEAD(path string, action func(e T) error) *Route[T] {
|
||||||
return group.Route(http.MethodHead, path, action)
|
return group.Route(http.MethodHead, path, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OPTIONS is a shorthand for [Group.AddRoute] with OPTIONS as route method.
|
// OPTIONS is a shorthand for [RouterGroup.AddRoute] with OPTIONS as route method.
|
||||||
func (group *RouterGroup[T]) OPTIONS(path string, action func(T) error) *Route[T] {
|
func (group *RouterGroup[T]) OPTIONS(path string, action func(e T) error) *Route[T] {
|
||||||
return group.Route(http.MethodOptions, path, action)
|
return group.Route(http.MethodOptions, path, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import "github.com/pocketbase/pocketbase/tools/hook"
|
||||||
type Route[T hook.Resolver] struct {
|
type Route[T hook.Resolver] struct {
|
||||||
excludedMiddlewares map[string]struct{}
|
excludedMiddlewares map[string]struct{}
|
||||||
|
|
||||||
Action func(T) error
|
Action func(e T) error
|
||||||
Method string
|
Method string
|
||||||
Path string
|
Path string
|
||||||
Middlewares []*hook.Handler[T]
|
Middlewares []*hook.Handler[T]
|
||||||
|
@ -17,8 +17,8 @@ type Route[T hook.Resolver] struct {
|
||||||
// aka. executes in the order they were registered.
|
// aka. executes in the order they were registered.
|
||||||
//
|
//
|
||||||
// If you need to specify a named middleware (ex. so that it can be removed)
|
// If you need to specify a named middleware (ex. so that it can be removed)
|
||||||
// or middleware with custom exec prirority, use the [Bind] method.
|
// or middleware with custom exec prirority, use the [Route.Bind] method.
|
||||||
func (route *Route[T]) BindFunc(middlewareFuncs ...func(T) error) *Route[T] {
|
func (route *Route[T]) BindFunc(middlewareFuncs ...func(e T) error) *Route[T] {
|
||||||
for _, m := range middlewareFuncs {
|
for _, m := range middlewareFuncs {
|
||||||
route.Middlewares = append(route.Middlewares, &hook.Handler[T]{Func: m})
|
route.Middlewares = append(route.Middlewares, &hook.Handler[T]{Func: m})
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,8 @@ type EventFactoryFunc[T hook.Resolver] func(w http.ResponseWriter, r *http.Reque
|
||||||
//
|
//
|
||||||
// http.ListenAndServe("localhost:8090", mux)
|
// http.ListenAndServe("localhost:8090", mux)
|
||||||
type Router[T hook.Resolver] struct {
|
type Router[T hook.Resolver] struct {
|
||||||
|
// @todo consider renaming the type to just Group and replace the embed type
|
||||||
|
// with an alias after Go 1.24 adds support for generic type aliases
|
||||||
*RouterGroup[T]
|
*RouterGroup[T]
|
||||||
|
|
||||||
eventFactory EventFactoryFunc[T]
|
eventFactory EventFactoryFunc[T]
|
||||||
|
|
Loading…
Reference in New Issue