From 745b2300970821d841ee3b5508a7470cdc04c324 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Wed, 14 Jun 2023 13:14:30 +0300 Subject: [PATCH] updated jsvm mapper and updated godoc formatting --- core/app.go | 4 ++-- core/base.go | 4 ++-- plugins/jsvm/mapper.go | 25 +++++++++++++++++++------ plugins/jsvm/mapper_test.go | 3 ++- tools/store/store.go | 2 +- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/core/app.go b/core/app.go index 98f2ccd8..c333fa73 100644 --- a/core/app.go +++ b/core/app.go @@ -74,14 +74,14 @@ type App interface { // NewFilesystem creates and returns a configured filesystem.System instance // for managing regular app files (eg. collection uploads). // - // NB! Make sure to call `Close()` on the returned result + // NB! Make sure to call Close() on the returned result // after you are done working with it. NewFilesystem() (*filesystem.System, error) // NewBackupsFilesystem creates and returns a configured filesystem.System instance // for managing app backups. // - // NB! Make sure to call `Close()` on the returned result + // NB! Make sure to call Close() on the returned result // after you are done working with it. NewBackupsFilesystem() (*filesystem.System, error) diff --git a/core/base.go b/core/base.go index a940c610..26084a7e 100644 --- a/core/base.go +++ b/core/base.go @@ -485,7 +485,7 @@ func (app *BaseApp) NewMailClient() mailer.Mailer { // for managing regular app files (eg. collection uploads) // based on the current app settings. // -// NB! Make sure to call `Close()` on the returned result +// NB! Make sure to call Close() on the returned result // after you are done working with it. func (app *BaseApp) NewFilesystem() (*filesystem.System, error) { if app.settings != nil && app.settings.S3.Enabled { @@ -506,7 +506,7 @@ func (app *BaseApp) NewFilesystem() (*filesystem.System, error) { // NewFilesystem creates a new local or S3 filesystem instance // for managing app backups based on the current app settings. // -// NB! Make sure to call `Close()` on the returned result +// NB! Make sure to call Close() on the returned result // after you are done working with it. func (app *BaseApp) NewBackupsFilesystem() (*filesystem.System, error) { if app.settings != nil && app.settings.Backups.S3.Enabled { diff --git a/plugins/jsvm/mapper.go b/plugins/jsvm/mapper.go index febe8b12..27f35431 100644 --- a/plugins/jsvm/mapper.go +++ b/plugins/jsvm/mapper.go @@ -30,19 +30,32 @@ func (u FieldMapper) MethodName(_ reflect.Type, m reflect.Method) string { } func convertGoToJSName(name string) string { - allUppercase := true + startUppercase := make([]rune, 0, len(name)) + for _, c := range name { - if c != '_' && !unicode.IsUpper(c) { - allUppercase = false + if c != '_' && !unicode.IsUpper(c) && !unicode.IsDigit(c) { break } + + startUppercase = append(startUppercase, c) } - // eg. "JSON" -> "json" - if allUppercase { + totalStartUppercase := len(startUppercase) + + // all uppercase eg. "JSON" -> "json" + if len(name) == totalStartUppercase { return strings.ToLower(name) } + // eg. "JSONField" -> "jsonField" + if totalStartUppercase > 1 { + return strings.ToLower(name[0:totalStartUppercase-1]) + name[totalStartUppercase-1:] + } + // eg. "GetField" -> "getField" - return strings.ToLower(name[0:1]) + name[1:] + if totalStartUppercase == 1 { + return strings.ToLower(name[0:1]) + name[1:] + } + + return name } diff --git a/plugins/jsvm/mapper_test.go b/plugins/jsvm/mapper_test.go index 4377b317..4ddfd628 100644 --- a/plugins/jsvm/mapper_test.go +++ b/plugins/jsvm/mapper_test.go @@ -22,8 +22,9 @@ func TestFieldMapper(t *testing.T) { {"ResolveRequestAsJSON", "resolveRequestAsJSON"}, {"Variable_with_underscore", "variable_with_underscore"}, {"ALLCAPS", "allcaps"}, - {"NOTALLCAPs", "nOTALLCAPs"}, {"ALL_CAPS_WITH_UNDERSCORE", "all_caps_with_underscore"}, + {"OIDCMap", "oidcMap"}, + {"MD5", "md5"}, } for i, s := range scenarios { diff --git a/tools/store/store.go b/tools/store/store.go index 2442139d..b3121e62 100644 --- a/tools/store/store.go +++ b/tools/store/store.go @@ -108,7 +108,7 @@ func (s *Store[T]) Set(key string, value T) { // // This method is similar to Set() but **it will skip adding new elements** // to the store if the store length has reached the specified limit. -// `false` is returned if maxAllowedElements limit is reached. +// false is returned if maxAllowedElements limit is reached. func (s *Store[T]) SetIfLessThanLimit(key string, value T, maxAllowedElements int) bool { s.mux.Lock() defer s.mux.Unlock()