@nocobase/plugin-flow-engine 2.0.0-alpha.24 → 2.0.0-alpha.25

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-alpha.24",
11
+ "@nocobase/client": "2.0.0-alpha.25",
12
12
  "lodash": "4.17.21",
13
- "@nocobase/database": "2.0.0-alpha.24",
14
- "@nocobase/data-source-manager": "2.0.0-alpha.24",
15
- "@nocobase/resourcer": "2.0.0-alpha.24",
16
- "@nocobase/server": "2.0.0-alpha.24",
17
- "@nocobase/utils": "2.0.0-alpha.24",
18
- "@nocobase/cache": "2.0.0-alpha.24",
19
- "@nocobase/plugin-localization": "2.0.0-alpha.24",
20
- "@nocobase/actions": "2.0.0-alpha.24"
13
+ "@nocobase/database": "2.0.0-alpha.25",
14
+ "@nocobase/data-source-manager": "2.0.0-alpha.25",
15
+ "@nocobase/resourcer": "2.0.0-alpha.25",
16
+ "@nocobase/server": "2.0.0-alpha.25",
17
+ "@nocobase/utils": "2.0.0-alpha.25",
18
+ "@nocobase/cache": "2.0.0-alpha.25",
19
+ "@nocobase/plugin-localization": "2.0.0-alpha.25",
20
+ "@nocobase/actions": "2.0.0-alpha.25"
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":"2025-10-26T10:30:14.651Z"}
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":"2025-10-29T11:27:39.076Z"}
@@ -43,6 +43,7 @@ module.exports = __toCommonJS(registry_exports);
43
43
  var import_lodash = __toESM(require("lodash"));
44
44
  var import_contexts = require("../template/contexts");
45
45
  var import_utils = require("@nocobase/utils");
