1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-03-18 05:37:49 +02:00

fixed comments and added default generic arg name

This commit is contained in:
Gani Georgiev 2024-10-14 14:32:52 +03:00
parent 56b756e16b
commit 47d5ea3ce2
8 changed files with 41 additions and 31 deletions

View File

@ -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
> [!CAUTION]

View File

@ -20,9 +20,6 @@ const (
// 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.
//
// Otherwise, if the request body size exceeds the configured limitBytes,

View File

@ -45,7 +45,7 @@ type GzipConfig struct {
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 {
return GzipWithConfig(GzipConfig{})
}

View File

@ -335,13 +335,13 @@ func (app *BaseApp) initHooks() {
app.onBatchRequest = &hook.Hook[*BatchRequestEvent]{}
}
// @todo consider caching the created instance?
//
// 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
// since the Record validations and data normalizations (including files uploads)
// rely on the app hooks to work.
//
// @todo consider caching the created instance?
func (app *BaseApp) UnsafeWithoutHooks() App {
clone := *app

View File

@ -922,7 +922,7 @@ declare namespace $os {
* const cmd = $os.cmd('ls', '-sl')
*
* // 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

View File

@ -45,8 +45,8 @@ func (group *RouterGroup[T]) Group(prefix string) *RouterGroup[T] {
// aka. executes in the order they were registered.
//
// 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.
func (group *RouterGroup[T]) BindFunc(middlewareFuncs ...func(T) error) *RouterGroup[T] {
// or middleware with custom exec prirority, use [RouterGroup.Bind] method.
func (group *RouterGroup[T]) BindFunc(middlewareFuncs ...func(e T) error) *RouterGroup[T] {
for _, m := range middlewareFuncs {
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.
//
// 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]{
Method: method,
Path: path,
@ -127,48 +127,48 @@ func (group *RouterGroup[T]) Route(method string, path string, action func(T) er
return route
}
// Any is a shorthand for [Group.AddRoute] with "" as route method (aka. matches any method).
func (group *RouterGroup[T]) Any(path string, action func(T) error) *Route[T] {
// Any is a shorthand for [RouterGroup.AddRoute] with "" as route method (aka. matches any method).
func (group *RouterGroup[T]) Any(path string, action func(e T) error) *Route[T] {
return group.Route("", path, action)
}
// GET is a shorthand for [Group.AddRoute] with GET as route method.
func (group *RouterGroup[T]) GET(path string, action func(T) error) *Route[T] {
// GET is a shorthand for [RouterGroup.AddRoute] with GET as route method.
func (group *RouterGroup[T]) GET(path string, action func(e T) error) *Route[T] {
return group.Route(http.MethodGet, path, action)
}
// SEARCH is a shorthand for [Group.AddRoute] with SEARCH as route method.
func (group *RouterGroup[T]) SEARCH(path string, action func(T) error) *Route[T] {
// SEARCH is a shorthand for [RouterGroup.AddRoute] with SEARCH as route method.
func (group *RouterGroup[T]) SEARCH(path string, action func(e T) error) *Route[T] {
return group.Route("SEARCH", path, action)
}
// POST is a shorthand for [Group.AddRoute] with POST as route method.
func (group *RouterGroup[T]) POST(path string, action func(T) error) *Route[T] {
// POST is a shorthand for [RouterGroup.AddRoute] with POST as route method.
func (group *RouterGroup[T]) POST(path string, action func(e T) error) *Route[T] {
return group.Route(http.MethodPost, path, action)
}
// DELETE is a shorthand for [Group.AddRoute] with DELETE as route method.
func (group *RouterGroup[T]) DELETE(path string, action func(T) error) *Route[T] {
// DELETE is a shorthand for [RouterGroup.AddRoute] with DELETE as route method.
func (group *RouterGroup[T]) DELETE(path string, action func(e T) error) *Route[T] {
return group.Route(http.MethodDelete, path, action)
}
// PATCH is a shorthand for [Group.AddRoute] with PATCH as route method.
func (group *RouterGroup[T]) PATCH(path string, action func(T) error) *Route[T] {
// PATCH is a shorthand for [RouterGroup.AddRoute] with PATCH as route method.
func (group *RouterGroup[T]) PATCH(path string, action func(e T) error) *Route[T] {
return group.Route(http.MethodPatch, path, action)
}
// PUT is a shorthand for [Group.AddRoute] with PUT as route method.
func (group *RouterGroup[T]) PUT(path string, action func(T) error) *Route[T] {
// PUT is a shorthand for [RouterGroup.AddRoute] with PUT as route method.
func (group *RouterGroup[T]) PUT(path string, action func(e T) error) *Route[T] {
return group.Route(http.MethodPut, path, action)
}
// HEAD is a shorthand for [Group.AddRoute] with HEAD as route method.
func (group *RouterGroup[T]) HEAD(path string, action func(T) error) *Route[T] {
// HEAD is a shorthand for [RouterGroup.AddRoute] with HEAD as route method.
func (group *RouterGroup[T]) HEAD(path string, action func(e T) error) *Route[T] {
return group.Route(http.MethodHead, path, action)
}
// OPTIONS is a shorthand for [Group.AddRoute] with OPTIONS as route method.
func (group *RouterGroup[T]) OPTIONS(path string, action func(T) error) *Route[T] {
// OPTIONS is a shorthand for [RouterGroup.AddRoute] with OPTIONS as route method.
func (group *RouterGroup[T]) OPTIONS(path string, action func(e T) error) *Route[T] {
return group.Route(http.MethodOptions, path, action)
}

View File

@ -5,7 +5,7 @@ import "github.com/pocketbase/pocketbase/tools/hook"
type Route[T hook.Resolver] struct {
excludedMiddlewares map[string]struct{}
Action func(T) error
Action func(e T) error
Method string
Path string
Middlewares []*hook.Handler[T]
@ -17,8 +17,8 @@ type Route[T hook.Resolver] struct {
// aka. executes in the order they were registered.
//
// 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.
func (route *Route[T]) BindFunc(middlewareFuncs ...func(T) error) *Route[T] {
// or middleware with custom exec prirority, use the [Route.Bind] method.
func (route *Route[T]) BindFunc(middlewareFuncs ...func(e T) error) *Route[T] {
for _, m := range middlewareFuncs {
route.Middlewares = append(route.Middlewares, &hook.Handler[T]{Func: m})
}

View File

@ -44,6 +44,8 @@ type EventFactoryFunc[T hook.Resolver] func(w http.ResponseWriter, r *http.Reque
//
// http.ListenAndServe("localhost:8090", mux)
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]
eventFactory EventFactoryFunc[T]