@nocobase/plugin-data-source-main 2.0.0-beta.2 → 2.0.0-beta.3
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.
- package/dist/externalVersion.js +7 -7
- package/dist/server/server.js +50 -24
- package/package.json +2 -2
package/dist/externalVersion.js
CHANGED
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "2.0.0-beta.
|
|
11
|
+
"@nocobase/client": "2.0.0-beta.3",
|
|
12
12
|
"lodash": "4.17.21",
|
|
13
|
-
"@nocobase/database": "2.0.0-beta.
|
|
14
|
-
"@nocobase/plugin-error-handler": "2.0.0-beta.
|
|
15
|
-
"@nocobase/server": "2.0.0-beta.
|
|
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",
|
|
16
16
|
"sequelize": "6.35.2",
|
|
17
17
|
"@formily/json-schema": "2.3.7",
|
|
18
|
-
"@nocobase/test": "2.0.0-beta.
|
|
19
|
-
"@nocobase/utils": "2.0.0-beta.
|
|
20
|
-
"@nocobase/actions": "2.0.0-beta.
|
|
18
|
+
"@nocobase/test": "2.0.0-beta.3",
|
|
19
|
+
"@nocobase/utils": "2.0.0-beta.3",
|
|
20
|
+
"@nocobase/actions": "2.0.0-beta.3",
|
|
21
21
|
"dayjs": "1.11.13"
|
|
22
22
|
};
|
package/dist/server/server.js
CHANGED
|
@@ -416,40 +416,66 @@ class PluginDataSourceMainServer extends import_server.Plugin {
|
|
|
416
416
|
this.app.resourceManager.registerActionHandlers(import_collections.default);
|
|
417
417
|
this.app.resourceManager.define(import_main_data_source.default);
|
|
418
418
|
const handleFieldSource = (fields, rawFields) => {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
419
|
+
import_lodash.default.castArray(fields).forEach((field, index) => {
|
|
420
|
+
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
|
+
}
|
|
427
|
+
if (!source) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
const [collectionSource, fieldSource] = source.split(".");
|
|
431
|
+
const collectionField = (_a = this.app.db.getCollection(collectionSource)) == null ? void 0 : _a.getField(fieldSource);
|
|
432
|
+
if (!collectionField) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
const newOptions = {};
|
|
436
|
+
import_lodash.default.merge(newOptions, import_lodash.default.omit(collectionField.options, "name"));
|
|
437
|
+
const currentValues = field && typeof field.get === "function" ? field.get() : field;
|
|
438
|
+
import_lodash.default.mergeWith(newOptions, currentValues, (objValue, srcValue) => {
|
|
439
|
+
if (srcValue === null) {
|
|
440
|
+
return objValue;
|
|
426
441
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
import_lodash.default.mergeWith(newOptions, field.get(), (objValue, srcValue) => {
|
|
430
|
-
if (srcValue === null) {
|
|
431
|
-
return objValue;
|
|
432
|
-
}
|
|
433
|
-
});
|
|
442
|
+
});
|
|
443
|
+
if (field && typeof field.set === "function") {
|
|
434
444
|
field.set("options", newOptions);
|
|
445
|
+
} else {
|
|
446
|
+
fields[index] = {
|
|
447
|
+
...field,
|
|
448
|
+
...newOptions
|
|
449
|
+
};
|
|
435
450
|
}
|
|
436
451
|
const fieldTypes = import_database.fieldTypeMap[this.db.options.dialect];
|
|
437
452
|
if (rawFields && fieldTypes) {
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
const
|
|
442
|
-
|
|
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
|
+
}
|
|
443
469
|
}
|
|
444
470
|
}
|
|
445
|
-
}
|
|
471
|
+
});
|
|
446
472
|
};
|
|
447
473
|
this.app.resourceManager.use(async function handleFieldSourceMiddleware(ctx, next) {
|
|
448
|
-
var _a
|
|
474
|
+
var _a;
|
|
449
475
|
await next();
|
|
450
|
-
if (ctx.action.resourceName === "collections" && ctx.action.actionName == "
|
|
476
|
+
if (ctx.action.resourceName === "collections" && ctx.action.actionName == "listMeta") {
|
|
451
477
|
for (const collection of ctx.body) {
|
|
452
|
-
if (collection.
|
|
478
|
+
if (collection.view === true) {
|
|
453
479
|
const fields = collection.fields;
|
|
454
480
|
handleFieldSource(fields);
|
|
455
481
|
}
|
|
@@ -467,7 +493,7 @@ class PluginDataSourceMainServer extends import_server.Plugin {
|
|
|
467
493
|
} catch (err) {
|
|
468
494
|
}
|
|
469
495
|
}
|
|
470
|
-
handleFieldSource(((
|
|
496
|
+
handleFieldSource(((_a = ctx.action.params) == null ? void 0 : _a.paginate) == "false" ? ctx.body : ctx.body.rows, rawFields);
|
|
471
497
|
}
|
|
472
498
|
if (ctx.action.resourceName == "collections.fields" && ctx.action.actionName == "get") {
|
|
473
499
|
handleFieldSource(ctx.body);
|
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.
|
|
9
|
+
"version": "2.0.0-beta.3",
|
|
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": "
|
|
28
|
+
"gitHead": "6c178de2050651bcfcc0b2708de0246977eac510",
|
|
29
29
|
"keywords": [
|
|
30
30
|
"Data sources"
|
|
31
31
|
]
|