@nocobase/plugin-data-source-main 1.9.33 → 1.9.34

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": "1.9.33",
11
+ "@nocobase/client": "1.9.34",
12
12
  "lodash": "4.17.21",
13
- "@nocobase/database": "1.9.33",
14
- "@nocobase/plugin-error-handler": "1.9.33",
15
- "@nocobase/server": "1.9.33",
13
+ "@nocobase/database": "1.9.34",
14
+ "@nocobase/plugin-error-handler": "1.9.34",
15
+ "@nocobase/server": "1.9.34",
16
16
  "@formily/json-schema": "2.3.0",
17
- "@nocobase/test": "1.9.33",
18
- "@nocobase/utils": "1.9.33",
17
+ "@nocobase/test": "1.9.34",
18
+ "@nocobase/utils": "1.9.34",
19
19
  "sequelize": "6.35.2",
20
20
  "dayjs": "1.11.13"
21
21
  };
@@ -412,42 +412,55 @@ class PluginDataSourceMainServer extends import_server.Plugin {
412
412
  });
413
413
  this.app.resource(import_views.default);
414
414
  this.app.actions(import_collections.default);
415
- const handleFieldSource = (fields) => {
416
- var _a;
417
- for (const field of import_lodash.default.castArray(fields)) {
418
- if (field.get("source")) {
419
- const [collectionSource, fieldSource] = field.get("source").split(".");
420
- const collectionField = (_a = this.app.db.getCollection(collectionSource)) == null ? void 0 : _a.getField(fieldSource);
421
- if (!collectionField) {
422
- continue;
415
+ const handleFieldSource = ({
416
+ fields,
417
+ isRawValue
418
+ }) => {
419
+ import_lodash.default.castArray(fields).forEach((field, index) => {
420
+ var _a;
421
+ const source = isRawValue ? field.source : field.get("source");
422
+ if (!source) {
423
+ return;
424
+ }
425
+ const [collectionSource, fieldSource] = source.split(".");
426
+ const collectionField = (_a = this.app.db.getCollection(collectionSource)) == null ? void 0 : _a.getField(fieldSource);
427
+ if (!collectionField) {
428
+ return;
429
+ }
430
+ const newOptions = {};
431
+ import_lodash.default.merge(newOptions, import_lodash.default.omit(collectionField.options, "name"));
432
+ const currentValues = isRawValue ? field : field.get();
433
+ import_lodash.default.mergeWith(newOptions, currentValues, (objValue, srcValue) => {
434
+ if (srcValue === null) {
435
+ return objValue;
423
436
  }
424
- const newOptions = {};
425
- import_lodash.default.merge(newOptions, import_lodash.default.omit(collectionField.options, "name"));
426
- import_lodash.default.mergeWith(newOptions, field.get(), (objValue, srcValue) => {
427
- if (srcValue === null) {
428
- return objValue;
429
- }
430
- });
437
+ });
438
+ if (isRawValue) {
439
+ fields[index] = {
440
+ ...field,
441
+ ...newOptions
442
+ };
443
+ } else {
431
444
  field.set("options", newOptions);
432
445
  }
433
- }
446
+ });
434
447
  };
435
448
  this.app.resourceManager.use(async function handleFieldSourceMiddleware(ctx, next) {
436
- var _a, _b;
449
+ var _a;
437
450
  await next();
438
- if (ctx.action.resourceName === "collections" && ctx.action.actionName == "list" && ((_a = ctx.action.params) == null ? void 0 : _a.paginate) == "false") {
451
+ if (ctx.action.resourceName === "collections" && ctx.action.actionName == "listMeta") {
439
452
  for (const collection of ctx.body) {
440
- if (collection.get("view")) {
453
+ if (collection.view === true) {
441
454
  const fields = collection.fields;
442
- handleFieldSource(fields);
455
+ handleFieldSource({ fields, isRawValue: true });
443
456
  }
444
457
  }
445
458
  }
446
459
  if (ctx.action.resourceName == "collections.fields" && ctx.action.actionName == "list") {
447
- handleFieldSource(((_b = ctx.action.params) == null ? void 0 : _b.paginate) == "false" ? ctx.body : ctx.body.rows);
460
+ handleFieldSource({ fields: ((_a = ctx.action.params) == null ? void 0 : _a.paginate) == "false" ? ctx.body : ctx.body.rows });
448
461
  }
449
462
  if (ctx.action.resourceName == "collections.fields" && ctx.action.actionName == "get") {
450
- handleFieldSource(ctx.body);
463
+ handleFieldSource({ fields: ctx.body });
451
464
  }
452
465
  });
453
466
  this.app.db.extendCollection({
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "description": "NocoBase main database, supports relational databases such as PostgreSQL, MySQL, MariaDB and so on.",
7
7
  "description.ru-RU": "Основная база данных NocoBase: поддерживает реляционные СУБД, включая PostgreSQL, MySQL, MariaDB и другие.",
8
8
  "description.zh-CN": "NocoBase 主数据库,支持 PostgreSQL、MySQL、MariaDB 等关系型数据库。",
9
- "version": "1.9.33",
9
+ "version": "1.9.34",
10
10
  "main": "./dist/server/index.js",
11
11
  "homepage": "https://docs.nocobase.com/handbook/data-source-main",
12
12
  "homepage.ru-RU": "https://docs-ru.nocobase.com/handbook/data-source-main",
@@ -25,7 +25,7 @@
25
25
  "@nocobase/test": "1.x",
26
26
  "@nocobase/utils": "1.x"
27
27
  },
28
- "gitHead": "705580251f0deffaf2a8c7c85006c770741941d3",
28
+ "gitHead": "8779a68face5b8f159aef726f73695f319ab7659",
29
29
  "keywords": [
30
30
  "Data sources"
31
31
  ]