CRUD Engine
The CRUD Engine is the core component of the@repo/crud
package, providing enhanced CRUD operations with support for plugins, permissions, and auditing. It wraps a data provider from the @repo/data
package and adds additional functionality.
Features
- Enhanced CRUD Operations: Extends the basic CRUD operations with additional features
- Plugin System: Support for plugins that can modify behavior before and after operations
- Permissions Integration: Built-in support for access control
- Audit Logging: Automatic tracking of data changes
- Internationalization: Support for multiple languages
- Error Handling: Consistent error handling across operations
Basic Usage
Creating a CRUD Engine
Using the CRUD Engine
Configuration Options
The CRUD Engine accepts the following configuration options:Plugin System
The CRUD Engine includes a powerful plugin system that allows you to extend its functionality. Plugins can modify the behavior of CRUD operations by intercepting them before and after they are executed.Plugin Interface
Creating a Plugin
Plugin Execution Order
Plugins are executed in the order they are provided in theplugins
array. For example, if you have three plugins:
getList
operation would be:
pluginA.hooks.beforeGetList
pluginB.hooks.beforeGetList
pluginC.hooks.beforeGetList
- Actual
getList
operation pluginC.hooks.afterGetList
pluginB.hooks.afterGetList
pluginA.hooks.afterGetList
Permissions Integration
The CRUD Engine includes built-in support for permissions checking. When enabled, it will check if the current user has permission to perform the requested operation.Enabling Permissions
Permissions Context
When using permissions, you need to set the current user in the permissions context:Audit Logging
The CRUD Engine includes built-in support for audit logging. When enabled, it will log all changes to data.Enabling Audit Logging
Audit Context
When using audit logging, you need to set the current user in the audit context:Internationalization
The CRUD Engine includes built-in support for internationalization. You can specify the default locale and supported locales when creating the engine.Configuring Internationalization
Using Translations
The CRUD Engine uses thenext-intl
package for translations. You can use the useTranslation
hook to get translations: