Browse Source

low-code: add 'Replace' interceptor & update docs

Add support and documentation for a new interceptor type, Replace, which runs JavaScript instead of the default DB operation. Updates made across low-code docs:

- docs/en/low-code/interceptors.md: Document Replace semantics for Create/Update/Delete, add examples and model.json/type notes.
- docs/en/low-code/fluent-api.md: Expand AddInterceptor docs to list allowed name/type values and note Replace behavior; small attribute call-site change (DynamicPropertySetByClients(false)).
- docs/en/low-code/index.md: Simplify Getting Started by removing the package table and renumbering steps (register assembly, configure DbContext, define entity, add migration).
- docs/en/low-code/scripting-api.md: Remove db.getList entry from the scripting API table.

These changes clarify interceptor capabilities (Pre/Post/Replace) and streamline the quickstart instructions.
pull/25021/head
SALİH ÖZKARA 1 month ago
parent
commit
d3200e7e2a
  1. 6
      docs/en/low-code/fluent-api.md
  2. 38
      docs/en/low-code/index.md
  3. 25
      docs/en/low-code/interceptors.md
  4. 1
      docs/en/low-code/scripting-api.md

6
docs/en/low-code/fluent-api.md

@ -182,7 +182,7 @@ public string InternalNotes { get; set; }
Controls whether clients can set this property value. Useful for computed or server-assigned fields:
````csharp
[DynamicPropertySetByClients(Allow = false)]
[DynamicPropertySetByClients(false)]
public string RegistrationNumber { get; set; }
````
@ -217,7 +217,7 @@ public class Organization
}
````
> The `Name` parameter must be one of: `"Create"`, `"Update"`, or `"Delete"`. Multiple interceptors can be added to the same class (`AllowMultiple = true`).
> The `Name` parameter must be one of: `"Create"`, `"Update"`, or `"Delete"`. The `InterceptorType` can be `Pre`, `Post`, or `Replace`. When `Replace` is used, the default DB operation is skipped entirely and only the JavaScript handler runs. Multiple interceptors can be added to the same class (`AllowMultiple = true`).
See [Interceptors](interceptors.md) for the full JavaScript context API.
@ -292,7 +292,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
| `SetParent(entityName)` | Set parent entity for nesting |
| `SetUI(action)` | Configure entity-level UI |
| `ConfigureProperty(name, action)` | Configure a specific property |
| `AddInterceptor(name, type, js)` | Add a JavaScript interceptor |
| `AddInterceptor(name, type, js)` | Add a JavaScript interceptor. `name`: `"Create"`, `"Update"`, or `"Delete"`. `type`: `Pre`, `Post`, or `Replace` |
### Property Configuration Methods

38
docs/en/low-code/index.md

