@nocobase/plugin-flow-engine 2.0.0-alpha.5 → 2.0.0-alpha.51
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/externalVersion.js +9 -9
- package/dist/locale/de-DE.json +63 -0
- package/dist/locale/en-US.json +47 -45
- package/dist/locale/es-ES.json +63 -0
- package/dist/locale/fr-FR.json +63 -0
- package/dist/locale/hu-HU.json +63 -0
- package/dist/locale/id-ID.json +63 -0
- package/dist/locale/index.d.ts +94 -90
- package/dist/locale/it-IT.json +63 -0
- package/dist/locale/ja-JP.json +63 -0
- package/dist/locale/ko-KR.json +63 -0
- package/dist/locale/nl-NL.json +63 -0
- package/dist/locale/pt-BR.json +63 -0
- package/dist/locale/ru-RU.json +63 -0
- package/dist/locale/tr-TR.json +63 -0
- package/dist/locale/uk-UA.json +63 -0
- package/dist/locale/vi-VN.json +63 -0
- package/dist/locale/zh-CN.json +47 -45
- package/dist/locale/zh-TW.json +63 -0
- package/dist/node_modules/ses/package.json +1 -1
- package/dist/server/collections/flowsql.js +1 -0
- package/dist/server/plugin.d.ts +0 -5
- package/dist/server/plugin.js +17 -98
- package/dist/server/repository.d.ts +3 -1
- package/dist/server/repository.js +74 -8
- package/dist/server/server.js +7 -0
- package/dist/server/variables/registry.d.ts +10 -0
- package/dist/server/variables/registry.js +196 -61
- package/dist/server/variables/selects.d.ts +19 -0
- package/dist/server/variables/selects.js +80 -0
- package/dist/server/variables/utils.d.ts +17 -0
- package/dist/server/variables/utils.js +123 -0
- package/package.json +2 -2
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var utils_exports = {};
|
|
28
|
+
__export(utils_exports, {
|
|
29
|
+
prefetchRecordsForResolve: () => prefetchRecordsForResolve
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(utils_exports);
|
|
32
|
+
var import_registry = require("./registry");
|
|
33
|
+
var import_selects = require("./selects");
|
|
34
|
+
async function prefetchRecordsForResolve(koaCtx, items) {
|
|
35
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
36
|
+
try {
|
|
37
|
+
const log = (_b = (_a = koaCtx.app) == null ? void 0 : _a.logger) == null ? void 0 : _b.child({ module: "plugin-flow-engine", submodule: "variables.prefetch" });
|
|
38
|
+
const groupMap = /* @__PURE__ */ new Map();
|
|
39
|
+
const ensureGroup = (dataSourceKey, collection, filterByTk) => {
|
|
40
|
+
const groupKey = JSON.stringify({ ds: dataSourceKey, collection, tk: filterByTk });
|
|
41
|
+
let group = groupMap.get(groupKey);
|
|
42
|
+
if (!group) {
|
|
43
|
+
group = { dataSourceKey, collection, filterByTk, fields: /* @__PURE__ */ new Set(), appends: /* @__PURE__ */ new Set() };
|
|
44
|
+
groupMap.set(groupKey, group);
|
|
45
|
+
}
|
|
46
|
+
return group;
|
|
47
|
+
};
|
|
48
|
+
const normalizeNestedSeg = (segment) => /^\d+$/.test(segment) ? `[${segment}]` : segment;
|
|
49
|
+
for (const it of items) {
|
|
50
|
+
const template = (it == null ? void 0 : it.template) ?? {};
|
|
51
|
+
const contextParams = (it == null ? void 0 : it.contextParams) || {};
|
|
52
|
+
const usage = import_registry.variables.extractUsage(template);
|
|
53
|
+
for (const [cpKey, recordParams] of Object.entries(contextParams)) {
|
|
54
|
+
const parts = String(cpKey).split(".");
|
|
55
|
+
const varName = parts[0];
|
|
56
|
+
const nestedSeg = parts.slice(1).join(".");
|
|
57
|
+
const paths = (usage == null ? void 0 : usage[varName]) || [];
|
|
58
|
+
if (!paths.length) continue;
|
|
59
|
+
const segNorm = nestedSeg ? normalizeNestedSeg(nestedSeg) : "";
|
|
60
|
+
const remainders = [];
|
|
61
|
+
for (const p of paths) {
|
|
62
|
+
if (!segNorm) remainders.push(p);
|
|
63
|
+
else if (p === segNorm) remainders.push("");
|
|
64
|
+
else if (p.startsWith(`${segNorm}.`) || p.startsWith(`${segNorm}[`))
|
|
65
|
+
remainders.push(p.slice(segNorm.length + 1));
|
|
66
|
+
}
|
|
67
|
+
if (!remainders.length) continue;
|
|
68
|
+
const dataSourceKey = (recordParams == null ? void 0 : recordParams.dataSourceKey) || "main";
|
|
69
|
+
const collection = recordParams == null ? void 0 : recordParams.collection;
|
|
70
|
+
const filterByTk = recordParams == null ? void 0 : recordParams.filterByTk;
|
|
71
|
+
if (!collection || typeof filterByTk === "undefined") continue;
|
|
72
|
+
const group = ensureGroup(dataSourceKey, collection, filterByTk);
|
|
73
|
+
let { generatedAppends, generatedFields } = (0, import_registry.inferSelectsFromUsage)(remainders);
|
|
74
|
+
const fixed = (0, import_selects.adjustSelectsForCollection)(koaCtx, dataSourceKey, collection, generatedFields, generatedAppends);
|
|
75
|
+
generatedFields = fixed.fields;
|
|
76
|
+
generatedAppends = fixed.appends;
|
|
77
|
+
if (generatedFields == null ? void 0 : generatedFields.length) generatedFields.forEach((f) => group.fields.add(f));
|
|
78
|
+
if (generatedAppends == null ? void 0 : generatedAppends.length) generatedAppends.forEach((a) => group.appends.add(a));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!groupMap.size) return;
|
|
82
|
+
const stateObj = koaCtx.state;
|
|
83
|
+
if (stateObj && !stateObj["__varResolveBatchCache"]) {
|
|
84
|
+
stateObj["__varResolveBatchCache"] = /* @__PURE__ */ new Map();
|
|
85
|
+
}
|
|
86
|
+
const cache = (_c = koaCtx.state) == null ? void 0 : _c["__varResolveBatchCache"];
|
|
87
|
+
for (const { dataSourceKey, collection, filterByTk, fields, appends } of groupMap.values()) {
|
|
88
|
+
try {
|
|
89
|
+
const ds = koaCtx.app.dataSourceManager.get(dataSourceKey);
|
|
90
|
+
const cm = ds.collectionManager;
|
|
91
|
+
if (!(cm == null ? void 0 : cm.db)) continue;
|
|
92
|
+
const repo = cm.db.getRepository(collection);
|
|
93
|
+
const modelInfo = (_d = repo.collection) == null ? void 0 : _d.model;
|
|
94
|
+
const pkAttr = modelInfo == null ? void 0 : modelInfo.primaryKeyAttribute;
|
|
95
|
+
const pkIsValid = pkAttr && (modelInfo == null ? void 0 : modelInfo.rawAttributes) && Object.prototype.hasOwnProperty.call(modelInfo.rawAttributes, pkAttr);
|
|
96
|
+
if (fields.size && pkIsValid) {
|
|
97
|
+
fields.add(pkAttr);
|
|
98
|
+
}
|
|
99
|
+
const fld = fields.size ? Array.from(fields).sort() : void 0;
|
|
100
|
+
const app = appends.size ? Array.from(appends).sort() : void 0;
|
|
101
|
+
const rec = await repo.findOne({ filterByTk, fields: fld, appends: app });
|
|
102
|
+
const json = rec ? rec.toJSON() : void 0;
|
|
103
|
+
if (cache) {
|
|
104
|
+
const key = JSON.stringify({ ds: dataSourceKey, c: collection, tk: filterByTk, f: fld, a: app });
|
|
105
|
+
cache.set(key, json);
|
|
106
|
+
}
|
|
107
|
+
} catch (e) {
|
|
108
|
+
log == null ? void 0 : log.debug("[variables.resolve] prefetch query error", {
|
|
109
|
+
ds: dataSourceKey,
|
|
110
|
+
collection,
|
|
111
|
+
tk: filterByTk,
|
|
112
|
+
error: (e == null ? void 0 : e.message) || String(e)
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
} catch (e) {
|
|
117
|
+
(_g = (_f = (_e = koaCtx.app) == null ? void 0 : _e.logger) == null ? void 0 : _f.child({ module: "plugin-flow-engine", submodule: "variables.prefetch" })) == null ? void 0 : _g.debug("[variables.resolve] prefetch fatal error", { error: (e == null ? void 0 : e.message) || String(e) });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
121
|
+
0 && (module.exports = {
|
|
122
|
+
prefetchRecordsForResolve
|
|
123
|
+
});
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName.zh-CN": "前端流引擎",
|
|
5
5
|
"description": "",
|
|
6
6
|
"description.zh-CN": "",
|
|
7
|
-
"version": "2.0.0-alpha.
|
|
7
|
+
"version": "2.0.0-alpha.51",
|
|
8
8
|
"main": "./dist/server/index.js",
|
|
9
9
|
"license": "AGPL-3.0",
|
|
10
10
|
"devDependencies": {
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"@nocobase/test": "2.x",
|
|
25
25
|
"@nocobase/utils": "2.x"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "a1e34dd97f370d54f3d80a6b83ab7ddb9c72dc18"
|
|
28
28
|
}
|