| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | // Package core is the backbone of PocketBase.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // It defines the main PocketBase App interface and its base implementation.
 | 
					
						
							|  |  |  | package core | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2023-05-09 02:52:40 +08:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2023-11-26 19:33:17 +08:00
										 |  |  | 	"log/slog" | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	"time" | 
					
						
							| 
									
										
										
										
											2023-05-09 02:52:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	"github.com/pocketbase/dbx" | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	"github.com/pocketbase/pocketbase/tools/cron" | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	"github.com/pocketbase/pocketbase/tools/filesystem" | 
					
						
							|  |  |  | 	"github.com/pocketbase/pocketbase/tools/hook" | 
					
						
							|  |  |  | 	"github.com/pocketbase/pocketbase/tools/mailer" | 
					
						
							|  |  |  | 	"github.com/pocketbase/pocketbase/tools/store" | 
					
						
							|  |  |  | 	"github.com/pocketbase/pocketbase/tools/subscriptions" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // App defines the main PocketBase app interface.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | // Note that the interface is not intended to be implemented manually by users
 | 
					
						
							|  |  |  | // and instead they should use core.BaseApp (either directly or as embedded field in a custom struct).
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // This interface exists to make testing easier and to allow users to
 | 
					
						
							|  |  |  | // create common and pluggable helpers and methods that doesn't rely
 | 
					
						
							|  |  |  | // on a specific wrapped app struct (hence the large interface size).
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | type App interface { | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// UnsafeWithoutHooks returns a shallow copy of the current app WITHOUT any registered hooks.
 | 
					
						
							| 
									
										
										
										
											2022-12-15 22:42:35 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	UnsafeWithoutHooks() App | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// Logger returns the default app logger.
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// If the application is not bootstrapped yet, fallbacks to slog.Default().
 | 
					
						
							|  |  |  | 	Logger() *slog.Logger | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// IsBootstrapped checks if the application was initialized
 | 
					
						
							|  |  |  | 	// (aka. whether Bootstrap() was called).
 | 
					
						
							|  |  |  | 	IsBootstrapped() bool | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// IsTransactional checks if the current app instance is part of a transaction.
 | 
					
						
							|  |  |  | 	IsTransactional() bool | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// Bootstrap initializes the application
 | 
					
						
							|  |  |  | 	// (aka. create data dir, open db connections, load settings, etc.).
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// It will call ResetBootstrapState() if the application was already bootstrapped.
 | 
					
						
							|  |  |  | 	Bootstrap() error | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// ResetBootstrapState releases the initialized core app resources
 | 
					
						
							|  |  |  | 	// (closing db connections, stopping cron ticker, etc.).
 | 
					
						
							|  |  |  | 	ResetBootstrapState() error | 
					
						
							| 
									
										
										
										
											2023-11-26 19:33:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	// DataDir returns the app data directory path.
 | 
					
						
							|  |  |  | 	DataDir() string | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// EncryptionEnv returns the name of the app secret env key
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// (currently used primarily for optional settings encryption but this may change in the future).
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	EncryptionEnv() string | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 21:41:12 +08:00
										 |  |  | 	// IsDev returns whether the app is in dev mode.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// When enabled logs, executed sql statements, etc. are printed to the stderr.
 | 
					
						
							| 
									
										
										
										
											2023-12-16 21:41:12 +08:00
										 |  |  | 	IsDev() bool | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	// Settings returns the loaded app settings.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	Settings() *Settings | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-26 19:33:17 +08:00
										 |  |  | 	// Store returns the app runtime store.
 | 
					
						
							|  |  |  | 	Store() *store.Store[any] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// Cron returns the app cron instance.
 | 
					
						
							|  |  |  | 	Cron() *cron.Cron | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	// SubscriptionsBroker returns the app realtime subscriptions broker instance.
 | 
					
						
							|  |  |  | 	SubscriptionsBroker() *subscriptions.Broker | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// NewMailClient creates and returns a new SMTP or Sendmail client
 | 
					
						
							|  |  |  | 	// based on the current app settings.
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	NewMailClient() mailer.Mailer | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// NewFilesystem creates a new local or S3 filesystem instance
 | 
					
						
							|  |  |  | 	// for managing regular app files (ex. record uploads)
 | 
					
						
							|  |  |  | 	// based on the current app settings.
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-06-14 18:14:30 +08:00
										 |  |  | 	// NB! Make sure to call Close() on the returned result
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	// after you are done working with it.
 | 
					
						
							|  |  |  | 	NewFilesystem() (*filesystem.System, error) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// NewFilesystem creates a new local or S3 filesystem instance
 | 
					
						
							|  |  |  | 	// for managing app backups based on the current app settings.
 | 
					
						
							| 
									
										
										
										
											2023-05-09 02:52:40 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-06-14 18:14:30 +08:00
										 |  |  | 	// NB! Make sure to call Close() on the returned result
 | 
					
						
							| 
									
										
										
										
											2023-05-09 02:52:40 +08:00
										 |  |  | 	// after you are done working with it.
 | 
					
						
							|  |  |  | 	NewBackupsFilesystem() (*filesystem.System, error) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// ReloadSettings reinitializes and reloads the stored application settings.
 | 
					
						
							|  |  |  | 	ReloadSettings() error | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-09 02:52:40 +08:00
										 |  |  | 	// 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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// Restart restarts (aka. replaces) the current running application process.
 | 
					
						
							| 
									
										
										
										
											2023-05-09 02:52:40 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// NB! It relies on execve which is supported only on UNIX based systems.
 | 
					
						
							| 
									
										
										
										
											2023-05-09 02:52:40 +08:00
										 |  |  | 	Restart() error | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// RunSystemMigrations applies all new migrations registered in the [core.SystemMigrations] list.
 | 
					
						
							|  |  |  | 	RunSystemMigrations() error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// RunAppMigrations applies all new migrations registered in the [core.AppMigrations] list.
 | 
					
						
							|  |  |  | 	RunAppMigrations() error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// RunAllMigrations applies all system and app migrations
 | 
					
						
							|  |  |  | 	// (aka. from both [core.SystemMigrations] and [core.AppMigrations]).
 | 
					
						
							|  |  |  | 	RunAllMigrations() error | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// DB methods
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// DB returns the default app data db instance (pb_data/data.db).
 | 
					
						
							|  |  |  | 	DB() dbx.Builder | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// NonconcurrentDB returns the nonconcurrent app data db instance (pb_data/data.db).
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// The returned db instance is limited only to a single open connection,
 | 
					
						
							|  |  |  | 	// meaning that it can process only 1 db operation at a time (other operations will be queued up).
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// This method is used mainly internally and in the tests to execute write
 | 
					
						
							|  |  |  | 	// (save/delete) db operations as it helps with minimizing the SQLITE_BUSY errors.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// For the majority of cases you would want to use the regular DB() method
 | 
					
						
							|  |  |  | 	// since it allows concurrent db read operations.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// In a transaction the ConcurrentDB() and NonconcurrentDB() refer to the same *dbx.TX instance.
 | 
					
						
							|  |  |  | 	NonconcurrentDB() dbx.Builder | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-06 21:41:05 +08:00
										 |  |  | 	// AuxDB returns the default app auxiliary db instance (pb_data/auxiliary.db).
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	AuxDB() dbx.Builder | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-06 21:41:05 +08:00
										 |  |  | 	// AuxNonconcurrentDB returns the nonconcurrent app auxiliary db instance (pb_data/auxiliary.db)..
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// The returned db instance is limited only to a single open connection,
 | 
					
						
							|  |  |  | 	// meaning that it can process only 1 db operation at a time (other operations will be queued up).
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// This method is used mainly internally and in the tests to execute write
 | 
					
						
							|  |  |  | 	// (save/delete) db operations as it helps with minimizing the SQLITE_BUSY errors.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// For the majority of cases you would want to use the regular DB() method
 | 
					
						
							|  |  |  | 	// since it allows concurrent db read operations.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// In a transaction the AuxNonconcurrentDB() and AuxNonconcurrentDB() refer to the same *dbx.TX instance.
 | 
					
						
							|  |  |  | 	AuxNonconcurrentDB() dbx.Builder | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// HasTable checks if a table (or view) with the provided name exists (case insensitive).
 | 
					
						
							| 
									
										
										
										
											2024-10-08 21:23:58 +08:00
										 |  |  | 	// in the current app.DB() instance.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	HasTable(tableName string) bool | 
					
						
							| 
									
										
										
										
											2022-12-02 22:36:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-08 21:23:58 +08:00
										 |  |  | 	// AuxHasTable checks if a table (or view) with the provided name exists (case insensitive)
 | 
					
						
							|  |  |  | 	// in the current app.AuxDB() instance.
 | 
					
						
							|  |  |  | 	AuxHasTable(tableName string) bool | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// TableColumns returns all column names of a single table by its name.
 | 
					
						
							|  |  |  | 	TableColumns(tableName string) ([]string, error) | 
					
						
							| 
									
										
										
										
											2022-12-02 22:36:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// TableInfo returns the "table_info" pragma result for the specified table.
 | 
					
						
							|  |  |  | 	TableInfo(tableName string) ([]*TableInfoRow, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// TableIndexes returns a name grouped map with all non empty index of the specified table.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Note: This method doesn't return an error on nonexisting table.
 | 
					
						
							|  |  |  | 	TableIndexes(tableName string) (map[string]string, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// DeleteTable drops the specified table.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// This method is a no-op if a table with the provided name doesn't exist.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// NB! Be aware that this method is vulnerable to SQL injection and the
 | 
					
						
							|  |  |  | 	// "tableName" argument must come only from trusted input!
 | 
					
						
							|  |  |  | 	DeleteTable(tableName string) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// DeleteView drops the specified view name.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// This method is a no-op if a view with the provided name doesn't exist.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// NB! Be aware that this method is vulnerable to SQL injection and the
 | 
					
						
							|  |  |  | 	// "name" argument must come only from trusted input!
 | 
					
						
							|  |  |  | 	DeleteView(name string) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// SaveView creates (or updates already existing) persistent SQL view.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// NB! Be aware that this method is vulnerable to SQL injection and the
 | 
					
						
							|  |  |  | 	// "selectQuery" argument must come only from trusted input!
 | 
					
						
							|  |  |  | 	SaveView(name string, selectQuery string) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// CreateViewFields creates a new FieldsList from the provided select query.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// There are some caveats:
 | 
					
						
							|  |  |  | 	// - The select query must have an "id" column.
 | 
					
						
							|  |  |  | 	// - Wildcard ("*") columns are not supported to avoid accidentally leaking sensitive data.
 | 
					
						
							|  |  |  | 	CreateViewFields(selectQuery string) (FieldsList, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindRecordByViewFile returns the original Record of the provided view collection file.
 | 
					
						
							|  |  |  | 	FindRecordByViewFile(viewCollectionModelOrIdentifier any, fileFieldName string, filename string) (*Record, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Vacuum executes VACUUM on the current app.DB() instance
 | 
					
						
							|  |  |  | 	// in order to reclaim unused data db disk space.
 | 
					
						
							|  |  |  | 	Vacuum() error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// AuxVacuum executes VACUUM on the current app.AuxDB() instance
 | 
					
						
							|  |  |  | 	// in order to reclaim unused auxiliary db disk space.
 | 
					
						
							|  |  |  | 	AuxVacuum() error | 
					
						
							| 
									
										
										
										
											2023-05-09 02:52:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// ModelQuery creates a new preconfigured select app.DB() query with preset
 | 
					
						
							|  |  |  | 	// SELECT, FROM and other common fields based on the provided model.
 | 
					
						
							|  |  |  | 	ModelQuery(model Model) *dbx.SelectQuery | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// AuxModelQuery creates a new preconfigured select app.AuxDB() query with preset
 | 
					
						
							|  |  |  | 	// SELECT, FROM and other common fields based on the provided model.
 | 
					
						
							|  |  |  | 	AuxModelQuery(model Model) *dbx.SelectQuery | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Delete deletes the specified model from the regular app database.
 | 
					
						
							|  |  |  | 	Delete(model Model) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Delete deletes the specified model from the regular app database
 | 
					
						
							|  |  |  | 	// (the context could be used to limit the query execution).
 | 
					
						
							|  |  |  | 	DeleteWithContext(ctx context.Context, model Model) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// AuxDelete deletes the specified model from the auxiliary database.
 | 
					
						
							|  |  |  | 	AuxDelete(model Model) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// AuxDeleteWithContext deletes the specified model from the auxiliary database
 | 
					
						
							|  |  |  | 	// (the context could be used to limit the query execution).
 | 
					
						
							|  |  |  | 	AuxDeleteWithContext(ctx context.Context, model Model) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Save validates and saves the specified model into the regular app database.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If you don't want to run validations, use [App.SaveNoValidate()].
 | 
					
						
							|  |  |  | 	Save(model Model) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// SaveWithContext is the same as [App.Save()] but allows specifying a context to limit the db execution.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If you don't want to run validations, use [App.SaveNoValidateWithContext()].
 | 
					
						
							|  |  |  | 	SaveWithContext(ctx context.Context, model Model) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// SaveNoValidate saves the specified model into the regular app database without performing validations.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If you want to also run validations before persisting, use [App.Save()].
 | 
					
						
							|  |  |  | 	SaveNoValidate(model Model) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// SaveNoValidateWithContext is the same as [App.SaveNoValidate()]
 | 
					
						
							|  |  |  | 	// but allows specifying a context to limit the db execution.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If you want to also run validations before persisting, use [App.SaveWithContext()].
 | 
					
						
							|  |  |  | 	SaveNoValidateWithContext(ctx context.Context, model Model) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// AuxSave validates and saves the specified model into the auxiliary app database.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If you don't want to run validations, use [App.AuxSaveNoValidate()].
 | 
					
						
							|  |  |  | 	AuxSave(model Model) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// AuxSaveWithContext is the same as [App.AuxSave()] but allows specifying a context to limit the db execution.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If you don't want to run validations, use [App.AuxSaveNoValidateWithContext()].
 | 
					
						
							|  |  |  | 	AuxSaveWithContext(ctx context.Context, model Model) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// AuxSaveNoValidate saves the specified model into the auxiliary app database without performing validations.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If you want to also run validations before persisting, use [App.AuxSave()].
 | 
					
						
							|  |  |  | 	AuxSaveNoValidate(model Model) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// AuxSaveNoValidateWithContext is the same as [App.AuxSaveNoValidate()]
 | 
					
						
							|  |  |  | 	// but allows specifying a context to limit the db execution.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If you want to also run validations before persisting, use [App.AuxSaveWithContext()].
 | 
					
						
							|  |  |  | 	AuxSaveNoValidateWithContext(ctx context.Context, model Model) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Validate triggers the OnModelValidate hook for the specified model.
 | 
					
						
							|  |  |  | 	Validate(model Model) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ValidateWithContext is the same as Validate but allows specifying the ModelEvent context.
 | 
					
						
							|  |  |  | 	ValidateWithContext(ctx context.Context, model Model) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// RunInTransaction wraps fn into a transaction for the regular app database.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// It is safe to nest RunInTransaction calls as long as you use the callback's txApp.
 | 
					
						
							|  |  |  | 	RunInTransaction(fn func(txApp App) error) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// AuxRunInTransaction wraps fn into a transaction for the auxiliary app database.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// It is safe to nest RunInTransaction calls as long as you use the callback's txApp.
 | 
					
						
							|  |  |  | 	AuxRunInTransaction(fn func(txApp App) error) error | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// LogQuery returns a new Log select query.
 | 
					
						
							|  |  |  | 	LogQuery() *dbx.SelectQuery | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindLogById finds a single Log entry by its id.
 | 
					
						
							|  |  |  | 	FindLogById(id string) (*Log, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// LogsStatsItem defines the total number of logs for a specific time period.
 | 
					
						
							|  |  |  | 	LogsStats(expr dbx.Expression) ([]*LogsStatsItem, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// DeleteOldLogs delete all requests that are created before createdBefore.
 | 
					
						
							|  |  |  | 	DeleteOldLogs(createdBefore time.Time) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// CollectionQuery returns a new Collection select query.
 | 
					
						
							|  |  |  | 	CollectionQuery() *dbx.SelectQuery | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindCollections finds all collections by the given type(s).
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If collectionTypes is not set, it returns all collections.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Example:
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	//	app.FindAllCollections() // all collections
 | 
					
						
							|  |  |  | 	//	app.FindAllCollections("auth", "view") // only auth and view collections
 | 
					
						
							|  |  |  | 	FindAllCollections(collectionTypes ...string) ([]*Collection, error) | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// ReloadCachedCollections fetches all collections and caches them into the app store.
 | 
					
						
							|  |  |  | 	ReloadCachedCollections() error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindCollectionByNameOrId finds a single collection by its name (case insensitive) or id.s
 | 
					
						
							|  |  |  | 	FindCollectionByNameOrId(nameOrId string) (*Collection, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindCachedCollectionByNameOrId is similar to [App.FindCollectionByNameOrId]
 | 
					
						
							|  |  |  | 	// but retrieves the Collection from the app cache instead of making a db call.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// NB! This method is suitable for read-only Collection operations.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Returns [sql.ErrNoRows] if no Collection is found for consistency
 | 
					
						
							|  |  |  | 	// with the [App.FindCollectionByNameOrId] method.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// If you plan making changes to the returned Collection model,
 | 
					
						
							|  |  |  | 	// use [App.FindCollectionByNameOrId] instead.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Caveats:
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//   - The returned Collection should be used only for read-only operations.
 | 
					
						
							|  |  |  | 	//     Avoid directly modifying the returned cached Collection as it will affect
 | 
					
						
							|  |  |  | 	//     the global cached value even if you don't persist the changes in the database!
 | 
					
						
							|  |  |  | 	//   - If you are updating a Collection in a transaction and then call this method before commit,
 | 
					
						
							|  |  |  | 	//     it'll return the cached Collection state and not the one from the uncommitted transaction.
 | 
					
						
							|  |  |  | 	//   - The cache is automatically updated on collections db change (create/update/delete).
 | 
					
						
							|  |  |  | 	//     To manually reload the cache you can call [App.ReloadCachedCollections()]
 | 
					
						
							|  |  |  | 	FindCachedCollectionByNameOrId(nameOrId string) (*Collection, error) | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// IsCollectionNameUnique checks that there is no existing collection
 | 
					
						
							|  |  |  | 	// with the provided name (case insensitive!).
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// Note: case insensitive check because the name is used also as
 | 
					
						
							|  |  |  | 	// table name for the records.
 | 
					
						
							|  |  |  | 	IsCollectionNameUnique(name string, excludeIds ...string) bool | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// FindCollectionReferences returns information for all relation
 | 
					
						
							|  |  |  | 	// fields referencing the provided collection.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// If the provided collection has reference to itself then it will be
 | 
					
						
							|  |  |  | 	// also included in the result. To exclude it, pass the collection id
 | 
					
						
							|  |  |  | 	// as the excludeIds argument.
 | 
					
						
							|  |  |  | 	FindCollectionReferences(collection *Collection, excludeIds ...string) (map[*Collection][]Field, error) | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// TruncateCollection deletes all records associated with the provided collection.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// The truncate operation is executed in a single transaction,
 | 
					
						
							|  |  |  | 	// aka. either everything is deleted or none.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Note that this method will also trigger the records related
 | 
					
						
							|  |  |  | 	// cascade and file delete actions.
 | 
					
						
							|  |  |  | 	TruncateCollection(collection *Collection) error | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// ImportCollections imports the provided collections data in a single transaction.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// For existing matching collections, the imported data is unmarshaled on top of the existing model.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// NB! If deleteMissing is true, ALL NON-SYSTEM COLLECTIONS AND SCHEMA FIELDS,
 | 
					
						
							|  |  |  | 	// that are not present in the imported configuration, WILL BE DELETED
 | 
					
						
							|  |  |  | 	// (this includes their related records data).
 | 
					
						
							|  |  |  | 	ImportCollections(toImport []map[string]any, deleteMissing bool) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ImportCollectionsByMarshaledJSON is the same as [ImportCollections]
 | 
					
						
							|  |  |  | 	// but accept marshaled json array as import data (usually used for the autogenerated snapshots).
 | 
					
						
							|  |  |  | 	ImportCollectionsByMarshaledJSON(rawSliceOfMaps []byte, deleteMissing bool) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// SyncRecordTableSchema compares the two provided collections
 | 
					
						
							|  |  |  | 	// and applies the necessary related record table changes.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If oldCollection is null, then only newCollection is used to create the record table.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// This method is automatically invoked as part of a collection create/update/delete operation.
 | 
					
						
							|  |  |  | 	SyncRecordTableSchema(newCollection *Collection, oldCollection *Collection) error | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// FindAllExternalAuthsByRecord returns all ExternalAuth models
 | 
					
						
							|  |  |  | 	// linked to the provided auth record.
 | 
					
						
							|  |  |  | 	FindAllExternalAuthsByRecord(authRecord *Record) ([]*ExternalAuth, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindAllExternalAuthsByCollection returns all ExternalAuth models
 | 
					
						
							|  |  |  | 	// linked to the provided auth collection.
 | 
					
						
							|  |  |  | 	FindAllExternalAuthsByCollection(collection *Collection) ([]*ExternalAuth, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindFirstExternalAuthByExpr returns the first available (the most recent created)
 | 
					
						
							|  |  |  | 	// ExternalAuth model that satisfies the non-nil expression.
 | 
					
						
							|  |  |  | 	FindFirstExternalAuthByExpr(expr dbx.Expression) (*ExternalAuth, error) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// FindAllMFAsByRecord returns all MFA models linked to the provided auth record.
 | 
					
						
							|  |  |  | 	FindAllMFAsByRecord(authRecord *Record) ([]*MFA, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindAllMFAsByCollection returns all MFA models linked to the provided collection.
 | 
					
						
							|  |  |  | 	FindAllMFAsByCollection(collection *Collection) ([]*MFA, error) | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// FindMFAById returns a single MFA model by its id.
 | 
					
						
							|  |  |  | 	FindMFAById(id string) (*MFA, error) | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// DeleteAllMFAsByRecord deletes all MFA models associated with the provided record.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// Returns a combined error with the failed deletes.
 | 
					
						
							|  |  |  | 	DeleteAllMFAsByRecord(authRecord *Record) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// DeleteExpiredMFAs deletes the expired MFAs for all auth collections.
 | 
					
						
							|  |  |  | 	DeleteExpiredMFAs() error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindAllOTPsByRecord returns all OTP models linked to the provided auth record.
 | 
					
						
							|  |  |  | 	FindAllOTPsByRecord(authRecord *Record) ([]*OTP, error) | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// FindAllOTPsByCollection returns all OTP models linked to the provided collection.
 | 
					
						
							|  |  |  | 	FindAllOTPsByCollection(collection *Collection) ([]*OTP, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindOTPById returns a single OTP model by its id.
 | 
					
						
							|  |  |  | 	FindOTPById(id string) (*OTP, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// DeleteAllOTPsByRecord deletes all OTP models associated with the provided record.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// Returns a combined error with the failed deletes.
 | 
					
						
							|  |  |  | 	DeleteAllOTPsByRecord(authRecord *Record) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// DeleteExpiredOTPs deletes the expired OTPs for all auth collections.
 | 
					
						
							|  |  |  | 	DeleteExpiredOTPs() error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindAllAuthOriginsByRecord returns all AuthOrigin models linked to the provided auth record (in DESC order).
 | 
					
						
							|  |  |  | 	FindAllAuthOriginsByRecord(authRecord *Record) ([]*AuthOrigin, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindAllAuthOriginsByCollection returns all AuthOrigin models linked to the provided collection (in DESC order).
 | 
					
						
							|  |  |  | 	FindAllAuthOriginsByCollection(collection *Collection) ([]*AuthOrigin, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindAuthOriginById returns a single AuthOrigin model by its id.
 | 
					
						
							|  |  |  | 	FindAuthOriginById(id string) (*AuthOrigin, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindAuthOriginByRecordAndFingerprint returns a single AuthOrigin model
 | 
					
						
							|  |  |  | 	// by its authRecord relation and fingerprint.
 | 
					
						
							|  |  |  | 	FindAuthOriginByRecordAndFingerprint(authRecord *Record, fingerprint string) (*AuthOrigin, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// DeleteAllAuthOriginsByRecord deletes all AuthOrigin models associated with the provided record.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Returns a combined error with the failed deletes.
 | 
					
						
							|  |  |  | 	DeleteAllAuthOriginsByRecord(authRecord *Record) error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// RecordQuery returns a new Record select query from a collection model, id or name.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// In case a collection id or name is provided and that collection doesn't
 | 
					
						
							|  |  |  | 	// actually exists, the generated query will be created with a cancelled context
 | 
					
						
							|  |  |  | 	// and will fail once an executor (Row(), One(), All(), etc.) is called.
 | 
					
						
							|  |  |  | 	RecordQuery(collectionModelOrIdentifier any) *dbx.SelectQuery | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindRecordById finds the Record model by its id.
 | 
					
						
							|  |  |  | 	FindRecordById(collectionModelOrIdentifier any, recordId string, optFilters ...func(q *dbx.SelectQuery) error) (*Record, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindRecordsByIds finds all records by the specified ids.
 | 
					
						
							|  |  |  | 	// If no records are found, returns an empty slice.
 | 
					
						
							|  |  |  | 	FindRecordsByIds(collectionModelOrIdentifier any, recordIds []string, optFilters ...func(q *dbx.SelectQuery) error) ([]*Record, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindAllRecords finds all records matching specified db expressions.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Returns all collection records if no expression is provided.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Returns an empty slice if no records are found.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Example:
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//	// no extra expressions
 | 
					
						
							|  |  |  | 	//	app.FindAllRecords("example")
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//	// with extra expressions
 | 
					
						
							|  |  |  | 	//	expr1 := dbx.HashExp{"email": "test@example.com"}
 | 
					
						
							|  |  |  | 	//	expr2 := dbx.NewExp("LOWER(username) = {:username}", dbx.Params{"username": "test"})
 | 
					
						
							|  |  |  | 	//	app.FindAllRecords("example", expr1, expr2)
 | 
					
						
							|  |  |  | 	FindAllRecords(collectionModelOrIdentifier any, exprs ...dbx.Expression) ([]*Record, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindFirstRecordByData returns the first found record matching
 | 
					
						
							|  |  |  | 	// the provided key-value pair.
 | 
					
						
							|  |  |  | 	FindFirstRecordByData(collectionModelOrIdentifier any, key string, value any) (*Record, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindRecordsByFilter returns limit number of records matching the
 | 
					
						
							|  |  |  | 	// provided string filter.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// NB! Use the last "params" argument to bind untrusted user variables!
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// The filter argument is optional and can be empty string to target
 | 
					
						
							|  |  |  | 	// all available records.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// The sort argument is optional and can be empty string OR the same format
 | 
					
						
							|  |  |  | 	// used in the web APIs, ex. "-created,title".
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If the limit argument is <= 0, no limit is applied to the query and
 | 
					
						
							|  |  |  | 	// all matching records are returned.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Returns an empty slice if no records are found.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Example:
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//	app.FindRecordsByFilter(
 | 
					
						
							|  |  |  | 	//		"posts",
 | 
					
						
							|  |  |  | 	//		"title ~ {:title} && visible = {:visible}",
 | 
					
						
							|  |  |  | 	//		"-created",
 | 
					
						
							|  |  |  | 	//		10,
 | 
					
						
							|  |  |  | 	//		0,
 | 
					
						
							|  |  |  | 	//		dbx.Params{"title": "lorem ipsum", "visible": true}
 | 
					
						
							|  |  |  | 	//	)
 | 
					
						
							|  |  |  | 	FindRecordsByFilter( | 
					
						
							|  |  |  | 		collectionModelOrIdentifier any, | 
					
						
							|  |  |  | 		filter string, | 
					
						
							|  |  |  | 		sort string, | 
					
						
							|  |  |  | 		limit int, | 
					
						
							|  |  |  | 		offset int, | 
					
						
							|  |  |  | 		params ...dbx.Params, | 
					
						
							|  |  |  | 	) ([]*Record, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindFirstRecordByFilter returns the first available record matching the provided filter (if any).
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// NB! Use the last params argument to bind untrusted user variables!
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Returns sql.ErrNoRows if no record is found.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Example:
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//	app.FindFirstRecordByFilter("posts", "")
 | 
					
						
							|  |  |  | 	//	app.FindFirstRecordByFilter("posts", "slug={:slug} && status='public'", dbx.Params{"slug": "test"})
 | 
					
						
							|  |  |  | 	FindFirstRecordByFilter( | 
					
						
							|  |  |  | 		collectionModelOrIdentifier any, | 
					
						
							|  |  |  | 		filter string, | 
					
						
							|  |  |  | 		params ...dbx.Params, | 
					
						
							|  |  |  | 	) (*Record, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// CountRecords returns the total number of records in a collection.
 | 
					
						
							|  |  |  | 	CountRecords(collectionModelOrIdentifier any, exprs ...dbx.Expression) (int64, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindAuthRecordByToken finds the auth record associated with the provided JWT
 | 
					
						
							|  |  |  | 	// (auth, file, verifyEmail, changeEmail, passwordReset types).
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Optionally specify a list of validTypes to check tokens only from those types.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Returns an error if the JWT is invalid, expired or not associated to an auth collection record.
 | 
					
						
							|  |  |  | 	FindAuthRecordByToken(token string, validTypes ...string) (*Record, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FindAuthRecordByEmail finds the auth record associated with the provided email.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Returns an error if it is not an auth collection or the record is not found.
 | 
					
						
							|  |  |  | 	FindAuthRecordByEmail(collectionModelOrIdentifier any, email string) (*Record, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// CanAccessRecord checks if a record is allowed to be accessed by the
 | 
					
						
							|  |  |  | 	// specified requestInfo and accessRule.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// Rule and db checks are ignored in case requestInfo.Auth is a superuser.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// The returned error indicate that something unexpected happened during
 | 
					
						
							|  |  |  | 	// the check (eg. invalid rule or db query error).
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// The method always return false on invalid rule or db query error.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Example:
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//	requestInfo, _ := e.RequestInfo()
 | 
					
						
							|  |  |  | 	//	record, _ := app.FindRecordById("example", "RECORD_ID")
 | 
					
						
							|  |  |  | 	//	rule := types.Pointer("@request.auth.id != '' || status = 'public'")
 | 
					
						
							|  |  |  | 	//	// ... or use one of the record collection's rule, eg. record.Collection().ViewRule
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//	if ok, _ := app.CanAccessRecord(record, requestInfo, rule); ok { ... }
 | 
					
						
							|  |  |  | 	CanAccessRecord(record *Record, requestInfo *RequestInfo, accessRule *string) (bool, error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ExpandRecord expands the relations of a single Record model.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If optFetchFunc is not set, then a default function will be used
 | 
					
						
							|  |  |  | 	// that returns all relation records.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Returns a map with the failed expand parameters and their errors.
 | 
					
						
							|  |  |  | 	ExpandRecord(record *Record, expands []string, optFetchFunc ExpandFetchFunc) map[string]error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ExpandRecords expands the relations of the provided Record models list.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If optFetchFunc is not set, then a default function will be used
 | 
					
						
							|  |  |  | 	// that returns all relation records.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Returns a map with the failed expand parameters and their errors.
 | 
					
						
							|  |  |  | 	ExpandRecords(records []*Record, expands []string, optFetchFunc ExpandFetchFunc) map[string]error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 	// App event hooks
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnBootstrap hook is triggered when initializing the main application
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// resources (db, app settings, etc).
 | 
					
						
							|  |  |  | 	OnBootstrap() *hook.Hook[*BootstrapEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnServe hook is triggered when the app web server is started
 | 
					
						
							|  |  |  | 	// (after starting the TCP listener but before initializing the blocking serve task),
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// allowing you to adjust its options and attach new routes or middlewares.
 | 
					
						
							|  |  |  | 	OnServe() *hook.Hook[*ServeEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnTerminate hook is triggered when the app is in the process
 | 
					
						
							|  |  |  | 	// of being terminated (ex. on SIGTERM signal).
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// Note that the app could be terminated abruptly without awaiting the hook completion.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnTerminate() *hook.Hook[*TerminateEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnBackupCreate hook is triggered on each [App.CreateBackup] call.
 | 
					
						
							|  |  |  | 	OnBackupCreate() *hook.Hook[*BackupEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnBackupRestore hook is triggered before app backup restore (aka. [App.RestoreBackup] call).
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Note that by default on success the application is restarted and the after state of the hook is ignored.
 | 
					
						
							|  |  |  | 	OnBackupRestore() *hook.Hook[*BackupEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 	// DB models event hooks
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnModelValidate is triggered every time when a model is being validated
 | 
					
						
							|  |  |  | 	// (e.g. triggered by App.Validate() or App.Save()).
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// For convenience, if you want to listen to only the Record models
 | 
					
						
							|  |  |  | 	// events without doing manual type assertion, you can attach to the OnRecord* proxy hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// If the optional "tags" list (Collection id/name, Model table name, etc.) is specified,
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// then all event handlers registered via the created hook will be
 | 
					
						
							|  |  |  | 	// triggered and called only if their event data origin matches the tags.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnModelValidate(tags ...string) *hook.TaggedHook[*ModelEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnModelCreate is triggered every time when a new model is being created
 | 
					
						
							|  |  |  | 	// (e.g. triggered by App.Save()).
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// Operations BEFORE the e.Next() execute before the model validation
 | 
					
						
							|  |  |  | 	// and the INSERT DB statement.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Operations AFTER the e.Next() execute after the model validation
 | 
					
						
							|  |  |  | 	// and the INSERT DB statement.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Note that successful execution doesn't guarantee that the model
 | 
					
						
							|  |  |  | 	// is persisted in the database since its wrapping transaction may
 | 
					
						
							|  |  |  | 	// not have been committed yet.
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// If you want to listen to only the actual persisted events, you can
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// bind to [OnModelAfterCreateSuccess] or [OnModelAfterCreateError] hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// For convenience, if you want to listen to only the Record models
 | 
					
						
							|  |  |  | 	// events without doing manual type assertion, you can attach to the OnRecord* proxy hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If the optional "tags" list (Collection id/name, Model table name, etc.) is specified,
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// then all event handlers registered via the created hook will be
 | 
					
						
							|  |  |  | 	// triggered and called only if their event data origin matches the tags.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnModelCreate(tags ...string) *hook.TaggedHook[*ModelEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnModelCreateExecute is triggered after successful Model validation
 | 
					
						
							|  |  |  | 	// and right before the model INSERT DB statement execution.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// Usually it is triggered as part of the App.Save() in the following firing order:
 | 
					
						
							|  |  |  | 	// OnModelCreate {
 | 
					
						
							|  |  |  | 	//    -> OnModelValidate (skipped with App.SaveNoValidate())
 | 
					
						
							|  |  |  | 	//    -> OnModelCreateExecute
 | 
					
						
							|  |  |  | 	// }
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Note that successful execution doesn't guarantee that the model
 | 
					
						
							|  |  |  | 	// is persisted in the database since its wrapping transaction may have been
 | 
					
						
							|  |  |  | 	// committed yet.
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// If you want to listen to only the actual persisted events,
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// you can bind to [OnModelAfterCreateSuccess] or [OnModelAfterCreateError] hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// For convenience, if you want to listen to only the Record models
 | 
					
						
							|  |  |  | 	// events without doing manual type assertion, you can attach to the OnRecord* proxy hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If the optional "tags" list (Collection id/name, Model table name, etc.) is specified,
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// then all event handlers registered via the created hook will be
 | 
					
						
							|  |  |  | 	// triggered and called only if their event data origin matches the tags.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnModelCreateExecute(tags ...string) *hook.TaggedHook[*ModelEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnModelAfterCreateSuccess is triggered after each successful
 | 
					
						
							|  |  |  | 	// Model DB create persistence.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// Note that when a Model is persisted as part of a transaction,
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// this hook is delayed and executed only AFTER the transaction has been committed.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// This hook is NOT triggered in case the transaction rollbacks
 | 
					
						
							|  |  |  | 	// (aka. when the model wasn't persisted).
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// For convenience, if you want to listen to only the Record models
 | 
					
						
							|  |  |  | 	// events without doing manual type assertion, you can attach to the OnRecord* proxy hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If the optional "tags" list (Collection id/name, Model table name, etc.) is specified,
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// then all event handlers registered via the created hook will be
 | 
					
						
							|  |  |  | 	// triggered and called only if their event data origin matches the tags.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnModelAfterCreateSuccess(tags ...string) *hook.TaggedHook[*ModelEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnModelAfterCreateError is triggered after each failed
 | 
					
						
							|  |  |  | 	// Model DB create persistence.
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// Note that the execution of this hook is either immediate or delayed
 | 
					
						
							|  |  |  | 	// depending on the error:
 | 
					
						
							|  |  |  | 	//   - "immediate" on App.Save() failure
 | 
					
						
							|  |  |  | 	//   - "delayed" on transaction rollback
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// For convenience, if you want to listen to only the Record models
 | 
					
						
							|  |  |  | 	// events without doing manual type assertion, you can attach to the OnRecord* proxy hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If the optional "tags" list (Collection id/name, Model table name, etc.) is specified,
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// then all event handlers registered via the created hook will be
 | 
					
						
							|  |  |  | 	// triggered and called only if their event data origin matches the tags.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnModelAfterCreateError(tags ...string) *hook.TaggedHook[*ModelErrorEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnModelUpdate is triggered every time when a new model is being updated
 | 
					
						
							|  |  |  | 	// (e.g. triggered by App.Save()).
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Operations BEFORE the e.Next() execute before the model validation
 | 
					
						
							|  |  |  | 	// and the UPDATE DB statement.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Operations AFTER the e.Next() execute after the model validation
 | 
					
						
							|  |  |  | 	// and the UPDATE DB statement.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Note that successful execution doesn't guarantee that the model
 | 
					
						
							|  |  |  | 	// is persisted in the database since its wrapping transaction may
 | 
					
						
							|  |  |  | 	// not have been committed yet.
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// If you want to listen to only the actual persisted events, you can
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// bind to [OnModelAfterUpdateSuccess] or [OnModelAfterUpdateError] hooks.
 | 
					
						
							| 
									
										
										
										
											2022-12-02 20:25:36 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// For convenience, if you want to listen to only the Record models
 | 
					
						
							|  |  |  | 	// events without doing manual type assertion, you can attach to the OnRecord* proxy hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If the optional "tags" list (Collection id/name, Model table name, etc.) 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.
 | 
					
						
							|  |  |  | 	OnModelUpdate(tags ...string) *hook.TaggedHook[*ModelEvent] | 
					
						
							| 
									
										
										
										
											2022-12-02 20:25:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnModelUpdateExecute is triggered after successful Model validation
 | 
					
						
							|  |  |  | 	// and right before the model UPDATE DB statement execution.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Usually it is triggered as part of the App.Save() in the following firing order:
 | 
					
						
							|  |  |  | 	// OnModelUpdate {
 | 
					
						
							|  |  |  | 	//    -> OnModelValidate (skipped with App.SaveNoValidate())
 | 
					
						
							|  |  |  | 	//    -> OnModelUpdateExecute
 | 
					
						
							|  |  |  | 	// }
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Note that successful execution doesn't guarantee that the model
 | 
					
						
							|  |  |  | 	// is persisted in the database since its wrapping transaction may have been
 | 
					
						
							|  |  |  | 	// committed yet.
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// If you want to listen to only the actual persisted events,
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// you can bind to [OnModelAfterUpdateSuccess] or [OnModelAfterUpdateError] hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// For convenience, if you want to listen to only the Record models
 | 
					
						
							|  |  |  | 	// events without doing manual type assertion, you can attach to the OnRecord* proxy hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If the optional "tags" list (Collection id/name, Model table name, etc.) 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.
 | 
					
						
							|  |  |  | 	OnModelUpdateExecute(tags ...string) *hook.TaggedHook[*ModelEvent] | 
					
						
							| 
									
										
										
										
											2022-12-02 20:25:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnModelAfterUpdateSuccess is triggered after each successful
 | 
					
						
							|  |  |  | 	// Model DB update persistence.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Note that when a Model is persisted as part of a transaction,
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// this hook is delayed and executed only AFTER the transaction has been committed.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// This hook is NOT triggered in case the transaction rollbacks
 | 
					
						
							|  |  |  | 	// (aka. when the model changes weren't persisted).
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// For convenience, if you want to listen to only the Record models
 | 
					
						
							|  |  |  | 	// events without doing manual type assertion, you can attach to the OnRecord* proxy hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If the optional "tags" list (Collection id/name, Model table name, etc.) 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.
 | 
					
						
							|  |  |  | 	OnModelAfterUpdateSuccess(tags ...string) *hook.TaggedHook[*ModelEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnModelAfterUpdateError is triggered after each failed
 | 
					
						
							|  |  |  | 	// Model DB update persistence.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// Note that the execution of this hook is either immediate or delayed
 | 
					
						
							|  |  |  | 	// depending on the error:
 | 
					
						
							|  |  |  | 	//   - "immediate" on App.Save() failure
 | 
					
						
							|  |  |  | 	//   - "delayed" on transaction rollback
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// For convenience, if you want to listen to only the Record models
 | 
					
						
							|  |  |  | 	// events without doing manual type assertion, you can attach to the OnRecord* proxy hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If the optional "tags" list (Collection id/name, Model table name, etc.) 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.
 | 
					
						
							|  |  |  | 	OnModelAfterUpdateError(tags ...string) *hook.TaggedHook[*ModelErrorEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnModelDelete is triggered every time when a new model is being deleted
 | 
					
						
							|  |  |  | 	// (e.g. triggered by App.Delete()).
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// Note that successful execution doesn't guarantee that the model
 | 
					
						
							|  |  |  | 	// is deleted from the database since its wrapping transaction may
 | 
					
						
							|  |  |  | 	// not have been committed yet.
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// If you want to listen to only the actual persisted deleted events, you can
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// bind to [OnModelAfterDeleteSuccess] or [OnModelAfterDeleteError] hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// For convenience, if you want to listen to only the Record models
 | 
					
						
							|  |  |  | 	// events without doing manual type assertion, you can attach to the OnRecord* proxy hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If the optional "tags" list (Collection id/name, Model table name, etc.) 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.
 | 
					
						
							|  |  |  | 	OnModelDelete(tags ...string) *hook.TaggedHook[*ModelEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnModelUpdateExecute is triggered right before the model
 | 
					
						
							|  |  |  | 	// DELETE DB statement execution.
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// Usually it is triggered as part of the App.Delete() in the following firing order:
 | 
					
						
							|  |  |  | 	// OnModelDelete {
 | 
					
						
							|  |  |  | 	//    -> (internal delete checks)
 | 
					
						
							|  |  |  | 	//    -> OnModelDeleteExecute
 | 
					
						
							|  |  |  | 	// }
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Note that successful execution doesn't guarantee that the model
 | 
					
						
							|  |  |  | 	// is deleted from the database since its wrapping transaction may
 | 
					
						
							|  |  |  | 	// not have been committed yet.
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// If you want to listen to only the actual persisted deleted events, you can
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// bind to [OnModelAfterDeleteSuccess] or [OnModelAfterDeleteError] hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// For convenience, if you want to listen to only the Record models
 | 
					
						
							|  |  |  | 	// events without doing manual type assertion, you can attach to the OnRecord* proxy hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If the optional "tags" list (Collection id/name, Model table name, etc.) 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.
 | 
					
						
							|  |  |  | 	OnModelDeleteExecute(tags ...string) *hook.TaggedHook[*ModelEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnModelAfterDeleteSuccess is triggered after each successful
 | 
					
						
							|  |  |  | 	// Model DB delete persistence.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Note that when a Model is deleted as part of a transaction,
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// this hook is delayed and executed only AFTER the transaction has been committed.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// This hook is NOT triggered in case the transaction rollbacks
 | 
					
						
							|  |  |  | 	// (aka. when the model delete wasn't persisted).
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// For convenience, if you want to listen to only the Record models
 | 
					
						
							|  |  |  | 	// events without doing manual type assertion, you can attach to the OnRecord* proxy hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If the optional "tags" list (Collection id/name, Model table name, etc.) 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.
 | 
					
						
							|  |  |  | 	OnModelAfterDeleteSuccess(tags ...string) *hook.TaggedHook[*ModelEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnModelAfterDeleteError is triggered after each failed
 | 
					
						
							|  |  |  | 	// Model DB delete persistence.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// Note that the execution of this hook is either immediate or delayed
 | 
					
						
							|  |  |  | 	// depending on the error:
 | 
					
						
							|  |  |  | 	//   - "immediate" on App.Delete() failure
 | 
					
						
							|  |  |  | 	//   - "delayed" on transaction rollback
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// For convenience, if you want to listen to only the Record models
 | 
					
						
							|  |  |  | 	// events without doing manual type assertion, you can attach to the OnRecord* proxy hooks.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// If the optional "tags" list (Collection id/name, Model table name, etc.) 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.
 | 
					
						
							|  |  |  | 	OnModelAfterDeleteError(tags ...string) *hook.TaggedHook[*ModelErrorEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// Record models event hooks
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnRecordEnrich is triggered every time when a record is enriched
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// (as part of the builtin Record responses, during realtime message seriazation, or when [apis.EnrichRecord] is invoked).
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// It could be used for example to redact/hide or add computed temporary
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// Record model props only for the specific request info. For example:
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//  app.OnRecordEnrich("posts").BindFunc(func(e core.*RecordEnrichEvent) {
 | 
					
						
							|  |  |  | 	//      // hide one or more fields
 | 
					
						
							|  |  |  | 	//      e.Record.Hide("role")
 | 
					
						
							| 
									
										
										
										
											2023-04-05 01:33:35 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	//      // add new custom field for registered users
 | 
					
						
							|  |  |  | 	//      if e.RequestInfo.Auth != nil && e.RequestInfo.Auth.Collection().Name == "users" {
 | 
					
						
							|  |  |  | 	//          e.Record.WithCustomData(true) // for security requires explicitly allowing it
 | 
					
						
							|  |  |  | 	//          e.Record.Set("computedScore", e.Record.GetInt("score") * e.RequestInfo.Auth.GetInt("baseScore"))
 | 
					
						
							|  |  |  | 	//      }
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//      return e.Next()
 | 
					
						
							|  |  |  | 	//  })
 | 
					
						
							| 
									
										
										
										
											2023-04-05 01:33:35 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordEnrich(tags ...string) *hook.TaggedHook[*RecordEnrichEvent] | 
					
						
							| 
									
										
										
										
											2023-04-05 01:33:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnRecordValidate is a Record proxy model hook of [OnModelValidate].
 | 
					
						
							| 
									
										
										
										
											2023-04-05 01:33:35 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordValidate(tags ...string) *hook.TaggedHook[*RecordEvent] | 
					
						
							| 
									
										
										
										
											2023-04-05 01:33:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnRecordCreate is a Record proxy model hook of [OnModelCreate].
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnRecordCreate(tags ...string) *hook.TaggedHook[*RecordEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnRecordCreateExecute is a Record proxy model hook of [OnModelCreateExecute].
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnRecordCreateExecute(tags ...string) *hook.TaggedHook[*RecordEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnRecordAfterCreateSuccess is a Record proxy model hook of [OnModelAfterCreateSuccess].
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnRecordAfterCreateSuccess(tags ...string) *hook.TaggedHook[*RecordEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnRecordAfterCreateError is a Record proxy model hook of [OnModelAfterCreateError].
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnRecordAfterCreateError(tags ...string) *hook.TaggedHook[*RecordErrorEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnRecordUpdate is a Record proxy model hook of [OnModelUpdate].
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnRecordUpdate(tags ...string) *hook.TaggedHook[*RecordEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnRecordUpdateExecute is a Record proxy model hook of [OnModelUpdateExecute].
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnRecordUpdateExecute(tags ...string) *hook.TaggedHook[*RecordEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnRecordAfterUpdateSuccess is a Record proxy model hook of [OnModelAfterUpdateSuccess].
 | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnRecordAfterUpdateSuccess(tags ...string) *hook.TaggedHook[*RecordEvent] | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnRecordAfterUpdateError is a Record proxy model hook of [OnModelAfterUpdateError].
 | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnRecordAfterUpdateError(tags ...string) *hook.TaggedHook[*RecordErrorEvent] | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnRecordDelete is a Record proxy model hook of [OnModelDelete].
 | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnRecordDelete(tags ...string) *hook.TaggedHook[*RecordEvent] | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnRecordDeleteExecute is a Record proxy model hook of [OnModelDeleteExecute].
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnRecordDeleteExecute(tags ...string) *hook.TaggedHook[*RecordEvent] | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnRecordAfterDeleteSuccess is a Record proxy model hook of [OnModelAfterDeleteSuccess].
 | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnRecordAfterDeleteSuccess(tags ...string) *hook.TaggedHook[*RecordEvent] | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnRecordAfterDeleteError is a Record proxy model hook of [OnModelAfterDeleteError].
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnRecordAfterDeleteError(tags ...string) *hook.TaggedHook[*RecordErrorEvent] | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// Collection models event hooks
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnCollectionValidate is a Collection proxy model hook of [OnModelValidate].
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnCollectionValidate(tags ...string) *hook.TaggedHook[*CollectionEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnCollectionCreate is a Collection proxy model hook of [OnModelCreate].
 | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnCollectionCreate(tags ...string) *hook.TaggedHook[*CollectionEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnCollectionCreateExecute is a Collection proxy model hook of [OnModelCreateExecute].
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnCollectionCreateExecute(tags ...string) *hook.TaggedHook[*CollectionEvent] | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnCollectionAfterCreateSuccess is a Collection proxy model hook of [OnModelAfterCreateSuccess].
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnCollectionAfterCreateSuccess(tags ...string) *hook.TaggedHook[*CollectionEvent] | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnCollectionAfterCreateError is a Collection proxy model hook of [OnModelAfterCreateError].
 | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnCollectionAfterCreateError(tags ...string) *hook.TaggedHook[*CollectionErrorEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnCollectionUpdate is a Collection proxy model hook of [OnModelUpdate].
 | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnCollectionUpdate(tags ...string) *hook.TaggedHook[*CollectionEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnCollectionUpdateExecute is a Collection proxy model hook of [OnModelUpdateExecute].
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnCollectionUpdateExecute(tags ...string) *hook.TaggedHook[*CollectionEvent] | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnCollectionAfterUpdateSuccess is a Collection proxy model hook of [OnModelAfterUpdateSuccess].
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnCollectionAfterUpdateSuccess(tags ...string) *hook.TaggedHook[*CollectionEvent] | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnCollectionAfterUpdateError is a Collection proxy model hook of [OnModelAfterUpdateError].
 | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnCollectionAfterUpdateError(tags ...string) *hook.TaggedHook[*CollectionErrorEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnCollectionDelete is a Collection proxy model hook of [OnModelDelete].
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnCollectionDelete(tags ...string) *hook.TaggedHook[*CollectionEvent] | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnCollectionDeleteExecute is a Collection proxy model hook of [OnModelDeleteExecute].
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnCollectionDeleteExecute(tags ...string) *hook.TaggedHook[*CollectionEvent] | 
					
						
							| 
									
										
										
										
											2023-01-15 23:00:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnCollectionAfterDeleteSuccess is a Collection proxy model hook of [OnModelAfterDeleteSuccess].
 | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnCollectionAfterDeleteSuccess(tags ...string) *hook.TaggedHook[*CollectionEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnCollectionAfterDeleteError is a Collection proxy model hook of [OnModelAfterDeleteError].
 | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnCollectionAfterDeleteError(tags ...string) *hook.TaggedHook[*CollectionErrorEvent] | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 	// Mailer event hooks
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnMailerSend hook is triggered every time when a new email is
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// being send using the [App.NewMailClient()] instance.
 | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// It allows intercepting the email message or to use a custom mailer client.
 | 
					
						
							|  |  |  | 	OnMailerSend() *hook.Hook[*MailerEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnMailerRecordAuthAlertSend hook is triggered when
 | 
					
						
							|  |  |  | 	// sending a new device login auth alert email, allowing you to
 | 
					
						
							|  |  |  | 	// intercept and customize the email message that is being sent.
 | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnMailerRecordAuthAlertSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent] | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnMailerBeforeRecordResetPasswordSend hook is triggered when
 | 
					
						
							|  |  |  | 	// sending a password reset email to an auth record, allowing
 | 
					
						
							|  |  |  | 	// you to intercept and customize the email message that is being sent.
 | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnMailerRecordPasswordResetSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent] | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnMailerBeforeRecordVerificationSend hook is triggered when
 | 
					
						
							|  |  |  | 	// sending a verification email to an auth record, allowing
 | 
					
						
							|  |  |  | 	// you to intercept and customize the email message that is being sent.
 | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnMailerRecordVerificationSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnMailerRecordEmailChangeSend hook is triggered when sending a
 | 
					
						
							|  |  |  | 	// confirmation new address email to an auth record, allowing
 | 
					
						
							|  |  |  | 	// you to intercept and customize the email message that is being sent.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnMailerRecordEmailChangeSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent] | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnMailerRecordOTPSend hook is triggered when sending an OTP email
 | 
					
						
							|  |  |  | 	// to an auth record, allowing you to intercept and customize the
 | 
					
						
							|  |  |  | 	// email message that is being sent.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnMailerRecordOTPSend(tags ...string) *hook.TaggedHook[*MailerRecordEvent] | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 	// Realtime API event hooks
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnRealtimeConnectRequest hook is triggered when establishing the SSE client connection.
 | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// Any execution after e.Next() of a hook handler happens after the client disconnects.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRealtimeConnectRequest() *hook.Hook[*RealtimeConnectRequestEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnRealtimeMessageSend hook is triggered when sending an SSE message to a client.
 | 
					
						
							|  |  |  | 	OnRealtimeMessageSend() *hook.Hook[*RealtimeMessageEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnRealtimeSubscribeRequest hook is triggered when updating the
 | 
					
						
							|  |  |  | 	// client subscriptions, allowing you to further validate and
 | 
					
						
							|  |  |  | 	// modify the submitted change.
 | 
					
						
							|  |  |  | 	OnRealtimeSubscribeRequest() *hook.Hook[*RealtimeSubscribeRequestEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 	// Settings API event hooks
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnSettingsListRequest hook is triggered on each API Settings list request.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Could be used to validate or modify the response before returning it to the client.
 | 
					
						
							|  |  |  | 	OnSettingsListRequest() *hook.Hook[*SettingsListRequestEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnSettingsUpdateRequest hook is triggered on each API Settings update request.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Could be used to additionally validate the request data or
 | 
					
						
							|  |  |  | 	// implement completely different persistence behavior.
 | 
					
						
							|  |  |  | 	OnSettingsUpdateRequest() *hook.Hook[*SettingsUpdateRequestEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnSettingsReload hook is triggered every time when the App.Settings()
 | 
					
						
							|  |  |  | 	// is being replaced with a new state.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// Calling App.Settings() after e.Next() returns the new state.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnSettingsReload() *hook.Hook[*SettingsReloadEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 	// File API event hooks
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 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[*FileDownloadRequestEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// OnFileBeforeTokenRequest hook is triggered on each auth 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.
 | 
					
						
							|  |  |  | 	OnFileTokenRequest(tags ...string) *hook.TaggedHook[*FileTokenRequestEvent] | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 	// Record Auth API event hooks
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordAuthRequest(tags ...string) *hook.TaggedHook[*RecordAuthRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnRecordAuthWithPasswordRequest hook is triggered on each
 | 
					
						
							|  |  |  | 	// Record auth with password API request.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// [RecordAuthWithPasswordRequestEvent.Record] could be nil if no matching identity is found, allowing
 | 
					
						
							|  |  |  | 	// you to manually locate a different Record model (by reassigning [RecordAuthWithPasswordRequestEvent.Record]).
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordAuthWithPasswordRequest(tags ...string) *hook.TaggedHook[*RecordAuthWithPasswordRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnRecordAuthWithOAuth2Request hook is triggered on each Record
 | 
					
						
							|  |  |  | 	// OAuth2 sign-in/sign-up API request (after token exchange and before external provider linking).
 | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	// If [RecordAuthWithOAuth2RequestEvent.Record] is not set, then the OAuth2
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// request will try to create a new auth Record.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// To assign or link a different existing record model you can
 | 
					
						
							|  |  |  | 	// change the [RecordAuthWithOAuth2RequestEvent.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.
 | 
					
						
							|  |  |  | 	OnRecordAuthWithOAuth2Request(tags ...string) *hook.TaggedHook[*RecordAuthWithOAuth2RequestEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnRecordAuthRefreshRequest hook is triggered on 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.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordAuthRefreshRequest(tags ...string) *hook.TaggedHook[*RecordAuthRefreshRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnRecordRequestPasswordResetRequest hook is triggered on
 | 
					
						
							|  |  |  | 	// each Record request password reset API request.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Could be used to additionally validate the request data or implement
 | 
					
						
							|  |  |  | 	// completely different password reset behavior.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordRequestPasswordResetRequest(tags ...string) *hook.TaggedHook[*RecordRequestPasswordResetRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnRecordConfirmPasswordResetRequest hook is triggered on
 | 
					
						
							|  |  |  | 	// each Record confirm password reset API request.
 | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// Could be used to additionally validate the request data or implement
 | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 	// completely different persistence behavior.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordConfirmPasswordResetRequest(tags ...string) *hook.TaggedHook[*RecordConfirmPasswordResetRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnRecordRequestVerificationRequest hook is triggered on
 | 
					
						
							|  |  |  | 	// each Record request verification API request.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Could be used to additionally validate the loaded request data or implement
 | 
					
						
							|  |  |  | 	// completely different verification behavior.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordRequestVerificationRequest(tags ...string) *hook.TaggedHook[*RecordRequestVerificationRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnRecordConfirmVerificationRequest hook is triggered on each
 | 
					
						
							|  |  |  | 	// Record confirm verification API request.
 | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// Could be used to additionally validate the request data or implement
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// completely different persistence behavior.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordConfirmVerificationRequest(tags ...string) *hook.TaggedHook[*RecordConfirmVerificationRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnRecordRequestEmailChangeRequest hook is triggered on each
 | 
					
						
							|  |  |  | 	// Record request email change API request.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Could be used to additionally validate the request data or implement
 | 
					
						
							|  |  |  | 	// completely different request email change behavior.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordRequestEmailChangeRequest(tags ...string) *hook.TaggedHook[*RecordRequestEmailChangeRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnRecordConfirmEmailChangeRequest hook is triggered on each
 | 
					
						
							|  |  |  | 	// Record confirm email change API request.
 | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// Could be used to additionally validate the request data or implement
 | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 	// completely different persistence behavior.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordConfirmEmailChangeRequest(tags ...string) *hook.TaggedHook[*RecordConfirmEmailChangeRequestEvent] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnRecordRequestOTPRequest hook is triggered on each Record
 | 
					
						
							|  |  |  | 	// request OTP API request.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-11-14 00:34:43 +08:00
										 |  |  | 	// [RecordCreateOTPRequestEvent.Record] could be nil if no matching identity is found, allowing
 | 
					
						
							|  |  |  | 	// you to manually create or locate a different Record model (by reassigning [RecordCreateOTPRequestEvent.Record]).
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	OnRecordRequestOTPRequest(tags ...string) *hook.TaggedHook[*RecordCreateOTPRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnRecordAuthWithOTPRequest hook is triggered on each Record
 | 
					
						
							|  |  |  | 	// auth with OTP API request.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordAuthWithOTPRequest(tags ...string) *hook.TaggedHook[*RecordAuthWithOTPRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2022-12-03 20:50:02 +08:00
										 |  |  | 	// Record CRUD API event hooks
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordsListRequest(tags ...string) *hook.TaggedHook[*RecordsListRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordViewRequest(tags ...string) *hook.TaggedHook[*RecordRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnRecordCreateRequest hook is triggered on each API Record create request.
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// Could be used to additionally validate the request data or implement
 | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 	// completely different persistence behavior.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordCreateRequest(tags ...string) *hook.TaggedHook[*RecordRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnRecordUpdateRequest hook is triggered on each API Record update request.
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// Could be used to additionally validate the request data or implement
 | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 	// completely different persistence behavior.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordUpdateRequest(tags ...string) *hook.TaggedHook[*RecordRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnRecordDeleteRequest hook is triggered on each API Record delete request.
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// Could be used to additionally validate the request data or implement
 | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 	// completely different delete behavior.
 | 
					
						
							| 
									
										
										
										
											2023-01-28 04:19:08 +08:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2023-01-29 22:00:03 +08:00
										 |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnRecordDeleteRequest(tags ...string) *hook.TaggedHook[*RecordRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 	// Collection API event hooks
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnCollectionsListRequest() *hook.Hook[*CollectionsListRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// 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.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnCollectionViewRequest() *hook.Hook[*CollectionRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnCollectionCreateRequest hook is triggered on each API Collection create request.
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// Could be used to additionally validate the request data or implement
 | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 	// completely different persistence behavior.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnCollectionCreateRequest() *hook.Hook[*CollectionRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnCollectionUpdateRequest hook is triggered on each API Collection update request.
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// Could be used to additionally validate the request data or implement
 | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 	// completely different persistence behavior.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnCollectionUpdateRequest() *hook.Hook[*CollectionRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnCollectionDeleteRequest hook is triggered on each API Collection delete request.
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// Could be used to additionally validate the request data or implement
 | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 	// completely different delete behavior.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnCollectionDeleteRequest() *hook.Hook[*CollectionRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// OnCollectionsBeforeImportRequest hook is triggered on each API
 | 
					
						
							|  |  |  | 	// collections import request.
 | 
					
						
							| 
									
										
										
										
											2022-08-08 01:58:21 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// Could be used to additionally validate the imported collections or
 | 
					
						
							| 
									
										
										
										
											2023-06-20 02:45:45 +08:00
										 |  |  | 	// to implement completely different import behavior.
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	OnCollectionsImportRequest() *hook.Hook[*CollectionsImportRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-08-08 01:58:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 	// Batch API event hooks
 | 
					
						
							|  |  |  | 	// ---------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// OnBatchRequest hook is triggered on each API batch request.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Could be used to additionally validate or modify the submitted batch requests.
 | 
					
						
							|  |  |  | 	OnBatchRequest() *hook.Hook[*BatchRequestEvent] | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | } |