core

package
v0.22.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 40 Imported by: 331

Documentation

Overview

Package core is the backbone of PocketBase.

It defines the main PocketBase App interface and its base implementation.

Index

Constants

View Source
const (
	DefaultDataMaxOpenConns int = 120
	DefaultDataMaxIdleConns int = 20
	DefaultLogsMaxOpenConns int = 10
	DefaultLogsMaxIdleConns int = 2

	LocalStorageDirName string = "storage"
	LocalBackupsDirName string = "backups"
	LocalTempDirName    string = ".pb_temp_to_delete" // temp pb_data sub directory that will be deleted on each app.Bootstrap()
)
View Source
const CacheKeyActiveBackup string = "@activeBackup"

Deprecated: Replaced with StoreKeyActiveBackup.

View Source
const StoreKeyActiveBackup string = "@activeBackup"

Variables

This section is empty.

Functions

This section is empty.

Types

type AdminAuthEvent

type AdminAuthEvent struct {
	HttpContext echo.Context
	Admin       *models.Admin
	Token       string
}

type AdminAuthRefreshEvent added in v0.12.0

type AdminAuthRefreshEvent struct {
	HttpContext echo.Context
	Admin       *models.Admin
}

type AdminAuthWithPasswordEvent added in v0.12.0

type AdminAuthWithPasswordEvent struct {
	HttpContext echo.Context
	Admin       *models.Admin
	Identity    string
	Password    string
}

type AdminConfirmPasswordResetEvent added in v0.12.0

type AdminConfirmPasswordResetEvent struct {
	HttpContext echo.Context
	Admin       *models.Admin
}

type AdminCreateEvent

type AdminCreateEvent struct {
	HttpContext echo.Context
	Admin       *models.Admin
}

type AdminDeleteEvent

type AdminDeleteEvent struct {
	HttpContext echo.Context
	Admin       *models.Admin
}

type AdminRequestPasswordResetEvent added in v0.12.0

type AdminRequestPasswordResetEvent struct {
	HttpContext echo.Context
	Admin       *models.Admin
}

type AdminUpdateEvent

type AdminUpdateEvent struct {
	HttpContext echo.Context
	Admin       *models.Admin
}

type AdminViewEvent

type AdminViewEvent struct {
	HttpContext echo.Context
	Admin       *models.Admin
}

type AdminsListEvent

type AdminsListEvent struct {
	HttpContext echo.Context
	Admins      []*models.Admin
	Result      *search.Result
}

type ApiErrorEvent added in v0.9.0

type ApiErrorEvent struct {
	HttpContext echo.Context
	Error       error
}

type App

