@nocobase/plugin-flow-engine 3.0.0-alpha.1 → 3.0.0-alpha.12

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 (53) hide show
  1. package/dist/externalVersion.js +9 -9
  2. package/dist/node_modules/@ant-design/icons-svg/package.json +1 -1
  3. package/dist/node_modules/acorn/package.json +1 -1
  4. package/dist/node_modules/acorn-jsx/package.json +1 -1
  5. package/dist/node_modules/acorn-walk/package.json +1 -1
  6. package/dist/node_modules/ses/package.json +1 -1
  7. package/dist/node_modules/zod/package.json +1 -1
  8. package/dist/server/flow-surfaces/builder.js +5 -0
  9. package/dist/server/flow-surfaces/catalog.js +27 -8
  10. package/dist/server/flow-surfaces/configure-options.js +17 -1
  11. package/dist/server/flow-surfaces/field-binding-registry.js +9 -8
  12. package/dist/server/flow-surfaces/navigation-targets.js +21 -40
  13. package/dist/server/flow-surfaces/service-utils.d.ts +1 -0
  14. package/dist/server/flow-surfaces/service-utils.js +17 -0
  15. package/dist/server/flow-surfaces/service.js +9 -0
  16. package/dist/server/index.d.ts +2 -0
  17. package/dist/server/index.js +7 -0
  18. package/dist/server/plugin.d.ts +13 -0
  19. package/dist/server/plugin.js +90 -3
  20. package/dist/server/repository.d.ts +12 -0
  21. package/dist/server/repository.js +39 -2
  22. package/dist/server/template/context-keys.d.ts +14 -0
  23. package/dist/server/template/context-keys.js +86 -0
  24. package/dist/server/template/contexts.d.ts +5 -8
  25. package/dist/server/template/contexts.js +43 -51
  26. package/dist/server/template/resolver.d.ts +5 -13
  27. package/dist/server/template/resolver.js +188 -257
  28. package/dist/server/template/variable-expression.d.ts +72 -0
  29. package/dist/server/template/variable-expression.js +597 -0
  30. package/dist/server/variables/allow-list.d.ts +49 -0
  31. package/dist/server/variables/allow-list.js +492 -0
  32. package/dist/server/variables/form-item-record-slot-resolvers.d.ts +10 -0
  33. package/dist/server/variables/form-item-record-slot-resolvers.js +280 -0
  34. package/dist/server/variables/record-bindings.d.ts +42 -0
  35. package/dist/server/variables/record-bindings.js +196 -0
  36. package/dist/server/variables/record-projection.d.ts +10 -0
  37. package/dist/server/variables/record-projection.js +140 -0
  38. package/dist/server/variables/record-slot-policy.d.ts +23 -0
  39. package/dist/server/variables/record-slot-policy.js +100 -0
  40. package/dist/server/variables/record-slot-resolvers.d.ts +46 -0
  41. package/dist/server/variables/record-slot-resolvers.js +115 -0
  42. package/dist/server/variables/records.d.ts +49 -2
  43. package/dist/server/variables/records.js +309 -18
  44. package/dist/server/variables/registry.d.ts +33 -10
  45. package/dist/server/variables/registry.js +197 -362
  46. package/dist/server/variables/resolve.d.ts +20 -2
  47. package/dist/server/variables/resolve.js +85 -13
  48. package/dist/server/variables/runjs-variable-dependencies.d.ts +23 -0
  49. package/dist/server/variables/runjs-variable-dependencies.js +407 -0
  50. package/dist/server/variables/selects.js +6 -3
  51. package/dist/server/variables/utils.d.ts +3 -6
  52. package/dist/server/variables/utils.js +50 -111
  53. package/package.json +2 -2
@@ -30,131 +30,70 @@ __export(utils_exports, {
30
30
  });
31
31
  module.exports = __toCommonJS(utils_exports);
32
32
  var import_registry = require("./registry");
