ModelCustomizer
The ModelCustomizer is the heart of Sentro's customization system. It provides a fluent API for customizing table behavior, appearance, and business logic.
Basic Usage
Register a customizer using the customize() method:
import { ModelCustomizer } from "@sentrodb/connector-node/dist/inc/customizers/modelCustomizer";
connector.customize(() => {
const c = new ModelCustomizer("users");
// Add customizations here
c.rename("System Users");
c.renameColumn("email", "Email Address");
return c;
});Table Display Customization
rename(name: string)
Change the display name of the table:
c.rename("Customer Accounts");renameColumn(columnName, displayName)
Change the display name of a column:
c.renameColumn("created_at", "Created Date");
c.renameColumn("is_active", "Active Status");addDisplayField(name, callback)
Add computed fields for display purposes:
// Add full name field
c.addDisplayField("fullName", (record) => {
return `${record.firstName} ${record.lastName}`;
});
// Add status badge
c.addDisplayField("statusBadge", (record) => {
return record.isActive ? "Active" : "Inactive";
});
// Add formatted date
c.addDisplayField("joinedDate", (record) => {
return new Date(record.createdAt).toLocaleDateString();
});Note: Display fields are computed at runtime and are not stored in the database. They're perfect for combining multiple fields or formatting data for display.
Complete API Reference
Constructor
new ModelCustomizer<TableName>(tableName: TableName)Display Methods
| Method | Description | Returns |
|---|---|---|
rename(name: string) | Set table display name | this |
renameColumn(column, name) | Set column display name | this |
addDisplayField(name, callback) | Add computed display field | this |
Hook Methods
| Method | Description | Returns |
|---|---|---|
onBefore(op, handler) | Register before hook | this |
onAfter(op, handler) | Register after hook | this |
Field Writer Methods
| Method | Description | Returns |
|---|---|---|
replaceFieldWriting(field, handler) | Replace field writing logic | this |
Action Methods
| Method | Description | Returns |
|---|---|---|
registerTableAction(id, label, callback) | Register bulk table action | this |
registerDetailAction(id, label, callback) | Register single record action | this |
addAction(config) | Unified action registration | this |
Query Methods
| Method | Description | Returns |
|---|---|---|
getTableAction(id) | Get table action by ID | Function | undefined |
getDetailAction(id) | Get detail action by ID | Function | undefined |
getTableActionIds() | Get all table action IDs | string[] |
getDetailActionIds() | Get all detail action IDs | string[] |
Chaining Methods
Most methods return this, enabling fluent chaining:
connector.customize(() => {
return new ModelCustomizer("users")
.rename("System Users")
.renameColumn("email", "Email Address")
.renameColumn("created_at", "Joined Date")
.addDisplayField("fullName", (r) => `${r.firstName} ${r.lastName}`)
.onBefore("CREATE", async (payload) => {
payload.createdAt = new Date().toISOString();
return payload;
});
});Multiple Table Customizations
Register customizers for multiple tables:
// Users table
connector.customize(() => {
const c = new ModelCustomizer("users");
c.rename("Customers");
c.renameColumn("email", "Email Address");
return c;
});
// Posts table
connector.customize(() => {
const c = new ModelCustomizer("posts");
c.rename("Blog Posts");
c.renameColumn("created_at", "Published Date");
return c;
});
// Orders table
connector.customize(() => {
const c = new ModelCustomizer("orders");
c.rename("Customer Orders");
c.addDisplayField("total", (r) => `$${r.amount.toFixed(2)}`);
return c;
});Type Safety
ModelCustomizer is fully type-safe when used with TypeScript. The table name and column names are validated at compile time:
// ✅ Correct - "users" exists in schema
const c = new ModelCustomizer("users");
// ❌ Error - "nonexistent" not in schema
const c = new ModelCustomizer("nonexistent");
// ✅ Correct - "email" exists in users table
c.renameColumn("email", "Email");
// ❌ Error - "invalid_column" not in users table
c.renameColumn("invalid_column", "Invalid");Next Steps: Learn about Hooks to intercept and modify CRUD operations.