type App interface {
	// Deprecated:
	// This method may get removed in the near future.
	// It is recommended to access the app db instance from app.Dao().DB() or
	// if you want more flexibility - app.Dao().ConcurrentDB() and app.Dao().NonconcurrentDB().
	//
	// DB returns the default app database instance.
	DB() *dbx.DB

	// Dao returns the default app Dao instance.
	//
	// This Dao could operate only on the tables and models
	// associated with the default app database. For example,
	// trying to access the request logs table will result in error.
	Dao() *daos.Dao

	// Deprecated:
	// This method may get removed in the near future.
	// It is recommended to access the logs db instance from app.LogsDao().DB() or
	// if you want more flexibility - app.LogsDao().ConcurrentDB() and app.LogsDao().NonconcurrentDB().
	//
	// LogsDB returns the app logs database instance.
	LogsDB() *dbx.DB

	// LogsDao returns the app logs Dao instance.
	//
	// This Dao could operate only on the tables and models
	// associated with the logs database. For example, trying to access
	// the users table from LogsDao will result in error.
	LogsDao() *daos.Dao

	// Logger returns the active app logger.
	Logger() *slog.Logger

	// DataDir returns the app data directory path.
	DataDir() string

	// EncryptionEnv returns the name of the app secret env key
	// (used for settings encryption).
	EncryptionEnv() string

	// IsDev returns whether the app is in dev mode.
	IsDev() bool

	// Settings returns the loaded app settings.
	Settings() *settings.Settings

	// Deprecated: Use app.Store() instead.
	Cache() *store.Store[any]

	// Store returns the app runtime store.
	Store() *store.Store[any]

	// SubscriptionsBroker returns the app realtime subscriptions broker instance.
	SubscriptionsBroker() *subscriptions.Broker

	// NewMailClient creates and returns a configured app mail client.
	NewMailClient() mailer.Mailer

	// 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
	// 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
	// after you are done working with it.
	NewBackupsFilesystem() (*filesystem.System, error)

	// RefreshSettings reinitializes and reloads the stored application settings.
	RefreshSettings() error

	// IsBootstrapped checks if the application was initialized
	// (aka. whether Bootstrap() was called).
	IsBootstrapped() bool

	// Bootstrap takes care for initializing the application
	// (open db connections, load settings, etc.).
	//
	// It will call ResetBootstrapState() if the application was already bootstrapped.
	Bootstrap() error

	// ResetBootstrapState takes care for releasing initialized app resources
	// (eg. closing db connections).
	ResetBootstrapState() error

	// CreateBackup creates a new backup of the current app pb_data directory.
	//
	// Backups can be stored on S3 if it is configured in app.Settings().Backups.
	//
	// Please refer to the godoc of the specific core.App implementation
	// for details on the backup procedures.
	CreateBackup(ctx context.Context, name string) error

	// RestoreBackup restores the backup with the specified name and restarts
	// the current running application process.
	//
	// The safely perform the restore it is recommended to have free disk space
	// for at least 2x the size of the restored pb_data backup.
	//
	// Please refer to the godoc of the specific core.App implementation
	// for details on the restore procedures.
	//
	// NB! This feature is experimental and currently is expected to work only on UNIX based systems.
	RestoreBackup(ctx context.Context, name string) error

	// Restart restarts the current running application process.
	//
	// Currently it is relying on execve so it is supported only on UNIX based systems.
	Restart() error

	// OnBeforeBootstrap hook is triggered before initializing the main
	// application resources (eg. before db open and initial settings load).
	OnBeforeBootstrap() *hook.Hook[*BootstrapEvent]

	// OnAfterBootstrap hook is triggered after initializing the main
	// application resources (eg. after db open and initial settings load).
	OnAfterBootstrap() *hook.Hook[*BootstrapEvent]

	// OnBeforeServe hook is triggered before serving the internal router (echo),
	// allowing you to adjust its options and attach new routes or middlewares.
	OnBeforeServe() *hook.Hook[*ServeEvent]

	// OnBeforeApiError hook is triggered right before sending an error API
	// response to the client, allowing you to further modify the error data
	// or to return a completely different API response.
	OnBeforeApiError() *hook.Hook[*ApiErrorEvent]

	// OnAfterApiError hook is triggered right after sending an error API
	// response to the client.
	// It could be used to log the final API error in external services.
	OnAfterApiError() *hook.Hook[*ApiErrorEvent]

	// OnTerminate hook is triggered when the app is in the process
	// of being terminated (eg. on SIGTERM signal).
	OnTerminate() *hook.Hook[*TerminateEvent]

	// OnModelBeforeCreate hook is triggered before inserting a new
	// model in the DB, allowing you to modify or validate the stored data.
	//
	// If the optional "tags" list (table names and/or the Collection id for Record models)
	// is specified, then all event handlers registered via the created hook
	// will be triggered and called only if their event data origin matches the tags.
	OnModelBeforeCreate(tags ...string) *hook.TaggedHook[*ModelEvent]

	// OnModelAfterCreate hook is triggered after successfully
	// inserting a new model in the DB.
	//
	// If the optional "tags" list (table names and/or the Collection id for Record models)
	// is specified, then all event handlers registered via the created hook
	// will be triggered and called only if their event data origin matches the tags.
	OnModelAfterCreate(tags ...string) *hook.TaggedHook[*ModelEvent]

	// OnModelBeforeUpdate hook is triggered before updating existing
	// model in the DB, allowing you to modify or validate the stored data.
	//
	// If the optional "tags" list (table names and/or the Collection id for Record models)
	// is specified, then all event handlers registered via the created hook
	// will be triggered and called only if their event data origin matches the tags.
	OnModelBeforeUpdate(tags ...string) *hook.TaggedHook[*ModelEvent]

	// OnModelAfterUpdate hook is triggered after successfully updating
	// existing model in the DB.
	//
	// If the optional "tags" list (table names and/or the Collection id for Record models)
	// is specified, then all event handlers registered via the created hook
	// will be triggered and called only if their event data origin matches the tags.
	OnModelAfterUpdate(tags ...string) *hook.TaggedHook[*ModelEvent]

	// OnModelBeforeDelete hook is triggered before deleting an
	// existing model from the DB.
	//
	// If the optional "tags" list (table names and/or the Collection id for Record models)
	// is specified, then all event handlers registered via the created hook
	// will be triggered and called only if their event data origin matches the tags.
	OnModelBeforeDelete(tags ...string) *hook.TaggedHook[*ModelEvent]

	// OnModelAfterDelete hook is triggered after successfully deleting an
	// existing model from the DB.
	//
	// If the optional "tags" list (table names and/or the Collection id for Record models)
	// is specified, then all event handlers registered via the created hook
	// will be triggered and called only if their event data origin matches the tags.
	OnModelAfterDelete(tags ...string) *hook.TaggedHook[*ModelEvent]

	// OnMailerBeforeAdminResetPasswordSend hook is triggered right
	// before sending a password reset email to an admin, allowing you
	// to inspect and customize the email message that is being sent.
	OnMailerBeforeAdminResetPasswordSend() *hook.Hook[*MailerAdminEvent]

	// OnMailerAfterAdminResetPasswordSend hook is triggered after
	// admin password reset email was successfully sent.
	OnMailerAfterAdminResetPasswordSend() *hook.Hook[*MailerAdminEvent]

	// OnMailerBeforeRecordResetPasswordSend hook is triggered right
	// before sending a password reset email to an auth record, allowing
	// you to inspect and customize the email message that is being sent.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnMailerBeforeRecordResetPasswordSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent]

	// OnMailerAfterRecordResetPasswordSend hook is triggered after
	// an auth record password reset email was successfully sent.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnMailerAfterRecordResetPasswordSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent]

	// OnMailerBeforeRecordVerificationSend hook is triggered right
	// before sending a verification email to an auth record, allowing
	// you to inspect and customize the email message that is being sent.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnMailerBeforeRecordVerificationSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent]

	// OnMailerAfterRecordVerificationSend hook is triggered after a
	// verification email was successfully sent to an auth record.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnMailerAfterRecordVerificationSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent]

	// OnMailerBeforeRecordChangeEmailSend hook is triggered right before
	// sending a confirmation new address email to an auth record, allowing
	// you to inspect and customize the email message that is being sent.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnMailerBeforeRecordChangeEmailSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent]

	// OnMailerAfterRecordChangeEmailSend hook is triggered after a
	// verification email was successfully sent to an auth record.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnMailerAfterRecordChangeEmailSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent]

	// OnRealtimeConnectRequest hook is triggered right before establishing
	// the SSE client connection.
	OnRealtimeConnectRequest() *hook.Hook[*RealtimeConnectEvent]

	// OnRealtimeDisconnectRequest hook is triggered on disconnected/interrupted
	// SSE client connection.
	OnRealtimeDisconnectRequest() *hook.Hook[*RealtimeDisconnectEvent]

	// OnRealtimeBeforeMessageSend hook is triggered right before sending
	// an SSE message to a client.
	//
	// Returning [hook.StopPropagation] will prevent sending the message.
	// Returning any other non-nil error will close the realtime connection.
	OnRealtimeBeforeMessageSend() *hook.Hook[*RealtimeMessageEvent]

	// OnRealtimeAfterMessageSend hook is triggered right after sending
	// an SSE message to a client.
	OnRealtimeAfterMessageSend() *hook.Hook[*RealtimeMessageEvent]

	// OnRealtimeBeforeSubscribeRequest hook is triggered before changing
	// the client subscriptions, allowing you to further validate and
	// modify the submitted change.
	OnRealtimeBeforeSubscribeRequest() *hook.Hook[*RealtimeSubscribeEvent]

	// OnRealtimeAfterSubscribeRequest hook is triggered after the client
	// subscriptions were successfully changed.
	OnRealtimeAfterSubscribeRequest() *hook.Hook[*RealtimeSubscribeEvent]

	// OnSettingsListRequest hook is triggered on each successful
	// API Settings list request.
	//
	// Could be used to validate or modify the response before
	// returning it to the client.
	OnSettingsListRequest() *hook.Hook[*SettingsListEvent]

	// OnSettingsBeforeUpdateRequest hook is triggered before each API
	// Settings update request (after request data load and before settings persistence).
	//
	// Could be used to additionally validate the request data or
	// implement completely different persistence behavior.
	OnSettingsBeforeUpdateRequest() *hook.Hook[*SettingsUpdateEvent]

	// OnSettingsAfterUpdateRequest hook is triggered after each
	// successful API Settings update request.
	OnSettingsAfterUpdateRequest() *hook.Hook[*SettingsUpdateEvent]

	// OnFileDownloadRequest hook is triggered before each API File download request.
	//
	// Could be used to validate or modify the file response before
	// returning it to the client.
	OnFileDownloadRequest(tags ...string) *hook.TaggedHook[*FileDownloadEvent]

	// OnFileBeforeTokenRequest hook is triggered before each file
	// token API request.
	//
	// If no token or model was submitted, e.Model and e.Token will be empty,
	// allowing you to implement your own custom model file auth implementation.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnFileBeforeTokenRequest(tags ...string) *hook.TaggedHook[*FileTokenEvent]

	// OnFileAfterTokenRequest hook is triggered after each
	// successful file token API request.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnFileAfterTokenRequest(tags ...string) *hook.TaggedHook[*FileTokenEvent]

	// OnAdminsListRequest hook is triggered on each API Admins list request.
	//
	// Could be used to validate or modify the response before returning it to the client.
	OnAdminsListRequest() *hook.Hook[*AdminsListEvent]

	// OnAdminViewRequest hook is triggered on each API Admin view request.
	//
	// Could be used to validate or modify the response before returning it to the client.
	OnAdminViewRequest() *hook.Hook[*AdminViewEvent]

	// OnAdminBeforeCreateRequest hook is triggered before each API
	// Admin create request (after request data load and before model persistence).
	//
	// Could be used to additionally validate the request data or implement
	// completely different persistence behavior.
	OnAdminBeforeCreateRequest() *hook.Hook[*AdminCreateEvent]

	// OnAdminAfterCreateRequest hook is triggered after each
	// successful API Admin create request.
	OnAdminAfterCreateRequest() *hook.Hook[*AdminCreateEvent]

	// OnAdminBeforeUpdateRequest hook is triggered before each API
	// Admin update request (after request data load and before model persistence).
	//
	// Could be used to additionally validate the request data or implement
	// completely different persistence behavior.
	OnAdminBeforeUpdateRequest() *hook.Hook[*AdminUpdateEvent]

	// OnAdminAfterUpdateRequest hook is triggered after each
	// successful API Admin update request.
	OnAdminAfterUpdateRequest() *hook.Hook[*AdminUpdateEvent]

	// OnAdminBeforeDeleteRequest hook is triggered before each API
	// Admin delete request (after model load and before actual deletion).
	//
	// Could be used to additionally validate the request data or implement
	// completely different delete behavior.
	OnAdminBeforeDeleteRequest() *hook.Hook[*AdminDeleteEvent]

	// OnAdminAfterDeleteRequest hook is triggered after each
	// successful API Admin delete request.
	OnAdminAfterDeleteRequest() *hook.Hook[*AdminDeleteEvent]

	// OnAdminAuthRequest hook is triggered on each successful API Admin
	// authentication request (sign-in, token refresh, etc.).
	//
	// Could be used to additionally validate or modify the
	// authenticated admin data and token.
	OnAdminAuthRequest() *hook.Hook[*AdminAuthEvent]

	// OnAdminBeforeAuthWithPasswordRequest hook is triggered before each Admin
	// auth with password API request (after request data load and before password validation).
	//
	// Could be used to implement for example a custom password validation
	// or to locate a different Admin identity (by assigning [AdminAuthWithPasswordEvent.Admin]).
	OnAdminBeforeAuthWithPasswordRequest() *hook.Hook[*AdminAuthWithPasswordEvent]

	// OnAdminAfterAuthWithPasswordRequest hook is triggered after each
	// successful Admin auth with password API request.
	OnAdminAfterAuthWithPasswordRequest() *hook.Hook[*AdminAuthWithPasswordEvent]

	// OnAdminBeforeAuthRefreshRequest hook is triggered before each Admin
	// auth refresh API request (right before generating a new auth token).
	//
	// Could be used to additionally validate the request data or implement
	// completely different auth refresh behavior.
	OnAdminBeforeAuthRefreshRequest() *hook.Hook[*AdminAuthRefreshEvent]

	// OnAdminAfterAuthRefreshRequest hook is triggered after each
	// successful auth refresh API request (right after generating a new auth token).
	OnAdminAfterAuthRefreshRequest() *hook.Hook[*AdminAuthRefreshEvent]

	// OnAdminBeforeRequestPasswordResetRequest hook is triggered before each Admin
	// request password reset API request (after request data load and before sending the reset email).
	//
	// Could be used to additionally validate the request data or implement
	// completely different password reset behavior.
	OnAdminBeforeRequestPasswordResetRequest() *hook.Hook[*AdminRequestPasswordResetEvent]

	// OnAdminAfterRequestPasswordResetRequest hook is triggered after each
	// successful request password reset API request.
	OnAdminAfterRequestPasswordResetRequest() *hook.Hook[*AdminRequestPasswordResetEvent]

	// OnAdminBeforeConfirmPasswordResetRequest hook is triggered before each Admin
	// confirm password reset API request (after request data load and before persistence).
	//
	// Could be used to additionally validate the request data or implement
	// completely different persistence behavior.
	OnAdminBeforeConfirmPasswordResetRequest() *hook.Hook[*AdminConfirmPasswordResetEvent]

	// OnAdminAfterConfirmPasswordResetRequest hook is triggered after each
	// successful confirm password reset API request.
	OnAdminAfterConfirmPasswordResetRequest() *hook.Hook[*AdminConfirmPasswordResetEvent]

	// OnRecordAuthRequest hook is triggered on each successful API
	// record authentication request (sign-in, token refresh, etc.).
	//
	// Could be used to additionally validate or modify the authenticated
	// record data and token.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordAuthRequest(tags ...string) *hook.TaggedHook[*RecordAuthEvent]

	// OnRecordBeforeAuthWithPasswordRequest hook is triggered before each Record
	// auth with password API request (after request data load and before password validation).
	//
	// Could be used to implement for example a custom password validation
	// or to locate a different Record model (by reassigning [RecordAuthWithPasswordEvent.Record]).
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordBeforeAuthWithPasswordRequest(tags ...string) *hook.TaggedHook[*RecordAuthWithPasswordEvent]

	// OnRecordAfterAuthWithPasswordRequest hook is triggered after each
	// successful Record auth with password API request.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordAfterAuthWithPasswordRequest(tags ...string) *hook.TaggedHook[*RecordAuthWithPasswordEvent]

	// OnRecordBeforeAuthWithOAuth2Request hook is triggered before each Record
	// OAuth2 sign-in/sign-up API request (after token exchange and before external provider linking).
	//
	// If the [RecordAuthWithOAuth2Event.Record] is not set, then the OAuth2
	// request will try to create a new auth Record.
	//
	// To assign or link a different existing record model you can
	// change the [RecordAuthWithOAuth2Event.Record] field.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordBeforeAuthWithOAuth2Request(tags ...string) *hook.TaggedHook[*RecordAuthWithOAuth2Event]

	// OnRecordAfterAuthWithOAuth2Request hook is triggered after each
	// successful Record OAuth2 API request.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordAfterAuthWithOAuth2Request(tags ...string) *hook.TaggedHook[*RecordAuthWithOAuth2Event]

	// OnRecordBeforeAuthRefreshRequest hook is triggered before each Record
	// auth refresh API request (right before generating a new auth token).
	//
	// Could be used to additionally validate the request data or implement
	// completely different auth refresh behavior.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordBeforeAuthRefreshRequest(tags ...string) *hook.TaggedHook[*RecordAuthRefreshEvent]

	// OnRecordAfterAuthRefreshRequest hook is triggered after each
	// successful auth refresh API request (right after generating a new auth token).
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordAfterAuthRefreshRequest(tags ...string) *hook.TaggedHook[*RecordAuthRefreshEvent]

	// OnRecordListExternalAuthsRequest hook is triggered on each API record external auths list request.
	//
	// Could be used to validate or modify the response before returning it to the client.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordListExternalAuthsRequest(tags ...string) *hook.TaggedHook[*RecordListExternalAuthsEvent]

	// OnRecordBeforeUnlinkExternalAuthRequest hook is triggered before each API record
	// external auth unlink request (after models load and before the actual relation deletion).
	//
	// Could be used to additionally validate the request data or implement
	// completely different delete behavior.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordBeforeUnlinkExternalAuthRequest(tags ...string) *hook.TaggedHook[*RecordUnlinkExternalAuthEvent]

	// OnRecordAfterUnlinkExternalAuthRequest hook is triggered after each
	// successful API record external auth unlink request.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordAfterUnlinkExternalAuthRequest(tags ...string) *hook.TaggedHook[*RecordUnlinkExternalAuthEvent]

	// OnRecordBeforeRequestPasswordResetRequest hook is triggered before each Record
	// request password reset API request (after request data load and before sending the reset email).
	//
	// Could be used to additionally validate the request data or implement
	// completely different password reset behavior.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordBeforeRequestPasswordResetRequest(tags ...string) *hook.TaggedHook[*RecordRequestPasswordResetEvent]

	// OnRecordAfterRequestPasswordResetRequest hook is triggered after each
	// successful request password reset API request.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordAfterRequestPasswordResetRequest(tags ...string) *hook.TaggedHook[*RecordRequestPasswordResetEvent]

	// OnRecordBeforeConfirmPasswordResetRequest hook is triggered before each Record
	// confirm password reset API request (after request data load and before persistence).
	//
	// Could be used to additionally validate the request data or implement
	// completely different persistence behavior.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordBeforeConfirmPasswordResetRequest(tags ...string) *hook.TaggedHook[*RecordConfirmPasswordResetEvent]

	// OnRecordAfterConfirmPasswordResetRequest hook is triggered after each
	// successful confirm password reset API request.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordAfterConfirmPasswordResetRequest(tags ...string) *hook.TaggedHook[*RecordConfirmPasswordResetEvent]

	// OnRecordBeforeRequestVerificationRequest hook is triggered before each Record
	// request verification API request (after request data load and before sending the verification email).
	//
	// Could be used to additionally validate the loaded request data or implement
	// completely different verification behavior.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordBeforeRequestVerificationRequest(tags ...string) *hook.TaggedHook[*RecordRequestVerificationEvent]

	// OnRecordAfterRequestVerificationRequest hook is triggered after each
	// successful request verification API request.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordAfterRequestVerificationRequest(tags ...string) *hook.TaggedHook[*RecordRequestVerificationEvent]

	// OnRecordBeforeConfirmVerificationRequest hook is triggered before each Record
	// confirm verification API request (after request data load and before persistence).
	//
	// Could be used to additionally validate the request data or implement
	// completely different persistence behavior.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordBeforeConfirmVerificationRequest(tags ...string) *hook.TaggedHook[*RecordConfirmVerificationEvent]

	// OnRecordAfterConfirmVerificationRequest hook is triggered after each
	// successful confirm verification API request.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordAfterConfirmVerificationRequest(tags ...string) *hook.TaggedHook[*RecordConfirmVerificationEvent]

	// OnRecordBeforeRequestEmailChangeRequest hook is triggered before each Record request email change API request
	// (after request data load and before sending the email link to confirm the change).
	//
	// Could be used to additionally validate the request data or implement
	// completely different request email change behavior.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordBeforeRequestEmailChangeRequest(tags ...string) *hook.TaggedHook[*RecordRequestEmailChangeEvent]

	// OnRecordAfterRequestEmailChangeRequest hook is triggered after each
	// successful request email change API request.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordAfterRequestEmailChangeRequest(tags ...string) *hook.TaggedHook[*RecordRequestEmailChangeEvent]

	// OnRecordBeforeConfirmEmailChangeRequest hook is triggered before each Record
	// confirm email change API request (after request data load and before persistence).
	//
	// Could be used to additionally validate the request data or implement
	// completely different persistence behavior.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordBeforeConfirmEmailChangeRequest(tags ...string) *hook.TaggedHook[*RecordConfirmEmailChangeEvent]

	// OnRecordAfterConfirmEmailChangeRequest hook is triggered after each
	// successful confirm email change API request.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordAfterConfirmEmailChangeRequest(tags ...string) *hook.TaggedHook[*RecordConfirmEmailChangeEvent]

	// OnRecordsListRequest hook is triggered on each API Records list request.
	//
	// Could be used to validate or modify the response before returning it to the client.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordsListRequest(tags ...string) *hook.TaggedHook[*RecordsListEvent]

	// OnRecordViewRequest hook is triggered on each API Record view request.
	//
	// Could be used to validate or modify the response before returning it to the client.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordViewRequest(tags ...string) *hook.TaggedHook[*RecordViewEvent]

	// OnRecordBeforeCreateRequest hook is triggered before each API Record
	// create request (after request data load and before model persistence).
	//
	// Could be used to additionally validate the request data or implement
	// completely different persistence behavior.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordBeforeCreateRequest(tags ...string) *hook.TaggedHook[*RecordCreateEvent]

	// OnRecordAfterCreateRequest hook is triggered after each
	// successful API Record create request.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordAfterCreateRequest(tags ...string) *hook.TaggedHook[*RecordCreateEvent]

	// OnRecordBeforeUpdateRequest hook is triggered before each API Record
	// update request (after request data load and before model persistence).
	//
	// Could be used to additionally validate the request data or implement
	// completely different persistence behavior.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordBeforeUpdateRequest(tags ...string) *hook.TaggedHook[*RecordUpdateEvent]

	// OnRecordAfterUpdateRequest hook is triggered after each
	// successful API Record update request.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordAfterUpdateRequest(tags ...string) *hook.TaggedHook[*RecordUpdateEvent]

	// OnRecordBeforeDeleteRequest hook is triggered before each API Record
	// delete request (after model load and before actual deletion).
	//
	// Could be used to additionally validate the request data or implement
	// completely different delete behavior.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordBeforeDeleteRequest(tags ...string) *hook.TaggedHook[*RecordDeleteEvent]

	// OnRecordAfterDeleteRequest hook is triggered after each
	// successful API Record delete request.
	//
	// If the optional "tags" list (Collection ids or names) is specified,
	// then all event handlers registered via the created hook will be
	// triggered and called only if their event data origin matches the tags.
	OnRecordAfterDeleteRequest(tags ...string) *hook.TaggedHook[*RecordDeleteEvent]

	// OnCollectionsListRequest hook is triggered on each API Collections list request.
	//
	// Could be used to validate or modify the response before returning it to the client.
	OnCollectionsListRequest() *hook.Hook[*CollectionsListEvent]

	// OnCollectionViewRequest hook is triggered on each API Collection view request.
	//
	// Could be used to validate or modify the response before returning it to the client.
	OnCollectionViewRequest() *hook.Hook[*CollectionViewEvent]

	// OnCollectionBeforeCreateRequest hook is triggered before each API Collection
	// create request (after request data load and before model persistence).
	//
	// Could be used to additionally validate the request data or implement
	// completely different persistence behavior.
	OnCollectionBeforeCreateRequest() *hook.Hook[*CollectionCreateEvent]

	// OnCollectionAfterCreateRequest hook is triggered after each
	// successful API Collection create request.
	OnCollectionAfterCreateRequest() *hook.Hook[*CollectionCreateEvent]

	// OnCollectionBeforeUpdateRequest hook is triggered before each API Collection
	// update request (after request data load and before model persistence).
	//
	// Could be used to additionally validate the request data or implement
	// completely different persistence behavior.
	OnCollectionBeforeUpdateRequest() *hook.Hook[*CollectionUpdateEvent]

	// OnCollectionAfterUpdateRequest hook is triggered after each
	// successful API Collection update request.
	OnCollectionAfterUpdateRequest() *hook.Hook[*CollectionUpdateEvent]

	// OnCollectionBeforeDeleteRequest hook is triggered before each API
	// Collection delete request (after model load and before actual deletion).
	//
	// Could be used to additionally validate the request data or implement
	// completely different delete behavior.
	OnCollectionBeforeDeleteRequest() *hook.Hook[*CollectionDeleteEvent]

	// OnCollectionAfterDeleteRequest hook is triggered after each
	// successful API Collection delete request.
	OnCollectionAfterDeleteRequest() *hook.Hook[*CollectionDeleteEvent]

	// OnCollectionsBeforeImportRequest hook is triggered before each API
	// collections import request (after request data load and before the actual import).
	//
	// Could be used to additionally validate the imported collections or
	// to implement completely different import behavior.
	OnCollectionsBeforeImportRequest() *hook.Hook[*CollectionsImportEvent]

	// OnCollectionsAfterImportRequest hook is triggered after each
	// successful API collections import request.
	OnCollectionsAfterImportRequest() *hook.Hook[*CollectionsImportEvent]
}