46
+ var import_selects = require("./selects");
46
47
  class VariableRegistry {
47
48
  vars = /* @__PURE__ */ new Map();
48
49
  register(def) {
@@ -128,8 +129,8 @@ function inferSelectsFromUsage(paths = [], _params) {
128
129
  const generatedFields = fieldSet.size ? Array.from(fieldSet) : void 0;
129
130
  return { generatedAppends, generatedFields };
130
131
  }
131
- async function fetchRecordWithRequestCache(koaCtx, dataSourceKey, collection, filterByTk, fields, appends) {
132
- var _a, _b, _c, _d;
132
+ async function fetchRecordWithRequestCache(koaCtx, dataSourceKey, collection, filterByTk, fields, appends, preferFullRecord) {
133
+ var _a, _b, _c, _d, _e;
133
134
  try {
134
135
  const log = (_b = (_a = koaCtx.app) == null ? void 0 : _a.logger) == null ? void 0 : _b.child({
135
136
  module: "plugin-flow-engine",
@@ -146,19 +147,24 @@ async function fetchRecordWithRequestCache(koaCtx, dataSourceKey, collection, fi
146
147
  const cm = ds.collectionManager;
147
148
  if (!(cm == null ? void 0 : cm.db)) return void 0;
148
149
  const repo = cm.db.getRepository(collection);
150
+ const modelInfo = (_c = repo.collection) == null ? void 0 : _c.model;
151
+ const pkAttr = modelInfo == null ? void 0 : modelInfo.primaryKeyAttribute;
152
+ const pkIsValid = pkAttr && (modelInfo == null ? void 0 : modelInfo.rawAttributes) && Object.prototype.hasOwnProperty.call(modelInfo.rawAttributes, pkAttr);
153
+ const fieldsWithPk = Array.isArray(fields) && fields.length > 0 && pkIsValid ? Array.from(/* @__PURE__ */ new Set([...fields, pkAttr])) : fields;
149
154
  const keyObj = {
150
155
  ds: dataSourceKey || "main",
151
156
  c: collection,
152
157
  tk: filterByTk,
153
- f: Array.isArray(fields) ? [...fields].sort() : void 0,
154
- a: Array.isArray(appends) ? [...appends].sort() : void 0
158
+ f: Array.isArray(fieldsWithPk) ? [...fieldsWithPk].sort() : void 0,
159
+ a: Array.isArray(appends) ? [...appends].sort() : void 0,
160
+ full: preferFullRecord ? true : void 0
155
161
  };
156
162
  const key = JSON.stringify(keyObj);
157
163
  if (cache) {
158
164
  if (cache.has(key)) {
159
165
  return cache.get(key);
160
166
  }
161
- const needFields = Array.isArray(fields) ? [...new Set(fields)] : void 0;
167
+ const needFields = Array.isArray(fieldsWithPk) ? [...new Set(fieldsWithPk)] : void 0;
162
168
  const needAppends = Array.isArray(appends) ? new Set(appends) : void 0;
163
169
  for (const [cacheKey, cacheVal] of cache.entries()) {
164
170
  const parsed = JSON.parse(cacheKey);
@@ -173,23 +179,34 @@ async function fetchRecordWithRequestCache(koaCtx, dataSourceKey, collection, fi
173
179
  }
174
180
  return false;
175
181
  };
176
- const fieldsOk = !needFields || needFields.every((f) => cachedFields.has(f) || fieldCoveredByAppends(f));
182
+ const fieldsOk = needFields ? needFields.every((f) => cachedFields.has(f) || fieldCoveredByAppends(f)) : parsed.f === void 0;
177
183
  const appendsOk = !needAppends || [...needAppends].every((a) => cachedAppends.has(a));
178
- if (fieldsOk && appendsOk) {
184
+ const fullOk = preferFullRecord ? parsed.full === true : true;
185
+ if (fieldsOk && appendsOk && fullOk) {
179
186
  return cacheVal;
180
187
  }
181
188
  }
182
189
  }
183
190
  const rec = await repo.findOne({
184
191
  filterByTk,
185
- fields,
192
+ fields: fieldsWithPk,
186
193
  appends
187
194
  });
188
- const json = rec ? rec.toJSON() : void 0;
195
+ let json = rec ? rec.toJSON() : void 0;
196
+ if (preferFullRecord && json && typeof json === "object" && pkIsValid) {
197
+ const keys = Object.keys(json);
198
+ const pkOnly = keys.length === 1 && keys[0] === pkAttr;
199
+ const rawAttrs = modelInfo == null ? void 0 : modelInfo.rawAttributes;
200
+ const hasMoreAttrs = rawAttrs && Object.keys(rawAttrs).some((k) => k !== pkAttr);
201
+ if (pkOnly && hasMoreAttrs) {
202
+ const rec2 = await repo.findOne({ filterByTk });
203
+ json = rec2 ? rec2.toJSON() : json;
204
+ }
205
+ }
189
206
  if (cache) cache.set(key, json);
190
207
  return json;
191
208
  } catch (e) {
192
- const log = (_d = (_c = koaCtx.app) == null ? void 0 : _c.logger) == null ? void 0 : _d.child({
209
+ const log = (_e = (_d = koaCtx.app) == null ? void 0 : _d.logger) == null ? void 0 : _e.child({
193
210
  module: "plugin-flow-engine",
194
211
  submodule: "variables.resolve",
195
212
  method: "fetchRecordWithRequestCache"
@@ -219,17 +236,26 @@ function attachGenericRecordVariables(flowCtx, koaCtx, usage, contextParams) {
219
236
  const topParams = import_lodash.default.get(contextParams, varName);
220
237
  if (isRecordParams(topParams)) {
221
238
  const { generatedAppends, generatedFields } = inferSelectsFromUsage(usedPaths, topParams);
239
+ const hasDirectRefTop = (usedPaths || []).some((p) => p === "");
222
240
  flowCtx.defineProperty(varName, {
223
241
  get: async () => {
224
242
  const dataSourceKey = (topParams == null ? void 0 : topParams.dataSourceKey) || "main";
225
- return await fetchRecordWithRequestCache(
243
+ const fixed = (0, import_selects.adjustSelectsForCollection)(
226
244
  koaCtx,
227
245
  dataSourceKey,
228
246
  topParams.collection,
229
- topParams.filterByTk,
230
247
  generatedFields,
231
248
  generatedAppends
232
249
  );
250
+ return await fetchRecordWithRequestCache(
251
+ koaCtx,
252
+ dataSourceKey,
253
+ topParams.collection,
254
+ topParams.filterByTk,
255
+ fixed.fields,
256
+ fixed.appends,
257
+ hasDirectRefTop
258
+ );
233
259
  },
234
260
  cache: true
235
261
  });
@@ -287,19 +313,27 @@ function attachGenericRecordVariables(flowCtx, koaCtx, usage, contextParams) {
287
313
  get: () => {
288
314
  const root = new import_contexts.ServerBaseContext();
289
315
  const definedFirstLevel = /* @__PURE__ */ new Set();
290
- const defineRecordGetter = (container, key, recordParams, subPaths = []) => {
316
+ const defineRecordGetter = (container, key, recordParams, subPaths = [], preferFull) => {
291
317
  const { generatedAppends, generatedFields } = inferSelectsFromUsage(subPaths, recordParams);
292
318
  container.defineProperty(key, {
293
319
  get: async () => {
294
320
  const dataSourceKey = (recordParams == null ? void 0 : recordParams.dataSourceKey) || "main";
295
- return await fetchRecordWithRequestCache(
321
+ const fixed = (0, import_selects.adjustSelectsForCollection)(
296
322
  koaCtx,
297
323
  dataSourceKey,
298
324
  recordParams.collection,
299
- recordParams.filterByTk,
300
325
  generatedFields,
301
326
  generatedAppends
302
327
  );
328
+ return await fetchRecordWithRequestCache(
329
+ koaCtx,
330
+ dataSourceKey,
331
+ recordParams.collection,
332
+ recordParams.filterByTk,
333
+ fixed.fields,
334
+ fixed.appends,
335
+ preferFull || ((subPaths == null ? void 0 : subPaths.length) ?? 0) === 0
336
+ );
303
337
  },
304
338
  cache: true
305
339
  });
@@ -330,7 +364,8 @@ function attachGenericRecordVariables(flowCtx, koaCtx, usage, contextParams) {
330
364
  ).filter((x) => !!x);
331
365
  if (all.length) effRemainders = all;
332
366
  }
333
- defineRecordGetter(root, idx ?? seg, recordParams, effRemainders);
367
+ const hasDirectRefOne = (usedPaths || []).some((p) => p === seg || !!idx && p === `[${idx}]`);
368
+ defineRecordGetter(root, idx ?? seg, recordParams, effRemainders, hasDirectRefOne);
334
369
  definedFirstLevel.add(idx ?? seg);
335
370
  }
336
371
  for (const [relative, recordParams] of deepRecordMap.entries()) {
@@ -348,7 +383,8 @@ function attachGenericRecordVariables(flowCtx, koaCtx, usage, contextParams) {
348
383
  }
349
384
  const leaf = segs[segs.length - 1];
350
385
  const subPaths = (usedPaths || []).map((p) => p === relative ? "" : p.startsWith(relative + ".") ? p.slice(relative.length + 1) : "").filter((x) => x !== "");
351
- defineRecordGetter(container, leaf, recordParams, subPaths);
386
+ const hasDirectRef = (usedPaths || []).some((p) => p === relative);
387
+ defineRecordGetter(container, leaf, recordParams, subPaths, hasDirectRef);
352
388
  }
353
389
  return root.createProxy();
354
390
  },
@@ -0,0 +1,19 @@
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
+ import { ResourcerContext } from '@nocobase/resourcer';
10
+ /**
11
+ * 针对给定集合,修正 selects:
12
+ * - 若 fields 中包含单段且为关联名(如 'roles'),则将其从 fields 移到 appends。
13
+ * - 若 fields 中包含多段且首段为关联名(如 'roles.name'),确保 appends 包含该关联名,并将首段替换为模型真实关联名。
14
+ * - 非关联字段:仅当模型存在该属性(或其 snake/camel 变体)时才保留,否则丢弃以避免数据库错误。
15
+ */
16
+ export declare function adjustSelectsForCollection(koaCtx: ResourcerContext, dataSourceKey: string, collection: string, fields?: string[], appends?: string[]): {
17
+ fields?: string[];
18
+ appends?: string[];
19
+ };
@@ -0,0 +1,80 @@
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 selects_exports = {};
28
+ __export(selects_exports, {
29
+ adjustSelectsForCollection: () => adjustSelectsForCollection
30
+ });
31
+ module.exports = __toCommonJS(selects_exports);
32
+ function adjustSelectsForCollection(koaCtx, dataSourceKey, collection, fields, appends) {
33
+ var _a, _b, _c, _d;
34
+ const ds = koaCtx.app.dataSourceManager.get(dataSourceKey || "main");
35
+ const cm = ds.collectionManager;
36
+ const coll = (_b = (_a = cm == null ? void 0 : cm.db) == null ? void 0 : _a.getCollection) == null ? void 0 : _b.call(_a, collection);
37
+ const assocKeys = Object.keys(((_c = coll == null ? void 0 : coll.model) == null ? void 0 : _c.associations) || {});
38
+ const rawAttrs = ((_d = coll == null ? void 0 : coll.model) == null ? void 0 : _d.rawAttributes) || {};
39
+ const toCamel = (s) => s.replace(/_([a-zA-Z0-9])/g, (_m, c) => String(c).toUpperCase());
40
+ const toSnake = (s) => s.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "");
41
+ const assocMap = /* @__PURE__ */ new Map();
42
+ for (const k of assocKeys) {
43
+ assocMap.set(k, k);
44
+ assocMap.set(toSnake(k), k);
45
+ assocMap.set(toCamel(k), k);
46
+ }
47
+ const outFields = [];
48
+ const outAppends = new Set(appends || []);
49
+ for (const f of fields || []) {
50
+ const segs = String(f).split(".").filter(Boolean);
51
+ if (!segs.length) continue;
52
+ const first = segs[0];
53
+ const assocCanonical = assocMap.get(first) || assocMap.get(toCamel(first)) || assocMap.get(toSnake(first));
54
+ if (assocCanonical) {
55
+ outAppends.add(assocCanonical);
56
+ if (segs.length === 1) {
57
+ continue;
58
+ }
59
+ outFields.push([assocCanonical, ...segs.slice(1)].join("."));
60
+ continue;
61
+ }
62
+ if (rawAttrs[first]) {
63
+ outFields.push(f);
64
+ } else if (rawAttrs[toSnake(first)]) {
65
+ outFields.push([toSnake(first), ...segs.slice(1)].join("."));
66
+ } else if (rawAttrs[toCamel(first)]) {
67
+ outFields.push([toCamel(first), ...segs.slice(1)].join("."));
68
+ } else {
69
+ continue;
70
+ }
71
+ }
72
+ return {
73
+ fields: outFields.length ? outFields : void 0,
74
+ appends: outAppends.size ? Array.from(outAppends) : void 0
75
+ };
76
+ }
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ adjustSelectsForCollection
80
+ });
@@ -30,8 +30,9 @@ __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");
33
34
  async function prefetchRecordsForResolve(koaCtx, items) {
34
- var _a, _b, _c, _d, _e, _f;
35
+ var _a, _b, _c, _d, _e, _f, _g;
35
36
  try {
36
37
  const log = (_b = (_a = koaCtx.app) == null ? void 0 : _a.logger) == null ? void 0 : _b.child({ module: "plugin-flow-engine", submodule: "variables.prefetch" });
37
38
  const groupMap = /* @__PURE__ */ new Map();
@@ -69,7 +70,10 @@ async function prefetchRecordsForResolve(koaCtx, items) {
69
70
  const filterByTk = recordParams == null ? void 0 : recordParams.filterByTk;
70
71
  if (!collection || typeof filterByTk === "undefined") continue;
71
72
  const group = ensureGroup(dataSourceKey, collection, filterByTk);
72
- const { generatedAppends, generatedFields } = (0, import_registry.inferSelectsFromUsage)(remainders);
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;
73
77
  if (generatedFields == null ? void 0 : generatedFields.length) generatedFields.forEach((f) => group.fields.add(f));
74
78
  if (generatedAppends == null ? void 0 : generatedAppends.length) generatedAppends.forEach((a) => group.appends.add(a));
75
79
  }
@@ -86,6 +90,12 @@ async function prefetchRecordsForResolve(koaCtx, items) {
86
90
  const cm = ds.collectionManager;
87
91
  if (!(cm == null ? void 0 : cm.db)) continue;
88
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
+ }
89
99
  const fld = fields.size ? Array.from(fields).sort() : void 0;
90
100
  const app = appends.size ? Array.from(appends).sort() : void 0;
91
101
  const rec = await repo.findOne({ filterByTk, fields: fld, appends: app });
@@ -104,7 +114,7 @@ async function prefetchRecordsForResolve(koaCtx, items) {
104
114
  }
105
115
  }
106
116
  } catch (e) {
107
- (_f = (_e = (_d = koaCtx.app) == null ? void 0 : _d.logger) == null ? void 0 : _e.child({ module: "plugin-flow-engine", submodule: "variables.prefetch" })) == null ? void 0 : _f.debug("[variables.resolve] prefetch fatal error", { error: (e == null ? void 0 : e.message) || String(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) });
108
118
  }
109
119
  }
110
120
  // 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-alpha.24",
7
+ "version": "2.0.0-alpha.25",
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": "4e6d1ae61143f01aba213355b4c416aab4d64077"
27
+ "gitHead": "8ce1972206272bd1723db193abd0425c532c5687"
28
28
  }