@nocobase/plugin-data-source-manager 2.0.0-alpha.5 → 2.0.0-alpha.51
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/client/1a8cce8035a89dd9.js +1 -1
- package/dist/client/2695e7fbad1ec078.js +10 -0
- package/dist/client/2f7a418e7935984d.js +10 -0
- package/dist/client/a279f7ca19e59f87.js +10 -0
- package/dist/client/component/MainDataSourceManager/Configuration/db-sync/LoadCollectionAction.d.ts +15 -0
- package/dist/client/component/MainDataSourceManager/Configuration/db-sync/SyncFieldChangesAction.d.ts +10 -0
- package/dist/client/component/MainDataSourceManager/Configuration/db-sync/SyncFromDatabaseAction.d.ts +10 -0
- package/dist/client/dbf5ddf434ab29c0.js +10 -0
- package/dist/client/e7a513a5b431455b.js +10 -0
- package/dist/client/fdae18574fda07af.js +10 -0
- package/dist/client/hooks/index.d.ts +3 -4
- package/dist/client/hooks/useDataSourceActions.d.ts +14 -0
- package/dist/client/hooks/useDataSourceRefresh.d.ts +18 -0
- package/dist/client/hooks/useResourceData.d.ts +31 -0
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +9 -8
- package/dist/locale/de-DE.json +35 -30
- package/dist/locale/en-US.json +45 -0
- package/dist/locale/es-ES.json +45 -0
- package/dist/locale/fr-FR.json +45 -0
- package/dist/locale/hu-HU.json +45 -0
- package/dist/locale/id-ID.json +45 -0
- package/dist/locale/it-IT.json +35 -30
- package/dist/locale/ja-JP.json +34 -29
- package/dist/locale/ko-KR.json +45 -0
- package/dist/locale/nl-NL.json +44 -40
- package/dist/locale/pt-BR.json +45 -0
- package/dist/locale/ru-RU.json +46 -0
- package/dist/locale/tr-TR.json +45 -0
- package/dist/locale/uk-UA.json +45 -0
- package/dist/locale/vi-VN.json +45 -0
- package/dist/locale/zh-CN.json +35 -30
- package/dist/locale/zh-TW.json +45 -0
- package/dist/server/actions/data-sources.d.ts +17 -0
- package/dist/server/actions/data-sources.js +114 -0
- package/dist/server/middlewares/load-tables.d.ts +10 -0
- package/dist/server/middlewares/load-tables.js +93 -0
- package/dist/server/plugin.js +10 -96
- package/dist/server/resourcers/data-sources-collections.d.ts +0 -2
- package/dist/server/resourcers/data-sources-collections.js +0 -83
- package/dist/server/utils.d.ts +3 -0
- package/dist/server/utils.js +45 -0
- package/package.json +5 -2
- package/dist/client/0e6cf640dde183c8.js +0 -10
- package/dist/client/7b6cb59b157f5087.js +0 -10
- package/dist/client/9aff90e19fbd41b6.js +0 -10
- package/dist/client/b3873b8560b4de87.js +0 -10
- package/dist/client/cab6d8ac1e107ea5.js +0 -10
- package/dist/client/cc4271412c5e6495.js +0 -10
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Allow adding and modifying collection": "Allow adding and modifying collection",
|
|
3
|
+
"Are you sure you want to set the \"{{title}}\" field as a record unique key? This setting cannot be changed after it's been set.": "Are you sure you want to set the \"{{title}}\" field as a record unique key? This setting cannot be changed after it's been set.",
|
|
4
|
+
"Available tables": "Available tables",
|
|
5
|
+
"Collections": "Collections",
|
|
6
|
+
"Connection successful": "Connection successful",
|
|
7
|
+
"Data source display name": "Data source display name",
|
|
8
|
+
"Data source manager": "Data source manager",
|
|
9
|
+
"Data source name": "Data source name",
|
|
10
|
+
"Data source synchronization in progress": "Data source synchronization in progress",
|
|
11
|
+
"Data source synchronization successful": "Data source synchronization successful",
|
|
12
|
+
"Data sources": "Data sources",
|
|
13
|
+
"Database": "Database",
|
|
14
|
+
"Description": "Description",
|
|
15
|
+
"Display name": "Display name",
|
|
16
|
+
"Failed": "Thất bại",
|
|
17
|
+
"Field database type": "Field database type",
|
|
18
|
+
"Field interface": "Giao diện trường",
|
|
19
|
+
"Field synchronization confirmation prompt": "Are you sure you want to synchronize fields from database? Depends on the number of tables and fields, This operation may take anywhere from a few seconds to several dozen seconds. If you only need to sync specific tables, please use the \"Configure Fields\" - \"Sync from database\" for those tables.",
|
|
20
|
+
"Filter data based on the specific field, with the requirement that the field value must be unique.": "Filter data based on the specific field, with the requirement that the field value must be unique.",
|
|
21
|
+
"Filter target key": "Filter target key",
|
|
22
|
+
"Host": "Host",
|
|
23
|
+
"If a collection lacks a primary key, you must configure a unique record key to locate row records within a block, failure to configure this will prevent the creation of data blocks for the collection.": "If a collection lacks a primary key, you must configure a unique record key to locate row records within a block, failure to configure this will prevent the creation of data blocks for the collection.",
|
|
24
|
+
"Load tables from database": "Load tables from database",
|
|
25
|
+
"Loaded": "Loaded",
|
|
26
|
+
"Loading": "Đang tải",
|
|
27
|
+
"No external data source plugin installed": "No external data source plugin installed",
|
|
28
|
+
"OK": "OK",
|
|
29
|
+
"Password": "Mật khẩu",
|
|
30
|
+
"Permissions": "Quyền",
|
|
31
|
+
"Please select a field.": "Please select a field.",
|
|
32
|
+
"Port": "Port",
|
|
33
|
+
"Reloading": "Reloading",
|
|
34
|
+
"Select field": "Select field",
|
|
35
|
+
"Selected tables": "Selected tables",
|
|
36
|
+
"Status": "Trạng thái",
|
|
37
|
+
"Storage": "Storage",
|
|
38
|
+
"Sync field changes from database": "Sync field changes from database",
|
|
39
|
+
"Test Connection": "Test Connection",
|
|
40
|
+
"The following field types are not compatible and do not support output and display": "The following field types are not compatible and do not support output and display",
|
|
41
|
+
"Type": "Loại",
|
|
42
|
+
"Unknown field type": "Unknown field type",
|
|
43
|
+
"Username": "Username",
|
|
44
|
+
"View documentation": "View documentation"
|
|
45
|
+
}
|
package/dist/locale/zh-CN.json
CHANGED
|
@@ -1,40 +1,45 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"Allow adding and modifying collection": "允许添加和修改数据表结构",
|
|
3
|
+
"Are you sure you want to set the \"{{title}}\" field as a record unique key? This setting cannot be changed after it's been set.": "你确定将 “{{title}}” 字段设置为主键吗?设置成功后不可修改。",
|
|
4
|
+
"Available tables": "可选数据表",
|
|
5
|
+
"Collections": "数据表",
|
|
6
|
+
"Connection successful": "连接成功",
|
|
3
7
|
"Data source display name": "数据源名称",
|
|
4
|
-
"Host": "服务器地址",
|
|
5
|
-
"Port": "端口",
|
|
6
|
-
"Database": "数据库",
|
|
7
8
|
"Data source manager": "数据源管理",
|
|
9
|
+
"Data source name": "数据源标识",
|
|
10
|
+
"Data source synchronization in progress": "数据源同步中",
|
|
11
|
+
"Data source synchronization successful": "数据源同步成功",
|
|
8
12
|
"Data sources": "数据源",
|
|
9
|
-
"
|
|
10
|
-
"View documentation": "查看文档",
|
|
11
|
-
"Test Connection": "测试连接",
|
|
12
|
-
"Connection successful": "连接成功",
|
|
13
|
-
"Display name": "名称",
|
|
14
|
-
"Username": "用户名",
|
|
15
|
-
"Password": "密码",
|
|
16
|
-
"Type": "类型",
|
|
13
|
+
"Database": "数据库",
|
|
17
14
|
"Description": "描述",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"Permissions": "权限",
|
|
21
|
-
"Allow adding and modifying collection": "允许添加和修改数据表结构",
|
|
22
|
-
"Unknown field type": "未知字段类型",
|
|
23
|
-
"The following field types are not compatible and do not support output and display": "以下字段类型未适配,不支持输出和显示",
|
|
15
|
+
"Display name": "名称",
|
|
16
|
+
"Failed": "加载失败",
|
|
24
17
|
"Field database type": "字段数据库类型",
|
|
25
18
|
"Field interface": "UI类型",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
19
|
+
"Field synchronization confirmation prompt": "确认要对所有数据表执行字段同步吗?取决于数据表和字段数量,可能会耗时几秒到几十秒。若只需同步个别表,请使用相应表的“配置字段” - “从数据库同步”进行操作。",
|
|
20
|
+
"Filter data based on the specific field, with the requirement that the field value must be unique.": "根据特定的字段筛选数据,字段值必须具备唯一性。",
|
|
21
|
+
"Filter target key": "筛选目标键",
|
|
22
|
+
"Host": "服务器地址",
|
|
23
|
+
"If a collection lacks a primary key, you must configure a unique record key to locate row records within a block, failure to configure this will prevent the creation of data blocks for the collection.": "当数据表没有主键时,你需要配置记录唯一标识符,用于在区块中定位行记录,不配置将无法创建该表的数据区块。",
|
|
24
|
+
"Load tables from database": "从数据库加载表",
|
|
29
25
|
"Loaded": "已加载",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"Data source synchronization successful": "数据源同步成功",
|
|
33
|
-
"Filter target key":"筛选目标键",
|
|
34
|
-
"Select field": "选择字段",
|
|
26
|
+
"Loading": "加载中",
|
|
27
|
+
"No external data source plugin installed": "未安装外部数据源",
|
|
35
28
|
"OK": "确定",
|
|
29
|
+
"Password": "密码",
|
|
30
|
+
"Permissions": "权限",
|
|
36
31
|
"Please select a field.": "请选择一个字段。",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
32
|
+
"Port": "端口",
|
|
33
|
+
"Reloading": "加载中",
|
|
34
|
+
"Select field": "选择字段",
|
|
35
|
+
"Selected tables": "已选数据表",
|
|
36
|
+
"Status": "状态",
|
|
37
|
+
"Storage": "文件地址",
|
|
38
|
+
"Sync field changes from database": "从数据库同步字段变更",
|
|
39
|
+
"Test Connection": "测试连接",
|
|
40
|
+
"The following field types are not compatible and do not support output and display": "以下字段类型未适配,不支持输出和显示",
|
|
41
|
+
"Type": "类型",
|
|
42
|
+
"Unknown field type": "未知字段类型",
|
|
43
|
+
"Username": "用户名",
|
|
44
|
+
"View documentation": "查看文档"
|
|
45
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Allow adding and modifying collection": "Allow adding and modifying collection",
|
|
3
|
+
"Are you sure you want to set the \"{{title}}\" field as a record unique key? This setting cannot be changed after it's been set.": "Are you sure you want to set the \"{{title}}\" field as a record unique key? This setting cannot be changed after it's been set.",
|
|
4
|
+
"Available tables": "Available tables",
|
|
5
|
+
"Collections": "Collections",
|
|
6
|
+
"Connection successful": "Connection successful",
|
|
7
|
+
"Data source display name": "Data source display name",
|
|
8
|
+
"Data source manager": "Data source manager",
|
|
9
|
+
"Data source name": "Data source name",
|
|
10
|
+
"Data source synchronization in progress": "Data source synchronization in progress",
|
|
11
|
+
"Data source synchronization successful": "Data source synchronization successful",
|
|
12
|
+
"Data sources": "Data sources",
|
|
13
|
+
"Database": "Database",
|
|
14
|
+
"Description": "Description",
|
|
15
|
+
"Display name": "Display name",
|
|
16
|
+
"Failed": "Failed",
|
|
17
|
+
"Field database type": "Field database type",
|
|
18
|
+
"Field interface": "Field interface",
|
|
19
|
+
"Field synchronization confirmation prompt": "Are you sure you want to synchronize fields from database? Depends on the number of tables and fields, This operation may take anywhere from a few seconds to several dozen seconds. If you only need to sync specific tables, please use the \"Configure Fields\" - \"Sync from database\" for those tables.",
|
|
20
|
+
"Filter data based on the specific field, with the requirement that the field value must be unique.": "Filter data based on the specific field, with the requirement that the field value must be unique.",
|
|
21
|
+
"Filter target key": "Filter target key",
|
|
22
|
+
"Host": "Host",
|
|
23
|
+
"If a collection lacks a primary key, you must configure a unique record key to locate row records within a block, failure to configure this will prevent the creation of data blocks for the collection.": "If a collection lacks a primary key, you must configure a unique record key to locate row records within a block, failure to configure this will prevent the creation of data blocks for the collection.",
|
|
24
|
+
"Load tables from database": "Load tables from database",
|
|
25
|
+
"Loaded": "Loaded",
|
|
26
|
+
"Loading": "Loading",
|
|
27
|
+
"No external data source plugin installed": "No external data source plugin installed",
|
|
28
|
+
"OK": "OK",
|
|
29
|
+
"Password": "Password",
|
|
30
|
+
"Permissions": "Permissions",
|
|
31
|
+
"Please select a field.": "Please select a field.",
|
|
32
|
+
"Port": "Port",
|
|
33
|
+
"Reloading": "Reloading",
|
|
34
|
+
"Select field": "Select field",
|
|
35
|
+
"Selected tables": "Selected tables",
|
|
36
|
+
"Status": "Status",
|
|
37
|
+
"Storage": "Storage",
|
|
38
|
+
"Sync field changes from database": "Sync field changes from database",
|
|
39
|
+
"Test Connection": "Test Connection",
|
|
40
|
+
"The following field types are not compatible and do not support output and display": "The following field types are not compatible and do not support output and display",
|
|
41
|
+
"Type": "Type",
|
|
42
|
+
"Unknown field type": "Unknown field type",
|
|
43
|
+
"Username": "Username",
|
|
44
|
+
"View documentation": "View documentation"
|
|
45
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Context, Next } from '@nocobase/actions';
|
|
10
|
+
declare const _default: {
|
|
11
|
+
"dataSources:listEnabled"(ctx: Context, next: Next): Promise<void>;
|
|
12
|
+
"dataSources:testConnection"(ctx: Context, next: Next): Promise<void>;
|
|
13
|
+
"dataSources:refresh"(ctx: Context, next: Next): Promise<void>;
|
|
14
|
+
"dataSources:readTables"(ctx: Context, next: Next): Promise<void>;
|
|
15
|
+
"dataSources:loadTables"(ctx: Context, next: Next): Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var data_sources_exports = {};
|
|
28
|
+
__export(data_sources_exports, {
|
|
29
|
+
default: () => data_sources_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(data_sources_exports);
|
|
32
|
+
var import_utils = require("../utils");
|
|
33
|
+
const canRefreshStatus = ["loaded", "loading-failed", "reloading-failed"];
|
|
34
|
+
var data_sources_default = {
|
|
35
|
+
async ["dataSources:listEnabled"](ctx, next) {
|
|
36
|
+
const dataSources = await ctx.db.getRepository("dataSources").find({
|
|
37
|
+
filter: {
|
|
38
|
+
enabled: true,
|
|
39
|
+
"type.$ne": "main"
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
ctx.body = dataSources.map((dataSourceModel) => {
|
|
43
|
+
return (0, import_utils.mapDataSourceWithCollection)(ctx.app, dataSourceModel);
|
|
44
|
+
});
|
|
45
|
+
await next();
|
|
46
|
+
},
|
|
47
|
+
async ["dataSources:testConnection"](ctx, next) {
|
|
48
|
+
const { values } = ctx.action.params;
|
|
49
|
+
const { options, type } = values;
|
|
50
|
+
const klass = ctx.app.dataSourceManager.factory.getClass(type);
|
|
51
|
+
try {
|
|
52
|
+
await klass.testConnection(ctx.app.environment.renderJsonTemplate(options));
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw new Error(`Test connection failed: ${error.message}`);
|
|
55
|
+
}
|
|
56
|
+
ctx.body = {
|
|
57
|
+
success: true
|
|
58
|
+
};
|
|
59
|
+
await next();
|
|
60
|
+
},
|
|
61
|
+
async ["dataSources:refresh"](ctx, next) {
|
|
62
|
+
const plugin = ctx.app.pm.get("data-source-manager");
|
|
63
|
+
const { filterByTk, clientStatus } = ctx.action.params;
|
|
64
|
+
const dataSourceModel = await ctx.db.getRepository("dataSources").findOne({
|
|
65
|
+
filter: {
|
|
66
|
+
key: filterByTk
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
const currentStatus = plugin.dataSourceStatus[filterByTk];
|
|
70
|
+
if (canRefreshStatus.includes(currentStatus) && (clientStatus ? clientStatus && canRefreshStatus.includes(clientStatus) : true)) {
|
|
71
|
+
dataSourceModel.loadIntoApplication({
|
|
72
|
+
app: ctx.app,
|
|
73
|
+
refresh: true
|
|
74
|
+
});
|
|
75
|
+
ctx.app.syncMessageManager.publish(plugin.name, {
|
|
76
|
+
type: "loadDataSource",
|
|
77
|
+
dataSourceKey: dataSourceModel.get("key")
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
ctx.body = {
|
|
81
|
+
status: plugin.dataSourceStatus[filterByTk]
|
|
82
|
+
};
|
|
83
|
+
await next();
|
|
84
|
+
},
|
|
85
|
+
async ["dataSources:readTables"](ctx, next) {
|
|
86
|
+
const { dataSourceKey, dbOptions } = ctx.action.params.values || {};
|
|
87
|
+
const dataSourceManager = ctx.app.dataSourceManager;
|
|
88
|
+
let dataSource;
|
|
89
|
+
if (dbOptions) {
|
|
90
|
+
dataSource = dataSourceManager.factory.create(dbOptions.type, {
|
|
91
|
+
name: dataSourceKey,
|
|
92
|
+
...dbOptions
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
dataSource = dataSourceManager.dataSources.get(dataSourceKey);
|
|
96
|
+
if (!dataSource) {
|
|
97
|
+
throw new Error(`dataSource ${dataSourceKey} not found`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const tables = await dataSource.readTables();
|
|
101
|
+
ctx.body = tables;
|
|
102
|
+
await next();
|
|
103
|
+
},
|
|
104
|
+
async ["dataSources:loadTables"](ctx, next) {
|
|
105
|
+
const { dataSourceKey, tables } = ctx.action.params.values || {};
|
|
106
|
+
const dataSourceManager = ctx.app.dataSourceManager;
|
|
107
|
+
const dataSource = dataSourceManager.dataSources.get(dataSourceKey);
|
|
108
|
+
if (!dataSource) {
|
|
109
|
+
throw new Error(`dataSource ${dataSourceKey} not found`);
|
|
110
|
+
}
|
|
111
|
+
await dataSource.loadTables(ctx, tables);
|
|
112
|
+
await next();
|
|
113
|
+
}
|
|
114
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Context, Next } from '@nocobase/actions';
|
|
10
|
+
export declare function loadDataSourceTablesIntoCollections(ctx: Context, next: Next): Promise<any>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var load_tables_exports = {};
|
|
38
|
+
__export(load_tables_exports, {
|
|
39
|
+
loadDataSourceTablesIntoCollections: () => loadDataSourceTablesIntoCollections
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(load_tables_exports);
|
|
42
|
+
var import_data_source_manager = require("@nocobase/data-source-manager");
|
|
43
|
+
var import_constants = require("../constants");
|
|
44
|
+
var import_lodash = __toESM(require("lodash"));
|
|
45
|
+
async function loadDataSourceTablesIntoCollections(ctx, next) {
|
|
46
|
+
const { actionName, resourceName, params } = ctx.action;
|
|
47
|
+
if (resourceName === "dataSources" && (actionName === "create" || actionName === "update")) {
|
|
48
|
+
const dataSourcesRepo = ctx.app.db.getRepository("dataSources");
|
|
49
|
+
const { options, type, collections, key } = params.values || {};
|
|
50
|
+
const dataSourceProvider = actionName === "update" ? {
|
|
51
|
+
get: async () => {
|
|
52
|
+
const { filterByTk } = params;
|
|
53
|
+
const model = await dataSourcesRepo.findByTargetKey(filterByTk);
|
|
54
|
+
if (import_lodash.default.isEqual(model.get("options"), options)) {
|
|
55
|
+
return ctx.app.dataSourceManager.get(filterByTk);
|
|
56
|
+
} else {
|
|
57
|
+
return ctx.app.dataSourceManager.factory.create(model.type, {
|
|
58
|
+
name: filterByTk,
|
|
59
|
+
...options
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} : {
|
|
64
|
+
get: () => ctx.app.dataSourceManager.factory.create(type, {
|
|
65
|
+
name: key,
|
|
66
|
+
...options
|
|
67
|
+
})
|
|
68
|
+
};
|
|
69
|
+
const dataSource = await dataSourceProvider.get();
|
|
70
|
+
dataSource.setLogger(ctx.logger);
|
|
71
|
+
if (!(dataSource instanceof import_data_source_manager.DatabaseDataSource)) {
|
|
72
|
+
return next();
|
|
73
|
+
}
|
|
74
|
+
if (options == null ? void 0 : options.addAllCollections) {
|
|
75
|
+
const allTables = await dataSource.introspector.getTables();
|
|
76
|
+
if (allTables.length > import_constants.ALLOW_MAX_COLLECTIONS_COUNT) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`The number of collections exceeds the limit of ${import_constants.ALLOW_MAX_COLLECTIONS_COUNT}. Please remove some collections before adding new ones.`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
await dataSource.loadTables(ctx, collections);
|
|
83
|
+
}
|
|
84
|
+
if (collections) {
|
|
85
|
+
delete ctx.action.params.values.collections;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
await next();
|
|
89
|
+
}
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
loadDataSourceTablesIntoCollections
|
|
93
|
+
});
|
package/dist/server/plugin.js
CHANGED
|
@@ -41,7 +41,6 @@ __export(plugin_exports, {
|
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(plugin_exports);
|
|
43
43
|
var import_server = require("@nocobase/server");
|
|
44
|
-
var import_path = require("path");
|
|
45
44
|
var import_data_sources_collection_model = require("./models/data-sources-collection-model");
|
|
46
45
|
var import_data_sources_field_model = require("./models/data-sources-field-model");
|
|
47
46
|
var import_data_sources_collections = __toESM(require("./resourcers/data-sources-collections"));
|
|
@@ -49,14 +48,14 @@ var import_data_sources_collections_fields = __toESM(require("./resourcers/data-
|
|
|
49
48
|
var import_data_sources_resources = __toESM(require("./resourcers/data-sources-resources"));
|
|
50
49
|
var import_data_sources_roles = __toESM(require("./resourcers/data-sources-roles"));
|
|
51
50
|
var import_roles_data_sources_collections = require("./resourcers/roles-data-sources-collections");
|
|
51
|
+
var import_data_sources = __toESM(require("./actions/data-sources"));
|
|
52
52
|
var import_lodash = __toESM(require("lodash"));
|
|
53
53
|
var import_connections_roles_resources = require("./models/connections-roles-resources");
|
|
54
54
|
var import_connections_roles_resources_action = require("./models/connections-roles-resources-action");
|
|
55
55
|
var import_data_source = require("./models/data-source");
|
|
56
56
|
var import_data_sources_roles_model = require("./models/data-sources-roles-model");
|
|
57
57
|
var import_acl = require("@nocobase/acl");
|
|
58
|
-
var
|
|
59
|
-
const canRefreshStatus = ["loaded", "loading-failed", "reloading-failed"];
|
|
58
|
+
var import_load_tables = require("./middlewares/load-tables");
|
|
60
59
|
class PluginDataSourceManagerServer extends import_server.Plugin {
|
|
61
60
|
dataSourceErrors = {};
|
|
62
61
|
dataSourceStatus = {};
|
|
@@ -312,41 +311,7 @@ class PluginDataSourceManagerServer extends import_server.Plugin {
|
|
|
312
311
|
}
|
|
313
312
|
await next();
|
|
314
313
|
});
|
|
315
|
-
this.app.resourceManager.use(
|
|
316
|
-
var _a;
|
|
317
|
-
if (!ctx.action) {
|
|
318
|
-
await next();
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
const { actionName, resourceName, params } = ctx.action;
|
|
322
|
-
if (resourceName === "dataSources" && (actionName === "add" || actionName === "update")) {
|
|
323
|
-
const { values, filterByTk: dataSourceKey } = params;
|
|
324
|
-
if ((_a = values.options) == null ? void 0 : _a.addAllCollections) {
|
|
325
|
-
let introspector = null;
|
|
326
|
-
const dataSourceManager = ctx.app["dataSourceManager"];
|
|
327
|
-
if (actionName === "add") {
|
|
328
|
-
const klass = dataSourceManager.factory.getClass(values.options.type);
|
|
329
|
-
const dataSource = new klass(dbOptions);
|
|
330
|
-
introspector = dataSource.collectionManager.dataSource.createDatabaseIntrospector(
|
|
331
|
-
dataSource.collectionManager.db
|
|
332
|
-
);
|
|
333
|
-
} else {
|
|
334
|
-
const dataSource = dataSourceManager.dataSources.get(dataSourceKey);
|
|
335
|
-
if (!dataSource) {
|
|
336
|
-
throw new Error(`dataSource ${dataSourceKey} not found`);
|
|
337
|
-
}
|
|
338
|
-
introspector = dataSource["introspector"];
|
|
339
|
-
}
|
|
340
|
-
const allCollections = await introspector.getCollections();
|
|
341
|
-
if (allCollections.length > import_constants.ALLOW_MAX_COLLECTIONS_COUNT) {
|
|
342
|
-
throw new Error(
|
|
343
|
-
`The number of collections exceeds the limit of ${import_constants.ALLOW_MAX_COLLECTIONS_COUNT}. Please remove some collections before adding new ones.`
|
|
344
|
-
);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
await next();
|
|
349
|
-
});
|
|
314
|
+
this.app.resourceManager.use(import_load_tables.loadDataSourceTablesIntoCollections);
|
|
350
315
|
this.app.use(async function handleAppendDataSourceCollection(ctx, next) {
|
|
351
316
|
await next();
|
|
352
317
|
if (!ctx.action) {
|
|
@@ -367,63 +332,13 @@ class PluginDataSourceManagerServer extends import_server.Plugin {
|
|
|
367
332
|
}
|
|
368
333
|
});
|
|
369
334
|
const self = this;
|
|
370
|
-
this.app.
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
});
|
|
378
|
-
ctx.body = dataSources.map((dataSourceModel) => {
|
|
379
|
-
return mapDataSourceWithCollection(dataSourceModel);
|
|
380
|
-
});
|
|
381
|
-
await next();
|
|
382
|
-
},
|
|
383
|
-
async ["dataSources:testConnection"](ctx, next) {
|
|
384
|
-
const { values } = ctx.action.params;
|
|
385
|
-
const { options, type } = values;
|
|
386
|
-
const klass = ctx.app.dataSourceManager.factory.getClass(type);
|
|
387
|
-
try {
|
|
388
|
-
await klass.testConnection(self.renderJsonTemplate(options));
|
|
389
|
-
} catch (error) {
|
|
390
|
-
throw new Error(`Test connection failed: ${error.message}`);
|
|
391
|
-
}
|
|
392
|
-
ctx.body = {
|
|
393
|
-
success: true
|
|
394
|
-
};
|
|
395
|
-
await next();
|
|
396
|
-
},
|
|
397
|
-
async ["dataSources:refresh"](ctx, next) {
|
|
398
|
-
const { filterByTk, clientStatus } = ctx.action.params;
|
|
399
|
-
const dataSourceModel = await ctx.db.getRepository("dataSources").findOne({
|
|
400
|
-
filter: {
|
|
401
|
-
key: filterByTk
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
const currentStatus = plugin.dataSourceStatus[filterByTk];
|
|
405
|
-
if (canRefreshStatus.includes(currentStatus) && (clientStatus ? clientStatus && canRefreshStatus.includes(clientStatus) : true)) {
|
|
406
|
-
dataSourceModel.loadIntoApplication({
|
|
407
|
-
app: ctx.app,
|
|
408
|
-
refresh: true
|
|
409
|
-
});
|
|
410
|
-
ctx.app.syncMessageManager.publish(self.name, {
|
|
411
|
-
type: "loadDataSource",
|
|
412
|
-
dataSourceKey: dataSourceModel.get("key")
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
ctx.body = {
|
|
416
|
-
status: plugin.dataSourceStatus[filterByTk]
|
|
417
|
-
};
|
|
418
|
-
await next();
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
this.app.resourcer.define(import_data_sources_collections.default);
|
|
422
|
-
this.app.resourcer.define(import_data_sources_collections_fields.default);
|
|
423
|
-
this.app.resourcer.define(import_roles_data_sources_collections.rolesRemoteCollectionsResourcer);
|
|
424
|
-
this.app.resourcer.define(import_data_sources_roles.default);
|
|
425
|
-
this.app.resourcer.define(import_data_sources_resources.default);
|
|
426
|
-
this.app.resourcer.define({
|
|
335
|
+
this.app.resourceManager.registerActionHandlers(import_data_sources.default);
|
|
336
|
+
this.app.resourceManager.define(import_data_sources_collections.default);
|
|
337
|
+
this.app.resourceManager.define(import_data_sources_collections_fields.default);
|
|
338
|
+
this.app.resourceManager.define(import_roles_data_sources_collections.rolesRemoteCollectionsResourcer);
|
|
339
|
+
this.app.resourceManager.define(import_data_sources_roles.default);
|
|
340
|
+
this.app.resourceManager.define(import_data_sources_resources.default);
|
|
341
|
+
this.app.resourceManager.define({
|
|
427
342
|
name: "dataSources"
|
|
428
343
|
});
|
|
429
344
|
this.app.db.on("dataSourcesFields.beforeSave", async (model, options) => {
|
|
@@ -692,7 +607,6 @@ class PluginDataSourceManagerServer extends import_server.Plugin {
|
|
|
692
607
|
});
|
|
693
608
|
}
|
|
694
609
|
async load() {
|
|
695
|
-
await this.importCollections((0, import_path.resolve)(__dirname, "collections"));
|
|
696
610
|
}
|
|
697
611
|
}
|
|
698
612
|
var plugin_default = PluginDataSourceManagerServer;
|
|
@@ -41,8 +41,6 @@ __export(data_sources_collections_exports, {
|
|
|
41
41
|
module.exports = __toCommonJS(data_sources_collections_exports);
|
|
42
42
|
var import_lodash = __toESM(require("lodash"));
|
|
43
43
|
var import_database = require("@nocobase/database");
|
|
44
|
-
var import_lodash2 = __toESM(require("lodash"));
|
|
45
|
-
var import_constants = require("../constants");
|
|
46
44
|
var data_sources_collections_default = {
|
|
47
45
|
name: "dataSources.collections",
|
|
48
46
|
actions: {
|
|
@@ -136,87 +134,6 @@ var data_sources_collections_default = {
|
|
|
136
134
|
});
|
|
137
135
|
ctx.body = dataSourceCollectionRecord.toJSON();
|
|
138
136
|
await next();
|
|
139
|
-
},
|
|
140
|
-
async all(ctx, next) {
|
|
141
|
-
const params = ctx.action.params;
|
|
142
|
-
const { associatedIndex: dataSourceKey, isFirst, dbOptions } = params;
|
|
143
|
-
const dataSourceManager = ctx.app.dataSourceManager;
|
|
144
|
-
let introspector = null;
|
|
145
|
-
if (isFirst) {
|
|
146
|
-
const klass = dataSourceManager.factory.getClass(dbOptions.type);
|
|
147
|
-
const dataSource = new klass(dbOptions);
|
|
148
|
-
introspector = dataSource.collectionManager.dataSource.createDatabaseIntrospector(
|
|
149
|
-
dataSource.collectionManager.db
|
|
150
|
-
);
|
|
151
|
-
} else {
|
|
152
|
-
const dataSource = dataSourceManager.dataSources.get(dataSourceKey);
|
|
153
|
-
if (!dataSource) {
|
|
154
|
-
throw new Error(`dataSource ${dataSourceKey} not found`);
|
|
155
|
-
}
|
|
156
|
-
introspector = dataSource["introspector"];
|
|
157
|
-
}
|
|
158
|
-
const allCollections = await introspector.getCollections();
|
|
159
|
-
const selectedCollections = await ctx.db.getRepository("dataSourcesCollections").find({
|
|
160
|
-
filter: { dataSourceKey }
|
|
161
|
-
});
|
|
162
|
-
const selectedMap = import_lodash2.default.keyBy(selectedCollections, (x) => x.name);
|
|
163
|
-
const result = allCollections.map((collection) => {
|
|
164
|
-
return {
|
|
165
|
-
name: collection,
|
|
166
|
-
selected: !!selectedMap[collection]
|
|
167
|
-
};
|
|
168
|
-
});
|
|
169
|
-
ctx.body = result;
|
|
170
|
-
await next();
|
|
171
|
-
},
|
|
172
|
-
async add(ctx, next) {
|
|
173
|
-
const params = ctx.action.params;
|
|
174
|
-
const { associatedIndex: dataSourceKey, values } = params;
|
|
175
|
-
const collections = values.collections || [];
|
|
176
|
-
const dbOptions = values.dbOptions || {};
|
|
177
|
-
if (dbOptions.addAllCollections !== false) {
|
|
178
|
-
await next();
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
if (collections.length > import_constants.ALLOW_MAX_COLLECTIONS_COUNT) {
|
|
182
|
-
throw new Error(
|
|
183
|
-
`The number of collections exceeds the limit of ${import_constants.ALLOW_MAX_COLLECTIONS_COUNT}. Please remove some collections before adding new ones.`
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
const transaction = await ctx.db.sequelize.transaction();
|
|
187
|
-
const repo = ctx.db.getRepository("dataSourcesCollections");
|
|
188
|
-
const alreadyInserted = await repo.find({
|
|
189
|
-
filter: {
|
|
190
|
-
dataSourceKey
|
|
191
|
-
},
|
|
192
|
-
transaction
|
|
193
|
-
});
|
|
194
|
-
const alreadyInsertedNames = import_lodash2.default.keyBy(alreadyInserted, (x) => x.name);
|
|
195
|
-
const incomingCollections = import_lodash2.default.keyBy(collections);
|
|
196
|
-
const toBeInserted = collections.filter((collection) => !alreadyInsertedNames[collection]);
|
|
197
|
-
const toBeDeleted = Object.keys(alreadyInsertedNames).filter((name) => !incomingCollections[name]);
|
|
198
|
-
if (toBeInserted.length > 0) {
|
|
199
|
-
const insertCollections = toBeInserted.map((collection) => {
|
|
200
|
-
return { name: collection, dataSourceKey };
|
|
201
|
-
});
|
|
202
|
-
await repo.model.bulkCreate(insertCollections, { transaction });
|
|
203
|
-
}
|
|
204
|
-
if (toBeDeleted.length > 0) {
|
|
205
|
-
await repo.model.destroy({
|
|
206
|
-
where: {
|
|
207
|
-
dataSourceKey,
|
|
208
|
-
name: toBeDeleted
|
|
209
|
-
},
|
|
210
|
-
transaction
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
await transaction.commit();
|
|
214
|
-
const dataSource = ctx.app.dataSourceManager.dataSources.get(dataSourceKey);
|
|
215
|
-
if (dataSource) {
|
|
216
|
-
await dataSource.load({ refresh: true, condition: toBeInserted ? { name: { $in: toBeInserted } } : {} });
|
|
217
|
-
}
|
|
218
|
-
ctx.body = true;
|
|
219
|
-
await next();
|
|
220
137
|
}
|
|
221
138
|
}
|
|
222
139
|
};
|