@nocobase/plugin-flow-engine 2.0.0-beta.10 → 2.0.0-beta.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.
@@ -8,14 +8,14 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "2.0.0-beta.10",
11
+ "@nocobase/client": "2.0.0-beta.12",
12
12
  "lodash": "4.17.21",
13
- "@nocobase/database": "2.0.0-beta.10",
14
- "@nocobase/data-source-manager": "2.0.0-beta.10",
15
- "@nocobase/resourcer": "2.0.0-beta.10",
16
- "@nocobase/server": "2.0.0-beta.10",
17
- "@nocobase/utils": "2.0.0-beta.10",
18
- "@nocobase/cache": "2.0.0-beta.10",
19
- "@nocobase/plugin-localization": "2.0.0-beta.10",
20
- "@nocobase/actions": "2.0.0-beta.10"
13
+ "@nocobase/database": "2.0.0-beta.12",
14
+ "@nocobase/data-source-manager": "2.0.0-beta.12",
15
+ "@nocobase/resourcer": "2.0.0-beta.12",
16
+ "@nocobase/server": "2.0.0-beta.12",
17
+ "@nocobase/utils": "2.0.0-beta.12",
18
+ "@nocobase/cache": "2.0.0-beta.12",
19
+ "@nocobase/plugin-localization": "2.0.0-beta.12",
20
+ "@nocobase/actions": "2.0.0-beta.12"
21
21
  };