33
- var import_selects = require("./selects");
34
33
  var import_records = require("./records");
35
- async function prefetchRecordsForResolve(koaCtx, items) {
36
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
34
+ async function prefetchRecordsForResolve(koaCtx, bindings) {
35
+ var _a, _b, _c, _d;
36
+ const log = (_b = (_a = koaCtx.app) == null ? void 0 : _a.logger) == null ? void 0 : _b.child({ module: "plugin-flow-engine", submodule: "variables.prefetch" });
37
37
  try {
38
- const log = (_b = (_a = koaCtx.app) == null ? void 0 : _a.logger) == null ? void 0 : _b.child({ module: "plugin-flow-engine", submodule: "variables.prefetch" });
39
- const groupMap = /* @__PURE__ */ new Map();
40
- const ensureGroup = (dataSourceKey, collection, filterByTk, strictSelects, opts) => {
41
- const groupKey = JSON.stringify({
42
- ds: dataSourceKey,
43
- collection,
44
- tk: filterByTk,
45
- f: Array.isArray(opts == null ? void 0 : opts.fields) ? [...opts.fields].sort() : void 0,
46
- a: Array.isArray(opts == null ? void 0 : opts.appends) ? [...opts.appends].sort() : void 0
38
+ const groups = /* @__PURE__ */ new Map();
39
+ for (const binding of bindings) {
40
+ if (!(0, import_registry.isSafeRecordBinding)(binding)) continue;
41
+ const target = (0, import_records.resolveRecordTarget)(koaCtx, binding.params);
42
+ if (!target) continue;
43
+ const strictSelects = Array.isArray(binding.params.fields) || Array.isArray(binding.params.appends);
44
+ const key = JSON.stringify({
45
+ ...target.cacheIdentity,
46
+ tk: binding.params.filterByTk,
47
+ strict: strictSelects,
48
+ f: strictSelects && binding.params.fields ? binding.params.fields.slice().sort() : void 0,
49
+ a: strictSelects && binding.params.appends ? binding.params.appends.slice().sort() : void 0
47
50
  });
48
- let group = groupMap.get(groupKey);
51
+ let group = groups.get(key);
49
52
  if (!group) {
50
53
  group = {
51
- dataSourceKey,
52
- collection,
53
- filterByTk,
54
- strictSelects,
54
+ appends: /* @__PURE__ */ new Set(),
55
55
  fields: /* @__PURE__ */ new Set(),
56
- appends: /* @__PURE__ */ new Set()
56
+ filterByTk: binding.params.filterByTk,
57
+ preferFullRecord: false,
58
+ strictSelects,
59
+ target
57
60
  };
58
- groupMap.set(groupKey, group);
59
- }
60
- return group;
61
- };
62
- const normalizeNestedSeg = (segment) => /^\d+$/.test(segment) ? `[${segment}]` : segment;
63
- for (const it of items) {
64
- const template = (it == null ? void 0 : it.template) ?? {};
65
- const contextParams = (it == null ? void 0 : it.contextParams) || {};
66
- const usage = import_registry.variables.extractUsage(template);
67
- for (const [cpKey, recordParams] of Object.entries(contextParams)) {
68
- const parts = String(cpKey).split(".");
69
- const varName = parts[0];
70
- const nestedSeg = parts.slice(1).join(".");
71
- const paths = (usage == null ? void 0 : usage[varName]) || [];
72
- if (!paths.length) continue;
73
- const segNorm = nestedSeg ? normalizeNestedSeg(nestedSeg) : "";
74
- const remainders = [];
75
- for (const p of paths) {
76
- if (!segNorm) remainders.push(p);
77
- else if (p === segNorm) remainders.push("");
78
- else if (p.startsWith(`${segNorm}.`) || p.startsWith(`${segNorm}[`))
79
- remainders.push(p.slice(segNorm.length + 1));
80
- }
81
- if (!remainders.length) continue;
82
- const dataSourceKey = (recordParams == null ? void 0 : recordParams.dataSourceKey) || "main";
83
- const collection = recordParams == null ? void 0 : recordParams.collection;
84
- const filterByTk = recordParams == null ? void 0 : recordParams.filterByTk;
85
- if (!collection || typeof filterByTk === "undefined") continue;
86
- const explicitFields = recordParams == null ? void 0 : recordParams.fields;
87
- const explicitAppends = recordParams == null ? void 0 : recordParams.appends;
88
- const hasExplicit = Array.isArray(explicitFields) || Array.isArray(explicitAppends);
89
- const group = ensureGroup(dataSourceKey, collection, filterByTk, hasExplicit, {
90
- fields: hasExplicit ? explicitFields : void 0,
91
- appends: hasExplicit ? explicitAppends : void 0
92
- });
93
- if (hasExplicit) {
94
- const fixed2 = (0, import_selects.adjustSelectsForCollection)(koaCtx, dataSourceKey, collection, explicitFields, explicitAppends);
95
- (_c = fixed2.fields) == null ? void 0 : _c.forEach((f) => group.fields.add(f));
96
- (_d = fixed2.appends) == null ? void 0 : _d.forEach((a) => group.appends.add(a));
97
- continue;
98
- }
99
- let { generatedAppends, generatedFields } = (0, import_registry.inferSelectsFromUsage)(remainders);
100
- const fixed = (0, import_selects.adjustSelectsForCollection)(koaCtx, dataSourceKey, collection, generatedFields, generatedAppends);
101
- generatedFields = fixed.fields;
102
- generatedAppends = fixed.appends;
103
- if (generatedFields == null ? void 0 : generatedFields.length) generatedFields.forEach((f) => group.fields.add(f));
104
- if (generatedAppends == null ? void 0 : generatedAppends.length) generatedAppends.forEach((a) => group.appends.add(a));
61
+ groups.set(key, group);
105
62
  }
63
+ const activeGroup = group;
64
+ activeGroup.preferFullRecord ||= binding.preferFullRecord || binding.relativePaths.some(
65
+ (path) => path.length === 0 || path.some((segment) => typeof segment === "string" && segment.includes("."))
66
+ );
67
+ const selects = strictSelects ? { generatedFields: binding.params.fields, generatedAppends: binding.params.appends } : (0, import_registry.inferSelectsFromUsage)(binding.relativePaths);
68
+ (_c = selects.generatedFields) == null ? void 0 : _c.forEach((field) => activeGroup.fields.add(field));
69
+ (_d = selects.generatedAppends) == null ? void 0 : _d.forEach((append) => activeGroup.appends.add(append));
106
70
  }
107
- if (!groupMap.size) return;
108
- const stateObj = koaCtx.state;
109
- if (stateObj && !stateObj["__varResolveBatchCache"]) {
110
- stateObj["__varResolveBatchCache"] = /* @__PURE__ */ new Map();
111
- }
112
- const cache = (_e = koaCtx.state) == null ? void 0 : _e["__varResolveBatchCache"];
113
- for (const { dataSourceKey, collection, filterByTk, strictSelects, fields, appends } of groupMap.values()) {
71
+ const cache = (0, import_records.getRecordRequestCache)(koaCtx);
72
+ for (const group of groups.values()) {
114
73
  try {
115
- const ds = koaCtx.app.dataSourceManager.get(dataSourceKey);
116
- const cm = ds.collectionManager;
117
- if (!(cm == null ? void 0 : cm.db)) continue;
118
- const repo = cm.db.getRepository(collection);
119
- const collectionInfo = repo == null ? void 0 : repo.collection;
120
- const filterTargetKey = collectionInfo == null ? void 0 : collectionInfo.filterTargetKey;
121
- const modelInfo = (_f = repo.collection) == null ? void 0 : _f.model;
122
- const pkAttr = modelInfo == null ? void 0 : modelInfo.primaryKeyAttribute;
123
- const rawAttributes = (modelInfo == null ? void 0 : modelInfo.rawAttributes) || void 0;
124
- const pkIsValid = !!(pkAttr && rawAttributes && Object.prototype.hasOwnProperty.call(rawAttributes, pkAttr));
125
- const fldBase = fields.size ? Array.from(fields).sort() : void 0;
126
- const extraKeys = (0, import_records.getExtraKeyFieldsForSelect)(filterByTk, {
127
- filterTargetKey,
128
- pkAttr,
129
- pkIsValid,
130
- rawAttributes
131
- });
132
- const effectiveExtras = strictSelects && Array.isArray(extraKeys) && extraKeys.length ? extraKeys.filter((k) => k === pkAttr) : extraKeys;
133
- const fld = (0, import_records.mergeFieldsWithExtras)(fldBase, effectiveExtras);
134
- const app = appends.size ? Array.from(appends).sort() : void 0;
135
- const json = await (0, import_records.fetchRecordOrRecordsJson)(repo, {
136
- filterByTk,
137
- fields: fld,
138
- appends: app,
139
- filterTargetKey,
140
- pkAttr,
141
- pkIsValid
142
- });
143
- if (cache) {
144
- const key = JSON.stringify({ ds: dataSourceKey, c: collection, tk: filterByTk, f: fld, a: app });
145
- cache.set(key, json);
146
- }
147
- } catch (e) {
74
+ const query = (0, import_records.prepareRecordQuery)(
75
+ koaCtx,
76
+ group.target,
77
+ group.filterByTk,
78
+ group.fields.size ? [...group.fields] : void 0,
79
+ group.appends.size ? [...group.appends] : void 0,
80
+ group.strictSelects,
81
+ group.preferFullRecord
82
+ );
83
+ if ((0, import_records.findRecordRequestCacheValue)(cache, query).hit) continue;
84
+ (0, import_records.setRecordRequestCache)(cache, query, await (0, import_records.fetchRecordOrRecordsJson)(query.repository, query, koaCtx));
85
+ } catch (error) {
148
86
  log == null ? void 0 : log.debug("[variables.resolve] prefetch query error", {
149
- ds: dataSourceKey,
150
- collection,
151
- tk: filterByTk,
152
- error: (e == null ? void 0 : e.message) || String(e)
87
+ ...group.target.cacheIdentity,
88
+ tk: group.filterByTk,
89
+ error: error instanceof Error ? error.message : String(error)
153
90
  });
154
91
  }
155
92
  }
156
- } catch (e) {
157
- (_i = (_h = (_g = koaCtx.app) == null ? void 0 : _g.logger) == null ? void 0 : _h.child({ module: "plugin-flow-engine", submodule: "variables.prefetch" })) == null ? void 0 : _i.debug("[variables.resolve] prefetch fatal error", { error: (e == null ? void 0 : e.message) || String(e) });
93
+ } catch (error) {
94
+ log == null ? void 0 : log.debug("[variables.resolve] prefetch fatal error", {
95
+ error: error instanceof Error ? error.message : String(error)
96
+ });
158
97
  }
159
98
  }
160
99
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "前端流引擎",
5
5
  "description": "",
6
6
  "description.zh-CN": "",
7
- "version": "3.0.0-alpha.1",
7
+ "version": "3.0.0-alpha.12",
8
8
  "main": "./dist/server/index.js",
9
9
  "license": "Apache-2.0",
10
10
  "devDependencies": {
@@ -26,5 +26,5 @@
26
26
  "@nocobase/test": "2.x",
27
27
  "@nocobase/utils": "2.x"
28
28
  },
29
- "gitHead": "22d8be8ece179cfa5c8a4ebb2c896c92bd418e03"
29
+ "gitHead": "2ba035885741a9977d76bbabf8f2caf44b199139"
30
30
  }