@nocobase/plugin-ui-schema-storage 0.7.5-alpha.1 → 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.
- package/lib/actions/ui-schema-action.js +10 -4
- package/lib/repository.d.ts +24 -7
- package/lib/repository.js +246 -155
- package/package.json +3 -3
|
@@ -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
|
-
|
|
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,11 +66,15 @@ 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
|
-
|
|
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'),
|
|
@@ -119,7 +125,7 @@ const uiSchemaActions = {
|
|
|
119
125
|
}),
|
|
120
126
|
transaction
|
|
121
127
|
});
|
|
122
|
-
yield
|
|
128
|
+
yield getRepositoryFromCtx(ctx).clearAncestor(filterByTk, {
|
|
123
129
|
transaction
|
|
124
130
|
});
|
|
125
131
|
ctx.body = {
|
package/lib/repository.d.ts
CHANGED
|
@@ -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?:
|
|
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): {
|
|
@@ -34,10 +51,10 @@ export declare class UiSchemaRepository extends Repository {
|
|
|
34
51
|
clearAncestor(uid: string, options?: Transactionable): Promise<void>;
|
|
35
52
|
patch(newSchema: any, options?: any): Promise<void>;
|
|
36
53
|
batchPatch(schemas: any[], options?: any): Promise<void>;
|
|
37
|
-
updateNode(uid: string, schema: any, transaction?: Transaction): Promise<void>;
|
|
54
|
+
protected updateNode(uid: string, schema: any, transaction?: Transaction): Promise<void>;
|
|
38
55
|
protected childrenCount(uid: any, transaction: any): Promise<number>;
|
|
39
56
|
protected isLeafNode(uid: any, transaction: any): Promise<boolean>;
|
|
40
|
-
findParentUid(uid: any, transaction?: any): Promise<string>;
|
|
57
|
+
protected findParentUid(uid: any, transaction?: any): Promise<string>;
|
|
41
58
|
protected findNodeSchemaWithParent(uid: any, transaction: any): Promise<{
|
|
42
59
|
parentUid: string;
|
|
43
60
|
schema: import("@nocobase/database").Model<any, any>;
|
|
@@ -53,15 +70,15 @@ export declare class UiSchemaRepository extends Repository {
|
|
|
53
70
|
breakRemoveOn?: BreakRemoveOnType;
|
|
54
71
|
}): Promise<void>;
|
|
55
72
|
remove(uid: string, options?: Transactionable & removeParentOptions): Promise<void>;
|
|
56
|
-
insertBeside(targetUid: string, schema: any, side: 'before' | 'after', options?: InsertAdjacentOptions): Promise<any>;
|
|
57
|
-
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>;
|
|
58
75
|
private schemaExists;
|
|
59
76
|
insertAdjacent(position: 'beforeBegin' | 'afterBegin' | 'beforeEnd' | 'afterEnd', target: string, schema: any, options?: InsertAdjacentOptions): Promise<any>;
|
|
60
77
|
protected insertAfterBegin(targetUid: string, schema: any, options?: InsertAdjacentOptions): Promise<any>;
|
|
61
78
|
protected insertBeforeEnd(targetUid: string, schema: any, options?: InsertAdjacentOptions): Promise<any>;
|
|
62
79
|
protected insertBeforeBegin(targetUid: string, schema: any, options?: InsertAdjacentOptions): Promise<any>;
|
|
63
80
|
protected insertAfterEnd(targetUid: string, schema: any, options?: InsertAdjacentOptions): Promise<any>;
|
|
64
|
-
insertNodes(nodes: SchemaNode[], options?: Transactionable): Promise<any[]>;
|
|
81
|
+
protected insertNodes(nodes: SchemaNode[], options?: Transactionable): Promise<any[]>;
|
|
65
82
|
insert(schema: any, options?: Transactionable): Promise<any>;
|
|
66
83
|
insertNewSchema(schema: any, options?: Transactionable & {
|
|
67
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
|
|
158
|
-
|
|
207
|
+
var _iterator2 = _createForOfIteratorHelper(nodeKeys),
|
|
208
|
+
_step2;
|
|
159
209
|
|
|
160
210
|
try {
|
|
161
|
-
for (
|
|
162
|
-
const nodeKey =
|
|
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
|
|
176
|
-
|
|
225
|
+
var _iterator3 = _createForOfIteratorHelper(handleItems.entries()),
|
|
226
|
+
_step3;
|
|
177
227
|
|
|
178
228
|
try {
|
|
179
|
-
for (
|
|
180
|
-
const
|
|
181
|
-
i =
|
|
182
|
-
item =
|
|
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
|
-
|
|
239
|
+
_iterator3.e(err);
|
|
190
240
|
} finally {
|
|
191
|
-
|
|
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
|
|
199
|
-
|
|
248
|
+
var _iterator4 = _createForOfIteratorHelper(subNodeNames.entries()),
|
|
249
|
+
_step4;
|
|
200
250
|
|
|
201
251
|
try {
|
|
202
|
-
for (
|
|
203
|
-
const
|
|
204
|
-
i =
|
|
205
|
-
subNodeName =
|
|
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
|
-
|
|
266
|
+
_iterator4.e(err);
|
|
217
267
|
} finally {
|
|
218
|
-
|
|
268
|
+
_iterator4.f();
|
|
219
269
|
}
|
|
220
270
|
}
|
|
221
271
|
}
|
|
222
272
|
} catch (err) {
|
|
223
|
-
|
|
273
|
+
_iterator2.e(err);
|
|
224
274
|
} finally {
|
|
225
|
-
|
|
275
|
+
_iterator2.f();
|
|
226
276
|
}
|
|
227
277
|
|
|
228
278
|
return carry;
|
|
229
279
|
}
|
|
230
280
|
|
|
231
281
|
getProperties(uid, options = {}) {
|
|
232
|
-
var
|
|
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 =
|
|
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 ${
|
|
242
|
-
LEFT JOIN ${
|
|
243
|
-
LEFT JOIN ${
|
|
244
|
-
LEFT JOIN ${
|
|
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(
|
|
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 =
|
|
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
|
-
|
|
264
|
-
var
|
|
327
|
+
doGetJsonSchema(uid, options) {
|
|
328
|
+
var _this4 = this;
|
|
265
329
|
|
|
266
330
|
return _asyncToGenerator(function* () {
|
|
267
|
-
const db =
|
|
268
|
-
const treeTable =
|
|
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 ${
|
|
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(
|
|
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
|
-
|
|
354
|
+
return _this4.nodesToSchema(nodes[0], uid);
|
|
355
|
+
})();
|
|
356
|
+
}
|
|
291
357
|
|
|
292
|
-
|
|
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
|
|
414
|
+
var _this6 = this;
|
|
339
415
|
|
|
340
416
|
return _asyncToGenerator(function* () {
|
|
341
|
-
|
|
342
|
-
const
|
|
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
|
|
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
|
-
|
|
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
|
|
450
|
+
yield _this7.updateNode(oldNodeUid, node, transaction);
|
|
373
451
|
const properties = node.properties;
|
|
374
452
|
|
|
375
453
|
if (_lodash().default.isPlainObject(properties)) {
|
|
@@ -390,34 +468,34 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
390
468
|
}
|
|
391
469
|
|
|
392
470
|
batchPatch(schemas, options) {
|
|
393
|
-
var
|
|
471
|
+
var _this8 = this;
|
|
394
472
|
|
|
395
473
|
return _asyncToGenerator(function* () {
|
|
396
474
|
const transaction = options.transaction;
|
|
397
475
|
|
|
398
|
-
var
|
|
399
|
-
|
|
476
|
+
var _iterator5 = _createForOfIteratorHelper(schemas),
|
|
477
|
+
_step5;
|
|
400
478
|
|
|
401
479
|
try {
|
|
402
|
-
for (
|
|
403
|
-
const schema =
|
|
404
|
-
yield
|
|
480
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
481
|
+
const schema = _step5.value;
|
|
482
|
+
yield _this8.patch(schema, _objectSpread(_objectSpread({}, options), {}, {
|
|
405
483
|
transaction
|
|
406
484
|
}));
|
|
407
485
|
}
|
|
408
486
|
} catch (err) {
|
|
409
|
-
|
|
487
|
+
_iterator5.e(err);
|
|
410
488
|
} finally {
|
|
411
|
-
|
|
489
|
+
_iterator5.f();
|
|
412
490
|
}
|
|
413
491
|
})();
|
|
414
492
|
}
|
|
415
493
|
|
|
416
494
|
updateNode(uid, schema, transaction) {
|
|
417
|
-
var
|
|
495
|
+
var _this9 = this;
|
|
418
496
|
|
|
419
497
|
return _asyncToGenerator(function* () {
|
|
420
|
-
const nodeModel = yield
|
|
498
|
+
const nodeModel = yield _this9.findOne({
|
|
421
499
|
filter: {
|
|
422
500
|
'x-uid': uid
|
|
423
501
|
}
|
|
@@ -432,11 +510,11 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
432
510
|
}
|
|
433
511
|
|
|
434
512
|
childrenCount(uid, transaction) {
|
|
435
|
-
var
|
|
513
|
+
var _this10 = this;
|
|
436
514
|
|
|
437
515
|
return _asyncToGenerator(function* () {
|
|
438
|
-
const db =
|
|
439
|
-
const countResult = yield db.sequelize.query(`SELECT COUNT(*) as count FROM ${
|
|
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`, {
|
|
440
518
|
replacements: {
|
|
441
519
|
ancestor: uid
|
|
442
520
|
},
|
|
@@ -448,19 +526,19 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
448
526
|
}
|
|
449
527
|
|
|
450
528
|
isLeafNode(uid, transaction) {
|
|
451
|
-
var
|
|
529
|
+
var _this11 = this;
|
|
452
530
|
|
|
453
531
|
return _asyncToGenerator(function* () {
|
|
454
|
-
const childrenCount = yield
|
|
532
|
+
const childrenCount = yield _this11.childrenCount(uid, transaction);
|
|
455
533
|
return childrenCount === 0;
|
|
456
534
|
})();
|
|
457
535
|
}
|
|
458
536
|
|
|
459
537
|
findParentUid(uid, transaction) {
|
|
460
|
-
var
|
|
538
|
+
var _this12 = this;
|
|
461
539
|
|
|
462
540
|
return _asyncToGenerator(function* () {
|
|
463
|
-
const parent = yield
|
|
541
|
+
const parent = yield _this12.database.getRepository('uiSchemaTreePath').findOne({
|
|
464
542
|
filter: {
|
|
465
543
|
descendant: uid,
|
|
466
544
|
depth: 1
|
|
@@ -472,34 +550,34 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
472
550
|
}
|
|
473
551
|
|
|
474
552
|
findNodeSchemaWithParent(uid, transaction) {
|
|
475
|
-
var
|
|
553
|
+
var _this13 = this;
|
|
476
554
|
|
|
477
555
|
return _asyncToGenerator(function* () {
|
|
478
|
-
const schema = yield
|
|
556
|
+
const schema = yield _this13.database.getRepository('uiSchemas').findOne({
|
|
479
557
|
filter: {
|
|
480
558
|
'x-uid': uid
|
|
481
559
|
},
|
|
482
560
|
transaction
|
|
483
561
|
});
|
|
484
562
|
return {
|
|
485
|
-
parentUid: yield
|
|
563
|
+
parentUid: yield _this13.findParentUid(uid, transaction),
|
|
486
564
|
schema
|
|
487
565
|
};
|
|
488
566
|
})();
|
|
489
567
|
}
|
|
490
568
|
|
|
491
569
|
isSingleChild(uid, transaction) {
|
|
492
|
-
var
|
|
570
|
+
var _this14 = this;
|
|
493
571
|
|
|
494
572
|
return _asyncToGenerator(function* () {
|
|
495
|
-
const db =
|
|
496
|
-
const parent = yield
|
|
573
|
+
const db = _this14.database;
|
|
574
|
+
const parent = yield _this14.findParentUid(uid, transaction);
|
|
497
575
|
|
|
498
576
|
if (!parent) {
|
|
499
577
|
return null;
|
|
500
578
|
}
|
|
501
579
|
|
|
502
|
-
const parentChildrenCount = yield
|
|
580
|
+
const parentChildrenCount = yield _this14.childrenCount(parent, transaction);
|
|
503
581
|
|
|
504
582
|
if (parentChildrenCount == 1) {
|
|
505
583
|
const schema = yield db.getRepository('uiSchemas').findOne({
|
|
@@ -516,21 +594,22 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
516
594
|
}
|
|
517
595
|
|
|
518
596
|
removeEmptyParents(options) {
|
|
519
|
-
var
|
|
597
|
+
var _this15 = this;
|
|
520
598
|
|
|
521
599
|
return _asyncToGenerator(function* () {
|
|
522
600
|
const transaction = options.transaction,
|
|
523
601
|
uid = options.uid,
|
|
524
602
|
breakRemoveOn = options.breakRemoveOn;
|
|
603
|
+
yield _this15.clearXUidPathCache(uid, transaction);
|
|
525
604
|
|
|
526
605
|
const removeParent = /*#__PURE__*/function () {
|
|
527
606
|
var _ref3 = _asyncToGenerator(function* (nodeUid) {
|
|
528
|
-
const parent = yield
|
|
607
|
+
const parent = yield _this15.isSingleChild(nodeUid, transaction);
|
|
529
608
|
|
|
530
|
-
if (parent && !
|
|
609
|
+
if (parent && !_this15.breakOnMatched(parent, breakRemoveOn)) {
|
|
531
610
|
yield removeParent(parent.get('x-uid'));
|
|
532
611
|
} else {
|
|
533
|
-
yield
|
|
612
|
+
yield _this15.remove(nodeUid, {
|
|
534
613
|
transaction
|
|
535
614
|
});
|
|
536
615
|
}
|
|
@@ -564,28 +643,29 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
564
643
|
}
|
|
565
644
|
|
|
566
645
|
recursivelyRemoveIfNoChildren(options) {
|
|
567
|
-
var
|
|
646
|
+
var _this16 = this;
|
|
568
647
|
|
|
569
648
|
return _asyncToGenerator(function* () {
|
|
570
649
|
const uid = options.uid,
|
|
571
650
|
transaction = options.transaction,
|
|
572
651
|
breakRemoveOn = options.breakRemoveOn;
|
|
652
|
+
yield _this16.clearXUidPathCache(uid, transaction);
|
|
573
653
|
|
|
574
654
|
const removeLeafNode = /*#__PURE__*/function () {
|
|
575
655
|
var _ref4 = _asyncToGenerator(function* (nodeUid) {
|
|
576
|
-
const isLeafNode = yield
|
|
656
|
+
const isLeafNode = yield _this16.isLeafNode(nodeUid, transaction);
|
|
577
657
|
|
|
578
658
|
if (isLeafNode) {
|
|
579
|
-
const _yield$
|
|
580
|
-
parentUid = _yield$
|
|
581
|
-
schema = _yield$
|
|
659
|
+
const _yield$_this16$findNo = yield _this16.findNodeSchemaWithParent(nodeUid, transaction),
|
|
660
|
+
parentUid = _yield$_this16$findNo.parentUid,
|
|
661
|
+
schema = _yield$_this16$findNo.schema;
|
|
582
662
|
|
|
583
|
-
if (
|
|
663
|
+
if (_this16.breakOnMatched(schema, breakRemoveOn)) {
|
|
584
664
|
// break at here
|
|
585
665
|
return;
|
|
586
666
|
} else {
|
|
587
667
|
// remove current node
|
|
588
|
-
yield
|
|
668
|
+
yield _this16.remove(nodeUid, {
|
|
589
669
|
transaction
|
|
590
670
|
}); // continue remove
|
|
591
671
|
|
|
@@ -604,13 +684,14 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
604
684
|
}
|
|
605
685
|
|
|
606
686
|
remove(uid, options) {
|
|
607
|
-
var
|
|
687
|
+
var _this17 = this;
|
|
608
688
|
|
|
609
689
|
return _asyncToGenerator(function* () {
|
|
610
690
|
let transaction = options.transaction;
|
|
691
|
+
yield _this17.clearXUidPathCache(uid, transaction);
|
|
611
692
|
|
|
612
693
|
if (options === null || options === void 0 ? void 0 : options.removeParentsIfNoChildren) {
|
|
613
|
-
yield
|
|
694
|
+
yield _this17.removeEmptyParents({
|
|
614
695
|
transaction,
|
|
615
696
|
uid,
|
|
616
697
|
breakRemoveOn: options.breakRemoveOn
|
|
@@ -618,19 +699,19 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
618
699
|
return;
|
|
619
700
|
}
|
|
620
701
|
|
|
621
|
-
yield
|
|
622
|
-
SELECT descendant FROM ${
|
|
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
|
|
623
704
|
)`), {
|
|
624
705
|
replacements: {
|
|
625
706
|
uid
|
|
626
707
|
},
|
|
627
708
|
transaction
|
|
628
709
|
});
|
|
629
|
-
yield
|
|
710
|
+
yield _this17.database.sequelize.query(` DELETE FROM ${_this17.uiSchemaTreePathTableName}
|
|
630
711
|
WHERE descendant IN (
|
|
631
712
|
select descendant FROM
|
|
632
713
|
(SELECT descendant
|
|
633
|
-
FROM ${
|
|
714
|
+
FROM ${_this17.uiSchemaTreePathTableName}
|
|
634
715
|
WHERE ancestor = :uid)as descendantTable) `, {
|
|
635
716
|
replacements: {
|
|
636
717
|
uid
|
|
@@ -641,13 +722,13 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
641
722
|
}
|
|
642
723
|
|
|
643
724
|
insertBeside(targetUid, schema, side, options) {
|
|
644
|
-
var
|
|
725
|
+
var _this18 = this;
|
|
645
726
|
|
|
646
727
|
return _asyncToGenerator(function* () {
|
|
647
728
|
const transaction = options.transaction;
|
|
648
|
-
const targetParent = yield
|
|
649
|
-
const db =
|
|
650
|
-
const treeTable =
|
|
729
|
+
const targetParent = yield _this18.findParentUid(targetUid, transaction);
|
|
730
|
+
const db = _this18.database;
|
|
731
|
+
const treeTable = _this18.uiSchemaTreePathTableName;
|
|
651
732
|
const typeQuery = yield db.sequelize.query(`SELECT type from ${treeTable} WHERE ancestor = :uid AND depth = 0;`, {
|
|
652
733
|
type: 'SELECT',
|
|
653
734
|
replacements: {
|
|
@@ -665,15 +746,15 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
665
746
|
target: targetUid
|
|
666
747
|
}
|
|
667
748
|
};
|
|
668
|
-
const insertedNodes = yield
|
|
669
|
-
return yield
|
|
749
|
+
const insertedNodes = yield _this18.insertNodes(nodes, options);
|
|
750
|
+
return yield _this18.getJsonSchema(insertedNodes[0].get('x-uid'), {
|
|
670
751
|
transaction
|
|
671
752
|
});
|
|
672
753
|
})();
|
|
673
754
|
}
|
|
674
755
|
|
|
675
756
|
insertInner(targetUid, schema, position, options) {
|
|
676
|
-
var
|
|
757
|
+
var _this19 = this;
|
|
677
758
|
|
|
678
759
|
return _asyncToGenerator(function* () {
|
|
679
760
|
const transaction = options.transaction;
|
|
@@ -684,15 +765,15 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
684
765
|
type: _lodash().default.get(schema, 'x-node-type', 'properties'),
|
|
685
766
|
position
|
|
686
767
|
};
|
|
687
|
-
const insertedNodes = yield
|
|
688
|
-
return yield
|
|
768
|
+
const insertedNodes = yield _this19.insertNodes(nodes, options);
|
|
769
|
+
return yield _this19.getJsonSchema(insertedNodes[0].get('x-uid'), {
|
|
689
770
|
transaction
|
|
690
771
|
});
|
|
691
772
|
})();
|
|
692
773
|
}
|
|
693
774
|
|
|
694
775
|
schemaExists(schema, options) {
|
|
695
|
-
var
|
|
776
|
+
var _this20 = this;
|
|
696
777
|
|
|
697
778
|
return _asyncToGenerator(function* () {
|
|
698
779
|
if (_lodash().default.isObject(schema) && !schema['x-uid']) {
|
|
@@ -700,7 +781,7 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
700
781
|
}
|
|
701
782
|
|
|
702
783
|
const transaction = options.transaction;
|
|
703
|
-
const result = yield
|
|
784
|
+
const result = yield _this20.database.sequelize.query(_this20.sqlAdapter(`select "x-uid" from ${_this20.uiSchemasTableName} where "x-uid" = :uid`), {
|
|
704
785
|
type: 'SELECT',
|
|
705
786
|
replacements: {
|
|
706
787
|
uid: _lodash().default.isString(schema) ? schema : schema['x-uid']
|
|
@@ -712,31 +793,33 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
712
793
|
}
|
|
713
794
|
|
|
714
795
|
insertAdjacent(position, target, schema, options) {
|
|
715
|
-
var
|
|
796
|
+
var _this21 = this;
|
|
716
797
|
|
|
717
798
|
return _asyncToGenerator(function* () {
|
|
718
|
-
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);
|
|
719
802
|
|
|
720
803
|
if (options.wrap) {
|
|
721
804
|
// insert wrap schema using insertNewSchema
|
|
722
|
-
const wrapSchemaNodes = yield
|
|
805
|
+
const wrapSchemaNodes = yield _this21.insertNewSchema(options.wrap, {
|
|
723
806
|
transaction,
|
|
724
807
|
returnNode: true
|
|
725
808
|
});
|
|
726
809
|
const lastWrapNode = wrapSchemaNodes[wrapSchemaNodes.length - 1]; // insert schema into wrap schema
|
|
727
810
|
|
|
728
|
-
yield
|
|
811
|
+
yield _this21.insertAdjacent('afterBegin', lastWrapNode['x-uid'], schema, _lodash().default.omit(options, 'wrap'));
|
|
729
812
|
schema = wrapSchemaNodes[0]['x-uid'];
|
|
730
813
|
options.removeParentsIfNoChildren = false;
|
|
731
814
|
} else {
|
|
732
|
-
const schemaExists = yield
|
|
815
|
+
const schemaExists = yield _this21.schemaExists(schema, {
|
|
733
816
|
transaction
|
|
734
817
|
});
|
|
735
818
|
|
|
736
819
|
if (schemaExists) {
|
|
737
820
|
schema = _lodash().default.isString(schema) ? schema : schema['x-uid'];
|
|
738
821
|
} else {
|
|
739
|
-
const insertedSchema = yield
|
|
822
|
+
const insertedSchema = yield _this21.insertNewSchema(schema, {
|
|
740
823
|
transaction,
|
|
741
824
|
returnNode: true
|
|
742
825
|
});
|
|
@@ -744,63 +827,66 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
744
827
|
}
|
|
745
828
|
}
|
|
746
829
|
|
|
747
|
-
|
|
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;
|
|
748
834
|
})();
|
|
749
835
|
}
|
|
750
836
|
|
|
751
837
|
insertAfterBegin(targetUid, schema, options) {
|
|
752
|
-
var
|
|
838
|
+
var _this22 = this;
|
|
753
839
|
|
|
754
840
|
return _asyncToGenerator(function* () {
|
|
755
|
-
return yield
|
|
841
|
+
return yield _this22.insertInner(targetUid, schema, 'first', options);
|
|
756
842
|
})();
|
|
757
843
|
}
|
|
758
844
|
|
|
759
845
|
insertBeforeEnd(targetUid, schema, options) {
|
|
760
|
-
var
|
|
846
|
+
var _this23 = this;
|
|
761
847
|
|
|
762
848
|
return _asyncToGenerator(function* () {
|
|
763
|
-
return yield
|
|
849
|
+
return yield _this23.insertInner(targetUid, schema, 'last', options);
|
|
764
850
|
})();
|
|
765
851
|
}
|
|
766
852
|
|
|
767
853
|
insertBeforeBegin(targetUid, schema, options) {
|
|
768
|
-
var
|
|
854
|
+
var _this24 = this;
|
|
769
855
|
|
|
770
856
|
return _asyncToGenerator(function* () {
|
|
771
|
-
return yield
|
|
857
|
+
return yield _this24.insertBeside(targetUid, schema, 'before', options);
|
|
772
858
|
})();
|
|
773
859
|
}
|
|
774
860
|
|
|
775
861
|
insertAfterEnd(targetUid, schema, options) {
|
|
776
|
-
var
|
|
862
|
+
var _this25 = this;
|
|
777
863
|
|
|
778
864
|
return _asyncToGenerator(function* () {
|
|
779
|
-
return yield
|
|
865
|
+
return yield _this25.insertBeside(targetUid, schema, 'after', options);
|
|
780
866
|
})();
|
|
781
867
|
}
|
|
782
868
|
|
|
783
869
|
insertNodes(nodes, options) {
|
|
784
|
-
var
|
|
870
|
+
var _this26 = this;
|
|
785
871
|
|
|
786
872
|
return _asyncToGenerator(function* () {
|
|
787
873
|
const transaction = options.transaction;
|
|
788
874
|
const insertedNodes = [];
|
|
789
875
|
|
|
790
|
-
var
|
|
791
|
-
|
|
876
|
+
var _iterator6 = _createForOfIteratorHelper(nodes),
|
|
877
|
+
_step6;
|
|
792
878
|
|
|
793
879
|
try {
|
|
794
|
-
for (
|
|
795
|
-
const node =
|
|
796
|
-
insertedNodes.push(yield
|
|
880
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
881
|
+
const node = _step6.value;
|
|
882
|
+
insertedNodes.push(yield _this26.insertSingleNode(node, _objectSpread(_objectSpread({}, options), {}, {
|
|
797
883
|
transaction
|
|
798
884
|
})));
|
|
799
885
|
}
|
|
800
886
|
} catch (err) {
|
|
801
|
-
|
|
887
|
+
_iterator6.e(err);
|
|
802
888
|
} finally {
|
|
803
|
-
|
|
889
|
+
_iterator6.f();
|
|
804
890
|
}
|
|
805
891
|
|
|
806
892
|
return insertedNodes;
|
|
@@ -808,29 +894,31 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
808
894
|
}
|
|
809
895
|
|
|
810
896
|
insert(schema, options) {
|
|
811
|
-
var
|
|
897
|
+
var _this27 = this;
|
|
812
898
|
|
|
813
899
|
return _asyncToGenerator(function* () {
|
|
814
900
|
const nodes = UiSchemaRepository.schemaToSingleNodes(schema);
|
|
815
|
-
const insertedNodes = yield
|
|
816
|
-
|
|
901
|
+
const insertedNodes = yield _this27.insertNodes(nodes, options);
|
|
902
|
+
const result = yield _this27.getJsonSchema(insertedNodes[0].get('x-uid'), {
|
|
817
903
|
transaction: options === null || options === void 0 ? void 0 : options.transaction
|
|
818
904
|
});
|
|
905
|
+
yield _this27.clearXUidPathCache(result['x-uid'], options === null || options === void 0 ? void 0 : options.transaction);
|
|
906
|
+
return result;
|
|
819
907
|
})();
|
|
820
908
|
}
|
|
821
909
|
|
|
822
910
|
insertNewSchema(schema, options) {
|
|
823
|
-
var
|
|
911
|
+
var _this28 = this;
|
|
824
912
|
|
|
825
913
|
return _asyncToGenerator(function* () {
|
|
826
914
|
const transaction = options.transaction;
|
|
827
915
|
const nodes = UiSchemaRepository.schemaToSingleNodes(schema); // insert schema fist
|
|
828
916
|
|
|
829
|
-
yield
|
|
917
|
+
yield _this28.database.sequelize.query(_this28.sqlAdapter(`INSERT INTO ${_this28.uiSchemasTableName} ("x-uid", "name", "schema") VALUES ${nodes.map(n => '(?)').join(',')};`), {
|
|
830
918
|
replacements: _lodash().default.cloneDeep(nodes).map(node => {
|
|
831
|
-
const
|
|
832
|
-
uid =
|
|
833
|
-
name =
|
|
919
|
+
const _this28$prepareSingle = _this28.prepareSingleNodeForInsert(node),
|
|
920
|
+
uid = _this28$prepareSingle.uid,
|
|
921
|
+
name = _this28$prepareSingle.name;
|
|
834
922
|
|
|
835
923
|
return [uid, name, JSON.stringify(node)];
|
|
836
924
|
}),
|
|
@@ -839,10 +927,10 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
839
927
|
});
|
|
840
928
|
|
|
841
929
|
const treePathData = _lodash().default.cloneDeep(nodes).reduce((carry, item) => {
|
|
842
|
-
const
|
|
843
|
-
uid =
|
|
844
|
-
childOptions =
|
|
845
|
-
async =
|
|
930
|
+
const _this28$prepareSingle2 = _this28.prepareSingleNodeForInsert(item),
|
|
931
|
+
uid = _this28$prepareSingle2.uid,
|
|
932
|
+
childOptions = _this28$prepareSingle2.childOptions,
|
|
933
|
+
async = _this28$prepareSingle2.async;
|
|
846
934
|
|
|
847
935
|
return [...carry, // self reference
|
|
848
936
|
[uid, uid, 0, (childOptions === null || childOptions === void 0 ? void 0 : childOptions.type) || null, async, null], // parent references
|
|
@@ -852,7 +940,7 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
852
940
|
}, []); // insert tree path
|
|
853
941
|
|
|
854
942
|
|
|
855
|
-
yield
|
|
943
|
+
yield _this28.database.sequelize.query(_this28.sqlAdapter(`INSERT INTO ${_this28.uiSchemaTreePathTableName} (ancestor, descendant, depth, type, async, sort) VALUES ${treePathData.map(item => '(?)').join(',')}`), {
|
|
856
944
|
replacements: treePathData,
|
|
857
945
|
type: 'insert',
|
|
858
946
|
transaction
|
|
@@ -860,31 +948,33 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
860
948
|
const rootNode = nodes[0];
|
|
861
949
|
|
|
862
950
|
if (rootNode['x-server-hooks']) {
|
|
863
|
-
const rootModel = yield
|
|
951
|
+
const rootModel = yield _this28.findOne({
|
|
864
952
|
filter: {
|
|
865
953
|
'x-uid': rootNode['x-uid']
|
|
866
954
|
},
|
|
867
955
|
transaction
|
|
868
956
|
});
|
|
869
|
-
yield
|
|
957
|
+
yield _this28.database.emitAsync(`${_this28.collection.name}.afterCreateWithAssociations`, rootModel, options);
|
|
870
958
|
}
|
|
871
959
|
|
|
872
960
|
if (options === null || options === void 0 ? void 0 : options.returnNode) {
|
|
873
961
|
return nodes;
|
|
874
962
|
}
|
|
875
963
|
|
|
876
|
-
|
|
964
|
+
const result = yield _this28.getJsonSchema(nodes[0]['x-uid'], {
|
|
877
965
|
transaction
|
|
878
966
|
});
|
|
967
|
+
yield _this28.clearXUidPathCache(result['x-uid'], transaction);
|
|
968
|
+
return result;
|
|
879
969
|
})();
|
|
880
970
|
}
|
|
881
971
|
|
|
882
972
|
insertSchemaRecord(name, uid, schema, transaction) {
|
|
883
|
-
var
|
|
973
|
+
var _this29 = this;
|
|
884
974
|
|
|
885
975
|
return _asyncToGenerator(function* () {
|
|
886
976
|
const serverHooks = schema['x-server-hooks'] || [];
|
|
887
|
-
const node = yield
|
|
977
|
+
const node = yield _this29.create({
|
|
888
978
|
values: {
|
|
889
979
|
name,
|
|
890
980
|
['x-uid']: uid,
|
|
@@ -920,42 +1010,42 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
920
1010
|
}
|
|
921
1011
|
|
|
922
1012
|
insertSingleNode(schema, options) {
|
|
923
|
-
var
|
|
1013
|
+
var _this30 = this;
|
|
924
1014
|
|
|
925
1015
|
return _asyncToGenerator(function* () {
|
|
926
1016
|
const transaction = options.transaction;
|
|
927
|
-
const db =
|
|
1017
|
+
const db = _this30.database;
|
|
928
1018
|
|
|
929
|
-
const
|
|
930
|
-
uid =
|
|
931
|
-
name =
|
|
932
|
-
async =
|
|
933
|
-
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;
|
|
934
1024
|
|
|
935
1025
|
let savedNode; // check node exists or not
|
|
936
1026
|
|
|
937
|
-
const existsNode = yield
|
|
1027
|
+
const existsNode = yield _this30.findOne({
|
|
938
1028
|
filter: {
|
|
939
1029
|
'x-uid': uid
|
|
940
1030
|
},
|
|
941
1031
|
transaction
|
|
942
1032
|
});
|
|
943
|
-
const treeTable =
|
|
1033
|
+
const treeTable = _this30.uiSchemaTreePathTableName;
|
|
944
1034
|
|
|
945
1035
|
if (existsNode) {
|
|
946
1036
|
savedNode = existsNode;
|
|
947
1037
|
} else {
|
|
948
|
-
savedNode = yield
|
|
1038
|
+
savedNode = yield _this30.insertSchemaRecord(name, uid, schema, transaction);
|
|
949
1039
|
}
|
|
950
1040
|
|
|
951
1041
|
if (childOptions) {
|
|
952
|
-
const oldParentUid = yield
|
|
1042
|
+
const oldParentUid = yield _this30.findParentUid(uid, transaction);
|
|
953
1043
|
const parentUid = childOptions.parentUid;
|
|
954
|
-
const childrenCount = yield
|
|
1044
|
+
const childrenCount = yield _this30.childrenCount(uid, transaction);
|
|
955
1045
|
const isTree = childrenCount > 0; // if node is a tree root move tree to new path
|
|
956
1046
|
|
|
957
1047
|
if (isTree) {
|
|
958
|
-
yield
|
|
1048
|
+
yield _this30.clearAncestor(uid, {
|
|
959
1049
|
transaction
|
|
960
1050
|
}); // insert new tree path
|
|
961
1051
|
|
|
@@ -1032,7 +1122,7 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
1032
1122
|
WHERE NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0
|
|
1033
1123
|
AND TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and NodeInfo.type = :type`; // Compatible with mysql
|
|
1034
1124
|
|
|
1035
|
-
if (
|
|
1125
|
+
if (_this30.database.sequelize.getDialect() === 'mysql') {
|
|
1036
1126
|
updateSql = `UPDATE ${treeTable} as TreeTable
|
|
1037
1127
|
JOIN ${treeTable} as NodeInfo ON (NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0)
|
|
1038
1128
|
SET TreeTable.sort = TreeTable.sort + 1
|
|
@@ -1050,7 +1140,7 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
1050
1140
|
}
|
|
1051
1141
|
|
|
1052
1142
|
if (nodePosition === 'last') {
|
|
1053
|
-
const maxSort = yield db.sequelize.query(`SELECT ${
|
|
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
|
|
1054
1144
|
LEFT JOIN ${treeTable} as NodeInfo
|
|
1055
1145
|
ON NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0
|
|
1056
1146
|
WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and NodeInfo.type = :type`, {
|
|
@@ -1094,7 +1184,7 @@ class UiSchemaRepository extends _database().Repository {
|
|
|
1094
1184
|
and TreeTable.sort >= :sort
|
|
1095
1185
|
and NodeInfo.type = :type`;
|
|
1096
1186
|
|
|
1097
|
-
if (
|
|
1187
|
+
if (_this30.database.sequelize.getDialect() === 'mysql') {
|
|
1098
1188
|
updateSql = `UPDATE ${treeTable} as TreeTable
|
|
1099
1189
|
JOIN ${treeTable} as NodeInfo ON (NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0)
|
|
1100
1190
|
SET TreeTable.sort = TreeTable.sort + 1
|
|
@@ -1124,14 +1214,14 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
|
|
|
1124
1214
|
}); // move node to new parent
|
|
1125
1215
|
|
|
1126
1216
|
if (oldParentUid !== null && oldParentUid !== parentUid) {
|
|
1127
|
-
yield
|
|
1217
|
+
yield _this30.database.emitAsync('uiSchemaMove', savedNode, {
|
|
1128
1218
|
transaction,
|
|
1129
1219
|
oldParentUid,
|
|
1130
1220
|
parentUid
|
|
1131
1221
|
});
|
|
1132
1222
|
|
|
1133
1223
|
if (options.removeParentsIfNoChildren) {
|
|
1134
|
-
yield
|
|
1224
|
+
yield _this30.recursivelyRemoveIfNoChildren({
|
|
1135
1225
|
transaction,
|
|
1136
1226
|
uid: oldParentUid,
|
|
1137
1227
|
breakRemoveOn: options.breakRemoveOn
|
|
@@ -1150,6 +1240,7 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
|
|
|
1150
1240
|
});
|
|
1151
1241
|
}
|
|
1152
1242
|
|
|
1243
|
+
yield _this30.clearXUidPathCache(uid, transaction);
|
|
1153
1244
|
return savedNode;
|
|
1154
1245
|
})();
|
|
1155
1246
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-ui-schema-storage",
|
|
3
|
-
"version": "0.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.
|
|
14
|
+
"@nocobase/test": "0.7.6-alpha.1"
|
|
15
15
|
},
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "f20ce011a9ac516dc6aec110979f063a0e63f923"
|
|
17
17
|
}
|