Giao diện
@digiforce-nc/plugin-ui-schema-storage
Plugin lưu trữ UI Schema — kho cây JSON schema cho toàn bộ giao diện (block, form, table, action, button), sử dụng closure table pattern.
Plugin này làm gì?
Mọi thành phần UI trong Digiforce — từ trang, block, form, bảng đến nút bấm — đều được mô tả bằng JSON schema. plugin-ui-schema-storage là kho lưu trữ trung tâm cho tất cả schema đó. Nó lưu trong DB dạng cây (parent-child) qua closure table, hỗ trợ CRUD, patch, di chuyển node, cache, và template tái sử dụng.
Ba nhiệm vụ chính
| # | Nhiệm vụ | Chi tiết |
|---|---|---|
| 1 | Lưu trữ cây schema | Mỗi schema là 1 node trong cây, PK = x-uid, quan hệ qua closure table |
| 2 | CRUD + patch | getJsonSchema, insert, remove, patch, batchPatch, insertAdjacent, clearAncestor |
| 3 | Template | Lưu schema thành template (saveAsTemplate) để tái sử dụng nhanh |
Kiến trúc lưu trữ — Closure Table
Schema được tổ chức dạng cây. Thay vì chỉ lưu parentId, plugin dùng closure table — lưu mọi cặp ancestor-descendant:
Luồng insert schema
API endpoints
| Endpoint | Mô tả |
|---|---|
uiSchemas:getJsonSchema | Lấy schema theo UID (bao gồm toàn bộ children tree) |
uiSchemas:getProperties | Lấy properties — chỉ children trực tiếp (depth = 1) |
uiSchemas:insert | Chèn schema mới vào vị trí trong cây |
uiSchemas:remove | Xóa schema (cascade xóa tất cả descendants) |
uiSchemas:patch | Cập nhật partial schema (merge vào existing) |
uiSchemas:batchPatch | Cập nhật nhiều schema cùng lúc (atomic) |
uiSchemas:insertAdjacent | Chèn ở vị trí cụ thể: beforeBegin, afterBegin, beforeEnd, afterEnd |
uiSchemas:clearAncestor | Xóa ancestor links (detach node khỏi cây) |
uiSchemas:clearCache | Xóa cache schema cho UID cụ thể hoặc toàn bộ |
uiSchemas:saveAsTemplate | Lưu schema subtree thành template tái sử dụng |
uiSchemaTemplates:list | Danh sách template đã lưu |
uiSchemaTemplates:get | Chi tiết template theo key |
Database — 5 bảng
| Bảng | Chứa gì | Ghi chú |
|---|---|---|
uiSchemas | Node schema (PK: x-uid, JSON schema data) | Mỗi node là 1 thành phần UI |
uiSchemaTreePath | Cặp ancestor-descendant + depth | Closure table — truy vấn subtree nhanh |
uiSchemaTemplates | Template schema tái sử dụng | Lưu snapshot của subtree |
uiSchemaServerHooks | Server-side hooks gắn vào schema events | VD: hook chạy khi button được click |
uiButtonSchemasRoles | Liên kết button schema ↔ role (M2M) | Kiểm soát role nào thấy button nào |
Thành phần chính phía server
| Thành phần | Mô tả |
|---|---|
UiSchemaRepository | Repository xử lý CRUD + tree operations (closure table) |
ServerHooks | Registry hook chạy khi schema events xảy ra (insert, remove, click) |
SchemaCache | Cache layer — invalidate khi schema thay đổi |
Dependencies
| Package | Vai trò |
|---|---|
@digiforce-nc/database | Database ORM (peer) |
@digiforce-nc/server | Server framework (peer) |
@digiforce-nc/cache | Cache schema (peer) |
@digiforce-nc/plugin-error-handler | Xử lý lỗi schema validation |
Mục lục chi tiết
- Kiến trúc — Repository, closure table, magic attribute, server hooks
- API reference — Tất cả uiSchemas actions + uiSchemaTemplates
- Database schema — ER diagram, 5 bảng
- FAQ — Câu hỏi thường gặp