@nocobase/plugin-ui-schema-storage 0.7.4-alpha.7 → 0.7.6-alpha.1

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.
@@ -6,6 +6,7 @@ export declare const uiSchemaActions: {
6
6
  insertNewSchema: (ctx: any, next: any) => Promise<void>;
7
7
  remove: (ctx: any, next: any) => Promise<void>;
8
8
  patch: (ctx: any, next: any) => Promise<void>;
9
+ batchPatch: (ctx: any, next: any) => Promise<void>;
9
10
  clearAncestor: (ctx: any, next: any) => Promise<void>;
10
11
  insertAdjacent(ctx: Context, next: any): Promise<void>;
11
12
  insertBeforeBegin: (ctx: Context, next: any) => Promise<void>;
@@ -28,7 +28,9 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
28
28
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
29
29
 
30
30
  const getRepositoryFromCtx = ctx => {
31
- return ctx.db.getCollection('uiSchemas').repository;
31
+ const repo = ctx.db.getCollection('uiSchemas').repository;
32
+ repo.setCache(ctx.cache);
33
+ return repo;
32
34
  };
33
35
 
34
36
  const callRepositoryMethod = (method, paramsKey, optionsBuilder) => {
@@ -64,15 +66,20 @@ function parseInsertAdjacentValues(values) {
64
66
 
65
67
  const uiSchemaActions = {
66
68
  getJsonSchema: callRepositoryMethod('getJsonSchema', 'resourceIndex', params => {
69
+ const includeAsyncNode = params === null || params === void 0 ? void 0 : params.includeAsyncNode;
67
70
  return {
68
- includeAsyncNode: params === null || params === void 0 ? void 0 : params.includeAsyncNode
71
+ readFromCache: !includeAsyncNode,
72
+ includeAsyncNode
69
73
  };
70
74
  }),
71
- getProperties: callRepositoryMethod('getProperties', 'resourceIndex'),
75
+ getProperties: callRepositoryMethod('getProperties', 'resourceIndex', () => ({
76
+ readFromCache: true
77
+ })),
72
78
  insert: callRepositoryMethod('insert', 'values'),
73
79
  insertNewSchema: callRepositoryMethod('insertNewSchema', 'values'),
74
80
  remove: callRepositoryMethod('remove', 'resourceIndex'),
75
81
  patch: callRepositoryMethod('patch', 'values'),
82
+ batchPatch: callRepositoryMethod('batchPatch', 'values'),
76
83
  clearAncestor: callRepositoryMethod('clearAncestor', 'resourceIndex'),
77
84
 
78
85
  insertAdjacent(ctx, next) {
@@ -118,7 +125,7 @@ const uiSchemaActions = {
118
125
  }),
119
126
  transaction
120
127
  });
121
- yield db.getRepository('uiSchemas').clearAncestor(filterByTk, {
128
+ yield getRepositoryFromCtx(ctx).clearAncestor(filterByTk, {
122
129
  transaction
123
130
  });
124
131
  ctx.body = {
@@ -1,8 +1,14 @@
1
1
  import { Repository, Transactionable } from '@nocobase/database';
2
+ import { Cache } from '@nocobase/cache';
2
3
  import { Transaction } from 'sequelize';
3
4
  import { ChildOptions, SchemaNode } from './dao/ui_schema_node_dao';
4
- interface GetJsonSchemaOptions {
5
+ export interface GetJsonSchemaOptions {
5
6
  includeAsyncNode?: boolean;
7
+ readFromCache?: boolean;
8
+ transaction?: Transaction;
9
+ }
10
+ export interface GetPropertiesOptions {
11
+ readFromCache?: boolean;
6
12
  transaction?: Transaction;
7
13
  }
8
14
  declare type BreakRemoveOnType = {
@@ -16,15 +22,26 @@ interface InsertAdjacentOptions extends removeParentOptions {
16
22
  wrap?: any;
17
23
  }
18
24
  export declare class UiSchemaRepository extends Repository {
25
+ cache: Cache;
26
+ setCache(cache: Cache): void;
27
+ /**
28
+ * clear cache with xUid which in uiSchemaTreePath's Path
29
+ * @param {string} xUid
30
+ * @param {Transaction} transaction
31
+ * @returns {Promise<void>}
32
+ */
33
+ clearXUidPathCache(xUid: string, transaction: Transaction): Promise<void>;
19
34
  tableNameAdapter(tableName: any): any;
20
35
  get uiSchemasTableName(): any;
21
36
  get uiSchemaTreePathTableName(): any;
22
37
  sqlAdapter(sql: string): string;
23
38
  static schemaToSingleNodes(schema: any, carry?: SchemaNode[], childOptions?: ChildOptions): SchemaNode[];
24
- getProperties(uid: string, options?: Transactionable): Promise<Partial<{
39
+ getProperties(uid: string, options?: GetPropertiesOptions): Promise<Partial<{
25
40
  "x-uid": any;
26
41
  "x-async": boolean;
27
42
  }>>;
43
+ private doGetProperties;
44
+ private doGetJsonSchema;
28
45
  getJsonSchema(uid: string, options?: GetJsonSchemaOptions): Promise<any>;
29
46
  private ignoreSchemaProperties;
30
47
  nodesToSchema(nodes: any, rootUid: any): {
@@ -33,10 +50,11 @@ export declare class UiSchemaRepository extends Repository {
33
50
  };
34
51
  clearAncestor(uid: string, options?: Transactionable): Promise<void>;
35
52
  patch(newSchema: any, options?: any): Promise<void>;
36
- updateNode(uid: string, schema: any, transaction?: Transaction): Promise<void>;
53
+ batchPatch(schemas: any[], options?: any): Promise<void>;
54
+ protected updateNode(uid: string, schema: any, transaction?: Transaction): Promise<void>;
37
55
  protected childrenCount(uid: any, transaction: any): Promise<number>;
38
56
  protected isLeafNode(uid: any, transaction: any): Promise<boolean>;
39
- findParentUid(uid: any, transaction?: any): Promise<string>;
57
+ protected findParentUid(uid: any, transaction?: any): Promise<string>;
40
58
  protected findNodeSchemaWithParent(uid: any, transaction: any): Promise<{
41
59
  parentUid: string;
42
60
  schema: import("@nocobase/database").Model<any, any>;
@@ -52,15 +70,15 @@ export declare class UiSchemaRepository extends Repository {
52
70
  breakRemoveOn?: BreakRemoveOnType;
53
71
  }): Promise<void>;
54
72
  remove(uid: string, options?: Transactionable & removeParentOptions): Promise<void>;
55
- insertBeside(targetUid: string, schema: any, side: 'before' | 'after', options?: InsertAdjacentOptions): Promise<any>;
56
- insertInner(targetUid: string, schema: any, position: 'first' | 'last', options?: InsertAdjacentOptions): Promise<any>;
73
+ protected insertBeside(targetUid: string, schema: any, side: 'before' | 'after', options?: InsertAdjacentOptions): Promise<any>;
74
+ protected insertInner(targetUid: string, schema: any, position: 'first' | 'last', options?: InsertAdjacentOptions): Promise<any>;
57
75
  private schemaExists;
58
76
  insertAdjacent(position: 'beforeBegin' | 'afterBegin' | 'beforeEnd' | 'afterEnd', target: string, schema: any, options?: InsertAdjacentOptions): Promise<any>;
59
77
  protected insertAfterBegin(targetUid: string, schema: any, options?: InsertAdjacentOptions): Promise<any>;
60
78
  protected insertBeforeEnd(targetUid: string, schema: any, options?: InsertAdjacentOptions): Promise<any>;
61
79
  protected insertBeforeBegin(targetUid: string, schema: any, options?: InsertAdjacentOptions): Promise<any>;
62
80
  protected insertAfterEnd(targetUid: string, schema: any, options?: InsertAdjacentOptions): Promise<any>;
63
- insertNodes(nodes: SchemaNode[], options?: Transactionable): Promise<any[]>;
81
+ protected insertNodes(nodes: SchemaNode[], options?: Transactionable): Promise<any[]>;
64
82
  insert(schema: any, options?: Transactionable): Promise<any>;
65
83
  insertNewSchema(schema: any, options?: Transactionable & {
66
84
  returnNode?: boolean;
package/lib/repository.js CHANGED
@@ -110,6 +110,56 @@ function transaction(transactionAbleArgPosition) {
110
110
  }
111
111
 
112
112
  class UiSchemaRepository extends _database().Repository {
113
+ constructor(...args) {
114
+ super(...args);
115
+ this.cache = void 0;
116
+ }
117
+
118
+ // if you need to handle cache in repo method, so you must set cache first
119
+ setCache(cache) {
120
+ this.cache = cache;
121
+ }
122
+ /**
123
+ * clear cache with xUid which in uiSchemaTreePath's Path
124
+ * @param {string} xUid
125
+ * @param {Transaction} transaction
126
+ * @returns {Promise<void>}
127
+ */
128
+
129
+
130
+ clearXUidPathCache(xUid, transaction) {
131
+ var _this = this;
132
+
133
+ return _asyncToGenerator(function* () {
134
+ if (!_this.cache || !xUid) {
135
+ return;
136
+ } // find all xUid node's parent nodes
137
+
138
+
139
+ const uiSchemaNodes = yield _this.database.getRepository('uiSchemaTreePath').find({
140
+ filter: {
141
+ descendant: xUid
142
+ },
143
+ transaction: transaction
144
+ });
145
+
146
+ var _iterator = _createForOfIteratorHelper(uiSchemaNodes),
147
+ _step;
148
+
149
+ try {
150
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
151
+ const uiSchemaNode = _step.value;
152
+ yield _this.cache.del(`p_${uiSchemaNode['ancestor']}`);
153
+ yield _this.cache.del(`s_${uiSchemaNode['ancestor']}`);
154
+ }
155
+ } catch (err) {
156
+ _iterator.e(err);
157
+ } finally {
158
+ _iterator.f();
159
+ }
160
+ })();
161
+ }
162
+
113
163
  tableNameAdapter(tableName) {
114
164
  if (this.database.sequelize.getDialect() === 'postgres') {
115
165
  return `"${tableName}"`;
@@ -154,12 +204,12 @@ class UiSchemaRepository extends _database().Repository {
154
204
 
155
205
  carry.push(node);
156
206
 
157
- var _iterator = _createForOfIteratorHelper(nodeKeys),
158
- _step;
207
+ var _iterator2 = _createForOfIteratorHelper(nodeKeys),
208
+ _step2;
159
209
 
160
210
  try {
161
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
162
- const nodeKey = _step.value;
211
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
212
+ const nodeKey = _step2.value;
163
213
 
164
214
  const nodeProperty = _lodash().default.get(node, nodeKey);
165
215
 
@@ -172,37 +222,37 @@ class UiSchemaRepository extends _database().Repository {
172
222
  if (nodeKey === 'items' && nodeProperty) {
173
223
  const handleItems = _lodash().default.isArray(nodeProperty) ? nodeProperty : [nodeProperty];
174
224
 
175
- var _iterator2 = _createForOfIteratorHelper(handleItems.entries()),
176
- _step2;
225
+ var _iterator3 = _createForOfIteratorHelper(handleItems.entries()),
226
+ _step3;
177
227
 
178
228
  try {
179
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
180
- const _step2$value = _slicedToArray(_step2.value, 2),
181
- i = _step2$value[0],
182
- item = _step2$value[1];
229
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
230
+ const _step3$value = _slicedToArray(_step3.value, 2),
231
+ i = _step3$value[0],
232
+ item = _step3$value[1];
183
233
 
184
234
  carry = this.schemaToSingleNodes(item, carry, _objectSpread(_objectSpread({}, childNodeChildOptions), {}, {
185
235
  sort: i + 1
186
236
  }));
187
237
  }
188
238
  } catch (err) {
189
- _iterator2.e(err);
239
+ _iterator3.e(err);
190
240
  } finally {
191
- _iterator2.f();
241
+ _iterator3.f();
192
242
  }
193
243
  } else if (_lodash().default.isPlainObject(nodeProperty)) {
194
244
  const subNodeNames = _lodash().default.keys(_lodash().default.get(node, nodeKey));
195
245
 
196
246
  delete node[nodeKey];
197
247
 
198
- var _iterator3 = _createForOfIteratorHelper(subNodeNames.entries()),
199
- _step3;
248
+ var _iterator4 = _createForOfIteratorHelper(subNodeNames.entries()),
249
+ _step4;
200
250
 
201
251
  try {
202
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
203
- const _step3$value = _slicedToArray(_step3.value, 2),
204
- i = _step3$value[0],
205
- subNodeName = _step3$value[1];
252
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
253
+ const _step4$value = _slicedToArray(_step4.value, 2),
254
+ i = _step4$value[0],
255
+ subNodeName = _step4$value[1];
206
256
 
207
257
  const subSchema = _objectSpread({
208
258
  name: subNodeName
@@ -213,37 +263,51 @@ class UiSchemaRepository extends _database().Repository {
213
263
  }));
214
264
  }
215
265
  } catch (err) {
216
- _iterator3.e(err);
266
+ _iterator4.e(err);
217
267
  } finally {
218
- _iterator3.f();
268
+ _iterator4.f();
219
269
  }
220
270
  }
221
271
  }
222
272
  } catch (err) {
223
- _iterator.e(err);
273
+ _iterator2.e(err);
224
274
  } finally {
225
- _iterator.f();
275
+ _iterator2.f();
226
276
  }
227
277
 
228
278
  return carry;
229
279
  }
230
280
 
231
281
  getProperties(uid, options = {}) {
232
- var _this = this;
282
+ var _this2 = this;
283
+
284
+ return _asyncToGenerator(function* () {
285
+ if ((options === null || options === void 0 ? void 0 : options.readFromCache) && _this2.cache) {
286
+ return _this2.cache.wrap(`p_${uid}`, () => {
287
+ return _this2.doGetProperties(uid, options);
288
+ });
289
+ }
290
+
291
+ return _this2.doGetProperties(uid, options);
292
+ })();
293
+ }
294
+
295
+ doGetProperties(uid, options = {}) {
296
+ var _this3 = this;
233
297
 
234
298
  return _asyncToGenerator(function* () {
235
299
  const transaction = options.transaction;
236
- const db = _this.database;
300
+ const db = _this3.database;
237
301
  const rawSql = `
238
302
  SELECT "SchemaTable"."x-uid" as "x-uid", "SchemaTable"."name" as "name", "SchemaTable"."schema" as "schema",
239
303
  TreePath.depth as depth,
240
304
  NodeInfo.type as type, NodeInfo.async as async, ParentPath.ancestor as parent, ParentPath.sort as sort
241
- FROM ${_this.uiSchemaTreePathTableName} as TreePath
242
- LEFT JOIN ${_this.uiSchemasTableName} as "SchemaTable" ON "SchemaTable"."x-uid" = TreePath.descendant
243
- LEFT JOIN ${_this.uiSchemaTreePathTableName} as NodeInfo ON NodeInfo.descendant = "SchemaTable"."x-uid" and NodeInfo.descendant = NodeInfo.ancestor and NodeInfo.depth = 0
244
- LEFT JOIN ${_this.uiSchemaTreePathTableName} as ParentPath ON (ParentPath.descendant = "SchemaTable"."x-uid" AND ParentPath.depth = 1)
305
+ FROM ${_this3.uiSchemaTreePathTableName} as TreePath
306
+ LEFT JOIN ${_this3.uiSchemasTableName} as "SchemaTable" ON "SchemaTable"."x-uid" = TreePath.descendant
307
+ LEFT JOIN ${_this3.uiSchemaTreePathTableName} as NodeInfo ON NodeInfo.descendant = "SchemaTable"."x-uid" and NodeInfo.descendant = NodeInfo.ancestor and NodeInfo.depth = 0
308
+ LEFT JOIN ${_this3.uiSchemaTreePathTableName} as ParentPath ON (ParentPath.descendant = "SchemaTable"."x-uid" AND ParentPath.depth = 1)
245
309
  WHERE TreePath.ancestor = :ancestor AND (NodeInfo.async = false or TreePath.depth = 1)`;
246
- const nodes = yield db.sequelize.query(_this.sqlAdapter(rawSql), {
310
+ const nodes = yield db.sequelize.query(_this3.sqlAdapter(rawSql), {
247
311
  replacements: {
248
312
  ancestor: uid
249
313
  },
@@ -254,29 +318,29 @@ class UiSchemaRepository extends _database().Repository {
254
318
  return {};
255
319
  }
256
320
 
257
- const schema = _this.nodesToSchema(nodes[0], uid);
321
+ const schema = _this3.nodesToSchema(nodes[0], uid);
258
322
 
259
323
  return _lodash().default.pick(schema, ['type', 'properties']);
260
324
  })();
261
325
  }
262
326
 
263
- getJsonSchema(uid, options) {
264
- var _this2 = this;
327
+ doGetJsonSchema(uid, options) {
328
+ var _this4 = this;
265
329
 
266
330
  return _asyncToGenerator(function* () {
267
- const db = _this2.database;
268
- const treeTable = _this2.uiSchemaTreePathTableName;
331
+ const db = _this4.database;
332
+ const treeTable = _this4.uiSchemaTreePathTableName;
269
333
  const rawSql = `
270
334
  SELECT "SchemaTable"."x-uid" as "x-uid", "SchemaTable"."name" as name, "SchemaTable"."schema" as "schema" ,
271
335
  TreePath.depth as depth,
272
336
  NodeInfo.type as type, NodeInfo.async as async, ParentPath.ancestor as parent, ParentPath.sort as sort
273
337
  FROM ${treeTable} as TreePath
274
- LEFT JOIN ${_this2.uiSchemasTableName} as "SchemaTable" ON "SchemaTable"."x-uid" = TreePath.descendant
338
+ LEFT JOIN ${_this4.uiSchemasTableName} as "SchemaTable" ON "SchemaTable"."x-uid" = TreePath.descendant
275
339
  LEFT JOIN ${treeTable} as NodeInfo ON NodeInfo.descendant = "SchemaTable"."x-uid" and NodeInfo.descendant = NodeInfo.ancestor and NodeInfo.depth = 0
276
340
  LEFT JOIN ${treeTable} as ParentPath ON (ParentPath.descendant = "SchemaTable"."x-uid" AND ParentPath.depth = 1)
277
341
  WHERE TreePath.ancestor = :ancestor ${(options === null || options === void 0 ? void 0 : options.includeAsyncNode) ? '' : 'AND (NodeInfo.async != true )'}
278
342
  `;
279
- const nodes = yield db.sequelize.query(_this2.sqlAdapter(rawSql), {
343
+ const nodes = yield db.sequelize.query(_this4.sqlAdapter(rawSql), {
280
344
  replacements: {
281
345
  ancestor: uid
282
346
  },
@@ -287,9 +351,21 @@ class UiSchemaRepository extends _database().Repository {
287
351
  return {};
288
352
  }
289
353
 
290
- const schema = _this2.nodesToSchema(nodes[0], uid);
354
+ return _this4.nodesToSchema(nodes[0], uid);
355
+ })();
356
+ }
291
357
 
292
- return schema;
358
+ getJsonSchema(uid, options) {
359
+ var _this5 = this;
360
+
361
+ return _asyncToGenerator(function* () {
362
+ if ((options === null || options === void 0 ? void 0 : options.readFromCache) && _this5.cache) {
363
+ return _this5.cache.wrap(`s_${uid}`, () => {
364
+ return _this5.doGetJsonSchema(uid, options);
365
+ });
366
+ }
367
+
368
+ return _this5.doGetJsonSchema(uid, options);
293
369
  })();
294
370
  }
295
371
 
@@ -335,11 +411,12 @@ class UiSchemaRepository extends _database().Repository {
335
411
  }
336
412
 
337
413
  clearAncestor(uid, options) {
338
- var _this3 = this;
414
+ var _this6 = this;
339
415
 
340
416
  return _asyncToGenerator(function* () {
341
- const db = _this3.database;
342
- const treeTable = _this3.uiSchemaTreePathTableName;
417
+ yield _this6.clearXUidPathCache(uid, options === null || options === void 0 ? void 0 : options.transaction);
418
+ const db = _this6.database;
419
+ const treeTable = _this6.uiSchemaTreePathTableName;
343
420
  yield db.sequelize.query(`DELETE
344
421
  FROM ${treeTable}
345
422
  WHERE descendant IN
@@ -357,19 +434,20 @@ class UiSchemaRepository extends _database().Repository {
357
434
  }
358
435
 
359
436
  patch(newSchema, options) {
360
- var _this4 = this;
437
+ var _this7 = this;
361
438
 
362
439
  return _asyncToGenerator(function* () {
363
440
  const transaction = options.transaction;
364
441
  const rootUid = newSchema['x-uid'];
365
- const oldTree = yield _this4.getJsonSchema(rootUid);
442
+ yield _this7.clearXUidPathCache(rootUid, transaction);
443
+ const oldTree = yield _this7.getJsonSchema(rootUid);
366
444
 
367
445
  const traverSchemaTree = /*#__PURE__*/function () {
368
446
  var _ref2 = _asyncToGenerator(function* (schema, path = []) {
369
447
  const node = schema;
370
448
  const oldNode = path.length == 0 ? oldTree : _lodash().default.get(oldTree, path);
371
449
  const oldNodeUid = oldNode['x-uid'];
372
- yield _this4.updateNode(oldNodeUid, node, transaction);
450
+ yield _this7.updateNode(oldNodeUid, node, transaction);
373
451
  const properties = node.properties;
374
452
 
375
453
  if (_lodash().default.isPlainObject(properties)) {
@@ -389,11 +467,35 @@ class UiSchemaRepository extends _database().Repository {
389
467
  })();
390
468
  }
391
469
 
470
+ batchPatch(schemas, options) {
471
+ var _this8 = this;
472
+
473
+ return _asyncToGenerator(function* () {
474
+ const transaction = options.transaction;
475
+
476
+ var _iterator5 = _createForOfIteratorHelper(schemas),
477
+ _step5;
478
+
479
+ try {
480
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
481
+ const schema = _step5.value;
482
+ yield _this8.patch(schema, _objectSpread(_objectSpread({}, options), {}, {
483
+ transaction
484
+ }));
485
+ }
486
+ } catch (err) {
487
+ _iterator5.e(err);
488
+ } finally {
489
+ _iterator5.f();
490
+ }
491
+ })();
492
+ }
493
+
392
494
  updateNode(uid, schema, transaction) {
393
- var _this5 = this;
495
+ var _this9 = this;
394
496
 
395
497
  return _asyncToGenerator(function* () {
396
- const nodeModel = yield _this5.findOne({
498
+ const nodeModel = yield _this9.findOne({
397
499
  filter: {
398
500
  'x-uid': uid
399
501
  }
@@ -408,11 +510,11 @@ class UiSchemaRepository extends _database().Repository {
408
510
  }
409
511
 
410
512
  childrenCount(uid, transaction) {
411
- var _this6 = this;
513
+ var _this10 = this;
412
514
 
413
515
  return _asyncToGenerator(function* () {
414
- const db = _this6.database;
415
- const countResult = yield db.sequelize.query(`SELECT COUNT(*) as count FROM ${_this6.uiSchemaTreePathTableName} where ancestor = :ancestor and depth = 1`, {
516
+ const db = _this10.database;
517
+ const countResult = yield db.sequelize.query(`SELECT COUNT(*) as count FROM ${_this10.uiSchemaTreePathTableName} where ancestor = :ancestor and depth = 1`, {
416
518
  replacements: {
417
519
  ancestor: uid
418
520
  },
@@ -424,19 +526,19 @@ class UiSchemaRepository extends _database().Repository {
424
526
  }
425
527
 
426
528
  isLeafNode(uid, transaction) {
427
- var _this7 = this;
529
+ var _this11 = this;
428
530
 
429
531
  return _asyncToGenerator(function* () {
430
- const childrenCount = yield _this7.childrenCount(uid, transaction);
532
+ const childrenCount = yield _this11.childrenCount(uid, transaction);
431
533
  return childrenCount === 0;
432
534
  })();
433
535
  }
434
536
 
435
537
  findParentUid(uid, transaction) {
436
- var _this8 = this;
538
+ var _this12 = this;
437
539
 
438
540
  return _asyncToGenerator(function* () {
439
- const parent = yield _this8.database.getRepository('uiSchemaTreePath').findOne({
541
+ const parent = yield _this12.database.getRepository('uiSchemaTreePath').findOne({
440
542
  filter: {
441
543
  descendant: uid,
442
544
  depth: 1
@@ -448,34 +550,34 @@ class UiSchemaRepository extends _database().Repository {
448
550
  }
449
551
 
450
552
  findNodeSchemaWithParent(uid, transaction) {
451
- var _this9 = this;
553
+ var _this13 = this;
452
554
 
453
555
  return _asyncToGenerator(function* () {
454
- const schema = yield _this9.database.getRepository('uiSchemas').findOne({
556
+ const schema = yield _this13.database.getRepository('uiSchemas').findOne({
455
557
  filter: {
456
558
  'x-uid': uid
457
559
  },
458
560
  transaction
459
561
  });
460
562
  return {
461
- parentUid: yield _this9.findParentUid(uid, transaction),
563
+ parentUid: yield _this13.findParentUid(uid, transaction),
462
564
  schema
463
565
  };
464
566
  })();
465
567
  }
466
568
 
467
569
  isSingleChild(uid, transaction) {
468
- var _this10 = this;
570
+ var _this14 = this;
469
571
 
470
572
  return _asyncToGenerator(function* () {
471
- const db = _this10.database;
472
- const parent = yield _this10.findParentUid(uid, transaction);
573
+ const db = _this14.database;
574
+ const parent = yield _this14.findParentUid(uid, transaction);
473
575
 
474
576
  if (!parent) {
475
577
  return null;
476
578
  }
477
579
 
478
- const parentChildrenCount = yield _this10.childrenCount(parent, transaction);
580
+ const parentChildrenCount = yield _this14.childrenCount(parent, transaction);
479
581
 
480
582
  if (parentChildrenCount == 1) {
481
583
  const schema = yield db.getRepository('uiSchemas').findOne({
@@ -492,21 +594,22 @@ class UiSchemaRepository extends _database().Repository {
492
594
  }
493
595
 
494
596
  removeEmptyParents(options) {
495
- var _this11 = this;
597
+ var _this15 = this;
496
598
 
497
599
  return _asyncToGenerator(function* () {
498
600
  const transaction = options.transaction,
499
601
  uid = options.uid,
500
602
  breakRemoveOn = options.breakRemoveOn;
603
+ yield _this15.clearXUidPathCache(uid, transaction);
501
604
 
502
605
  const removeParent = /*#__PURE__*/function () {
503
606
  var _ref3 = _asyncToGenerator(function* (nodeUid) {
504
- const parent = yield _this11.isSingleChild(nodeUid, transaction);
607
+ const parent = yield _this15.isSingleChild(nodeUid, transaction);
505
608
 
506
- if (parent && !_this11.breakOnMatched(parent, breakRemoveOn)) {
609
+ if (parent && !_this15.breakOnMatched(parent, breakRemoveOn)) {
507
610
  yield removeParent(parent.get('x-uid'));
508
611
  } else {
509
- yield _this11.remove(nodeUid, {
612
+ yield _this15.remove(nodeUid, {
510
613
  transaction
511
614
  });
512
615
  }
@@ -540,28 +643,29 @@ class UiSchemaRepository extends _database().Repository {
540
643
  }
541
644
 
542
645
  recursivelyRemoveIfNoChildren(options) {
543
- var _this12 = this;
646
+ var _this16 = this;
544
647
 
545
648
  return _asyncToGenerator(function* () {
546
649
  const uid = options.uid,
547
650
  transaction = options.transaction,
548
651
  breakRemoveOn = options.breakRemoveOn;
652
+ yield _this16.clearXUidPathCache(uid, transaction);
549
653
 
550
654
  const removeLeafNode = /*#__PURE__*/function () {
551
655
  var _ref4 = _asyncToGenerator(function* (nodeUid) {
552
- const isLeafNode = yield _this12.isLeafNode(nodeUid, transaction);
656
+ const isLeafNode = yield _this16.isLeafNode(nodeUid, transaction);
553
657
 
554
658
  if (isLeafNode) {
555
- const _yield$_this12$findNo = yield _this12.findNodeSchemaWithParent(nodeUid, transaction),
556
- parentUid = _yield$_this12$findNo.parentUid,
557
- schema = _yield$_this12$findNo.schema;
659
+ const _yield$_this16$findNo = yield _this16.findNodeSchemaWithParent(nodeUid, transaction),
660
+ parentUid = _yield$_this16$findNo.parentUid,
661
+ schema = _yield$_this16$findNo.schema;
558
662
 
559
- if (_this12.breakOnMatched(schema, breakRemoveOn)) {
663
+ if (_this16.breakOnMatched(schema, breakRemoveOn)) {
560
664
  // break at here
561
665
  return;
562
666
  } else {
563
667
  // remove current node
564
- yield _this12.remove(nodeUid, {
668
+ yield _this16.remove(nodeUid, {
565
669
  transaction
566
670
  }); // continue remove
567
671
 
@@ -580,13 +684,14 @@ class UiSchemaRepository extends _database().Repository {
580
684
  }
581
685
 
582
686
  remove(uid, options) {
583
- var _this13 = this;
687
+ var _this17 = this;
584
688
 
585
689
  return _asyncToGenerator(function* () {
586
690
  let transaction = options.transaction;
691
+ yield _this17.clearXUidPathCache(uid, transaction);
587
692
 
588
693
  if (options === null || options === void 0 ? void 0 : options.removeParentsIfNoChildren) {
589
- yield _this13.removeEmptyParents({
694
+ yield _this17.removeEmptyParents({
590
695
  transaction,
591
696
  uid,
592
697
  breakRemoveOn: options.breakRemoveOn
@@ -594,19 +699,19 @@ class UiSchemaRepository extends _database().Repository {
594
699
  return;
595
700
  }
596
701
 
597
- yield _this13.database.sequelize.query(_this13.sqlAdapter(`DELETE FROM ${_this13.uiSchemasTableName} WHERE "x-uid" IN (
598
- SELECT descendant FROM ${_this13.uiSchemaTreePathTableName} WHERE ancestor = :uid
702
+ yield _this17.database.sequelize.query(_this17.sqlAdapter(`DELETE FROM ${_this17.uiSchemasTableName} WHERE "x-uid" IN (
703
+ SELECT descendant FROM ${_this17.uiSchemaTreePathTableName} WHERE ancestor = :uid
599
704
  )`), {
600
705
  replacements: {
601
706
  uid
602
707
  },
603
708
  transaction
604
709
  });
605
- yield _this13.database.sequelize.query(` DELETE FROM ${_this13.uiSchemaTreePathTableName}
710
+ yield _this17.database.sequelize.query(` DELETE FROM ${_this17.uiSchemaTreePathTableName}
606
711
  WHERE descendant IN (
607
712
  select descendant FROM
608
713
  (SELECT descendant
609
- FROM ${_this13.uiSchemaTreePathTableName}
714
+ FROM ${_this17.uiSchemaTreePathTableName}
610
715
  WHERE ancestor = :uid)as descendantTable) `, {
611
716
  replacements: {
612
717
  uid
@@ -617,13 +722,13 @@ class UiSchemaRepository extends _database().Repository {
617
722
  }
618
723
 
619
724
  insertBeside(targetUid, schema, side, options) {
620
- var _this14 = this;
725
+ var _this18 = this;
621
726
 
622
727
  return _asyncToGenerator(function* () {
623
728
  const transaction = options.transaction;
624
- const targetParent = yield _this14.findParentUid(targetUid, transaction);
625
- const db = _this14.database;
626
- const treeTable = _this14.uiSchemaTreePathTableName;
729
+ const targetParent = yield _this18.findParentUid(targetUid, transaction);
730
+ const db = _this18.database;
731
+ const treeTable = _this18.uiSchemaTreePathTableName;
627
732
  const typeQuery = yield db.sequelize.query(`SELECT type from ${treeTable} WHERE ancestor = :uid AND depth = 0;`, {
628
733
  type: 'SELECT',
629
734
  replacements: {
@@ -641,15 +746,15 @@ class UiSchemaRepository extends _database().Repository {
641
746
  target: targetUid
642
747
  }
643
748
  };
644
- const insertedNodes = yield _this14.insertNodes(nodes, options);
645
- return yield _this14.getJsonSchema(insertedNodes[0].get('x-uid'), {
749
+ const insertedNodes = yield _this18.insertNodes(nodes, options);
750
+ return yield _this18.getJsonSchema(insertedNodes[0].get('x-uid'), {
646
751
  transaction
647
752
  });
648
753
  })();
649
754
  }
650
755
 
651
756
  insertInner(targetUid, schema, position, options) {
652
- var _this15 = this;
757
+ var _this19 = this;
653
758
 
654
759
  return _asyncToGenerator(function* () {
655
760
  const transaction = options.transaction;
@@ -660,15 +765,15 @@ class UiSchemaRepository extends _database().Repository {
660
765
  type: _lodash().default.get(schema, 'x-node-type', 'properties'),
661
766
  position
662
767
  };
663
- const insertedNodes = yield _this15.insertNodes(nodes, options);
664
- return yield _this15.getJsonSchema(insertedNodes[0].get('x-uid'), {
768
+ const insertedNodes = yield _this19.insertNodes(nodes, options);
769
+ return yield _this19.getJsonSchema(insertedNodes[0].get('x-uid'), {
665
770
  transaction
666
771
  });
667
772
  })();
668
773
  }
669
774
 
670
775
  schemaExists(schema, options) {
671
- var _this16 = this;
776
+ var _this20 = this;
672
777
 
673
778
  return _asyncToGenerator(function* () {
674
779
  if (_lodash().default.isObject(schema) && !schema['x-uid']) {
@@ -676,7 +781,7 @@ class UiSchemaRepository extends _database().Repository {
676
781
  }
677
782
 
678
783
  const transaction = options.transaction;
679
- const result = yield _this16.database.sequelize.query(_this16.sqlAdapter(`select "x-uid" from ${_this16.uiSchemasTableName} where "x-uid" = :uid`), {
784
+ const result = yield _this20.database.sequelize.query(_this20.sqlAdapter(`select "x-uid" from ${_this20.uiSchemasTableName} where "x-uid" = :uid`), {
680
785
  type: 'SELECT',
681
786
  replacements: {
682
787
  uid: _lodash().default.isString(schema) ? schema : schema['x-uid']
@@ -688,31 +793,33 @@ class UiSchemaRepository extends _database().Repository {
688
793
  }
689
794
 
690
795
  insertAdjacent(position, target, schema, options) {
691
- var _this17 = this;
796
+ var _this21 = this;
692
797
 
693
798
  return _asyncToGenerator(function* () {
694
- const transaction = options.transaction;
799
+ const transaction = options.transaction; // if schema is existed then clear origin path schema cache
800
+
801
+ yield _this21.clearXUidPathCache(schema['x-uid'], transaction);
695
802
 
696
803
  if (options.wrap) {
697
804
  // insert wrap schema using insertNewSchema
698
- const wrapSchemaNodes = yield _this17.insertNewSchema(options.wrap, {
805
+ const wrapSchemaNodes = yield _this21.insertNewSchema(options.wrap, {
699
806
  transaction,
700
807
  returnNode: true
701
808
  });
702
809
  const lastWrapNode = wrapSchemaNodes[wrapSchemaNodes.length - 1]; // insert schema into wrap schema
703
810
 
704
- yield _this17.insertAdjacent('afterBegin', lastWrapNode['x-uid'], schema, _lodash().default.omit(options, 'wrap'));
811
+ yield _this21.insertAdjacent('afterBegin', lastWrapNode['x-uid'], schema, _lodash().default.omit(options, 'wrap'));
705
812
  schema = wrapSchemaNodes[0]['x-uid'];
706
813
  options.removeParentsIfNoChildren = false;
707
814
  } else {
708
- const schemaExists = yield _this17.schemaExists(schema, {
815
+ const schemaExists = yield _this21.schemaExists(schema, {
709
816
  transaction
710
817
  });
711
818
 
712
819
  if (schemaExists) {
713
820
  schema = _lodash().default.isString(schema) ? schema : schema['x-uid'];
714
821
  } else {
715
- const insertedSchema = yield _this17.insertNewSchema(schema, {
822
+ const insertedSchema = yield _this21.insertNewSchema(schema, {
716
823
  transaction,
717
824
  returnNode: true
718
825
  });
@@ -720,63 +827,66 @@ class UiSchemaRepository extends _database().Repository {
720
827
  }
721
828
  }
722
829
 
723
- return yield _this17[`insert${_lodash().default.upperFirst(position)}`](target, schema, options);
830
+ const result = yield _this21[`insert${_lodash().default.upperFirst(position)}`](target, schema, options); // clear target schema path cache
831
+
832
+ yield _this21.clearXUidPathCache(result['x-uid'], transaction);
833
+ return result;
724
834
  })();
725
835
  }
726
836
 
727
837
  insertAfterBegin(targetUid, schema, options) {
728
- var _this18 = this;
838
+ var _this22 = this;
729
839
 
730
840
  return _asyncToGenerator(function* () {
731
- return yield _this18.insertInner(targetUid, schema, 'first', options);
841
+ return yield _this22.insertInner(targetUid, schema, 'first', options);
732
842
  })();
733
843
  }
734
844
 
735
845
  insertBeforeEnd(targetUid, schema, options) {
736
- var _this19 = this;
846
+ var _this23 = this;
737
847
 
738
848
  return _asyncToGenerator(function* () {
739
- return yield _this19.insertInner(targetUid, schema, 'last', options);
849
+ return yield _this23.insertInner(targetUid, schema, 'last', options);
740
850
  })();
741
851
  }
742
852
 
743
853
  insertBeforeBegin(targetUid, schema, options) {
744
- var _this20 = this;
854
+ var _this24 = this;
745
855
 
746
856
  return _asyncToGenerator(function* () {
747
- return yield _this20.insertBeside(targetUid, schema, 'before', options);
857
+ return yield _this24.insertBeside(targetUid, schema, 'before', options);
748
858
  })();
749
859
  }
750
860
 
751
861
  insertAfterEnd(targetUid, schema, options) {
752
- var _this21 = this;
862
+ var _this25 = this;
753
863
 
754
864
  return _asyncToGenerator(function* () {
755
- return yield _this21.insertBeside(targetUid, schema, 'after', options);
865
+ return yield _this25.insertBeside(targetUid, schema, 'after', options);
756
866
  })();
757
867
  }
758
868
 
759
869
  insertNodes(nodes, options) {
760
- var _this22 = this;
870
+ var _this26 = this;
761
871
 
762
872
  return _asyncToGenerator(function* () {
763
873
  const transaction = options.transaction;
764
874
  const insertedNodes = [];
765
875
 
766
- var _iterator4 = _createForOfIteratorHelper(nodes),
767
- _step4;
876
+ var _iterator6 = _createForOfIteratorHelper(nodes),
877
+ _step6;
768
878
 
769
879
  try {
770
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
771
- const node = _step4.value;
772
- insertedNodes.push(yield _this22.insertSingleNode(node, _objectSpread(_objectSpread({}, options), {}, {
880
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
881
+ const node = _step6.value;
882
+ insertedNodes.push(yield _this26.insertSingleNode(node, _objectSpread(_objectSpread({}, options), {}, {
773
883
  transaction
774
884
  })));
775
885
  }
776
886
  } catch (err) {
777
- _iterator4.e(err);
887
+ _iterator6.e(err);
778
888
  } finally {
779
- _iterator4.f();
889
+ _iterator6.f();
780
890
  }
781
891
 
782
892
  return insertedNodes;
@@ -784,29 +894,31 @@ class UiSchemaRepository extends _database().Repository {
784
894
  }
785
895
 
786
896
  insert(schema, options) {
787
- var _this23 = this;
897
+ var _this27 = this;
788
898
 
789
899
  return _asyncToGenerator(function* () {
790
900
  const nodes = UiSchemaRepository.schemaToSingleNodes(schema);
791
- const insertedNodes = yield _this23.insertNodes(nodes, options);
792
- return _this23.getJsonSchema(insertedNodes[0].get('x-uid'), {
901
+ const insertedNodes = yield _this27.insertNodes(nodes, options);
902
+ const result = yield _this27.getJsonSchema(insertedNodes[0].get('x-uid'), {
793
903
  transaction: options === null || options === void 0 ? void 0 : options.transaction
794
904
  });
905
+ yield _this27.clearXUidPathCache(result['x-uid'], options === null || options === void 0 ? void 0 : options.transaction);
906
+ return result;
795
907
  })();
796
908
  }
797
909
 
798
910
  insertNewSchema(schema, options) {
799
- var _this24 = this;
911
+ var _this28 = this;
800
912
 
801
913
  return _asyncToGenerator(function* () {
802
914
  const transaction = options.transaction;
803
915
  const nodes = UiSchemaRepository.schemaToSingleNodes(schema); // insert schema fist
804
916
 
805
- yield _this24.database.sequelize.query(_this24.sqlAdapter(`INSERT INTO ${_this24.uiSchemasTableName} ("x-uid", "name", "schema") VALUES ${nodes.map(n => '(?)').join(',')};`), {
917
+ yield _this28.database.sequelize.query(_this28.sqlAdapter(`INSERT INTO ${_this28.uiSchemasTableName} ("x-uid", "name", "schema") VALUES ${nodes.map(n => '(?)').join(',')};`), {
806
918
  replacements: _lodash().default.cloneDeep(nodes).map(node => {
807
- const _this24$prepareSingle = _this24.prepareSingleNodeForInsert(node),
808
- uid = _this24$prepareSingle.uid,
809
- name = _this24$prepareSingle.name;
919
+ const _this28$prepareSingle = _this28.prepareSingleNodeForInsert(node),
920
+ uid = _this28$prepareSingle.uid,
921
+ name = _this28$prepareSingle.name;
810
922
 
811
923
  return [uid, name, JSON.stringify(node)];
812
924
  }),
@@ -815,10 +927,10 @@ class UiSchemaRepository extends _database().Repository {
815
927
  });
816
928
 
817
929
  const treePathData = _lodash().default.cloneDeep(nodes).reduce((carry, item) => {
818
- const _this24$prepareSingle2 = _this24.prepareSingleNodeForInsert(item),
819
- uid = _this24$prepareSingle2.uid,
820
- childOptions = _this24$prepareSingle2.childOptions,
821
- async = _this24$prepareSingle2.async;
930
+ const _this28$prepareSingle2 = _this28.prepareSingleNodeForInsert(item),
931
+ uid = _this28$prepareSingle2.uid,
932
+ childOptions = _this28$prepareSingle2.childOptions,
933
+ async = _this28$prepareSingle2.async;
822
934
 
823
935
  return [...carry, // self reference
824
936
  [uid, uid, 0, (childOptions === null || childOptions === void 0 ? void 0 : childOptions.type) || null, async, null], // parent references
@@ -828,7 +940,7 @@ class UiSchemaRepository extends _database().Repository {
828
940
  }, []); // insert tree path
829
941
 
830
942
 
831
- yield _this24.database.sequelize.query(_this24.sqlAdapter(`INSERT INTO ${_this24.uiSchemaTreePathTableName} (ancestor, descendant, depth, type, async, sort) VALUES ${treePathData.map(item => '(?)').join(',')}`), {
943
+ yield _this28.database.sequelize.query(_this28.sqlAdapter(`INSERT INTO ${_this28.uiSchemaTreePathTableName} (ancestor, descendant, depth, type, async, sort) VALUES ${treePathData.map(item => '(?)').join(',')}`), {
832
944
  replacements: treePathData,
833
945
  type: 'insert',
834
946
  transaction
@@ -836,31 +948,33 @@ class UiSchemaRepository extends _database().Repository {
836
948
  const rootNode = nodes[0];
837
949
 
838
950
  if (rootNode['x-server-hooks']) {
839
- const rootModel = yield _this24.findOne({
951
+ const rootModel = yield _this28.findOne({
840
952
  filter: {
841
953
  'x-uid': rootNode['x-uid']
842
954
  },
843
955
  transaction
844
956
  });
845
- yield _this24.database.emitAsync(`${_this24.collection.name}.afterCreateWithAssociations`, rootModel, options);
957
+ yield _this28.database.emitAsync(`${_this28.collection.name}.afterCreateWithAssociations`, rootModel, options);
846
958
  }
847
959
 
848
960
  if (options === null || options === void 0 ? void 0 : options.returnNode) {
849
961
  return nodes;
850
962
  }
851
963
 
852
- return _this24.getJsonSchema(nodes[0]['x-uid'], {
964
+ const result = yield _this28.getJsonSchema(nodes[0]['x-uid'], {
853
965
  transaction
854
966
  });
967
+ yield _this28.clearXUidPathCache(result['x-uid'], transaction);
968
+ return result;
855
969
  })();
856
970
  }
857
971
 
858
972
  insertSchemaRecord(name, uid, schema, transaction) {
859
- var _this25 = this;
973
+ var _this29 = this;
860
974
 
861
975
  return _asyncToGenerator(function* () {
862
976
  const serverHooks = schema['x-server-hooks'] || [];
863
- const node = yield _this25.create({
977
+ const node = yield _this29.create({
864
978
  values: {
865
979
  name,
866
980
  ['x-uid']: uid,
@@ -896,42 +1010,42 @@ class UiSchemaRepository extends _database().Repository {
896
1010
  }
897
1011
 
898
1012
  insertSingleNode(schema, options) {
899
- var _this26 = this;
1013
+ var _this30 = this;
900
1014
 
901
1015
  return _asyncToGenerator(function* () {
902
1016
  const transaction = options.transaction;
903
- const db = _this26.database;
1017
+ const db = _this30.database;
904
1018
 
905
- const _this26$prepareSingle = _this26.prepareSingleNodeForInsert(schema),
906
- uid = _this26$prepareSingle.uid,
907
- name = _this26$prepareSingle.name,
908
- async = _this26$prepareSingle.async,
909
- childOptions = _this26$prepareSingle.childOptions;
1019
+ const _this30$prepareSingle = _this30.prepareSingleNodeForInsert(schema),
1020
+ uid = _this30$prepareSingle.uid,
1021
+ name = _this30$prepareSingle.name,
1022
+ async = _this30$prepareSingle.async,
1023
+ childOptions = _this30$prepareSingle.childOptions;
910
1024
 
911
1025
  let savedNode; // check node exists or not
912
1026
 
913
- const existsNode = yield _this26.findOne({
1027
+ const existsNode = yield _this30.findOne({
914
1028
  filter: {
915
1029
  'x-uid': uid
916
1030
  },
917
1031
  transaction
918
1032
  });
919
- const treeTable = _this26.uiSchemaTreePathTableName;
1033
+ const treeTable = _this30.uiSchemaTreePathTableName;
920
1034
 
921
1035
  if (existsNode) {
922
1036
  savedNode = existsNode;
923
1037
  } else {
924
- savedNode = yield _this26.insertSchemaRecord(name, uid, schema, transaction);
1038
+ savedNode = yield _this30.insertSchemaRecord(name, uid, schema, transaction);
925
1039
  }
926
1040
 
927
1041
  if (childOptions) {
928
- const oldParentUid = yield _this26.findParentUid(uid, transaction);
1042
+ const oldParentUid = yield _this30.findParentUid(uid, transaction);
929
1043
  const parentUid = childOptions.parentUid;
930
- const childrenCount = yield _this26.childrenCount(uid, transaction);
1044
+ const childrenCount = yield _this30.childrenCount(uid, transaction);
931
1045
  const isTree = childrenCount > 0; // if node is a tree root move tree to new path
932
1046
 
933
1047
  if (isTree) {
934
- yield _this26.clearAncestor(uid, {
1048
+ yield _this30.clearAncestor(uid, {
935
1049
  transaction
936
1050
  }); // insert new tree path
937
1051
 
@@ -1008,7 +1122,7 @@ class UiSchemaRepository extends _database().Repository {
1008
1122
  WHERE NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0
1009
1123
  AND TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and NodeInfo.type = :type`; // Compatible with mysql
1010
1124
 
1011
- if (_this26.database.sequelize.getDialect() === 'mysql') {
1125
+ if (_this30.database.sequelize.getDialect() === 'mysql') {
1012
1126
  updateSql = `UPDATE ${treeTable} as TreeTable
1013
1127
  JOIN ${treeTable} as NodeInfo ON (NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0)
1014
1128
  SET TreeTable.sort = TreeTable.sort + 1
@@ -1026,7 +1140,7 @@ class UiSchemaRepository extends _database().Repository {
1026
1140
  }
1027
1141
 
1028
1142
  if (nodePosition === 'last') {
1029
- const maxSort = yield db.sequelize.query(`SELECT ${_this26.database.sequelize.getDialect() === 'postgres' ? 'coalesce' : 'ifnull'}(MAX(TreeTable.sort), 0) as maxsort FROM ${treeTable} as TreeTable
1143
+ const maxSort = yield db.sequelize.query(`SELECT ${_this30.database.sequelize.getDialect() === 'postgres' ? 'coalesce' : 'ifnull'}(MAX(TreeTable.sort), 0) as maxsort FROM ${treeTable} as TreeTable
1030
1144
  LEFT JOIN ${treeTable} as NodeInfo
1031
1145
  ON NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0
1032
1146
  WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and NodeInfo.type = :type`, {
@@ -1070,7 +1184,7 @@ class UiSchemaRepository extends _database().Repository {
1070
1184
  and TreeTable.sort >= :sort
1071
1185
  and NodeInfo.type = :type`;
1072
1186
 
1073
- if (_this26.database.sequelize.getDialect() === 'mysql') {
1187
+ if (_this30.database.sequelize.getDialect() === 'mysql') {
1074
1188
  updateSql = `UPDATE ${treeTable} as TreeTable
1075
1189
  JOIN ${treeTable} as NodeInfo ON (NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0)
1076
1190
  SET TreeTable.sort = TreeTable.sort + 1
@@ -1100,14 +1214,14 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
1100
1214
  }); // move node to new parent
1101
1215
 
1102
1216
  if (oldParentUid !== null && oldParentUid !== parentUid) {
1103
- yield _this26.database.emitAsync('uiSchemaMove', savedNode, {
1217
+ yield _this30.database.emitAsync('uiSchemaMove', savedNode, {
1104
1218
  transaction,
1105
1219
  oldParentUid,
1106
1220
  parentUid
1107
1221
  });
1108
1222
 
1109
1223
  if (options.removeParentsIfNoChildren) {
1110
- yield _this26.recursivelyRemoveIfNoChildren({
1224
+ yield _this30.recursivelyRemoveIfNoChildren({
1111
1225
  transaction,
1112
1226
  uid: oldParentUid,
1113
1227
  breakRemoveOn: options.breakRemoveOn
@@ -1126,6 +1240,7 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
1126
1240
  });
1127
1241
  }
1128
1242
 
1243
+ yield _this30.clearXUidPathCache(uid, transaction);
1129
1244
  return savedNode;
1130
1245
  })();
1131
1246
  }
@@ -1138,6 +1253,8 @@ __decorate([transaction()], UiSchemaRepository.prototype, "clearAncestor", null)
1138
1253
 
1139
1254
  __decorate([transaction()], UiSchemaRepository.prototype, "patch", null);
1140
1255
 
1256
+ __decorate([transaction()], UiSchemaRepository.prototype, "batchPatch", null);
1257
+
1141
1258
  __decorate([transaction()], UiSchemaRepository.prototype, "remove", null);
1142
1259
 
1143
1260
  __decorate([transaction()], UiSchemaRepository.prototype, "insertBeside", null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-ui-schema-storage",
3
- "version": "0.7.4-alpha.7",
3
+ "version": "0.7.6-alpha.1",
4
4
  "main": "lib/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "licenses": [
@@ -11,7 +11,7 @@
11
11
  ],
12
12
  "devDependencies": {
13
13
  "@formily/json-schema": "2.0.20",
14
- "@nocobase/test": "0.7.4-alpha.7"
14
+ "@nocobase/test": "0.7.6-alpha.1"
15
15
  },
16
- "gitHead": "77f22e6da464d19be111835316faf4b94cd80413"
16
+ "gitHead": "f20ce011a9ac516dc6aec110979f063a0e63f923"
17
17
  }