@nocobase/plugin-ui-schema-storage 1.9.0-beta.9 → 2.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/externalVersion.js +9 -9
- package/dist/server/repository.d.ts +13 -0
- package/dist/server/repository.js +192 -5
- package/dist/server/server.js +2 -3
- package/package.json +11 -11
package/dist/externalVersion.js
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "
|
|
12
|
-
"@nocobase/database": "
|
|
13
|
-
"@nocobase/cache": "
|
|
14
|
-
"@nocobase/utils": "
|
|
11
|
+
"@nocobase/client": "2.0.0-alpha.11",
|
|
12
|
+
"@nocobase/database": "2.0.0-alpha.11",
|
|
13
|
+
"@nocobase/cache": "2.0.0-alpha.11",
|
|
14
|
+
"@nocobase/utils": "2.0.0-alpha.11",
|
|
15
15
|
"lodash": "4.17.21",
|
|
16
|
-
"@nocobase/
|
|
17
|
-
"@nocobase/
|
|
18
|
-
"@nocobase/actions": "
|
|
19
|
-
"@nocobase/resourcer": "
|
|
20
|
-
"@formily/json-schema": "2.3.
|
|
16
|
+
"@nocobase/plugin-localization": "2.0.0-alpha.11",
|
|
17
|
+
"@nocobase/server": "2.0.0-alpha.11",
|
|
18
|
+
"@nocobase/actions": "2.0.0-alpha.11",
|
|
19
|
+
"@nocobase/resourcer": "2.0.0-alpha.11",
|
|
20
|
+
"@formily/json-schema": "2.3.7"
|
|
21
21
|
};
|
|
@@ -28,6 +28,7 @@ export interface removeParentOptions extends Transactionable {
|
|
|
28
28
|
interface InsertAdjacentOptions extends removeParentOptions {
|
|
29
29
|
wrap?: any;
|
|
30
30
|
}
|
|
31
|
+
export declare function transaction(transactionAbleArgPosition?: number): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
31
32
|
export declare class UiSchemaRepository extends Repository {
|
|
32
33
|
cache: Cache;
|
|
33
34
|
get uiSchemasTableName(): any;
|
|
@@ -92,6 +93,7 @@ export declare class UiSchemaRepository extends Repository {
|
|
|
92
93
|
protected insertAfterEnd(targetUid: string, schema: any, options?: InsertAdjacentOptions): Promise<any>;
|
|
93
94
|
protected insertNodes(nodes: SchemaNode[], options?: Transactionable): Promise<any[]>;
|
|
94
95
|
private doGetProperties;
|
|
96
|
+
findNodesById(uid: string, options?: GetJsonSchemaOptions): Promise<unknown[]>;
|
|
95
97
|
private doGetJsonSchema;
|
|
96
98
|
private ignoreSchemaProperties;
|
|
97
99
|
private breakOnMatched;
|
|
@@ -99,5 +101,16 @@ export declare class UiSchemaRepository extends Repository {
|
|
|
99
101
|
private regenerateUid;
|
|
100
102
|
private insertSchemaRecord;
|
|
101
103
|
private prepareSingleNodeForInsert;
|
|
104
|
+
static modelToSingleNodes(model: any, parentChildOptions?: any): SchemaNode[];
|
|
105
|
+
static nodeToModel(node: any): any;
|
|
106
|
+
static nodesToModel(nodes: any[], rootUid: string): any;
|
|
107
|
+
insertModel(model: any, options?: Transactionable): Promise<any>;
|
|
108
|
+
updateSingleNode(node: SchemaNode, options?: Transactionable): Promise<boolean>;
|
|
109
|
+
upsertModel(model: any, options?: Transactionable): Promise<string>;
|
|
110
|
+
findModelById(uid: string, options?: GetJsonSchemaOptions): Promise<any>;
|
|
111
|
+
findModelByParentId(parentUid: string, options?: GetJsonSchemaOptions & {
|
|
112
|
+
subKey?: string;
|
|
113
|
+
}): Promise<any>;
|
|
114
|
+
move(options: any): Promise<any>;
|
|
102
115
|
}
|
|
103
116
|
export default UiSchemaRepository;
|
|
@@ -45,7 +45,8 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
45
45
|
var repository_exports = {};
|
|
46
46
|
__export(repository_exports, {
|
|
47
47
|
UiSchemaRepository: () => UiSchemaRepository,
|
|
48
|
-
default: () => repository_default
|
|
48
|
+
default: () => repository_default,
|
|
49
|
+
transaction: () => transaction
|
|
49
50
|
});
|
|
50
51
|
module.exports = __toCommonJS(repository_exports);
|
|
51
52
|
var import_database = require("@nocobase/database");
|
|
@@ -217,6 +218,9 @@ const _UiSchemaRepository = class _UiSchemaRepository extends import_database.Re
|
|
|
217
218
|
return schema;
|
|
218
219
|
};
|
|
219
220
|
const buildTree = (rootNode) => {
|
|
221
|
+
if (!rootNode) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
220
224
|
const children = nodes.filter((node) => node.parent == rootNode["x-uid"]);
|
|
221
225
|
if (children.length > 0) {
|
|
222
226
|
const childrenGroupByType = import_lodash.default.groupBy(children, "type");
|
|
@@ -879,7 +883,7 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
|
|
|
879
883
|
const schema = this.nodesToSchema(nodes[0], uid2);
|
|
880
884
|
return import_lodash.default.pick(schema, ["type", "properties"]);
|
|
881
885
|
}
|
|
882
|
-
async
|
|
886
|
+
async findNodesById(uid2, options) {
|
|
883
887
|
const db = this.database;
|
|
884
888
|
const treeTable = this.uiSchemaTreePathTableName;
|
|
885
889
|
const rawSql = `
|
|
@@ -899,9 +903,13 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
|
|
|
899
903
|
transaction: options == null ? void 0 : options.transaction
|
|
900
904
|
});
|
|
901
905
|
if (nodes[0].length == 0) {
|
|
902
|
-
return
|
|
906
|
+
return [];
|
|
903
907
|
}
|
|
904
|
-
return
|
|
908
|
+
return nodes[0];
|
|
909
|
+
}
|
|
910
|
+
async doGetJsonSchema(uid2, options) {
|
|
911
|
+
const nodes = await this.findNodesById(uid2, options);
|
|
912
|
+
return this.nodesToSchema(nodes, uid2);
|
|
905
913
|
}
|
|
906
914
|
ignoreSchemaProperties(schemaProperties) {
|
|
907
915
|
return import_lodash.default.omit(schemaProperties, nodeKeys);
|
|
@@ -969,6 +977,175 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
|
|
|
969
977
|
delete schema["childOptions"];
|
|
970
978
|
return { uid: uid2, name, async, childOptions };
|
|
971
979
|
}
|
|
980
|
+
static modelToSingleNodes(model, parentChildOptions = null) {
|
|
981
|
+
const { uid: oldUid, async, subModels, ...rest } = import_lodash.default.cloneDeep(model);
|
|
982
|
+
const currentUid = oldUid || (0, import_utils.uid)();
|
|
983
|
+
const node = {
|
|
984
|
+
"x-uid": currentUid,
|
|
985
|
+
"x-async": async || false,
|
|
986
|
+
name: currentUid,
|
|
987
|
+
...rest
|
|
988
|
+
};
|
|
989
|
+
if (parentChildOptions) {
|
|
990
|
+
node.childOptions = parentChildOptions;
|
|
991
|
+
}
|
|
992
|
+
const nodes = [node];
|
|
993
|
+
if (Object.keys(subModels || {}).length > 0) {
|
|
994
|
+
for (const [subKey, subItems] of Object.entries(subModels)) {
|
|
995
|
+
const items = import_lodash.default.castArray(subItems);
|
|
996
|
+
let sort = 0;
|
|
997
|
+
for (const item of items) {
|
|
998
|
+
item.subKey = subKey;
|
|
999
|
+
item.subType = Array.isArray(subItems) ? "array" : "object";
|
|
1000
|
+
const childOptions = {
|
|
1001
|
+
parentUid: currentUid,
|
|
1002
|
+
parentPath: [currentUid, ...(parentChildOptions == null ? void 0 : parentChildOptions.parentPath) || []].filter(Boolean),
|
|
1003
|
+
type: subKey,
|
|
1004
|
+
// type: 'properties',
|
|
1005
|
+
sort: ++sort
|
|
1006
|
+
};
|
|
1007
|
+
const children = this.modelToSingleNodes(item, childOptions);
|
|
1008
|
+
nodes.push(...children);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
return nodes;
|
|
1013
|
+
}
|
|
1014
|
+
static nodeToModel(node) {
|
|
1015
|
+
const { "x-uid": uid2, name, schema } = node;
|
|
1016
|
+
const model = {
|
|
1017
|
+
uid: uid2,
|
|
1018
|
+
...schema
|
|
1019
|
+
};
|
|
1020
|
+
return model;
|
|
1021
|
+
}
|
|
1022
|
+
static nodesToModel(nodes, rootUid) {
|
|
1023
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
1024
|
+
for (const node of nodes) {
|
|
1025
|
+
nodeMap.set(node["x-uid"], node);
|
|
1026
|
+
}
|
|
1027
|
+
const rootNode = nodeMap.get(rootUid);
|
|
1028
|
+
if (!rootNode) return null;
|
|
1029
|
+
const children = nodes.filter((n) => n.parent === rootUid);
|
|
1030
|
+
const subModels = {};
|
|
1031
|
+
for (const child of children) {
|
|
1032
|
+
const { subKey, subType } = child.schema;
|
|
1033
|
+
if (!subKey) continue;
|
|
1034
|
+
const model = _UiSchemaRepository.nodesToModel(nodes, child["x-uid"]) || {
|
|
1035
|
+
uid: child["x-uid"],
|
|
1036
|
+
...child.schema,
|
|
1037
|
+
sortIndex: child.sort
|
|
1038
|
+
};
|
|
1039
|
+
model.sortIndex = child.sort;
|
|
1040
|
+
if (subType === "array") {
|
|
1041
|
+
if (!subModels[subKey]) subModels[subKey] = [];
|
|
1042
|
+
subModels[subKey].push(model);
|
|
1043
|
+
} else {
|
|
1044
|
+
subModels[subKey] = model;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
for (const key in subModels) {
|
|
1048
|
+
if (Array.isArray(subModels[key])) {
|
|
1049
|
+
subModels[key].sort((a, b) => (a.sortIndex ?? 0) - (b.sortIndex ?? 0));
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
const filteredSubModels = {};
|
|
1053
|
+
for (const key in subModels) {
|
|
1054
|
+
const value = subModels[key];
|
|
1055
|
+
if (Array.isArray(value) && value.length === 0) continue;
|
|
1056
|
+
if (!Array.isArray(value) && typeof value === "object" && value !== null && Object.keys(value).length === 0)
|
|
1057
|
+
continue;
|
|
1058
|
+
filteredSubModels[key] = value;
|
|
1059
|
+
}
|
|
1060
|
+
return {
|
|
1061
|
+
uid: rootNode["x-uid"],
|
|
1062
|
+
...rootNode.schema,
|
|
1063
|
+
...Object.keys(filteredSubModels).length > 0 ? { subModels: filteredSubModels } : {}
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
async insertModel(model, options) {
|
|
1067
|
+
const nodes = _UiSchemaRepository.modelToSingleNodes(model);
|
|
1068
|
+
const rootUid = nodes[0]["x-uid"];
|
|
1069
|
+
await this.insertNodes(nodes, options);
|
|
1070
|
+
return await this.findModelById(rootUid, options);
|
|
1071
|
+
}
|
|
1072
|
+
async updateSingleNode(node, options) {
|
|
1073
|
+
const instance = await this.model.findByPk(node["x-uid"], {
|
|
1074
|
+
transaction: options == null ? void 0 : options.transaction
|
|
1075
|
+
});
|
|
1076
|
+
if (instance) {
|
|
1077
|
+
await instance.update(
|
|
1078
|
+
{
|
|
1079
|
+
schema: {
|
|
1080
|
+
...instance.get("schema"),
|
|
1081
|
+
...import_lodash.default.omit(node, ["x-async", "name", "x-uid", "childOptions"])
|
|
1082
|
+
}
|
|
1083
|
+
},
|
|
1084
|
+
{
|
|
1085
|
+
hooks: false,
|
|
1086
|
+
transaction: options == null ? void 0 : options.transaction
|
|
1087
|
+
}
|
|
1088
|
+
);
|
|
1089
|
+
return true;
|
|
1090
|
+
}
|
|
1091
|
+
return false;
|
|
1092
|
+
}
|
|
1093
|
+
async upsertModel(model, options) {
|
|
1094
|
+
let childOptions = null;
|
|
1095
|
+
if (model.parentId) {
|
|
1096
|
+
childOptions = {
|
|
1097
|
+
parentUid: model.parentId,
|
|
1098
|
+
type: model.subKey,
|
|
1099
|
+
// type: 'properties',
|
|
1100
|
+
position: "last"
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
const nodes = _UiSchemaRepository.modelToSingleNodes(model, childOptions);
|
|
1104
|
+
const rootUid = nodes[0]["x-uid"];
|
|
1105
|
+
for (const node of nodes) {
|
|
1106
|
+
const exists = await this.updateSingleNode(node, options);
|
|
1107
|
+
if (!exists) {
|
|
1108
|
+
await this.insertSingleNode(node, options);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
return rootUid;
|
|
1112
|
+
}
|
|
1113
|
+
async findModelById(uid2, options) {
|
|
1114
|
+
const nodes = await this.findNodesById(uid2, options);
|
|
1115
|
+
return _UiSchemaRepository.nodesToModel(nodes, uid2);
|
|
1116
|
+
}
|
|
1117
|
+
async findModelByParentId(parentUid, options) {
|
|
1118
|
+
const r = this.database.getRepository("uiSchemaTreePath");
|
|
1119
|
+
const treePaths = await r.model.findAll({
|
|
1120
|
+
where: {
|
|
1121
|
+
ancestor: parentUid,
|
|
1122
|
+
depth: 1
|
|
1123
|
+
},
|
|
1124
|
+
transaction: options == null ? void 0 : options.transaction
|
|
1125
|
+
});
|
|
1126
|
+
const ancestors = treePaths.map((treePath2) => treePath2["descendant"]);
|
|
1127
|
+
const where = {
|
|
1128
|
+
ancestor: ancestors,
|
|
1129
|
+
depth: 0
|
|
1130
|
+
};
|
|
1131
|
+
if (options == null ? void 0 : options.subKey) {
|
|
1132
|
+
where["type"] = options.subKey;
|
|
1133
|
+
}
|
|
1134
|
+
const treePath = await r.model.findOne({
|
|
1135
|
+
where,
|
|
1136
|
+
transaction: options == null ? void 0 : options.transaction
|
|
1137
|
+
});
|
|
1138
|
+
if (treePath == null ? void 0 : treePath["descendant"]) {
|
|
1139
|
+
return this.findModelById(treePath["descendant"], options);
|
|
1140
|
+
}
|
|
1141
|
+
return null;
|
|
1142
|
+
}
|
|
1143
|
+
async move(options) {
|
|
1144
|
+
const { sourceId, targetId, position } = options;
|
|
1145
|
+
return await this.insertAdjacent(position === "after" ? "afterEnd" : "beforeBegin", targetId, {
|
|
1146
|
+
["x-uid"]: sourceId
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
972
1149
|
};
|
|
973
1150
|
__decorateClass([
|
|
974
1151
|
transaction()
|
|
@@ -1018,9 +1195,19 @@ __decorateClass([
|
|
|
1018
1195
|
__decorateClass([
|
|
1019
1196
|
transaction()
|
|
1020
1197
|
], _UiSchemaRepository.prototype, "insertNodes", 1);
|
|
1198
|
+
__decorateClass([
|
|
1199
|
+
transaction()
|
|
1200
|
+
], _UiSchemaRepository.prototype, "insertModel", 1);
|
|
1201
|
+
__decorateClass([
|
|
1202
|
+
transaction()
|
|
1203
|
+
], _UiSchemaRepository.prototype, "updateSingleNode", 1);
|
|
1204
|
+
__decorateClass([
|
|
1205
|
+
transaction()
|
|
1206
|
+
], _UiSchemaRepository.prototype, "upsertModel", 1);
|
|
1021
1207
|
let UiSchemaRepository = _UiSchemaRepository;
|
|
1022
1208
|
var repository_default = UiSchemaRepository;
|
|
1023
1209
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1024
1210
|
0 && (module.exports = {
|
|
1025
|
-
UiSchemaRepository
|
|
1211
|
+
UiSchemaRepository,
|
|
1212
|
+
transaction
|
|
1026
1213
|
});
|
package/dist/server/server.js
CHANGED
|
@@ -44,7 +44,6 @@ module.exports = __toCommonJS(server_exports);
|
|
|
44
44
|
var import_database = require("@nocobase/database");
|
|
45
45
|
var import_server = require("@nocobase/server");
|
|
46
46
|
var import_utils = require("@nocobase/utils");
|
|
47
|
-
var import_utils2 = require("@nocobase/utils");
|
|
48
47
|
var import_path = __toESM(require("path"));
|
|
49
48
|
var import_ui_schema_action = require("./actions/ui-schema-action");
|
|
50
49
|
var import_model = require("./model");
|
|
@@ -97,7 +96,7 @@ class PluginUISchemaStorageServer extends import_server.Plugin {
|
|
|
97
96
|
});
|
|
98
97
|
db.on("uiSchemas.beforeCreate", function setUid(model) {
|
|
99
98
|
if (!model.get("name")) {
|
|
100
|
-
model.set("name", (0,
|
|
99
|
+
model.set("name", (0, import_utils.uid)());
|
|
101
100
|
}
|
|
102
101
|
});
|
|
103
102
|
db.on("uiSchemas.afterSave", async function setUid(model, options) {
|
|
@@ -131,7 +130,7 @@ class PluginUISchemaStorageServer extends import_server.Plugin {
|
|
|
131
130
|
transaction
|
|
132
131
|
});
|
|
133
132
|
});
|
|
134
|
-
this.app.
|
|
133
|
+
this.app.resourceManager.define({
|
|
135
134
|
name: "uiSchemas",
|
|
136
135
|
actions: import_ui_schema_action.uiSchemaActions
|
|
137
136
|
});
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName.zh-CN": "UI schema 存储服务",
|
|
5
5
|
"description": "Provides centralized UI schema storage service.",
|
|
6
6
|
"description.zh-CN": "提供中心化的 UI schema 存储服务。",
|
|
7
|
-
"version": "
|
|
7
|
+
"version": "2.0.0-alpha.11",
|
|
8
8
|
"license": "AGPL-3.0",
|
|
9
9
|
"main": "./dist/server/index.js",
|
|
10
10
|
"homepage": "https://docs.nocobase.com/handbook/ui-schema-storage",
|
|
@@ -13,17 +13,17 @@
|
|
|
13
13
|
"@formily/json-schema": "2.x"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"@nocobase/actions": "
|
|
17
|
-
"@nocobase/cache": "
|
|
18
|
-
"@nocobase/client": "
|
|
19
|
-
"@nocobase/database": "
|
|
20
|
-
"@nocobase/plugin-error-handler": "
|
|
21
|
-
"@nocobase/resourcer": "
|
|
22
|
-
"@nocobase/server": "
|
|
23
|
-
"@nocobase/test": "
|
|
24
|
-
"@nocobase/utils": "
|
|
16
|
+
"@nocobase/actions": "2.x",
|
|
17
|
+
"@nocobase/cache": "2.x",
|
|
18
|
+
"@nocobase/client": "2.x",
|
|
19
|
+
"@nocobase/database": "2.x",
|
|
20
|
+
"@nocobase/plugin-error-handler": "2.x",
|
|
21
|
+
"@nocobase/resourcer": "2.x",
|
|
22
|
+
"@nocobase/server": "2.x",
|
|
23
|
+
"@nocobase/test": "2.x",
|
|
24
|
+
"@nocobase/utils": "2.x"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "172b05411f66f7024d5294caf2852533569c3796",
|
|
27
27
|
"keywords": [
|
|
28
28
|
"System & security"
|
|
29
29
|
]
|