@nocobase/plugin-data-source-manager 2.0.0-alpha.8 → 2.0.0-beta.1

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.
Files changed (54) hide show
  1. package/dist/client/1a8cce8035a89dd9.js +1 -1
  2. package/dist/client/260a6717d1f70d00.js +10 -0
  3. package/dist/client/2695e7fbad1ec078.js +10 -0
  4. package/dist/client/2f7a418e7935984d.js +10 -0
  5. package/dist/client/component/CollectionsManager/components/FieldTitleInput.d.ts +1 -1
  6. package/dist/client/component/CollectionsManager/components/FieldType.d.ts +1 -1
  7. package/dist/client/component/CollectionsTableField.d.ts +1 -1
  8. package/dist/client/component/MainDataSourceManager/Configuration/db-sync/LoadCollectionAction.d.ts +15 -0
  9. package/dist/client/component/MainDataSourceManager/Configuration/db-sync/SyncFieldChangesAction.d.ts +10 -0
  10. package/dist/client/component/MainDataSourceManager/Configuration/db-sync/SyncFromDatabaseAction.d.ts +10 -0
  11. package/dist/client/dbf5ddf434ab29c0.js +10 -0
  12. package/dist/client/ee0c98746b4afdbb.js +10 -0
  13. package/dist/client/fdae18574fda07af.js +10 -0
  14. package/dist/client/hooks/index.d.ts +3 -4
  15. package/dist/client/hooks/useDataSourceActions.d.ts +14 -0
  16. package/dist/client/hooks/useDataSourceRefresh.d.ts +18 -0
  17. package/dist/client/hooks/useResourceData.d.ts +31 -0
  18. package/dist/client/index.js +1 -1
  19. package/dist/externalVersion.js +11 -9
  20. package/dist/locale/de-DE.json +35 -30
  21. package/dist/locale/en-US.json +45 -0
  22. package/dist/locale/es-ES.json +45 -0
  23. package/dist/locale/fr-FR.json +45 -0
  24. package/dist/locale/hu-HU.json +45 -0
  25. package/dist/locale/id-ID.json +45 -0
  26. package/dist/locale/it-IT.json +35 -30
  27. package/dist/locale/ja-JP.json +34 -29
  28. package/dist/locale/ko-KR.json +45 -0
  29. package/dist/locale/nl-NL.json +44 -40
  30. package/dist/locale/pt-BR.json +45 -0
  31. package/dist/locale/ru-RU.json +46 -0
  32. package/dist/locale/tr-TR.json +45 -0
  33. package/dist/locale/uk-UA.json +45 -0
  34. package/dist/locale/vi-VN.json +45 -0
  35. package/dist/locale/zh-CN.json +35 -30
  36. package/dist/locale/zh-TW.json +45 -0
  37. package/dist/server/actions/data-sources.d.ts +17 -0
  38. package/dist/server/actions/data-sources.js +115 -0
  39. package/dist/server/middlewares/load-tables.d.ts +10 -0
  40. package/dist/server/middlewares/load-tables.js +93 -0
  41. package/dist/server/models/data-source.d.ts +1 -0
  42. package/dist/server/models/data-source.js +7 -3
  43. package/dist/server/plugin.js +10 -96
  44. package/dist/server/resourcers/data-sources-collections.d.ts +0 -2
  45. package/dist/server/resourcers/data-sources-collections.js +0 -83
  46. package/dist/server/utils.d.ts +3 -0
  47. package/dist/server/utils.js +45 -0
  48. package/package.json +5 -2
  49. package/dist/client/0e6cf640dde183c8.js +0 -10
  50. package/dist/client/7b6cb59b157f5087.js +0 -10
  51. package/dist/client/9aff90e19fbd41b6.js +0 -10
  52. package/dist/client/b3873b8560b4de87.js +0 -10
  53. package/dist/client/cab6d8ac1e107ea5.js +0 -10
  54. package/dist/client/cc4271412c5e6495.js +0 -10
