@nocobase/plugin-data-source-main 2.0.0-alpha.60 → 2.0.0-alpha.62

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,15 +8,15 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "2.0.0-alpha.60",
11
+ "@nocobase/client": "2.0.0-alpha.62",
12
12
  "lodash": "4.17.21",
13
- "@nocobase/database": "2.0.0-alpha.60",
14
- "@nocobase/plugin-error-handler": "2.0.0-alpha.60",
15
- "@nocobase/server": "2.0.0-alpha.60",
13
+ "@nocobase/database": "2.0.0-alpha.62",
14
+ "@nocobase/plugin-error-handler": "2.0.0-alpha.62",
15
+ "@nocobase/server": "2.0.0-alpha.62",
16
16
  "sequelize": "6.35.2",
17
17
  "@formily/json-schema": "2.3.7",
18
- "@nocobase/test": "2.0.0-alpha.60",
19
- "@nocobase/utils": "2.0.0-alpha.60",
20
- "@nocobase/actions": "2.0.0-alpha.60",
18
+ "@nocobase/test": "2.0.0-alpha.62",
19
+ "@nocobase/utils": "2.0.0-alpha.62",
20
+ "@nocobase/actions": "2.0.0-alpha.62",
21
21
  "dayjs": "1.11.13"
22
22
  };
@@ -415,22 +415,36 @@ class PluginDataSourceMainServer extends import_server.Plugin {
415
415
  this.app.resourceManager.define(import_views.default);
416
416
  this.app.resourceManager.registerActionHandlers(import_collections.default);
417
417
  this.app.resourceManager.define(import_main_data_source.default);
418
- const handleFieldSource = (fields, rawFields) => {
419
- var _a;
420
- for (const field of import_lodash.default.castArray(fields)) {
421
- if (field.get("source")) {
422
- const [collectionSource, fieldSource] = field.get("source").split(".");
423
- const collectionField = (_a = this.app.db.getCollection(collectionSource)) == null ? void 0 : _a.getField(fieldSource);
424
- if (!collectionField) {
425
- continue;
418
+ const handleFieldSource = ({
419
+ fields,
420
+ isRawValue,
421
+ rawFields
422
+ }) => {
423
+ import_lodash.default.castArray(fields).forEach((field, index) => {
424
+ var _a;
425
+ const source = isRawValue ? field.source : field.get("source");
426
+ if (!source) {
427
+ return;
428
+ }
429
+ const [collectionSource, fieldSource] = source.split(".");
430
+ const collectionField = (_a = this.app.db.getCollection(collectionSource)) == null ? void 0 : _a.getField(fieldSource);
431
+ if (!collectionField) {
432
+ return;
433
+ }
434
+ const newOptions = {};
435
+ import_lodash.default.merge(newOptions, import_lodash.default.omit(collectionField.options, "name"));
436
+ const currentValues = isRawValue ? field : field.get();
437
+ import_lodash.default.mergeWith(newOptions, currentValues, (objValue, srcValue) => {
438
+ if (srcValue === null) {
439
+ return objValue;
426
440
  }
427
- const newOptions = {};
428
- import_lodash.default.merge(newOptions, import_lodash.default.omit(collectionField.options, "name"));
429
- import_lodash.default.mergeWith(newOptions, field.get(), (objValue, srcValue) => {
430
- if (srcValue === null) {
431
- return objValue;
432
- }
433
- });
441
+ });
442
+ if (isRawValue) {
443
+ fields[index] = {
444
+ ...field,
445
+ ...newOptions
446
+ };
447
+ } else {
434
448
  field.set("options", newOptions);
435
449
  }
436
450
  const fieldTypes = import_database.fieldTypeMap[this.db.options.dialect];
@@ -442,16 +456,16 @@ class PluginDataSourceMainServer extends import_server.Plugin {
442
456
  field.set("possibleTypes", possibleTypes);
443
457
  }
444
458
  }
445
- }
459
+ });
446
460
  };
447
461
  this.app.resourceManager.use(async function handleFieldSourceMiddleware(ctx, next) {
448
- var _a, _b;
462
+ var _a;
449
463
  await next();
450
- if (ctx.action.resourceName === "collections" && ctx.action.actionName == "list" && ((_a = ctx.action.params) == null ? void 0 : _a.paginate) == "false") {
464
+ if (ctx.action.resourceName === "collections" && ctx.action.actionName == "listMeta") {
451
465
  for (const collection of ctx.body) {
452
- if (collection.get("view")) {
466
+ if (collection.view === true) {
453
467
  const fields = collection.fields;
454
- handleFieldSource(fields);
468
+ handleFieldSource({ fields, isRawValue: true });
455
469
  }
456
470
  }
457
471
  }
@@ -467,10 +481,10 @@ class PluginDataSourceMainServer extends import_server.Plugin {
467
481
  } catch (err) {
468
482
  }
469
483
  }
470
- handleFieldSource(((_b = ctx.action.params) == null ? void 0 : _b.paginate) == "false" ? ctx.body : ctx.body.rows, rawFields);
484
+ handleFieldSource({ fields: ((_a = ctx.action.params) == null ? void 0 : _a.paginate) == "false" ? ctx.body : ctx.body.rows, rawFields });
471
485
  }
472
486
  if (ctx.action.resourceName == "collections.fields" && ctx.action.actionName == "get") {
473
- handleFieldSource(ctx.body);
487
+ handleFieldSource({ fields: ctx.body });
474
488
  }
475
489
  });
476
490
  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": "2.0.0-alpha.60",
9
+ "version": "2.0.0-alpha.62",
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": "2.x",
26
26
  "@nocobase/utils": "2.x"
27
27
  },
28
- "gitHead": "9113d61ce85b60b7ba3d0e5ca64182d92a15ece4",
28
+ "gitHead": "a6e543098afba0edc2189edc04f27c1726fff564",
29
29
  "keywords": [
30
30
  "Data sources"
31
31
  ]