@nocobase/server 2.0.11 → 2.0.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 (2) hide show
  1. package/lib/helper.js +33 -1
  2. package/package.json +17 -17
package/lib/helper.js CHANGED
@@ -239,14 +239,46 @@ function isNumeric(str) {
239
239
  return !isNaN(str) && !isNaN(parseFloat(str));
240
240
  }
241
241
  __name(isNumeric, "isNumeric");
242
+ function getFieldFromCollectionManager(ctx, resourceName, fieldPath) {
243
+ var _a;
244
+ const collectionManager = (_a = ctx.dataSource) == null ? void 0 : _a.collectionManager;
245
+ if (!(collectionManager == null ? void 0 : collectionManager.getCollection)) {
246
+ return;
247
+ }
248
+ const collection = collectionManager.getCollection(resourceName);
249
+ if (!(collection == null ? void 0 : collection.getField)) {
250
+ return;
251
+ }
252
+ const [firstName, ...others] = fieldPath.split(".");
253
+ let field = collection.getField(firstName);
254
+ if (!field || !others.length) {
255
+ return field;
256
+ }
257
+ let currentCollection = typeof field.targetCollection === "function" ? field.targetCollection() : field.targetCollection;
258
+ for (const name of others) {
259
+ if (!(currentCollection == null ? void 0 : currentCollection.getField)) {
260
+ return;
261
+ }
262
+ field = currentCollection.getField(name);
263
+ if (!field) {
264
+ return;
265
+ }
266
+ currentCollection = typeof field.targetCollection === "function" ? field.targetCollection() : field.targetCollection;
267
+ }
268
+ return field;
269
+ }
270
+ __name(getFieldFromCollectionManager, "getFieldFromCollectionManager");
242
271
  function createContextVariablesScope(ctx) {
243
272
  const state = JSON.parse(JSON.stringify(ctx.state));
244
273
  return {
245
274
  timezone: ctx.get("x-timezone"),
246
275
  now: (/* @__PURE__ */ new Date()).toISOString(),
247
276
  getField: /* @__PURE__ */ __name((path) => {
248
- const fieldPath = path.split(".").filter((p) => !p.startsWith("$") && !isNumeric(p)).join(".");
249
277
  const { resourceName } = ctx.action;
278
+ const fieldPath = path.split(".").filter((p) => !p.startsWith("$") && !isNumeric(p)).join(".");
279
+ if (!ctx.database) {
280
+ return getFieldFromCollectionManager(ctx, resourceName, fieldPath);
281
+ }
250
282
  return ctx.database.getFieldByPath(`${resourceName}.${fieldPath}`);
251
283
  }, "getField"),
252
284
  vars: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "2.0.11",
3
+ "version": "2.0.12",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -10,21 +10,21 @@
10
10
  "@koa/cors": "^5.0.0",
11
11
  "@koa/multer": "^3.1.0",
12
12
  "@koa/router": "^13.1.0",
13
- "@nocobase/acl": "2.0.11",
14
- "@nocobase/actions": "2.0.11",
15
- "@nocobase/ai": "2.0.11",
16
- "@nocobase/auth": "2.0.11",
17
- "@nocobase/cache": "2.0.11",
18
- "@nocobase/data-source-manager": "2.0.11",
19
- "@nocobase/database": "2.0.11",
20
- "@nocobase/evaluators": "2.0.11",
21
- "@nocobase/lock-manager": "2.0.11",
22
- "@nocobase/logger": "2.0.11",
23
- "@nocobase/resourcer": "2.0.11",
24
- "@nocobase/sdk": "2.0.11",
25
- "@nocobase/snowflake-id": "2.0.11",
26
- "@nocobase/telemetry": "2.0.11",
27
- "@nocobase/utils": "2.0.11",
13
+ "@nocobase/acl": "2.0.12",
14
+ "@nocobase/actions": "2.0.12",
15
+ "@nocobase/ai": "2.0.12",
16
+ "@nocobase/auth": "2.0.12",
17
+ "@nocobase/cache": "2.0.12",
18
+ "@nocobase/data-source-manager": "2.0.12",
19
+ "@nocobase/database": "2.0.12",
20
+ "@nocobase/evaluators": "2.0.12",
21
+ "@nocobase/lock-manager": "2.0.12",
22
+ "@nocobase/logger": "2.0.12",
23
+ "@nocobase/resourcer": "2.0.12",
24
+ "@nocobase/sdk": "2.0.12",
25
+ "@nocobase/snowflake-id": "2.0.12",
26
+ "@nocobase/telemetry": "2.0.12",
27
+ "@nocobase/utils": "2.0.12",
28
28
  "@types/decompress": "4.2.7",
29
29
  "@types/ini": "^1.3.31",
30
30
  "@types/koa-send": "^4.1.3",
@@ -61,5 +61,5 @@
61
61
  "@types/serve-handler": "^6.1.1",
62
62
  "@types/ws": "^8.5.5"
63
63
  },
64
- "gitHead": "657733e68b31cbb788f8b1b7c4926383c96b5889"
64
+ "gitHead": "a96acd22a9b0744b567617e3a1f1d42cb7f72368"
65
65
  }