@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.
- package/lib/actions/ui-schema-action.d.ts +1 -0
- package/lib/actions/ui-schema-action.js +11 -4
- package/lib/repository.d.ts +25 -7
- package/lib/repository.js +264 -147
- package/package.json +3 -3
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
128
|
+
yield getRepositoryFromCtx(ctx).clearAncestor(filterByTk, {
|
|
122
129
|
transaction
|
|
123
130
|
});
|
|
124
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): {
|
|
@@ -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
|
-
|
|
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
|
|
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)) {
|
|
@@ -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
|
|
495
|
+
var _this9 = this;
|
|
394
496
|
|
|
395
497
|
return _asyncToGenerator(function* () {
|
|
396
|
-
const nodeModel = yield
|
|
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
|
|
513
|
+
var _this10 = this;
|
|
412
514
|
|
|
413
515
|
return _asyncToGenerator(function* () {
|
|
414
|
-
const db =
|
|
415
|
-
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`, {
|
|
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
|
|
529
|
+
var _this11 = this;
|
|
428
530
|
|
|
429
531
|
return _asyncToGenerator(function* () {
|
|
430
|
-
const childrenCount = yield
|
|
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
|
|
538
|
+
var _this12 = this;
|
|
437
539
|
|
|
438
540
|
return _asyncToGenerator(function* () {
|
|
439
|
-
const parent = yield
|
|
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
|
|
553
|
+
var _this13 = this;
|
|
452
554
|
|
|
453
555
|
return _asyncToGenerator(function* () {
|
|
454
|
-
const schema = yield
|
|
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
|
|
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
|
|
570
|
+
var _this14 = this;
|
|
469
571
|
|
|
470
572
|
return _asyncToGenerator(function* () {
|
|
471
|
-
const db =
|
|
472
|
-
const parent = yield
|
|
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
|
|
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
|
|
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
|
|
607
|
+
const parent = yield _this15.isSingleChild(nodeUid, transaction);
|
|
505
608
|
|
|
506
|
-
if (parent && !
|
|
609
|
+
if (parent && !_this15.breakOnMatched(parent, breakRemoveOn)) {
|
|
507
610
|
yield removeParent(parent.get('x-uid'));
|
|
508
611
|
} else {
|
|
509
|
-
yield
|
|
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
|
|
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
|
|
656
|
+
const isLeafNode = yield _this16.isLeafNode(nodeUid, transaction);
|
|
553
657
|
|
|
554
658
|
if (isLeafNode) {
|
|
555
|
-
const _yield$
|
|
556
|
-
parentUid = _yield$
|
|
557
|
-
schema = _yield$
|
|
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 (
|
|
663
|
+
if (_this16.breakOnMatched(schema, breakRemoveOn)) {
|
|
560
664
|
// break at here
|
|
561
665
|
return;
|
|
562
666
|
} else {
|
|
563
667
|
// remove current node
|
|
564
|
-
yield
|
|
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
|
|
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
|
|
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
|
|
598
|
-
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
|
|
599
704
|
)`), {
|
|
600
705
|
replacements: {
|
|
601
706
|
uid
|
|
602
707
|
},
|
|
603
708
|
transaction
|
|
604
709
|
});
|
|
605
|
-
yield
|
|
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 ${
|
|
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
|
|
725
|
+
var _this18 = this;
|
|
621
726
|
|
|
622
727
|
return _asyncToGenerator(function* () {
|
|
623
728
|
const transaction = options.transaction;
|
|
624
|
-
const targetParent = yield
|
|
625
|
-
const db =
|
|
626
|
-
const treeTable =
|
|
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
|
|
645
|
-
return yield
|
|
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
|
|
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
|
|
664
|
-
return yield
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
838
|
+
var _this22 = this;
|
|
729
839
|
|
|
730
840
|
return _asyncToGenerator(function* () {
|
|
731
|
-
return yield
|
|
841
|
+
return yield _this22.insertInner(targetUid, schema, 'first', options);
|
|
732
842
|
})();
|
|
733
843
|
}
|
|
734
844
|
|
|
735
845
|
insertBeforeEnd(targetUid, schema, options) {
|
|
736
|
-
var
|
|
846
|
+
var _this23 = this;
|
|
737
847
|
|
|
738
848
|
return _asyncToGenerator(function* () {
|
|
739
|
-
return yield
|
|
849
|
+
return yield _this23.insertInner(targetUid, schema, 'last', options);
|
|
740
850
|
})();
|
|
741
851
|
}
|
|
742
852
|
|
|
743
853
|
insertBeforeBegin(targetUid, schema, options) {
|
|
744
|
-
var
|
|
854
|
+
var _this24 = this;
|
|
745
855
|
|
|
746
856
|
return _asyncToGenerator(function* () {
|
|
747
|
-
return yield
|
|
857
|
+
return yield _this24.insertBeside(targetUid, schema, 'before', options);
|
|
748
858
|
})();
|
|
749
859
|
}
|
|
750
860
|
|
|
751
861
|
insertAfterEnd(targetUid, schema, options) {
|
|
752
|
-
var
|
|
862
|
+
var _this25 = this;
|
|
753
863
|
|
|
754
864
|
return _asyncToGenerator(function* () {
|
|
755
|
-
return yield
|
|
865
|
+
return yield _this25.insertBeside(targetUid, schema, 'after', options);
|
|
756
866
|
})();
|
|
757
867
|
}
|
|
758
868
|
|
|
759
869
|
insertNodes(nodes, options) {
|
|
760
|
-
var
|
|
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
|
|
767
|
-
|
|
876
|
+
var _iterator6 = _createForOfIteratorHelper(nodes),
|
|
877
|
+
_step6;
|
|
768
878
|
|
|
769
879
|
try {
|
|
770
|
-
for (
|
|
771
|
-
const node =
|
|
772
|
-
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), {}, {
|
|
773
883
|
transaction
|
|
774
884
|
})));
|
|
775
885
|
}
|
|
776
886
|
} catch (err) {
|
|
777
|
-
|
|
887
|
+
_iterator6.e(err);
|
|
778
888
|
} finally {
|
|
779
|
-
|
|
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
|
|
897
|
+
var _this27 = this;
|
|
788
898
|
|
|
789
899
|
return _asyncToGenerator(function* () {
|
|
790
900
|
const nodes = UiSchemaRepository.schemaToSingleNodes(schema);
|
|
791
|
-
const insertedNodes = yield
|
|
792
|
-
|
|
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
|
|
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
|
|
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
|
|
808
|
-
uid =
|
|
809
|
-
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
|
|
819
|
-
uid =
|
|
820
|
-
childOptions =
|
|
821
|
-
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
973
|
+
var _this29 = this;
|
|
860
974
|
|
|
861
975
|
return _asyncToGenerator(function* () {
|
|
862
976
|
const serverHooks = schema['x-server-hooks'] || [];
|
|
863
|
-
const node = yield
|
|
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
|
|
1013
|
+
var _this30 = this;
|
|
900
1014
|
|
|
901
1015
|
return _asyncToGenerator(function* () {
|
|
902
1016
|
const transaction = options.transaction;
|
|
903
|
-
const db =
|
|
1017
|
+
const db = _this30.database;
|
|
904
1018
|
|
|
905
|
-
const
|
|
906
|
-
uid =
|
|
907
|
-
name =
|
|
908
|
-
async =
|
|
909
|
-
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
|
|
1027
|
+
const existsNode = yield _this30.findOne({
|
|
914
1028
|
filter: {
|
|
915
1029
|
'x-uid': uid
|
|
916
1030
|
},
|
|
917
1031
|
transaction
|
|
918
1032
|
});
|
|
919
|
-
const treeTable =
|
|
1033
|
+
const treeTable = _this30.uiSchemaTreePathTableName;
|
|
920
1034
|
|
|
921
1035
|
if (existsNode) {
|
|
922
1036
|
savedNode = existsNode;
|
|
923
1037
|
} else {
|
|
924
|
-
savedNode = yield
|
|
1038
|
+
savedNode = yield _this30.insertSchemaRecord(name, uid, schema, transaction);
|
|
925
1039
|
}
|
|
926
1040
|
|
|
927
1041
|
if (childOptions) {
|
|
928
|
-
const oldParentUid = yield
|
|
1042
|
+
const oldParentUid = yield _this30.findParentUid(uid, transaction);
|
|
929
1043
|
const parentUid = childOptions.parentUid;
|
|
930
|
-
const childrenCount = yield
|
|
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
|
|
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 (
|
|
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 ${
|
|
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 (
|
|
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
|
|
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
|
|
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.
|
|
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
|
}
|