@ -53,37 +53,7 @@ Run `dotnet ef migrations add Added_Product` and start your application. You get
## Getting Started
### 1. Install NuGet Packages
| Package | Layer |
|---------|-------|
| `Volo.Abp.LowCode.Domain.Shared` | Domain.Shared |
| `Volo.Abp.LowCode.Domain` | Domain |
| `Volo.Abp.LowCode.Application.Contracts` | Application.Contracts |
| `Volo.Abp.LowCode.Application` | Application |
| `Volo.Abp.LowCode.HttpApi` | HttpApi |
| `Volo.Abp.LowCode.HttpApi.Client` | HttpApi.Client |
| `Volo.Abp.LowCode.EntityFrameworkCore` | EF Core |
| `Volo.Abp.LowCode.Blazor` | Blazor UI (SSR) |
| `Volo.Abp.LowCode.Blazor.Server` | Blazor Server |
| `Volo.Abp.LowCode.Blazor.WebAssembly` | Blazor WebAssembly |
| `Volo.Abp.LowCode.Installer` | Auto module discovery |
### 2. Add Module Dependencies
````csharp
[DependsOn(
typeof(AbpLowCodeApplicationModule),
typeof(AbpLowCodeEntityFrameworkCoreModule),
typeof(AbpLowCodeHttpApiModule),
typeof(AbpLowCodeBlazorModule)
)]
public class YourModule : AbpModule
{
}
````
### 3. Register Your Assembly
### 1. Register Your Assembly
In your Domain module, register the assembly that contains your `[DynamicEntity]` classes:
@ -96,7 +66,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
}
````
### 4. Configure DbContext
### 2. Configure DbContext
Call `ConfigureDynamicEntities()` in your `DbContext`:
@ -108,7 +78,7 @@ protected override void OnModelCreating(ModelBuilder builder)
}
````
### 5. Define Your First Entity
### 3. Define Your First Entity
````csharp
[DynamicEntity]
@ -125,7 +95,7 @@ public class Customer
}
````
### 6. Add Migration and Run
### 4. Add Migration and Run
```bash
dotnet ef migrations add Added_Customer

25
docs/en/low-code/interceptors.md

@ -7,7 +7,7 @@
# Interceptors
Interceptors allow you to run custom JavaScript code before or after Create, Update, and Delete operations on dynamic entities.
Interceptors allow you to run custom JavaScript code before, after, or instead of Create, Update, and Delete operations on dynamic entities.
## Interceptor Types
@ -15,10 +15,13 @@ Interceptors allow you to run custom JavaScript code before or after Create, Upd
|---------|------|---------------|
| `Create` | `Pre` | Before entity creation — validation, default values |
| `Create` | `Post` | After entity creation — notifications, related data |
| `Create` | `Replace` | Instead of entity creation — the default DB insert is skipped, only JavaScript runs |
| `Update` | `Pre` | Before entity update — validation, authorization |
| `Update` | `Post` | After entity update — sync, notifications |
| `Update` | `Replace` | Instead of entity update — the default DB update is skipped, only JavaScript runs |
| `Delete` | `Pre` | Before entity deletion — dependency checks |
| `Delete` | `Post` | After entity deletion — cleanup |
| `Delete` | `Replace` | Instead of entity deletion — the default DB delete is skipped, only JavaScript runs |
## Defining Interceptors with Attributes
@ -42,7 +45,7 @@ public class Organization
}
````
The `Name` parameter must be one of: `"Create"`, `"Update"`, or `"Delete"`. This maps directly to the CRUD command being intercepted. Multiple interceptors can be added to the same class (`AllowMultiple = true`).
The `Name` parameter must be one of: `"Create"`, `"Update"`, or `"Delete"`. The `InterceptorType` can be `Pre`, `Post`, or `Replace`. When `Replace` is used, the default database operation is completely skipped and only your JavaScript handler executes. Multiple interceptors can be added to the same class (`AllowMultiple = true`).
## Defining Interceptors in model.json
@ -66,7 +69,7 @@ Add interceptors to the `interceptors` array of an entity:
| Field | Type | Description |
|-------|------|-------------|
| `commandName` | string | `"Create"`, `"Update"`, or `"Delete"` |
| `type` | string | `"Pre"` or `"Post"` |
| `type` | string | `"Pre"`, `"Post"`, or `"Replace"` |
| `javascript` | string | JavaScript code to execute |
## JavaScript Context
@ -166,7 +169,21 @@ globalError = 'Cannot delete this entity!';
}
```
### Pre-Create: Self-Reference Check
### Replace-Create: Custom Insert Logic
When you need to completely replace the default create operation with custom logic:
```json
{
"commandName": "Create",
"type": "Replace",
"javascript": "var data = context.commandArgs.data;\ndata['Code'] = 'PRD-' + Date.now();\nawait db.insert('LowCodeDemo.Products.Product', data);\ncontext.log('Product created with custom code: ' + data['Code']);"
}
```
> When `Replace` is used, the standard database operation does not run. You are responsible for performing any necessary persistence in your JavaScript handler.
### Pre-Update: Self-Reference Check
```json
{

1
docs/en/low-code/scripting-api.md

@ -278,7 +278,6 @@ Direct CRUD methods on the `db` object:
| Method | Description | Returns |
|--------|-------------|---------|
| `db.get(entityName, id)` | Get by ID | `Promise<object\|null>` |
| `db.getList(entityName, take?)` | Get list | `Promise<object[]>` |
| `db.getCount(entityName)` | Get count | `Promise<number>` |
| `db.insert(entityName, entity)` | Insert new | `Promise<object>` |
| `db.update(entityName, entity)` | Update existing | `Promise<object>` |

Loading…
Cancel
Save