App defines the main PocketBase app interface.

type BaseApp

type BaseApp struct {
	// contains filtered or unexported fields
}

BaseApp implements core.App and defines the base PocketBase app structure.

func NewBaseApp

func NewBaseApp(config BaseAppConfig) *BaseApp

NewBaseApp creates and returns a new BaseApp instance configured with the provided arguments.

To initialize the app, you need to call `app.Bootstrap()`.

func (*BaseApp) Bootstrap

func (app *BaseApp) Bootstrap() error

Bootstrap initializes the application (aka. create data dir, open db connections, load settings, etc.).

It will call ResetBootstrapState() if the application was already bootstrapped.

func (*BaseApp) Cache deprecated

func (app *BaseApp) Cache() *store.Store[any]

Deprecated: Use app.Store() instead.

func (*BaseApp) CreateBackup added in v0.16.0

func (app *BaseApp) CreateBackup(ctx context.Context, name string) error

CreateBackup creates a new backup of the current app pb_data directory.

If name is empty, it will be autogenerated. If backup with the same name exists, the new backup file will replace it.

The backup is executed within a transaction, meaning that new writes will be temporary "blocked" until the backup file is generated.

To safely perform the backup, it is recommended to have free disk space for at least 2x the size of the pb_data directory.

By default backups are stored in pb_data/backups (the backups directory itself is excluded from the generated backup).

When using S3 storage for the uploaded collection files, you have to take care manually to backup those since they are not part of the pb_data.

Backups can be stored on S3 if it is configured in app.Settings().Backups.

func (*BaseApp) DB deprecated

func (app *BaseApp) DB() *dbx.DB

Deprecated: This method may get removed in the near future. It is recommended to access the db instance from app.Dao().DB() or if you want more flexibility - app.Dao().ConcurrentDB() and app.Dao().NonconcurrentDB().

DB returns the default app database instance.

func (*BaseApp) Dao

func (app *BaseApp) Dao() *daos.Dao

Dao returns the default app Dao instance.

func (*BaseApp) DataDir

func (app *BaseApp) DataDir() string

DataDir returns the app data directory path.

func (*BaseApp) EncryptionEnv

func (app *BaseApp) EncryptionEnv() string

EncryptionEnv returns the name of the app secret env key (used for settings encryption).

func (*BaseApp) IsBootstrapped added in v0.10.0

func (app *BaseApp) IsBootstrapped() bool

IsBootstrapped checks if the application was initialized (aka. whether Bootstrap() was called).

func (*BaseApp) IsDev added in v0.20.1

func (app *BaseApp) IsDev() bool

IsDev returns whether the app is in dev mode.

When enabled logs, executed sql statements, etc. are printed to the stderr.

func (*BaseApp) Logger added in v0.20.0

func (app *BaseApp) Logger() *slog.Logger

Logger returns the default app logger.

If the application is not bootstrapped yet, fallbacks to slog.Default().

func (*BaseApp) LogsDB deprecated

func (app *BaseApp) LogsDB() *dbx.DB

Deprecated: This method may get removed in the near future. It is recommended to access the logs db instance from app.LogsDao().DB() or if you want more flexibility - app.LogsDao().ConcurrentDB() and app.LogsDao().NonconcurrentDB().

LogsDB returns the app logs database instance.

func (*BaseApp) LogsDao

func (app *BaseApp) LogsDao() *daos.Dao

LogsDao returns the app logs Dao instance.

func (*BaseApp) NewBackupsFilesystem added in v0.16.0

func (app *BaseApp) NewBackupsFilesystem() (*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 after you are done working with it.

func (*BaseApp) NewFilesystem

func (app *BaseApp) NewFilesystem() (*filesystem.System, error)

NewFilesystem creates a new local or S3 filesystem instance for managing regular app files (eg. collection uploads) based on the current app settings.

NB! Make sure to call Close() on the returned result after you are done working with it.

func (*BaseApp) NewMailClient

func (app *BaseApp) NewMailClient() mailer.Mailer

NewMailClient creates and returns a new SMTP or Sendmail client based on the current app settings.

func (*BaseApp) OnAdminAfterAuthRefreshRequest added in v0.12.0

func (app *BaseApp) OnAdminAfterAuthRefreshRequest() *hook.Hook[*AdminAuthRefreshEvent]

func (*BaseApp) OnAdminAfterAuthWithPasswordRequest added in v0.12.0

func (app *BaseApp) OnAdminAfterAuthWithPasswordRequest() *hook.Hook[*AdminAuthWithPasswordEvent]

func (*BaseApp) OnAdminAfterConfirmPasswordResetRequest added in v0.12.0

func (app *BaseApp) OnAdminAfterConfirmPasswordResetRequest() *hook.Hook[*AdminConfirmPasswordResetEvent]

func (*BaseApp) OnAdminAfterCreateRequest

func (app *BaseApp) OnAdminAfterCreateRequest() *hook.Hook[*AdminCreateEvent]

func (*BaseApp) OnAdminAfterDeleteRequest

func (app *BaseApp) OnAdminAfterDeleteRequest() *hook.Hook[*AdminDeleteEvent]

func (*BaseApp) OnAdminAfterRequestPasswordResetRequest added in v0.12.0

func (app *BaseApp) OnAdminAfterRequestPasswordResetRequest() *hook.Hook[*AdminRequestPasswordResetEvent]

func (*BaseApp) OnAdminAfterUpdateRequest

func (app *BaseApp) OnAdminAfterUpdateRequest() *hook.Hook[*AdminUpdateEvent]

func (*BaseApp) OnAdminAuthRequest

func (app *BaseApp) OnAdminAuthRequest() *hook.Hook[*AdminAuthEvent]

func (*BaseApp) OnAdminBeforeAuthRefreshRequest added in v0.12.0

func (app *BaseApp) OnAdminBeforeAuthRefreshRequest() *hook.Hook[*AdminAuthRefreshEvent]

func (*BaseApp) OnAdminBeforeAuthWithPasswordRequest added in v0.12.0

func (app *BaseApp) OnAdminBeforeAuthWithPasswordRequest() *hook.Hook[*AdminAuthWithPasswordEvent]

func (*BaseApp) OnAdminBeforeConfirmPasswordResetRequest added in v0.12.0

func (app *BaseApp) OnAdminBeforeConfirmPasswordResetRequest() *hook.Hook[*AdminConfirmPasswordResetEvent]

func (*BaseApp) OnAdminBeforeCreateRequest

func (app *BaseApp) OnAdminBeforeCreateRequest() *hook.Hook[*AdminCreateEvent]

func (*BaseApp) OnAdminBeforeDeleteRequest

func (app *BaseApp) OnAdminBeforeDeleteRequest() *hook.Hook[*AdminDeleteEvent]

func (*BaseApp) OnAdminBeforeRequestPasswordResetRequest added in v0.12.0

func (app *BaseApp) OnAdminBeforeRequestPasswordResetRequest() *hook.Hook[*AdminRequestPasswordResetEvent]

func (*BaseApp) OnAdminBeforeUpdateRequest

func (app *BaseApp) OnAdminBeforeUpdateRequest() *hook.Hook[*AdminUpdateEvent]

func (*BaseApp) OnAdminViewRequest

func (app *BaseApp) OnAdminViewRequest() *hook.Hook[*AdminViewEvent]

func (*BaseApp) OnAdminsListRequest

func (app *BaseApp) OnAdminsListRequest() *hook.Hook[*AdminsListEvent]

func (*BaseApp) OnAfterApiError added in v0.9.0

func (app *BaseApp) OnAfterApiError() *hook.Hook[*ApiErrorEvent]

func (*BaseApp) OnAfterBootstrap added in v0.9.0

func (app *BaseApp) OnAfterBootstrap() *hook.Hook[*BootstrapEvent]

func (*BaseApp) OnBeforeApiError added in v0.9.0

func (app *BaseApp) OnBeforeApiError() *hook.Hook[*ApiErrorEvent]

func (*BaseApp) OnBeforeBootstrap added in v0.9.0

func (app *BaseApp) OnBeforeBootstrap() *hook.Hook[*BootstrapEvent]

func (*BaseApp) OnBeforeServe

func (app *BaseApp) OnBeforeServe() *hook.Hook[*ServeEvent]

func (*BaseApp) OnCollectionAfterCreateRequest

func (app *BaseApp) OnCollectionAfterCreateRequest() *hook.Hook[*CollectionCreateEvent]

func (*BaseApp) OnCollectionAfterDeleteRequest

func (app *BaseApp) OnCollectionAfterDeleteRequest() *hook.Hook[*CollectionDeleteEvent]

func (*BaseApp) OnCollectionAfterUpdateRequest

func (app *BaseApp) OnCollectionAfterUpdateRequest() *hook.Hook[*CollectionUpdateEvent]

func (*BaseApp) OnCollectionBeforeCreateRequest

func (app *BaseApp) OnCollectionBeforeCreateRequest() *hook.Hook[*CollectionCreateEvent]

func (*BaseApp) OnCollectionBeforeDeleteRequest

func (app *BaseApp) OnCollectionBeforeDeleteRequest() *hook.Hook[*CollectionDeleteEvent]

func (*BaseApp) OnCollectionBeforeUpdateRequest

func (app *BaseApp) OnCollectionBeforeUpdateRequest() *hook.Hook[*CollectionUpdateEvent]

func (*BaseApp) OnCollectionViewRequest

func (app *BaseApp) OnCollectionViewRequest() *hook.Hook[*CollectionViewEvent]

func (*BaseApp) OnCollectionsAfterImportRequest added in v0.4.0

func (app *BaseApp) OnCollectionsAfterImportRequest() *hook.Hook[*CollectionsImportEvent]

func (*BaseApp) OnCollectionsBeforeImportRequest added in v0.4.0

func (app *BaseApp) OnCollectionsBeforeImportRequest() *hook.Hook[*CollectionsImportEvent]

func (*BaseApp) OnCollectionsListRequest

func (app *BaseApp) OnCollectionsListRequest() *hook.Hook[*CollectionsListEvent]

func (*BaseApp) OnFileAfterTokenRequest added in v0.15.0

func (app *BaseApp) OnFileAfterTokenRequest(tags ...string) *hook.TaggedHook[*FileTokenEvent]

func (*BaseApp) OnFileBeforeTokenRequest added in v0.15.0

func (app *BaseApp) OnFileBeforeTokenRequest(tags ...string) *hook.TaggedHook[*FileTokenEvent]

func (*BaseApp) OnFileDownloadRequest

func (app *BaseApp) OnFileDownloadRequest(tags ...string) *hook.TaggedHook[*FileDownloadEvent]

func (*BaseApp) OnMailerAfterAdminResetPasswordSend

func (app *BaseApp) OnMailerAfterAdminResetPasswordSend() *hook.Hook[*MailerAdminEvent]

func (*BaseApp) OnMailerAfterRecordChangeEmailSend added in v0.8.0

func (app *BaseApp) OnMailerAfterRecordChangeEmailSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent]

