@tachybase/module-ui-schema 0.23.8

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.
Files changed (68) hide show
  1. package/.turbo/turbo-build.log +6 -0
  2. package/LICENSE +201 -0
  3. package/README.md +9 -0
  4. package/README.zh-CN.md +9 -0
  5. package/client.d.ts +2 -0
  6. package/client.js +1 -0
  7. package/dist/client/index.d.ts +5 -0
  8. package/dist/client/index.js +1 -0
  9. package/dist/externalVersion.js +11 -0
  10. package/dist/index.d.ts +3 -0
  11. package/dist/index.js +30 -0
  12. package/dist/server/actions/ui-schema-action.d.ts +17 -0
  13. package/dist/server/actions/ui-schema-action.js +133 -0
  14. package/dist/server/collections/uiSchemaServerHooks.d.ts +3 -0
  15. package/dist/server/collections/uiSchemaServerHooks.js +49 -0
  16. package/dist/server/collections/uiSchemaTemplates.d.ts +2 -0
  17. package/dist/server/collections/uiSchemaTemplates.js +66 -0
  18. package/dist/server/collections/uiSchemaTreePath.d.ts +3 -0
  19. package/dist/server/collections/uiSchemaTreePath.js +64 -0
  20. package/dist/server/collections/uiSchemas.d.ts +3 -0
  21. package/dist/server/collections/uiSchemas.js +53 -0
  22. package/dist/server/dao/ui_schema_dao.d.ts +4 -0
  23. package/dist/server/dao/ui_schema_dao.js +31 -0
  24. package/dist/server/dao/ui_schema_node_dao.d.ts +22 -0
  25. package/dist/server/dao/ui_schema_node_dao.js +32 -0
  26. package/dist/server/helper.d.ts +0 -0
  27. package/dist/server/helper.js +0 -0
  28. package/dist/server/index.d.ts +4 -0
  29. package/dist/server/index.js +32 -0
  30. package/dist/server/migrations/20230330214649-filter-form-block.d.ts +5 -0
  31. package/dist/server/migrations/20230330214649-filter-form-block.js +48 -0
  32. package/dist/server/migrations/20230509221649-association-select.d.ts +5 -0
  33. package/dist/server/migrations/20230509221649-association-select.js +61 -0
  34. package/dist/server/migrations/20230509235247-record-picker.d.ts +8 -0
  35. package/dist/server/migrations/20230509235247-record-picker.js +111 -0
  36. package/dist/server/migrations/20230522231231-association-field.d.ts +5 -0
  37. package/dist/server/migrations/20230522231231-association-field.js +64 -0
  38. package/dist/server/migrations/20231015125000-support-filter-blocks-in-select-record-drawer.d.ts +5 -0
  39. package/dist/server/migrations/20231015125000-support-filter-blocks-in-select-record-drawer.js +45 -0
  40. package/dist/server/migrations/2024082000001-update-uiSchemas_customDesigner.d.ts +6 -0
  41. package/dist/server/migrations/2024082000001-update-uiSchemas_customDesigner.js +37 -0
  42. package/dist/server/migrations/20241120132559-modify-schema.d.ts +6 -0
  43. package/dist/server/migrations/20241120132559-modify-schema.js +119 -0
  44. package/dist/server/model.d.ts +6 -0
  45. package/dist/server/model.js +33 -0
  46. package/dist/server/repository.d.ts +85 -0
  47. package/dist/server/repository.js +969 -0
  48. package/dist/server/server-hooks/hooks/bind-menu-to-role.d.ts +5 -0
  49. package/dist/server/server-hooks/hooks/bind-menu-to-role.js +40 -0
  50. package/dist/server/server-hooks/hooks/factory.d.ts +6 -0
  51. package/dist/server/server-hooks/hooks/factory.js +33 -0
  52. package/dist/server/server-hooks/hooks/index.d.ts +6 -0
  53. package/dist/server/server-hooks/hooks/index.js +36 -0
  54. package/dist/server/server-hooks/hooks/remove-parents-if-no-children.d.ts +6 -0
  55. package/dist/server/server-hooks/hooks/remove-parents-if-no-children.js +35 -0
  56. package/dist/server/server-hooks/hooks/remove-schema.d.ts +6 -0
  57. package/dist/server/server-hooks/hooks/remove-schema.js +42 -0
  58. package/dist/server/server-hooks/index.d.ts +25 -0
  59. package/dist/server/server-hooks/index.js +165 -0
  60. package/dist/server/server-hooks/model.d.ts +3 -0
  61. package/dist/server/server-hooks/model.js +29 -0
  62. package/dist/server/server.d.ts +8 -0
  63. package/dist/server/server.js +136 -0
  64. package/dist/swagger/index.d.ts +326 -0
  65. package/dist/swagger/index.js +354 -0
  66. package/package.json +32 -0
  67. package/server.d.ts +2 -0
  68. package/server.js +1 -0
