fixed formatting and typos

This commit is contained in:
Gani Georgiev 2023-02-23 21:51:42 +02:00
parent aa4e405f92
commit 21b152b58c
14 changed files with 45 additions and 50 deletions

View File

@ -45,7 +45,7 @@
- **!** Repurposed the Authentik integration as a more generic "OpenID Connect" provider (`oidc`) to support any OIDC provider (Okta, Keycloak, etc.). - **!** Repurposed the Authentik integration as a more generic "OpenID Connect" provider (`oidc`) to support any OIDC provider (Okta, Keycloak, etc.).
_If you've previously used Authentik, make sure to rename the provider key in your code to `oidc`._ _If you've previously used Authentik, make sure to rename the provider key in your code to `oidc`._
_For more than one OIDC provider you can use the additional `oidc2` and `oidc3` settings._ _To enable more than one OIDC provider you can use the additional `oidc2` and `oidc3` provider keys._
- **!** Removed the previously deprecated `Dao.Block()` and `Dao.Continue()` helpers in favor of `Dao.NonconcurrentDB()`. - **!** Removed the previously deprecated `Dao.Block()` and `Dao.Continue()` helpers in favor of `Dao.NonconcurrentDB()`.

View File

@ -17,6 +17,7 @@ func execLockRetry(timeout time.Duration, maxRetries int) dbx.ExecHookFunc {
cancelCtx, cancel := context.WithTimeout(context.Background(), timeout) cancelCtx, cancel := context.WithTimeout(context.Background(), timeout)
defer func() { defer func() {
cancel() cancel()
//nolint:staticcheck
q.WithContext(nil) // reset q.WithContext(nil) // reset
}() }()
q.WithContext(cancelCtx) q.WithContext(cancelCtx)

View File

@ -12,8 +12,8 @@ func (dao *Dao) ExternalAuthQuery() *dbx.SelectQuery {
return dao.ModelQuery(&models.ExternalAuth{}) return dao.ModelQuery(&models.ExternalAuth{})
} }
/// FindAllExternalAuthsByRecord returns all ExternalAuth models // FindAllExternalAuthsByRecord returns all ExternalAuth models
/// linked to the provided auth record. // linked to the provided auth record.
func (dao *Dao) FindAllExternalAuthsByRecord(authRecord *models.Record) ([]*models.ExternalAuth, error) { func (dao *Dao) FindAllExternalAuthsByRecord(authRecord *models.Record) ([]*models.ExternalAuth, error) {
auths := []*models.ExternalAuth{} auths := []*models.ExternalAuth{}

View File

@ -429,7 +429,6 @@ func (form *RecordUpsert) LoadData(requestData map[string]any) error {
if len(submittedNames) == 0 && len(oldNames) > 0 { if len(submittedNames) == 0 && len(oldNames) > 0 {
form.RemoveFiles(key) form.RemoveFiles(key)
} else if len(oldNames) > 0 { } else if len(oldNames) > 0 {
toDelete := []string{} toDelete := []string{}
for _, name := range oldNames { for _, name := range oldNames {
@ -763,18 +762,6 @@ func (form *RecordUpsert) Submit(interceptors ...InterceptorFunc[*models.Record]
}, interceptors...) }, interceptors...)
} }
func (form *RecordUpsert) getFilesToUploadNames() []string {
names := []string{}
for fieldKey := range form.filesToUpload {
for _, file := range form.filesToUpload[fieldKey] {
names = append(names, file.Name)
}
}
return names
}
func (form *RecordUpsert) processFilesToUpload() error { func (form *RecordUpsert) processFilesToUpload() error {
if len(form.filesToUpload) == 0 { if len(form.filesToUpload) == 0 {
return nil // no parsed file fields return nil // no parsed file fields

View File

@ -13,6 +13,7 @@ import (
// size is no more than the provided maxBytes. // size is no more than the provided maxBytes.
// //
// Example: // Example:
//
// validation.Field(&form.File, validation.By(validators.UploadedFileSize(1000))) // validation.Field(&form.File, validation.By(validators.UploadedFileSize(1000)))
func UploadedFileSize(maxBytes int) validation.RuleFunc { func UploadedFileSize(maxBytes int) validation.RuleFunc {
return func(value any) error { return func(value any) error {
@ -36,7 +37,8 @@ func UploadedFileSize(maxBytes int) validation.RuleFunc {
// mimetype is within the provided allowed mime types. // mimetype is within the provided allowed mime types.
// //
// Example: // Example:
// validMimeTypes := []string{"test/plain","image/jpeg"} //
// validMimeTypes := []string{"test/plain","image/jpeg"}
// validation.Field(&form.File, validation.By(validators.UploadedFileMimeType(validMimeTypes))) // validation.Field(&form.File, validation.By(validators.UploadedFileMimeType(validMimeTypes)))
func UploadedFileMimeType(validTypes []string) validation.RuleFunc { func UploadedFileMimeType(validTypes []string) validation.RuleFunc {
return func(value any) error { return func(value any) error {

View File

@ -12,6 +12,7 @@ import (
// Compare checks whether the provided model id exists. // Compare checks whether the provided model id exists.
// //
// Example: // Example:
//
// validation.Field(&form.Id, validation.By(validators.UniqueId(form.dao, tableName))) // validation.Field(&form.Id, validation.By(validators.UniqueId(form.dao, tableName)))
func UniqueId(dao *daos.Dao, tableName string) validation.RuleFunc { func UniqueId(dao *daos.Dao, tableName string) validation.RuleFunc {
return func(value any) error { return func(value any) error {

View File

@ -7,6 +7,7 @@ import (
// Compare checks whether the validated value matches another string. // Compare checks whether the validated value matches another string.
// //
// Example: // Example:
//
// validation.Field(&form.PasswordConfirm, validation.By(validators.Compare(form.Password))) // validation.Field(&form.PasswordConfirm, validation.By(validators.Compare(form.Password)))
func Compare(valueToCompare string) validation.RuleFunc { func Compare(valueToCompare string) validation.RuleFunc {
return func(value any) error { return func(value any) error {

View File

@ -566,7 +566,7 @@ func (m *Record) ReplaceModifers(data map[string]any) map[string]any {
} }
// ----------------------------------------------------------- // -----------------------------------------------------------
// legacy file field modifiers (kept for backward compatability) // legacy file field modifiers (kept for backward compatibility)
// ----------------------------------------------------------- // -----------------------------------------------------------
var oldNames []string var oldNames []string

View File

@ -386,8 +386,7 @@ func (f *SchemaField) PrepareValueWithModifier(baseValue any, modifier string, m
} }
case FieldTypeFile: case FieldTypeFile:
// note: file for now supports only the subtract modifier // note: file for now supports only the subtract modifier
switch modifier { if modifier == FieldValueModifierSubtract {
case FieldValueModifierSubtract:
resolvedValue = list.SubtractSlice( resolvedValue = list.SubtractSlice(
list.ToUniqueStringSlice(baseValue), list.ToUniqueStringSlice(baseValue),
list.ToUniqueStringSlice(modifierValue), list.ToUniqueStringSlice(modifierValue),

View File

@ -5,9 +5,9 @@
// //
// 1. JS Migrations loader: // 1. JS Migrations loader:
// //
// jsvm.MustRegisterMigrations(app, &jsvm.MigrationsOptions{ // jsvm.MustRegisterMigrations(app, &jsvm.MigrationsOptions{
// Dir: "custom_js_migrations_dir_path", // default to "pb_data/../pb_migrations" // Dir: "custom_js_migrations_dir_path", // default to "pb_data/../pb_migrations"
// }) // })
package jsvm package jsvm
import ( import (

View File

@ -5,14 +5,14 @@
// //
// Example usage: // Example usage:
// //
// migratecmd.MustRegister(app, app.RootCmd, &migratecmd.Options{ // migratecmd.MustRegister(app, app.RootCmd, &migratecmd.Options{
// TemplateLang: migratecmd.TemplateLangJS, // default to migratecmd.TemplateLangGo // TemplateLang: migratecmd.TemplateLangJS, // default to migratecmd.TemplateLangGo
// Automigrate: true, // Automigrate: true,
// Dir: "migrations_dir_path", // optional template migrations path; default to "pb_migrations" (for JS) and "migrations" (for Go) // Dir: "migrations_dir_path", // optional template migrations path; default to "pb_migrations" (for JS) and "migrations" (for Go)
// }) // })
// //
// Note: To allow running JS migrations you'll need to enable first // Note: To allow running JS migrations you'll need to enable first
// [jsvm.MustRegisterMigrations]. // [jsvm.MustRegisterMigrations].
package migratecmd package migratecmd
import ( import (

View File

@ -42,15 +42,17 @@ var _ search.FieldResolver = (*RecordFieldResolver)(nil)
// RecordFieldResolver defines a custom search resolver struct for // RecordFieldResolver defines a custom search resolver struct for
// managing Record model search fields. // managing Record model search fields.
// //
// Usually used together with `search.Provider`. Example: // Usually used together with `search.Provider`.
// resolver := resolvers.NewRecordFieldResolver( // Example:
// app.Dao(), //
// myCollection, // resolver := resolvers.NewRecordFieldResolver(
// &models.RequestData{...}, // app.Dao(),
// true, // myCollection,
// ) // &models.RequestData{...},
// provider := search.NewProvider(resolver) // true,
// ... // )
// provider := search.NewProvider(resolver)
// ...
type RecordFieldResolver struct { type RecordFieldResolver struct {
dao *daos.Dao dao *daos.Dao
baseCollection *models.Collection baseCollection *models.Collection
@ -125,17 +127,17 @@ func (r *RecordFieldResolver) UpdateQuery(query *dbx.SelectQuery) error {
// //
// Example of some resolvable fieldName formats: // Example of some resolvable fieldName formats:
// //
// id // id
// someSelect.each // someSelect.each
// project.screen.status // project.screen.status
// @request.status // @request.status
// @request.query.filter // @request.query.filter
// @request.auth.someRelation.name // @request.auth.someRelation.name
// @request.data.someRelation.name // @request.data.someRelation.name
// @request.data.someField // @request.data.someField
// @request.data.someSelect:each // @request.data.someSelect:each
// @request.data.someField:isset // @request.data.someField:isset
// @collection.product.name // @collection.product.name
func (r *RecordFieldResolver) Resolve(fieldName string) (*search.ResolverResult, error) { func (r *RecordFieldResolver) Resolve(fieldName string) (*search.ResolverResult, error) {
return parseAndRun(fieldName, r) return parseAndRun(fieldName, r)
} }

View File

@ -10,6 +10,7 @@ import (
// MockMultipartData creates a mocked multipart/form-data payload. // MockMultipartData creates a mocked multipart/form-data payload.
// //
// Example // Example
//
// data, mp, err := tests.MockMultipartData( // data, mp, err := tests.MockMultipartData(
// map[string]string{"title": "new"}, // map[string]string{"title": "new"},
// "file1", // "file1",

View File

@ -40,6 +40,7 @@ func (s *SortField) BuildExpr(fieldResolver FieldResolver) (string, error) {
// into a slice of SortFields. // into a slice of SortFields.
// //
// Example: // Example:
//
// fields := search.ParseSortFromString("-name,+created") // fields := search.ParseSortFromString("-name,+created")
func ParseSortFromString(str string) (fields []SortField) { func ParseSortFromString(str string) (fields []SortField) {
data := strings.Split(str, ",") data := strings.Split(str, ",")