@@ -0,0 +1,46 @@
1
+ {
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": "Available tables",
5
+ "Collections": "Коллекции",
6
+ "Connection successful": "Соединение успешно",
7
+ "Connection successful'": "Подключение успешно",
8
+ "Data source display name": "Отображаемое имя источника данных",
9
+ "Data source manager": "Менеджер источников данных",
10
+ "Data source name": "Имя источника данных",
11
+ "Data source synchronization in progress": "Выполняется синхронизация источника данных",
12
+ "Data source synchronization successful": "Синхронизация источника данных выполнена успешно",
13
+ "Data sources": "Источники данных",
14
+ "Database": "База данных",
15
+ "Description": "Описание",
16
+ "Display name": "Отображаемое имя",
17
+ "Failed": "Ошибка",
18
+ "Field database type": "Тип поля в базе данных",
19
+ "Field interface": "Интерфейс поля",
20
+ "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.",
21
+ "Filter data based on the specific field, with the requirement that the field value must be unique.": "Фильтровать данные на основе определенного поля с требованием уникальности значения поля.",
22
+ "Filter target key": "Целевой ключ фильтра",
23
+ "Host": "Хост",
24
+ "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.": "Если у коллекции отсутствует первичный ключ, необходимо настроить уникальный ключ записи для определения строковых записей в блоке, иначе создание блоков данных для коллекции будет невозможно.",
25
+ "Load tables from database": "Load tables from database",
26
+ "Loaded": "Загружено",
27
+ "Loading": "Загрузка",
28
+ "No external data source plugin installed": "Нет установленных плагинов внешних источников данных",
29
+ "OK": "OK",
30
+ "Password": "Пароль",
31
+ "Permissions": "Права доступа",
32
+ "Please select a field.": "Пожалуйста, выберите поле.",
33
+ "Port": "Порт",
34
+ "Reloading": "Перезагрузка",
35
+ "Select field": "Выбрать поле",
36
+ "Selected tables": "Selected tables",
37
+ "Status": "Статус",
38
+ "Storage": "Хранилище",
39
+ "Sync field changes from database": "Sync field changes from database",
40
+ "Test Connection": "Тест соединения",
41
+ "The following field types are not compatible and do not support output and display": "Следующие типы полей не совместимы и не поддерживают вывод и отображение",
42
+ "Type": "Тип",
43
+ "Unknown field type": "Неизвестный тип поля",
44
+ "Username": "Имя пользователя",
45
+ "View documentation": "Просмотр документации"
46
+ }
@@ -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,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,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
+ }
@@ -1,40 +1,45 @@
1
1
  {
2
- "Data source name": "数据源标识",
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
- "No external data source plugin installed": "未安装外部数据源",
10
- "View documentation": "查看文档",
11
- "Test Connection": "测试连接",
12
- "Connection successful": "连接成功",
13
- "Display name": "名称",
14
- "Username": "用户名",
15
- "Password": "密码",
16
- "Type": "类型",
13
+ "Database": "数据库",
17
14
  "Description": "描述",
18
- "Storage": "文件地址",
19
- "Collections": "数据表",
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
- "Status": "状态",
27
- "Loading": "加载中",
28
- "Failed": "加载失败",
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
- "Reloading": "加载中",
31
- "Data source synchronization in progress": "数据源同步中",
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
- "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}}” 字段设置为主键吗?设置成功后不可修改。",
38
- "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.": "当数据表没有主键时,你需要配置记录唯一标识符,用于在区块中定位行记录,不配置将无法创建该表的数据区块。",
39
- "Filter data based on the specific field, with the requirement that the field value must be unique.": "根据特定的字段筛选数据,字段值必须具备唯一性。"
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,115 @@
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
+ reuseDB: true
75
+ });
76
+ ctx.app.syncMessageManager.publish(plugin.name, {
77
+ type: "loadDataSource",
78
+ dataSourceKey: dataSourceModel.get("key")
79
+ });
80
+ }
81
+ ctx.body = {
82
+ status: plugin.dataSourceStatus[filterByTk]
83
+ };
84
+ await next();
85
+ },
86
+ async ["dataSources:readTables"](ctx, next) {
87
+ const { dataSourceKey, dbOptions } = ctx.action.params.values || {};
88
+ const dataSourceManager = ctx.app.dataSourceManager;
89
+ let dataSource;
90
+ if (dbOptions) {
91
+ dataSource = dataSourceManager.factory.create(dbOptions.type, {
92
+ name: dataSourceKey,
93
+ ...dbOptions
94
+ });
95
+ } else {
96
+ dataSource = dataSourceManager.dataSources.get(dataSourceKey);
97
+ if (!dataSource) {
98
+ throw new Error(`dataSource ${dataSourceKey} not found`);
99
+ }
100
+ }
101
+ const tables = await dataSource.readTables();
102
+ ctx.body = tables;
103
+ await next();
104
+ },
105
+ async ["dataSources:loadTables"](ctx, next) {
106
+ const { dataSourceKey, tables } = ctx.action.params.values || {};
107
+ const dataSourceManager = ctx.app.dataSourceManager;
108
+ const dataSource = dataSourceManager.dataSources.get(dataSourceKey);
109
+ if (!dataSource) {
110
+ throw new Error(`dataSource ${dataSourceKey} not found`);
111
+ }
112
+ await dataSource.loadTables(ctx, tables);
113
+ await next();
114
+ }
115
+ };
@@ -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
+ });
@@ -21,6 +21,7 @@ export declare class DataSourceModel extends Model {
21
21
  transaction?: Transaction;
22
22
  loadAtAfterStart?: boolean;
23
23
  refresh?: boolean;
24
+ reuseDB?: boolean;
24
25
  }): Promise<void>;
