@nocobase/plugin-data-source-main 2.0.0-beta.3 → 2.0.0-beta.5

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-beta.3",
11
+ "@nocobase/client": "2.0.0-beta.5",
12
12
  "lodash": "4.17.21",
13
- "@nocobase/database": "2.0.0-beta.3",
14
- "@nocobase/plugin-error-handler": "2.0.0-beta.3",
15
- "@nocobase/server": "2.0.0-beta.3",
13
+ "@nocobase/database": "2.0.0-beta.5",
14
+ "@nocobase/plugin-error-handler": "2.0.0-beta.5",
15
+ "@nocobase/server": "2.0.0-beta.5",
16
16
  "sequelize": "6.35.2",
17
17
  "@formily/json-schema": "2.3.7",
18
- "@nocobase/test": "2.0.0-beta.3",
19
- "@nocobase/utils": "2.0.0-beta.3",
20
- "@nocobase/actions": "2.0.0-beta.3",
18
+ "@nocobase/test": "2.0.0-beta.5",
19
+ "@nocobase/utils": "2.0.0-beta.5",
20
+ "@nocobase/actions": "2.0.0-beta.5",
21
21
  "dayjs": "1.11.13"
22
22
  };
@@ -415,15 +415,14 @@ 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) => {
418
+ const handleFieldSource = ({
419
+ fields,
420
+ isRawValue,
421
+ rawFields
422
+ }) => {
419
423
  import_lodash.default.castArray(fields).forEach((field, index) => {
420
424
  var _a;
421
- let source;
422
- if (field && typeof field.get === "function") {
423
- source = field.get("source");
424
- } else {
425
- source = field == null ? void 0 : field.source;
426
- }
425
+ const source = isRawValue ? field.source : field.get("source");
427
426
  if (!source) {
428
427
  return;
429
428
  }
@@ -434,38 +433,27 @@ class PluginDataSourceMainServer extends import_server.Plugin {
434
433
  }
435
434
  const newOptions = {};
436
435
  import_lodash.default.merge(newOptions, import_lodash.default.omit(collectionField.options, "name"));
437
- const currentValues = field && typeof field.get === "function" ? field.get() : field;
436
+ const currentValues = isRawValue ? field : field.get();
438
437
  import_lodash.default.mergeWith(newOptions, currentValues, (objValue, srcValue) => {
439
438
  if (srcValue === null) {
440
439
  return objValue;
441
440
  }
442
441
  });
443
- if (field && typeof field.set === "function") {
444
- field.set("options", newOptions);
445
- } else {
442
+ if (isRawValue) {
446
443
  fields[index] = {
447
444
  ...field,
448
445
  ...newOptions
449
446
  };
447
+ } else {
448
+ field.set("options", newOptions);
450
449
  }
451
450
  const fieldTypes = import_database.fieldTypeMap[this.db.options.dialect];
452
451
  if (rawFields && fieldTypes) {
453
- const fieldName = field && typeof field.get === "function" ? field.get("name") : field == null ? void 0 : field.name;
454
- const rawField = rawFields[fieldName];
455
- if (rawField) {
456
- const interfaceValue = field && typeof field.get === "function" ? field.get("interface") : field == null ? void 0 : field.interface;
457
- if (!import_constants.PRESET_FIELDS_INTERFACES.includes(interfaceValue)) {
458
- const mappedType = (0, import_database.extractTypeFromDefinition)(rawField.type);
459
- const possibleTypes = fieldTypes[mappedType];
460
- if (field && typeof field.set === "function") {
461
- field.set("possibleTypes", possibleTypes);
462
- } else {
463
- fields[index] = {
464
- ...fields[index],
465
- possibleTypes
466
- };
467
- }
468
- }
452
+ const rawField = rawFields[field.get("name")];
453
+ if (rawField && !import_constants.PRESET_FIELDS_INTERFACES.includes(field.get("interface"))) {
454
+ const mappedType = (0, import_database.extractTypeFromDefinition)(rawField.type);
455
+ const possibleTypes = fieldTypes[mappedType];
456
+ field.set("possibleTypes", possibleTypes);
469
457
  }
470
458
  }
471
459
  });
@@ -477,7 +465,7 @@ class PluginDataSourceMainServer extends import_server.Plugin {
477
465
  for (const collection of ctx.body) {
478
466
  if (collection.view === true) {
479
467
  const fields = collection.fields;
480
- handleFieldSource(fields);
468
+ handleFieldSource({ fields, isRawValue: true });
481
469
  }
482
470
  }
483
471
  }
@@ -493,10 +481,10 @@ class PluginDataSourceMainServer extends import_server.Plugin {
493
481
  } catch (err) {
494
482
  }
495
483
  }
496
- handleFieldSource(((_a = ctx.action.params) == null ? void 0 : _a.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 });
497
485
  }
498
486
  if (ctx.action.resourceName == "collections.fields" && ctx.action.actionName == "get") {
499
- handleFieldSource(ctx.body);
487
+ handleFieldSource({ fields: ctx.body });
500
488
  }
501
489
  });
502
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-beta.3",
9
+ "version": "2.0.0-beta.5",
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": "6c178de2050651bcfcc0b2708de0246977eac510",
28
+ "gitHead": "ea028f41293607ac0a20d054107e2ba772d639b2",
29
29
  "keywords": [
30
30
  "Data sources"
31
31
  ]