func (*BaseApp) OnMailerAfterRecordResetPasswordSend added in v0.8.0

func (app *BaseApp) OnMailerAfterRecordResetPasswordSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent]

func (*BaseApp) OnMailerAfterRecordVerificationSend added in v0.8.0

func (app *BaseApp) OnMailerAfterRecordVerificationSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent]

func (*BaseApp) OnMailerBeforeAdminResetPasswordSend

func (app *BaseApp) OnMailerBeforeAdminResetPasswordSend() *hook.Hook[*MailerAdminEvent]

func (*BaseApp) OnMailerBeforeRecordChangeEmailSend added in v0.8.0

func (app *BaseApp) OnMailerBeforeRecordChangeEmailSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent]

func (*BaseApp) OnMailerBeforeRecordResetPasswordSend added in v0.8.0

func (app *BaseApp) OnMailerBeforeRecordResetPasswordSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent]

func (*BaseApp) OnMailerBeforeRecordVerificationSend added in v0.8.0

func (app *BaseApp) OnMailerBeforeRecordVerificationSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent]

func (*BaseApp) OnModelAfterCreate

func (app *BaseApp) OnModelAfterCreate(tags ...string) *hook.TaggedHook[*ModelEvent]

func (*BaseApp) OnModelAfterDelete

func (app *BaseApp) OnModelAfterDelete(tags ...string) *hook.TaggedHook[*ModelEvent]

func (*BaseApp) OnModelAfterUpdate

func (app *BaseApp) OnModelAfterUpdate(tags ...string) *hook.TaggedHook[*ModelEvent]

func (*BaseApp) OnModelBeforeCreate

func (app *BaseApp) OnModelBeforeCreate(tags ...string) *hook.TaggedHook[*ModelEvent]

func (*BaseApp) OnModelBeforeDelete

func (app *BaseApp) OnModelBeforeDelete(tags ...string) *hook.TaggedHook[*ModelEvent]

func (*BaseApp) OnModelBeforeUpdate

func (app *BaseApp) OnModelBeforeUpdate(tags ...string) *hook.TaggedHook[*ModelEvent]

func (*BaseApp) OnRealtimeAfterMessageSend added in v0.9.0

func (app *BaseApp) OnRealtimeAfterMessageSend() *hook.Hook[*RealtimeMessageEvent]

func (*BaseApp) OnRealtimeAfterSubscribeRequest

func (app *BaseApp) OnRealtimeAfterSubscribeRequest() *hook.Hook[*RealtimeSubscribeEvent]

func (*BaseApp) OnRealtimeBeforeMessageSend added in v0.9.0

func (app *BaseApp) OnRealtimeBeforeMessageSend() *hook.Hook[*RealtimeMessageEvent]

func (*BaseApp) OnRealtimeBeforeSubscribeRequest

func (app *BaseApp) OnRealtimeBeforeSubscribeRequest() *hook.Hook[*RealtimeSubscribeEvent]

func (*BaseApp) OnRealtimeConnectRequest

func (app *BaseApp) OnRealtimeConnectRequest() *hook.Hook[*RealtimeConnectEvent]

func (*BaseApp) OnRealtimeDisconnectRequest added in v0.9.0

func (app *BaseApp) OnRealtimeDisconnectRequest() *hook.Hook[*RealtimeDisconnectEvent]

func (*BaseApp) OnRecordAfterAuthRefreshRequest added in v0.12.0

func (app *BaseApp) OnRecordAfterAuthRefreshRequest(tags ...string) *hook.TaggedHook[*RecordAuthRefreshEvent]

func (*BaseApp) OnRecordAfterAuthWithOAuth2Request added in v0.12.0

func (app *BaseApp) OnRecordAfterAuthWithOAuth2Request(tags ...string) *hook.TaggedHook[*RecordAuthWithOAuth2Event]

func (*BaseApp) OnRecordAfterAuthWithPasswordRequest added in v0.12.0

func (app *BaseApp) OnRecordAfterAuthWithPasswordRequest(tags ...string) *hook.TaggedHook[*RecordAuthWithPasswordEvent]

func (*BaseApp) OnRecordAfterConfirmEmailChangeRequest added in v0.9.0

func (app *BaseApp) OnRecordAfterConfirmEmailChangeRequest(tags ...string) *hook.TaggedHook[*RecordConfirmEmailChangeEvent]

func (*BaseApp) OnRecordAfterConfirmPasswordResetRequest added in v0.9.0

func (app *BaseApp) OnRecordAfterConfirmPasswordResetRequest(tags ...string) *hook.TaggedHook[*RecordConfirmPasswordResetEvent]