@@ -1 +1 @@
1
- {"name":"ses","version":"1.14.0","description":"Hardened JavaScript for Fearless Cooperation","keywords":["lockdown","harden","Compartment","assert","security","confinement","isolation","object capabilities","ocaps","secure execution","third-party code","prototype pollution","supply-chain attack","plugin"],"author":"Agoric","license":"Apache-2.0","homepage":"https://github.com/Agoric/SES-shim/tree/master/packages/ses#readme","repository":{"type":"git","url":"git+https://github.com/endojs/endo.git","directory":"packages/ses"},"bugs":{"url":"https://github.com/endojs/endo/issues"},"type":"module","main":"./dist/ses.cjs","module":"./index.js","unpkg":"./dist/ses.umd.js","types":"./types.d.ts","exports":{".":{"import":{"types":"./types.d.ts","xs":"./src-xs/index.js","default":"./index.js"},"require":{"types":"./dist/types.d.cts","default":"./dist/ses.cjs"}},"./lockdown":{"import":{"types":"./types.d.ts","default":"./index.js"},"require":{"types":"./dist/types.d.cts","default":"./dist/ses.cjs"}},"./hermes":{"require":{"types":"./dist/types.d.cts","default":"./dist/ses-hermes.cjs"}},"./tools.js":"./tools.js","./assert-shim.js":"./assert-shim.js","./lockdown-shim.js":{"xs":"./src-xs/lockdown-shim.js","default":"./lockdown-shim.js"},"./compartment-shim.js":{"xs":"./src-xs/compartment-shim.js","default":"./compartment-shim.js"},"./console-shim.js":"./console-shim.js","./package.json":"./package.json"},"scripts":{"build:vanilla":"node scripts/bundle.js","build:hermes":"node scripts/bundle.js hermes","build":"yarn build:vanilla && yarn build:hermes","clean":"rm -rf dist","cover":"c8 ava","demo":"python3 -m http.server","lint":"yarn lint:types && yarn lint:eslint","lint-fix":"eslint --fix .","lint:eslint":"eslint .","lint:types":"tsc","prepare":"npm run clean && npm run build","qt":"ava","test":"tsd && ava","test:hermes":"./scripts/hermes-test.sh","test:xs":"xst dist/ses.umd.js test/_lockdown-safe.js && node scripts/generate-test-xs.js && xst tmp/test-xs.js && rm -rf tmp","postpack":"git clean -fX \"*.d.ts*\" \"*.d.cts*\" \"*.d.mts*\" \"*.tsbuildinfo\""},"dependencies":{"@endo/cache-map":"^1.1.0","@endo/env-options":"^1.1.11","@endo/immutable-arraybuffer":"^1.1.2"},"devDependencies":{"@babel/generator":"^7.26.3","@babel/parser":"~7.26.2","@babel/traverse":"~7.25.9","@babel/types":"~7.26.0","@endo/compartment-mapper":"^1.6.3","@endo/module-source":"^1.3.3","@endo/test262-runner":"^0.1.48","@types/babel__traverse":"^7.20.5","ava":"^6.1.3","babel-eslint":"^10.1.0","c8":"^7.14.0","core-js":"^3.31.0","eslint":"^8.57.1","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^9.1.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.31.0","hermes-engine-cli":"^0.12.0","prettier":"^3.5.3","terser":"^5.16.6","tsd":"^0.31.2","typescript":"~5.8.3"},"files":["./*.d.ts","./*.js","./*.map","LICENSE*","SECURITY*","dist","lib","src","tools"],"publishConfig":{"access":"public"},"eslintConfig":{"extends":["plugin:@endo/ses"]},"ava":{"files":["test/**/*.test.*"],"timeout":"2m"},"typeCoverage":{"atLeast":81.17},"gitHead":"9815aea9541f241389d2135c6097a7442bdffa17","_lastModified":"2026-01-14T02:29:50.432Z"}
1
+ {"name":"ses","version":"1.14.0","description":"Hardened JavaScript for Fearless Cooperation","keywords":["lockdown","harden","Compartment","assert","security","confinement","isolation","object capabilities","ocaps","secure execution","third-party code","prototype pollution","supply-chain attack","plugin"],"author":"Agoric","license":"Apache-2.0","homepage":"https://github.com/Agoric/SES-shim/tree/master/packages/ses#readme","repository":{"type":"git","url":"git+https://github.com/endojs/endo.git","directory":"packages/ses"},"bugs":{"url":"https://github.com/endojs/endo/issues"},"type":"module","main":"./dist/ses.cjs","module":"./index.js","unpkg":"./dist/ses.umd.js","types":"./types.d.ts","exports":{".":{"import":{"types":"./types.d.ts","xs":"./src-xs/index.js","default":"./index.js"},"require":{"types":"./dist/types.d.cts","default":"./dist/ses.cjs"}},"./lockdown":{"import":{"types":"./types.d.ts","default":"./index.js"},"require":{"types":"./dist/types.d.cts","default":"./dist/ses.cjs"}},"./hermes":{"require":{"types":"./dist/types.d.cts","default":"./dist/ses-hermes.cjs"}},"./tools.js":"./tools.js","./assert-shim.js":"./assert-shim.js","./lockdown-shim.js":{"xs":"./src-xs/lockdown-shim.js","default":"./lockdown-shim.js"},"./compartment-shim.js":{"xs":"./src-xs/compartment-shim.js","default":"./compartment-shim.js"},"./console-shim.js":"./console-shim.js","./package.json":"./package.json"},"scripts":{"build:vanilla":"node scripts/bundle.js","build:hermes":"node scripts/bundle.js hermes","build":"yarn build:vanilla && yarn build:hermes","clean":"rm -rf dist","cover":"c8 ava","demo":"python3 -m http.server","lint":"yarn lint:types && yarn lint:eslint","lint-fix":"eslint --fix .","lint:eslint":"eslint .","lint:types":"tsc","prepare":"npm run clean && npm run build","qt":"ava","test":"tsd && ava","test:hermes":"./scripts/hermes-test.sh","test:xs":"xst dist/ses.umd.js test/_lockdown-safe.js && node scripts/generate-test-xs.js && xst tmp/test-xs.js && rm -rf tmp","postpack":"git clean -fX \"*.d.ts*\" \"*.d.cts*\" \"*.d.mts*\" \"*.tsbuildinfo\""},"dependencies":{"@endo/cache-map":"^1.1.0","@endo/env-options":"^1.1.11","@endo/immutable-arraybuffer":"^1.1.2"},"devDependencies":{"@babel/generator":"^7.26.3","@babel/parser":"~7.26.2","@babel/traverse":"~7.25.9","@babel/types":"~7.26.0","@endo/compartment-mapper":"^1.6.3","@endo/module-source":"^1.3.3","@endo/test262-runner":"^0.1.48","@types/babel__traverse":"^7.20.5","ava":"^6.1.3","babel-eslint":"^10.1.0","c8":"^7.14.0","core-js":"^3.31.0","eslint":"^8.57.1","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^9.1.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.31.0","hermes-engine-cli":"^0.12.0","prettier":"^3.5.3","terser":"^5.16.6","tsd":"^0.31.2","typescript":"~5.8.3"},"files":["./*.d.ts","./*.js","./*.map","LICENSE*","SECURITY*","dist","lib","src","tools"],"publishConfig":{"access":"public"},"eslintConfig":{"extends":["plugin:@endo/ses"]},"ava":{"files":["test/**/*.test.*"],"timeout":"2m"},"typeCoverage":{"atLeast":81.17},"gitHead":"9815aea9541f241389d2135c6097a7442bdffa17","_lastModified":"2026-01-16T01:59:26.562Z"}
@@ -0,0 +1,38 @@
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
+ type FilterTargetKey = string | string[] | undefined;
10
+ /**
11
+ * 为了:
12
+ * - 关联加载/缓存:fields 模式下确保包含主键
13
+ * - filterByTk 为数组时:尽量包含 filterTargetKey,以便按输入顺序对齐结果
14
+ *
15
+ * 该函数只返回“建议追加”的 key 字段(不会决定是否追加,由调用方根据是否启用 fields 决定)。
16
+ */
17
+ export declare function getExtraKeyFieldsForSelect(filterByTk: unknown, options: {
18
+ filterTargetKey?: FilterTargetKey;
19
+ pkAttr?: string;
20
+ pkIsValid?: boolean;
21
+ rawAttributes?: Record<string, unknown>;
22
+ }): string[];
23
+ export declare function mergeFieldsWithExtras(fields?: string[], extras?: string[]): string[] | undefined;
24
+ /**
25
+ * 根据 filterByTk 类型(单值/数组)查询并返回 JSON 数据:
26
+ * - 单值:返回 object | undefined
27
+ * - 数组:返回 array(空数组时返回 [],不会退化为无条件查询)
28
+ */
29
+ export declare function fetchRecordOrRecordsJson(repo: any, params: {
30
+ filterByTk: unknown;
31
+ preferFullRecord?: boolean;
32
+ fields?: string[];
33
+ appends?: string[];
34
+ filterTargetKey?: FilterTargetKey;
35
+ pkAttr?: string;
36
+ pkIsValid?: boolean;
37
+ }): Promise<unknown>;
38
+ export {};
@@ -0,0 +1,120 @@
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 records_exports = {};
28
+ __export(records_exports, {
29
+ fetchRecordOrRecordsJson: () => fetchRecordOrRecordsJson,
30
+ getExtraKeyFieldsForSelect: () => getExtraKeyFieldsForSelect,
31
+ mergeFieldsWithExtras: () => mergeFieldsWithExtras
32
+ });
33
+ module.exports = __toCommonJS(records_exports);
34
+ function uniqStrings(list) {
35
+ return Array.from(new Set(list));
36
+ }
37
+ function isPrimitiveTkArray(arr) {
38
+ return arr.every((v) => typeof v === "string" || typeof v === "number");
39
+ }
40
+ function getOrderKey(options) {
41
+ if (typeof options.filterTargetKey === "string") return options.filterTargetKey;
42
+ if (options.pkIsValid && options.pkAttr) return options.pkAttr;
43
+ return void 0;
44
+ }
45
+ function getExtraKeyFieldsForSelect(filterByTk, options) {
46
+ const extra = [];
47
+ if (options.pkIsValid && options.pkAttr) {
48
+ extra.push(options.pkAttr);
49
+ }
50
+ if (Array.isArray(filterByTk) && filterByTk.length > 0) {
51
+ const tkKeys = typeof options.filterTargetKey === "string" ? [options.filterTargetKey] : Array.isArray(options.filterTargetKey) ? options.filterTargetKey : [];
52
+ if (options.rawAttributes) {
53
+ for (const k of tkKeys) {
54
+ if (k && Object.prototype.hasOwnProperty.call(options.rawAttributes, k)) {
55
+ extra.push(k);
56
+ }
57
+ }
58
+ }
59
+ }
60
+ return uniqStrings(extra);
61
+ }
62
+ function mergeFieldsWithExtras(fields, extras = []) {
63
+ if (!Array.isArray(fields) || fields.length === 0 || extras.length === 0) return fields;
64
+ return uniqStrings([...fields, ...extras]);
65
+ }
66
+ function toJsonArray(rows) {
67
+ if (!Array.isArray(rows)) return [];
68
+ return rows.map((r) => (r == null ? void 0 : r.toJSON) ? r.toJSON() : r);
69
+ }
70
+ function reorderRecordsByFilterByTk(records, filterByTk, options) {
71
+ if (!Array.isArray(filterByTk) || filterByTk.length === 0) return records;
72
+ if (!isPrimitiveTkArray(filterByTk)) return records;
73
+ const orderKey = getOrderKey(options);
74
+ if (!orderKey) return records;
75
+ const map = /* @__PURE__ */ new Map();
76
+ for (const rec of records || []) {
77
+ const k = rec == null ? void 0 : rec[orderKey];
78
+ if (typeof k !== "undefined" && k !== null) {
79
+ map.set(String(k), rec);
80
+ }
81
+ }
82
+ const ordered = [];
83
+ const used = /* @__PURE__ */ new Set();
84
+ for (const tk of filterByTk) {
85
+ const k = String(tk);
86
+ const rec = map.get(k);
87
+ if (typeof rec !== "undefined") {
88
+ ordered.push(rec);
89
+ used.add(k);
90
+ }
91
+ }
92
+ for (const rec of records || []) {
93
+ const k = rec == null ? void 0 : rec[orderKey];
94
+ const ks = typeof k === "undefined" || k === null ? void 0 : String(k);
95
+ if (!ks || used.has(ks)) continue;
96
+ ordered.push(rec);
97
+ }
98
+ return ordered;
99
+ }
100
+ async function fetchRecordOrRecordsJson(repo, params) {
101
+ const { filterByTk, preferFullRecord, fields, appends } = params;
102
+ if (Array.isArray(filterByTk)) {
103
+ if (filterByTk.length === 0) return [];
104
+ const rows = await repo.find(
105
+ preferFullRecord ? { filterByTk } : { filterByTk, fields, appends }
106
+ );
107
+ const jsonArr = toJsonArray(rows);
108
+ return reorderRecordsByFilterByTk(jsonArr, filterByTk, params);
109
+ }
110
+ const rec = await repo.findOne(
111
+ preferFullRecord ? { filterByTk } : { filterByTk, fields, appends }
112
+ );
113
+ return rec ? rec.toJSON() : void 0;
114
+ }
115
+ // Annotate the CommonJS export names for ESM import in node:
116
+ 0 && (module.exports = {
117
+ fetchRecordOrRecordsJson,
118
+ getExtraKeyFieldsForSelect,
119
+ mergeFieldsWithExtras
120
+ });
@@ -129,7 +129,7 @@ function inferSelectsFromUsage(paths = [], _params) {
129
129
  const generatedFields = fieldSet.size ? Array.from(fieldSet) : void 0;
130
130
  return { generatedAppends, generatedFields };
131
131
  }
