@nocobase/plugin-flow-engine 2.1.0-beta.43 → 2.1.0-beta.45
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/dist/client/index.js +1 -1
- package/dist/externalVersion.js +9 -9
- package/dist/node_modules/@ant-design/icons-svg/package.json +1 -1
- package/dist/node_modules/acorn/package.json +1 -1
- package/dist/node_modules/acorn-jsx/package.json +1 -1
- package/dist/node_modules/acorn-walk/package.json +1 -1
- package/dist/node_modules/ses/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/flow-surfaces/authoring-validation.js +160 -21
- package/dist/server/flow-surfaces/catalog.js +9 -5
- package/dist/server/flow-surfaces/chart-config.js +29 -6
- package/dist/server/flow-surfaces/contract-guard.js +39 -5
- package/dist/server/flow-surfaces/default-block-actions.js +2 -0
- package/dist/server/flow-surfaces/errors.d.ts +15 -0
- package/dist/server/flow-surfaces/errors.js +49 -3
- package/dist/server/flow-surfaces/filter-group.d.ts +7 -1
- package/dist/server/flow-surfaces/filter-group.js +175 -71
- package/dist/server/flow-surfaces/public-data-surface-default-filter.js +2 -1
- package/dist/server/flow-surfaces/runjs-authoring/ast/bindings.d.ts +66 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/bindings.js +661 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/execution.d.ts +20 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/execution.js +275 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/parser.d.ts +16 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/parser.js +130 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/react-values.d.ts +20 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/react-values.js +401 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/request-config.d.ts +21 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/request-config.js +199 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/source.d.ts +70 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/source.js +895 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-bindings.d.ts +23 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-bindings.js +618 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-values.d.ts +196 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-values.js +1777 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/walk.d.ts +10 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/walk.js +55 -0
- package/dist/server/flow-surfaces/runjs-authoring/collectors.d.ts +12 -0
- package/dist/server/flow-surfaces/runjs-authoring/collectors.js +589 -0
- package/dist/server/flow-surfaces/runjs-authoring/index.d.ts +2 -25
- package/dist/server/flow-surfaces/runjs-authoring/index.js +5 -11138
- package/dist/server/flow-surfaces/runjs-authoring/inspect.d.ts +13 -0
- package/dist/server/flow-surfaces/runjs-authoring/inspect.js +149 -0
- package/dist/server/flow-surfaces/runjs-authoring/internal-types.d.ts +333 -0
- package/dist/server/flow-surfaces/runjs-authoring/internal-types.js +36 -0
- package/dist/server/flow-surfaces/runjs-authoring/rules.js +2 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.d.ts +67 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.js +757 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/errors.d.ts +22 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/errors.js +91 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/source-budget.d.ts +16 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/source-budget.js +115 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/surface.d.ts +19 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/surface.js +140 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/types.d.ts +91 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/types.js +24 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/ctx-api.d.ts +138 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/ctx-api.js +1779 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/filter.d.ts +10 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/filter.js +1583 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/index.d.ts +195 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/index.js +463 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/react-render.d.ts +48 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/react-render.js +379 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/react.d.ts +26 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/react.js +1441 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/resource.d.ts +23 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/resource.js +1427 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.d.ts +91 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.js +889 -0
- package/dist/server/flow-surfaces/runjs-authoring/types.d.ts +1 -1
- package/dist/server/flow-surfaces/runjs-authoring/unknown-global-stop/index.d.ts +10 -0
- package/dist/server/flow-surfaces/runjs-authoring/unknown-global-stop/index.js +40 -0
- package/dist/server/flow-surfaces/runjs-authoring/validators/index.d.ts +12 -0
- package/dist/server/flow-surfaces/runjs-authoring/validators/index.js +887 -0
- package/dist/server/flow-surfaces/service-helpers.d.ts +29 -0
- package/dist/server/flow-surfaces/service-helpers.js +105 -0
- package/dist/server/flow-surfaces/service-utils.d.ts +15 -3
- package/dist/server/flow-surfaces/service-utils.js +5 -4
- package/dist/server/flow-surfaces/service.d.ts +4 -0
- package/dist/server/flow-surfaces/service.js +360 -30
- package/dist/server/flow-surfaces/types.d.ts +3 -0
- package/dist/server/repository.d.ts +15 -1
- package/dist/server/repository.js +262 -23
- package/dist/server/template/contexts.d.ts +2 -0
- package/dist/server/template/contexts.js +34 -0
- package/dist/server/template/resolver.js +233 -22
- package/dist/swagger/flow-surfaces.d.ts +175 -0
- package/dist/swagger/flow-surfaces.js +130 -51
- package/dist/swagger/index.d.ts +175 -0
- package/package.json +2 -2
|
@@ -207,6 +207,32 @@ const _FlowModelRepository = class _FlowModelRepository extends import_database.
|
|
|
207
207
|
static optionsToJson(options) {
|
|
208
208
|
return import_lodash.default.isPlainObject(options) ? options : JSON.parse(options);
|
|
209
209
|
}
|
|
210
|
+
static getSortNumber(value) {
|
|
211
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
212
|
+
return value;
|
|
213
|
+
}
|
|
214
|
+
if (typeof value === "string" && value.trim()) {
|
|
215
|
+
const parsed = Number(value);
|
|
216
|
+
if (Number.isFinite(parsed)) {
|
|
217
|
+
return parsed;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
static compareBySortAndUid(a, b) {
|
|
223
|
+
const aSort = _FlowModelRepository.getSortNumber(a.sort);
|
|
224
|
+
const bSort = _FlowModelRepository.getSortNumber(b.sort);
|
|
225
|
+
if (aSort !== null && bSort !== null && aSort !== bSort) {
|
|
226
|
+
return aSort - bSort;
|
|
227
|
+
}
|
|
228
|
+
if (aSort !== null && bSort === null) {
|
|
229
|
+
return -1;
|
|
230
|
+
}
|
|
231
|
+
if (aSort === null && bSort !== null) {
|
|
232
|
+
return 1;
|
|
233
|
+
}
|
|
234
|
+
return String(a.uid || "").localeCompare(String(b.uid || ""));
|
|
235
|
+
}
|
|
210
236
|
nodesToSchema(nodes, rootUid) {
|
|
211
237
|
const nodeAttributeSanitize = (node) => {
|
|
212
238
|
const schema = {
|
|
@@ -215,8 +241,9 @@ const _FlowModelRepository = class _FlowModelRepository extends import_database.
|
|
|
215
241
|
["uid"]: node["uid"],
|
|
216
242
|
["x-async"]: !!node.async
|
|
217
243
|
};
|
|
218
|
-
|
|
219
|
-
|
|
244
|
+
const sort = _FlowModelRepository.getSortNumber(node.sort);
|
|
245
|
+
if (sort !== null) {
|
|
246
|
+
schema["x-index"] = sort;
|
|
220
247
|
}
|
|
221
248
|
return schema;
|
|
222
249
|
};
|
|
@@ -228,7 +255,12 @@ const _FlowModelRepository = class _FlowModelRepository extends import_database.
|
|
|
228
255
|
if (children.length > 0) {
|
|
229
256
|
const childrenGroupByType = import_lodash.default.groupBy(children, "type");
|
|
230
257
|
for (const childType of Object.keys(childrenGroupByType)) {
|
|
231
|
-
const properties = childrenGroupByType[childType].map((child) => buildTree(child)).sort(
|
|
258
|
+
const properties = childrenGroupByType[childType].map((child) => buildTree(child)).sort(
|
|
259
|
+
(a, b) => _FlowModelRepository.compareBySortAndUid(
|
|
260
|
+
{ sort: a["x-index"], uid: a.uid },
|
|
261
|
+
{ sort: b["x-index"], uid: b.uid }
|
|
262
|
+
)
|
|
263
|
+
);
|
|
232
264
|
rootNode[childType] = childType == "items" ? properties.length == 1 ? properties[0] : properties : properties.reduce((carry, item) => {
|
|
233
265
|
carry[item.name] = item;
|
|
234
266
|
delete item["name"];
|
|
@@ -289,7 +321,10 @@ const _FlowModelRepository = class _FlowModelRepository extends import_database.
|
|
|
289
321
|
await this.clearXUidPathCache(rootUid, transaction2);
|
|
290
322
|
if (!newSchema["properties"]) {
|
|
291
323
|
const s = await this.model.findByPk(rootUid, { transaction: transaction2 });
|
|
292
|
-
s.set("options", {
|
|
324
|
+
s.set("options", {
|
|
325
|
+
...import_lodash.default.omit(_FlowModelRepository.optionsToJson(s.get("options") || {}), ["uid"]),
|
|
326
|
+
...import_lodash.default.omit(newSchema, ["uid", "name", "options"])
|
|
327
|
+
});
|
|
293
328
|
await s.save({ transaction: transaction2, hooks: false });
|
|
294
329
|
await this.emitAfterSaveEvent(s, options);
|
|
295
330
|
if (newSchema["x-server-hooks"]) {
|
|
@@ -478,17 +513,25 @@ const _FlowModelRepository = class _FlowModelRepository extends import_database.
|
|
|
478
513
|
const oldParentUid = n["parent"];
|
|
479
514
|
const newParentUid = uidMap[oldParentUid] ?? null;
|
|
480
515
|
const optionsObj = this.replaceStepParamsModelUids(
|
|
481
|
-
import_lodash.default.
|
|
516
|
+
import_lodash.default.cloneDeep(_FlowModelRepository.optionsToJson(n.options)),
|
|
482
517
|
uidMap
|
|
483
518
|
);
|
|
519
|
+
delete optionsObj.uid;
|
|
520
|
+
delete optionsObj.name;
|
|
521
|
+
delete optionsObj.childOptions;
|
|
522
|
+
delete optionsObj["x-async"];
|
|
484
523
|
if (newParentUid) {
|
|
485
524
|
optionsObj.parent = newParentUid;
|
|
486
525
|
optionsObj.parentId = newParentUid;
|
|
526
|
+
} else {
|
|
527
|
+
delete optionsObj.parent;
|
|
528
|
+
delete optionsObj.parentId;
|
|
487
529
|
}
|
|
488
530
|
const schemaNode = {
|
|
531
|
+
...optionsObj,
|
|
489
532
|
uid: newUid,
|
|
490
|
-
|
|
491
|
-
|
|
533
|
+
name: newUid,
|
|
534
|
+
["x-async"]: !!n.async
|
|
492
535
|
};
|
|
493
536
|
if (newParentUid) {
|
|
494
537
|
schemaNode.childOptions = {
|
|
@@ -847,7 +890,7 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
|
|
|
847
890
|
await nodeModel.update(
|
|
848
891
|
{
|
|
849
892
|
options: {
|
|
850
|
-
...nodeModel.get("options"),
|
|
893
|
+
...import_lodash.default.omit(_FlowModelRepository.optionsToJson(nodeModel.get("options") || {}), ["uid"]),
|
|
851
894
|
...import_lodash.default.omit(schema, ["x-async", "name", "uid", "properties"])
|
|
852
895
|
}
|
|
853
896
|
},
|
|
@@ -889,6 +932,115 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
|
|
|
889
932
|
});
|
|
890
933
|
return parent ? parent.get("ancestor") : null;
|
|
891
934
|
}
|
|
935
|
+
async findSiblingInfo(uid2, transaction2) {
|
|
936
|
+
const rows = await this.database.sequelize.query(
|
|
937
|
+
this.sqlAdapter(`SELECT ParentPath.ancestor as parent, NodeInfo.type as type
|
|
938
|
+
FROM ${this.flowModelTreePathTableName} as ParentPath
|
|
939
|
+
LEFT JOIN ${this.flowModelTreePathTableName} as NodeInfo
|
|
940
|
+
ON NodeInfo.ancestor = ParentPath.descendant
|
|
941
|
+
AND NodeInfo.descendant = ParentPath.descendant
|
|
942
|
+
AND NodeInfo.depth = 0
|
|
943
|
+
WHERE ParentPath.descendant = :uid AND ParentPath.depth = 1`),
|
|
944
|
+
{
|
|
945
|
+
type: "SELECT",
|
|
946
|
+
replacements: { uid: uid2 },
|
|
947
|
+
transaction: transaction2
|
|
948
|
+
}
|
|
949
|
+
);
|
|
950
|
+
const row = rows[0];
|
|
951
|
+
if (!(row == null ? void 0 : row.parent) || !(row == null ? void 0 : row.type)) {
|
|
952
|
+
return null;
|
|
953
|
+
}
|
|
954
|
+
return {
|
|
955
|
+
parentUid: row.parent,
|
|
956
|
+
type: row.type
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
async findSiblingSortRows(parentUid, type, transaction2) {
|
|
960
|
+
const treeTable = this.flowModelTreePathTableName;
|
|
961
|
+
const rows = await this.database.sequelize.query(
|
|
962
|
+
this.sqlAdapter(`SELECT ChildPath.descendant as uid, ChildPath.sort as sort
|
|
963
|
+
FROM ${treeTable} as ChildPath
|
|
964
|
+
LEFT JOIN ${treeTable} as NodeInfo
|
|
965
|
+
ON NodeInfo.ancestor = ChildPath.descendant
|
|
966
|
+
AND NodeInfo.descendant = ChildPath.descendant
|
|
967
|
+
AND NodeInfo.depth = 0
|
|
968
|
+
WHERE ChildPath.ancestor = :parentUid
|
|
969
|
+
AND ChildPath.depth = 1
|
|
970
|
+
AND NodeInfo.type = :type`),
|
|
971
|
+
{
|
|
972
|
+
type: "SELECT",
|
|
973
|
+
replacements: { parentUid, type },
|
|
974
|
+
transaction: transaction2
|
|
975
|
+
}
|
|
976
|
+
);
|
|
977
|
+
return rows.sort((a, b) => _FlowModelRepository.compareBySortAndUid(a, b));
|
|
978
|
+
}
|
|
979
|
+
async writeSiblingSorts(parentUid, orderedUids, transaction2) {
|
|
980
|
+
const treeTable = this.flowModelTreePathTableName;
|
|
981
|
+
for (const [index, uid2] of orderedUids.entries()) {
|
|
982
|
+
await this.database.sequelize.query(
|
|
983
|
+
this.sqlAdapter(
|
|
984
|
+
`UPDATE ${treeTable} SET sort = :sort WHERE ancestor = :parentUid AND descendant = :uid AND depth = 1`
|
|
985
|
+
),
|
|
986
|
+
{
|
|
987
|
+
type: "UPDATE",
|
|
988
|
+
replacements: {
|
|
989
|
+
parentUid,
|
|
990
|
+
uid: uid2,
|
|
991
|
+
sort: index + 1
|
|
992
|
+
},
|
|
993
|
+
transaction: transaction2
|
|
994
|
+
}
|
|
995
|
+
);
|
|
996
|
+
}
|
|
997
|
+
await this.clearXUidPathCache(parentUid, transaction2);
|
|
998
|
+
}
|
|
999
|
+
async normalizeSiblingSorts(info, transaction2) {
|
|
1000
|
+
if (!info) {
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
const siblingRows = await this.findSiblingSortRows(info.parentUid, info.type, transaction2);
|
|
1004
|
+
await this.writeSiblingSorts(
|
|
1005
|
+
info.parentUid,
|
|
1006
|
+
siblingRows.map((row) => row.uid),
|
|
1007
|
+
transaction2
|
|
1008
|
+
);
|
|
1009
|
+
}
|
|
1010
|
+
async isAncestorOf(ancestorUid, descendantUid, transaction2) {
|
|
1011
|
+
const rows = await this.database.sequelize.query(
|
|
1012
|
+
this.sqlAdapter(`SELECT 1 as v
|
|
1013
|
+
FROM ${this.flowModelTreePathTableName}
|
|
1014
|
+
WHERE ancestor = :ancestorUid
|
|
1015
|
+
AND descendant = :descendantUid
|
|
1016
|
+
AND depth > 0
|
|
1017
|
+
LIMIT 1`),
|
|
1018
|
+
{
|
|
1019
|
+
type: "SELECT",
|
|
1020
|
+
replacements: { ancestorUid, descendantUid },
|
|
1021
|
+
transaction: transaction2
|
|
1022
|
+
}
|
|
1023
|
+
);
|
|
1024
|
+
return rows.length > 0;
|
|
1025
|
+
}
|
|
1026
|
+
async updateModelParentOptions(uid2, parentId, subKey, subType, transaction2) {
|
|
1027
|
+
const modelInstance = await this.model.findByPk(uid2, { transaction: transaction2 });
|
|
1028
|
+
if (!modelInstance) {
|
|
1029
|
+
throw new Error(`flowModels:move sourceId '${uid2}' not found`);
|
|
1030
|
+
}
|
|
1031
|
+
await modelInstance.update(
|
|
1032
|
+
{
|
|
1033
|
+
options: {
|
|
1034
|
+
...import_lodash.default.omit(_FlowModelRepository.optionsToJson(modelInstance.get("options") || {}), ["uid"]),
|
|
1035
|
+
parentId,
|
|
1036
|
+
parent: parentId,
|
|
1037
|
+
subKey,
|
|
1038
|
+
subType
|
|
1039
|
+
}
|
|
1040
|
+
},
|
|
1041
|
+
{ transaction: transaction2, hooks: false }
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
892
1044
|
async findNodeSchemaWithParent(uid2, transaction2) {
|
|
893
1045
|
const schema = await this.database.getRepository("flowModels").findOne({
|
|
894
1046
|
filter: {
|
|
@@ -1155,22 +1307,30 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
|
|
|
1155
1307
|
for (const child of children) {
|
|
1156
1308
|
const { subKey, subType } = this.optionsToJson(child.options);
|
|
1157
1309
|
if (!subKey) continue;
|
|
1158
|
-
const
|
|
1159
|
-
uid: child["uid"],
|
|
1310
|
+
const model2 = _FlowModelRepository.nodesToModel(nodes, child["uid"]) || {
|
|
1160
1311
|
...this.optionsToJson(child.options),
|
|
1312
|
+
uid: child["uid"],
|
|
1161
1313
|
sortIndex: child.sort
|
|
1162
1314
|
};
|
|
1163
|
-
|
|
1315
|
+
model2.sortIndex = child.sort;
|
|
1164
1316
|
if (subType === "array") {
|
|
1165
1317
|
if (!subModels[subKey]) subModels[subKey] = [];
|
|
1166
|
-
subModels[subKey].push(
|
|
1318
|
+
subModels[subKey].push(model2);
|
|
1167
1319
|
} else {
|
|
1168
|
-
subModels[subKey] =
|
|
1320
|
+
subModels[subKey] = model2;
|
|
1169
1321
|
}
|
|
1170
1322
|
}
|
|
1171
1323
|
for (const key in subModels) {
|
|
1172
1324
|
if (Array.isArray(subModels[key])) {
|
|
1173
|
-
subModels[key]
|
|
1325
|
+
subModels[key] = subModels[key].sort(
|
|
1326
|
+
(a, b) => _FlowModelRepository.compareBySortAndUid(
|
|
1327
|
+
{ sort: a.sortIndex, uid: a.uid },
|
|
1328
|
+
{ sort: b.sortIndex, uid: b.uid }
|
|
1329
|
+
)
|
|
1330
|
+
).map((item, index) => {
|
|
1331
|
+
item.sortIndex = index + 1;
|
|
1332
|
+
return item;
|
|
1333
|
+
});
|
|
1174
1334
|
}
|
|
1175
1335
|
}
|
|
1176
1336
|
const filteredSubModels = {};
|
|
@@ -1181,11 +1341,19 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
|
|
|
1181
1341
|
continue;
|
|
1182
1342
|
filteredSubModels[key] = value;
|
|
1183
1343
|
}
|
|
1184
|
-
|
|
1185
|
-
uid: rootNode["uid"],
|
|
1344
|
+
const model = {
|
|
1186
1345
|
...this.optionsToJson(rootNode.options),
|
|
1346
|
+
uid: rootNode["uid"],
|
|
1187
1347
|
...Object.keys(filteredSubModels).length > 0 ? { subModels: filteredSubModels } : {}
|
|
1188
1348
|
};
|
|
1349
|
+
if (rootNode.parent) {
|
|
1350
|
+
model.parent = rootNode.parent;
|
|
1351
|
+
model.parentId = rootNode.parent;
|
|
1352
|
+
} else {
|
|
1353
|
+
delete model.parent;
|
|
1354
|
+
delete model.parentId;
|
|
1355
|
+
}
|
|
1356
|
+
return model;
|
|
1189
1357
|
}
|
|
1190
1358
|
async insertModel(model, options) {
|
|
1191
1359
|
const nodes = _FlowModelRepository.modelToSingleNodes(model);
|
|
@@ -1194,6 +1362,7 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
|
|
|
1194
1362
|
return await this.findModelById(rootUid, options);
|
|
1195
1363
|
}
|
|
1196
1364
|
async updateSingleNode(node, options) {
|
|
1365
|
+
var _a;
|
|
1197
1366
|
const instance = await this.model.findByPk(node["uid"], {
|
|
1198
1367
|
transaction: options == null ? void 0 : options.transaction
|
|
1199
1368
|
});
|
|
@@ -1201,8 +1370,12 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
|
|
|
1201
1370
|
await instance.update(
|
|
1202
1371
|
{
|
|
1203
1372
|
options: {
|
|
1204
|
-
...instance.get("options"),
|
|
1205
|
-
...import_lodash.default.omit(node, ["x-async", "name", "uid", "childOptions"])
|
|
1373
|
+
...import_lodash.default.omit(instance.get("options"), ["uid"]),
|
|
1374
|
+
...import_lodash.default.omit(node, ["x-async", "name", "uid", "childOptions"]),
|
|
1375
|
+
...((_a = node.childOptions) == null ? void 0 : _a.parentUid) ? {
|
|
1376
|
+
parent: node.childOptions.parentUid,
|
|
1377
|
+
parentId: node.childOptions.parentUid
|
|
1378
|
+
} : {}
|
|
1206
1379
|
}
|
|
1207
1380
|
},
|
|
1208
1381
|
{
|
|
@@ -1376,7 +1549,7 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
|
|
|
1376
1549
|
await modelInstance.update(
|
|
1377
1550
|
{
|
|
1378
1551
|
options: {
|
|
1379
|
-
...modelInstance.get("options"),
|
|
1552
|
+
...import_lodash.default.omit(modelInstance.get("options"), ["uid"]),
|
|
1380
1553
|
parentId,
|
|
1381
1554
|
parent: parentId,
|
|
1382
1555
|
subKey,
|
|
@@ -1399,11 +1572,74 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
|
|
|
1399
1572
|
);
|
|
1400
1573
|
return await this.findModelById(modelUid, { transaction: transaction2, includeAsyncNode: true });
|
|
1401
1574
|
}
|
|
1402
|
-
async move(options) {
|
|
1575
|
+
async move(options, transactionOptions) {
|
|
1403
1576
|
const { sourceId, targetId, position } = options;
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1577
|
+
const sourceUid = String(sourceId || "").trim();
|
|
1578
|
+
const targetUid = String(targetId || "").trim();
|
|
1579
|
+
if (!sourceUid || !targetUid) {
|
|
1580
|
+
throw new Error("flowModels:move missing required params");
|
|
1581
|
+
}
|
|
1582
|
+
if (position !== "before" && position !== "after") {
|
|
1583
|
+
throw new Error("flowModels:move invalid position");
|
|
1584
|
+
}
|
|
1585
|
+
const transaction2 = transactionOptions == null ? void 0 : transactionOptions.transaction;
|
|
1586
|
+
const sourceInstance = await this.model.findByPk(sourceUid, { transaction: transaction2 });
|
|
1587
|
+
if (!sourceInstance) {
|
|
1588
|
+
throw new Error(`flowModels:move sourceId '${sourceUid}' not found`);
|
|
1589
|
+
}
|
|
1590
|
+
if (sourceUid === targetUid) {
|
|
1591
|
+
await this.normalizeSiblingSorts(await this.findSiblingInfo(sourceUid, transaction2), transaction2);
|
|
1592
|
+
return null;
|
|
1593
|
+
}
|
|
1594
|
+
const sourceInfo = await this.findSiblingInfo(sourceUid, transaction2);
|
|
1595
|
+
const targetInfo = await this.findSiblingInfo(targetUid, transaction2);
|
|
1596
|
+
if (!targetInfo) {
|
|
1597
|
+
throw new Error("flowModels:move target is not attached to a parent");
|
|
1598
|
+
}
|
|
1599
|
+
const targetInstance = await this.model.findByPk(targetUid, { transaction: transaction2 });
|
|
1600
|
+
const targetOptions = _FlowModelRepository.optionsToJson((targetInstance == null ? void 0 : targetInstance.get("options")) || {});
|
|
1601
|
+
const targetSubType = targetOptions.subType === "object" ? "object" : "array";
|
|
1602
|
+
if (targetInfo.parentUid === sourceUid || await this.isAncestorOf(sourceUid, targetInfo.parentUid, transaction2)) {
|
|
1603
|
+
throw new Error("flowModels:move cycle detected");
|
|
1604
|
+
}
|
|
1605
|
+
if ((sourceInfo == null ? void 0 : sourceInfo.parentUid) === targetInfo.parentUid && sourceInfo.type === targetInfo.type) {
|
|
1606
|
+
const siblingRows = await this.findSiblingSortRows(sourceInfo.parentUid, sourceInfo.type, transaction2);
|
|
1607
|
+
const sourceRow = siblingRows.find((row) => row.uid === sourceUid);
|
|
1608
|
+
const targetIndex = siblingRows.findIndex((row) => row.uid === targetUid);
|
|
1609
|
+
if (!sourceRow || targetIndex === -1) {
|
|
1610
|
+
throw new Error("flowModels:move source and target must be sibling nodes under the same parent/subKey");
|
|
1611
|
+
}
|
|
1612
|
+
const rowsWithoutSource = siblingRows.filter((row) => row.uid !== sourceUid);
|
|
1613
|
+
const insertIndex = rowsWithoutSource.findIndex((row) => row.uid === targetUid);
|
|
1614
|
+
rowsWithoutSource.splice(position === "after" ? insertIndex + 1 : insertIndex, 0, sourceRow);
|
|
1615
|
+
await this.writeSiblingSorts(
|
|
1616
|
+
sourceInfo.parentUid,
|
|
1617
|
+
rowsWithoutSource.map((row) => row.uid),
|
|
1618
|
+
transaction2
|
|
1619
|
+
);
|
|
1620
|
+
return await this.findModelById(sourceUid, { transaction: transaction2 });
|
|
1621
|
+
}
|
|
1622
|
+
await this.normalizeSiblingSorts(sourceInfo, transaction2);
|
|
1623
|
+
await this.normalizeSiblingSorts(targetInfo, transaction2);
|
|
1624
|
+
await this.updateModelParentOptions(sourceUid, targetInfo.parentUid, targetInfo.type, targetSubType, transaction2);
|
|
1625
|
+
await this.insertSingleNode(
|
|
1626
|
+
{
|
|
1627
|
+
uid: sourceUid,
|
|
1628
|
+
name: sourceUid,
|
|
1629
|
+
childOptions: {
|
|
1630
|
+
parentUid: targetInfo.parentUid,
|
|
1631
|
+
type: targetInfo.type,
|
|
1632
|
+
position: {
|
|
1633
|
+
type: position,
|
|
1634
|
+
target: targetUid
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
},
|
|
1638
|
+
{ transaction: transaction2, removeParentsIfNoChildren: false }
|
|
1639
|
+
);
|
|
1640
|
+
await this.normalizeSiblingSorts(sourceInfo, transaction2);
|
|
1641
|
+
await this.normalizeSiblingSorts(await this.findSiblingInfo(sourceUid, transaction2), transaction2);
|
|
1642
|
+
return await this.findModelById(sourceUid, { transaction: transaction2 });
|
|
1407
1643
|
}
|
|
1408
1644
|
};
|
|
1409
1645
|
__decorateClass([
|
|
@@ -1466,6 +1702,9 @@ __decorateClass([
|
|
|
1466
1702
|
__decorateClass([
|
|
1467
1703
|
transaction()
|
|
1468
1704
|
], _FlowModelRepository.prototype, "attach", 1);
|
|
1705
|
+
__decorateClass([
|
|
1706
|
+
transaction()
|
|
1707
|
+
], _FlowModelRepository.prototype, "move", 1);
|
|
1469
1708
|
let FlowModelRepository = _FlowModelRepository;
|
|
1470
1709
|
var repository_default = FlowModelRepository;
|
|
1471
1710
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -50,6 +50,8 @@ export declare class ServerBaseContext {
|
|
|
50
50
|
delegate(ctx: ServerBaseContext): void;
|
|
51
51
|
/** 清空所有委托 */
|
|
52
52
|
clearDelegates(): void;
|
|
53
|
+
getSandboxKeys(): string[];
|
|
54
|
+
getSandboxValue(key: string, current?: ServerBaseContext): any;
|
|
53
55
|
/** 创建并返回代理对象(同一实例下保持稳定引用) */
|
|
54
56
|
createProxy(): any;
|
|
55
57
|
}
|
|
@@ -42,6 +42,10 @@ __export(contexts_exports, {
|
|
|
42
42
|
});
|
|
43
43
|
module.exports = __toCommonJS(contexts_exports);
|
|
44
44
|
var import_lodash = __toESM(require("lodash"));
|
|
45
|
+
const BLOCKED_SANDBOX_KEYS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor", "then"]);
|
|
46
|
+
function isBlockedSandboxKey(key) {
|
|
47
|
+
return BLOCKED_SANDBOX_KEYS.has(key);
|
|
48
|
+
}
|
|
45
49
|
class ServerBaseContext {
|
|
46
50
|
_props = {};
|
|
47
51
|
_methods = {};
|
|
@@ -106,6 +110,36 @@ class ServerBaseContext {
|
|
|
106
110
|
clearDelegates() {
|
|
107
111
|
this._delegates = [];
|
|
108
112
|
}
|
|
113
|
+
getSandboxKeys() {
|
|
114
|
+
const keys = /* @__PURE__ */ new Set();
|
|
115
|
+
for (const key of Object.keys(this._props)) {
|
|
116
|
+
if (!isBlockedSandboxKey(key)) keys.add(key);
|
|
117
|
+
}
|
|
118
|
+
for (const key of Object.keys(this._methods)) {
|
|
119
|
+
if (!isBlockedSandboxKey(key)) keys.add(key);
|
|
120
|
+
}
|
|
121
|
+
for (const d of this._delegates) {
|
|
122
|
+
for (const key of d.getSandboxKeys()) {
|
|
123
|
+
if (!isBlockedSandboxKey(key)) keys.add(key);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return Array.from(keys);
|
|
127
|
+
}
|
|
128
|
+
getSandboxValue(key, current = this.createProxy()) {
|
|
129
|
+
if (isBlockedSandboxKey(key)) return void 0;
|
|
130
|
+
if (Object.prototype.hasOwnProperty.call(this._props, key)) {
|
|
131
|
+
return this._getOwn(key, current);
|
|
132
|
+
}
|
|
133
|
+
if (Object.prototype.hasOwnProperty.call(this._methods, key)) {
|
|
134
|
+
const fn = this._methods[key];
|
|
135
|
+
return typeof fn === "function" ? fn.bind(this) : fn;
|
|
136
|
+
}
|
|
137
|
+
for (const d of this._delegates) {
|
|
138
|
+
if (!d.getSandboxKeys().includes(key)) continue;
|
|
139
|
+
return d.getSandboxValue(key, current);
|
|
140
|
+
}
|
|
141
|
+
return void 0;
|
|
142
|
+
}
|
|
109
143
|
/** 创建并返回代理对象(同一实例下保持稳定引用) */
|
|
110
144
|
createProxy() {
|
|
111
145
|
if (this._proxy) return this._proxy;
|