Bỏ qua, đến nội dung

@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-storagekho 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
1Lưu trữ cây schemaMỗi schema là 1 node trong cây, PK = x-uid, quan hệ qua closure table
2CRUD + patchgetJsonSchema, insert, remove, patch, batchPatch, insertAdjacent, clearAncestor
3TemplateLư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

EndpointMô tả
uiSchemas:getJsonSchemaLấy schema theo UID (bao gồm toàn bộ children tree)
uiSchemas:getPropertiesLấy properties — chỉ children trực tiếp (depth = 1)
uiSchemas:insertChèn schema mới vào vị trí trong cây
uiSchemas:removeXóa schema (cascade xóa tất cả descendants)
uiSchemas:patchCập nhật partial schema (merge vào existing)
uiSchemas:batchPatchCập nhật nhiều schema cùng lúc (atomic)
uiSchemas:insertAdjacentChèn ở vị trí cụ thể: beforeBegin, afterBegin, beforeEnd, afterEnd
uiSchemas:clearAncestorXóa ancestor links (detach node khỏi cây)
uiSchemas:clearCacheXóa cache schema cho UID cụ thể hoặc toàn bộ
uiSchemas:saveAsTemplateLưu schema subtree thành template tái sử dụng
uiSchemaTemplates:listDanh sách template đã lưu
uiSchemaTemplates:getChi tiết template theo key

Database — 5 bảng

BảngChứa gìGhi chú
uiSchemasNode schema (PK: x-uid, JSON schema data)Mỗi node là 1 thành phần UI
uiSchemaTreePathCặp ancestor-descendant + depthClosure table — truy vấn subtree nhanh
uiSchemaTemplatesTemplate schema tái sử dụngLưu snapshot của subtree
uiSchemaServerHooksServer-side hooks gắn vào schema eventsVD: hook chạy khi button được click
uiButtonSchemasRolesLiê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ầnMô tả
UiSchemaRepositoryRepository xử lý CRUD + tree operations (closure table)
ServerHooksRegistry hook chạy khi schema events xảy ra (insert, remove, click)
SchemaCacheCache layer — invalidate khi schema thay đổi

Dependencies

PackageVai trò
@digiforce-nc/databaseDatabase ORM (peer)
@digiforce-nc/serverServer framework (peer)
@digiforce-nc/cacheCache schema (peer)
@digiforce-nc/plugin-error-handlerXử lý lỗi schema validation

Mục lục chi tiết