From 47d5ea3ce2075baf639a5c5fcd7fb5e08c6db9ae Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Mon, 14 Oct 2024 14:32:52 +0300 Subject: [PATCH] fixed comments and added default generic arg name --- CHANGELOG.md | 11 ++++++++ apis/middlewares_body_limit.go | 3 -- apis/middlewares_gzip.go | 2 +- core/base.go | 4 +-- plugins/jsvm/internal/types/types.go | 2 +- tools/router/group.go | 42 ++++++++++++++-------------- tools/router/route.go | 6 ++-- tools/router/router.go | 2 ++ 8 files changed, 41 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9e78fb9..5f830f7f 100644 --- a/CHANGELOG.md +++ b/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 > [!CAUTION] diff --git a/apis/middlewares_body_limit.go b/apis/middlewares_body_limit.go index 643ec59d..aac09a06 100644 --- a/apis/middlewares_body_limit.go +++ b/apis/middlewares_body_limit.go @@ -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, diff --git a/apis/middlewares_gzip.go b/apis/middlewares_gzip.go index 7f205a87..68923e6e 100644 --- a/apis/middlewares_gzip.go +++ b/apis/middlewares_gzip.go @@ -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{}) } diff --git a/core/base.go b/core/base.go index 2ac42898..22869f83 100644 --- a/core/base.go +++ b/core/base.go @@ -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 diff --git a/plugins/jsvm/internal/types/types.go b/plugins/jsvm/internal/types/types.go index b09adea3..90039d34 100644 --- a/plugins/jsvm/internal/types/types.go +++ b/plugins/jsvm/internal/types/types.go @@ -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 diff --git a/tools/router/group.go b/tools/router/group.go index c9dec0fb..b6f75248 100644 --- a/tools/router/group.go +++ b/tools/router/group.go @@ -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) } diff --git a/tools/router/route.go b/tools/router/route.go index fb6063ac..351096df 100644 --- a/tools/router/route.go +++ b/tools/router/route.go @@ -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}) } diff --git a/tools/router/router.go b/tools/router/router.go index 8a9051da..bf862fff 100644 --- a/tools/router/router.go +++ b/tools/router/router.go @@ -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]