func (*BaseApp) OnRecordAfterConfirmVerificationRequest added in v0.9.0

func (app *BaseApp) OnRecordAfterConfirmVerificationRequest(tags ...string) *hook.TaggedHook[*RecordConfirmVerificationEvent]

func (*BaseApp) OnRecordAfterCreateRequest

func (app *BaseApp) OnRecordAfterCreateRequest(tags ...string) *hook.TaggedHook[*RecordCreateEvent]

func (*BaseApp) OnRecordAfterDeleteRequest

func (app *BaseApp) OnRecordAfterDeleteRequest(tags ...string) *hook.TaggedHook[*RecordDeleteEvent]

func (*BaseApp) OnRecordAfterRequestEmailChangeRequest added in v0.9.0

func (app *BaseApp) OnRecordAfterRequestEmailChangeRequest(tags ...string) *hook.TaggedHook[*RecordRequestEmailChangeEvent]

func (*BaseApp) OnRecordAfterRequestPasswordResetRequest added in v0.9.0

func (app *BaseApp) OnRecordAfterRequestPasswordResetRequest(tags ...string) *hook.TaggedHook[*RecordRequestPasswordResetEvent]

func (*BaseApp) OnRecordAfterRequestVerificationRequest added in v0.9.0

func (app *BaseApp) OnRecordAfterRequestVerificationRequest(tags ...string) *hook.TaggedHook[*RecordRequestVerificationEvent]

func (*BaseApp) OnRecordAfterUnlinkExternalAuthRequest added in v0.8.0

func (app *BaseApp) OnRecordAfterUnlinkExternalAuthRequest(tags ...string) *hook.TaggedHook[*RecordUnlinkExternalAuthEvent]

func (*BaseApp) OnRecordAfterUpdateRequest

func (app *BaseApp) OnRecordAfterUpdateRequest(tags ...string) *hook.TaggedHook[*RecordUpdateEvent]

func (*BaseApp) OnRecordAuthRequest added in v0.8.0

func (app *BaseApp) OnRecordAuthRequest(tags ...string) *hook.TaggedHook[*RecordAuthEvent]

func (*BaseApp) OnRecordBeforeAuthRefreshRequest added in v0.12.0

func (app *BaseApp) OnRecordBeforeAuthRefreshRequest(tags ...string) *hook.TaggedHook[*RecordAuthRefreshEvent]

func (*BaseApp) OnRecordBeforeAuthWithOAuth2Request added in v0.12.0

func (app *BaseApp) OnRecordBeforeAuthWithOAuth2Request(tags ...string) *hook.TaggedHook[*RecordAuthWithOAuth2Event]

func (*BaseApp) OnRecordBeforeAuthWithPasswordRequest added in v0.12.0

func (app *BaseApp) OnRecordBeforeAuthWithPasswordRequest(tags ...string) *hook.TaggedHook[*RecordAuthWithPasswordEvent]

func (*BaseApp) OnRecordBeforeConfirmEmailChangeRequest added in v0.9.0

func (app *BaseApp) OnRecordBeforeConfirmEmailChangeRequest(tags ...string) *hook.TaggedHook[*RecordConfirmEmailChangeEvent]

func (*BaseApp) OnRecordBeforeConfirmPasswordResetRequest added in v0.9.0

func (app *BaseApp) OnRecordBeforeConfirmPasswordResetRequest(tags ...string) *hook.TaggedHook[*RecordConfirmPasswordResetEvent]

func (*BaseApp) OnRecordBeforeConfirmVerificationRequest added in v0.9.0

func (app *BaseApp) OnRecordBeforeConfirmVerificationRequest(tags ...string) *hook.TaggedHook[*RecordConfirmVerificationEvent]

func (*BaseApp) OnRecordBeforeCreateRequest

func (app *BaseApp) OnRecordBeforeCreateRequest(tags ...string) *hook.TaggedHook[*RecordCreateEvent]

func (*BaseApp) OnRecordBeforeDeleteRequest

func (app *BaseApp) OnRecordBeforeDeleteRequest(tags ...string) *hook.TaggedHook[*RecordDeleteEvent]

func (*BaseApp) OnRecordBeforeRequestEmailChangeRequest added in v0.9.0

func (app *BaseApp) OnRecordBeforeRequestEmailChangeRequest(tags ...string) *hook.TaggedHook[*RecordRequestEmailChangeEvent]

func (*BaseApp) OnRecordBeforeRequestPasswordResetRequest added in v0.9.0

func (app *BaseApp) OnRecordBeforeRequestPasswordResetRequest(tags ...string) *hook.TaggedHook[*RecordRequestPasswordResetEvent]

func (*BaseApp) OnRecordBeforeRequestVerificationRequest added in v0.9.0

func (app *BaseApp) OnRecordBeforeRequestVerificationRequest(tags ...string) *hook.TaggedHook[*RecordRequestVerificationEvent]

func (*BaseApp) OnRecordBeforeUnlinkExternalAuthRequest added in v0.8.0

func (app *BaseApp) OnRecordBeforeUnlinkExternalAuthRequest(tags ...string) *hook.TaggedHook[*RecordUnlinkExternalAuthEvent]

func (*BaseApp) OnRecordBeforeUpdateRequest

func (app *BaseApp) OnRecordBeforeUpdateRequest(tags ...string) *hook.TaggedHook[*RecordUpdateEvent]

func (*BaseApp) OnRecordListExternalAuthsRequest added in v0.8.0

func (app *BaseApp) OnRecordListExternalAuthsRequest(tags ...string) *hook.TaggedHook[*RecordListExternalAuthsEvent]

func (*BaseApp) OnRecordViewRequest

func (app *BaseApp) OnRecordViewRequest(tags ...string) *hook.TaggedHook[*RecordViewEvent]

func (*BaseApp) OnRecordsListRequest

func (app *BaseApp) OnRecordsListRequest(tags ...string) *hook.TaggedHook[*RecordsListEvent]

func (*BaseApp) OnSettingsAfterUpdateRequest

func (app *BaseApp) OnSettingsAfterUpdateRequest() *hook.Hook[*SettingsUpdateEvent]

func (*BaseApp) OnSettingsBeforeUpdateRequest

func (app *BaseApp) OnSettingsBeforeUpdateRequest() *hook.Hook[*SettingsUpdateEvent]

func (*BaseApp) OnSettingsListRequest

func (app *BaseApp) OnSettingsListRequest() *hook.Hook[*SettingsListEvent]

func (*BaseApp) OnTerminate added in v0.16.0

func (app *BaseApp) OnTerminate() *hook.Hook[*TerminateEvent]

func (*BaseApp) RefreshSettings

func (app *BaseApp) RefreshSettings() error

RefreshSettings reinitializes and reloads the stored application settings.

func (*BaseApp) ResetBootstrapState

func (app *BaseApp) ResetBootstrapState() error

ResetBootstrapState takes care for releasing initialized app resources (eg. closing db connections).

func (*BaseApp) Restart added in v0.16.0

func (app *BaseApp) Restart() error

Restart restarts (aka. replaces) the current running application process.

NB! It relies on execve which is supported only on UNIX based systems.

func (*BaseApp) RestoreBackup added in v0.16.0

func (app *BaseApp) RestoreBackup(ctx context.Context, name string) error

RestoreBackup restores the backup with the specified name and restarts the current running application process.

NB! This feature is experimental and currently is expected to work only on UNIX based systems.

To safely perform the restore it is recommended to have free disk space for at least 2x the size of the restored pb_data backup.