25
26
  private loadLocalData;
26
27
  }
@@ -98,7 +98,7 @@ class DataSourceModel extends import_database.Model {
98
98
  }
99
99
  }
100
100
  async loadIntoApplication(options) {
101
- const { app, loadAtAfterStart, refresh } = options;
101
+ const { app, loadAtAfterStart, refresh, reuseDB } = options;
102
102
  const dataSourceKey = this.get("key");
103
103
  const pluginDataSourceManagerServer = app.pm.get("data-source-manager");
104
104
  if (pluginDataSourceManagerServer.dataSourceStatus[dataSourceKey] === "loaded") {
@@ -109,13 +109,16 @@ class DataSourceModel extends import_database.Model {
109
109
  const type = this.get("type");
110
110
  const createOptions = this.get("options");
111
111
  try {
112
+ const oldDataSource = app.dataSourceManager.get(dataSourceKey);
113
+ const { db: databaseInstance = void 0 } = reuseDB === true ? (oldDataSource == null ? void 0 : oldDataSource.collectionManager) ?? {} : {};
112
114
  const dataSource = app.dataSourceManager.factory.create(type, {
113
115
  ...createOptions,
114
116
  name: dataSourceKey,
115
117
  logger: app.logger.child({ dataSourceKey }),
116
118
  sqlLogger: app.sqlLogger.child({ dataSourceKey }),
117
119
  cache: app.cache,
118
- storagePath: import_path.default.join(process.cwd(), "storage", "cache", "apps", app.name)
120
+ storagePath: import_path.default.join(process.cwd(), "storage", "cache", "apps", app.name),
121
+ databaseInstance
119
122
  });
120
123
  dataSource.on("loadingProgress", (progress) => {
121
124
  pluginDataSourceManagerServer.dataSourceLoadingProgress[dataSourceKey] = progress;
@@ -137,7 +140,8 @@ class DataSourceModel extends import_database.Model {
137
140
  await this.loadIntoACL({ app, acl, transaction: options.transaction });
138
141
  await app.dataSourceManager.add(dataSource, {
139
142
  localData: await this.loadLocalData(),
140
- refresh
143
+ refresh,
144
+ reuseDB
141
145
  });
142
146
  } catch (e) {
143
147
  app.logger.error(`load data source failed`, { cause: e });