@@ -0,0 +1,969 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
8
+ var __typeError = (msg) => {
9
+ throw TypeError(msg);
10
+ };
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
13
+ var __export = (target, all) => {
14
+ for (var name in all)
15
+ __defProp(target, name, { get: all[name], enumerable: true });
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
33
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
+ var __decoratorStart = (base) => [, , , __create((base == null ? void 0 : base[__knownSymbol("metadata")]) ?? null)];
35
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
36
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
37
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
38
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
39
+ var __runInitializers = (array, flags, self, value) => {
40
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
41
+ return value;
42
+ };
43
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
44
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
45
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
46
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
47
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
48
+ return __privateGet(this, extra);
49
+ }, set [name](x) {
50
+ return __privateSet(this, extra, x);
51
+ } }, name));
52
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
53
+ for (var i = decorators.length - 1; i >= 0; i--) {
54
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
55
+ if (k) {
56
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
57
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
58
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
59
+ }
60
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
61
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
62
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
63
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
64
+ }
65
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
66
+ };
67
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
68
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
69
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
70
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
71
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
72
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
73
+ var repository_exports = {};
74
+ __export(repository_exports, {
75
+ UiSchemaRepository: () => UiSchemaRepository,
76
+ default: () => repository_default
77
+ });
78
+ module.exports = __toCommonJS(repository_exports);
79
+ var import_database = require("@tachybase/database");
80
+ var import_utils = require("@tachybase/utils");
81
+ var import_lodash = __toESM(require("lodash"));
82
+ var _insertNodes_dec, _insertAfterEnd_dec, _insertBeforeBegin_dec, _insertBeforeEnd_dec, _insertAfterBegin_dec, _insertInner_dec, _insertBeside_dec, _insertNewSchema_dec, _insert_dec, _duplicate_dec, _insertAdjacent_dec, _remove_dec, _batchPatch_dec, _patch_dec, _clearAncestor_dec, _a, _init;
83
+ const nodeKeys = ["properties", "definitions", "patternProperties", "additionalProperties", "items"];
84
+ function transaction(transactionAbleArgPosition) {
85
+ return (originalMethod) => {
86
+ const newMethod = async function(...args) {
87
+ if (!import_lodash.default.isNumber(transactionAbleArgPosition)) {
88
+ transactionAbleArgPosition = originalMethod.length - 1;
89
+ }
90
+ let transaction2 = import_lodash.default.get(args, [transactionAbleArgPosition, "transaction"]);
91
+ let handleTransaction = false;
92
+ if (!transaction2) {
93
+ transaction2 = await this.database.sequelize.transaction();
94
+ handleTransaction = true;
95
+ import_lodash.default.set(args, transactionAbleArgPosition, {
96
+ ...import_lodash.default.get(args, transactionAbleArgPosition, {}),
97
+ transaction: transaction2
98
+ });
99
+ }
100
+ if (handleTransaction) {
101
+ try {
102
+ const results = await originalMethod.apply(this, args);
103
+ await transaction2.commit();
104
+ return results;
105
+ } catch (e) {
106
+ await transaction2.rollback();
107
+ throw e;
108
+ }
109
+ } else {
110
+ return await originalMethod.apply(this, args);
111
+ }
112
+ };
113
+ return newMethod;
114
+ };
115
+ }
116
+ const _UiSchemaRepository = class _UiSchemaRepository extends (_a = import_database.Repository, _clearAncestor_dec = [transaction()], _patch_dec = [transaction()], _batchPatch_dec = [transaction()], _remove_dec = [transaction()], _insertAdjacent_dec = [transaction()], _duplicate_dec = [transaction()], _insert_dec = [transaction()], _insertNewSchema_dec = [transaction()], _insertBeside_dec = [transaction()], _insertInner_dec = [transaction()], _insertAfterBegin_dec = [transaction()], _insertBeforeEnd_dec = [transaction()], _insertBeforeBegin_dec = [transaction()], _insertAfterEnd_dec = [transaction()], _insertNodes_dec = [transaction()], _a) {
117
+ constructor() {
118
+ super(...arguments);
119
+ __runInitializers(_init, 5, this);
120
+ __publicField(this, "cache");
121
+ }
122
+ get uiSchemasTableName() {
123
+ return this.tableNameAdapter(this.model.tableName);
124
+ }
125
+ get uiSchemaTreePathTableName() {
126
+ const model = this.database.getCollection("uiSchemaTreePath").model;
127
+ return this.tableNameAdapter(model.tableName);
128
+ }
129
+ static schemaToSingleNodes(schema, carry = [], childOptions = null) {
130
+ const node = import_lodash.default.cloneDeep(
131
+ import_lodash.default.isString(schema) ? {
132
+ "x-uid": schema
133
+ } : schema
134
+ );
135
+ if (!import_lodash.default.get(node, "name")) {
136
+ node.name = (0, import_utils.uid)();
137
+ }
138
+ if (!import_lodash.default.get(node, "x-uid")) {
139
+ node["x-uid"] = (0, import_utils.uid)();
140
+ }
141
+ if (childOptions) {
142
+ node.childOptions = childOptions;
143
+ }
144
+ carry.push(node);
145
+ for (const nodeKey of nodeKeys) {
146
+ const nodeProperty = import_lodash.default.get(node, nodeKey);
147
+ const childNodeChildOptions = {
148
+ parentUid: node["x-uid"],
149
+ parentPath: [node["x-uid"], ...import_lodash.default.get(childOptions, "parentPath", [])],
150
+ type: nodeKey
151
+ };
152
+ if (nodeKey === "items" && nodeProperty) {
153
+ const handleItems = import_lodash.default.isArray(nodeProperty) ? nodeProperty : [nodeProperty];
154
+ for (const [i, item] of handleItems.entries()) {
155
+ carry = this.schemaToSingleNodes(item, carry, { ...childNodeChildOptions, sort: i + 1 });
156
+ }
157
+ } else if (import_lodash.default.isPlainObject(nodeProperty)) {
158
+ const subNodeNames = import_lodash.default.keys(import_lodash.default.get(node, nodeKey));
159
+ delete node[nodeKey];
160
+ for (const [i, subNodeName] of subNodeNames.entries()) {
161
+ const subSchema = {
162
+ name: subNodeName,
163
+ ...import_lodash.default.get(nodeProperty, subNodeName)
164
+ };
165
+ carry = this.schemaToSingleNodes(subSchema, carry, { ...childNodeChildOptions, sort: i + 1 });
166
+ }
167
+ }
168
+ }
169
+ return carry;
170
+ }
171
+ // if you need to handle cache in repo method, so you must set cache first
172
+ setCache(cache) {
173
+ this.cache = cache;
174
+ }
175
+ /**
176
+ * clear cache with xUid which in uiSchemaTreePath's Path
177
+ * @param {string} xUid
178
+ * @param {Transaction} transaction
179
+ * @returns {Promise<void>}
180
+ */
181
+ async clearXUidPathCache(xUid, transaction2) {
182
+ if (!this.cache || !xUid) {
183
+ return;
184
+ }
185
+ const uiSchemaNodes = await this.database.getRepository("uiSchemaTreePath").find({
186
+ filter: {
187
+ descendant: xUid
188
+ },
189
+ transaction: transaction2
190
+ });
191
+ for (const uiSchemaNode of uiSchemaNodes) {
192
+ await this.cache.del(`p_${uiSchemaNode["ancestor"]}`);
193
+ await this.cache.del(`s_${uiSchemaNode["ancestor"]}`);
194
+ }
195
+ }
196
+ tableNameAdapter(tableName) {
197
+ if (this.database.sequelize.getDialect() === "postgres") {
198
+ return `"${this.database.options.schema || "public"}"."${tableName}"`;
199
+ }
200
+ return tableName;
201
+ }
202
+ sqlAdapter(sql) {
203
+ if (this.database.isMySQLCompatibleDialect()) {
204
+ return import_lodash.default.replace(sql, /"/g, "`");
205
+ }
206
+ return sql;
207
+ }
208
+ async getProperties(uid2, options = {}) {
209
+ if ((options == null ? void 0 : options.readFromCache) && this.cache) {
210
+ return this.cache.wrap(`p_${uid2}`, () => {
211
+ return this.doGetProperties(uid2, options);
212
+ });
213
+ }
214
+ return this.doGetProperties(uid2, options);
215
+ }
216
+ async getJsonSchema(uid2, options) {
217
+ if ((options == null ? void 0 : options.readFromCache) && this.cache) {
218
+ return this.cache.wrap(`s_${uid2}`, () => {
219
+ return this.doGetJsonSchema(uid2, options);
220
+ });
221
+ }
222
+ return this.doGetJsonSchema(uid2, options);
223
+ }
224
+ nodesToSchema(nodes, rootUid) {
225
+ const nodeAttributeSanitize = (node) => {
226
+ const schema = {
227
+ ...this.ignoreSchemaProperties(import_lodash.default.isPlainObject(node.schema) ? node.schema : JSON.parse(node.schema)),
228
+ ...import_lodash.default.pick(node, [...nodeKeys, "name"]),
229
+ ["x-uid"]: node["x-uid"],
230
+ ["x-async"]: !!node.async
231
+ };
232
+ if (import_lodash.default.isNumber(node.sort)) {
233
+ schema["x-index"] = node.sort;
234
+ }
235
+ return schema;
236
+ };
237
+ const buildTree = (rootNode) => {
238
+ const children = nodes.filter((node) => node.parent == rootNode["x-uid"]);
239
+ if (children.length > 0) {
240
+ const childrenGroupByType = import_lodash.default.groupBy(children, "type");
241
+ for (const childType of Object.keys(childrenGroupByType)) {
242
+ const properties = childrenGroupByType[childType].map((child) => buildTree(child)).sort((a, b) => a["x-index"] - b["x-index"]);
243
+ rootNode[childType] = childType == "items" ? properties.length == 1 ? properties[0] : properties : properties.reduce((carry, item) => {
244
+ carry[item.name] = item;
245
+ delete item["name"];
246
+ return carry;
247
+ }, {});
248
+ }
249
+ }
250
+ return nodeAttributeSanitize(rootNode);
251
+ };
252
+ return buildTree(nodes.find((node) => node["x-uid"] == rootUid));
253
+ }
254
+ async clearAncestor(uid2, options) {
255
+ await this.clearXUidPathCache(uid2, options == null ? void 0 : options.transaction);
256
+ const db = this.database;
257
+ const treeTable = this.uiSchemaTreePathTableName;
258
+ await db.sequelize.query(
259
+ `DELETE
260
+ FROM ${treeTable}
261
+ WHERE descendant IN
262
+ (SELECT descendant FROM (SELECT descendant FROM ${treeTable} WHERE ancestor = :uid) as descendantTable)
263
+ AND ancestor IN (SELECT ancestor
264
+ FROM (SELECT ancestor FROM ${treeTable} WHERE descendant = :uid AND ancestor != descendant) as ancestorTable)
265
+ `,
266
+ {
267
+ type: "DELETE",
268
+ replacements: {
269
+ uid: uid2
270
+ },
271
+ transaction: options.transaction
272
+ }
273
+ );
274
+ }
275
+ async patch(newSchema, options) {
276
+ const { transaction: transaction2 } = options;
277
+ const rootUid = newSchema["x-uid"];
278
+ await this.clearXUidPathCache(rootUid, transaction2);
279
+ if (!newSchema["properties"]) {
280
+ const s = await this.model.findByPk(rootUid, { transaction: transaction2 });
281
+ s.set("schema", { ...s.toJSON(), ...newSchema });
282
+ await s.save({ transaction: transaction2, hooks: false });
283
+ if (newSchema["x-server-hooks"]) {
284
+ await this.database.emitAsync(`${this.collection.name}.afterSave`, s, options);
285
+ }
286
+ return;
287
+ }
288
+ const oldTree = await this.getJsonSchema(rootUid, { transaction: transaction2 });
289
+ const traverSchemaTree = async (schema, path = []) => {
290
+ const node = schema;
291
+ const oldNode = path.length == 0 ? oldTree : import_lodash.default.get(oldTree, path);
292
+ const oldNodeUid = oldNode["x-uid"];
293
+ await this.updateNode(oldNodeUid, node, transaction2);
294
+ const properties = node.properties;
295
+ if (import_lodash.default.isPlainObject(properties)) {
296
+ for (const name of Object.keys(properties)) {
297
+ await traverSchemaTree(properties[name], [...path, "properties", name]);
298
+ }
299
+ }
300
+ };
301
+ await traverSchemaTree(newSchema);
302
+ }
303
+ async batchPatch(schemas, options) {
304
+ const { transaction: transaction2 } = options;
305
+ for (const schema of schemas) {
306
+ await this.patch(schema, { ...options, transaction: transaction2 });
307
+ }
308
+ }
309
+ async removeEmptyParents(options) {
310
+ const { transaction: transaction2, uid: uid2, breakRemoveOn } = options;
311
+ await this.clearXUidPathCache(uid2, transaction2);
312
+ const removeParent = async (nodeUid) => {
313
+ const parent = await this.isSingleChild(nodeUid, transaction2);
314
+ if (parent && !this.breakOnMatched(parent, breakRemoveOn)) {
315
+ await removeParent(parent.get("x-uid"));
316
+ } else {
317
+ await this.remove(nodeUid, { transaction: transaction2 });
318
+ }
319
+ };
320
+ await removeParent(uid2);
321
+ }
322
+ async recursivelyRemoveIfNoChildren(options) {
323
+ const { uid: uid2, transaction: transaction2, breakRemoveOn } = options;
324
+ await this.clearXUidPathCache(uid2, transaction2);
325
+ const removeLeafNode = async (nodeUid) => {
326
+ const isLeafNode = await this.isLeafNode(nodeUid, transaction2);
327
+ if (isLeafNode) {
328
+ const { parentUid, schema } = await this.findNodeSchemaWithParent(nodeUid, transaction2);
329
+ if (this.breakOnMatched(schema, breakRemoveOn)) {
330
+ return;
331
+ } else {
332
+ await this.remove(nodeUid, {
333
+ transaction: transaction2
334
+ });
335
+ await removeLeafNode(parentUid);
336
+ }
337
+ }
338
+ };
339
+ await removeLeafNode(uid2);
340
+ }
341
+ async remove(uid2, options) {
342
+ const { transaction: transaction2 } = options;
343
+ await this.clearXUidPathCache(uid2, transaction2);
344
+ if (options == null ? void 0 : options.removeParentsIfNoChildren) {
345
+ await this.removeEmptyParents({ transaction: transaction2, uid: uid2, breakRemoveOn: options.breakRemoveOn });
346
+ return;
347
+ }
348
+ await this.database.sequelize.query(
349
+ this.sqlAdapter(`DELETE FROM ${this.uiSchemasTableName} WHERE "x-uid" IN (
350
+ SELECT descendant FROM ${this.uiSchemaTreePathTableName} WHERE ancestor = :uid
351
+ )`),
352
+ {
353
+ replacements: {
354
+ uid: uid2
355
+ },
356
+ transaction: transaction2
357
+ }
358
+ );
359
+ await this.database.sequelize.query(
360
+ ` DELETE FROM ${this.uiSchemaTreePathTableName}
361
+ WHERE descendant IN (
362
+ select descendant FROM
363
+ (SELECT descendant
364
+ FROM ${this.uiSchemaTreePathTableName}
365
+ WHERE ancestor = :uid)as descendantTable) `,
366
+ {
367
+ replacements: {
368
+ uid: uid2
369
+ },
370
+ transaction: transaction2
371
+ }
372
+ );
373
+ }
374
+ async insertAdjacent(position, target, schema, options) {
375
+ const { transaction: transaction2 } = options;
376
+ await this.clearXUidPathCache(schema["x-uid"], transaction2);
377
+ if (options.wrap) {
378
+ const wrapSchemaNodes = await this.insertNewSchema(options.wrap, {
379
+ transaction: transaction2,
380
+ returnNode: true
381
+ });
382
+ const lastWrapNode = wrapSchemaNodes[wrapSchemaNodes.length - 1];
383
+ await this.insertAdjacent("afterBegin", lastWrapNode["x-uid"], schema, import_lodash.default.omit(options, "wrap"));
384
+ schema = wrapSchemaNodes[0]["x-uid"];
385
+ options.removeParentsIfNoChildren = false;
386
+ } else {
387
+ const schemaExists = await this.schemaExists(schema, { transaction: transaction2 });
388
+ if (schemaExists) {
389
+ schema = import_lodash.default.isString(schema) ? schema : schema["x-uid"];
390
+ } else {
391
+ const insertedSchema = await this.insertNewSchema(schema, {
392
+ transaction: transaction2,
393
+ returnNode: true
394
+ });
395
+ schema = insertedSchema[0]["x-uid"];
396
+ }
397
+ }
398
+ const result = await this[`insert${import_lodash.default.upperFirst(position)}`](target, schema, options);
399
+ await this.clearXUidPathCache(result["x-uid"], transaction2);
400
+ return result;
401
+ }
402
+ async duplicate(uid2, options) {
403
+ const s = await this.getJsonSchema(uid2, { ...options, includeAsyncNode: true });
404
+ if (!(s == null ? void 0 : s["x-uid"])) {
405
+ return null;
406
+ }
407
+ this.regenerateUid(s);
408
+ return this.insert(s, options);
409
+ }
410
+ async insert(schema, options) {
411
+ const nodes = _UiSchemaRepository.schemaToSingleNodes(schema);
412
+ const insertedNodes = await this.insertNodes(nodes, options);
413
+ const result = await this.getJsonSchema(insertedNodes[0].get("x-uid"), {
414
+ transaction: options == null ? void 0 : options.transaction
415
+ });
416
+ await this.clearXUidPathCache(result["x-uid"], options == null ? void 0 : options.transaction);
417
+ return result;
418
+ }
419
+ async insertNewSchema(schema, options) {
420
+ const { transaction: transaction2 } = options;
421
+ const nodes = _UiSchemaRepository.schemaToSingleNodes(schema);
422
+ await this.database.sequelize.query(
423
+ this.sqlAdapter(
424
+ `INSERT INTO ${this.uiSchemasTableName} ("x-uid", "name", "schema") VALUES ${nodes.map((n) => "(?)").join(",")};`
425
+ ),
426
+ {
427
+ replacements: import_lodash.default.cloneDeep(nodes).map((node) => {
428
+ const { uid: uid2, name } = this.prepareSingleNodeForInsert(node);
429
+ return [uid2, name, JSON.stringify(node)];
430
+ }),
431
+ type: "insert",
432
+ transaction: transaction2
433
+ }
434
+ );
435
+ const treePathData = import_lodash.default.cloneDeep(nodes).reduce((carry, item) => {
436
+ const { uid: uid2, childOptions, async } = this.prepareSingleNodeForInsert(item);
437
+ return [
438
+ ...carry,
439
+ // self reference
440
+ [uid2, uid2, 0, (childOptions == null ? void 0 : childOptions.type) || null, async, null],
441
+ // parent references
442
+ ...import_lodash.default.get(childOptions, "parentPath", []).map((parentUid, index) => {
443
+ return [parentUid, uid2, index + 1, null, null, childOptions.sort];
444
+ })
445
+ ];
446
+ }, []);
447
+ await this.database.sequelize.query(
448
+ this.sqlAdapter(
449
+ `INSERT INTO ${this.uiSchemaTreePathTableName} (ancestor, descendant, depth, type, async, sort) VALUES ${treePathData.map((item) => "(?)").join(",")}`
450
+ ),
451
+ {
452
+ replacements: treePathData,
453
+ type: "insert",
454
+ transaction: transaction2
455
+ }
456
+ );
457
+ const rootNode = nodes[0];
458
+ if (rootNode["x-server-hooks"]) {
459
+ const rootModel = await this.findOne({ filter: { "x-uid": rootNode["x-uid"] }, transaction: transaction2 });
460
+ await this.database.emitAsync(`${this.collection.name}.afterCreateWithAssociations`, rootModel, options);
461
+ await this.database.emitAsync(`${this.collection.name}.afterSave`, rootModel, options);
462
+ }
463
+ if (options == null ? void 0 : options.returnNode) {
464
+ return nodes;
465
+ }
466
+ const result = await this.getJsonSchema(nodes[0]["x-uid"], {
467
+ transaction: transaction2
468
+ });
469
+ await this.clearXUidPathCache(result["x-uid"], transaction2);
470
+ return result;
471
+ }
472
+ async insertSingleNode(schema, options) {
473
+ const { transaction: transaction2 } = options;
474
+ const db = this.database;
475
+ const { uid: uid2, name, async, childOptions } = this.prepareSingleNodeForInsert(schema);
476
+ let savedNode;
477
+ const existsNode = await this.findOne({
478
+ filter: {
479
+ "x-uid": uid2
480
+ },
481
+ transaction: transaction2
482
+ });
483
+ const treeTable = this.uiSchemaTreePathTableName;
484
+ if (existsNode) {
485
+ savedNode = existsNode;
486
+ } else {
487
+ savedNode = await this.insertSchemaRecord(name, uid2, schema, transaction2);
488
+ }
489
+ if (childOptions) {
490
+ const oldParentUid = await this.findParentUid(uid2, transaction2);
491
+ const parentUid = childOptions.parentUid;
492
+ const childrenCount = await this.childrenCount(uid2, transaction2);
493
+ const isTree = childrenCount > 0;
494
+ if (isTree) {
495
+ await this.clearAncestor(uid2, { transaction: transaction2 });
496
+ await db.sequelize.query(
497
+ `INSERT INTO ${treeTable} (ancestor, descendant, depth)
498
+ SELECT supertree.ancestor, subtree.descendant, supertree.depth + subtree.depth + 1
499
+ FROM ${treeTable} AS supertree
500
+ CROSS JOIN ${treeTable} AS subtree
501
+ WHERE supertree.descendant = :parentUid
502
+ AND subtree.ancestor = :uid;`,
503
+ {
504
+ type: "INSERT",
505
+ replacements: {
506
+ uid: uid2,
507
+ parentUid
508
+ },
509
+ transaction: transaction2
510
+ }
511
+ );
512
+ }
513
+ await db.sequelize.query(
514
+ `UPDATE ${treeTable} SET type = :type WHERE depth = 0 AND ancestor = :uid AND descendant = :uid`,
515
+ {
516
+ type: "update",
517
+ transaction: transaction2,
518
+ replacements: {
519
+ type: childOptions.type,
520
+ uid: uid2
521
+ }
522
+ }
523
+ );
524
+ if (!isTree) {
525
+ if (existsNode) {
526
+ await db.sequelize.query(`DELETE FROM ${treeTable} WHERE descendant = :uid AND ancestor != descendant`, {
527
+ type: "DELETE",
528
+ replacements: {
529
+ uid: uid2
530
+ },
531
+ transaction: transaction2
532
+ });
533
+ }
534
+ await db.sequelize.query(
535
+ `INSERT INTO ${treeTable} (ancestor, descendant, depth)
536
+ SELECT t.ancestor, :modelKey, depth + 1 FROM ${treeTable} AS t WHERE t.descendant = :modelParentKey `,
537
+ {
538
+ type: "INSERT",
539
+ transaction: transaction2,
540
+ replacements: {
541
+ modelKey: savedNode.get("x-uid"),
542
+ modelParentKey: parentUid
543
+ }
544
+ }
545
+ );
546
+ }
547
+ if (!existsNode) {
548
+ await db.sequelize.query(
549
+ `INSERT INTO ${treeTable}(ancestor, descendant, depth, type, async) VALUES (:modelKey, :modelKey, 0, :type, :async )`,
550
+ {
551
+ type: "INSERT",
552
+ replacements: {
553
+ modelKey: savedNode.get("x-uid"),
554
+ type: childOptions.type,
555
+ async
556
+ },
557
+ transaction: transaction2
558
+ }
559
+ );
560
+ }
561
+ const nodePosition = childOptions.position || "last";
562
+ let sort;
563
+ if (nodePosition === "first") {
564
+ sort = 1;
565
+ let updateSql2 = `UPDATE ${treeTable} as TreeTable
566
+ SET sort = TreeTable.sort + 1
567
+ FROM ${treeTable} as NodeInfo
568
+ WHERE NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0
569
+ AND TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and NodeInfo.type = :type`;
570
+ if (this.database.isMySQLCompatibleDialect()) {
571
+ updateSql2 = `UPDATE ${treeTable} as TreeTable
572
+ JOIN ${treeTable} as NodeInfo ON (NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0)
573
+ SET TreeTable.sort = TreeTable.sort + 1
574
+ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and NodeInfo.type = :type`;
575
+ }
576
+ await db.sequelize.query(updateSql2, {
577
+ replacements: {
578
+ ancestor: childOptions.parentUid,
579
+ type: childOptions.type
580
+ },
581
+ transaction: transaction2
582
+ });
583
+ }
584
+ if (nodePosition === "last") {
585
+ const maxSort = await db.sequelize.query(
586
+ `SELECT ${this.database.sequelize.getDialect() === "postgres" ? "coalesce" : "ifnull"}(MAX(TreeTable.sort), 0) as maxsort FROM ${treeTable} as TreeTable
587
+ LEFT JOIN ${treeTable} as NodeInfo
588
+ ON NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0
589
+ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and NodeInfo.type = :type`,
590
+ {
591
+ type: "SELECT",
592
+ replacements: {
593
+ ancestor: childOptions.parentUid,
594
+ type: childOptions.type
595
+ },
596
+ transaction: transaction2
597
+ }
598
+ );
599
+ sort = parseInt(maxSort[0]["maxsort"]) + 1;
600
+ }
601
+ if (import_lodash.default.isPlainObject(nodePosition)) {
602
+ const targetPosition = nodePosition;
603
+ const target = targetPosition.target;
604
+ const targetSort = await db.sequelize.query(
605
+ `SELECT TreeTable.sort as sort FROM ${treeTable} as TreeTable
606
+ LEFT JOIN ${treeTable} as NodeInfo
607
+ ON NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0 WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor AND TreeTable.descendant = :descendant and NodeInfo.type = :type`,
608
+ {
609
+ type: "SELECT",
610
+ replacements: {
611
+ ancestor: childOptions.parentUid,
612
+ descendant: target,
613
+ type: childOptions.type
614
+ },
615
+ transaction: transaction2
616
+ }
617
+ );
618
+ sort = targetSort[0].sort;
619
+ if (targetPosition.type == "after") {
620
+ sort += 1;
621
+ }
622
+ let updateSql2 = `UPDATE ${treeTable} as TreeTable
623
+ SET sort = TreeTable.sort + 1
624
+ FROM ${treeTable} as NodeInfo
625
+ WHERE NodeInfo.descendant = TreeTable.descendant
626
+ and NodeInfo.depth = 0
627
+ AND TreeTable.depth = 1
628
+ AND TreeTable.ancestor = :ancestor
629
+ and TreeTable.sort >= :sort
630
+ and NodeInfo.type = :type`;
631
+ if (this.database.isMySQLCompatibleDialect()) {
632
+ updateSql2 = `UPDATE ${treeTable} as TreeTable
633
+ JOIN ${treeTable} as NodeInfo ON (NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0)
634
+ SET TreeTable.sort = TreeTable.sort + 1
635
+ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort >= :sort and NodeInfo.type = :type`;
636
+ }
637
+ await db.sequelize.query(updateSql2, {
638
+ replacements: {
639
+ ancestor: childOptions.parentUid,
640
+ sort,
641
+ type: childOptions.type
642
+ },
643
+ transaction: transaction2
644
+ });
645
+ }
646
+ const updateSql = `UPDATE ${treeTable} SET sort = :sort WHERE depth = 1 AND ancestor = :ancestor AND descendant = :descendant`;
647
+ await db.sequelize.query(updateSql, {
648
+ type: "UPDATE",
649
+ replacements: {
650
+ ancestor: childOptions.parentUid,
651
+ sort,
652
+ descendant: uid2
653
+ },
654
+ transaction: transaction2
655
+ });
656
+ if (oldParentUid !== null && oldParentUid !== parentUid) {
657
+ await this.database.emitAsync("uiSchemaMove", savedNode, {
658
+ transaction: transaction2,
659
+ oldParentUid,
660
+ parentUid
661
+ });
662
+ if (options.removeParentsIfNoChildren) {
663
+ await this.recursivelyRemoveIfNoChildren({
664
+ transaction: transaction2,
665
+ uid: oldParentUid,
666
+ breakRemoveOn: options.breakRemoveOn
667
+ });
668
+ }
669
+ }
670
+ } else {
671
+ await db.sequelize.query(
672
+ `INSERT INTO ${treeTable}(ancestor, descendant, depth, async) VALUES (:modelKey, :modelKey, 0, :async )`,
673
+ {
674
+ type: "INSERT",
675
+ replacements: {
676
+ modelKey: savedNode.get("x-uid"),
677
+ async
678
+ },
679
+ transaction: transaction2
680
+ }
681
+ );
682
+ }
683
+ await this.clearXUidPathCache(uid2, transaction2);
684
+ return savedNode;
685
+ }
686
+ async updateNode(uid2, schema, transaction2) {
687
+ const nodeModel = await this.findOne({
688
+ filter: {
689
+ "x-uid": uid2
690
+ }
691
+ });
692
+ await nodeModel.update(
693
+ {
694
+ schema: {
695
+ ...nodeModel.get("schema"),
696
+ ...import_lodash.default.omit(schema, ["x-async", "name", "x-uid", "properties"])
697
+ }
698
+ },
699
+ {
700
+ hooks: false,
701
+ transaction: transaction2
702
+ }
703
+ );
704
+ if (schema["x-server-hooks"]) {
705
+ await this.database.emitAsync(`${this.collection.name}.afterSave`, nodeModel, { transaction: transaction2 });
706
+ }
707
+ }
708
+ async childrenCount(uid2, transaction2) {
709
+ const db = this.database;
710
+ const countResult = await db.sequelize.query(
711
+ `SELECT COUNT(*) as count FROM ${this.uiSchemaTreePathTableName} where ancestor = :ancestor and depth = 1`,
712
+ {
713
+ replacements: {
714
+ ancestor: uid2
715
+ },
716
+ type: "SELECT",
717
+ transaction: transaction2
718
+ }
719
+ );
720
+ return parseInt(countResult[0]["count"]);
721
+ }
722
+ async isLeafNode(uid2, transaction2) {
723
+ const childrenCount = await this.childrenCount(uid2, transaction2);
724
+ return childrenCount === 0;
725
+ }
726
+ async findParentUid(uid2, transaction2) {
727
+ const parent = await this.database.getRepository("uiSchemaTreePath").findOne({
728
+ filter: {
729
+ descendant: uid2,
730
+ depth: 1
731
+ },
732
+ transaction: transaction2
733
+ });
734
+ return parent ? parent.get("ancestor") : null;
735
+ }
736
+ async findNodeSchemaWithParent(uid2, transaction2) {
737
+ const schema = await this.database.getRepository("uiSchemas").findOne({
738
+ filter: {
739
+ "x-uid": uid2
740
+ },
741
+ transaction: transaction2
742
+ });
743
+ return {
744
+ parentUid: await this.findParentUid(uid2, transaction2),
745
+ schema
746
+ };
747
+ }
748
+ async isSingleChild(uid2, transaction2) {
749
+ const db = this.database;
750
+ const parent = await this.findParentUid(uid2, transaction2);
751
+ if (!parent) {
752
+ return null;
753
+ }
754
+ const parentChildrenCount = await this.childrenCount(parent, transaction2);
755
+ if (parentChildrenCount == 1) {
756
+ const schema = await db.getRepository("uiSchemas").findOne({
757
+ filter: {
758
+ "x-uid": parent
759
+ },
760
+ transaction: transaction2
761
+ });
762
+ return schema;
763
+ }
764
+ return null;
765
+ }
766
+ async insertBeside(targetUid, schema, side, options) {
767
+ const { transaction: transaction2 } = options;
768
+ const targetParent = await this.findParentUid(targetUid, transaction2);
769
+ const db = this.database;
770
+ const treeTable = this.uiSchemaTreePathTableName;
771
+ const typeQuery = await db.sequelize.query(`SELECT type from ${treeTable} WHERE ancestor = :uid AND depth = 0;`, {
772
+ type: "SELECT",
773
+ replacements: {
774
+ uid: targetUid
775
+ },
776
+ transaction: transaction2
777
+ });
778
+ const nodes = _UiSchemaRepository.schemaToSingleNodes(schema);
779
+ const rootNode = nodes[0];
780
+ rootNode.childOptions = {
781
+ parentUid: targetParent,
782
+ type: typeQuery[0]["type"],
783
+ position: {
784
+ type: side,
785
+ target: targetUid
786
+ }
787
+ };
788
+ const insertedNodes = await this.insertNodes(nodes, options);
789
+ return await this.getJsonSchema(insertedNodes[0].get("x-uid"), {
790
+ transaction: transaction2
791
+ });
792
+ }
793
+ async insertInner(targetUid, schema, position, options) {
794
+ const { transaction: transaction2 } = options;
795
+ const nodes = _UiSchemaRepository.schemaToSingleNodes(schema);
796
+ const rootNode = nodes[0];
797
+ rootNode.childOptions = {
798
+ parentUid: targetUid,
799
+ type: import_lodash.default.get(schema, "x-node-type", "properties"),
800
+ position
801
+ };
802
+ const insertedNodes = await this.insertNodes(nodes, options);
803
+ return await this.getJsonSchema(insertedNodes[0].get("x-uid"), {
804
+ transaction: transaction2
805
+ });
806
+ }
807
+ async insertAfterBegin(targetUid, schema, options) {
808
+ return await this.insertInner(targetUid, schema, "first", options);
809
+ }
810
+ async insertBeforeEnd(targetUid, schema, options) {
811
+ return await this.insertInner(targetUid, schema, "last", options);
812
+ }
813
+ async insertBeforeBegin(targetUid, schema, options) {
814
+ return await this.insertBeside(targetUid, schema, "before", options);
815
+ }
816
+ async insertAfterEnd(targetUid, schema, options) {
817
+ return await this.insertBeside(targetUid, schema, "after", options);
818
+ }
819
+ async insertNodes(nodes, options) {
820
+ const { transaction: transaction2 } = options;
821
+ const insertedNodes = [];
822
+ for (const node of nodes) {
823
+ insertedNodes.push(
824
+ await this.insertSingleNode(node, {
825
+ ...options,
826
+ transaction: transaction2
827
+ })
828
+ );
829
+ }
830
+ return insertedNodes;
831
+ }
832
+ async doGetProperties(uid2, options = {}) {
833
+ const { transaction: transaction2 } = options;
834
+ const db = this.database;
835
+ const rawSql = `
836
+ SELECT "SchemaTable"."x-uid" as "x-uid", "SchemaTable"."name" as "name", "SchemaTable"."schema" as "schema",
837
+ TreePath.depth as depth,
838
+ NodeInfo.type as type, NodeInfo.async as async, ParentPath.ancestor as parent, ParentPath.sort as sort
839
+ FROM ${this.uiSchemaTreePathTableName} as TreePath
840
+ LEFT JOIN ${this.uiSchemasTableName} as "SchemaTable" ON "SchemaTable"."x-uid" = TreePath.descendant
841
+ LEFT JOIN ${this.uiSchemaTreePathTableName} as NodeInfo ON NodeInfo.descendant = "SchemaTable"."x-uid" and NodeInfo.descendant = NodeInfo.ancestor and NodeInfo.depth = 0
842
+ LEFT JOIN ${this.uiSchemaTreePathTableName} as ParentPath ON (ParentPath.descendant = "SchemaTable"."x-uid" AND ParentPath.depth = 1)
843
+ WHERE TreePath.ancestor = :ancestor AND (NodeInfo.async = false or TreePath.depth <= 1)`;
844
+ const nodes = await db.sequelize.query(this.sqlAdapter(rawSql), {
845
+ replacements: {
846
+ ancestor: uid2
847
+ },
848
+ transaction: transaction2
849
+ });
850
+ if (nodes[0].length == 0) {
851
+ return {};
852
+ }
853
+ const schema = this.nodesToSchema(nodes[0], uid2);
854
+ return import_lodash.default.pick(schema, ["type", "properties"]);
855
+ }
856
+ async doGetJsonSchema(uid2, options) {
857
+ const db = this.database;
858
+ const treeTable = this.uiSchemaTreePathTableName;
859
+ const rawSql = `
860
+ SELECT "SchemaTable"."x-uid" as "x-uid", "SchemaTable"."name" as name, "SchemaTable"."schema" as "schema" ,
861
+ TreePath.depth as depth,
862
+ NodeInfo.type as type, NodeInfo.async as async, ParentPath.ancestor as parent, ParentPath.sort as sort
863
+ FROM ${treeTable} as TreePath
864
+ LEFT JOIN ${this.uiSchemasTableName} as "SchemaTable" ON "SchemaTable"."x-uid" = TreePath.descendant
865
+ LEFT JOIN ${treeTable} as NodeInfo ON NodeInfo.descendant = "SchemaTable"."x-uid" and NodeInfo.descendant = NodeInfo.ancestor and NodeInfo.depth = 0
866
+ LEFT JOIN ${treeTable} as ParentPath ON (ParentPath.descendant = "SchemaTable"."x-uid" AND ParentPath.depth = 1)
867
+ WHERE TreePath.ancestor = :ancestor ${(options == null ? void 0 : options.includeAsyncNode) ? "" : "AND (NodeInfo.async != true or TreePath.depth = 0)"}
868
+ `;
869
+ const nodes = await db.sequelize.query(this.sqlAdapter(rawSql), {
870
+ replacements: {
871
+ ancestor: uid2
872
+ },
873
+ transaction: options == null ? void 0 : options.transaction
874
+ });
875
+ if (nodes[0].length == 0) {
876
+ return {};
877
+ }
878
+ return this.nodesToSchema(nodes[0], uid2);
879
+ }
880
+ ignoreSchemaProperties(schemaProperties) {
881
+ return import_lodash.default.omit(schemaProperties, nodeKeys);
882
+ }
883
+ breakOnMatched(schemaInstance, breakRemoveOn) {
884
+ if (!breakRemoveOn) {
885
+ return false;
886
+ }
887
+ for (const key of Object.keys(breakRemoveOn)) {
888
+ const instanceValue = schemaInstance.get(key);
889
+ const breakRemoveOnValue = breakRemoveOn[key];
890
+ if (instanceValue !== breakRemoveOnValue) {
891
+ return false;
892
+ }
893
+ }
894
+ return true;
895
+ }
896
+ async schemaExists(schema, options) {
897
+ if (import_lodash.default.isObject(schema) && !schema["x-uid"]) {
898
+ return false;
899
+ }
900
+ const { transaction: transaction2 } = options;
901
+ const result = await this.database.sequelize.query(
902
+ this.sqlAdapter(`select "x-uid" from ${this.uiSchemasTableName} where "x-uid" = :uid`),
903
+ {
904
+ type: "SELECT",
905
+ replacements: {
906
+ uid: import_lodash.default.isString(schema) ? schema : schema["x-uid"]
907
+ },
908
+ transaction: transaction2
909
+ }
910
+ );
911
+ return result.length > 0;
912
+ }
913
+ regenerateUid(s) {
914
+ s["x-uid"] = (0, import_utils.uid)();
915
+ Object.keys(s.properties || {}).forEach((key) => {
916
+ this.regenerateUid(s.properties[key]);
917
+ });
918
+ }
919
+ async insertSchemaRecord(name, uid2, schema, transaction2) {
920
+ const serverHooks = schema["x-server-hooks"] || [];
921
+ const node = await this.create({
922
+ values: {
923
+ name,
924
+ ["x-uid"]: uid2,
925
+ schema,
926
+ serverHooks
927
+ },
928
+ transaction: transaction2,
929
+ context: {
930
+ disableInsertHook: true
931
+ }
932
+ });
933
+ return node;
934
+ }
935
+ prepareSingleNodeForInsert(schema) {
936
+ const uid2 = schema["x-uid"];
937
+ const name = schema["name"];
938
+ const async = import_lodash.default.get(schema, "x-async", false);
939
+ const childOptions = schema["childOptions"];
940
+ delete schema["x-uid"];
941
+ delete schema["x-async"];
942
+ delete schema["name"];
943
+ delete schema["childOptions"];
944
+ return { uid: uid2, name, async, childOptions };
945
+ }
946
+ };
947
+ _init = __decoratorStart(_a);
948
+ __decorateElement(_init, 1, "clearAncestor", _clearAncestor_dec, _UiSchemaRepository);
949
+ __decorateElement(_init, 1, "patch", _patch_dec, _UiSchemaRepository);
950
+ __decorateElement(_init, 1, "batchPatch", _batchPatch_dec, _UiSchemaRepository);
951
+ __decorateElement(_init, 1, "remove", _remove_dec, _UiSchemaRepository);
952
+ __decorateElement(_init, 1, "insertAdjacent", _insertAdjacent_dec, _UiSchemaRepository);
953
+ __decorateElement(_init, 1, "duplicate", _duplicate_dec, _UiSchemaRepository);
954
+ __decorateElement(_init, 1, "insert", _insert_dec, _UiSchemaRepository);
955
+ __decorateElement(_init, 1, "insertNewSchema", _insertNewSchema_dec, _UiSchemaRepository);
956
+ __decorateElement(_init, 1, "insertBeside", _insertBeside_dec, _UiSchemaRepository);
957
+ __decorateElement(_init, 1, "insertInner", _insertInner_dec, _UiSchemaRepository);
958
+ __decorateElement(_init, 1, "insertAfterBegin", _insertAfterBegin_dec, _UiSchemaRepository);
959
+ __decorateElement(_init, 1, "insertBeforeEnd", _insertBeforeEnd_dec, _UiSchemaRepository);
960
+ __decorateElement(_init, 1, "insertBeforeBegin", _insertBeforeBegin_dec, _UiSchemaRepository);
961
+ __decorateElement(_init, 1, "insertAfterEnd", _insertAfterEnd_dec, _UiSchemaRepository);
962
+ __decorateElement(_init, 1, "insertNodes", _insertNodes_dec, _UiSchemaRepository);
963
+ __decoratorMetadata(_init, _UiSchemaRepository);
964
+ let UiSchemaRepository = _UiSchemaRepository;
965
+ var repository_default = UiSchemaRepository;
966
+ // Annotate the CommonJS export names for ESM import in node:
967
+ 0 && (module.exports = {
968
+ UiSchemaRepository
969
+ });