@nocobase/plugin-ui-schema-storage 2.0.0-alpha.5 → 2.0.0-alpha.50

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.
@@ -8,14 +8,14 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "2.0.0-alpha.5",
12
- "@nocobase/database": "2.0.0-alpha.5",
13
- "@nocobase/cache": "2.0.0-alpha.5",
14
- "@nocobase/utils": "2.0.0-alpha.5",
11
+ "@nocobase/client": "2.0.0-alpha.50",
12
+ "@nocobase/database": "2.0.0-alpha.50",
13
+ "@nocobase/cache": "2.0.0-alpha.50",
14
+ "@nocobase/utils": "2.0.0-alpha.50",
15
15
  "lodash": "4.17.21",
16
- "@nocobase/plugin-localization": "2.0.0-alpha.5",
17
- "@nocobase/server": "2.0.0-alpha.5",
18
- "@nocobase/actions": "2.0.0-alpha.5",
19
- "@nocobase/resourcer": "2.0.0-alpha.5",
16
+ "@nocobase/plugin-localization": "2.0.0-alpha.50",
17
+ "@nocobase/server": "2.0.0-alpha.50",
18
+ "@nocobase/actions": "2.0.0-alpha.50",
19
+ "@nocobase/resourcer": "2.0.0-alpha.50",
20
20
  "@formily/json-schema": "2.3.7"
21
21
  };
@@ -0,0 +1 @@
1
+ {}
@@ -28,7 +28,6 @@ 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;
32
31
  export declare class UiSchemaRepository extends Repository {
33
32
  cache: Cache;
34
33
  get uiSchemasTableName(): any;
@@ -93,7 +92,6 @@ export declare class UiSchemaRepository extends Repository {
93
92
  protected insertAfterEnd(targetUid: string, schema: any, options?: InsertAdjacentOptions): Promise<any>;
94
93
  protected insertNodes(nodes: SchemaNode[], options?: Transactionable): Promise<any[]>;
95
94
  private doGetProperties;
96
- findNodesById(uid: string, options?: GetJsonSchemaOptions): Promise<unknown[]>;
97
95
  private doGetJsonSchema;
98
96
  private ignoreSchemaProperties;
99
97
  private breakOnMatched;
@@ -101,16 +99,5 @@ export declare class UiSchemaRepository extends Repository {
101
99
  private regenerateUid;
102
100
  private insertSchemaRecord;
103
101
  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>;
115
102
  }
116
103
  export default UiSchemaRepository;
@@ -45,8 +45,7 @@ var __decorateClass = (decorators, target, key, kind) => {
45
45
  var repository_exports = {};
46
46
  __export(repository_exports, {
47
47
  UiSchemaRepository: () => UiSchemaRepository,
48
- default: () => repository_default,
49
- transaction: () => transaction
48
+ default: () => repository_default
50
49
  });
51
50
  module.exports = __toCommonJS(repository_exports);
52
51
  var import_database = require("@nocobase/database");
@@ -218,9 +217,6 @@ const _UiSchemaRepository = class _UiSchemaRepository extends import_database.Re
218
217
  return schema;
219
218
  };
220
219
  const buildTree = (rootNode) => {
221
- if (!rootNode) {
222
- return null;
223
- }
224
220
  const children = nodes.filter((node) => node.parent == rootNode["x-uid"]);
225
221
  if (children.length > 0) {
226
222
  const childrenGroupByType = import_lodash.default.groupBy(children, "type");
@@ -883,7 +879,7 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
883
879
  const schema = this.nodesToSchema(nodes[0], uid2);
884
880
  return import_lodash.default.pick(schema, ["type", "properties"]);
885
881
  }
886
- async findNodesById(uid2, options) {
882
+ async doGetJsonSchema(uid2, options) {
887
883
  const db = this.database;
888
884
  const treeTable = this.uiSchemaTreePathTableName;
889
885
  const rawSql = `
@@ -903,13 +899,9 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
903
899
  transaction: options == null ? void 0 : options.transaction
904
900
  });
905
901
  if (nodes[0].length == 0) {
906
- return [];
902
+ return {};
907
903
  }
908
- return nodes[0];
909
- }
910
- async doGetJsonSchema(uid2, options) {
911
- const nodes = await this.findNodesById(uid2, options);
912
- return this.nodesToSchema(nodes, uid2);
904
+ return this.nodesToSchema(nodes[0], uid2);
913
905
  }
914
906
  ignoreSchemaProperties(schemaProperties) {
915
907
  return import_lodash.default.omit(schemaProperties, nodeKeys);
@@ -977,175 +969,6 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
977
969
  delete schema["childOptions"];
978
970
  return { uid: uid2, name, async, childOptions };
979
971
  }
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
- }
1149
972
  };
1150
973
  __decorateClass([
1151
974
  transaction()
@@ -1195,19 +1018,9 @@ __decorateClass([
1195
1018
  __decorateClass([
1196
1019
  transaction()
1197
1020
  ], _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);
1207
1021
  let UiSchemaRepository = _UiSchemaRepository;
1208
1022
  var repository_default = UiSchemaRepository;
1209
1023
  // Annotate the CommonJS export names for ESM import in node:
1210
1024
  0 && (module.exports = {
1211
- UiSchemaRepository,
1212
- transaction
1025
+ UiSchemaRepository
1213
1026
  });
@@ -130,7 +130,7 @@ class PluginUISchemaStorageServer extends import_server.Plugin {
130
130
  transaction
131
131
  });
132
132
  });
133
- this.app.resourceManager.define({
133
+ this.app.resourcer.define({
134
134
  name: "uiSchemas",
135
135
  actions: import_ui_schema_action.uiSchemaActions
136
136
  });
package/package.json CHANGED
@@ -2,12 +2,15 @@
2
2
  "name": "@nocobase/plugin-ui-schema-storage",
3
3
  "displayName": "UI schema storage",
4
4
  "displayName.zh-CN": "UI schema 存储服务",
5
+ "displayName.ru-RU": "Хранилище UI схем",
5
6
  "description": "Provides centralized UI schema storage service.",
6
7
  "description.zh-CN": "提供中心化的 UI schema 存储服务。",
7
- "version": "2.0.0-alpha.5",
8
+ "description.ru-RU": "Предоставляет централизованный сервис хранения UI схем.",
9
+ "version": "2.0.0-alpha.50",
8
10
  "license": "AGPL-3.0",
9
11
  "main": "./dist/server/index.js",
10
12
  "homepage": "https://docs.nocobase.com/handbook/ui-schema-storage",
13
+ "homepage.ru-RU": "https://docs-ru.nocobase.com/handbook/ui-schema-storage",
11
14
  "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/ui-schema-storage",
12
15
  "devDependencies": {
13
16
  "@formily/json-schema": "2.x"
@@ -23,7 +26,7 @@
23
26
  "@nocobase/test": "2.x",
24
27
  "@nocobase/utils": "2.x"
25
28
  },
26
- "gitHead": "943e035bbec27f9ecfe8ce8857955945f20976f3",
29
+ "gitHead": "a6eb64abf3632e116ad0b295a7f410270a1059d1",
27
30
  "keywords": [
28
31
  "System & security"
29
32
  ]