132
- async function fetchRecordWithRequestCache(koaCtx, dataSourceKey, collection, filterByTk, fields, appends, preferFullRecord, associationName, sourceId) {
132
+ async function fetchRecordWithRequestCache(koaCtx, dataSourceKey, collection, filterByTk, fields, appends, strictSelects, preferFullRecord, associationName, sourceId) {
133
133
  var _a, _b, _c, _d, _e;
134
134
  try {
135
135
  const log = (_b = (_a = koaCtx.app) == null ? void 0 : _a.logger) == null ? void 0 : _b.child({
@@ -168,27 +168,29 @@ async function fetchRecordWithRequestCache(koaCtx, dataSourceKey, collection, fi
168
168
  if (cache.has(key)) {
169
169
  return cache.get(key);
170
170
  }
171
- const needFields = !preferFullRecord && Array.isArray(fieldsWithPk) ? [...new Set(fieldsWithPk)] : void 0;
172
- const needAppends = !preferFullRecord && Array.isArray(appends) ? new Set(appends) : void 0;
173
- for (const [cacheKey, cacheVal] of cache.entries()) {
174
- const parsed = JSON.parse(cacheKey);
175
- if (!parsed || parsed.ds !== keyObj.ds || parsed.c !== keyObj.c || parsed.tk !== keyObj.tk || parsed.assoc !== keyObj.assoc || parsed.sid !== keyObj.sid)
176
- continue;
177
- const cachedFields = new Set(parsed.f || []);
178
- const cachedAppends = new Set(parsed.a || []);
179
- const fieldCoveredByAppends = (fieldPath) => {
180
- const p = String(fieldPath || "");
181
- for (const a of cachedAppends) {
182
- if (!a) continue;
183
- if (p === a || p.startsWith(a + ".")) return true;
171
+ if (!strictSelects) {
172
+ const needFields = !preferFullRecord && Array.isArray(fieldsWithPk) ? [...new Set(fieldsWithPk)] : void 0;
173
+ const needAppends = !preferFullRecord && Array.isArray(appends) ? new Set(appends) : void 0;
174
+ for (const [cacheKey, cacheVal] of cache.entries()) {
175
+ const parsed = JSON.parse(cacheKey);
176
+ if (!parsed || parsed.ds !== keyObj.ds || parsed.c !== keyObj.c || parsed.tk !== keyObj.tk || parsed.assoc !== keyObj.assoc || parsed.sid !== keyObj.sid)
177
+ continue;
178
+ const cachedFields = new Set(parsed.f || []);
179
+ const cachedAppends = new Set(parsed.a || []);
180
+ const fieldCoveredByAppends = (fieldPath) => {
181
+ const p = String(fieldPath || "");
182
+ for (const a of cachedAppends) {
183
+ if (!a) continue;
184
+ if (p === a || p.startsWith(a + ".")) return true;
185
+ }
186
+ return false;
187
+ };
188
+ const fieldsOk = needFields ? needFields.every((f) => cachedFields.has(f) || fieldCoveredByAppends(f)) : parsed.f === void 0;
189
+ const appendsOk = !needAppends || [...needAppends].every((a) => cachedAppends.has(a));
190
+ const fullOk = preferFullRecord ? parsed.full === true : true;
191
+ if (fieldsOk && appendsOk && fullOk) {
192
+ return cacheVal;
184
193
  }
185
- return false;
186
- };
187
- const fieldsOk = needFields ? needFields.every((f) => cachedFields.has(f) || fieldCoveredByAppends(f)) : parsed.f === void 0;
188
- const appendsOk = !needAppends || [...needAppends].every((a) => cachedAppends.has(a));
189
- const fullOk = preferFullRecord ? parsed.full === true : true;
190
- if (fieldsOk && appendsOk && fullOk) {
191
- return cacheVal;
192
194
  }
193
195
  }
194
196
  }
@@ -233,12 +235,37 @@ function attachGenericRecordVariables(flowCtx, koaCtx, usage, contextParams) {
233
235
  for (const varName of Object.keys(usage)) {
234
236
  const usedPaths = usage[varName] || [];
235
237
  const topParams = import_lodash.default.get(contextParams, varName);
238
+ const deepRecordMap = /* @__PURE__ */ new Map();
239
+ const cp = contextParams;
240
+ if (cp && typeof cp === "object") {
241
+ const cpRec = cp;
242
+ for (const key of Object.keys(cpRec)) {
243
+ if (!key || key !== varName && !key.startsWith(`${varName}.`)) continue;
244
+ if (key === varName) continue;
245
+ const val = cpRec[key];
246
+ if (!isRecordParams(val)) continue;
247
+ const relative = key.slice(varName.length + 1);
248
+ if (!relative) continue;
249
+ deepRecordMap.set(relative, val);
250
+ }
251
+ }
236
252
  if (isRecordParams(topParams)) {
237
- const { generatedAppends, generatedFields } = inferSelectsFromUsage(usedPaths, topParams);
238
- const hasDirectRefTop = (usedPaths || []).some((p) => p === "");
253
+ const usedPathsForBase = deepRecordMap.size ? (usedPaths || []).filter((p) => {
254
+ if (!p) return true;
255
+ for (const relative of deepRecordMap.keys()) {
256
+ if (!relative) continue;
257
+ if (p === relative || p.startsWith(relative + ".") || p.startsWith(relative + "[")) return false;
258
+ }
259
+ return true;
260
+ }) : usedPaths || [];
261
+ const hasDirectRefTop = usedPathsForBase.some((p) => p === "");
239
262
  flowCtx.defineProperty(varName, {
240
263
  get: async () => {
241
264
  const dataSourceKey = (topParams == null ? void 0 : topParams.dataSourceKey) || "main";
265
+ const strictSelects = Array.isArray(topParams == null ? void 0 : topParams.fields) || Array.isArray(topParams == null ? void 0 : topParams.appends);
266
+ let { generatedAppends, generatedFields } = inferSelectsFromUsage(usedPathsForBase, topParams);
267
+ if (Array.isArray(topParams == null ? void 0 : topParams.fields)) generatedFields = topParams.fields;
268
+ if (Array.isArray(topParams == null ? void 0 : topParams.appends)) generatedAppends = topParams.appends;
242
269
  const fixed = (0, import_selects.adjustSelectsForCollection)(
243
270
  koaCtx,
244
271
  dataSourceKey,
@@ -246,17 +273,69 @@ function attachGenericRecordVariables(flowCtx, koaCtx, usage, contextParams) {
246
273
  generatedFields,
247
274
  generatedAppends
248
275
  );
249
- return await fetchRecordWithRequestCache(
276
+ const base = await fetchRecordWithRequestCache(
250
277
  koaCtx,
251
278
  dataSourceKey,
252
279
  topParams.collection,
253
280
  topParams.filterByTk,
254
281
  fixed.fields,
255
282
  fixed.appends,
283
+ strictSelects,
256
284
  hasDirectRefTop,
257
285
  topParams.associationName,
258
286
  topParams.sourceId
259
287
  );
288
+ if (!deepRecordMap.size) return base;
289
+ const merged = base && typeof base === "object" && !Array.isArray(base) ? { ...base } : {};
290
+ const setClonedPath = (obj, path, value) => {
291
+ const segs = String(path || "").split(".").filter(Boolean);
292
+ if (!segs.length) return;
293
+ if (segs.length === 1) {
294
+ obj[segs[0]] = value;
295
+ return;
296
+ }
297
+ let cur = obj;
298
+ for (let i = 0; i < segs.length - 1; i++) {
299
+ const seg = segs[i];
300
+ const prev = cur[seg];
301
+ const next = prev && typeof prev === "object" && !Array.isArray(prev) ? { ...prev } : {};
302
+ cur[seg] = next;
303
+ cur = next;
304
+ }
305
+ cur[segs[segs.length - 1]] = value;
306
+ };
307
+ const buildNestedPromise = (recordParams, relative) => {
308
+ const subPaths = (usedPaths || []).map((p) => p === relative ? "" : p.startsWith(relative + ".") ? p.slice(relative.length + 1) : "").filter((x) => x !== "");
309
+ const hasDirectRef = (usedPaths || []).some((p) => p === relative);
310
+ const dataSourceKey2 = (recordParams == null ? void 0 : recordParams.dataSourceKey) || "main";
311
+ const strictSelects2 = Array.isArray(recordParams == null ? void 0 : recordParams.fields) || Array.isArray(recordParams == null ? void 0 : recordParams.appends);
312
+ let { generatedAppends: generatedAppends2, generatedFields: generatedFields2 } = inferSelectsFromUsage(subPaths, recordParams);
313
+ if (Array.isArray(recordParams == null ? void 0 : recordParams.fields)) generatedFields2 = recordParams.fields;
314
+ if (Array.isArray(recordParams == null ? void 0 : recordParams.appends)) generatedAppends2 = recordParams.appends;
315
+ const fixed2 = (0, import_selects.adjustSelectsForCollection)(
316
+ koaCtx,
317
+ dataSourceKey2,
318
+ recordParams.collection,
319
+ generatedFields2,
320
+ generatedAppends2
321
+ );
322
+ return fetchRecordWithRequestCache(
323
+ koaCtx,
324
+ dataSourceKey2,
325
+ recordParams.collection,
326
+ recordParams.filterByTk,
327
+ fixed2.fields,
328
+ fixed2.appends,
329
+ strictSelects2,
330
+ hasDirectRef,
331
+ recordParams.associationName,
332
+ recordParams.sourceId
333
+ );
334
+ };
335
+ for (const [relative, recordParams] of deepRecordMap.entries()) {
336
+ setClonedPath(merged, relative, buildNestedPromise(recordParams, relative));
337
+ }
338
+ return merged;
260
339
  },
261
340
  cache: true
262
341
  });
@@ -295,27 +374,16 @@ function attachGenericRecordVariables(flowCtx, koaCtx, usage, contextParams) {
295
374
  const dotted = (contextParams || {})[`${varName}.${seg}`] ?? (idx ? (contextParams || {})[`${varName}.${idx}`] : void 0);
296
375
  return isRecordParams(nestedObj) || isRecordParams(dotted);
297
376
  });
298
- const deepRecordMap = /* @__PURE__ */ new Map();
299
- const cp = contextParams;
300
- if (cp && typeof cp === "object") {
301
- const cpRec = cp;
302
- for (const key of Object.keys(cpRec)) {
303
- if (!key || key !== varName && !key.startsWith(`${varName}.`)) continue;
304
- if (key === varName) continue;
305
- const val = cpRec[key];
306
- if (!isRecordParams(val)) continue;
307
- const relative = key.slice(varName.length + 1);
308
- if (!relative) continue;
309
- deepRecordMap.set(relative, val);
310
- }
311
- }
312
377
  if (!oneLevelRecordChildren.length && deepRecordMap.size === 0) continue;
313
378
  flowCtx.defineProperty(varName, {
314
379
  get: () => {
315
380
  const root = new import_contexts.ServerBaseContext();
316
381
  const definedFirstLevel = /* @__PURE__ */ new Set();
317
382
  const defineRecordGetter = (container, key, recordParams, subPaths = [], preferFull) => {
318
- const { generatedAppends, generatedFields } = inferSelectsFromUsage(subPaths, recordParams);
383
+ const strictSelects = Array.isArray(recordParams == null ? void 0 : recordParams.fields) || Array.isArray(recordParams == null ? void 0 : recordParams.appends);
384
+ let { generatedAppends, generatedFields } = inferSelectsFromUsage(subPaths, recordParams);
385
+ if (Array.isArray(recordParams == null ? void 0 : recordParams.fields)) generatedFields = recordParams.fields;
386
+ if (Array.isArray(recordParams == null ? void 0 : recordParams.appends)) generatedAppends = recordParams.appends;
319
387
  container.defineProperty(key, {
320
388
  get: async () => {
321
389
  const dataSourceKey = (recordParams == null ? void 0 : recordParams.dataSourceKey) || "main";
@@ -333,6 +401,7 @@ function attachGenericRecordVariables(flowCtx, koaCtx, usage, contextParams) {
333
401
  recordParams.filterByTk,
334
402
  fixed.fields,
335
403
  fixed.appends,
404
+ strictSelects,
336
405
  preferFull || ((subPaths == null ? void 0 : subPaths.length) ?? 0) === 0,
337
406
  recordParams.associationName,
338
407
  recordParams.sourceId
@@ -416,6 +485,7 @@ function registerBuiltInVariables(reg) {
416
485
  uid,
417
486
  generatedFields,
418
487
  generatedAppends,
488
+ false,
419
489
  void 0,
420
490
  void 0,
421
491
  void 0
@@ -32,12 +32,18 @@ module.exports = __toCommonJS(utils_exports);
32
32
  var import_registry = require("./registry");
33
33
  var import_selects = require("./selects");
34
34
  async function prefetchRecordsForResolve(koaCtx, items) {
35
- var _a, _b, _c, _d, _e, _f, _g;
35
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
36
36
  try {
37
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
38
  const groupMap = /* @__PURE__ */ new Map();
39
- const ensureGroup = (dataSourceKey, collection, filterByTk) => {
40
- const groupKey = JSON.stringify({ ds: dataSourceKey, collection, tk: filterByTk });
39
+ const ensureGroup = (dataSourceKey, collection, filterByTk, opts) => {
40
+ const groupKey = JSON.stringify({
41
+ ds: dataSourceKey,
42
+ collection,
43
+ tk: filterByTk,
44
+ f: Array.isArray(opts == null ? void 0 : opts.fields) ? [...opts.fields].sort() : void 0,
45
+ a: Array.isArray(opts == null ? void 0 : opts.appends) ? [...opts.appends].sort() : void 0
46
+ });
41
47
  let group = groupMap.get(groupKey);
42
48
  if (!group) {
43
49
  group = { dataSourceKey, collection, filterByTk, fields: /* @__PURE__ */ new Set(), appends: /* @__PURE__ */ new Set() };
@@ -69,7 +75,19 @@ async function prefetchRecordsForResolve(koaCtx, items) {
69
75
  const collection = recordParams == null ? void 0 : recordParams.collection;
70
76
  const filterByTk = recordParams == null ? void 0 : recordParams.filterByTk;
71
77
  if (!collection || typeof filterByTk === "undefined") continue;
72
- const group = ensureGroup(dataSourceKey, collection, filterByTk);
78
+ const explicitFields = recordParams == null ? void 0 : recordParams.fields;
79
+ const explicitAppends = recordParams == null ? void 0 : recordParams.appends;
80
+ const hasExplicit = Array.isArray(explicitFields) || Array.isArray(explicitAppends);
81
+ const group = ensureGroup(dataSourceKey, collection, filterByTk, {
82
+ fields: hasExplicit ? explicitFields : void 0,
83
+ appends: hasExplicit ? explicitAppends : void 0
84
+ });
85
+ if (hasExplicit) {
86
+ const fixed2 = (0, import_selects.adjustSelectsForCollection)(koaCtx, dataSourceKey, collection, explicitFields, explicitAppends);
87
+ (_c = fixed2.fields) == null ? void 0 : _c.forEach((f) => group.fields.add(f));
88
+ (_d = fixed2.appends) == null ? void 0 : _d.forEach((a) => group.appends.add(a));
89
+ continue;
90
+ }
73
91
  let { generatedAppends, generatedFields } = (0, import_registry.inferSelectsFromUsage)(remainders);
74
92
  const fixed = (0, import_selects.adjustSelectsForCollection)(koaCtx, dataSourceKey, collection, generatedFields, generatedAppends);
75
93
  generatedFields = fixed.fields;
@@ -83,14 +101,14 @@ async function prefetchRecordsForResolve(koaCtx, items) {
83
101
  if (stateObj && !stateObj["__varResolveBatchCache"]) {
84
102
  stateObj["__varResolveBatchCache"] = /* @__PURE__ */ new Map();
85
103
  }
86
- const cache = (_c = koaCtx.state) == null ? void 0 : _c["__varResolveBatchCache"];
104
+ const cache = (_e = koaCtx.state) == null ? void 0 : _e["__varResolveBatchCache"];
87
105
  for (const { dataSourceKey, collection, filterByTk, fields, appends } of groupMap.values()) {
88
106
  try {
89
107
  const ds = koaCtx.app.dataSourceManager.get(dataSourceKey);
90
108
  const cm = ds.collectionManager;
91
109
  if (!(cm == null ? void 0 : cm.db)) continue;
92
110
  const repo = cm.db.getRepository(collection);
93
- const modelInfo = (_d = repo.collection) == null ? void 0 : _d.model;
111
+ const modelInfo = (_f = repo.collection) == null ? void 0 : _f.model;
94
112
  const pkAttr = modelInfo == null ? void 0 : modelInfo.primaryKeyAttribute;
95
113
  const pkIsValid = pkAttr && (modelInfo == null ? void 0 : modelInfo.rawAttributes) && Object.prototype.hasOwnProperty.call(modelInfo.rawAttributes, pkAttr);
96
114
  if (fields.size && pkIsValid) {
@@ -114,7 +132,7 @@ async function prefetchRecordsForResolve(koaCtx, items) {
114
132
  }
115
133
  }
116
134
  } 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) });
135
+ (_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) });
118
136
  }
119
137
  }
120
138
  // 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": "2.0.0-beta.10",
7
+ "version": "2.0.0-beta.12",
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": "9943dc4b0fdedcac3f304714b58635ae441e2560"
27
+ "gitHead": "184ac65ad8ca60618075936c990dc52addda79b7"
28
28
  }