The performed steps are:

  1. Download the backup with the specified name in a temp location (this is in case of S3; otherwise it creates a temp copy of the zip)

  2. Extract the backup in a temp directory inside the app "pb_data" (eg. "pb_data/.pb_temp_to_delete/pb_restore").

  3. Move the current app "pb_data" content (excluding the local backups and the special temp dir) under another temp sub dir that will be deleted on the next app start up (eg. "pb_data/.pb_temp_to_delete/old_pb_data"). This is because on some environments it may not be allowed to delete the currently open "pb_data" files.

  4. Move the extracted dir content to the app "pb_data".

  5. Restart the app (on successful app bootstap it will also remove the old pb_data).

If a failure occure during the restore process the dir changes are reverted. If for whatever reason the revert is not possible, it panics.

func (*BaseApp) Settings

func (app *BaseApp) Settings() *settings.Settings

Settings returns the loaded app settings.

func (*BaseApp) Store added in v0.20.0

func (app *BaseApp) Store() *store.Store[any]

Store returns the app internal runtime store.

func (*BaseApp) SubscriptionsBroker

func (app *BaseApp) SubscriptionsBroker() *subscriptions.Broker

SubscriptionsBroker returns the app realtime subscriptions broker instance.

type BaseAppConfig added in v0.10.0

type BaseAppConfig struct {
	IsDev            bool
	DataDir          string
	EncryptionEnv    string
	DataMaxOpenConns int // default to 500
	DataMaxIdleConns int // default 20
	LogsMaxOpenConns int // default to 100
	LogsMaxIdleConns int // default to 5
}

BaseAppConfig defines a BaseApp configuration option

type BaseCollectionEvent added in v0.12.0

type BaseCollectionEvent struct {
	Collection *models.Collection
}

func (*BaseCollectionEvent) Tags added in v0.12.0

func (e *BaseCollectionEvent) Tags() []string

type BaseModelEvent added in v0.15.0

type BaseModelEvent struct {
	Model models.Model
}

func (*BaseModelEvent) Tags added in v0.15.0

func (e *BaseModelEvent) Tags() []string

type BootstrapEvent added in v0.9.0

type BootstrapEvent struct {
	App App
}

type CollectionCreateEvent

type CollectionCreateEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
}

type CollectionDeleteEvent

type CollectionDeleteEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
}

type CollectionUpdateEvent

type CollectionUpdateEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
}

type CollectionViewEvent

type CollectionViewEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
}

type CollectionsImportEvent added in v0.4.0

type CollectionsImportEvent struct {
	HttpContext echo.Context
	Collections []*models.Collection
}

type CollectionsListEvent

type CollectionsListEvent struct {
	HttpContext echo.Context
	Collections []*models.Collection
	Result      *search.Result
}

type FileDownloadEvent

type FileDownloadEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
	Record      *models.Record
	FileField   *schema.SchemaField
	ServedPath  string
	ServedName  string
}

type FileTokenEvent added in v0.15.0

type FileTokenEvent struct {
	BaseModelEvent

	HttpContext echo.Context
	Token       string
}

type MailerAdminEvent

type MailerAdminEvent struct {
	MailClient mailer.Mailer
	Message    *mailer.Message
	Admin      *models.Admin
	Meta       map[string]any
}

type MailerRecordEvent added in v0.8.0

type MailerRecordEvent struct {
	BaseCollectionEvent

	MailClient mailer.Mailer
	Message    *mailer.Message
	Record     *models.Record
	Meta       map[string]any
}

type ModelEvent

type ModelEvent struct {
	BaseModelEvent

	Dao *daos.Dao
}

type RealtimeConnectEvent

type RealtimeConnectEvent struct {
	HttpContext echo.Context
	Client      subscriptions.Client
	IdleTimeout time.Duration
}

type RealtimeDisconnectEvent added in v0.9.0

type RealtimeDisconnectEvent struct {
	HttpContext echo.Context
	Client      subscriptions.Client
}

type RealtimeMessageEvent added in v0.9.0

type RealtimeMessageEvent struct {
	HttpContext echo.Context
	Client      subscriptions.Client
	Message     *subscriptions.Message
}

type RealtimeSubscribeEvent

type RealtimeSubscribeEvent struct {
	HttpContext   echo.Context
	Client        subscriptions.Client
	Subscriptions []string
}

type RecordAuthEvent added in v0.8.0

type RecordAuthEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
	Record      *models.Record
	Token       string
	Meta        any
}

type RecordAuthRefreshEvent added in v0.12.0

type RecordAuthRefreshEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
	Record      *models.Record
}

type RecordAuthWithOAuth2Event added in v0.12.0

type RecordAuthWithOAuth2Event struct {
	BaseCollectionEvent

	HttpContext    echo.Context
	ProviderName   string
	ProviderClient auth.Provider
	Record         *models.Record
	OAuth2User     *auth.AuthUser
	IsNewRecord    bool
}

type RecordAuthWithPasswordEvent added in v0.12.0

type RecordAuthWithPasswordEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
	Record      *models.Record
	Identity    string
	Password    string
}

type RecordConfirmEmailChangeEvent added in v0.9.0

type RecordConfirmEmailChangeEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
	Record      *models.Record
}

type RecordConfirmPasswordResetEvent added in v0.9.0

type RecordConfirmPasswordResetEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
	Record      *models.Record
}

type RecordConfirmVerificationEvent added in v0.9.0

type RecordConfirmVerificationEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
	Record      *models.Record
}

type RecordCreateEvent

type RecordCreateEvent struct {
	BaseCollectionEvent

	HttpContext   echo.Context
	Record        *models.Record
	UploadedFiles map[string][]*filesystem.File
}

type RecordDeleteEvent

type RecordDeleteEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
	Record      *models.Record
}

type RecordListExternalAuthsEvent added in v0.8.0

type RecordListExternalAuthsEvent struct {
	BaseCollectionEvent

	HttpContext   echo.Context
	Record        *models.Record
	ExternalAuths []*models.ExternalAuth
}

type RecordRequestEmailChangeEvent added in v0.9.0

type RecordRequestEmailChangeEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
	Record      *models.Record
}

type RecordRequestPasswordResetEvent added in v0.9.0

type RecordRequestPasswordResetEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
	Record      *models.Record
}

type RecordRequestVerificationEvent added in v0.9.0

type RecordRequestVerificationEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
	Record      *models.Record
}

type RecordUnlinkExternalAuthEvent added in v0.8.0

type RecordUnlinkExternalAuthEvent struct {
	BaseCollectionEvent

	HttpContext  echo.Context
	Record       *models.Record
	ExternalAuth *models.ExternalAuth
}

type RecordUpdateEvent

type RecordUpdateEvent struct {
	BaseCollectionEvent

	HttpContext   echo.Context
	Record        *models.Record
	UploadedFiles map[string][]*filesystem.File
}

type RecordViewEvent

type RecordViewEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
	Record      *models.Record
}

type RecordsListEvent

type RecordsListEvent struct {
	BaseCollectionEvent

	HttpContext echo.Context
	Records     []*models.Record
	Result      *search.Result
}

type ServeEvent

type ServeEvent struct {
	App         App
	Router      *echo.Echo
	Server      *http.Server
	CertManager *autocert.Manager
}

type SettingsListEvent

type SettingsListEvent struct {
	HttpContext      echo.Context
	RedactedSettings *settings.Settings
}

type SettingsUpdateEvent

type SettingsUpdateEvent struct {
	HttpContext echo.Context
	OldSettings *settings.Settings
	NewSettings *settings.Settings
}

type TerminateEvent added in v0.16.0

type TerminateEvent struct {
	App       App
	IsRestart bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL